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);
168 else if (cost
> UINT32_MAX
)
175 static void ospf6_interface_force_recalculate_cost(struct ospf6_interface
*oi
)
177 /* update cost held in route_connected list in ospf6_interface */
178 ospf6_interface_connected_route_update(oi
->interface
);
180 /* execute LSA hooks */
182 OSPF6_LINK_LSA_SCHEDULE(oi
);
183 OSPF6_ROUTER_LSA_SCHEDULE(oi
->area
);
184 OSPF6_NETWORK_LSA_SCHEDULE(oi
);
185 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
186 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
190 static void ospf6_interface_recalculate_cost(struct ospf6_interface
*oi
)
194 newcost
= ospf6_interface_get_cost(oi
);
195 if (newcost
== oi
->cost
)
199 ospf6_interface_force_recalculate_cost(oi
);
202 /* Create new ospf6 interface structure */
203 struct ospf6_interface
*ospf6_interface_create(struct interface
*ifp
)
205 struct ospf6_interface
*oi
;
206 unsigned int iobuflen
;
208 oi
= XCALLOC(MTYPE_OSPF6_IF
, sizeof(struct ospf6_interface
));
210 oi
->obuf
= ospf6_fifo_new();
212 oi
->area
= (struct ospf6_area
*)NULL
;
213 oi
->neighbor_list
= list_new();
214 oi
->neighbor_list
->cmp
= ospf6_neighbor_cmp
;
215 oi
->linklocal_addr
= (struct in6_addr
*)NULL
;
216 oi
->instance_id
= OSPF6_INTERFACE_INSTANCE_ID
;
217 oi
->transdelay
= OSPF6_INTERFACE_TRANSDELAY
;
218 oi
->priority
= OSPF6_INTERFACE_PRIORITY
;
220 oi
->hello_interval
= OSPF_HELLO_INTERVAL_DEFAULT
;
221 oi
->dead_interval
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
222 oi
->rxmt_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
223 oi
->type
= ospf6_default_iftype(ifp
);
224 oi
->state
= OSPF6_INTERFACE_DOWN
;
229 /* Try to adjust I/O buffer size with IfMtu */
230 oi
->ifmtu
= ifp
->mtu6
;
231 iobuflen
= ospf6_iobuf_size(ifp
->mtu6
);
232 if (oi
->ifmtu
> iobuflen
) {
233 if (IS_OSPF6_DEBUG_INTERFACE
)
235 "Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
236 ifp
->name
, iobuflen
);
237 oi
->ifmtu
= iobuflen
;
240 QOBJ_REG(oi
, ospf6_interface
);
242 oi
->lsupdate_list
= ospf6_lsdb_create(oi
);
243 oi
->lsack_list
= ospf6_lsdb_create(oi
);
244 oi
->lsdb
= ospf6_lsdb_create(oi
);
245 oi
->lsdb
->hook_add
= ospf6_interface_lsdb_hook_add
;
246 oi
->lsdb
->hook_remove
= ospf6_interface_lsdb_hook_remove
;
247 oi
->lsdb_self
= ospf6_lsdb_create(oi
);
249 oi
->route_connected
=
250 OSPF6_ROUTE_TABLE_CREATE(INTERFACE
, CONNECTED_ROUTES
);
251 oi
->route_connected
->scope
= oi
;
258 oi
->cost
= ospf6_interface_get_cost(oi
);
260 oi
->at_data
.flags
= 0;
265 void ospf6_interface_delete(struct ospf6_interface
*oi
)
267 struct listnode
*node
, *nnode
;
268 struct ospf6_neighbor
*on
;
272 ospf6_fifo_free(oi
->obuf
);
274 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
))
275 ospf6_neighbor_delete(on
);
277 list_delete(&oi
->neighbor_list
);
279 THREAD_OFF(oi
->thread_send_hello
);
280 THREAD_OFF(oi
->thread_send_lsupdate
);
281 THREAD_OFF(oi
->thread_send_lsack
);
282 THREAD_OFF(oi
->thread_sso
);
283 THREAD_OFF(oi
->thread_wait_timer
);
285 ospf6_lsdb_remove_all(oi
->lsdb
);
286 ospf6_lsdb_remove_all(oi
->lsupdate_list
);
287 ospf6_lsdb_remove_all(oi
->lsack_list
);
289 ospf6_lsdb_delete(oi
->lsdb
);
290 ospf6_lsdb_delete(oi
->lsdb_self
);
292 ospf6_lsdb_delete(oi
->lsupdate_list
);
293 ospf6_lsdb_delete(oi
->lsack_list
);
295 ospf6_route_table_delete(oi
->route_connected
);
298 oi
->interface
->info
= NULL
;
302 XFREE(MTYPE_CFG_PLIST_NAME
, oi
->plist_name
);
304 /* disable from area list if possible */
305 ospf6_area_interface_delete(oi
);
307 /* Free BFD allocated data. */
308 XFREE(MTYPE_TMP
, oi
->bfd_config
.profile
);
310 XFREE(MTYPE_OSPF6_IF
, oi
);
313 void ospf6_interface_enable(struct ospf6_interface
*oi
)
315 UNSET_FLAG(oi
->flag
, OSPF6_INTERFACE_DISABLE
);
316 ospf6_interface_state_update(oi
->interface
);
319 void ospf6_interface_disable(struct ospf6_interface
*oi
)
321 SET_FLAG(oi
->flag
, OSPF6_INTERFACE_DISABLE
);
323 thread_execute(master
, interface_down
, oi
, 0);
325 ospf6_lsdb_remove_all(oi
->lsdb
);
326 ospf6_lsdb_remove_all(oi
->lsdb_self
);
327 ospf6_lsdb_remove_all(oi
->lsupdate_list
);
328 ospf6_lsdb_remove_all(oi
->lsack_list
);
330 THREAD_OFF(oi
->thread_send_hello
);
331 THREAD_OFF(oi
->thread_send_lsupdate
);
332 THREAD_OFF(oi
->thread_send_lsack
);
333 THREAD_OFF(oi
->thread_sso
);
335 THREAD_OFF(oi
->thread_network_lsa
);
336 THREAD_OFF(oi
->thread_link_lsa
);
337 THREAD_OFF(oi
->thread_intra_prefix_lsa
);
338 THREAD_OFF(oi
->thread_as_extern_lsa
);
339 THREAD_OFF(oi
->thread_wait_timer
);
342 static struct in6_addr
*
343 ospf6_interface_get_linklocal_address(struct interface
*ifp
)
347 struct in6_addr
*l
= (struct in6_addr
*)NULL
;
349 /* for each connected address */
350 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, n
, c
)) {
351 /* if family not AF_INET6, ignore */
352 if (c
->address
->family
!= AF_INET6
)
355 /* linklocal scope check */
356 if (IN6_IS_ADDR_LINKLOCAL(&c
->address
->u
.prefix6
))
357 l
= &c
->address
->u
.prefix6
;
362 void ospf6_interface_state_update(struct interface
*ifp
)
364 struct ospf6_interface
*oi
;
365 unsigned int iobuflen
;
367 oi
= (struct ospf6_interface
*)ifp
->info
;
370 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_DISABLE
))
373 /* Adjust the mtu values if the kernel told us something new */
374 if (ifp
->mtu6
!= oi
->ifmtu
) {
375 /* If nothing configured, accept it and check for buffer size */
377 oi
->ifmtu
= ifp
->mtu6
;
378 iobuflen
= ospf6_iobuf_size(ifp
->mtu6
);
379 if (oi
->ifmtu
> iobuflen
) {
380 if (IS_OSPF6_DEBUG_INTERFACE
)
382 "Interface %s: IfMtu is adjusted to I/O buffer size: %d.",
383 ifp
->name
, iobuflen
);
384 oi
->ifmtu
= iobuflen
;
386 } else if (oi
->c_ifmtu
> ifp
->mtu6
) {
387 oi
->ifmtu
= ifp
->mtu6
;
389 "Configured mtu %u on %s overridden by kernel %u",
390 oi
->c_ifmtu
, ifp
->name
, ifp
->mtu6
);
392 oi
->ifmtu
= oi
->c_ifmtu
;
395 if (if_is_operative(ifp
)
396 && (ospf6_interface_get_linklocal_address(oi
->interface
)
397 || if_is_loopback(oi
->interface
)))
398 thread_execute(master
, interface_up
, oi
, 0);
400 thread_execute(master
, interface_down
, oi
, 0);
405 void ospf6_interface_connected_route_update(struct interface
*ifp
)
407 struct ospf6_interface
*oi
;
408 struct ospf6_route
*route
;
410 struct listnode
*node
, *nnode
;
411 struct in6_addr nh_addr
;
413 oi
= (struct ospf6_interface
*)ifp
->info
;
417 /* reset linklocal pointer */
418 oi
->linklocal_addr
= ospf6_interface_get_linklocal_address(ifp
);
420 /* if area is null, do not make connected-route list */
421 if (oi
->area
== NULL
)
424 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_DISABLE
))
427 /* update "route to advertise" interface route table */
428 ospf6_route_remove_all(oi
->route_connected
);
430 for (ALL_LIST_ELEMENTS(oi
->interface
->connected
, node
, nnode
, c
)) {
431 if (c
->address
->family
!= AF_INET6
)
434 CONTINUE_IF_ADDRESS_LINKLOCAL(IS_OSPF6_DEBUG_INTERFACE
,
436 CONTINUE_IF_ADDRESS_UNSPECIFIED(IS_OSPF6_DEBUG_INTERFACE
,
438 CONTINUE_IF_ADDRESS_LOOPBACK(IS_OSPF6_DEBUG_INTERFACE
,
440 CONTINUE_IF_ADDRESS_V4COMPAT(IS_OSPF6_DEBUG_INTERFACE
,
442 CONTINUE_IF_ADDRESS_V4MAPPED(IS_OSPF6_DEBUG_INTERFACE
,
446 if (oi
->plist_name
) {
447 struct prefix_list
*plist
;
448 enum prefix_list_type ret
;
450 plist
= prefix_list_lookup(AFI_IP6
, oi
->plist_name
);
451 ret
= prefix_list_apply(plist
, (void *)c
->address
);
452 if (ret
== PREFIX_DENY
) {
453 if (IS_OSPF6_DEBUG_INTERFACE
)
455 "%pFX on %s filtered by prefix-list %s ",
456 c
->address
, oi
->interface
->name
,
462 route
= ospf6_route_create(oi
->area
->ospf6
);
463 memcpy(&route
->prefix
, c
->address
, sizeof(struct prefix
));
464 apply_mask(&route
->prefix
);
465 route
->type
= OSPF6_DEST_TYPE_NETWORK
;
466 route
->path
.area_id
= oi
->area
->area_id
;
467 route
->path
.type
= OSPF6_PATH_TYPE_INTRA
;
468 route
->path
.cost
= oi
->cost
;
469 inet_pton(AF_INET6
, "::1", &nh_addr
);
470 ospf6_route_add_nexthop(route
, oi
->interface
->ifindex
,
472 ospf6_route_add(route
, oi
->route_connected
);
475 /* create new Link-LSA */
476 OSPF6_LINK_LSA_SCHEDULE(oi
);
477 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
478 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
481 static int ospf6_interface_state_change(uint8_t next_state
,
482 struct ospf6_interface
*oi
)
487 prev_state
= oi
->state
;
488 oi
->state
= next_state
;
490 if (prev_state
== next_state
)
497 if (IS_OSPF6_DEBUG_INTERFACE
) {
498 zlog_debug("Interface state change %s: %s -> %s",
500 ospf6_interface_state_str
[prev_state
],
501 ospf6_interface_state_str
[next_state
]);
505 ospf6
= oi
->area
->ospf6
;
507 if ((prev_state
== OSPF6_INTERFACE_DR
508 || prev_state
== OSPF6_INTERFACE_BDR
)
509 && (next_state
!= OSPF6_INTERFACE_DR
510 && next_state
!= OSPF6_INTERFACE_BDR
))
511 ospf6_sso(oi
->interface
->ifindex
, &alldrouters6
,
512 IPV6_LEAVE_GROUP
, ospf6
->fd
);
514 if ((prev_state
!= OSPF6_INTERFACE_DR
515 && prev_state
!= OSPF6_INTERFACE_BDR
)
516 && (next_state
== OSPF6_INTERFACE_DR
517 || next_state
== OSPF6_INTERFACE_BDR
))
518 ospf6_sso(oi
->interface
->ifindex
, &alldrouters6
,
519 IPV6_JOIN_GROUP
, ospf6
->fd
);
521 OSPF6_ROUTER_LSA_SCHEDULE(oi
->area
);
522 OSPF6_LINK_LSA_SCHEDULE(oi
);
523 if (next_state
== OSPF6_INTERFACE_DOWN
) {
524 OSPF6_NETWORK_LSA_EXECUTE(oi
);
525 OSPF6_INTRA_PREFIX_LSA_EXECUTE_TRANSIT(oi
);
526 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
527 OSPF6_INTRA_PREFIX_LSA_EXECUTE_TRANSIT(oi
);
528 } else if (prev_state
== OSPF6_INTERFACE_DR
529 || next_state
== OSPF6_INTERFACE_DR
) {
530 OSPF6_NETWORK_LSA_SCHEDULE(oi
);
531 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
532 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
535 hook_call(ospf6_interface_change
, oi
, next_state
, prev_state
);
541 /* DR Election, RFC2328 section 9.4 */
543 #define IS_ELIGIBLE(n) \
544 ((n)->state >= OSPF6_NEIGHBOR_TWOWAY && (n)->priority != 0)
546 static struct ospf6_neighbor
*better_bdrouter(struct ospf6_neighbor
*a
,
547 struct ospf6_neighbor
*b
)
549 if ((a
== NULL
|| !IS_ELIGIBLE(a
) || a
->drouter
== a
->router_id
)
550 && (b
== NULL
|| !IS_ELIGIBLE(b
) || b
->drouter
== b
->router_id
))
552 else if (a
== NULL
|| !IS_ELIGIBLE(a
) || a
->drouter
== a
->router_id
)
554 else if (b
== NULL
|| !IS_ELIGIBLE(b
) || b
->drouter
== b
->router_id
)
557 if (a
->bdrouter
== a
->router_id
&& b
->bdrouter
!= b
->router_id
)
559 if (a
->bdrouter
!= a
->router_id
&& b
->bdrouter
== b
->router_id
)
562 if (a
->priority
> b
->priority
)
564 if (a
->priority
< b
->priority
)
567 if (ntohl(a
->router_id
) > ntohl(b
->router_id
))
569 if (ntohl(a
->router_id
) < ntohl(b
->router_id
))
572 zlog_warn("Router-ID duplicate ?");
576 static struct ospf6_neighbor
*better_drouter(struct ospf6_neighbor
*a
,
577 struct ospf6_neighbor
*b
)
579 if ((a
== NULL
|| !IS_ELIGIBLE(a
) || a
->drouter
!= a
->router_id
)
580 && (b
== NULL
|| !IS_ELIGIBLE(b
) || b
->drouter
!= b
->router_id
))
582 else if (a
== NULL
|| !IS_ELIGIBLE(a
) || a
->drouter
!= a
->router_id
)
584 else if (b
== NULL
|| !IS_ELIGIBLE(b
) || b
->drouter
!= b
->router_id
)
587 if (a
->drouter
== a
->router_id
&& b
->drouter
!= b
->router_id
)
589 if (a
->drouter
!= a
->router_id
&& b
->drouter
== b
->router_id
)
592 if (a
->priority
> b
->priority
)
594 if (a
->priority
< b
->priority
)
597 if (ntohl(a
->router_id
) > ntohl(b
->router_id
))
599 if (ntohl(a
->router_id
) < ntohl(b
->router_id
))
602 zlog_warn("Router-ID duplicate ?");
606 uint8_t dr_election(struct ospf6_interface
*oi
)
608 struct listnode
*node
, *nnode
;
609 struct ospf6_neighbor
*on
, *drouter
, *bdrouter
, myself
;
610 struct ospf6_neighbor
*best_drouter
, *best_bdrouter
;
611 uint8_t next_state
= 0;
613 drouter
= bdrouter
= NULL
;
614 best_drouter
= best_bdrouter
= NULL
;
616 /* pseudo neighbor myself, including noting current DR/BDR (1) */
617 memset(&myself
, 0, sizeof(myself
));
618 inet_ntop(AF_INET
, &oi
->area
->ospf6
->router_id
, myself
.name
,
619 sizeof(myself
.name
));
620 myself
.state
= OSPF6_NEIGHBOR_TWOWAY
;
621 myself
.drouter
= oi
->drouter
;
622 myself
.bdrouter
= oi
->bdrouter
;
623 myself
.priority
= oi
->priority
;
624 myself
.router_id
= oi
->area
->ospf6
->router_id
;
626 /* Electing BDR (2) */
627 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
))
628 bdrouter
= better_bdrouter(bdrouter
, on
);
630 best_bdrouter
= bdrouter
;
631 bdrouter
= better_bdrouter(best_bdrouter
, &myself
);
633 /* Electing DR (3) */
634 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
))
635 drouter
= better_drouter(drouter
, on
);
637 best_drouter
= drouter
;
638 drouter
= better_drouter(best_drouter
, &myself
);
642 /* the router itself is newly/no longer DR/BDR (4) */
643 if ((drouter
== &myself
&& myself
.drouter
!= myself
.router_id
)
644 || (drouter
!= &myself
&& myself
.drouter
== myself
.router_id
)
645 || (bdrouter
== &myself
&& myself
.bdrouter
!= myself
.router_id
)
646 || (bdrouter
!= &myself
&& myself
.bdrouter
== myself
.router_id
)) {
647 myself
.drouter
= (drouter
? drouter
->router_id
: htonl(0));
648 myself
.bdrouter
= (bdrouter
? bdrouter
->router_id
: htonl(0));
650 /* compatible to Electing BDR (2) */
651 bdrouter
= better_bdrouter(best_bdrouter
, &myself
);
653 /* compatible to Electing DR (3) */
654 drouter
= better_drouter(best_drouter
, &myself
);
659 /* Set interface state accordingly (5) */
660 if (drouter
&& drouter
== &myself
)
661 next_state
= OSPF6_INTERFACE_DR
;
662 else if (bdrouter
&& bdrouter
== &myself
)
663 next_state
= OSPF6_INTERFACE_BDR
;
665 next_state
= OSPF6_INTERFACE_DROTHER
;
667 /* If NBMA, schedule Start for each neighbor having priority of 0 (6) */
670 /* If DR or BDR change, invoke AdjOK? for each neighbor (7) */
671 /* RFC 2328 section 12.4. Originating LSAs (3) will be handled
672 accordingly after AdjOK */
673 if (oi
->drouter
!= (drouter
? drouter
->router_id
: htonl(0))
674 || oi
->bdrouter
!= (bdrouter
? bdrouter
->router_id
: htonl(0))) {
675 if (IS_OSPF6_DEBUG_INTERFACE
)
676 zlog_debug("DR Election on %s: DR: %s BDR: %s",
678 (drouter
? drouter
->name
: "0.0.0.0"),
679 (bdrouter
? bdrouter
->name
: "0.0.0.0"));
681 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, node
, on
)) {
682 if (on
->state
< OSPF6_NEIGHBOR_TWOWAY
)
684 /* Schedule AdjOK. */
685 thread_add_event(master
, adj_ok
, on
, 0,
690 oi
->drouter
= (drouter
? drouter
->router_id
: htonl(0));
691 oi
->bdrouter
= (bdrouter
? bdrouter
->router_id
: htonl(0));
699 static bool ifmaddr_check(ifindex_t ifindex
, struct in6_addr
*addr
)
701 struct ifmaddrs
*ifmap
, *ifma
;
702 struct sockaddr_dl
*sdl
;
703 struct sockaddr_in6
*sin6
;
706 if (getifmaddrs(&ifmap
) != 0)
709 for (ifma
= ifmap
; ifma
; ifma
= ifma
->ifma_next
) {
710 if (ifma
->ifma_name
== NULL
|| ifma
->ifma_addr
== NULL
)
712 if (ifma
->ifma_name
->sa_family
!= AF_LINK
)
714 if (ifma
->ifma_addr
->sa_family
!= AF_INET6
)
716 sdl
= (struct sockaddr_dl
*)ifma
->ifma_name
;
717 sin6
= (struct sockaddr_in6
*)ifma
->ifma_addr
;
718 if (sdl
->sdl_index
== ifindex
719 && memcmp(&sin6
->sin6_addr
, addr
, IPV6_MAX_BYTELEN
) == 0) {
731 #endif /* __FreeBSD__ */
733 /* Interface State Machine */
734 void interface_up(struct thread
*thread
)
736 struct ospf6_interface
*oi
;
739 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
740 assert(oi
&& oi
->interface
);
743 oi
->type
= ospf6_default_iftype(oi
->interface
);
745 thread_cancel(&oi
->thread_sso
);
747 if (IS_OSPF6_DEBUG_INTERFACE
)
748 zlog_debug("Interface Event %s: [InterfaceUp]",
749 oi
->interface
->name
);
751 /* check physical interface is up */
752 if (!if_is_operative(oi
->interface
)) {
753 zlog_warn("Interface %s is down, can't execute [InterfaceUp]",
754 oi
->interface
->name
);
758 /* check interface has a link-local address */
759 if (!(ospf6_interface_get_linklocal_address(oi
->interface
)
760 || if_is_loopback(oi
->interface
))) {
762 "Interface %s has no link local address, can't execute [InterfaceUp]",
763 oi
->interface
->name
);
768 ospf6_interface_recalculate_cost(oi
);
770 /* if already enabled, do nothing */
771 if (oi
->state
> OSPF6_INTERFACE_DOWN
) {
772 if (IS_OSPF6_DEBUG_INTERFACE
)
773 zlog_debug("Interface %s already enabled",
774 oi
->interface
->name
);
778 /* If no area assigned, return */
779 if (oi
->area
== NULL
) {
781 "%s: Not scheduling Hello for %s as there is no area assigned yet",
782 __func__
, oi
->interface
->name
);
788 * There's a delay in FreeBSD between issuing a command to leave a
789 * multicast group and an actual leave. If we execute "no router ospf6"
790 * and "router ospf6" fast enough, we can end up in a situation when OS
791 * performs the leave later than it performs the join and the interface
792 * remains without a multicast group. We have to do the join only after
793 * the interface actually left the group.
795 if (ifmaddr_check(oi
->interface
->ifindex
, &allspfrouters6
)) {
797 "Interface %s is still in all routers group, rescheduling for SSO",
798 oi
->interface
->name
);
799 thread_add_timer(master
, interface_up
, oi
,
800 OSPF6_INTERFACE_SSO_RETRY_INT
,
804 #endif /* __FreeBSD__ */
806 ospf6
= oi
->area
->ospf6
;
808 /* Join AllSPFRouters */
809 if (ospf6_sso(oi
->interface
->ifindex
, &allspfrouters6
, IPV6_JOIN_GROUP
,
812 if (oi
->sso_try_cnt
++ < OSPF6_INTERFACE_SSO_RETRY_MAX
) {
814 "Scheduling %s for sso retry, trial count: %d",
815 oi
->interface
->name
, oi
->sso_try_cnt
);
816 thread_add_timer(master
, interface_up
, oi
,
817 OSPF6_INTERFACE_SSO_RETRY_INT
,
822 oi
->sso_try_cnt
= 0; /* Reset on success */
824 /* Update interface route */
825 ospf6_interface_connected_route_update(oi
->interface
);
828 if (!CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_PASSIVE
)
829 && !if_is_loopback(oi
->interface
)) {
830 thread_add_timer(master
, ospf6_hello_send
, oi
, 0,
831 &oi
->thread_send_hello
);
834 /* decide next interface state */
835 if (oi
->type
== OSPF_IFTYPE_LOOPBACK
) {
836 ospf6_interface_state_change(OSPF6_INTERFACE_LOOPBACK
, oi
);
837 } else if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
) {
838 ospf6_interface_state_change(OSPF6_INTERFACE_POINTTOPOINT
, oi
);
839 } else if (oi
->priority
== 0)
840 ospf6_interface_state_change(OSPF6_INTERFACE_DROTHER
, oi
);
842 ospf6_interface_state_change(OSPF6_INTERFACE_WAITING
, oi
);
843 thread_add_timer(master
, wait_timer
, oi
, oi
->dead_interval
,
844 &oi
->thread_wait_timer
);
848 void wait_timer(struct thread
*thread
)
850 struct ospf6_interface
*oi
;
852 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
853 assert(oi
&& oi
->interface
);
855 if (IS_OSPF6_DEBUG_INTERFACE
)
856 zlog_debug("Interface Event %s: [WaitTimer]",
857 oi
->interface
->name
);
859 if (oi
->state
== OSPF6_INTERFACE_WAITING
)
860 ospf6_interface_state_change(dr_election(oi
), oi
);
863 void backup_seen(struct thread
*thread
)
865 struct ospf6_interface
*oi
;
867 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
868 assert(oi
&& oi
->interface
);
870 if (IS_OSPF6_DEBUG_INTERFACE
)
871 zlog_debug("Interface Event %s: [BackupSeen]",
872 oi
->interface
->name
);
874 if (oi
->state
== OSPF6_INTERFACE_WAITING
)
875 ospf6_interface_state_change(dr_election(oi
), oi
);
878 void neighbor_change(struct thread
*thread
)
880 struct ospf6_interface
*oi
;
882 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
883 assert(oi
&& oi
->interface
);
885 if (IS_OSPF6_DEBUG_INTERFACE
)
886 zlog_debug("Interface Event %s: [NeighborChange]",
887 oi
->interface
->name
);
889 if (oi
->state
== OSPF6_INTERFACE_DROTHER
890 || oi
->state
== OSPF6_INTERFACE_BDR
891 || oi
->state
== OSPF6_INTERFACE_DR
)
892 ospf6_interface_state_change(dr_election(oi
), oi
);
895 void interface_down(struct thread
*thread
)
897 struct ospf6_interface
*oi
;
898 struct listnode
*node
, *nnode
;
899 struct ospf6_neighbor
*on
;
902 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
903 assert(oi
&& oi
->interface
);
905 if (IS_OSPF6_DEBUG_INTERFACE
)
906 zlog_debug("Interface Event %s: [InterfaceDown]",
907 oi
->interface
->name
);
910 THREAD_OFF(oi
->thread_send_hello
);
912 /* Stop trying to set socket options. */
913 THREAD_OFF(oi
->thread_sso
);
915 /* Cease the HELPER role for all the neighbours
918 if (ospf6_interface_neighbor_count(oi
)) {
920 struct ospf6_neighbor
*nbr
= NULL
;
922 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, ln
, nbr
))
923 ospf6_gr_helper_exit(nbr
, OSPF6_GR_HELPER_TOPO_CHG
);
926 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
))
927 ospf6_neighbor_delete(on
);
929 list_delete_all_node(oi
->neighbor_list
);
931 /* When interface state is reset, also reset information about
932 * DR election, as it is no longer valid. */
933 oi
->drouter
= oi
->prev_drouter
= htonl(0);
934 oi
->bdrouter
= oi
->prev_bdrouter
= htonl(0);
936 if (oi
->area
== NULL
)
939 ospf6
= oi
->area
->ospf6
;
940 /* Leave AllSPFRouters */
941 if (oi
->state
> OSPF6_INTERFACE_DOWN
)
942 ospf6_sso(oi
->interface
->ifindex
, &allspfrouters6
,
943 IPV6_LEAVE_GROUP
, ospf6
->fd
);
945 /* deal with write fifo */
946 ospf6_fifo_flush(oi
->obuf
);
947 if (oi
->on_write_q
) {
948 listnode_delete(ospf6
->oi_write_q
, oi
);
949 if (list_isempty(ospf6
->oi_write_q
))
950 thread_cancel(&ospf6
->t_write
);
954 ospf6_interface_state_change(OSPF6_INTERFACE_DOWN
, oi
);
958 static const char *ospf6_iftype_str(uint8_t iftype
)
961 case OSPF_IFTYPE_LOOPBACK
:
963 case OSPF_IFTYPE_BROADCAST
:
965 case OSPF_IFTYPE_POINTOPOINT
:
966 return "POINTOPOINT";
971 #if CONFDATE > 20220709
972 CPP_NOTICE("Time to remove ospf6Enabled from JSON output")
975 /* show specified interface structure */
976 static int ospf6_interface_show(struct vty
*vty
, struct interface
*ifp
,
977 json_object
*json_obj
, bool use_json
)
979 struct ospf6_interface
*oi
;
983 char strbuf
[PREFIX2STR_BUFFER
], drouter
[32], bdrouter
[32];
984 uint8_t default_iftype
;
985 struct timeval res
, now
;
987 struct ospf6_lsa
*lsa
, *lsanext
;
988 json_object
*json_arr
;
989 json_object
*json_addr
;
990 struct json_object
*json_auth
= NULL
;
992 default_iftype
= ospf6_default_iftype(ifp
);
995 json_object_string_add(json_obj
, "status",
996 (if_is_operative(ifp
) ? "up" : "down"));
997 json_object_string_add(json_obj
, "type",
998 ospf6_iftype_str(default_iftype
));
999 json_object_int_add(json_obj
, "interfaceId", ifp
->ifindex
);
1001 if (ifp
->info
== NULL
) {
1002 json_object_boolean_false_add(json_obj
, "ospf6Enabled");
1005 json_object_boolean_true_add(json_obj
, "ospf6Enabled");
1007 oi
= (struct ospf6_interface
*)ifp
->info
;
1009 if (if_is_operative(ifp
) && oi
->type
!= default_iftype
)
1010 json_object_string_add(json_obj
, "operatingAsType",
1011 ospf6_iftype_str(oi
->type
));
1014 vty_out(vty
, "%s is %s, type %s\n", ifp
->name
,
1015 (if_is_operative(ifp
) ? "up" : "down"),
1016 ospf6_iftype_str(default_iftype
));
1017 vty_out(vty
, " Interface ID: %d\n", ifp
->ifindex
);
1019 if (ifp
->info
== NULL
) {
1020 vty_out(vty
, " OSPF not enabled on this interface\n");
1023 oi
= (struct ospf6_interface
*)ifp
->info
;
1025 if (if_is_operative(ifp
) && oi
->type
!= default_iftype
)
1026 vty_out(vty
, " Operating as type %s\n",
1027 ospf6_iftype_str(oi
->type
));
1031 json_arr
= json_object_new_array();
1032 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, i
, c
)) {
1033 json_addr
= json_object_new_object();
1035 prefix2str(p
, strbuf
, sizeof(strbuf
));
1036 switch (p
->family
) {
1038 json_object_string_add(json_addr
, "type",
1040 json_object_string_add(json_addr
, "address",
1042 json_object_array_add(json_arr
, json_addr
);
1045 json_object_string_add(json_addr
, "type",
1047 json_object_string_add(json_addr
, "address",
1049 json_object_array_add(json_arr
, json_addr
);
1052 json_object_string_add(json_addr
, "type",
1054 json_object_string_add(json_addr
, "address",
1056 json_object_array_add(json_arr
, json_addr
);
1060 json_object_object_add(json_obj
, "internetAddress", json_arr
);
1062 vty_out(vty
, " Internet Address:\n");
1064 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, i
, c
)) {
1066 prefix2str(p
, strbuf
, sizeof(strbuf
));
1067 switch (p
->family
) {
1069 vty_out(vty
, " inet : %pFX\n", p
);
1072 vty_out(vty
, " inet6: %pFX\n", p
);
1075 vty_out(vty
, " ??? : %pFX\n", p
);
1083 json_object_boolean_true_add(json_obj
,
1085 json_object_int_add(json_obj
, "instanceId",
1087 json_object_int_add(json_obj
, "interfaceMtu",
1089 json_object_int_add(json_obj
, "autoDetect", ifp
->mtu6
);
1090 json_object_string_add(json_obj
, "mtuMismatchDetection",
1091 oi
->mtu_ignore
? "disabled"
1093 inet_ntop(AF_INET
, &oi
->area
->area_id
, strbuf
,
1095 json_object_string_add(json_obj
, "areaId", strbuf
);
1096 json_object_int_add(json_obj
, "cost", oi
->cost
);
1098 json_object_boolean_false_add(json_obj
,
1104 " Instance ID %d, Interface MTU %d (autodetect: %d)\n",
1105 oi
->instance_id
, oi
->ifmtu
, ifp
->mtu6
);
1106 vty_out(vty
, " MTU mismatch detection: %s\n",
1107 oi
->mtu_ignore
? "disabled" : "enabled");
1108 inet_ntop(AF_INET
, &oi
->area
->area_id
, strbuf
,
1110 vty_out(vty
, " Area ID %s, Cost %u\n", strbuf
,
1113 vty_out(vty
, " Not Attached to Area\n");
1117 json_object_string_add(json_obj
, "ospf6InterfaceState",
1118 ospf6_interface_state_str
[oi
->state
]);
1119 json_object_int_add(json_obj
, "transmitDelaySec",
1121 json_object_int_add(json_obj
, "priority", oi
->priority
);
1122 json_object_int_add(json_obj
, "timerIntervalsConfigHello",
1123 oi
->hello_interval
);
1124 json_object_int_add(json_obj
, "timerIntervalsConfigDead",
1126 json_object_int_add(json_obj
, "timerIntervalsConfigRetransmit",
1129 vty_out(vty
, " State %s, Transmit Delay %d sec, Priority %d\n",
1130 ospf6_interface_state_str
[oi
->state
], oi
->transdelay
,
1132 vty_out(vty
, " Timer intervals configured:\n");
1133 vty_out(vty
, " Hello %d(%pTHd), Dead %d, Retransmit %d\n",
1134 oi
->hello_interval
, oi
->thread_send_hello
,
1135 oi
->dead_interval
, oi
->rxmt_interval
);
1138 inet_ntop(AF_INET
, &oi
->drouter
, drouter
, sizeof(drouter
));
1139 inet_ntop(AF_INET
, &oi
->bdrouter
, bdrouter
, sizeof(bdrouter
));
1141 json_object_string_add(json_obj
, "dr", drouter
);
1142 json_object_string_add(json_obj
, "bdr", bdrouter
);
1143 json_object_int_add(json_obj
, "numberOfInterfaceScopedLsa",
1146 vty_out(vty
, " DR: %s BDR: %s\n", drouter
, bdrouter
);
1147 vty_out(vty
, " Number of I/F scoped LSAs is %u\n",
1155 if (oi
->thread_send_lsupdate
)
1156 timersub(&oi
->thread_send_lsupdate
->u
.sands
, &now
,
1158 timerstring(&res
, duration
, sizeof(duration
));
1159 json_object_int_add(json_obj
, "pendingLsaLsUpdateCount",
1160 oi
->lsupdate_list
->count
);
1161 json_object_string_add(json_obj
, "pendingLsaLsUpdateTime",
1163 json_object_string_add(
1164 json_obj
, "lsUpdateSendThread",
1165 (oi
->thread_send_lsupdate
? "on" : "off"));
1167 json_arr
= json_object_new_array();
1168 for (ALL_LSDB(oi
->lsupdate_list
, lsa
, lsanext
))
1169 json_object_array_add(
1170 json_arr
, json_object_new_string(lsa
->name
));
1171 json_object_object_add(json_obj
, "pendingLsaLsUpdate",
1175 if (oi
->thread_send_lsack
)
1176 timersub(&oi
->thread_send_lsack
->u
.sands
, &now
, &res
);
1177 timerstring(&res
, duration
, sizeof(duration
));
1179 json_object_int_add(json_obj
, "pendingLsaLsAckCount",
1180 oi
->lsack_list
->count
);
1181 json_object_string_add(json_obj
, "pendingLsaLsAckTime",
1183 json_object_string_add(json_obj
, "lsAckSendThread",
1184 (oi
->thread_send_lsack
? "on" : "off"));
1186 json_arr
= json_object_new_array();
1187 for (ALL_LSDB(oi
->lsack_list
, lsa
, lsanext
))
1188 json_object_array_add(
1189 json_arr
, json_object_new_string(lsa
->name
));
1190 json_object_object_add(json_obj
, "pendingLsaLsAck", json_arr
);
1194 if (oi
->thread_send_lsupdate
)
1195 timersub(&oi
->thread_send_lsupdate
->u
.sands
, &now
,
1197 timerstring(&res
, duration
, sizeof(duration
));
1199 " %d Pending LSAs for LSUpdate in Time %s [thread %s]\n",
1200 oi
->lsupdate_list
->count
, duration
,
1201 (oi
->thread_send_lsupdate
? "on" : "off"));
1202 for (ALL_LSDB(oi
->lsupdate_list
, lsa
, lsanext
))
1203 vty_out(vty
, " %s\n", lsa
->name
);
1206 if (oi
->thread_send_lsack
)
1207 timersub(&oi
->thread_send_lsack
->u
.sands
, &now
, &res
);
1208 timerstring(&res
, duration
, sizeof(duration
));
1210 " %d Pending LSAs for LSAck in Time %s [thread %s]\n",
1211 oi
->lsack_list
->count
, duration
,
1212 (oi
->thread_send_lsack
? "on" : "off"));
1213 for (ALL_LSDB(oi
->lsack_list
, lsa
, lsanext
))
1214 vty_out(vty
, " %s\n", lsa
->name
);
1218 if (oi
->bfd_config
.enabled
) {
1220 struct json_object
*json_bfd
= json_object_new_object();
1222 json_object_int_add(
1223 json_bfd
, "detectMultiplier",
1224 oi
->bfd_config
.detection_multiplier
);
1225 json_object_int_add(json_bfd
, "rxMinInterval",
1226 oi
->bfd_config
.min_rx
);
1227 json_object_int_add(json_bfd
, "txMinInterval",
1228 oi
->bfd_config
.min_tx
);
1229 json_object_object_add(json_obj
, "peerBfdInfo",
1233 " BFD: Detect Multiplier: %d, Min Rx interval: %d, Min Tx interval: %d\n",
1234 oi
->bfd_config
.detection_multiplier
,
1235 oi
->bfd_config
.min_rx
, oi
->bfd_config
.min_tx
);
1239 json_auth
= json_object_new_object();
1240 if (oi
->at_data
.flags
!= 0) {
1242 if (CHECK_FLAG(oi
->at_data
.flags
,
1243 OSPF6_AUTH_TRAILER_KEYCHAIN
)) {
1244 json_object_string_add(json_auth
, "authType",
1246 json_object_string_add(json_auth
,
1248 oi
->at_data
.keychain
);
1249 } else if (CHECK_FLAG(oi
->at_data
.flags
,
1250 OSPF6_AUTH_TRAILER_MANUAL_KEY
))
1251 json_object_string_add(json_auth
, "authType",
1253 json_object_int_add(json_auth
, "txPktDrop",
1254 oi
->at_data
.tx_drop
);
1255 json_object_int_add(json_auth
, "rxPktDrop",
1256 oi
->at_data
.rx_drop
);
1258 if (CHECK_FLAG(oi
->at_data
.flags
,
1259 OSPF6_AUTH_TRAILER_KEYCHAIN
))
1261 " Authentication Trailer is enabled with key-chain %s\n",
1262 oi
->at_data
.keychain
);
1263 else if (CHECK_FLAG(oi
->at_data
.flags
,
1264 OSPF6_AUTH_TRAILER_MANUAL_KEY
))
1266 " Authentication trailer is enabled with manual key\n");
1268 " Packet drop Tx %u, Packet drop Rx %u\n",
1269 oi
->at_data
.tx_drop
, oi
->at_data
.rx_drop
);
1273 json_object_string_add(json_auth
, "authType", "NULL");
1275 vty_out(vty
, " Authentication Trailer is disabled\n");
1279 json_object_object_add(json_obj
, "authInfo", json_auth
);
1284 /* Find the global address to be used as a forwarding address in NSSA LSA.*/
1285 struct in6_addr
*ospf6_interface_get_global_address(struct interface
*ifp
)
1288 struct connected
*c
;
1290 /* for each connected address */
1291 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, n
, c
)) {
1292 /* if family not AF_INET6, ignore */
1293 if (c
->address
->family
!= AF_INET6
)
1296 if (!IN6_IS_ADDR_LINKLOCAL(&c
->address
->u
.prefix6
))
1297 return &c
->address
->u
.prefix6
;
1304 static int show_ospf6_interface_common(struct vty
*vty
, vrf_id_t vrf_id
,
1305 int argc
, struct cmd_token
**argv
,
1306 int idx_ifname
, int intf_idx
,
1307 int json_idx
, bool uj
)
1310 struct vrf
*vrf
= vrf_lookup_by_id(vrf_id
);
1311 struct interface
*ifp
;
1313 json_object
*json_int
;
1316 json
= json_object_new_object();
1317 if (argc
== json_idx
) {
1318 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
1319 json_int
= json_object_new_object();
1321 json_object_string_add(json
, "noSuchInterface",
1322 argv
[idx_ifname
]->arg
);
1323 vty_json(vty
, json
);
1324 json_object_free(json_int
);
1327 ospf6_interface_show(vty
, ifp
, json_int
, uj
);
1328 json_object_object_add(json
, ifp
->name
, json_int
);
1330 FOR_ALL_INTERFACES (vrf
, ifp
) {
1331 json_int
= json_object_new_object();
1332 ospf6_interface_show(vty
, ifp
, json_int
, uj
);
1333 json_object_object_add(json
, ifp
->name
,
1337 vty_json(vty
, json
);
1339 if (argc
== intf_idx
) {
1340 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
, vrf_id
);
1342 vty_out(vty
, "No such Interface: %s\n",
1343 argv
[idx_ifname
]->arg
);
1346 ospf6_interface_show(vty
, ifp
, NULL
, uj
);
1348 FOR_ALL_INTERFACES (vrf
, ifp
)
1349 ospf6_interface_show(vty
, ifp
, NULL
, uj
);
1355 /* show interface */
1356 DEFUN(show_ipv6_ospf6_interface
, show_ipv6_ospf6_interface_ifname_cmd
,
1357 "show ipv6 ospf6 [vrf <NAME|all>] interface [IFNAME] [json]",
1358 SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR
1359 "All VRFs\n" INTERFACE_STR IFNAME_STR JSON_STR
)
1364 struct listnode
*node
;
1365 struct ospf6
*ospf6
;
1366 const char *vrf_name
= NULL
;
1367 bool all_vrf
= false;
1369 bool uj
= use_json(argc
, argv
);
1371 OSPF6_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
1378 for (ALL_LIST_ELEMENTS_RO(om6
->ospf6
, node
, ospf6
)) {
1379 if (all_vrf
|| strcmp(ospf6
->name
, vrf_name
) == 0) {
1380 show_ospf6_interface_common(vty
, ospf6
->vrf_id
, argc
,
1381 argv
, idx_ifname
, intf_idx
,
1389 OSPF6_CMD_CHECK_VRF(uj
, all_vrf
, ospf6
);
1394 static int ospf6_interface_show_traffic(struct vty
*vty
,
1395 struct interface
*intf_ifp
,
1396 int display_once
, json_object
*json
,
1397 bool use_json
, vrf_id_t vrf_id
)
1399 struct interface
*ifp
;
1400 struct vrf
*vrf
= NULL
;
1401 struct ospf6_interface
*oi
= NULL
;
1402 json_object
*json_interface
;
1404 if (!display_once
&& !use_json
) {
1406 vty_out(vty
, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface",
1407 " HELLO", " DB-Desc", " LS-Req", " LS-Update",
1409 vty_out(vty
, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "",
1410 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
1413 "--------------------------------------------------------------------------------------------\n");
1416 if (intf_ifp
== NULL
) {
1417 vrf
= vrf_lookup_by_id(vrf_id
);
1418 FOR_ALL_INTERFACES (vrf
, ifp
) {
1420 oi
= (struct ospf6_interface
*)ifp
->info
;
1425 json_interface
= json_object_new_object();
1426 json_object_int_add(json_interface
, "helloRx",
1428 json_object_int_add(json_interface
, "helloTx",
1430 json_object_int_add(json_interface
, "dbDescRx",
1432 json_object_int_add(json_interface
, "dbDescTx",
1434 json_object_int_add(json_interface
, "lsReqRx",
1436 json_object_int_add(json_interface
, "lsReqTx",
1438 json_object_int_add(json_interface
,
1441 json_object_int_add(json_interface
,
1444 json_object_int_add(json_interface
, "lsAckRx",
1446 json_object_int_add(json_interface
, "lsAckTx",
1449 json_object_object_add(json
,
1450 oi
->interface
->name
,
1454 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
1455 oi
->interface
->name
, oi
->hello_in
,
1456 oi
->hello_out
, oi
->db_desc_in
,
1457 oi
->db_desc_out
, oi
->ls_req_in
,
1458 oi
->ls_req_out
, oi
->ls_upd_in
,
1459 oi
->ls_upd_out
, oi
->ls_ack_in
,
1463 oi
= intf_ifp
->info
;
1468 json_interface
= json_object_new_object();
1469 json_object_int_add(json_interface
, "helloRx",
1471 json_object_int_add(json_interface
, "helloTx",
1473 json_object_int_add(json_interface
, "dbDescRx",
1475 json_object_int_add(json_interface
, "dbDescTx",
1477 json_object_int_add(json_interface
, "lsReqRx",
1479 json_object_int_add(json_interface
, "lsReqTx",
1481 json_object_int_add(json_interface
, "lsUpdateRx",
1483 json_object_int_add(json_interface
, "lsUpdateTx",
1485 json_object_int_add(json_interface
, "lsAckRx",
1487 json_object_int_add(json_interface
, "lsAckTx",
1490 json_object_object_add(json
, oi
->interface
->name
,
1494 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
1495 oi
->interface
->name
, oi
->hello_in
,
1496 oi
->hello_out
, oi
->db_desc_in
, oi
->db_desc_out
,
1497 oi
->ls_req_in
, oi
->ls_req_out
, oi
->ls_upd_in
,
1498 oi
->ls_upd_out
, oi
->ls_ack_in
, oi
->ls_ack_out
);
1504 static int ospf6_interface_show_traffic_common(struct vty
*vty
, int argc
,
1505 struct cmd_token
**argv
,
1506 vrf_id_t vrf_id
, bool uj
)
1509 int display_once
= 0;
1510 char *intf_name
= NULL
;
1511 struct interface
*ifp
= NULL
;
1512 json_object
*json
= NULL
;
1515 json
= json_object_new_object();
1517 if (argv_find(argv
, argc
, "IFNAME", &idx_ifname
)) {
1518 intf_name
= argv
[idx_ifname
]->arg
;
1519 ifp
= if_lookup_by_name(intf_name
, vrf_id
);
1522 json_object_string_add(json
, "status",
1523 "No Such Interface");
1524 json_object_string_add(json
, "interface",
1526 vty_json(vty
, json
);
1529 if (ifp
->info
== NULL
) {
1530 json_object_string_add(
1532 "OSPF not enabled on this interface");
1533 json_object_string_add(json
, "interface",
1535 vty_json(vty
, json
);
1540 vty_out(vty
, "No such Interface: %s\n",
1544 if (ifp
->info
== NULL
) {
1546 " OSPF not enabled on this interface %s\n",
1553 ospf6_interface_show_traffic(vty
, ifp
, display_once
, json
, uj
, vrf_id
);
1556 vty_json(vty
, json
);
1561 /* show interface */
1562 DEFUN(show_ipv6_ospf6_interface_traffic
, show_ipv6_ospf6_interface_traffic_cmd
,
1563 "show ipv6 ospf6 [vrf <NAME|all>] interface traffic [IFNAME] [json]",
1564 SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR
1565 "All VRFs\n" INTERFACE_STR
1566 "Protocol Packet counters\n" IFNAME_STR JSON_STR
)
1568 struct ospf6
*ospf6
;
1569 struct listnode
*node
;
1570 const char *vrf_name
= NULL
;
1571 bool all_vrf
= false;
1573 bool uj
= use_json(argc
, argv
);
1575 OSPF6_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
1577 for (ALL_LIST_ELEMENTS_RO(om6
->ospf6
, node
, ospf6
)) {
1578 if (all_vrf
|| strcmp(ospf6
->name
, vrf_name
) == 0) {
1579 ospf6_interface_show_traffic_common(vty
, argc
, argv
,
1587 OSPF6_CMD_CHECK_VRF(uj
, all_vrf
, ospf6
);
1593 DEFUN(show_ipv6_ospf6_interface_ifname_prefix
,
1594 show_ipv6_ospf6_interface_ifname_prefix_cmd
,
1595 "show ipv6 ospf6 [vrf <NAME|all>] interface IFNAME prefix\
1598 |<X:X::X:X|X:X::X:X/M> [<match|detail>]\
1600 SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR
1601 "All VRFs\n" INTERFACE_STR IFNAME_STR
1602 "Display connected prefixes to advertise\n"
1603 "Display details of the prefixes\n" OSPF6_ROUTE_ADDRESS_STR
1604 OSPF6_ROUTE_PREFIX_STR OSPF6_ROUTE_MATCH_STR
1605 "Display details of the prefixes\n" JSON_STR
)
1609 struct ospf6_interface
*oi
;
1610 bool uj
= use_json(argc
, argv
);
1612 struct ospf6
*ospf6
;
1613 struct listnode
*node
;
1614 struct interface
*ifp
;
1615 const char *vrf_name
= NULL
;
1616 bool all_vrf
= false;
1619 OSPF6_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
1625 for (ALL_LIST_ELEMENTS_RO(om6
->ospf6
, node
, ospf6
)) {
1626 if (all_vrf
|| strcmp(ospf6
->name
, vrf_name
) == 0) {
1627 ifp
= if_lookup_by_name(argv
[idx_ifname
]->arg
,
1630 vty_out(vty
, "No such Interface: %s\n",
1631 argv
[idx_ifname
]->arg
);
1637 || CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_DISABLE
)) {
1639 "Interface %s not attached to area\n",
1640 argv
[idx_ifname
]->arg
);
1644 ospf6_route_table_show(vty
, idx_prefix
, argc
, argv
,
1645 oi
->route_connected
, uj
);
1652 OSPF6_CMD_CHECK_VRF(uj
, all_vrf
, ospf6
);
1657 DEFUN(show_ipv6_ospf6_interface_prefix
, show_ipv6_ospf6_interface_prefix_cmd
,
1658 "show ipv6 ospf6 [vrf <NAME|all>] interface prefix\
1661 |<X:X::X:X|X:X::X:X/M> [<match|detail>]\
1663 SHOW_STR IP6_STR OSPF6_STR VRF_CMD_HELP_STR
1664 "All VRFs\n" INTERFACE_STR
1665 "Display connected prefixes to advertise\n"
1666 "Display details of the prefixes\n" OSPF6_ROUTE_ADDRESS_STR
1667 OSPF6_ROUTE_PREFIX_STR OSPF6_ROUTE_MATCH_STR
1668 "Display details of the prefixes\n" JSON_STR
)
1670 struct vrf
*vrf
= NULL
;
1672 struct ospf6_interface
*oi
;
1673 struct interface
*ifp
;
1674 bool uj
= use_json(argc
, argv
);
1675 struct listnode
*node
;
1676 struct ospf6
*ospf6
;
1677 const char *vrf_name
= NULL
;
1678 bool all_vrf
= false;
1681 OSPF6_FIND_VRF_ARGS(argv
, argc
, idx_vrf
, vrf_name
, all_vrf
);
1685 for (ALL_LIST_ELEMENTS_RO(om6
->ospf6
, node
, ospf6
)) {
1686 if (all_vrf
|| strcmp(ospf6
->name
, vrf_name
) == 0) {
1687 vrf
= vrf_lookup_by_id(ospf6
->vrf_id
);
1688 FOR_ALL_INTERFACES (vrf
, ifp
) {
1689 oi
= (struct ospf6_interface
*)ifp
->info
;
1691 || CHECK_FLAG(oi
->flag
,
1692 OSPF6_INTERFACE_DISABLE
))
1695 ospf6_route_table_show(vty
, idx_prefix
, argc
,
1697 oi
->route_connected
, uj
);
1704 OSPF6_CMD_CHECK_VRF(uj
, all_vrf
, ospf6
);
1709 void ospf6_interface_start(struct ospf6_interface
*oi
)
1711 struct ospf6
*ospf6
;
1712 struct ospf6_area
*oa
;
1714 if (oi
->area_id_format
== OSPF6_AREA_FMT_UNSET
)
1720 ospf6
= oi
->interface
->vrf
->info
;
1724 oa
= ospf6_area_lookup(oi
->area_id
, ospf6
);
1726 oa
= ospf6_area_create(oi
->area_id
, ospf6
, oi
->area_id_format
);
1728 /* attach interface to area */
1729 listnode_add(oa
->if_list
, oi
);
1732 SET_FLAG(oa
->flag
, OSPF6_AREA_ENABLE
);
1735 ospf6_interface_enable(oi
);
1737 /* If the router is ABR, originate summary routes */
1738 if (ospf6_check_and_set_router_abr(ospf6
))
1739 ospf6_abr_enable_area(oa
);
1742 void ospf6_interface_stop(struct ospf6_interface
*oi
)
1744 struct ospf6_area
*oa
;
1750 ospf6_interface_disable(oi
);
1752 listnode_delete(oa
->if_list
, oi
);
1755 if (oa
->if_list
->count
== 0) {
1756 UNSET_FLAG(oa
->flag
, OSPF6_AREA_ENABLE
);
1757 ospf6_abr_disable_area(oa
);
1761 /* interface variable set command */
1762 DEFUN (ipv6_ospf6_area
,
1763 ipv6_ospf6_area_cmd
,
1764 "ipv6 ospf6 area <A.B.C.D|(0-4294967295)>",
1767 "Specify the OSPF6 area ID\n"
1768 "OSPF6 area ID in IPv4 address notation\n"
1769 "OSPF6 area ID in decimal notation\n")
1771 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1772 struct ospf6_interface
*oi
;
1779 oi
= (struct ospf6_interface
*)ifp
->info
;
1781 oi
= ospf6_interface_create(ifp
);
1785 vty_out(vty
, "%s already attached to Area %s\n",
1786 oi
->interface
->name
, oi
->area
->name
);
1790 if (str2area_id(argv
[idx_ipv4
]->arg
, &area_id
, &format
)) {
1791 vty_out(vty
, "Malformed Area-ID: %s\n", argv
[idx_ipv4
]->arg
);
1792 return CMD_WARNING_CONFIG_FAILED
;
1795 oi
->area_id
= area_id
;
1796 oi
->area_id_format
= format
;
1798 ospf6_interface_start(oi
);
1803 DEFUN (no_ipv6_ospf6_area
,
1804 no_ipv6_ospf6_area_cmd
,
1805 "no ipv6 ospf6 area [<A.B.C.D|(0-4294967295)>]",
1809 "Specify the OSPF6 area ID\n"
1810 "OSPF6 area ID in IPv4 address notation\n"
1811 "OSPF6 area ID in decimal notation\n")
1813 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1814 struct ospf6_interface
*oi
;
1818 oi
= (struct ospf6_interface
*)ifp
->info
;
1820 oi
= ospf6_interface_create(ifp
);
1823 ospf6_interface_stop(oi
);
1826 oi
->area_id_format
= OSPF6_AREA_FMT_UNSET
;
1831 DEFUN (ipv6_ospf6_ifmtu
,
1832 ipv6_ospf6_ifmtu_cmd
,
1833 "ipv6 ospf6 ifmtu (1-65535)",
1837 "OSPFv3 Interface MTU\n"
1840 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1842 struct ospf6_interface
*oi
;
1843 unsigned int ifmtu
, iobuflen
;
1844 struct listnode
*node
, *nnode
;
1845 struct ospf6_neighbor
*on
;
1849 oi
= (struct ospf6_interface
*)ifp
->info
;
1851 oi
= ospf6_interface_create(ifp
);
1854 ifmtu
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
1856 if (oi
->c_ifmtu
== ifmtu
)
1859 if (ifp
->mtu6
!= 0 && ifp
->mtu6
< ifmtu
) {
1861 "%s's ospf6 ifmtu cannot go beyond physical mtu (%d)\n",
1862 ifp
->name
, ifp
->mtu6
);
1863 return CMD_WARNING_CONFIG_FAILED
;
1866 if (oi
->ifmtu
< ifmtu
) {
1867 iobuflen
= ospf6_iobuf_size(ifmtu
);
1868 if (iobuflen
< ifmtu
) {
1870 "%s's ifmtu is adjusted to I/O buffer size (%d).\n",
1871 ifp
->name
, iobuflen
);
1872 oi
->ifmtu
= oi
->c_ifmtu
= iobuflen
;
1874 oi
->ifmtu
= oi
->c_ifmtu
= ifmtu
;
1876 oi
->ifmtu
= oi
->c_ifmtu
= ifmtu
;
1878 /* re-establish adjacencies */
1879 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
)) {
1880 THREAD_OFF(on
->inactivity_timer
);
1881 thread_add_event(master
, inactivity_timer
, on
, 0, NULL
);
1887 DEFUN (no_ipv6_ospf6_ifmtu
,
1888 no_ipv6_ospf6_ifmtu_cmd
,
1889 "no ipv6 ospf6 ifmtu [(1-65535)]",
1894 "OSPFv3 Interface MTU\n"
1897 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1898 struct ospf6_interface
*oi
;
1899 unsigned int iobuflen
;
1900 struct listnode
*node
, *nnode
;
1901 struct ospf6_neighbor
*on
;
1905 oi
= (struct ospf6_interface
*)ifp
->info
;
1907 oi
= ospf6_interface_create(ifp
);
1910 if (oi
->ifmtu
< ifp
->mtu
) {
1911 iobuflen
= ospf6_iobuf_size(ifp
->mtu
);
1912 if (iobuflen
< ifp
->mtu
) {
1914 "%s's ifmtu is adjusted to I/O buffer size (%d).\n",
1915 ifp
->name
, iobuflen
);
1916 oi
->ifmtu
= iobuflen
;
1918 oi
->ifmtu
= ifp
->mtu
;
1920 oi
->ifmtu
= ifp
->mtu
;
1924 /* re-establish adjacencies */
1925 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
)) {
1926 THREAD_OFF(on
->inactivity_timer
);
1927 thread_add_event(master
, inactivity_timer
, on
, 0, NULL
);
1933 DEFUN (ipv6_ospf6_cost
,
1934 ipv6_ospf6_cost_cmd
,
1935 "ipv6 ospf6 cost (1-65535)",
1939 "Outgoing metric of this interface\n")
1941 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1943 struct ospf6_interface
*oi
;
1944 unsigned long int lcost
;
1948 oi
= (struct ospf6_interface
*)ifp
->info
;
1950 oi
= ospf6_interface_create(ifp
);
1953 lcost
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
1955 if (lcost
> UINT32_MAX
) {
1956 vty_out(vty
, "Cost %ld is out of range\n", lcost
);
1957 return CMD_WARNING_CONFIG_FAILED
;
1960 SET_FLAG(oi
->flag
, OSPF6_INTERFACE_NOAUTOCOST
);
1961 if (oi
->cost
== lcost
)
1965 ospf6_interface_force_recalculate_cost(oi
);
1970 DEFUN (no_ipv6_ospf6_cost
,
1971 no_ipv6_ospf6_cost_cmd
,
1972 "no ipv6 ospf6 cost [(1-65535)]",
1976 "Calculate interface cost from bandwidth\n"
1977 "Outgoing metric of this interface\n")
1979 VTY_DECLVAR_CONTEXT(interface
, ifp
);
1980 struct ospf6_interface
*oi
;
1983 oi
= (struct ospf6_interface
*)ifp
->info
;
1985 oi
= ospf6_interface_create(ifp
);
1988 UNSET_FLAG(oi
->flag
, OSPF6_INTERFACE_NOAUTOCOST
);
1990 ospf6_interface_recalculate_cost(oi
);
1995 DEFUN (auto_cost_reference_bandwidth
,
1996 auto_cost_reference_bandwidth_cmd
,
1997 "auto-cost reference-bandwidth (1-4294967)",
1998 "Calculate OSPF interface cost according to bandwidth\n"
1999 "Use reference bandwidth method to assign OSPF cost\n"
2000 "The reference bandwidth in terms of Mbits per second\n")
2002 VTY_DECLVAR_CONTEXT(ospf6
, o
);
2004 struct ospf6_area
*oa
;
2005 struct ospf6_interface
*oi
;
2006 struct listnode
*i
, *j
;
2009 refbw
= strtol(argv
[idx_number
]->arg
, NULL
, 10);
2010 if (refbw
< 1 || refbw
> 4294967) {
2011 vty_out(vty
, "reference-bandwidth value is invalid\n");
2012 return CMD_WARNING_CONFIG_FAILED
;
2015 /* If reference bandwidth is changed. */
2016 if ((refbw
) == o
->ref_bandwidth
)
2019 o
->ref_bandwidth
= refbw
;
2020 for (ALL_LIST_ELEMENTS_RO(o
->area_list
, i
, oa
))
2021 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
2022 ospf6_interface_recalculate_cost(oi
);
2027 DEFUN (no_auto_cost_reference_bandwidth
,
2028 no_auto_cost_reference_bandwidth_cmd
,
2029 "no auto-cost reference-bandwidth [(1-4294967)]",
2031 "Calculate OSPF interface cost according to bandwidth\n"
2032 "Use reference bandwidth method to assign OSPF cost\n"
2033 "The reference bandwidth in terms of Mbits per second\n")
2035 VTY_DECLVAR_CONTEXT(ospf6
, o
);
2036 struct ospf6_area
*oa
;
2037 struct ospf6_interface
*oi
;
2038 struct listnode
*i
, *j
;
2040 if (o
->ref_bandwidth
== OSPF6_REFERENCE_BANDWIDTH
)
2043 o
->ref_bandwidth
= OSPF6_REFERENCE_BANDWIDTH
;
2044 for (ALL_LIST_ELEMENTS_RO(o
->area_list
, i
, oa
))
2045 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, j
, oi
))
2046 ospf6_interface_recalculate_cost(oi
);
2052 DEFUN (ospf6_write_multiplier
,
2053 ospf6_write_multiplier_cmd
,
2054 "write-multiplier (1-100)",
2055 "Write multiplier\n"
2056 "Maximum number of interface serviced per write\n")
2058 VTY_DECLVAR_CONTEXT(ospf6
, o
);
2059 uint32_t write_oi_count
;
2061 write_oi_count
= strtol(argv
[1]->arg
, NULL
, 10);
2062 if (write_oi_count
< 1 || write_oi_count
> 100) {
2063 vty_out(vty
, "write-multiplier value is invalid\n");
2064 return CMD_WARNING_CONFIG_FAILED
;
2067 o
->write_oi_count
= write_oi_count
;
2071 DEFUN (no_ospf6_write_multiplier
,
2072 no_ospf6_write_multiplier_cmd
,
2073 "no write-multiplier (1-100)",
2075 "Write multiplier\n"
2076 "Maximum number of interface serviced per write\n")
2078 VTY_DECLVAR_CONTEXT(ospf6
, o
);
2080 o
->write_oi_count
= OSPF6_WRITE_INTERFACE_COUNT_DEFAULT
;
2084 DEFUN (ipv6_ospf6_hellointerval
,
2085 ipv6_ospf6_hellointerval_cmd
,
2086 "ipv6 ospf6 hello-interval (1-65535)",
2089 "Time between HELLO packets\n"
2092 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2094 struct ospf6_interface
*oi
;
2097 oi
= (struct ospf6_interface
*)ifp
->info
;
2099 oi
= ospf6_interface_create(ifp
);
2102 oi
->hello_interval
= strmatch(argv
[0]->text
, "no")
2103 ? OSPF_HELLO_INTERVAL_DEFAULT
2104 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2107 * If the thread is scheduled, send the new hello now.
2109 if (thread_is_scheduled(oi
->thread_send_hello
)) {
2110 THREAD_OFF(oi
->thread_send_hello
);
2112 thread_add_timer(master
, ospf6_hello_send
, oi
, 0,
2113 &oi
->thread_send_hello
);
2118 ALIAS (ipv6_ospf6_hellointerval
,
2119 no_ipv6_ospf6_hellointerval_cmd
,
2120 "no ipv6 ospf6 hello-interval [(1-65535)]",
2124 "Time between HELLO packets\n"
2127 /* interface variable set command */
2128 DEFUN (ipv6_ospf6_deadinterval
,
2129 ipv6_ospf6_deadinterval_cmd
,
2130 "ipv6 ospf6 dead-interval (1-65535)",
2133 "Interval time after which a neighbor is declared down\n"
2136 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2138 struct ospf6_interface
*oi
;
2141 oi
= (struct ospf6_interface
*)ifp
->info
;
2143 oi
= ospf6_interface_create(ifp
);
2146 oi
->dead_interval
= strmatch(argv
[0]->arg
, "no")
2147 ? OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
2148 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2152 ALIAS (ipv6_ospf6_deadinterval
,
2153 no_ipv6_ospf6_deadinterval_cmd
,
2154 "no ipv6 ospf6 dead-interval [(1-65535)]",
2158 "Interval time after which a neighbor is declared down\n"
2161 /* interface variable set command */
2162 DEFUN (ipv6_ospf6_transmitdelay
,
2163 ipv6_ospf6_transmitdelay_cmd
,
2164 "ipv6 ospf6 transmit-delay (1-3600)",
2167 "Link state transmit delay\n"
2170 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2172 struct ospf6_interface
*oi
;
2175 oi
= (struct ospf6_interface
*)ifp
->info
;
2177 oi
= ospf6_interface_create(ifp
);
2180 oi
->transdelay
= strmatch(argv
[0]->text
, "no")
2181 ? OSPF6_INTERFACE_TRANSDELAY
2182 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2186 ALIAS (ipv6_ospf6_transmitdelay
,
2187 no_ipv6_ospf6_transmitdelay_cmd
,
2188 "no ipv6 ospf6 transmit-delay [(1-3600)]",
2192 "Link state transmit delay\n"
2195 /* interface variable set command */
2196 DEFUN (ipv6_ospf6_retransmitinterval
,
2197 ipv6_ospf6_retransmitinterval_cmd
,
2198 "ipv6 ospf6 retransmit-interval (1-65535)",
2201 "Time between retransmitting lost link state advertisements\n"
2204 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2206 struct ospf6_interface
*oi
;
2209 oi
= (struct ospf6_interface
*)ifp
->info
;
2211 oi
= ospf6_interface_create(ifp
);
2214 oi
->rxmt_interval
= strmatch(argv
[0]->text
, "no")
2215 ? OSPF_RETRANSMIT_INTERVAL_DEFAULT
2216 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2220 ALIAS (ipv6_ospf6_retransmitinterval
,
2221 no_ipv6_ospf6_retransmitinterval_cmd
,
2222 "no ipv6 ospf6 retransmit-interval [(1-65535)]",
2226 "Time between retransmitting lost link state advertisements\n"
2229 /* interface variable set command */
2230 DEFUN (ipv6_ospf6_priority
,
2231 ipv6_ospf6_priority_cmd
,
2232 "ipv6 ospf6 priority (0-255)",
2238 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2240 struct ospf6_interface
*oi
;
2243 oi
= (struct ospf6_interface
*)ifp
->info
;
2245 oi
= ospf6_interface_create(ifp
);
2248 oi
->priority
= strmatch(argv
[0]->text
, "no")
2249 ? OSPF6_INTERFACE_PRIORITY
2250 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2253 && (oi
->state
== OSPF6_INTERFACE_DROTHER
2254 || oi
->state
== OSPF6_INTERFACE_BDR
2255 || oi
->state
== OSPF6_INTERFACE_DR
)) {
2256 if (ospf6_interface_state_change(dr_election(oi
), oi
) == -1)
2257 OSPF6_LINK_LSA_SCHEDULE(oi
);
2263 ALIAS (ipv6_ospf6_priority
,
2264 no_ipv6_ospf6_priority_cmd
,
2265 "no ipv6 ospf6 priority [(0-255)]",
2272 DEFUN (ipv6_ospf6_instance
,
2273 ipv6_ospf6_instance_cmd
,
2274 "ipv6 ospf6 instance-id (0-255)",
2277 "Instance ID for this interface\n"
2278 "Instance ID value\n")
2280 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2282 struct ospf6_interface
*oi
;
2285 oi
= (struct ospf6_interface
*)ifp
->info
;
2287 oi
= ospf6_interface_create(ifp
);
2290 oi
->instance_id
= strmatch(argv
[0]->text
, "no")
2291 ? OSPF6_INTERFACE_INSTANCE_ID
2292 : strtoul(argv
[idx_number
]->arg
, NULL
, 10);
2296 ALIAS (ipv6_ospf6_instance
,
2297 no_ipv6_ospf6_instance_cmd
,
2298 "no ipv6 ospf6 instance-id [(0-255)]",
2302 "Instance ID for this interface\n"
2303 "Instance ID value\n")
2305 DEFUN (ipv6_ospf6_passive
,
2306 ipv6_ospf6_passive_cmd
,
2307 "ipv6 ospf6 passive",
2310 "Passive interface; no adjacency will be formed on this interface\n"
2313 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2314 struct ospf6_interface
*oi
;
2315 struct listnode
*node
, *nnode
;
2316 struct ospf6_neighbor
*on
;
2320 oi
= (struct ospf6_interface
*)ifp
->info
;
2322 oi
= ospf6_interface_create(ifp
);
2325 SET_FLAG(oi
->flag
, OSPF6_INTERFACE_PASSIVE
);
2326 THREAD_OFF(oi
->thread_send_hello
);
2327 THREAD_OFF(oi
->thread_sso
);
2329 for (ALL_LIST_ELEMENTS(oi
->neighbor_list
, node
, nnode
, on
)) {
2330 THREAD_OFF(on
->inactivity_timer
);
2331 thread_add_event(master
, inactivity_timer
, on
, 0, NULL
);
2337 DEFUN (no_ipv6_ospf6_passive
,
2338 no_ipv6_ospf6_passive_cmd
,
2339 "no ipv6 ospf6 passive",
2343 "passive interface: No Adjacency will be formed on this I/F\n"
2346 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2347 struct ospf6_interface
*oi
;
2350 oi
= (struct ospf6_interface
*)ifp
->info
;
2352 oi
= ospf6_interface_create(ifp
);
2355 UNSET_FLAG(oi
->flag
, OSPF6_INTERFACE_PASSIVE
);
2356 THREAD_OFF(oi
->thread_send_hello
);
2357 THREAD_OFF(oi
->thread_sso
);
2359 /* don't send hellos over loopback interface */
2360 if (!if_is_loopback(oi
->interface
))
2361 thread_add_timer(master
, ospf6_hello_send
, oi
, 0,
2362 &oi
->thread_send_hello
);
2367 DEFUN (ipv6_ospf6_mtu_ignore
,
2368 ipv6_ospf6_mtu_ignore_cmd
,
2369 "ipv6 ospf6 mtu-ignore",
2372 "Disable MTU mismatch detection on this interface\n"
2375 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2376 struct ospf6_interface
*oi
;
2379 oi
= (struct ospf6_interface
*)ifp
->info
;
2381 oi
= ospf6_interface_create(ifp
);
2389 DEFUN (no_ipv6_ospf6_mtu_ignore
,
2390 no_ipv6_ospf6_mtu_ignore_cmd
,
2391 "no ipv6 ospf6 mtu-ignore",
2395 "Disable MTU mismatch detection on this interface\n"
2398 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2399 struct ospf6_interface
*oi
;
2402 oi
= (struct ospf6_interface
*)ifp
->info
;
2404 oi
= ospf6_interface_create(ifp
);
2412 DEFUN (ipv6_ospf6_advertise_prefix_list
,
2413 ipv6_ospf6_advertise_prefix_list_cmd
,
2414 "ipv6 ospf6 advertise prefix-list WORD",
2417 "Advertising options\n"
2418 "Filter prefix using prefix-list\n"
2419 "Prefix list name\n"
2422 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2424 struct ospf6_interface
*oi
;
2427 oi
= (struct ospf6_interface
*)ifp
->info
;
2429 oi
= ospf6_interface_create(ifp
);
2433 XFREE(MTYPE_CFG_PLIST_NAME
, oi
->plist_name
);
2434 oi
->plist_name
= XSTRDUP(MTYPE_CFG_PLIST_NAME
, argv
[idx_word
]->arg
);
2436 ospf6_interface_connected_route_update(oi
->interface
);
2439 OSPF6_LINK_LSA_SCHEDULE(oi
);
2440 if (oi
->state
== OSPF6_INTERFACE_DR
) {
2441 OSPF6_NETWORK_LSA_SCHEDULE(oi
);
2442 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
2444 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
2450 DEFUN (no_ipv6_ospf6_advertise_prefix_list
,
2451 no_ipv6_ospf6_advertise_prefix_list_cmd
,
2452 "no ipv6 ospf6 advertise prefix-list [WORD]",
2456 "Advertising options\n"
2457 "Filter prefix using prefix-list\n"
2458 "Prefix list name\n")
2460 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2461 struct ospf6_interface
*oi
;
2464 oi
= (struct ospf6_interface
*)ifp
->info
;
2466 oi
= ospf6_interface_create(ifp
);
2470 XFREE(MTYPE_CFG_PLIST_NAME
, oi
->plist_name
);
2472 ospf6_interface_connected_route_update(oi
->interface
);
2475 OSPF6_LINK_LSA_SCHEDULE(oi
);
2476 if (oi
->state
== OSPF6_INTERFACE_DR
) {
2477 OSPF6_NETWORK_LSA_SCHEDULE(oi
);
2478 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(oi
);
2480 OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi
->area
);
2486 DEFUN (ipv6_ospf6_network
,
2487 ipv6_ospf6_network_cmd
,
2488 "ipv6 ospf6 network <broadcast|point-to-point>",
2492 "Specify OSPF6 broadcast network\n"
2493 "Specify OSPF6 point-to-point network\n"
2496 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2497 int idx_network
= 3;
2498 struct ospf6_interface
*oi
;
2501 oi
= (struct ospf6_interface
*)ifp
->info
;
2503 oi
= ospf6_interface_create(ifp
);
2507 oi
->type_cfg
= true;
2509 if (strncmp(argv
[idx_network
]->arg
, "b", 1) == 0) {
2510 if (oi
->type
== OSPF_IFTYPE_BROADCAST
)
2513 oi
->type
= OSPF_IFTYPE_BROADCAST
;
2514 } else if (strncmp(argv
[idx_network
]->arg
, "point-to-p", 10) == 0) {
2515 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
) {
2518 oi
->type
= OSPF_IFTYPE_POINTOPOINT
;
2521 /* Reset the interface */
2522 thread_execute(master
, interface_down
, oi
, 0);
2523 thread_execute(master
, interface_up
, oi
, 0);
2528 DEFUN (no_ipv6_ospf6_network
,
2529 no_ipv6_ospf6_network_cmd
,
2530 "no ipv6 ospf6 network [<broadcast|point-to-point>]",
2534 "Set default network type\n"
2535 "Specify OSPF6 broadcast network\n"
2536 "Specify OSPF6 point-to-point network\n")
2538 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2539 struct ospf6_interface
*oi
;
2544 oi
= (struct ospf6_interface
*)ifp
->info
;
2549 oi
->type_cfg
= false;
2551 type
= ospf6_default_iftype(ifp
);
2552 if (oi
->type
== type
) {
2557 /* Reset the interface */
2558 thread_execute(master
, interface_down
, oi
, 0);
2559 thread_execute(master
, interface_up
, oi
, 0);
2564 static int config_write_ospf6_interface(struct vty
*vty
, struct vrf
*vrf
)
2566 struct ospf6_interface
*oi
;
2567 struct interface
*ifp
;
2568 char buf
[INET_ADDRSTRLEN
];
2570 FOR_ALL_INTERFACES (vrf
, ifp
) {
2571 oi
= (struct ospf6_interface
*)ifp
->info
;
2575 if_vty_config_start(vty
, ifp
);
2578 vty_out(vty
, " description %s\n", ifp
->desc
);
2579 if (oi
->area_id_format
!= OSPF6_AREA_FMT_UNSET
) {
2580 area_id2str(buf
, sizeof(buf
), oi
->area_id
,
2581 oi
->area_id_format
);
2582 vty_out(vty
, " ipv6 ospf6 area %s\n", buf
);
2585 vty_out(vty
, " ipv6 ospf6 ifmtu %d\n", oi
->c_ifmtu
);
2587 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_NOAUTOCOST
))
2588 vty_out(vty
, " ipv6 ospf6 cost %d\n", oi
->cost
);
2590 if (oi
->hello_interval
!= OSPF6_INTERFACE_HELLO_INTERVAL
)
2591 vty_out(vty
, " ipv6 ospf6 hello-interval %d\n",
2592 oi
->hello_interval
);
2594 if (oi
->dead_interval
!= OSPF6_INTERFACE_DEAD_INTERVAL
)
2595 vty_out(vty
, " ipv6 ospf6 dead-interval %d\n",
2598 if (oi
->rxmt_interval
!= OSPF6_INTERFACE_RXMT_INTERVAL
)
2599 vty_out(vty
, " ipv6 ospf6 retransmit-interval %d\n",
2602 if (oi
->priority
!= OSPF6_INTERFACE_PRIORITY
)
2603 vty_out(vty
, " ipv6 ospf6 priority %d\n", oi
->priority
);
2605 if (oi
->transdelay
!= OSPF6_INTERFACE_TRANSDELAY
)
2606 vty_out(vty
, " ipv6 ospf6 transmit-delay %d\n",
2609 if (oi
->instance_id
!= OSPF6_INTERFACE_INSTANCE_ID
)
2610 vty_out(vty
, " ipv6 ospf6 instance-id %d\n",
2614 vty_out(vty
, " ipv6 ospf6 advertise prefix-list %s\n",
2617 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_PASSIVE
))
2618 vty_out(vty
, " ipv6 ospf6 passive\n");
2621 vty_out(vty
, " ipv6 ospf6 mtu-ignore\n");
2623 if (oi
->type_cfg
&& oi
->type
== OSPF_IFTYPE_POINTOPOINT
)
2624 vty_out(vty
, " ipv6 ospf6 network point-to-point\n");
2625 else if (oi
->type_cfg
&& oi
->type
== OSPF_IFTYPE_BROADCAST
)
2626 vty_out(vty
, " ipv6 ospf6 network broadcast\n");
2628 ospf6_bfd_write_config(vty
, oi
);
2630 ospf6_auth_write_config(vty
, &oi
->at_data
);
2631 if_vty_config_end(vty
);
2636 /* Configuration write function for ospfd. */
2637 static int config_write_interface(struct vty
*vty
)
2640 struct vrf
*vrf
= NULL
;
2642 /* Display all VRF aware OSPF interface configuration */
2643 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
2644 write
+= config_write_ospf6_interface(vty
, vrf
);
2650 static int ospf6_ifp_create(struct interface
*ifp
)
2652 if (IS_OSPF6_DEBUG_ZEBRA(RECV
))
2653 zlog_debug("Zebra Interface add: %s index %d mtu %d", ifp
->name
,
2654 ifp
->ifindex
, ifp
->mtu6
);
2657 ospf6_interface_start(ifp
->info
);
2662 static int ospf6_ifp_up(struct interface
*ifp
)
2664 if (IS_OSPF6_DEBUG_ZEBRA(RECV
))
2666 "Zebra Interface state change: %s index %d flags %llx metric %d mtu %d bandwidth %d",
2667 ifp
->name
, ifp
->ifindex
, (unsigned long long)ifp
->flags
,
2668 ifp
->metric
, ifp
->mtu6
, ifp
->bandwidth
);
2670 ospf6_interface_state_update(ifp
);
2675 static int ospf6_ifp_down(struct interface
*ifp
)
2677 if (IS_OSPF6_DEBUG_ZEBRA(RECV
))
2679 "Zebra Interface state change: %s index %d flags %llx metric %d mtu %d bandwidth %d",
2680 ifp
->name
, ifp
->ifindex
, (unsigned long long)ifp
->flags
,
2681 ifp
->metric
, ifp
->mtu6
, ifp
->bandwidth
);
2683 ospf6_interface_state_update(ifp
);
2688 static int ospf6_ifp_destroy(struct interface
*ifp
)
2691 zlog_warn("Zebra: got delete of %s, but interface is still up",
2694 if (IS_OSPF6_DEBUG_ZEBRA(RECV
))
2695 zlog_debug("Zebra Interface delete: %s index %d mtu %d",
2696 ifp
->name
, ifp
->ifindex
, ifp
->mtu6
);
2699 ospf6_interface_stop(ifp
->info
);
2704 void ospf6_interface_init(void)
2706 /* Install interface node. */
2707 if_cmd_init(config_write_interface
);
2708 if_zapi_callbacks(ospf6_ifp_create
, ospf6_ifp_up
,
2709 ospf6_ifp_down
, ospf6_ifp_destroy
);
2711 install_element(VIEW_NODE
, &show_ipv6_ospf6_interface_prefix_cmd
);
2712 install_element(VIEW_NODE
, &show_ipv6_ospf6_interface_ifname_cmd
);
2713 install_element(VIEW_NODE
,
2714 &show_ipv6_ospf6_interface_ifname_prefix_cmd
);
2715 install_element(VIEW_NODE
, &show_ipv6_ospf6_interface_traffic_cmd
);
2717 install_element(INTERFACE_NODE
, &ipv6_ospf6_area_cmd
);
2718 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_area_cmd
);
2719 install_element(INTERFACE_NODE
, &ipv6_ospf6_cost_cmd
);
2720 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_cost_cmd
);
2721 install_element(INTERFACE_NODE
, &ipv6_ospf6_ifmtu_cmd
);
2722 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_ifmtu_cmd
);
2724 install_element(INTERFACE_NODE
, &ipv6_ospf6_deadinterval_cmd
);
2725 install_element(INTERFACE_NODE
, &ipv6_ospf6_hellointerval_cmd
);
2726 install_element(INTERFACE_NODE
, &ipv6_ospf6_priority_cmd
);
2727 install_element(INTERFACE_NODE
, &ipv6_ospf6_retransmitinterval_cmd
);
2728 install_element(INTERFACE_NODE
, &ipv6_ospf6_transmitdelay_cmd
);
2729 install_element(INTERFACE_NODE
, &ipv6_ospf6_instance_cmd
);
2730 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_deadinterval_cmd
);
2731 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_hellointerval_cmd
);
2732 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_priority_cmd
);
2733 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_retransmitinterval_cmd
);
2734 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_transmitdelay_cmd
);
2735 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_instance_cmd
);
2737 install_element(INTERFACE_NODE
, &ipv6_ospf6_passive_cmd
);
2738 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_passive_cmd
);
2740 install_element(INTERFACE_NODE
, &ipv6_ospf6_mtu_ignore_cmd
);
2741 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_mtu_ignore_cmd
);
2743 install_element(INTERFACE_NODE
, &ipv6_ospf6_advertise_prefix_list_cmd
);
2744 install_element(INTERFACE_NODE
,
2745 &no_ipv6_ospf6_advertise_prefix_list_cmd
);
2747 install_element(INTERFACE_NODE
, &ipv6_ospf6_network_cmd
);
2748 install_element(INTERFACE_NODE
, &no_ipv6_ospf6_network_cmd
);
2750 /* reference bandwidth commands */
2751 install_element(OSPF6_NODE
, &auto_cost_reference_bandwidth_cmd
);
2752 install_element(OSPF6_NODE
, &no_auto_cost_reference_bandwidth_cmd
);
2753 /* write-multiplier commands */
2754 install_element(OSPF6_NODE
, &ospf6_write_multiplier_cmd
);
2755 install_element(OSPF6_NODE
, &no_ospf6_write_multiplier_cmd
);
2758 /* Clear the specified interface structure */
2759 void ospf6_interface_clear(struct interface
*ifp
)
2761 struct ospf6_interface
*oi
;
2763 if (!if_is_operative(ifp
))
2766 if (ifp
->info
== NULL
)
2769 oi
= (struct ospf6_interface
*)ifp
->info
;
2771 if (IS_OSPF6_DEBUG_INTERFACE
)
2772 zlog_debug("Interface %s: clear by reset", ifp
->name
);
2774 /* Reset the interface */
2775 thread_execute(master
, interface_down
, oi
, 0);
2776 thread_execute(master
, interface_up
, oi
, 0);
2779 /* Clear interface */
2780 DEFUN (clear_ipv6_ospf6_interface
,
2781 clear_ipv6_ospf6_interface_cmd
,
2782 "clear ipv6 ospf6 [vrf NAME] interface [IFNAME]",
2794 struct interface
*ifp
;
2795 const char *vrf_name
;
2797 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
2798 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
2800 vrf_name
= VRF_DEFAULT_NAME
;
2801 vrf
= vrf_lookup_by_name(vrf_name
);
2803 vty_out(vty
, "%% VRF %s not found\n", vrf_name
);
2807 if (!argv_find(argv
, argc
, "IFNAME", &idx_ifname
)) {
2808 /* Clear all the ospfv3 interfaces. */
2809 FOR_ALL_INTERFACES (vrf
, ifp
)
2810 ospf6_interface_clear(ifp
);
2812 /* Interface name is specified. */
2813 ifp
= if_lookup_by_name_vrf(argv
[idx_ifname
]->arg
, vrf
);
2815 vty_out(vty
, "No such Interface: %s\n",
2816 argv
[idx_ifname
]->arg
);
2819 ospf6_interface_clear(ifp
);
2825 void install_element_ospf6_clear_interface(void)
2827 install_element(ENABLE_NODE
, &clear_ipv6_ospf6_interface_cmd
);
2830 DEFUN (debug_ospf6_interface
,
2831 debug_ospf6_interface_cmd
,
2832 "debug ospf6 interface",
2835 "Debug OSPFv3 Interface\n"
2838 OSPF6_DEBUG_INTERFACE_ON();
2842 DEFUN (no_debug_ospf6_interface
,
2843 no_debug_ospf6_interface_cmd
,
2844 "no debug ospf6 interface",
2848 "Debug OSPFv3 Interface\n"
2851 OSPF6_DEBUG_INTERFACE_OFF();
2855 int config_write_ospf6_debug_interface(struct vty
*vty
)
2857 if (IS_OSPF6_DEBUG_INTERFACE
)
2858 vty_out(vty
, "debug ospf6 interface\n");
2862 void install_element_ospf6_debug_interface(void)
2864 install_element(ENABLE_NODE
, &debug_ospf6_interface_cmd
);
2865 install_element(ENABLE_NODE
, &no_debug_ospf6_interface_cmd
);
2866 install_element(CONFIG_NODE
, &debug_ospf6_interface_cmd
);
2867 install_element(CONFIG_NODE
, &no_debug_ospf6_interface_cmd
);
2870 void ospf6_auth_write_config(struct vty
*vty
, struct ospf6_auth_data
*at_data
)
2872 if (CHECK_FLAG(at_data
->flags
, OSPF6_AUTH_TRAILER_KEYCHAIN
))
2873 vty_out(vty
, " ipv6 ospf6 authentication keychain %s\n",
2875 else if (CHECK_FLAG(at_data
->flags
, OSPF6_AUTH_TRAILER_MANUAL_KEY
))
2877 " ipv6 ospf6 authentication key-id %d hash-algo %s key %s\n",
2879 keychain_get_algo_name_by_id(at_data
->hash_algo
),
2883 DEFUN(ipv6_ospf6_intf_auth_trailer_keychain
,
2884 ipv6_ospf6_intf_auth_trailer_keychain_cmd
,
2885 "ipv6 ospf6 authentication keychain KEYCHAIN_NAME",
2887 "Enable authentication on this interface\n"
2891 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2892 int keychain_idx
= 4;
2893 struct ospf6_interface
*oi
;
2895 oi
= (struct ospf6_interface
*)ifp
->info
;
2897 oi
= ospf6_interface_create(ifp
);
2900 if (CHECK_FLAG(oi
->at_data
.flags
, OSPF6_AUTH_TRAILER_MANUAL_KEY
)) {
2902 "Manual key configured, unconfigure it before configuring key chain\n");
2903 return CMD_WARNING_CONFIG_FAILED
;
2906 SET_FLAG(oi
->at_data
.flags
, OSPF6_AUTH_TRAILER_KEYCHAIN
);
2907 if (oi
->at_data
.keychain
)
2908 XFREE(MTYPE_OSPF6_AUTH_KEYCHAIN
, oi
->at_data
.keychain
);
2910 oi
->at_data
.keychain
=
2911 XSTRDUP(MTYPE_OSPF6_AUTH_KEYCHAIN
, argv
[keychain_idx
]->arg
);
2916 DEFUN(no_ipv6_ospf6_intf_auth_trailer_keychain
,
2917 no_ipv6_ospf6_intf_auth_trailer_keychain_cmd
,
2918 "no ipv6 ospf6 authentication keychain [KEYCHAIN_NAME]",
2919 NO_STR IP6_STR OSPF6_STR
2920 "Enable authentication on this interface\n"
2924 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2925 struct ospf6_interface
*oi
;
2927 oi
= (struct ospf6_interface
*)ifp
->info
;
2929 oi
= ospf6_interface_create(ifp
);
2932 if (!CHECK_FLAG(oi
->at_data
.flags
, OSPF6_AUTH_TRAILER_KEYCHAIN
))
2935 if (oi
->at_data
.keychain
) {
2936 oi
->at_data
.flags
= 0;
2937 XFREE(MTYPE_OSPF6_AUTH_KEYCHAIN
, oi
->at_data
.keychain
);
2938 oi
->at_data
.keychain
= NULL
;
2944 DEFUN(ipv6_ospf6_intf_auth_trailer_key
, ipv6_ospf6_intf_auth_trailer_key_cmd
,
2945 "ipv6 ospf6 authentication key-id (1-65535) hash-algo "
2946 "<md5|hmac-sha-1|hmac-sha-256|hmac-sha-384|hmac-sha-512> "
2952 "Cryptographic-algorithm\n"
2953 "Use MD5 algorithm\n"
2954 "Use HMAC-SHA-1 algorithm\n"
2955 "Use HMAC-SHA-256 algorithm\n"
2956 "Use HMAC-SHA-384 algorithm\n"
2957 "Use HMAC-SHA-512 algorithm\n"
2959 "Password string (key)\n")
2961 VTY_DECLVAR_CONTEXT(interface
, ifp
);
2963 int hash_algo_idx
= 6;
2964 int password_idx
= 8;
2965 struct ospf6_interface
*oi
;
2966 uint8_t hash_algo
= KEYCHAIN_ALGO_NULL
;
2968 oi
= (struct ospf6_interface
*)ifp
->info
;
2970 oi
= ospf6_interface_create(ifp
);
2973 if (CHECK_FLAG(oi
->at_data
.flags
, OSPF6_AUTH_TRAILER_KEYCHAIN
)) {
2975 "key chain configured, unconfigure it before configuring manual key\n");
2976 return CMD_WARNING_CONFIG_FAILED
;
2979 hash_algo
= keychain_get_algo_id_by_name(argv
[hash_algo_idx
]->arg
);
2980 #ifndef CRYPTO_OPENSSL
2981 if (hash_algo
== KEYCHAIN_ALGO_NULL
) {
2983 "Hash algorithm not supported, compile with --with-crypto=openssl\n");
2984 return CMD_WARNING_CONFIG_FAILED
;
2986 #endif /* CRYPTO_OPENSSL */
2988 SET_FLAG(oi
->at_data
.flags
, OSPF6_AUTH_TRAILER_MANUAL_KEY
);
2989 oi
->at_data
.hash_algo
= hash_algo
;
2990 oi
->at_data
.key_id
= (uint16_t)strtol(argv
[key_id_idx
]->arg
, NULL
, 10);
2991 if (oi
->at_data
.auth_key
)
2992 XFREE(MTYPE_OSPF6_AUTH_MANUAL_KEY
, oi
->at_data
.auth_key
);
2993 oi
->at_data
.auth_key
=
2994 XSTRDUP(MTYPE_OSPF6_AUTH_MANUAL_KEY
, argv
[password_idx
]->arg
);
2999 DEFUN(no_ipv6_ospf6_intf_auth_trailer_key
,
3000 no_ipv6_ospf6_intf_auth_trailer_key_cmd
,
3001 "no ipv6 ospf6 authentication key-id [(1-65535) hash-algo "
3002 "<md5|hmac-sha-1|hmac-sha-256|hmac-sha-384|hmac-sha-512> "
3004 NO_STR IP6_STR OSPF6_STR
3008 "Cryptographic-algorithm\n"
3009 "Use MD5 algorithm\n"
3010 "Use HMAC-SHA-1 algorithm\n"
3011 "Use HMAC-SHA-256 algorithm\n"
3012 "Use HMAC-SHA-384 algorithm\n"
3013 "Use HMAC-SHA-512 algorithm\n"
3015 "Password string (key)\n")
3017 VTY_DECLVAR_CONTEXT(interface
, ifp
);
3018 struct ospf6_interface
*oi
;
3019 #ifndef CRYPTO_OPENSSL
3020 int hash_algo_idx
= 7;
3021 uint8_t hash_algo
= KEYCHAIN_ALGO_NULL
;
3022 #endif /* CRYPTO_OPENSSL */
3024 oi
= (struct ospf6_interface
*)ifp
->info
;
3026 oi
= ospf6_interface_create(ifp
);
3029 if (!CHECK_FLAG(oi
->at_data
.flags
, OSPF6_AUTH_TRAILER_MANUAL_KEY
))
3032 #ifndef CRYPTO_OPENSSL
3033 hash_algo
= keychain_get_algo_id_by_name(argv
[hash_algo_idx
]->arg
);
3034 if (hash_algo
== KEYCHAIN_ALGO_NULL
) {
3036 "Hash algorithm not supported, compile with --with-crypto=openssl\n");
3037 return CMD_WARNING_CONFIG_FAILED
;
3039 #endif /* CRYPTO_OPENSSL */
3041 if (oi
->at_data
.auth_key
) {
3042 oi
->at_data
.flags
= 0;
3043 XFREE(MTYPE_OSPF6_AUTH_MANUAL_KEY
, oi
->at_data
.auth_key
);
3044 oi
->at_data
.auth_key
= NULL
;
3050 void ospf6_interface_auth_trailer_cmd_init(void)
3052 /*Install OSPF6 auth trailer commands at interface level */
3053 install_element(INTERFACE_NODE
,
3054 &ipv6_ospf6_intf_auth_trailer_keychain_cmd
);
3055 install_element(INTERFACE_NODE
,
3056 &no_ipv6_ospf6_intf_auth_trailer_keychain_cmd
);
3057 install_element(INTERFACE_NODE
, &ipv6_ospf6_intf_auth_trailer_key_cmd
);
3058 install_element(INTERFACE_NODE
,
3059 &no_ipv6_ospf6_intf_auth_trailer_key_cmd
);