3 * Copyright (C) 1997, 98 Kunihiro Ishiguro
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation; either version 2, or (at your
10 * option) any later version.
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #include "lib_errors.h"
31 #include "sockunion.h"
37 #include "northbound_cli.h"
38 #ifndef VTYSH_EXTRACT_PL
39 #include "lib/if_clippy.c"
42 DEFINE_MTYPE_STATIC(LIB
, IF
, "Interface")
43 DEFINE_MTYPE_STATIC(LIB
, CONNECTED
, "Connected")
44 DEFINE_MTYPE_STATIC(LIB
, NBR_CONNECTED
, "Neighbor Connected")
45 DEFINE_MTYPE(LIB
, CONNECTED_LABEL
, "Connected interface label")
46 DEFINE_MTYPE_STATIC(LIB
, IF_LINK_PARAMS
, "Informational Link Parameters")
48 static struct interface
*if_lookup_by_ifindex(ifindex_t ifindex
,
50 static int if_cmp_func(const struct interface
*, const struct interface
*);
51 static int if_cmp_index_func(const struct interface
*ifp1
,
52 const struct interface
*ifp2
);
53 RB_GENERATE(if_name_head
, interface
, name_entry
, if_cmp_func
);
54 RB_GENERATE(if_index_head
, interface
, index_entry
, if_cmp_index_func
);
56 DEFINE_QOBJ_TYPE(interface
)
58 DEFINE_HOOK(if_add
, (struct interface
* ifp
), (ifp
))
59 DEFINE_KOOH(if_del
, (struct interface
* ifp
), (ifp
))
61 static struct interface_master
{
62 int (*create_hook
)(struct interface
*ifp
);
63 int (*up_hook
)(struct interface
*ifp
);
64 int (*down_hook
)(struct interface
*ifp
);
65 int (*destroy_hook
)(struct interface
*ifp
);
66 } ifp_master
= { 0, };
68 /* Compare interface names, returning an integer greater than, equal to, or
69 * less than 0, (following the strcmp convention), according to the
70 * relationship between ifp1 and ifp2. Interface names consist of an
71 * alphabetic prefix and a numeric suffix. The primary sort key is
72 * lexicographic by name, and then numeric by number. No number sorts
73 * before all numbers. Examples: de0 < de1, de100 < fxp0 < xl0, devpty <
76 int if_cmp_name_func(const char *p1
, const char *p2
)
83 /* look up to any number */
84 l1
= strcspn(p1
, "0123456789");
85 l2
= strcspn(p2
, "0123456789");
87 /* name lengths are different -> compare names */
89 return (strcmp(p1
, p2
));
91 /* Note that this relies on all numbers being less than all
95 res
= strncmp(p1
, p2
, l1
);
97 /* names are different -> compare them */
101 /* with identical name part, go to numeric part */
112 x1
= strtol(p1
, (char **)&p1
, 10);
113 x2
= strtol(p2
, (char **)&p2
, 10);
115 /* let's compare numbers now */
121 /* numbers were equal, lets do it again..
122 (it happens with name like "eth123.456:789") */
131 static int if_cmp_func(const struct interface
*ifp1
,
132 const struct interface
*ifp2
)
134 return if_cmp_name_func(ifp1
->name
, ifp2
->name
);
137 static int if_cmp_index_func(const struct interface
*ifp1
,
138 const struct interface
*ifp2
)
140 if (ifp1
->ifindex
== ifp2
->ifindex
)
142 else if (ifp1
->ifindex
> ifp2
->ifindex
)
148 static void ifp_connected_free(void *arg
)
150 struct connected
*c
= arg
;
155 /* Create new interface structure. */
156 static struct interface
*if_new(vrf_id_t vrf_id
)
158 struct interface
*ifp
;
160 ifp
= XCALLOC(MTYPE_IF
, sizeof(struct interface
));
162 ifp
->ifindex
= IFINDEX_INTERNAL
;
165 ifp
->vrf_id
= vrf_id
;
167 ifp
->connected
= list_new();
168 ifp
->connected
->del
= ifp_connected_free
;
170 ifp
->nbr_connected
= list_new();
171 ifp
->nbr_connected
->del
= (void (*)(void *))nbr_connected_free
;
173 /* Enable Link-detection by default */
174 SET_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
);
176 QOBJ_REG(ifp
, interface
);
180 void if_new_via_zapi(struct interface
*ifp
)
182 if (ifp_master
.create_hook
)
183 (*ifp_master
.create_hook
)(ifp
);
186 void if_destroy_via_zapi(struct interface
*ifp
)
188 if (ifp_master
.destroy_hook
)
189 (*ifp_master
.destroy_hook
)(ifp
);
191 if_set_index(ifp
, IFINDEX_INTERNAL
);
192 if (!ifp
->configured
)
196 void if_up_via_zapi(struct interface
*ifp
)
198 if (ifp_master
.up_hook
)
199 (*ifp_master
.up_hook
)(ifp
);
202 void if_down_via_zapi(struct interface
*ifp
)
204 if (ifp_master
.down_hook
)
205 (*ifp_master
.down_hook
)(ifp
);
208 struct interface
*if_create_name(const char *name
, vrf_id_t vrf_id
)
210 struct interface
*ifp
;
212 ifp
= if_new(vrf_id
);
214 if_set_name(ifp
, name
);
216 hook_call(if_add
, ifp
);
220 struct interface
*if_create_ifindex(ifindex_t ifindex
, vrf_id_t vrf_id
)
222 struct interface
*ifp
;
224 ifp
= if_new(vrf_id
);
226 if_set_index(ifp
, ifindex
);
228 hook_call(if_add
, ifp
);
232 /* Create new interface structure. */
233 void if_update_to_new_vrf(struct interface
*ifp
, vrf_id_t vrf_id
)
235 struct vrf
*old_vrf
, *vrf
;
237 /* remove interface from old master vrf list */
238 old_vrf
= vrf_lookup_by_id(ifp
->vrf_id
);
240 if (ifp
->name
[0] != '\0')
241 IFNAME_RB_REMOVE(old_vrf
, ifp
);
243 if (ifp
->ifindex
!= IFINDEX_INTERNAL
)
244 IFINDEX_RB_REMOVE(old_vrf
, ifp
);
247 ifp
->vrf_id
= vrf_id
;
248 vrf
= vrf_get(ifp
->vrf_id
, NULL
);
250 if (ifp
->name
[0] != '\0')
251 IFNAME_RB_INSERT(vrf
, ifp
);
253 if (ifp
->ifindex
!= IFINDEX_INTERNAL
)
254 IFINDEX_RB_INSERT(vrf
, ifp
);
257 * HACK: Change the interface VRF in the running configuration directly,
258 * bypassing the northbound layer. This is necessary to avoid deleting
259 * the interface and readding it in the new VRF, which would have
260 * several implications.
262 if (yang_module_find("frr-interface")) {
263 struct lyd_node
*if_dnode
;
265 if_dnode
= yang_dnode_get(
266 running_config
->dnode
,
267 "/frr-interface:lib/interface[name='%s'][vrf='%s']/vrf",
268 ifp
->name
, old_vrf
->name
);
270 nb_running_unset_entry(if_dnode
->parent
);
271 yang_dnode_change_leaf(if_dnode
, vrf
->name
);
272 nb_running_set_entry(if_dnode
->parent
, ifp
);
273 running_config
->version
++;
279 /* Delete interface structure. */
280 void if_delete_retain(struct interface
*ifp
)
282 hook_call(if_del
, ifp
);
285 /* Free connected address list */
286 list_delete_all_node(ifp
->connected
);
288 /* Free connected nbr address list */
289 list_delete_all_node(ifp
->nbr_connected
);
292 /* Delete and free interface structure. */
293 void if_delete(struct interface
**ifp
)
295 struct interface
*ptr
= *ifp
;
298 vrf
= vrf_lookup_by_id(ptr
->vrf_id
);
301 IFNAME_RB_REMOVE(vrf
, ptr
);
302 if (ptr
->ifindex
!= IFINDEX_INTERNAL
)
303 IFINDEX_RB_REMOVE(vrf
, ptr
);
305 if_delete_retain(ptr
);
307 list_delete(&ptr
->connected
);
308 list_delete(&ptr
->nbr_connected
);
310 if_link_params_free(ptr
);
312 XFREE(MTYPE_TMP
, ptr
->desc
);
314 XFREE(MTYPE_IF
, ptr
);
318 /* Used only internally to check within VRF only */
319 static struct interface
*if_lookup_by_ifindex(ifindex_t ifindex
,
323 struct interface if_tmp
;
325 vrf
= vrf_lookup_by_id(vrf_id
);
329 if_tmp
.ifindex
= ifindex
;
330 return RB_FIND(if_index_head
, &vrf
->ifaces_by_index
, &if_tmp
);
333 /* Interface existance check by index. */
334 struct interface
*if_lookup_by_index(ifindex_t ifindex
, vrf_id_t vrf_id
)
336 switch (vrf_get_backend()) {
337 case VRF_BACKEND_UNKNOWN
:
338 case VRF_BACKEND_NETNS
:
339 return(if_lookup_by_ifindex(ifindex
, vrf_id
));
340 case VRF_BACKEND_VRF_LITE
:
341 return(if_lookup_by_index_all_vrf(ifindex
));
346 const char *ifindex2ifname(ifindex_t ifindex
, vrf_id_t vrf_id
)
348 struct interface
*ifp
;
350 return ((ifp
= if_lookup_by_index(ifindex
, vrf_id
)) != NULL
)
355 ifindex_t
ifname2ifindex(const char *name
, vrf_id_t vrf_id
)
357 struct interface
*ifp
;
359 return ((ifp
= if_lookup_by_name(name
, vrf_id
)) != NULL
)
364 /* Interface existance check by interface name. */
365 struct interface
*if_lookup_by_name(const char *name
, vrf_id_t vrf_id
)
367 struct vrf
*vrf
= vrf_lookup_by_id(vrf_id
);
368 struct interface if_tmp
;
371 || strnlen(name
, INTERFACE_NAMSIZ
) == INTERFACE_NAMSIZ
)
374 strlcpy(if_tmp
.name
, name
, sizeof(if_tmp
.name
));
375 return RB_FIND(if_name_head
, &vrf
->ifaces_by_name
, &if_tmp
);
378 struct interface
*if_lookup_by_name_all_vrf(const char *name
)
381 struct interface
*ifp
;
383 if (!name
|| strnlen(name
, INTERFACE_NAMSIZ
) == INTERFACE_NAMSIZ
)
386 RB_FOREACH (vrf
, vrf_id_head
, &vrfs_by_id
) {
387 ifp
= if_lookup_by_name(name
, vrf
->vrf_id
);
395 struct interface
*if_lookup_by_index_all_vrf(ifindex_t ifindex
)
398 struct interface
*ifp
;
400 if (ifindex
== IFINDEX_INTERNAL
)
403 RB_FOREACH (vrf
, vrf_id_head
, &vrfs_by_id
) {
404 ifp
= if_lookup_by_ifindex(ifindex
, vrf
->vrf_id
);
412 /* Lookup interface by IP address. */
413 struct interface
*if_lookup_exact_address(void *src
, int family
,
416 struct vrf
*vrf
= vrf_lookup_by_id(vrf_id
);
417 struct listnode
*cnode
;
418 struct interface
*ifp
;
422 FOR_ALL_INTERFACES (vrf
, ifp
) {
423 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, c
)) {
426 if (p
&& (p
->family
== family
)) {
427 if (family
== AF_INET
) {
430 (struct in_addr
*)src
))
432 } else if (family
== AF_INET6
) {
435 (struct in6_addr
*)src
))
444 /* Lookup interface by IP address. */
445 struct connected
*if_lookup_address(void *matchaddr
, int family
,
448 struct vrf
*vrf
= vrf_lookup_by_id(vrf_id
);
451 struct listnode
*cnode
;
452 struct interface
*ifp
;
454 struct connected
*match
;
456 if (family
== AF_INET
) {
457 addr
.family
= AF_INET
;
458 addr
.u
.prefix4
= *((struct in_addr
*)matchaddr
);
459 addr
.prefixlen
= IPV4_MAX_BITLEN
;
460 } else if (family
== AF_INET6
) {
461 addr
.family
= AF_INET6
;
462 addr
.u
.prefix6
= *((struct in6_addr
*)matchaddr
);
463 addr
.prefixlen
= IPV6_MAX_BITLEN
;
468 FOR_ALL_INTERFACES (vrf
, ifp
) {
469 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, c
)) {
470 if (c
->address
&& (c
->address
->family
== AF_INET
)
471 && prefix_match(CONNECTED_PREFIX(c
), &addr
)
472 && (c
->address
->prefixlen
> bestlen
)) {
473 bestlen
= c
->address
->prefixlen
;
481 /* Lookup interface by prefix */
482 struct interface
*if_lookup_prefix(struct prefix
*prefix
, vrf_id_t vrf_id
)
484 struct vrf
*vrf
= vrf_lookup_by_id(vrf_id
);
485 struct listnode
*cnode
;
486 struct interface
*ifp
;
489 FOR_ALL_INTERFACES (vrf
, ifp
) {
490 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, c
)) {
491 if (prefix_cmp(c
->address
, prefix
) == 0) {
499 size_t if_lookup_by_hwaddr(const uint8_t *hw_addr
, size_t addrsz
,
500 struct interface
***result
, vrf_id_t vrf_id
)
502 struct vrf
*vrf
= vrf_lookup_by_id(vrf_id
);
504 struct list
*rs
= list_new();
505 struct interface
*ifp
;
507 FOR_ALL_INTERFACES (vrf
, ifp
) {
508 if (ifp
->hw_addr_len
== (int)addrsz
509 && !memcmp(hw_addr
, ifp
->hw_addr
, addrsz
))
510 listnode_add(rs
, ifp
);
514 *result
= XCALLOC(MTYPE_TMP
,
515 sizeof(struct interface
*) * rs
->count
);
516 list_to_array(rs
, (void **)*result
, rs
->count
);
519 int count
= rs
->count
;
527 /* Get interface by name if given name interface doesn't exist create
529 struct interface
*if_get_by_name(const char *name
, vrf_id_t vrf_id
)
531 struct interface
*ifp
;
533 switch (vrf_get_backend()) {
534 case VRF_BACKEND_UNKNOWN
:
535 case VRF_BACKEND_NETNS
:
536 ifp
= if_lookup_by_name(name
, vrf_id
);
539 return if_create_name(name
, vrf_id
);
540 case VRF_BACKEND_VRF_LITE
:
541 ifp
= if_lookup_by_name_all_vrf(name
);
543 if (ifp
->vrf_id
== vrf_id
)
545 /* If it came from the kernel or by way of zclient,
546 * believe it and update the ifp accordingly.
548 if_update_to_new_vrf(ifp
, vrf_id
);
551 return if_create_name(name
, vrf_id
);
557 struct interface
*if_get_by_ifindex(ifindex_t ifindex
, vrf_id_t vrf_id
)
559 struct interface
*ifp
;
561 switch (vrf_get_backend()) {
562 case VRF_BACKEND_UNKNOWN
:
563 case VRF_BACKEND_NETNS
:
564 ifp
= if_lookup_by_ifindex(ifindex
, vrf_id
);
567 return if_create_ifindex(ifindex
, vrf_id
);
568 case VRF_BACKEND_VRF_LITE
:
569 ifp
= if_lookup_by_index_all_vrf(ifindex
);
571 if (ifp
->vrf_id
== vrf_id
)
573 /* If it came from the kernel or by way of zclient,
574 * believe it and update the ifp accordingly.
576 if_update_to_new_vrf(ifp
, vrf_id
);
579 return if_create_ifindex(ifindex
, vrf_id
);
585 void if_set_index(struct interface
*ifp
, ifindex_t ifindex
)
589 vrf
= vrf_get(ifp
->vrf_id
, NULL
);
592 if (ifp
->ifindex
== ifindex
)
595 if (ifp
->ifindex
!= IFINDEX_INTERNAL
)
596 IFINDEX_RB_REMOVE(vrf
, ifp
);
598 ifp
->ifindex
= ifindex
;
600 if (ifp
->ifindex
!= IFINDEX_INTERNAL
)
601 IFINDEX_RB_INSERT(vrf
, ifp
)
604 void if_set_name(struct interface
*ifp
, const char *name
)
608 vrf
= vrf_get(ifp
->vrf_id
, NULL
);
611 if (if_cmp_name_func(ifp
->name
, name
) == 0)
614 if (ifp
->name
[0] != '\0')
615 IFNAME_RB_REMOVE(vrf
, ifp
);
617 strlcpy(ifp
->name
, name
, sizeof(ifp
->name
));
619 if (ifp
->name
[0] != '\0')
620 IFNAME_RB_INSERT(vrf
, ifp
);
623 /* Does interface up ? */
624 int if_is_up(const struct interface
*ifp
)
626 return ifp
->flags
& IFF_UP
;
629 /* Is interface running? */
630 int if_is_running(const struct interface
*ifp
)
632 return ifp
->flags
& IFF_RUNNING
;
635 /* Is the interface operative, eg. either UP & RUNNING
636 or UP & !ZEBRA_INTERFACE_LINK_DETECTION and
637 if ptm checking is enabled, then ptm check has passed */
638 int if_is_operative(const struct interface
*ifp
)
640 return ((ifp
->flags
& IFF_UP
)
641 && (((ifp
->flags
& IFF_RUNNING
)
642 && (ifp
->ptm_status
|| !ifp
->ptm_enable
))
643 || !CHECK_FLAG(ifp
->status
,
644 ZEBRA_INTERFACE_LINKDETECTION
)));
647 /* Is the interface operative, eg. either UP & RUNNING
648 or UP & !ZEBRA_INTERFACE_LINK_DETECTION, without PTM check */
649 int if_is_no_ptm_operative(const struct interface
*ifp
)
651 return ((ifp
->flags
& IFF_UP
)
652 && ((ifp
->flags
& IFF_RUNNING
)
653 || !CHECK_FLAG(ifp
->status
,
654 ZEBRA_INTERFACE_LINKDETECTION
)));
657 /* Is this loopback interface ? */
658 int if_is_loopback(const struct interface
*ifp
)
660 /* XXX: Do this better, eg what if IFF_WHATEVER means X on platform M
661 * but Y on platform N?
663 return (ifp
->flags
& (IFF_LOOPBACK
| IFF_NOXMIT
| IFF_VIRTUAL
));
666 /* Check interface is VRF */
667 int if_is_vrf(const struct interface
*ifp
)
669 return CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_VRF_LOOPBACK
);
672 bool if_is_loopback_or_vrf(const struct interface
*ifp
)
674 if (if_is_loopback(ifp
) || if_is_vrf(ifp
))
680 /* Does this interface support broadcast ? */
681 int if_is_broadcast(const struct interface
*ifp
)
683 return ifp
->flags
& IFF_BROADCAST
;
686 /* Does this interface support broadcast ? */
687 int if_is_pointopoint(const struct interface
*ifp
)
689 return ifp
->flags
& IFF_POINTOPOINT
;
692 /* Does this interface support multicast ? */
693 int if_is_multicast(const struct interface
*ifp
)
695 return ifp
->flags
& IFF_MULTICAST
;
698 /* Printout flag information into log */
699 const char *if_flag_dump(unsigned long flag
)
702 static char logbuf
[BUFSIZ
];
704 #define IFF_OUT_LOG(X, STR) \
707 strlcat(logbuf, ",", sizeof(logbuf)); \
710 strlcat(logbuf, STR, sizeof(logbuf)); \
713 strlcpy(logbuf
, "<", BUFSIZ
);
714 IFF_OUT_LOG(IFF_UP
, "UP");
715 IFF_OUT_LOG(IFF_BROADCAST
, "BROADCAST");
716 IFF_OUT_LOG(IFF_DEBUG
, "DEBUG");
717 IFF_OUT_LOG(IFF_LOOPBACK
, "LOOPBACK");
718 IFF_OUT_LOG(IFF_POINTOPOINT
, "POINTOPOINT");
719 IFF_OUT_LOG(IFF_NOTRAILERS
, "NOTRAILERS");
720 IFF_OUT_LOG(IFF_RUNNING
, "RUNNING");
721 IFF_OUT_LOG(IFF_NOARP
, "NOARP");
722 IFF_OUT_LOG(IFF_PROMISC
, "PROMISC");
723 IFF_OUT_LOG(IFF_ALLMULTI
, "ALLMULTI");
724 IFF_OUT_LOG(IFF_OACTIVE
, "OACTIVE");
725 IFF_OUT_LOG(IFF_SIMPLEX
, "SIMPLEX");
726 IFF_OUT_LOG(IFF_LINK0
, "LINK0");
727 IFF_OUT_LOG(IFF_LINK1
, "LINK1");
728 IFF_OUT_LOG(IFF_LINK2
, "LINK2");
729 IFF_OUT_LOG(IFF_MULTICAST
, "MULTICAST");
730 IFF_OUT_LOG(IFF_NOXMIT
, "NOXMIT");
731 IFF_OUT_LOG(IFF_NORTEXCH
, "NORTEXCH");
732 IFF_OUT_LOG(IFF_VIRTUAL
, "VIRTUAL");
733 IFF_OUT_LOG(IFF_IPV4
, "IPv4");
734 IFF_OUT_LOG(IFF_IPV6
, "IPv6");
736 strlcat(logbuf
, ">", sizeof(logbuf
));
743 static void if_dump(const struct interface
*ifp
)
745 struct listnode
*node
;
746 struct connected
*c
__attribute__((unused
));
748 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, c
))
750 "Interface %s vrf %u index %d metric %d mtu %d "
752 ifp
->name
, ifp
->vrf_id
, ifp
->ifindex
, ifp
->metric
,
753 ifp
->mtu
, ifp
->mtu6
, if_flag_dump(ifp
->flags
));
756 /* Interface printing for all interface. */
757 void if_dump_all(void)
762 RB_FOREACH (vrf
, vrf_id_head
, &vrfs_by_id
)
763 FOR_ALL_INTERFACES (vrf
, ifp
)
768 /* Need to handle upgrade from SUNWzebra to Quagga. SUNWzebra created
769 * a seperate struct interface for each logical interface, so config
770 * file may be full of 'interface fooX:Y'. Solaris however does not
771 * expose logical interfaces via PF_ROUTE, so trying to track logical
772 * interfaces can be fruitless, for that reason Quagga only tracks
773 * the primary IP interface.
775 * We try accomodate SUNWzebra by:
776 * - looking up the interface name, to see whether it exists, if so
778 * - for protocol daemons, this could only because zebra told us of
780 * - for zebra, only because it learnt from kernel
782 * - search the name to see if it contains a sub-ipif / logical interface
783 * seperator, the ':' char. If it does:
784 * - text up to that char must be the primary name - get that name.
786 * - no idea, just get the name in its entirety.
788 static struct interface
*if_sunwzebra_get(const char *name
, vrf_id_t vrf_id
)
790 struct interface
*ifp
;
793 if ((ifp
= if_lookup_by_name(name
, vrf_id
)) != NULL
)
796 /* hunt the primary interface name... */
797 cp
= strchr(name
, ':');
801 return if_get_by_name(name
, vrf_id
);
806 /* For debug purpose. */
809 "show address [vrf NAME]",
815 struct listnode
*node
;
816 struct interface
*ifp
;
817 struct connected
*ifc
;
819 vrf_id_t vrf_id
= VRF_DEFAULT
;
822 VRF_GET_ID (vrf_id
, argv
[idx_vrf
]->arg
);
824 FOR_ALL_INTERFACES (vrf
, ifp
)
826 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, node
, ifc
))
830 if (p
->family
== AF_INET
)
831 vty_out (vty
, "%s/%d\n", inet_ntoa (p
->u
.prefix4
), p
->prefixlen
);
837 DEFUN (show_address_vrf_all
,
838 show_address_vrf_all_cmd
,
839 "show address vrf all",
842 VRF_ALL_CMD_HELP_STR
)
845 struct listnode
*node
;
846 struct interface
*ifp
;
847 struct connected
*ifc
;
850 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
)
852 if (RB_EMPTY (if_name_head
, &vrf
->ifaces_by_name
))
855 vty_out (vty
, "\nVRF %u\n\n", vrf
->vrf_id
);
857 FOR_ALL_INTERFACES (vrf
, ifp
)
859 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, node
, ifc
))
863 if (p
->family
== AF_INET
)
864 vty_out (vty
, "%s/%d\n", inet_ntoa (p
->u
.prefix4
), p
->prefixlen
);
872 /* Allocate connected structure. */
873 struct connected
*connected_new(void)
875 return XCALLOC(MTYPE_CONNECTED
, sizeof(struct connected
));
878 /* Allocate nbr connected structure. */
879 struct nbr_connected
*nbr_connected_new(void)
881 return XCALLOC(MTYPE_NBR_CONNECTED
, sizeof(struct nbr_connected
));
884 /* Free connected structure. */
885 void connected_free(struct connected
**connected
)
887 struct connected
*ptr
= *connected
;
890 prefix_free(&ptr
->address
);
892 if (ptr
->destination
)
893 prefix_free(&ptr
->destination
);
895 XFREE(MTYPE_CONNECTED_LABEL
, ptr
->label
);
897 XFREE(MTYPE_CONNECTED
, ptr
);
901 /* Free nbr connected structure. */
902 void nbr_connected_free(struct nbr_connected
*connected
)
904 if (connected
->address
)
905 prefix_free(&connected
->address
);
907 XFREE(MTYPE_NBR_CONNECTED
, connected
);
910 /* If same interface nbr address already exists... */
911 struct nbr_connected
*nbr_connected_check(struct interface
*ifp
,
914 struct nbr_connected
*ifc
;
915 struct listnode
*node
;
917 for (ALL_LIST_ELEMENTS_RO(ifp
->nbr_connected
, node
, ifc
))
918 if (prefix_same(ifc
->address
, p
))
924 /* Print if_addr structure. */
925 static void __attribute__((unused
))
926 connected_log(struct connected
*connected
, char *str
)
929 struct interface
*ifp
;
933 ifp
= connected
->ifp
;
934 p
= connected
->address
;
936 snprintf(logbuf
, BUFSIZ
, "%s interface %s vrf %u %s %s/%d ", str
,
937 ifp
->name
, ifp
->vrf_id
, prefix_family_str(p
),
938 inet_ntop(p
->family
, &p
->u
.prefix
, buf
, BUFSIZ
), p
->prefixlen
);
940 p
= connected
->destination
;
942 strncat(logbuf
, inet_ntop(p
->family
, &p
->u
.prefix
, buf
, BUFSIZ
),
943 BUFSIZ
- strlen(logbuf
));
945 zlog_info("%s", logbuf
);
948 /* Print if_addr structure. */
949 static void __attribute__((unused
))
950 nbr_connected_log(struct nbr_connected
*connected
, char *str
)
953 struct interface
*ifp
;
957 ifp
= connected
->ifp
;
958 p
= connected
->address
;
960 snprintf(logbuf
, BUFSIZ
, "%s interface %s %s %s/%d ", str
, ifp
->name
,
961 prefix_family_str(p
),
962 inet_ntop(p
->family
, &p
->u
.prefix
, buf
, BUFSIZ
), p
->prefixlen
);
964 zlog_info("%s", logbuf
);
967 /* If two connected address has same prefix return 1. */
968 static int connected_same_prefix(struct prefix
*p1
, struct prefix
*p2
)
970 if (p1
->family
== p2
->family
) {
971 if (p1
->family
== AF_INET
972 && IPV4_ADDR_SAME(&p1
->u
.prefix4
, &p2
->u
.prefix4
))
974 if (p1
->family
== AF_INET6
975 && IPV6_ADDR_SAME(&p1
->u
.prefix6
, &p2
->u
.prefix6
))
981 /* count the number of connected addresses that are in the given family */
982 unsigned int connected_count_by_family(struct interface
*ifp
, int family
)
984 struct listnode
*cnode
;
985 struct connected
*connected
;
986 unsigned int cnt
= 0;
988 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, connected
))
989 if (connected
->address
->family
== family
)
995 struct connected
*connected_lookup_prefix_exact(struct interface
*ifp
,
998 struct listnode
*node
;
999 struct listnode
*next
;
1000 struct connected
*ifc
;
1002 for (node
= listhead(ifp
->connected
); node
; node
= next
) {
1003 ifc
= listgetdata(node
);
1006 if (connected_same_prefix(ifc
->address
, p
))
1012 struct connected
*connected_delete_by_prefix(struct interface
*ifp
,
1015 struct listnode
*node
;
1016 struct listnode
*next
;
1017 struct connected
*ifc
;
1019 /* In case of same prefix come, replace it with new one. */
1020 for (node
= listhead(ifp
->connected
); node
; node
= next
) {
1021 ifc
= listgetdata(node
);
1024 if (connected_same_prefix(ifc
->address
, p
)) {
1025 listnode_delete(ifp
->connected
, ifc
);
1032 /* Find the address on our side that will be used when packets
1034 struct connected
*connected_lookup_prefix(struct interface
*ifp
,
1035 struct prefix
*addr
)
1037 struct listnode
*cnode
;
1038 struct connected
*c
;
1039 struct connected
*match
;
1043 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, c
)) {
1044 if (c
->address
&& (c
->address
->family
== addr
->family
)
1045 && prefix_match(CONNECTED_PREFIX(c
), addr
)
1047 || (c
->address
->prefixlen
> match
->address
->prefixlen
)))
1053 struct connected
*connected_add_by_prefix(struct interface
*ifp
,
1055 struct prefix
*destination
)
1057 struct connected
*ifc
;
1059 /* Allocate new connected address. */
1060 ifc
= connected_new();
1063 /* Fetch interface address */
1064 ifc
->address
= prefix_new();
1065 memcpy(ifc
->address
, p
, sizeof(struct prefix
));
1067 /* Fetch dest address */
1069 ifc
->destination
= prefix_new();
1070 memcpy(ifc
->destination
, destination
, sizeof(struct prefix
));
1073 /* Add connected address to the interface. */
1074 listnode_add(ifp
->connected
, ifc
);
1078 struct connected
*connected_get_linklocal(struct interface
*ifp
)
1081 struct connected
*c
= NULL
;
1083 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, n
, c
)) {
1084 if (c
->address
->family
== AF_INET6
1085 && IN6_IS_ADDR_LINKLOCAL(&c
->address
->u
.prefix6
))
1091 #if 0 /* this route_table of struct connected's is unused \
1092 * however, it would be good to use a route_table rather than \
1095 /* Interface looking up by interface's address. */
1096 /* Interface's IPv4 address reverse lookup table. */
1097 struct route_table
*ifaddr_ipv4_table
;
1098 /* struct route_table *ifaddr_ipv6_table; */
1101 ifaddr_ipv4_add (struct in_addr
*ifaddr
, struct interface
*ifp
)
1103 struct route_node
*rn
;
1104 struct prefix_ipv4 p
;
1107 p
.prefixlen
= IPV4_MAX_PREFIXLEN
;
1110 rn
= route_node_get (ifaddr_ipv4_table
, (struct prefix
*) &p
);
1113 route_unlock_node (rn
);
1114 zlog_info ("ifaddr_ipv4_add(): address %s is already added",
1115 inet_ntoa (*ifaddr
));
1122 ifaddr_ipv4_delete (struct in_addr
*ifaddr
, struct interface
*ifp
)
1124 struct route_node
*rn
;
1125 struct prefix_ipv4 p
;
1128 p
.prefixlen
= IPV4_MAX_PREFIXLEN
;
1131 rn
= route_node_lookup (ifaddr_ipv4_table
, (struct prefix
*) &p
);
1134 zlog_info ("ifaddr_ipv4_delete(): can't find address %s",
1135 inet_ntoa (*ifaddr
));
1139 route_unlock_node (rn
);
1140 route_unlock_node (rn
);
1143 /* Lookup interface by interface's IP address or interface index. */
1144 static struct interface
*
1145 ifaddr_ipv4_lookup (struct in_addr
*addr
, ifindex_t ifindex
)
1147 struct prefix_ipv4 p
;
1148 struct route_node
*rn
;
1149 struct interface
*ifp
;
1154 p
.prefixlen
= IPV4_MAX_PREFIXLEN
;
1157 rn
= route_node_lookup (ifaddr_ipv4_table
, (struct prefix
*) &p
);
1162 route_unlock_node (rn
);
1166 return if_lookup_by_index(ifindex
, VRF_DEFAULT
);
1168 #endif /* ifaddr_ipv4_table */
1170 void if_terminate(struct vrf
*vrf
)
1172 struct interface
*ifp
;
1174 while (!RB_EMPTY(if_name_head
, &vrf
->ifaces_by_name
)) {
1175 ifp
= RB_ROOT(if_name_head
, &vrf
->ifaces_by_name
);
1178 ifp
->node
->info
= NULL
;
1179 route_unlock_node(ifp
->node
);
1185 const char *if_link_type_str(enum zebra_link_type llt
)
1188 #define llts(T,S) case (T): return (S)
1189 llts(ZEBRA_LLT_UNKNOWN
, "Unknown");
1190 llts(ZEBRA_LLT_ETHER
, "Ethernet");
1191 llts(ZEBRA_LLT_EETHER
, "Experimental Ethernet");
1192 llts(ZEBRA_LLT_AX25
, "AX.25 Level 2");
1193 llts(ZEBRA_LLT_PRONET
, "PROnet token ring");
1194 llts(ZEBRA_LLT_IEEE802
, "IEEE 802.2 Ethernet/TR/TB");
1195 llts(ZEBRA_LLT_ARCNET
, "ARCnet");
1196 llts(ZEBRA_LLT_APPLETLK
, "AppleTalk");
1197 llts(ZEBRA_LLT_DLCI
, "Frame Relay DLCI");
1198 llts(ZEBRA_LLT_ATM
, "ATM");
1199 llts(ZEBRA_LLT_METRICOM
, "Metricom STRIP");
1200 llts(ZEBRA_LLT_IEEE1394
, "IEEE 1394 IPv4");
1201 llts(ZEBRA_LLT_EUI64
, "EUI-64");
1202 llts(ZEBRA_LLT_INFINIBAND
, "InfiniBand");
1203 llts(ZEBRA_LLT_SLIP
, "SLIP");
1204 llts(ZEBRA_LLT_CSLIP
, "Compressed SLIP");
1205 llts(ZEBRA_LLT_SLIP6
, "SLIPv6");
1206 llts(ZEBRA_LLT_CSLIP6
, "Compressed SLIPv6");
1207 llts(ZEBRA_LLT_ROSE
, "ROSE packet radio");
1208 llts(ZEBRA_LLT_X25
, "CCITT X.25");
1209 llts(ZEBRA_LLT_PPP
, "PPP");
1210 llts(ZEBRA_LLT_CHDLC
, "Cisco HDLC");
1211 llts(ZEBRA_LLT_RAWHDLC
, "Raw HDLC");
1212 llts(ZEBRA_LLT_LAPB
, "LAPB");
1213 llts(ZEBRA_LLT_IPIP
, "IPIP Tunnel");
1214 llts(ZEBRA_LLT_IPIP6
, "IPIP6 Tunnel");
1215 llts(ZEBRA_LLT_FRAD
, "FRAD");
1216 llts(ZEBRA_LLT_SKIP
, "SKIP vif");
1217 llts(ZEBRA_LLT_LOOPBACK
, "Loopback");
1218 llts(ZEBRA_LLT_LOCALTLK
, "Localtalk");
1219 llts(ZEBRA_LLT_FDDI
, "FDDI");
1220 llts(ZEBRA_LLT_SIT
, "IPv6-in-IPv4 SIT");
1221 llts(ZEBRA_LLT_IPDDP
, "IP-in-DDP tunnel");
1222 llts(ZEBRA_LLT_IPGRE
, "GRE over IP");
1223 llts(ZEBRA_LLT_PIMREG
, "PIMSM registration");
1224 llts(ZEBRA_LLT_HIPPI
, "HiPPI");
1225 llts(ZEBRA_LLT_IRDA
, "IrDA");
1226 llts(ZEBRA_LLT_FCPP
, "Fibre-Channel PtP");
1227 llts(ZEBRA_LLT_FCAL
, "Fibre-Channel Arbitrated Loop");
1228 llts(ZEBRA_LLT_FCPL
, "Fibre-Channel Public Loop");
1229 llts(ZEBRA_LLT_FCFABRIC
, "Fibre-Channel Fabric");
1230 llts(ZEBRA_LLT_IEEE802_TR
, "IEEE 802.2 Token Ring");
1231 llts(ZEBRA_LLT_IEEE80211
, "IEEE 802.11");
1232 llts(ZEBRA_LLT_IEEE80211_RADIOTAP
, "IEEE 802.11 Radiotap");
1233 llts(ZEBRA_LLT_IEEE802154
, "IEEE 802.15.4");
1234 llts(ZEBRA_LLT_IEEE802154_PHY
, "IEEE 802.15.4 Phy");
1236 flog_err(EC_LIB_DEVELOPMENT
, "Unknown value %d", llt
);
1237 return "Unknown type!";
1243 struct if_link_params
*if_link_params_get(struct interface
*ifp
)
1247 if (ifp
->link_params
!= NULL
)
1248 return ifp
->link_params
;
1250 struct if_link_params
*iflp
=
1251 XCALLOC(MTYPE_IF_LINK_PARAMS
, sizeof(struct if_link_params
));
1255 /* Set TE metric equal to standard metric */
1256 iflp
->te_metric
= ifp
->metric
;
1258 /* Compute default bandwidth based on interface */
1260 ((ifp
->bandwidth
? ifp
->bandwidth
: DEFAULT_BANDWIDTH
)
1261 * TE_KILO_BIT
/ TE_BYTE
);
1263 /* Set Max, Reservable and Unreserved Bandwidth */
1264 iflp
->max_bw
= iflp
->default_bw
;
1265 iflp
->max_rsv_bw
= iflp
->default_bw
;
1266 for (i
= 0; i
< MAX_CLASS_TYPE
; i
++)
1267 iflp
->unrsv_bw
[i
] = iflp
->default_bw
;
1269 /* Update Link parameters status */
1271 LP_TE_METRIC
| LP_MAX_BW
| LP_MAX_RSV_BW
| LP_UNRSV_BW
;
1273 /* Finally attach newly created Link Parameters */
1274 ifp
->link_params
= iflp
;
1279 void if_link_params_free(struct interface
*ifp
)
1281 if (ifp
->link_params
== NULL
)
1283 XFREE(MTYPE_IF_LINK_PARAMS
, ifp
->link_params
);
1286 /* ----------- CLI commands ----------- */
1289 * XPath: /frr-interface:lib/interface
1291 DEFPY_NOSH (interface
,
1293 "interface IFNAME [vrf NAME$vrf_name]",
1294 "Select an interface to configure\n"
1295 "Interface's name\n"
1298 char xpath_list
[XPATH_MAXLEN
];
1300 struct interface
*ifp
;
1304 vrf_name
= VRF_DEFAULT_NAME
;
1307 * This command requires special handling to maintain backward
1308 * compatibility. If a VRF name is not specified, it means we're willing
1309 * to accept any interface with the given name on any VRF. If no
1310 * interface is found, then a new one should be created on the default
1313 VRF_GET_ID(vrf_id
, vrf_name
, false);
1314 ifp
= if_lookup_by_name_all_vrf(ifname
);
1315 if (ifp
&& ifp
->vrf_id
!= vrf_id
) {
1319 * Special case 1: a VRF name was specified, but the found
1320 * interface is associated to different VRF. Reject the command.
1322 if (vrf_id
!= VRF_DEFAULT
) {
1323 vty_out(vty
, "%% interface %s not in %s vrf\n", ifname
,
1325 return CMD_WARNING_CONFIG_FAILED
;
1329 * Special case 2: a VRF name was *not* specified, and the found
1330 * interface is associated to a VRF other than the default one.
1331 * Update vrf_id and vrf_name to account for that.
1333 vrf
= vrf_lookup_by_id(ifp
->vrf_id
);
1335 vrf_id
= ifp
->vrf_id
;
1336 vrf_name
= vrf
->name
;
1339 snprintf(xpath_list
, sizeof(xpath_list
),
1340 "/frr-interface:lib/interface[name='%s'][vrf='%s']", ifname
,
1343 nb_cli_enqueue_change(vty
, ".", NB_OP_CREATE
, NULL
);
1344 ret
= nb_cli_apply_changes(vty
, xpath_list
);
1345 if (ret
== CMD_SUCCESS
) {
1346 VTY_PUSH_XPATH(INTERFACE_NODE
, xpath_list
);
1349 * For backward compatibility with old commands we still need
1350 * to use the qobj infrastructure. This can be removed once
1351 * all interface-level commands are converted to the new
1354 ifp
= if_lookup_by_name(ifname
, vrf_id
);
1356 VTY_PUSH_CONTEXT(INTERFACE_NODE
, ifp
);
1362 DEFPY (no_interface
,
1364 "no interface IFNAME [vrf NAME$vrf_name]",
1366 "Delete a pseudo interface's configuration\n"
1367 "Interface's name\n"
1371 vrf_name
= VRF_DEFAULT_NAME
;
1373 nb_cli_enqueue_change(vty
, ".", NB_OP_DESTROY
, NULL
);
1375 return nb_cli_apply_changes(
1376 vty
, "/frr-interface:lib/interface[name='%s'][vrf='%s']",
1380 static void cli_show_interface(struct vty
*vty
, struct lyd_node
*dnode
,
1385 vrf
= yang_dnode_get_string(dnode
, "./vrf");
1387 vty_out(vty
, "!\n");
1388 vty_out(vty
, "interface %s", yang_dnode_get_string(dnode
, "./name"));
1389 if (!strmatch(vrf
, VRF_DEFAULT_NAME
))
1390 vty_out(vty
, " vrf %s", vrf
);
1395 * XPath: /frr-interface:lib/interface/description
1397 DEFPY (interface_desc
,
1399 "description LINE...",
1400 "Interface specific description\n"
1401 "Characters describing this interface\n")
1406 desc
= argv_concat(argv
, argc
, 1);
1407 nb_cli_enqueue_change(vty
, "./description", NB_OP_MODIFY
, desc
);
1408 ret
= nb_cli_apply_changes(vty
, NULL
);
1409 XFREE(MTYPE_TMP
, desc
);
1414 DEFPY (no_interface_desc
,
1415 no_interface_desc_cmd
,
1418 "Interface specific description\n")
1420 nb_cli_enqueue_change(vty
, "./description", NB_OP_DESTROY
, NULL
);
1422 return nb_cli_apply_changes(vty
, NULL
);
1425 static void cli_show_interface_desc(struct vty
*vty
, struct lyd_node
*dnode
,
1428 vty_out(vty
, " description %s\n", yang_dnode_get_string(dnode
, NULL
));
1431 /* Interface autocomplete. */
1432 static void if_autocomplete(vector comps
, struct cmd_token
*token
)
1434 struct interface
*ifp
;
1437 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
1438 FOR_ALL_INTERFACES (vrf
, ifp
) {
1439 vector_set(comps
, XSTRDUP(MTYPE_COMPLETION
, ifp
->name
));
1444 static const struct cmd_variable_handler if_var_handlers
[] = {
1445 {/* "interface NAME" */
1446 .varname
= "interface",
1447 .completions
= if_autocomplete
},
1448 {.tokenname
= "IFNAME", .completions
= if_autocomplete
},
1449 {.tokenname
= "INTERFACE", .completions
= if_autocomplete
},
1450 {.completions
= NULL
}};
1452 void if_cmd_init(void)
1454 cmd_variable_handler_register(if_var_handlers
);
1456 install_element(CONFIG_NODE
, &interface_cmd
);
1457 install_element(CONFIG_NODE
, &no_interface_cmd
);
1459 install_default(INTERFACE_NODE
);
1460 install_element(INTERFACE_NODE
, &interface_desc_cmd
);
1461 install_element(INTERFACE_NODE
, &no_interface_desc_cmd
);
1464 void if_zapi_callbacks(int (*create
)(struct interface
*ifp
),
1465 int (*up
)(struct interface
*ifp
),
1466 int (*down
)(struct interface
*ifp
),
1467 int (*destroy
)(struct interface
*ifp
))
1469 ifp_master
.create_hook
= create
;
1470 ifp_master
.up_hook
= up
;
1471 ifp_master
.down_hook
= down
;
1472 ifp_master
.destroy_hook
= destroy
;
1475 /* ------- Northbound callbacks ------- */
1478 * XPath: /frr-interface:lib/interface
1480 static int lib_interface_create(enum nb_event event
,
1481 const struct lyd_node
*dnode
,
1482 union nb_resource
*resource
)
1485 const char *vrfname
;
1487 struct interface
*ifp
;
1489 ifname
= yang_dnode_get_string(dnode
, "./name");
1490 vrfname
= yang_dnode_get_string(dnode
, "./vrf");
1493 case NB_EV_VALIDATE
:
1494 vrf
= vrf_lookup_by_name(vrfname
);
1496 zlog_warn("%s: VRF %s doesn't exist", __func__
,
1498 return NB_ERR_VALIDATION
;
1500 if (vrf
->vrf_id
== VRF_UNKNOWN
) {
1501 zlog_warn("%s: VRF %s is not active", __func__
,
1503 return NB_ERR_VALIDATION
;
1506 /* if VRF is netns or not yet known - init for instance
1507 * then assumption is that passed config is exact
1508 * then the user intent was not to use an other iface
1510 if (vrf_get_backend() == VRF_BACKEND_VRF_LITE
) {
1511 ifp
= if_lookup_by_name_all_vrf(ifname
);
1512 if (ifp
&& ifp
->vrf_id
!= vrf
->vrf_id
) {
1514 "%s: interface %s already exists in another VRF",
1515 __func__
, ifp
->name
);
1516 return NB_ERR_VALIDATION
;
1524 vrf
= vrf_lookup_by_name(vrfname
);
1527 ifp
= if_sunwzebra_get(ifname
, vrf
->vrf_id
);
1529 ifp
= if_get_by_name(ifname
, vrf
->vrf_id
);
1530 #endif /* SUNOS_5 */
1532 ifp
->configured
= true;
1533 nb_running_set_entry(dnode
, ifp
);
1540 static int lib_interface_destroy(enum nb_event event
,
1541 const struct lyd_node
*dnode
)
1543 struct interface
*ifp
;
1547 case NB_EV_VALIDATE
:
1548 ifp
= nb_running_get_entry(dnode
, NULL
, true);
1549 if (CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
1550 zlog_warn("%s: only inactive interfaces can be deleted",
1552 return NB_ERR_VALIDATION
;
1559 ifp
= nb_running_unset_entry(dnode
);
1561 ifp
->configured
= false;
1570 * XPath: /frr-interface:lib/interface
1572 static const void *lib_interface_get_next(const void *parent_list_entry
,
1573 const void *list_entry
)
1576 struct interface
*pif
= (struct interface
*)list_entry
;
1578 if (list_entry
== NULL
) {
1579 vrf
= RB_MIN(vrf_name_head
, &vrfs_by_name
);
1581 pif
= RB_MIN(if_name_head
, &vrf
->ifaces_by_name
);
1583 vrf
= vrf_lookup_by_id(pif
->vrf_id
);
1584 pif
= RB_NEXT(if_name_head
, pif
);
1585 /* if no more interfaces, switch to next vrf */
1586 while (pif
== NULL
) {
1587 vrf
= RB_NEXT(vrf_name_head
, vrf
);
1590 pif
= RB_MIN(if_name_head
, &vrf
->ifaces_by_name
);
1597 static int lib_interface_get_keys(const void *list_entry
,
1598 struct yang_list_keys
*keys
)
1600 const struct interface
*ifp
= list_entry
;
1602 struct vrf
*vrf
= vrf_lookup_by_id(ifp
->vrf_id
);
1607 strlcpy(keys
->key
[0], ifp
->name
, sizeof(keys
->key
[0]));
1608 strlcpy(keys
->key
[1], vrf
->name
, sizeof(keys
->key
[1]));
1613 static const void *lib_interface_lookup_entry(const void *parent_list_entry
,
1614 const struct yang_list_keys
*keys
)
1616 const char *ifname
= keys
->key
[0];
1617 const char *vrfname
= keys
->key
[1];
1618 struct vrf
*vrf
= vrf_lookup_by_name(vrfname
);
1620 return vrf
? if_lookup_by_name(ifname
, vrf
->vrf_id
) : NULL
;
1624 * XPath: /frr-interface:lib/interface/description
1626 static int lib_interface_description_modify(enum nb_event event
,
1627 const struct lyd_node
*dnode
,
1628 union nb_resource
*resource
)
1630 struct interface
*ifp
;
1631 const char *description
;
1633 if (event
!= NB_EV_APPLY
)
1636 ifp
= nb_running_get_entry(dnode
, NULL
, true);
1637 XFREE(MTYPE_TMP
, ifp
->desc
);
1638 description
= yang_dnode_get_string(dnode
, NULL
);
1639 ifp
->desc
= XSTRDUP(MTYPE_TMP
, description
);
1644 static int lib_interface_description_destroy(enum nb_event event
,
1645 const struct lyd_node
*dnode
)
1647 struct interface
*ifp
;
1649 if (event
!= NB_EV_APPLY
)
1652 ifp
= nb_running_get_entry(dnode
, NULL
, true);
1653 XFREE(MTYPE_TMP
, ifp
->desc
);
1658 /* clang-format off */
1660 #if defined(__GNUC__) && ((__GNUC__ - 0) < 5) && !defined(__clang__)
1661 /* gcc versions before 5.x miscalculate the size for structs with variable
1662 * length arrays (they just count it as size 0)
1664 struct frr_yang_module_info_size3
{
1665 /* YANG module name. */
1668 /* Northbound callbacks. */
1670 /* Data path of this YANG node. */
1673 /* Callbacks implemented for this node. */
1674 struct nb_callbacks cbs
;
1676 /* Priority - lower priorities are processed first. */
1681 const struct frr_yang_module_info_size3 frr_interface_info_size3
asm("frr_interface_info") = {
1683 const struct frr_yang_module_info frr_interface_info
= {
1685 .name
= "frr-interface",
1688 .xpath
= "/frr-interface:lib/interface",
1690 .create
= lib_interface_create
,
1691 .destroy
= lib_interface_destroy
,
1692 .cli_show
= cli_show_interface
,
1693 .get_next
= lib_interface_get_next
,
1694 .get_keys
= lib_interface_get_keys
,
1695 .lookup_entry
= lib_interface_lookup_entry
,
1699 .xpath
= "/frr-interface:lib/interface/description",
1701 .modify
= lib_interface_description_modify
,
1702 .destroy
= lib_interface_description_destroy
,
1703 .cli_show
= cli_show_interface_desc
,