]> git.proxmox.com Git - mirror_frr.git/blob - ospf6d/ospf6_interface.c
94b599be5641000f962a8145110a5d58e226f039
[mirror_frr.git] / ospf6d / ospf6_interface.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
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
22 #include <zebra.h>
23
24 #include "memory.h"
25 #include "if.h"
26 #include "log.h"
27 #include "command.h"
28 #include "thread.h"
29 #include "prefix.h"
30 #include "plist.h"
31
32 #include "ospf6_lsa.h"
33 #include "ospf6_lsdb.h"
34 #include "ospf6_network.h"
35 #include "ospf6_message.h"
36 #include "ospf6_route.h"
37 #include "ospf6_top.h"
38 #include "ospf6_area.h"
39 #include "ospf6_interface.h"
40 #include "ospf6_neighbor.h"
41 #include "ospf6_intra.h"
42 #include "ospf6_spf.h"
43 #include "ospf6d.h"
44
45 unsigned char conf_debug_ospf6_interface = 0;
46
47 const char *ospf6_interface_state_str[] =
48 {
49 "None",
50 "Down",
51 "Loopback",
52 "Waiting",
53 "PointToPoint",
54 "DROther",
55 "BDR",
56 "DR",
57 NULL
58 };
59
60 struct ospf6_interface *
61 ospf6_interface_lookup_by_ifindex (int ifindex)
62 {
63 struct ospf6_interface *oi;
64 struct interface *ifp;
65
66 ifp = if_lookup_by_index (ifindex);
67 if (ifp == NULL)
68 return (struct ospf6_interface *) NULL;
69
70 oi = (struct ospf6_interface *) ifp->info;
71 return oi;
72 }
73
74 /* schedule routing table recalculation */
75 static void
76 ospf6_interface_lsdb_hook (struct ospf6_lsa *lsa)
77 {
78 struct ospf6_interface *oi;
79
80 if (lsa == NULL)
81 return;
82
83 oi = lsa->lsdb->data;
84 switch (ntohs (lsa->header->type))
85 {
86 case OSPF6_LSTYPE_LINK:
87 if (oi->state == OSPF6_INTERFACE_DR)
88 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
89 ospf6_spf_schedule (oi->area->ospf6);
90 break;
91
92 default:
93 break;
94 }
95 }
96
97 static u_char
98 ospf6_default_iftype(struct interface *ifp)
99 {
100 if (if_is_pointopoint (ifp))
101 return OSPF_IFTYPE_POINTOPOINT;
102 else if (if_is_loopback (ifp))
103 return OSPF_IFTYPE_LOOPBACK;
104 else
105 return OSPF_IFTYPE_BROADCAST;
106 }
107
108 /* Create new ospf6 interface structure */
109 struct ospf6_interface *
110 ospf6_interface_create (struct interface *ifp)
111 {
112 struct ospf6_interface *oi;
113 unsigned int iobuflen;
114
115 oi = (struct ospf6_interface *)
116 XCALLOC (MTYPE_OSPF6_IF, sizeof (struct ospf6_interface));
117
118 if (!oi)
119 {
120 zlog_err ("Can't malloc ospf6_interface for ifindex %d", ifp->ifindex);
121 return (struct ospf6_interface *) NULL;
122 }
123
124 oi->area = (struct ospf6_area *) NULL;
125 oi->neighbor_list = list_new ();
126 oi->neighbor_list->cmp = ospf6_neighbor_cmp;
127 oi->linklocal_addr = (struct in6_addr *) NULL;
128 oi->instance_id = OSPF6_INTERFACE_INSTANCE_ID;
129 oi->transdelay = OSPF6_INTERFACE_TRANSDELAY;
130 oi->priority = OSPF6_INTERFACE_PRIORITY;
131
132 oi->hello_interval = OSPF_HELLO_INTERVAL_DEFAULT;
133 oi->dead_interval = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
134 oi->rxmt_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
135 oi->cost = OSPF6_INTERFACE_COST;
136 oi->type = ospf6_default_iftype (ifp);
137 oi->state = OSPF6_INTERFACE_DOWN;
138 oi->flag = 0;
139 oi->mtu_ignore = 0;
140
141 /* Try to adjust I/O buffer size with IfMtu */
142 oi->ifmtu = ifp->mtu6;
143 iobuflen = ospf6_iobuf_size (ifp->mtu6);
144 if (oi->ifmtu > iobuflen)
145 {
146 if (IS_OSPF6_DEBUG_INTERFACE)
147 zlog_debug ("Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
148 ifp->name, iobuflen);
149 oi->ifmtu = iobuflen;
150 }
151
152 oi->lsupdate_list = ospf6_lsdb_create (oi);
153 oi->lsack_list = ospf6_lsdb_create (oi);
154 oi->lsdb = ospf6_lsdb_create (oi);
155 oi->lsdb->hook_add = ospf6_interface_lsdb_hook;
156 oi->lsdb->hook_remove = ospf6_interface_lsdb_hook;
157 oi->lsdb_self = ospf6_lsdb_create (oi);
158
159 oi->route_connected = OSPF6_ROUTE_TABLE_CREATE (INTERFACE, CONNECTED_ROUTES);
160 oi->route_connected->scope = oi;
161
162 /* link both */
163 oi->interface = ifp;
164 ifp->info = oi;
165
166 return oi;
167 }
168
169 void
170 ospf6_interface_delete (struct ospf6_interface *oi)
171 {
172 struct listnode *node, *nnode;
173 struct ospf6_neighbor *on;
174
175 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
176 ospf6_neighbor_delete (on);
177
178 list_delete (oi->neighbor_list);
179
180 THREAD_OFF (oi->thread_send_hello);
181 THREAD_OFF (oi->thread_send_lsupdate);
182 THREAD_OFF (oi->thread_send_lsack);
183
184 ospf6_lsdb_remove_all (oi->lsdb);
185 ospf6_lsdb_remove_all (oi->lsupdate_list);
186 ospf6_lsdb_remove_all (oi->lsack_list);
187
188 ospf6_lsdb_delete (oi->lsdb);
189 ospf6_lsdb_delete (oi->lsdb_self);
190
191 ospf6_lsdb_delete (oi->lsupdate_list);
192 ospf6_lsdb_delete (oi->lsack_list);
193
194 ospf6_route_table_delete (oi->route_connected);
195
196 /* cut link */
197 oi->interface->info = NULL;
198
199 /* plist_name */
200 if (oi->plist_name)
201 XFREE (MTYPE_PREFIX_LIST_STR, oi->plist_name);
202
203 XFREE (MTYPE_OSPF6_IF, oi);
204 }
205
206 void
207 ospf6_interface_enable (struct ospf6_interface *oi)
208 {
209 UNSET_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE);
210
211 oi->thread_send_hello =
212 thread_add_event (master, ospf6_hello_send, oi, 0);
213 }
214
215 void
216 ospf6_interface_disable (struct ospf6_interface *oi)
217 {
218 struct listnode *node, *nnode;
219 struct ospf6_neighbor *on;
220
221 SET_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE);
222
223 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
224 ospf6_neighbor_delete (on);
225
226 list_delete_all_node (oi->neighbor_list);
227
228 ospf6_lsdb_remove_all (oi->lsdb);
229 ospf6_lsdb_remove_all (oi->lsupdate_list);
230 ospf6_lsdb_remove_all (oi->lsack_list);
231
232 THREAD_OFF (oi->thread_send_hello);
233 THREAD_OFF (oi->thread_send_lsupdate);
234 THREAD_OFF (oi->thread_send_lsack);
235 }
236
237 static struct in6_addr *
238 ospf6_interface_get_linklocal_address (struct interface *ifp)
239 {
240 struct listnode *n;
241 struct connected *c;
242 struct in6_addr *l = (struct in6_addr *) NULL;
243
244 /* for each connected address */
245 for (ALL_LIST_ELEMENTS_RO (ifp->connected, n, c))
246 {
247 /* if family not AF_INET6, ignore */
248 if (c->address->family != AF_INET6)
249 continue;
250
251 /* linklocal scope check */
252 if (IN6_IS_ADDR_LINKLOCAL (&c->address->u.prefix6))
253 l = &c->address->u.prefix6;
254 }
255 return l;
256 }
257
258 void
259 ospf6_interface_if_add (struct interface *ifp)
260 {
261 struct ospf6_interface *oi;
262 unsigned int iobuflen;
263
264 oi = (struct ospf6_interface *) ifp->info;
265 if (oi == NULL)
266 return;
267
268 /* Try to adjust I/O buffer size with IfMtu */
269 if (oi->ifmtu == 0)
270 oi->ifmtu = ifp->mtu6;
271 iobuflen = ospf6_iobuf_size (ifp->mtu6);
272 if (oi->ifmtu > iobuflen)
273 {
274 if (IS_OSPF6_DEBUG_INTERFACE)
275 zlog_debug ("Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
276 ifp->name, iobuflen);
277 oi->ifmtu = iobuflen;
278 }
279
280 /* interface start */
281 if (oi->area)
282 thread_add_event (master, interface_up, oi, 0);
283 }
284
285 void
286 ospf6_interface_if_del (struct interface *ifp)
287 {
288 struct ospf6_interface *oi;
289
290 oi = (struct ospf6_interface *) ifp->info;
291 if (oi == NULL)
292 return;
293
294 /* interface stop */
295 if (oi->area)
296 thread_execute (master, interface_down, oi, 0);
297
298 listnode_delete (oi->area->if_list, oi);
299 oi->area = (struct ospf6_area *) NULL;
300
301 /* cut link */
302 oi->interface = NULL;
303 ifp->info = NULL;
304
305 ospf6_interface_delete (oi);
306 }
307
308 void
309 ospf6_interface_state_update (struct interface *ifp)
310 {
311 struct ospf6_interface *oi;
312
313 oi = (struct ospf6_interface *) ifp->info;
314 if (oi == NULL)
315 return;
316 if (oi->area == NULL)
317 return;
318
319 if (if_is_up (ifp))
320 thread_add_event (master, interface_up, oi, 0);
321 else
322 thread_add_event (master, interface_down, oi, 0);
323
324 return;
325 }
326
327 void
328 ospf6_interface_connected_route_update (struct interface *ifp)
329 {
330 struct ospf6_interface *oi;
331 struct ospf6_route *route;
332 struct connected *c;
333 struct listnode *node, *nnode;
334
335 oi = (struct ospf6_interface *) ifp->info;
336 if (oi == NULL)
337 return;
338
339 /* reset linklocal pointer */
340 oi->linklocal_addr = ospf6_interface_get_linklocal_address (ifp);
341
342 /* if area is null, do not make connected-route list */
343 if (oi->area == NULL)
344 return;
345
346 /* update "route to advertise" interface route table */
347 ospf6_route_remove_all (oi->route_connected);
348
349 for (ALL_LIST_ELEMENTS (oi->interface->connected, node, nnode, c))
350 {
351 if (c->address->family != AF_INET6)
352 continue;
353
354 CONTINUE_IF_ADDRESS_LINKLOCAL (IS_OSPF6_DEBUG_INTERFACE, c->address);
355 CONTINUE_IF_ADDRESS_UNSPECIFIED (IS_OSPF6_DEBUG_INTERFACE, c->address);
356 CONTINUE_IF_ADDRESS_LOOPBACK (IS_OSPF6_DEBUG_INTERFACE, c->address);
357 CONTINUE_IF_ADDRESS_V4COMPAT (IS_OSPF6_DEBUG_INTERFACE, c->address);
358 CONTINUE_IF_ADDRESS_V4MAPPED (IS_OSPF6_DEBUG_INTERFACE, c->address);
359
360 /* apply filter */
361 if (oi->plist_name)
362 {
363 struct prefix_list *plist;
364 enum prefix_list_type ret;
365 char buf[128];
366
367 prefix2str (c->address, buf, sizeof (buf));
368 plist = prefix_list_lookup (AFI_IP6, oi->plist_name);
369 ret = prefix_list_apply (plist, (void *) c->address);
370 if (ret == PREFIX_DENY)
371 {
372 if (IS_OSPF6_DEBUG_INTERFACE)
373 zlog_debug ("%s on %s filtered by prefix-list %s ",
374 buf, oi->interface->name, oi->plist_name);
375 continue;
376 }
377 }
378
379 route = ospf6_route_create ();
380 memcpy (&route->prefix, c->address, sizeof (struct prefix));
381 apply_mask (&route->prefix);
382 route->type = OSPF6_DEST_TYPE_NETWORK;
383 route->path.area_id = oi->area->area_id;
384 route->path.type = OSPF6_PATH_TYPE_INTRA;
385 route->path.cost = oi->cost;
386 route->nexthop[0].ifindex = oi->interface->ifindex;
387 inet_pton (AF_INET6, "::1", &route->nexthop[0].address);
388 ospf6_route_add (route, oi->route_connected);
389 }
390
391 /* create new Link-LSA */
392 OSPF6_LINK_LSA_SCHEDULE (oi);
393 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
394 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
395 }
396
397 static void
398 ospf6_interface_state_change (u_char next_state, struct ospf6_interface *oi)
399 {
400 u_char prev_state;
401
402 prev_state = oi->state;
403 oi->state = next_state;
404
405 if (prev_state == next_state)
406 return;
407
408 /* log */
409 if (IS_OSPF6_DEBUG_INTERFACE)
410 {
411 zlog_debug ("Interface state change %s: %s -> %s", oi->interface->name,
412 ospf6_interface_state_str[prev_state],
413 ospf6_interface_state_str[next_state]);
414 }
415 oi->state_change++;
416
417 if ((prev_state == OSPF6_INTERFACE_DR ||
418 prev_state == OSPF6_INTERFACE_BDR) &&
419 (next_state != OSPF6_INTERFACE_DR &&
420 next_state != OSPF6_INTERFACE_BDR))
421 ospf6_sso (oi->interface->ifindex, &alldrouters6, IPV6_LEAVE_GROUP);
422
423 if ((prev_state != OSPF6_INTERFACE_DR &&
424 prev_state != OSPF6_INTERFACE_BDR) &&
425 (next_state == OSPF6_INTERFACE_DR ||
426 next_state == OSPF6_INTERFACE_BDR))
427 ospf6_sso (oi->interface->ifindex, &alldrouters6, IPV6_JOIN_GROUP);
428
429 OSPF6_ROUTER_LSA_SCHEDULE (oi->area);
430 if (next_state == OSPF6_INTERFACE_DOWN)
431 {
432 OSPF6_NETWORK_LSA_EXECUTE (oi);
433 OSPF6_INTRA_PREFIX_LSA_EXECUTE_TRANSIT (oi);
434 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
435 }
436 else if (prev_state == OSPF6_INTERFACE_DR ||
437 next_state == OSPF6_INTERFACE_DR)
438 {
439 OSPF6_NETWORK_LSA_SCHEDULE (oi);
440 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
441 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
442 }
443
444 #ifdef HAVE_SNMP
445 /* Terminal state or regression */
446 if ((next_state == OSPF6_INTERFACE_POINTTOPOINT) ||
447 (next_state == OSPF6_INTERFACE_DROTHER) ||
448 (next_state == OSPF6_INTERFACE_BDR) ||
449 (next_state == OSPF6_INTERFACE_DR) ||
450 (next_state < prev_state))
451 ospf6TrapIfStateChange (oi);
452 #endif
453
454 }
455
456 \f
457 /* DR Election, RFC2328 section 9.4 */
458
459 #define IS_ELIGIBLE(n) \
460 ((n)->state >= OSPF6_NEIGHBOR_TWOWAY && (n)->priority != 0)
461
462 static struct ospf6_neighbor *
463 better_bdrouter (struct ospf6_neighbor *a, struct ospf6_neighbor *b)
464 {
465 if ((a == NULL || ! IS_ELIGIBLE (a) || a->drouter == a->router_id) &&
466 (b == NULL || ! IS_ELIGIBLE (b) || b->drouter == b->router_id))
467 return NULL;
468 else if (a == NULL || ! IS_ELIGIBLE (a) || a->drouter == a->router_id)
469 return b;
470 else if (b == NULL || ! IS_ELIGIBLE (b) || b->drouter == b->router_id)
471 return a;
472
473 if (a->bdrouter == a->router_id && b->bdrouter != b->router_id)
474 return a;
475 if (a->bdrouter != a->router_id && b->bdrouter == b->router_id)
476 return b;
477
478 if (a->priority > b->priority)
479 return a;
480 if (a->priority < b->priority)
481 return b;
482
483 if (ntohl (a->router_id) > ntohl (b->router_id))
484 return a;
485 if (ntohl (a->router_id) < ntohl (b->router_id))
486 return b;
487
488 zlog_warn ("Router-ID duplicate ?");
489 return a;
490 }
491
492 static struct ospf6_neighbor *
493 better_drouter (struct ospf6_neighbor *a, struct ospf6_neighbor *b)
494 {
495 if ((a == NULL || ! IS_ELIGIBLE (a) || a->drouter != a->router_id) &&
496 (b == NULL || ! IS_ELIGIBLE (b) || b->drouter != b->router_id))
497 return NULL;
498 else if (a == NULL || ! IS_ELIGIBLE (a) || a->drouter != a->router_id)
499 return b;
500 else if (b == NULL || ! IS_ELIGIBLE (b) || b->drouter != b->router_id)
501 return a;
502
503 if (a->drouter == a->router_id && b->drouter != b->router_id)
504 return a;
505 if (a->drouter != a->router_id && b->drouter == b->router_id)
506 return b;
507
508 if (a->priority > b->priority)
509 return a;
510 if (a->priority < b->priority)
511 return b;
512
513 if (ntohl (a->router_id) > ntohl (b->router_id))
514 return a;
515 if (ntohl (a->router_id) < ntohl (b->router_id))
516 return b;
517
518 zlog_warn ("Router-ID duplicate ?");
519 return a;
520 }
521
522 static u_char
523 dr_election (struct ospf6_interface *oi)
524 {
525 struct listnode *node, *nnode;
526 struct ospf6_neighbor *on, *drouter, *bdrouter, myself;
527 struct ospf6_neighbor *best_drouter, *best_bdrouter;
528 u_char next_state = 0;
529
530 drouter = bdrouter = NULL;
531 best_drouter = best_bdrouter = NULL;
532
533 /* pseudo neighbor myself, including noting current DR/BDR (1) */
534 memset (&myself, 0, sizeof (myself));
535 inet_ntop (AF_INET, &oi->area->ospf6->router_id, myself.name,
536 sizeof (myself.name));
537 myself.state = OSPF6_NEIGHBOR_TWOWAY;
538 myself.drouter = oi->drouter;
539 myself.bdrouter = oi->bdrouter;
540 myself.priority = oi->priority;
541 myself.router_id = oi->area->ospf6->router_id;
542
543 /* Electing BDR (2) */
544 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
545 bdrouter = better_bdrouter (bdrouter, on);
546
547 best_bdrouter = bdrouter;
548 bdrouter = better_bdrouter (best_bdrouter, &myself);
549
550 /* Electing DR (3) */
551 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
552 drouter = better_drouter (drouter, on);
553
554 best_drouter = drouter;
555 drouter = better_drouter (best_drouter, &myself);
556 if (drouter == NULL)
557 drouter = bdrouter;
558
559 /* the router itself is newly/no longer DR/BDR (4) */
560 if ((drouter == &myself && myself.drouter != myself.router_id) ||
561 (drouter != &myself && myself.drouter == myself.router_id) ||
562 (bdrouter == &myself && myself.bdrouter != myself.router_id) ||
563 (bdrouter != &myself && myself.bdrouter == myself.router_id))
564 {
565 myself.drouter = (drouter ? drouter->router_id : htonl (0));
566 myself.bdrouter = (bdrouter ? bdrouter->router_id : htonl (0));
567
568 /* compatible to Electing BDR (2) */
569 bdrouter = better_bdrouter (best_bdrouter, &myself);
570
571 /* compatible to Electing DR (3) */
572 drouter = better_drouter (best_drouter, &myself);
573 if (drouter == NULL)
574 drouter = bdrouter;
575 }
576
577 /* Set interface state accordingly (5) */
578 if (drouter && drouter == &myself)
579 next_state = OSPF6_INTERFACE_DR;
580 else if (bdrouter && bdrouter == &myself)
581 next_state = OSPF6_INTERFACE_BDR;
582 else
583 next_state = OSPF6_INTERFACE_DROTHER;
584
585 /* If NBMA, schedule Start for each neighbor having priority of 0 (6) */
586 /* XXX */
587
588 /* If DR or BDR change, invoke AdjOK? for each neighbor (7) */
589 /* RFC 2328 section 12.4. Originating LSAs (3) will be handled
590 accordingly after AdjOK */
591 if (oi->drouter != (drouter ? drouter->router_id : htonl (0)) ||
592 oi->bdrouter != (bdrouter ? bdrouter->router_id : htonl (0)))
593 {
594 if (IS_OSPF6_DEBUG_INTERFACE)
595 zlog_debug ("DR Election on %s: DR: %s BDR: %s", oi->interface->name,
596 (drouter ? drouter->name : "0.0.0.0"),
597 (bdrouter ? bdrouter->name : "0.0.0.0"));
598
599 for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, node, on))
600 {
601 if (on->state < OSPF6_NEIGHBOR_TWOWAY)
602 continue;
603 /* Schedule AdjOK. */
604 thread_add_event (master, adj_ok, on, 0);
605 }
606 }
607
608 oi->drouter = (drouter ? drouter->router_id : htonl (0));
609 oi->bdrouter = (bdrouter ? bdrouter->router_id : htonl (0));
610 return next_state;
611 }
612
613 \f
614 /* Interface State Machine */
615 int
616 interface_up (struct thread *thread)
617 {
618 struct ospf6_interface *oi;
619
620 oi = (struct ospf6_interface *) THREAD_ARG (thread);
621 assert (oi && oi->interface);
622
623 if (IS_OSPF6_DEBUG_INTERFACE)
624 zlog_debug ("Interface Event %s: [InterfaceUp]",
625 oi->interface->name);
626
627 /* check physical interface is up */
628 if (! if_is_up (oi->interface))
629 {
630 if (IS_OSPF6_DEBUG_INTERFACE)
631 zlog_debug ("Interface %s is down, can't execute [InterfaceUp]",
632 oi->interface->name);
633 return 0;
634 }
635
636 /* if already enabled, do nothing */
637 if (oi->state > OSPF6_INTERFACE_DOWN)
638 {
639 if (IS_OSPF6_DEBUG_INTERFACE)
640 zlog_debug ("Interface %s already enabled",
641 oi->interface->name);
642 return 0;
643 }
644
645 /* Join AllSPFRouters */
646 ospf6_sso (oi->interface->ifindex, &allspfrouters6, IPV6_JOIN_GROUP);
647
648 /* Update interface route */
649 ospf6_interface_connected_route_update (oi->interface);
650
651 /* Schedule Hello */
652 if (! CHECK_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE))
653 thread_add_event (master, ospf6_hello_send, oi, 0);
654
655 /* decide next interface state */
656 if ((if_is_pointopoint (oi->interface)) ||
657 (oi->type == OSPF_IFTYPE_POINTOPOINT)) {
658 ospf6_interface_state_change (OSPF6_INTERFACE_POINTTOPOINT, oi);
659 }
660 else if (oi->priority == 0)
661 ospf6_interface_state_change (OSPF6_INTERFACE_DROTHER, oi);
662 else
663 {
664 ospf6_interface_state_change (OSPF6_INTERFACE_WAITING, oi);
665 thread_add_timer (master, wait_timer, oi, oi->dead_interval);
666 }
667
668 return 0;
669 }
670
671 int
672 wait_timer (struct thread *thread)
673 {
674 struct ospf6_interface *oi;
675
676 oi = (struct ospf6_interface *) THREAD_ARG (thread);
677 assert (oi && oi->interface);
678
679 if (IS_OSPF6_DEBUG_INTERFACE)
680 zlog_debug ("Interface Event %s: [WaitTimer]",
681 oi->interface->name);
682
683 if (oi->state == OSPF6_INTERFACE_WAITING)
684 ospf6_interface_state_change (dr_election (oi), oi);
685
686 return 0;
687 }
688
689 int
690 backup_seen (struct thread *thread)
691 {
692 struct ospf6_interface *oi;
693
694 oi = (struct ospf6_interface *) THREAD_ARG (thread);
695 assert (oi && oi->interface);
696
697 if (IS_OSPF6_DEBUG_INTERFACE)
698 zlog_debug ("Interface Event %s: [BackupSeen]",
699 oi->interface->name);
700
701 if (oi->state == OSPF6_INTERFACE_WAITING)
702 ospf6_interface_state_change (dr_election (oi), oi);
703
704 return 0;
705 }
706
707 int
708 neighbor_change (struct thread *thread)
709 {
710 struct ospf6_interface *oi;
711
712 oi = (struct ospf6_interface *) THREAD_ARG (thread);
713 assert (oi && oi->interface);
714
715 if (IS_OSPF6_DEBUG_INTERFACE)
716 zlog_debug ("Interface Event %s: [NeighborChange]",
717 oi->interface->name);
718
719 if (oi->state == OSPF6_INTERFACE_DROTHER ||
720 oi->state == OSPF6_INTERFACE_BDR ||
721 oi->state == OSPF6_INTERFACE_DR)
722 ospf6_interface_state_change (dr_election (oi), oi);
723
724 return 0;
725 }
726
727 int
728 interface_down (struct thread *thread)
729 {
730 struct ospf6_interface *oi;
731 struct listnode *node, *nnode;
732 struct ospf6_neighbor *on;
733
734 oi = (struct ospf6_interface *) THREAD_ARG (thread);
735 assert (oi && oi->interface);
736
737 if (IS_OSPF6_DEBUG_INTERFACE)
738 zlog_debug ("Interface Event %s: [InterfaceDown]",
739 oi->interface->name);
740
741 /* Leave AllSPFRouters */
742 if (oi->state > OSPF6_INTERFACE_DOWN)
743 ospf6_sso (oi->interface->ifindex, &allspfrouters6, IPV6_LEAVE_GROUP);
744
745 ospf6_interface_state_change (OSPF6_INTERFACE_DOWN, oi);
746
747 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
748 ospf6_neighbor_delete (on);
749
750 list_delete_all_node (oi->neighbor_list);
751
752 return 0;
753 }
754
755 \f
756 /* show specified interface structure */
757 static int
758 ospf6_interface_show (struct vty *vty, struct interface *ifp)
759 {
760 struct ospf6_interface *oi;
761 struct connected *c;
762 struct prefix *p;
763 struct listnode *i;
764 char strbuf[64], drouter[32], bdrouter[32];
765 const char *updown[3] = {"down", "up", NULL};
766 const char *type;
767 struct timeval res, now;
768 char duration[32];
769 struct ospf6_lsa *lsa;
770
771 /* check physical interface type */
772 if (if_is_loopback (ifp))
773 type = "LOOPBACK";
774 else if (if_is_broadcast (ifp))
775 type = "BROADCAST";
776 else if (if_is_pointopoint (ifp))
777 type = "POINTOPOINT";
778 else
779 type = "UNKNOWN";
780
781 vty_out (vty, "%s is %s, type %s%s",
782 ifp->name, updown[if_is_up (ifp)], type,
783 VNL);
784 vty_out (vty, " Interface ID: %d%s", ifp->ifindex, VNL);
785
786 if (ifp->info == NULL)
787 {
788 vty_out (vty, " OSPF not enabled on this interface%s", VNL);
789 return 0;
790 }
791 else
792 oi = (struct ospf6_interface *) ifp->info;
793
794 vty_out (vty, " Internet Address:%s", VNL);
795
796 for (ALL_LIST_ELEMENTS_RO (ifp->connected, i, c))
797 {
798 p = c->address;
799 prefix2str (p, strbuf, sizeof (strbuf));
800 switch (p->family)
801 {
802 case AF_INET:
803 vty_out (vty, " inet : %s%s", strbuf,
804 VNL);
805 break;
806 case AF_INET6:
807 vty_out (vty, " inet6: %s%s", strbuf,
808 VNL);
809 break;
810 default:
811 vty_out (vty, " ??? : %s%s", strbuf,
812 VNL);
813 break;
814 }
815 }
816
817 if (oi->area)
818 {
819 vty_out (vty, " Instance ID %d, Interface MTU %d (autodetect: %d)%s",
820 oi->instance_id, oi->ifmtu, ifp->mtu6, VNL);
821 vty_out (vty, " MTU mismatch detection: %s%s", oi->mtu_ignore ?
822 "disabled" : "enabled", VNL);
823 inet_ntop (AF_INET, &oi->area->area_id,
824 strbuf, sizeof (strbuf));
825 vty_out (vty, " Area ID %s, Cost %hu%s", strbuf, oi->cost,
826 VNL);
827 }
828 else
829 vty_out (vty, " Not Attached to Area%s", VNL);
830
831 vty_out (vty, " State %s, Transmit Delay %d sec, Priority %d%s",
832 ospf6_interface_state_str[oi->state],
833 oi->transdelay, oi->priority,
834 VNL);
835 vty_out (vty, " Timer intervals configured:%s", VNL);
836 vty_out (vty, " Hello %d, Dead %d, Retransmit %d%s",
837 oi->hello_interval, oi->dead_interval, oi->rxmt_interval,
838 VNL);
839
840 inet_ntop (AF_INET, &oi->drouter, drouter, sizeof (drouter));
841 inet_ntop (AF_INET, &oi->bdrouter, bdrouter, sizeof (bdrouter));
842 vty_out (vty, " DR: %s BDR: %s%s", drouter, bdrouter, VNL);
843
844 vty_out (vty, " Number of I/F scoped LSAs is %u%s",
845 oi->lsdb->count, VNL);
846
847 quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
848
849 timerclear (&res);
850 if (oi->thread_send_lsupdate)
851 timersub (&oi->thread_send_lsupdate->u.sands, &now, &res);
852 timerstring (&res, duration, sizeof (duration));
853 vty_out (vty, " %d Pending LSAs for LSUpdate in Time %s [thread %s]%s",
854 oi->lsupdate_list->count, duration,
855 (oi->thread_send_lsupdate ? "on" : "off"),
856 VNL);
857 for (lsa = ospf6_lsdb_head (oi->lsupdate_list); lsa;
858 lsa = ospf6_lsdb_next (lsa))
859 vty_out (vty, " %s%s", lsa->name, VNL);
860
861 timerclear (&res);
862 if (oi->thread_send_lsack)
863 timersub (&oi->thread_send_lsack->u.sands, &now, &res);
864 timerstring (&res, duration, sizeof (duration));
865 vty_out (vty, " %d Pending LSAs for LSAck in Time %s [thread %s]%s",
866 oi->lsack_list->count, duration,
867 (oi->thread_send_lsack ? "on" : "off"),
868 VNL);
869 for (lsa = ospf6_lsdb_head (oi->lsack_list); lsa;
870 lsa = ospf6_lsdb_next (lsa))
871 vty_out (vty, " %s%s", lsa->name, VNL);
872
873 return 0;
874 }
875
876 /* show interface */
877 DEFUN (show_ipv6_ospf6_interface,
878 show_ipv6_ospf6_interface_ifname_cmd,
879 "show ipv6 ospf6 interface IFNAME",
880 SHOW_STR
881 IP6_STR
882 OSPF6_STR
883 INTERFACE_STR
884 IFNAME_STR
885 )
886 {
887 struct interface *ifp;
888 struct listnode *i;
889
890 if (argc)
891 {
892 ifp = if_lookup_by_name (argv[0]);
893 if (ifp == NULL)
894 {
895 vty_out (vty, "No such Interface: %s%s", argv[0],
896 VNL);
897 return CMD_WARNING;
898 }
899 ospf6_interface_show (vty, ifp);
900 }
901 else
902 {
903 for (ALL_LIST_ELEMENTS_RO (iflist, i, ifp))
904 ospf6_interface_show (vty, ifp);
905 }
906
907 return CMD_SUCCESS;
908 }
909
910 ALIAS (show_ipv6_ospf6_interface,
911 show_ipv6_ospf6_interface_cmd,
912 "show ipv6 ospf6 interface",
913 SHOW_STR
914 IP6_STR
915 OSPF6_STR
916 INTERFACE_STR
917 )
918
919 DEFUN (show_ipv6_ospf6_interface_ifname_prefix,
920 show_ipv6_ospf6_interface_ifname_prefix_cmd,
921 "show ipv6 ospf6 interface IFNAME prefix",
922 SHOW_STR
923 IP6_STR
924 OSPF6_STR
925 INTERFACE_STR
926 IFNAME_STR
927 "Display connected prefixes to advertise\n"
928 )
929 {
930 struct interface *ifp;
931 struct ospf6_interface *oi;
932
933 ifp = if_lookup_by_name (argv[0]);
934 if (ifp == NULL)
935 {
936 vty_out (vty, "No such Interface: %s%s", argv[0], VNL);
937 return CMD_WARNING;
938 }
939
940 oi = ifp->info;
941 if (oi == NULL)
942 {
943 vty_out (vty, "OSPFv3 is not enabled on %s%s", argv[0], VNL);
944 return CMD_WARNING;
945 }
946
947 argc--;
948 argv++;
949 ospf6_route_table_show (vty, argc, argv, oi->route_connected);
950
951 return CMD_SUCCESS;
952 }
953
954 ALIAS (show_ipv6_ospf6_interface_ifname_prefix,
955 show_ipv6_ospf6_interface_ifname_prefix_detail_cmd,
956 "show ipv6 ospf6 interface IFNAME prefix (X:X::X:X|X:X::X:X/M|detail)",
957 SHOW_STR
958 IP6_STR
959 OSPF6_STR
960 INTERFACE_STR
961 IFNAME_STR
962 "Display connected prefixes to advertise\n"
963 OSPF6_ROUTE_ADDRESS_STR
964 OSPF6_ROUTE_PREFIX_STR
965 "Display details of the prefixes\n"
966 )
967
968 ALIAS (show_ipv6_ospf6_interface_ifname_prefix,
969 show_ipv6_ospf6_interface_ifname_prefix_match_cmd,
970 "show ipv6 ospf6 interface IFNAME prefix X:X::X:X/M (match|detail)",
971 SHOW_STR
972 IP6_STR
973 OSPF6_STR
974 INTERFACE_STR
975 IFNAME_STR
976 "Display connected prefixes to advertise\n"
977 OSPF6_ROUTE_PREFIX_STR
978 OSPF6_ROUTE_MATCH_STR
979 "Display details of the prefixes\n"
980 )
981
982 DEFUN (show_ipv6_ospf6_interface_prefix,
983 show_ipv6_ospf6_interface_prefix_cmd,
984 "show ipv6 ospf6 interface prefix",
985 SHOW_STR
986 IP6_STR
987 OSPF6_STR
988 INTERFACE_STR
989 "Display connected prefixes to advertise\n"
990 )
991 {
992 struct listnode *i;
993 struct ospf6_interface *oi;
994 struct interface *ifp;
995
996 for (ALL_LIST_ELEMENTS_RO (iflist, i, ifp))
997 {
998 oi = (struct ospf6_interface *) ifp->info;
999 if (oi == NULL)
1000 continue;
1001
1002 ospf6_route_table_show (vty, argc, argv, oi->route_connected);
1003 }
1004
1005 return CMD_SUCCESS;
1006 }
1007
1008 ALIAS (show_ipv6_ospf6_interface_prefix,
1009 show_ipv6_ospf6_interface_prefix_detail_cmd,
1010 "show ipv6 ospf6 interface prefix (X:X::X:X|X:X::X:X/M|detail)",
1011 SHOW_STR
1012 IP6_STR
1013 OSPF6_STR
1014 INTERFACE_STR
1015 "Display connected prefixes to advertise\n"
1016 OSPF6_ROUTE_ADDRESS_STR
1017 OSPF6_ROUTE_PREFIX_STR
1018 "Display details of the prefixes\n"
1019 )
1020
1021 ALIAS (show_ipv6_ospf6_interface_prefix,
1022 show_ipv6_ospf6_interface_prefix_match_cmd,
1023 "show ipv6 ospf6 interface prefix X:X::X:X/M (match|detail)",
1024 SHOW_STR
1025 IP6_STR
1026 OSPF6_STR
1027 INTERFACE_STR
1028 "Display connected prefixes to advertise\n"
1029 OSPF6_ROUTE_PREFIX_STR
1030 OSPF6_ROUTE_MATCH_STR
1031 "Display details of the prefixes\n"
1032 )
1033
1034
1035 /* interface variable set command */
1036 DEFUN (ipv6_ospf6_ifmtu,
1037 ipv6_ospf6_ifmtu_cmd,
1038 "ipv6 ospf6 ifmtu <1-65535>",
1039 IP6_STR
1040 OSPF6_STR
1041 "Interface MTU\n"
1042 "OSPFv3 Interface MTU\n"
1043 )
1044 {
1045 struct ospf6_interface *oi;
1046 struct interface *ifp;
1047 unsigned int ifmtu, iobuflen;
1048 struct listnode *node, *nnode;
1049 struct ospf6_neighbor *on;
1050
1051 ifp = (struct interface *) vty->index;
1052 assert (ifp);
1053
1054 oi = (struct ospf6_interface *) ifp->info;
1055 if (oi == NULL)
1056 oi = ospf6_interface_create (ifp);
1057 assert (oi);
1058
1059 ifmtu = strtol (argv[0], NULL, 10);
1060
1061 if (oi->ifmtu == ifmtu)
1062 return CMD_SUCCESS;
1063
1064 if (ifp->mtu6 != 0 && ifp->mtu6 < ifmtu)
1065 {
1066 vty_out (vty, "%s's ospf6 ifmtu cannot go beyond physical mtu (%d)%s",
1067 ifp->name, ifp->mtu6, VNL);
1068 return CMD_WARNING;
1069 }
1070
1071 if (oi->ifmtu < ifmtu)
1072 {
1073 iobuflen = ospf6_iobuf_size (ifmtu);
1074 if (iobuflen < ifmtu)
1075 {
1076 vty_out (vty, "%s's ifmtu is adjusted to I/O buffer size (%d).%s",
1077 ifp->name, iobuflen, VNL);
1078 oi->ifmtu = iobuflen;
1079 }
1080 else
1081 oi->ifmtu = ifmtu;
1082 }
1083 else
1084 oi->ifmtu = ifmtu;
1085
1086 /* re-establish adjacencies */
1087 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
1088 {
1089 THREAD_OFF (on->inactivity_timer);
1090 thread_add_event (master, inactivity_timer, on, 0);
1091 }
1092
1093 return CMD_SUCCESS;
1094 }
1095
1096 DEFUN (no_ipv6_ospf6_ifmtu,
1097 no_ipv6_ospf6_ifmtu_cmd,
1098 "no ipv6 ospf6 ifmtu",
1099 NO_STR
1100 IP6_STR
1101 OSPF6_STR
1102 "Interface MTU\n"
1103 )
1104 {
1105 struct ospf6_interface *oi;
1106 struct interface *ifp;
1107 unsigned int iobuflen;
1108 struct listnode *node, *nnode;
1109 struct ospf6_neighbor *on;
1110
1111 ifp = (struct interface *) vty->index;
1112 assert (ifp);
1113
1114 oi = (struct ospf6_interface *) ifp->info;
1115 if (oi == NULL)
1116 oi = ospf6_interface_create (ifp);
1117 assert (oi);
1118
1119 if (oi->ifmtu < ifp->mtu)
1120 {
1121 iobuflen = ospf6_iobuf_size (ifp->mtu);
1122 if (iobuflen < ifp->mtu)
1123 {
1124 vty_out (vty, "%s's ifmtu is adjusted to I/O buffer size (%d).%s",
1125 ifp->name, iobuflen, VNL);
1126 oi->ifmtu = iobuflen;
1127 }
1128 else
1129 oi->ifmtu = ifp->mtu;
1130 }
1131 else
1132 oi->ifmtu = ifp->mtu;
1133
1134 /* re-establish adjacencies */
1135 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
1136 {
1137 THREAD_OFF (on->inactivity_timer);
1138 thread_add_event (master, inactivity_timer, on, 0);
1139 }
1140
1141 return CMD_SUCCESS;
1142 }
1143
1144 DEFUN (ipv6_ospf6_cost,
1145 ipv6_ospf6_cost_cmd,
1146 "ipv6 ospf6 cost <1-65535>",
1147 IP6_STR
1148 OSPF6_STR
1149 "Interface cost\n"
1150 "Outgoing metric of this interface\n"
1151 )
1152 {
1153 struct ospf6_interface *oi;
1154 struct interface *ifp;
1155 unsigned long int lcost;
1156
1157 ifp = (struct interface *) vty->index;
1158 assert (ifp);
1159
1160 oi = (struct ospf6_interface *) ifp->info;
1161 if (oi == NULL)
1162 oi = ospf6_interface_create (ifp);
1163 assert (oi);
1164
1165 lcost = strtol (argv[0], NULL, 10);
1166
1167 if (lcost > UINT32_MAX)
1168 {
1169 vty_out (vty, "Cost %ld is out of range%s", lcost, VNL);
1170 return CMD_WARNING;
1171 }
1172
1173 if (oi->cost == lcost)
1174 return CMD_SUCCESS;
1175
1176 oi->cost = lcost;
1177
1178 /* update cost held in route_connected list in ospf6_interface */
1179 ospf6_interface_connected_route_update (oi->interface);
1180
1181 /* execute LSA hooks */
1182 if (oi->area)
1183 {
1184 OSPF6_LINK_LSA_SCHEDULE (oi);
1185 OSPF6_ROUTER_LSA_SCHEDULE (oi->area);
1186 OSPF6_NETWORK_LSA_SCHEDULE (oi);
1187 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
1188 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
1189 }
1190
1191 return CMD_SUCCESS;
1192 }
1193
1194 DEFUN (ipv6_ospf6_hellointerval,
1195 ipv6_ospf6_hellointerval_cmd,
1196 "ipv6 ospf6 hello-interval <1-65535>",
1197 IP6_STR
1198 OSPF6_STR
1199 "Interval time of Hello packets\n"
1200 SECONDS_STR
1201 )
1202 {
1203 struct ospf6_interface *oi;
1204 struct interface *ifp;
1205
1206 ifp = (struct interface *) vty->index;
1207 assert (ifp);
1208
1209 oi = (struct ospf6_interface *) ifp->info;
1210 if (oi == NULL)
1211 oi = ospf6_interface_create (ifp);
1212 assert (oi);
1213
1214 oi->hello_interval = strtol (argv[0], NULL, 10);
1215 return CMD_SUCCESS;
1216 }
1217
1218 /* interface variable set command */
1219 DEFUN (ipv6_ospf6_deadinterval,
1220 ipv6_ospf6_deadinterval_cmd,
1221 "ipv6 ospf6 dead-interval <1-65535>",
1222 IP6_STR
1223 OSPF6_STR
1224 "Interval time after which a neighbor is declared down\n"
1225 SECONDS_STR
1226 )
1227 {
1228 struct ospf6_interface *oi;
1229 struct interface *ifp;
1230
1231 ifp = (struct interface *) vty->index;
1232 assert (ifp);
1233
1234 oi = (struct ospf6_interface *) ifp->info;
1235 if (oi == NULL)
1236 oi = ospf6_interface_create (ifp);
1237 assert (oi);
1238
1239 oi->dead_interval = strtol (argv[0], NULL, 10);
1240 return CMD_SUCCESS;
1241 }
1242
1243 /* interface variable set command */
1244 DEFUN (ipv6_ospf6_transmitdelay,
1245 ipv6_ospf6_transmitdelay_cmd,
1246 "ipv6 ospf6 transmit-delay <1-3600>",
1247 IP6_STR
1248 OSPF6_STR
1249 "Transmit delay of this interface\n"
1250 SECONDS_STR
1251 )
1252 {
1253 struct ospf6_interface *oi;
1254 struct interface *ifp;
1255
1256 ifp = (struct interface *) vty->index;
1257 assert (ifp);
1258
1259 oi = (struct ospf6_interface *) ifp->info;
1260 if (oi == NULL)
1261 oi = ospf6_interface_create (ifp);
1262 assert (oi);
1263
1264 oi->transdelay = strtol (argv[0], NULL, 10);
1265 return CMD_SUCCESS;
1266 }
1267
1268 /* interface variable set command */
1269 DEFUN (ipv6_ospf6_retransmitinterval,
1270 ipv6_ospf6_retransmitinterval_cmd,
1271 "ipv6 ospf6 retransmit-interval <1-65535>",
1272 IP6_STR
1273 OSPF6_STR
1274 "Time between retransmitting lost link state advertisements\n"
1275 SECONDS_STR
1276 )
1277 {
1278 struct ospf6_interface *oi;
1279 struct interface *ifp;
1280
1281 ifp = (struct interface *) vty->index;
1282 assert (ifp);
1283
1284 oi = (struct ospf6_interface *) ifp->info;
1285 if (oi == NULL)
1286 oi = ospf6_interface_create (ifp);
1287 assert (oi);
1288
1289 oi->rxmt_interval = strtol (argv[0], NULL, 10);
1290 return CMD_SUCCESS;
1291 }
1292
1293 /* interface variable set command */
1294 DEFUN (ipv6_ospf6_priority,
1295 ipv6_ospf6_priority_cmd,
1296 "ipv6 ospf6 priority <0-255>",
1297 IP6_STR
1298 OSPF6_STR
1299 "Router priority\n"
1300 "Priority value\n"
1301 )
1302 {
1303 struct ospf6_interface *oi;
1304 struct interface *ifp;
1305
1306 ifp = (struct interface *) vty->index;
1307 assert (ifp);
1308
1309 oi = (struct ospf6_interface *) ifp->info;
1310 if (oi == NULL)
1311 oi = ospf6_interface_create (ifp);
1312 assert (oi);
1313
1314 oi->priority = strtol (argv[0], NULL, 10);
1315
1316 if (oi->area)
1317 ospf6_interface_state_change (dr_election (oi), oi);
1318
1319 return CMD_SUCCESS;
1320 }
1321
1322 DEFUN (ipv6_ospf6_instance,
1323 ipv6_ospf6_instance_cmd,
1324 "ipv6 ospf6 instance-id <0-255>",
1325 IP6_STR
1326 OSPF6_STR
1327 "Instance ID for this interface\n"
1328 "Instance ID value\n"
1329 )
1330 {
1331 struct ospf6_interface *oi;
1332 struct interface *ifp;
1333
1334 ifp = (struct interface *)vty->index;
1335 assert (ifp);
1336
1337 oi = (struct ospf6_interface *)ifp->info;
1338 if (oi == NULL)
1339 oi = ospf6_interface_create (ifp);
1340 assert (oi);
1341
1342 oi->instance_id = strtol (argv[0], NULL, 10);
1343 return CMD_SUCCESS;
1344 }
1345
1346 DEFUN (ipv6_ospf6_passive,
1347 ipv6_ospf6_passive_cmd,
1348 "ipv6 ospf6 passive",
1349 IP6_STR
1350 OSPF6_STR
1351 "passive interface, No adjacency will be formed on this interface\n"
1352 )
1353 {
1354 struct ospf6_interface *oi;
1355 struct interface *ifp;
1356 struct listnode *node, *nnode;
1357 struct ospf6_neighbor *on;
1358
1359 ifp = (struct interface *) vty->index;
1360 assert (ifp);
1361
1362 oi = (struct ospf6_interface *) ifp->info;
1363 if (oi == NULL)
1364 oi = ospf6_interface_create (ifp);
1365 assert (oi);
1366
1367 SET_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE);
1368 THREAD_OFF (oi->thread_send_hello);
1369
1370 for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
1371 {
1372 THREAD_OFF (on->inactivity_timer);
1373 thread_add_event (master, inactivity_timer, on, 0);
1374 }
1375
1376 return CMD_SUCCESS;
1377 }
1378
1379 DEFUN (no_ipv6_ospf6_passive,
1380 no_ipv6_ospf6_passive_cmd,
1381 "no ipv6 ospf6 passive",
1382 NO_STR
1383 IP6_STR
1384 OSPF6_STR
1385 "passive interface: No Adjacency will be formed on this I/F\n"
1386 )
1387 {
1388 struct ospf6_interface *oi;
1389 struct interface *ifp;
1390
1391 ifp = (struct interface *) vty->index;
1392 assert (ifp);
1393
1394 oi = (struct ospf6_interface *) ifp->info;
1395 if (oi == NULL)
1396 oi = ospf6_interface_create (ifp);
1397 assert (oi);
1398
1399 UNSET_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE);
1400 THREAD_OFF (oi->thread_send_hello);
1401 oi->thread_send_hello =
1402 thread_add_event (master, ospf6_hello_send, oi, 0);
1403
1404 return CMD_SUCCESS;
1405 }
1406
1407 DEFUN (ipv6_ospf6_mtu_ignore,
1408 ipv6_ospf6_mtu_ignore_cmd,
1409 "ipv6 ospf6 mtu-ignore",
1410 IP6_STR
1411 OSPF6_STR
1412 "Ignore MTU mismatch on this interface\n"
1413 )
1414 {
1415 struct ospf6_interface *oi;
1416 struct interface *ifp;
1417
1418 ifp = (struct interface *) vty->index;
1419 assert (ifp);
1420
1421 oi = (struct ospf6_interface *) ifp->info;
1422 if (oi == NULL)
1423 oi = ospf6_interface_create (ifp);
1424 assert (oi);
1425
1426 oi->mtu_ignore = 1;
1427
1428 return CMD_SUCCESS;
1429 }
1430
1431 DEFUN (no_ipv6_ospf6_mtu_ignore,
1432 no_ipv6_ospf6_mtu_ignore_cmd,
1433 "no ipv6 ospf6 mtu-ignore",
1434 NO_STR
1435 IP6_STR
1436 OSPF6_STR
1437 "Ignore MTU mismatch on this interface\n"
1438 )
1439 {
1440 struct ospf6_interface *oi;
1441 struct interface *ifp;
1442
1443 ifp = (struct interface *) vty->index;
1444 assert (ifp);
1445
1446 oi = (struct ospf6_interface *) ifp->info;
1447 if (oi == NULL)
1448 oi = ospf6_interface_create (ifp);
1449 assert (oi);
1450
1451 oi->mtu_ignore = 0;
1452
1453 return CMD_SUCCESS;
1454 }
1455
1456 DEFUN (ipv6_ospf6_advertise_prefix_list,
1457 ipv6_ospf6_advertise_prefix_list_cmd,
1458 "ipv6 ospf6 advertise prefix-list WORD",
1459 IP6_STR
1460 OSPF6_STR
1461 "Advertising options\n"
1462 "Filter prefix using prefix-list\n"
1463 "Prefix list name\n"
1464 )
1465 {
1466 struct ospf6_interface *oi;
1467 struct interface *ifp;
1468
1469 ifp = (struct interface *) vty->index;
1470 assert (ifp);
1471
1472 oi = (struct ospf6_interface *) ifp->info;
1473 if (oi == NULL)
1474 oi = ospf6_interface_create (ifp);
1475 assert (oi);
1476
1477 if (oi->plist_name)
1478 XFREE (MTYPE_PREFIX_LIST_STR, oi->plist_name);
1479 oi->plist_name = XSTRDUP (MTYPE_PREFIX_LIST_STR, argv[0]);
1480
1481 ospf6_interface_connected_route_update (oi->interface);
1482
1483 if (oi->area)
1484 {
1485 OSPF6_LINK_LSA_SCHEDULE (oi);
1486 if (oi->state == OSPF6_INTERFACE_DR)
1487 {
1488 OSPF6_NETWORK_LSA_SCHEDULE (oi);
1489 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
1490 }
1491 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
1492 }
1493
1494 return CMD_SUCCESS;
1495 }
1496
1497 DEFUN (no_ipv6_ospf6_advertise_prefix_list,
1498 no_ipv6_ospf6_advertise_prefix_list_cmd,
1499 "no ipv6 ospf6 advertise prefix-list",
1500 NO_STR
1501 IP6_STR
1502 OSPF6_STR
1503 "Advertising options\n"
1504 "Filter prefix using prefix-list\n"
1505 )
1506 {
1507 struct ospf6_interface *oi;
1508 struct interface *ifp;
1509
1510 ifp = (struct interface *) vty->index;
1511 assert (ifp);
1512
1513 oi = (struct ospf6_interface *) ifp->info;
1514 if (oi == NULL)
1515 oi = ospf6_interface_create (ifp);
1516 assert (oi);
1517
1518 if (oi->plist_name)
1519 {
1520 XFREE (MTYPE_PREFIX_LIST_STR, oi->plist_name);
1521 oi->plist_name = NULL;
1522 }
1523
1524 ospf6_interface_connected_route_update (oi->interface);
1525
1526 if (oi->area)
1527 {
1528 OSPF6_LINK_LSA_SCHEDULE (oi);
1529 if (oi->state == OSPF6_INTERFACE_DR)
1530 {
1531 OSPF6_NETWORK_LSA_SCHEDULE (oi);
1532 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (oi);
1533 }
1534 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (oi->area);
1535 }
1536
1537 return CMD_SUCCESS;
1538 }
1539
1540 DEFUN (ipv6_ospf6_network,
1541 ipv6_ospf6_network_cmd,
1542 "ipv6 ospf6 network (broadcast|point-to-point)",
1543 IP6_STR
1544 OSPF6_STR
1545 "Network Type\n"
1546 "Specify OSPFv6 broadcast network\n"
1547 "Specify OSPF6 point-to-point network\n"
1548 )
1549 {
1550 struct ospf6_interface *oi;
1551 struct interface *ifp;
1552
1553 ifp = (struct interface *) vty->index;
1554 assert (ifp);
1555
1556 oi = (struct ospf6_interface *) ifp->info;
1557 if (oi == NULL) {
1558 oi = ospf6_interface_create (ifp);
1559 }
1560 assert (oi);
1561
1562 if (strncmp (argv[0], "b", 1) == 0)
1563 {
1564 if (oi->type == OSPF_IFTYPE_BROADCAST)
1565 return CMD_SUCCESS;
1566
1567 oi->type = OSPF_IFTYPE_BROADCAST;
1568 }
1569 else if (strncmp (argv[0], "point-to-p", 10) == 0)
1570 {
1571 if (oi->type == OSPF_IFTYPE_POINTOPOINT) {
1572 return CMD_SUCCESS;
1573 }
1574 oi->type = OSPF_IFTYPE_POINTOPOINT;
1575 }
1576
1577 /* Reset the interface */
1578 thread_add_event (master, interface_down, oi, 0);
1579 thread_add_event (master, interface_up, oi, 0);
1580
1581 return CMD_SUCCESS;
1582 }
1583
1584 DEFUN (no_ipv6_ospf6_network,
1585 no_ipv6_ospf6_network_cmd,
1586 "no ipv6 ospf6 network",
1587 NO_STR
1588 IP6_STR
1589 OSPF6_STR
1590 "Network Type\n"
1591 "Default to whatever interface type system specifies"
1592 )
1593 {
1594 struct ospf6_interface *oi;
1595 struct interface *ifp;
1596 int type;
1597
1598 ifp = (struct interface *) vty->index;
1599 assert (ifp);
1600
1601 oi = (struct ospf6_interface *) ifp->info;
1602 if (oi == NULL) {
1603 return CMD_SUCCESS;
1604 }
1605
1606 type = ospf6_default_iftype (ifp);
1607 if (oi->type == type)
1608 {
1609 return CMD_SUCCESS;
1610 }
1611 oi->type = type;
1612
1613 /* Reset the interface */
1614 thread_add_event (master, interface_down, oi, 0);
1615 thread_add_event (master, interface_up, oi, 0);
1616
1617 return CMD_SUCCESS;
1618 }
1619
1620 static int
1621 config_write_ospf6_interface (struct vty *vty)
1622 {
1623 struct listnode *i;
1624 struct ospf6_interface *oi;
1625 struct interface *ifp;
1626
1627 for (ALL_LIST_ELEMENTS_RO (iflist, i, ifp))
1628 {
1629 oi = (struct ospf6_interface *) ifp->info;
1630 if (oi == NULL)
1631 continue;
1632
1633 vty_out (vty, "interface %s%s",
1634 oi->interface->name, VNL);
1635
1636 if (ifp->desc)
1637 vty_out (vty, " description %s%s", ifp->desc, VNL);
1638 if (ifp->mtu6 != oi->ifmtu)
1639 vty_out (vty, " ipv6 ospf6 ifmtu %d%s", oi->ifmtu, VNL);
1640
1641 if (oi->cost != OSPF6_INTERFACE_COST)
1642 vty_out (vty, " ipv6 ospf6 cost %d%s",
1643 oi->cost, VNL);
1644
1645 if (oi->hello_interval != OSPF6_INTERFACE_HELLO_INTERVAL)
1646 vty_out (vty, " ipv6 ospf6 hello-interval %d%s",
1647 oi->hello_interval, VNL);
1648
1649 if (oi->dead_interval != OSPF6_INTERFACE_DEAD_INTERVAL)
1650 vty_out (vty, " ipv6 ospf6 dead-interval %d%s",
1651 oi->dead_interval, VNL);
1652
1653 if (oi->rxmt_interval != OSPF6_INTERFACE_RXMT_INTERVAL)
1654 vty_out (vty, " ipv6 ospf6 retransmit-interval %d%s",
1655 oi->rxmt_interval, VNL);
1656
1657 if (oi->priority != OSPF6_INTERFACE_PRIORITY)
1658 vty_out (vty, " ipv6 ospf6 priority %d%s",
1659 oi->priority, VNL);
1660
1661 if (oi->transdelay != OSPF6_INTERFACE_TRANSDELAY)
1662 vty_out (vty, " ipv6 ospf6 transmit-delay %d%s",
1663 oi->transdelay, VNL);
1664
1665 if (oi->instance_id != OSPF6_INTERFACE_INSTANCE_ID)
1666 vty_out (vty, " ipv6 ospf6 instance-id %d%s",
1667 oi->instance_id, VNL);
1668
1669 if (oi->plist_name)
1670 vty_out (vty, " ipv6 ospf6 advertise prefix-list %s%s",
1671 oi->plist_name, VNL);
1672
1673 if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE))
1674 vty_out (vty, " ipv6 ospf6 passive%s", VNL);
1675
1676 if (oi->mtu_ignore)
1677 vty_out (vty, " ipv6 ospf6 mtu-ignore%s", VNL);
1678
1679 if (oi->type == OSPF_IFTYPE_POINTOPOINT)
1680 vty_out (vty, " ipv6 ospf6 network point-to-point%s", VNL);
1681 else if (oi->type == OSPF_IFTYPE_BROADCAST)
1682 vty_out (vty, " ipv6 ospf6 network broadcast%s", VNL);
1683
1684 vty_out (vty, "!%s", VNL);
1685 }
1686 return 0;
1687 }
1688
1689 static struct cmd_node interface_node =
1690 {
1691 INTERFACE_NODE,
1692 "%s(config-if)# ",
1693 1 /* VTYSH */
1694 };
1695
1696 void
1697 ospf6_interface_init (void)
1698 {
1699 /* Install interface node. */
1700 install_node (&interface_node, config_write_ospf6_interface);
1701
1702 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_cmd);
1703 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_cmd);
1704 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_detail_cmd);
1705 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_match_cmd);
1706 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_cmd);
1707 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_cmd);
1708 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_detail_cmd);
1709 install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_match_cmd);
1710 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_cmd);
1711 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_prefix_cmd);
1712 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_prefix_detail_cmd);
1713 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_prefix_match_cmd);
1714 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_cmd);
1715 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_prefix_cmd);
1716 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_prefix_detail_cmd);
1717 install_element (ENABLE_NODE, &show_ipv6_ospf6_interface_ifname_prefix_match_cmd);
1718
1719 install_element (CONFIG_NODE, &interface_cmd);
1720 install_default (INTERFACE_NODE);
1721 install_element (INTERFACE_NODE, &interface_desc_cmd);
1722 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
1723 install_element (INTERFACE_NODE, &ipv6_ospf6_cost_cmd);
1724 install_element (INTERFACE_NODE, &ipv6_ospf6_ifmtu_cmd);
1725 install_element (INTERFACE_NODE, &no_ipv6_ospf6_ifmtu_cmd);
1726 install_element (INTERFACE_NODE, &ipv6_ospf6_deadinterval_cmd);
1727 install_element (INTERFACE_NODE, &ipv6_ospf6_hellointerval_cmd);
1728 install_element (INTERFACE_NODE, &ipv6_ospf6_priority_cmd);
1729 install_element (INTERFACE_NODE, &ipv6_ospf6_retransmitinterval_cmd);
1730 install_element (INTERFACE_NODE, &ipv6_ospf6_transmitdelay_cmd);
1731 install_element (INTERFACE_NODE, &ipv6_ospf6_instance_cmd);
1732
1733 install_element (INTERFACE_NODE, &ipv6_ospf6_passive_cmd);
1734 install_element (INTERFACE_NODE, &no_ipv6_ospf6_passive_cmd);
1735
1736 install_element (INTERFACE_NODE, &ipv6_ospf6_mtu_ignore_cmd);
1737 install_element (INTERFACE_NODE, &no_ipv6_ospf6_mtu_ignore_cmd);
1738
1739 install_element (INTERFACE_NODE, &ipv6_ospf6_advertise_prefix_list_cmd);
1740 install_element (INTERFACE_NODE, &no_ipv6_ospf6_advertise_prefix_list_cmd);
1741
1742 install_element (INTERFACE_NODE, &ipv6_ospf6_network_cmd);
1743 install_element (INTERFACE_NODE, &no_ipv6_ospf6_network_cmd);
1744 }
1745
1746 DEFUN (debug_ospf6_interface,
1747 debug_ospf6_interface_cmd,
1748 "debug ospf6 interface",
1749 DEBUG_STR
1750 OSPF6_STR
1751 "Debug OSPFv3 Interface\n"
1752 )
1753 {
1754 OSPF6_DEBUG_INTERFACE_ON ();
1755 return CMD_SUCCESS;
1756 }
1757
1758 DEFUN (no_debug_ospf6_interface,
1759 no_debug_ospf6_interface_cmd,
1760 "no debug ospf6 interface",
1761 NO_STR
1762 DEBUG_STR
1763 OSPF6_STR
1764 "Debug OSPFv3 Interface\n"
1765 )
1766 {
1767 OSPF6_DEBUG_INTERFACE_OFF ();
1768 return CMD_SUCCESS;
1769 }
1770
1771 int
1772 config_write_ospf6_debug_interface (struct vty *vty)
1773 {
1774 if (IS_OSPF6_DEBUG_INTERFACE)
1775 vty_out (vty, "debug ospf6 interface%s", VNL);
1776 return 0;
1777 }
1778
1779 void
1780 install_element_ospf6_debug_interface (void)
1781 {
1782 install_element (ENABLE_NODE, &debug_ospf6_interface_cmd);
1783 install_element (ENABLE_NODE, &no_debug_ospf6_interface_cmd);
1784 install_element (CONFIG_NODE, &debug_ospf6_interface_cmd);
1785 install_element (CONFIG_NODE, &no_debug_ospf6_interface_cmd);
1786 }
1787
1788