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 (oi
->area
== NULL
)
360 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_DISABLE
))
363 /* Adjust the mtu values if the kernel told us something new */
364 if (ifp
->mtu6
!= oi
->ifmtu
) {
365 /* If nothing configured, accept it and check for buffer size */
367 oi
->ifmtu
= ifp
->mtu6
;
368 iobuflen
= ospf6_iobuf_size(ifp
->mtu6
);
369 if (oi
->ifmtu
> iobuflen
) {
370 if (IS_OSPF6_DEBUG_INTERFACE
)
372 "Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
373 ifp
->name
, iobuflen
);
374 oi
->ifmtu
= iobuflen
;
376 } else if (oi
->c_ifmtu
> ifp
->mtu6
) {
377 oi
->ifmtu
= ifp
->mtu6
;
379 "Configured mtu %u on %s overridden by kernel %u",
380 oi
->c_ifmtu
, ifp
->name
, ifp
->mtu6
);
382 oi
->ifmtu
= oi
->c_ifmtu
;
385 if (if_is_operative(ifp
)
386 && (ospf6_interface_get_linklocal_address(oi
->interface
)
387 || if_is_loopback(oi
->interface
)))
388 thread_execute(master
, interface_up
, oi
, 0);
390 thread_execute(master
, interface_down
, oi
, 0);
395 void ospf6_interface_connected_route_update(struct interface
*ifp
)
397 struct ospf6_interface
*oi
;
398 struct ospf6_route
*route
;
400 struct listnode
*node
, *nnode
;
401 struct in6_addr nh_addr
;
403 oi
= (struct ospf6_interface
*)ifp
->info
;
407 /* reset linklocal pointer */
408 oi
->linklocal_addr
= ospf6_interface_get_linklocal_address(ifp
);
410 /* if area is null, do not make connected-route list */
411 if (oi
->area
== NULL
)
414 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_DISABLE
))
417 /* update "route to advertise" interface route table */
418 ospf6_route_remove_all(oi
->route_connected
);
420 for (ALL_LIST_ELEMENTS(oi
->interface
->connected
, node
, nnode
, c
)) {
421 if (c
->address
->family
!= AF_INET6
)
424 CONTINUE_IF_ADDRESS_LINKLOCAL(IS_OSPF6_DEBUG_INTERFACE
,
426 CONTINUE_IF_ADDRESS_UNSPECIFIED(IS_OSPF6_DEBUG_INTERFACE
,
428 CONTINUE_IF_ADDRESS_LOOPBACK(IS_OSPF6_DEBUG_INTERFACE
,
430 CONTINUE_IF_ADDRESS_V4COMPAT(IS_OSPF6_DEBUG_INTERFACE
,
432 CONTINUE_IF_ADDRESS_V4MAPPED(IS_OSPF6_DEBUG_INTERFACE
,
436 if (oi
->plist_name
) {
437 struct prefix_list
*plist
;
438 enum prefix_list_type ret
;
439 char buf
[PREFIX2STR_BUFFER
];
441 prefix2str(c
->address
, buf
, sizeof(buf
));
442 plist
= prefix_list_lookup(AFI_IP6
, oi
->plist_name
);
443 ret
= prefix_list_apply(plist
, (void *)c
->address
);
444 if (ret
== PREFIX_DENY
) {
445 if (IS_OSPF6_DEBUG_INTERFACE
)
447 "%s on %s filtered by prefix-list %s ",
448 buf
, oi
->interface
->name
,
454 route
= ospf6_route_create();
455 memcpy(&route
->prefix
, c
->address
, sizeof(struct prefix
));
456 apply_mask(&route
->prefix
);
457 route
->type
= OSPF6_DEST_TYPE_NETWORK
;
458 route
->path
.area_id
= oi
->area
->area_id
;
459 route
->path
.type
= OSPF6_PATH_TYPE_INTRA
;
460 route
->path
.cost
= oi
->cost
;
461 inet_pton(AF_INET6
, "::1", &nh_addr
);
462 ospf6_route_add_nexthop(route
, oi
->interface
->ifindex
,
464 ospf6_route_add(route
, oi
->route_connected
);
467 /* create new Link-LSA */
468 OSPF6_LINK_LSA_SCHEDULE(oi
);
469 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
470 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
473 static void ospf6_interface_state_change(uint8_t next_state
,
474 struct ospf6_interface
*oi
)
478 prev_state
= oi
->state
;
479 oi
->state
= next_state
;
481 if (prev_state
== next_state
)
485 if (IS_OSPF6_DEBUG_INTERFACE
) {
486 zlog_debug("Interface state change %s: %s -> %s",
488 ospf6_interface_state_str
[prev_state
],
489 ospf6_interface_state_str
[next_state
]);
493 if ((prev_state
== OSPF6_INTERFACE_DR
494 || prev_state
== OSPF6_INTERFACE_BDR
)
495 && (next_state
!= OSPF6_INTERFACE_DR
496 && next_state
!= OSPF6_INTERFACE_BDR
))
497 ospf6_sso(oi
->interface
->ifindex
, &alldrouters6
,
500 if ((prev_state
!= OSPF6_INTERFACE_DR
501 && prev_state
!= OSPF6_INTERFACE_BDR
)
502 && (next_state
== OSPF6_INTERFACE_DR
503 || next_state
== OSPF6_INTERFACE_BDR
))
504 ospf6_sso(oi
->interface
->ifindex
, &alldrouters6
,
507 OSPF6_ROUTER_LSA_SCHEDULE(oi
->area
);
508 if (next_state
== OSPF6_INTERFACE_DOWN
) {
509 OSPF6_NETWORK_LSA_EXECUTE(oi
);
510 OSPF6_INTRA_PREFIX_LSA_EXECUTE_TRANSIT(oi
);
511 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
512 OSPF6_INTRA_PREFIX_LSA_EXECUTE_TRANSIT(oi
);
513 } else if (prev_state
== OSPF6_INTERFACE_DR
514 || next_state
== OSPF6_INTERFACE_DR
) {
515 OSPF6_NETWORK_LSA_SCHEDULE(oi
);
516 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
517 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
520 hook_call(ospf6_interface_change
, oi
, next_state
, prev_state
);
524 /* DR Election, RFC2328 section 9.4 */
526 #define IS_ELIGIBLE(n) \
527 ((n)->state >= OSPF6_NEIGHBOR_TWOWAY && (n)->priority != 0)
529 static struct ospf6_neighbor
*better_bdrouter(struct ospf6_neighbor
*a
,
530 struct ospf6_neighbor
*b
)
532 if ((a
== NULL
|| !IS_ELIGIBLE(a
) || a
->drouter
== a
->router_id
)
533 && (b
== NULL
|| !IS_ELIGIBLE(b
) || b
->drouter
== b
->router_id
))
535 else if (a
== NULL
|| !IS_ELIGIBLE(a
) || a
->drouter
== a
->router_id
)
537 else if (b
== NULL
|| !IS_ELIGIBLE(b
) || b
->drouter
== b
->router_id
)
540 if (a
->bdrouter
== a
->router_id
&& b
->bdrouter
!= b
->router_id
)
542 if (a
->bdrouter
!= a
->router_id
&& b
->bdrouter
== b
->router_id
)
545 if (a
->priority
> b
->priority
)
547 if (a
->priority
< b
->priority
)
550 if (ntohl(a
->router_id
) > ntohl(b
->router_id
))
552 if (ntohl(a
->router_id
) < ntohl(b
->router_id
))
555 zlog_warn("Router-ID duplicate ?");
559 static struct ospf6_neighbor
*better_drouter(struct ospf6_neighbor
*a
,
560 struct ospf6_neighbor
*b
)
562 if ((a
== NULL
|| !IS_ELIGIBLE(a
) || a
->drouter
!= a
->router_id
)
563 && (b
== NULL
|| !IS_ELIGIBLE(b
) || b
->drouter
!= b
->router_id
))
565 else if (a
== NULL
|| !IS_ELIGIBLE(a
) || a
->drouter
!= a
->router_id
)
567 else if (b
== NULL
|| !IS_ELIGIBLE(b
) || b
->drouter
!= b
->router_id
)
570 if (a
->drouter
== a
->router_id
&& b
->drouter
!= b
->router_id
)
572 if (a
->drouter
!= a
->router_id
&& b
->drouter
== b
->router_id
)
575 if (a
->priority
> b
->priority
)
577 if (a
->priority
< b
->priority
)
580 if (ntohl(a
->router_id
) > ntohl(b
->router_id
))
582 if (ntohl(a
->router_id
) < ntohl(b
->router_id
))
585 zlog_warn("Router-ID duplicate ?");
589 static uint8_t dr_election(struct ospf6_interface
*oi
)
591 struct listnode
*node
, *nnode
;
592 struct ospf6_neighbor
*on
, *drouter
, *bdrouter
, myself
;
593 struct ospf6_neighbor
*best_drouter
, *best_bdrouter
;
594 uint8_t next_state
= 0;
596 drouter
= bdrouter
= NULL
;
597 best_drouter
= best_bdrouter
= NULL
;
599 /* pseudo neighbor myself, including noting current DR/BDR (1) */
600 memset(&myself
, 0, sizeof(myself
));
601 inet_ntop(AF_INET
, &oi
->area
->ospf6
->router_id
, myself
.name
,
602 sizeof(myself
.name
));
603 myself
.state
= OSPF6_NEIGHBOR_TWOWAY
;
604 myself
.drouter
= oi
->drouter
;
605 myself
.bdrouter
= oi
->bdrouter
;
606 myself
.priority
= oi
->priority
;
607 myself
.router_id
= oi
->area
->ospf6
->router_id
;
609 /* Electing BDR (2) */
610 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
))
611 bdrouter
= better_bdrouter(bdrouter
, on
);
613 best_bdrouter
= bdrouter
;
614 bdrouter
= better_bdrouter(best_bdrouter
, &myself
);
616 /* Electing DR (3) */
617 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
))
618 drouter
= better_drouter(drouter
, on
);
620 best_drouter
= drouter
;
621 drouter
= better_drouter(best_drouter
, &myself
);
625 /* the router itself is newly/no longer DR/BDR (4) */
626 if ((drouter
== &myself
&& myself
.drouter
!= myself
.router_id
)
627 || (drouter
!= &myself
&& myself
.drouter
== myself
.router_id
)
628 || (bdrouter
== &myself
&& myself
.bdrouter
!= myself
.router_id
)
629 || (bdrouter
!= &myself
&& myself
.bdrouter
== myself
.router_id
)) {
630 myself
.drouter
= (drouter
? drouter
->router_id
: htonl(0));
631 myself
.bdrouter
= (bdrouter
? bdrouter
->router_id
: htonl(0));
633 /* compatible to Electing BDR (2) */
634 bdrouter
= better_bdrouter(best_bdrouter
, &myself
);
636 /* compatible to Electing DR (3) */
637 drouter
= better_drouter(best_drouter
, &myself
);
642 /* Set interface state accordingly (5) */
643 if (drouter
&& drouter
== &myself
)
644 next_state
= OSPF6_INTERFACE_DR
;
645 else if (bdrouter
&& bdrouter
== &myself
)
646 next_state
= OSPF6_INTERFACE_BDR
;
648 next_state
= OSPF6_INTERFACE_DROTHER
;
650 /* If NBMA, schedule Start for each neighbor having priority of 0 (6) */
653 /* If DR or BDR change, invoke AdjOK? for each neighbor (7) */
654 /* RFC 2328 section 12.4. Originating LSAs (3) will be handled
655 accordingly after AdjOK */
656 if (oi
->drouter
!= (drouter
? drouter
->router_id
: htonl(0))
657 || oi
->bdrouter
!= (bdrouter
? bdrouter
->router_id
: htonl(0))) {
658 if (IS_OSPF6_DEBUG_INTERFACE
)
659 zlog_debug("DR Election on %s: DR: %s BDR: %s",
661 (drouter
? drouter
->name
: "0.0.0.0"),
662 (bdrouter
? bdrouter
->name
: "0.0.0.0"));
664 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, node
, on
)) {
665 if (on
->state
< OSPF6_NEIGHBOR_TWOWAY
)
667 /* Schedule AdjOK. */
668 thread_add_event(master
, adj_ok
, on
, 0, NULL
);
672 oi
->drouter
= (drouter
? drouter
->router_id
: htonl(0));
673 oi
->bdrouter
= (bdrouter
? bdrouter
->router_id
: htonl(0));
678 /* Interface State Machine */
679 int interface_up(struct thread
*thread
)
681 struct ospf6_interface
*oi
;
683 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
684 assert(oi
&& oi
->interface
);
687 * Remove old pointer. If this thread wasn't a timer this
688 * operation won't make a difference, because it is already NULL.
690 oi
->thread_sso
= NULL
;
692 if (IS_OSPF6_DEBUG_INTERFACE
)
693 zlog_debug("Interface Event %s: [InterfaceUp]",
694 oi
->interface
->name
);
696 /* check physical interface is up */
697 if (!if_is_operative(oi
->interface
)) {
698 if (IS_OSPF6_DEBUG_INTERFACE
)
700 "Interface %s is down, can't execute [InterfaceUp]",
701 oi
->interface
->name
);
705 /* check interface has a link-local address */
706 if (!(ospf6_interface_get_linklocal_address(oi
->interface
)
707 || if_is_loopback(oi
->interface
))) {
708 if (IS_OSPF6_DEBUG_INTERFACE
)
710 "Interface %s has no link local address, can't execute [InterfaceUp]",
711 oi
->interface
->name
);
716 ospf6_interface_recalculate_cost(oi
);
718 /* if already enabled, do nothing */
719 if (oi
->state
> OSPF6_INTERFACE_DOWN
) {
720 if (IS_OSPF6_DEBUG_INTERFACE
)
721 zlog_debug("Interface %s already enabled",
722 oi
->interface
->name
);
726 /* If no area assigned, return */
727 if (oi
->area
== NULL
) {
729 "%s: Not scheduleing Hello for %s as there is no area assigned yet",
730 __func__
, oi
->interface
->name
);
736 * XXX: Schedule IPv6 group join for later, otherwise we might
737 * lose the multicast group registration caused by IPv6 group
740 if (oi
->sso_try_cnt
== 0) {
742 zlog_info("Scheduling %s for sso", oi
->interface
->name
);
743 thread_add_timer(master
, interface_up
, oi
,
744 OSPF6_INTERFACE_SSO_RETRY_INT
,
748 #endif /* __FreeBSD__ */
750 /* Join AllSPFRouters */
751 if (ospf6_sso(oi
->interface
->ifindex
, &allspfrouters6
, IPV6_JOIN_GROUP
)
753 if (oi
->sso_try_cnt
++ < OSPF6_INTERFACE_SSO_RETRY_MAX
) {
755 "Scheduling %s for sso retry, trial count: %d",
756 oi
->interface
->name
, oi
->sso_try_cnt
);
757 thread_add_timer(master
, interface_up
, oi
,
758 OSPF6_INTERFACE_SSO_RETRY_INT
,
763 oi
->sso_try_cnt
= 0; /* Reset on success */
765 /* Update interface route */
766 ospf6_interface_connected_route_update(oi
->interface
);
769 if (!CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_PASSIVE
)
770 && !if_is_loopback(oi
->interface
)) {
771 oi
->thread_send_hello
= NULL
;
772 thread_add_event(master
, ospf6_hello_send
, oi
, 0,
773 &oi
->thread_send_hello
);
776 /* decide next interface state */
777 if ((if_is_pointopoint(oi
->interface
))
778 || (oi
->type
== OSPF_IFTYPE_POINTOPOINT
)) {
779 ospf6_interface_state_change(OSPF6_INTERFACE_POINTTOPOINT
, oi
);
780 } else if (oi
->priority
== 0)
781 ospf6_interface_state_change(OSPF6_INTERFACE_DROTHER
, oi
);
783 ospf6_interface_state_change(OSPF6_INTERFACE_WAITING
, oi
);
784 thread_add_timer(master
, wait_timer
, oi
, oi
->dead_interval
,
791 int wait_timer(struct thread
*thread
)
793 struct ospf6_interface
*oi
;
795 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
796 assert(oi
&& oi
->interface
);
798 if (IS_OSPF6_DEBUG_INTERFACE
)
799 zlog_debug("Interface Event %s: [WaitTimer]",
800 oi
->interface
->name
);
802 if (oi
->state
== OSPF6_INTERFACE_WAITING
)
803 ospf6_interface_state_change(dr_election(oi
), oi
);
808 int backup_seen(struct thread
*thread
)
810 struct ospf6_interface
*oi
;
812 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
813 assert(oi
&& oi
->interface
);
815 if (IS_OSPF6_DEBUG_INTERFACE
)
816 zlog_debug("Interface Event %s: [BackupSeen]",
817 oi
->interface
->name
);
819 if (oi
->state
== OSPF6_INTERFACE_WAITING
)
820 ospf6_interface_state_change(dr_election(oi
), oi
);
825 int neighbor_change(struct thread
*thread
)
827 struct ospf6_interface
*oi
;
829 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
830 assert(oi
&& oi
->interface
);
832 if (IS_OSPF6_DEBUG_INTERFACE
)
833 zlog_debug("Interface Event %s: [NeighborChange]",
834 oi
->interface
->name
);
836 if (oi
->state
== OSPF6_INTERFACE_DROTHER
837 || oi
->state
== OSPF6_INTERFACE_BDR
838 || oi
->state
== OSPF6_INTERFACE_DR
)
839 ospf6_interface_state_change(dr_election(oi
), oi
);
844 int interface_down(struct thread
*thread
)
846 struct ospf6_interface
*oi
;
847 struct listnode
*node
, *nnode
;
848 struct ospf6_neighbor
*on
;
850 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
851 assert(oi
&& oi
->interface
);
853 if (IS_OSPF6_DEBUG_INTERFACE
)
854 zlog_debug("Interface Event %s: [InterfaceDown]",
855 oi
->interface
->name
);
858 THREAD_OFF(oi
->thread_send_hello
);
860 /* Stop trying to set socket options. */
861 THREAD_OFF(oi
->thread_sso
);
863 /* Leave AllSPFRouters */
864 if (oi
->state
> OSPF6_INTERFACE_DOWN
)
865 ospf6_sso(oi
->interface
->ifindex
, &allspfrouters6
,
868 ospf6_interface_state_change(OSPF6_INTERFACE_DOWN
, oi
);
870 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
))
871 ospf6_neighbor_delete(on
);
873 list_delete_all_node(oi
->neighbor_list
);
875 /* When interface state is reset, also reset information about
876 * DR election, as it is no longer valid. */
877 oi
->drouter
= oi
->prev_drouter
= htonl(0);
878 oi
->bdrouter
= oi
->prev_bdrouter
= htonl(0);
883 /* show specified interface structure */
884 static int ospf6_interface_show(struct vty
*vty
, struct interface
*ifp
)
886 struct ospf6_interface
*oi
;
890 char strbuf
[PREFIX2STR_BUFFER
], drouter
[32], bdrouter
[32];
892 struct timeval res
, now
;
894 struct ospf6_lsa
*lsa
;
896 /* check physical interface type */
897 if (if_is_loopback(ifp
))
899 else if (if_is_broadcast(ifp
))
901 else if (if_is_pointopoint(ifp
))
902 type
= "POINTOPOINT";
906 vty_out(vty
, "%s is %s, type %s\n", ifp
->name
,
907 (if_is_operative(ifp
) ? "up" : "down"), type
);
908 vty_out(vty
, " Interface ID: %d\n", ifp
->ifindex
);
910 if (ifp
->info
== NULL
) {
911 vty_out(vty
, " OSPF not enabled on this interface\n");
914 oi
= (struct ospf6_interface
*)ifp
->info
;
916 vty_out(vty
, " Internet Address:\n");
918 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, i
, c
)) {
920 prefix2str(p
, strbuf
, sizeof(strbuf
));
923 vty_out(vty
, " inet : %s\n", strbuf
);
926 vty_out(vty
, " inet6: %s\n", strbuf
);
929 vty_out(vty
, " ??? : %s\n", strbuf
);
936 " Instance ID %d, Interface MTU %d (autodetect: %d)\n",
937 oi
->instance_id
, oi
->ifmtu
, ifp
->mtu6
);
938 vty_out(vty
, " MTU mismatch detection: %s\n",
939 oi
->mtu_ignore
? "disabled" : "enabled");
940 inet_ntop(AF_INET
, &oi
->area
->area_id
, strbuf
, sizeof(strbuf
));
941 vty_out(vty
, " Area ID %s, Cost %u\n", strbuf
, oi
->cost
);
943 vty_out(vty
, " Not Attached to Area\n");
945 vty_out(vty
, " State %s, Transmit Delay %d sec, Priority %d\n",
946 ospf6_interface_state_str
[oi
->state
], oi
->transdelay
,
948 vty_out(vty
, " Timer intervals configured:\n");
949 vty_out(vty
, " Hello %d, Dead %d, Retransmit %d\n",
950 oi
->hello_interval
, oi
->dead_interval
, oi
->rxmt_interval
);
952 inet_ntop(AF_INET
, &oi
->drouter
, drouter
, sizeof(drouter
));
953 inet_ntop(AF_INET
, &oi
->bdrouter
, bdrouter
, sizeof(bdrouter
));
954 vty_out(vty
, " DR: %s BDR: %s\n", drouter
, bdrouter
);
956 vty_out(vty
, " Number of I/F scoped LSAs is %u\n", oi
->lsdb
->count
);
961 if (oi
->thread_send_lsupdate
)
962 timersub(&oi
->thread_send_lsupdate
->u
.sands
, &now
, &res
);
963 timerstring(&res
, duration
, sizeof(duration
));
965 " %d Pending LSAs for LSUpdate in Time %s [thread %s]\n",
966 oi
->lsupdate_list
->count
, duration
,
967 (oi
->thread_send_lsupdate
? "on" : "off"));
968 for (ALL_LSDB(oi
->lsupdate_list
, lsa
))
969 vty_out(vty
, " %s\n", lsa
->name
);
972 if (oi
->thread_send_lsack
)
973 timersub(&oi
->thread_send_lsack
->u
.sands
, &now
, &res
);
974 timerstring(&res
, duration
, sizeof(duration
));
975 vty_out(vty
, " %d Pending LSAs for LSAck in Time %s [thread %s]\n",
976 oi
->lsack_list
->count
, duration
,
977 (oi
->thread_send_lsack
? "on" : "off"));
978 for (ALL_LSDB(oi
->lsack_list
, lsa
))
979 vty_out(vty
, " %s\n", lsa
->name
);
980 ospf6_bfd_show_info(vty
, oi
->bfd_info
, 1);
985 DEFUN (show_ipv6_ospf6_interface
,
986 show_ipv6_ospf6_interface_ifname_cmd
,
987 "show ipv6 ospf6 interface [IFNAME]",
994 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
996 struct interface
*ifp
;
999 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
,
1000 vrf_lookup_by_id(VRF_DEFAULT
));
1002 vty_out(vty
, "No such Interface: %s\n",
1003 argv
[idx_ifname
]->arg
);
1006 ospf6_interface_show(vty
, ifp
);
1008 FOR_ALL_INTERFACES (vrf
, ifp
)
1009 ospf6_interface_show(vty
, ifp
);
1015 static int ospf6_interface_show_traffic(struct vty
*vty
, uint32_t vrf_id
,
1016 struct interface
*intf_ifp
,
1019 struct interface
*ifp
;
1020 struct vrf
*vrf
= NULL
;
1021 struct ospf6_interface
*oi
= NULL
;
1023 vrf
= vrf_lookup_by_id(vrf_id
);
1025 if (!display_once
) {
1027 vty_out(vty
, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface",
1028 " HELLO", " DB-Desc", " LS-Req", " LS-Update",
1030 vty_out(vty
, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "",
1031 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
1034 "--------------------------------------------------------------------------------------------\n");
1037 if (intf_ifp
== NULL
) {
1038 FOR_ALL_INTERFACES (vrf
, ifp
) {
1040 oi
= (struct ospf6_interface
*)ifp
->info
;
1045 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
1046 oi
->interface
->name
, oi
->hello_in
,
1047 oi
->hello_out
, oi
->db_desc_in
, oi
->db_desc_out
,
1048 oi
->ls_req_in
, oi
->ls_req_out
, oi
->ls_upd_in
,
1049 oi
->ls_upd_out
, oi
->ls_ack_in
, oi
->ls_ack_out
);
1052 oi
= intf_ifp
->info
;
1057 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
1058 oi
->interface
->name
, oi
->hello_in
, oi
->hello_out
,
1059 oi
->db_desc_in
, oi
->db_desc_out
, oi
->ls_req_in
,
1060 oi
->ls_req_out
, oi
->ls_upd_in
, oi
->ls_upd_out
,
1061 oi
->ls_ack_in
, oi
->ls_ack_out
);
1067 /* show interface */
1068 DEFUN (show_ipv6_ospf6_interface_traffic
,
1069 show_ipv6_ospf6_interface_traffic_cmd
,
1070 "show ipv6 ospf6 interface traffic [IFNAME]",
1075 "Protocol Packet counters\n"
1079 int display_once
= 0;
1080 char *intf_name
= NULL
;
1081 struct interface
*ifp
= NULL
;
1083 if (argv_find(argv
, argc
, "IFNAME", &idx_ifname
)) {
1084 intf_name
= argv
[idx_ifname
]->arg
;
1085 ifp
= if_lookup_by_name(intf_name
,
1086 vrf_lookup_by_id(VRF_DEFAULT
));
1088 vty_out(vty
, "No such Interface: %s\n", intf_name
);
1091 if (ifp
->info
== NULL
) {
1093 " OSPF not enabled on this interface %s\n",
1099 ospf6_interface_show_traffic(vty
, VRF_DEFAULT
, ifp
, display_once
);
1106 DEFUN (show_ipv6_ospf6_interface_ifname_prefix
,
1107 show_ipv6_ospf6_interface_ifname_prefix_cmd
,
1108 "show ipv6 ospf6 interface IFNAME prefix\
1111 |<X:X::X:X|X:X::X:X/M> [<match|detail>]\
1118 "Display connected prefixes to advertise\n"
1119 "Display details of the prefixes\n"
1120 OSPF6_ROUTE_ADDRESS_STR
1121 OSPF6_ROUTE_PREFIX_STR
1122 OSPF6_ROUTE_MATCH_STR
1123 "Display details of the prefixes\n")
1127 struct interface
*ifp
;
1128 struct ospf6_interface
*oi
;
1130 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
,
1131 vrf_lookup_by_id(VRF_DEFAULT
));
1133 vty_out(vty
, "No such Interface: %s\n", argv
[idx_ifname
]->arg
);
1139 vty_out(vty
, "OSPFv3 is not enabled on %s\n",
1140 argv
[idx_ifname
]->arg
);
1144 ospf6_route_table_show(vty
, idx_prefix
, argc
, argv
,
1145 oi
->route_connected
);
1150 DEFUN (show_ipv6_ospf6_interface_prefix
,
1151 show_ipv6_ospf6_interface_prefix_cmd
,
1152 "show ipv6 ospf6 interface prefix\
1155 |<X:X::X:X|X:X::X:X/M> [<match|detail>]\
1161 "Display connected prefixes to advertise\n"
1162 "Display details of the prefixes\n"
1163 OSPF6_ROUTE_ADDRESS_STR
1164 OSPF6_ROUTE_PREFIX_STR
1165 OSPF6_ROUTE_MATCH_STR
1166 "Display details of the prefixes\n")
1168 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
1170 struct ospf6_interface
*oi
;
1171 struct interface
*ifp
;
1173 FOR_ALL_INTERFACES (vrf
, ifp
) {
1174 oi
= (struct ospf6_interface
*)ifp
->info
;
1178 ospf6_route_table_show(vty
, idx_prefix
, argc
, argv
,
1179 oi
->route_connected
);
1185 /* interface variable set command */
1186 DEFUN (ipv6_ospf6_ifmtu
,
1187 ipv6_ospf6_ifmtu_cmd
,
1188 "ipv6 ospf6 ifmtu (1-65535)",
1192 "OSPFv3 Interface MTU\n"
1195 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1197 struct ospf6_interface
*oi
;
1198 unsigned int ifmtu
, iobuflen
;
1199 struct listnode
*node
, *nnode
;
1200 struct ospf6_neighbor
*on
;
1204 oi
= (struct ospf6_interface
*)ifp
->info
;
1206 oi
= ospf6_interface_create(ifp
);
1209 ifmtu
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
1211 if (oi
->c_ifmtu
== ifmtu
)
1214 if (ifp
->mtu6
!= 0 && ifp
->mtu6
< ifmtu
) {
1216 "%s's ospf6 ifmtu cannot go beyond physical mtu (%d)\n",
1217 ifp
->name
, ifp
->mtu6
);
1218 return CMD_WARNING_CONFIG_FAILED
;
1221 if (oi
->ifmtu
< ifmtu
) {
1222 iobuflen
= ospf6_iobuf_size(ifmtu
);
1223 if (iobuflen
< ifmtu
) {
1225 "%s's ifmtu is adjusted to I/O buffer size (%d).\n",
1226 ifp
->name
, iobuflen
);
1227 oi
->ifmtu
= oi
->c_ifmtu
= iobuflen
;
1229 oi
->ifmtu
= oi
->c_ifmtu
= ifmtu
;
1231 oi
->ifmtu
= oi
->c_ifmtu
= ifmtu
;
1233 /* re-establish adjacencies */
1234 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
)) {
1235 THREAD_OFF(on
->inactivity_timer
);
1236 thread_add_event(master
, inactivity_timer
, on
, 0, NULL
);
1242 DEFUN (no_ipv6_ospf6_ifmtu
,
1243 no_ipv6_ospf6_ifmtu_cmd
,
1244 "no ipv6 ospf6 ifmtu [(1-65535)]",
1249 "OSPFv3 Interface MTU\n"
1252 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1253 struct ospf6_interface
*oi
;
1254 unsigned int iobuflen
;
1255 struct listnode
*node
, *nnode
;
1256 struct ospf6_neighbor
*on
;
1260 oi
= (struct ospf6_interface
*)ifp
->info
;
1262 oi
= ospf6_interface_create(ifp
);
1265 if (oi
->ifmtu
< ifp
->mtu
) {
1266 iobuflen
= ospf6_iobuf_size(ifp
->mtu
);
1267 if (iobuflen
< ifp
->mtu
) {
1269 "%s's ifmtu is adjusted to I/O buffer size (%d).\n",
1270 ifp
->name
, iobuflen
);
1271 oi
->ifmtu
= iobuflen
;
1273 oi
->ifmtu
= ifp
->mtu
;
1275 oi
->ifmtu
= ifp
->mtu
;
1279 /* re-establish adjacencies */
1280 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
)) {
1281 THREAD_OFF(on
->inactivity_timer
);
1282 thread_add_event(master
, inactivity_timer
, on
, 0, NULL
);
1288 DEFUN (ipv6_ospf6_cost
,
1289 ipv6_ospf6_cost_cmd
,
1290 "ipv6 ospf6 cost (1-65535)",
1294 "Outgoing metric of this interface\n")
1296 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1298 struct ospf6_interface
*oi
;
1299 unsigned long int lcost
;
1303 oi
= (struct ospf6_interface
*)ifp
->info
;
1305 oi
= ospf6_interface_create(ifp
);
1308 lcost
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
1310 if (lcost
> UINT32_MAX
) {
1311 vty_out(vty
, "Cost %ld is out of range\n", lcost
);
1312 return CMD_WARNING_CONFIG_FAILED
;
1315 if (oi
->cost
== lcost
)
1319 SET_FLAG(oi
->flag
, OSPF6_INTERFACE_NOAUTOCOST
);
1321 ospf6_interface_force_recalculate_cost(oi
);
1326 DEFUN (no_ipv6_ospf6_cost
,
1327 no_ipv6_ospf6_cost_cmd
,
1328 "no ipv6 ospf6 cost [(1-65535)]",
1332 "Calculate interface cost from bandwidth\n"
1333 "Outgoing metric of this interface\n")
1335 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1336 struct ospf6_interface
*oi
;
1339 oi
= (struct ospf6_interface
*)ifp
->info
;
1341 oi
= ospf6_interface_create(ifp
);
1344 UNSET_FLAG(oi
->flag
, OSPF6_INTERFACE_NOAUTOCOST
);
1346 ospf6_interface_recalculate_cost(oi
);
1351 DEFUN (auto_cost_reference_bandwidth
,
1352 auto_cost_reference_bandwidth_cmd
,
1353 "auto-cost reference-bandwidth (1-4294967)",
1354 "Calculate OSPF interface cost according to bandwidth\n"
1355 "Use reference bandwidth method to assign OSPF cost\n"
1356 "The reference bandwidth in terms of Mbits per second\n")
1358 VTY_DECLVAR_CONTEXT(ospf6
, o
);
1360 struct ospf6_area
*oa
;
1361 struct ospf6_interface
*oi
;
1362 struct listnode
*i
, *j
;
1365 refbw
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
1366 if (refbw
< 1 || refbw
> 4294967) {
1367 vty_out(vty
, "reference-bandwidth value is invalid\n");
1368 return CMD_WARNING_CONFIG_FAILED
;
1371 /* If reference bandwidth is changed. */
1372 if ((refbw
) == o
->ref_bandwidth
)
1375 o
->ref_bandwidth
= refbw
;
1376 for (ALL_LIST_ELEMENTS_RO(o
->area_list
, i
, oa
))
1377 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
1378 ospf6_interface_recalculate_cost(oi
);
1383 DEFUN (no_auto_cost_reference_bandwidth
,
1384 no_auto_cost_reference_bandwidth_cmd
,
1385 "no auto-cost reference-bandwidth [(1-4294967)]",
1387 "Calculate OSPF interface cost according to bandwidth\n"
1388 "Use reference bandwidth method to assign OSPF cost\n"
1389 "The reference bandwidth in terms of Mbits per second\n")
1391 VTY_DECLVAR_CONTEXT(ospf6
, o
);
1392 struct ospf6_area
*oa
;
1393 struct ospf6_interface
*oi
;
1394 struct listnode
*i
, *j
;
1396 if (o
->ref_bandwidth
== OSPF6_REFERENCE_BANDWIDTH
)
1399 o
->ref_bandwidth
= OSPF6_REFERENCE_BANDWIDTH
;
1400 for (ALL_LIST_ELEMENTS_RO(o
->area_list
, i
, oa
))
1401 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
1402 ospf6_interface_recalculate_cost(oi
);
1408 DEFUN (ipv6_ospf6_hellointerval
,
1409 ipv6_ospf6_hellointerval_cmd
,
1410 "ipv6 ospf6 hello-interval (1-65535)",
1413 "Time between HELLO packets\n"
1416 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1418 struct ospf6_interface
*oi
;
1421 oi
= (struct ospf6_interface
*)ifp
->info
;
1423 oi
= ospf6_interface_create(ifp
);
1426 oi
->hello_interval
= strmatch(argv
[0]->text
, "no")
1427 ? OSPF_HELLO_INTERVAL_DEFAULT
1428 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1432 ALIAS (ipv6_ospf6_hellointerval
,
1433 no_ipv6_ospf6_hellointerval_cmd
,
1434 "no ipv6 ospf6 hello-interval [(1-65535)]",
1438 "Time between HELLO packets\n"
1441 /* interface variable set command */
1442 DEFUN (ipv6_ospf6_deadinterval
,
1443 ipv6_ospf6_deadinterval_cmd
,
1444 "ipv6 ospf6 dead-interval (1-65535)",
1447 "Interval time after which a neighbor is declared down\n"
1450 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1452 struct ospf6_interface
*oi
;
1455 oi
= (struct ospf6_interface
*)ifp
->info
;
1457 oi
= ospf6_interface_create(ifp
);
1460 oi
->dead_interval
= strmatch(argv
[0]->arg
, "no")
1461 ? OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
1462 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1466 ALIAS (ipv6_ospf6_deadinterval
,
1467 no_ipv6_ospf6_deadinterval_cmd
,
1468 "no ipv6 ospf6 dead-interval [(1-65535)]",
1472 "Interval time after which a neighbor is declared down\n"
1475 /* interface variable set command */
1476 DEFUN (ipv6_ospf6_transmitdelay
,
1477 ipv6_ospf6_transmitdelay_cmd
,
1478 "ipv6 ospf6 transmit-delay (1-3600)",
1481 "Link state transmit delay\n"
1484 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1486 struct ospf6_interface
*oi
;
1489 oi
= (struct ospf6_interface
*)ifp
->info
;
1491 oi
= ospf6_interface_create(ifp
);
1494 oi
->transdelay
= strmatch(argv
[0]->text
, "no")
1495 ? OSPF6_INTERFACE_TRANSDELAY
1496 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1500 ALIAS (ipv6_ospf6_transmitdelay
,
1501 no_ipv6_ospf6_transmitdelay_cmd
,
1502 "no ipv6 ospf6 transmit-delay [(1-3600)]",
1506 "Link state transmit delay\n"
1509 /* interface variable set command */
1510 DEFUN (ipv6_ospf6_retransmitinterval
,
1511 ipv6_ospf6_retransmitinterval_cmd
,
1512 "ipv6 ospf6 retransmit-interval (1-65535)",
1515 "Time between retransmitting lost link state advertisements\n"
1518 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1520 struct ospf6_interface
*oi
;
1523 oi
= (struct ospf6_interface
*)ifp
->info
;
1525 oi
= ospf6_interface_create(ifp
);
1528 oi
->rxmt_interval
= strmatch(argv
[0]->text
, "no")
1529 ? OSPF_RETRANSMIT_INTERVAL_DEFAULT
1530 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1534 ALIAS (ipv6_ospf6_retransmitinterval
,
1535 no_ipv6_ospf6_retransmitinterval_cmd
,
1536 "no ipv6 ospf6 retransmit-interval [(1-65535)]",
1540 "Time between retransmitting lost link state advertisements\n"
1543 /* interface variable set command */
1544 DEFUN (ipv6_ospf6_priority
,
1545 ipv6_ospf6_priority_cmd
,
1546 "ipv6 ospf6 priority (0-255)",
1552 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1554 struct ospf6_interface
*oi
;
1557 oi
= (struct ospf6_interface
*)ifp
->info
;
1559 oi
= ospf6_interface_create(ifp
);
1562 oi
->priority
= strmatch(argv
[0]->text
, "no")
1563 ? OSPF6_INTERFACE_PRIORITY
1564 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1566 if (oi
->area
&& (oi
->state
== OSPF6_INTERFACE_DROTHER
1567 || oi
->state
== OSPF6_INTERFACE_BDR
1568 || oi
->state
== OSPF6_INTERFACE_DR
))
1569 ospf6_interface_state_change(dr_election(oi
), oi
);
1574 ALIAS (ipv6_ospf6_priority
,
1575 no_ipv6_ospf6_priority_cmd
,
1576 "no ipv6 ospf6 priority [(0-255)]",
1583 DEFUN (ipv6_ospf6_instance
,
1584 ipv6_ospf6_instance_cmd
,
1585 "ipv6 ospf6 instance-id (0-255)",
1588 "Instance ID for this interface\n"
1589 "Instance ID value\n")
1591 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1593 struct ospf6_interface
*oi
;
1596 oi
= (struct ospf6_interface
*)ifp
->info
;
1598 oi
= ospf6_interface_create(ifp
);
1601 oi
->instance_id
= strmatch(argv
[0]->text
, "no")
1602 ? OSPF6_INTERFACE_INSTANCE_ID
1603 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1607 ALIAS (ipv6_ospf6_instance
,
1608 no_ipv6_ospf6_instance_cmd
,
1609 "no ipv6 ospf6 instance-id [(0-255)]",
1613 "Instance ID for this interface\n"
1614 "Instance ID value\n")
1616 DEFUN (ipv6_ospf6_passive
,
1617 ipv6_ospf6_passive_cmd
,
1618 "ipv6 ospf6 passive",
1621 "Passive interface; no adjacency will be formed on this interface\n"
1624 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1625 struct ospf6_interface
*oi
;
1626 struct listnode
*node
, *nnode
;
1627 struct ospf6_neighbor
*on
;
1631 oi
= (struct ospf6_interface
*)ifp
->info
;
1633 oi
= ospf6_interface_create(ifp
);
1636 SET_FLAG(oi
->flag
, OSPF6_INTERFACE_PASSIVE
);
1637 THREAD_OFF(oi
->thread_send_hello
);
1638 THREAD_OFF(oi
->thread_sso
);
1640 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
)) {
1641 THREAD_OFF(on
->inactivity_timer
);
1642 thread_add_event(master
, inactivity_timer
, on
, 0, NULL
);
1648 DEFUN (no_ipv6_ospf6_passive
,
1649 no_ipv6_ospf6_passive_cmd
,
1650 "no ipv6 ospf6 passive",
1654 "passive interface: No Adjacency will be formed on this I/F\n"
1657 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1658 struct ospf6_interface
*oi
;
1661 oi
= (struct ospf6_interface
*)ifp
->info
;
1663 oi
= ospf6_interface_create(ifp
);
1666 UNSET_FLAG(oi
->flag
, OSPF6_INTERFACE_PASSIVE
);
1667 THREAD_OFF(oi
->thread_send_hello
);
1668 THREAD_OFF(oi
->thread_sso
);
1669 thread_add_event(master
, ospf6_hello_send
, oi
, 0,
1670 &oi
->thread_send_hello
);
1675 DEFUN (ipv6_ospf6_mtu_ignore
,
1676 ipv6_ospf6_mtu_ignore_cmd
,
1677 "ipv6 ospf6 mtu-ignore",
1680 "Disable MTU mismatch detection on this interface\n"
1683 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1684 struct ospf6_interface
*oi
;
1687 oi
= (struct ospf6_interface
*)ifp
->info
;
1689 oi
= ospf6_interface_create(ifp
);
1697 DEFUN (no_ipv6_ospf6_mtu_ignore
,
1698 no_ipv6_ospf6_mtu_ignore_cmd
,
1699 "no ipv6 ospf6 mtu-ignore",
1703 "Disable MTU mismatch detection on this interface\n"
1706 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1707 struct ospf6_interface
*oi
;
1710 oi
= (struct ospf6_interface
*)ifp
->info
;
1712 oi
= ospf6_interface_create(ifp
);
1720 DEFUN (ipv6_ospf6_advertise_prefix_list
,
1721 ipv6_ospf6_advertise_prefix_list_cmd
,
1722 "ipv6 ospf6 advertise prefix-list WORD",
1725 "Advertising options\n"
1726 "Filter prefix using prefix-list\n"
1727 "Prefix list name\n"
1730 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1732 struct ospf6_interface
*oi
;
1735 oi
= (struct ospf6_interface
*)ifp
->info
;
1737 oi
= ospf6_interface_create(ifp
);
1741 XFREE(MTYPE_CFG_PLIST_NAME
, oi
->plist_name
);
1742 oi
->plist_name
= XSTRDUP(MTYPE_CFG_PLIST_NAME
, argv
[idx_word
]->arg
);
1744 ospf6_interface_connected_route_update(oi
->interface
);
1747 OSPF6_LINK_LSA_SCHEDULE(oi
);
1748 if (oi
->state
== OSPF6_INTERFACE_DR
) {
1749 OSPF6_NETWORK_LSA_SCHEDULE(oi
);
1750 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
1752 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
1758 DEFUN (no_ipv6_ospf6_advertise_prefix_list
,
1759 no_ipv6_ospf6_advertise_prefix_list_cmd
,
1760 "no ipv6 ospf6 advertise prefix-list [WORD]",
1764 "Advertising options\n"
1765 "Filter prefix using prefix-list\n"
1766 "Prefix list name\n")
1768 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1769 struct ospf6_interface
*oi
;
1772 oi
= (struct ospf6_interface
*)ifp
->info
;
1774 oi
= ospf6_interface_create(ifp
);
1778 XFREE(MTYPE_CFG_PLIST_NAME
, oi
->plist_name
);
1780 ospf6_interface_connected_route_update(oi
->interface
);
1783 OSPF6_LINK_LSA_SCHEDULE(oi
);
1784 if (oi
->state
== OSPF6_INTERFACE_DR
) {
1785 OSPF6_NETWORK_LSA_SCHEDULE(oi
);
1786 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
1788 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
1794 DEFUN (ipv6_ospf6_network
,
1795 ipv6_ospf6_network_cmd
,
1796 "ipv6 ospf6 network <broadcast|point-to-point>",
1800 "Specify OSPF6 broadcast network\n"
1801 "Specify OSPF6 point-to-point network\n"
1804 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1805 int idx_network
= 3;
1806 struct ospf6_interface
*oi
;
1809 oi
= (struct ospf6_interface
*)ifp
->info
;
1811 oi
= ospf6_interface_create(ifp
);
1815 if (strncmp(argv
[idx_network
]->arg
, "b", 1) == 0) {
1816 if (oi
->type
== OSPF_IFTYPE_BROADCAST
)
1819 oi
->type
= OSPF_IFTYPE_BROADCAST
;
1820 } else if (strncmp(argv
[idx_network
]->arg
, "point-to-p", 10) == 0) {
1821 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
) {
1824 oi
->type
= OSPF_IFTYPE_POINTOPOINT
;
1827 /* Reset the interface */
1828 thread_execute(master
, interface_down
, oi
, 0);
1829 thread_execute(master
, interface_up
, oi
, 0);
1834 DEFUN (no_ipv6_ospf6_network
,
1835 no_ipv6_ospf6_network_cmd
,
1836 "no ipv6 ospf6 network [<broadcast|point-to-point>]",
1840 "Set default network type\n"
1841 "Specify OSPF6 broadcast network\n"
1842 "Specify OSPF6 point-to-point network\n")
1844 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1845 struct ospf6_interface
*oi
;
1850 oi
= (struct ospf6_interface
*)ifp
->info
;
1855 type
= ospf6_default_iftype(ifp
);
1856 if (oi
->type
== type
) {
1861 /* Reset the interface */
1862 thread_execute(master
, interface_down
, oi
, 0);
1863 thread_execute(master
, interface_up
, oi
, 0);
1868 static int config_write_ospf6_interface(struct vty
*vty
)
1870 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
1871 struct ospf6_interface
*oi
;
1872 struct interface
*ifp
;
1874 FOR_ALL_INTERFACES (vrf
, ifp
) {
1875 oi
= (struct ospf6_interface
*)ifp
->info
;
1879 vty_frame(vty
, "interface %s\n", oi
->interface
->name
);
1882 vty_out(vty
, " description %s\n", ifp
->desc
);
1884 vty_out(vty
, " ipv6 ospf6 ifmtu %d\n", oi
->c_ifmtu
);
1886 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_NOAUTOCOST
))
1887 vty_out(vty
, " ipv6 ospf6 cost %d\n", oi
->cost
);
1889 if (oi
->hello_interval
!= OSPF6_INTERFACE_HELLO_INTERVAL
)
1890 vty_out(vty
, " ipv6 ospf6 hello-interval %d\n",
1891 oi
->hello_interval
);
1893 if (oi
->dead_interval
!= OSPF6_INTERFACE_DEAD_INTERVAL
)
1894 vty_out(vty
, " ipv6 ospf6 dead-interval %d\n",
1897 if (oi
->rxmt_interval
!= OSPF6_INTERFACE_RXMT_INTERVAL
)
1898 vty_out(vty
, " ipv6 ospf6 retransmit-interval %d\n",
1901 if (oi
->priority
!= OSPF6_INTERFACE_PRIORITY
)
1902 vty_out(vty
, " ipv6 ospf6 priority %d\n", oi
->priority
);
1904 if (oi
->transdelay
!= OSPF6_INTERFACE_TRANSDELAY
)
1905 vty_out(vty
, " ipv6 ospf6 transmit-delay %d\n",
1908 if (oi
->instance_id
!= OSPF6_INTERFACE_INSTANCE_ID
)
1909 vty_out(vty
, " ipv6 ospf6 instance-id %d\n",
1913 vty_out(vty
, " ipv6 ospf6 advertise prefix-list %s\n",
1916 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_PASSIVE
))
1917 vty_out(vty
, " ipv6 ospf6 passive\n");
1920 vty_out(vty
, " ipv6 ospf6 mtu-ignore\n");
1922 if (oi
->type
!= ospf6_default_iftype(ifp
)) {
1923 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
)
1925 " ipv6 ospf6 network point-to-point\n");
1926 else if (oi
->type
== OSPF_IFTYPE_BROADCAST
)
1927 vty_out(vty
, " ipv6 ospf6 network broadcast\n");
1930 ospf6_bfd_write_config(vty
, oi
);
1932 vty_endframe(vty
, "!\n");
1937 static struct cmd_node interface_node
= {
1938 INTERFACE_NODE
, "%s(config-if)# ", 1 /* VTYSH */
1941 void ospf6_interface_init(void)
1943 /* Install interface node. */
1944 install_node(&interface_node
, config_write_ospf6_interface
);
1947 install_element(VIEW_NODE
, &show_ipv6_ospf6_interface_prefix_cmd
);
1948 install_element(VIEW_NODE
, &show_ipv6_ospf6_interface_ifname_cmd
);
1949 install_element(VIEW_NODE
,
1950 &show_ipv6_ospf6_interface_ifname_prefix_cmd
);
1951 install_element(VIEW_NODE
, &show_ipv6_ospf6_interface_traffic_cmd
);
1953 install_element(INTERFACE_NODE
, &ipv6_ospf6_cost_cmd
);
1954 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_cost_cmd
);
1955 install_element(INTERFACE_NODE
, &ipv6_ospf6_ifmtu_cmd
);
1956 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_ifmtu_cmd
);
1958 install_element(INTERFACE_NODE
, &ipv6_ospf6_deadinterval_cmd
);
1959 install_element(INTERFACE_NODE
, &ipv6_ospf6_hellointerval_cmd
);
1960 install_element(INTERFACE_NODE
, &ipv6_ospf6_priority_cmd
);
1961 install_element(INTERFACE_NODE
, &ipv6_ospf6_retransmitinterval_cmd
);
1962 install_element(INTERFACE_NODE
, &ipv6_ospf6_transmitdelay_cmd
);
1963 install_element(INTERFACE_NODE
, &ipv6_ospf6_instance_cmd
);
1964 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_deadinterval_cmd
);
1965 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_hellointerval_cmd
);
1966 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_priority_cmd
);
1967 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_retransmitinterval_cmd
);
1968 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_transmitdelay_cmd
);
1969 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_instance_cmd
);
1971 install_element(INTERFACE_NODE
, &ipv6_ospf6_passive_cmd
);
1972 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_passive_cmd
);
1974 install_element(INTERFACE_NODE
, &ipv6_ospf6_mtu_ignore_cmd
);
1975 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_mtu_ignore_cmd
);
1977 install_element(INTERFACE_NODE
, &ipv6_ospf6_advertise_prefix_list_cmd
);
1978 install_element(INTERFACE_NODE
,
1979 &no_ipv6_ospf6_advertise_prefix_list_cmd
);
1981 install_element(INTERFACE_NODE
, &ipv6_ospf6_network_cmd
);
1982 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_network_cmd
);
1984 /* reference bandwidth commands */
1985 install_element(OSPF6_NODE
, &auto_cost_reference_bandwidth_cmd
);
1986 install_element(OSPF6_NODE
, &no_auto_cost_reference_bandwidth_cmd
);
1989 /* Clear the specified interface structure */
1990 static void ospf6_interface_clear(struct vty
*vty
, struct interface
*ifp
)
1992 struct ospf6_interface
*oi
;
1994 if (!if_is_operative(ifp
))
1997 if (ifp
->info
== NULL
)
2000 oi
= (struct ospf6_interface
*)ifp
->info
;
2002 if (IS_OSPF6_DEBUG_INTERFACE
)
2003 zlog_debug("Interface %s: clear by reset", ifp
->name
);
2005 /* Reset the interface */
2006 thread_execute(master
, interface_down
, oi
, 0);
2007 thread_execute(master
, interface_up
, oi
, 0);
2010 /* Clear interface */
2011 DEFUN (clear_ipv6_ospf6_interface
,
2012 clear_ipv6_ospf6_interface_cmd
,
2013 "clear ipv6 ospf6 interface [IFNAME]",
2021 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
2023 struct interface
*ifp
;
2025 if (argc
== 4) /* Clear all the ospfv3 interfaces. */
2027 FOR_ALL_INTERFACES (vrf
, ifp
)
2028 ospf6_interface_clear(vty
, ifp
);
2029 } else /* Interface name is specified. */
2031 if ((ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
,
2032 vrf_lookup_by_id(VRF_DEFAULT
)))
2034 vty_out(vty
, "No such Interface: %s\n",
2035 argv
[idx_ifname
]->arg
);
2038 ospf6_interface_clear(vty
, ifp
);
2044 void install_element_ospf6_clear_interface(void)
2046 install_element(ENABLE_NODE
, &clear_ipv6_ospf6_interface_cmd
);
2049 DEFUN (debug_ospf6_interface
,
2050 debug_ospf6_interface_cmd
,
2051 "debug ospf6 interface",
2054 "Debug OSPFv3 Interface\n"
2057 OSPF6_DEBUG_INTERFACE_ON();
2061 DEFUN (no_debug_ospf6_interface
,
2062 no_debug_ospf6_interface_cmd
,
2063 "no debug ospf6 interface",
2067 "Debug OSPFv3 Interface\n"
2070 OSPF6_DEBUG_INTERFACE_OFF();
2074 int config_write_ospf6_debug_interface(struct vty
*vty
)
2076 if (IS_OSPF6_DEBUG_INTERFACE
)
2077 vty_out(vty
, "debug ospf6 interface\n");
2081 void install_element_ospf6_debug_interface(void)
2083 install_element(ENABLE_NODE
, &debug_ospf6_interface_cmd
);
2084 install_element(ENABLE_NODE
, &no_debug_ospf6_interface_cmd
);
2085 install_element(CONFIG_NODE
, &debug_ospf6_interface_cmd
);
2086 install_element(CONFIG_NODE
, &no_debug_ospf6_interface_cmd
);