]> git.proxmox.com Git - mirror_frr.git/blame - ospf6d/ospf6_neighbor.c
bgpd: Prevent crash in bgp_table_range_lookup
[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"
29
508e53e2 30#include "ospf6_proto.h"
718e3744 31#include "ospf6_lsa.h"
508e53e2 32#include "ospf6_lsdb.h"
718e3744 33#include "ospf6_message.h"
508e53e2 34#include "ospf6_top.h"
35#include "ospf6_area.h"
36#include "ospf6_interface.h"
718e3744 37#include "ospf6_neighbor.h"
508e53e2 38#include "ospf6_intra.h"
3b4cd3a9 39#include "ospf6_flood.h"
049207c3 40#include "ospf6d.h"
7f342629 41#include "ospf6_bfd.h"
4dfd8aff
DW
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"
718e3744 47
3012671f 48DEFINE_HOOK(ospf6_neighbor_change,
d62a17ae 49 (struct ospf6_neighbor * on, int state, int next_state),
50 (on, state, next_state))
3012671f 51
508e53e2 52unsigned char conf_debug_ospf6_neighbor = 0;
53
d62a17ae 54const char *ospf6_neighbor_state_str[] = {
55 "None", "Down", "Attempt", "Init", "Twoway",
56 "ExStart", "ExChange", "Loading", "Full", NULL};
718e3744 57
d62a17ae 58int ospf6_neighbor_cmp(void *va, void *vb)
718e3744 59{
d62a17ae 60 struct ospf6_neighbor *ona = (struct ospf6_neighbor *)va;
61 struct ospf6_neighbor *onb = (struct ospf6_neighbor *)vb;
27fa3398
DS
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;
718e3744 67}
68
d7c0a89a 69struct ospf6_neighbor *ospf6_neighbor_lookup(uint32_t router_id,
d62a17ae 70 struct ospf6_interface *oi)
718e3744 71{
d62a17ae 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;
718e3744 80}
81
508e53e2 82/* create ospf6_neighbor */
d7c0a89a 83struct ospf6_neighbor *ospf6_neighbor_create(uint32_t router_id,
d62a17ae 84 struct ospf6_interface *oi)
718e3744 85{
d62a17ae 86 struct ospf6_neighbor *on;
87 char buf[16];
88
aa406bbc 89 on = XCALLOC(MTYPE_OSPF6_NEIGHBOR, sizeof(struct ospf6_neighbor));
d62a17ae 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;
718e3744 111}
112
d62a17ae 113void ospf6_neighbor_delete(struct ospf6_neighbor *on)
718e3744 114{
d62a17ae 115 struct ospf6_lsa *lsa;
3b4cd3a9 116
d62a17ae 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 }
718e3744 123
d62a17ae 124 ospf6_lsdb_remove_all(on->dbdesc_list);
125 ospf6_lsdb_remove_all(on->lsupdate_list);
126 ospf6_lsdb_remove_all(on->lsack_list);
508e53e2 127
d62a17ae 128 ospf6_lsdb_delete(on->summary_list);
129 ospf6_lsdb_delete(on->request_list);
130 ospf6_lsdb_delete(on->retrans_list);
718e3744 131
d62a17ae 132 ospf6_lsdb_delete(on->dbdesc_list);
133 ospf6_lsdb_delete(on->lsupdate_list);
134 ospf6_lsdb_delete(on->lsack_list);
508e53e2 135
d62a17ae 136 THREAD_OFF(on->inactivity_timer);
508e53e2 137
d62a17ae 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);
508e53e2 142
d62a17ae 143 ospf6_bfd_reg_dereg_nbr(on, ZEBRA_BFD_DEST_DEREGISTER);
144 XFREE(MTYPE_OSPF6_NEIGHBOR, on);
718e3744 145}
146
d7c0a89a 147static void ospf6_neighbor_state_change(uint8_t next_state,
d62a17ae 148 struct ospf6_neighbor *on, int event)
718e3744 149{
d7c0a89a 150 uint8_t prev_state;
d62a17ae 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 }
690df177
CS
188 if (next_state == OSPF6_NEIGHBOR_FULL)
189 on->ospf6_if->area->intra_prefix_originate = 1;
190
d62a17ae 191 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(on->ospf6_if->area);
76249532 192
6b1886f5
CS
193 if ((prev_state == OSPF6_NEIGHBOR_LOADING ||
194 prev_state == OSPF6_NEIGHBOR_EXCHANGE) &&
195 next_state == OSPF6_NEIGHBOR_FULL) {
76249532 196 OSPF6_AS_EXTERN_LSA_SCHEDULE(on->ospf6_if);
d6927cf3 197 on->ospf6_if->area->full_nbrs++;
76249532 198 }
d6927cf3
CS
199
200 if (prev_state == OSPF6_NEIGHBOR_FULL)
201 on->ospf6_if->area->full_nbrs--;
d62a17ae 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);
718e3744 212}
213
508e53e2 214/* RFC2328 section 10.4 */
d62a17ae 215static int need_adjacency(struct ospf6_neighbor *on)
718e3744 216{
d62a17ae 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;
718e3744 221
d62a17ae 222 if (on->ospf6_if->drouter == on->router_id
223 || on->ospf6_if->bdrouter == on->router_id)
224 return 1;
508e53e2 225
d62a17ae 226 return 0;
718e3744 227}
228
d62a17ae 229int hello_received(struct thread *thread)
718e3744 230{
d62a17ae 231 struct ospf6_neighbor *on;
718e3744 232
d62a17ae 233 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
234 assert(on);
718e3744 235
d62a17ae 236 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
237 zlog_debug("Neighbor Event %s: *HelloReceived*", on->name);
508e53e2 238
d62a17ae 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);
508e53e2 244
d62a17ae 245 if (on->state <= OSPF6_NEIGHBOR_DOWN)
246 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_INIT, on,
247 OSPF6_NEIGHBOR_EVENT_HELLO_RCVD);
508e53e2 248
d62a17ae 249 return 0;
718e3744 250}
251
d62a17ae 252int twoway_received(struct thread *thread)
718e3744 253{
d62a17ae 254 struct ospf6_neighbor *on;
508e53e2 255
d62a17ae 256 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
257 assert(on);
508e53e2 258
d62a17ae 259 if (on->state > OSPF6_NEIGHBOR_INIT)
260 return 0;
508e53e2 261
d62a17ae 262 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
263 zlog_debug("Neighbor Event %s: *2Way-Received*", on->name);
508e53e2 264
d62a17ae 265 thread_add_event(master, neighbor_change, on->ospf6_if, 0, NULL);
508e53e2 266
d62a17ae 267 if (!need_adjacency(on)) {
268 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_TWOWAY, on,
269 OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD);
270 return 0;
271 }
718e3744 272
d62a17ae 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);
508e53e2 278
d62a17ae 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);
508e53e2 283
d62a17ae 284 return 0;
718e3744 285}
286
d62a17ae 287int negotiation_done(struct thread *thread)
718e3744 288{
d62a17ae 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;
718e3744 341}
342
d62a17ae 343int exchange_done(struct thread *thread)
718e3744 344{
d62a17ae 345 struct ospf6_neighbor *on;
718e3744 346
d62a17ae 347 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
348 assert(on);
508e53e2 349
d62a17ae 350 if (on->state != OSPF6_NEIGHBOR_EXCHANGE)
351 return 0;
508e53e2 352
d62a17ae 353 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
354 zlog_debug("Neighbor Event %s: *ExchangeDone*", on->name);
508e53e2 355
d62a17ae 356 THREAD_OFF(on->thread_send_dbdesc);
357 ospf6_lsdb_remove_all(on->dbdesc_list);
508e53e2 358
d62a17ae 359 /* XXX
360 thread_add_timer (master, ospf6_neighbor_last_dbdesc_release, on,
361 on->ospf6_if->dead_interval);
362 */
508e53e2 363
d62a17ae 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);
eb82e9ee 370
d62a17ae 371 thread_add_event(master, ospf6_lsreq_send, on, 0,
372 &on->thread_send_lsreq);
373 }
508e53e2 374
d62a17ae 375 return 0;
508e53e2 376}
377
eb82e9ee 378/* Check loading state. */
d62a17ae 379void ospf6_check_nbr_loading(struct ospf6_neighbor *on)
eb82e9ee
DD
380{
381
d62a17ae 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 }
eb82e9ee 397 }
eb82e9ee
DD
398}
399
d62a17ae 400int loading_done(struct thread *thread)
508e53e2 401{
d62a17ae 402 struct ospf6_neighbor *on;
508e53e2 403
d62a17ae 404 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
405 assert(on);
508e53e2 406
d62a17ae 407 if (on->state != OSPF6_NEIGHBOR_LOADING)
408 return 0;
508e53e2 409
d62a17ae 410 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
411 zlog_debug("Neighbor Event %s: *LoadingDone*", on->name);
508e53e2 412
d62a17ae 413 assert(on->request_list->count == 0);
508e53e2 414
d62a17ae 415 ospf6_neighbor_state_change(OSPF6_NEIGHBOR_FULL, on,
416 OSPF6_NEIGHBOR_EVENT_LOADING_DONE);
508e53e2 417
d62a17ae 418 return 0;
508e53e2 419}
420
d62a17ae 421int adj_ok(struct thread *thread)
508e53e2 422{
d62a17ae 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;
508e53e2 456}
718e3744 457
d62a17ae 458int seqnumber_mismatch(struct thread *thread)
508e53e2 459{
d62a17ae 460 struct ospf6_neighbor *on;
461 struct ospf6_lsa *lsa;
718e3744 462
d62a17ae 463 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
464 assert(on);
718e3744 465
d62a17ae 466 if (on->state < OSPF6_NEIGHBOR_EXCHANGE)
467 return 0;
718e3744 468
d62a17ae 469 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
470 zlog_debug("Neighbor Event %s: *SeqNumberMismatch*", on->name);
718e3744 471
d62a17ae 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);
718e3744 477
d62a17ae 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 }
508e53e2 484
d62a17ae 485 THREAD_OFF(on->thread_send_dbdesc);
486 on->dbdesc_seqnum++; /* Incr seqnum as per RFC2328, sec 10.3 */
931b1b8c 487
d62a17ae 488 on->thread_send_dbdesc = NULL;
489 thread_add_event(master, ospf6_dbdesc_send, on, 0,
490 &on->thread_send_dbdesc);
508e53e2 491
d62a17ae 492 return 0;
718e3744 493}
494
d62a17ae 495int bad_lsreq(struct thread *thread)
718e3744 496{
d62a17ae 497 struct ospf6_neighbor *on;
498 struct ospf6_lsa *lsa;
508e53e2 499
d62a17ae 500 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
501 assert(on);
508e53e2 502
d62a17ae 503 if (on->state < OSPF6_NEIGHBOR_EXCHANGE)
504 return 0;
718e3744 505
d62a17ae 506 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
507 zlog_debug("Neighbor Event %s: *BadLSReq*", on->name);
718e3744 508
d62a17ae 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);
718e3744 514
d62a17ae 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 }
718e3744 521
d62a17ae 522 THREAD_OFF(on->thread_send_dbdesc);
523 on->dbdesc_seqnum++; /* Incr seqnum as per RFC2328, sec 10.3 */
931b1b8c 524
d62a17ae 525 on->thread_send_dbdesc = NULL;
526 thread_add_event(master, ospf6_dbdesc_send, on, 0,
527 &on->thread_send_dbdesc);
508e53e2 528
d62a17ae 529 return 0;
718e3744 530}
531
d62a17ae 532int oneway_received(struct thread *thread)
718e3744 533{
d62a17ae 534 struct ospf6_neighbor *on;
535 struct ospf6_lsa *lsa;
718e3744 536
d62a17ae 537 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
538 assert(on);
508e53e2 539
d62a17ae 540 if (on->state < OSPF6_NEIGHBOR_TWOWAY)
541 return 0;
508e53e2 542
d62a17ae 543 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
544 zlog_debug("Neighbor Event %s: *1Way-Received*", on->name);
508e53e2 545
d62a17ae 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);
508e53e2 549
d62a17ae 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 }
508e53e2 556
d62a17ae 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);
508e53e2 561
d62a17ae 562 return 0;
508e53e2 563}
564
d62a17ae 565int inactivity_timer(struct thread *thread)
508e53e2 566{
d62a17ae 567 struct ospf6_neighbor *on;
508e53e2 568
d62a17ae 569 on = (struct ospf6_neighbor *)THREAD_ARG(thread);
570 assert(on);
508e53e2 571
d62a17ae 572 if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT))
573 zlog_debug("Neighbor Event %s: *InactivityTimer*", on->name);
508e53e2 574
d62a17ae 575 on->inactivity_timer = NULL;
576 on->drouter = on->prev_drouter = 0;
577 on->bdrouter = on->prev_bdrouter = 0;
508e53e2 578
d62a17ae 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);
508e53e2 582
d62a17ae 583 listnode_delete(on->ospf6_if->neighbor_list, on);
584 ospf6_neighbor_delete(on);
508e53e2 585
d62a17ae 586 return 0;
718e3744 587}
588
508e53e2 589
718e3744 590/* vty functions */
591/* show neighbor structure */
d62a17ae 592static void ospf6_neighbor_show(struct vty *vty, struct ospf6_neighbor *on)
718e3744 593{
d62a17ae 594 char router_id[16];
68bfcc05 595 char duration[64];
d62a17ae 596 struct timeval res;
597 char nstate[16];
68bfcc05 598 char deadtime[64];
d62a17ae 599 long h, m, s;
600
601 /* Router-ID (Name) */
602 inet_ntop(AF_INET, &on->router_id, router_id, sizeof(router_id));
508e53e2 603#ifdef HAVE_GETNAMEINFO
d62a17ae 604 {
605 }
508e53e2 606#endif /*HAVE_GETNAMEINFO*/
607
d62a17ae 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]);
508e53e2 646}
647
d62a17ae 648static void ospf6_neighbor_show_drchoice(struct vty *vty,
649 struct ospf6_neighbor *on)
508e53e2 650{
d62a17ae 651 char router_id[16];
652 char drouter[16], bdrouter[16];
68bfcc05 653 char duration[64];
d62a17ae 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]);
718e3744 674}
675
d62a17ae 676static void ospf6_neighbor_show_detail(struct vty *vty,
677 struct ospf6_neighbor *on)
718e3744 678{
d62a17ae 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"),
d7c0a89a 709 (unsigned long)ntohl(on->dbdesc_seqnum));
d62a17ae 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);
718e3744 765}
766
508e53e2 767DEFUN (show_ipv6_ospf6_neighbor,
768 show_ipv6_ospf6_neighbor_cmd,
6de69f83 769 "show ipv6 ospf6 neighbor [<detail|drchoice>]",
718e3744 770 SHOW_STR
771 IP6_STR
772 OSPF6_STR
773 "Neighbor list\n"
1d68dbfe
DW
774 "Display details\n"
775 "Display DR choices\n")
718e3744 776{
d62a17ae 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;
718e3744 808}
809
718e3744 810
508e53e2 811DEFUN (show_ipv6_ospf6_neighbor_one,
812 show_ipv6_ospf6_neighbor_one_cmd,
813 "show ipv6 ospf6 neighbor A.B.C.D",
718e3744 814 SHOW_STR
815 IP6_STR
816 OSPF6_STR
508e53e2 817 "Neighbor list\n"
818 "Specify Router-ID as IPv4 address notation\n"
819 )
718e3744 820{
d62a17ae 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 *);
d7c0a89a 827 uint32_t router_id;
d62a17ae 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;
718e3744 844}
845
d62a17ae 846void ospf6_neighbor_init(void)
718e3744 847{
d62a17ae 848 install_element(VIEW_NODE, &show_ipv6_ospf6_neighbor_cmd);
849 install_element(VIEW_NODE, &show_ipv6_ospf6_neighbor_one_cmd);
508e53e2 850}
851
852DEFUN (debug_ospf6_neighbor,
853 debug_ospf6_neighbor_cmd,
6de69f83 854 "debug ospf6 neighbor [<state|event>]",
508e53e2 855 DEBUG_STR
856 OSPF6_STR
857 "Debug OSPFv3 Neighbor\n"
1d68dbfe
DW
858 "Debug OSPFv3 Neighbor State Change\n"
859 "Debug OSPFv3 Neighbor Event\n")
508e53e2 860{
d62a17ae 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;
718e3744 874}
875
508e53e2 876
877DEFUN (no_debug_ospf6_neighbor,
878 no_debug_ospf6_neighbor_cmd,
6de69f83 879 "no debug ospf6 neighbor [<state|event>]",
508e53e2 880 NO_STR
881 DEBUG_STR
882 OSPF6_STR
883 "Debug OSPFv3 Neighbor\n"
1d68dbfe
DW
884 "Debug OSPFv3 Neighbor State Change\n"
885 "Debug OSPFv3 Neighbor Event\n")
508e53e2 886{
d62a17ae 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;
508e53e2 900}
901
508e53e2 902
4dfd8aff
DW
903DEFUN (no_debug_ospf6,
904 no_debug_ospf6_cmd,
905 "no debug ospf6",
906 NO_STR
907 DEBUG_STR
908 OSPF6_STR)
909{
d7c0a89a 910 unsigned int i;
d62a17ae 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) {
01db90cd 925 UNSET_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG);
d62a17ae 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;
4dfd8aff
DW
946}
947
d62a17ae 948int config_write_ospf6_debug_neighbor(struct vty *vty)
508e53e2 949{
d62a17ae 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;
508e53e2 957}
958
d62a17ae 959void install_element_ospf6_debug_neighbor(void)
508e53e2 960{
d62a17ae 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);
508e53e2 967}