]>
Commit | Line | Data |
---|---|---|
7f57883e DS |
1 | /* |
2 | * EIGRP Neighbor Handling. | |
3 | * Copyright (C) 2013-2016 | |
4 | * Authors: | |
5 | * Donnie Savage | |
6 | * Jan Janovic | |
7 | * Matej Perina | |
8 | * Peter Orsag | |
9 | * Peter Paluch | |
10 | * Frantisek Gazo | |
11 | * Tomas Hvorkovy | |
12 | * Martin Kontsek | |
13 | * Lukas Koribsky | |
14 | * | |
15 | * This file is part of GNU Zebra. | |
16 | * | |
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 | |
20 | * later version. | |
21 | * | |
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. | |
26 | * | |
896014f4 DL |
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 | |
7f57883e DS |
30 | */ |
31 | ||
32 | #include <zebra.h> | |
33 | ||
34 | #include "linklist.h" | |
35 | #include "prefix.h" | |
36 | #include "memory.h" | |
37 | #include "command.h" | |
38 | #include "thread.h" | |
39 | #include "stream.h" | |
40 | #include "table.h" | |
41 | #include "log.h" | |
42 | #include "keychain.h" | |
43 | #include "vty.h" | |
44 | ||
45 | #include "eigrpd/eigrp_structs.h" | |
46 | #include "eigrpd/eigrpd.h" | |
47 | #include "eigrpd/eigrp_interface.h" | |
48 | #include "eigrpd/eigrp_neighbor.h" | |
49 | #include "eigrpd/eigrp_dump.h" | |
50 | #include "eigrpd/eigrp_packet.h" | |
51 | #include "eigrpd/eigrp_zebra.h" | |
52 | #include "eigrpd/eigrp_vty.h" | |
53 | #include "eigrpd/eigrp_network.h" | |
54 | #include "eigrpd/eigrp_topology.h" | |
55 | #include "eigrpd/eigrp_memory.h" | |
8b0a80f1 | 56 | #include "eigrpd/eigrp_errors.h" |
7f57883e | 57 | |
d62a17ae | 58 | struct eigrp_neighbor *eigrp_nbr_new(struct eigrp_interface *ei) |
7f57883e | 59 | { |
d62a17ae | 60 | struct eigrp_neighbor *nbr; |
7f57883e | 61 | |
d62a17ae | 62 | /* Allcate new neighbor. */ |
63 | nbr = XCALLOC(MTYPE_EIGRP_NEIGHBOR, sizeof(struct eigrp_neighbor)); | |
7f57883e | 64 | |
d62a17ae | 65 | /* Relate neighbor to the interface. */ |
66 | nbr->ei = ei; | |
7f57883e | 67 | |
d62a17ae | 68 | /* Set default values. */ |
69 | eigrp_nbr_state_set(nbr, EIGRP_NEIGHBOR_DOWN); | |
7f57883e | 70 | |
d62a17ae | 71 | return nbr; |
7f57883e DS |
72 | } |
73 | ||
74 | /** | |
75 | *@fn void dissect_eigrp_sw_version (tvbuff_t *tvb, proto_tree *tree, | |
76 | * proto_item *ti) | |
77 | * | |
78 | * @par | |
79 | * Create a new neighbor structure and initalize it. | |
80 | */ | |
d62a17ae | 81 | static struct eigrp_neighbor *eigrp_nbr_add(struct eigrp_interface *ei, |
82 | struct eigrp_header *eigrph, | |
83 | struct ip *iph) | |
7f57883e | 84 | { |
d62a17ae | 85 | struct eigrp_neighbor *nbr; |
7f57883e | 86 | |
d62a17ae | 87 | nbr = eigrp_nbr_new(ei); |
88 | nbr->src = iph->ip_src; | |
7f57883e | 89 | |
d62a17ae | 90 | // if (IS_DEBUG_EIGRP_EVENT) |
91 | // zlog_debug("NSM[%s:%s]: start", IF_NAME (nbr->oi), | |
92 | // inet_ntoa (nbr->router_id)); | |
7f57883e | 93 | |
d62a17ae | 94 | return nbr; |
7f57883e DS |
95 | } |
96 | ||
d62a17ae | 97 | struct eigrp_neighbor *eigrp_nbr_get(struct eigrp_interface *ei, |
98 | struct eigrp_header *eigrph, | |
99 | struct ip *iph) | |
7f57883e | 100 | { |
d62a17ae | 101 | struct eigrp_neighbor *nbr; |
102 | struct listnode *node, *nnode; | |
7f57883e | 103 | |
d62a17ae | 104 | for (ALL_LIST_ELEMENTS(ei->nbrs, node, nnode, nbr)) { |
105 | if (iph->ip_src.s_addr == nbr->src.s_addr) { | |
106 | return nbr; | |
107 | } | |
108 | } | |
7f57883e | 109 | |
d62a17ae | 110 | nbr = eigrp_nbr_add(ei, eigrph, iph); |
111 | listnode_add(ei->nbrs, nbr); | |
7f57883e | 112 | |
d62a17ae | 113 | return nbr; |
7f57883e DS |
114 | } |
115 | ||
116 | /** | |
117 | * @fn eigrp_nbr_lookup_by_addr | |
118 | * | |
119 | * @param[in] ei EIGRP interface | |
120 | * @param[in] nbr_addr Address of neighbor | |
121 | * | |
122 | * @return void | |
123 | * | |
124 | * @par | |
125 | * Function is used for neighbor lookup by address | |
126 | * in specified interface. | |
127 | */ | |
d62a17ae | 128 | struct eigrp_neighbor *eigrp_nbr_lookup_by_addr(struct eigrp_interface *ei, |
129 | struct in_addr *addr) | |
7f57883e | 130 | { |
d62a17ae | 131 | struct eigrp_neighbor *nbr; |
132 | struct listnode *node, *nnode; | |
133 | ||
134 | for (ALL_LIST_ELEMENTS(ei->nbrs, node, nnode, nbr)) { | |
135 | if (addr->s_addr == nbr->src.s_addr) { | |
136 | return nbr; | |
137 | } | |
138 | } | |
139 | ||
140 | return NULL; | |
7f57883e DS |
141 | } |
142 | ||
143 | /** | |
144 | * @fn eigrp_nbr_lookup_by_addr_process | |
145 | * | |
f9e5c9ca DS |
146 | * @param[in] eigrp EIGRP process |
147 | * @param[in] nbr_addr Address of neighbor | |
7f57883e DS |
148 | * |
149 | * @return void | |
150 | * | |
151 | * @par | |
152 | * Function is used for neighbor lookup by address | |
153 | * in whole EIGRP process. | |
154 | */ | |
d62a17ae | 155 | struct eigrp_neighbor *eigrp_nbr_lookup_by_addr_process(struct eigrp *eigrp, |
156 | struct in_addr nbr_addr) | |
7f57883e | 157 | { |
d62a17ae | 158 | struct eigrp_interface *ei; |
159 | struct listnode *node, *node2, *nnode2; | |
160 | struct eigrp_neighbor *nbr; | |
161 | ||
162 | /* iterate over all eigrp interfaces */ | |
163 | for (ALL_LIST_ELEMENTS_RO(eigrp->eiflist, node, ei)) { | |
164 | /* iterate over all neighbors on eigrp interface */ | |
165 | for (ALL_LIST_ELEMENTS(ei->nbrs, node2, nnode2, nbr)) { | |
166 | /* compare if neighbor address is same as arg address */ | |
167 | if (nbr->src.s_addr == nbr_addr.s_addr) { | |
168 | return nbr; | |
169 | } | |
170 | } | |
171 | } | |
172 | ||
173 | return NULL; | |
7f57883e DS |
174 | } |
175 | ||
176 | ||
177 | /* Delete specified EIGRP neighbor from interface. */ | |
d62a17ae | 178 | void eigrp_nbr_delete(struct eigrp_neighbor *nbr) |
7f57883e | 179 | { |
d62a17ae | 180 | eigrp_nbr_state_set(nbr, EIGRP_NEIGHBOR_DOWN); |
181 | if (nbr->ei) | |
182 | eigrp_topology_neighbor_down(nbr->ei->eigrp, nbr); | |
183 | ||
184 | /* Cancel all events. */ /* Thread lookup cost would be negligible. */ | |
185 | thread_cancel_event(master, nbr); | |
186 | eigrp_fifo_free(nbr->multicast_queue); | |
187 | eigrp_fifo_free(nbr->retrans_queue); | |
188 | THREAD_OFF(nbr->t_holddown); | |
189 | ||
190 | if (nbr->ei) | |
191 | listnode_delete(nbr->ei->nbrs, nbr); | |
192 | XFREE(MTYPE_EIGRP_NEIGHBOR, nbr); | |
7f57883e DS |
193 | } |
194 | ||
d62a17ae | 195 | int holddown_timer_expired(struct thread *thread) |
7f57883e | 196 | { |
2ea6b572 DS |
197 | struct eigrp_neighbor *nbr = THREAD_ARG(thread); |
198 | struct eigrp *eigrp = nbr->ei->eigrp; | |
7f57883e | 199 | |
d62a17ae | 200 | zlog_info("Neighbor %s (%s) is down: holding time expired", |
201 | inet_ntoa(nbr->src), | |
2ea6b572 | 202 | ifindex2ifname(nbr->ei->ifp->ifindex, eigrp->vrf_id)); |
d62a17ae | 203 | nbr->state = EIGRP_NEIGHBOR_DOWN; |
204 | eigrp_nbr_delete(nbr); | |
7f57883e | 205 | |
d62a17ae | 206 | return 0; |
7f57883e DS |
207 | } |
208 | ||
d7c0a89a | 209 | uint8_t eigrp_nbr_state_get(struct eigrp_neighbor *nbr) |
7f57883e | 210 | { |
d62a17ae | 211 | return (nbr->state); |
7f57883e DS |
212 | } |
213 | ||
d7c0a89a | 214 | void eigrp_nbr_state_set(struct eigrp_neighbor *nbr, uint8_t state) |
7f57883e | 215 | { |
d62a17ae | 216 | nbr->state = state; |
217 | ||
218 | if (eigrp_nbr_state_get(nbr) == EIGRP_NEIGHBOR_DOWN) { | |
219 | // reset all the seq/ack counters | |
220 | nbr->recv_sequence_number = 0; | |
221 | nbr->init_sequence_number = 0; | |
222 | nbr->retrans_counter = 0; | |
223 | ||
224 | // Kvalues | |
225 | nbr->K1 = EIGRP_K1_DEFAULT; | |
226 | nbr->K2 = EIGRP_K2_DEFAULT; | |
227 | nbr->K3 = EIGRP_K3_DEFAULT; | |
228 | nbr->K4 = EIGRP_K4_DEFAULT; | |
229 | nbr->K5 = EIGRP_K5_DEFAULT; | |
230 | nbr->K6 = EIGRP_K6_DEFAULT; | |
231 | ||
232 | // hold time.. | |
233 | nbr->v_holddown = EIGRP_HOLD_INTERVAL_DEFAULT; | |
234 | THREAD_OFF(nbr->t_holddown); | |
235 | ||
236 | /* out with the old */ | |
237 | if (nbr->multicast_queue) | |
238 | eigrp_fifo_free(nbr->multicast_queue); | |
239 | if (nbr->retrans_queue) | |
240 | eigrp_fifo_free(nbr->retrans_queue); | |
241 | ||
242 | /* in with the new */ | |
243 | nbr->retrans_queue = eigrp_fifo_new(); | |
244 | nbr->multicast_queue = eigrp_fifo_new(); | |
245 | ||
246 | nbr->crypt_seqnum = 0; | |
247 | } | |
7f57883e DS |
248 | } |
249 | ||
d62a17ae | 250 | const char *eigrp_nbr_state_str(struct eigrp_neighbor *nbr) |
7f57883e | 251 | { |
d62a17ae | 252 | const char *state; |
253 | switch (nbr->state) { | |
254 | case EIGRP_NEIGHBOR_DOWN: | |
255 | state = "Down"; | |
256 | break; | |
257 | case EIGRP_NEIGHBOR_PENDING: | |
258 | state = "Waiting for Init"; | |
259 | break; | |
260 | case EIGRP_NEIGHBOR_UP: | |
261 | state = "Up"; | |
262 | break; | |
263 | default: | |
264 | state = "Unknown"; | |
265 | break; | |
266 | } | |
267 | ||
268 | return (state); | |
7f57883e DS |
269 | } |
270 | ||
d62a17ae | 271 | void eigrp_nbr_state_update(struct eigrp_neighbor *nbr) |
7f57883e | 272 | { |
d62a17ae | 273 | switch (nbr->state) { |
274 | case EIGRP_NEIGHBOR_DOWN: { | |
275 | /*Start Hold Down Timer for neighbor*/ | |
276 | // THREAD_OFF(nbr->t_holddown); | |
277 | // THREAD_TIMER_ON(master, nbr->t_holddown, | |
278 | // holddown_timer_expired, | |
279 | // nbr, nbr->v_holddown); | |
280 | break; | |
281 | } | |
282 | case EIGRP_NEIGHBOR_PENDING: { | |
283 | /*Reset Hold Down Timer for neighbor*/ | |
284 | THREAD_OFF(nbr->t_holddown); | |
285 | thread_add_timer(master, holddown_timer_expired, nbr, | |
286 | nbr->v_holddown, &nbr->t_holddown); | |
287 | break; | |
288 | } | |
289 | case EIGRP_NEIGHBOR_UP: { | |
290 | /*Reset Hold Down Timer for neighbor*/ | |
291 | THREAD_OFF(nbr->t_holddown); | |
292 | thread_add_timer(master, holddown_timer_expired, nbr, | |
293 | nbr->v_holddown, &nbr->t_holddown); | |
294 | break; | |
295 | } | |
296 | } | |
7f57883e DS |
297 | } |
298 | ||
2ea6b572 | 299 | int eigrp_nbr_count_get(struct eigrp *eigrp) |
d62a17ae | 300 | { |
301 | struct eigrp_interface *iface; | |
302 | struct listnode *node, *node2, *nnode2; | |
303 | struct eigrp_neighbor *nbr; | |
d7c0a89a | 304 | uint32_t counter; |
d62a17ae | 305 | |
d62a17ae | 306 | counter = 0; |
307 | for (ALL_LIST_ELEMENTS_RO(eigrp->eiflist, node, iface)) { | |
308 | for (ALL_LIST_ELEMENTS(iface->nbrs, node2, nnode2, nbr)) { | |
309 | if (nbr->state == EIGRP_NEIGHBOR_UP) { | |
310 | counter++; | |
311 | } | |
312 | } | |
313 | } | |
314 | return counter; | |
7f57883e DS |
315 | } |
316 | ||
317 | /** | |
318 | * @fn eigrp_nbr_hard_restart | |
319 | * | |
320 | * @param[in] nbr Neighbor who would receive hard restart | |
321 | * @param[in] vty Virtual terminal for log output | |
322 | * @return void | |
323 | * | |
324 | * @par | |
325 | * Function used for executing hard restart for neighbor: | |
326 | * Send Hello packet with Peer Termination TLV with | |
327 | * neighbor's address, set it's state to DOWN and delete the neighbor | |
328 | */ | |
329 | void eigrp_nbr_hard_restart(struct eigrp_neighbor *nbr, struct vty *vty) | |
330 | { | |
2ea6b572 | 331 | struct eigrp *eigrp = nbr->ei->eigrp; |
d62a17ae | 332 | |
333 | zlog_debug("Neighbor %s (%s) is down: manually cleared", | |
334 | inet_ntoa(nbr->src), | |
2ea6b572 | 335 | ifindex2ifname(nbr->ei->ifp->ifindex, eigrp->vrf_id)); |
d62a17ae | 336 | if (vty != NULL) { |
337 | vty_time_print(vty, 0); | |
338 | vty_out(vty, "Neighbor %s (%s) is down: manually cleared\n", | |
339 | inet_ntoa(nbr->src), | |
2ea6b572 | 340 | ifindex2ifname(nbr->ei->ifp->ifindex, eigrp->vrf_id)); |
d62a17ae | 341 | } |
342 | ||
343 | /* send Hello with Peer Termination TLV */ | |
344 | eigrp_hello_send(nbr->ei, EIGRP_HELLO_GRACEFUL_SHUTDOWN_NBR, | |
345 | &(nbr->src)); | |
346 | /* set neighbor to DOWN */ | |
347 | nbr->state = EIGRP_NEIGHBOR_DOWN; | |
348 | /* delete neighbor */ | |
349 | eigrp_nbr_delete(nbr); | |
7f57883e | 350 | } |
cd044247 | 351 | |
996c9314 LB |
352 | int eigrp_nbr_split_horizon_check(struct eigrp_nexthop_entry *ne, |
353 | struct eigrp_interface *ei) | |
cd044247 DS |
354 | { |
355 | if (ne->distance == EIGRP_MAX_METRIC) | |
356 | return 0; | |
357 | ||
358 | return (ne->ei == ei); | |
359 | } |