2 * Copyright (C) 2003 Yasuhiro Ohara
4 * This file is part of GNU Zebra.
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
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.
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
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"
44 #include "ospf6_bfd.h"
46 DEFINE_MTYPE_STATIC(OSPF6D
, CFG_PLIST_NAME
, "configured prefix list names")
47 DEFINE_QOBJ_TYPE(ospf6_interface
)
48 DEFINE_HOOK(ospf6_interface_change
,
49 (struct ospf6_interface
* oi
, int state
, int old_state
),
50 (oi
, state
, old_state
))
52 unsigned char conf_debug_ospf6_interface
= 0;
54 const char *ospf6_interface_state_str
[] = {
55 "None", "Down", "Loopback", "Waiting", "PointToPoint",
56 "DROther", "BDR", "DR", NULL
};
58 struct ospf6_interface
*ospf6_interface_lookup_by_ifindex(ifindex_t ifindex
)
60 struct ospf6_interface
*oi
;
61 struct interface
*ifp
;
63 ifp
= if_lookup_by_index(ifindex
, VRF_DEFAULT
);
65 return (struct ospf6_interface
*)NULL
;
67 oi
= (struct ospf6_interface
*)ifp
->info
;
71 /* schedule routing table recalculation */
72 static void ospf6_interface_lsdb_hook(struct ospf6_lsa
*lsa
,
75 struct ospf6_interface
*oi
;
81 switch (ntohs(lsa
->header
->type
)) {
82 case OSPF6_LSTYPE_LINK
:
83 if (oi
->state
== OSPF6_INTERFACE_DR
)
84 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
86 ospf6_spf_schedule(oi
->area
->ospf6
, reason
);
94 static void ospf6_interface_lsdb_hook_add(struct ospf6_lsa
*lsa
)
96 ospf6_interface_lsdb_hook(lsa
, ospf6_lsadd_to_spf_reason(lsa
));
99 static void ospf6_interface_lsdb_hook_remove(struct ospf6_lsa
*lsa
)
101 ospf6_interface_lsdb_hook(lsa
, ospf6_lsremove_to_spf_reason(lsa
));
104 static uint8_t ospf6_default_iftype(struct interface
*ifp
)
106 if (if_is_pointopoint(ifp
))
107 return OSPF_IFTYPE_POINTOPOINT
;
108 else if (if_is_loopback(ifp
))
109 return OSPF_IFTYPE_LOOPBACK
;
111 return OSPF_IFTYPE_BROADCAST
;
114 static uint32_t ospf6_interface_get_cost(struct ospf6_interface
*oi
)
116 /* If all else fails, use default OSPF cost */
120 /* interface speed and bw can be 0 in some platforms,
121 * use ospf default bw. If bw is configured then it would
124 if (!oi
->interface
->bandwidth
&& oi
->interface
->speed
) {
125 bw
= oi
->interface
->speed
;
127 bw
= oi
->interface
->bandwidth
? oi
->interface
->bandwidth
128 : OSPF6_INTERFACE_BANDWIDTH
;
131 refbw
= ospf6
? ospf6
->ref_bandwidth
: OSPF6_REFERENCE_BANDWIDTH
;
133 /* A specifed ip ospf cost overrides a calculated one. */
134 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_NOAUTOCOST
))
137 cost
= (uint32_t)((double)refbw
/ (double)bw
+ (double)0.5);
140 else if (cost
> UINT32_MAX
)
147 static void ospf6_interface_force_recalculate_cost(struct ospf6_interface
*oi
)
149 /* update cost held in route_connected list in ospf6_interface */
150 ospf6_interface_connected_route_update(oi
->interface
);
152 /* execute LSA hooks */
154 OSPF6_LINK_LSA_SCHEDULE(oi
);
155 OSPF6_ROUTER_LSA_SCHEDULE(oi
->area
);
156 OSPF6_NETWORK_LSA_SCHEDULE(oi
);
157 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
158 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
162 static void ospf6_interface_recalculate_cost(struct ospf6_interface
*oi
)
166 newcost
= ospf6_interface_get_cost(oi
);
167 if (newcost
== oi
->cost
)
171 ospf6_interface_force_recalculate_cost(oi
);
174 /* Create new ospf6 interface structure */
175 struct ospf6_interface
*ospf6_interface_create(struct interface
*ifp
)
177 struct ospf6_interface
*oi
;
178 unsigned int iobuflen
;
180 oi
= (struct ospf6_interface
*)XCALLOC(MTYPE_OSPF6_IF
,
181 sizeof(struct ospf6_interface
));
183 oi
->area
= (struct ospf6_area
*)NULL
;
184 oi
->neighbor_list
= list_new();
185 oi
->neighbor_list
->cmp
= ospf6_neighbor_cmp
;
186 oi
->linklocal_addr
= (struct in6_addr
*)NULL
;
187 oi
->instance_id
= OSPF6_INTERFACE_INSTANCE_ID
;
188 oi
->transdelay
= OSPF6_INTERFACE_TRANSDELAY
;
189 oi
->priority
= OSPF6_INTERFACE_PRIORITY
;
191 oi
->hello_interval
= OSPF_HELLO_INTERVAL_DEFAULT
;
192 oi
->dead_interval
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
193 oi
->rxmt_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
194 oi
->type
= ospf6_default_iftype(ifp
);
195 oi
->state
= OSPF6_INTERFACE_DOWN
;
200 /* Try to adjust I/O buffer size with IfMtu */
201 oi
->ifmtu
= ifp
->mtu6
;
202 iobuflen
= ospf6_iobuf_size(ifp
->mtu6
);
203 if (oi
->ifmtu
> iobuflen
) {
204 if (IS_OSPF6_DEBUG_INTERFACE
)
206 "Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
207 ifp
->name
, iobuflen
);
208 oi
->ifmtu
= iobuflen
;
211 QOBJ_REG(oi
, ospf6_interface
);
213 oi
->lsupdate_list
= ospf6_lsdb_create(oi
);
214 oi
->lsack_list
= ospf6_lsdb_create(oi
);
215 oi
->lsdb
= ospf6_lsdb_create(oi
);
216 oi
->lsdb
->hook_add
= ospf6_interface_lsdb_hook_add
;
217 oi
->lsdb
->hook_remove
= ospf6_interface_lsdb_hook_remove
;
218 oi
->lsdb_self
= ospf6_lsdb_create(oi
);
220 oi
->route_connected
=
221 OSPF6_ROUTE_TABLE_CREATE(INTERFACE
, CONNECTED_ROUTES
);
222 oi
->route_connected
->scope
= oi
;
229 oi
->cost
= ospf6_interface_get_cost(oi
);
234 void ospf6_interface_delete(struct ospf6_interface
*oi
)
236 struct listnode
*node
, *nnode
;
237 struct ospf6_neighbor
*on
;
241 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
))
242 ospf6_neighbor_delete(on
);
244 list_delete_and_null(&oi
->neighbor_list
);
246 THREAD_OFF(oi
->thread_send_hello
);
247 THREAD_OFF(oi
->thread_send_lsupdate
);
248 THREAD_OFF(oi
->thread_send_lsack
);
250 ospf6_lsdb_remove_all(oi
->lsdb
);
251 ospf6_lsdb_remove_all(oi
->lsupdate_list
);
252 ospf6_lsdb_remove_all(oi
->lsack_list
);
254 ospf6_lsdb_delete(oi
->lsdb
);
255 ospf6_lsdb_delete(oi
->lsdb_self
);
257 ospf6_lsdb_delete(oi
->lsupdate_list
);
258 ospf6_lsdb_delete(oi
->lsack_list
);
260 ospf6_route_table_delete(oi
->route_connected
);
263 oi
->interface
->info
= NULL
;
267 XFREE(MTYPE_CFG_PLIST_NAME
, oi
->plist_name
);
269 ospf6_bfd_info_free(&(oi
->bfd_info
));
271 XFREE(MTYPE_OSPF6_IF
, oi
);
274 void ospf6_interface_enable(struct ospf6_interface
*oi
)
276 UNSET_FLAG(oi
->flag
, OSPF6_INTERFACE_DISABLE
);
277 ospf6_interface_state_update(oi
->interface
);
280 void ospf6_interface_disable(struct ospf6_interface
*oi
)
282 SET_FLAG(oi
->flag
, OSPF6_INTERFACE_DISABLE
);
284 thread_execute(master
, interface_down
, oi
, 0);
286 ospf6_lsdb_remove_all(oi
->lsdb
);
287 ospf6_lsdb_remove_all(oi
->lsdb_self
);
288 ospf6_lsdb_remove_all(oi
->lsupdate_list
);
289 ospf6_lsdb_remove_all(oi
->lsack_list
);
291 THREAD_OFF(oi
->thread_send_hello
);
292 THREAD_OFF(oi
->thread_send_lsupdate
);
293 THREAD_OFF(oi
->thread_send_lsack
);
295 THREAD_OFF(oi
->thread_network_lsa
);
296 THREAD_OFF(oi
->thread_link_lsa
);
297 THREAD_OFF(oi
->thread_intra_prefix_lsa
);
298 THREAD_OFF(oi
->thread_as_extern_lsa
);
301 static struct in6_addr
*
302 ospf6_interface_get_linklocal_address(struct interface
*ifp
)
306 struct in6_addr
*l
= (struct in6_addr
*)NULL
;
308 /* for each connected address */
309 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, n
, c
)) {
310 /* if family not AF_INET6, ignore */
311 if (c
->address
->family
!= AF_INET6
)
314 /* linklocal scope check */
315 if (IN6_IS_ADDR_LINKLOCAL(&c
->address
->u
.prefix6
))
316 l
= &c
->address
->u
.prefix6
;
321 void ospf6_interface_if_add(struct interface
*ifp
)
323 struct ospf6_interface
*oi
;
324 unsigned int iobuflen
;
326 oi
= (struct ospf6_interface
*)ifp
->info
;
330 /* Try to adjust I/O buffer size with IfMtu */
332 oi
->ifmtu
= ifp
->mtu6
;
333 iobuflen
= ospf6_iobuf_size(ifp
->mtu6
);
334 if (oi
->ifmtu
> iobuflen
) {
335 if (IS_OSPF6_DEBUG_INTERFACE
)
337 "Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
338 ifp
->name
, iobuflen
);
339 oi
->ifmtu
= iobuflen
;
342 /* interface start */
343 ospf6_interface_state_update(oi
->interface
);
346 void ospf6_interface_state_update(struct interface
*ifp
)
348 struct ospf6_interface
*oi
;
349 unsigned int iobuflen
;
351 oi
= (struct ospf6_interface
*)ifp
->info
;
354 if (oi
->area
== NULL
)
356 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_DISABLE
))
359 /* Adjust the mtu values if the kernel told us something new */
360 if (ifp
->mtu6
!= oi
->ifmtu
) {
361 /* If nothing configured, accept it and check for buffer size */
363 oi
->ifmtu
= ifp
->mtu6
;
364 iobuflen
= ospf6_iobuf_size(ifp
->mtu6
);
365 if (oi
->ifmtu
> iobuflen
) {
366 if (IS_OSPF6_DEBUG_INTERFACE
)
368 "Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
369 ifp
->name
, iobuflen
);
370 oi
->ifmtu
= iobuflen
;
372 } else if (oi
->c_ifmtu
> ifp
->mtu6
) {
373 oi
->ifmtu
= ifp
->mtu6
;
375 "Configured mtu %u on %s overridden by kernel %u",
376 oi
->c_ifmtu
, ifp
->name
, ifp
->mtu6
);
378 oi
->ifmtu
= oi
->c_ifmtu
;
381 if (if_is_operative(ifp
)
382 && (ospf6_interface_get_linklocal_address(oi
->interface
)
383 || if_is_loopback(oi
->interface
)))
384 thread_add_event(master
, interface_up
, oi
, 0, NULL
);
386 thread_add_event(master
, interface_down
, oi
, 0, NULL
);
391 void ospf6_interface_connected_route_update(struct interface
*ifp
)
393 struct ospf6_interface
*oi
;
394 struct ospf6_route
*route
;
396 struct listnode
*node
, *nnode
;
397 struct in6_addr nh_addr
;
399 oi
= (struct ospf6_interface
*)ifp
->info
;
403 /* reset linklocal pointer */
404 oi
->linklocal_addr
= ospf6_interface_get_linklocal_address(ifp
);
406 /* if area is null, do not make connected-route list */
407 if (oi
->area
== NULL
)
410 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_DISABLE
))
413 /* update "route to advertise" interface route table */
414 ospf6_route_remove_all(oi
->route_connected
);
416 for (ALL_LIST_ELEMENTS(oi
->interface
->connected
, node
, nnode
, c
)) {
417 if (c
->address
->family
!= AF_INET6
)
420 CONTINUE_IF_ADDRESS_LINKLOCAL(IS_OSPF6_DEBUG_INTERFACE
,
422 CONTINUE_IF_ADDRESS_UNSPECIFIED(IS_OSPF6_DEBUG_INTERFACE
,
424 CONTINUE_IF_ADDRESS_LOOPBACK(IS_OSPF6_DEBUG_INTERFACE
,
426 CONTINUE_IF_ADDRESS_V4COMPAT(IS_OSPF6_DEBUG_INTERFACE
,
428 CONTINUE_IF_ADDRESS_V4MAPPED(IS_OSPF6_DEBUG_INTERFACE
,
432 if (oi
->plist_name
) {
433 struct prefix_list
*plist
;
434 enum prefix_list_type ret
;
435 char buf
[PREFIX2STR_BUFFER
];
437 prefix2str(c
->address
, buf
, sizeof(buf
));
438 plist
= prefix_list_lookup(AFI_IP6
, oi
->plist_name
);
439 ret
= prefix_list_apply(plist
, (void *)c
->address
);
440 if (ret
== PREFIX_DENY
) {
441 if (IS_OSPF6_DEBUG_INTERFACE
)
443 "%s on %s filtered by prefix-list %s ",
444 buf
, oi
->interface
->name
,
450 route
= ospf6_route_create();
451 memcpy(&route
->prefix
, c
->address
, sizeof(struct prefix
));
452 apply_mask(&route
->prefix
);
453 route
->type
= OSPF6_DEST_TYPE_NETWORK
;
454 route
->path
.area_id
= oi
->area
->area_id
;
455 route
->path
.type
= OSPF6_PATH_TYPE_INTRA
;
456 route
->path
.cost
= oi
->cost
;
457 inet_pton(AF_INET6
, "::1", &nh_addr
);
458 ospf6_route_add_nexthop(route
, oi
->interface
->ifindex
,
460 ospf6_route_add(route
, oi
->route_connected
);
463 /* create new Link-LSA */
464 OSPF6_LINK_LSA_SCHEDULE(oi
);
465 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
466 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
469 static void ospf6_interface_state_change(uint8_t next_state
,
470 struct ospf6_interface
*oi
)
474 prev_state
= oi
->state
;
475 oi
->state
= next_state
;
477 if (prev_state
== next_state
)
481 if (IS_OSPF6_DEBUG_INTERFACE
) {
482 zlog_debug("Interface state change %s: %s -> %s",
484 ospf6_interface_state_str
[prev_state
],
485 ospf6_interface_state_str
[next_state
]);
489 if ((prev_state
== OSPF6_INTERFACE_DR
490 || prev_state
== OSPF6_INTERFACE_BDR
)
491 && (next_state
!= OSPF6_INTERFACE_DR
492 && next_state
!= OSPF6_INTERFACE_BDR
))
493 ospf6_sso(oi
->interface
->ifindex
, &alldrouters6
,
496 if ((prev_state
!= OSPF6_INTERFACE_DR
497 && prev_state
!= OSPF6_INTERFACE_BDR
)
498 && (next_state
== OSPF6_INTERFACE_DR
499 || next_state
== OSPF6_INTERFACE_BDR
))
500 ospf6_sso(oi
->interface
->ifindex
, &alldrouters6
,
503 OSPF6_ROUTER_LSA_SCHEDULE(oi
->area
);
504 if (next_state
== OSPF6_INTERFACE_DOWN
) {
505 OSPF6_NETWORK_LSA_EXECUTE(oi
);
506 OSPF6_INTRA_PREFIX_LSA_EXECUTE_TRANSIT(oi
);
507 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
508 OSPF6_INTRA_PREFIX_LSA_EXECUTE_TRANSIT(oi
);
509 } else if (prev_state
== OSPF6_INTERFACE_DR
510 || next_state
== OSPF6_INTERFACE_DR
) {
511 OSPF6_NETWORK_LSA_SCHEDULE(oi
);
512 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
513 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
516 hook_call(ospf6_interface_change
, oi
, next_state
, prev_state
);
520 /* DR Election, RFC2328 section 9.4 */
522 #define IS_ELIGIBLE(n) \
523 ((n)->state >= OSPF6_NEIGHBOR_TWOWAY && (n)->priority != 0)
525 static struct ospf6_neighbor
*better_bdrouter(struct ospf6_neighbor
*a
,
526 struct ospf6_neighbor
*b
)
528 if ((a
== NULL
|| !IS_ELIGIBLE(a
) || a
->drouter
== a
->router_id
)
529 && (b
== NULL
|| !IS_ELIGIBLE(b
) || b
->drouter
== b
->router_id
))
531 else if (a
== NULL
|| !IS_ELIGIBLE(a
) || a
->drouter
== a
->router_id
)
533 else if (b
== NULL
|| !IS_ELIGIBLE(b
) || b
->drouter
== b
->router_id
)
536 if (a
->bdrouter
== a
->router_id
&& b
->bdrouter
!= b
->router_id
)
538 if (a
->bdrouter
!= a
->router_id
&& b
->bdrouter
== b
->router_id
)
541 if (a
->priority
> b
->priority
)
543 if (a
->priority
< b
->priority
)
546 if (ntohl(a
->router_id
) > ntohl(b
->router_id
))
548 if (ntohl(a
->router_id
) < ntohl(b
->router_id
))
551 zlog_warn("Router-ID duplicate ?");
555 static struct ospf6_neighbor
*better_drouter(struct ospf6_neighbor
*a
,
556 struct ospf6_neighbor
*b
)
558 if ((a
== NULL
|| !IS_ELIGIBLE(a
) || a
->drouter
!= a
->router_id
)
559 && (b
== NULL
|| !IS_ELIGIBLE(b
) || b
->drouter
!= b
->router_id
))
561 else if (a
== NULL
|| !IS_ELIGIBLE(a
) || a
->drouter
!= a
->router_id
)
563 else if (b
== NULL
|| !IS_ELIGIBLE(b
) || b
->drouter
!= b
->router_id
)
566 if (a
->drouter
== a
->router_id
&& b
->drouter
!= b
->router_id
)
568 if (a
->drouter
!= a
->router_id
&& b
->drouter
== b
->router_id
)
571 if (a
->priority
> b
->priority
)
573 if (a
->priority
< b
->priority
)
576 if (ntohl(a
->router_id
) > ntohl(b
->router_id
))
578 if (ntohl(a
->router_id
) < ntohl(b
->router_id
))
581 zlog_warn("Router-ID duplicate ?");
585 static uint8_t dr_election(struct ospf6_interface
*oi
)
587 struct listnode
*node
, *nnode
;
588 struct ospf6_neighbor
*on
, *drouter
, *bdrouter
, myself
;
589 struct ospf6_neighbor
*best_drouter
, *best_bdrouter
;
590 uint8_t next_state
= 0;
592 drouter
= bdrouter
= NULL
;
593 best_drouter
= best_bdrouter
= NULL
;
595 /* pseudo neighbor myself, including noting current DR/BDR (1) */
596 memset(&myself
, 0, sizeof(myself
));
597 inet_ntop(AF_INET
, &oi
->area
->ospf6
->router_id
, myself
.name
,
598 sizeof(myself
.name
));
599 myself
.state
= OSPF6_NEIGHBOR_TWOWAY
;
600 myself
.drouter
= oi
->drouter
;
601 myself
.bdrouter
= oi
->bdrouter
;
602 myself
.priority
= oi
->priority
;
603 myself
.router_id
= oi
->area
->ospf6
->router_id
;
605 /* Electing BDR (2) */
606 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
))
607 bdrouter
= better_bdrouter(bdrouter
, on
);
609 best_bdrouter
= bdrouter
;
610 bdrouter
= better_bdrouter(best_bdrouter
, &myself
);
612 /* Electing DR (3) */
613 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
))
614 drouter
= better_drouter(drouter
, on
);
616 best_drouter
= drouter
;
617 drouter
= better_drouter(best_drouter
, &myself
);
621 /* the router itself is newly/no longer DR/BDR (4) */
622 if ((drouter
== &myself
&& myself
.drouter
!= myself
.router_id
)
623 || (drouter
!= &myself
&& myself
.drouter
== myself
.router_id
)
624 || (bdrouter
== &myself
&& myself
.bdrouter
!= myself
.router_id
)
625 || (bdrouter
!= &myself
&& myself
.bdrouter
== myself
.router_id
)) {
626 myself
.drouter
= (drouter
? drouter
->router_id
: htonl(0));
627 myself
.bdrouter
= (bdrouter
? bdrouter
->router_id
: htonl(0));
629 /* compatible to Electing BDR (2) */
630 bdrouter
= better_bdrouter(best_bdrouter
, &myself
);
632 /* compatible to Electing DR (3) */
633 drouter
= better_drouter(best_drouter
, &myself
);
638 /* Set interface state accordingly (5) */
639 if (drouter
&& drouter
== &myself
)
640 next_state
= OSPF6_INTERFACE_DR
;
641 else if (bdrouter
&& bdrouter
== &myself
)
642 next_state
= OSPF6_INTERFACE_BDR
;
644 next_state
= OSPF6_INTERFACE_DROTHER
;
646 /* If NBMA, schedule Start for each neighbor having priority of 0 (6) */
649 /* If DR or BDR change, invoke AdjOK? for each neighbor (7) */
650 /* RFC 2328 section 12.4. Originating LSAs (3) will be handled
651 accordingly after AdjOK */
652 if (oi
->drouter
!= (drouter
? drouter
->router_id
: htonl(0))
653 || oi
->bdrouter
!= (bdrouter
? bdrouter
->router_id
: htonl(0))) {
654 if (IS_OSPF6_DEBUG_INTERFACE
)
655 zlog_debug("DR Election on %s: DR: %s BDR: %s",
657 (drouter
? drouter
->name
: "0.0.0.0"),
658 (bdrouter
? bdrouter
->name
: "0.0.0.0"));
660 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, node
, on
)) {
661 if (on
->state
< OSPF6_NEIGHBOR_TWOWAY
)
663 /* Schedule AdjOK. */
664 thread_add_event(master
, adj_ok
, on
, 0, NULL
);
668 oi
->drouter
= (drouter
? drouter
->router_id
: htonl(0));
669 oi
->bdrouter
= (bdrouter
? bdrouter
->router_id
: htonl(0));
674 /* Interface State Machine */
675 int interface_up(struct thread
*thread
)
677 struct ospf6_interface
*oi
;
679 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
680 assert(oi
&& oi
->interface
);
682 if (IS_OSPF6_DEBUG_INTERFACE
)
683 zlog_debug("Interface Event %s: [InterfaceUp]",
684 oi
->interface
->name
);
686 /* check physical interface is up */
687 if (!if_is_operative(oi
->interface
)) {
688 if (IS_OSPF6_DEBUG_INTERFACE
)
690 "Interface %s is down, can't execute [InterfaceUp]",
691 oi
->interface
->name
);
695 /* check interface has a link-local address */
696 if (!(ospf6_interface_get_linklocal_address(oi
->interface
)
697 || if_is_loopback(oi
->interface
))) {
698 if (IS_OSPF6_DEBUG_INTERFACE
)
700 "Interface %s has no link local address, can't execute [InterfaceUp]",
701 oi
->interface
->name
);
706 ospf6_interface_recalculate_cost(oi
);
708 /* if already enabled, do nothing */
709 if (oi
->state
> OSPF6_INTERFACE_DOWN
) {
710 if (IS_OSPF6_DEBUG_INTERFACE
)
711 zlog_debug("Interface %s already enabled",
712 oi
->interface
->name
);
716 /* If no area assigned, return */
717 if (oi
->area
== NULL
) {
719 "%s: Not scheduleing Hello for %s as there is no area assigned yet",
720 __func__
, oi
->interface
->name
);
724 /* Join AllSPFRouters */
725 if (ospf6_sso(oi
->interface
->ifindex
, &allspfrouters6
, IPV6_JOIN_GROUP
)
727 if (oi
->sso_try_cnt
++ < OSPF6_INTERFACE_SSO_RETRY_MAX
) {
729 "Scheduling %s for sso retry, trial count: %d",
730 oi
->interface
->name
, oi
->sso_try_cnt
);
731 thread_add_timer(master
, interface_up
, oi
,
732 OSPF6_INTERFACE_SSO_RETRY_INT
, NULL
);
736 oi
->sso_try_cnt
= 0; /* Reset on success */
738 /* Update interface route */
739 ospf6_interface_connected_route_update(oi
->interface
);
742 if (!CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_PASSIVE
)
743 && !if_is_loopback(oi
->interface
)) {
744 oi
->thread_send_hello
= NULL
;
745 thread_add_event(master
, ospf6_hello_send
, oi
, 0,
746 &oi
->thread_send_hello
);
749 /* decide next interface state */
750 if ((if_is_pointopoint(oi
->interface
))
751 || (oi
->type
== OSPF_IFTYPE_POINTOPOINT
)) {
752 ospf6_interface_state_change(OSPF6_INTERFACE_POINTTOPOINT
, oi
);
753 } else if (oi
->priority
== 0)
754 ospf6_interface_state_change(OSPF6_INTERFACE_DROTHER
, oi
);
756 ospf6_interface_state_change(OSPF6_INTERFACE_WAITING
, oi
);
757 thread_add_timer(master
, wait_timer
, oi
, oi
->dead_interval
,
764 int wait_timer(struct thread
*thread
)
766 struct ospf6_interface
*oi
;
768 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
769 assert(oi
&& oi
->interface
);
771 if (IS_OSPF6_DEBUG_INTERFACE
)
772 zlog_debug("Interface Event %s: [WaitTimer]",
773 oi
->interface
->name
);
775 if (oi
->state
== OSPF6_INTERFACE_WAITING
)
776 ospf6_interface_state_change(dr_election(oi
), oi
);
781 int backup_seen(struct thread
*thread
)
783 struct ospf6_interface
*oi
;
785 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
786 assert(oi
&& oi
->interface
);
788 if (IS_OSPF6_DEBUG_INTERFACE
)
789 zlog_debug("Interface Event %s: [BackupSeen]",
790 oi
->interface
->name
);
792 if (oi
->state
== OSPF6_INTERFACE_WAITING
)
793 ospf6_interface_state_change(dr_election(oi
), oi
);
798 int neighbor_change(struct thread
*thread
)
800 struct ospf6_interface
*oi
;
802 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
803 assert(oi
&& oi
->interface
);
805 if (IS_OSPF6_DEBUG_INTERFACE
)
806 zlog_debug("Interface Event %s: [NeighborChange]",
807 oi
->interface
->name
);
809 if (oi
->state
== OSPF6_INTERFACE_DROTHER
810 || oi
->state
== OSPF6_INTERFACE_BDR
811 || oi
->state
== OSPF6_INTERFACE_DR
)
812 ospf6_interface_state_change(dr_election(oi
), oi
);
817 int interface_down(struct thread
*thread
)
819 struct ospf6_interface
*oi
;
820 struct listnode
*node
, *nnode
;
821 struct ospf6_neighbor
*on
;
823 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
824 assert(oi
&& oi
->interface
);
826 if (IS_OSPF6_DEBUG_INTERFACE
)
827 zlog_debug("Interface Event %s: [InterfaceDown]",
828 oi
->interface
->name
);
831 THREAD_OFF(oi
->thread_send_hello
);
833 /* Leave AllSPFRouters */
834 if (oi
->state
> OSPF6_INTERFACE_DOWN
)
835 ospf6_sso(oi
->interface
->ifindex
, &allspfrouters6
,
838 ospf6_interface_state_change(OSPF6_INTERFACE_DOWN
, oi
);
840 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
))
841 ospf6_neighbor_delete(on
);
843 list_delete_all_node(oi
->neighbor_list
);
845 /* When interface state is reset, also reset information about
846 * DR election, as it is no longer valid. */
847 oi
->drouter
= oi
->prev_drouter
= htonl(0);
848 oi
->bdrouter
= oi
->prev_bdrouter
= htonl(0);
853 /* show specified interface structure */
854 static int ospf6_interface_show(struct vty
*vty
, struct interface
*ifp
)
856 struct ospf6_interface
*oi
;
860 char strbuf
[PREFIX2STR_BUFFER
], drouter
[32], bdrouter
[32];
862 struct timeval res
, now
;
864 struct ospf6_lsa
*lsa
;
866 /* check physical interface type */
867 if (if_is_loopback(ifp
))
869 else if (if_is_broadcast(ifp
))
871 else if (if_is_pointopoint(ifp
))
872 type
= "POINTOPOINT";
876 vty_out(vty
, "%s is %s, type %s\n", ifp
->name
,
877 (if_is_operative(ifp
) ? "up" : "down"), type
);
878 vty_out(vty
, " Interface ID: %d\n", ifp
->ifindex
);
880 if (ifp
->info
== NULL
) {
881 vty_out(vty
, " OSPF not enabled on this interface\n");
884 oi
= (struct ospf6_interface
*)ifp
->info
;
886 vty_out(vty
, " Internet Address:\n");
888 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, i
, c
)) {
890 prefix2str(p
, strbuf
, sizeof(strbuf
));
893 vty_out(vty
, " inet : %s\n", strbuf
);
896 vty_out(vty
, " inet6: %s\n", strbuf
);
899 vty_out(vty
, " ??? : %s\n", strbuf
);
906 " Instance ID %d, Interface MTU %d (autodetect: %d)\n",
907 oi
->instance_id
, oi
->ifmtu
, ifp
->mtu6
);
908 vty_out(vty
, " MTU mismatch detection: %s\n",
909 oi
->mtu_ignore
? "disabled" : "enabled");
910 inet_ntop(AF_INET
, &oi
->area
->area_id
, strbuf
, sizeof(strbuf
));
911 vty_out(vty
, " Area ID %s, Cost %u\n", strbuf
, oi
->cost
);
913 vty_out(vty
, " Not Attached to Area\n");
915 vty_out(vty
, " State %s, Transmit Delay %d sec, Priority %d\n",
916 ospf6_interface_state_str
[oi
->state
], oi
->transdelay
,
918 vty_out(vty
, " Timer intervals configured:\n");
919 vty_out(vty
, " Hello %d, Dead %d, Retransmit %d\n",
920 oi
->hello_interval
, oi
->dead_interval
, oi
->rxmt_interval
);
922 inet_ntop(AF_INET
, &oi
->drouter
, drouter
, sizeof(drouter
));
923 inet_ntop(AF_INET
, &oi
->bdrouter
, bdrouter
, sizeof(bdrouter
));
924 vty_out(vty
, " DR: %s BDR: %s\n", drouter
, bdrouter
);
926 vty_out(vty
, " Number of I/F scoped LSAs is %u\n", oi
->lsdb
->count
);
931 if (oi
->thread_send_lsupdate
)
932 timersub(&oi
->thread_send_lsupdate
->u
.sands
, &now
, &res
);
933 timerstring(&res
, duration
, sizeof(duration
));
935 " %d Pending LSAs for LSUpdate in Time %s [thread %s]\n",
936 oi
->lsupdate_list
->count
, duration
,
937 (oi
->thread_send_lsupdate
? "on" : "off"));
938 for (ALL_LSDB(oi
->lsupdate_list
, lsa
))
939 vty_out(vty
, " %s\n", lsa
->name
);
942 if (oi
->thread_send_lsack
)
943 timersub(&oi
->thread_send_lsack
->u
.sands
, &now
, &res
);
944 timerstring(&res
, duration
, sizeof(duration
));
945 vty_out(vty
, " %d Pending LSAs for LSAck in Time %s [thread %s]\n",
946 oi
->lsack_list
->count
, duration
,
947 (oi
->thread_send_lsack
? "on" : "off"));
948 for (ALL_LSDB(oi
->lsack_list
, lsa
))
949 vty_out(vty
, " %s\n", lsa
->name
);
950 ospf6_bfd_show_info(vty
, oi
->bfd_info
, 1);
955 DEFUN (show_ipv6_ospf6_interface
,
956 show_ipv6_ospf6_interface_ifname_cmd
,
957 "show ipv6 ospf6 interface [IFNAME]",
964 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
966 struct interface
*ifp
;
969 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, VRF_DEFAULT
);
971 vty_out(vty
, "No such Interface: %s\n",
972 argv
[idx_ifname
]->arg
);
975 ospf6_interface_show(vty
, ifp
);
977 FOR_ALL_INTERFACES (vrf
, ifp
)
978 ospf6_interface_show(vty
, ifp
);
984 static int ospf6_interface_show_traffic(struct vty
*vty
, uint32_t vrf_id
,
985 struct interface
*intf_ifp
,
988 struct interface
*ifp
;
989 struct vrf
*vrf
= NULL
;
990 struct ospf6_interface
*oi
= NULL
;
992 vrf
= vrf_lookup_by_id(vrf_id
);
996 vty_out(vty
, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface",
997 " HELLO", " DB-Desc", " LS-Req", " LS-Update",
999 vty_out(vty
, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "",
1000 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
1003 "--------------------------------------------------------------------------------------------\n");
1006 if (intf_ifp
== NULL
) {
1007 FOR_ALL_INTERFACES (vrf
, ifp
) {
1009 oi
= (struct ospf6_interface
*)ifp
->info
;
1014 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
1015 oi
->interface
->name
, oi
->hello_in
,
1016 oi
->hello_out
, oi
->db_desc_in
, oi
->db_desc_out
,
1017 oi
->ls_req_in
, oi
->ls_req_out
, oi
->ls_upd_in
,
1018 oi
->ls_upd_out
, oi
->ls_ack_in
, oi
->ls_ack_out
);
1021 oi
= intf_ifp
->info
;
1026 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
1027 oi
->interface
->name
, oi
->hello_in
, oi
->hello_out
,
1028 oi
->db_desc_in
, oi
->db_desc_out
, oi
->ls_req_in
,
1029 oi
->ls_req_out
, oi
->ls_upd_in
, oi
->ls_upd_out
,
1030 oi
->ls_ack_in
, oi
->ls_ack_out
);
1036 /* show interface */
1037 DEFUN (show_ipv6_ospf6_interface_traffic
,
1038 show_ipv6_ospf6_interface_traffic_cmd
,
1039 "show ipv6 ospf6 interface traffic [IFNAME]",
1044 "Protocol Packet counters\n"
1048 int display_once
= 0;
1049 char *intf_name
= NULL
;
1050 struct interface
*ifp
= NULL
;
1052 if (argv_find(argv
, argc
, "IFNAME", &idx_ifname
)) {
1053 intf_name
= argv
[idx_ifname
]->arg
;
1054 ifp
= if_lookup_by_name(intf_name
, VRF_DEFAULT
);
1056 vty_out(vty
, "No such Interface: %s\n", intf_name
);
1059 if (ifp
->info
== NULL
) {
1061 " OSPF not enabled on this interface %s\n",
1067 ospf6_interface_show_traffic(vty
, VRF_DEFAULT
, ifp
, display_once
);
1074 DEFUN (show_ipv6_ospf6_interface_ifname_prefix
,
1075 show_ipv6_ospf6_interface_ifname_prefix_cmd
,
1076 "show ipv6 ospf6 interface IFNAME prefix [<X:X::X:X|X:X::X:X/M>] [<match|detail>]",
1082 "Display connected prefixes to advertise\n"
1083 OSPF6_ROUTE_ADDRESS_STR
1084 OSPF6_ROUTE_PREFIX_STR
1085 OSPF6_ROUTE_MATCH_STR
1086 "Display details of the prefixes\n")
1090 struct interface
*ifp
;
1091 struct ospf6_interface
*oi
;
1093 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, VRF_DEFAULT
);
1095 vty_out(vty
, "No such Interface: %s\n", argv
[idx_ifname
]->arg
);
1101 vty_out(vty
, "OSPFv3 is not enabled on %s\n",
1102 argv
[idx_ifname
]->arg
);
1106 ospf6_route_table_show(vty
, idx_prefix
, argc
, argv
,
1107 oi
->route_connected
);
1112 DEFUN (show_ipv6_ospf6_interface_prefix
,
1113 show_ipv6_ospf6_interface_prefix_cmd
,
1114 "show ipv6 ospf6 interface prefix [<X:X::X:X|X:X::X:X/M>] [<match|detail>]",
1119 "Display connected prefixes to advertise\n"
1120 OSPF6_ROUTE_ADDRESS_STR
1121 OSPF6_ROUTE_PREFIX_STR
1122 OSPF6_ROUTE_MATCH_STR
1123 "Display details of the prefixes\n")
1125 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
1127 struct ospf6_interface
*oi
;
1128 struct interface
*ifp
;
1130 FOR_ALL_INTERFACES (vrf
, ifp
) {
1131 oi
= (struct ospf6_interface
*)ifp
->info
;
1135 ospf6_route_table_show(vty
, idx_prefix
, argc
, argv
,
1136 oi
->route_connected
);
1142 /* interface variable set command */
1143 DEFUN (ipv6_ospf6_ifmtu
,
1144 ipv6_ospf6_ifmtu_cmd
,
1145 "ipv6 ospf6 ifmtu (1-65535)",
1149 "OSPFv3 Interface MTU\n"
1152 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1154 struct ospf6_interface
*oi
;
1155 unsigned int ifmtu
, iobuflen
;
1156 struct listnode
*node
, *nnode
;
1157 struct ospf6_neighbor
*on
;
1161 oi
= (struct ospf6_interface
*)ifp
->info
;
1163 oi
= ospf6_interface_create(ifp
);
1166 ifmtu
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
1168 if (oi
->c_ifmtu
== ifmtu
)
1171 if (ifp
->mtu6
!= 0 && ifp
->mtu6
< ifmtu
) {
1173 "%s's ospf6 ifmtu cannot go beyond physical mtu (%d)\n",
1174 ifp
->name
, ifp
->mtu6
);
1175 return CMD_WARNING_CONFIG_FAILED
;
1178 if (oi
->ifmtu
< ifmtu
) {
1179 iobuflen
= ospf6_iobuf_size(ifmtu
);
1180 if (iobuflen
< ifmtu
) {
1182 "%s's ifmtu is adjusted to I/O buffer size (%d).\n",
1183 ifp
->name
, iobuflen
);
1184 oi
->ifmtu
= oi
->c_ifmtu
= iobuflen
;
1186 oi
->ifmtu
= oi
->c_ifmtu
= ifmtu
;
1188 oi
->ifmtu
= oi
->c_ifmtu
= ifmtu
;
1190 /* re-establish adjacencies */
1191 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
)) {
1192 THREAD_OFF(on
->inactivity_timer
);
1193 thread_add_event(master
, inactivity_timer
, on
, 0, NULL
);
1199 DEFUN (no_ipv6_ospf6_ifmtu
,
1200 no_ipv6_ospf6_ifmtu_cmd
,
1201 "no ipv6 ospf6 ifmtu [(1-65535)]",
1206 "OSPFv3 Interface MTU\n"
1209 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1210 struct ospf6_interface
*oi
;
1211 unsigned int iobuflen
;
1212 struct listnode
*node
, *nnode
;
1213 struct ospf6_neighbor
*on
;
1217 oi
= (struct ospf6_interface
*)ifp
->info
;
1219 oi
= ospf6_interface_create(ifp
);
1222 if (oi
->ifmtu
< ifp
->mtu
) {
1223 iobuflen
= ospf6_iobuf_size(ifp
->mtu
);
1224 if (iobuflen
< ifp
->mtu
) {
1226 "%s's ifmtu is adjusted to I/O buffer size (%d).\n",
1227 ifp
->name
, iobuflen
);
1228 oi
->ifmtu
= iobuflen
;
1230 oi
->ifmtu
= ifp
->mtu
;
1232 oi
->ifmtu
= ifp
->mtu
;
1236 /* re-establish adjacencies */
1237 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
)) {
1238 THREAD_OFF(on
->inactivity_timer
);
1239 thread_add_event(master
, inactivity_timer
, on
, 0, NULL
);
1245 DEFUN (ipv6_ospf6_cost
,
1246 ipv6_ospf6_cost_cmd
,
1247 "ipv6 ospf6 cost (1-65535)",
1251 "Outgoing metric of this interface\n")
1253 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1255 struct ospf6_interface
*oi
;
1256 unsigned long int lcost
;
1260 oi
= (struct ospf6_interface
*)ifp
->info
;
1262 oi
= ospf6_interface_create(ifp
);
1265 lcost
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
1267 if (lcost
> UINT32_MAX
) {
1268 vty_out(vty
, "Cost %ld is out of range\n", lcost
);
1269 return CMD_WARNING_CONFIG_FAILED
;
1272 if (oi
->cost
== lcost
)
1276 SET_FLAG(oi
->flag
, OSPF6_INTERFACE_NOAUTOCOST
);
1278 ospf6_interface_force_recalculate_cost(oi
);
1283 DEFUN (no_ipv6_ospf6_cost
,
1284 no_ipv6_ospf6_cost_cmd
,
1285 "no ipv6 ospf6 cost [(1-65535)]",
1289 "Calculate interface cost from bandwidth\n"
1290 "Outgoing metric of this interface\n")
1292 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1293 struct ospf6_interface
*oi
;
1296 oi
= (struct ospf6_interface
*)ifp
->info
;
1298 oi
= ospf6_interface_create(ifp
);
1301 UNSET_FLAG(oi
->flag
, OSPF6_INTERFACE_NOAUTOCOST
);
1303 ospf6_interface_recalculate_cost(oi
);
1308 DEFUN (auto_cost_reference_bandwidth
,
1309 auto_cost_reference_bandwidth_cmd
,
1310 "auto-cost reference-bandwidth (1-4294967)",
1311 "Calculate OSPF interface cost according to bandwidth\n"
1312 "Use reference bandwidth method to assign OSPF cost\n"
1313 "The reference bandwidth in terms of Mbits per second\n")
1315 VTY_DECLVAR_CONTEXT(ospf6
, o
);
1317 struct ospf6_area
*oa
;
1318 struct ospf6_interface
*oi
;
1319 struct listnode
*i
, *j
;
1322 refbw
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
1323 if (refbw
< 1 || refbw
> 4294967) {
1324 vty_out(vty
, "reference-bandwidth value is invalid\n");
1325 return CMD_WARNING_CONFIG_FAILED
;
1328 /* If reference bandwidth is changed. */
1329 if ((refbw
) == o
->ref_bandwidth
)
1332 o
->ref_bandwidth
= refbw
;
1333 for (ALL_LIST_ELEMENTS_RO(o
->area_list
, i
, oa
))
1334 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
1335 ospf6_interface_recalculate_cost(oi
);
1340 DEFUN (no_auto_cost_reference_bandwidth
,
1341 no_auto_cost_reference_bandwidth_cmd
,
1342 "no auto-cost reference-bandwidth [(1-4294967)]",
1344 "Calculate OSPF interface cost according to bandwidth\n"
1345 "Use reference bandwidth method to assign OSPF cost\n"
1346 "The reference bandwidth in terms of Mbits per second\n")
1348 VTY_DECLVAR_CONTEXT(ospf6
, o
);
1349 struct ospf6_area
*oa
;
1350 struct ospf6_interface
*oi
;
1351 struct listnode
*i
, *j
;
1353 if (o
->ref_bandwidth
== OSPF6_REFERENCE_BANDWIDTH
)
1356 o
->ref_bandwidth
= OSPF6_REFERENCE_BANDWIDTH
;
1357 for (ALL_LIST_ELEMENTS_RO(o
->area_list
, i
, oa
))
1358 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
1359 ospf6_interface_recalculate_cost(oi
);
1365 DEFUN (ipv6_ospf6_hellointerval
,
1366 ipv6_ospf6_hellointerval_cmd
,
1367 "ipv6 ospf6 hello-interval (1-65535)",
1370 "Time between HELLO packets\n"
1373 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1375 struct ospf6_interface
*oi
;
1378 oi
= (struct ospf6_interface
*)ifp
->info
;
1380 oi
= ospf6_interface_create(ifp
);
1383 oi
->hello_interval
= strmatch(argv
[0]->text
, "no")
1384 ? OSPF_HELLO_INTERVAL_DEFAULT
1385 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1389 ALIAS (ipv6_ospf6_hellointerval
,
1390 no_ipv6_ospf6_hellointerval_cmd
,
1391 "no ipv6 ospf6 hello-interval [(1-65535)]",
1395 "Time between HELLO packets\n"
1398 /* interface variable set command */
1399 DEFUN (ipv6_ospf6_deadinterval
,
1400 ipv6_ospf6_deadinterval_cmd
,
1401 "ipv6 ospf6 dead-interval (1-65535)",
1404 "Interval time after which a neighbor is declared down\n"
1407 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1409 struct ospf6_interface
*oi
;
1412 oi
= (struct ospf6_interface
*)ifp
->info
;
1414 oi
= ospf6_interface_create(ifp
);
1417 oi
->dead_interval
= strmatch(argv
[0]->arg
, "no")
1418 ? OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
1419 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1423 ALIAS (ipv6_ospf6_deadinterval
,
1424 no_ipv6_ospf6_deadinterval_cmd
,
1425 "no ipv6 ospf6 dead-interval [(1-65535)]",
1429 "Interval time after which a neighbor is declared down\n"
1432 /* interface variable set command */
1433 DEFUN (ipv6_ospf6_transmitdelay
,
1434 ipv6_ospf6_transmitdelay_cmd
,
1435 "ipv6 ospf6 transmit-delay (1-3600)",
1438 "Link state transmit delay\n"
1441 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1443 struct ospf6_interface
*oi
;
1446 oi
= (struct ospf6_interface
*)ifp
->info
;
1448 oi
= ospf6_interface_create(ifp
);
1451 oi
->transdelay
= strmatch(argv
[0]->text
, "no")
1452 ? OSPF6_INTERFACE_TRANSDELAY
1453 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1457 ALIAS (ipv6_ospf6_transmitdelay
,
1458 no_ipv6_ospf6_transmitdelay_cmd
,
1459 "no ipv6 ospf6 transmit-delay [(1-3600)]",
1463 "Link state transmit delay\n"
1466 /* interface variable set command */
1467 DEFUN (ipv6_ospf6_retransmitinterval
,
1468 ipv6_ospf6_retransmitinterval_cmd
,
1469 "ipv6 ospf6 retransmit-interval (1-65535)",
1472 "Time between retransmitting lost link state advertisements\n"
1475 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1477 struct ospf6_interface
*oi
;
1480 oi
= (struct ospf6_interface
*)ifp
->info
;
1482 oi
= ospf6_interface_create(ifp
);
1485 oi
->rxmt_interval
= strmatch(argv
[0]->text
, "no")
1486 ? OSPF_RETRANSMIT_INTERVAL_DEFAULT
1487 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1491 ALIAS (ipv6_ospf6_retransmitinterval
,
1492 no_ipv6_ospf6_retransmitinterval_cmd
,
1493 "no ipv6 ospf6 retransmit-interval [(1-65535)]",
1497 "Time between retransmitting lost link state advertisements\n"
1500 /* interface variable set command */
1501 DEFUN (ipv6_ospf6_priority
,
1502 ipv6_ospf6_priority_cmd
,
1503 "ipv6 ospf6 priority (0-255)",
1509 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1511 struct ospf6_interface
*oi
;
1514 oi
= (struct ospf6_interface
*)ifp
->info
;
1516 oi
= ospf6_interface_create(ifp
);
1519 oi
->priority
= strmatch(argv
[0]->text
, "no")
1520 ? OSPF6_INTERFACE_PRIORITY
1521 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1523 if (oi
->area
&& (oi
->state
== OSPF6_INTERFACE_DROTHER
1524 || oi
->state
== OSPF6_INTERFACE_BDR
1525 || oi
->state
== OSPF6_INTERFACE_DR
))
1526 ospf6_interface_state_change(dr_election(oi
), oi
);
1531 ALIAS (ipv6_ospf6_priority
,
1532 no_ipv6_ospf6_priority_cmd
,
1533 "no ipv6 ospf6 priority [(0-255)]",
1540 DEFUN (ipv6_ospf6_instance
,
1541 ipv6_ospf6_instance_cmd
,
1542 "ipv6 ospf6 instance-id (0-255)",
1545 "Instance ID for this interface\n"
1546 "Instance ID value\n")
1548 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1550 struct ospf6_interface
*oi
;
1553 oi
= (struct ospf6_interface
*)ifp
->info
;
1555 oi
= ospf6_interface_create(ifp
);
1558 oi
->instance_id
= strmatch(argv
[0]->text
, "no")
1559 ? OSPF6_INTERFACE_INSTANCE_ID
1560 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1564 ALIAS (ipv6_ospf6_instance
,
1565 no_ipv6_ospf6_instance_cmd
,
1566 "no ipv6 ospf6 instance-id [(0-255)]",
1570 "Instance ID for this interface\n"
1571 "Instance ID value\n")
1573 DEFUN (ipv6_ospf6_passive
,
1574 ipv6_ospf6_passive_cmd
,
1575 "ipv6 ospf6 passive",
1578 "Passive interface; no adjacency will be formed on this interface\n"
1581 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1582 struct ospf6_interface
*oi
;
1583 struct listnode
*node
, *nnode
;
1584 struct ospf6_neighbor
*on
;
1588 oi
= (struct ospf6_interface
*)ifp
->info
;
1590 oi
= ospf6_interface_create(ifp
);
1593 SET_FLAG(oi
->flag
, OSPF6_INTERFACE_PASSIVE
);
1594 THREAD_OFF(oi
->thread_send_hello
);
1596 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
)) {
1597 THREAD_OFF(on
->inactivity_timer
);
1598 thread_add_event(master
, inactivity_timer
, on
, 0, NULL
);
1604 DEFUN (no_ipv6_ospf6_passive
,
1605 no_ipv6_ospf6_passive_cmd
,
1606 "no ipv6 ospf6 passive",
1610 "passive interface: No Adjacency will be formed on this I/F\n"
1613 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1614 struct ospf6_interface
*oi
;
1617 oi
= (struct ospf6_interface
*)ifp
->info
;
1619 oi
= ospf6_interface_create(ifp
);
1622 UNSET_FLAG(oi
->flag
, OSPF6_INTERFACE_PASSIVE
);
1623 THREAD_OFF(oi
->thread_send_hello
);
1624 oi
->thread_send_hello
= NULL
;
1625 thread_add_event(master
, ospf6_hello_send
, oi
, 0,
1626 &oi
->thread_send_hello
);
1631 DEFUN (ipv6_ospf6_mtu_ignore
,
1632 ipv6_ospf6_mtu_ignore_cmd
,
1633 "ipv6 ospf6 mtu-ignore",
1636 "Disable MTU mismatch detection on this interface\n"
1639 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1640 struct ospf6_interface
*oi
;
1643 oi
= (struct ospf6_interface
*)ifp
->info
;
1645 oi
= ospf6_interface_create(ifp
);
1653 DEFUN (no_ipv6_ospf6_mtu_ignore
,
1654 no_ipv6_ospf6_mtu_ignore_cmd
,
1655 "no ipv6 ospf6 mtu-ignore",
1659 "Disable MTU mismatch detection on this interface\n"
1662 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1663 struct ospf6_interface
*oi
;
1666 oi
= (struct ospf6_interface
*)ifp
->info
;
1668 oi
= ospf6_interface_create(ifp
);
1676 DEFUN (ipv6_ospf6_advertise_prefix_list
,
1677 ipv6_ospf6_advertise_prefix_list_cmd
,
1678 "ipv6 ospf6 advertise prefix-list WORD",
1681 "Advertising options\n"
1682 "Filter prefix using prefix-list\n"
1683 "Prefix list name\n"
1686 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1688 struct ospf6_interface
*oi
;
1691 oi
= (struct ospf6_interface
*)ifp
->info
;
1693 oi
= ospf6_interface_create(ifp
);
1697 XFREE(MTYPE_CFG_PLIST_NAME
, oi
->plist_name
);
1698 oi
->plist_name
= XSTRDUP(MTYPE_CFG_PLIST_NAME
, argv
[idx_word
]->arg
);
1700 ospf6_interface_connected_route_update(oi
->interface
);
1703 OSPF6_LINK_LSA_SCHEDULE(oi
);
1704 if (oi
->state
== OSPF6_INTERFACE_DR
) {
1705 OSPF6_NETWORK_LSA_SCHEDULE(oi
);
1706 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
1708 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
1714 DEFUN (no_ipv6_ospf6_advertise_prefix_list
,
1715 no_ipv6_ospf6_advertise_prefix_list_cmd
,
1716 "no ipv6 ospf6 advertise prefix-list [WORD]",
1720 "Advertising options\n"
1721 "Filter prefix using prefix-list\n"
1722 "Prefix list name\n")
1724 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1725 struct ospf6_interface
*oi
;
1728 oi
= (struct ospf6_interface
*)ifp
->info
;
1730 oi
= ospf6_interface_create(ifp
);
1734 XFREE(MTYPE_CFG_PLIST_NAME
, oi
->plist_name
);
1736 ospf6_interface_connected_route_update(oi
->interface
);
1739 OSPF6_LINK_LSA_SCHEDULE(oi
);
1740 if (oi
->state
== OSPF6_INTERFACE_DR
) {
1741 OSPF6_NETWORK_LSA_SCHEDULE(oi
);
1742 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
1744 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
1750 DEFUN (ipv6_ospf6_network
,
1751 ipv6_ospf6_network_cmd
,
1752 "ipv6 ospf6 network <broadcast|point-to-point>",
1756 "Specify OSPF6 broadcast network\n"
1757 "Specify OSPF6 point-to-point network\n"
1760 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1761 int idx_network
= 3;
1762 struct ospf6_interface
*oi
;
1765 oi
= (struct ospf6_interface
*)ifp
->info
;
1767 oi
= ospf6_interface_create(ifp
);
1771 if (strncmp(argv
[idx_network
]->arg
, "b", 1) == 0) {
1772 if (oi
->type
== OSPF_IFTYPE_BROADCAST
)
1775 oi
->type
= OSPF_IFTYPE_BROADCAST
;
1776 } else if (strncmp(argv
[idx_network
]->arg
, "point-to-p", 10) == 0) {
1777 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
) {
1780 oi
->type
= OSPF_IFTYPE_POINTOPOINT
;
1783 /* Reset the interface */
1784 thread_add_event(master
, interface_down
, oi
, 0, NULL
);
1785 thread_add_event(master
, interface_up
, oi
, 0, NULL
);
1790 DEFUN (no_ipv6_ospf6_network
,
1791 no_ipv6_ospf6_network_cmd
,
1792 "no ipv6 ospf6 network [<broadcast|point-to-point>]",
1796 "Set default network type\n"
1797 "Specify OSPF6 broadcast network\n"
1798 "Specify OSPF6 point-to-point network\n")
1800 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1801 struct ospf6_interface
*oi
;
1806 oi
= (struct ospf6_interface
*)ifp
->info
;
1811 type
= ospf6_default_iftype(ifp
);
1812 if (oi
->type
== type
) {
1817 /* Reset the interface */
1818 thread_add_event(master
, interface_down
, oi
, 0, NULL
);
1819 thread_add_event(master
, interface_up
, oi
, 0, NULL
);
1824 static int config_write_ospf6_interface(struct vty
*vty
)
1826 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
1827 struct ospf6_interface
*oi
;
1828 struct interface
*ifp
;
1830 FOR_ALL_INTERFACES (vrf
, ifp
) {
1831 oi
= (struct ospf6_interface
*)ifp
->info
;
1835 vty_frame(vty
, "interface %s\n", oi
->interface
->name
);
1838 vty_out(vty
, " description %s\n", ifp
->desc
);
1840 vty_out(vty
, " ipv6 ospf6 ifmtu %d\n", oi
->c_ifmtu
);
1842 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_NOAUTOCOST
))
1843 vty_out(vty
, " ipv6 ospf6 cost %d\n", oi
->cost
);
1845 if (oi
->hello_interval
!= OSPF6_INTERFACE_HELLO_INTERVAL
)
1846 vty_out(vty
, " ipv6 ospf6 hello-interval %d\n",
1847 oi
->hello_interval
);
1849 if (oi
->dead_interval
!= OSPF6_INTERFACE_DEAD_INTERVAL
)
1850 vty_out(vty
, " ipv6 ospf6 dead-interval %d\n",
1853 if (oi
->rxmt_interval
!= OSPF6_INTERFACE_RXMT_INTERVAL
)
1854 vty_out(vty
, " ipv6 ospf6 retransmit-interval %d\n",
1857 if (oi
->priority
!= OSPF6_INTERFACE_PRIORITY
)
1858 vty_out(vty
, " ipv6 ospf6 priority %d\n", oi
->priority
);
1860 if (oi
->transdelay
!= OSPF6_INTERFACE_TRANSDELAY
)
1861 vty_out(vty
, " ipv6 ospf6 transmit-delay %d\n",
1864 if (oi
->instance_id
!= OSPF6_INTERFACE_INSTANCE_ID
)
1865 vty_out(vty
, " ipv6 ospf6 instance-id %d\n",
1869 vty_out(vty
, " ipv6 ospf6 advertise prefix-list %s\n",
1872 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_PASSIVE
))
1873 vty_out(vty
, " ipv6 ospf6 passive\n");
1876 vty_out(vty
, " ipv6 ospf6 mtu-ignore\n");
1878 if (oi
->type
!= ospf6_default_iftype(ifp
)) {
1879 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
)
1881 " ipv6 ospf6 network point-to-point\n");
1882 else if (oi
->type
== OSPF_IFTYPE_BROADCAST
)
1883 vty_out(vty
, " ipv6 ospf6 network broadcast\n");
1886 ospf6_bfd_write_config(vty
, oi
);
1888 vty_endframe(vty
, "!\n");
1893 static struct cmd_node interface_node
= {
1894 INTERFACE_NODE
, "%s(config-if)# ", 1 /* VTYSH */
1897 void ospf6_interface_init(void)
1899 /* Install interface node. */
1900 install_node(&interface_node
, config_write_ospf6_interface
);
1903 install_element(VIEW_NODE
, &show_ipv6_ospf6_interface_prefix_cmd
);
1904 install_element(VIEW_NODE
, &show_ipv6_ospf6_interface_ifname_cmd
);
1905 install_element(VIEW_NODE
,
1906 &show_ipv6_ospf6_interface_ifname_prefix_cmd
);
1907 install_element(VIEW_NODE
, &show_ipv6_ospf6_interface_traffic_cmd
);
1909 install_element(INTERFACE_NODE
, &ipv6_ospf6_cost_cmd
);
1910 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_cost_cmd
);
1911 install_element(INTERFACE_NODE
, &ipv6_ospf6_ifmtu_cmd
);
1912 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_ifmtu_cmd
);
1914 install_element(INTERFACE_NODE
, &ipv6_ospf6_deadinterval_cmd
);
1915 install_element(INTERFACE_NODE
, &ipv6_ospf6_hellointerval_cmd
);
1916 install_element(INTERFACE_NODE
, &ipv6_ospf6_priority_cmd
);
1917 install_element(INTERFACE_NODE
, &ipv6_ospf6_retransmitinterval_cmd
);
1918 install_element(INTERFACE_NODE
, &ipv6_ospf6_transmitdelay_cmd
);
1919 install_element(INTERFACE_NODE
, &ipv6_ospf6_instance_cmd
);
1920 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_deadinterval_cmd
);
1921 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_hellointerval_cmd
);
1922 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_priority_cmd
);
1923 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_retransmitinterval_cmd
);
1924 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_transmitdelay_cmd
);
1925 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_instance_cmd
);
1927 install_element(INTERFACE_NODE
, &ipv6_ospf6_passive_cmd
);
1928 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_passive_cmd
);
1930 install_element(INTERFACE_NODE
, &ipv6_ospf6_mtu_ignore_cmd
);
1931 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_mtu_ignore_cmd
);
1933 install_element(INTERFACE_NODE
, &ipv6_ospf6_advertise_prefix_list_cmd
);
1934 install_element(INTERFACE_NODE
,
1935 &no_ipv6_ospf6_advertise_prefix_list_cmd
);
1937 install_element(INTERFACE_NODE
, &ipv6_ospf6_network_cmd
);
1938 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_network_cmd
);
1940 /* reference bandwidth commands */
1941 install_element(OSPF6_NODE
, &auto_cost_reference_bandwidth_cmd
);
1942 install_element(OSPF6_NODE
, &no_auto_cost_reference_bandwidth_cmd
);
1945 /* Clear the specified interface structure */
1946 static void ospf6_interface_clear(struct vty
*vty
, struct interface
*ifp
)
1948 struct ospf6_interface
*oi
;
1950 if (!if_is_operative(ifp
))
1953 if (ifp
->info
== NULL
)
1956 oi
= (struct ospf6_interface
*)ifp
->info
;
1958 if (IS_OSPF6_DEBUG_INTERFACE
)
1959 zlog_debug("Interface %s: clear by reset", ifp
->name
);
1961 /* Reset the interface */
1962 thread_add_event(master
, interface_down
, oi
, 0, NULL
);
1963 thread_add_event(master
, interface_up
, oi
, 0, NULL
);
1966 /* Clear interface */
1967 DEFUN (clear_ipv6_ospf6_interface
,
1968 clear_ipv6_ospf6_interface_cmd
,
1969 "clear ipv6 ospf6 interface [IFNAME]",
1977 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
1979 struct interface
*ifp
;
1981 if (argc
== 4) /* Clear all the ospfv3 interfaces. */
1983 FOR_ALL_INTERFACES (vrf
, ifp
)
1984 ospf6_interface_clear(vty
, ifp
);
1985 } else /* Interface name is specified. */
1987 if ((ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
,
1990 vty_out(vty
, "No such Interface: %s\n",
1991 argv
[idx_ifname
]->arg
);
1994 ospf6_interface_clear(vty
, ifp
);
2000 void install_element_ospf6_clear_interface(void)
2002 install_element(ENABLE_NODE
, &clear_ipv6_ospf6_interface_cmd
);
2005 DEFUN (debug_ospf6_interface
,
2006 debug_ospf6_interface_cmd
,
2007 "debug ospf6 interface",
2010 "Debug OSPFv3 Interface\n"
2013 OSPF6_DEBUG_INTERFACE_ON();
2017 DEFUN (no_debug_ospf6_interface
,
2018 no_debug_ospf6_interface_cmd
,
2019 "no debug ospf6 interface",
2023 "Debug OSPFv3 Interface\n"
2026 OSPF6_DEBUG_INTERFACE_OFF();
2030 int config_write_ospf6_debug_interface(struct vty
*vty
)
2032 if (IS_OSPF6_DEBUG_INTERFACE
)
2033 vty_out(vty
, "debug ospf6 interface\n");
2037 void install_element_ospf6_debug_interface(void)
2039 install_element(ENABLE_NODE
, &debug_ospf6_interface_cmd
);
2040 install_element(ENABLE_NODE
, &no_debug_ospf6_interface_cmd
);
2041 install_element(CONFIG_NODE
, &debug_ospf6_interface_cmd
);
2042 install_element(CONFIG_NODE
, &no_debug_ospf6_interface_cmd
);