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
];
88 /* Check if any list fits */
90 && access_list_apply(alist
, pe2
->destination
)
93 && prefix_list_apply(plist
,
97 && access_list_apply(alist_i
,
101 && prefix_list_apply(plist_i
,
104 zlog_info("REPLY SEND: Setting Metric to max");
105 pe2
->reported_metric
.delay
= EIGRP_MAX_METRIC
;
113 ep
= eigrp_packet_new(nbr
->ei
->ifp
->mtu
, nbr
);
115 /* Prepare EIGRP INIT UPDATE header */
116 eigrp_packet_header_init(EIGRP_OPC_REPLY
, e
, ep
->s
, 0,
117 nbr
->ei
->eigrp
->sequence_number
, 0);
119 // encode Authentication TLV, if needed
120 if ((IF_DEF_PARAMS(nbr
->ei
->ifp
)->auth_type
== EIGRP_AUTH_TYPE_MD5
)
121 && (IF_DEF_PARAMS(nbr
->ei
->ifp
)->auth_keychain
!= NULL
)) {
122 length
+= eigrp_add_authTLV_MD5_to_stream(ep
->s
, nbr
->ei
);
126 length
+= eigrp_add_internalTLV_to_stream(ep
->s
, pe2
);
128 if ((IF_DEF_PARAMS(nbr
->ei
->ifp
)->auth_type
== EIGRP_AUTH_TYPE_MD5
)
129 && (IF_DEF_PARAMS(nbr
->ei
->ifp
)->auth_keychain
!= NULL
)) {
130 eigrp_make_md5_digest(nbr
->ei
, ep
->s
, EIGRP_AUTH_UPDATE_FLAG
);
134 eigrp_packet_checksum(nbr
->ei
, ep
->s
, length
);
137 ep
->dst
.s_addr
= nbr
->src
.s_addr
;
139 /*This ack number we await from neighbor*/
140 ep
->sequence_number
= nbr
->ei
->eigrp
->sequence_number
;
142 /*Put packet to retransmission queue*/
143 eigrp_fifo_push(nbr
->retrans_queue
, ep
);
145 if (nbr
->retrans_queue
->count
== 1) {
146 eigrp_send_packet_reliably(nbr
);
149 XFREE(MTYPE_EIGRP_PREFIX_ENTRY
, pe2
);
152 /*EIGRP REPLY read function*/
153 void eigrp_reply_receive(struct eigrp
*eigrp
, struct ip
*iph
,
154 struct eigrp_header
*eigrph
, struct stream
*s
,
155 struct eigrp_interface
*ei
, int size
)
157 struct eigrp_neighbor
*nbr
;
158 struct TLV_IPv4_Internal_type
*tlv
;
160 struct access_list
*alist
;
161 struct prefix_list
*plist
;
162 struct access_list
*alist_i
;
163 struct prefix_list
*plist_i
;
168 /* increment statistics. */
171 /* get neighbor struct */
172 nbr
= eigrp_nbr_get(ei
, eigrph
, iph
);
174 /* neighbor must be valid, eigrp_nbr_get creates if none existed */
177 nbr
->recv_sequence_number
= ntohl(eigrph
->sequence
);
179 while (s
->endp
> s
->getp
) {
180 type
= stream_getw(s
);
181 if (type
== EIGRP_TLV_IPv4_INT
) {
182 struct prefix dest_addr
;
184 stream_set_getp(s
, s
->getp
- sizeof(u_int16_t
));
186 tlv
= eigrp_read_ipv4_tlv(s
);
188 dest_addr
.family
= AF_INET
;
189 dest_addr
.u
.prefix4
= tlv
->destination
;
190 dest_addr
.prefixlen
= tlv
->prefix_length
;
191 struct eigrp_prefix_entry
*dest
=
192 eigrp_topology_table_lookup_ipv4(
193 eigrp
->topology_table
, &dest_addr
);
195 * Destination must exists
199 struct eigrp_fsm_action_message msg
;
200 struct eigrp_neighbor_entry
*entry
=
201 eigrp_prefix_entry_lookup(dest
->entries
, nbr
);
206 // TODO: Work in progress
207 /* get list from eigrp process */
209 /* Get access-lists and prefix-lists from process and
211 alist
= e
->list
[EIGRP_FILTER_IN
];
212 plist
= e
->prefix
[EIGRP_FILTER_IN
];
213 alist_i
= ei
->list
[EIGRP_FILTER_IN
];
214 plist_i
= ei
->prefix
[EIGRP_FILTER_IN
];
215 /* Check if any list fits */
217 && access_list_apply(alist
,
218 (struct prefix
*)&dest_addr
)
221 && prefix_list_apply(
222 plist
, (struct prefix
*)&dest_addr
)
225 && access_list_apply(
226 alist_i
, (struct prefix
*)&dest_addr
)
229 && prefix_list_apply(
230 plist_i
, (struct prefix
*)&dest_addr
)
232 tlv
->metric
.delay
= EIGRP_MAX_METRIC
;
238 msg
.packet_type
= EIGRP_OPC_REPLY
;
240 msg
.data_type
= EIGRP_INT
;
241 msg
.adv_router
= nbr
;
242 msg
.metrics
= tlv
->metric
;
245 eigrp_fsm_event(&msg
);
248 eigrp_IPv4_InternalTLV_free(tlv
);
251 eigrp_hello_send_ack(nbr
);