]>
Commit | Line | Data |
---|---|---|
7f57883e DS |
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 | * | |
896014f4 DL |
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 | |
7f57883e DS |
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" | |
7f57883e | 55 | |
d7c0a89a | 56 | uint32_t eigrp_query_send_all(struct eigrp *eigrp) |
7f57883e | 57 | { |
d62a17ae | 58 | struct eigrp_interface *iface; |
59 | struct listnode *node, *node2, *nnode2; | |
dc4accdd | 60 | struct eigrp_prefix_descriptor *pe; |
d7c0a89a | 61 | uint32_t counter; |
d62a17ae | 62 | |
63 | if (eigrp == NULL) { | |
64 | zlog_debug("EIGRP Routing Process not enabled"); | |
65 | return 0; | |
66 | } | |
67 | ||
68 | counter = 0; | |
69 | for (ALL_LIST_ELEMENTS_RO(eigrp->eiflist, node, iface)) { | |
70 | eigrp_send_query(iface); | |
71 | counter++; | |
72 | } | |
73 | ||
74 | for (ALL_LIST_ELEMENTS(eigrp->topology_changes_internalIPV4, node2, | |
75 | nnode2, pe)) { | |
76 | if (pe->req_action & EIGRP_FSM_NEED_QUERY) { | |
77 | pe->req_action &= ~EIGRP_FSM_NEED_QUERY; | |
78 | listnode_delete(eigrp->topology_changes_internalIPV4, | |
79 | pe); | |
80 | } | |
81 | } | |
82 | ||
83 | return counter; | |
7f57883e DS |
84 | } |
85 | ||
86 | /*EIGRP QUERY read function*/ | |
d62a17ae | 87 | void eigrp_query_receive(struct eigrp *eigrp, struct ip *iph, |
88 | struct eigrp_header *eigrph, struct stream *s, | |
89 | struct eigrp_interface *ei, int size) | |
7f57883e | 90 | { |
d62a17ae | 91 | struct eigrp_neighbor *nbr; |
92 | struct TLV_IPv4_Internal_type *tlv; | |
476a1469 | 93 | struct prefix dest_addr; |
d62a17ae | 94 | |
d7c0a89a QY |
95 | uint16_t type; |
96 | uint16_t length; | |
d62a17ae | 97 | |
98 | /* increment statistics. */ | |
99 | ei->query_in++; | |
100 | ||
101 | /* get neighbor struct */ | |
102 | nbr = eigrp_nbr_get(ei, eigrph, iph); | |
103 | ||
104 | /* neighbor must be valid, eigrp_nbr_get creates if none existed */ | |
105 | assert(nbr); | |
106 | ||
107 | nbr->recv_sequence_number = ntohl(eigrph->sequence); | |
108 | ||
109 | while (s->endp > s->getp) { | |
110 | type = stream_getw(s); | |
c283f389 DS |
111 | switch (type) { |
112 | case EIGRP_TLV_IPv4_INT: | |
d7c0a89a | 113 | stream_set_getp(s, s->getp - sizeof(uint16_t)); |
d62a17ae | 114 | |
115 | tlv = eigrp_read_ipv4_tlv(s); | |
116 | ||
117 | dest_addr.family = AF_INET; | |
476a1469 | 118 | dest_addr.u.prefix4 = tlv->destination; |
d62a17ae | 119 | dest_addr.prefixlen = tlv->prefix_length; |
dc4accdd | 120 | struct eigrp_prefix_descriptor *dest = |
d62a17ae | 121 | eigrp_topology_table_lookup_ipv4( |
122 | eigrp->topology_table, &dest_addr); | |
123 | ||
124 | /* If the destination exists (it should, but one never | |
125 | * know)*/ | |
126 | if (dest != NULL) { | |
92035b1d | 127 | struct eigrp_fsm_action_message msg; |
dc4accdd DS |
128 | struct eigrp_route_descriptor *entry = |
129 | eigrp_route_descriptor_lookup( | |
130 | dest->entries, nbr); | |
92035b1d DS |
131 | msg.packet_type = EIGRP_OPC_QUERY; |
132 | msg.eigrp = eigrp; | |
7cfa4322 | 133 | msg.data_type = EIGRP_INT; |
92035b1d | 134 | msg.adv_router = nbr; |
db6ec9ff | 135 | msg.metrics = tlv->metric; |
92035b1d DS |
136 | msg.entry = entry; |
137 | msg.prefix = dest; | |
6118272f | 138 | eigrp_fsm_event(&msg); |
d62a17ae | 139 | } |
140 | eigrp_IPv4_InternalTLV_free(tlv); | |
c283f389 DS |
141 | break; |
142 | ||
143 | case EIGRP_TLV_IPv4_EXT: | |
996c9314 LB |
144 | /* DVS: processing of external routes needs packet and fsm work. |
145 | * for now, lets just not creash the box | |
146 | */ | |
c283f389 DS |
147 | default: |
148 | length = stream_getw(s); | |
149 | // -2 for type, -2 for len | |
996c9314 | 150 | for (length -= 4; length; length--) { |
c283f389 DS |
151 | (void)stream_getc(s); |
152 | } | |
d62a17ae | 153 | } |
154 | } | |
155 | eigrp_hello_send_ack(nbr); | |
156 | eigrp_query_send_all(eigrp); | |
157 | eigrp_update_send_all(eigrp, nbr->ei); | |
7f57883e DS |
158 | } |
159 | ||
d62a17ae | 160 | void eigrp_send_query(struct eigrp_interface *ei) |
7f57883e | 161 | { |
c3d4dea2 | 162 | struct eigrp_packet *ep = NULL; |
d7c0a89a | 163 | uint16_t length = EIGRP_HEADER_LEN; |
d62a17ae | 164 | struct listnode *node, *nnode, *node2, *nnode2; |
165 | struct eigrp_neighbor *nbr; | |
dc4accdd | 166 | struct eigrp_prefix_descriptor *pe; |
d4395853 | 167 | bool has_tlv = false; |
c3d4dea2 | 168 | bool new_packet = true; |
9378632f | 169 | uint16_t eigrp_mtu = EIGRP_PACKET_MTU(ei->ifp->mtu); |
d62a17ae | 170 | |
d62a17ae | 171 | for (ALL_LIST_ELEMENTS(ei->eigrp->topology_changes_internalIPV4, node, |
172 | nnode, pe)) { | |
68b7dd07 DS |
173 | if (!(pe->req_action & EIGRP_FSM_NEED_QUERY)) |
174 | continue; | |
175 | ||
c3d4dea2 | 176 | if (new_packet) { |
ca83a1ab | 177 | ep = eigrp_packet_new(eigrp_mtu, NULL); |
c3d4dea2 DS |
178 | |
179 | /* Prepare EIGRP INIT UPDATE header */ | |
996c9314 LB |
180 | eigrp_packet_header_init(EIGRP_OPC_QUERY, ei->eigrp, |
181 | ep->s, 0, | |
c3d4dea2 DS |
182 | ei->eigrp->sequence_number, 0); |
183 | ||
184 | // encode Authentication TLV, if needed | |
185 | if ((ei->params.auth_type == EIGRP_AUTH_TYPE_MD5) | |
186 | && (ei->params.auth_keychain != NULL)) { | |
996c9314 LB |
187 | length += eigrp_add_authTLV_MD5_to_stream(ep->s, |
188 | ei); | |
c3d4dea2 DS |
189 | } |
190 | new_packet = false; | |
191 | } | |
192 | ||
68b7dd07 | 193 | length += eigrp_add_internalTLV_to_stream(ep->s, pe); |
c3d4dea2 | 194 | has_tlv = true; |
68b7dd07 | 195 | for (ALL_LIST_ELEMENTS(ei->nbrs, node2, nnode2, nbr)) { |
c3d4dea2 | 196 | if (nbr->state == EIGRP_NEIGHBOR_UP) |
68b7dd07 | 197 | listnode_add(pe->rij, nbr); |
c3d4dea2 DS |
198 | } |
199 | ||
ca83a1ab | 200 | if (length + EIGRP_TLV_MAX_IPV4_BYTE > eigrp_mtu) { |
c3d4dea2 DS |
201 | if ((ei->params.auth_type == EIGRP_AUTH_TYPE_MD5) |
202 | && ei->params.auth_keychain != NULL) { | |
203 | eigrp_make_md5_digest(ei, ep->s, | |
204 | EIGRP_AUTH_UPDATE_FLAG); | |
205 | } | |
206 | ||
207 | eigrp_packet_checksum(ei, ep->s, length); | |
208 | ep->length = length; | |
209 | ||
210 | ep->dst.s_addr = htonl(EIGRP_MULTICAST_ADDRESS); | |
211 | ||
212 | ep->sequence_number = ei->eigrp->sequence_number; | |
213 | ei->eigrp->sequence_number++; | |
214 | ||
215 | for (ALL_LIST_ELEMENTS(ei->nbrs, node2, nnode2, nbr)) { | |
216 | struct eigrp_packet *dup; | |
217 | ||
218 | if (nbr->state != EIGRP_NEIGHBOR_UP) | |
219 | continue; | |
220 | ||
221 | dup = eigrp_packet_duplicate(ep, nbr); | |
222 | /*Put packet to retransmission queue*/ | |
223 | eigrp_fifo_push(nbr->retrans_queue, dup); | |
224 | ||
225 | if (nbr->retrans_queue->count == 1) | |
226 | eigrp_send_packet_reliably(nbr); | |
d62a17ae | 227 | } |
c3d4dea2 DS |
228 | |
229 | has_tlv = false; | |
230 | length = 0; | |
231 | eigrp_packet_free(ep); | |
232 | ep = NULL; | |
233 | new_packet = true; | |
d62a17ae | 234 | } |
235 | } | |
236 | ||
11b88ecf | 237 | if (!has_tlv) |
d62a17ae | 238 | return; |
d62a17ae | 239 | |
b748db67 | 240 | if ((ei->params.auth_type == EIGRP_AUTH_TYPE_MD5) |
c3d4dea2 | 241 | && ei->params.auth_keychain != NULL) |
d62a17ae | 242 | eigrp_make_md5_digest(ei, ep->s, EIGRP_AUTH_UPDATE_FLAG); |
c3d4dea2 | 243 | |
d62a17ae | 244 | |
245 | /* EIGRP Checksum */ | |
246 | eigrp_packet_checksum(ei, ep->s, length); | |
247 | ||
248 | ep->length = length; | |
249 | ep->dst.s_addr = htonl(EIGRP_MULTICAST_ADDRESS); | |
250 | ||
251 | /*This ack number we await from neighbor*/ | |
252 | ep->sequence_number = ei->eigrp->sequence_number; | |
68b7dd07 | 253 | ei->eigrp->sequence_number++; |
d62a17ae | 254 | |
255 | for (ALL_LIST_ELEMENTS(ei->nbrs, node2, nnode2, nbr)) { | |
c3d4dea2 | 256 | struct eigrp_packet *dup; |
d62a17ae | 257 | |
c3d4dea2 DS |
258 | if (nbr->state != EIGRP_NEIGHBOR_UP) |
259 | continue; | |
260 | ||
261 | dup = eigrp_packet_duplicate(ep, nbr); | |
262 | /*Put packet to retransmission queue*/ | |
263 | eigrp_fifo_push(nbr->retrans_queue, dup); | |
264 | ||
265 | if (nbr->retrans_queue->count == 1) | |
266 | eigrp_send_packet_reliably(nbr); | |
d62a17ae | 267 | } |
268 | ||
c3d4dea2 | 269 | eigrp_packet_free(ep); |
7f57883e | 270 | } |