]> git.proxmox.com Git - mirror_frr.git/blob - ospf6d/ospf6_neighbor.c
Merge pull request #9750 from mjstapp/zebra_installed_nhg_id
[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 #include "lib/bfd.h"
30
31 #include "ospf6_proto.h"
32 #include "ospf6_lsa.h"
33 #include "ospf6_lsdb.h"
34 #include "ospf6_message.h"
35 #include "ospf6_top.h"
36 #include "ospf6_area.h"
37 #include "ospf6_interface.h"
38 #include "ospf6_neighbor.h"
39 #include "ospf6_intra.h"
40 #include "ospf6_flood.h"
41 #include "ospf6d.h"
42 #include "ospf6_bfd.h"
43 #include "ospf6_abr.h"
44 #include "ospf6_asbr.h"
45 #include "ospf6_lsa.h"
46 #include "ospf6_spf.h"
47 #include "ospf6_zebra.h"
48 #include "ospf6_gr.h"
49 #include "lib/json.h"
50
51 DEFINE_MTYPE_STATIC(OSPF6D, OSPF6_NEIGHBOR, "OSPF6 neighbor");
52
53 DEFINE_HOOK(ospf6_neighbor_change,
54 (struct ospf6_neighbor * on, int state, int next_state),
55 (on, state, next_state));
56
57 unsigned char conf_debug_ospf6_neighbor = 0;
58
59 const char *const ospf6_neighbor_state_str[] = {
60 "None", "Down", "Attempt", "Init", "Twoway",
61 "ExStart", "ExChange", "Loading", "Full", NULL};
62
63 const char *const ospf6_neighbor_event_str[] = {
64 "NoEvent", "HelloReceived", "2-WayReceived", "NegotiationDone",
65 "ExchangeDone", "LoadingDone", "AdjOK?", "SeqNumberMismatch",
66 "BadLSReq", "1-WayReceived", "InactivityTimer",
67 };
68
69 int ospf6_neighbor_cmp(void *va, void *vb)
70 {
71 struct ospf6_neighbor *ona = (struct ospf6_neighbor *)va;
72 struct ospf6_neighbor *onb = (struct ospf6_neighbor *)vb;
73
74 if (ona->router_id == onb->router_id)
75 return 0;
76
77 return (ntohl(ona->router_id) < ntohl(onb->router_id)) ? -1 : 1;
78 }
79
80 struct ospf6_neighbor *ospf6_neighbor_lookup(uint32_t router_id,
81 struct ospf6_interface *oi)
82 {
83 struct listnode *n;
84 struct ospf6_neighbor *on;
85
86 for (ALL_LIST_ELEMENTS_RO(oi->neighbor_list, n, on))
87 if (on->router_id == router_id)
88 return on;
89
90 return (struct ospf6_neighbor *)NULL;
91 }
92
93 struct ospf6_neighbor *ospf6_area_neighbor_lookup(struct ospf6_area *area,
94 uint32_t router_id)
95 {
96 struct ospf6_interface *oi;
97 struct ospf6_neighbor *nbr;
98 struct listnode *node;
99
100 for (ALL_LIST_ELEMENTS_RO(area->if_list, node, oi)) {
101 nbr = ospf6_neighbor_lookup(router_id, oi);
102 if (nbr)
103 return nbr;
104 }
105
106 return NULL;
107 }
108
109 /* create ospf6_neighbor */
110 struct ospf6_neighbor *ospf6_neighbor_create(uint32_t router_id,
111 struct ospf6_interface *oi)
112 {
113 struct ospf6_neighbor *on;
114 char buf[16];
115
116 on = XCALLOC(MTYPE_OSPF6_NEIGHBOR, sizeof(struct ospf6_neighbor));
117 inet_ntop(AF_INET, &router_id, buf, sizeof(buf));
118 snprintf(on->name, sizeof(on->name), "%s%%%s", buf,
119 oi->interface->name);
120 on->ospf6_if = oi;
121 on->state = OSPF6_NEIGHBOR_DOWN;
122 on->state_change = 0;
123 monotime(&on->last_changed);
124 on->router_id = router_id;
125
126 on->summary_list = ospf6_lsdb_create(on);
127 on->request_list = ospf6_lsdb_create(on);
128 on->retrans_list = ospf6_lsdb_create(on);
129
130 on->dbdesc_list = ospf6_lsdb_create(on);
131 on->lsupdate_list = ospf6_lsdb_create(on);
132 on->lsack_list = ospf6_lsdb_create(on);
133
134 listnode_add_sort(oi->neighbor_list, on);
135
136 ospf6_bfd_info_nbr_create(oi, on);
137 return on;
138 }
139
140 void ospf6_neighbor_delete(struct ospf6_neighbor *on)
141 {
142 struct ospf6_lsa *lsa, *lsanext;
143
144 ospf6_lsdb_remove_all(on->summary_list);
145 ospf6_lsdb_remove_all(on->request_list);
146 for (ALL_LSDB(on->retrans_list, lsa, lsanext)) {
147 ospf6_decrement_retrans_count(lsa);
148 ospf6_lsdb_remove(lsa, on->retrans_list);
149 }
150
151 ospf6_lsdb_remove_all(on->dbdesc_list);
152 ospf6_lsdb_remove_all(on->lsupdate_list);
153 ospf6_lsdb_remove_all(on->lsack_list);
154
155 ospf6_lsdb_delete(on->summary_list);
156 ospf6_lsdb_delete(on->request_list);
157 ospf6_lsdb_delete(on->retrans_list);
158
159 ospf6_lsdb_delete(on->dbdesc_list);
160 ospf6_lsdb_delete(on->lsupdate_list);
161 ospf6_lsdb_delete(on->lsack_list);
162
163 THREAD_OFF(on->inactivity_timer);
164
165 THREAD_OFF(on->last_dbdesc_release_timer);
166
167 THREAD_OFF(on->thread_send_dbdesc);
168 THREAD_OFF(on->thread_send_lsreq);
169 THREAD_OFF(on->thread_send_lsupdate);
170 THREAD_OFF(on->thread_send_lsack);
171 THREAD_OFF(on->thread_exchange_done);
172 THREAD_OFF(on->thread_adj_ok);
173
174 THREAD_OFF(on->gr_helper_info.t_grace_timer);
175
176 bfd_sess_free(&on->bfd_session);
177 XFREE(MTYPE_OSPF6_NEIGHBOR, on);
178 }
179
180 static void ospf6_neighbor_state_change(uint8_t next_state,
181 struct ospf6_neighbor *on, int event)
182 {
183 uint8_t prev_state;
184
185 prev_state = on->state;
186 on->state = next_state;
187
188 if (prev_state == next_state)
189 return;
190
191 on->state_change++;
192 monotime(&on->last_changed);
193
194 /* log */
195 if (IS_OSPF6_DEBUG_NEIGHBOR(STATE)) {
196 zlog_debug("Neighbor state change %s: [%s]->[%s] (%s)",
197 on->name, ospf6_neighbor_state_str[prev_state],
198 ospf6_neighbor_state_str[next_state],
199 ospf6_neighbor_event_string(event));
200 }
201
202 /* Optionally notify about adjacency changes */
203 if (CHECK_FLAG(on->ospf6_if->area->ospf6->config_flags,
204 OSPF6_LOG_ADJACENCY_CHANGES)
205 && (CHECK_FLAG(on->ospf6_if->area->ospf6->config_flags,
206 OSPF6_LOG_ADJACENCY_DETAIL)
207 || (next_state == OSPF6_NEIGHBOR_FULL)
208 || (next_state < prev_state)))
209 zlog_notice("AdjChg: Nbr %s: %s -> %s (%s)", on->name,
210 ospf6_neighbor_state_str[prev_state],
211 ospf6_neighbor_state_str[next_state],
212 ospf6_neighbor_event_string(event));
213
214 if (prev_state == OSPF6_NEIGHBOR_FULL
215 || next_state == OSPF6_NEIGHBOR_FULL) {
216 if (!OSPF6_GR_IS_ACTIVE_HELPER(on)) {
217 OSPF6_ROUTER_LSA_SCHEDULE(on->ospf6_if->area);
218 if (on->ospf6_if->state == OSPF6_INTERFACE_DR) {
219 OSPF6_NETWORK_LSA_SCHEDULE(on->ospf6_if);
220 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(
221 on->ospf6_if);
222 }
223 }
224 if (next_state == OSPF6_NEIGHBOR_FULL)
225 on->ospf6_if->area->intra_prefix_originate = 1;
226
227 if (!OSPF6_GR_IS_ACTIVE_HELPER(on))
228 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(
229 on->ospf6_if->area);
230
231 if ((prev_state == OSPF6_NEIGHBOR_LOADING
232 || prev_state == OSPF6_NEIGHBOR_EXCHANGE)
233 && next_state == OSPF6_NEIGHBOR_FULL) {
234 OSPF6_AS_EXTERN_LSA_SCHEDULE(on->ospf6_if);
235 on->ospf6_if->area->full_nbrs++;
236 }
237
238 if (prev_state == OSPF6_NEIGHBOR_FULL)
239 on->ospf6_if->area->full_nbrs--;
240 }
241
242 if ((prev_state == OSPF6_NEIGHBOR_EXCHANGE
243 || prev_state == OSPF6_NEIGHBOR_LOADING)
244 && (next_state != OSPF6_NEIGHBOR_EXCHANGE
245 && next_state != OSPF6_NEIGHBOR_LOADING))
246 ospf6_maxage_remove(on->ospf6_if->area->ospf6);
247
248 hook_call(ospf6_neighbor_change, on, next_state, prev_state);
249 ospf6_bfd_trigger_event(on, prev_state, next_state);
250 }
251
252 /* RFC2328 section 10.4 */
253 static int need_adjacency(struct ospf6_neighbor *on)
254 {
255 if (on->ospf6_if->state == OSPF6_INTERFACE_POINTTOPOINT
256 || on->ospf6_if->state == OSPF6_INTERFACE_DR
257 || on->ospf6_if->state == OSPF6_INTERFACE_BDR)
258 return 1;
259
260 if (on->ospf6_if->drouter == on->router_id
261 || on->ospf6_if->bdrouter == on->router_id)
262 return 1;
263
264 return 0;
265 }
266
267 int hello_received(struct thread *thread)
268 {
269 struct ospf6_neighbor *on;
270
271 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
272 assert(on);
273
274 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
275 zlog_debug("Neighbor Event %s: *HelloReceived*", on->name);
276
277 /* reset Inactivity Timer */
278 THREAD_OFF(on->inactivity_timer);
279 thread_add_timer(master, inactivity_timer, on,
280 on->ospf6_if->dead_interval, &on->inactivity_timer);
281
282 if (on->state <= OSPF6_NEIGHBOR_DOWN)
283 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_INIT, on,
284 OSPF6_NEIGHBOR_EVENT_HELLO_RCVD);
285
286 return 0;
287 }
288
289 int twoway_received(struct thread *thread)
290 {
291 struct ospf6_neighbor *on;
292
293 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
294 assert(on);
295
296 if (on->state > OSPF6_NEIGHBOR_INIT)
297 return 0;
298
299 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
300 zlog_debug("Neighbor Event %s: *2Way-Received*", on->name);
301
302 thread_add_event(master, neighbor_change, on->ospf6_if, 0, NULL);
303
304 if (!need_adjacency(on)) {
305 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_TWOWAY, on,
306 OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD);
307 return 0;
308 }
309
310 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART, on,
311 OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD);
312 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
313 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT);
314 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT);
315
316 THREAD_OFF(on->thread_send_dbdesc);
317 thread_add_event(master, ospf6_dbdesc_send, on, 0,
318 &on->thread_send_dbdesc);
319
320 return 0;
321 }
322
323 int negotiation_done(struct thread *thread)
324 {
325 struct ospf6_neighbor *on;
326 struct ospf6_lsa *lsa, *lsanext;
327
328 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
329 assert(on);
330
331 if (on->state != OSPF6_NEIGHBOR_EXSTART)
332 return 0;
333
334 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
335 zlog_debug("Neighbor Event %s: *NegotiationDone*", on->name);
336
337 /* clear ls-list */
338 ospf6_lsdb_remove_all(on->summary_list);
339 ospf6_lsdb_remove_all(on->request_list);
340 for (ALL_LSDB(on->retrans_list, lsa, lsanext)) {
341 ospf6_decrement_retrans_count(lsa);
342 ospf6_lsdb_remove(lsa, on->retrans_list);
343 }
344
345 /* Interface scoped LSAs */
346 for (ALL_LSDB(on->ospf6_if->lsdb, lsa, lsanext)) {
347 if (OSPF6_LSA_IS_MAXAGE(lsa)) {
348 ospf6_increment_retrans_count(lsa);
349 ospf6_lsdb_add(ospf6_lsa_copy(lsa), on->retrans_list);
350 } else
351 ospf6_lsdb_add(ospf6_lsa_copy(lsa), on->summary_list);
352 }
353
354 /* Area scoped LSAs */
355 for (ALL_LSDB(on->ospf6_if->area->lsdb, lsa, lsanext)) {
356 if (OSPF6_LSA_IS_MAXAGE(lsa)) {
357 ospf6_increment_retrans_count(lsa);
358 ospf6_lsdb_add(ospf6_lsa_copy(lsa), on->retrans_list);
359 } else
360 ospf6_lsdb_add(ospf6_lsa_copy(lsa), on->summary_list);
361 }
362
363 /* AS scoped LSAs */
364 for (ALL_LSDB(on->ospf6_if->area->ospf6->lsdb, lsa, lsanext)) {
365 if (OSPF6_LSA_IS_MAXAGE(lsa)) {
366 ospf6_increment_retrans_count(lsa);
367 ospf6_lsdb_add(ospf6_lsa_copy(lsa), on->retrans_list);
368 } else
369 ospf6_lsdb_add(ospf6_lsa_copy(lsa), on->summary_list);
370 }
371
372 UNSET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT);
373 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXCHANGE, on,
374 OSPF6_NEIGHBOR_EVENT_NEGOTIATION_DONE);
375
376 return 0;
377 }
378
379 static int ospf6_neighbor_last_dbdesc_release(struct thread *thread)
380 {
381 struct ospf6_neighbor *on = THREAD_ARG(thread);
382
383 assert(on);
384 memset(&on->dbdesc_last, 0, sizeof(struct ospf6_dbdesc));
385
386 return 0;
387 }
388
389 int exchange_done(struct thread *thread)
390 {
391 struct ospf6_neighbor *on;
392
393 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
394 assert(on);
395
396 if (on->state != OSPF6_NEIGHBOR_EXCHANGE)
397 return 0;
398
399 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
400 zlog_debug("Neighbor Event %s: *ExchangeDone*", on->name);
401
402 THREAD_OFF(on->thread_send_dbdesc);
403 ospf6_lsdb_remove_all(on->dbdesc_list);
404
405 /* RFC 2328 (10.8): Release the last dbdesc after dead_interval */
406 if (!CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT)) {
407 THREAD_OFF(on->last_dbdesc_release_timer);
408 thread_add_timer(master, ospf6_neighbor_last_dbdesc_release, on,
409 on->ospf6_if->dead_interval,
410 &on->last_dbdesc_release_timer);
411 }
412
413 if (on->request_list->count == 0)
414 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_FULL, on,
415 OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE);
416 else {
417 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_LOADING, on,
418 OSPF6_NEIGHBOR_EVENT_EXCHANGE_DONE);
419
420 thread_add_event(master, ospf6_lsreq_send, on, 0,
421 &on->thread_send_lsreq);
422 }
423
424 return 0;
425 }
426
427 /* Check loading state. */
428 void ospf6_check_nbr_loading(struct ospf6_neighbor *on)
429 {
430
431 /* RFC2328 Section 10.9: When the neighbor responds to these requests
432 with the proper Link State Update packet(s), the Link state request
433 list is truncated and a new Link State Request packet is sent.
434 */
435 if ((on->state == OSPF6_NEIGHBOR_LOADING)
436 || (on->state == OSPF6_NEIGHBOR_EXCHANGE)) {
437 if (on->request_list->count == 0)
438 thread_add_event(master, loading_done, on, 0, NULL);
439 else if (on->last_ls_req == NULL) {
440 if (on->thread_send_lsreq != NULL)
441 THREAD_OFF(on->thread_send_lsreq);
442 thread_add_event(master, ospf6_lsreq_send, on, 0,
443 &on->thread_send_lsreq);
444 }
445 }
446 }
447
448 int loading_done(struct thread *thread)
449 {
450 struct ospf6_neighbor *on;
451
452 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
453 assert(on);
454
455 if (on->state != OSPF6_NEIGHBOR_LOADING)
456 return 0;
457
458 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
459 zlog_debug("Neighbor Event %s: *LoadingDone*", on->name);
460
461 assert(on->request_list->count == 0);
462
463 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_FULL, on,
464 OSPF6_NEIGHBOR_EVENT_LOADING_DONE);
465
466 return 0;
467 }
468
469 int adj_ok(struct thread *thread)
470 {
471 struct ospf6_neighbor *on;
472 struct ospf6_lsa *lsa, *lsanext;
473
474 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
475 assert(on);
476
477 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
478 zlog_debug("Neighbor Event %s: *AdjOK?*", on->name);
479
480 if (on->state == OSPF6_NEIGHBOR_TWOWAY && need_adjacency(on)) {
481 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART, on,
482 OSPF6_NEIGHBOR_EVENT_ADJ_OK);
483 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
484 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT);
485 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT);
486
487 THREAD_OFF(on->thread_send_dbdesc);
488 on->thread_send_dbdesc = NULL;
489 thread_add_event(master, ospf6_dbdesc_send, on, 0,
490 &on->thread_send_dbdesc);
491
492 } else if (on->state >= OSPF6_NEIGHBOR_EXSTART && !need_adjacency(on)) {
493 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_TWOWAY, on,
494 OSPF6_NEIGHBOR_EVENT_ADJ_OK);
495 ospf6_lsdb_remove_all(on->summary_list);
496 ospf6_lsdb_remove_all(on->request_list);
497 for (ALL_LSDB(on->retrans_list, lsa, lsanext)) {
498 ospf6_decrement_retrans_count(lsa);
499 ospf6_lsdb_remove(lsa, on->retrans_list);
500 }
501 }
502
503 return 0;
504 }
505
506 int seqnumber_mismatch(struct thread *thread)
507 {
508 struct ospf6_neighbor *on;
509 struct ospf6_lsa *lsa, *lsanext;
510
511 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
512 assert(on);
513
514 if (on->state < OSPF6_NEIGHBOR_EXCHANGE)
515 return 0;
516
517 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
518 zlog_debug("Neighbor Event %s: *SeqNumberMismatch*", on->name);
519
520 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART, on,
521 OSPF6_NEIGHBOR_EVENT_SEQNUMBER_MISMATCH);
522 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
523 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT);
524 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT);
525
526 ospf6_lsdb_remove_all(on->summary_list);
527 ospf6_lsdb_remove_all(on->request_list);
528 for (ALL_LSDB(on->retrans_list, lsa, lsanext)) {
529 ospf6_decrement_retrans_count(lsa);
530 ospf6_lsdb_remove(lsa, on->retrans_list);
531 }
532
533 THREAD_OFF(on->thread_send_dbdesc);
534 on->dbdesc_seqnum++; /* Incr seqnum as per RFC2328, sec 10.3 */
535
536 on->thread_send_dbdesc = NULL;
537 thread_add_event(master, ospf6_dbdesc_send, on, 0,
538 &on->thread_send_dbdesc);
539
540 return 0;
541 }
542
543 int bad_lsreq(struct thread *thread)
544 {
545 struct ospf6_neighbor *on;
546 struct ospf6_lsa *lsa, *lsanext;
547
548 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
549 assert(on);
550
551 if (on->state < OSPF6_NEIGHBOR_EXCHANGE)
552 return 0;
553
554 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
555 zlog_debug("Neighbor Event %s: *BadLSReq*", on->name);
556
557 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART, on,
558 OSPF6_NEIGHBOR_EVENT_BAD_LSREQ);
559 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
560 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT);
561 SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT);
562
563 ospf6_lsdb_remove_all(on->summary_list);
564 ospf6_lsdb_remove_all(on->request_list);
565 for (ALL_LSDB(on->retrans_list, lsa, lsanext)) {
566 ospf6_decrement_retrans_count(lsa);
567 ospf6_lsdb_remove(lsa, on->retrans_list);
568 }
569
570 THREAD_OFF(on->thread_send_dbdesc);
571 on->dbdesc_seqnum++; /* Incr seqnum as per RFC2328, sec 10.3 */
572
573 on->thread_send_dbdesc = NULL;
574 thread_add_event(master, ospf6_dbdesc_send, on, 0,
575 &on->thread_send_dbdesc);
576
577 return 0;
578 }
579
580 int oneway_received(struct thread *thread)
581 {
582 struct ospf6_neighbor *on;
583 struct ospf6_lsa *lsa, *lsanext;
584
585 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
586 assert(on);
587
588 if (on->state < OSPF6_NEIGHBOR_TWOWAY)
589 return 0;
590
591 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
592 zlog_debug("Neighbor Event %s: *1Way-Received*", on->name);
593
594 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_INIT, on,
595 OSPF6_NEIGHBOR_EVENT_ONEWAY_RCVD);
596 thread_add_event(master, neighbor_change, on->ospf6_if, 0, NULL);
597
598 ospf6_lsdb_remove_all(on->summary_list);
599 ospf6_lsdb_remove_all(on->request_list);
600 for (ALL_LSDB(on->retrans_list, lsa, lsanext)) {
601 ospf6_decrement_retrans_count(lsa);
602 ospf6_lsdb_remove(lsa, on->retrans_list);
603 }
604
605 THREAD_OFF(on->thread_send_dbdesc);
606 THREAD_OFF(on->thread_send_lsreq);
607 THREAD_OFF(on->thread_send_lsupdate);
608 THREAD_OFF(on->thread_send_lsack);
609 THREAD_OFF(on->thread_exchange_done);
610 THREAD_OFF(on->thread_adj_ok);
611
612 return 0;
613 }
614
615 int inactivity_timer(struct thread *thread)
616 {
617 struct ospf6_neighbor *on;
618
619 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
620 assert(on);
621
622 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
623 zlog_debug("Neighbor Event %s: *InactivityTimer*", on->name);
624
625 on->drouter = on->prev_drouter = 0;
626 on->bdrouter = on->prev_bdrouter = 0;
627
628 if (!OSPF6_GR_IS_ACTIVE_HELPER(on)) {
629 on->drouter = on->prev_drouter = 0;
630 on->bdrouter = on->prev_bdrouter = 0;
631
632 ospf6_neighbor_state_change(
633 OSPF6_NEIGHBOR_DOWN, on,
634 OSPF6_NEIGHBOR_EVENT_INACTIVITY_TIMER);
635 thread_add_event(master, neighbor_change, on->ospf6_if, 0,
636 NULL);
637
638 listnode_delete(on->ospf6_if->neighbor_list, on);
639 ospf6_neighbor_delete(on);
640
641 } else {
642 if (IS_DEBUG_OSPF6_GR)
643 zlog_debug(
644 "%s, Acting as HELPER for this neighbour, So restart the dead timer.",
645 __PRETTY_FUNCTION__);
646
647 thread_add_timer(master, inactivity_timer, on,
648 on->ospf6_if->dead_interval,
649 &on->inactivity_timer);
650 }
651
652 return 0;
653 }
654
655
656 /* vty functions */
657 /* show neighbor structure */
658 static void ospf6_neighbor_show(struct vty *vty, struct ospf6_neighbor *on,
659 json_object *json_array, bool use_json)
660 {
661 char router_id[16];
662 char duration[64];
663 struct timeval res;
664 char nstate[16];
665 char deadtime[64];
666 long h, m, s;
667 json_object *json_route;
668
669 /* Router-ID (Name) */
670 inet_ntop(AF_INET, &on->router_id, router_id, sizeof(router_id));
671 #ifdef HAVE_GETNAMEINFO
672 {
673 }
674 #endif /*HAVE_GETNAMEINFO*/
675
676 /* Dead time */
677 h = m = s = 0;
678 if (on->inactivity_timer) {
679 s = monotime_until(&on->inactivity_timer->u.sands, NULL)
680 / 1000000LL;
681 h = s / 3600;
682 s -= h * 3600;
683 m = s / 60;
684 s -= m * 60;
685 }
686 snprintf(deadtime, sizeof(deadtime), "%02ld:%02ld:%02ld", h, m, s);
687
688 /* Neighbor State */
689 if (on->ospf6_if->type == OSPF_IFTYPE_POINTOPOINT)
690 snprintf(nstate, sizeof(nstate), "PointToPoint");
691 else {
692 if (on->router_id == on->drouter)
693 snprintf(nstate, sizeof(nstate), "DR");
694 else if (on->router_id == on->bdrouter)
695 snprintf(nstate, sizeof(nstate), "BDR");
696 else
697 snprintf(nstate, sizeof(nstate), "DROther");
698 }
699
700 /* Duration */
701 monotime_since(&on->last_changed, &res);
702 timerstring(&res, duration, sizeof(duration));
703
704 /*
705 vty_out (vty, "%-15s %3d %11s %6s/%-12s %11s %s[%s]\n",
706 "Neighbor ID", "Pri", "DeadTime", "State", "IfState",
707 "Duration", "I/F", "State");
708 */
709 if (use_json) {
710 json_route = json_object_new_object();
711
712 json_object_string_add(json_route, "neighborId", router_id);
713 json_object_int_add(json_route, "priority", on->priority);
714 json_object_string_add(json_route, "deadTime", deadtime);
715 json_object_string_add(json_route, "state",
716 ospf6_neighbor_state_str[on->state]);
717 json_object_string_add(json_route, "ifState", nstate);
718 json_object_string_add(json_route, "duration", duration);
719 json_object_string_add(json_route, "interfaceName",
720 on->ospf6_if->interface->name);
721 json_object_string_add(
722 json_route, "interfaceState",
723 ospf6_interface_state_str[on->ospf6_if->state]);
724
725 json_object_array_add(json_array, json_route);
726 } else
727 vty_out(vty, "%-15s %3d %11s %8s/%-12s %11s %s[%s]\n",
728 router_id, on->priority, deadtime,
729 ospf6_neighbor_state_str[on->state], nstate, duration,
730 on->ospf6_if->interface->name,
731 ospf6_interface_state_str[on->ospf6_if->state]);
732 }
733
734 static void ospf6_neighbor_show_drchoice(struct vty *vty,
735 struct ospf6_neighbor *on,
736 json_object *json_array, bool use_json)
737 {
738 char router_id[16];
739 char drouter[16], bdrouter[16];
740 char duration[64];
741 struct timeval now, res;
742 json_object *json_route;
743
744 /*
745 vty_out (vty, "%-15s %6s/%-11s %-15s %-15s %s[%s]\n",
746 "RouterID", "State", "Duration", "DR", "BDR", "I/F",
747 "State");
748 */
749
750 inet_ntop(AF_INET, &on->router_id, router_id, sizeof(router_id));
751 inet_ntop(AF_INET, &on->drouter, drouter, sizeof(drouter));
752 inet_ntop(AF_INET, &on->bdrouter, bdrouter, sizeof(bdrouter));
753
754 monotime(&now);
755 timersub(&now, &on->last_changed, &res);
756 timerstring(&res, duration, sizeof(duration));
757
758 if (use_json) {
759 json_route = json_object_new_object();
760 json_object_string_add(json_route, "routerId", router_id);
761 json_object_string_add(json_route, "state",
762 ospf6_neighbor_state_str[on->state]);
763 json_object_string_add(json_route, "duration", duration);
764 json_object_string_add(json_route, "dRouter", drouter);
765 json_object_string_add(json_route, "bdRouter", bdrouter);
766 json_object_string_add(json_route, "interfaceName",
767 on->ospf6_if->interface->name);
768 json_object_string_add(
769 json_route, "interfaceState",
770 ospf6_interface_state_str[on->ospf6_if->state]);
771
772 json_object_array_add(json_array, json_route);
773 } else
774 vty_out(vty, "%-15s %8s/%-11s %-15s %-15s %s[%s]\n", router_id,
775 ospf6_neighbor_state_str[on->state], duration, drouter,
776 bdrouter, on->ospf6_if->interface->name,
777 ospf6_interface_state_str[on->ospf6_if->state]);
778 }
779
780 static void ospf6_neighbor_show_detail(struct vty *vty,
781 struct ospf6_neighbor *on,
782 json_object *json, bool use_json)
783 {
784 char drouter[16], bdrouter[16];
785 char linklocal_addr[64], duration[32];
786 struct timeval now, res;
787 struct ospf6_lsa *lsa, *lsanext;
788 json_object *json_neighbor;
789 json_object *json_array;
790 char db_desc_str[20];
791
792 inet_ntop(AF_INET6, &on->linklocal_addr, linklocal_addr,
793 sizeof(linklocal_addr));
794 inet_ntop(AF_INET, &on->drouter, drouter, sizeof(drouter));
795 inet_ntop(AF_INET, &on->bdrouter, bdrouter, sizeof(bdrouter));
796
797 monotime(&now);
798 timersub(&now, &on->last_changed, &res);
799 timerstring(&res, duration, sizeof(duration));
800
801 if (use_json) {
802 json_neighbor = json_object_new_object();
803 json_object_string_add(json_neighbor, "area",
804 on->ospf6_if->area->name);
805 json_object_string_add(json_neighbor, "interface",
806 on->ospf6_if->interface->name);
807 json_object_int_add(json_neighbor, "interfaceIndex",
808 on->ospf6_if->interface->ifindex);
809 json_object_int_add(json_neighbor, "neighborInterfaceIndex",
810 on->ifindex);
811 json_object_string_add(json_neighbor, "linkLocalAddress",
812 linklocal_addr);
813 json_object_string_add(json_neighbor, "neighborState",
814 ospf6_neighbor_state_str[on->state]);
815 json_object_string_add(json_neighbor, "neighborStateDuration",
816 duration);
817 json_object_string_add(json_neighbor, "neighborDRouter",
818 drouter);
819 json_object_string_add(json_neighbor, "neighborBdRouter",
820 bdrouter);
821 snprintf(db_desc_str, sizeof(db_desc_str), "%s%s%s",
822 (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT)
823 ? "Initial "
824 : ""),
825 (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT)
826 ? "More"
827 : ""),
828 (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT)
829 ? "Master"
830 : "Slave"));
831 json_object_string_add(json_neighbor, "dbDescStatus",
832 db_desc_str);
833
834 json_object_int_add(json_neighbor, "dbDescSeqNumber",
835 (unsigned long)ntohl(on->dbdesc_seqnum));
836
837 json_array = json_object_new_array();
838 json_object_int_add(json_neighbor, "summaryListCount",
839 on->summary_list->count);
840 for (ALL_LSDB(on->summary_list, lsa, lsanext))
841 json_object_array_add(
842 json_array, json_object_new_string(lsa->name));
843 json_object_object_add(json_neighbor, "summaryListLsa",
844 json_array);
845
846 json_array = json_object_new_array();
847 json_object_int_add(json_neighbor, "requestListCount",
848 on->request_list->count);
849 for (ALL_LSDB(on->request_list, lsa, lsanext))
850 json_object_array_add(
851 json_array, json_object_new_string(lsa->name));
852 json_object_object_add(json_neighbor, "requestListLsa",
853 json_array);
854
855 json_array = json_object_new_array();
856 json_object_int_add(json_neighbor, "reTransListCount",
857 on->retrans_list->count);
858 for (ALL_LSDB(on->retrans_list, lsa, lsanext))
859 json_object_array_add(
860 json_array, json_object_new_string(lsa->name));
861 json_object_object_add(json_neighbor, "reTransListLsa",
862 json_array);
863
864
865 timerclear(&res);
866 if (on->thread_send_dbdesc)
867 timersub(&on->thread_send_dbdesc->u.sands, &now, &res);
868 timerstring(&res, duration, sizeof(duration));
869 json_object_int_add(json_neighbor, "pendingLsaDbDescCount",
870 on->dbdesc_list->count);
871 json_object_string_add(json_neighbor, "pendingLsaDbDescTime",
872 duration);
873 json_object_string_add(json_neighbor, "dbDescSendThread",
874 (on->thread_send_dbdesc ? "on" : "off"));
875 json_array = json_object_new_array();
876 for (ALL_LSDB(on->dbdesc_list, lsa, lsanext))
877 json_object_array_add(
878 json_array, json_object_new_string(lsa->name));
879 json_object_object_add(json_neighbor, "pendingLsaDbDesc",
880 json_array);
881
882 timerclear(&res);
883 if (on->thread_send_lsreq)
884 timersub(&on->thread_send_lsreq->u.sands, &now, &res);
885 timerstring(&res, duration, sizeof(duration));
886 json_object_int_add(json_neighbor, "pendingLsaLsReqCount",
887 on->request_list->count);
888 json_object_string_add(json_neighbor, "pendingLsaLsReqTime",
889 duration);
890 json_object_string_add(json_neighbor, "lsReqSendThread",
891 (on->thread_send_lsreq ? "on" : "off"));
892 json_array = json_object_new_array();
893 for (ALL_LSDB(on->request_list, lsa, lsanext))
894 json_object_array_add(
895 json_array, json_object_new_string(lsa->name));
896 json_object_object_add(json_neighbor, "pendingLsaLsReq",
897 json_array);
898
899
900 timerclear(&res);
901 if (on->thread_send_lsupdate)
902 timersub(&on->thread_send_lsupdate->u.sands, &now,
903 &res);
904 timerstring(&res, duration, sizeof(duration));
905 json_object_int_add(json_neighbor, "pendingLsaLsUpdateCount",
906 on->lsupdate_list->count);
907 json_object_string_add(json_neighbor, "pendingLsaLsUpdateTime",
908 duration);
909 json_object_string_add(
910 json_neighbor, "lsUpdateSendThread",
911 (on->thread_send_lsupdate ? "on" : "off"));
912 json_array = json_object_new_array();
913 for (ALL_LSDB(on->lsupdate_list, lsa, lsanext))
914 json_object_array_add(
915 json_array, json_object_new_string(lsa->name));
916 json_object_object_add(json_neighbor, "pendingLsaLsUpdate",
917 json_array);
918
919 timerclear(&res);
920 if (on->thread_send_lsack)
921 timersub(&on->thread_send_lsack->u.sands, &now, &res);
922 timerstring(&res, duration, sizeof(duration));
923 json_object_int_add(json_neighbor, "pendingLsaLsAckCount",
924 on->lsack_list->count);
925 json_object_string_add(json_neighbor, "pendingLsaLsAckTime",
926 duration);
927 json_object_string_add(json_neighbor, "lsAckSendThread",
928 (on->thread_send_lsack ? "on" : "off"));
929 json_array = json_object_new_array();
930 for (ALL_LSDB(on->lsack_list, lsa, lsanext))
931 json_object_array_add(
932 json_array, json_object_new_string(lsa->name));
933 json_object_object_add(json_neighbor, "pendingLsaLsAck",
934 json_array);
935
936 bfd_sess_show(vty, json_neighbor, on->bfd_session);
937
938 json_object_object_add(json, on->name, json_neighbor);
939
940
941 } else {
942 vty_out(vty, " Neighbor %s\n", on->name);
943 vty_out(vty, " Area %s via interface %s (ifindex %d)\n",
944 on->ospf6_if->area->name, on->ospf6_if->interface->name,
945 on->ospf6_if->interface->ifindex);
946 vty_out(vty, " His IfIndex: %d Link-local address: %s\n",
947 on->ifindex, linklocal_addr);
948 vty_out(vty, " State %s for a duration of %s\n",
949 ospf6_neighbor_state_str[on->state], duration);
950 vty_out(vty, " His choice of DR/BDR %s/%s, Priority %d\n",
951 drouter, bdrouter, on->priority);
952 vty_out(vty, " DbDesc status: %s%s%s SeqNum: %#lx\n",
953 (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT)
954 ? "Initial "
955 : ""),
956 (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT)
957 ? "More "
958 : ""),
959 (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT)
960 ? "Master"
961 : "Slave"),
962 (unsigned long)ntohl(on->dbdesc_seqnum));
963
964 vty_out(vty, " Summary-List: %d LSAs\n",
965 on->summary_list->count);
966 for (ALL_LSDB(on->summary_list, lsa, lsanext))
967 vty_out(vty, " %s\n", lsa->name);
968
969 vty_out(vty, " Request-List: %d LSAs\n",
970 on->request_list->count);
971 for (ALL_LSDB(on->request_list, lsa, lsanext))
972 vty_out(vty, " %s\n", lsa->name);
973
974 vty_out(vty, " Retrans-List: %d LSAs\n",
975 on->retrans_list->count);
976 for (ALL_LSDB(on->retrans_list, lsa, lsanext))
977 vty_out(vty, " %s\n", lsa->name);
978
979 timerclear(&res);
980 if (on->thread_send_dbdesc)
981 timersub(&on->thread_send_dbdesc->u.sands, &now, &res);
982 timerstring(&res, duration, sizeof(duration));
983 vty_out(vty,
984 " %d Pending LSAs for DbDesc in Time %s [thread %s]\n",
985 on->dbdesc_list->count, duration,
986 (on->thread_send_dbdesc ? "on" : "off"));
987 for (ALL_LSDB(on->dbdesc_list, lsa, lsanext))
988 vty_out(vty, " %s\n", lsa->name);
989
990 timerclear(&res);
991 if (on->thread_send_lsreq)
992 timersub(&on->thread_send_lsreq->u.sands, &now, &res);
993 timerstring(&res, duration, sizeof(duration));
994 vty_out(vty,
995 " %d Pending LSAs for LSReq in Time %s [thread %s]\n",
996 on->request_list->count, duration,
997 (on->thread_send_lsreq ? "on" : "off"));
998 for (ALL_LSDB(on->request_list, lsa, lsanext))
999 vty_out(vty, " %s\n", lsa->name);
1000
1001 timerclear(&res);
1002 if (on->thread_send_lsupdate)
1003 timersub(&on->thread_send_lsupdate->u.sands, &now,
1004 &res);
1005 timerstring(&res, duration, sizeof(duration));
1006 vty_out(vty,
1007 " %d Pending LSAs for LSUpdate in Time %s [thread %s]\n",
1008 on->lsupdate_list->count, duration,
1009 (on->thread_send_lsupdate ? "on" : "off"));
1010 for (ALL_LSDB(on->lsupdate_list, lsa, lsanext))
1011 vty_out(vty, " %s\n", lsa->name);
1012
1013 timerclear(&res);
1014 if (on->thread_send_lsack)
1015 timersub(&on->thread_send_lsack->u.sands, &now, &res);
1016 timerstring(&res, duration, sizeof(duration));
1017 vty_out(vty,
1018 " %d Pending LSAs for LSAck in Time %s [thread %s]\n",
1019 on->lsack_list->count, duration,
1020 (on->thread_send_lsack ? "on" : "off"));
1021 for (ALL_LSDB(on->lsack_list, lsa, lsanext))
1022 vty_out(vty, " %s\n", lsa->name);
1023
1024 bfd_sess_show(vty, NULL, on->bfd_session);
1025 }
1026 }
1027
1028 static void ospf6_neighbor_show_detail_common(struct vty *vty,
1029 struct ospf6 *ospf6, bool uj,
1030 bool detail, bool drchoice)
1031 {
1032 struct ospf6_neighbor *on;
1033 struct ospf6_interface *oi;
1034 struct ospf6_area *oa;
1035 struct listnode *i, *j, *k;
1036 json_object *json = NULL;
1037 json_object *json_array = NULL;
1038 void (*showfunc)(struct vty *, struct ospf6_neighbor *,
1039 json_object *json, bool use_json);
1040
1041 if (detail)
1042 showfunc = ospf6_neighbor_show_detail;
1043 else if (drchoice)
1044 showfunc = ospf6_neighbor_show_drchoice;
1045 else
1046 showfunc = ospf6_neighbor_show;
1047
1048 if (uj) {
1049 json = json_object_new_object();
1050 json_array = json_object_new_array();
1051 } else {
1052 if (showfunc == ospf6_neighbor_show)
1053 vty_out(vty, "%-15s %3s %11s %8s/%-12s %11s %s[%s]\n",
1054 "Neighbor ID", "Pri", "DeadTime", "State",
1055 "IfState", "Duration", "I/F", "State");
1056 else if (showfunc == ospf6_neighbor_show_drchoice)
1057 vty_out(vty, "%-15s %8s/%-11s %-15s %-15s %s[%s]\n",
1058 "RouterID", "State", "Duration", "DR", "BDR",
1059 "I/F", "State");
1060 }
1061
1062 for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa))
1063 for (ALL_LIST_ELEMENTS_RO(oa->if_list, j, oi))
1064 for (ALL_LIST_ELEMENTS_RO(oi->neighbor_list, k, on)) {
1065 if (showfunc == ospf6_neighbor_show_detail)
1066 (*showfunc)(vty, on, json, uj);
1067 else
1068 (*showfunc)(vty, on, json_array, uj);
1069 }
1070
1071 if (uj) {
1072 if (showfunc != ospf6_neighbor_show_detail)
1073 json_object_object_add(json, "neighbors", json_array);
1074 else
1075 json_object_free(json_array);
1076 vty_json(vty, json);
1077 }
1078 }
1079
1080 DEFUN(show_ipv6_ospf6_neighbor, show_ipv6_ospf6_neighbor_cmd,
1081 "show ipv6 ospf6 [vrf <NAME|all>] neighbor [<detail|drchoice>] [json]",
1082 SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR
1083 "All VRFs\n"
1084 "Neighbor list\n"
1085 "Display details\n"
1086 "Display DR choices\n" JSON_STR)
1087 {
1088 struct ospf6 *ospf6;
1089 struct listnode *node;
1090 const char *vrf_name = NULL;
1091 bool all_vrf = false;
1092 int idx_vrf = 0;
1093 int idx_type = 4;
1094 bool uj = use_json(argc, argv);
1095 bool detail = false;
1096 bool drchoice = false;
1097
1098 OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
1099
1100 if (argv_find(argv, argc, "detail", &idx_type))
1101 detail = true;
1102 else if (argv_find(argv, argc, "drchoice", &idx_type))
1103 drchoice = true;
1104
1105 for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) {
1106 if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) {
1107 ospf6_neighbor_show_detail_common(vty, ospf6, uj,
1108 detail, drchoice);
1109 if (!all_vrf)
1110 break;
1111 }
1112 }
1113
1114 return CMD_SUCCESS;
1115 }
1116
1117 static int ospf6_neighbor_show_common(struct vty *vty, int argc,
1118 struct cmd_token **argv,
1119 struct ospf6 *ospf6, int idx_ipv4)
1120 {
1121 struct ospf6_neighbor *on;
1122 struct ospf6_interface *oi;
1123 struct ospf6_area *oa;
1124 struct listnode *i, *j, *k;
1125 void (*showfunc)(struct vty *, struct ospf6_neighbor *,
1126 json_object *json, bool use_json);
1127 uint32_t router_id;
1128 json_object *json = NULL;
1129 bool uj = use_json(argc, argv);
1130
1131 showfunc = ospf6_neighbor_show_detail;
1132 if (uj)
1133 json = json_object_new_object();
1134
1135 if ((inet_pton(AF_INET, argv[idx_ipv4]->arg, &router_id)) != 1) {
1136 vty_out(vty, "Router-ID is not parsable: %s\n",
1137 argv[idx_ipv4]->arg);
1138 return CMD_SUCCESS;
1139 }
1140
1141 for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, i, oa))
1142 for (ALL_LIST_ELEMENTS_RO(oa->if_list, j, oi))
1143 for (ALL_LIST_ELEMENTS_RO(oi->neighbor_list, k, on)) {
1144 if (router_id == on->router_id)
1145 (*showfunc)(vty, on, json, uj);
1146 }
1147
1148 if (uj)
1149 vty_json(vty, json);
1150
1151 return CMD_SUCCESS;
1152 }
1153
1154 DEFUN(show_ipv6_ospf6_neighbor_one, show_ipv6_ospf6_neighbor_one_cmd,
1155 "show ipv6 ospf6 [vrf <NAME|all>] neighbor A.B.C.D [json]",
1156 SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR
1157 "All VRFs\n"
1158 "Neighbor list\n"
1159 "Specify Router-ID as IPv4 address notation\n" JSON_STR)
1160 {
1161 int idx_ipv4 = 4;
1162 struct ospf6 *ospf6;
1163 struct listnode *node;
1164 const char *vrf_name = NULL;
1165 bool all_vrf = false;
1166 int idx_vrf = 0;
1167
1168 OSPF6_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
1169 if (idx_vrf > 0)
1170 idx_ipv4 += 2;
1171
1172 for (ALL_LIST_ELEMENTS_RO(om6->ospf6, node, ospf6)) {
1173 if (all_vrf || strcmp(ospf6->name, vrf_name) == 0) {
1174 ospf6_neighbor_show_common(vty, argc, argv, ospf6,
1175 idx_ipv4);
1176
1177 if (!all_vrf)
1178 break;
1179 }
1180 }
1181
1182 return CMD_SUCCESS;
1183 }
1184
1185 void ospf6_neighbor_init(void)
1186 {
1187 install_element(VIEW_NODE, &show_ipv6_ospf6_neighbor_cmd);
1188 install_element(VIEW_NODE, &show_ipv6_ospf6_neighbor_one_cmd);
1189 }
1190
1191 DEFUN (debug_ospf6_neighbor,
1192 debug_ospf6_neighbor_cmd,
1193 "debug ospf6 neighbor [<state|event>]",
1194 DEBUG_STR
1195 OSPF6_STR
1196 "Debug OSPFv3 Neighbor\n"
1197 "Debug OSPFv3 Neighbor State Change\n"
1198 "Debug OSPFv3 Neighbor Event\n")
1199 {
1200 int idx_type = 3;
1201 unsigned char level = 0;
1202
1203 if (argc == 4) {
1204 if (!strncmp(argv[idx_type]->arg, "s", 1))
1205 level = OSPF6_DEBUG_NEIGHBOR_STATE;
1206 else if (!strncmp(argv[idx_type]->arg, "e", 1))
1207 level = OSPF6_DEBUG_NEIGHBOR_EVENT;
1208 } else
1209 level = OSPF6_DEBUG_NEIGHBOR_STATE | OSPF6_DEBUG_NEIGHBOR_EVENT;
1210
1211 OSPF6_DEBUG_NEIGHBOR_ON(level);
1212 return CMD_SUCCESS;
1213 }
1214
1215
1216 DEFUN (no_debug_ospf6_neighbor,
1217 no_debug_ospf6_neighbor_cmd,
1218 "no debug ospf6 neighbor [<state|event>]",
1219 NO_STR
1220 DEBUG_STR
1221 OSPF6_STR
1222 "Debug OSPFv3 Neighbor\n"
1223 "Debug OSPFv3 Neighbor State Change\n"
1224 "Debug OSPFv3 Neighbor Event\n")
1225 {
1226 int idx_type = 4;
1227 unsigned char level = 0;
1228
1229 if (argc == 5) {
1230 if (!strncmp(argv[idx_type]->arg, "s", 1))
1231 level = OSPF6_DEBUG_NEIGHBOR_STATE;
1232 if (!strncmp(argv[idx_type]->arg, "e", 1))
1233 level = OSPF6_DEBUG_NEIGHBOR_EVENT;
1234 } else
1235 level = OSPF6_DEBUG_NEIGHBOR_STATE | OSPF6_DEBUG_NEIGHBOR_EVENT;
1236
1237 OSPF6_DEBUG_NEIGHBOR_OFF(level);
1238 return CMD_SUCCESS;
1239 }
1240
1241
1242 DEFUN (no_debug_ospf6,
1243 no_debug_ospf6_cmd,
1244 "no debug ospf6",
1245 NO_STR
1246 DEBUG_STR
1247 OSPF6_STR)
1248 {
1249 unsigned int i;
1250
1251 OSPF6_DEBUG_ABR_OFF();
1252 OSPF6_DEBUG_ASBR_OFF();
1253 OSPF6_DEBUG_BROUTER_OFF();
1254 OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_OFF();
1255 OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_OFF();
1256 OSPF6_DEBUG_FLOODING_OFF();
1257 OSPF6_DEBUG_INTERFACE_OFF();
1258
1259 ospf6_lsa_debug_set_all(false);
1260
1261 for (i = 0; i < 6; i++)
1262 OSPF6_DEBUG_MESSAGE_OFF(i,
1263 OSPF6_DEBUG_NEIGHBOR_STATE
1264 | OSPF6_DEBUG_NEIGHBOR_EVENT);
1265
1266 OSPF6_DEBUG_NEIGHBOR_OFF(OSPF6_DEBUG_NEIGHBOR_STATE
1267 | OSPF6_DEBUG_NEIGHBOR_EVENT);
1268 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_TABLE);
1269 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_INTRA);
1270 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_INTER);
1271 OSPF6_DEBUG_ROUTE_OFF(OSPF6_DEBUG_ROUTE_MEMORY);
1272 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_PROCESS);
1273 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_TIME);
1274 OSPF6_DEBUG_SPF_OFF(OSPF6_DEBUG_SPF_DATABASE);
1275 OSPF6_DEBUG_ZEBRA_OFF(OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV);
1276
1277 return CMD_SUCCESS;
1278 }
1279
1280 int config_write_ospf6_debug_neighbor(struct vty *vty)
1281 {
1282 if (IS_OSPF6_DEBUG_NEIGHBOR(STATE) && IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
1283 vty_out(vty, "debug ospf6 neighbor\n");
1284 else if (IS_OSPF6_DEBUG_NEIGHBOR(STATE))
1285 vty_out(vty, "debug ospf6 neighbor state\n");
1286 else if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
1287 vty_out(vty, "debug ospf6 neighbor event\n");
1288 return 0;
1289 }
1290
1291 void install_element_ospf6_debug_neighbor(void)
1292 {
1293 install_element(ENABLE_NODE, &debug_ospf6_neighbor_cmd);
1294 install_element(ENABLE_NODE, &no_debug_ospf6_neighbor_cmd);
1295 install_element(ENABLE_NODE, &no_debug_ospf6_cmd);
1296 install_element(CONFIG_NODE, &debug_ospf6_neighbor_cmd);
1297 install_element(CONFIG_NODE, &no_debug_ospf6_neighbor_cmd);
1298 install_element(CONFIG_NODE, &no_debug_ospf6_cmd);
1299 }