]> git.proxmox.com Git - mirror_frr.git/blob - ospf6d/ospf6_neighbor.c
Merge pull request #5011 from karamalla0406/evpn_cli_json
[mirror_frr.git] / ospf6d / ospf6_neighbor.c
1 /*
2 * Copyright (C) 2003 Yasuhiro Ohara
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <zebra.h>
22
23 #include "log.h"
24 #include "memory.h"
25 #include "thread.h"
26 #include "linklist.h"
27 #include "vty.h"
28 #include "command.h"
29
30 #include "ospf6_proto.h"
31 #include "ospf6_lsa.h"
32 #include "ospf6_lsdb.h"
33 #include "ospf6_message.h"
34 #include "ospf6_top.h"
35 #include "ospf6_area.h"
36 #include "ospf6_interface.h"
37 #include "ospf6_neighbor.h"
38 #include "ospf6_intra.h"
39 #include "ospf6_flood.h"
40 #include "ospf6d.h"
41 #include "ospf6_bfd.h"
42 #include "ospf6_abr.h"
43 #include "ospf6_asbr.h"
44 #include "ospf6_lsa.h"
45 #include "ospf6_spf.h"
46 #include "ospf6_zebra.h"
47
48 DEFINE_HOOK(ospf6_neighbor_change,
49 (struct ospf6_neighbor * on, int state, int next_state),
50 (on, state, next_state))
51
52 unsigned char conf_debug_ospf6_neighbor = 0;
53
54 const char *ospf6_neighbor_state_str[] = {
55 "None", "Down", "Attempt", "Init", "Twoway",
56 "ExStart", "ExChange", "Loading", "Full", NULL};
57
58 int ospf6_neighbor_cmp(void *va, void *vb)
59 {
60 struct ospf6_neighbor *ona = (struct ospf6_neighbor *)va;
61 struct ospf6_neighbor *onb = (struct ospf6_neighbor *)vb;
62
63 if (ona->router_id == onb->router_id)
64 return 0;
65
66 return (ntohl(ona->router_id) < ntohl(onb->router_id)) ? -1 : 1;
67 }
68
69 struct ospf6_neighbor *ospf6_neighbor_lookup(uint32_t router_id,
70 struct ospf6_interface *oi)
71 {
72 struct listnode *n;
73 struct ospf6_neighbor *on;
74
75 for (ALL_LIST_ELEMENTS_RO(oi->neighbor_list, n, on))
76 if (on->router_id == router_id)
77 return on;
78
79 return (struct ospf6_neighbor *)NULL;
80 }
81
82 /* create ospf6_neighbor */
83 struct ospf6_neighbor *ospf6_neighbor_create(uint32_t router_id,
84 struct ospf6_interface *oi)
85 {
86 struct ospf6_neighbor *on;
87 char buf[16];
88
89 on = XCALLOC(MTYPE_OSPF6_NEIGHBOR, sizeof(struct ospf6_neighbor));
90 inet_ntop(AF_INET, &router_id, buf, sizeof(buf));
91 snprintf(on->name, sizeof(on->name), "%s%%%s", buf,
92 oi->interface->name);
93 on->ospf6_if = oi;
94 on->state = OSPF6_NEIGHBOR_DOWN;
95 on->state_change = 0;
96 monotime(&on->last_changed);
97 on->router_id = router_id;
98
99 on->summary_list = ospf6_lsdb_create(on);
100 on->request_list = ospf6_lsdb_create(on);
101 on->retrans_list = ospf6_lsdb_create(on);
102
103 on->dbdesc_list = ospf6_lsdb_create(on);
104 on->lsupdate_list = ospf6_lsdb_create(on);
105 on->lsack_list = ospf6_lsdb_create(on);
106
107 listnode_add_sort(oi->neighbor_list, on);
108
109 ospf6_bfd_info_nbr_create(oi, on);
110 return on;
111 }
112
113 void ospf6_neighbor_delete(struct ospf6_neighbor *on)
114 {
115 struct ospf6_lsa *lsa, *lsa_next;
116 const struct route_node *iterend;
117
118 ospf6_lsdb_remove_all(on->summary_list);
119 ospf6_lsdb_remove_all(on->request_list);
120
121 for (iterend = ospf6_lsdb_head(on->retrans_list, 0, 0, 0, &lsa); lsa;
122 lsa = lsa_next) {
123 lsa_next = ospf6_lsdb_next(iterend, lsa);
124 ospf6_decrement_retrans_count(lsa);
125 ospf6_lsdb_remove(lsa, on->retrans_list);
126 }
127
128 ospf6_lsdb_remove_all(on->dbdesc_list);
129 ospf6_lsdb_remove_all(on->lsupdate_list);
130 ospf6_lsdb_remove_all(on->lsack_list);
131
132 ospf6_lsdb_delete(on->summary_list);
133 ospf6_lsdb_delete(on->request_list);
134 ospf6_lsdb_delete(on->retrans_list);
135
136 ospf6_lsdb_delete(on->dbdesc_list);
137 ospf6_lsdb_delete(on->lsupdate_list);
138 ospf6_lsdb_delete(on->lsack_list);
139
140 THREAD_OFF(on->inactivity_timer);
141
142 THREAD_OFF(on->thread_send_dbdesc);
143 THREAD_OFF(on->thread_send_lsreq);
144 THREAD_OFF(on->thread_send_lsupdate);
145 THREAD_OFF(on->thread_send_lsack);
146
147 ospf6_bfd_reg_dereg_nbr(on, ZEBRA_BFD_DEST_DEREGISTER);
148 XFREE(MTYPE_OSPF6_NEIGHBOR, on);
149 }
150
151 static void ospf6_neighbor_state_change(uint8_t next_state,
152 struct ospf6_neighbor *on, int event)
153 {
154 uint8_t prev_state;
155
156 prev_state = on->state;
157 on->state = next_state;
158
159 if (prev_state == next_state)
160 return;
161
162 on->state_change++;
163 monotime(&on->last_changed);
164
165 /* log */
166 if (IS_OSPF6_DEBUG_NEIGHBOR(STATE)) {
167 zlog_debug("Neighbor state change %s: [%s]->[%s] (%s)",
168 on->name, ospf6_neighbor_state_str[prev_state],
169 ospf6_neighbor_state_str[next_state],
170 ospf6_neighbor_event_string(event));
171 }
172
173 /* Optionally notify about adjacency changes */
174 if (CHECK_FLAG(on->ospf6_if->area->ospf6->config_flags,
175 OSPF6_LOG_ADJACENCY_CHANGES)
176 && (CHECK_FLAG(on->ospf6_if->area->ospf6->config_flags,
177 OSPF6_LOG_ADJACENCY_DETAIL)
178 || (next_state == OSPF6_NEIGHBOR_FULL)
179 || (next_state < prev_state)))
180 zlog_notice("AdjChg: Nbr %s: %s -> %s (%s)", on->name,
181 ospf6_neighbor_state_str[prev_state],
182 ospf6_neighbor_state_str[next_state],
183 ospf6_neighbor_event_string(event));
184
185 if (prev_state == OSPF6_NEIGHBOR_FULL
186 || next_state == OSPF6_NEIGHBOR_FULL) {
187 OSPF6_ROUTER_LSA_SCHEDULE(on->ospf6_if->area);
188 if (on->ospf6_if->state == OSPF6_INTERFACE_DR) {
189 OSPF6_NETWORK_LSA_SCHEDULE(on->ospf6_if);
190 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(on->ospf6_if);
191 }
192 if (next_state == OSPF6_NEIGHBOR_FULL)
193 on->ospf6_if->area->intra_prefix_originate = 1;
194
195 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(on->ospf6_if->area);
196
197 if ((prev_state == OSPF6_NEIGHBOR_LOADING ||
198 prev_state == OSPF6_NEIGHBOR_EXCHANGE) &&
199 next_state == OSPF6_NEIGHBOR_FULL) {
200 OSPF6_AS_EXTERN_LSA_SCHEDULE(on->ospf6_if);
201 on->ospf6_if->area->full_nbrs++;
202 }
203
204 if (prev_state == OSPF6_NEIGHBOR_FULL)
205 on->ospf6_if->area->full_nbrs--;
206 }
207
208 if ((prev_state == OSPF6_NEIGHBOR_EXCHANGE
209 || prev_state == OSPF6_NEIGHBOR_LOADING)
210 && (next_state != OSPF6_NEIGHBOR_EXCHANGE
211 && next_state != OSPF6_NEIGHBOR_LOADING))
212 ospf6_maxage_remove(on->ospf6_if->area->ospf6);
213
214 hook_call(ospf6_neighbor_change, on, next_state, prev_state);
215 ospf6_bfd_trigger_event(on, prev_state, next_state);
216 }
217
218 /* RFC2328 section 10.4 */
219 static int need_adjacency(struct ospf6_neighbor *on)
220 {
221 if (on->ospf6_if->state == OSPF6_INTERFACE_POINTTOPOINT
222 || on->ospf6_if->state == OSPF6_INTERFACE_DR
223 || on->ospf6_if->state == OSPF6_INTERFACE_BDR)
224 return 1;
225
226 if (on->ospf6_if->drouter == on->router_id
227 || on->ospf6_if->bdrouter == on->router_id)
228 return 1;
229
230 return 0;
231 }
232
233 int hello_received(struct thread *thread)
234 {
235 struct ospf6_neighbor *on;
236
237 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
238 assert(on);
239
240 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
241 zlog_debug("Neighbor Event %s: *HelloReceived*", on->name);
242
243 /* reset Inactivity Timer */
244 THREAD_OFF(on->inactivity_timer);
245 on->inactivity_timer = NULL;
246 thread_add_timer(master, inactivity_timer, on,
247 on->ospf6_if->dead_interval, &on->inactivity_timer);
248
249 if (on->state <= OSPF6_NEIGHBOR_DOWN)
250 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_INIT, on,
251 OSPF6_NEIGHBOR_EVENT_HELLO_RCVD);
252
253 return 0;
254 }
255
256 int twoway_received(struct thread *thread)
257 {
258 struct ospf6_neighbor *on;
259
260 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
261 assert(on);
262
263 if (on->state > OSPF6_NEIGHBOR_INIT)
264 return 0;
265
266 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
267 zlog_debug("Neighbor Event %s: *2Way-Received*", on->name);
268
269 thread_add_event(master, neighbor_change, on->ospf6_if, 0, NULL);
270
271 if (!need_adjacency(on)) {
272 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_TWOWAY, on,
273 OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD);
274 return 0;
275 }
276
277 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART, on,
278 OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD);
279 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
280 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT);
281 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT);
282
283 THREAD_OFF(on->thread_send_dbdesc);
284 on->thread_send_dbdesc = NULL;
285 thread_add_event(master, ospf6_dbdesc_send, on, 0,
286 &on->thread_send_dbdesc);
287
288 return 0;
289 }
290
291 int negotiation_done(struct thread *thread)
292 {
293 struct ospf6_neighbor *on;
294 struct ospf6_lsa *lsa, *lsa_next;
295 const struct route_node *iterend;
296
297 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
298 assert(on);
299
300 if (on->state != OSPF6_NEIGHBOR_EXSTART)
301 return 0;
302
303 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
304 zlog_debug("Neighbor Event %s: *NegotiationDone*", on->name);
305
306 /* clear ls-list */
307 ospf6_lsdb_remove_all(on->summary_list);
308 ospf6_lsdb_remove_all(on->request_list);
309
310 for (iterend = ospf6_lsdb_head(on->retrans_list, 0, 0, 0, &lsa); lsa;
311 lsa = lsa_next) {
312 lsa_next = ospf6_lsdb_next(iterend, lsa);
313 ospf6_decrement_retrans_count(lsa);
314 ospf6_lsdb_remove(lsa, on->retrans_list);
315 }
316
317 /* Interface scoped LSAs */
318 for (ALL_LSDB(on->ospf6_if->lsdb, lsa)) {
319 if (OSPF6_LSA_IS_MAXAGE(lsa)) {
320 ospf6_increment_retrans_count(lsa);
321 ospf6_lsdb_add(ospf6_lsa_copy(lsa), on->retrans_list);
322 } else
323 ospf6_lsdb_add(ospf6_lsa_copy(lsa), on->summary_list);
324 }
325
326 /* Area scoped LSAs */
327 for (ALL_LSDB(on->ospf6_if->area->lsdb, lsa)) {
328 if (OSPF6_LSA_IS_MAXAGE(lsa)) {
329 ospf6_increment_retrans_count(lsa);
330 ospf6_lsdb_add(ospf6_lsa_copy(lsa), on->retrans_list);
331 } else
332 ospf6_lsdb_add(ospf6_lsa_copy(lsa), on->summary_list);
333 }
334
335 /* AS scoped LSAs */
336 for (ALL_LSDB(on->ospf6_if->area->ospf6->lsdb, lsa)) {
337 if (OSPF6_LSA_IS_MAXAGE(lsa)) {
338 ospf6_increment_retrans_count(lsa);
339 ospf6_lsdb_add(ospf6_lsa_copy(lsa), on->retrans_list);
340 } else
341 ospf6_lsdb_add(ospf6_lsa_copy(lsa), on->summary_list);
342 }
343
344 UNSET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT);
345 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXCHANGE, on,
346 OSPF6_NEIGHBOR_EVENT_NEGOTIATION_DONE);
347
348 return 0;
349 }
350
351 int exchange_done(struct thread *thread)
352 {
353 struct ospf6_neighbor *on;
354
355 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
356 assert(on);
357
358 if (on->state != OSPF6_NEIGHBOR_EXCHANGE)
359 return 0;
360
361 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
362 zlog_debug("Neighbor Event %s: *ExchangeDone*", on->name);
363
364 THREAD_OFF(on->thread_send_dbdesc);
365 ospf6_lsdb_remove_all(on->dbdesc_list);
366
367 /* XXX
368 thread_add_timer (master, ospf6_neighbor_last_dbdesc_release, on,
369 on->ospf6_if->dead_interval);
370 */
371
372 if (on->request_list->count == 0)
373 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_FULL, on,
374 OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE);
375 else {
376 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_LOADING, on,
377 OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE);
378
379 thread_add_event(master, ospf6_lsreq_send, on, 0,
380 &on->thread_send_lsreq);
381 }
382
383 return 0;
384 }
385
386 /* Check loading state. */
387 void ospf6_check_nbr_loading(struct ospf6_neighbor *on)
388 {
389
390 /* RFC2328 Section 10.9: When the neighbor responds to these requests
391 with the proper Link State Update packet(s), the Link state request
392 list is truncated and a new Link State Request packet is sent.
393 */
394 if ((on->state == OSPF6_NEIGHBOR_LOADING)
395 || (on->state == OSPF6_NEIGHBOR_EXCHANGE)) {
396 if (on->request_list->count == 0)
397 thread_add_event(master, loading_done, on, 0, NULL);
398 else if (on->last_ls_req == NULL) {
399 if (on->thread_send_lsreq != NULL)
400 THREAD_OFF(on->thread_send_lsreq);
401 on->thread_send_lsreq = NULL;
402 thread_add_event(master, ospf6_lsreq_send, on, 0,
403 &on->thread_send_lsreq);
404 }
405 }
406 }
407
408 int loading_done(struct thread *thread)
409 {
410 struct ospf6_neighbor *on;
411
412 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
413 assert(on);
414
415 if (on->state != OSPF6_NEIGHBOR_LOADING)
416 return 0;
417
418 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
419 zlog_debug("Neighbor Event %s: *LoadingDone*", on->name);
420
421 assert(on->request_list->count == 0);
422
423 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_FULL, on,
424 OSPF6_NEIGHBOR_EVENT_LOADING_DONE);
425
426 return 0;
427 }
428
429 int adj_ok(struct thread *thread)
430 {
431 struct ospf6_neighbor *on;
432 struct ospf6_lsa *lsa;
433
434 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
435 assert(on);
436
437 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
438 zlog_debug("Neighbor Event %s: *AdjOK?*", on->name);
439
440 if (on->state == OSPF6_NEIGHBOR_TWOWAY && need_adjacency(on)) {
441 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART, on,
442 OSPF6_NEIGHBOR_EVENT_ADJ_OK);
443 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
444 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT);
445 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT);
446
447 THREAD_OFF(on->thread_send_dbdesc);
448 on->thread_send_dbdesc = NULL;
449 thread_add_event(master, ospf6_dbdesc_send, on, 0,
450 &on->thread_send_dbdesc);
451
452 } else if (on->state >= OSPF6_NEIGHBOR_EXSTART && !need_adjacency(on)) {
453 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_TWOWAY, on,
454 OSPF6_NEIGHBOR_EVENT_ADJ_OK);
455 ospf6_lsdb_remove_all(on->summary_list);
456 ospf6_lsdb_remove_all(on->request_list);
457 for (ALL_LSDB(on->retrans_list, lsa)) {
458 ospf6_decrement_retrans_count(lsa);
459 ospf6_lsdb_remove(lsa, on->retrans_list);
460 }
461 }
462
463 return 0;
464 }
465
466 int seqnumber_mismatch(struct thread *thread)
467 {
468 struct ospf6_neighbor *on;
469 struct ospf6_lsa *lsa;
470
471 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
472 assert(on);
473
474 if (on->state < OSPF6_NEIGHBOR_EXCHANGE)
475 return 0;
476
477 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
478 zlog_debug("Neighbor Event %s: *SeqNumberMismatch*", on->name);
479
480 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART, on,
481 OSPF6_NEIGHBOR_EVENT_SEQNUMBER_MISMATCH);
482 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
483 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT);
484 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT);
485
486 ospf6_lsdb_remove_all(on->summary_list);
487 ospf6_lsdb_remove_all(on->request_list);
488 for (ALL_LSDB(on->retrans_list, lsa)) {
489 ospf6_decrement_retrans_count(lsa);
490 ospf6_lsdb_remove(lsa, on->retrans_list);
491 }
492
493 THREAD_OFF(on->thread_send_dbdesc);
494 on->dbdesc_seqnum++; /* Incr seqnum as per RFC2328, sec 10.3 */
495
496 on->thread_send_dbdesc = NULL;
497 thread_add_event(master, ospf6_dbdesc_send, on, 0,
498 &on->thread_send_dbdesc);
499
500 return 0;
501 }
502
503 int bad_lsreq(struct thread *thread)
504 {
505 struct ospf6_neighbor *on;
506 struct ospf6_lsa *lsa, *lsa_next;
507 const struct route_node *iterend;
508
509 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
510 assert(on);
511
512 if (on->state < OSPF6_NEIGHBOR_EXCHANGE)
513 return 0;
514
515 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
516 zlog_debug("Neighbor Event %s: *BadLSReq*", on->name);
517
518 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART, on,
519 OSPF6_NEIGHBOR_EVENT_BAD_LSREQ);
520 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
521 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT);
522 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT);
523
524 ospf6_lsdb_remove_all(on->summary_list);
525 ospf6_lsdb_remove_all(on->request_list);
526
527 for (iterend = ospf6_lsdb_head(on->retrans_list, 0, 0, 0, &lsa); lsa;
528 lsa = lsa_next) {
529 lsa_next = ospf6_lsdb_next(iterend, lsa);
530 ospf6_decrement_retrans_count(lsa);
531 ospf6_lsdb_remove(lsa, on->retrans_list);
532 }
533
534 THREAD_OFF(on->thread_send_dbdesc);
535 on->dbdesc_seqnum++; /* Incr seqnum as per RFC2328, sec 10.3 */
536
537 on->thread_send_dbdesc = NULL;
538 thread_add_event(master, ospf6_dbdesc_send, on, 0,
539 &on->thread_send_dbdesc);
540
541 return 0;
542 }
543
544 int oneway_received(struct thread *thread)
545 {
546 struct ospf6_neighbor *on;
547 struct ospf6_lsa *lsa, *lsa_next;
548 const struct route_node *iterend;
549
550 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
551 assert(on);
552
553 if (on->state < OSPF6_NEIGHBOR_TWOWAY)
554 return 0;
555
556 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
557 zlog_debug("Neighbor Event %s: *1Way-Received*", on->name);
558
559 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_INIT, on,
560 OSPF6_NEIGHBOR_EVENT_ONEWAY_RCVD);
561 thread_add_event(master, neighbor_change, on->ospf6_if, 0, NULL);
562
563 ospf6_lsdb_remove_all(on->summary_list);
564 ospf6_lsdb_remove_all(on->request_list);
565 for (iterend = ospf6_lsdb_head(on->retrans_list, 0, 0, 0, &lsa); lsa;
566 lsa = lsa_next) {
567 lsa_next = ospf6_lsdb_next(iterend, lsa);
568 ospf6_decrement_retrans_count(lsa);
569 ospf6_lsdb_remove(lsa, on->retrans_list);
570 }
571
572 THREAD_OFF(on->thread_send_dbdesc);
573 THREAD_OFF(on->thread_send_lsreq);
574 THREAD_OFF(on->thread_send_lsupdate);
575 THREAD_OFF(on->thread_send_lsack);
576
577 return 0;
578 }
579
580 int inactivity_timer(struct thread *thread)
581 {
582 struct ospf6_neighbor *on;
583
584 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
585 assert(on);
586
587 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
588 zlog_debug("Neighbor Event %s: *InactivityTimer*", on->name);
589
590 on->inactivity_timer = NULL;
591 on->drouter = on->prev_drouter = 0;
592 on->bdrouter = on->prev_bdrouter = 0;
593
594 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_DOWN, on,
595 OSPF6_NEIGHBOR_EVENT_INACTIVITY_TIMER);
596 thread_add_event(master, neighbor_change, on->ospf6_if, 0, NULL);
597
598 listnode_delete(on->ospf6_if->neighbor_list, on);
599 ospf6_neighbor_delete(on);
600
601 return 0;
602 }
603
604
605 /* vty functions */
606 /* show neighbor structure */
607 static void ospf6_neighbor_show(struct vty *vty, struct ospf6_neighbor *on)
608 {
609 char router_id[16];
610 char duration[64];
611 struct timeval res;
612 char nstate[16];
613 char deadtime[64];
614 long h, m, s;
615
616 /* Router-ID (Name) */
617 inet_ntop(AF_INET, &on->router_id, router_id, sizeof(router_id));
618 #ifdef HAVE_GETNAMEINFO
619 {
620 }
621 #endif /*HAVE_GETNAMEINFO*/
622
623 /* Dead time */
624 h = m = s = 0;
625 if (on->inactivity_timer) {
626 s = monotime_until(&on->inactivity_timer->u.sands, NULL)
627 / 1000000LL;
628 h = s / 3600;
629 s -= h * 3600;
630 m = s / 60;
631 s -= m * 60;
632 }
633 snprintf(deadtime, sizeof(deadtime), "%02ld:%02ld:%02ld", h, m, s);
634
635 /* Neighbor State */
636 if (on->ospf6_if->type == OSPF_IFTYPE_POINTOPOINT)
637 snprintf(nstate, sizeof(nstate), "PointToPoint");
638 else {
639 if (on->router_id == on->drouter)
640 snprintf(nstate, sizeof(nstate), "DR");
641 else if (on->router_id == on->bdrouter)
642 snprintf(nstate, sizeof(nstate), "BDR");
643 else
644 snprintf(nstate, sizeof(nstate), "DROther");
645 }
646
647 /* Duration */
648 monotime_since(&on->last_changed, &res);
649 timerstring(&res, duration, sizeof(duration));
650
651 /*
652 vty_out (vty, "%-15s %3d %11s %6s/%-12s %11s %s[%s]\n",
653 "Neighbor ID", "Pri", "DeadTime", "State", "", "Duration",
654 "I/F", "State");
655 */
656
657 vty_out(vty, "%-15s %3d %11s %8s/%-12s %11s %s[%s]\n", router_id,
658 on->priority, deadtime, ospf6_neighbor_state_str[on->state],
659 nstate, duration, on->ospf6_if->interface->name,
660 ospf6_interface_state_str[on->ospf6_if->state]);
661 }
662
663 static void ospf6_neighbor_show_drchoice(struct vty *vty,
664 struct ospf6_neighbor *on)
665 {
666 char router_id[16];
667 char drouter[16], bdrouter[16];
668 char duration[64];
669 struct timeval now, res;
670
671 /*
672 vty_out (vty, "%-15s %6s/%-11s %-15s %-15s %s[%s]\n",
673 "RouterID", "State", "Duration", "DR", "BDR", "I/F",
674 "State");
675 */
676
677 inet_ntop(AF_INET, &on->router_id, router_id, sizeof(router_id));
678 inet_ntop(AF_INET, &on->drouter, drouter, sizeof(drouter));
679 inet_ntop(AF_INET, &on->bdrouter, bdrouter, sizeof(bdrouter));
680
681 monotime(&now);
682 timersub(&now, &on->last_changed, &res);
683 timerstring(&res, duration, sizeof(duration));
684
685 vty_out(vty, "%-15s %8s/%-11s %-15s %-15s %s[%s]\n", router_id,
686 ospf6_neighbor_state_str[on->state], duration, drouter,
687 bdrouter, on->ospf6_if->interface->name,
688 ospf6_interface_state_str[on->ospf6_if->state]);
689 }
690
691 static void ospf6_neighbor_show_detail(struct vty *vty,
692 struct ospf6_neighbor *on)
693 {
694 char drouter[16], bdrouter[16];
695 char linklocal_addr[64], duration[32];
696 struct timeval now, res;
697 struct ospf6_lsa *lsa;
698
699 inet_ntop(AF_INET6, &on->linklocal_addr, linklocal_addr,
700 sizeof(linklocal_addr));
701 inet_ntop(AF_INET, &on->drouter, drouter, sizeof(drouter));
702 inet_ntop(AF_INET, &on->bdrouter, bdrouter, sizeof(bdrouter));
703
704 monotime(&now);
705 timersub(&now, &on->last_changed, &res);
706 timerstring(&res, duration, sizeof(duration));
707
708 vty_out(vty, " Neighbor %s\n", on->name);
709 vty_out(vty, " Area %s via interface %s (ifindex %d)\n",
710 on->ospf6_if->area->name, on->ospf6_if->interface->name,
711 on->ospf6_if->interface->ifindex);
712 vty_out(vty, " His IfIndex: %d Link-local address: %s\n",
713 on->ifindex, linklocal_addr);
714 vty_out(vty, " State %s for a duration of %s\n",
715 ospf6_neighbor_state_str[on->state], duration);
716 vty_out(vty, " His choice of DR/BDR %s/%s, Priority %d\n", drouter,
717 bdrouter, on->priority);
718 vty_out(vty, " DbDesc status: %s%s%s SeqNum: %#lx\n",
719 (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT) ? "Initial "
720 : ""),
721 (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT) ? "More " : ""),
722 (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT) ? "Master"
723 : "Slave"),
724 (unsigned long)ntohl(on->dbdesc_seqnum));
725
726 vty_out(vty, " Summary-List: %d LSAs\n", on->summary_list->count);
727 for (ALL_LSDB(on->summary_list, lsa))
728 vty_out(vty, " %s\n", lsa->name);
729
730 vty_out(vty, " Request-List: %d LSAs\n", on->request_list->count);
731 for (ALL_LSDB(on->request_list, lsa))
732 vty_out(vty, " %s\n", lsa->name);
733
734 vty_out(vty, " Retrans-List: %d LSAs\n", on->retrans_list->count);
735 for (ALL_LSDB(on->retrans_list, lsa))
736 vty_out(vty, " %s\n", lsa->name);
737
738 timerclear(&res);
739 if (on->thread_send_dbdesc)
740 timersub(&on->thread_send_dbdesc->u.sands, &now, &res);
741 timerstring(&res, duration, sizeof(duration));
742 vty_out(vty, " %d Pending LSAs for DbDesc in Time %s [thread %s]\n",
743 on->dbdesc_list->count, duration,
744 (on->thread_send_dbdesc ? "on" : "off"));
745 for (ALL_LSDB(on->dbdesc_list, lsa))
746 vty_out(vty, " %s\n", lsa->name);
747
748 timerclear(&res);
749 if (on->thread_send_lsreq)
750 timersub(&on->thread_send_lsreq->u.sands, &now, &res);
751 timerstring(&res, duration, sizeof(duration));
752 vty_out(vty, " %d Pending LSAs for LSReq in Time %s [thread %s]\n",
753 on->request_list->count, duration,
754 (on->thread_send_lsreq ? "on" : "off"));
755 for (ALL_LSDB(on->request_list, lsa))
756 vty_out(vty, " %s\n", lsa->name);
757
758 timerclear(&res);
759 if (on->thread_send_lsupdate)
760 timersub(&on->thread_send_lsupdate->u.sands, &now, &res);
761 timerstring(&res, duration, sizeof(duration));
762 vty_out(vty,
763 " %d Pending LSAs for LSUpdate in Time %s [thread %s]\n",
764 on->lsupdate_list->count, duration,
765 (on->thread_send_lsupdate ? "on" : "off"));
766 for (ALL_LSDB(on->lsupdate_list, lsa))
767 vty_out(vty, " %s\n", lsa->name);
768
769 timerclear(&res);
770 if (on->thread_send_lsack)
771 timersub(&on->thread_send_lsack->u.sands, &now, &res);
772 timerstring(&res, duration, sizeof(duration));
773 vty_out(vty, " %d Pending LSAs for LSAck in Time %s [thread %s]\n",
774 on->lsack_list->count, duration,
775 (on->thread_send_lsack ? "on" : "off"));
776 for (ALL_LSDB(on->lsack_list, lsa))
777 vty_out(vty, " %s\n", lsa->name);
778
779 ospf6_bfd_show_info(vty, on->bfd_info, 0);
780 }
781
782 DEFUN (show_ipv6_ospf6_neighbor,
783 show_ipv6_ospf6_neighbor_cmd,
784 "show ipv6 ospf6 neighbor [<detail|drchoice>]",
785 SHOW_STR
786 IP6_STR
787 OSPF6_STR
788 "Neighbor list\n"
789 "Display details\n"
790 "Display DR choices\n")
791 {
792 int idx_type = 4;
793 struct ospf6_neighbor *on;
794 struct ospf6_interface *oi;
795 struct ospf6_area *oa;
796 struct listnode *i, *j, *k;
797 void (*showfunc)(struct vty *, struct ospf6_neighbor *);
798
799 OSPF6_CMD_CHECK_RUNNING();
800 showfunc = ospf6_neighbor_show;
801
802 if (argc == 5) {
803 if (!strncmp(argv[idx_type]->arg, "de", 2))
804 showfunc = ospf6_neighbor_show_detail;
805 else if (!strncmp(argv[idx_type]->arg, "dr", 2))
806 showfunc = ospf6_neighbor_show_drchoice;
807 }
808
809 if (showfunc == ospf6_neighbor_show)
810 vty_out(vty, "%-15s %3s %11s %8s/%-12s %11s %s[%s]\n",
811 "Neighbor ID", "Pri", "DeadTime", "State", "IfState",
812 "Duration", "I/F", "State");
813 else if (showfunc == ospf6_neighbor_show_drchoice)
814 vty_out(vty, "%-15s %8s/%-11s %-15s %-15s %s[%s]\n", "RouterID",
815 "State", "Duration", "DR", "BDR", "I/F", "State");
816
817 for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa))
818 for (ALL_LIST_ELEMENTS_RO(oa->if_list, j, oi))
819 for (ALL_LIST_ELEMENTS_RO(oi->neighbor_list, k, on))
820 (*showfunc)(vty, on);
821
822 return CMD_SUCCESS;
823 }
824
825
826 DEFUN (show_ipv6_ospf6_neighbor_one,
827 show_ipv6_ospf6_neighbor_one_cmd,
828 "show ipv6 ospf6 neighbor A.B.C.D",
829 SHOW_STR
830 IP6_STR
831 OSPF6_STR
832 "Neighbor list\n"
833 "Specify Router-ID as IPv4 address notation\n"
834 )
835 {
836 int idx_ipv4 = 4;
837 struct ospf6_neighbor *on;
838 struct ospf6_interface *oi;
839 struct ospf6_area *oa;
840 struct listnode *i, *j, *k;
841 void (*showfunc)(struct vty *, struct ospf6_neighbor *);
842 uint32_t router_id;
843
844 OSPF6_CMD_CHECK_RUNNING();
845 showfunc = ospf6_neighbor_show_detail;
846
847 if ((inet_pton(AF_INET, argv[idx_ipv4]->arg, &router_id)) != 1) {
848 vty_out(vty, "Router-ID is not parsable: %s\n",
849 argv[idx_ipv4]->arg);
850 return CMD_SUCCESS;
851 }
852
853 for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa))
854 for (ALL_LIST_ELEMENTS_RO(oa->if_list, j, oi))
855 for (ALL_LIST_ELEMENTS_RO(oi->neighbor_list, k, on))
856 (*showfunc)(vty, on);
857
858 return CMD_SUCCESS;
859 }
860
861 void ospf6_neighbor_init(void)
862 {
863 install_element(VIEW_NODE, &show_ipv6_ospf6_neighbor_cmd);
864 install_element(VIEW_NODE, &show_ipv6_ospf6_neighbor_one_cmd);
865 }
866
867 DEFUN (debug_ospf6_neighbor,
868 debug_ospf6_neighbor_cmd,
869 "debug ospf6 neighbor [<state|event>]",
870 DEBUG_STR
871 OSPF6_STR
872 "Debug OSPFv3 Neighbor\n"
873 "Debug OSPFv3 Neighbor State Change\n"
874 "Debug OSPFv3 Neighbor Event\n")
875 {
876 int idx_type = 3;
877 unsigned char level = 0;
878
879 if (argc == 4) {
880 if (!strncmp(argv[idx_type]->arg, "s", 1))
881 level = OSPF6_DEBUG_NEIGHBOR_STATE;
882 else if (!strncmp(argv[idx_type]->arg, "e", 1))
883 level = OSPF6_DEBUG_NEIGHBOR_EVENT;
884 } else
885 level = OSPF6_DEBUG_NEIGHBOR_STATE | OSPF6_DEBUG_NEIGHBOR_EVENT;
886
887 OSPF6_DEBUG_NEIGHBOR_ON(level);
888 return CMD_SUCCESS;
889 }
890
891
892 DEFUN (no_debug_ospf6_neighbor,
893 no_debug_ospf6_neighbor_cmd,
894 "no debug ospf6 neighbor [<state|event>]",
895 NO_STR
896 DEBUG_STR
897 OSPF6_STR
898 "Debug OSPFv3 Neighbor\n"
899 "Debug OSPFv3 Neighbor State Change\n"
900 "Debug OSPFv3 Neighbor Event\n")
901 {
902 int idx_type = 4;
903 unsigned char level = 0;
904
905 if (argc == 5) {
906 if (!strncmp(argv[idx_type]->arg, "s", 1))
907 level = OSPF6_DEBUG_NEIGHBOR_STATE;
908 if (!strncmp(argv[idx_type]->arg, "e", 1))
909 level = OSPF6_DEBUG_NEIGHBOR_EVENT;
910 } else
911 level = OSPF6_DEBUG_NEIGHBOR_STATE | OSPF6_DEBUG_NEIGHBOR_EVENT;
912
913 OSPF6_DEBUG_NEIGHBOR_OFF(level);
914 return CMD_SUCCESS;
915 }
916
917
918 DEFUN (no_debug_ospf6,
919 no_debug_ospf6_cmd,
920 "no debug ospf6",
921 NO_STR
922 DEBUG_STR
923 OSPF6_STR)
924 {
925 unsigned int i;
926 struct ospf6_lsa_handler *handler = NULL;
927
928 OSPF6_DEBUG_ABR_OFF();
929 OSPF6_DEBUG_ASBR_OFF();
930 OSPF6_DEBUG_BROUTER_OFF();
931 OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_OFF();
932 OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_OFF();
933 OSPF6_DEBUG_FLOODING_OFF();
934 OSPF6_DEBUG_INTERFACE_OFF();
935
936 for (i = 0; i < vector_active(ospf6_lsa_handler_vector); i++) {
937 handler = vector_slot(ospf6_lsa_handler_vector, i);
938
939 if (handler != NULL) {
940 UNSET_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG);
941 }
942 }
943
944 for (i = 0; i < 6; i++)
945 OSPF6_DEBUG_MESSAGE_OFF(i,
946 OSPF6_DEBUG_NEIGHBOR_STATE
947 | OSPF6_DEBUG_NEIGHBOR_EVENT);
948
949 OSPF6_DEBUG_NEIGHBOR_OFF(OSPF6_DEBUG_NEIGHBOR_STATE
950 | OSPF6_DEBUG_NEIGHBOR_EVENT);
951 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_TABLE);
952 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_INTRA);
953 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_INTER);
954 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_MEMORY);
955 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_PROCESS);
956 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_TIME);
957 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_DATABASE);
958 OSPF6_DEBUG_ZEBRA_OFF(OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV);
959
960 return CMD_SUCCESS;
961 }
962
963 int config_write_ospf6_debug_neighbor(struct vty *vty)
964 {
965 if (IS_OSPF6_DEBUG_NEIGHBOR(STATE) && IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
966 vty_out(vty, "debug ospf6 neighbor\n");
967 else if (IS_OSPF6_DEBUG_NEIGHBOR(STATE))
968 vty_out(vty, "debug ospf6 neighbor state\n");
969 else if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
970 vty_out(vty, "debug ospf6 neighbor event\n");
971 return 0;
972 }
973
974 void install_element_ospf6_debug_neighbor(void)
975 {
976 install_element(ENABLE_NODE, &debug_ospf6_neighbor_cmd);
977 install_element(ENABLE_NODE, &no_debug_ospf6_neighbor_cmd);
978 install_element(ENABLE_NODE, &no_debug_ospf6_cmd);
979 install_element(CONFIG_NODE, &debug_ospf6_neighbor_cmd);
980 install_element(CONFIG_NODE, &no_debug_ospf6_neighbor_cmd);
981 install_element(CONFIG_NODE, &no_debug_ospf6_cmd);
982 }