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 void if_set_name(struct interface
*ifp
, const char *name
);
49 static struct interface
*if_lookup_by_ifindex(ifindex_t ifindex
,
51 static struct interface
*if_lookup_by_index_all_vrf(ifindex_t ifindex
);
52 static int if_cmp_func(const struct interface
*, const struct interface
*);
53 static int if_cmp_index_func(const struct interface
*ifp1
,
54 const struct interface
*ifp2
);
55 RB_GENERATE(if_name_head
, interface
, name_entry
, if_cmp_func
);
56 RB_GENERATE(if_index_head
, interface
, index_entry
, if_cmp_index_func
);
58 DEFINE_QOBJ_TYPE(interface
);
60 DEFINE_HOOK(if_add
, (struct interface
* ifp
), (ifp
));
61 DEFINE_KOOH(if_del
, (struct interface
* ifp
), (ifp
));
63 static struct interface_master
{
64 int (*create_hook
)(struct interface
*ifp
);
65 int (*up_hook
)(struct interface
*ifp
);
66 int (*down_hook
)(struct interface
*ifp
);
67 int (*destroy_hook
)(struct interface
*ifp
);
68 } ifp_master
= { 0, };
70 /* Compare interface names, returning an integer greater than, equal to, or
71 * less than 0, (following the strcmp convention), according to the
72 * relationship between ifp1 and ifp2. Interface names consist of an
73 * alphabetic prefix and a numeric suffix. The primary sort key is
74 * lexicographic by name, and then numeric by number. No number sorts
75 * before all numbers. Examples: de0 < de1, de100 < fxp0 < xl0, devpty <
78 int if_cmp_name_func(const char *p1
, const char *p2
)
85 /* look up to any number */
86 l1
= strcspn(p1
, "0123456789");
87 l2
= strcspn(p2
, "0123456789");
89 /* name lengths are different -> compare names */
91 return (strcmp(p1
, p2
));
93 /* Note that this relies on all numbers being less than all
97 res
= strncmp(p1
, p2
, l1
);
99 /* names are different -> compare them */
103 /* with identical name part, go to numeric part */
114 x1
= strtol(p1
, (char **)&p1
, 10);
115 x2
= strtol(p2
, (char **)&p2
, 10);
117 /* let's compare numbers now */
123 /* numbers were equal, lets do it again..
124 (it happens with name like "eth123.456:789") */
133 static int if_cmp_func(const struct interface
*ifp1
,
134 const struct interface
*ifp2
)
136 return if_cmp_name_func(ifp1
->name
, ifp2
->name
);
139 static int if_cmp_index_func(const struct interface
*ifp1
,
140 const struct interface
*ifp2
)
142 if (ifp1
->ifindex
== ifp2
->ifindex
)
144 else if (ifp1
->ifindex
> ifp2
->ifindex
)
150 static void ifp_connected_free(void *arg
)
152 struct connected
*c
= arg
;
157 /* Create new interface structure. */
158 static struct interface
*if_new(struct vrf
*vrf
)
160 struct interface
*ifp
;
164 ifp
= XCALLOC(MTYPE_IF
, sizeof(struct interface
));
166 ifp
->ifindex
= IFINDEX_INTERNAL
;
171 ifp
->connected
= list_new();
172 ifp
->connected
->del
= ifp_connected_free
;
174 ifp
->nbr_connected
= list_new();
175 ifp
->nbr_connected
->del
= (void (*)(void *))nbr_connected_free
;
177 /* Enable Link-detection by default */
178 SET_FLAG(ifp
->status
, ZEBRA_INTERFACE_LINKDETECTION
);
180 QOBJ_REG(ifp
, interface
);
184 void if_new_via_zapi(struct interface
*ifp
)
186 if (ifp_master
.create_hook
)
187 (*ifp_master
.create_hook
)(ifp
);
190 void if_destroy_via_zapi(struct interface
*ifp
)
192 if (ifp_master
.destroy_hook
)
193 (*ifp_master
.destroy_hook
)(ifp
);
195 ifp
->oldifindex
= ifp
->ifindex
;
196 if_set_index(ifp
, IFINDEX_INTERNAL
);
198 if (!ifp
->configured
)
202 void if_up_via_zapi(struct interface
*ifp
)
204 if (ifp_master
.up_hook
)
205 (*ifp_master
.up_hook
)(ifp
);
208 void if_down_via_zapi(struct interface
*ifp
)
210 if (ifp_master
.down_hook
)
211 (*ifp_master
.down_hook
)(ifp
);
214 static struct interface
*if_create_name(const char *name
, struct vrf
*vrf
)
216 struct interface
*ifp
;
220 if_set_name(ifp
, name
);
222 hook_call(if_add
, ifp
);
226 /* Create new interface structure. */
227 void if_update_to_new_vrf(struct interface
*ifp
, vrf_id_t vrf_id
)
229 struct vrf
*old_vrf
, *vrf
;
231 /* remove interface from old master vrf list */
234 if (ifp
->name
[0] != '\0')
235 IFNAME_RB_REMOVE(old_vrf
, ifp
);
237 if (ifp
->ifindex
!= IFINDEX_INTERNAL
)
238 IFINDEX_RB_REMOVE(old_vrf
, ifp
);
240 vrf
= vrf_get(vrf_id
, NULL
);
243 if (ifp
->name
[0] != '\0')
244 IFNAME_RB_INSERT(vrf
, ifp
);
246 if (ifp
->ifindex
!= IFINDEX_INTERNAL
)
247 IFINDEX_RB_INSERT(vrf
, ifp
);
251 /* Delete interface structure. */
252 void if_delete_retain(struct interface
*ifp
)
254 hook_call(if_del
, ifp
);
257 /* Free connected address list */
258 list_delete_all_node(ifp
->connected
);
260 /* Free connected nbr address list */
261 list_delete_all_node(ifp
->nbr_connected
);
264 /* Delete and free interface structure. */
265 void if_delete(struct interface
**ifp
)
267 struct interface
*ptr
= *ifp
;
268 struct vrf
*vrf
= ptr
->vrf
;
270 IFNAME_RB_REMOVE(vrf
, ptr
);
271 if (ptr
->ifindex
!= IFINDEX_INTERNAL
)
272 IFINDEX_RB_REMOVE(vrf
, ptr
);
274 if_delete_retain(ptr
);
276 list_delete(&ptr
->connected
);
277 list_delete(&ptr
->nbr_connected
);
279 if_link_params_free(ptr
);
281 XFREE(MTYPE_TMP
, ptr
->desc
);
283 XFREE(MTYPE_IF
, ptr
);
287 /* Used only internally to check within VRF only */
288 static struct interface
*if_lookup_by_ifindex(ifindex_t ifindex
,
292 struct interface if_tmp
;
294 vrf
= vrf_lookup_by_id(vrf_id
);
298 if_tmp
.ifindex
= ifindex
;
299 return RB_FIND(if_index_head
, &vrf
->ifaces_by_index
, &if_tmp
);
302 /* Interface existence check by index. */
303 struct interface
*if_lookup_by_index(ifindex_t ifindex
, vrf_id_t vrf_id
)
305 switch (vrf_get_backend()) {
306 case VRF_BACKEND_UNKNOWN
:
307 case VRF_BACKEND_NETNS
:
308 return(if_lookup_by_ifindex(ifindex
, vrf_id
));
309 case VRF_BACKEND_VRF_LITE
:
310 return(if_lookup_by_index_all_vrf(ifindex
));
315 /* Interface existence check by index. */
316 struct interface
*if_vrf_lookup_by_index_next(ifindex_t ifindex
,
319 struct vrf
*vrf
= vrf_lookup_by_id(vrf_id
);
320 struct interface
*tmp_ifp
;
327 tmp_ifp
= RB_MIN(if_index_head
, &vrf
->ifaces_by_index
);
328 /* skip the vrf interface */
329 if (tmp_ifp
&& if_is_vrf(tmp_ifp
))
330 ifindex
= tmp_ifp
->ifindex
;
335 RB_FOREACH (tmp_ifp
, if_index_head
, &vrf
->ifaces_by_index
) {
337 /* skip the vrf interface */
338 if (tmp_ifp
&& if_is_vrf(tmp_ifp
))
343 if (tmp_ifp
->ifindex
== ifindex
)
349 const char *ifindex2ifname(ifindex_t ifindex
, vrf_id_t vrf_id
)
351 struct interface
*ifp
;
353 return ((ifp
= if_lookup_by_index(ifindex
, vrf_id
)) != NULL
)
358 ifindex_t
ifname2ifindex(const char *name
, vrf_id_t vrf_id
)
360 struct interface
*ifp
;
362 return ((ifp
= if_lookup_by_name(name
, vrf_id
)) != NULL
)
367 /* Interface existence check by interface name. */
368 struct interface
*if_lookup_by_name(const char *name
, vrf_id_t vrf_id
)
370 struct vrf
*vrf
= vrf_lookup_by_id(vrf_id
);
371 struct interface if_tmp
;
374 || strnlen(name
, INTERFACE_NAMSIZ
) == INTERFACE_NAMSIZ
)
377 strlcpy(if_tmp
.name
, name
, sizeof(if_tmp
.name
));
378 return RB_FIND(if_name_head
, &vrf
->ifaces_by_name
, &if_tmp
);
381 struct interface
*if_lookup_by_name_vrf(const char *name
, struct vrf
*vrf
)
383 struct interface if_tmp
;
385 if (!name
|| strnlen(name
, INTERFACE_NAMSIZ
) == INTERFACE_NAMSIZ
)
388 strlcpy(if_tmp
.name
, name
, sizeof(if_tmp
.name
));
389 return RB_FIND(if_name_head
, &vrf
->ifaces_by_name
, &if_tmp
);
392 static struct interface
*if_lookup_by_name_all_vrf(const char *name
)
395 struct interface
*ifp
;
397 if (!name
|| strnlen(name
, INTERFACE_NAMSIZ
) == INTERFACE_NAMSIZ
)
400 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
401 ifp
= if_lookup_by_name_vrf(name
, vrf
);
409 static struct interface
*if_lookup_by_index_all_vrf(ifindex_t ifindex
)
412 struct interface
*ifp
;
414 if (ifindex
== IFINDEX_INTERNAL
)
417 RB_FOREACH (vrf
, vrf_id_head
, &vrfs_by_id
) {
418 ifp
= if_lookup_by_ifindex(ifindex
, vrf
->vrf_id
);
426 /* Lookup interface by IP address.
428 * supersedes if_lookup_exact_address(), which didn't care about up/down
429 * state. but all users we have either only care if the address is local
430 * (=> use if_address_is_local() please), or care about UP interfaces before
433 * to accept only UP interfaces, check if_is_up() on the returned ifp.
435 struct interface
*if_lookup_address_local(const void *src
, int family
,
438 struct vrf
*vrf
= vrf_lookup_by_id(vrf_id
);
439 struct listnode
*cnode
;
440 struct interface
*ifp
, *best_down
= NULL
;
444 if (family
!= AF_INET
&& family
!= AF_INET6
)
447 FOR_ALL_INTERFACES (vrf
, ifp
) {
448 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, c
)) {
451 if (!p
|| p
->family
!= family
)
454 if (family
== AF_INET
) {
455 if (!IPV4_ADDR_SAME(&p
->u
.prefix4
,
456 (struct in_addr
*)src
))
458 } else if (family
== AF_INET6
) {
459 if (!IPV6_ADDR_SAME(&p
->u
.prefix6
,
460 (struct in6_addr
*)src
))
473 /* Lookup interface by IP address. */
474 struct connected
*if_lookup_address(const void *matchaddr
, int family
,
477 struct vrf
*vrf
= vrf_lookup_by_id(vrf_id
);
480 struct listnode
*cnode
;
481 struct interface
*ifp
;
483 struct connected
*match
;
485 if (family
== AF_INET
) {
486 addr
.family
= AF_INET
;
487 addr
.u
.prefix4
= *((struct in_addr
*)matchaddr
);
488 addr
.prefixlen
= IPV4_MAX_BITLEN
;
489 } else if (family
== AF_INET6
) {
490 addr
.family
= AF_INET6
;
491 addr
.u
.prefix6
= *((struct in6_addr
*)matchaddr
);
492 addr
.prefixlen
= IPV6_MAX_BITLEN
;
494 assert(!"Attempted lookup of family not supported");
498 FOR_ALL_INTERFACES (vrf
, ifp
) {
499 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, c
)) {
500 if (c
->address
&& (c
->address
->family
== AF_INET
)
501 && prefix_match(CONNECTED_PREFIX(c
), &addr
)
502 && (c
->address
->prefixlen
> bestlen
)) {
503 bestlen
= c
->address
->prefixlen
;
511 /* Lookup interface by prefix */
512 struct interface
*if_lookup_prefix(const struct prefix
*prefix
, vrf_id_t vrf_id
)
514 struct vrf
*vrf
= vrf_lookup_by_id(vrf_id
);
515 struct listnode
*cnode
;
516 struct interface
*ifp
;
519 FOR_ALL_INTERFACES (vrf
, ifp
) {
520 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, c
)) {
521 if (prefix_cmp(c
->address
, prefix
) == 0) {
529 size_t if_lookup_by_hwaddr(const uint8_t *hw_addr
, size_t addrsz
,
530 struct interface
***result
, vrf_id_t vrf_id
)
532 struct vrf
*vrf
= vrf_lookup_by_id(vrf_id
);
534 struct list
*rs
= list_new();
535 struct interface
*ifp
;
537 FOR_ALL_INTERFACES (vrf
, ifp
) {
538 if (ifp
->hw_addr_len
== (int)addrsz
539 && !memcmp(hw_addr
, ifp
->hw_addr
, addrsz
))
540 listnode_add(rs
, ifp
);
544 *result
= XCALLOC(MTYPE_TMP
,
545 sizeof(struct interface
*) * rs
->count
);
546 list_to_array(rs
, (void **)*result
, rs
->count
);
549 int count
= rs
->count
;
557 /* Get interface by name if given name interface doesn't exist create
559 struct interface
*if_get_by_name(const char *name
, vrf_id_t vrf_id
,
560 const char *vrf_name
)
562 struct interface
*ifp
= NULL
;
565 switch (vrf_get_backend()) {
566 case VRF_BACKEND_UNKNOWN
:
567 case VRF_BACKEND_NETNS
:
568 vrf
= vrf_get(vrf_id
, vrf_name
);
571 ifp
= if_lookup_by_name_vrf(name
, vrf
);
573 /* If it came from the kernel or by way of zclient,
574 * believe it and update the ifp accordingly.
576 if (ifp
->vrf
->vrf_id
!= vrf_id
&& vrf_id
!= VRF_UNKNOWN
)
577 if_update_to_new_vrf(ifp
, vrf_id
);
583 case VRF_BACKEND_VRF_LITE
:
584 ifp
= if_lookup_by_name_all_vrf(name
);
586 /* If it came from the kernel or by way of zclient,
587 * believe it and update the ifp accordingly.
589 if (ifp
->vrf
->vrf_id
!= vrf_id
&& vrf_id
!= VRF_UNKNOWN
)
590 if_update_to_new_vrf(ifp
, vrf_id
);
595 vrf
= vrf_get(vrf_id
, vrf_name
);
603 return if_create_name(name
, vrf
);
606 int if_set_index(struct interface
*ifp
, ifindex_t ifindex
)
608 if (ifp
->ifindex
== ifindex
)
612 * If there is already an interface with this ifindex, we will collide
613 * on insertion, so don't even try.
615 if (if_lookup_by_ifindex(ifindex
, ifp
->vrf
->vrf_id
))
618 if (ifp
->ifindex
!= IFINDEX_INTERNAL
)
619 IFINDEX_RB_REMOVE(ifp
->vrf
, ifp
);
621 ifp
->ifindex
= ifindex
;
623 if (ifp
->ifindex
!= IFINDEX_INTERNAL
) {
625 * This should never happen, since we checked if there was
626 * already an interface with the desired ifindex at the top of
627 * the function. Nevertheless.
629 if (IFINDEX_RB_INSERT(ifp
->vrf
, ifp
))
636 static void if_set_name(struct interface
*ifp
, const char *name
)
638 if (if_cmp_name_func(ifp
->name
, name
) == 0)
641 if (ifp
->name
[0] != '\0')
642 IFNAME_RB_REMOVE(ifp
->vrf
, ifp
);
644 strlcpy(ifp
->name
, name
, sizeof(ifp
->name
));
646 if (ifp
->name
[0] != '\0')
647 IFNAME_RB_INSERT(ifp
->vrf
, ifp
);
650 /* Does interface up ? */
651 int if_is_up(const struct interface
*ifp
)
653 return ifp
->flags
& IFF_UP
;
656 /* Is interface running? */
657 int if_is_running(const struct interface
*ifp
)
659 return ifp
->flags
& IFF_RUNNING
;
662 /* Is the interface operative, eg. either UP & RUNNING
663 or UP & !ZEBRA_INTERFACE_LINK_DETECTION and
664 if ptm checking is enabled, then ptm check has passed */
665 int if_is_operative(const struct interface
*ifp
)
667 return ((ifp
->flags
& IFF_UP
)
668 && (((ifp
->flags
& IFF_RUNNING
)
669 && (ifp
->ptm_status
|| !ifp
->ptm_enable
))
670 || !CHECK_FLAG(ifp
->status
,
671 ZEBRA_INTERFACE_LINKDETECTION
)));
674 /* Is the interface operative, eg. either UP & RUNNING
675 or UP & !ZEBRA_INTERFACE_LINK_DETECTION, without PTM check */
676 int if_is_no_ptm_operative(const struct interface
*ifp
)
678 return ((ifp
->flags
& IFF_UP
)
679 && ((ifp
->flags
& IFF_RUNNING
)
680 || !CHECK_FLAG(ifp
->status
,
681 ZEBRA_INTERFACE_LINKDETECTION
)));
684 /* Is this loopback interface ? */
685 int if_is_loopback_exact(const struct interface
*ifp
)
687 /* XXX: Do this better, eg what if IFF_WHATEVER means X on platform M
688 * but Y on platform N?
690 return (ifp
->flags
& (IFF_LOOPBACK
| IFF_NOXMIT
| IFF_VIRTUAL
));
693 /* Check interface is VRF */
694 int if_is_vrf(const struct interface
*ifp
)
696 return CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_VRF_LOOPBACK
);
699 /* Should this interface be treated as a loopback? */
700 bool if_is_loopback(const struct interface
*ifp
)
702 if (if_is_loopback_exact(ifp
) || if_is_vrf(ifp
))
708 /* Does this interface support broadcast ? */
709 int if_is_broadcast(const struct interface
*ifp
)
711 return ifp
->flags
& IFF_BROADCAST
;
714 /* Does this interface support broadcast ? */
715 int if_is_pointopoint(const struct interface
*ifp
)
717 return ifp
->flags
& IFF_POINTOPOINT
;
720 /* Does this interface support multicast ? */
721 int if_is_multicast(const struct interface
*ifp
)
723 return ifp
->flags
& IFF_MULTICAST
;
726 /* Printout flag information into log */
727 const char *if_flag_dump(unsigned long flag
)
730 static char logbuf
[BUFSIZ
];
732 #define IFF_OUT_LOG(X, STR) \
735 strlcat(logbuf, ",", sizeof(logbuf)); \
738 strlcat(logbuf, STR, sizeof(logbuf)); \
741 strlcpy(logbuf
, "<", BUFSIZ
);
742 IFF_OUT_LOG(IFF_UP
, "UP");
743 IFF_OUT_LOG(IFF_BROADCAST
, "BROADCAST");
744 IFF_OUT_LOG(IFF_DEBUG
, "DEBUG");
745 IFF_OUT_LOG(IFF_LOOPBACK
, "LOOPBACK");
746 IFF_OUT_LOG(IFF_POINTOPOINT
, "POINTOPOINT");
747 IFF_OUT_LOG(IFF_NOTRAILERS
, "NOTRAILERS");
748 IFF_OUT_LOG(IFF_RUNNING
, "RUNNING");
749 IFF_OUT_LOG(IFF_NOARP
, "NOARP");
750 IFF_OUT_LOG(IFF_PROMISC
, "PROMISC");
751 IFF_OUT_LOG(IFF_ALLMULTI
, "ALLMULTI");
752 IFF_OUT_LOG(IFF_OACTIVE
, "OACTIVE");
753 IFF_OUT_LOG(IFF_SIMPLEX
, "SIMPLEX");
754 IFF_OUT_LOG(IFF_LINK0
, "LINK0");
755 IFF_OUT_LOG(IFF_LINK1
, "LINK1");
756 IFF_OUT_LOG(IFF_LINK2
, "LINK2");
757 IFF_OUT_LOG(IFF_MULTICAST
, "MULTICAST");
758 IFF_OUT_LOG(IFF_NOXMIT
, "NOXMIT");
759 IFF_OUT_LOG(IFF_NORTEXCH
, "NORTEXCH");
760 IFF_OUT_LOG(IFF_VIRTUAL
, "VIRTUAL");
761 IFF_OUT_LOG(IFF_IPV4
, "IPv4");
762 IFF_OUT_LOG(IFF_IPV6
, "IPv6");
764 strlcat(logbuf
, ">", sizeof(logbuf
));
771 static void if_dump(const struct interface
*ifp
)
773 struct listnode
*node
;
774 struct connected
*c
__attribute__((unused
));
776 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, c
))
778 "Interface %s vrf %s(%u) index %d metric %d mtu %d mtu6 %d %s",
779 ifp
->name
, ifp
->vrf
->name
, ifp
->vrf
->vrf_id
,
780 ifp
->ifindex
, ifp
->metric
, ifp
->mtu
, ifp
->mtu6
,
781 if_flag_dump(ifp
->flags
));
784 /* Interface printing for all interface. */
785 void if_dump_all(void)
790 RB_FOREACH (vrf
, vrf_id_head
, &vrfs_by_id
)
791 FOR_ALL_INTERFACES (vrf
, ifp
)
795 /* Allocate connected structure. */
796 struct connected
*connected_new(void)
798 return XCALLOC(MTYPE_CONNECTED
, sizeof(struct connected
));
801 /* Allocate nbr connected structure. */
802 struct nbr_connected
*nbr_connected_new(void)
804 return XCALLOC(MTYPE_NBR_CONNECTED
, sizeof(struct nbr_connected
));
807 /* Free connected structure. */
808 void connected_free(struct connected
**connected
)
810 struct connected
*ptr
= *connected
;
812 prefix_free(&ptr
->address
);
813 prefix_free(&ptr
->destination
);
815 XFREE(MTYPE_CONNECTED_LABEL
, ptr
->label
);
817 XFREE(MTYPE_CONNECTED
, ptr
);
821 /* Free nbr connected structure. */
822 void nbr_connected_free(struct nbr_connected
*connected
)
824 if (connected
->address
)
825 prefix_free(&connected
->address
);
827 XFREE(MTYPE_NBR_CONNECTED
, connected
);
830 /* If same interface nbr address already exists... */
831 struct nbr_connected
*nbr_connected_check(struct interface
*ifp
,
834 struct nbr_connected
*ifc
;
835 struct listnode
*node
;
837 for (ALL_LIST_ELEMENTS_RO(ifp
->nbr_connected
, node
, ifc
))
838 if (prefix_same(ifc
->address
, p
))
844 /* Print if_addr structure. */
845 static void __attribute__((unused
))
846 connected_log(struct connected
*connected
, char *str
)
849 struct interface
*ifp
;
853 ifp
= connected
->ifp
;
854 p
= connected
->address
;
856 snprintf(logbuf
, sizeof(logbuf
), "%s interface %s vrf %s(%u) %s %pFX ",
857 str
, ifp
->name
, ifp
->vrf
->name
, ifp
->vrf
->vrf_id
,
858 prefix_family_str(p
), p
);
860 p
= connected
->destination
;
862 strlcat(logbuf
, inet_ntop(p
->family
, &p
->u
.prefix
, buf
, BUFSIZ
),
865 zlog_info("%s", logbuf
);
868 /* Print if_addr structure. */
869 static void __attribute__((unused
))
870 nbr_connected_log(struct nbr_connected
*connected
, char *str
)
873 struct interface
*ifp
;
876 ifp
= connected
->ifp
;
877 p
= connected
->address
;
879 snprintf(logbuf
, sizeof(logbuf
), "%s interface %s %s %pFX ", str
,
880 ifp
->name
, prefix_family_str(p
), p
);
882 zlog_info("%s", logbuf
);
885 /* If two connected address has same prefix return 1. */
886 static int connected_same_prefix(const struct prefix
*p1
,
887 const struct prefix
*p2
)
889 if (p1
->family
== p2
->family
) {
890 if (p1
->family
== AF_INET
891 && IPV4_ADDR_SAME(&p1
->u
.prefix4
, &p2
->u
.prefix4
))
893 if (p1
->family
== AF_INET6
894 && IPV6_ADDR_SAME(&p1
->u
.prefix6
, &p2
->u
.prefix6
))
900 /* count the number of connected addresses that are in the given family */
901 unsigned int connected_count_by_family(struct interface
*ifp
, int family
)
903 struct listnode
*cnode
;
904 struct connected
*connected
;
905 unsigned int cnt
= 0;
907 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, connected
))
908 if (connected
->address
->family
== family
)
914 struct connected
*connected_lookup_prefix_exact(struct interface
*ifp
,
915 const struct prefix
*p
)
917 struct listnode
*node
;
918 struct listnode
*next
;
919 struct connected
*ifc
;
921 for (node
= listhead(ifp
->connected
); node
; node
= next
) {
922 ifc
= listgetdata(node
);
925 if (connected_same_prefix(ifc
->address
, p
))
931 struct connected
*connected_delete_by_prefix(struct interface
*ifp
,
934 struct listnode
*node
;
935 struct listnode
*next
;
936 struct connected
*ifc
;
938 /* In case of same prefix come, replace it with new one. */
939 for (node
= listhead(ifp
->connected
); node
; node
= next
) {
940 ifc
= listgetdata(node
);
943 if (connected_same_prefix(ifc
->address
, p
)) {
944 listnode_delete(ifp
->connected
, ifc
);
951 /* Find the address on our side that will be used when packets
953 struct connected
*connected_lookup_prefix(struct interface
*ifp
,
954 const struct prefix
*addr
)
956 struct listnode
*cnode
;
958 struct connected
*match
;
962 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, cnode
, c
)) {
963 if (c
->address
&& (c
->address
->family
== addr
->family
)
964 && prefix_match(CONNECTED_PREFIX(c
), addr
)
966 || (c
->address
->prefixlen
> match
->address
->prefixlen
)))
972 struct connected
*connected_add_by_prefix(struct interface
*ifp
,
974 struct prefix
*destination
)
976 struct connected
*ifc
;
978 /* Allocate new connected address. */
979 ifc
= connected_new();
982 /* Fetch interface address */
983 ifc
->address
= prefix_new();
984 memcpy(ifc
->address
, p
, sizeof(struct prefix
));
986 /* Fetch dest address */
988 ifc
->destination
= prefix_new();
989 memcpy(ifc
->destination
, destination
, sizeof(struct prefix
));
992 /* Add connected address to the interface. */
993 listnode_add(ifp
->connected
, ifc
);
997 struct connected
*connected_get_linklocal(struct interface
*ifp
)
1000 struct connected
*c
= NULL
;
1002 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, n
, c
)) {
1003 if (c
->address
->family
== AF_INET6
1004 && IN6_IS_ADDR_LINKLOCAL(&c
->address
->u
.prefix6
))
1010 void if_terminate(struct vrf
*vrf
)
1012 struct interface
*ifp
;
1014 while (!RB_EMPTY(if_name_head
, &vrf
->ifaces_by_name
)) {
1015 ifp
= RB_ROOT(if_name_head
, &vrf
->ifaces_by_name
);
1018 ifp
->node
->info
= NULL
;
1019 route_unlock_node(ifp
->node
);
1025 const char *if_link_type_str(enum zebra_link_type llt
)
1028 #define llts(T,S) case (T): return (S)
1029 llts(ZEBRA_LLT_UNKNOWN
, "Unknown");
1030 llts(ZEBRA_LLT_ETHER
, "Ethernet");
1031 llts(ZEBRA_LLT_EETHER
, "Experimental Ethernet");
1032 llts(ZEBRA_LLT_AX25
, "AX.25 Level 2");
1033 llts(ZEBRA_LLT_PRONET
, "PROnet token ring");
1034 llts(ZEBRA_LLT_IEEE802
, "IEEE 802.2 Ethernet/TR/TB");
1035 llts(ZEBRA_LLT_ARCNET
, "ARCnet");
1036 llts(ZEBRA_LLT_APPLETLK
, "AppleTalk");
1037 llts(ZEBRA_LLT_DLCI
, "Frame Relay DLCI");
1038 llts(ZEBRA_LLT_ATM
, "ATM");
1039 llts(ZEBRA_LLT_METRICOM
, "Metricom STRIP");
1040 llts(ZEBRA_LLT_IEEE1394
, "IEEE 1394 IPv4");
1041 llts(ZEBRA_LLT_EUI64
, "EUI-64");
1042 llts(ZEBRA_LLT_INFINIBAND
, "InfiniBand");
1043 llts(ZEBRA_LLT_SLIP
, "SLIP");
1044 llts(ZEBRA_LLT_CSLIP
, "Compressed SLIP");
1045 llts(ZEBRA_LLT_SLIP6
, "SLIPv6");
1046 llts(ZEBRA_LLT_CSLIP6
, "Compressed SLIPv6");
1047 llts(ZEBRA_LLT_RSRVD
, "Reserved");
1048 llts(ZEBRA_LLT_ADAPT
, "Adapt");
1049 llts(ZEBRA_LLT_ROSE
, "ROSE packet radio");
1050 llts(ZEBRA_LLT_X25
, "CCITT X.25");
1051 llts(ZEBRA_LLT_PPP
, "PPP");
1052 llts(ZEBRA_LLT_CHDLC
, "Cisco HDLC");
1053 llts(ZEBRA_LLT_RAWHDLC
, "Raw HDLC");
1054 llts(ZEBRA_LLT_LAPB
, "LAPB");
1055 llts(ZEBRA_LLT_IPIP
, "IPIP Tunnel");
1056 llts(ZEBRA_LLT_IPIP6
, "IPIP6 Tunnel");
1057 llts(ZEBRA_LLT_FRAD
, "FRAD");
1058 llts(ZEBRA_LLT_SKIP
, "SKIP vif");
1059 llts(ZEBRA_LLT_LOOPBACK
, "Loopback");
1060 llts(ZEBRA_LLT_LOCALTLK
, "Localtalk");
1061 llts(ZEBRA_LLT_FDDI
, "FDDI");
1062 llts(ZEBRA_LLT_SIT
, "IPv6-in-IPv4 SIT");
1063 llts(ZEBRA_LLT_IPDDP
, "IP-in-DDP tunnel");
1064 llts(ZEBRA_LLT_IPGRE
, "GRE over IP");
1065 llts(ZEBRA_LLT_IP6GRE
, "GRE over IPv6");
1066 llts(ZEBRA_LLT_PIMREG
, "PIMSM registration");
1067 llts(ZEBRA_LLT_HIPPI
, "HiPPI");
1068 llts(ZEBRA_LLT_ECONET
, "Acorn Econet");
1069 llts(ZEBRA_LLT_IRDA
, "IrDA");
1070 llts(ZEBRA_LLT_FCPP
, "Fibre-Channel PtP");
1071 llts(ZEBRA_LLT_FCAL
, "Fibre-Channel Arbitrated Loop");
1072 llts(ZEBRA_LLT_FCPL
, "Fibre-Channel Public Loop");
1073 llts(ZEBRA_LLT_FCFABRIC
, "Fibre-Channel Fabric");
1074 llts(ZEBRA_LLT_IEEE802_TR
, "IEEE 802.2 Token Ring");
1075 llts(ZEBRA_LLT_IEEE80211
, "IEEE 802.11");
1076 llts(ZEBRA_LLT_IEEE80211_RADIOTAP
, "IEEE 802.11 Radiotap");
1077 llts(ZEBRA_LLT_IEEE802154
, "IEEE 802.15.4");
1078 llts(ZEBRA_LLT_IEEE802154_PHY
, "IEEE 802.15.4 Phy");
1084 struct if_link_params
*if_link_params_get(struct interface
*ifp
)
1088 if (ifp
->link_params
!= NULL
)
1089 return ifp
->link_params
;
1091 struct if_link_params
*iflp
=
1092 XCALLOC(MTYPE_IF_LINK_PARAMS
, sizeof(struct if_link_params
));
1094 /* Compute default bandwidth based on interface */
1096 ((ifp
->bandwidth
? ifp
->bandwidth
: DEFAULT_BANDWIDTH
)
1097 * TE_MEGA_BIT
/ TE_BYTE
);
1099 /* Set Max, Reservable and Unreserved Bandwidth */
1100 iflp
->max_bw
= iflp
->default_bw
;
1101 iflp
->max_rsv_bw
= iflp
->default_bw
;
1102 for (i
= 0; i
< MAX_CLASS_TYPE
; i
++)
1103 iflp
->unrsv_bw
[i
] = iflp
->default_bw
;
1105 /* Update Link parameters status */
1106 iflp
->lp_status
= LP_MAX_BW
| LP_MAX_RSV_BW
| LP_UNRSV_BW
;
1108 /* Set TE metric equal to standard metric only if it is set */
1109 if (ifp
->metric
!= 0) {
1110 iflp
->te_metric
= ifp
->metric
;
1111 iflp
->lp_status
|= LP_TE_METRIC
;
1114 /* Finally attach newly created Link Parameters */
1115 ifp
->link_params
= iflp
;
1120 void if_link_params_free(struct interface
*ifp
)
1122 XFREE(MTYPE_IF_LINK_PARAMS
, ifp
->link_params
);
1125 /* ----------- CLI commands ----------- */
1127 /* Guess the VRF of an interface. */
1128 static int vrfname_by_ifname(const char *ifname
, const char **vrfname
)
1131 struct interface
*ifp
;
1134 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
1135 FOR_ALL_INTERFACES (vrf
, ifp
) {
1136 if (strmatch(ifp
->name
, ifname
)) {
1137 *vrfname
= vrf
->name
;
1147 * XPath: /frr-interface:lib/interface
1149 DEFPY_YANG_NOSH (interface
,
1151 "interface IFNAME [vrf NAME$vrf_name]",
1152 "Select an interface to configure\n"
1153 "Interface's name\n"
1156 char xpath_list
[XPATH_MAXLEN
];
1157 struct interface
*ifp
;
1161 if (vrf_is_backend_netns()) {
1163 * For backward compatibility, if the VRF name is not specified
1164 * and there is exactly one interface with this name in the
1165 * system, use its VRF. Otherwise fallback to the default VRF.
1168 count
= vrfname_by_ifname(ifname
, &vrf_name
);
1170 vrf_name
= VRF_DEFAULT_NAME
;
1173 snprintf(xpath_list
, XPATH_MAXLEN
,
1174 "/frr-interface:lib/interface[name='%s:%s']", vrf_name
,
1177 snprintf(xpath_list
, XPATH_MAXLEN
,
1178 "/frr-interface:lib/interface[name='%s']", ifname
);
1181 nb_cli_enqueue_change(vty
, ".", NB_OP_CREATE
, NULL
);
1182 ret
= nb_cli_apply_changes_clear_pending(vty
, xpath_list
);
1183 if (ret
== CMD_SUCCESS
) {
1184 VTY_PUSH_XPATH(INTERFACE_NODE
, xpath_list
);
1187 * For backward compatibility with old commands we still need
1188 * to use the qobj infrastructure. This can be removed once
1189 * all interface-level commands are converted to the new
1192 if (vrf_is_backend_netns()) {
1193 vrf
= vrf_lookup_by_name(vrf_name
);
1195 ifp
= if_lookup_by_name_vrf(ifname
, vrf
);
1199 ifp
= if_lookup_by_name_all_vrf(ifname
);
1202 VTY_PUSH_CONTEXT(INTERFACE_NODE
, ifp
);
1208 DEFPY_YANG (no_interface
,
1210 "no interface IFNAME [vrf NAME$vrf_name]",
1212 "Delete a pseudo interface's configuration\n"
1213 "Interface's name\n"
1216 char xpath_list
[XPATH_MAXLEN
];
1219 if (vrf_is_backend_netns()) {
1221 * For backward compatibility, if the VRF name is not specified
1222 * and there is exactly one interface with this name in the
1223 * system, use its VRF. Otherwise fallback to the default VRF.
1226 count
= vrfname_by_ifname(ifname
, &vrf_name
);
1228 vrf_name
= VRF_DEFAULT_NAME
;
1231 snprintf(xpath_list
, XPATH_MAXLEN
,
1232 "/frr-interface:lib/interface[name='%s:%s']", vrf_name
,
1235 snprintf(xpath_list
, XPATH_MAXLEN
,
1236 "/frr-interface:lib/interface[name='%s']", ifname
);
1239 nb_cli_enqueue_change(vty
, ".", NB_OP_DESTROY
, NULL
);
1241 return nb_cli_apply_changes(vty
, xpath_list
);
1244 static void netns_ifname_split(const char *xpath
, char *ifname
, char *vrfname
)
1249 assert(vrf_is_backend_netns());
1251 delim
= strchr(xpath
, ':');
1254 len
= delim
- xpath
;
1255 memcpy(vrfname
, xpath
, len
);
1258 strlcpy(ifname
, delim
+ 1, XPATH_MAXLEN
);
1261 static void cli_show_interface(struct vty
*vty
, const struct lyd_node
*dnode
,
1264 vty_out(vty
, "!\n");
1266 if (vrf_is_backend_netns()) {
1267 char ifname
[XPATH_MAXLEN
];
1268 char vrfname
[XPATH_MAXLEN
];
1270 netns_ifname_split(yang_dnode_get_string(dnode
, "./name"),
1273 vty_out(vty
, "interface %s", ifname
);
1274 if (!strmatch(vrfname
, VRF_DEFAULT_NAME
))
1275 vty_out(vty
, " vrf %s", vrfname
);
1277 const char *ifname
= yang_dnode_get_string(dnode
, "./name");
1279 vty_out(vty
, "interface %s", ifname
);
1285 static void cli_show_interface_end(struct vty
*vty
,
1286 const struct lyd_node
*dnode
)
1288 vty_out(vty
, "exit\n");
1291 void if_vty_config_start(struct vty
*vty
, struct interface
*ifp
)
1293 vty_frame(vty
, "!\n");
1294 vty_frame(vty
, "interface %s", ifp
->name
);
1296 if (vrf_is_backend_netns() && strcmp(ifp
->vrf
->name
, VRF_DEFAULT_NAME
))
1297 vty_frame(vty
, " vrf %s", ifp
->vrf
->name
);
1299 vty_frame(vty
, "\n");
1302 void if_vty_config_end(struct vty
*vty
)
1304 vty_endframe(vty
, "exit\n!\n");
1308 * XPath: /frr-interface:lib/interface/description
1310 DEFPY_YANG (interface_desc
,
1312 "description LINE...",
1313 "Interface specific description\n"
1314 "Characters describing this interface\n")
1319 desc
= argv_concat(argv
, argc
, 1);
1320 nb_cli_enqueue_change(vty
, "./description", NB_OP_MODIFY
, desc
);
1321 ret
= nb_cli_apply_changes(vty
, NULL
);
1322 XFREE(MTYPE_TMP
, desc
);
1327 DEFPY_YANG (no_interface_desc
,
1328 no_interface_desc_cmd
,
1331 "Interface specific description\n")
1333 nb_cli_enqueue_change(vty
, "./description", NB_OP_DESTROY
, NULL
);
1335 return nb_cli_apply_changes(vty
, NULL
);
1338 static void cli_show_interface_desc(struct vty
*vty
,
1339 const struct lyd_node
*dnode
,
1342 vty_out(vty
, " description %s\n", yang_dnode_get_string(dnode
, NULL
));
1345 /* Interface autocomplete. */
1346 static void if_autocomplete(vector comps
, struct cmd_token
*token
)
1348 struct interface
*ifp
;
1351 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
1352 FOR_ALL_INTERFACES (vrf
, ifp
) {
1353 vector_set(comps
, XSTRDUP(MTYPE_COMPLETION
, ifp
->name
));
1358 static const struct cmd_variable_handler if_var_handlers
[] = {
1359 {/* "interface NAME" */
1360 .varname
= "interface",
1361 .completions
= if_autocomplete
},
1362 {.tokenname
= "IFNAME", .completions
= if_autocomplete
},
1363 {.tokenname
= "INTERFACE", .completions
= if_autocomplete
},
1364 {.completions
= NULL
}};
1366 static struct cmd_node interface_node
= {
1367 .name
= "interface",
1368 .node
= INTERFACE_NODE
,
1369 .parent_node
= CONFIG_NODE
,
1370 .prompt
= "%s(config-if)# ",
1373 static int if_config_write_single(const struct lyd_node
*dnode
, void *arg
)
1375 nb_cli_show_dnode_cmds(arg
, dnode
, false);
1377 return YANG_ITER_CONTINUE
;
1380 static int if_nb_config_write(struct vty
*vty
)
1382 yang_dnode_iterate(if_config_write_single
, vty
, running_config
->dnode
,
1383 "/frr-interface:lib/interface");
1387 void if_cmd_init(int (*config_write
)(struct vty
*))
1389 cmd_variable_handler_register(if_var_handlers
);
1391 interface_node
.config_write
= config_write
;
1392 install_node(&interface_node
);
1394 install_element(CONFIG_NODE
, &interface_cmd
);
1395 install_element(CONFIG_NODE
, &no_interface_cmd
);
1397 install_default(INTERFACE_NODE
);
1398 install_element(INTERFACE_NODE
, &interface_desc_cmd
);
1399 install_element(INTERFACE_NODE
, &no_interface_desc_cmd
);
1402 void if_cmd_init_default(void)
1404 if_cmd_init(if_nb_config_write
);
1407 void if_zapi_callbacks(int (*create
)(struct interface
*ifp
),
1408 int (*up
)(struct interface
*ifp
),
1409 int (*down
)(struct interface
*ifp
),
1410 int (*destroy
)(struct interface
*ifp
))
1412 ifp_master
.create_hook
= create
;
1413 ifp_master
.up_hook
= up
;
1414 ifp_master
.down_hook
= down
;
1415 ifp_master
.destroy_hook
= destroy
;
1418 /* ------- Northbound callbacks ------- */
1421 * XPath: /frr-interface:lib/interface
1423 static int lib_interface_create(struct nb_cb_create_args
*args
)
1426 struct interface
*ifp
;
1428 ifname
= yang_dnode_get_string(args
->dnode
, "./name");
1430 switch (args
->event
) {
1431 case NB_EV_VALIDATE
:
1432 if (vrf_is_backend_netns()) {
1433 char ifname_ns
[XPATH_MAXLEN
];
1434 char vrfname_ns
[XPATH_MAXLEN
];
1436 netns_ifname_split(ifname
, ifname_ns
, vrfname_ns
);
1438 if (strlen(ifname_ns
) > 16) {
1440 args
->errmsg
, args
->errmsg_len
,
1441 "Maximum interface name length is 16 characters");
1442 return NB_ERR_VALIDATION
;
1444 if (strlen(vrfname_ns
) > 36) {
1446 args
->errmsg
, args
->errmsg_len
,
1447 "Maximum VRF name length is 36 characters");
1448 return NB_ERR_VALIDATION
;
1451 if (strlen(ifname
) > 16) {
1453 args
->errmsg
, args
->errmsg_len
,
1454 "Maximum interface name length is 16 characters");
1455 return NB_ERR_VALIDATION
;
1463 if (vrf_is_backend_netns()) {
1464 char ifname_ns
[XPATH_MAXLEN
];
1465 char vrfname_ns
[XPATH_MAXLEN
];
1467 netns_ifname_split(ifname
, ifname_ns
, vrfname_ns
);
1469 ifp
= if_get_by_name(ifname_ns
, VRF_UNKNOWN
,
1472 ifp
= if_get_by_name(ifname
, VRF_UNKNOWN
,
1476 ifp
->configured
= true;
1477 nb_running_set_entry(args
->dnode
, ifp
);
1484 static int lib_interface_destroy(struct nb_cb_destroy_args
*args
)
1486 struct interface
*ifp
;
1489 switch (args
->event
) {
1490 case NB_EV_VALIDATE
:
1491 ifp
= nb_running_get_entry(args
->dnode
, NULL
, true);
1492 if (CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
1493 snprintf(args
->errmsg
, args
->errmsg_len
,
1494 "only inactive interfaces can be deleted");
1495 return NB_ERR_VALIDATION
;
1502 ifp
= nb_running_unset_entry(args
->dnode
);
1505 ifp
->configured
= false;
1508 if (!vrf_is_enabled(vrf
))
1517 * XPath: /frr-interface:lib/interface
1519 static const void *lib_interface_get_next(struct nb_cb_get_next_args
*args
)
1522 struct interface
*pif
= (struct interface
*)args
->list_entry
;
1524 if (args
->list_entry
== NULL
) {
1525 vrf
= RB_MIN(vrf_name_head
, &vrfs_by_name
);
1527 pif
= RB_MIN(if_name_head
, &vrf
->ifaces_by_name
);
1530 pif
= RB_NEXT(if_name_head
, pif
);
1531 /* if no more interfaces, switch to next vrf */
1532 while (pif
== NULL
) {
1533 vrf
= RB_NEXT(vrf_name_head
, vrf
);
1536 pif
= RB_MIN(if_name_head
, &vrf
->ifaces_by_name
);
1543 static int lib_interface_get_keys(struct nb_cb_get_keys_args
*args
)
1545 const struct interface
*ifp
= args
->list_entry
;
1547 args
->keys
->num
= 1;
1549 if (vrf_is_backend_netns())
1550 snprintf(args
->keys
->key
[0], sizeof(args
->keys
->key
[0]),
1551 "%s:%s", ifp
->vrf
->name
, ifp
->name
);
1553 snprintf(args
->keys
->key
[0], sizeof(args
->keys
->key
[0]), "%s",
1560 lib_interface_lookup_entry(struct nb_cb_lookup_entry_args
*args
)
1562 if (vrf_is_backend_netns()) {
1563 char ifname
[XPATH_MAXLEN
];
1564 char vrfname
[XPATH_MAXLEN
];
1567 netns_ifname_split(args
->keys
->key
[0], ifname
, vrfname
);
1569 vrf
= vrf_lookup_by_name(vrfname
);
1571 return vrf
? if_lookup_by_name(ifname
, vrf
->vrf_id
) : NULL
;
1573 return if_lookup_by_name_all_vrf(args
->keys
->key
[0]);
1578 * XPath: /frr-interface:lib/interface/description
1580 static int lib_interface_description_modify(struct nb_cb_modify_args
*args
)
1582 struct interface
*ifp
;
1583 const char *description
;
1585 if (args
->event
!= NB_EV_APPLY
)
1588 ifp
= nb_running_get_entry(args
->dnode
, NULL
, true);
1589 XFREE(MTYPE_TMP
, ifp
->desc
);
1590 description
= yang_dnode_get_string(args
->dnode
, NULL
);
1591 ifp
->desc
= XSTRDUP(MTYPE_TMP
, description
);
1596 static int lib_interface_description_destroy(struct nb_cb_destroy_args
*args
)
1598 struct interface
*ifp
;
1600 if (args
->event
!= NB_EV_APPLY
)
1603 ifp
= nb_running_get_entry(args
->dnode
, NULL
, true);
1604 XFREE(MTYPE_TMP
, ifp
->desc
);
1610 * XPath: /frr-interface:lib/interface/vrf
1612 static struct yang_data
*
1613 lib_interface_vrf_get_elem(struct nb_cb_get_elem_args
*args
)
1615 const struct interface
*ifp
= args
->list_entry
;
1617 return yang_data_new_string(args
->xpath
, ifp
->vrf
->name
);
1621 * XPath: /frr-interface:lib/interface/state/if-index
1623 static struct yang_data
*
1624 lib_interface_state_if_index_get_elem(struct nb_cb_get_elem_args
*args
)
1626 const struct interface
*ifp
= args
->list_entry
;
1628 return yang_data_new_int32(args
->xpath
, ifp
->ifindex
);
1632 * XPath: /frr-interface:lib/interface/state/mtu
1634 static struct yang_data
*
1635 lib_interface_state_mtu_get_elem(struct nb_cb_get_elem_args
*args
)
1637 const struct interface
*ifp
= args
->list_entry
;
1639 return yang_data_new_uint16(args
->xpath
, ifp
->mtu
);
1643 * XPath: /frr-interface:lib/interface/state/mtu6
1645 static struct yang_data
*
1646 lib_interface_state_mtu6_get_elem(struct nb_cb_get_elem_args
*args
)
1648 const struct interface
*ifp
= args
->list_entry
;
1650 return yang_data_new_uint32(args
->xpath
, ifp
->mtu6
);
1654 * XPath: /frr-interface:lib/interface/state/speed
1656 static struct yang_data
*
1657 lib_interface_state_speed_get_elem(struct nb_cb_get_elem_args
*args
)
1659 const struct interface
*ifp
= args
->list_entry
;
1661 return yang_data_new_uint32(args
->xpath
, ifp
->speed
);
1665 * XPath: /frr-interface:lib/interface/state/metric
1667 static struct yang_data
*
1668 lib_interface_state_metric_get_elem(struct nb_cb_get_elem_args
*args
)
1670 const struct interface
*ifp
= args
->list_entry
;
1672 return yang_data_new_uint32(args
->xpath
, ifp
->metric
);
1676 * XPath: /frr-interface:lib/interface/state/flags
1678 static struct yang_data
*
1679 lib_interface_state_flags_get_elem(struct nb_cb_get_elem_args
*args
)
1681 /* TODO: implement me. */
1686 * XPath: /frr-interface:lib/interface/state/type
1688 static struct yang_data
*
1689 lib_interface_state_type_get_elem(struct nb_cb_get_elem_args
*args
)
1691 /* TODO: implement me. */
1696 * XPath: /frr-interface:lib/interface/state/phy-address
1698 static struct yang_data
*
1699 lib_interface_state_phy_address_get_elem(struct nb_cb_get_elem_args
*args
)
1701 const struct interface
*ifp
= args
->list_entry
;
1702 struct ethaddr macaddr
;
1704 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
1706 return yang_data_new_mac(args
->xpath
, &macaddr
);
1709 /* clang-format off */
1710 const struct frr_yang_module_info frr_interface_info
= {
1711 .name
= "frr-interface",
1714 .xpath
= "/frr-interface:lib/interface",
1716 .create
= lib_interface_create
,
1717 .destroy
= lib_interface_destroy
,
1718 .cli_show
= cli_show_interface
,
1719 .cli_show_end
= cli_show_interface_end
,
1720 .get_next
= lib_interface_get_next
,
1721 .get_keys
= lib_interface_get_keys
,
1722 .lookup_entry
= lib_interface_lookup_entry
,
1726 .xpath
= "/frr-interface:lib/interface/description",
1728 .modify
= lib_interface_description_modify
,
1729 .destroy
= lib_interface_description_destroy
,
1730 .cli_show
= cli_show_interface_desc
,
1734 .xpath
= "/frr-interface:lib/interface/vrf",
1736 .get_elem
= lib_interface_vrf_get_elem
,
1740 .xpath
= "/frr-interface:lib/interface/state/if-index",
1742 .get_elem
= lib_interface_state_if_index_get_elem
,
1746 .xpath
= "/frr-interface:lib/interface/state/mtu",
1748 .get_elem
= lib_interface_state_mtu_get_elem
,
1752 .xpath
= "/frr-interface:lib/interface/state/mtu6",
1754 .get_elem
= lib_interface_state_mtu6_get_elem
,
1758 .xpath
= "/frr-interface:lib/interface/state/speed",
1760 .get_elem
= lib_interface_state_speed_get_elem
,
1764 .xpath
= "/frr-interface:lib/interface/state/metric",
1766 .get_elem
= lib_interface_state_metric_get_elem
,
1770 .xpath
= "/frr-interface:lib/interface/state/flags",
1772 .get_elem
= lib_interface_state_flags_get_elem
,
1776 .xpath
= "/frr-interface:lib/interface/state/type",
1778 .get_elem
= lib_interface_state_type_get_elem
,
1782 .xpath
= "/frr-interface:lib/interface/state/phy-address",
1784 .get_elem
= lib_interface_state_phy_address_get_elem
,