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