2 * Copyright (C) 2003 Yasuhiro Ohara
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 #include "ospf6_lsa.h"
33 #include "ospf6_lsdb.h"
34 #include "ospf6_network.h"
35 #include "ospf6_message.h"
36 #include "ospf6_route.h"
37 #include "ospf6_top.h"
38 #include "ospf6_area.h"
39 #include "ospf6_interface.h"
40 #include "ospf6_neighbor.h"
41 #include "ospf6_intra.h"
42 #include "ospf6_spf.h"
44 #include "ospf6_bfd.h"
46 DEFINE_MTYPE_STATIC(OSPF6D
, CFG_PLIST_NAME
, "configured prefix list names")
47 DEFINE_QOBJ_TYPE(ospf6_interface
)
48 DEFINE_HOOK(ospf6_interface_change
,
49 (struct ospf6_interface
* oi
, int state
, int old_state
),
50 (oi
, state
, old_state
))
52 unsigned char conf_debug_ospf6_interface
= 0;
54 const char *ospf6_interface_state_str
[] = {
55 "None", "Down", "Loopback", "Waiting", "PointToPoint",
56 "DROther", "BDR", "DR", NULL
};
58 struct ospf6_interface
*ospf6_interface_lookup_by_ifindex(ifindex_t ifindex
)
60 struct ospf6_interface
*oi
;
61 struct interface
*ifp
;
63 ifp
= if_lookup_by_index(ifindex
, VRF_DEFAULT
);
65 return (struct ospf6_interface
*)NULL
;
67 oi
= (struct ospf6_interface
*)ifp
->info
;
71 /* schedule routing table recalculation */
72 static void ospf6_interface_lsdb_hook(struct ospf6_lsa
*lsa
,
75 struct ospf6_interface
*oi
;
81 switch (ntohs(lsa
->header
->type
)) {
82 case OSPF6_LSTYPE_LINK
:
83 if (oi
->state
== OSPF6_INTERFACE_DR
)
84 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
86 ospf6_spf_schedule(oi
->area
->ospf6
, reason
);
94 static void ospf6_interface_lsdb_hook_add(struct ospf6_lsa
*lsa
)
96 ospf6_interface_lsdb_hook(lsa
, ospf6_lsadd_to_spf_reason(lsa
));
99 static void ospf6_interface_lsdb_hook_remove(struct ospf6_lsa
*lsa
)
101 ospf6_interface_lsdb_hook(lsa
, ospf6_lsremove_to_spf_reason(lsa
));
104 static uint8_t ospf6_default_iftype(struct interface
*ifp
)
106 if (if_is_pointopoint(ifp
))
107 return OSPF_IFTYPE_POINTOPOINT
;
108 else if (if_is_loopback(ifp
))
109 return OSPF_IFTYPE_LOOPBACK
;
111 return OSPF_IFTYPE_BROADCAST
;
114 static uint32_t ospf6_interface_get_cost(struct ospf6_interface
*oi
)
116 /* If all else fails, use default OSPF cost */
120 /* interface speed and bw can be 0 in some platforms,
121 * use ospf default bw. If bw is configured then it would
124 if (!oi
->interface
->bandwidth
&& oi
->interface
->speed
) {
125 bw
= oi
->interface
->speed
;
127 bw
= oi
->interface
->bandwidth
? oi
->interface
->bandwidth
128 : OSPF6_INTERFACE_BANDWIDTH
;
131 refbw
= ospf6
? ospf6
->ref_bandwidth
: OSPF6_REFERENCE_BANDWIDTH
;
133 /* A specifed ip ospf cost overrides a calculated one. */
134 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_NOAUTOCOST
))
137 cost
= (uint32_t)((double)refbw
/ (double)bw
+ (double)0.5);
140 else if (cost
> UINT32_MAX
)
147 static void ospf6_interface_force_recalculate_cost(struct ospf6_interface
*oi
)
149 /* update cost held in route_connected list in ospf6_interface */
150 ospf6_interface_connected_route_update(oi
->interface
);
152 /* execute LSA hooks */
154 OSPF6_LINK_LSA_SCHEDULE(oi
);
155 OSPF6_ROUTER_LSA_SCHEDULE(oi
->area
);
156 OSPF6_NETWORK_LSA_SCHEDULE(oi
);
157 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
158 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
162 static void ospf6_interface_recalculate_cost(struct ospf6_interface
*oi
)
166 newcost
= ospf6_interface_get_cost(oi
);
167 if (newcost
== oi
->cost
)
171 ospf6_interface_force_recalculate_cost(oi
);
174 /* Create new ospf6 interface structure */
175 struct ospf6_interface
*ospf6_interface_create(struct interface
*ifp
)
177 struct ospf6_interface
*oi
;
178 unsigned int iobuflen
;
180 oi
= (struct ospf6_interface
*)XCALLOC(MTYPE_OSPF6_IF
,
181 sizeof(struct ospf6_interface
));
183 oi
->area
= (struct ospf6_area
*)NULL
;
184 oi
->neighbor_list
= list_new();
185 oi
->neighbor_list
->cmp
= ospf6_neighbor_cmp
;
186 oi
->linklocal_addr
= (struct in6_addr
*)NULL
;
187 oi
->instance_id
= OSPF6_INTERFACE_INSTANCE_ID
;
188 oi
->transdelay
= OSPF6_INTERFACE_TRANSDELAY
;
189 oi
->priority
= OSPF6_INTERFACE_PRIORITY
;
191 oi
->hello_interval
= OSPF_HELLO_INTERVAL_DEFAULT
;
192 oi
->dead_interval
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
193 oi
->rxmt_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
194 oi
->type
= ospf6_default_iftype(ifp
);
195 oi
->state
= OSPF6_INTERFACE_DOWN
;
200 /* Try to adjust I/O buffer size with IfMtu */
201 oi
->ifmtu
= ifp
->mtu6
;
202 iobuflen
= ospf6_iobuf_size(ifp
->mtu6
);
203 if (oi
->ifmtu
> iobuflen
) {
204 if (IS_OSPF6_DEBUG_INTERFACE
)
206 "Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
207 ifp
->name
, iobuflen
);
208 oi
->ifmtu
= iobuflen
;
211 QOBJ_REG(oi
, ospf6_interface
);
213 oi
->lsupdate_list
= ospf6_lsdb_create(oi
);
214 oi
->lsack_list
= ospf6_lsdb_create(oi
);
215 oi
->lsdb
= ospf6_lsdb_create(oi
);
216 oi
->lsdb
->hook_add
= ospf6_interface_lsdb_hook_add
;
217 oi
->lsdb
->hook_remove
= ospf6_interface_lsdb_hook_remove
;
218 oi
->lsdb_self
= ospf6_lsdb_create(oi
);
220 oi
->route_connected
=
221 OSPF6_ROUTE_TABLE_CREATE(INTERFACE
, CONNECTED_ROUTES
);
222 oi
->route_connected
->scope
= oi
;
229 oi
->cost
= ospf6_interface_get_cost(oi
);
234 void ospf6_interface_delete(struct ospf6_interface
*oi
)
236 struct listnode
*node
, *nnode
;
237 struct ospf6_neighbor
*on
;
241 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
))
242 ospf6_neighbor_delete(on
);
244 list_delete(&oi
->neighbor_list
);
246 THREAD_OFF(oi
->thread_send_hello
);
247 THREAD_OFF(oi
->thread_send_lsupdate
);
248 THREAD_OFF(oi
->thread_send_lsack
);
249 THREAD_OFF(oi
->thread_sso
);
251 ospf6_lsdb_remove_all(oi
->lsdb
);
252 ospf6_lsdb_remove_all(oi
->lsupdate_list
);
253 ospf6_lsdb_remove_all(oi
->lsack_list
);
255 ospf6_lsdb_delete(oi
->lsdb
);
256 ospf6_lsdb_delete(oi
->lsdb_self
);
258 ospf6_lsdb_delete(oi
->lsupdate_list
);
259 ospf6_lsdb_delete(oi
->lsack_list
);
261 ospf6_route_table_delete(oi
->route_connected
);
264 oi
->interface
->info
= NULL
;
268 XFREE(MTYPE_CFG_PLIST_NAME
, oi
->plist_name
);
270 ospf6_bfd_info_free(&(oi
->bfd_info
));
272 /* disable from area list if possible */
273 ospf6_area_interface_delete(oi
);
275 XFREE(MTYPE_OSPF6_IF
, oi
);
278 void ospf6_interface_enable(struct ospf6_interface
*oi
)
280 UNSET_FLAG(oi
->flag
, OSPF6_INTERFACE_DISABLE
);
281 ospf6_interface_state_update(oi
->interface
);
284 void ospf6_interface_disable(struct ospf6_interface
*oi
)
286 SET_FLAG(oi
->flag
, OSPF6_INTERFACE_DISABLE
);
288 thread_execute(master
, interface_down
, oi
, 0);
290 ospf6_lsdb_remove_all(oi
->lsdb
);
291 ospf6_lsdb_remove_all(oi
->lsdb_self
);
292 ospf6_lsdb_remove_all(oi
->lsupdate_list
);
293 ospf6_lsdb_remove_all(oi
->lsack_list
);
295 THREAD_OFF(oi
->thread_send_hello
);
296 THREAD_OFF(oi
->thread_send_lsupdate
);
297 THREAD_OFF(oi
->thread_send_lsack
);
298 THREAD_OFF(oi
->thread_sso
);
300 THREAD_OFF(oi
->thread_network_lsa
);
301 THREAD_OFF(oi
->thread_link_lsa
);
302 THREAD_OFF(oi
->thread_intra_prefix_lsa
);
303 THREAD_OFF(oi
->thread_as_extern_lsa
);
306 static struct in6_addr
*
307 ospf6_interface_get_linklocal_address(struct interface
*ifp
)
311 struct in6_addr
*l
= (struct in6_addr
*)NULL
;
313 /* for each connected address */
314 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, n
, c
)) {
315 /* if family not AF_INET6, ignore */
316 if (c
->address
->family
!= AF_INET6
)
319 /* linklocal scope check */
320 if (IN6_IS_ADDR_LINKLOCAL(&c
->address
->u
.prefix6
))
321 l
= &c
->address
->u
.prefix6
;
326 void ospf6_interface_if_add(struct interface
*ifp
)
328 struct ospf6_interface
*oi
;
329 unsigned int iobuflen
;
331 oi
= (struct ospf6_interface
*)ifp
->info
;
335 /* Try to adjust I/O buffer size with IfMtu */
337 oi
->ifmtu
= ifp
->mtu6
;
338 iobuflen
= ospf6_iobuf_size(ifp
->mtu6
);
339 if (oi
->ifmtu
> iobuflen
) {
340 if (IS_OSPF6_DEBUG_INTERFACE
)
342 "Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
343 ifp
->name
, iobuflen
);
344 oi
->ifmtu
= iobuflen
;
347 /* interface start */
348 ospf6_interface_state_update(oi
->interface
);
351 void ospf6_interface_state_update(struct interface
*ifp
)
353 struct ospf6_interface
*oi
;
354 unsigned int iobuflen
;
356 oi
= (struct ospf6_interface
*)ifp
->info
;
359 if (oi
->area
== NULL
)
361 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_DISABLE
))
364 /* Adjust the mtu values if the kernel told us something new */
365 if (ifp
->mtu6
!= oi
->ifmtu
) {
366 /* If nothing configured, accept it and check for buffer size */
368 oi
->ifmtu
= ifp
->mtu6
;
369 iobuflen
= ospf6_iobuf_size(ifp
->mtu6
);
370 if (oi
->ifmtu
> iobuflen
) {
371 if (IS_OSPF6_DEBUG_INTERFACE
)
373 "Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
374 ifp
->name
, iobuflen
);
375 oi
->ifmtu
= iobuflen
;
377 } else if (oi
->c_ifmtu
> ifp
->mtu6
) {
378 oi
->ifmtu
= ifp
->mtu6
;
380 "Configured mtu %u on %s overridden by kernel %u",
381 oi
->c_ifmtu
, ifp
->name
, ifp
->mtu6
);
383 oi
->ifmtu
= oi
->c_ifmtu
;
386 if (if_is_operative(ifp
)
387 && (ospf6_interface_get_linklocal_address(oi
->interface
)
388 || if_is_loopback(oi
->interface
)))
389 thread_execute(master
, interface_up
, oi
, 0);
391 thread_execute(master
, interface_down
, oi
, 0);
396 void ospf6_interface_connected_route_update(struct interface
*ifp
)
398 struct ospf6_interface
*oi
;
399 struct ospf6_route
*route
;
401 struct listnode
*node
, *nnode
;
402 struct in6_addr nh_addr
;
404 oi
= (struct ospf6_interface
*)ifp
->info
;
408 /* reset linklocal pointer */
409 oi
->linklocal_addr
= ospf6_interface_get_linklocal_address(ifp
);
411 /* if area is null, do not make connected-route list */
412 if (oi
->area
== NULL
)
415 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_DISABLE
))
418 /* update "route to advertise" interface route table */
419 ospf6_route_remove_all(oi
->route_connected
);
421 for (ALL_LIST_ELEMENTS(oi
->interface
->connected
, node
, nnode
, c
)) {
422 if (c
->address
->family
!= AF_INET6
)
425 CONTINUE_IF_ADDRESS_LINKLOCAL(IS_OSPF6_DEBUG_INTERFACE
,
427 CONTINUE_IF_ADDRESS_UNSPECIFIED(IS_OSPF6_DEBUG_INTERFACE
,
429 CONTINUE_IF_ADDRESS_LOOPBACK(IS_OSPF6_DEBUG_INTERFACE
,
431 CONTINUE_IF_ADDRESS_V4COMPAT(IS_OSPF6_DEBUG_INTERFACE
,
433 CONTINUE_IF_ADDRESS_V4MAPPED(IS_OSPF6_DEBUG_INTERFACE
,
437 if (oi
->plist_name
) {
438 struct prefix_list
*plist
;
439 enum prefix_list_type ret
;
440 char buf
[PREFIX2STR_BUFFER
];
442 prefix2str(c
->address
, buf
, sizeof(buf
));
443 plist
= prefix_list_lookup(AFI_IP6
, oi
->plist_name
);
444 ret
= prefix_list_apply(plist
, (void *)c
->address
);
445 if (ret
== PREFIX_DENY
) {
446 if (IS_OSPF6_DEBUG_INTERFACE
)
448 "%s on %s filtered by prefix-list %s ",
449 buf
, oi
->interface
->name
,
455 route
= ospf6_route_create();
456 memcpy(&route
->prefix
, c
->address
, sizeof(struct prefix
));
457 apply_mask(&route
->prefix
);
458 route
->type
= OSPF6_DEST_TYPE_NETWORK
;
459 route
->path
.area_id
= oi
->area
->area_id
;
460 route
->path
.type
= OSPF6_PATH_TYPE_INTRA
;
461 route
->path
.cost
= oi
->cost
;
462 inet_pton(AF_INET6
, "::1", &nh_addr
);
463 ospf6_route_add_nexthop(route
, oi
->interface
->ifindex
,
465 ospf6_route_add(route
, oi
->route_connected
);
468 /* create new Link-LSA */
469 OSPF6_LINK_LSA_SCHEDULE(oi
);
470 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
471 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
474 static void ospf6_interface_state_change(uint8_t next_state
,
475 struct ospf6_interface
*oi
)
479 prev_state
= oi
->state
;
480 oi
->state
= next_state
;
482 if (prev_state
== next_state
)
486 if (IS_OSPF6_DEBUG_INTERFACE
) {
487 zlog_debug("Interface state change %s: %s -> %s",
489 ospf6_interface_state_str
[prev_state
],
490 ospf6_interface_state_str
[next_state
]);
494 if ((prev_state
== OSPF6_INTERFACE_DR
495 || prev_state
== OSPF6_INTERFACE_BDR
)
496 && (next_state
!= OSPF6_INTERFACE_DR
497 && next_state
!= OSPF6_INTERFACE_BDR
))
498 ospf6_sso(oi
->interface
->ifindex
, &alldrouters6
,
501 if ((prev_state
!= OSPF6_INTERFACE_DR
502 && prev_state
!= OSPF6_INTERFACE_BDR
)
503 && (next_state
== OSPF6_INTERFACE_DR
504 || next_state
== OSPF6_INTERFACE_BDR
))
505 ospf6_sso(oi
->interface
->ifindex
, &alldrouters6
,
508 OSPF6_ROUTER_LSA_SCHEDULE(oi
->area
);
509 if (next_state
== OSPF6_INTERFACE_DOWN
) {
510 OSPF6_NETWORK_LSA_EXECUTE(oi
);
511 OSPF6_INTRA_PREFIX_LSA_EXECUTE_TRANSIT(oi
);
512 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
513 OSPF6_INTRA_PREFIX_LSA_EXECUTE_TRANSIT(oi
);
514 } else if (prev_state
== OSPF6_INTERFACE_DR
515 || next_state
== OSPF6_INTERFACE_DR
) {
516 OSPF6_NETWORK_LSA_SCHEDULE(oi
);
517 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
518 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
521 hook_call(ospf6_interface_change
, oi
, next_state
, prev_state
);
525 /* DR Election, RFC2328 section 9.4 */
527 #define IS_ELIGIBLE(n) \
528 ((n)->state >= OSPF6_NEIGHBOR_TWOWAY && (n)->priority != 0)
530 static struct ospf6_neighbor
*better_bdrouter(struct ospf6_neighbor
*a
,
531 struct ospf6_neighbor
*b
)
533 if ((a
== NULL
|| !IS_ELIGIBLE(a
) || a
->drouter
== a
->router_id
)
534 && (b
== NULL
|| !IS_ELIGIBLE(b
) || b
->drouter
== b
->router_id
))
536 else if (a
== NULL
|| !IS_ELIGIBLE(a
) || a
->drouter
== a
->router_id
)
538 else if (b
== NULL
|| !IS_ELIGIBLE(b
) || b
->drouter
== b
->router_id
)
541 if (a
->bdrouter
== a
->router_id
&& b
->bdrouter
!= b
->router_id
)
543 if (a
->bdrouter
!= a
->router_id
&& b
->bdrouter
== b
->router_id
)
546 if (a
->priority
> b
->priority
)
548 if (a
->priority
< b
->priority
)
551 if (ntohl(a
->router_id
) > ntohl(b
->router_id
))
553 if (ntohl(a
->router_id
) < ntohl(b
->router_id
))
556 zlog_warn("Router-ID duplicate ?");
560 static struct ospf6_neighbor
*better_drouter(struct ospf6_neighbor
*a
,
561 struct ospf6_neighbor
*b
)
563 if ((a
== NULL
|| !IS_ELIGIBLE(a
) || a
->drouter
!= a
->router_id
)
564 && (b
== NULL
|| !IS_ELIGIBLE(b
) || b
->drouter
!= b
->router_id
))
566 else if (a
== NULL
|| !IS_ELIGIBLE(a
) || a
->drouter
!= a
->router_id
)
568 else if (b
== NULL
|| !IS_ELIGIBLE(b
) || b
->drouter
!= b
->router_id
)
571 if (a
->drouter
== a
->router_id
&& b
->drouter
!= b
->router_id
)
573 if (a
->drouter
!= a
->router_id
&& b
->drouter
== b
->router_id
)
576 if (a
->priority
> b
->priority
)
578 if (a
->priority
< b
->priority
)
581 if (ntohl(a
->router_id
) > ntohl(b
->router_id
))
583 if (ntohl(a
->router_id
) < ntohl(b
->router_id
))
586 zlog_warn("Router-ID duplicate ?");
590 static uint8_t dr_election(struct ospf6_interface
*oi
)
592 struct listnode
*node
, *nnode
;
593 struct ospf6_neighbor
*on
, *drouter
, *bdrouter
, myself
;
594 struct ospf6_neighbor
*best_drouter
, *best_bdrouter
;
595 uint8_t next_state
= 0;
597 drouter
= bdrouter
= NULL
;
598 best_drouter
= best_bdrouter
= NULL
;
600 /* pseudo neighbor myself, including noting current DR/BDR (1) */
601 memset(&myself
, 0, sizeof(myself
));
602 inet_ntop(AF_INET
, &oi
->area
->ospf6
->router_id
, myself
.name
,
603 sizeof(myself
.name
));
604 myself
.state
= OSPF6_NEIGHBOR_TWOWAY
;
605 myself
.drouter
= oi
->drouter
;
606 myself
.bdrouter
= oi
->bdrouter
;
607 myself
.priority
= oi
->priority
;
608 myself
.router_id
= oi
->area
->ospf6
->router_id
;
610 /* Electing BDR (2) */
611 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
))
612 bdrouter
= better_bdrouter(bdrouter
, on
);
614 best_bdrouter
= bdrouter
;
615 bdrouter
= better_bdrouter(best_bdrouter
, &myself
);
617 /* Electing DR (3) */
618 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
))
619 drouter
= better_drouter(drouter
, on
);
621 best_drouter
= drouter
;
622 drouter
= better_drouter(best_drouter
, &myself
);
626 /* the router itself is newly/no longer DR/BDR (4) */
627 if ((drouter
== &myself
&& myself
.drouter
!= myself
.router_id
)
628 || (drouter
!= &myself
&& myself
.drouter
== myself
.router_id
)
629 || (bdrouter
== &myself
&& myself
.bdrouter
!= myself
.router_id
)
630 || (bdrouter
!= &myself
&& myself
.bdrouter
== myself
.router_id
)) {
631 myself
.drouter
= (drouter
? drouter
->router_id
: htonl(0));
632 myself
.bdrouter
= (bdrouter
? bdrouter
->router_id
: htonl(0));
634 /* compatible to Electing BDR (2) */
635 bdrouter
= better_bdrouter(best_bdrouter
, &myself
);
637 /* compatible to Electing DR (3) */
638 drouter
= better_drouter(best_drouter
, &myself
);
643 /* Set interface state accordingly (5) */
644 if (drouter
&& drouter
== &myself
)
645 next_state
= OSPF6_INTERFACE_DR
;
646 else if (bdrouter
&& bdrouter
== &myself
)
647 next_state
= OSPF6_INTERFACE_BDR
;
649 next_state
= OSPF6_INTERFACE_DROTHER
;
651 /* If NBMA, schedule Start for each neighbor having priority of 0 (6) */
654 /* If DR or BDR change, invoke AdjOK? for each neighbor (7) */
655 /* RFC 2328 section 12.4. Originating LSAs (3) will be handled
656 accordingly after AdjOK */
657 if (oi
->drouter
!= (drouter
? drouter
->router_id
: htonl(0))
658 || oi
->bdrouter
!= (bdrouter
? bdrouter
->router_id
: htonl(0))) {
659 if (IS_OSPF6_DEBUG_INTERFACE
)
660 zlog_debug("DR Election on %s: DR: %s BDR: %s",
662 (drouter
? drouter
->name
: "0.0.0.0"),
663 (bdrouter
? bdrouter
->name
: "0.0.0.0"));
665 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, node
, on
)) {
666 if (on
->state
< OSPF6_NEIGHBOR_TWOWAY
)
668 /* Schedule AdjOK. */
669 thread_add_event(master
, adj_ok
, on
, 0, NULL
);
673 oi
->drouter
= (drouter
? drouter
->router_id
: htonl(0));
674 oi
->bdrouter
= (bdrouter
? bdrouter
->router_id
: htonl(0));
679 /* Interface State Machine */
680 int interface_up(struct thread
*thread
)
682 struct ospf6_interface
*oi
;
684 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
685 assert(oi
&& oi
->interface
);
688 * Remove old pointer. If this thread wasn't a timer this
689 * operation won't make a difference, because it is already NULL.
691 oi
->thread_sso
= NULL
;
693 if (IS_OSPF6_DEBUG_INTERFACE
)
694 zlog_debug("Interface Event %s: [InterfaceUp]",
695 oi
->interface
->name
);
697 /* check physical interface is up */
698 if (!if_is_operative(oi
->interface
)) {
699 if (IS_OSPF6_DEBUG_INTERFACE
)
701 "Interface %s is down, can't execute [InterfaceUp]",
702 oi
->interface
->name
);
706 /* check interface has a link-local address */
707 if (!(ospf6_interface_get_linklocal_address(oi
->interface
)
708 || if_is_loopback(oi
->interface
))) {
709 if (IS_OSPF6_DEBUG_INTERFACE
)
711 "Interface %s has no link local address, can't execute [InterfaceUp]",
712 oi
->interface
->name
);
717 ospf6_interface_recalculate_cost(oi
);
719 /* if already enabled, do nothing */
720 if (oi
->state
> OSPF6_INTERFACE_DOWN
) {
721 if (IS_OSPF6_DEBUG_INTERFACE
)
722 zlog_debug("Interface %s already enabled",
723 oi
->interface
->name
);
727 /* If no area assigned, return */
728 if (oi
->area
== NULL
) {
730 "%s: Not scheduleing Hello for %s as there is no area assigned yet",
731 __func__
, oi
->interface
->name
);
737 * XXX: Schedule IPv6 group join for later, otherwise we might
738 * lose the multicast group registration caused by IPv6 group
741 if (oi
->sso_try_cnt
== 0) {
743 zlog_info("Scheduling %s for sso", oi
->interface
->name
);
744 thread_add_timer(master
, interface_up
, oi
,
745 OSPF6_INTERFACE_SSO_RETRY_INT
,
749 #endif /* __FreeBSD__ */
751 /* Join AllSPFRouters */
752 if (ospf6_sso(oi
->interface
->ifindex
, &allspfrouters6
, IPV6_JOIN_GROUP
)
754 if (oi
->sso_try_cnt
++ < OSPF6_INTERFACE_SSO_RETRY_MAX
) {
756 "Scheduling %s for sso retry, trial count: %d",
757 oi
->interface
->name
, oi
->sso_try_cnt
);
758 thread_add_timer(master
, interface_up
, oi
,
759 OSPF6_INTERFACE_SSO_RETRY_INT
,
764 oi
->sso_try_cnt
= 0; /* Reset on success */
766 /* Update interface route */
767 ospf6_interface_connected_route_update(oi
->interface
);
770 if (!CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_PASSIVE
)
771 && !if_is_loopback(oi
->interface
)) {
772 oi
->thread_send_hello
= NULL
;
773 thread_add_event(master
, ospf6_hello_send
, oi
, 0,
774 &oi
->thread_send_hello
);
777 /* decide next interface state */
778 if ((if_is_pointopoint(oi
->interface
))
779 || (oi
->type
== OSPF_IFTYPE_POINTOPOINT
)) {
780 ospf6_interface_state_change(OSPF6_INTERFACE_POINTTOPOINT
, oi
);
781 } else if (oi
->priority
== 0)
782 ospf6_interface_state_change(OSPF6_INTERFACE_DROTHER
, oi
);
784 ospf6_interface_state_change(OSPF6_INTERFACE_WAITING
, oi
);
785 thread_add_timer(master
, wait_timer
, oi
, oi
->dead_interval
,
792 int wait_timer(struct thread
*thread
)
794 struct ospf6_interface
*oi
;
796 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
797 assert(oi
&& oi
->interface
);
799 if (IS_OSPF6_DEBUG_INTERFACE
)
800 zlog_debug("Interface Event %s: [WaitTimer]",
801 oi
->interface
->name
);
803 if (oi
->state
== OSPF6_INTERFACE_WAITING
)
804 ospf6_interface_state_change(dr_election(oi
), oi
);
809 int backup_seen(struct thread
*thread
)
811 struct ospf6_interface
*oi
;
813 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
814 assert(oi
&& oi
->interface
);
816 if (IS_OSPF6_DEBUG_INTERFACE
)
817 zlog_debug("Interface Event %s: [BackupSeen]",
818 oi
->interface
->name
);
820 if (oi
->state
== OSPF6_INTERFACE_WAITING
)
821 ospf6_interface_state_change(dr_election(oi
), oi
);
826 int neighbor_change(struct thread
*thread
)
828 struct ospf6_interface
*oi
;
830 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
831 assert(oi
&& oi
->interface
);
833 if (IS_OSPF6_DEBUG_INTERFACE
)
834 zlog_debug("Interface Event %s: [NeighborChange]",
835 oi
->interface
->name
);
837 if (oi
->state
== OSPF6_INTERFACE_DROTHER
838 || oi
->state
== OSPF6_INTERFACE_BDR
839 || oi
->state
== OSPF6_INTERFACE_DR
)
840 ospf6_interface_state_change(dr_election(oi
), oi
);
845 int interface_down(struct thread
*thread
)
847 struct ospf6_interface
*oi
;
848 struct listnode
*node
, *nnode
;
849 struct ospf6_neighbor
*on
;
851 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
852 assert(oi
&& oi
->interface
);
854 if (IS_OSPF6_DEBUG_INTERFACE
)
855 zlog_debug("Interface Event %s: [InterfaceDown]",
856 oi
->interface
->name
);
859 THREAD_OFF(oi
->thread_send_hello
);
861 /* Stop trying to set socket options. */
862 THREAD_OFF(oi
->thread_sso
);
864 /* Leave AllSPFRouters */
865 if (oi
->state
> OSPF6_INTERFACE_DOWN
)
866 ospf6_sso(oi
->interface
->ifindex
, &allspfrouters6
,
869 ospf6_interface_state_change(OSPF6_INTERFACE_DOWN
, oi
);
871 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
))
872 ospf6_neighbor_delete(on
);
874 list_delete_all_node(oi
->neighbor_list
);
876 /* When interface state is reset, also reset information about
877 * DR election, as it is no longer valid. */
878 oi
->drouter
= oi
->prev_drouter
= htonl(0);
879 oi
->bdrouter
= oi
->prev_bdrouter
= htonl(0);
884 /* show specified interface structure */
885 static int ospf6_interface_show(struct vty
*vty
, struct interface
*ifp
)
887 struct ospf6_interface
*oi
;
891 char strbuf
[PREFIX2STR_BUFFER
], drouter
[32], bdrouter
[32];
893 struct timeval res
, now
;
895 struct ospf6_lsa
*lsa
;
897 /* check physical interface type */
898 if (if_is_loopback(ifp
))
900 else if (if_is_broadcast(ifp
))
902 else if (if_is_pointopoint(ifp
))
903 type
= "POINTOPOINT";
907 vty_out(vty
, "%s is %s, type %s\n", ifp
->name
,
908 (if_is_operative(ifp
) ? "up" : "down"), type
);
909 vty_out(vty
, " Interface ID: %d\n", ifp
->ifindex
);
911 if (ifp
->info
== NULL
) {
912 vty_out(vty
, " OSPF not enabled on this interface\n");
915 oi
= (struct ospf6_interface
*)ifp
->info
;
917 vty_out(vty
, " Internet Address:\n");
919 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, i
, c
)) {
921 prefix2str(p
, strbuf
, sizeof(strbuf
));
924 vty_out(vty
, " inet : %s\n", strbuf
);
927 vty_out(vty
, " inet6: %s\n", strbuf
);
930 vty_out(vty
, " ??? : %s\n", strbuf
);
937 " Instance ID %d, Interface MTU %d (autodetect: %d)\n",
938 oi
->instance_id
, oi
->ifmtu
, ifp
->mtu6
);
939 vty_out(vty
, " MTU mismatch detection: %s\n",
940 oi
->mtu_ignore
? "disabled" : "enabled");
941 inet_ntop(AF_INET
, &oi
->area
->area_id
, strbuf
, sizeof(strbuf
));
942 vty_out(vty
, " Area ID %s, Cost %u\n", strbuf
, oi
->cost
);
944 vty_out(vty
, " Not Attached to Area\n");
946 vty_out(vty
, " State %s, Transmit Delay %d sec, Priority %d\n",
947 ospf6_interface_state_str
[oi
->state
], oi
->transdelay
,
949 vty_out(vty
, " Timer intervals configured:\n");
950 vty_out(vty
, " Hello %d, Dead %d, Retransmit %d\n",
951 oi
->hello_interval
, oi
->dead_interval
, oi
->rxmt_interval
);
953 inet_ntop(AF_INET
, &oi
->drouter
, drouter
, sizeof(drouter
));
954 inet_ntop(AF_INET
, &oi
->bdrouter
, bdrouter
, sizeof(bdrouter
));
955 vty_out(vty
, " DR: %s BDR: %s\n", drouter
, bdrouter
);
957 vty_out(vty
, " Number of I/F scoped LSAs is %u\n", oi
->lsdb
->count
);
962 if (oi
->thread_send_lsupdate
)
963 timersub(&oi
->thread_send_lsupdate
->u
.sands
, &now
, &res
);
964 timerstring(&res
, duration
, sizeof(duration
));
966 " %d Pending LSAs for LSUpdate in Time %s [thread %s]\n",
967 oi
->lsupdate_list
->count
, duration
,
968 (oi
->thread_send_lsupdate
? "on" : "off"));
969 for (ALL_LSDB(oi
->lsupdate_list
, lsa
))
970 vty_out(vty
, " %s\n", lsa
->name
);
973 if (oi
->thread_send_lsack
)
974 timersub(&oi
->thread_send_lsack
->u
.sands
, &now
, &res
);
975 timerstring(&res
, duration
, sizeof(duration
));
976 vty_out(vty
, " %d Pending LSAs for LSAck in Time %s [thread %s]\n",
977 oi
->lsack_list
->count
, duration
,
978 (oi
->thread_send_lsack
? "on" : "off"));
979 for (ALL_LSDB(oi
->lsack_list
, lsa
))
980 vty_out(vty
, " %s\n", lsa
->name
);
981 ospf6_bfd_show_info(vty
, oi
->bfd_info
, 1);
986 DEFUN (show_ipv6_ospf6_interface
,
987 show_ipv6_ospf6_interface_ifname_cmd
,
988 "show ipv6 ospf6 interface [IFNAME]",
995 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
997 struct interface
*ifp
;
1000 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, 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
, VRF_DEFAULT
);
1087 vty_out(vty
, "No such Interface: %s\n", intf_name
);
1090 if (ifp
->info
== NULL
) {
1092 " OSPF not enabled on this interface %s\n",
1098 ospf6_interface_show_traffic(vty
, VRF_DEFAULT
, ifp
, display_once
);
1105 DEFUN (show_ipv6_ospf6_interface_ifname_prefix
,
1106 show_ipv6_ospf6_interface_ifname_prefix_cmd
,
1107 "show ipv6 ospf6 interface IFNAME prefix\
1110 |<X:X::X:X|X:X::X:X/M> [<match|detail>]\
1117 "Display connected prefixes to advertise\n"
1118 "Display details of the prefixes\n"
1119 OSPF6_ROUTE_ADDRESS_STR
1120 OSPF6_ROUTE_PREFIX_STR
1121 OSPF6_ROUTE_MATCH_STR
1122 "Display details of the prefixes\n")
1126 struct interface
*ifp
;
1127 struct ospf6_interface
*oi
;
1129 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, VRF_DEFAULT
);
1131 vty_out(vty
, "No such Interface: %s\n", argv
[idx_ifname
]->arg
);
1137 vty_out(vty
, "OSPFv3 is not enabled on %s\n",
1138 argv
[idx_ifname
]->arg
);
1142 ospf6_route_table_show(vty
, idx_prefix
, argc
, argv
,
1143 oi
->route_connected
);
1148 DEFUN (show_ipv6_ospf6_interface_prefix
,
1149 show_ipv6_ospf6_interface_prefix_cmd
,
1150 "show ipv6 ospf6 interface prefix\
1153 |<X:X::X:X|X:X::X:X/M> [<match|detail>]\
1159 "Display connected prefixes to advertise\n"
1160 "Display details of the prefixes\n"
1161 OSPF6_ROUTE_ADDRESS_STR
1162 OSPF6_ROUTE_PREFIX_STR
1163 OSPF6_ROUTE_MATCH_STR
1164 "Display details of the prefixes\n")
1166 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
1168 struct ospf6_interface
*oi
;
1169 struct interface
*ifp
;
1171 FOR_ALL_INTERFACES (vrf
, ifp
) {
1172 oi
= (struct ospf6_interface
*)ifp
->info
;
1176 ospf6_route_table_show(vty
, idx_prefix
, argc
, argv
,
1177 oi
->route_connected
);
1183 /* interface variable set command */
1184 DEFUN (ipv6_ospf6_ifmtu
,
1185 ipv6_ospf6_ifmtu_cmd
,
1186 "ipv6 ospf6 ifmtu (1-65535)",
1190 "OSPFv3 Interface MTU\n"
1193 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1195 struct ospf6_interface
*oi
;
1196 unsigned int ifmtu
, iobuflen
;
1197 struct listnode
*node
, *nnode
;
1198 struct ospf6_neighbor
*on
;
1202 oi
= (struct ospf6_interface
*)ifp
->info
;
1204 oi
= ospf6_interface_create(ifp
);
1207 ifmtu
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
1209 if (oi
->c_ifmtu
== ifmtu
)
1212 if (ifp
->mtu6
!= 0 && ifp
->mtu6
< ifmtu
) {
1214 "%s's ospf6 ifmtu cannot go beyond physical mtu (%d)\n",
1215 ifp
->name
, ifp
->mtu6
);
1216 return CMD_WARNING_CONFIG_FAILED
;
1219 if (oi
->ifmtu
< ifmtu
) {
1220 iobuflen
= ospf6_iobuf_size(ifmtu
);
1221 if (iobuflen
< ifmtu
) {
1223 "%s's ifmtu is adjusted to I/O buffer size (%d).\n",
1224 ifp
->name
, iobuflen
);
1225 oi
->ifmtu
= oi
->c_ifmtu
= iobuflen
;
1227 oi
->ifmtu
= oi
->c_ifmtu
= ifmtu
;
1229 oi
->ifmtu
= oi
->c_ifmtu
= ifmtu
;
1231 /* re-establish adjacencies */
1232 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
)) {
1233 THREAD_OFF(on
->inactivity_timer
);
1234 thread_add_event(master
, inactivity_timer
, on
, 0, NULL
);
1240 DEFUN (no_ipv6_ospf6_ifmtu
,
1241 no_ipv6_ospf6_ifmtu_cmd
,
1242 "no ipv6 ospf6 ifmtu [(1-65535)]",
1247 "OSPFv3 Interface MTU\n"
1250 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1251 struct ospf6_interface
*oi
;
1252 unsigned int iobuflen
;
1253 struct listnode
*node
, *nnode
;
1254 struct ospf6_neighbor
*on
;
1258 oi
= (struct ospf6_interface
*)ifp
->info
;
1260 oi
= ospf6_interface_create(ifp
);
1263 if (oi
->ifmtu
< ifp
->mtu
) {
1264 iobuflen
= ospf6_iobuf_size(ifp
->mtu
);
1265 if (iobuflen
< ifp
->mtu
) {
1267 "%s's ifmtu is adjusted to I/O buffer size (%d).\n",
1268 ifp
->name
, iobuflen
);
1269 oi
->ifmtu
= iobuflen
;
1271 oi
->ifmtu
= ifp
->mtu
;
1273 oi
->ifmtu
= ifp
->mtu
;
1277 /* re-establish adjacencies */
1278 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
)) {
1279 THREAD_OFF(on
->inactivity_timer
);
1280 thread_add_event(master
, inactivity_timer
, on
, 0, NULL
);
1286 DEFUN (ipv6_ospf6_cost
,
1287 ipv6_ospf6_cost_cmd
,
1288 "ipv6 ospf6 cost (1-65535)",
1292 "Outgoing metric of this interface\n")
1294 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1296 struct ospf6_interface
*oi
;
1297 unsigned long int lcost
;
1301 oi
= (struct ospf6_interface
*)ifp
->info
;
1303 oi
= ospf6_interface_create(ifp
);
1306 lcost
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
1308 if (lcost
> UINT32_MAX
) {
1309 vty_out(vty
, "Cost %ld is out of range\n", lcost
);
1310 return CMD_WARNING_CONFIG_FAILED
;
1313 if (oi
->cost
== lcost
)
1317 SET_FLAG(oi
->flag
, OSPF6_INTERFACE_NOAUTOCOST
);
1319 ospf6_interface_force_recalculate_cost(oi
);
1324 DEFUN (no_ipv6_ospf6_cost
,
1325 no_ipv6_ospf6_cost_cmd
,
1326 "no ipv6 ospf6 cost [(1-65535)]",
1330 "Calculate interface cost from bandwidth\n"
1331 "Outgoing metric of this interface\n")
1333 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1334 struct ospf6_interface
*oi
;
1337 oi
= (struct ospf6_interface
*)ifp
->info
;
1339 oi
= ospf6_interface_create(ifp
);
1342 UNSET_FLAG(oi
->flag
, OSPF6_INTERFACE_NOAUTOCOST
);
1344 ospf6_interface_recalculate_cost(oi
);
1349 DEFUN (auto_cost_reference_bandwidth
,
1350 auto_cost_reference_bandwidth_cmd
,
1351 "auto-cost reference-bandwidth (1-4294967)",
1352 "Calculate OSPF interface cost according to bandwidth\n"
1353 "Use reference bandwidth method to assign OSPF cost\n"
1354 "The reference bandwidth in terms of Mbits per second\n")
1356 VTY_DECLVAR_CONTEXT(ospf6
, o
);
1358 struct ospf6_area
*oa
;
1359 struct ospf6_interface
*oi
;
1360 struct listnode
*i
, *j
;
1363 refbw
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
1364 if (refbw
< 1 || refbw
> 4294967) {
1365 vty_out(vty
, "reference-bandwidth value is invalid\n");
1366 return CMD_WARNING_CONFIG_FAILED
;
1369 /* If reference bandwidth is changed. */
1370 if ((refbw
) == o
->ref_bandwidth
)
1373 o
->ref_bandwidth
= refbw
;
1374 for (ALL_LIST_ELEMENTS_RO(o
->area_list
, i
, oa
))
1375 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
1376 ospf6_interface_recalculate_cost(oi
);
1381 DEFUN (no_auto_cost_reference_bandwidth
,
1382 no_auto_cost_reference_bandwidth_cmd
,
1383 "no auto-cost reference-bandwidth [(1-4294967)]",
1385 "Calculate OSPF interface cost according to bandwidth\n"
1386 "Use reference bandwidth method to assign OSPF cost\n"
1387 "The reference bandwidth in terms of Mbits per second\n")
1389 VTY_DECLVAR_CONTEXT(ospf6
, o
);
1390 struct ospf6_area
*oa
;
1391 struct ospf6_interface
*oi
;
1392 struct listnode
*i
, *j
;
1394 if (o
->ref_bandwidth
== OSPF6_REFERENCE_BANDWIDTH
)
1397 o
->ref_bandwidth
= OSPF6_REFERENCE_BANDWIDTH
;
1398 for (ALL_LIST_ELEMENTS_RO(o
->area_list
, i
, oa
))
1399 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
1400 ospf6_interface_recalculate_cost(oi
);
1406 DEFUN (ipv6_ospf6_hellointerval
,
1407 ipv6_ospf6_hellointerval_cmd
,
1408 "ipv6 ospf6 hello-interval (1-65535)",
1411 "Time between HELLO packets\n"
1414 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1416 struct ospf6_interface
*oi
;
1419 oi
= (struct ospf6_interface
*)ifp
->info
;
1421 oi
= ospf6_interface_create(ifp
);
1424 oi
->hello_interval
= strmatch(argv
[0]->text
, "no")
1425 ? OSPF_HELLO_INTERVAL_DEFAULT
1426 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1430 ALIAS (ipv6_ospf6_hellointerval
,
1431 no_ipv6_ospf6_hellointerval_cmd
,
1432 "no ipv6 ospf6 hello-interval [(1-65535)]",
1436 "Time between HELLO packets\n"
1439 /* interface variable set command */
1440 DEFUN (ipv6_ospf6_deadinterval
,
1441 ipv6_ospf6_deadinterval_cmd
,
1442 "ipv6 ospf6 dead-interval (1-65535)",
1445 "Interval time after which a neighbor is declared down\n"
1448 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1450 struct ospf6_interface
*oi
;
1453 oi
= (struct ospf6_interface
*)ifp
->info
;
1455 oi
= ospf6_interface_create(ifp
);
1458 oi
->dead_interval
= strmatch(argv
[0]->arg
, "no")
1459 ? OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
1460 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1464 ALIAS (ipv6_ospf6_deadinterval
,
1465 no_ipv6_ospf6_deadinterval_cmd
,
1466 "no ipv6 ospf6 dead-interval [(1-65535)]",
1470 "Interval time after which a neighbor is declared down\n"
1473 /* interface variable set command */
1474 DEFUN (ipv6_ospf6_transmitdelay
,
1475 ipv6_ospf6_transmitdelay_cmd
,
1476 "ipv6 ospf6 transmit-delay (1-3600)",
1479 "Link state transmit delay\n"
1482 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1484 struct ospf6_interface
*oi
;
1487 oi
= (struct ospf6_interface
*)ifp
->info
;
1489 oi
= ospf6_interface_create(ifp
);
1492 oi
->transdelay
= strmatch(argv
[0]->text
, "no")
1493 ? OSPF6_INTERFACE_TRANSDELAY
1494 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1498 ALIAS (ipv6_ospf6_transmitdelay
,
1499 no_ipv6_ospf6_transmitdelay_cmd
,
1500 "no ipv6 ospf6 transmit-delay [(1-3600)]",
1504 "Link state transmit delay\n"
1507 /* interface variable set command */
1508 DEFUN (ipv6_ospf6_retransmitinterval
,
1509 ipv6_ospf6_retransmitinterval_cmd
,
1510 "ipv6 ospf6 retransmit-interval (1-65535)",
1513 "Time between retransmitting lost link state advertisements\n"
1516 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1518 struct ospf6_interface
*oi
;
1521 oi
= (struct ospf6_interface
*)ifp
->info
;
1523 oi
= ospf6_interface_create(ifp
);
1526 oi
->rxmt_interval
= strmatch(argv
[0]->text
, "no")
1527 ? OSPF_RETRANSMIT_INTERVAL_DEFAULT
1528 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1532 ALIAS (ipv6_ospf6_retransmitinterval
,
1533 no_ipv6_ospf6_retransmitinterval_cmd
,
1534 "no ipv6 ospf6 retransmit-interval [(1-65535)]",
1538 "Time between retransmitting lost link state advertisements\n"
1541 /* interface variable set command */
1542 DEFUN (ipv6_ospf6_priority
,
1543 ipv6_ospf6_priority_cmd
,
1544 "ipv6 ospf6 priority (0-255)",
1550 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1552 struct ospf6_interface
*oi
;
1555 oi
= (struct ospf6_interface
*)ifp
->info
;
1557 oi
= ospf6_interface_create(ifp
);
1560 oi
->priority
= strmatch(argv
[0]->text
, "no")
1561 ? OSPF6_INTERFACE_PRIORITY
1562 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1564 if (oi
->area
&& (oi
->state
== OSPF6_INTERFACE_DROTHER
1565 || oi
->state
== OSPF6_INTERFACE_BDR
1566 || oi
->state
== OSPF6_INTERFACE_DR
))
1567 ospf6_interface_state_change(dr_election(oi
), oi
);
1572 ALIAS (ipv6_ospf6_priority
,
1573 no_ipv6_ospf6_priority_cmd
,
1574 "no ipv6 ospf6 priority [(0-255)]",
1581 DEFUN (ipv6_ospf6_instance
,
1582 ipv6_ospf6_instance_cmd
,
1583 "ipv6 ospf6 instance-id (0-255)",
1586 "Instance ID for this interface\n"
1587 "Instance ID value\n")
1589 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1591 struct ospf6_interface
*oi
;
1594 oi
= (struct ospf6_interface
*)ifp
->info
;
1596 oi
= ospf6_interface_create(ifp
);
1599 oi
->instance_id
= strmatch(argv
[0]->text
, "no")
1600 ? OSPF6_INTERFACE_INSTANCE_ID
1601 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
1605 ALIAS (ipv6_ospf6_instance
,
1606 no_ipv6_ospf6_instance_cmd
,
1607 "no ipv6 ospf6 instance-id [(0-255)]",
1611 "Instance ID for this interface\n"
1612 "Instance ID value\n")
1614 DEFUN (ipv6_ospf6_passive
,
1615 ipv6_ospf6_passive_cmd
,
1616 "ipv6 ospf6 passive",
1619 "Passive interface; no adjacency will be formed on this interface\n"
1622 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1623 struct ospf6_interface
*oi
;
1624 struct listnode
*node
, *nnode
;
1625 struct ospf6_neighbor
*on
;
1629 oi
= (struct ospf6_interface
*)ifp
->info
;
1631 oi
= ospf6_interface_create(ifp
);
1634 SET_FLAG(oi
->flag
, OSPF6_INTERFACE_PASSIVE
);
1635 THREAD_OFF(oi
->thread_send_hello
);
1636 THREAD_OFF(oi
->thread_sso
);
1638 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
)) {
1639 THREAD_OFF(on
->inactivity_timer
);
1640 thread_add_event(master
, inactivity_timer
, on
, 0, NULL
);
1646 DEFUN (no_ipv6_ospf6_passive
,
1647 no_ipv6_ospf6_passive_cmd
,
1648 "no ipv6 ospf6 passive",
1652 "passive interface: No Adjacency will be formed on this I/F\n"
1655 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1656 struct ospf6_interface
*oi
;
1659 oi
= (struct ospf6_interface
*)ifp
->info
;
1661 oi
= ospf6_interface_create(ifp
);
1664 UNSET_FLAG(oi
->flag
, OSPF6_INTERFACE_PASSIVE
);
1665 THREAD_OFF(oi
->thread_send_hello
);
1666 THREAD_OFF(oi
->thread_sso
);
1667 thread_add_event(master
, ospf6_hello_send
, oi
, 0,
1668 &oi
->thread_send_hello
);
1673 DEFUN (ipv6_ospf6_mtu_ignore
,
1674 ipv6_ospf6_mtu_ignore_cmd
,
1675 "ipv6 ospf6 mtu-ignore",
1678 "Disable MTU mismatch detection on this interface\n"
1681 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1682 struct ospf6_interface
*oi
;
1685 oi
= (struct ospf6_interface
*)ifp
->info
;
1687 oi
= ospf6_interface_create(ifp
);
1695 DEFUN (no_ipv6_ospf6_mtu_ignore
,
1696 no_ipv6_ospf6_mtu_ignore_cmd
,
1697 "no ipv6 ospf6 mtu-ignore",
1701 "Disable MTU mismatch detection on this interface\n"
1704 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1705 struct ospf6_interface
*oi
;
1708 oi
= (struct ospf6_interface
*)ifp
->info
;
1710 oi
= ospf6_interface_create(ifp
);
1718 DEFUN (ipv6_ospf6_advertise_prefix_list
,
1719 ipv6_ospf6_advertise_prefix_list_cmd
,
1720 "ipv6 ospf6 advertise prefix-list WORD",
1723 "Advertising options\n"
1724 "Filter prefix using prefix-list\n"
1725 "Prefix list name\n"
1728 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1730 struct ospf6_interface
*oi
;
1733 oi
= (struct ospf6_interface
*)ifp
->info
;
1735 oi
= ospf6_interface_create(ifp
);
1739 XFREE(MTYPE_CFG_PLIST_NAME
, oi
->plist_name
);
1740 oi
->plist_name
= XSTRDUP(MTYPE_CFG_PLIST_NAME
, argv
[idx_word
]->arg
);
1742 ospf6_interface_connected_route_update(oi
->interface
);
1745 OSPF6_LINK_LSA_SCHEDULE(oi
);
1746 if (oi
->state
== OSPF6_INTERFACE_DR
) {
1747 OSPF6_NETWORK_LSA_SCHEDULE(oi
);
1748 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
1750 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
1756 DEFUN (no_ipv6_ospf6_advertise_prefix_list
,
1757 no_ipv6_ospf6_advertise_prefix_list_cmd
,
1758 "no ipv6 ospf6 advertise prefix-list [WORD]",
1762 "Advertising options\n"
1763 "Filter prefix using prefix-list\n"
1764 "Prefix list name\n")
1766 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1767 struct ospf6_interface
*oi
;
1770 oi
= (struct ospf6_interface
*)ifp
->info
;
1772 oi
= ospf6_interface_create(ifp
);
1776 XFREE(MTYPE_CFG_PLIST_NAME
, oi
->plist_name
);
1778 ospf6_interface_connected_route_update(oi
->interface
);
1781 OSPF6_LINK_LSA_SCHEDULE(oi
);
1782 if (oi
->state
== OSPF6_INTERFACE_DR
) {
1783 OSPF6_NETWORK_LSA_SCHEDULE(oi
);
1784 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
1786 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
1792 DEFUN (ipv6_ospf6_network
,
1793 ipv6_ospf6_network_cmd
,
1794 "ipv6 ospf6 network <broadcast|point-to-point>",
1798 "Specify OSPF6 broadcast network\n"
1799 "Specify OSPF6 point-to-point network\n"
1802 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1803 int idx_network
= 3;
1804 struct ospf6_interface
*oi
;
1807 oi
= (struct ospf6_interface
*)ifp
->info
;
1809 oi
= ospf6_interface_create(ifp
);
1813 if (strncmp(argv
[idx_network
]->arg
, "b", 1) == 0) {
1814 if (oi
->type
== OSPF_IFTYPE_BROADCAST
)
1817 oi
->type
= OSPF_IFTYPE_BROADCAST
;
1818 } else if (strncmp(argv
[idx_network
]->arg
, "point-to-p", 10) == 0) {
1819 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
) {
1822 oi
->type
= OSPF_IFTYPE_POINTOPOINT
;
1825 /* Reset the interface */
1826 thread_execute(master
, interface_down
, oi
, 0);
1827 thread_execute(master
, interface_up
, oi
, 0);
1832 DEFUN (no_ipv6_ospf6_network
,
1833 no_ipv6_ospf6_network_cmd
,
1834 "no ipv6 ospf6 network [<broadcast|point-to-point>]",
1838 "Set default network type\n"
1839 "Specify OSPF6 broadcast network\n"
1840 "Specify OSPF6 point-to-point network\n")
1842 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1843 struct ospf6_interface
*oi
;
1848 oi
= (struct ospf6_interface
*)ifp
->info
;
1853 type
= ospf6_default_iftype(ifp
);
1854 if (oi
->type
== type
) {
1859 /* Reset the interface */
1860 thread_execute(master
, interface_down
, oi
, 0);
1861 thread_execute(master
, interface_up
, oi
, 0);
1866 static int config_write_ospf6_interface(struct vty
*vty
)
1868 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
1869 struct ospf6_interface
*oi
;
1870 struct interface
*ifp
;
1872 FOR_ALL_INTERFACES (vrf
, ifp
) {
1873 oi
= (struct ospf6_interface
*)ifp
->info
;
1877 vty_frame(vty
, "interface %s\n", oi
->interface
->name
);
1880 vty_out(vty
, " description %s\n", ifp
->desc
);
1882 vty_out(vty
, " ipv6 ospf6 ifmtu %d\n", oi
->c_ifmtu
);
1884 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_NOAUTOCOST
))
1885 vty_out(vty
, " ipv6 ospf6 cost %d\n", oi
->cost
);
1887 if (oi
->hello_interval
!= OSPF6_INTERFACE_HELLO_INTERVAL
)
1888 vty_out(vty
, " ipv6 ospf6 hello-interval %d\n",
1889 oi
->hello_interval
);
1891 if (oi
->dead_interval
!= OSPF6_INTERFACE_DEAD_INTERVAL
)
1892 vty_out(vty
, " ipv6 ospf6 dead-interval %d\n",
1895 if (oi
->rxmt_interval
!= OSPF6_INTERFACE_RXMT_INTERVAL
)
1896 vty_out(vty
, " ipv6 ospf6 retransmit-interval %d\n",
1899 if (oi
->priority
!= OSPF6_INTERFACE_PRIORITY
)
1900 vty_out(vty
, " ipv6 ospf6 priority %d\n", oi
->priority
);
1902 if (oi
->transdelay
!= OSPF6_INTERFACE_TRANSDELAY
)
1903 vty_out(vty
, " ipv6 ospf6 transmit-delay %d\n",
1906 if (oi
->instance_id
!= OSPF6_INTERFACE_INSTANCE_ID
)
1907 vty_out(vty
, " ipv6 ospf6 instance-id %d\n",
1911 vty_out(vty
, " ipv6 ospf6 advertise prefix-list %s\n",
1914 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_PASSIVE
))
1915 vty_out(vty
, " ipv6 ospf6 passive\n");
1918 vty_out(vty
, " ipv6 ospf6 mtu-ignore\n");
1920 if (oi
->type
!= ospf6_default_iftype(ifp
)) {
1921 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
)
1923 " ipv6 ospf6 network point-to-point\n");
1924 else if (oi
->type
== OSPF_IFTYPE_BROADCAST
)
1925 vty_out(vty
, " ipv6 ospf6 network broadcast\n");
1928 ospf6_bfd_write_config(vty
, oi
);
1930 vty_endframe(vty
, "!\n");
1935 static struct cmd_node interface_node
= {
1936 INTERFACE_NODE
, "%s(config-if)# ", 1 /* VTYSH */
1939 void ospf6_interface_init(void)
1941 /* Install interface node. */
1942 install_node(&interface_node
, config_write_ospf6_interface
);
1945 install_element(VIEW_NODE
, &show_ipv6_ospf6_interface_prefix_cmd
);
1946 install_element(VIEW_NODE
, &show_ipv6_ospf6_interface_ifname_cmd
);
1947 install_element(VIEW_NODE
,
1948 &show_ipv6_ospf6_interface_ifname_prefix_cmd
);
1949 install_element(VIEW_NODE
, &show_ipv6_ospf6_interface_traffic_cmd
);
1951 install_element(INTERFACE_NODE
, &ipv6_ospf6_cost_cmd
);
1952 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_cost_cmd
);
1953 install_element(INTERFACE_NODE
, &ipv6_ospf6_ifmtu_cmd
);
1954 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_ifmtu_cmd
);
1956 install_element(INTERFACE_NODE
, &ipv6_ospf6_deadinterval_cmd
);
1957 install_element(INTERFACE_NODE
, &ipv6_ospf6_hellointerval_cmd
);
1958 install_element(INTERFACE_NODE
, &ipv6_ospf6_priority_cmd
);
1959 install_element(INTERFACE_NODE
, &ipv6_ospf6_retransmitinterval_cmd
);
1960 install_element(INTERFACE_NODE
, &ipv6_ospf6_transmitdelay_cmd
);
1961 install_element(INTERFACE_NODE
, &ipv6_ospf6_instance_cmd
);
1962 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_deadinterval_cmd
);
1963 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_hellointerval_cmd
);
1964 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_priority_cmd
);
1965 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_retransmitinterval_cmd
);
1966 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_transmitdelay_cmd
);
1967 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_instance_cmd
);
1969 install_element(INTERFACE_NODE
, &ipv6_ospf6_passive_cmd
);
1970 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_passive_cmd
);
1972 install_element(INTERFACE_NODE
, &ipv6_ospf6_mtu_ignore_cmd
);
1973 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_mtu_ignore_cmd
);
1975 install_element(INTERFACE_NODE
, &ipv6_ospf6_advertise_prefix_list_cmd
);
1976 install_element(INTERFACE_NODE
,
1977 &no_ipv6_ospf6_advertise_prefix_list_cmd
);
1979 install_element(INTERFACE_NODE
, &ipv6_ospf6_network_cmd
);
1980 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_network_cmd
);
1982 /* reference bandwidth commands */
1983 install_element(OSPF6_NODE
, &auto_cost_reference_bandwidth_cmd
);
1984 install_element(OSPF6_NODE
, &no_auto_cost_reference_bandwidth_cmd
);
1987 /* Clear the specified interface structure */
1988 static void ospf6_interface_clear(struct vty
*vty
, struct interface
*ifp
)
1990 struct ospf6_interface
*oi
;
1992 if (!if_is_operative(ifp
))
1995 if (ifp
->info
== NULL
)
1998 oi
= (struct ospf6_interface
*)ifp
->info
;
2000 if (IS_OSPF6_DEBUG_INTERFACE
)
2001 zlog_debug("Interface %s: clear by reset", ifp
->name
);
2003 /* Reset the interface */
2004 thread_execute(master
, interface_down
, oi
, 0);
2005 thread_execute(master
, interface_up
, oi
, 0);
2008 /* Clear interface */
2009 DEFUN (clear_ipv6_ospf6_interface
,
2010 clear_ipv6_ospf6_interface_cmd
,
2011 "clear ipv6 ospf6 interface [IFNAME]",
2019 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
2021 struct interface
*ifp
;
2023 if (argc
== 4) /* Clear all the ospfv3 interfaces. */
2025 FOR_ALL_INTERFACES (vrf
, ifp
)
2026 ospf6_interface_clear(vty
, ifp
);
2027 } else /* Interface name is specified. */
2029 if ((ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
,
2032 vty_out(vty
, "No such Interface: %s\n",
2033 argv
[idx_ifname
]->arg
);
2036 ospf6_interface_clear(vty
, ifp
);
2042 void install_element_ospf6_clear_interface(void)
2044 install_element(ENABLE_NODE
, &clear_ipv6_ospf6_interface_cmd
);
2047 DEFUN (debug_ospf6_interface
,
2048 debug_ospf6_interface_cmd
,
2049 "debug ospf6 interface",
2052 "Debug OSPFv3 Interface\n"
2055 OSPF6_DEBUG_INTERFACE_ON();
2059 DEFUN (no_debug_ospf6_interface
,
2060 no_debug_ospf6_interface_cmd
,
2061 "no debug ospf6 interface",
2065 "Debug OSPFv3 Interface\n"
2068 OSPF6_DEBUG_INTERFACE_OFF();
2072 int config_write_ospf6_debug_interface(struct vty
*vty
)
2074 if (IS_OSPF6_DEBUG_INTERFACE
)
2075 vty_out(vty
, "debug ospf6 interface\n");
2079 void install_element_ospf6_debug_interface(void)
2081 install_element(ENABLE_NODE
, &debug_ospf6_interface_cmd
);
2082 install_element(ENABLE_NODE
, &no_debug_ospf6_interface_cmd
);
2083 install_element(CONFIG_NODE
, &debug_ospf6_interface_cmd
);
2084 install_element(CONFIG_NODE
, &no_debug_ospf6_interface_cmd
);