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