]> git.proxmox.com Git - mirror_frr.git/blob - eigrpd/eigrp_query.c
zebra: Allow ns delete to happen after under/over flow checks
[mirror_frr.git] / eigrpd / eigrp_query.c
1 /*
2 * EIGRP Sending and Receiving EIGRP Query Packets.
3 * Copyright (C) 2013-2014
4 * Authors:
5 * Donnie Savage
6 * Jan Janovic
7 * Matej Perina
8 * Peter Orsag
9 * Peter Paluch
10 *
11 * This file is part of GNU Zebra.
12 *
13 * GNU Zebra is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2, or (at your option) any
16 * later version.
17 *
18 * GNU Zebra is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with this program; see the file COPYING; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 */
27
28 #include <zebra.h>
29
30 #include "thread.h"
31 #include "memory.h"
32 #include "linklist.h"
33 #include "prefix.h"
34 #include "if.h"
35 #include "table.h"
36 #include "sockunion.h"
37 #include "stream.h"
38 #include "log.h"
39 #include "sockopt.h"
40 #include "checksum.h"
41 #include "md5.h"
42 #include "vty.h"
43
44 #include "eigrpd/eigrp_structs.h"
45 #include "eigrpd/eigrpd.h"
46 #include "eigrpd/eigrp_interface.h"
47 #include "eigrpd/eigrp_neighbor.h"
48 #include "eigrpd/eigrp_packet.h"
49 #include "eigrpd/eigrp_zebra.h"
50 #include "eigrpd/eigrp_vty.h"
51 #include "eigrpd/eigrp_dump.h"
52 #include "eigrpd/eigrp_macros.h"
53 #include "eigrpd/eigrp_topology.h"
54 #include "eigrpd/eigrp_fsm.h"
55 #include "eigrpd/eigrp_memory.h"
56
57 uint32_t eigrp_query_send_all(struct eigrp *eigrp)
58 {
59 struct eigrp_interface *iface;
60 struct listnode *node, *node2, *nnode2;
61 struct eigrp_prefix_entry *pe;
62 uint32_t counter;
63
64 if (eigrp == NULL) {
65 zlog_debug("EIGRP Routing Process not enabled");
66 return 0;
67 }
68
69 counter = 0;
70 for (ALL_LIST_ELEMENTS_RO(eigrp->eiflist, node, iface)) {
71 eigrp_send_query(iface);
72 counter++;
73 }
74
75 for (ALL_LIST_ELEMENTS(eigrp->topology_changes_internalIPV4, node2,
76 nnode2, pe)) {
77 if (pe->req_action & EIGRP_FSM_NEED_QUERY) {
78 pe->req_action &= ~EIGRP_FSM_NEED_QUERY;
79 listnode_delete(eigrp->topology_changes_internalIPV4,
80 pe);
81 }
82 }
83
84 return counter;
85 }
86
87 /*EIGRP QUERY read function*/
88 void eigrp_query_receive(struct eigrp *eigrp, struct ip *iph,
89 struct eigrp_header *eigrph, struct stream *s,
90 struct eigrp_interface *ei, int size)
91 {
92 struct eigrp_neighbor *nbr;
93 struct TLV_IPv4_Internal_type *tlv;
94 struct prefix dest_addr;
95
96 uint16_t type;
97 uint16_t length;
98
99 /* increment statistics. */
100 ei->query_in++;
101
102 /* get neighbor struct */
103 nbr = eigrp_nbr_get(ei, eigrph, iph);
104
105 /* neighbor must be valid, eigrp_nbr_get creates if none existed */
106 assert(nbr);
107
108 nbr->recv_sequence_number = ntohl(eigrph->sequence);
109
110 while (s->endp > s->getp) {
111 type = stream_getw(s);
112 switch (type) {
113 case EIGRP_TLV_IPv4_INT:
114 stream_set_getp(s, s->getp - sizeof(uint16_t));
115
116 tlv = eigrp_read_ipv4_tlv(s);
117
118 dest_addr.family = AF_INET;
119 dest_addr.u.prefix4 = tlv->destination;
120 dest_addr.prefixlen = tlv->prefix_length;
121 struct eigrp_prefix_entry *dest =
122 eigrp_topology_table_lookup_ipv4(
123 eigrp->topology_table, &dest_addr);
124
125 /* If the destination exists (it should, but one never
126 * know)*/
127 if (dest != NULL) {
128 struct eigrp_fsm_action_message msg;
129 struct eigrp_nexthop_entry *entry =
130 eigrp_prefix_entry_lookup(dest->entries,
131 nbr);
132 msg.packet_type = EIGRP_OPC_QUERY;
133 msg.eigrp = eigrp;
134 msg.data_type = EIGRP_INT;
135 msg.adv_router = nbr;
136 msg.metrics = tlv->metric;
137 msg.entry = entry;
138 msg.prefix = dest;
139 eigrp_fsm_event(&msg);
140 }
141 eigrp_IPv4_InternalTLV_free(tlv);
142 break;
143
144 case EIGRP_TLV_IPv4_EXT:
145 /* DVS: processing of external routes needs packet and fsm work.
146 * for now, lets just not creash the box
147 */
148 default:
149 length = stream_getw(s);
150 // -2 for type, -2 for len
151 for (length -= 4; length; length--) {
152 (void)stream_getc(s);
153 }
154 }
155 }
156 eigrp_hello_send_ack(nbr);
157 eigrp_query_send_all(eigrp);
158 eigrp_update_send_all(eigrp, nbr->ei);
159 }
160
161 void eigrp_send_query(struct eigrp_interface *ei)
162 {
163 struct eigrp_packet *ep = NULL;
164 uint16_t length = EIGRP_HEADER_LEN;
165 struct listnode *node, *nnode, *node2, *nnode2;
166 struct eigrp_neighbor *nbr;
167 struct eigrp_prefix_entry *pe;
168 bool has_tlv = false;
169 bool new_packet = true;
170 uint16_t eigrp_mtu = EIGRP_PACKET_MTU(ei->ifp->mtu);
171
172 for (ALL_LIST_ELEMENTS(ei->eigrp->topology_changes_internalIPV4, node,
173 nnode, pe)) {
174 if (!(pe->req_action & EIGRP_FSM_NEED_QUERY))
175 continue;
176
177 if (new_packet) {
178 ep = eigrp_packet_new(eigrp_mtu, NULL);
179
180 /* Prepare EIGRP INIT UPDATE header */
181 eigrp_packet_header_init(EIGRP_OPC_QUERY, ei->eigrp,
182 ep->s, 0,
183 ei->eigrp->sequence_number, 0);
184
185 // encode Authentication TLV, if needed
186 if ((ei->params.auth_type == EIGRP_AUTH_TYPE_MD5)
187 && (ei->params.auth_keychain != NULL)) {
188 length += eigrp_add_authTLV_MD5_to_stream(ep->s,
189 ei);
190 }
191 new_packet = false;
192 }
193
194 length += eigrp_add_internalTLV_to_stream(ep->s, pe);
195 has_tlv = true;
196 for (ALL_LIST_ELEMENTS(ei->nbrs, node2, nnode2, nbr)) {
197 if (nbr->state == EIGRP_NEIGHBOR_UP)
198 listnode_add(pe->rij, nbr);
199 }
200
201 if (length + EIGRP_TLV_MAX_IPV4_BYTE > eigrp_mtu) {
202 if ((ei->params.auth_type == EIGRP_AUTH_TYPE_MD5)
203 && ei->params.auth_keychain != NULL) {
204 eigrp_make_md5_digest(ei, ep->s,
205 EIGRP_AUTH_UPDATE_FLAG);
206 }
207
208 eigrp_packet_checksum(ei, ep->s, length);
209 ep->length = length;
210
211 ep->dst.s_addr = htonl(EIGRP_MULTICAST_ADDRESS);
212
213 ep->sequence_number = ei->eigrp->sequence_number;
214 ei->eigrp->sequence_number++;
215
216 for (ALL_LIST_ELEMENTS(ei->nbrs, node2, nnode2, nbr)) {
217 struct eigrp_packet *dup;
218
219 if (nbr->state != EIGRP_NEIGHBOR_UP)
220 continue;
221
222 dup = eigrp_packet_duplicate(ep, nbr);
223 /*Put packet to retransmission queue*/
224 eigrp_fifo_push(nbr->retrans_queue, dup);
225
226 if (nbr->retrans_queue->count == 1)
227 eigrp_send_packet_reliably(nbr);
228 }
229
230 has_tlv = false;
231 length = 0;
232 eigrp_packet_free(ep);
233 ep = NULL;
234 new_packet = true;
235 }
236 }
237
238 if (!has_tlv)
239 return;
240
241 if ((ei->params.auth_type == EIGRP_AUTH_TYPE_MD5)
242 && ei->params.auth_keychain != NULL)
243 eigrp_make_md5_digest(ei, ep->s, EIGRP_AUTH_UPDATE_FLAG);
244
245
246 /* EIGRP Checksum */
247 eigrp_packet_checksum(ei, ep->s, length);
248
249 ep->length = length;
250 ep->dst.s_addr = htonl(EIGRP_MULTICAST_ADDRESS);
251
252 /*This ack number we await from neighbor*/
253 ep->sequence_number = ei->eigrp->sequence_number;
254 ei->eigrp->sequence_number++;
255
256 for (ALL_LIST_ELEMENTS(ei->nbrs, node2, nnode2, nbr)) {
257 struct eigrp_packet *dup;
258
259 if (nbr->state != EIGRP_NEIGHBOR_UP)
260 continue;
261
262 dup = eigrp_packet_duplicate(ep, nbr);
263 /*Put packet to retransmission queue*/
264 eigrp_fifo_push(nbr->retrans_queue, dup);
265
266 if (nbr->retrans_queue->count == 1)
267 eigrp_send_packet_reliably(nbr);
268 }
269
270 eigrp_packet_free(ep);
271 }