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_top.h"
35 #include "ospf6_network.h"
36 #include "ospf6_message.h"
37 #include "ospf6_route.h"
38 #include "ospf6_area.h"
39 #include "ospf6_abr.h"
40 #include "ospf6_interface.h"
41 #include "ospf6_neighbor.h"
42 #include "ospf6_intra.h"
43 #include "ospf6_spf.h"
45 #include "ospf6_bfd.h"
46 #include "ospf6_zebra.h"
49 #include "ospf6_proto.h"
50 #include "lib/keychain.h"
51 #include "ospf6_auth_trailer.h"
53 DEFINE_MTYPE_STATIC(OSPF6D
, OSPF6_IF
, "OSPF6 interface");
54 DEFINE_MTYPE(OSPF6D
, OSPF6_AUTH_KEYCHAIN
, "OSPF6 auth keychain");
55 DEFINE_MTYPE(OSPF6D
, OSPF6_AUTH_MANUAL_KEY
, "OSPF6 auth key");
56 DEFINE_MTYPE_STATIC(OSPF6D
, CFG_PLIST_NAME
, "configured prefix list names");
57 DEFINE_QOBJ_TYPE(ospf6_interface
);
58 DEFINE_HOOK(ospf6_interface_change
,
59 (struct ospf6_interface
* oi
, int state
, int old_state
),
60 (oi
, state
, old_state
));
62 unsigned char conf_debug_ospf6_interface
= 0;
64 const char *const ospf6_interface_state_str
[] = {
65 "None", "Down", "Loopback", "Waiting", "PointToPoint",
66 "DROther", "BDR", "DR", NULL
};
68 int ospf6_interface_neighbor_count(struct ospf6_interface
*oi
)
71 struct ospf6_neighbor
*nbr
= NULL
;
72 struct listnode
*node
;
74 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, node
, nbr
)) {
75 /* Down state is not shown. */
76 if (nbr
->state
== OSPF6_NEIGHBOR_DOWN
)
84 struct ospf6_interface
*ospf6_interface_lookup_by_ifindex(ifindex_t ifindex
,
87 struct ospf6_interface
*oi
;
88 struct interface
*ifp
;
90 ifp
= if_lookup_by_index(ifindex
, vrf_id
);
92 return (struct ospf6_interface
*)NULL
;
94 oi
= (struct ospf6_interface
*)ifp
->info
;
98 /* schedule routing table recalculation */
99 static void ospf6_interface_lsdb_hook(struct ospf6_lsa
*lsa
,
102 struct ospf6_interface
*oi
;
107 oi
= lsa
->lsdb
->data
;
108 switch (ntohs(lsa
->header
->type
)) {
109 case OSPF6_LSTYPE_LINK
:
110 if (oi
->state
== OSPF6_INTERFACE_DR
)
111 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
113 ospf6_spf_schedule(oi
->area
->ospf6
, reason
);
121 static void ospf6_interface_lsdb_hook_add(struct ospf6_lsa
*lsa
)
123 ospf6_interface_lsdb_hook(lsa
, ospf6_lsadd_to_spf_reason(lsa
));
126 static void ospf6_interface_lsdb_hook_remove(struct ospf6_lsa
*lsa
)
128 ospf6_interface_lsdb_hook(lsa
, ospf6_lsremove_to_spf_reason(lsa
));
131 static uint8_t ospf6_default_iftype(struct interface
*ifp
)
133 if (if_is_pointopoint(ifp
))
134 return OSPF_IFTYPE_POINTOPOINT
;
135 else if (if_is_loopback(ifp
))
136 return OSPF_IFTYPE_LOOPBACK
;
138 return OSPF_IFTYPE_BROADCAST
;
141 static uint32_t ospf6_interface_get_cost(struct ospf6_interface
*oi
)
143 /* If all else fails, use default OSPF cost */
147 /* interface speed and bw can be 0 in some platforms,
148 * use ospf default bw. If bw is configured then it would
151 if (!oi
->interface
->bandwidth
&& oi
->interface
->speed
) {
152 bw
= oi
->interface
->speed
;
154 bw
= oi
->interface
->bandwidth
? oi
->interface
->bandwidth
155 : OSPF6_INTERFACE_BANDWIDTH
;
158 ospf6
= oi
->interface
->vrf
->info
;
159 refbw
= ospf6
? ospf6
->ref_bandwidth
: OSPF6_REFERENCE_BANDWIDTH
;
161 /* A specified ip ospf cost overrides a calculated one. */
162 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_NOAUTOCOST
))
165 cost
= (uint32_t)((double)refbw
/ (double)bw
+ (double)0.5);
173 static void ospf6_interface_force_recalculate_cost(struct ospf6_interface
*oi
)
175 /* update cost held in route_connected list in ospf6_interface */
176 ospf6_interface_connected_route_update(oi
->interface
);
178 /* execute LSA hooks */
180 OSPF6_LINK_LSA_SCHEDULE(oi
);
181 OSPF6_ROUTER_LSA_SCHEDULE(oi
->area
);
182 OSPF6_NETWORK_LSA_SCHEDULE(oi
);
183 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
184 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
188 static void ospf6_interface_recalculate_cost(struct ospf6_interface
*oi
)
192 newcost
= ospf6_interface_get_cost(oi
);
193 if (newcost
== oi
->cost
)
197 ospf6_interface_force_recalculate_cost(oi
);
200 /* Create new ospf6 interface structure */
201 struct ospf6_interface
*ospf6_interface_create(struct interface
*ifp
)
203 struct ospf6_interface
*oi
;
204 unsigned int iobuflen
;
206 oi
= XCALLOC(MTYPE_OSPF6_IF
, sizeof(struct ospf6_interface
));
208 oi
->obuf
= ospf6_fifo_new();
210 oi
->area
= (struct ospf6_area
*)NULL
;
211 oi
->neighbor_list
= list_new();
212 oi
->neighbor_list
->cmp
= ospf6_neighbor_cmp
;
213 oi
->linklocal_addr
= (struct in6_addr
*)NULL
;
214 oi
->instance_id
= OSPF6_INTERFACE_INSTANCE_ID
;
215 oi
->transdelay
= OSPF6_INTERFACE_TRANSDELAY
;
216 oi
->priority
= OSPF6_INTERFACE_PRIORITY
;
218 oi
->hello_interval
= OSPF_HELLO_INTERVAL_DEFAULT
;
219 oi
->dead_interval
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
220 oi
->rxmt_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
221 oi
->type
= ospf6_default_iftype(ifp
);
222 oi
->state
= OSPF6_INTERFACE_DOWN
;
227 /* Try to adjust I/O buffer size with IfMtu */
228 oi
->ifmtu
= ifp
->mtu6
;
229 iobuflen
= ospf6_iobuf_size(ifp
->mtu6
);
230 if (oi
->ifmtu
> iobuflen
) {
231 if (IS_OSPF6_DEBUG_INTERFACE
)
233 "Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
234 ifp
->name
, iobuflen
);
235 oi
->ifmtu
= iobuflen
;
238 QOBJ_REG(oi
, ospf6_interface
);
240 oi
->lsupdate_list
= ospf6_lsdb_create(oi
);
241 oi
->lsack_list
= ospf6_lsdb_create(oi
);
242 oi
->lsdb
= ospf6_lsdb_create(oi
);
243 oi
->lsdb
->hook_add
= ospf6_interface_lsdb_hook_add
;
244 oi
->lsdb
->hook_remove
= ospf6_interface_lsdb_hook_remove
;
245 oi
->lsdb_self
= ospf6_lsdb_create(oi
);
247 oi
->route_connected
=
248 OSPF6_ROUTE_TABLE_CREATE(INTERFACE
, CONNECTED_ROUTES
);
249 oi
->route_connected
->scope
= oi
;
256 oi
->cost
= ospf6_interface_get_cost(oi
);
258 oi
->at_data
.flags
= 0;
263 void ospf6_interface_delete(struct ospf6_interface
*oi
)
265 struct listnode
*node
, *nnode
;
266 struct ospf6_neighbor
*on
;
270 ospf6_fifo_free(oi
->obuf
);
272 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
))
273 ospf6_neighbor_delete(on
);
275 list_delete(&oi
->neighbor_list
);
277 THREAD_OFF(oi
->thread_send_hello
);
278 THREAD_OFF(oi
->thread_send_lsupdate
);
279 THREAD_OFF(oi
->thread_send_lsack
);
280 THREAD_OFF(oi
->thread_sso
);
281 THREAD_OFF(oi
->thread_wait_timer
);
283 ospf6_lsdb_remove_all(oi
->lsdb
);
284 ospf6_lsdb_remove_all(oi
->lsupdate_list
);
285 ospf6_lsdb_remove_all(oi
->lsack_list
);
287 ospf6_lsdb_delete(oi
->lsdb
);
288 ospf6_lsdb_delete(oi
->lsdb_self
);
290 ospf6_lsdb_delete(oi
->lsupdate_list
);
291 ospf6_lsdb_delete(oi
->lsack_list
);
293 ospf6_route_table_delete(oi
->route_connected
);
296 oi
->interface
->info
= NULL
;
300 XFREE(MTYPE_CFG_PLIST_NAME
, oi
->plist_name
);
302 /* disable from area list if possible */
303 ospf6_area_interface_delete(oi
);
305 /* Free BFD allocated data. */
306 XFREE(MTYPE_TMP
, oi
->bfd_config
.profile
);
308 XFREE(MTYPE_OSPF6_IF
, oi
);
311 void ospf6_interface_enable(struct ospf6_interface
*oi
)
313 UNSET_FLAG(oi
->flag
, OSPF6_INTERFACE_DISABLE
);
314 ospf6_interface_state_update(oi
->interface
);
317 void ospf6_interface_disable(struct ospf6_interface
*oi
)
319 SET_FLAG(oi
->flag
, OSPF6_INTERFACE_DISABLE
);
321 thread_execute(master
, interface_down
, oi
, 0);
323 ospf6_lsdb_remove_all(oi
->lsdb
);
324 ospf6_lsdb_remove_all(oi
->lsdb_self
);
325 ospf6_lsdb_remove_all(oi
->lsupdate_list
);
326 ospf6_lsdb_remove_all(oi
->lsack_list
);
328 THREAD_OFF(oi
->thread_send_hello
);
329 THREAD_OFF(oi
->thread_send_lsupdate
);
330 THREAD_OFF(oi
->thread_send_lsack
);
331 THREAD_OFF(oi
->thread_sso
);
333 THREAD_OFF(oi
->thread_network_lsa
);
334 THREAD_OFF(oi
->thread_link_lsa
);
335 THREAD_OFF(oi
->thread_intra_prefix_lsa
);
336 THREAD_OFF(oi
->thread_as_extern_lsa
);
337 THREAD_OFF(oi
->thread_wait_timer
);
340 static struct in6_addr
*
341 ospf6_interface_get_linklocal_address(struct interface
*ifp
)
345 struct in6_addr
*l
= (struct in6_addr
*)NULL
;
347 /* for each connected address */
348 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, n
, c
)) {
349 /* if family not AF_INET6, ignore */
350 if (c
->address
->family
!= AF_INET6
)
353 /* linklocal scope check */
354 if (IN6_IS_ADDR_LINKLOCAL(&c
->address
->u
.prefix6
))
355 l
= &c
->address
->u
.prefix6
;
360 void ospf6_interface_state_update(struct interface
*ifp
)
362 struct ospf6_interface
*oi
;
363 unsigned int iobuflen
;
365 oi
= (struct ospf6_interface
*)ifp
->info
;
368 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_DISABLE
))
371 /* Adjust the mtu values if the kernel told us something new */
372 if (ifp
->mtu6
!= oi
->ifmtu
) {
373 /* If nothing configured, accept it and check for buffer size */
375 oi
->ifmtu
= ifp
->mtu6
;
376 iobuflen
= ospf6_iobuf_size(ifp
->mtu6
);
377 if (oi
->ifmtu
> iobuflen
) {
378 if (IS_OSPF6_DEBUG_INTERFACE
)
380 "Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
381 ifp
->name
, iobuflen
);
382 oi
->ifmtu
= iobuflen
;
384 } else if (oi
->c_ifmtu
> ifp
->mtu6
) {
385 oi
->ifmtu
= ifp
->mtu6
;
387 "Configured mtu %u on %s overridden by kernel %u",
388 oi
->c_ifmtu
, ifp
->name
, ifp
->mtu6
);
390 oi
->ifmtu
= oi
->c_ifmtu
;
393 if (if_is_operative(ifp
)
394 && (ospf6_interface_get_linklocal_address(oi
->interface
)
395 || if_is_loopback(oi
->interface
)))
396 thread_execute(master
, interface_up
, oi
, 0);
398 thread_execute(master
, interface_down
, oi
, 0);
403 void ospf6_interface_connected_route_update(struct interface
*ifp
)
405 struct ospf6_interface
*oi
;
406 struct ospf6_route
*route
;
408 struct listnode
*node
, *nnode
;
409 struct in6_addr nh_addr
;
411 oi
= (struct ospf6_interface
*)ifp
->info
;
415 /* reset linklocal pointer */
416 oi
->linklocal_addr
= ospf6_interface_get_linklocal_address(ifp
);
418 /* if area is null, do not make connected-route list */
419 if (oi
->area
== NULL
)
422 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_DISABLE
))
425 /* update "route to advertise" interface route table */
426 ospf6_route_remove_all(oi
->route_connected
);
428 for (ALL_LIST_ELEMENTS(oi
->interface
->connected
, node
, nnode
, c
)) {
429 if (c
->address
->family
!= AF_INET6
)
432 CONTINUE_IF_ADDRESS_LINKLOCAL(IS_OSPF6_DEBUG_INTERFACE
,
434 CONTINUE_IF_ADDRESS_UNSPECIFIED(IS_OSPF6_DEBUG_INTERFACE
,
436 CONTINUE_IF_ADDRESS_LOOPBACK(IS_OSPF6_DEBUG_INTERFACE
,
438 CONTINUE_IF_ADDRESS_V4COMPAT(IS_OSPF6_DEBUG_INTERFACE
,
440 CONTINUE_IF_ADDRESS_V4MAPPED(IS_OSPF6_DEBUG_INTERFACE
,
444 if (oi
->plist_name
) {
445 struct prefix_list
*plist
;
446 enum prefix_list_type ret
;
448 plist
= prefix_list_lookup(AFI_IP6
, oi
->plist_name
);
449 ret
= prefix_list_apply(plist
, (void *)c
->address
);
450 if (ret
== PREFIX_DENY
) {
451 if (IS_OSPF6_DEBUG_INTERFACE
)
453 "%pFX on %s filtered by prefix-list %s ",
454 c
->address
, oi
->interface
->name
,
460 route
= ospf6_route_create(oi
->area
->ospf6
);
461 memcpy(&route
->prefix
, c
->address
, sizeof(struct prefix
));
462 apply_mask(&route
->prefix
);
463 route
->type
= OSPF6_DEST_TYPE_NETWORK
;
464 route
->path
.area_id
= oi
->area
->area_id
;
465 route
->path
.type
= OSPF6_PATH_TYPE_INTRA
;
466 route
->path
.cost
= oi
->cost
;
467 inet_pton(AF_INET6
, "::1", &nh_addr
);
468 ospf6_route_add_nexthop(route
, oi
->interface
->ifindex
,
470 ospf6_route_add(route
, oi
->route_connected
);
473 /* create new Link-LSA */
474 OSPF6_LINK_LSA_SCHEDULE(oi
);
475 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
476 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
479 static int ospf6_interface_state_change(uint8_t next_state
,
480 struct ospf6_interface
*oi
)
485 prev_state
= oi
->state
;
486 oi
->state
= next_state
;
488 if (prev_state
== next_state
)
495 if (IS_OSPF6_DEBUG_INTERFACE
) {
496 zlog_debug("Interface state change %s: %s -> %s",
498 ospf6_interface_state_str
[prev_state
],
499 ospf6_interface_state_str
[next_state
]);
503 ospf6
= oi
->area
->ospf6
;
505 if ((prev_state
== OSPF6_INTERFACE_DR
506 || prev_state
== OSPF6_INTERFACE_BDR
)
507 && (next_state
!= OSPF6_INTERFACE_DR
508 && next_state
!= OSPF6_INTERFACE_BDR
))
509 ospf6_sso(oi
->interface
->ifindex
, &alldrouters6
,
510 IPV6_LEAVE_GROUP
, ospf6
->fd
);
512 if ((prev_state
!= OSPF6_INTERFACE_DR
513 && prev_state
!= OSPF6_INTERFACE_BDR
)
514 && (next_state
== OSPF6_INTERFACE_DR
515 || next_state
== OSPF6_INTERFACE_BDR
))
516 ospf6_sso(oi
->interface
->ifindex
, &alldrouters6
,
517 IPV6_JOIN_GROUP
, ospf6
->fd
);
519 OSPF6_ROUTER_LSA_SCHEDULE(oi
->area
);
520 OSPF6_LINK_LSA_SCHEDULE(oi
);
521 if (next_state
== OSPF6_INTERFACE_DOWN
) {
522 OSPF6_NETWORK_LSA_EXECUTE(oi
);
523 OSPF6_INTRA_PREFIX_LSA_EXECUTE_TRANSIT(oi
);
524 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
525 OSPF6_INTRA_PREFIX_LSA_EXECUTE_TRANSIT(oi
);
526 } else if (prev_state
== OSPF6_INTERFACE_DR
527 || next_state
== OSPF6_INTERFACE_DR
) {
528 OSPF6_NETWORK_LSA_SCHEDULE(oi
);
529 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
530 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
533 hook_call(ospf6_interface_change
, oi
, next_state
, prev_state
);
539 /* DR Election, RFC2328 section 9.4 */
541 #define IS_ELIGIBLE(n) \
542 ((n)->state >= OSPF6_NEIGHBOR_TWOWAY && (n)->priority != 0)
544 static struct ospf6_neighbor
*better_bdrouter(struct ospf6_neighbor
*a
,
545 struct ospf6_neighbor
*b
)
547 if ((a
== NULL
|| !IS_ELIGIBLE(a
) || a
->drouter
== a
->router_id
)
548 && (b
== NULL
|| !IS_ELIGIBLE(b
) || b
->drouter
== b
->router_id
))
550 else if (a
== NULL
|| !IS_ELIGIBLE(a
) || a
->drouter
== a
->router_id
)
552 else if (b
== NULL
|| !IS_ELIGIBLE(b
) || b
->drouter
== b
->router_id
)
555 if (a
->bdrouter
== a
->router_id
&& b
->bdrouter
!= b
->router_id
)
557 if (a
->bdrouter
!= a
->router_id
&& b
->bdrouter
== b
->router_id
)
560 if (a
->priority
> b
->priority
)
562 if (a
->priority
< b
->priority
)
565 if (ntohl(a
->router_id
) > ntohl(b
->router_id
))
567 if (ntohl(a
->router_id
) < ntohl(b
->router_id
))
570 zlog_warn("Router-ID duplicate ?");
574 static struct ospf6_neighbor
*better_drouter(struct ospf6_neighbor
*a
,
575 struct ospf6_neighbor
*b
)
577 if ((a
== NULL
|| !IS_ELIGIBLE(a
) || a
->drouter
!= a
->router_id
)
578 && (b
== NULL
|| !IS_ELIGIBLE(b
) || b
->drouter
!= b
->router_id
))
580 else if (a
== NULL
|| !IS_ELIGIBLE(a
) || a
->drouter
!= a
->router_id
)
582 else if (b
== NULL
|| !IS_ELIGIBLE(b
) || b
->drouter
!= b
->router_id
)
585 if (a
->drouter
== a
->router_id
&& b
->drouter
!= b
->router_id
)
587 if (a
->drouter
!= a
->router_id
&& b
->drouter
== b
->router_id
)
590 if (a
->priority
> b
->priority
)
592 if (a
->priority
< b
->priority
)
595 if (ntohl(a
->router_id
) > ntohl(b
->router_id
))
597 if (ntohl(a
->router_id
) < ntohl(b
->router_id
))
600 zlog_warn("Router-ID duplicate ?");
604 uint8_t dr_election(struct ospf6_interface
*oi
)
606 struct listnode
*node
, *nnode
;
607 struct ospf6_neighbor
*on
, *drouter
, *bdrouter
, myself
;
608 struct ospf6_neighbor
*best_drouter
, *best_bdrouter
;
609 uint8_t next_state
= 0;
611 drouter
= bdrouter
= NULL
;
612 best_drouter
= best_bdrouter
= NULL
;
614 /* pseudo neighbor myself, including noting current DR/BDR (1) */
615 memset(&myself
, 0, sizeof(myself
));
616 inet_ntop(AF_INET
, &oi
->area
->ospf6
->router_id
, myself
.name
,
617 sizeof(myself
.name
));
618 myself
.state
= OSPF6_NEIGHBOR_TWOWAY
;
619 myself
.drouter
= oi
->drouter
;
620 myself
.bdrouter
= oi
->bdrouter
;
621 myself
.priority
= oi
->priority
;
622 myself
.router_id
= oi
->area
->ospf6
->router_id
;
624 /* Electing BDR (2) */
625 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
))
626 bdrouter
= better_bdrouter(bdrouter
, on
);
628 best_bdrouter
= bdrouter
;
629 bdrouter
= better_bdrouter(best_bdrouter
, &myself
);
631 /* Electing DR (3) */
632 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
))
633 drouter
= better_drouter(drouter
, on
);
635 best_drouter
= drouter
;
636 drouter
= better_drouter(best_drouter
, &myself
);
640 /* the router itself is newly/no longer DR/BDR (4) */
641 if ((drouter
== &myself
&& myself
.drouter
!= myself
.router_id
)
642 || (drouter
!= &myself
&& myself
.drouter
== myself
.router_id
)
643 || (bdrouter
== &myself
&& myself
.bdrouter
!= myself
.router_id
)
644 || (bdrouter
!= &myself
&& myself
.bdrouter
== myself
.router_id
)) {
645 myself
.drouter
= (drouter
? drouter
->router_id
: htonl(0));
646 myself
.bdrouter
= (bdrouter
? bdrouter
->router_id
: htonl(0));
648 /* compatible to Electing BDR (2) */
649 bdrouter
= better_bdrouter(best_bdrouter
, &myself
);
651 /* compatible to Electing DR (3) */
652 drouter
= better_drouter(best_drouter
, &myself
);
657 /* Set interface state accordingly (5) */
658 if (drouter
&& drouter
== &myself
)
659 next_state
= OSPF6_INTERFACE_DR
;
660 else if (bdrouter
&& bdrouter
== &myself
)
661 next_state
= OSPF6_INTERFACE_BDR
;
663 next_state
= OSPF6_INTERFACE_DROTHER
;
665 /* If NBMA, schedule Start for each neighbor having priority of 0 (6) */
668 /* If DR or BDR change, invoke AdjOK? for each neighbor (7) */
669 /* RFC 2328 section 12.4. Originating LSAs (3) will be handled
670 accordingly after AdjOK */
671 if (oi
->drouter
!= (drouter
? drouter
->router_id
: htonl(0))
672 || oi
->bdrouter
!= (bdrouter
? bdrouter
->router_id
: htonl(0))) {
673 if (IS_OSPF6_DEBUG_INTERFACE
)
674 zlog_debug("DR Election on %s: DR: %s BDR: %s",
676 (drouter
? drouter
->name
: "0.0.0.0"),
677 (bdrouter
? bdrouter
->name
: "0.0.0.0"));
679 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, node
, on
)) {
680 if (on
->state
< OSPF6_NEIGHBOR_TWOWAY
)
682 /* Schedule AdjOK. */
683 thread_add_event(master
, adj_ok
, on
, 0,
688 oi
->drouter
= (drouter
? drouter
->router_id
: htonl(0));
689 oi
->bdrouter
= (bdrouter
? bdrouter
->router_id
: htonl(0));
697 static bool ifmaddr_check(ifindex_t ifindex
, struct in6_addr
*addr
)
699 struct ifmaddrs
*ifmap
, *ifma
;
700 struct sockaddr_dl
*sdl
;
701 struct sockaddr_in6
*sin6
;
704 if (getifmaddrs(&ifmap
) != 0)
707 for (ifma
= ifmap
; ifma
; ifma
= ifma
->ifma_next
) {
708 if (ifma
->ifma_name
== NULL
|| ifma
->ifma_addr
== NULL
)
710 if (ifma
->ifma_name
->sa_family
!= AF_LINK
)
712 if (ifma
->ifma_addr
->sa_family
!= AF_INET6
)
714 sdl
= (struct sockaddr_dl
*)ifma
->ifma_name
;
715 sin6
= (struct sockaddr_in6
*)ifma
->ifma_addr
;
716 if (sdl
->sdl_index
== ifindex
717 && memcmp(&sin6
->sin6_addr
, addr
, IPV6_MAX_BYTELEN
) == 0) {
729 #endif /* __FreeBSD__ */
731 /* Interface State Machine */
732 void interface_up(struct thread
*thread
)
734 struct ospf6_interface
*oi
;
737 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
738 assert(oi
&& oi
->interface
);
741 oi
->type
= ospf6_default_iftype(oi
->interface
);
743 thread_cancel(&oi
->thread_sso
);
745 if (IS_OSPF6_DEBUG_INTERFACE
)
746 zlog_debug("Interface Event %s: [InterfaceUp]",
747 oi
->interface
->name
);
749 /* check physical interface is up */
750 if (!if_is_operative(oi
->interface
)) {
751 zlog_warn("Interface %s is down, can't execute [InterfaceUp]",
752 oi
->interface
->name
);
756 /* check interface has a link-local address */
757 if (!(ospf6_interface_get_linklocal_address(oi
->interface
)
758 || if_is_loopback(oi
->interface
))) {
760 "Interface %s has no link local address, can't execute [InterfaceUp]",
761 oi
->interface
->name
);
766 ospf6_interface_recalculate_cost(oi
);
768 /* if already enabled, do nothing */
769 if (oi
->state
> OSPF6_INTERFACE_DOWN
) {
770 if (IS_OSPF6_DEBUG_INTERFACE
)
771 zlog_debug("Interface %s already enabled",
772 oi
->interface
->name
);
776 /* If no area assigned, return */
777 if (oi
->area
== NULL
) {
779 "%s: Not scheduling Hello for %s as there is no area assigned yet",
780 __func__
, oi
->interface
->name
);
786 * There's a delay in FreeBSD between issuing a command to leave a
787 * multicast group and an actual leave. If we execute "no router ospf6"
788 * and "router ospf6" fast enough, we can end up in a situation when OS
789 * performs the leave later than it performs the join and the interface
790 * remains without a multicast group. We have to do the join only after
791 * the interface actually left the group.
793 if (ifmaddr_check(oi
->interface
->ifindex
, &allspfrouters6
)) {
795 "Interface %s is still in all routers group, rescheduling for SSO",
796 oi
->interface
->name
);
797 thread_add_timer(master
, interface_up
, oi
,
798 OSPF6_INTERFACE_SSO_RETRY_INT
,
802 #endif /* __FreeBSD__ */
804 ospf6
= oi
->area
->ospf6
;
806 /* Join AllSPFRouters */
807 if (ospf6_sso(oi
->interface
->ifindex
, &allspfrouters6
, IPV6_JOIN_GROUP
,
810 if (oi
->sso_try_cnt
++ < OSPF6_INTERFACE_SSO_RETRY_MAX
) {
812 "Scheduling %s for sso retry, trial count: %d",
813 oi
->interface
->name
, oi
->sso_try_cnt
);
814 thread_add_timer(master
, interface_up
, oi
,
815 OSPF6_INTERFACE_SSO_RETRY_INT
,
820 oi
->sso_try_cnt
= 0; /* Reset on success */
822 /* Update interface route */
823 ospf6_interface_connected_route_update(oi
->interface
);
826 if (!CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_PASSIVE
)
827 && !if_is_loopback(oi
->interface
)) {
828 thread_add_timer(master
, ospf6_hello_send
, oi
, 0,
829 &oi
->thread_send_hello
);
832 /* decide next interface state */
833 if (oi
->type
== OSPF_IFTYPE_LOOPBACK
) {
834 ospf6_interface_state_change(OSPF6_INTERFACE_LOOPBACK
, oi
);
835 } else if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
) {
836 ospf6_interface_state_change(OSPF6_INTERFACE_POINTTOPOINT
, oi
);
837 } else if (oi
->priority
== 0)
838 ospf6_interface_state_change(OSPF6_INTERFACE_DROTHER
, oi
);
840 ospf6_interface_state_change(OSPF6_INTERFACE_WAITING
, oi
);
841 thread_add_timer(master
, wait_timer
, oi
, oi
->dead_interval
,
842 &oi
->thread_wait_timer
);
846 void wait_timer(struct thread
*thread
)
848 struct ospf6_interface
*oi
;
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: [WaitTimer]",
855 oi
->interface
->name
);
857 if (oi
->state
== OSPF6_INTERFACE_WAITING
)
858 ospf6_interface_state_change(dr_election(oi
), oi
);
861 void backup_seen(struct thread
*thread
)
863 struct ospf6_interface
*oi
;
865 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
866 assert(oi
&& oi
->interface
);
868 if (IS_OSPF6_DEBUG_INTERFACE
)
869 zlog_debug("Interface Event %s: [BackupSeen]",
870 oi
->interface
->name
);
872 if (oi
->state
== OSPF6_INTERFACE_WAITING
)
873 ospf6_interface_state_change(dr_election(oi
), oi
);
876 void neighbor_change(struct thread
*thread
)
878 struct ospf6_interface
*oi
;
880 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
881 assert(oi
&& oi
->interface
);
883 if (IS_OSPF6_DEBUG_INTERFACE
)
884 zlog_debug("Interface Event %s: [NeighborChange]",
885 oi
->interface
->name
);
887 if (oi
->state
== OSPF6_INTERFACE_DROTHER
888 || oi
->state
== OSPF6_INTERFACE_BDR
889 || oi
->state
== OSPF6_INTERFACE_DR
)
890 ospf6_interface_state_change(dr_election(oi
), oi
);
893 void interface_down(struct thread
*thread
)
895 struct ospf6_interface
*oi
;
896 struct listnode
*node
, *nnode
;
897 struct ospf6_neighbor
*on
;
900 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
901 assert(oi
&& oi
->interface
);
903 if (IS_OSPF6_DEBUG_INTERFACE
)
904 zlog_debug("Interface Event %s: [InterfaceDown]",
905 oi
->interface
->name
);
908 THREAD_OFF(oi
->thread_send_hello
);
910 /* Stop trying to set socket options. */
911 THREAD_OFF(oi
->thread_sso
);
913 /* Cease the HELPER role for all the neighbours
916 if (ospf6_interface_neighbor_count(oi
)) {
918 struct ospf6_neighbor
*nbr
= NULL
;
920 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, ln
, nbr
))
921 ospf6_gr_helper_exit(nbr
, OSPF6_GR_HELPER_TOPO_CHG
);
924 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
))
925 ospf6_neighbor_delete(on
);
927 list_delete_all_node(oi
->neighbor_list
);
929 /* When interface state is reset, also reset information about
930 * DR election, as it is no longer valid. */
931 oi
->drouter
= oi
->prev_drouter
= htonl(0);
932 oi
->bdrouter
= oi
->prev_bdrouter
= htonl(0);
934 if (oi
->area
== NULL
)
937 ospf6
= oi
->area
->ospf6
;
938 /* Leave AllSPFRouters */
939 if (oi
->state
> OSPF6_INTERFACE_DOWN
)
940 ospf6_sso(oi
->interface
->ifindex
, &allspfrouters6
,
941 IPV6_LEAVE_GROUP
, ospf6
->fd
);
943 /* deal with write fifo */
944 ospf6_fifo_flush(oi
->obuf
);
945 if (oi
->on_write_q
) {
946 listnode_delete(ospf6
->oi_write_q
, oi
);
947 if (list_isempty(ospf6
->oi_write_q
))
948 thread_cancel(&ospf6
->t_write
);
952 ospf6_interface_state_change(OSPF6_INTERFACE_DOWN
, oi
);
956 static const char *ospf6_iftype_str(uint8_t iftype
)
959 case OSPF_IFTYPE_LOOPBACK
:
961 case OSPF_IFTYPE_BROADCAST
:
963 case OSPF_IFTYPE_POINTOPOINT
:
964 return "POINTOPOINT";
969 /* show specified interface structure */
970 static int ospf6_interface_show(struct vty
*vty
, struct interface
*ifp
,
971 json_object
*json_obj
, bool use_json
)
973 struct ospf6_interface
*oi
;
977 char strbuf
[PREFIX2STR_BUFFER
], drouter
[32], bdrouter
[32];
978 uint8_t default_iftype
;
979 struct timeval res
, now
;
981 struct ospf6_lsa
*lsa
, *lsanext
;
982 json_object
*json_arr
;
983 json_object
*json_addr
;
984 struct json_object
*json_auth
= NULL
;
986 default_iftype
= ospf6_default_iftype(ifp
);
989 json_object_string_add(json_obj
, "status",
990 (if_is_operative(ifp
) ? "up" : "down"));
991 json_object_string_add(json_obj
, "type",
992 ospf6_iftype_str(default_iftype
));
993 json_object_int_add(json_obj
, "interfaceId", ifp
->ifindex
);
995 if (ifp
->info
== NULL
)
998 oi
= (struct ospf6_interface
*)ifp
->info
;
1000 if (if_is_operative(ifp
) && oi
->type
!= default_iftype
)
1001 json_object_string_add(json_obj
, "operatingAsType",
1002 ospf6_iftype_str(oi
->type
));
1005 vty_out(vty
, "%s is %s, type %s\n", ifp
->name
,
1006 (if_is_operative(ifp
) ? "up" : "down"),
1007 ospf6_iftype_str(default_iftype
));
1008 vty_out(vty
, " Interface ID: %d\n", ifp
->ifindex
);
1010 if (ifp
->info
== NULL
) {
1011 vty_out(vty
, " OSPF not enabled on this interface\n");
1014 oi
= (struct ospf6_interface
*)ifp
->info
;
1016 if (if_is_operative(ifp
) && oi
->type
!= default_iftype
)
1017 vty_out(vty
, " Operating as type %s\n",
1018 ospf6_iftype_str(oi
->type
));
1022 json_arr
= json_object_new_array();
1023 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, i
, c
)) {
1024 json_addr
= json_object_new_object();
1026 prefix2str(p
, strbuf
, sizeof(strbuf
));
1027 switch (p
->family
) {
1029 json_object_string_add(json_addr
, "type",
1031 json_object_string_add(json_addr
, "address",
1033 json_object_array_add(json_arr
, json_addr
);
1036 json_object_string_add(json_addr
, "type",
1038 json_object_string_add(json_addr
, "address",
1040 json_object_array_add(json_arr
, json_addr
);
1043 json_object_string_add(json_addr
, "type",
1045 json_object_string_add(json_addr
, "address",
1047 json_object_array_add(json_arr
, json_addr
);
1051 json_object_object_add(json_obj
, "internetAddress", json_arr
);
1053 vty_out(vty
, " Internet Address:\n");
1055 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, i
, c
)) {
1057 prefix2str(p
, strbuf
, sizeof(strbuf
));
1058 switch (p
->family
) {
1060 vty_out(vty
, " inet : %pFX\n", p
);
1063 vty_out(vty
, " inet6: %pFX\n", p
);
1066 vty_out(vty
, " ??? : %pFX\n", p
);
1074 json_object_boolean_true_add(json_obj
,
1076 json_object_int_add(json_obj
, "instanceId",
1078 json_object_int_add(json_obj
, "interfaceMtu",
1080 json_object_int_add(json_obj
, "autoDetect", ifp
->mtu6
);
1081 json_object_string_add(json_obj
, "mtuMismatchDetection",
1082 oi
->mtu_ignore
? "disabled"
1084 inet_ntop(AF_INET
, &oi
->area
->area_id
, strbuf
,
1086 json_object_string_add(json_obj
, "areaId", strbuf
);
1087 json_object_int_add(json_obj
, "cost", oi
->cost
);
1089 json_object_boolean_false_add(json_obj
,
1095 " Instance ID %d, Interface MTU %d (autodetect: %d)\n",
1096 oi
->instance_id
, oi
->ifmtu
, ifp
->mtu6
);
1097 vty_out(vty
, " MTU mismatch detection: %s\n",
1098 oi
->mtu_ignore
? "disabled" : "enabled");
1099 inet_ntop(AF_INET
, &oi
->area
->area_id
, strbuf
,
1101 vty_out(vty
, " Area ID %s, Cost %u\n", strbuf
,
1104 vty_out(vty
, " Not Attached to Area\n");
1108 json_object_string_add(json_obj
, "ospf6InterfaceState",
1109 ospf6_interface_state_str
[oi
->state
]);
1110 json_object_int_add(json_obj
, "transmitDelaySec",
1112 json_object_int_add(json_obj
, "priority", oi
->priority
);
1113 json_object_int_add(json_obj
, "timerIntervalsConfigHello",
1114 oi
->hello_interval
);
1115 json_object_int_add(json_obj
, "timerIntervalsConfigDead",
1117 json_object_int_add(json_obj
, "timerIntervalsConfigRetransmit",
1120 vty_out(vty
, " State %s, Transmit Delay %d sec, Priority %d\n",
1121 ospf6_interface_state_str
[oi
->state
], oi
->transdelay
,
1123 vty_out(vty
, " Timer intervals configured:\n");
1124 vty_out(vty
, " Hello %d(%pTHd), Dead %d, Retransmit %d\n",
1125 oi
->hello_interval
, oi
->thread_send_hello
,
1126 oi
->dead_interval
, oi
->rxmt_interval
);
1129 inet_ntop(AF_INET
, &oi
->drouter
, drouter
, sizeof(drouter
));
1130 inet_ntop(AF_INET
, &oi
->bdrouter
, bdrouter
, sizeof(bdrouter
));
1132 json_object_string_add(json_obj
, "dr", drouter
);
1133 json_object_string_add(json_obj
, "bdr", bdrouter
);
1134 json_object_int_add(json_obj
, "numberOfInterfaceScopedLsa",
1137 vty_out(vty
, " DR: %s BDR: %s\n", drouter
, bdrouter
);
1138 vty_out(vty
, " Number of I/F scoped LSAs is %u\n",
1146 if (thread_is_scheduled(oi
->thread_send_lsupdate
))
1147 timersub(&oi
->thread_send_lsupdate
->u
.sands
, &now
,
1149 timerstring(&res
, duration
, sizeof(duration
));
1150 json_object_int_add(json_obj
, "pendingLsaLsUpdateCount",
1151 oi
->lsupdate_list
->count
);
1152 json_object_string_add(json_obj
, "pendingLsaLsUpdateTime",
1154 json_object_string_add(
1155 json_obj
, "lsUpdateSendThread",
1156 (thread_is_scheduled(oi
->thread_send_lsupdate
)
1160 json_arr
= json_object_new_array();
1161 for (ALL_LSDB(oi
->lsupdate_list
, lsa
, lsanext
))
1162 json_object_array_add(
1163 json_arr
, json_object_new_string(lsa
->name
));
1164 json_object_object_add(json_obj
, "pendingLsaLsUpdate",
1168 if (thread_is_scheduled(oi
->thread_send_lsack
))
1169 timersub(&oi
->thread_send_lsack
->u
.sands
, &now
, &res
);
1170 timerstring(&res
, duration
, sizeof(duration
));
1172 json_object_int_add(json_obj
, "pendingLsaLsAckCount",
1173 oi
->lsack_list
->count
);
1174 json_object_string_add(json_obj
, "pendingLsaLsAckTime",
1176 json_object_string_add(
1177 json_obj
, "lsAckSendThread",
1178 (thread_is_scheduled(oi
->thread_send_lsack
) ? "on"
1181 json_arr
= json_object_new_array();
1182 for (ALL_LSDB(oi
->lsack_list
, lsa
, lsanext
))
1183 json_object_array_add(
1184 json_arr
, json_object_new_string(lsa
->name
));
1185 json_object_object_add(json_obj
, "pendingLsaLsAck", json_arr
);
1189 if (thread_is_scheduled(oi
->thread_send_lsupdate
))
1190 timersub(&oi
->thread_send_lsupdate
->u
.sands
, &now
,
1192 timerstring(&res
, duration
, sizeof(duration
));
1194 " %d Pending LSAs for LSUpdate in Time %s [thread %s]\n",
1195 oi
->lsupdate_list
->count
, duration
,
1196 (thread_is_scheduled(oi
->thread_send_lsupdate
)
1199 for (ALL_LSDB(oi
->lsupdate_list
, lsa
, lsanext
))
1200 vty_out(vty
, " %s\n", lsa
->name
);
1203 if (thread_is_scheduled(oi
->thread_send_lsack
))
1204 timersub(&oi
->thread_send_lsack
->u
.sands
, &now
, &res
);
1205 timerstring(&res
, duration
, sizeof(duration
));
1207 " %d Pending LSAs for LSAck in Time %s [thread %s]\n",
1208 oi
->lsack_list
->count
, duration
,
1209 (thread_is_scheduled(oi
->thread_send_lsack
) ? "on"
1211 for (ALL_LSDB(oi
->lsack_list
, lsa
, lsanext
))
1212 vty_out(vty
, " %s\n", lsa
->name
);
1216 if (oi
->bfd_config
.enabled
) {
1218 struct json_object
*json_bfd
= json_object_new_object();
1220 json_object_int_add(
1221 json_bfd
, "detectMultiplier",
1222 oi
->bfd_config
.detection_multiplier
);
1223 json_object_int_add(json_bfd
, "rxMinInterval",
1224 oi
->bfd_config
.min_rx
);
1225 json_object_int_add(json_bfd
, "txMinInterval",
1226 oi
->bfd_config
.min_tx
);
1227 json_object_object_add(json_obj
, "peerBfdInfo",
1231 " BFD: Detect Multiplier: %d, Min Rx interval: %d, Min Tx interval: %d\n",
1232 oi
->bfd_config
.detection_multiplier
,
1233 oi
->bfd_config
.min_rx
, oi
->bfd_config
.min_tx
);
1237 json_auth
= json_object_new_object();
1238 if (oi
->at_data
.flags
!= 0) {
1240 if (CHECK_FLAG(oi
->at_data
.flags
,
1241 OSPF6_AUTH_TRAILER_KEYCHAIN
)) {
1242 json_object_string_add(json_auth
, "authType",
1244 json_object_string_add(json_auth
,
1246 oi
->at_data
.keychain
);
1247 } else if (CHECK_FLAG(oi
->at_data
.flags
,
1248 OSPF6_AUTH_TRAILER_MANUAL_KEY
))
1249 json_object_string_add(json_auth
, "authType",
1251 json_object_int_add(json_auth
, "txPktDrop",
1252 oi
->at_data
.tx_drop
);
1253 json_object_int_add(json_auth
, "rxPktDrop",
1254 oi
->at_data
.rx_drop
);
1256 if (CHECK_FLAG(oi
->at_data
.flags
,
1257 OSPF6_AUTH_TRAILER_KEYCHAIN
))
1259 " Authentication Trailer is enabled with key-chain %s\n",
1260 oi
->at_data
.keychain
);
1261 else if (CHECK_FLAG(oi
->at_data
.flags
,
1262 OSPF6_AUTH_TRAILER_MANUAL_KEY
))
1264 " Authentication trailer is enabled with manual key\n");
1266 " Packet drop Tx %u, Packet drop Rx %u\n",
1267 oi
->at_data
.tx_drop
, oi
->at_data
.rx_drop
);
1271 json_object_string_add(json_auth
, "authType", "NULL");
1273 vty_out(vty
, " Authentication Trailer is disabled\n");
1277 json_object_object_add(json_obj
, "authInfo", json_auth
);
1282 /* Find the global address to be used as a forwarding address in NSSA LSA.*/
1283 struct in6_addr
*ospf6_interface_get_global_address(struct interface
*ifp
)
1286 struct connected
*c
;
1288 /* for each connected address */
1289 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, n
, c
)) {
1290 /* if family not AF_INET6, ignore */
1291 if (c
->address
->family
!= AF_INET6
)
1294 if (!IN6_IS_ADDR_LINKLOCAL(&c
->address
->u
.prefix6
))
1295 return &c
->address
->u
.prefix6
;
1302 static int show_ospf6_interface_common(struct vty
*vty
, vrf_id_t vrf_id
,
1303 int argc
, struct cmd_token
**argv
,
1304 int idx_ifname
, int intf_idx
,
1305 int json_idx
, bool uj
)
1308 struct vrf
*vrf
= vrf_lookup_by_id(vrf_id
);
1309 struct interface
*ifp
;
1311 json_object
*json_int
;
1314 json
= json_object_new_object();
1315 if (argc
== json_idx
) {
1316 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
1317 json_int
= json_object_new_object();
1319 json_object_string_add(json
, "noSuchInterface",
1320 argv
[idx_ifname
]->arg
);
1321 vty_json(vty
, json
);
1322 json_object_free(json_int
);
1325 ospf6_interface_show(vty
, ifp
, json_int
, uj
);
1326 json_object_object_add(json
, ifp
->name
, json_int
);
1328 FOR_ALL_INTERFACES (vrf
, ifp
) {
1329 json_int
= json_object_new_object();
1330 ospf6_interface_show(vty
, ifp
, json_int
, uj
);
1331 json_object_object_add(json
, ifp
->name
,
1335 vty_json(vty
, json
);
1337 if (argc
== intf_idx
) {
1338 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
1340 vty_out(vty
, "No such Interface: %s\n",
1341 argv
[idx_ifname
]->arg
);
1344 ospf6_interface_show(vty
, ifp
, NULL
, uj
);
1346 FOR_ALL_INTERFACES (vrf
, ifp
)
1347 ospf6_interface_show(vty
, ifp
, NULL
, uj
);
1353 /* show interface */
1354 DEFUN(show_ipv6_ospf6_interface
, show_ipv6_ospf6_interface_ifname_cmd
,
1355 "show ipv6 ospf6 [vrf <NAME|all>] interface [IFNAME] [json]",
1356 SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR
1357 "All VRFs\n" INTERFACE_STR IFNAME_STR JSON_STR
)
1362 struct listnode
*node
;
1363 struct ospf6
*ospf6
;
1364 const char *vrf_name
= NULL
;
1365 bool all_vrf
= false;
1367 bool uj
= use_json(argc
, argv
);
1369 OSPF6_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
1376 for (ALL_LIST_ELEMENTS_RO(om6
->ospf6
, node
, ospf6
)) {
1377 if (all_vrf
|| strcmp(ospf6
->name
, vrf_name
) == 0) {
1378 show_ospf6_interface_common(vty
, ospf6
->vrf_id
, argc
,
1379 argv
, idx_ifname
, intf_idx
,
1387 OSPF6_CMD_CHECK_VRF(uj
, all_vrf
, ospf6
);
1392 static int ospf6_interface_show_traffic(struct vty
*vty
,
1393 struct interface
*intf_ifp
,
1394 int display_once
, json_object
*json
,
1395 bool use_json
, vrf_id_t vrf_id
)
1397 struct interface
*ifp
;
1398 struct vrf
*vrf
= NULL
;
1399 struct ospf6_interface
*oi
= NULL
;
1400 json_object
*json_interface
;
1402 if (!display_once
&& !use_json
) {
1404 vty_out(vty
, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface",
1405 " HELLO", " DB-Desc", " LS-Req", " LS-Update",
1407 vty_out(vty
, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "",
1408 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
1411 "--------------------------------------------------------------------------------------------\n");
1414 if (intf_ifp
== NULL
) {
1415 vrf
= vrf_lookup_by_id(vrf_id
);
1416 FOR_ALL_INTERFACES (vrf
, ifp
) {
1418 oi
= (struct ospf6_interface
*)ifp
->info
;
1423 json_interface
= json_object_new_object();
1424 json_object_int_add(json_interface
, "helloRx",
1426 json_object_int_add(json_interface
, "helloTx",
1428 json_object_int_add(json_interface
, "dbDescRx",
1430 json_object_int_add(json_interface
, "dbDescTx",
1432 json_object_int_add(json_interface
, "lsReqRx",
1434 json_object_int_add(json_interface
, "lsReqTx",
1436 json_object_int_add(json_interface
,
1439 json_object_int_add(json_interface
,
1442 json_object_int_add(json_interface
, "lsAckRx",
1444 json_object_int_add(json_interface
, "lsAckTx",
1447 json_object_object_add(json
,
1448 oi
->interface
->name
,
1452 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
1453 oi
->interface
->name
, oi
->hello_in
,
1454 oi
->hello_out
, oi
->db_desc_in
,
1455 oi
->db_desc_out
, oi
->ls_req_in
,
1456 oi
->ls_req_out
, oi
->ls_upd_in
,
1457 oi
->ls_upd_out
, oi
->ls_ack_in
,
1461 oi
= intf_ifp
->info
;
1466 json_interface
= json_object_new_object();
1467 json_object_int_add(json_interface
, "helloRx",
1469 json_object_int_add(json_interface
, "helloTx",
1471 json_object_int_add(json_interface
, "dbDescRx",
1473 json_object_int_add(json_interface
, "dbDescTx",
1475 json_object_int_add(json_interface
, "lsReqRx",
1477 json_object_int_add(json_interface
, "lsReqTx",
1479 json_object_int_add(json_interface
, "lsUpdateRx",
1481 json_object_int_add(json_interface
, "lsUpdateTx",
1483 json_object_int_add(json_interface
, "lsAckRx",
1485 json_object_int_add(json_interface
, "lsAckTx",
1488 json_object_object_add(json
, oi
->interface
->name
,
1492 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
1493 oi
->interface
->name
, oi
->hello_in
,
1494 oi
->hello_out
, oi
->db_desc_in
, oi
->db_desc_out
,
1495 oi
->ls_req_in
, oi
->ls_req_out
, oi
->ls_upd_in
,
1496 oi
->ls_upd_out
, oi
->ls_ack_in
, oi
->ls_ack_out
);
1502 static int ospf6_interface_show_traffic_common(struct vty
*vty
, int argc
,
1503 struct cmd_token
**argv
,
1504 vrf_id_t vrf_id
, bool uj
)
1507 int display_once
= 0;
1508 char *intf_name
= NULL
;
1509 struct interface
*ifp
= NULL
;
1510 json_object
*json
= NULL
;
1513 json
= json_object_new_object();
1515 if (argv_find(argv
, argc
, "IFNAME", &idx_ifname
)) {
1516 intf_name
= argv
[idx_ifname
]->arg
;
1517 ifp
= if_lookup_by_name(intf_name
, vrf_id
);
1520 json_object_string_add(json
, "status",
1521 "No Such Interface");
1522 json_object_string_add(json
, "interface",
1524 vty_json(vty
, json
);
1527 if (ifp
->info
== NULL
) {
1528 json_object_string_add(
1530 "OSPF not enabled on this interface");
1531 json_object_string_add(json
, "interface",
1533 vty_json(vty
, json
);
1538 vty_out(vty
, "No such Interface: %s\n",
1542 if (ifp
->info
== NULL
) {
1544 " OSPF not enabled on this interface %s\n",
1551 ospf6_interface_show_traffic(vty
, ifp
, display_once
, json
, uj
, vrf_id
);
1554 vty_json(vty
, json
);
1559 /* show interface */
1560 DEFUN(show_ipv6_ospf6_interface_traffic
, show_ipv6_ospf6_interface_traffic_cmd
,
1561 "show ipv6 ospf6 [vrf <NAME|all>] interface traffic [IFNAME] [json]",
1562 SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR
1563 "All VRFs\n" INTERFACE_STR
1564 "Protocol Packet counters\n" IFNAME_STR JSON_STR
)
1566 struct ospf6
*ospf6
;
1567 struct listnode
*node
;
1568 const char *vrf_name
= NULL
;
1569 bool all_vrf
= false;
1571 bool uj
= use_json(argc
, argv
);
1573 OSPF6_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
1575 for (ALL_LIST_ELEMENTS_RO(om6
->ospf6
, node
, ospf6
)) {
1576 if (all_vrf
|| strcmp(ospf6
->name
, vrf_name
) == 0) {
1577 ospf6_interface_show_traffic_common(vty
, argc
, argv
,
1585 OSPF6_CMD_CHECK_VRF(uj
, all_vrf
, ospf6
);
1591 DEFUN(show_ipv6_ospf6_interface_ifname_prefix
,
1592 show_ipv6_ospf6_interface_ifname_prefix_cmd
,
1593 "show ipv6 ospf6 [vrf <NAME|all>] interface IFNAME prefix\
1596 |<X:X::X:X|X:X::X:X/M> [<match|detail>]\
1598 SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR
1599 "All VRFs\n" INTERFACE_STR IFNAME_STR
1600 "Display connected prefixes to advertise\n"
1601 "Display details of the prefixes\n" OSPF6_ROUTE_ADDRESS_STR
1602 OSPF6_ROUTE_PREFIX_STR OSPF6_ROUTE_MATCH_STR
1603 "Display details of the prefixes\n" JSON_STR
)
1607 struct ospf6_interface
*oi
;
1608 bool uj
= use_json(argc
, argv
);
1610 struct ospf6
*ospf6
;
1611 struct listnode
*node
;
1612 struct interface
*ifp
;
1613 const char *vrf_name
= NULL
;
1614 bool all_vrf
= false;
1617 OSPF6_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
1623 for (ALL_LIST_ELEMENTS_RO(om6
->ospf6
, node
, ospf6
)) {
1624 if (all_vrf
|| strcmp(ospf6
->name
, vrf_name
) == 0) {
1625 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
,
1628 vty_out(vty
, "No such Interface: %s\n",
1629 argv
[idx_ifname
]->arg
);
1635 || CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_DISABLE
)) {
1637 "Interface %s not attached to area\n",
1638 argv
[idx_ifname
]->arg
);
1642 ospf6_route_table_show(vty
, idx_prefix
, argc
, argv
,
1643 oi
->route_connected
, uj
);
1650 OSPF6_CMD_CHECK_VRF(uj
, all_vrf
, ospf6
);
1655 DEFUN(show_ipv6_ospf6_interface_prefix
, show_ipv6_ospf6_interface_prefix_cmd
,
1656 "show ipv6 ospf6 [vrf <NAME|all>] interface prefix\
1659 |<X:X::X:X|X:X::X:X/M> [<match|detail>]\
1661 SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR
1662 "All VRFs\n" INTERFACE_STR
1663 "Display connected prefixes to advertise\n"
1664 "Display details of the prefixes\n" OSPF6_ROUTE_ADDRESS_STR
1665 OSPF6_ROUTE_PREFIX_STR OSPF6_ROUTE_MATCH_STR
1666 "Display details of the prefixes\n" JSON_STR
)
1668 struct vrf
*vrf
= NULL
;
1670 struct ospf6_interface
*oi
;
1671 struct interface
*ifp
;
1672 bool uj
= use_json(argc
, argv
);
1673 struct listnode
*node
;
1674 struct ospf6
*ospf6
;
1675 const char *vrf_name
= NULL
;
1676 bool all_vrf
= false;
1679 OSPF6_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
1683 for (ALL_LIST_ELEMENTS_RO(om6
->ospf6
, node
, ospf6
)) {
1684 if (all_vrf
|| strcmp(ospf6
->name
, vrf_name
) == 0) {
1685 vrf
= vrf_lookup_by_id(ospf6
->vrf_id
);
1686 FOR_ALL_INTERFACES (vrf
, ifp
) {
1687 oi
= (struct ospf6_interface
*)ifp
->info
;
1689 || CHECK_FLAG(oi
->flag
,
1690 OSPF6_INTERFACE_DISABLE
))
1693 ospf6_route_table_show(vty
, idx_prefix
, argc
,
1695 oi
->route_connected
, uj
);
1702 OSPF6_CMD_CHECK_VRF(uj
, all_vrf
, ospf6
);
1707 void ospf6_interface_start(struct ospf6_interface
*oi
)
1709 struct ospf6
*ospf6
;
1710 struct ospf6_area
*oa
;
1712 if (oi
->area_id_format
== OSPF6_AREA_FMT_UNSET
)
1718 ospf6
= oi
->interface
->vrf
->info
;
1722 oa
= ospf6_area_lookup(oi
->area_id
, ospf6
);
1724 oa
= ospf6_area_create(oi
->area_id
, ospf6
, oi
->area_id_format
);
1726 /* attach interface to area */
1727 listnode_add(oa
->if_list
, oi
);
1730 SET_FLAG(oa
->flag
, OSPF6_AREA_ENABLE
);
1733 ospf6_interface_enable(oi
);
1735 /* If the router is ABR, originate summary routes */
1736 if (ospf6_check_and_set_router_abr(ospf6
))
1737 ospf6_abr_enable_area(oa
);
1740 void ospf6_interface_stop(struct ospf6_interface
*oi
)
1742 struct ospf6_area
*oa
;
1748 ospf6_interface_disable(oi
);
1750 listnode_delete(oa
->if_list
, oi
);
1753 if (oa
->if_list
->count
== 0) {
1754 UNSET_FLAG(oa
->flag
, OSPF6_AREA_ENABLE
);
1755 ospf6_abr_disable_area(oa
);
1759 /* interface variable set command */
1760 DEFUN (ipv6_ospf6_area
,
1761 ipv6_ospf6_area_cmd
,
1762 "ipv6 ospf6 area <A.B.C.D|(0-4294967295)>",
1765 "Specify the OSPF6 area ID\n"
1766 "OSPF6 area ID in IPv4 address notation\n"
1767 "OSPF6 area ID in decimal notation\n")
1769 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1770 struct ospf6_interface
*oi
;
1777 oi
= (struct ospf6_interface
*)ifp
->info
;
1779 oi
= ospf6_interface_create(ifp
);
1783 vty_out(vty
, "%s already attached to Area %s\n",
1784 oi
->interface
->name
, oi
->area
->name
);
1788 if (str2area_id(argv
[idx_ipv4
]->arg
, &area_id
, &format
)) {
1789 vty_out(vty
, "Malformed Area-ID: %s\n", argv
[idx_ipv4
]->arg
);
1790 return CMD_WARNING_CONFIG_FAILED
;
1793 oi
->area_id
= area_id
;
1794 oi
->area_id_format
= format
;
1796 ospf6_interface_start(oi
);
1801 DEFUN (no_ipv6_ospf6_area
,
1802 no_ipv6_ospf6_area_cmd
,
1803 "no ipv6 ospf6 area [<A.B.C.D|(0-4294967295)>]",
1807 "Specify the OSPF6 area ID\n"
1808 "OSPF6 area ID in IPv4 address notation\n"
1809 "OSPF6 area ID in decimal notation\n")
1811 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1812 struct ospf6_interface
*oi
;
1816 oi
= (struct ospf6_interface
*)ifp
->info
;
1818 oi
= ospf6_interface_create(ifp
);
1821 ospf6_interface_stop(oi
);
1824 oi
->area_id_format
= OSPF6_AREA_FMT_UNSET
;
1829 DEFUN (ipv6_ospf6_ifmtu
,
1830 ipv6_ospf6_ifmtu_cmd
,
1831 "ipv6 ospf6 ifmtu (1-65535)",
1835 "OSPFv3 Interface MTU\n"
1838 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1840 struct ospf6_interface
*oi
;
1841 unsigned int ifmtu
, iobuflen
;
1842 struct listnode
*node
, *nnode
;
1843 struct ospf6_neighbor
*on
;
1847 oi
= (struct ospf6_interface
*)ifp
->info
;
1849 oi
= ospf6_interface_create(ifp
);
1852 ifmtu
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
1854 if (oi
->c_ifmtu
== ifmtu
)
1857 if (ifp
->mtu6
!= 0 && ifp
->mtu6
< ifmtu
) {
1859 "%s's ospf6 ifmtu cannot go beyond physical mtu (%d)\n",
1860 ifp
->name
, ifp
->mtu6
);
1861 return CMD_WARNING_CONFIG_FAILED
;
1864 if (oi
->ifmtu
< ifmtu
) {
1865 iobuflen
= ospf6_iobuf_size(ifmtu
);
1866 if (iobuflen
< ifmtu
) {
1868 "%s's ifmtu is adjusted to I/O buffer size (%d).\n",
1869 ifp
->name
, iobuflen
);
1870 oi
->ifmtu
= oi
->c_ifmtu
= iobuflen
;
1872 oi
->ifmtu
= oi
->c_ifmtu
= ifmtu
;
1874 oi
->ifmtu
= oi
->c_ifmtu
= ifmtu
;
1876 /* re-establish adjacencies */
1877 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
)) {
1878 THREAD_OFF(on
->inactivity_timer
);
1879 thread_add_event(master
, inactivity_timer
, on
, 0, NULL
);
1885 DEFUN (no_ipv6_ospf6_ifmtu
,
1886 no_ipv6_ospf6_ifmtu_cmd
,
1887 "no ipv6 ospf6 ifmtu [(1-65535)]",
1892 "OSPFv3 Interface MTU\n"
1895 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1896 struct ospf6_interface
*oi
;
1897 unsigned int iobuflen
;
1898 struct listnode
*node
, *nnode
;
1899 struct ospf6_neighbor
*on
;
1903 oi
= (struct ospf6_interface
*)ifp
->info
;
1905 oi
= ospf6_interface_create(ifp
);
1908 if (oi
->ifmtu
< ifp
->mtu
) {
1909 iobuflen
= ospf6_iobuf_size(ifp
->mtu
);
1910 if (iobuflen
< ifp
->mtu
) {
1912 "%s's ifmtu is adjusted to I/O buffer size (%d).\n",
1913 ifp
->name
, iobuflen
);
1914 oi
->ifmtu
= iobuflen
;
1916 oi
->ifmtu
= ifp
->mtu
;
1918 oi
->ifmtu
= ifp
->mtu
;
1922 /* re-establish adjacencies */
1923 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
)) {
1924 THREAD_OFF(on
->inactivity_timer
);
1925 thread_add_event(master
, inactivity_timer
, on
, 0, NULL
);
1931 DEFUN (ipv6_ospf6_cost
,
1932 ipv6_ospf6_cost_cmd
,
1933 "ipv6 ospf6 cost (1-65535)",
1937 "Outgoing metric of this interface\n")
1939 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1941 struct ospf6_interface
*oi
;
1942 unsigned long int lcost
;
1946 oi
= (struct ospf6_interface
*)ifp
->info
;
1948 oi
= ospf6_interface_create(ifp
);
1951 lcost
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
1953 if (lcost
> UINT32_MAX
) {
1954 vty_out(vty
, "Cost %ld is out of range\n", lcost
);
1955 return CMD_WARNING_CONFIG_FAILED
;
1958 SET_FLAG(oi
->flag
, OSPF6_INTERFACE_NOAUTOCOST
);
1959 if (oi
->cost
== lcost
)
1963 ospf6_interface_force_recalculate_cost(oi
);
1968 DEFUN (no_ipv6_ospf6_cost
,
1969 no_ipv6_ospf6_cost_cmd
,
1970 "no ipv6 ospf6 cost [(1-65535)]",
1974 "Calculate interface cost from bandwidth\n"
1975 "Outgoing metric of this interface\n")
1977 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1978 struct ospf6_interface
*oi
;
1981 oi
= (struct ospf6_interface
*)ifp
->info
;
1983 oi
= ospf6_interface_create(ifp
);
1986 UNSET_FLAG(oi
->flag
, OSPF6_INTERFACE_NOAUTOCOST
);
1988 ospf6_interface_recalculate_cost(oi
);
1993 DEFUN (auto_cost_reference_bandwidth
,
1994 auto_cost_reference_bandwidth_cmd
,
1995 "auto-cost reference-bandwidth (1-4294967)",
1996 "Calculate OSPF interface cost according to bandwidth\n"
1997 "Use reference bandwidth method to assign OSPF cost\n"
1998 "The reference bandwidth in terms of Mbits per second\n")
2000 VTY_DECLVAR_CONTEXT(ospf6
, o
);
2002 struct ospf6_area
*oa
;
2003 struct ospf6_interface
*oi
;
2004 struct listnode
*i
, *j
;
2007 refbw
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2008 if (refbw
< 1 || refbw
> 4294967) {
2009 vty_out(vty
, "reference-bandwidth value is invalid\n");
2010 return CMD_WARNING_CONFIG_FAILED
;
2013 /* If reference bandwidth is changed. */
2014 if ((refbw
) == o
->ref_bandwidth
)
2017 o
->ref_bandwidth
= refbw
;
2018 for (ALL_LIST_ELEMENTS_RO(o
->area_list
, i
, oa
))
2019 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
2020 ospf6_interface_recalculate_cost(oi
);
2025 DEFUN (no_auto_cost_reference_bandwidth
,
2026 no_auto_cost_reference_bandwidth_cmd
,
2027 "no auto-cost reference-bandwidth [(1-4294967)]",
2029 "Calculate OSPF interface cost according to bandwidth\n"
2030 "Use reference bandwidth method to assign OSPF cost\n"
2031 "The reference bandwidth in terms of Mbits per second\n")
2033 VTY_DECLVAR_CONTEXT(ospf6
, o
);
2034 struct ospf6_area
*oa
;
2035 struct ospf6_interface
*oi
;
2036 struct listnode
*i
, *j
;
2038 if (o
->ref_bandwidth
== OSPF6_REFERENCE_BANDWIDTH
)
2041 o
->ref_bandwidth
= OSPF6_REFERENCE_BANDWIDTH
;
2042 for (ALL_LIST_ELEMENTS_RO(o
->area_list
, i
, oa
))
2043 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
2044 ospf6_interface_recalculate_cost(oi
);
2050 DEFUN (ospf6_write_multiplier
,
2051 ospf6_write_multiplier_cmd
,
2052 "write-multiplier (1-100)",
2053 "Write multiplier\n"
2054 "Maximum number of interface serviced per write\n")
2056 VTY_DECLVAR_CONTEXT(ospf6
, o
);
2057 uint32_t write_oi_count
;
2059 write_oi_count
= strtol(argv
[1]->arg
, NULL
, 10);
2060 if (write_oi_count
< 1 || write_oi_count
> 100) {
2061 vty_out(vty
, "write-multiplier value is invalid\n");
2062 return CMD_WARNING_CONFIG_FAILED
;
2065 o
->write_oi_count
= write_oi_count
;
2069 DEFUN (no_ospf6_write_multiplier
,
2070 no_ospf6_write_multiplier_cmd
,
2071 "no write-multiplier (1-100)",
2073 "Write multiplier\n"
2074 "Maximum number of interface serviced per write\n")
2076 VTY_DECLVAR_CONTEXT(ospf6
, o
);
2078 o
->write_oi_count
= OSPF6_WRITE_INTERFACE_COUNT_DEFAULT
;
2082 DEFUN (ipv6_ospf6_hellointerval
,
2083 ipv6_ospf6_hellointerval_cmd
,
2084 "ipv6 ospf6 hello-interval (1-65535)",
2087 "Time between HELLO packets\n"
2090 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2092 struct ospf6_interface
*oi
;
2095 oi
= (struct ospf6_interface
*)ifp
->info
;
2097 oi
= ospf6_interface_create(ifp
);
2100 oi
->hello_interval
= strmatch(argv
[0]->text
, "no")
2101 ? OSPF_HELLO_INTERVAL_DEFAULT
2102 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2105 * If the thread is scheduled, send the new hello now.
2107 if (thread_is_scheduled(oi
->thread_send_hello
)) {
2108 THREAD_OFF(oi
->thread_send_hello
);
2110 thread_add_timer(master
, ospf6_hello_send
, oi
, 0,
2111 &oi
->thread_send_hello
);
2116 ALIAS (ipv6_ospf6_hellointerval
,
2117 no_ipv6_ospf6_hellointerval_cmd
,
2118 "no ipv6 ospf6 hello-interval [(1-65535)]",
2122 "Time between HELLO packets\n"
2125 /* interface variable set command */
2126 DEFUN (ipv6_ospf6_deadinterval
,
2127 ipv6_ospf6_deadinterval_cmd
,
2128 "ipv6 ospf6 dead-interval (1-65535)",
2131 "Interval time after which a neighbor is declared down\n"
2134 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2136 struct ospf6_interface
*oi
;
2139 oi
= (struct ospf6_interface
*)ifp
->info
;
2141 oi
= ospf6_interface_create(ifp
);
2144 oi
->dead_interval
= strmatch(argv
[0]->arg
, "no")
2145 ? OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
2146 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2150 ALIAS (ipv6_ospf6_deadinterval
,
2151 no_ipv6_ospf6_deadinterval_cmd
,
2152 "no ipv6 ospf6 dead-interval [(1-65535)]",
2156 "Interval time after which a neighbor is declared down\n"
2159 /* interface variable set command */
2160 DEFUN (ipv6_ospf6_transmitdelay
,
2161 ipv6_ospf6_transmitdelay_cmd
,
2162 "ipv6 ospf6 transmit-delay (1-3600)",
2165 "Link state transmit delay\n"
2168 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2170 struct ospf6_interface
*oi
;
2173 oi
= (struct ospf6_interface
*)ifp
->info
;
2175 oi
= ospf6_interface_create(ifp
);
2178 oi
->transdelay
= strmatch(argv
[0]->text
, "no")
2179 ? OSPF6_INTERFACE_TRANSDELAY
2180 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2184 ALIAS (ipv6_ospf6_transmitdelay
,
2185 no_ipv6_ospf6_transmitdelay_cmd
,
2186 "no ipv6 ospf6 transmit-delay [(1-3600)]",
2190 "Link state transmit delay\n"
2193 /* interface variable set command */
2194 DEFUN (ipv6_ospf6_retransmitinterval
,
2195 ipv6_ospf6_retransmitinterval_cmd
,
2196 "ipv6 ospf6 retransmit-interval (1-65535)",
2199 "Time between retransmitting lost link state advertisements\n"
2202 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2204 struct ospf6_interface
*oi
;
2207 oi
= (struct ospf6_interface
*)ifp
->info
;
2209 oi
= ospf6_interface_create(ifp
);
2212 oi
->rxmt_interval
= strmatch(argv
[0]->text
, "no")
2213 ? OSPF_RETRANSMIT_INTERVAL_DEFAULT
2214 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2218 ALIAS (ipv6_ospf6_retransmitinterval
,
2219 no_ipv6_ospf6_retransmitinterval_cmd
,
2220 "no ipv6 ospf6 retransmit-interval [(1-65535)]",
2224 "Time between retransmitting lost link state advertisements\n"
2227 /* interface variable set command */
2228 DEFUN (ipv6_ospf6_priority
,
2229 ipv6_ospf6_priority_cmd
,
2230 "ipv6 ospf6 priority (0-255)",
2236 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2238 struct ospf6_interface
*oi
;
2241 oi
= (struct ospf6_interface
*)ifp
->info
;
2243 oi
= ospf6_interface_create(ifp
);
2246 oi
->priority
= strmatch(argv
[0]->text
, "no")
2247 ? OSPF6_INTERFACE_PRIORITY
2248 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2251 && (oi
->state
== OSPF6_INTERFACE_DROTHER
2252 || oi
->state
== OSPF6_INTERFACE_BDR
2253 || oi
->state
== OSPF6_INTERFACE_DR
)) {
2254 if (ospf6_interface_state_change(dr_election(oi
), oi
) == -1)
2255 OSPF6_LINK_LSA_SCHEDULE(oi
);
2261 ALIAS (ipv6_ospf6_priority
,
2262 no_ipv6_ospf6_priority_cmd
,
2263 "no ipv6 ospf6 priority [(0-255)]",
2270 DEFUN (ipv6_ospf6_instance
,
2271 ipv6_ospf6_instance_cmd
,
2272 "ipv6 ospf6 instance-id (0-255)",
2275 "Instance ID for this interface\n"
2276 "Instance ID value\n")
2278 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2280 struct ospf6_interface
*oi
;
2283 oi
= (struct ospf6_interface
*)ifp
->info
;
2285 oi
= ospf6_interface_create(ifp
);
2288 oi
->instance_id
= strmatch(argv
[0]->text
, "no")
2289 ? OSPF6_INTERFACE_INSTANCE_ID
2290 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2294 ALIAS (ipv6_ospf6_instance
,
2295 no_ipv6_ospf6_instance_cmd
,
2296 "no ipv6 ospf6 instance-id [(0-255)]",
2300 "Instance ID for this interface\n"
2301 "Instance ID value\n")
2303 DEFUN (ipv6_ospf6_passive
,
2304 ipv6_ospf6_passive_cmd
,
2305 "ipv6 ospf6 passive",
2308 "Passive interface; no adjacency will be formed on this interface\n"
2311 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2312 struct ospf6_interface
*oi
;
2313 struct listnode
*node
, *nnode
;
2314 struct ospf6_neighbor
*on
;
2318 oi
= (struct ospf6_interface
*)ifp
->info
;
2320 oi
= ospf6_interface_create(ifp
);
2323 SET_FLAG(oi
->flag
, OSPF6_INTERFACE_PASSIVE
);
2324 THREAD_OFF(oi
->thread_send_hello
);
2325 THREAD_OFF(oi
->thread_sso
);
2327 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
)) {
2328 THREAD_OFF(on
->inactivity_timer
);
2329 thread_add_event(master
, inactivity_timer
, on
, 0, NULL
);
2335 DEFUN (no_ipv6_ospf6_passive
,
2336 no_ipv6_ospf6_passive_cmd
,
2337 "no ipv6 ospf6 passive",
2341 "passive interface: No Adjacency will be formed on this I/F\n"
2344 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2345 struct ospf6_interface
*oi
;
2348 oi
= (struct ospf6_interface
*)ifp
->info
;
2350 oi
= ospf6_interface_create(ifp
);
2353 UNSET_FLAG(oi
->flag
, OSPF6_INTERFACE_PASSIVE
);
2354 THREAD_OFF(oi
->thread_send_hello
);
2355 THREAD_OFF(oi
->thread_sso
);
2357 /* don't send hellos over loopback interface */
2358 if (!if_is_loopback(oi
->interface
))
2359 thread_add_timer(master
, ospf6_hello_send
, oi
, 0,
2360 &oi
->thread_send_hello
);
2365 DEFUN (ipv6_ospf6_mtu_ignore
,
2366 ipv6_ospf6_mtu_ignore_cmd
,
2367 "ipv6 ospf6 mtu-ignore",
2370 "Disable MTU mismatch detection on this interface\n"
2373 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2374 struct ospf6_interface
*oi
;
2377 oi
= (struct ospf6_interface
*)ifp
->info
;
2379 oi
= ospf6_interface_create(ifp
);
2387 DEFUN (no_ipv6_ospf6_mtu_ignore
,
2388 no_ipv6_ospf6_mtu_ignore_cmd
,
2389 "no ipv6 ospf6 mtu-ignore",
2393 "Disable MTU mismatch detection on this interface\n"
2396 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2397 struct ospf6_interface
*oi
;
2400 oi
= (struct ospf6_interface
*)ifp
->info
;
2402 oi
= ospf6_interface_create(ifp
);
2410 DEFUN (ipv6_ospf6_advertise_prefix_list
,
2411 ipv6_ospf6_advertise_prefix_list_cmd
,
2412 "ipv6 ospf6 advertise prefix-list WORD",
2415 "Advertising options\n"
2416 "Filter prefix using prefix-list\n"
2417 "Prefix list name\n"
2420 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2422 struct ospf6_interface
*oi
;
2425 oi
= (struct ospf6_interface
*)ifp
->info
;
2427 oi
= ospf6_interface_create(ifp
);
2431 XFREE(MTYPE_CFG_PLIST_NAME
, oi
->plist_name
);
2432 oi
->plist_name
= XSTRDUP(MTYPE_CFG_PLIST_NAME
, argv
[idx_word
]->arg
);
2434 ospf6_interface_connected_route_update(oi
->interface
);
2437 OSPF6_LINK_LSA_SCHEDULE(oi
);
2438 if (oi
->state
== OSPF6_INTERFACE_DR
) {
2439 OSPF6_NETWORK_LSA_SCHEDULE(oi
);
2440 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
2442 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
2448 DEFUN (no_ipv6_ospf6_advertise_prefix_list
,
2449 no_ipv6_ospf6_advertise_prefix_list_cmd
,
2450 "no ipv6 ospf6 advertise prefix-list [WORD]",
2454 "Advertising options\n"
2455 "Filter prefix using prefix-list\n"
2456 "Prefix list name\n")
2458 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2459 struct ospf6_interface
*oi
;
2462 oi
= (struct ospf6_interface
*)ifp
->info
;
2464 oi
= ospf6_interface_create(ifp
);
2468 XFREE(MTYPE_CFG_PLIST_NAME
, oi
->plist_name
);
2470 ospf6_interface_connected_route_update(oi
->interface
);
2473 OSPF6_LINK_LSA_SCHEDULE(oi
);
2474 if (oi
->state
== OSPF6_INTERFACE_DR
) {
2475 OSPF6_NETWORK_LSA_SCHEDULE(oi
);
2476 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
2478 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
2484 DEFUN (ipv6_ospf6_network
,
2485 ipv6_ospf6_network_cmd
,
2486 "ipv6 ospf6 network <broadcast|point-to-point>",
2490 "Specify OSPF6 broadcast network\n"
2491 "Specify OSPF6 point-to-point network\n"
2494 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2495 int idx_network
= 3;
2496 struct ospf6_interface
*oi
;
2499 oi
= (struct ospf6_interface
*)ifp
->info
;
2501 oi
= ospf6_interface_create(ifp
);
2505 oi
->type_cfg
= true;
2507 if (strncmp(argv
[idx_network
]->arg
, "b", 1) == 0) {
2508 if (oi
->type
== OSPF_IFTYPE_BROADCAST
)
2511 oi
->type
= OSPF_IFTYPE_BROADCAST
;
2512 } else if (strncmp(argv
[idx_network
]->arg
, "point-to-p", 10) == 0) {
2513 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
) {
2516 oi
->type
= OSPF_IFTYPE_POINTOPOINT
;
2519 /* Reset the interface */
2520 thread_execute(master
, interface_down
, oi
, 0);
2521 thread_execute(master
, interface_up
, oi
, 0);
2526 DEFUN (no_ipv6_ospf6_network
,
2527 no_ipv6_ospf6_network_cmd
,
2528 "no ipv6 ospf6 network [<broadcast|point-to-point>]",
2532 "Set default network type\n"
2533 "Specify OSPF6 broadcast network\n"
2534 "Specify OSPF6 point-to-point network\n")
2536 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2537 struct ospf6_interface
*oi
;
2542 oi
= (struct ospf6_interface
*)ifp
->info
;
2547 oi
->type_cfg
= false;
2549 type
= ospf6_default_iftype(ifp
);
2550 if (oi
->type
== type
) {
2555 /* Reset the interface */
2556 thread_execute(master
, interface_down
, oi
, 0);
2557 thread_execute(master
, interface_up
, oi
, 0);
2562 static int config_write_ospf6_interface(struct vty
*vty
, struct vrf
*vrf
)
2564 struct ospf6_interface
*oi
;
2565 struct interface
*ifp
;
2566 char buf
[INET_ADDRSTRLEN
];
2568 FOR_ALL_INTERFACES (vrf
, ifp
) {
2569 oi
= (struct ospf6_interface
*)ifp
->info
;
2573 if_vty_config_start(vty
, ifp
);
2576 vty_out(vty
, " description %s\n", ifp
->desc
);
2577 if (oi
->area_id_format
!= OSPF6_AREA_FMT_UNSET
) {
2578 area_id2str(buf
, sizeof(buf
), oi
->area_id
,
2579 oi
->area_id_format
);
2580 vty_out(vty
, " ipv6 ospf6 area %s\n", buf
);
2583 vty_out(vty
, " ipv6 ospf6 ifmtu %d\n", oi
->c_ifmtu
);
2585 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_NOAUTOCOST
))
2586 vty_out(vty
, " ipv6 ospf6 cost %d\n", oi
->cost
);
2588 if (oi
->hello_interval
!= OSPF6_INTERFACE_HELLO_INTERVAL
)
2589 vty_out(vty
, " ipv6 ospf6 hello-interval %d\n",
2590 oi
->hello_interval
);
2592 if (oi
->dead_interval
!= OSPF6_INTERFACE_DEAD_INTERVAL
)
2593 vty_out(vty
, " ipv6 ospf6 dead-interval %d\n",
2596 if (oi
->rxmt_interval
!= OSPF6_INTERFACE_RXMT_INTERVAL
)
2597 vty_out(vty
, " ipv6 ospf6 retransmit-interval %d\n",
2600 if (oi
->priority
!= OSPF6_INTERFACE_PRIORITY
)
2601 vty_out(vty
, " ipv6 ospf6 priority %d\n", oi
->priority
);
2603 if (oi
->transdelay
!= OSPF6_INTERFACE_TRANSDELAY
)
2604 vty_out(vty
, " ipv6 ospf6 transmit-delay %d\n",
2607 if (oi
->instance_id
!= OSPF6_INTERFACE_INSTANCE_ID
)
2608 vty_out(vty
, " ipv6 ospf6 instance-id %d\n",
2612 vty_out(vty
, " ipv6 ospf6 advertise prefix-list %s\n",
2615 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_PASSIVE
))
2616 vty_out(vty
, " ipv6 ospf6 passive\n");
2619 vty_out(vty
, " ipv6 ospf6 mtu-ignore\n");
2621 if (oi
->type_cfg
&& oi
->type
== OSPF_IFTYPE_POINTOPOINT
)
2622 vty_out(vty
, " ipv6 ospf6 network point-to-point\n");
2623 else if (oi
->type_cfg
&& oi
->type
== OSPF_IFTYPE_BROADCAST
)
2624 vty_out(vty
, " ipv6 ospf6 network broadcast\n");
2626 ospf6_bfd_write_config(vty
, oi
);
2628 ospf6_auth_write_config(vty
, &oi
->at_data
);
2629 if_vty_config_end(vty
);
2634 /* Configuration write function for ospfd. */
2635 static int config_write_interface(struct vty
*vty
)
2638 struct vrf
*vrf
= NULL
;
2640 /* Display all VRF aware OSPF interface configuration */
2641 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
2642 write
+= config_write_ospf6_interface(vty
, vrf
);
2648 static int ospf6_ifp_create(struct interface
*ifp
)
2650 if (IS_OSPF6_DEBUG_ZEBRA(RECV
))
2651 zlog_debug("Zebra Interface add: %s index %d mtu %d", ifp
->name
,
2652 ifp
->ifindex
, ifp
->mtu6
);
2655 ospf6_interface_start(ifp
->info
);
2660 static int ospf6_ifp_up(struct interface
*ifp
)
2662 if (IS_OSPF6_DEBUG_ZEBRA(RECV
))
2664 "Zebra Interface state change: %s index %d flags %llx metric %d mtu %d bandwidth %d",
2665 ifp
->name
, ifp
->ifindex
, (unsigned long long)ifp
->flags
,
2666 ifp
->metric
, ifp
->mtu6
, ifp
->bandwidth
);
2668 ospf6_interface_state_update(ifp
);
2673 static int ospf6_ifp_down(struct interface
*ifp
)
2675 if (IS_OSPF6_DEBUG_ZEBRA(RECV
))
2677 "Zebra Interface state change: %s index %d flags %llx metric %d mtu %d bandwidth %d",
2678 ifp
->name
, ifp
->ifindex
, (unsigned long long)ifp
->flags
,
2679 ifp
->metric
, ifp
->mtu6
, ifp
->bandwidth
);
2681 ospf6_interface_state_update(ifp
);
2686 static int ospf6_ifp_destroy(struct interface
*ifp
)
2689 zlog_warn("Zebra: got delete of %s, but interface is still up",
2692 if (IS_OSPF6_DEBUG_ZEBRA(RECV
))
2693 zlog_debug("Zebra Interface delete: %s index %d mtu %d",
2694 ifp
->name
, ifp
->ifindex
, ifp
->mtu6
);
2697 ospf6_interface_stop(ifp
->info
);
2702 void ospf6_interface_init(void)
2704 /* Install interface node. */
2705 if_cmd_init(config_write_interface
);
2706 if_zapi_callbacks(ospf6_ifp_create
, ospf6_ifp_up
,
2707 ospf6_ifp_down
, ospf6_ifp_destroy
);
2709 install_element(VIEW_NODE
, &show_ipv6_ospf6_interface_prefix_cmd
);
2710 install_element(VIEW_NODE
, &show_ipv6_ospf6_interface_ifname_cmd
);
2711 install_element(VIEW_NODE
,
2712 &show_ipv6_ospf6_interface_ifname_prefix_cmd
);
2713 install_element(VIEW_NODE
, &show_ipv6_ospf6_interface_traffic_cmd
);
2715 install_element(INTERFACE_NODE
, &ipv6_ospf6_area_cmd
);
2716 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_area_cmd
);
2717 install_element(INTERFACE_NODE
, &ipv6_ospf6_cost_cmd
);
2718 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_cost_cmd
);
2719 install_element(INTERFACE_NODE
, &ipv6_ospf6_ifmtu_cmd
);
2720 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_ifmtu_cmd
);
2722 install_element(INTERFACE_NODE
, &ipv6_ospf6_deadinterval_cmd
);
2723 install_element(INTERFACE_NODE
, &ipv6_ospf6_hellointerval_cmd
);
2724 install_element(INTERFACE_NODE
, &ipv6_ospf6_priority_cmd
);
2725 install_element(INTERFACE_NODE
, &ipv6_ospf6_retransmitinterval_cmd
);
2726 install_element(INTERFACE_NODE
, &ipv6_ospf6_transmitdelay_cmd
);
2727 install_element(INTERFACE_NODE
, &ipv6_ospf6_instance_cmd
);
2728 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_deadinterval_cmd
);
2729 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_hellointerval_cmd
);
2730 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_priority_cmd
);
2731 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_retransmitinterval_cmd
);
2732 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_transmitdelay_cmd
);
2733 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_instance_cmd
);
2735 install_element(INTERFACE_NODE
, &ipv6_ospf6_passive_cmd
);
2736 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_passive_cmd
);
2738 install_element(INTERFACE_NODE
, &ipv6_ospf6_mtu_ignore_cmd
);
2739 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_mtu_ignore_cmd
);
2741 install_element(INTERFACE_NODE
, &ipv6_ospf6_advertise_prefix_list_cmd
);
2742 install_element(INTERFACE_NODE
,
2743 &no_ipv6_ospf6_advertise_prefix_list_cmd
);
2745 install_element(INTERFACE_NODE
, &ipv6_ospf6_network_cmd
);
2746 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_network_cmd
);
2748 /* reference bandwidth commands */
2749 install_element(OSPF6_NODE
, &auto_cost_reference_bandwidth_cmd
);
2750 install_element(OSPF6_NODE
, &no_auto_cost_reference_bandwidth_cmd
);
2751 /* write-multiplier commands */
2752 install_element(OSPF6_NODE
, &ospf6_write_multiplier_cmd
);
2753 install_element(OSPF6_NODE
, &no_ospf6_write_multiplier_cmd
);
2756 /* Clear the specified interface structure */
2757 void ospf6_interface_clear(struct interface
*ifp
)
2759 struct ospf6_interface
*oi
;
2761 if (!if_is_operative(ifp
))
2764 if (ifp
->info
== NULL
)
2767 oi
= (struct ospf6_interface
*)ifp
->info
;
2769 if (IS_OSPF6_DEBUG_INTERFACE
)
2770 zlog_debug("Interface %s: clear by reset", ifp
->name
);
2772 /* Reset the interface */
2773 thread_execute(master
, interface_down
, oi
, 0);
2774 thread_execute(master
, interface_up
, oi
, 0);
2777 /* Clear interface */
2778 DEFUN (clear_ipv6_ospf6_interface
,
2779 clear_ipv6_ospf6_interface_cmd
,
2780 "clear ipv6 ospf6 [vrf NAME] interface [IFNAME]",
2792 struct interface
*ifp
;
2793 const char *vrf_name
;
2795 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
2796 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
2798 vrf_name
= VRF_DEFAULT_NAME
;
2799 vrf
= vrf_lookup_by_name(vrf_name
);
2801 vty_out(vty
, "%% VRF %s not found\n", vrf_name
);
2805 if (!argv_find(argv
, argc
, "IFNAME", &idx_ifname
)) {
2806 /* Clear all the ospfv3 interfaces. */
2807 FOR_ALL_INTERFACES (vrf
, ifp
)
2808 ospf6_interface_clear(ifp
);
2810 /* Interface name is specified. */
2811 ifp
= if_lookup_by_name_vrf(argv
[idx_ifname
]->arg
, vrf
);
2813 vty_out(vty
, "No such Interface: %s\n",
2814 argv
[idx_ifname
]->arg
);
2817 ospf6_interface_clear(ifp
);
2823 void install_element_ospf6_clear_interface(void)
2825 install_element(ENABLE_NODE
, &clear_ipv6_ospf6_interface_cmd
);
2828 DEFUN (debug_ospf6_interface
,
2829 debug_ospf6_interface_cmd
,
2830 "debug ospf6 interface",
2833 "Debug OSPFv3 Interface\n"
2836 OSPF6_DEBUG_INTERFACE_ON();
2840 DEFUN (no_debug_ospf6_interface
,
2841 no_debug_ospf6_interface_cmd
,
2842 "no debug ospf6 interface",
2846 "Debug OSPFv3 Interface\n"
2849 OSPF6_DEBUG_INTERFACE_OFF();
2853 int config_write_ospf6_debug_interface(struct vty
*vty
)
2855 if (IS_OSPF6_DEBUG_INTERFACE
)
2856 vty_out(vty
, "debug ospf6 interface\n");
2860 void install_element_ospf6_debug_interface(void)
2862 install_element(ENABLE_NODE
, &debug_ospf6_interface_cmd
);
2863 install_element(ENABLE_NODE
, &no_debug_ospf6_interface_cmd
);
2864 install_element(CONFIG_NODE
, &debug_ospf6_interface_cmd
);
2865 install_element(CONFIG_NODE
, &no_debug_ospf6_interface_cmd
);
2868 void ospf6_auth_write_config(struct vty
*vty
, struct ospf6_auth_data
*at_data
)
2870 if (CHECK_FLAG(at_data
->flags
, OSPF6_AUTH_TRAILER_KEYCHAIN
))
2871 vty_out(vty
, " ipv6 ospf6 authentication keychain %s\n",
2873 else if (CHECK_FLAG(at_data
->flags
, OSPF6_AUTH_TRAILER_MANUAL_KEY
))
2875 " ipv6 ospf6 authentication key-id %d hash-algo %s key %s\n",
2877 keychain_get_algo_name_by_id(at_data
->hash_algo
),
2881 DEFUN(ipv6_ospf6_intf_auth_trailer_keychain
,
2882 ipv6_ospf6_intf_auth_trailer_keychain_cmd
,
2883 "ipv6 ospf6 authentication keychain KEYCHAIN_NAME",
2885 "Enable authentication on this interface\n"
2889 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2890 int keychain_idx
= 4;
2891 struct ospf6_interface
*oi
;
2893 oi
= (struct ospf6_interface
*)ifp
->info
;
2895 oi
= ospf6_interface_create(ifp
);
2898 if (CHECK_FLAG(oi
->at_data
.flags
, OSPF6_AUTH_TRAILER_MANUAL_KEY
)) {
2900 "Manual key configured, unconfigure it before configuring key chain\n");
2901 return CMD_WARNING_CONFIG_FAILED
;
2904 SET_FLAG(oi
->at_data
.flags
, OSPF6_AUTH_TRAILER_KEYCHAIN
);
2905 if (oi
->at_data
.keychain
)
2906 XFREE(MTYPE_OSPF6_AUTH_KEYCHAIN
, oi
->at_data
.keychain
);
2908 oi
->at_data
.keychain
=
2909 XSTRDUP(MTYPE_OSPF6_AUTH_KEYCHAIN
, argv
[keychain_idx
]->arg
);
2914 DEFUN(no_ipv6_ospf6_intf_auth_trailer_keychain
,
2915 no_ipv6_ospf6_intf_auth_trailer_keychain_cmd
,
2916 "no ipv6 ospf6 authentication keychain [KEYCHAIN_NAME]",
2917 NO_STR IP6_STR OSPF6_STR
2918 "Enable authentication on this interface\n"
2922 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2923 struct ospf6_interface
*oi
;
2925 oi
= (struct ospf6_interface
*)ifp
->info
;
2927 oi
= ospf6_interface_create(ifp
);
2930 if (!CHECK_FLAG(oi
->at_data
.flags
, OSPF6_AUTH_TRAILER_KEYCHAIN
))
2933 if (oi
->at_data
.keychain
) {
2934 oi
->at_data
.flags
= 0;
2935 XFREE(MTYPE_OSPF6_AUTH_KEYCHAIN
, oi
->at_data
.keychain
);
2936 oi
->at_data
.keychain
= NULL
;
2942 DEFUN(ipv6_ospf6_intf_auth_trailer_key
, ipv6_ospf6_intf_auth_trailer_key_cmd
,
2943 "ipv6 ospf6 authentication key-id (1-65535) hash-algo "
2944 "<md5|hmac-sha-1|hmac-sha-256|hmac-sha-384|hmac-sha-512> "
2950 "Cryptographic-algorithm\n"
2951 "Use MD5 algorithm\n"
2952 "Use HMAC-SHA-1 algorithm\n"
2953 "Use HMAC-SHA-256 algorithm\n"
2954 "Use HMAC-SHA-384 algorithm\n"
2955 "Use HMAC-SHA-512 algorithm\n"
2957 "Password string (key)\n")
2959 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2961 int hash_algo_idx
= 6;
2962 int password_idx
= 8;
2963 struct ospf6_interface
*oi
;
2964 uint8_t hash_algo
= KEYCHAIN_ALGO_NULL
;
2966 oi
= (struct ospf6_interface
*)ifp
->info
;
2968 oi
= ospf6_interface_create(ifp
);
2971 if (CHECK_FLAG(oi
->at_data
.flags
, OSPF6_AUTH_TRAILER_KEYCHAIN
)) {
2973 "key chain configured, unconfigure it before configuring manual key\n");
2974 return CMD_WARNING_CONFIG_FAILED
;
2977 hash_algo
= keychain_get_algo_id_by_name(argv
[hash_algo_idx
]->arg
);
2978 #ifndef CRYPTO_OPENSSL
2979 if (hash_algo
== KEYCHAIN_ALGO_NULL
) {
2981 "Hash algorithm not supported, compile with --with-crypto=openssl\n");
2982 return CMD_WARNING_CONFIG_FAILED
;
2984 #endif /* CRYPTO_OPENSSL */
2986 SET_FLAG(oi
->at_data
.flags
, OSPF6_AUTH_TRAILER_MANUAL_KEY
);
2987 oi
->at_data
.hash_algo
= hash_algo
;
2988 oi
->at_data
.key_id
= (uint16_t)strtol(argv
[key_id_idx
]->arg
, NULL
, 10);
2989 if (oi
->at_data
.auth_key
)
2990 XFREE(MTYPE_OSPF6_AUTH_MANUAL_KEY
, oi
->at_data
.auth_key
);
2991 oi
->at_data
.auth_key
=
2992 XSTRDUP(MTYPE_OSPF6_AUTH_MANUAL_KEY
, argv
[password_idx
]->arg
);
2997 DEFUN(no_ipv6_ospf6_intf_auth_trailer_key
,
2998 no_ipv6_ospf6_intf_auth_trailer_key_cmd
,
2999 "no ipv6 ospf6 authentication key-id [(1-65535) hash-algo "
3000 "<md5|hmac-sha-1|hmac-sha-256|hmac-sha-384|hmac-sha-512> "
3002 NO_STR IP6_STR OSPF6_STR
3006 "Cryptographic-algorithm\n"
3007 "Use MD5 algorithm\n"
3008 "Use HMAC-SHA-1 algorithm\n"
3009 "Use HMAC-SHA-256 algorithm\n"
3010 "Use HMAC-SHA-384 algorithm\n"
3011 "Use HMAC-SHA-512 algorithm\n"
3013 "Password string (key)\n")
3015 VTY_DECLVAR_CONTEXT(interface
, ifp
);
3016 struct ospf6_interface
*oi
;
3017 #ifndef CRYPTO_OPENSSL
3018 int hash_algo_idx
= 7;
3019 uint8_t hash_algo
= KEYCHAIN_ALGO_NULL
;
3020 #endif /* CRYPTO_OPENSSL */
3022 oi
= (struct ospf6_interface
*)ifp
->info
;
3024 oi
= ospf6_interface_create(ifp
);
3027 if (!CHECK_FLAG(oi
->at_data
.flags
, OSPF6_AUTH_TRAILER_MANUAL_KEY
))
3030 #ifndef CRYPTO_OPENSSL
3031 hash_algo
= keychain_get_algo_id_by_name(argv
[hash_algo_idx
]->arg
);
3032 if (hash_algo
== KEYCHAIN_ALGO_NULL
) {
3034 "Hash algorithm not supported, compile with --with-crypto=openssl\n");
3035 return CMD_WARNING_CONFIG_FAILED
;
3037 #endif /* CRYPTO_OPENSSL */
3039 if (oi
->at_data
.auth_key
) {
3040 oi
->at_data
.flags
= 0;
3041 XFREE(MTYPE_OSPF6_AUTH_MANUAL_KEY
, oi
->at_data
.auth_key
);
3042 oi
->at_data
.auth_key
= NULL
;
3048 void ospf6_interface_auth_trailer_cmd_init(void)
3050 /*Install OSPF6 auth trailer commands at interface level */
3051 install_element(INTERFACE_NODE
,
3052 &ipv6_ospf6_intf_auth_trailer_keychain_cmd
);
3053 install_element(INTERFACE_NODE
,
3054 &no_ipv6_ospf6_intf_auth_trailer_keychain_cmd
);
3055 install_element(INTERFACE_NODE
, &ipv6_ospf6_intf_auth_trailer_key_cmd
);
3056 install_element(INTERFACE_NODE
,
3057 &no_ipv6_ospf6_intf_auth_trailer_key_cmd
);