2 * Interface looking up by netlink.
3 * Copyright (C) 1998 Kunihiro Ishiguro
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
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 /* The following definition is to workaround an issue in the Linux kernel
27 * header files with redefinition of 'struct in6_addr' in both
28 * netinet/in.h and linux/in6.h.
29 * Reference - https://sourceware.org/ml/libc-alpha/2013-01/msg00599.html
33 #include <netinet/if_ether.h>
34 #include <linux/if_bridge.h>
35 #include <linux/if_link.h>
36 #include <net/if_arp.h>
37 #include <linux/sockios.h>
38 #include <linux/ethtool.h>
44 #include "connected.h"
47 #include "zebra_memory.h"
55 #include "lib_errors.h"
58 #include "zebra/zserv.h"
59 #include "zebra/zebra_ns.h"
60 #include "zebra/zebra_vrf.h"
62 #include "zebra/redistribute.h"
63 #include "zebra/interface.h"
64 #include "zebra/debug.h"
65 #include "zebra/rtadv.h"
66 #include "zebra/zebra_ptm.h"
67 #include "zebra/zebra_mpls.h"
68 #include "zebra/kernel_netlink.h"
69 #include "zebra/if_netlink.h"
70 #include "zebra/zebra_errors.h"
71 #include "zebra/zebra_vxlan.h"
73 extern struct zebra_privs_t zserv_privs
;
75 /* Note: on netlink systems, there should be a 1-to-1 mapping between interface
76 names and ifindex values. */
77 static void set_ifindex(struct interface
*ifp
, ifindex_t ifi_index
,
80 struct interface
*oifp
;
82 if (((oifp
= if_lookup_by_index_per_ns(zns
, ifi_index
)) != NULL
)
84 if (ifi_index
== IFINDEX_INTERNAL
)
87 "Netlink is setting interface %s ifindex to reserved internal value %u",
88 ifp
->name
, ifi_index
);
90 if (IS_ZEBRA_DEBUG_KERNEL
)
92 "interface index %d was renamed from %s to %s",
93 ifi_index
, oifp
->name
, ifp
->name
);
97 "interface rename detected on up interface: index %d was renamed from %s to %s, results are uncertain!",
98 ifi_index
, oifp
->name
, ifp
->name
);
99 if_delete_update(oifp
);
102 if_set_index(ifp
, ifi_index
);
105 /* Utility function to parse hardware link-layer address and update ifp */
106 static void netlink_interface_update_hw_addr(struct rtattr
**tb
,
107 struct interface
*ifp
)
111 if (tb
[IFLA_ADDRESS
]) {
114 hw_addr_len
= RTA_PAYLOAD(tb
[IFLA_ADDRESS
]);
116 if (hw_addr_len
> INTERFACE_HWADDR_MAX
)
117 zlog_debug("Hardware address is too large: %d",
120 ifp
->hw_addr_len
= hw_addr_len
;
121 memcpy(ifp
->hw_addr
, RTA_DATA(tb
[IFLA_ADDRESS
]),
124 for (i
= 0; i
< hw_addr_len
; i
++)
125 if (ifp
->hw_addr
[i
] != 0)
128 if (i
== hw_addr_len
)
129 ifp
->hw_addr_len
= 0;
131 ifp
->hw_addr_len
= hw_addr_len
;
136 static enum zebra_link_type
netlink_to_zebra_link_type(unsigned int hwt
)
140 return ZEBRA_LLT_ETHER
;
142 return ZEBRA_LLT_EETHER
;
144 return ZEBRA_LLT_AX25
;
146 return ZEBRA_LLT_PRONET
;
148 return ZEBRA_LLT_IEEE802
;
150 return ZEBRA_LLT_ARCNET
;
151 case ARPHRD_APPLETLK
:
152 return ZEBRA_LLT_APPLETLK
;
154 return ZEBRA_LLT_DLCI
;
156 return ZEBRA_LLT_ATM
;
157 case ARPHRD_METRICOM
:
158 return ZEBRA_LLT_METRICOM
;
159 case ARPHRD_IEEE1394
:
160 return ZEBRA_LLT_IEEE1394
;
162 return ZEBRA_LLT_EUI64
;
163 case ARPHRD_INFINIBAND
:
164 return ZEBRA_LLT_INFINIBAND
;
166 return ZEBRA_LLT_SLIP
;
168 return ZEBRA_LLT_CSLIP
;
170 return ZEBRA_LLT_SLIP6
;
172 return ZEBRA_LLT_CSLIP6
;
174 return ZEBRA_LLT_RSRVD
;
176 return ZEBRA_LLT_ADAPT
;
178 return ZEBRA_LLT_ROSE
;
180 return ZEBRA_LLT_X25
;
182 return ZEBRA_LLT_PPP
;
184 return ZEBRA_LLT_CHDLC
;
186 return ZEBRA_LLT_LAPB
;
188 return ZEBRA_LLT_RAWHDLC
;
190 return ZEBRA_LLT_IPIP
;
192 return ZEBRA_LLT_IPIP6
;
194 return ZEBRA_LLT_FRAD
;
196 return ZEBRA_LLT_SKIP
;
197 case ARPHRD_LOOPBACK
:
198 return ZEBRA_LLT_LOOPBACK
;
199 case ARPHRD_LOCALTLK
:
200 return ZEBRA_LLT_LOCALTLK
;
202 return ZEBRA_LLT_FDDI
;
204 return ZEBRA_LLT_SIT
;
206 return ZEBRA_LLT_IPDDP
;
208 return ZEBRA_LLT_IPGRE
;
210 return ZEBRA_LLT_PIMREG
;
212 return ZEBRA_LLT_HIPPI
;
214 return ZEBRA_LLT_ECONET
;
216 return ZEBRA_LLT_IRDA
;
218 return ZEBRA_LLT_FCPP
;
220 return ZEBRA_LLT_FCAL
;
222 return ZEBRA_LLT_FCPL
;
223 case ARPHRD_FCFABRIC
:
224 return ZEBRA_LLT_FCFABRIC
;
225 case ARPHRD_IEEE802_TR
:
226 return ZEBRA_LLT_IEEE802_TR
;
227 case ARPHRD_IEEE80211
:
228 return ZEBRA_LLT_IEEE80211
;
229 #ifdef ARPHRD_IEEE802154
230 case ARPHRD_IEEE802154
:
231 return ZEBRA_LLT_IEEE802154
;
235 return ZEBRA_LLT_IP6GRE
;
237 #ifdef ARPHRD_IEEE802154_PHY
238 case ARPHRD_IEEE802154_PHY
:
239 return ZEBRA_LLT_IEEE802154_PHY
;
243 return ZEBRA_LLT_UNKNOWN
;
247 static void netlink_determine_zebra_iftype(const char *kind
,
248 zebra_iftype_t
*zif_type
)
250 *zif_type
= ZEBRA_IF_OTHER
;
255 if (strcmp(kind
, "vrf") == 0)
256 *zif_type
= ZEBRA_IF_VRF
;
257 else if (strcmp(kind
, "bridge") == 0)
258 *zif_type
= ZEBRA_IF_BRIDGE
;
259 else if (strcmp(kind
, "vlan") == 0)
260 *zif_type
= ZEBRA_IF_VLAN
;
261 else if (strcmp(kind
, "vxlan") == 0)
262 *zif_type
= ZEBRA_IF_VXLAN
;
263 else if (strcmp(kind
, "macvlan") == 0)
264 *zif_type
= ZEBRA_IF_MACVLAN
;
265 else if (strcmp(kind
, "veth") == 0)
266 *zif_type
= ZEBRA_IF_VETH
;
267 else if (strcmp(kind
, "bond") == 0)
268 *zif_type
= ZEBRA_IF_BOND
;
269 else if (strcmp(kind
, "bond_slave") == 0)
270 *zif_type
= ZEBRA_IF_BOND_SLAVE
;
273 #define parse_rtattr_nested(tb, max, rta) \
274 netlink_parse_rtattr((tb), (max), RTA_DATA(rta), RTA_PAYLOAD(rta))
276 static void netlink_vrf_change(struct nlmsghdr
*h
, struct rtattr
*tb
,
279 struct ifinfomsg
*ifi
;
280 struct rtattr
*linkinfo
[IFLA_INFO_MAX
+ 1];
281 struct rtattr
*attr
[IFLA_VRF_MAX
+ 1];
283 struct zebra_vrf
*zvrf
;
284 uint32_t nl_table_id
;
288 memset(linkinfo
, 0, sizeof linkinfo
);
289 parse_rtattr_nested(linkinfo
, IFLA_INFO_MAX
, tb
);
291 if (!linkinfo
[IFLA_INFO_DATA
]) {
292 if (IS_ZEBRA_DEBUG_KERNEL
)
294 "%s: IFLA_INFO_DATA missing from VRF message: %s",
299 memset(attr
, 0, sizeof attr
);
300 parse_rtattr_nested(attr
, IFLA_VRF_MAX
, linkinfo
[IFLA_INFO_DATA
]);
301 if (!attr
[IFLA_VRF_TABLE
]) {
302 if (IS_ZEBRA_DEBUG_KERNEL
)
304 "%s: IFLA_VRF_TABLE missing from VRF message: %s",
309 nl_table_id
= *(uint32_t *)RTA_DATA(attr
[IFLA_VRF_TABLE
]);
311 if (h
->nlmsg_type
== RTM_NEWLINK
) {
312 if (IS_ZEBRA_DEBUG_KERNEL
)
313 zlog_debug("RTM_NEWLINK for VRF %s(%u) table %u", name
,
314 ifi
->ifi_index
, nl_table_id
);
317 * vrf_get is implied creation if it does not exist
319 vrf
= vrf_get((vrf_id_t
)ifi
->ifi_index
,
320 name
); // It would create vrf
322 flog_err(EC_LIB_INTERFACE
, "VRF %s id %u not created",
323 name
, ifi
->ifi_index
);
328 * This is the only place that we get the actual kernel table_id
329 * being used. We need it to set the table_id of the routes
330 * we are passing to the kernel.... And to throw some totally
331 * awesome parties. that too.
333 * At this point we *must* have a zvrf because the vrf_create
334 * callback creates one. We *must* set the table id
335 * before the vrf_enable because of( at the very least )
336 * static routes being delayed for installation until
337 * during the vrf_enable callbacks.
339 zvrf
= (struct zebra_vrf
*)vrf
->info
;
340 zvrf
->table_id
= nl_table_id
;
342 /* Enable the created VRF. */
343 if (!vrf_enable(vrf
)) {
344 flog_err(EC_LIB_INTERFACE
,
345 "Failed to enable VRF %s id %u", name
,
350 } else // h->nlmsg_type == RTM_DELLINK
352 if (IS_ZEBRA_DEBUG_KERNEL
)
353 zlog_debug("RTM_DELLINK for VRF %s(%u)", name
,
356 vrf
= vrf_lookup_by_id((vrf_id_t
)ifi
->ifi_index
);
359 flog_warn(EC_ZEBRA_VRF_NOT_FOUND
, "%s: vrf not found",
368 static int get_iflink_speed(struct interface
*interface
)
371 struct ethtool_cmd ecmd
;
374 const char *ifname
= interface
->name
;
376 /* initialize struct */
377 memset(&ifdata
, 0, sizeof(ifdata
));
379 /* set interface name */
380 strlcpy(ifdata
.ifr_name
, ifname
, sizeof(ifdata
.ifr_name
));
382 /* initialize ethtool interface */
383 memset(&ecmd
, 0, sizeof(ecmd
));
384 ecmd
.cmd
= ETHTOOL_GSET
; /* ETHTOOL_GLINK */
385 ifdata
.ifr_data
= (caddr_t
)&ecmd
;
387 /* use ioctl to get IP address of an interface */
388 frr_elevate_privs(&zserv_privs
) {
389 sd
= vrf_socket(PF_INET
, SOCK_DGRAM
, IPPROTO_IP
,
393 if (IS_ZEBRA_DEBUG_KERNEL
)
394 zlog_debug("Failure to read interface %s speed: %d %s",
395 ifname
, errno
, safe_strerror(errno
));
398 /* Get the current link state for the interface */
399 rc
= vrf_ioctl(interface
->vrf_id
, sd
, SIOCETHTOOL
,
403 if (errno
!= EOPNOTSUPP
&& IS_ZEBRA_DEBUG_KERNEL
)
405 "IOCTL failure to read interface %s speed: %d %s",
406 ifname
, errno
, safe_strerror(errno
));
413 return (ecmd
.speed_hi
<< 16) | ecmd
.speed
;
416 uint32_t kernel_get_speed(struct interface
*ifp
)
418 return get_iflink_speed(ifp
);
421 static int netlink_extract_bridge_info(struct rtattr
*link_data
,
422 struct zebra_l2info_bridge
*bridge_info
)
424 struct rtattr
*attr
[IFLA_BR_MAX
+ 1];
426 memset(bridge_info
, 0, sizeof(*bridge_info
));
427 memset(attr
, 0, sizeof attr
);
428 parse_rtattr_nested(attr
, IFLA_BR_MAX
, link_data
);
429 if (attr
[IFLA_BR_VLAN_FILTERING
])
430 bridge_info
->vlan_aware
=
431 *(uint8_t *)RTA_DATA(attr
[IFLA_BR_VLAN_FILTERING
]);
435 static int netlink_extract_vlan_info(struct rtattr
*link_data
,
436 struct zebra_l2info_vlan
*vlan_info
)
438 struct rtattr
*attr
[IFLA_VLAN_MAX
+ 1];
441 memset(vlan_info
, 0, sizeof(*vlan_info
));
442 memset(attr
, 0, sizeof attr
);
443 parse_rtattr_nested(attr
, IFLA_VLAN_MAX
, link_data
);
444 if (!attr
[IFLA_VLAN_ID
]) {
445 if (IS_ZEBRA_DEBUG_KERNEL
)
446 zlog_debug("IFLA_VLAN_ID missing from VLAN IF message");
450 vid_in_msg
= *(vlanid_t
*)RTA_DATA(attr
[IFLA_VLAN_ID
]);
451 vlan_info
->vid
= vid_in_msg
;
455 static int netlink_extract_vxlan_info(struct rtattr
*link_data
,
456 struct zebra_l2info_vxlan
*vxl_info
)
458 struct rtattr
*attr
[IFLA_VXLAN_MAX
+ 1];
460 struct in_addr vtep_ip_in_msg
;
462 memset(vxl_info
, 0, sizeof(*vxl_info
));
463 memset(attr
, 0, sizeof attr
);
464 parse_rtattr_nested(attr
, IFLA_VXLAN_MAX
, link_data
);
465 if (!attr
[IFLA_VXLAN_ID
]) {
466 if (IS_ZEBRA_DEBUG_KERNEL
)
468 "IFLA_VXLAN_ID missing from VXLAN IF message");
472 vni_in_msg
= *(vni_t
*)RTA_DATA(attr
[IFLA_VXLAN_ID
]);
473 vxl_info
->vni
= vni_in_msg
;
474 if (!attr
[IFLA_VXLAN_LOCAL
]) {
475 if (IS_ZEBRA_DEBUG_KERNEL
)
477 "IFLA_VXLAN_LOCAL missing from VXLAN IF message");
480 *(struct in_addr
*)RTA_DATA(attr
[IFLA_VXLAN_LOCAL
]);
481 vxl_info
->vtep_ip
= vtep_ip_in_msg
;
484 if (attr
[IFLA_VXLAN_GROUP
]) {
485 vxl_info
->mcast_grp
=
486 *(struct in_addr
*)RTA_DATA(attr
[IFLA_VXLAN_GROUP
]);
493 * Extract and save L2 params (of interest) for an interface. When a
494 * bridge interface is added or updated, take further actions to map
495 * its members. Likewise, for VxLAN interface.
497 static void netlink_interface_update_l2info(struct interface
*ifp
,
498 struct rtattr
*link_data
, int add
)
503 if (IS_ZEBRA_IF_BRIDGE(ifp
)) {
504 struct zebra_l2info_bridge bridge_info
;
506 netlink_extract_bridge_info(link_data
, &bridge_info
);
507 zebra_l2_bridge_add_update(ifp
, &bridge_info
, add
);
508 } else if (IS_ZEBRA_IF_VLAN(ifp
)) {
509 struct zebra_l2info_vlan vlan_info
;
511 netlink_extract_vlan_info(link_data
, &vlan_info
);
512 zebra_l2_vlanif_update(ifp
, &vlan_info
);
513 } else if (IS_ZEBRA_IF_VXLAN(ifp
)) {
514 struct zebra_l2info_vxlan vxlan_info
;
516 netlink_extract_vxlan_info(link_data
, &vxlan_info
);
517 zebra_l2_vxlanif_add_update(ifp
, &vxlan_info
, add
);
521 static int netlink_bridge_interface(struct nlmsghdr
*h
, int len
, ns_id_t ns_id
,
525 struct ifinfomsg
*ifi
;
526 struct rtattr
*tb
[IFLA_MAX
+ 1];
527 struct interface
*ifp
;
528 struct rtattr
*aftb
[IFLA_BRIDGE_MAX
+ 1];
533 vlanid_t access_vlan
;
535 /* Fetch name and ifindex */
537 memset(tb
, 0, sizeof tb
);
538 netlink_parse_rtattr(tb
, IFLA_MAX
, IFLA_RTA(ifi
), len
);
540 if (tb
[IFLA_IFNAME
] == NULL
)
542 name
= (char *)RTA_DATA(tb
[IFLA_IFNAME
]);
544 /* The interface should already be known, if not discard. */
545 ifp
= if_lookup_by_index_per_ns(zebra_ns_lookup(ns_id
), ifi
->ifi_index
);
547 zlog_debug("Cannot find bridge IF %s(%u)", name
,
551 if (!IS_ZEBRA_IF_VXLAN(ifp
))
554 /* We are only interested in the access VLAN i.e., AF_SPEC */
555 if (!tb
[IFLA_AF_SPEC
])
558 /* There is a 1-to-1 mapping of VLAN to VxLAN - hence
559 * only 1 access VLAN is accepted.
561 memset(aftb
, 0, sizeof aftb
);
562 parse_rtattr_nested(aftb
, IFLA_BRIDGE_MAX
, tb
[IFLA_AF_SPEC
]);
563 if (!aftb
[IFLA_BRIDGE_VLAN_INFO
])
566 vinfo
= RTA_DATA(aftb
[IFLA_BRIDGE_VLAN_INFO
]);
567 if (!(vinfo
->flags
& BRIDGE_VLAN_INFO_PVID
))
570 access_vlan
= (vlanid_t
)vinfo
->vid
;
571 if (IS_ZEBRA_DEBUG_KERNEL
)
572 zlog_debug("Access VLAN %u for VxLAN IF %s(%u)", access_vlan
,
573 name
, ifi
->ifi_index
);
574 zebra_l2_vxlanif_update_access_vlan(ifp
, access_vlan
);
579 * Called from interface_lookup_netlink(). This function is only used
582 static int netlink_interface(struct nlmsghdr
*h
, ns_id_t ns_id
, int startup
)
585 struct ifinfomsg
*ifi
;
586 struct rtattr
*tb
[IFLA_MAX
+ 1];
587 struct rtattr
*linkinfo
[IFLA_MAX
+ 1];
588 struct interface
*ifp
;
592 char *slave_kind
= NULL
;
593 struct zebra_ns
*zns
;
594 vrf_id_t vrf_id
= VRF_DEFAULT
;
595 zebra_iftype_t zif_type
= ZEBRA_IF_OTHER
;
596 zebra_slave_iftype_t zif_slave_type
= ZEBRA_IF_SLAVE_NONE
;
597 ifindex_t bridge_ifindex
= IFINDEX_INTERNAL
;
598 ifindex_t link_ifindex
= IFINDEX_INTERNAL
;
599 ifindex_t bond_ifindex
= IFINDEX_INTERNAL
;
600 struct zebra_if
*zif
;
602 zns
= zebra_ns_lookup(ns_id
);
605 if (h
->nlmsg_type
!= RTM_NEWLINK
)
608 len
= h
->nlmsg_len
- NLMSG_LENGTH(sizeof(struct ifinfomsg
));
610 zlog_err("%s: Message received from netlink is of a broken size: %d %zu",
613 (size_t)NLMSG_LENGTH(sizeof(struct ifinfomsg
)));
617 /* We are interested in some AF_BRIDGE notifications. */
618 if (ifi
->ifi_family
== AF_BRIDGE
)
619 return netlink_bridge_interface(h
, len
, ns_id
, startup
);
621 /* Looking up interface name. */
622 memset(tb
, 0, sizeof tb
);
623 memset(linkinfo
, 0, sizeof linkinfo
);
624 netlink_parse_rtattr(tb
, IFLA_MAX
, IFLA_RTA(ifi
), len
);
626 /* check for wireless messages to ignore */
627 if ((tb
[IFLA_WIRELESS
] != NULL
) && (ifi
->ifi_change
== 0)) {
628 if (IS_ZEBRA_DEBUG_KERNEL
)
629 zlog_debug("%s: ignoring IFLA_WIRELESS message",
634 if (tb
[IFLA_IFNAME
] == NULL
)
636 name
= (char *)RTA_DATA(tb
[IFLA_IFNAME
]);
638 if (tb
[IFLA_IFALIAS
])
639 desc
= (char *)RTA_DATA(tb
[IFLA_IFALIAS
]);
641 if (tb
[IFLA_LINKINFO
]) {
642 parse_rtattr_nested(linkinfo
, IFLA_INFO_MAX
, tb
[IFLA_LINKINFO
]);
644 if (linkinfo
[IFLA_INFO_KIND
])
645 kind
= RTA_DATA(linkinfo
[IFLA_INFO_KIND
]);
647 if (linkinfo
[IFLA_INFO_SLAVE_KIND
])
648 slave_kind
= RTA_DATA(linkinfo
[IFLA_INFO_SLAVE_KIND
]);
650 if ((slave_kind
!= NULL
) && strcmp(slave_kind
, "bond") == 0)
651 netlink_determine_zebra_iftype("bond_slave", &zif_type
);
653 netlink_determine_zebra_iftype(kind
, &zif_type
);
656 /* If VRF, create the VRF structure itself. */
657 if (zif_type
== ZEBRA_IF_VRF
&& !vrf_is_backend_netns()) {
658 netlink_vrf_change(h
, tb
[IFLA_LINKINFO
], name
);
659 vrf_id
= (vrf_id_t
)ifi
->ifi_index
;
662 if (tb
[IFLA_MASTER
]) {
663 if (slave_kind
&& (strcmp(slave_kind
, "vrf") == 0)
664 && !vrf_is_backend_netns()) {
665 zif_slave_type
= ZEBRA_IF_SLAVE_VRF
;
666 vrf_id
= *(uint32_t *)RTA_DATA(tb
[IFLA_MASTER
]);
667 } else if (slave_kind
&& (strcmp(slave_kind
, "bridge") == 0)) {
668 zif_slave_type
= ZEBRA_IF_SLAVE_BRIDGE
;
670 *(ifindex_t
*)RTA_DATA(tb
[IFLA_MASTER
]);
671 } else if (slave_kind
&& (strcmp(slave_kind
, "bond") == 0)) {
672 zif_slave_type
= ZEBRA_IF_SLAVE_BOND
;
673 bond_ifindex
= *(ifindex_t
*)RTA_DATA(tb
[IFLA_MASTER
]);
675 zif_slave_type
= ZEBRA_IF_SLAVE_OTHER
;
677 if (vrf_is_backend_netns())
678 vrf_id
= (vrf_id_t
)ns_id
;
680 /* If linking to another interface, note it. */
682 link_ifindex
= *(ifindex_t
*)RTA_DATA(tb
[IFLA_LINK
]);
685 ifp
= if_get_by_name(name
, vrf_id
);
686 set_ifindex(ifp
, ifi
->ifi_index
, zns
);
687 ifp
->flags
= ifi
->ifi_flags
& 0x0000fffff;
688 ifp
->mtu6
= ifp
->mtu
= *(uint32_t *)RTA_DATA(tb
[IFLA_MTU
]);
690 ifp
->speed
= get_iflink_speed(ifp
);
691 ifp
->ptm_status
= ZEBRA_PTM_STATUS_UNKNOWN
;
694 ifp
->desc
= XSTRDUP(MTYPE_TMP
, desc
);
696 /* Set zebra interface type */
697 zebra_if_set_ziftype(ifp
, zif_type
, zif_slave_type
);
698 if (IS_ZEBRA_IF_VRF(ifp
))
699 SET_FLAG(ifp
->status
, ZEBRA_INTERFACE_VRF_LOOPBACK
);
702 * Just set the @link/lower-device ifindex. During nldump interfaces are
703 * not ordered in any fashion so we may end up getting upper devices
704 * before lower devices. We will setup the real linkage once the dump
707 zif
= (struct zebra_if
*)ifp
->info
;
708 zif
->link_ifindex
= link_ifindex
;
710 /* Hardware type and address. */
711 ifp
->ll_type
= netlink_to_zebra_link_type(ifi
->ifi_type
);
712 netlink_interface_update_hw_addr(tb
, ifp
);
716 /* Extract and save L2 interface information, take additional actions.
718 netlink_interface_update_l2info(ifp
, linkinfo
[IFLA_INFO_DATA
], 1);
719 if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp
))
720 zebra_l2if_update_bridge_slave(ifp
, bridge_ifindex
);
721 else if (IS_ZEBRA_IF_BOND_SLAVE(ifp
))
722 zebra_l2if_update_bond_slave(ifp
, bond_ifindex
);
727 /* Request for specific interface or address information from the kernel */
728 static int netlink_request_intf_addr(struct nlsock
*netlink_cmd
, int family
,
729 int type
, uint32_t filter_mask
)
733 struct ifinfomsg ifm
;
737 /* Form the request, specifying filter (rtattr) if needed. */
738 memset(&req
, 0, sizeof(req
));
739 req
.n
.nlmsg_type
= type
;
740 req
.n
.nlmsg_flags
= NLM_F_ROOT
| NLM_F_MATCH
| NLM_F_REQUEST
;
741 req
.n
.nlmsg_len
= NLMSG_LENGTH(sizeof(struct ifinfomsg
));
742 req
.ifm
.ifi_family
= family
;
744 /* Include filter, if specified. */
746 addattr32(&req
.n
, sizeof(req
), IFLA_EXT_MASK
, filter_mask
);
748 return netlink_request(netlink_cmd
, &req
.n
);
751 /* Interface lookup by netlink socket. */
752 int interface_lookup_netlink(struct zebra_ns
*zns
)
755 struct zebra_dplane_info dp_info
;
756 struct nlsock
*netlink_cmd
= &zns
->netlink_cmd
;
758 /* Capture key info from ns struct */
759 zebra_dplane_info_from_zns(&dp_info
, zns
, true /*is_cmd*/);
761 /* Get interface information. */
762 ret
= netlink_request_intf_addr(netlink_cmd
, AF_PACKET
, RTM_GETLINK
, 0);
765 ret
= netlink_parse_info(netlink_interface
, netlink_cmd
, &dp_info
, 0,
770 /* Get interface information - for bridge interfaces. */
771 ret
= netlink_request_intf_addr(netlink_cmd
, AF_BRIDGE
, RTM_GETLINK
,
772 RTEXT_FILTER_BRVLAN
);
775 ret
= netlink_parse_info(netlink_interface
, netlink_cmd
, &dp_info
, 0,
780 /* Get interface information - for bridge interfaces. */
781 ret
= netlink_request_intf_addr(netlink_cmd
, AF_BRIDGE
, RTM_GETLINK
,
782 RTEXT_FILTER_BRVLAN
);
785 ret
= netlink_parse_info(netlink_interface
, netlink_cmd
, &dp_info
, 0,
791 zebra_if_update_all_links();
793 /* Get IPv4 address of the interfaces. */
794 ret
= netlink_request_intf_addr(netlink_cmd
, AF_INET
, RTM_GETADDR
, 0);
797 ret
= netlink_parse_info(netlink_interface_addr
, netlink_cmd
, &dp_info
,
802 /* Get IPv6 address of the interfaces. */
803 ret
= netlink_request_intf_addr(netlink_cmd
, AF_INET6
, RTM_GETADDR
, 0);
806 ret
= netlink_parse_info(netlink_interface_addr
, netlink_cmd
, &dp_info
,
814 int kernel_interface_set_master(struct interface
*master
,
815 struct interface
*slave
)
817 struct zebra_ns
*zns
= zebra_ns_lookup(NS_DEFAULT
);
821 struct ifinfomsg ifa
;
822 char buf
[NL_PKT_BUF_SIZE
];
825 memset(&req
, 0, sizeof req
);
827 req
.n
.nlmsg_len
= NLMSG_LENGTH(sizeof(struct ifinfomsg
));
828 req
.n
.nlmsg_flags
= NLM_F_REQUEST
;
829 req
.n
.nlmsg_type
= RTM_SETLINK
;
830 req
.n
.nlmsg_pid
= zns
->netlink_cmd
.snl
.nl_pid
;
832 req
.ifa
.ifi_index
= slave
->ifindex
;
834 addattr_l(&req
.n
, sizeof req
, IFLA_MASTER
, &master
->ifindex
, 4);
835 addattr_l(&req
.n
, sizeof req
, IFLA_LINK
, &slave
->ifindex
, 4);
837 return netlink_talk(netlink_talk_filter
, &req
.n
, &zns
->netlink_cmd
, zns
,
841 /* Interface address modification. */
842 static int netlink_address(int cmd
, int family
, struct interface
*ifp
,
843 struct connected
*ifc
)
850 struct ifaddrmsg ifa
;
851 char buf
[NL_PKT_BUF_SIZE
];
854 struct zebra_ns
*zns
;
856 if (vrf_is_backend_netns())
857 zns
= zebra_ns_lookup((ns_id_t
)ifp
->vrf_id
);
859 zns
= zebra_ns_lookup(NS_DEFAULT
);
861 memset(&req
, 0, sizeof req
- NL_PKT_BUF_SIZE
);
863 bytelen
= (family
== AF_INET
? 4 : 16);
865 req
.n
.nlmsg_len
= NLMSG_LENGTH(sizeof(struct ifaddrmsg
));
866 req
.n
.nlmsg_flags
= NLM_F_REQUEST
;
867 req
.n
.nlmsg_type
= cmd
;
868 req
.n
.nlmsg_pid
= zns
->netlink_cmd
.snl
.nl_pid
;
870 req
.ifa
.ifa_family
= family
;
872 req
.ifa
.ifa_index
= ifp
->ifindex
;
874 addattr_l(&req
.n
, sizeof req
, IFA_LOCAL
, &p
->u
.prefix
, bytelen
);
876 if (family
== AF_INET
) {
877 if (CONNECTED_PEER(ifc
)) {
878 p
= ifc
->destination
;
879 addattr_l(&req
.n
, sizeof req
, IFA_ADDRESS
, &p
->u
.prefix
,
881 } else if (cmd
== RTM_NEWADDR
&& ifc
->destination
) {
882 p
= ifc
->destination
;
883 addattr_l(&req
.n
, sizeof req
, IFA_BROADCAST
,
884 &p
->u
.prefix
, bytelen
);
888 /* p is now either ifc->address or ifc->destination */
889 req
.ifa
.ifa_prefixlen
= p
->prefixlen
;
891 if (CHECK_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
))
892 SET_FLAG(req
.ifa
.ifa_flags
, IFA_F_SECONDARY
);
895 addattr_l(&req
.n
, sizeof req
, IFA_LABEL
, ifc
->label
,
896 strlen(ifc
->label
) + 1);
898 return netlink_talk(netlink_talk_filter
, &req
.n
, &zns
->netlink_cmd
, zns
,
902 int kernel_address_add_ipv4(struct interface
*ifp
, struct connected
*ifc
)
904 return netlink_address(RTM_NEWADDR
, AF_INET
, ifp
, ifc
);
907 int kernel_address_delete_ipv4(struct interface
*ifp
, struct connected
*ifc
)
909 return netlink_address(RTM_DELADDR
, AF_INET
, ifp
, ifc
);
912 int kernel_address_add_ipv6(struct interface
*ifp
, struct connected
*ifc
)
914 return netlink_address(RTM_NEWADDR
, AF_INET6
, ifp
, ifc
);
917 int kernel_address_delete_ipv6(struct interface
*ifp
, struct connected
*ifc
)
919 return netlink_address(RTM_DELADDR
, AF_INET6
, ifp
, ifc
);
922 int netlink_interface_addr(struct nlmsghdr
*h
, ns_id_t ns_id
, int startup
)
925 struct ifaddrmsg
*ifa
;
926 struct rtattr
*tb
[IFA_MAX
+ 1];
927 struct interface
*ifp
;
932 struct zebra_ns
*zns
;
933 uint32_t metric
= METRIC_MAX
;
934 uint32_t kernel_flags
= 0;
936 zns
= zebra_ns_lookup(ns_id
);
939 if (ifa
->ifa_family
!= AF_INET
&& ifa
->ifa_family
!= AF_INET6
) {
941 EC_ZEBRA_UNKNOWN_FAMILY
,
942 "Invalid address family: %u received from kernel interface addr change: %s",
943 ifa
->ifa_family
, nl_msg_type_to_str(h
->nlmsg_type
));
947 if (h
->nlmsg_type
!= RTM_NEWADDR
&& h
->nlmsg_type
!= RTM_DELADDR
)
950 len
= h
->nlmsg_len
- NLMSG_LENGTH(sizeof(struct ifaddrmsg
));
952 zlog_err("%s: Message received from netlink is of a broken size: %d %zu",
955 (size_t)NLMSG_LENGTH(sizeof(struct ifaddrmsg
)));
959 memset(tb
, 0, sizeof tb
);
960 netlink_parse_rtattr(tb
, IFA_MAX
, IFA_RTA(ifa
), len
);
962 ifp
= if_lookup_by_index_per_ns(zns
, ifa
->ifa_index
);
966 "netlink_interface_addr can't find interface by index %d",
971 /* Flags passed through */
973 kernel_flags
= *(int *)RTA_DATA(tb
[IFA_FLAGS
]);
975 kernel_flags
= ifa
->ifa_flags
;
977 if (IS_ZEBRA_DEBUG_KERNEL
) /* remove this line to see initial ifcfg */
980 zlog_debug("netlink_interface_addr %s %s flags 0x%x:",
981 nl_msg_type_to_str(h
->nlmsg_type
), ifp
->name
,
984 zlog_debug(" IFA_LOCAL %s/%d",
985 inet_ntop(ifa
->ifa_family
,
986 RTA_DATA(tb
[IFA_LOCAL
]), buf
,
990 zlog_debug(" IFA_ADDRESS %s/%d",
991 inet_ntop(ifa
->ifa_family
,
992 RTA_DATA(tb
[IFA_ADDRESS
]), buf
,
995 if (tb
[IFA_BROADCAST
])
996 zlog_debug(" IFA_BROADCAST %s/%d",
997 inet_ntop(ifa
->ifa_family
,
998 RTA_DATA(tb
[IFA_BROADCAST
]), buf
,
1000 ifa
->ifa_prefixlen
);
1001 if (tb
[IFA_LABEL
] && strcmp(ifp
->name
, RTA_DATA(tb
[IFA_LABEL
])))
1002 zlog_debug(" IFA_LABEL %s",
1003 (char *)RTA_DATA(tb
[IFA_LABEL
]));
1005 if (tb
[IFA_CACHEINFO
]) {
1006 struct ifa_cacheinfo
*ci
= RTA_DATA(tb
[IFA_CACHEINFO
]);
1007 zlog_debug(" IFA_CACHEINFO pref %d, valid %d",
1008 ci
->ifa_prefered
, ci
->ifa_valid
);
1012 /* logic copied from iproute2/ip/ipaddress.c:print_addrinfo() */
1013 if (tb
[IFA_LOCAL
] == NULL
)
1014 tb
[IFA_LOCAL
] = tb
[IFA_ADDRESS
];
1015 if (tb
[IFA_ADDRESS
] == NULL
)
1016 tb
[IFA_ADDRESS
] = tb
[IFA_LOCAL
];
1018 /* local interface address */
1019 addr
= (tb
[IFA_LOCAL
] ? RTA_DATA(tb
[IFA_LOCAL
]) : NULL
);
1021 /* is there a peer address? */
1023 && memcmp(RTA_DATA(tb
[IFA_ADDRESS
]), RTA_DATA(tb
[IFA_LOCAL
]),
1024 RTA_PAYLOAD(tb
[IFA_ADDRESS
]))) {
1025 broad
= RTA_DATA(tb
[IFA_ADDRESS
]);
1026 SET_FLAG(flags
, ZEBRA_IFA_PEER
);
1028 /* seeking a broadcast address */
1029 broad
= (tb
[IFA_BROADCAST
] ? RTA_DATA(tb
[IFA_BROADCAST
])
1032 /* addr is primary key, SOL if we don't have one */
1034 zlog_debug("%s: NULL address", __func__
);
1039 if (kernel_flags
& IFA_F_SECONDARY
)
1040 SET_FLAG(flags
, ZEBRA_IFA_SECONDARY
);
1044 label
= (char *)RTA_DATA(tb
[IFA_LABEL
]);
1046 if (label
&& strcmp(ifp
->name
, label
) == 0)
1049 if (tb
[IFA_RT_PRIORITY
])
1050 metric
= *(uint32_t *)RTA_DATA(tb
[IFA_RT_PRIORITY
]);
1052 /* Register interface address to the interface. */
1053 if (ifa
->ifa_family
== AF_INET
) {
1054 if (ifa
->ifa_prefixlen
> IPV4_MAX_BITLEN
) {
1056 "Invalid prefix length: %u received from kernel interface addr change: %s",
1058 nl_msg_type_to_str(h
->nlmsg_type
));
1061 if (h
->nlmsg_type
== RTM_NEWADDR
)
1062 connected_add_ipv4(ifp
, flags
, (struct in_addr
*)addr
,
1064 (struct in_addr
*)broad
, label
,
1067 connected_delete_ipv4(
1068 ifp
, flags
, (struct in_addr
*)addr
,
1069 ifa
->ifa_prefixlen
, (struct in_addr
*)broad
);
1071 if (ifa
->ifa_family
== AF_INET6
) {
1072 if (ifa
->ifa_prefixlen
> IPV6_MAX_BITLEN
) {
1074 "Invalid prefix length: %u received from kernel interface addr change: %s",
1076 nl_msg_type_to_str(h
->nlmsg_type
));
1079 if (h
->nlmsg_type
== RTM_NEWADDR
) {
1080 /* Only consider valid addresses; we'll not get a
1082 * the kernel till IPv6 DAD has completed, but at init
1084 * does query for and will receive all addresses.
1087 & (IFA_F_DADFAILED
| IFA_F_TENTATIVE
)))
1088 connected_add_ipv6(ifp
, flags
,
1089 (struct in6_addr
*)addr
,
1090 (struct in6_addr
*)broad
,
1091 ifa
->ifa_prefixlen
, label
,
1094 connected_delete_ipv6(ifp
, (struct in6_addr
*)addr
,
1095 (struct in6_addr
*)broad
,
1096 ifa
->ifa_prefixlen
);
1102 int netlink_link_change(struct nlmsghdr
*h
, ns_id_t ns_id
, int startup
)
1105 struct ifinfomsg
*ifi
;
1106 struct rtattr
*tb
[IFLA_MAX
+ 1];
1107 struct rtattr
*linkinfo
[IFLA_MAX
+ 1];
1108 struct interface
*ifp
;
1112 char *slave_kind
= NULL
;
1113 struct zebra_ns
*zns
;
1114 vrf_id_t vrf_id
= VRF_DEFAULT
;
1115 zebra_iftype_t zif_type
= ZEBRA_IF_OTHER
;
1116 zebra_slave_iftype_t zif_slave_type
= ZEBRA_IF_SLAVE_NONE
;
1117 ifindex_t bridge_ifindex
= IFINDEX_INTERNAL
;
1118 ifindex_t bond_ifindex
= IFINDEX_INTERNAL
;
1119 ifindex_t link_ifindex
= IFINDEX_INTERNAL
;
1120 uint8_t old_hw_addr
[INTERFACE_HWADDR_MAX
];
1123 zns
= zebra_ns_lookup(ns_id
);
1124 ifi
= NLMSG_DATA(h
);
1126 /* assume if not default zns, then new VRF */
1127 if (!(h
->nlmsg_type
== RTM_NEWLINK
|| h
->nlmsg_type
== RTM_DELLINK
)) {
1128 /* If this is not link add/delete message so print warning. */
1129 zlog_debug("netlink_link_change: wrong kernel message %s",
1130 nl_msg_type_to_str(h
->nlmsg_type
));
1134 if (!(ifi
->ifi_family
== AF_UNSPEC
|| ifi
->ifi_family
== AF_BRIDGE
1135 || ifi
->ifi_family
== AF_INET6
)) {
1137 EC_ZEBRA_UNKNOWN_FAMILY
,
1138 "Invalid address family: %u received from kernel link change: %s",
1139 ifi
->ifi_family
, nl_msg_type_to_str(h
->nlmsg_type
));
1143 len
= h
->nlmsg_len
- NLMSG_LENGTH(sizeof(struct ifinfomsg
));
1145 zlog_err("%s: Message received from netlink is of a broken size %d %zu",
1146 __PRETTY_FUNCTION__
, h
->nlmsg_len
,
1147 (size_t)NLMSG_LENGTH(sizeof(struct ifinfomsg
)));
1151 /* We are interested in some AF_BRIDGE notifications. */
1152 if (ifi
->ifi_family
== AF_BRIDGE
)
1153 return netlink_bridge_interface(h
, len
, ns_id
, startup
);
1155 /* Looking up interface name. */
1156 memset(tb
, 0, sizeof tb
);
1157 memset(linkinfo
, 0, sizeof linkinfo
);
1158 netlink_parse_rtattr(tb
, IFLA_MAX
, IFLA_RTA(ifi
), len
);
1160 /* check for wireless messages to ignore */
1161 if ((tb
[IFLA_WIRELESS
] != NULL
) && (ifi
->ifi_change
== 0)) {
1162 if (IS_ZEBRA_DEBUG_KERNEL
)
1163 zlog_debug("%s: ignoring IFLA_WIRELESS message",
1168 if (tb
[IFLA_IFNAME
] == NULL
)
1170 name
= (char *)RTA_DATA(tb
[IFLA_IFNAME
]);
1172 if (tb
[IFLA_LINKINFO
]) {
1173 parse_rtattr_nested(linkinfo
, IFLA_INFO_MAX
, tb
[IFLA_LINKINFO
]);
1175 if (linkinfo
[IFLA_INFO_KIND
])
1176 kind
= RTA_DATA(linkinfo
[IFLA_INFO_KIND
]);
1178 if (linkinfo
[IFLA_INFO_SLAVE_KIND
])
1179 slave_kind
= RTA_DATA(linkinfo
[IFLA_INFO_SLAVE_KIND
]);
1181 netlink_determine_zebra_iftype(kind
, &zif_type
);
1184 /* If linking to another interface, note it. */
1186 link_ifindex
= *(ifindex_t
*)RTA_DATA(tb
[IFLA_LINK
]);
1188 if (tb
[IFLA_IFALIAS
]) {
1189 desc
= (char *)RTA_DATA(tb
[IFLA_IFALIAS
]);
1192 /* If VRF, create or update the VRF structure itself. */
1193 if (zif_type
== ZEBRA_IF_VRF
&& !vrf_is_backend_netns()) {
1194 netlink_vrf_change(h
, tb
[IFLA_LINKINFO
], name
);
1195 vrf_id
= (vrf_id_t
)ifi
->ifi_index
;
1198 /* See if interface is present. */
1199 ifp
= if_lookup_by_name_per_ns(zns
, name
);
1202 XFREE(MTYPE_TMP
, ifp
->desc
);
1204 ifp
->desc
= XSTRDUP(MTYPE_TMP
, desc
);
1207 if (h
->nlmsg_type
== RTM_NEWLINK
) {
1208 if (tb
[IFLA_MASTER
]) {
1209 if (slave_kind
&& (strcmp(slave_kind
, "vrf") == 0)
1210 && !vrf_is_backend_netns()) {
1211 zif_slave_type
= ZEBRA_IF_SLAVE_VRF
;
1212 vrf_id
= *(uint32_t *)RTA_DATA(tb
[IFLA_MASTER
]);
1213 } else if (slave_kind
1214 && (strcmp(slave_kind
, "bridge") == 0)) {
1215 zif_slave_type
= ZEBRA_IF_SLAVE_BRIDGE
;
1217 *(ifindex_t
*)RTA_DATA(tb
[IFLA_MASTER
]);
1218 } else if (slave_kind
1219 && (strcmp(slave_kind
, "bond") == 0)) {
1220 zif_slave_type
= ZEBRA_IF_SLAVE_BOND
;
1222 *(ifindex_t
*)RTA_DATA(tb
[IFLA_MASTER
]);
1224 zif_slave_type
= ZEBRA_IF_SLAVE_OTHER
;
1226 if (vrf_is_backend_netns())
1227 vrf_id
= (vrf_id_t
)ns_id
;
1229 || !CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
1230 /* Add interface notification from kernel */
1231 if (IS_ZEBRA_DEBUG_KERNEL
)
1233 "RTM_NEWLINK ADD for %s(%u) vrf_id %u type %d "
1234 "sl_type %d master %u flags 0x%x",
1235 name
, ifi
->ifi_index
, vrf_id
, zif_type
,
1236 zif_slave_type
, bridge_ifindex
,
1240 /* unknown interface */
1241 ifp
= if_get_by_name(name
, vrf_id
);
1243 /* pre-configured interface, learnt now */
1244 if (ifp
->vrf_id
!= vrf_id
)
1245 if_update_to_new_vrf(ifp
, vrf_id
);
1248 /* Update interface information. */
1249 set_ifindex(ifp
, ifi
->ifi_index
, zns
);
1250 ifp
->flags
= ifi
->ifi_flags
& 0x0000fffff;
1251 if (!tb
[IFLA_MTU
]) {
1253 "RTM_NEWLINK for interface %s(%u) without MTU set",
1254 name
, ifi
->ifi_index
);
1257 ifp
->mtu6
= ifp
->mtu
= *(int *)RTA_DATA(tb
[IFLA_MTU
]);
1259 ifp
->ptm_status
= ZEBRA_PTM_STATUS_UNKNOWN
;
1261 /* Set interface type */
1262 zebra_if_set_ziftype(ifp
, zif_type
, zif_slave_type
);
1263 if (IS_ZEBRA_IF_VRF(ifp
))
1264 SET_FLAG(ifp
->status
,
1265 ZEBRA_INTERFACE_VRF_LOOPBACK
);
1268 zebra_if_update_link(ifp
, link_ifindex
, ns_id
);
1270 netlink_interface_update_hw_addr(tb
, ifp
);
1272 /* Inform clients, install any configured addresses. */
1275 /* Extract and save L2 interface information, take
1276 * additional actions. */
1277 netlink_interface_update_l2info(
1278 ifp
, linkinfo
[IFLA_INFO_DATA
], 1);
1279 if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp
))
1280 zebra_l2if_update_bridge_slave(ifp
,
1282 else if (IS_ZEBRA_IF_BOND_SLAVE(ifp
))
1283 zebra_l2if_update_bond_slave(ifp
, bond_ifindex
);
1284 } else if (ifp
->vrf_id
!= vrf_id
) {
1285 /* VRF change for an interface. */
1286 if (IS_ZEBRA_DEBUG_KERNEL
)
1288 "RTM_NEWLINK vrf-change for %s(%u) "
1289 "vrf_id %u -> %u flags 0x%x",
1290 name
, ifp
->ifindex
, ifp
->vrf_id
, vrf_id
,
1293 if_handle_vrf_change(ifp
, vrf_id
);
1295 bool was_bridge_slave
, was_bond_slave
;
1297 /* Interface update. */
1298 if (IS_ZEBRA_DEBUG_KERNEL
)
1300 "RTM_NEWLINK update for %s(%u) "
1301 "sl_type %d master %u flags 0x%x",
1302 name
, ifp
->ifindex
, zif_slave_type
,
1303 bridge_ifindex
, ifi
->ifi_flags
);
1305 set_ifindex(ifp
, ifi
->ifi_index
, zns
);
1306 if (!tb
[IFLA_MTU
]) {
1308 "RTM_NEWLINK for interface %s(%u) without MTU set",
1309 name
, ifi
->ifi_index
);
1312 ifp
->mtu6
= ifp
->mtu
= *(int *)RTA_DATA(tb
[IFLA_MTU
]);
1315 /* Update interface type - NOTE: Only slave_type can
1317 was_bridge_slave
= IS_ZEBRA_IF_BRIDGE_SLAVE(ifp
);
1318 was_bond_slave
= IS_ZEBRA_IF_BOND_SLAVE(ifp
);
1319 zebra_if_set_ziftype(ifp
, zif_type
, zif_slave_type
);
1321 memcpy(old_hw_addr
, ifp
->hw_addr
, INTERFACE_HWADDR_MAX
);
1323 netlink_interface_update_hw_addr(tb
, ifp
);
1325 if (if_is_no_ptm_operative(ifp
)) {
1326 ifp
->flags
= ifi
->ifi_flags
& 0x0000fffff;
1327 if (!if_is_no_ptm_operative(ifp
)) {
1328 if (IS_ZEBRA_DEBUG_KERNEL
)
1330 "Intf %s(%u) has gone DOWN",
1331 name
, ifp
->ifindex
);
1333 } else if (if_is_operative(ifp
)) {
1334 /* Must notify client daemons of new
1335 * interface status. */
1336 if (IS_ZEBRA_DEBUG_KERNEL
)
1338 "Intf %s(%u) PTM up, notifying clients",
1339 name
, ifp
->ifindex
);
1340 zebra_interface_up_update(ifp
);
1342 /* Update EVPN VNI when SVI MAC change
1344 if (IS_ZEBRA_IF_VLAN(ifp
) &&
1345 memcmp(old_hw_addr
, ifp
->hw_addr
,
1346 INTERFACE_HWADDR_MAX
)) {
1347 struct interface
*link_if
;
1350 if_lookup_by_index_per_ns(
1351 zebra_ns_lookup(NS_DEFAULT
),
1354 zebra_vxlan_svi_up(ifp
,
1359 ifp
->flags
= ifi
->ifi_flags
& 0x0000fffff;
1360 if (if_is_operative(ifp
)) {
1361 if (IS_ZEBRA_DEBUG_KERNEL
)
1363 "Intf %s(%u) has come UP",
1364 name
, ifp
->ifindex
);
1369 /* Extract and save L2 interface information, take
1370 * additional actions. */
1371 netlink_interface_update_l2info(
1372 ifp
, linkinfo
[IFLA_INFO_DATA
], 0);
1373 if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp
) || was_bridge_slave
)
1374 zebra_l2if_update_bridge_slave(ifp
,
1376 else if (IS_ZEBRA_IF_BOND_SLAVE(ifp
) || was_bond_slave
)
1377 zebra_l2if_update_bond_slave(ifp
, bond_ifindex
);
1380 /* Delete interface notification from kernel */
1382 if (IS_ZEBRA_DEBUG_KERNEL
)
1384 "RTM_DELLINK for unknown interface %s(%u)",
1385 name
, ifi
->ifi_index
);
1389 if (IS_ZEBRA_DEBUG_KERNEL
)
1390 zlog_debug("RTM_DELLINK for %s(%u)", name
,
1393 UNSET_FLAG(ifp
->status
, ZEBRA_INTERFACE_VRF_LOOPBACK
);
1395 /* Special handling for bridge or VxLAN interfaces. */
1396 if (IS_ZEBRA_IF_BRIDGE(ifp
))
1397 zebra_l2_bridge_del(ifp
);
1398 else if (IS_ZEBRA_IF_VXLAN(ifp
))
1399 zebra_l2_vxlanif_del(ifp
);
1401 if (!IS_ZEBRA_IF_VRF(ifp
))
1402 if_delete_update(ifp
);
1408 /* Interface information read by netlink. */
1409 void interface_list(struct zebra_ns
*zns
)
1411 interface_lookup_netlink(zns
);
1414 #endif /* GNU_LINUX */