]>
git.proxmox.com Git - mirror_frr.git/blob - eigrpd/eigrp_reply.c
2 * EIGRP Sending and Receiving EIGRP Reply Packets.
3 * Copyright (C) 2013-2016
15 * This file is part of GNU Zebra.
17 * GNU Zebra is free software; you can redistribute it and/or modify it
18 * under the terms of the GNU General Public License as published by the
19 * Free Software Foundation; either version 2, or (at your option) any
22 * GNU Zebra is distributed in the hope that it will be useful, but
23 * WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * General Public License for more details.
27 * You should have received a copy of the GNU General Public License along
28 * with this program; see the file COPYING; if not, write to the Free Software
29 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
40 #include "sockunion.h"
50 #include "eigrpd/eigrp_structs.h"
51 #include "eigrpd/eigrpd.h"
52 #include "eigrpd/eigrp_interface.h"
53 #include "eigrpd/eigrp_neighbor.h"
54 #include "eigrpd/eigrp_packet.h"
55 #include "eigrpd/eigrp_zebra.h"
56 #include "eigrpd/eigrp_vty.h"
57 #include "eigrpd/eigrp_dump.h"
58 #include "eigrpd/eigrp_macros.h"
59 #include "eigrpd/eigrp_topology.h"
60 #include "eigrpd/eigrp_fsm.h"
61 #include "eigrpd/eigrp_memory.h"
63 void eigrp_send_reply(struct eigrp_neighbor
*nbr
, struct eigrp_prefix_entry
*pe
)
65 struct eigrp_packet
*ep
;
66 u_int16_t length
= EIGRP_HEADER_LEN
;
68 struct access_list
*alist
;
69 struct prefix_list
*plist
;
70 struct access_list
*alist_i
;
71 struct prefix_list
*plist_i
;
73 struct eigrp_prefix_entry
*pe2
;
75 // TODO: Work in progress
77 /* get list from eigrp process */
79 pe2
= XCALLOC(MTYPE_EIGRP_PREFIX_ENTRY
,
80 sizeof(struct eigrp_prefix_entry
));
81 memcpy(pe2
, pe
, sizeof(struct eigrp_prefix_entry
));
82 /* Get access-lists and prefix-lists from process and interface */
83 alist
= e
->list
[EIGRP_FILTER_OUT
];
84 plist
= e
->prefix
[EIGRP_FILTER_OUT
];
85 alist_i
= nbr
->ei
->list
[EIGRP_FILTER_OUT
];
86 plist_i
= nbr
->ei
->prefix
[EIGRP_FILTER_OUT
];
87 zlog_info("REPLY Send: Filtering");
89 zlog_info("REPLY SEND Prefix: %s", inet_ntoa(nbr
->src
));
90 /* Check if any list fits */
92 && access_list_apply(alist
, (struct prefix
*)pe2
->destination_ipv4
)
95 && prefix_list_apply(plist
,
96 (struct prefix
*)pe2
->destination_ipv4
)
99 && access_list_apply(alist_i
,
100 (struct prefix
*)pe2
->destination_ipv4
)
103 && prefix_list_apply(plist_i
,
104 (struct prefix
*)pe2
->destination_ipv4
)
106 zlog_info("REPLY SEND: Setting Metric to max");
107 pe2
->reported_metric
.delay
= EIGRP_MAX_METRIC
;
110 zlog_info("REPLY SEND: Not setting metric");
117 ep
= eigrp_packet_new(nbr
->ei
->ifp
->mtu
);
119 /* Prepare EIGRP INIT UPDATE header */
120 eigrp_packet_header_init(EIGRP_OPC_REPLY
, nbr
->ei
, ep
->s
, 0,
121 nbr
->ei
->eigrp
->sequence_number
, 0);
123 // encode Authentication TLV, if needed
124 if ((IF_DEF_PARAMS(nbr
->ei
->ifp
)->auth_type
== EIGRP_AUTH_TYPE_MD5
)
125 && (IF_DEF_PARAMS(nbr
->ei
->ifp
)->auth_keychain
!= NULL
)) {
126 length
+= eigrp_add_authTLV_MD5_to_stream(ep
->s
, nbr
->ei
);
130 length
+= eigrp_add_internalTLV_to_stream(ep
->s
, pe2
);
132 if ((IF_DEF_PARAMS(nbr
->ei
->ifp
)->auth_type
== EIGRP_AUTH_TYPE_MD5
)
133 && (IF_DEF_PARAMS(nbr
->ei
->ifp
)->auth_keychain
!= NULL
)) {
134 eigrp_make_md5_digest(nbr
->ei
, ep
->s
, EIGRP_AUTH_UPDATE_FLAG
);
138 eigrp_packet_checksum(nbr
->ei
, ep
->s
, length
);
141 ep
->dst
.s_addr
= nbr
->src
.s_addr
;
143 /*This ack number we await from neighbor*/
144 ep
->sequence_number
= nbr
->ei
->eigrp
->sequence_number
;
146 /*Put packet to retransmission queue*/
147 eigrp_fifo_push_head(nbr
->retrans_queue
, ep
);
149 if (nbr
->retrans_queue
->count
== 1) {
150 eigrp_send_packet_reliably(nbr
);
153 XFREE(MTYPE_EIGRP_PREFIX_ENTRY
, pe2
);
156 /*EIGRP REPLY read function*/
157 void eigrp_reply_receive(struct eigrp
*eigrp
, struct ip
*iph
,
158 struct eigrp_header
*eigrph
, struct stream
*s
,
159 struct eigrp_interface
*ei
, int size
)
161 struct eigrp_neighbor
*nbr
;
162 struct TLV_IPv4_Internal_type
*tlv
;
164 struct access_list
*alist
;
165 struct prefix_list
*plist
;
166 struct access_list
*alist_i
;
167 struct prefix_list
*plist_i
;
172 /* increment statistics. */
175 /* get neighbor struct */
176 nbr
= eigrp_nbr_get(ei
, eigrph
, iph
);
178 /* neighbor must be valid, eigrp_nbr_get creates if none existed */
181 nbr
->recv_sequence_number
= ntohl(eigrph
->sequence
);
183 while (s
->endp
> s
->getp
) {
184 type
= stream_getw(s
);
185 if (type
== EIGRP_TLV_IPv4_INT
) {
186 struct prefix_ipv4 dest_addr
;
188 stream_set_getp(s
, s
->getp
- sizeof(u_int16_t
));
190 tlv
= eigrp_read_ipv4_tlv(s
);
192 dest_addr
.family
= AF_INET
;
193 dest_addr
.prefix
= tlv
->destination
;
194 dest_addr
.prefixlen
= tlv
->prefix_length
;
195 struct eigrp_prefix_entry
*dest
=
196 eigrp_topology_table_lookup_ipv4(
197 eigrp
->topology_table
, &dest_addr
);
199 * Destination must exists
203 struct eigrp_fsm_action_message
*msg
;
204 msg
= XCALLOC(MTYPE_EIGRP_FSM_MSG
,
205 sizeof(struct eigrp_fsm_action_message
));
206 struct eigrp_neighbor_entry
*entry
=
207 eigrp_prefix_entry_lookup(dest
->entries
, nbr
);
212 // TODO: Work in progress
213 /* get list from eigrp process */
215 /* Get access-lists and prefix-lists from process and
217 alist
= e
->list
[EIGRP_FILTER_IN
];
218 plist
= e
->prefix
[EIGRP_FILTER_IN
];
219 alist_i
= ei
->list
[EIGRP_FILTER_IN
];
220 plist_i
= ei
->prefix
[EIGRP_FILTER_IN
];
221 /* Check if any list fits */
223 && access_list_apply(alist
,
224 (struct prefix
*)&dest_addr
)
227 && prefix_list_apply(
228 plist
, (struct prefix
*)&dest_addr
)
231 && access_list_apply(
232 alist_i
, (struct prefix
*)&dest_addr
)
235 && prefix_list_apply(
236 plist_i
, (struct prefix
*)&dest_addr
)
238 tlv
->metric
.delay
= EIGRP_MAX_METRIC
;
244 msg
->packet_type
= EIGRP_OPC_REPLY
;
246 msg
->data_type
= EIGRP_TLV_IPv4_INT
;
247 msg
->adv_router
= nbr
;
248 msg
->data
.ipv4_int_type
= tlv
;
251 int event
= eigrp_get_fsm_event(msg
);
252 eigrp_fsm_event(msg
, event
);
255 eigrp_IPv4_InternalTLV_free(tlv
);
258 eigrp_hello_send_ack(nbr
);