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