]>
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" | |
55 | #include "eigrpd/eigrp_memory.h" | |
56 | ||
d7c0a89a | 57 | uint32_t eigrp_query_send_all(struct eigrp *eigrp) |
7f57883e | 58 | { |
d62a17ae | 59 | struct eigrp_interface *iface; |
60 | struct listnode *node, *node2, *nnode2; | |
61 | struct eigrp_prefix_entry *pe; | |
d7c0a89a | 62 | uint32_t counter; |
d62a17ae | 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; | |
7f57883e DS |
85 | } |
86 | ||
87 | /*EIGRP QUERY read function*/ | |
d62a17ae | 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) | |
7f57883e | 91 | { |
d62a17ae | 92 | struct eigrp_neighbor *nbr; |
93 | struct TLV_IPv4_Internal_type *tlv; | |
476a1469 | 94 | struct prefix dest_addr; |
d62a17ae | 95 | |
d7c0a89a QY |
96 | uint16_t type; |
97 | uint16_t length; | |
d62a17ae | 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); | |
c283f389 DS |
112 | switch (type) { |
113 | case EIGRP_TLV_IPv4_INT: | |
d7c0a89a | 114 | stream_set_getp(s, s->getp - sizeof(uint16_t)); |
d62a17ae | 115 | |
116 | tlv = eigrp_read_ipv4_tlv(s); | |
117 | ||
118 | dest_addr.family = AF_INET; | |
476a1469 | 119 | dest_addr.u.prefix4 = tlv->destination; |
d62a17ae | 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) { | |
92035b1d | 128 | struct eigrp_fsm_action_message msg; |
af0a6344 | 129 | struct eigrp_nexthop_entry *entry = |
d62a17ae | 130 | eigrp_prefix_entry_lookup(dest->entries, |
131 | nbr); | |
92035b1d DS |
132 | msg.packet_type = EIGRP_OPC_QUERY; |
133 | msg.eigrp = eigrp; | |
7cfa4322 | 134 | msg.data_type = EIGRP_INT; |
92035b1d | 135 | msg.adv_router = nbr; |
db6ec9ff | 136 | msg.metrics = tlv->metric; |
92035b1d DS |
137 | msg.entry = entry; |
138 | msg.prefix = dest; | |
6118272f | 139 | eigrp_fsm_event(&msg); |
d62a17ae | 140 | } |
141 | eigrp_IPv4_InternalTLV_free(tlv); | |
c283f389 DS |
142 | break; |
143 | ||
144 | case EIGRP_TLV_IPv4_EXT: | |
996c9314 LB |
145 | /* DVS: processing of external routes needs packet and fsm work. |
146 | * for now, lets just not creash the box | |
147 | */ | |
c283f389 DS |
148 | default: |
149 | length = stream_getw(s); | |
150 | // -2 for type, -2 for len | |
996c9314 | 151 | for (length -= 4; length; length--) { |
c283f389 DS |
152 | (void)stream_getc(s); |
153 | } | |
d62a17ae | 154 | } |
155 | } | |
156 | eigrp_hello_send_ack(nbr); | |
157 | eigrp_query_send_all(eigrp); | |
158 | eigrp_update_send_all(eigrp, nbr->ei); | |
7f57883e DS |
159 | } |
160 | ||
d62a17ae | 161 | void eigrp_send_query(struct eigrp_interface *ei) |
7f57883e | 162 | { |
c3d4dea2 | 163 | struct eigrp_packet *ep = NULL; |
d7c0a89a | 164 | uint16_t length = EIGRP_HEADER_LEN; |
d62a17ae | 165 | struct listnode *node, *nnode, *node2, *nnode2; |
166 | struct eigrp_neighbor *nbr; | |
167 | struct eigrp_prefix_entry *pe; | |
d4395853 | 168 | bool has_tlv = false; |
c3d4dea2 | 169 | bool new_packet = true; |
9378632f | 170 | uint16_t eigrp_mtu = EIGRP_PACKET_MTU(ei->ifp->mtu); |
d62a17ae | 171 | |
d62a17ae | 172 | for (ALL_LIST_ELEMENTS(ei->eigrp->topology_changes_internalIPV4, node, |
173 | nnode, pe)) { | |
68b7dd07 DS |
174 | if (!(pe->req_action & EIGRP_FSM_NEED_QUERY)) |
175 | continue; | |
176 | ||
c3d4dea2 | 177 | if (new_packet) { |
ca83a1ab | 178 | ep = eigrp_packet_new(eigrp_mtu, NULL); |
c3d4dea2 DS |
179 | |
180 | /* Prepare EIGRP INIT UPDATE header */ | |
996c9314 LB |
181 | eigrp_packet_header_init(EIGRP_OPC_QUERY, ei->eigrp, |
182 | ep->s, 0, | |
c3d4dea2 DS |
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)) { | |
996c9314 LB |
188 | length += eigrp_add_authTLV_MD5_to_stream(ep->s, |
189 | ei); | |
c3d4dea2 DS |
190 | } |
191 | new_packet = false; | |
192 | } | |
193 | ||
68b7dd07 | 194 | length += eigrp_add_internalTLV_to_stream(ep->s, pe); |
c3d4dea2 | 195 | has_tlv = true; |
68b7dd07 | 196 | for (ALL_LIST_ELEMENTS(ei->nbrs, node2, nnode2, nbr)) { |
c3d4dea2 | 197 | if (nbr->state == EIGRP_NEIGHBOR_UP) |
68b7dd07 | 198 | listnode_add(pe->rij, nbr); |
c3d4dea2 DS |
199 | } |
200 | ||
ca83a1ab | 201 | if (length + EIGRP_TLV_MAX_IPV4_BYTE > eigrp_mtu) { |
c3d4dea2 DS |
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); | |
d62a17ae | 228 | } |
c3d4dea2 DS |
229 | |
230 | has_tlv = false; | |
231 | length = 0; | |
232 | eigrp_packet_free(ep); | |
233 | ep = NULL; | |
234 | new_packet = true; | |
d62a17ae | 235 | } |
236 | } | |
237 | ||
11b88ecf | 238 | if (!has_tlv) |
d62a17ae | 239 | return; |
d62a17ae | 240 | |
b748db67 | 241 | if ((ei->params.auth_type == EIGRP_AUTH_TYPE_MD5) |
c3d4dea2 | 242 | && ei->params.auth_keychain != NULL) |
d62a17ae | 243 | eigrp_make_md5_digest(ei, ep->s, EIGRP_AUTH_UPDATE_FLAG); |
c3d4dea2 | 244 | |
d62a17ae | 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; | |
68b7dd07 | 254 | ei->eigrp->sequence_number++; |
d62a17ae | 255 | |
256 | for (ALL_LIST_ELEMENTS(ei->nbrs, node2, nnode2, nbr)) { | |
c3d4dea2 | 257 | struct eigrp_packet *dup; |
d62a17ae | 258 | |
c3d4dea2 DS |
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); | |
d62a17ae | 268 | } |
269 | ||
c3d4dea2 | 270 | eigrp_packet_free(ep); |
7f57883e | 271 | } |