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
= XCALLOC(MTYPE_OSPF6_IF
, sizeof(struct ospf6_interface
));
182 oi
->area
= (struct ospf6_area
*)NULL
;
183 oi
->neighbor_list
= list_new();
184 oi
->neighbor_list
->cmp
= ospf6_neighbor_cmp
;
185 oi
->linklocal_addr
= (struct in6_addr
*)NULL
;
186 oi
->instance_id
= OSPF6_INTERFACE_INSTANCE_ID
;
187 oi
->transdelay
= OSPF6_INTERFACE_TRANSDELAY
;
188 oi
->priority
= OSPF6_INTERFACE_PRIORITY
;
190 oi
->hello_interval
= OSPF_HELLO_INTERVAL_DEFAULT
;
191 oi
->dead_interval
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
192 oi
->rxmt_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
193 oi
->type
= ospf6_default_iftype(ifp
);
194 oi
->state
= OSPF6_INTERFACE_DOWN
;
199 /* Try to adjust I/O buffer size with IfMtu */
200 oi
->ifmtu
= ifp
->mtu6
;
201 iobuflen
= ospf6_iobuf_size(ifp
->mtu6
);
202 if (oi
->ifmtu
> iobuflen
) {
203 if (IS_OSPF6_DEBUG_INTERFACE
)
205 "Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
206 ifp
->name
, iobuflen
);
207 oi
->ifmtu
= iobuflen
;
210 QOBJ_REG(oi
, ospf6_interface
);
212 oi
->lsupdate_list
= ospf6_lsdb_create(oi
);
213 oi
->lsack_list
= ospf6_lsdb_create(oi
);
214 oi
->lsdb
= ospf6_lsdb_create(oi
);
215 oi
->lsdb
->hook_add
= ospf6_interface_lsdb_hook_add
;
216 oi
->lsdb
->hook_remove
= ospf6_interface_lsdb_hook_remove
;
217 oi
->lsdb_self
= ospf6_lsdb_create(oi
);
219 oi
->route_connected
=
220 OSPF6_ROUTE_TABLE_CREATE(INTERFACE
, CONNECTED_ROUTES
);
221 oi
->route_connected
->scope
= oi
;
228 oi
->cost
= ospf6_interface_get_cost(oi
);
233 void ospf6_interface_delete(struct ospf6_interface
*oi
)
235 struct listnode
*node
, *nnode
;
236 struct ospf6_neighbor
*on
;
240 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
))
241 ospf6_neighbor_delete(on
);
243 list_delete(&oi
->neighbor_list
);
245 THREAD_OFF(oi
->thread_send_hello
);
246 THREAD_OFF(oi
->thread_send_lsupdate
);
247 THREAD_OFF(oi
->thread_send_lsack
);
248 THREAD_OFF(oi
->thread_sso
);
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 /* disable from area list if possible */
272 ospf6_area_interface_delete(oi
);
274 XFREE(MTYPE_OSPF6_IF
, oi
);
277 void ospf6_interface_enable(struct ospf6_interface
*oi
)
279 UNSET_FLAG(oi
->flag
, OSPF6_INTERFACE_DISABLE
);
280 ospf6_interface_state_update(oi
->interface
);
283 void ospf6_interface_disable(struct ospf6_interface
*oi
)
285 SET_FLAG(oi
->flag
, OSPF6_INTERFACE_DISABLE
);
287 thread_execute(master
, interface_down
, oi
, 0);
289 ospf6_lsdb_remove_all(oi
->lsdb
);
290 ospf6_lsdb_remove_all(oi
->lsdb_self
);
291 ospf6_lsdb_remove_all(oi
->lsupdate_list
);
292 ospf6_lsdb_remove_all(oi
->lsack_list
);
294 THREAD_OFF(oi
->thread_send_hello
);
295 THREAD_OFF(oi
->thread_send_lsupdate
);
296 THREAD_OFF(oi
->thread_send_lsack
);
297 THREAD_OFF(oi
->thread_sso
);
299 THREAD_OFF(oi
->thread_network_lsa
);
300 THREAD_OFF(oi
->thread_link_lsa
);
301 THREAD_OFF(oi
->thread_intra_prefix_lsa
);
302 THREAD_OFF(oi
->thread_as_extern_lsa
);
305 static struct in6_addr
*
306 ospf6_interface_get_linklocal_address(struct interface
*ifp
)
310 struct in6_addr
*l
= (struct in6_addr
*)NULL
;
312 /* for each connected address */
313 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, n
, c
)) {
314 /* if family not AF_INET6, ignore */
315 if (c
->address
->family
!= AF_INET6
)
318 /* linklocal scope check */
319 if (IN6_IS_ADDR_LINKLOCAL(&c
->address
->u
.prefix6
))
320 l
= &c
->address
->u
.prefix6
;
325 void ospf6_interface_if_add(struct interface
*ifp
)
327 struct ospf6_interface
*oi
;
328 unsigned int iobuflen
;
330 oi
= (struct ospf6_interface
*)ifp
->info
;
334 /* Try to adjust I/O buffer size with IfMtu */
336 oi
->ifmtu
= ifp
->mtu6
;
337 iobuflen
= ospf6_iobuf_size(ifp
->mtu6
);
338 if (oi
->ifmtu
> iobuflen
) {
339 if (IS_OSPF6_DEBUG_INTERFACE
)
341 "Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
342 ifp
->name
, iobuflen
);
343 oi
->ifmtu
= iobuflen
;
346 /* interface start */
347 ospf6_interface_state_update(oi
->interface
);
350 void ospf6_interface_state_update(struct interface
*ifp
)
352 struct ospf6_interface
*oi
;
353 unsigned int iobuflen
;
355 oi
= (struct ospf6_interface
*)ifp
->info
;
358 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_DISABLE
))
361 /* Adjust the mtu values if the kernel told us something new */
362 if (ifp
->mtu6
!= oi
->ifmtu
) {
363 /* If nothing configured, accept it and check for buffer size */
365 oi
->ifmtu
= ifp
->mtu6
;
366 iobuflen
= ospf6_iobuf_size(ifp
->mtu6
);
367 if (oi
->ifmtu
> iobuflen
) {
368 if (IS_OSPF6_DEBUG_INTERFACE
)
370 "Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
371 ifp
->name
, iobuflen
);
372 oi
->ifmtu
= iobuflen
;
374 } else if (oi
->c_ifmtu
> ifp
->mtu6
) {
375 oi
->ifmtu
= ifp
->mtu6
;
377 "Configured mtu %u on %s overridden by kernel %u",
378 oi
->c_ifmtu
, ifp
->name
, ifp
->mtu6
);
380 oi
->ifmtu
= oi
->c_ifmtu
;
383 if (if_is_operative(ifp
)
384 && (ospf6_interface_get_linklocal_address(oi
->interface
)
385 || if_is_loopback(oi
->interface
)))
386 thread_execute(master
, interface_up
, oi
, 0);
388 thread_execute(master
, interface_down
, oi
, 0);
393 void ospf6_interface_connected_route_update(struct interface
*ifp
)
395 struct ospf6_interface
*oi
;
396 struct ospf6_route
*route
;
398 struct listnode
*node
, *nnode
;
399 struct in6_addr nh_addr
;
401 oi
= (struct ospf6_interface
*)ifp
->info
;
405 /* reset linklocal pointer */
406 oi
->linklocal_addr
= ospf6_interface_get_linklocal_address(ifp
);
408 /* if area is null, do not make connected-route list */
409 if (oi
->area
== NULL
)
412 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_DISABLE
))
415 /* update "route to advertise" interface route table */
416 ospf6_route_remove_all(oi
->route_connected
);
418 for (ALL_LIST_ELEMENTS(oi
->interface
->connected
, node
, nnode
, c
)) {
419 if (c
->address
->family
!= AF_INET6
)
422 CONTINUE_IF_ADDRESS_LINKLOCAL(IS_OSPF6_DEBUG_INTERFACE
,
424 CONTINUE_IF_ADDRESS_UNSPECIFIED(IS_OSPF6_DEBUG_INTERFACE
,
426 CONTINUE_IF_ADDRESS_LOOPBACK(IS_OSPF6_DEBUG_INTERFACE
,
428 CONTINUE_IF_ADDRESS_V4COMPAT(IS_OSPF6_DEBUG_INTERFACE
,
430 CONTINUE_IF_ADDRESS_V4MAPPED(IS_OSPF6_DEBUG_INTERFACE
,
434 if (oi
->plist_name
) {
435 struct prefix_list
*plist
;
436 enum prefix_list_type ret
;
437 char buf
[PREFIX2STR_BUFFER
];
439 prefix2str(c
->address
, buf
, sizeof(buf
));
440 plist
= prefix_list_lookup(AFI_IP6
, oi
->plist_name
);
441 ret
= prefix_list_apply(plist
, (void *)c
->address
);
442 if (ret
== PREFIX_DENY
) {
443 if (IS_OSPF6_DEBUG_INTERFACE
)
445 "%s on %s filtered by prefix-list %s ",
446 buf
, oi
->interface
->name
,
452 route
= ospf6_route_create();
453 memcpy(&route
->prefix
, c
->address
, sizeof(struct prefix
));
454 apply_mask(&route
->prefix
);
455 route
->type
= OSPF6_DEST_TYPE_NETWORK
;
456 route
->path
.area_id
= oi
->area
->area_id
;
457 route
->path
.type
= OSPF6_PATH_TYPE_INTRA
;
458 route
->path
.cost
= oi
->cost
;
459 inet_pton(AF_INET6
, "::1", &nh_addr
);
460 ospf6_route_add_nexthop(route
, oi
->interface
->ifindex
,
462 ospf6_route_add(route
, oi
->route_connected
);
465 /* create new Link-LSA */
466 OSPF6_LINK_LSA_SCHEDULE(oi
);
467 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
468 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
471 static void ospf6_interface_state_change(uint8_t next_state
,
472 struct ospf6_interface
*oi
)
476 prev_state
= oi
->state
;
477 oi
->state
= next_state
;
479 if (prev_state
== next_state
)
483 if (IS_OSPF6_DEBUG_INTERFACE
) {
484 zlog_debug("Interface state change %s: %s -> %s",
486 ospf6_interface_state_str
[prev_state
],
487 ospf6_interface_state_str
[next_state
]);
491 if ((prev_state
== OSPF6_INTERFACE_DR
492 || prev_state
== OSPF6_INTERFACE_BDR
)
493 && (next_state
!= OSPF6_INTERFACE_DR
494 && next_state
!= OSPF6_INTERFACE_BDR
))
495 ospf6_sso(oi
->interface
->ifindex
, &alldrouters6
,
498 if ((prev_state
!= OSPF6_INTERFACE_DR
499 && prev_state
!= OSPF6_INTERFACE_BDR
)
500 && (next_state
== OSPF6_INTERFACE_DR
501 || next_state
== OSPF6_INTERFACE_BDR
))
502 ospf6_sso(oi
->interface
->ifindex
, &alldrouters6
,
505 OSPF6_ROUTER_LSA_SCHEDULE(oi
->area
);
506 if (next_state
== OSPF6_INTERFACE_DOWN
) {
507 OSPF6_NETWORK_LSA_EXECUTE(oi
);
508 OSPF6_INTRA_PREFIX_LSA_EXECUTE_TRANSIT(oi
);
509 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
510 OSPF6_INTRA_PREFIX_LSA_EXECUTE_TRANSIT(oi
);
511 } else if (prev_state
== OSPF6_INTERFACE_DR
512 || next_state
== OSPF6_INTERFACE_DR
) {
513 OSPF6_NETWORK_LSA_SCHEDULE(oi
);
514 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
515 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
518 hook_call(ospf6_interface_change
, oi
, next_state
, prev_state
);
522 /* DR Election, RFC2328 section 9.4 */
524 #define IS_ELIGIBLE(n) \
525 ((n)->state >= OSPF6_NEIGHBOR_TWOWAY && (n)->priority != 0)
527 static struct ospf6_neighbor
*better_bdrouter(struct ospf6_neighbor
*a
,
528 struct ospf6_neighbor
*b
)
530 if ((a
== NULL
|| !IS_ELIGIBLE(a
) || a
->drouter
== a
->router_id
)
531 && (b
== NULL
|| !IS_ELIGIBLE(b
) || b
->drouter
== b
->router_id
))
533 else if (a
== NULL
|| !IS_ELIGIBLE(a
) || a
->drouter
== a
->router_id
)
535 else if (b
== NULL
|| !IS_ELIGIBLE(b
) || b
->drouter
== b
->router_id
)
538 if (a
->bdrouter
== a
->router_id
&& b
->bdrouter
!= b
->router_id
)
540 if (a
->bdrouter
!= a
->router_id
&& b
->bdrouter
== b
->router_id
)
543 if (a
->priority
> b
->priority
)
545 if (a
->priority
< b
->priority
)
548 if (ntohl(a
->router_id
) > ntohl(b
->router_id
))
550 if (ntohl(a
->router_id
) < ntohl(b
->router_id
))
553 zlog_warn("Router-ID duplicate ?");
557 static struct ospf6_neighbor
*better_drouter(struct ospf6_neighbor
*a
,
558 struct ospf6_neighbor
*b
)
560 if ((a
== NULL
|| !IS_ELIGIBLE(a
) || a
->drouter
!= a
->router_id
)
561 && (b
== NULL
|| !IS_ELIGIBLE(b
) || b
->drouter
!= b
->router_id
))
563 else if (a
== NULL
|| !IS_ELIGIBLE(a
) || a
->drouter
!= a
->router_id
)
565 else if (b
== NULL
|| !IS_ELIGIBLE(b
) || b
->drouter
!= b
->router_id
)
568 if (a
->drouter
== a
->router_id
&& b
->drouter
!= b
->router_id
)
570 if (a
->drouter
!= a
->router_id
&& b
->drouter
== b
->router_id
)
573 if (a
->priority
> b
->priority
)
575 if (a
->priority
< b
->priority
)
578 if (ntohl(a
->router_id
) > ntohl(b
->router_id
))
580 if (ntohl(a
->router_id
) < ntohl(b
->router_id
))
583 zlog_warn("Router-ID duplicate ?");
587 static uint8_t dr_election(struct ospf6_interface
*oi
)
589 struct listnode
*node
, *nnode
;
590 struct ospf6_neighbor
*on
, *drouter
, *bdrouter
, myself
;
591 struct ospf6_neighbor
*best_drouter
, *best_bdrouter
;
592 uint8_t next_state
= 0;
594 drouter
= bdrouter
= NULL
;
595 best_drouter
= best_bdrouter
= NULL
;
597 /* pseudo neighbor myself, including noting current DR/BDR (1) */
598 memset(&myself
, 0, sizeof(myself
));
599 inet_ntop(AF_INET
, &oi
->area
->ospf6
->router_id
, myself
.name
,
600 sizeof(myself
.name
));
601 myself
.state
= OSPF6_NEIGHBOR_TWOWAY
;
602 myself
.drouter
= oi
->drouter
;
603 myself
.bdrouter
= oi
->bdrouter
;
604 myself
.priority
= oi
->priority
;
605 myself
.router_id
= oi
->area
->ospf6
->router_id
;
607 /* Electing BDR (2) */
608 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
))
609 bdrouter
= better_bdrouter(bdrouter
, on
);
611 best_bdrouter
= bdrouter
;
612 bdrouter
= better_bdrouter(best_bdrouter
, &myself
);
614 /* Electing DR (3) */
615 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
))
616 drouter
= better_drouter(drouter
, on
);
618 best_drouter
= drouter
;
619 drouter
= better_drouter(best_drouter
, &myself
);
623 /* the router itself is newly/no longer DR/BDR (4) */
624 if ((drouter
== &myself
&& myself
.drouter
!= myself
.router_id
)
625 || (drouter
!= &myself
&& myself
.drouter
== myself
.router_id
)
626 || (bdrouter
== &myself
&& myself
.bdrouter
!= myself
.router_id
)
627 || (bdrouter
!= &myself
&& myself
.bdrouter
== myself
.router_id
)) {
628 myself
.drouter
= (drouter
? drouter
->router_id
: htonl(0));
629 myself
.bdrouter
= (bdrouter
? bdrouter
->router_id
: htonl(0));
631 /* compatible to Electing BDR (2) */
632 bdrouter
= better_bdrouter(best_bdrouter
, &myself
);
634 /* compatible to Electing DR (3) */
635 drouter
= better_drouter(best_drouter
, &myself
);
640 /* Set interface state accordingly (5) */
641 if (drouter
&& drouter
== &myself
)
642 next_state
= OSPF6_INTERFACE_DR
;
643 else if (bdrouter
&& bdrouter
== &myself
)
644 next_state
= OSPF6_INTERFACE_BDR
;
646 next_state
= OSPF6_INTERFACE_DROTHER
;
648 /* If NBMA, schedule Start for each neighbor having priority of 0 (6) */
651 /* If DR or BDR change, invoke AdjOK? for each neighbor (7) */
652 /* RFC 2328 section 12.4. Originating LSAs (3) will be handled
653 accordingly after AdjOK */
654 if (oi
->drouter
!= (drouter
? drouter
->router_id
: htonl(0))
655 || oi
->bdrouter
!= (bdrouter
? bdrouter
->router_id
: htonl(0))) {
656 if (IS_OSPF6_DEBUG_INTERFACE
)
657 zlog_debug("DR Election on %s: DR: %s BDR: %s",
659 (drouter
? drouter
->name
: "0.0.0.0"),
660 (bdrouter
? bdrouter
->name
: "0.0.0.0"));
662 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, node
, on
)) {
663 if (on
->state
< OSPF6_NEIGHBOR_TWOWAY
)
665 /* Schedule AdjOK. */
666 thread_add_event(master
, adj_ok
, on
, 0, NULL
);
670 oi
->drouter
= (drouter
? drouter
->router_id
: htonl(0));
671 oi
->bdrouter
= (bdrouter
? bdrouter
->router_id
: htonl(0));
676 /* Interface State Machine */
677 int interface_up(struct thread
*thread
)
679 struct ospf6_interface
*oi
;
681 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
682 assert(oi
&& oi
->interface
);
685 * Remove old pointer. If this thread wasn't a timer this
686 * operation won't make a difference, because it is already NULL.
688 oi
->thread_sso
= NULL
;
690 if (IS_OSPF6_DEBUG_INTERFACE
)
691 zlog_debug("Interface Event %s: [InterfaceUp]",
692 oi
->interface
->name
);
694 /* check physical interface is up */
695 if (!if_is_operative(oi
->interface
)) {
696 if (IS_OSPF6_DEBUG_INTERFACE
)
698 "Interface %s is down, can't execute [InterfaceUp]",
699 oi
->interface
->name
);
703 /* check interface has a link-local address */
704 if (!(ospf6_interface_get_linklocal_address(oi
->interface
)
705 || if_is_loopback(oi
->interface
))) {
706 if (IS_OSPF6_DEBUG_INTERFACE
)
708 "Interface %s has no link local address, can't execute [InterfaceUp]",
709 oi
->interface
->name
);
714 ospf6_interface_recalculate_cost(oi
);
716 /* if already enabled, do nothing */
717 if (oi
->state
> OSPF6_INTERFACE_DOWN
) {
718 if (IS_OSPF6_DEBUG_INTERFACE
)
719 zlog_debug("Interface %s already enabled",
720 oi
->interface
->name
);
724 /* If no area assigned, return */
725 if (oi
->area
== NULL
) {
727 "%s: Not scheduleing Hello for %s as there is no area assigned yet",
728 __func__
, oi
->interface
->name
);
734 * XXX: Schedule IPv6 group join for later, otherwise we might
735 * lose the multicast group registration caused by IPv6 group
738 if (oi
->sso_try_cnt
== 0) {
740 zlog_info("Scheduling %s for sso", oi
->interface
->name
);
741 thread_add_timer(master
, interface_up
, oi
,
742 OSPF6_INTERFACE_SSO_RETRY_INT
,
746 #endif /* __FreeBSD__ */
748 /* Join AllSPFRouters */
749 if (ospf6_sso(oi
->interface
->ifindex
, &allspfrouters6
, IPV6_JOIN_GROUP
)
751 if (oi
->sso_try_cnt
++ < OSPF6_INTERFACE_SSO_RETRY_MAX
) {
753 "Scheduling %s for sso retry, trial count: %d",
754 oi
->interface
->name
, oi
->sso_try_cnt
);
755 thread_add_timer(master
, interface_up
, oi
,
756 OSPF6_INTERFACE_SSO_RETRY_INT
,
761 oi
->sso_try_cnt
= 0; /* Reset on success */
763 /* Update interface route */
764 ospf6_interface_connected_route_update(oi
->interface
);
767 if (!CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_PASSIVE
)
768 && !if_is_loopback(oi
->interface
)) {
769 oi
->thread_send_hello
= NULL
;
770 thread_add_event(master
, ospf6_hello_send
, oi
, 0,
771 &oi
->thread_send_hello
);
774 /* decide next interface state */
775 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
) {
776 ospf6_interface_state_change(OSPF6_INTERFACE_POINTTOPOINT
, oi
);
777 } else if (oi
->priority
== 0)
778 ospf6_interface_state_change(OSPF6_INTERFACE_DROTHER
, oi
);
780 ospf6_interface_state_change(OSPF6_INTERFACE_WAITING
, oi
);
781 thread_add_timer(master
, wait_timer
, oi
, oi
->dead_interval
,
788 int wait_timer(struct thread
*thread
)
790 struct ospf6_interface
*oi
;
792 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
793 assert(oi
&& oi
->interface
);
795 if (IS_OSPF6_DEBUG_INTERFACE
)
796 zlog_debug("Interface Event %s: [WaitTimer]",
797 oi
->interface
->name
);
799 if (oi
->state
== OSPF6_INTERFACE_WAITING
)
800 ospf6_interface_state_change(dr_election(oi
), oi
);
805 int backup_seen(struct thread
*thread
)
807 struct ospf6_interface
*oi
;
809 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
810 assert(oi
&& oi
->interface
);
812 if (IS_OSPF6_DEBUG_INTERFACE
)
813 zlog_debug("Interface Event %s: [BackupSeen]",
814 oi
->interface
->name
);
816 if (oi
->state
== OSPF6_INTERFACE_WAITING
)
817 ospf6_interface_state_change(dr_election(oi
), oi
);
822 int neighbor_change(struct thread
*thread
)
824 struct ospf6_interface
*oi
;
826 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
827 assert(oi
&& oi
->interface
);
829 if (IS_OSPF6_DEBUG_INTERFACE
)
830 zlog_debug("Interface Event %s: [NeighborChange]",
831 oi
->interface
->name
);
833 if (oi
->state
== OSPF6_INTERFACE_DROTHER
834 || oi
->state
== OSPF6_INTERFACE_BDR
835 || oi
->state
== OSPF6_INTERFACE_DR
)
836 ospf6_interface_state_change(dr_election(oi
), oi
);
841 int interface_down(struct thread
*thread
)
843 struct ospf6_interface
*oi
;
844 struct listnode
*node
, *nnode
;
845 struct ospf6_neighbor
*on
;
847 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
848 assert(oi
&& oi
->interface
);
850 if (IS_OSPF6_DEBUG_INTERFACE
)
851 zlog_debug("Interface Event %s: [InterfaceDown]",
852 oi
->interface
->name
);
855 THREAD_OFF(oi
->thread_send_hello
);
857 /* Stop trying to set socket options. */
858 THREAD_OFF(oi
->thread_sso
);
860 /* Leave AllSPFRouters */
861 if (oi
->state
> OSPF6_INTERFACE_DOWN
)
862 ospf6_sso(oi
->interface
->ifindex
, &allspfrouters6
,
865 ospf6_interface_state_change(OSPF6_INTERFACE_DOWN
, oi
);
867 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
))
868 ospf6_neighbor_delete(on
);
870 list_delete_all_node(oi
->neighbor_list
);
872 /* When interface state is reset, also reset information about
873 * DR election, as it is no longer valid. */
874 oi
->drouter
= oi
->prev_drouter
= htonl(0);
875 oi
->bdrouter
= oi
->prev_bdrouter
= htonl(0);
880 /* show specified interface structure */
881 static int ospf6_interface_show(struct vty
*vty
, struct interface
*ifp
)
883 struct ospf6_interface
*oi
;
887 char strbuf
[PREFIX2STR_BUFFER
], drouter
[32], bdrouter
[32];
889 struct timeval res
, now
;
891 struct ospf6_lsa
*lsa
;
893 /* check physical interface type */
894 if (if_is_loopback(ifp
))
896 else if (if_is_broadcast(ifp
))
898 else if (if_is_pointopoint(ifp
))
899 type
= "POINTOPOINT";
903 vty_out(vty
, "%s is %s, type %s\n", ifp
->name
,
904 (if_is_operative(ifp
) ? "up" : "down"), type
);
905 vty_out(vty
, " Interface ID: %d\n", ifp
->ifindex
);
907 if (ifp
->info
== NULL
) {
908 vty_out(vty
, " OSPF not enabled on this interface\n");
911 oi
= (struct ospf6_interface
*)ifp
->info
;
913 vty_out(vty
, " Internet Address:\n");
915 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, i
, c
)) {
917 prefix2str(p
, strbuf
, sizeof(strbuf
));
920 vty_out(vty
, " inet : %s\n", strbuf
);
923 vty_out(vty
, " inet6: %s\n", strbuf
);
926 vty_out(vty
, " ??? : %s\n", strbuf
);
933 " Instance ID %d, Interface MTU %d (autodetect: %d)\n",
934 oi
->instance_id
, oi
->ifmtu
, ifp
->mtu6
);
935 vty_out(vty
, " MTU mismatch detection: %s\n",
936 oi
->mtu_ignore
? "disabled" : "enabled");
937 inet_ntop(AF_INET
, &oi
->area
->area_id
, strbuf
, sizeof(strbuf
));
938 vty_out(vty
, " Area ID %s, Cost %u\n", strbuf
, oi
->cost
);
940 vty_out(vty
, " Not Attached to Area\n");
942 vty_out(vty
, " State %s, Transmit Delay %d sec, Priority %d\n",
943 ospf6_interface_state_str
[oi
->state
], oi
->transdelay
,
945 vty_out(vty
, " Timer intervals configured:\n");
946 vty_out(vty
, " Hello %d, Dead %d, Retransmit %d\n",
947 oi
->hello_interval
, oi
->dead_interval
, oi
->rxmt_interval
);
949 inet_ntop(AF_INET
, &oi
->drouter
, drouter
, sizeof(drouter
));
950 inet_ntop(AF_INET
, &oi
->bdrouter
, bdrouter
, sizeof(bdrouter
));
951 vty_out(vty
, " DR: %s BDR: %s\n", drouter
, bdrouter
);
953 vty_out(vty
, " Number of I/F scoped LSAs is %u\n", oi
->lsdb
->count
);
958 if (oi
->thread_send_lsupdate
)
959 timersub(&oi
->thread_send_lsupdate
->u
.sands
, &now
, &res
);
960 timerstring(&res
, duration
, sizeof(duration
));
962 " %d Pending LSAs for LSUpdate in Time %s [thread %s]\n",
963 oi
->lsupdate_list
->count
, duration
,
964 (oi
->thread_send_lsupdate
? "on" : "off"));
965 for (ALL_LSDB(oi
->lsupdate_list
, lsa
))
966 vty_out(vty
, " %s\n", lsa
->name
);
969 if (oi
->thread_send_lsack
)
970 timersub(&oi
->thread_send_lsack
->u
.sands
, &now
, &res
);
971 timerstring(&res
, duration
, sizeof(duration
));
972 vty_out(vty
, " %d Pending LSAs for LSAck in Time %s [thread %s]\n",
973 oi
->lsack_list
->count
, duration
,
974 (oi
->thread_send_lsack
? "on" : "off"));
975 for (ALL_LSDB(oi
->lsack_list
, lsa
))
976 vty_out(vty
, " %s\n", lsa
->name
);
977 ospf6_bfd_show_info(vty
, oi
->bfd_info
, 1);
982 DEFUN (show_ipv6_ospf6_interface
,
983 show_ipv6_ospf6_interface_ifname_cmd
,
984 "show ipv6 ospf6 interface [IFNAME]",
991 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
993 struct interface
*ifp
;
996 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, VRF_DEFAULT
);
998 vty_out(vty
, "No such Interface: %s\n",
999 argv
[idx_ifname
]->arg
);
1002 ospf6_interface_show(vty
, ifp
);
1004 FOR_ALL_INTERFACES (vrf
, ifp
)
1005 ospf6_interface_show(vty
, ifp
);
1011 static int ospf6_interface_show_traffic(struct vty
*vty
, uint32_t vrf_id
,
1012 struct interface
*intf_ifp
,
1015 struct interface
*ifp
;
1016 struct vrf
*vrf
= NULL
;
1017 struct ospf6_interface
*oi
= NULL
;
1019 vrf
= vrf_lookup_by_id(vrf_id
);
1021 if (!display_once
) {
1023 vty_out(vty
, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface",
1024 " HELLO", " DB-Desc", " LS-Req", " LS-Update",
1026 vty_out(vty
, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "",
1027 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
1030 "--------------------------------------------------------------------------------------------\n");
1033 if (intf_ifp
== NULL
) {
1034 FOR_ALL_INTERFACES (vrf
, ifp
) {
1036 oi
= (struct ospf6_interface
*)ifp
->info
;
1041 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
1042 oi
->interface
->name
, oi
->hello_in
,
1043 oi
->hello_out
, oi
->db_desc_in
, oi
->db_desc_out
,
1044 oi
->ls_req_in
, oi
->ls_req_out
, oi
->ls_upd_in
,
1045 oi
->ls_upd_out
, oi
->ls_ack_in
, oi
->ls_ack_out
);
1048 oi
= intf_ifp
->info
;
1053 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
1054 oi
->interface
->name
, oi
->hello_in
, oi
->hello_out
,
1055 oi
->db_desc_in
, oi
->db_desc_out
, oi
->ls_req_in
,
1056 oi
->ls_req_out
, oi
->ls_upd_in
, oi
->ls_upd_out
,
1057 oi
->ls_ack_in
, oi
->ls_ack_out
);
1063 /* show interface */
1064 DEFUN (show_ipv6_ospf6_interface_traffic
,
1065 show_ipv6_ospf6_interface_traffic_cmd
,
1066 "show ipv6 ospf6 interface traffic [IFNAME]",
1071 "Protocol Packet counters\n"
1075 int display_once
= 0;
1076 char *intf_name
= NULL
;
1077 struct interface
*ifp
= NULL
;
1079 if (argv_find(argv
, argc
, "IFNAME", &idx_ifname
)) {
1080 intf_name
= argv
[idx_ifname
]->arg
;
1081 ifp
= if_lookup_by_name(intf_name
, VRF_DEFAULT
);
1083 vty_out(vty
, "No such Interface: %s\n", intf_name
);
1086 if (ifp
->info
== NULL
) {
1088 " OSPF not enabled on this interface %s\n",
1094 ospf6_interface_show_traffic(vty
, VRF_DEFAULT
, ifp
, display_once
);
1101 DEFUN (show_ipv6_ospf6_interface_ifname_prefix
,
1102 show_ipv6_ospf6_interface_ifname_prefix_cmd
,
1103 "show ipv6 ospf6 interface IFNAME prefix\
1106 |<X:X::X:X|X:X::X:X/M> [<match|detail>]\
1113 "Display connected prefixes to advertise\n"
1114 "Display details of the prefixes\n"
1115 OSPF6_ROUTE_ADDRESS_STR
1116 OSPF6_ROUTE_PREFIX_STR
1117 OSPF6_ROUTE_MATCH_STR
1118 "Display details of the prefixes\n")
1122 struct interface
*ifp
;
1123 struct ospf6_interface
*oi
;
1125 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, VRF_DEFAULT
);
1127 vty_out(vty
, "No such Interface: %s\n", argv
[idx_ifname
]->arg
);
1133 vty_out(vty
, "OSPFv3 is not enabled on %s\n",
1134 argv
[idx_ifname
]->arg
);
1138 ospf6_route_table_show(vty
, idx_prefix
, argc
, argv
,
1139 oi
->route_connected
);
1144 DEFUN (show_ipv6_ospf6_interface_prefix
,
1145 show_ipv6_ospf6_interface_prefix_cmd
,
1146 "show ipv6 ospf6 interface prefix\
1149 |<X:X::X:X|X:X::X:X/M> [<match|detail>]\
1155 "Display connected prefixes to advertise\n"
1156 "Display details of the prefixes\n"
1157 OSPF6_ROUTE_ADDRESS_STR
1158 OSPF6_ROUTE_PREFIX_STR
1159 OSPF6_ROUTE_MATCH_STR
1160 "Display details of the prefixes\n")
1162 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
1164 struct ospf6_interface
*oi
;
1165 struct interface
*ifp
;
1167 FOR_ALL_INTERFACES (vrf
, ifp
) {
1168 oi
= (struct ospf6_interface
*)ifp
->info
;
1172 ospf6_route_table_show(vty
, idx_prefix
, argc
, argv
,
1173 oi
->route_connected
);
1179 /* interface variable set command */
1180 DEFUN (ipv6_ospf6_ifmtu
,
1181 ipv6_ospf6_ifmtu_cmd
,
1182 "ipv6 ospf6 ifmtu (1-65535)",
1186 "OSPFv3 Interface MTU\n"
1189 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1191 struct ospf6_interface
*oi
;
1192 unsigned int ifmtu
, iobuflen
;
1193 struct listnode
*node
, *nnode
;
1194 struct ospf6_neighbor
*on
;
1198 oi
= (struct ospf6_interface
*)ifp
->info
;
1200 oi
= ospf6_interface_create(ifp
);
1203 ifmtu
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
1205 if (oi
->c_ifmtu
== ifmtu
)
1208 if (ifp
->mtu6
!= 0 && ifp
->mtu6
< ifmtu
) {
1210 "%s's ospf6 ifmtu cannot go beyond physical mtu (%d)\n",
1211 ifp
->name
, ifp
->mtu6
);
1212 return CMD_WARNING_CONFIG_FAILED
;
1215 if (oi
->ifmtu
< ifmtu
) {
1216 iobuflen
= ospf6_iobuf_size(ifmtu
);
1217 if (iobuflen
< ifmtu
) {
1219 "%s's ifmtu is adjusted to I/O buffer size (%d).\n",
1220 ifp
->name
, iobuflen
);
1221 oi
->ifmtu
= oi
->c_ifmtu
= iobuflen
;
1223 oi
->ifmtu
= oi
->c_ifmtu
= ifmtu
;
1225 oi
->ifmtu
= oi
->c_ifmtu
= ifmtu
;
1227 /* re-establish adjacencies */
1228 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
)) {
1229 THREAD_OFF(on
->inactivity_timer
);
1230 thread_add_event(master
, inactivity_timer
, on
, 0, NULL
);
1236 DEFUN (no_ipv6_ospf6_ifmtu
,
1237 no_ipv6_ospf6_ifmtu_cmd
,
1238 "no ipv6 ospf6 ifmtu [(1-65535)]",
1243 "OSPFv3 Interface MTU\n"
1246 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1247 struct ospf6_interface
*oi
;
1248 unsigned int iobuflen
;
1249 struct listnode
*node
, *nnode
;
1250 struct ospf6_neighbor
*on
;
1254 oi
= (struct ospf6_interface
*)ifp
->info
;
1256 oi
= ospf6_interface_create(ifp
);
1259 if (oi
->ifmtu
< ifp
->mtu
) {
1260 iobuflen
= ospf6_iobuf_size(ifp
->mtu
);
1261 if (iobuflen
< ifp
->mtu
) {
1263 "%s's ifmtu is adjusted to I/O buffer size (%d).\n",
1264 ifp
->name
, iobuflen
);
1265 oi
->ifmtu
= iobuflen
;
1267 oi
->ifmtu
= ifp
->mtu
;
1269 oi
->ifmtu
= ifp
->mtu
;
1273 /* re-establish adjacencies */
1274 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
)) {
1275 THREAD_OFF(on
->inactivity_timer
);
1276 thread_add_event(master
, inactivity_timer
, on
, 0, NULL
);
1282 DEFUN (ipv6_ospf6_cost
,
1283 ipv6_ospf6_cost_cmd
,
1284 "ipv6 ospf6 cost (1-65535)",
1288 "Outgoing metric of this interface\n")
1290 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1292 struct ospf6_interface
*oi
;
1293 unsigned long int lcost
;
1297 oi
= (struct ospf6_interface
*)ifp
->info
;
1299 oi
= ospf6_interface_create(ifp
);
1302 lcost
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
1304 if (lcost
> UINT32_MAX
) {
1305 vty_out(vty
, "Cost %ld is out of range\n", lcost
);
1306 return CMD_WARNING_CONFIG_FAILED
;
1309 if (oi
->cost
== lcost
)
1313 SET_FLAG(oi
->flag
, OSPF6_INTERFACE_NOAUTOCOST
);
1315 ospf6_interface_force_recalculate_cost(oi
);
1320 DEFUN (no_ipv6_ospf6_cost
,
1321 no_ipv6_ospf6_cost_cmd
,
1322 "no ipv6 ospf6 cost [(1-65535)]",
1326 "Calculate interface cost from bandwidth\n"
1327 "Outgoing metric of this interface\n")
1329 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1330 struct ospf6_interface
*oi
;
1333 oi
= (struct ospf6_interface
*)ifp
->info
;
1335 oi
= ospf6_interface_create(ifp
);
1338 UNSET_FLAG(oi
->flag
, OSPF6_INTERFACE_NOAUTOCOST
);
1340 ospf6_interface_recalculate_cost(oi
);
1345 DEFUN (auto_cost_reference_bandwidth
,
1346 auto_cost_reference_bandwidth_cmd
,
1347 "auto-cost reference-bandwidth (1-4294967)",
1348 "Calculate OSPF interface cost according to bandwidth\n"
1349 "Use reference bandwidth method to assign OSPF cost\n"
1350 "The reference bandwidth in terms of Mbits per second\n")
1352 VTY_DECLVAR_CONTEXT(ospf6
, o
);
1354 struct ospf6_area
*oa
;
1355 struct ospf6_interface
*oi
;
1356 struct listnode
*i
, *j
;
1359 refbw
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
1360 if (refbw
< 1 || refbw
> 4294967) {
1361 vty_out(vty
, "reference-bandwidth value is invalid\n");
1362 return CMD_WARNING_CONFIG_FAILED
;
1365 /* If reference bandwidth is changed. */
1366 if ((refbw
) == o
->ref_bandwidth
)
1369 o
->ref_bandwidth
= refbw
;
1370 for (ALL_LIST_ELEMENTS_RO(o
->area_list
, i
, oa
))
1371 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
1372 ospf6_interface_recalculate_cost(oi
);
1377 DEFUN (no_auto_cost_reference_bandwidth
,
1378 no_auto_cost_reference_bandwidth_cmd
,
1379 "no auto-cost reference-bandwidth [(1-4294967)]",
1381 "Calculate OSPF interface cost according to bandwidth\n"
1382 "Use reference bandwidth method to assign OSPF cost\n"
1383 "The reference bandwidth in terms of Mbits per second\n")
1385 VTY_DECLVAR_CONTEXT(ospf6
, o
);
1386 struct ospf6_area
*oa
;
1387 struct ospf6_interface
*oi
;
1388 struct listnode
*i
, *j
;
1390 if (o
->ref_bandwidth
== OSPF6_REFERENCE_BANDWIDTH
)
1393 o
->ref_bandwidth
= OSPF6_REFERENCE_BANDWIDTH
;
1394 for (ALL_LIST_ELEMENTS_RO(o
->area_list
, i
, oa
))
1395 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
1396 ospf6_interface_recalculate_cost(oi
);
1402 DEFUN (ipv6_ospf6_hellointerval
,
1403 ipv6_ospf6_hellointerval_cmd
,
1404 "ipv6 ospf6 hello-interval (1-65535)",
1407 "Time between HELLO packets\n"
1410 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1412 struct ospf6_interface
*oi
;
1415 oi
= (struct ospf6_interface
*)ifp
->info
;
1417 oi
= ospf6_interface_create(ifp
);
1420 oi
->hello_interval
= strmatch(argv
[0]->text
, "no")
1421 ? OSPF_HELLO_INTERVAL_DEFAULT
1422 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1426 ALIAS (ipv6_ospf6_hellointerval
,
1427 no_ipv6_ospf6_hellointerval_cmd
,
1428 "no ipv6 ospf6 hello-interval [(1-65535)]",
1432 "Time between HELLO packets\n"
1435 /* interface variable set command */
1436 DEFUN (ipv6_ospf6_deadinterval
,
1437 ipv6_ospf6_deadinterval_cmd
,
1438 "ipv6 ospf6 dead-interval (1-65535)",
1441 "Interval time after which a neighbor is declared down\n"
1444 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1446 struct ospf6_interface
*oi
;
1449 oi
= (struct ospf6_interface
*)ifp
->info
;
1451 oi
= ospf6_interface_create(ifp
);
1454 oi
->dead_interval
= strmatch(argv
[0]->arg
, "no")
1455 ? OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
1456 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1460 ALIAS (ipv6_ospf6_deadinterval
,
1461 no_ipv6_ospf6_deadinterval_cmd
,
1462 "no ipv6 ospf6 dead-interval [(1-65535)]",
1466 "Interval time after which a neighbor is declared down\n"
1469 /* interface variable set command */
1470 DEFUN (ipv6_ospf6_transmitdelay
,
1471 ipv6_ospf6_transmitdelay_cmd
,
1472 "ipv6 ospf6 transmit-delay (1-3600)",
1475 "Link state transmit delay\n"
1478 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1480 struct ospf6_interface
*oi
;
1483 oi
= (struct ospf6_interface
*)ifp
->info
;
1485 oi
= ospf6_interface_create(ifp
);
1488 oi
->transdelay
= strmatch(argv
[0]->text
, "no")
1489 ? OSPF6_INTERFACE_TRANSDELAY
1490 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1494 ALIAS (ipv6_ospf6_transmitdelay
,
1495 no_ipv6_ospf6_transmitdelay_cmd
,
1496 "no ipv6 ospf6 transmit-delay [(1-3600)]",
1500 "Link state transmit delay\n"
1503 /* interface variable set command */
1504 DEFUN (ipv6_ospf6_retransmitinterval
,
1505 ipv6_ospf6_retransmitinterval_cmd
,
1506 "ipv6 ospf6 retransmit-interval (1-65535)",
1509 "Time between retransmitting lost link state advertisements\n"
1512 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1514 struct ospf6_interface
*oi
;
1517 oi
= (struct ospf6_interface
*)ifp
->info
;
1519 oi
= ospf6_interface_create(ifp
);
1522 oi
->rxmt_interval
= strmatch(argv
[0]->text
, "no")
1523 ? OSPF_RETRANSMIT_INTERVAL_DEFAULT
1524 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1528 ALIAS (ipv6_ospf6_retransmitinterval
,
1529 no_ipv6_ospf6_retransmitinterval_cmd
,
1530 "no ipv6 ospf6 retransmit-interval [(1-65535)]",
1534 "Time between retransmitting lost link state advertisements\n"
1537 /* interface variable set command */
1538 DEFUN (ipv6_ospf6_priority
,
1539 ipv6_ospf6_priority_cmd
,
1540 "ipv6 ospf6 priority (0-255)",
1546 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1548 struct ospf6_interface
*oi
;
1551 oi
= (struct ospf6_interface
*)ifp
->info
;
1553 oi
= ospf6_interface_create(ifp
);
1556 oi
->priority
= strmatch(argv
[0]->text
, "no")
1557 ? OSPF6_INTERFACE_PRIORITY
1558 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1560 if (oi
->area
&& (oi
->state
== OSPF6_INTERFACE_DROTHER
1561 || oi
->state
== OSPF6_INTERFACE_BDR
1562 || oi
->state
== OSPF6_INTERFACE_DR
))
1563 ospf6_interface_state_change(dr_election(oi
), oi
);
1568 ALIAS (ipv6_ospf6_priority
,
1569 no_ipv6_ospf6_priority_cmd
,
1570 "no ipv6 ospf6 priority [(0-255)]",
1577 DEFUN (ipv6_ospf6_instance
,
1578 ipv6_ospf6_instance_cmd
,
1579 "ipv6 ospf6 instance-id (0-255)",
1582 "Instance ID for this interface\n"
1583 "Instance ID value\n")
1585 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1587 struct ospf6_interface
*oi
;
1590 oi
= (struct ospf6_interface
*)ifp
->info
;
1592 oi
= ospf6_interface_create(ifp
);
1595 oi
->instance_id
= strmatch(argv
[0]->text
, "no")
1596 ? OSPF6_INTERFACE_INSTANCE_ID
1597 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1601 ALIAS (ipv6_ospf6_instance
,
1602 no_ipv6_ospf6_instance_cmd
,
1603 "no ipv6 ospf6 instance-id [(0-255)]",
1607 "Instance ID for this interface\n"
1608 "Instance ID value\n")
1610 DEFUN (ipv6_ospf6_passive
,
1611 ipv6_ospf6_passive_cmd
,
1612 "ipv6 ospf6 passive",
1615 "Passive interface; no adjacency will be formed on this interface\n"
1618 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1619 struct ospf6_interface
*oi
;
1620 struct listnode
*node
, *nnode
;
1621 struct ospf6_neighbor
*on
;
1625 oi
= (struct ospf6_interface
*)ifp
->info
;
1627 oi
= ospf6_interface_create(ifp
);
1630 SET_FLAG(oi
->flag
, OSPF6_INTERFACE_PASSIVE
);
1631 THREAD_OFF(oi
->thread_send_hello
);
1632 THREAD_OFF(oi
->thread_sso
);
1634 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
)) {
1635 THREAD_OFF(on
->inactivity_timer
);
1636 thread_add_event(master
, inactivity_timer
, on
, 0, NULL
);
1642 DEFUN (no_ipv6_ospf6_passive
,
1643 no_ipv6_ospf6_passive_cmd
,
1644 "no ipv6 ospf6 passive",
1648 "passive interface: No Adjacency will be formed on this I/F\n"
1651 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1652 struct ospf6_interface
*oi
;
1655 oi
= (struct ospf6_interface
*)ifp
->info
;
1657 oi
= ospf6_interface_create(ifp
);
1660 UNSET_FLAG(oi
->flag
, OSPF6_INTERFACE_PASSIVE
);
1661 THREAD_OFF(oi
->thread_send_hello
);
1662 THREAD_OFF(oi
->thread_sso
);
1663 thread_add_event(master
, ospf6_hello_send
, oi
, 0,
1664 &oi
->thread_send_hello
);
1669 DEFUN (ipv6_ospf6_mtu_ignore
,
1670 ipv6_ospf6_mtu_ignore_cmd
,
1671 "ipv6 ospf6 mtu-ignore",
1674 "Disable MTU mismatch detection on this interface\n"
1677 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1678 struct ospf6_interface
*oi
;
1681 oi
= (struct ospf6_interface
*)ifp
->info
;
1683 oi
= ospf6_interface_create(ifp
);
1691 DEFUN (no_ipv6_ospf6_mtu_ignore
,
1692 no_ipv6_ospf6_mtu_ignore_cmd
,
1693 "no ipv6 ospf6 mtu-ignore",
1697 "Disable MTU mismatch detection on this interface\n"
1700 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1701 struct ospf6_interface
*oi
;
1704 oi
= (struct ospf6_interface
*)ifp
->info
;
1706 oi
= ospf6_interface_create(ifp
);
1714 DEFUN (ipv6_ospf6_advertise_prefix_list
,
1715 ipv6_ospf6_advertise_prefix_list_cmd
,
1716 "ipv6 ospf6 advertise prefix-list WORD",
1719 "Advertising options\n"
1720 "Filter prefix using prefix-list\n"
1721 "Prefix list name\n"
1724 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1726 struct ospf6_interface
*oi
;
1729 oi
= (struct ospf6_interface
*)ifp
->info
;
1731 oi
= ospf6_interface_create(ifp
);
1735 XFREE(MTYPE_CFG_PLIST_NAME
, oi
->plist_name
);
1736 oi
->plist_name
= XSTRDUP(MTYPE_CFG_PLIST_NAME
, argv
[idx_word
]->arg
);
1738 ospf6_interface_connected_route_update(oi
->interface
);
1741 OSPF6_LINK_LSA_SCHEDULE(oi
);
1742 if (oi
->state
== OSPF6_INTERFACE_DR
) {
1743 OSPF6_NETWORK_LSA_SCHEDULE(oi
);
1744 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
1746 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
1752 DEFUN (no_ipv6_ospf6_advertise_prefix_list
,
1753 no_ipv6_ospf6_advertise_prefix_list_cmd
,
1754 "no ipv6 ospf6 advertise prefix-list [WORD]",
1758 "Advertising options\n"
1759 "Filter prefix using prefix-list\n"
1760 "Prefix list name\n")
1762 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1763 struct ospf6_interface
*oi
;
1766 oi
= (struct ospf6_interface
*)ifp
->info
;
1768 oi
= ospf6_interface_create(ifp
);
1772 XFREE(MTYPE_CFG_PLIST_NAME
, oi
->plist_name
);
1774 ospf6_interface_connected_route_update(oi
->interface
);
1777 OSPF6_LINK_LSA_SCHEDULE(oi
);
1778 if (oi
->state
== OSPF6_INTERFACE_DR
) {
1779 OSPF6_NETWORK_LSA_SCHEDULE(oi
);
1780 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
1782 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
1788 DEFUN (ipv6_ospf6_network
,
1789 ipv6_ospf6_network_cmd
,
1790 "ipv6 ospf6 network <broadcast|point-to-point>",
1794 "Specify OSPF6 broadcast network\n"
1795 "Specify OSPF6 point-to-point network\n"
1798 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1799 int idx_network
= 3;
1800 struct ospf6_interface
*oi
;
1803 oi
= (struct ospf6_interface
*)ifp
->info
;
1805 oi
= ospf6_interface_create(ifp
);
1809 if (strncmp(argv
[idx_network
]->arg
, "b", 1) == 0) {
1810 if (oi
->type
== OSPF_IFTYPE_BROADCAST
)
1813 oi
->type
= OSPF_IFTYPE_BROADCAST
;
1814 } else if (strncmp(argv
[idx_network
]->arg
, "point-to-p", 10) == 0) {
1815 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
) {
1818 oi
->type
= OSPF_IFTYPE_POINTOPOINT
;
1821 /* Reset the interface */
1822 thread_execute(master
, interface_down
, oi
, 0);
1823 thread_execute(master
, interface_up
, oi
, 0);
1828 DEFUN (no_ipv6_ospf6_network
,
1829 no_ipv6_ospf6_network_cmd
,
1830 "no ipv6 ospf6 network [<broadcast|point-to-point>]",
1834 "Set default network type\n"
1835 "Specify OSPF6 broadcast network\n"
1836 "Specify OSPF6 point-to-point network\n")
1838 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1839 struct ospf6_interface
*oi
;
1844 oi
= (struct ospf6_interface
*)ifp
->info
;
1849 type
= ospf6_default_iftype(ifp
);
1850 if (oi
->type
== type
) {
1855 /* Reset the interface */
1856 thread_execute(master
, interface_down
, oi
, 0);
1857 thread_execute(master
, interface_up
, oi
, 0);
1862 static int config_write_ospf6_interface(struct vty
*vty
)
1864 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
1865 struct ospf6_interface
*oi
;
1866 struct interface
*ifp
;
1868 FOR_ALL_INTERFACES (vrf
, ifp
) {
1869 oi
= (struct ospf6_interface
*)ifp
->info
;
1873 vty_frame(vty
, "interface %s\n", oi
->interface
->name
);
1876 vty_out(vty
, " description %s\n", ifp
->desc
);
1878 vty_out(vty
, " ipv6 ospf6 ifmtu %d\n", oi
->c_ifmtu
);
1880 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_NOAUTOCOST
))
1881 vty_out(vty
, " ipv6 ospf6 cost %d\n", oi
->cost
);
1883 if (oi
->hello_interval
!= OSPF6_INTERFACE_HELLO_INTERVAL
)
1884 vty_out(vty
, " ipv6 ospf6 hello-interval %d\n",
1885 oi
->hello_interval
);
1887 if (oi
->dead_interval
!= OSPF6_INTERFACE_DEAD_INTERVAL
)
1888 vty_out(vty
, " ipv6 ospf6 dead-interval %d\n",
1891 if (oi
->rxmt_interval
!= OSPF6_INTERFACE_RXMT_INTERVAL
)
1892 vty_out(vty
, " ipv6 ospf6 retransmit-interval %d\n",
1895 if (oi
->priority
!= OSPF6_INTERFACE_PRIORITY
)
1896 vty_out(vty
, " ipv6 ospf6 priority %d\n", oi
->priority
);
1898 if (oi
->transdelay
!= OSPF6_INTERFACE_TRANSDELAY
)
1899 vty_out(vty
, " ipv6 ospf6 transmit-delay %d\n",
1902 if (oi
->instance_id
!= OSPF6_INTERFACE_INSTANCE_ID
)
1903 vty_out(vty
, " ipv6 ospf6 instance-id %d\n",
1907 vty_out(vty
, " ipv6 ospf6 advertise prefix-list %s\n",
1910 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_PASSIVE
))
1911 vty_out(vty
, " ipv6 ospf6 passive\n");
1914 vty_out(vty
, " ipv6 ospf6 mtu-ignore\n");
1916 if (oi
->type
!= ospf6_default_iftype(ifp
)) {
1917 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
)
1919 " ipv6 ospf6 network point-to-point\n");
1920 else if (oi
->type
== OSPF_IFTYPE_BROADCAST
)
1921 vty_out(vty
, " ipv6 ospf6 network broadcast\n");
1924 ospf6_bfd_write_config(vty
, oi
);
1926 vty_endframe(vty
, "!\n");
1931 static struct cmd_node interface_node
= {
1932 INTERFACE_NODE
, "%s(config-if)# ", 1 /* VTYSH */
1935 void ospf6_interface_init(void)
1937 /* Install interface node. */
1938 install_node(&interface_node
, config_write_ospf6_interface
);
1941 install_element(VIEW_NODE
, &show_ipv6_ospf6_interface_prefix_cmd
);
1942 install_element(VIEW_NODE
, &show_ipv6_ospf6_interface_ifname_cmd
);
1943 install_element(VIEW_NODE
,
1944 &show_ipv6_ospf6_interface_ifname_prefix_cmd
);
1945 install_element(VIEW_NODE
, &show_ipv6_ospf6_interface_traffic_cmd
);
1947 install_element(INTERFACE_NODE
, &ipv6_ospf6_cost_cmd
);
1948 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_cost_cmd
);
1949 install_element(INTERFACE_NODE
, &ipv6_ospf6_ifmtu_cmd
);
1950 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_ifmtu_cmd
);
1952 install_element(INTERFACE_NODE
, &ipv6_ospf6_deadinterval_cmd
);
1953 install_element(INTERFACE_NODE
, &ipv6_ospf6_hellointerval_cmd
);
1954 install_element(INTERFACE_NODE
, &ipv6_ospf6_priority_cmd
);
1955 install_element(INTERFACE_NODE
, &ipv6_ospf6_retransmitinterval_cmd
);
1956 install_element(INTERFACE_NODE
, &ipv6_ospf6_transmitdelay_cmd
);
1957 install_element(INTERFACE_NODE
, &ipv6_ospf6_instance_cmd
);
1958 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_deadinterval_cmd
);
1959 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_hellointerval_cmd
);
1960 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_priority_cmd
);
1961 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_retransmitinterval_cmd
);
1962 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_transmitdelay_cmd
);
1963 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_instance_cmd
);
1965 install_element(INTERFACE_NODE
, &ipv6_ospf6_passive_cmd
);
1966 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_passive_cmd
);
1968 install_element(INTERFACE_NODE
, &ipv6_ospf6_mtu_ignore_cmd
);
1969 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_mtu_ignore_cmd
);
1971 install_element(INTERFACE_NODE
, &ipv6_ospf6_advertise_prefix_list_cmd
);
1972 install_element(INTERFACE_NODE
,
1973 &no_ipv6_ospf6_advertise_prefix_list_cmd
);
1975 install_element(INTERFACE_NODE
, &ipv6_ospf6_network_cmd
);
1976 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_network_cmd
);
1978 /* reference bandwidth commands */
1979 install_element(OSPF6_NODE
, &auto_cost_reference_bandwidth_cmd
);
1980 install_element(OSPF6_NODE
, &no_auto_cost_reference_bandwidth_cmd
);
1983 /* Clear the specified interface structure */
1984 static void ospf6_interface_clear(struct vty
*vty
, struct interface
*ifp
)
1986 struct ospf6_interface
*oi
;
1988 if (!if_is_operative(ifp
))
1991 if (ifp
->info
== NULL
)
1994 oi
= (struct ospf6_interface
*)ifp
->info
;
1996 if (IS_OSPF6_DEBUG_INTERFACE
)
1997 zlog_debug("Interface %s: clear by reset", ifp
->name
);
1999 /* Reset the interface */
2000 thread_execute(master
, interface_down
, oi
, 0);
2001 thread_execute(master
, interface_up
, oi
, 0);
2004 /* Clear interface */
2005 DEFUN (clear_ipv6_ospf6_interface
,
2006 clear_ipv6_ospf6_interface_cmd
,
2007 "clear ipv6 ospf6 interface [IFNAME]",
2015 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
2017 struct interface
*ifp
;
2019 if (argc
== 4) /* Clear all the ospfv3 interfaces. */
2021 FOR_ALL_INTERFACES (vrf
, ifp
)
2022 ospf6_interface_clear(vty
, ifp
);
2023 } else /* Interface name is specified. */
2025 if ((ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
,
2028 vty_out(vty
, "No such Interface: %s\n",
2029 argv
[idx_ifname
]->arg
);
2032 ospf6_interface_clear(vty
, ifp
);
2038 void install_element_ospf6_clear_interface(void)
2040 install_element(ENABLE_NODE
, &clear_ipv6_ospf6_interface_cmd
);
2043 DEFUN (debug_ospf6_interface
,
2044 debug_ospf6_interface_cmd
,
2045 "debug ospf6 interface",
2048 "Debug OSPFv3 Interface\n"
2051 OSPF6_DEBUG_INTERFACE_ON();
2055 DEFUN (no_debug_ospf6_interface
,
2056 no_debug_ospf6_interface_cmd
,
2057 "no debug ospf6 interface",
2061 "Debug OSPFv3 Interface\n"
2064 OSPF6_DEBUG_INTERFACE_OFF();
2068 int config_write_ospf6_debug_interface(struct vty
*vty
)
2070 if (IS_OSPF6_DEBUG_INTERFACE
)
2071 vty_out(vty
, "debug ospf6 interface\n");
2075 void install_element_ospf6_debug_interface(void)
2077 install_element(ENABLE_NODE
, &debug_ospf6_interface_cmd
);
2078 install_element(ENABLE_NODE
, &no_debug_ospf6_interface_cmd
);
2079 install_element(CONFIG_NODE
, &debug_ospf6_interface_cmd
);
2080 install_element(CONFIG_NODE
, &no_debug_ospf6_interface_cmd
);