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