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
, VRF_DEFAULT
);
1001 vty_out(vty
, "No such Interface: %s\n",
1002 argv
[idx_ifname
]->arg
);
1005 ospf6_interface_show(vty
, ifp
);
1007 FOR_ALL_INTERFACES (vrf
, ifp
)
1008 ospf6_interface_show(vty
, ifp
);
1014 static int ospf6_interface_show_traffic(struct vty
*vty
, uint32_t vrf_id
,
1015 struct interface
*intf_ifp
,
1018 struct interface
*ifp
;
1019 struct vrf
*vrf
= NULL
;
1020 struct ospf6_interface
*oi
= NULL
;
1022 vrf
= vrf_lookup_by_id(vrf_id
);
1024 if (!display_once
) {
1026 vty_out(vty
, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface",
1027 " HELLO", " DB-Desc", " LS-Req", " LS-Update",
1029 vty_out(vty
, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "",
1030 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
1033 "--------------------------------------------------------------------------------------------\n");
1036 if (intf_ifp
== NULL
) {
1037 FOR_ALL_INTERFACES (vrf
, ifp
) {
1039 oi
= (struct ospf6_interface
*)ifp
->info
;
1044 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
1045 oi
->interface
->name
, oi
->hello_in
,
1046 oi
->hello_out
, oi
->db_desc_in
, oi
->db_desc_out
,
1047 oi
->ls_req_in
, oi
->ls_req_out
, oi
->ls_upd_in
,
1048 oi
->ls_upd_out
, oi
->ls_ack_in
, oi
->ls_ack_out
);
1051 oi
= intf_ifp
->info
;
1056 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
1057 oi
->interface
->name
, oi
->hello_in
, oi
->hello_out
,
1058 oi
->db_desc_in
, oi
->db_desc_out
, oi
->ls_req_in
,
1059 oi
->ls_req_out
, oi
->ls_upd_in
, oi
->ls_upd_out
,
1060 oi
->ls_ack_in
, oi
->ls_ack_out
);
1066 /* show interface */
1067 DEFUN (show_ipv6_ospf6_interface_traffic
,
1068 show_ipv6_ospf6_interface_traffic_cmd
,
1069 "show ipv6 ospf6 interface traffic [IFNAME]",
1074 "Protocol Packet counters\n"
1078 int display_once
= 0;
1079 char *intf_name
= NULL
;
1080 struct interface
*ifp
= NULL
;
1082 if (argv_find(argv
, argc
, "IFNAME", &idx_ifname
)) {
1083 intf_name
= argv
[idx_ifname
]->arg
;
1084 ifp
= if_lookup_by_name(intf_name
, VRF_DEFAULT
);
1086 vty_out(vty
, "No such Interface: %s\n", intf_name
);
1089 if (ifp
->info
== NULL
) {
1091 " OSPF not enabled on this interface %s\n",
1097 ospf6_interface_show_traffic(vty
, VRF_DEFAULT
, ifp
, display_once
);
1104 DEFUN (show_ipv6_ospf6_interface_ifname_prefix
,
1105 show_ipv6_ospf6_interface_ifname_prefix_cmd
,
1106 "show ipv6 ospf6 interface IFNAME prefix\
1109 |<X:X::X:X|X:X::X:X/M> [<match|detail>]\
1116 "Display connected prefixes to advertise\n"
1117 "Display details of the prefixes\n"
1118 OSPF6_ROUTE_ADDRESS_STR
1119 OSPF6_ROUTE_PREFIX_STR
1120 OSPF6_ROUTE_MATCH_STR
1121 "Display details of the prefixes\n")
1125 struct interface
*ifp
;
1126 struct ospf6_interface
*oi
;
1128 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, VRF_DEFAULT
);
1130 vty_out(vty
, "No such Interface: %s\n", argv
[idx_ifname
]->arg
);
1136 vty_out(vty
, "OSPFv3 is not enabled on %s\n",
1137 argv
[idx_ifname
]->arg
);
1141 ospf6_route_table_show(vty
, idx_prefix
, argc
, argv
,
1142 oi
->route_connected
);
1147 DEFUN (show_ipv6_ospf6_interface_prefix
,
1148 show_ipv6_ospf6_interface_prefix_cmd
,
1149 "show ipv6 ospf6 interface prefix\
1152 |<X:X::X:X|X:X::X:X/M> [<match|detail>]\
1158 "Display connected prefixes to advertise\n"
1159 "Display details of the prefixes\n"
1160 OSPF6_ROUTE_ADDRESS_STR
1161 OSPF6_ROUTE_PREFIX_STR
1162 OSPF6_ROUTE_MATCH_STR
1163 "Display details of the prefixes\n")
1165 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
1167 struct ospf6_interface
*oi
;
1168 struct interface
*ifp
;
1170 FOR_ALL_INTERFACES (vrf
, ifp
) {
1171 oi
= (struct ospf6_interface
*)ifp
->info
;
1175 ospf6_route_table_show(vty
, idx_prefix
, argc
, argv
,
1176 oi
->route_connected
);
1182 /* interface variable set command */
1183 DEFUN (ipv6_ospf6_ifmtu
,
1184 ipv6_ospf6_ifmtu_cmd
,
1185 "ipv6 ospf6 ifmtu (1-65535)",
1189 "OSPFv3 Interface MTU\n"
1192 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1194 struct ospf6_interface
*oi
;
1195 unsigned int ifmtu
, iobuflen
;
1196 struct listnode
*node
, *nnode
;
1197 struct ospf6_neighbor
*on
;
1201 oi
= (struct ospf6_interface
*)ifp
->info
;
1203 oi
= ospf6_interface_create(ifp
);
1206 ifmtu
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
1208 if (oi
->c_ifmtu
== ifmtu
)
1211 if (ifp
->mtu6
!= 0 && ifp
->mtu6
< ifmtu
) {
1213 "%s's ospf6 ifmtu cannot go beyond physical mtu (%d)\n",
1214 ifp
->name
, ifp
->mtu6
);
1215 return CMD_WARNING_CONFIG_FAILED
;
1218 if (oi
->ifmtu
< ifmtu
) {
1219 iobuflen
= ospf6_iobuf_size(ifmtu
);
1220 if (iobuflen
< ifmtu
) {
1222 "%s's ifmtu is adjusted to I/O buffer size (%d).\n",
1223 ifp
->name
, iobuflen
);
1224 oi
->ifmtu
= oi
->c_ifmtu
= iobuflen
;
1226 oi
->ifmtu
= oi
->c_ifmtu
= ifmtu
;
1228 oi
->ifmtu
= oi
->c_ifmtu
= ifmtu
;
1230 /* re-establish adjacencies */
1231 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
)) {
1232 THREAD_OFF(on
->inactivity_timer
);
1233 thread_add_event(master
, inactivity_timer
, on
, 0, NULL
);
1239 DEFUN (no_ipv6_ospf6_ifmtu
,
1240 no_ipv6_ospf6_ifmtu_cmd
,
1241 "no ipv6 ospf6 ifmtu [(1-65535)]",
1246 "OSPFv3 Interface MTU\n"
1249 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1250 struct ospf6_interface
*oi
;
1251 unsigned int iobuflen
;
1252 struct listnode
*node
, *nnode
;
1253 struct ospf6_neighbor
*on
;
1257 oi
= (struct ospf6_interface
*)ifp
->info
;
1259 oi
= ospf6_interface_create(ifp
);
1262 if (oi
->ifmtu
< ifp
->mtu
) {
1263 iobuflen
= ospf6_iobuf_size(ifp
->mtu
);
1264 if (iobuflen
< ifp
->mtu
) {
1266 "%s's ifmtu is adjusted to I/O buffer size (%d).\n",
1267 ifp
->name
, iobuflen
);
1268 oi
->ifmtu
= iobuflen
;
1270 oi
->ifmtu
= ifp
->mtu
;
1272 oi
->ifmtu
= ifp
->mtu
;
1276 /* re-establish adjacencies */
1277 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
)) {
1278 THREAD_OFF(on
->inactivity_timer
);
1279 thread_add_event(master
, inactivity_timer
, on
, 0, NULL
);
1285 DEFUN (ipv6_ospf6_cost
,
1286 ipv6_ospf6_cost_cmd
,
1287 "ipv6 ospf6 cost (1-65535)",
1291 "Outgoing metric of this interface\n")
1293 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1295 struct ospf6_interface
*oi
;
1296 unsigned long int lcost
;
1300 oi
= (struct ospf6_interface
*)ifp
->info
;
1302 oi
= ospf6_interface_create(ifp
);
1305 lcost
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
1307 if (lcost
> UINT32_MAX
) {
1308 vty_out(vty
, "Cost %ld is out of range\n", lcost
);
1309 return CMD_WARNING_CONFIG_FAILED
;
1312 if (oi
->cost
== lcost
)
1316 SET_FLAG(oi
->flag
, OSPF6_INTERFACE_NOAUTOCOST
);
1318 ospf6_interface_force_recalculate_cost(oi
);
1323 DEFUN (no_ipv6_ospf6_cost
,
1324 no_ipv6_ospf6_cost_cmd
,
1325 "no ipv6 ospf6 cost [(1-65535)]",
1329 "Calculate interface cost from bandwidth\n"
1330 "Outgoing metric of this interface\n")
1332 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1333 struct ospf6_interface
*oi
;
1336 oi
= (struct ospf6_interface
*)ifp
->info
;
1338 oi
= ospf6_interface_create(ifp
);
1341 UNSET_FLAG(oi
->flag
, OSPF6_INTERFACE_NOAUTOCOST
);
1343 ospf6_interface_recalculate_cost(oi
);
1348 DEFUN (auto_cost_reference_bandwidth
,
1349 auto_cost_reference_bandwidth_cmd
,
1350 "auto-cost reference-bandwidth (1-4294967)",
1351 "Calculate OSPF interface cost according to bandwidth\n"
1352 "Use reference bandwidth method to assign OSPF cost\n"
1353 "The reference bandwidth in terms of Mbits per second\n")
1355 VTY_DECLVAR_CONTEXT(ospf6
, o
);
1357 struct ospf6_area
*oa
;
1358 struct ospf6_interface
*oi
;
1359 struct listnode
*i
, *j
;
1362 refbw
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
1363 if (refbw
< 1 || refbw
> 4294967) {
1364 vty_out(vty
, "reference-bandwidth value is invalid\n");
1365 return CMD_WARNING_CONFIG_FAILED
;
1368 /* If reference bandwidth is changed. */
1369 if ((refbw
) == o
->ref_bandwidth
)
1372 o
->ref_bandwidth
= refbw
;
1373 for (ALL_LIST_ELEMENTS_RO(o
->area_list
, i
, oa
))
1374 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
1375 ospf6_interface_recalculate_cost(oi
);
1380 DEFUN (no_auto_cost_reference_bandwidth
,
1381 no_auto_cost_reference_bandwidth_cmd
,
1382 "no auto-cost reference-bandwidth [(1-4294967)]",
1384 "Calculate OSPF interface cost according to bandwidth\n"
1385 "Use reference bandwidth method to assign OSPF cost\n"
1386 "The reference bandwidth in terms of Mbits per second\n")
1388 VTY_DECLVAR_CONTEXT(ospf6
, o
);
1389 struct ospf6_area
*oa
;
1390 struct ospf6_interface
*oi
;
1391 struct listnode
*i
, *j
;
1393 if (o
->ref_bandwidth
== OSPF6_REFERENCE_BANDWIDTH
)
1396 o
->ref_bandwidth
= OSPF6_REFERENCE_BANDWIDTH
;
1397 for (ALL_LIST_ELEMENTS_RO(o
->area_list
, i
, oa
))
1398 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
1399 ospf6_interface_recalculate_cost(oi
);
1405 DEFUN (ipv6_ospf6_hellointerval
,
1406 ipv6_ospf6_hellointerval_cmd
,
1407 "ipv6 ospf6 hello-interval (1-65535)",
1410 "Time between HELLO packets\n"
1413 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1415 struct ospf6_interface
*oi
;
1418 oi
= (struct ospf6_interface
*)ifp
->info
;
1420 oi
= ospf6_interface_create(ifp
);
1423 oi
->hello_interval
= strmatch(argv
[0]->text
, "no")
1424 ? OSPF_HELLO_INTERVAL_DEFAULT
1425 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1429 ALIAS (ipv6_ospf6_hellointerval
,
1430 no_ipv6_ospf6_hellointerval_cmd
,
1431 "no ipv6 ospf6 hello-interval [(1-65535)]",
1435 "Time between HELLO packets\n"
1438 /* interface variable set command */
1439 DEFUN (ipv6_ospf6_deadinterval
,
1440 ipv6_ospf6_deadinterval_cmd
,
1441 "ipv6 ospf6 dead-interval (1-65535)",
1444 "Interval time after which a neighbor is declared down\n"
1447 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1449 struct ospf6_interface
*oi
;
1452 oi
= (struct ospf6_interface
*)ifp
->info
;
1454 oi
= ospf6_interface_create(ifp
);
1457 oi
->dead_interval
= strmatch(argv
[0]->arg
, "no")
1458 ? OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
1459 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1463 ALIAS (ipv6_ospf6_deadinterval
,
1464 no_ipv6_ospf6_deadinterval_cmd
,
1465 "no ipv6 ospf6 dead-interval [(1-65535)]",
1469 "Interval time after which a neighbor is declared down\n"
1472 /* interface variable set command */
1473 DEFUN (ipv6_ospf6_transmitdelay
,
1474 ipv6_ospf6_transmitdelay_cmd
,
1475 "ipv6 ospf6 transmit-delay (1-3600)",
1478 "Link state transmit delay\n"
1481 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1483 struct ospf6_interface
*oi
;
1486 oi
= (struct ospf6_interface
*)ifp
->info
;
1488 oi
= ospf6_interface_create(ifp
);
1491 oi
->transdelay
= strmatch(argv
[0]->text
, "no")
1492 ? OSPF6_INTERFACE_TRANSDELAY
1493 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1497 ALIAS (ipv6_ospf6_transmitdelay
,
1498 no_ipv6_ospf6_transmitdelay_cmd
,
1499 "no ipv6 ospf6 transmit-delay [(1-3600)]",
1503 "Link state transmit delay\n"
1506 /* interface variable set command */
1507 DEFUN (ipv6_ospf6_retransmitinterval
,
1508 ipv6_ospf6_retransmitinterval_cmd
,
1509 "ipv6 ospf6 retransmit-interval (1-65535)",
1512 "Time between retransmitting lost link state advertisements\n"
1515 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1517 struct ospf6_interface
*oi
;
1520 oi
= (struct ospf6_interface
*)ifp
->info
;
1522 oi
= ospf6_interface_create(ifp
);
1525 oi
->rxmt_interval
= strmatch(argv
[0]->text
, "no")
1526 ? OSPF_RETRANSMIT_INTERVAL_DEFAULT
1527 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1531 ALIAS (ipv6_ospf6_retransmitinterval
,
1532 no_ipv6_ospf6_retransmitinterval_cmd
,
1533 "no ipv6 ospf6 retransmit-interval [(1-65535)]",
1537 "Time between retransmitting lost link state advertisements\n"
1540 /* interface variable set command */
1541 DEFUN (ipv6_ospf6_priority
,
1542 ipv6_ospf6_priority_cmd
,
1543 "ipv6 ospf6 priority (0-255)",
1549 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1551 struct ospf6_interface
*oi
;
1554 oi
= (struct ospf6_interface
*)ifp
->info
;
1556 oi
= ospf6_interface_create(ifp
);
1559 oi
->priority
= strmatch(argv
[0]->text
, "no")
1560 ? OSPF6_INTERFACE_PRIORITY
1561 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1563 if (oi
->area
&& (oi
->state
== OSPF6_INTERFACE_DROTHER
1564 || oi
->state
== OSPF6_INTERFACE_BDR
1565 || oi
->state
== OSPF6_INTERFACE_DR
))
1566 ospf6_interface_state_change(dr_election(oi
), oi
);
1571 ALIAS (ipv6_ospf6_priority
,
1572 no_ipv6_ospf6_priority_cmd
,
1573 "no ipv6 ospf6 priority [(0-255)]",
1580 DEFUN (ipv6_ospf6_instance
,
1581 ipv6_ospf6_instance_cmd
,
1582 "ipv6 ospf6 instance-id (0-255)",
1585 "Instance ID for this interface\n"
1586 "Instance ID value\n")
1588 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1590 struct ospf6_interface
*oi
;
1593 oi
= (struct ospf6_interface
*)ifp
->info
;
1595 oi
= ospf6_interface_create(ifp
);
1598 oi
->instance_id
= strmatch(argv
[0]->text
, "no")
1599 ? OSPF6_INTERFACE_INSTANCE_ID
1600 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1604 ALIAS (ipv6_ospf6_instance
,
1605 no_ipv6_ospf6_instance_cmd
,
1606 "no ipv6 ospf6 instance-id [(0-255)]",
1610 "Instance ID for this interface\n"
1611 "Instance ID value\n")
1613 DEFUN (ipv6_ospf6_passive
,
1614 ipv6_ospf6_passive_cmd
,
1615 "ipv6 ospf6 passive",
1618 "Passive interface; no adjacency will be formed on this interface\n"
1621 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1622 struct ospf6_interface
*oi
;
1623 struct listnode
*node
, *nnode
;
1624 struct ospf6_neighbor
*on
;
1628 oi
= (struct ospf6_interface
*)ifp
->info
;
1630 oi
= ospf6_interface_create(ifp
);
1633 SET_FLAG(oi
->flag
, OSPF6_INTERFACE_PASSIVE
);
1634 THREAD_OFF(oi
->thread_send_hello
);
1635 THREAD_OFF(oi
->thread_sso
);
1637 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
)) {
1638 THREAD_OFF(on
->inactivity_timer
);
1639 thread_add_event(master
, inactivity_timer
, on
, 0, NULL
);
1645 DEFUN (no_ipv6_ospf6_passive
,
1646 no_ipv6_ospf6_passive_cmd
,
1647 "no ipv6 ospf6 passive",
1651 "passive interface: No Adjacency will be formed on this I/F\n"
1654 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1655 struct ospf6_interface
*oi
;
1658 oi
= (struct ospf6_interface
*)ifp
->info
;
1660 oi
= ospf6_interface_create(ifp
);
1663 UNSET_FLAG(oi
->flag
, OSPF6_INTERFACE_PASSIVE
);
1664 THREAD_OFF(oi
->thread_send_hello
);
1665 THREAD_OFF(oi
->thread_sso
);
1666 thread_add_event(master
, ospf6_hello_send
, oi
, 0,
1667 &oi
->thread_send_hello
);
1672 DEFUN (ipv6_ospf6_mtu_ignore
,
1673 ipv6_ospf6_mtu_ignore_cmd
,
1674 "ipv6 ospf6 mtu-ignore",
1677 "Disable MTU mismatch detection on this interface\n"
1680 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1681 struct ospf6_interface
*oi
;
1684 oi
= (struct ospf6_interface
*)ifp
->info
;
1686 oi
= ospf6_interface_create(ifp
);
1694 DEFUN (no_ipv6_ospf6_mtu_ignore
,
1695 no_ipv6_ospf6_mtu_ignore_cmd
,
1696 "no ipv6 ospf6 mtu-ignore",
1700 "Disable MTU mismatch detection on this interface\n"
1703 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1704 struct ospf6_interface
*oi
;
1707 oi
= (struct ospf6_interface
*)ifp
->info
;
1709 oi
= ospf6_interface_create(ifp
);
1717 DEFUN (ipv6_ospf6_advertise_prefix_list
,
1718 ipv6_ospf6_advertise_prefix_list_cmd
,
1719 "ipv6 ospf6 advertise prefix-list WORD",
1722 "Advertising options\n"
1723 "Filter prefix using prefix-list\n"
1724 "Prefix list name\n"
1727 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1729 struct ospf6_interface
*oi
;
1732 oi
= (struct ospf6_interface
*)ifp
->info
;
1734 oi
= ospf6_interface_create(ifp
);
1738 XFREE(MTYPE_CFG_PLIST_NAME
, oi
->plist_name
);
1739 oi
->plist_name
= XSTRDUP(MTYPE_CFG_PLIST_NAME
, argv
[idx_word
]->arg
);
1741 ospf6_interface_connected_route_update(oi
->interface
);
1744 OSPF6_LINK_LSA_SCHEDULE(oi
);
1745 if (oi
->state
== OSPF6_INTERFACE_DR
) {
1746 OSPF6_NETWORK_LSA_SCHEDULE(oi
);
1747 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
1749 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
1755 DEFUN (no_ipv6_ospf6_advertise_prefix_list
,
1756 no_ipv6_ospf6_advertise_prefix_list_cmd
,
1757 "no ipv6 ospf6 advertise prefix-list [WORD]",
1761 "Advertising options\n"
1762 "Filter prefix using prefix-list\n"
1763 "Prefix list name\n")
1765 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1766 struct ospf6_interface
*oi
;
1769 oi
= (struct ospf6_interface
*)ifp
->info
;
1771 oi
= ospf6_interface_create(ifp
);
1775 XFREE(MTYPE_CFG_PLIST_NAME
, oi
->plist_name
);
1777 ospf6_interface_connected_route_update(oi
->interface
);
1780 OSPF6_LINK_LSA_SCHEDULE(oi
);
1781 if (oi
->state
== OSPF6_INTERFACE_DR
) {
1782 OSPF6_NETWORK_LSA_SCHEDULE(oi
);
1783 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
1785 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
1791 DEFUN (ipv6_ospf6_network
,
1792 ipv6_ospf6_network_cmd
,
1793 "ipv6 ospf6 network <broadcast|point-to-point>",
1797 "Specify OSPF6 broadcast network\n"
1798 "Specify OSPF6 point-to-point network\n"
1801 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1802 int idx_network
= 3;
1803 struct ospf6_interface
*oi
;
1806 oi
= (struct ospf6_interface
*)ifp
->info
;
1808 oi
= ospf6_interface_create(ifp
);
1812 if (strncmp(argv
[idx_network
]->arg
, "b", 1) == 0) {
1813 if (oi
->type
== OSPF_IFTYPE_BROADCAST
)
1816 oi
->type
= OSPF_IFTYPE_BROADCAST
;
1817 } else if (strncmp(argv
[idx_network
]->arg
, "point-to-p", 10) == 0) {
1818 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
) {
1821 oi
->type
= OSPF_IFTYPE_POINTOPOINT
;
1824 /* Reset the interface */
1825 thread_execute(master
, interface_down
, oi
, 0);
1826 thread_execute(master
, interface_up
, oi
, 0);
1831 DEFUN (no_ipv6_ospf6_network
,
1832 no_ipv6_ospf6_network_cmd
,
1833 "no ipv6 ospf6 network [<broadcast|point-to-point>]",
1837 "Set default network type\n"
1838 "Specify OSPF6 broadcast network\n"
1839 "Specify OSPF6 point-to-point network\n")
1841 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1842 struct ospf6_interface
*oi
;
1847 oi
= (struct ospf6_interface
*)ifp
->info
;
1852 type
= ospf6_default_iftype(ifp
);
1853 if (oi
->type
== type
) {
1858 /* Reset the interface */
1859 thread_execute(master
, interface_down
, oi
, 0);
1860 thread_execute(master
, interface_up
, oi
, 0);
1865 static int config_write_ospf6_interface(struct vty
*vty
)
1867 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
1868 struct ospf6_interface
*oi
;
1869 struct interface
*ifp
;
1871 FOR_ALL_INTERFACES (vrf
, ifp
) {
1872 oi
= (struct ospf6_interface
*)ifp
->info
;
1876 vty_frame(vty
, "interface %s\n", oi
->interface
->name
);
1879 vty_out(vty
, " description %s\n", ifp
->desc
);
1881 vty_out(vty
, " ipv6 ospf6 ifmtu %d\n", oi
->c_ifmtu
);
1883 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_NOAUTOCOST
))
1884 vty_out(vty
, " ipv6 ospf6 cost %d\n", oi
->cost
);
1886 if (oi
->hello_interval
!= OSPF6_INTERFACE_HELLO_INTERVAL
)
1887 vty_out(vty
, " ipv6 ospf6 hello-interval %d\n",
1888 oi
->hello_interval
);
1890 if (oi
->dead_interval
!= OSPF6_INTERFACE_DEAD_INTERVAL
)
1891 vty_out(vty
, " ipv6 ospf6 dead-interval %d\n",
1894 if (oi
->rxmt_interval
!= OSPF6_INTERFACE_RXMT_INTERVAL
)
1895 vty_out(vty
, " ipv6 ospf6 retransmit-interval %d\n",
1898 if (oi
->priority
!= OSPF6_INTERFACE_PRIORITY
)
1899 vty_out(vty
, " ipv6 ospf6 priority %d\n", oi
->priority
);
1901 if (oi
->transdelay
!= OSPF6_INTERFACE_TRANSDELAY
)
1902 vty_out(vty
, " ipv6 ospf6 transmit-delay %d\n",
1905 if (oi
->instance_id
!= OSPF6_INTERFACE_INSTANCE_ID
)
1906 vty_out(vty
, " ipv6 ospf6 instance-id %d\n",
1910 vty_out(vty
, " ipv6 ospf6 advertise prefix-list %s\n",
1913 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_PASSIVE
))
1914 vty_out(vty
, " ipv6 ospf6 passive\n");
1917 vty_out(vty
, " ipv6 ospf6 mtu-ignore\n");
1919 if (oi
->type
!= ospf6_default_iftype(ifp
)) {
1920 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
)
1922 " ipv6 ospf6 network point-to-point\n");
1923 else if (oi
->type
== OSPF_IFTYPE_BROADCAST
)
1924 vty_out(vty
, " ipv6 ospf6 network broadcast\n");
1927 ospf6_bfd_write_config(vty
, oi
);
1929 vty_endframe(vty
, "!\n");
1934 static struct cmd_node interface_node
= {
1935 INTERFACE_NODE
, "%s(config-if)# ", 1 /* VTYSH */
1938 void ospf6_interface_init(void)
1940 /* Install interface node. */
1941 install_node(&interface_node
, config_write_ospf6_interface
);
1944 install_element(VIEW_NODE
, &show_ipv6_ospf6_interface_prefix_cmd
);
1945 install_element(VIEW_NODE
, &show_ipv6_ospf6_interface_ifname_cmd
);
1946 install_element(VIEW_NODE
,
1947 &show_ipv6_ospf6_interface_ifname_prefix_cmd
);
1948 install_element(VIEW_NODE
, &show_ipv6_ospf6_interface_traffic_cmd
);
1950 install_element(INTERFACE_NODE
, &ipv6_ospf6_cost_cmd
);
1951 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_cost_cmd
);
1952 install_element(INTERFACE_NODE
, &ipv6_ospf6_ifmtu_cmd
);
1953 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_ifmtu_cmd
);
1955 install_element(INTERFACE_NODE
, &ipv6_ospf6_deadinterval_cmd
);
1956 install_element(INTERFACE_NODE
, &ipv6_ospf6_hellointerval_cmd
);
1957 install_element(INTERFACE_NODE
, &ipv6_ospf6_priority_cmd
);
1958 install_element(INTERFACE_NODE
, &ipv6_ospf6_retransmitinterval_cmd
);
1959 install_element(INTERFACE_NODE
, &ipv6_ospf6_transmitdelay_cmd
);
1960 install_element(INTERFACE_NODE
, &ipv6_ospf6_instance_cmd
);
1961 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_deadinterval_cmd
);
1962 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_hellointerval_cmd
);
1963 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_priority_cmd
);
1964 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_retransmitinterval_cmd
);
1965 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_transmitdelay_cmd
);
1966 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_instance_cmd
);
1968 install_element(INTERFACE_NODE
, &ipv6_ospf6_passive_cmd
);
1969 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_passive_cmd
);
1971 install_element(INTERFACE_NODE
, &ipv6_ospf6_mtu_ignore_cmd
);
1972 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_mtu_ignore_cmd
);
1974 install_element(INTERFACE_NODE
, &ipv6_ospf6_advertise_prefix_list_cmd
);
1975 install_element(INTERFACE_NODE
,
1976 &no_ipv6_ospf6_advertise_prefix_list_cmd
);
1978 install_element(INTERFACE_NODE
, &ipv6_ospf6_network_cmd
);
1979 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_network_cmd
);
1981 /* reference bandwidth commands */
1982 install_element(OSPF6_NODE
, &auto_cost_reference_bandwidth_cmd
);
1983 install_element(OSPF6_NODE
, &no_auto_cost_reference_bandwidth_cmd
);
1986 /* Clear the specified interface structure */
1987 static void ospf6_interface_clear(struct vty
*vty
, struct interface
*ifp
)
1989 struct ospf6_interface
*oi
;
1991 if (!if_is_operative(ifp
))
1994 if (ifp
->info
== NULL
)
1997 oi
= (struct ospf6_interface
*)ifp
->info
;
1999 if (IS_OSPF6_DEBUG_INTERFACE
)
2000 zlog_debug("Interface %s: clear by reset", ifp
->name
);
2002 /* Reset the interface */
2003 thread_execute(master
, interface_down
, oi
, 0);
2004 thread_execute(master
, interface_up
, oi
, 0);
2007 /* Clear interface */
2008 DEFUN (clear_ipv6_ospf6_interface
,
2009 clear_ipv6_ospf6_interface_cmd
,
2010 "clear ipv6 ospf6 interface [IFNAME]",
2018 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
2020 struct interface
*ifp
;
2022 if (argc
== 4) /* Clear all the ospfv3 interfaces. */
2024 FOR_ALL_INTERFACES (vrf
, ifp
)
2025 ospf6_interface_clear(vty
, ifp
);
2026 } else /* Interface name is specified. */
2028 if ((ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
,
2031 vty_out(vty
, "No such Interface: %s\n",
2032 argv
[idx_ifname
]->arg
);
2035 ospf6_interface_clear(vty
, ifp
);
2041 void install_element_ospf6_clear_interface(void)
2043 install_element(ENABLE_NODE
, &clear_ipv6_ospf6_interface_cmd
);
2046 DEFUN (debug_ospf6_interface
,
2047 debug_ospf6_interface_cmd
,
2048 "debug ospf6 interface",
2051 "Debug OSPFv3 Interface\n"
2054 OSPF6_DEBUG_INTERFACE_ON();
2058 DEFUN (no_debug_ospf6_interface
,
2059 no_debug_ospf6_interface_cmd
,
2060 "no debug ospf6 interface",
2064 "Debug OSPFv3 Interface\n"
2067 OSPF6_DEBUG_INTERFACE_OFF();
2071 int config_write_ospf6_debug_interface(struct vty
*vty
)
2073 if (IS_OSPF6_DEBUG_INTERFACE
)
2074 vty_out(vty
, "debug ospf6 interface\n");
2078 void install_element_ospf6_debug_interface(void)
2080 install_element(ENABLE_NODE
, &debug_ospf6_interface_cmd
);
2081 install_element(ENABLE_NODE
, &no_debug_ospf6_interface_cmd
);
2082 install_element(CONFIG_NODE
, &debug_ospf6_interface_cmd
);
2083 install_element(CONFIG_NODE
, &no_debug_ospf6_interface_cmd
);