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"
72 extern struct zebra_privs_t zserv_privs
;
74 /* Note: on netlink systems, there should be a 1-to-1 mapping between interface
75 names and ifindex values. */
76 static void set_ifindex(struct interface
*ifp
, ifindex_t ifi_index
,
79 struct interface
*oifp
;
81 if (((oifp
= if_lookup_by_index_per_ns(zns
, ifi_index
)) != NULL
)
83 if (ifi_index
== IFINDEX_INTERNAL
)
86 "Netlink is setting interface %s ifindex to reserved internal value %u",
87 ifp
->name
, ifi_index
);
89 if (IS_ZEBRA_DEBUG_KERNEL
)
91 "interface index %d was renamed from %s to %s",
92 ifi_index
, oifp
->name
, ifp
->name
);
96 "interface rename detected on up interface: index %d was renamed from %s to %s, results are uncertain!",
97 ifi_index
, oifp
->name
, ifp
->name
);
98 if_delete_update(oifp
);
101 if_set_index(ifp
, ifi_index
);
104 /* Utility function to parse hardware link-layer address and update ifp */
105 static void netlink_interface_update_hw_addr(struct rtattr
**tb
,
106 struct interface
*ifp
)
110 if (tb
[IFLA_ADDRESS
]) {
113 hw_addr_len
= RTA_PAYLOAD(tb
[IFLA_ADDRESS
]);
115 if (hw_addr_len
> INTERFACE_HWADDR_MAX
)
116 zlog_debug("Hardware address is too large: %d",
119 ifp
->hw_addr_len
= hw_addr_len
;
120 memcpy(ifp
->hw_addr
, RTA_DATA(tb
[IFLA_ADDRESS
]),
123 for (i
= 0; i
< hw_addr_len
; i
++)
124 if (ifp
->hw_addr
[i
] != 0)
127 if (i
== hw_addr_len
)
128 ifp
->hw_addr_len
= 0;
130 ifp
->hw_addr_len
= hw_addr_len
;
135 static enum zebra_link_type
netlink_to_zebra_link_type(unsigned int hwt
)
139 return ZEBRA_LLT_ETHER
;
141 return ZEBRA_LLT_EETHER
;
143 return ZEBRA_LLT_AX25
;
145 return ZEBRA_LLT_PRONET
;
147 return ZEBRA_LLT_IEEE802
;
149 return ZEBRA_LLT_ARCNET
;
150 case ARPHRD_APPLETLK
:
151 return ZEBRA_LLT_APPLETLK
;
153 return ZEBRA_LLT_DLCI
;
155 return ZEBRA_LLT_ATM
;
156 case ARPHRD_METRICOM
:
157 return ZEBRA_LLT_METRICOM
;
158 case ARPHRD_IEEE1394
:
159 return ZEBRA_LLT_IEEE1394
;
161 return ZEBRA_LLT_EUI64
;
162 case ARPHRD_INFINIBAND
:
163 return ZEBRA_LLT_INFINIBAND
;
165 return ZEBRA_LLT_SLIP
;
167 return ZEBRA_LLT_CSLIP
;
169 return ZEBRA_LLT_SLIP6
;
171 return ZEBRA_LLT_CSLIP6
;
173 return ZEBRA_LLT_RSRVD
;
175 return ZEBRA_LLT_ADAPT
;
177 return ZEBRA_LLT_ROSE
;
179 return ZEBRA_LLT_X25
;
181 return ZEBRA_LLT_PPP
;
183 return ZEBRA_LLT_CHDLC
;
185 return ZEBRA_LLT_LAPB
;
187 return ZEBRA_LLT_RAWHDLC
;
189 return ZEBRA_LLT_IPIP
;
191 return ZEBRA_LLT_IPIP6
;
193 return ZEBRA_LLT_FRAD
;
195 return ZEBRA_LLT_SKIP
;
196 case ARPHRD_LOOPBACK
:
197 return ZEBRA_LLT_LOOPBACK
;
198 case ARPHRD_LOCALTLK
:
199 return ZEBRA_LLT_LOCALTLK
;
201 return ZEBRA_LLT_FDDI
;
203 return ZEBRA_LLT_SIT
;
205 return ZEBRA_LLT_IPDDP
;
207 return ZEBRA_LLT_IPGRE
;
209 return ZEBRA_LLT_PIMREG
;
211 return ZEBRA_LLT_HIPPI
;
213 return ZEBRA_LLT_ECONET
;
215 return ZEBRA_LLT_IRDA
;
217 return ZEBRA_LLT_FCPP
;
219 return ZEBRA_LLT_FCAL
;
221 return ZEBRA_LLT_FCPL
;
222 case ARPHRD_FCFABRIC
:
223 return ZEBRA_LLT_FCFABRIC
;
224 case ARPHRD_IEEE802_TR
:
225 return ZEBRA_LLT_IEEE802_TR
;
226 case ARPHRD_IEEE80211
:
227 return ZEBRA_LLT_IEEE80211
;
228 #ifdef ARPHRD_IEEE802154
229 case ARPHRD_IEEE802154
:
230 return ZEBRA_LLT_IEEE802154
;
234 return ZEBRA_LLT_IP6GRE
;
236 #ifdef ARPHRD_IEEE802154_PHY
237 case ARPHRD_IEEE802154_PHY
:
238 return ZEBRA_LLT_IEEE802154_PHY
;
242 return ZEBRA_LLT_UNKNOWN
;
246 static void netlink_determine_zebra_iftype(const char *kind
,
247 zebra_iftype_t
*zif_type
)
249 *zif_type
= ZEBRA_IF_OTHER
;
254 if (strcmp(kind
, "vrf") == 0)
255 *zif_type
= ZEBRA_IF_VRF
;
256 else if (strcmp(kind
, "bridge") == 0)
257 *zif_type
= ZEBRA_IF_BRIDGE
;
258 else if (strcmp(kind
, "vlan") == 0)
259 *zif_type
= ZEBRA_IF_VLAN
;
260 else if (strcmp(kind
, "vxlan") == 0)
261 *zif_type
= ZEBRA_IF_VXLAN
;
262 else if (strcmp(kind
, "macvlan") == 0)
263 *zif_type
= ZEBRA_IF_MACVLAN
;
264 else if (strcmp(kind
, "veth") == 0)
265 *zif_type
= ZEBRA_IF_VETH
;
266 else if (strcmp(kind
, "bond") == 0)
267 *zif_type
= ZEBRA_IF_BOND
;
268 else if (strcmp(kind
, "bond_slave") == 0)
269 *zif_type
= ZEBRA_IF_BOND_SLAVE
;
272 #define parse_rtattr_nested(tb, max, rta) \
273 netlink_parse_rtattr((tb), (max), RTA_DATA(rta), RTA_PAYLOAD(rta))
275 static void netlink_vrf_change(struct nlmsghdr
*h
, struct rtattr
*tb
,
278 struct ifinfomsg
*ifi
;
279 struct rtattr
*linkinfo
[IFLA_INFO_MAX
+ 1];
280 struct rtattr
*attr
[IFLA_VRF_MAX
+ 1];
282 struct zebra_vrf
*zvrf
;
283 uint32_t nl_table_id
;
287 memset(linkinfo
, 0, sizeof linkinfo
);
288 parse_rtattr_nested(linkinfo
, IFLA_INFO_MAX
, tb
);
290 if (!linkinfo
[IFLA_INFO_DATA
]) {
291 if (IS_ZEBRA_DEBUG_KERNEL
)
293 "%s: IFLA_INFO_DATA missing from VRF message: %s",
298 memset(attr
, 0, sizeof attr
);
299 parse_rtattr_nested(attr
, IFLA_VRF_MAX
, linkinfo
[IFLA_INFO_DATA
]);
300 if (!attr
[IFLA_VRF_TABLE
]) {
301 if (IS_ZEBRA_DEBUG_KERNEL
)
303 "%s: IFLA_VRF_TABLE missing from VRF message: %s",
308 nl_table_id
= *(uint32_t *)RTA_DATA(attr
[IFLA_VRF_TABLE
]);
310 if (h
->nlmsg_type
== RTM_NEWLINK
) {
311 if (IS_ZEBRA_DEBUG_KERNEL
)
312 zlog_debug("RTM_NEWLINK for VRF %s(%u) table %u", name
,
313 ifi
->ifi_index
, nl_table_id
);
316 * vrf_get is implied creation if it does not exist
318 vrf
= vrf_get((vrf_id_t
)ifi
->ifi_index
,
319 name
); // It would create vrf
321 flog_err(EC_LIB_INTERFACE
, "VRF %s id %u not created",
322 name
, ifi
->ifi_index
);
327 * This is the only place that we get the actual kernel table_id
328 * being used. We need it to set the table_id of the routes
329 * we are passing to the kernel.... And to throw some totally
330 * awesome parties. that too.
332 * At this point we *must* have a zvrf because the vrf_create
333 * callback creates one. We *must* set the table id
334 * before the vrf_enable because of( at the very least )
335 * static routes being delayed for installation until
336 * during the vrf_enable callbacks.
338 zvrf
= (struct zebra_vrf
*)vrf
->info
;
339 zvrf
->table_id
= nl_table_id
;
341 /* Enable the created VRF. */
342 if (!vrf_enable(vrf
)) {
343 flog_err(EC_LIB_INTERFACE
,
344 "Failed to enable VRF %s id %u", name
,
349 } else // h->nlmsg_type == RTM_DELLINK
351 if (IS_ZEBRA_DEBUG_KERNEL
)
352 zlog_debug("RTM_DELLINK for VRF %s(%u)", name
,
355 vrf
= vrf_lookup_by_id((vrf_id_t
)ifi
->ifi_index
);
358 flog_warn(EC_ZEBRA_VRF_NOT_FOUND
, "%s: vrf not found",
367 static int get_iflink_speed(struct interface
*interface
)
370 struct ethtool_cmd ecmd
;
373 const char *ifname
= interface
->name
;
375 /* initialize struct */
376 memset(&ifdata
, 0, sizeof(ifdata
));
378 /* set interface name */
379 strlcpy(ifdata
.ifr_name
, ifname
, sizeof(ifdata
.ifr_name
));
381 /* initialize ethtool interface */
382 memset(&ecmd
, 0, sizeof(ecmd
));
383 ecmd
.cmd
= ETHTOOL_GSET
; /* ETHTOOL_GLINK */
384 ifdata
.ifr_data
= (caddr_t
)&ecmd
;
386 /* use ioctl to get IP address of an interface */
387 frr_elevate_privs(&zserv_privs
) {
388 sd
= vrf_socket(PF_INET
, SOCK_DGRAM
, IPPROTO_IP
,
392 if (IS_ZEBRA_DEBUG_KERNEL
)
393 zlog_debug("Failure to read interface %s speed: %d %s",
394 ifname
, errno
, safe_strerror(errno
));
397 /* Get the current link state for the interface */
398 rc
= vrf_ioctl(interface
->vrf_id
, sd
, SIOCETHTOOL
,
402 if (IS_ZEBRA_DEBUG_KERNEL
)
404 "IOCTL failure to read interface %s speed: %d %s",
405 ifname
, errno
, safe_strerror(errno
));
412 return (ecmd
.speed_hi
<< 16) | ecmd
.speed
;
415 uint32_t kernel_get_speed(struct interface
*ifp
)
417 return get_iflink_speed(ifp
);
420 static int netlink_extract_bridge_info(struct rtattr
*link_data
,
421 struct zebra_l2info_bridge
*bridge_info
)
423 struct rtattr
*attr
[IFLA_BR_MAX
+ 1];
425 memset(bridge_info
, 0, sizeof(*bridge_info
));
426 memset(attr
, 0, sizeof attr
);
427 parse_rtattr_nested(attr
, IFLA_BR_MAX
, link_data
);
428 if (attr
[IFLA_BR_VLAN_FILTERING
])
429 bridge_info
->vlan_aware
=
430 *(uint8_t *)RTA_DATA(attr
[IFLA_BR_VLAN_FILTERING
]);
434 static int netlink_extract_vlan_info(struct rtattr
*link_data
,
435 struct zebra_l2info_vlan
*vlan_info
)
437 struct rtattr
*attr
[IFLA_VLAN_MAX
+ 1];
440 memset(vlan_info
, 0, sizeof(*vlan_info
));
441 memset(attr
, 0, sizeof attr
);
442 parse_rtattr_nested(attr
, IFLA_VLAN_MAX
, link_data
);
443 if (!attr
[IFLA_VLAN_ID
]) {
444 if (IS_ZEBRA_DEBUG_KERNEL
)
445 zlog_debug("IFLA_VLAN_ID missing from VLAN IF message");
449 vid_in_msg
= *(vlanid_t
*)RTA_DATA(attr
[IFLA_VLAN_ID
]);
450 vlan_info
->vid
= vid_in_msg
;
454 static int netlink_extract_vxlan_info(struct rtattr
*link_data
,
455 struct zebra_l2info_vxlan
*vxl_info
)
457 struct rtattr
*attr
[IFLA_VXLAN_MAX
+ 1];
459 struct in_addr vtep_ip_in_msg
;
461 memset(vxl_info
, 0, sizeof(*vxl_info
));
462 memset(attr
, 0, sizeof attr
);
463 parse_rtattr_nested(attr
, IFLA_VXLAN_MAX
, link_data
);
464 if (!attr
[IFLA_VXLAN_ID
]) {
465 if (IS_ZEBRA_DEBUG_KERNEL
)
467 "IFLA_VXLAN_ID missing from VXLAN IF message");
471 vni_in_msg
= *(vni_t
*)RTA_DATA(attr
[IFLA_VXLAN_ID
]);
472 vxl_info
->vni
= vni_in_msg
;
473 if (!attr
[IFLA_VXLAN_LOCAL
]) {
474 if (IS_ZEBRA_DEBUG_KERNEL
)
476 "IFLA_VXLAN_LOCAL missing from VXLAN IF message");
479 *(struct in_addr
*)RTA_DATA(attr
[IFLA_VXLAN_LOCAL
]);
480 vxl_info
->vtep_ip
= vtep_ip_in_msg
;
487 * Extract and save L2 params (of interest) for an interface. When a
488 * bridge interface is added or updated, take further actions to map
489 * its members. Likewise, for VxLAN interface.
491 static void netlink_interface_update_l2info(struct interface
*ifp
,
492 struct rtattr
*link_data
, int add
)
497 if (IS_ZEBRA_IF_BRIDGE(ifp
)) {
498 struct zebra_l2info_bridge bridge_info
;
500 netlink_extract_bridge_info(link_data
, &bridge_info
);
501 zebra_l2_bridge_add_update(ifp
, &bridge_info
, add
);
502 } else if (IS_ZEBRA_IF_VLAN(ifp
)) {
503 struct zebra_l2info_vlan vlan_info
;
505 netlink_extract_vlan_info(link_data
, &vlan_info
);
506 zebra_l2_vlanif_update(ifp
, &vlan_info
);
507 } else if (IS_ZEBRA_IF_VXLAN(ifp
)) {
508 struct zebra_l2info_vxlan vxlan_info
;
510 netlink_extract_vxlan_info(link_data
, &vxlan_info
);
511 zebra_l2_vxlanif_add_update(ifp
, &vxlan_info
, add
);
515 static int netlink_bridge_interface(struct nlmsghdr
*h
, int len
, ns_id_t ns_id
,
519 struct ifinfomsg
*ifi
;
520 struct rtattr
*tb
[IFLA_MAX
+ 1];
521 struct interface
*ifp
;
522 struct rtattr
*aftb
[IFLA_BRIDGE_MAX
+ 1];
527 vlanid_t access_vlan
;
529 /* Fetch name and ifindex */
531 memset(tb
, 0, sizeof tb
);
532 netlink_parse_rtattr(tb
, IFLA_MAX
, IFLA_RTA(ifi
), len
);
534 if (tb
[IFLA_IFNAME
] == NULL
)
536 name
= (char *)RTA_DATA(tb
[IFLA_IFNAME
]);
538 /* The interface should already be known, if not discard. */
539 ifp
= if_lookup_by_index_per_ns(zebra_ns_lookup(ns_id
), ifi
->ifi_index
);
541 zlog_debug("Cannot find bridge IF %s(%u)", name
,
545 if (!IS_ZEBRA_IF_VXLAN(ifp
))
548 /* We are only interested in the access VLAN i.e., AF_SPEC */
549 if (!tb
[IFLA_AF_SPEC
])
552 /* There is a 1-to-1 mapping of VLAN to VxLAN - hence
553 * only 1 access VLAN is accepted.
555 memset(aftb
, 0, sizeof aftb
);
556 parse_rtattr_nested(aftb
, IFLA_BRIDGE_MAX
, tb
[IFLA_AF_SPEC
]);
557 if (!aftb
[IFLA_BRIDGE_VLAN_INFO
])
560 vinfo
= RTA_DATA(aftb
[IFLA_BRIDGE_VLAN_INFO
]);
561 if (!(vinfo
->flags
& BRIDGE_VLAN_INFO_PVID
))
564 access_vlan
= (vlanid_t
)vinfo
->vid
;
565 if (IS_ZEBRA_DEBUG_KERNEL
)
566 zlog_debug("Access VLAN %u for VxLAN IF %s(%u)", access_vlan
,
567 name
, ifi
->ifi_index
);
568 zebra_l2_vxlanif_update_access_vlan(ifp
, access_vlan
);
573 * Called from interface_lookup_netlink(). This function is only used
576 static int netlink_interface(struct nlmsghdr
*h
, ns_id_t ns_id
, int startup
)
579 struct ifinfomsg
*ifi
;
580 struct rtattr
*tb
[IFLA_MAX
+ 1];
581 struct rtattr
*linkinfo
[IFLA_MAX
+ 1];
582 struct interface
*ifp
;
586 char *slave_kind
= NULL
;
587 struct zebra_ns
*zns
;
588 vrf_id_t vrf_id
= VRF_DEFAULT
;
589 zebra_iftype_t zif_type
= ZEBRA_IF_OTHER
;
590 zebra_slave_iftype_t zif_slave_type
= ZEBRA_IF_SLAVE_NONE
;
591 ifindex_t bridge_ifindex
= IFINDEX_INTERNAL
;
592 ifindex_t link_ifindex
= IFINDEX_INTERNAL
;
593 ifindex_t bond_ifindex
= IFINDEX_INTERNAL
;
594 struct zebra_if
*zif
;
596 zns
= zebra_ns_lookup(ns_id
);
599 if (h
->nlmsg_type
!= RTM_NEWLINK
)
602 len
= h
->nlmsg_len
- NLMSG_LENGTH(sizeof(struct ifinfomsg
));
604 zlog_err("%s: Message received from netlink is of a broken size: %d %zu",
607 (size_t)NLMSG_LENGTH(sizeof(struct ifinfomsg
)));
611 /* We are interested in some AF_BRIDGE notifications. */
612 if (ifi
->ifi_family
== AF_BRIDGE
)
613 return netlink_bridge_interface(h
, len
, ns_id
, startup
);
615 /* Looking up interface name. */
616 memset(tb
, 0, sizeof tb
);
617 memset(linkinfo
, 0, sizeof linkinfo
);
618 netlink_parse_rtattr(tb
, IFLA_MAX
, IFLA_RTA(ifi
), len
);
620 /* check for wireless messages to ignore */
621 if ((tb
[IFLA_WIRELESS
] != NULL
) && (ifi
->ifi_change
== 0)) {
622 if (IS_ZEBRA_DEBUG_KERNEL
)
623 zlog_debug("%s: ignoring IFLA_WIRELESS message",
628 if (tb
[IFLA_IFNAME
] == NULL
)
630 name
= (char *)RTA_DATA(tb
[IFLA_IFNAME
]);
632 if (tb
[IFLA_IFALIAS
])
633 desc
= (char *)RTA_DATA(tb
[IFLA_IFALIAS
]);
635 if (tb
[IFLA_LINKINFO
]) {
636 parse_rtattr_nested(linkinfo
, IFLA_INFO_MAX
, tb
[IFLA_LINKINFO
]);
638 if (linkinfo
[IFLA_INFO_KIND
])
639 kind
= RTA_DATA(linkinfo
[IFLA_INFO_KIND
]);
641 if (linkinfo
[IFLA_INFO_SLAVE_KIND
])
642 slave_kind
= RTA_DATA(linkinfo
[IFLA_INFO_SLAVE_KIND
]);
644 if ((slave_kind
!= NULL
) && strcmp(slave_kind
, "bond") == 0)
645 netlink_determine_zebra_iftype("bond_slave", &zif_type
);
647 netlink_determine_zebra_iftype(kind
, &zif_type
);
650 /* If VRF, create the VRF structure itself. */
651 if (zif_type
== ZEBRA_IF_VRF
&& !vrf_is_backend_netns()) {
652 netlink_vrf_change(h
, tb
[IFLA_LINKINFO
], name
);
653 vrf_id
= (vrf_id_t
)ifi
->ifi_index
;
656 if (tb
[IFLA_MASTER
]) {
657 if (slave_kind
&& (strcmp(slave_kind
, "vrf") == 0)
658 && !vrf_is_backend_netns()) {
659 zif_slave_type
= ZEBRA_IF_SLAVE_VRF
;
660 vrf_id
= *(uint32_t *)RTA_DATA(tb
[IFLA_MASTER
]);
661 } else if (slave_kind
&& (strcmp(slave_kind
, "bridge") == 0)) {
662 zif_slave_type
= ZEBRA_IF_SLAVE_BRIDGE
;
664 *(ifindex_t
*)RTA_DATA(tb
[IFLA_MASTER
]);
665 } else if (slave_kind
&& (strcmp(slave_kind
, "bond") == 0)) {
666 zif_slave_type
= ZEBRA_IF_SLAVE_BOND
;
667 bond_ifindex
= *(ifindex_t
*)RTA_DATA(tb
[IFLA_MASTER
]);
669 zif_slave_type
= ZEBRA_IF_SLAVE_OTHER
;
671 if (vrf_is_backend_netns())
672 vrf_id
= (vrf_id_t
)ns_id
;
674 /* If linking to another interface, note it. */
676 link_ifindex
= *(ifindex_t
*)RTA_DATA(tb
[IFLA_LINK
]);
679 ifp
= if_get_by_name(name
, vrf_id
);
680 set_ifindex(ifp
, ifi
->ifi_index
, zns
);
681 ifp
->flags
= ifi
->ifi_flags
& 0x0000fffff;
682 ifp
->mtu6
= ifp
->mtu
= *(uint32_t *)RTA_DATA(tb
[IFLA_MTU
]);
684 ifp
->speed
= get_iflink_speed(ifp
);
685 ifp
->ptm_status
= ZEBRA_PTM_STATUS_UNKNOWN
;
688 ifp
->desc
= XSTRDUP(MTYPE_TMP
, desc
);
690 /* Set zebra interface type */
691 zebra_if_set_ziftype(ifp
, zif_type
, zif_slave_type
);
692 if (IS_ZEBRA_IF_VRF(ifp
))
693 SET_FLAG(ifp
->status
, ZEBRA_INTERFACE_VRF_LOOPBACK
);
696 * Just set the @link/lower-device ifindex. During nldump interfaces are
697 * not ordered in any fashion so we may end up getting upper devices
698 * before lower devices. We will setup the real linkage once the dump
701 zif
= (struct zebra_if
*)ifp
->info
;
702 zif
->link_ifindex
= link_ifindex
;
704 /* Hardware type and address. */
705 ifp
->ll_type
= netlink_to_zebra_link_type(ifi
->ifi_type
);
706 netlink_interface_update_hw_addr(tb
, ifp
);
710 /* Extract and save L2 interface information, take additional actions.
712 netlink_interface_update_l2info(ifp
, linkinfo
[IFLA_INFO_DATA
], 1);
713 if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp
))
714 zebra_l2if_update_bridge_slave(ifp
, bridge_ifindex
);
715 else if (IS_ZEBRA_IF_BOND_SLAVE(ifp
))
716 zebra_l2if_update_bond_slave(ifp
, bond_ifindex
);
721 /* Request for specific interface or address information from the kernel */
722 static int netlink_request_intf_addr(struct nlsock
*netlink_cmd
, int family
,
723 int type
, uint32_t filter_mask
)
727 struct ifinfomsg ifm
;
731 /* Form the request, specifying filter (rtattr) if needed. */
732 memset(&req
, 0, sizeof(req
));
733 req
.n
.nlmsg_type
= type
;
734 req
.n
.nlmsg_len
= NLMSG_LENGTH(sizeof(struct ifinfomsg
));
735 req
.ifm
.ifi_family
= family
;
737 /* Include filter, if specified. */
739 addattr32(&req
.n
, sizeof(req
), IFLA_EXT_MASK
, filter_mask
);
741 return netlink_request(netlink_cmd
, &req
.n
);
744 /* Interface lookup by netlink socket. */
745 int interface_lookup_netlink(struct zebra_ns
*zns
)
748 struct zebra_dplane_info dp_info
;
749 struct nlsock
*netlink_cmd
= &zns
->netlink_cmd
;
751 /* Capture key info from ns struct */
752 zebra_dplane_info_from_zns(&dp_info
, zns
, true /*is_cmd*/);
754 /* Get interface information. */
755 ret
= netlink_request_intf_addr(netlink_cmd
, AF_PACKET
, RTM_GETLINK
, 0);
758 ret
= netlink_parse_info(netlink_interface
, netlink_cmd
, &dp_info
, 0,
763 /* Get interface information - for bridge interfaces. */
764 ret
= netlink_request_intf_addr(netlink_cmd
, AF_BRIDGE
, RTM_GETLINK
,
765 RTEXT_FILTER_BRVLAN
);
768 ret
= netlink_parse_info(netlink_interface
, netlink_cmd
, &dp_info
, 0,
773 /* Get interface information - for bridge interfaces. */
774 ret
= netlink_request_intf_addr(netlink_cmd
, AF_BRIDGE
, RTM_GETLINK
,
775 RTEXT_FILTER_BRVLAN
);
778 ret
= netlink_parse_info(netlink_interface
, netlink_cmd
, &dp_info
, 0,
784 zebra_if_update_all_links();
786 /* Get IPv4 address of the interfaces. */
787 ret
= netlink_request_intf_addr(netlink_cmd
, AF_INET
, RTM_GETADDR
, 0);
790 ret
= netlink_parse_info(netlink_interface_addr
, netlink_cmd
, &dp_info
,
795 /* Get IPv6 address of the interfaces. */
796 ret
= netlink_request_intf_addr(netlink_cmd
, AF_INET6
, RTM_GETADDR
, 0);
799 ret
= netlink_parse_info(netlink_interface_addr
, netlink_cmd
, &dp_info
,
807 int kernel_interface_set_master(struct interface
*master
,
808 struct interface
*slave
)
810 struct zebra_ns
*zns
= zebra_ns_lookup(NS_DEFAULT
);
814 struct ifinfomsg ifa
;
815 char buf
[NL_PKT_BUF_SIZE
];
818 memset(&req
, 0, sizeof req
);
820 req
.n
.nlmsg_len
= NLMSG_LENGTH(sizeof(struct ifinfomsg
));
821 req
.n
.nlmsg_flags
= NLM_F_REQUEST
;
822 req
.n
.nlmsg_type
= RTM_SETLINK
;
823 req
.n
.nlmsg_pid
= zns
->netlink_cmd
.snl
.nl_pid
;
825 req
.ifa
.ifi_index
= slave
->ifindex
;
827 addattr_l(&req
.n
, sizeof req
, IFLA_MASTER
, &master
->ifindex
, 4);
828 addattr_l(&req
.n
, sizeof req
, IFLA_LINK
, &slave
->ifindex
, 4);
830 return netlink_talk(netlink_talk_filter
, &req
.n
, &zns
->netlink_cmd
, zns
,
834 /* Interface address modification. */
835 static int netlink_address(int cmd
, int family
, struct interface
*ifp
,
836 struct connected
*ifc
)
843 struct ifaddrmsg ifa
;
844 char buf
[NL_PKT_BUF_SIZE
];
847 struct zebra_ns
*zns
;
849 if (vrf_is_backend_netns())
850 zns
= zebra_ns_lookup((ns_id_t
)ifp
->vrf_id
);
852 zns
= zebra_ns_lookup(NS_DEFAULT
);
854 memset(&req
, 0, sizeof req
- NL_PKT_BUF_SIZE
);
856 bytelen
= (family
== AF_INET
? 4 : 16);
858 req
.n
.nlmsg_len
= NLMSG_LENGTH(sizeof(struct ifaddrmsg
));
859 req
.n
.nlmsg_flags
= NLM_F_REQUEST
;
860 req
.n
.nlmsg_type
= cmd
;
861 req
.n
.nlmsg_pid
= zns
->netlink_cmd
.snl
.nl_pid
;
863 req
.ifa
.ifa_family
= family
;
865 req
.ifa
.ifa_index
= ifp
->ifindex
;
867 addattr_l(&req
.n
, sizeof req
, IFA_LOCAL
, &p
->u
.prefix
, bytelen
);
869 if (family
== AF_INET
) {
870 if (CONNECTED_PEER(ifc
)) {
871 p
= ifc
->destination
;
872 addattr_l(&req
.n
, sizeof req
, IFA_ADDRESS
, &p
->u
.prefix
,
874 } else if (cmd
== RTM_NEWADDR
&& ifc
->destination
) {
875 p
= ifc
->destination
;
876 addattr_l(&req
.n
, sizeof req
, IFA_BROADCAST
,
877 &p
->u
.prefix
, bytelen
);
881 /* p is now either ifc->address or ifc->destination */
882 req
.ifa
.ifa_prefixlen
= p
->prefixlen
;
884 if (CHECK_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
))
885 SET_FLAG(req
.ifa
.ifa_flags
, IFA_F_SECONDARY
);
888 addattr_l(&req
.n
, sizeof req
, IFA_LABEL
, ifc
->label
,
889 strlen(ifc
->label
) + 1);
891 return netlink_talk(netlink_talk_filter
, &req
.n
, &zns
->netlink_cmd
, zns
,
895 int kernel_address_add_ipv4(struct interface
*ifp
, struct connected
*ifc
)
897 return netlink_address(RTM_NEWADDR
, AF_INET
, ifp
, ifc
);
900 int kernel_address_delete_ipv4(struct interface
*ifp
, struct connected
*ifc
)
902 return netlink_address(RTM_DELADDR
, AF_INET
, ifp
, ifc
);
905 int kernel_address_add_ipv6(struct interface
*ifp
, struct connected
*ifc
)
907 return netlink_address(RTM_NEWADDR
, AF_INET6
, ifp
, ifc
);
910 int kernel_address_delete_ipv6(struct interface
*ifp
, struct connected
*ifc
)
912 return netlink_address(RTM_DELADDR
, AF_INET6
, ifp
, ifc
);
915 int netlink_interface_addr(struct nlmsghdr
*h
, ns_id_t ns_id
, int startup
)
918 struct ifaddrmsg
*ifa
;
919 struct rtattr
*tb
[IFA_MAX
+ 1];
920 struct interface
*ifp
;
925 struct zebra_ns
*zns
;
927 zns
= zebra_ns_lookup(ns_id
);
930 if (ifa
->ifa_family
!= AF_INET
&& ifa
->ifa_family
!= AF_INET6
) {
932 EC_ZEBRA_UNKNOWN_FAMILY
,
933 "Invalid address family: %u received from kernel interface addr change: %s",
934 ifa
->ifa_family
, nl_msg_type_to_str(h
->nlmsg_type
));
938 if (h
->nlmsg_type
!= RTM_NEWADDR
&& h
->nlmsg_type
!= RTM_DELADDR
)
941 len
= h
->nlmsg_len
- NLMSG_LENGTH(sizeof(struct ifaddrmsg
));
943 zlog_err("%s: Message received from netlink is of a broken size: %d %zu",
946 (size_t)NLMSG_LENGTH(sizeof(struct ifaddrmsg
)));
950 memset(tb
, 0, sizeof tb
);
951 netlink_parse_rtattr(tb
, IFA_MAX
, IFA_RTA(ifa
), len
);
953 ifp
= if_lookup_by_index_per_ns(zns
, ifa
->ifa_index
);
957 "netlink_interface_addr can't find interface by index %d",
962 if (IS_ZEBRA_DEBUG_KERNEL
) /* remove this line to see initial ifcfg */
965 zlog_debug("netlink_interface_addr %s %s flags 0x%x:",
966 nl_msg_type_to_str(h
->nlmsg_type
), ifp
->name
,
969 zlog_debug(" IFA_LOCAL %s/%d",
970 inet_ntop(ifa
->ifa_family
,
971 RTA_DATA(tb
[IFA_LOCAL
]), buf
,
975 zlog_debug(" IFA_ADDRESS %s/%d",
976 inet_ntop(ifa
->ifa_family
,
977 RTA_DATA(tb
[IFA_ADDRESS
]), buf
,
980 if (tb
[IFA_BROADCAST
])
981 zlog_debug(" IFA_BROADCAST %s/%d",
982 inet_ntop(ifa
->ifa_family
,
983 RTA_DATA(tb
[IFA_BROADCAST
]), buf
,
986 if (tb
[IFA_LABEL
] && strcmp(ifp
->name
, RTA_DATA(tb
[IFA_LABEL
])))
987 zlog_debug(" IFA_LABEL %s",
988 (char *)RTA_DATA(tb
[IFA_LABEL
]));
990 if (tb
[IFA_CACHEINFO
]) {
991 struct ifa_cacheinfo
*ci
= RTA_DATA(tb
[IFA_CACHEINFO
]);
992 zlog_debug(" IFA_CACHEINFO pref %d, valid %d",
993 ci
->ifa_prefered
, ci
->ifa_valid
);
997 /* logic copied from iproute2/ip/ipaddress.c:print_addrinfo() */
998 if (tb
[IFA_LOCAL
] == NULL
)
999 tb
[IFA_LOCAL
] = tb
[IFA_ADDRESS
];
1000 if (tb
[IFA_ADDRESS
] == NULL
)
1001 tb
[IFA_ADDRESS
] = tb
[IFA_LOCAL
];
1003 /* local interface address */
1004 addr
= (tb
[IFA_LOCAL
] ? RTA_DATA(tb
[IFA_LOCAL
]) : NULL
);
1006 /* is there a peer address? */
1008 && memcmp(RTA_DATA(tb
[IFA_ADDRESS
]), RTA_DATA(tb
[IFA_LOCAL
]),
1009 RTA_PAYLOAD(tb
[IFA_ADDRESS
]))) {
1010 broad
= RTA_DATA(tb
[IFA_ADDRESS
]);
1011 SET_FLAG(flags
, ZEBRA_IFA_PEER
);
1013 /* seeking a broadcast address */
1014 broad
= (tb
[IFA_BROADCAST
] ? RTA_DATA(tb
[IFA_BROADCAST
])
1017 /* addr is primary key, SOL if we don't have one */
1019 zlog_debug("%s: NULL address", __func__
);
1024 if (ifa
->ifa_flags
& IFA_F_SECONDARY
)
1025 SET_FLAG(flags
, ZEBRA_IFA_SECONDARY
);
1029 label
= (char *)RTA_DATA(tb
[IFA_LABEL
]);
1031 if (label
&& strcmp(ifp
->name
, label
) == 0)
1034 /* Register interface address to the interface. */
1035 if (ifa
->ifa_family
== AF_INET
) {
1036 if (ifa
->ifa_prefixlen
> IPV4_MAX_BITLEN
) {
1038 "Invalid prefix length: %u received from kernel interface addr change: %s",
1040 nl_msg_type_to_str(h
->nlmsg_type
));
1043 if (h
->nlmsg_type
== RTM_NEWADDR
)
1044 connected_add_ipv4(ifp
, flags
, (struct in_addr
*)addr
,
1046 (struct in_addr
*)broad
, label
);
1048 connected_delete_ipv4(
1049 ifp
, flags
, (struct in_addr
*)addr
,
1050 ifa
->ifa_prefixlen
, (struct in_addr
*)broad
);
1052 if (ifa
->ifa_family
== AF_INET6
) {
1053 if (ifa
->ifa_prefixlen
> IPV6_MAX_BITLEN
) {
1055 "Invalid prefix length: %u received from kernel interface addr change: %s",
1057 nl_msg_type_to_str(h
->nlmsg_type
));
1060 if (h
->nlmsg_type
== RTM_NEWADDR
) {
1061 /* Only consider valid addresses; we'll not get a
1063 * the kernel till IPv6 DAD has completed, but at init
1065 * does query for and will receive all addresses.
1067 if (!(ifa
->ifa_flags
1068 & (IFA_F_DADFAILED
| IFA_F_TENTATIVE
)))
1069 connected_add_ipv6(ifp
, flags
,
1070 (struct in6_addr
*)addr
,
1071 (struct in6_addr
*)broad
,
1072 ifa
->ifa_prefixlen
, label
);
1074 connected_delete_ipv6(ifp
, (struct in6_addr
*)addr
,
1075 (struct in6_addr
*)broad
,
1076 ifa
->ifa_prefixlen
);
1082 int netlink_link_change(struct nlmsghdr
*h
, ns_id_t ns_id
, int startup
)
1085 struct ifinfomsg
*ifi
;
1086 struct rtattr
*tb
[IFLA_MAX
+ 1];
1087 struct rtattr
*linkinfo
[IFLA_MAX
+ 1];
1088 struct interface
*ifp
;
1092 char *slave_kind
= NULL
;
1093 struct zebra_ns
*zns
;
1094 vrf_id_t vrf_id
= VRF_DEFAULT
;
1095 zebra_iftype_t zif_type
= ZEBRA_IF_OTHER
;
1096 zebra_slave_iftype_t zif_slave_type
= ZEBRA_IF_SLAVE_NONE
;
1097 ifindex_t bridge_ifindex
= IFINDEX_INTERNAL
;
1098 ifindex_t bond_ifindex
= IFINDEX_INTERNAL
;
1099 ifindex_t link_ifindex
= IFINDEX_INTERNAL
;
1102 zns
= zebra_ns_lookup(ns_id
);
1103 ifi
= NLMSG_DATA(h
);
1105 /* assume if not default zns, then new VRF */
1106 if (!(h
->nlmsg_type
== RTM_NEWLINK
|| h
->nlmsg_type
== RTM_DELLINK
)) {
1107 /* If this is not link add/delete message so print warning. */
1108 zlog_debug("netlink_link_change: wrong kernel message %s",
1109 nl_msg_type_to_str(h
->nlmsg_type
));
1113 if (!(ifi
->ifi_family
== AF_UNSPEC
|| ifi
->ifi_family
== AF_BRIDGE
1114 || ifi
->ifi_family
== AF_INET6
)) {
1116 EC_ZEBRA_UNKNOWN_FAMILY
,
1117 "Invalid address family: %u received from kernel link change: %s",
1118 ifi
->ifi_family
, nl_msg_type_to_str(h
->nlmsg_type
));
1122 len
= h
->nlmsg_len
- NLMSG_LENGTH(sizeof(struct ifinfomsg
));
1124 zlog_err("%s: Message received from netlink is of a broken size %d %zu",
1125 __PRETTY_FUNCTION__
, h
->nlmsg_len
,
1126 (size_t)NLMSG_LENGTH(sizeof(struct ifinfomsg
)));
1130 /* We are interested in some AF_BRIDGE notifications. */
1131 if (ifi
->ifi_family
== AF_BRIDGE
)
1132 return netlink_bridge_interface(h
, len
, ns_id
, startup
);
1134 /* Looking up interface name. */
1135 memset(tb
, 0, sizeof tb
);
1136 memset(linkinfo
, 0, sizeof linkinfo
);
1137 netlink_parse_rtattr(tb
, IFLA_MAX
, IFLA_RTA(ifi
), len
);
1139 /* check for wireless messages to ignore */
1140 if ((tb
[IFLA_WIRELESS
] != NULL
) && (ifi
->ifi_change
== 0)) {
1141 if (IS_ZEBRA_DEBUG_KERNEL
)
1142 zlog_debug("%s: ignoring IFLA_WIRELESS message",
1147 if (tb
[IFLA_IFNAME
] == NULL
)
1149 name
= (char *)RTA_DATA(tb
[IFLA_IFNAME
]);
1151 if (tb
[IFLA_LINKINFO
]) {
1152 parse_rtattr_nested(linkinfo
, IFLA_INFO_MAX
, tb
[IFLA_LINKINFO
]);
1154 if (linkinfo
[IFLA_INFO_KIND
])
1155 kind
= RTA_DATA(linkinfo
[IFLA_INFO_KIND
]);
1157 if (linkinfo
[IFLA_INFO_SLAVE_KIND
])
1158 slave_kind
= RTA_DATA(linkinfo
[IFLA_INFO_SLAVE_KIND
]);
1160 netlink_determine_zebra_iftype(kind
, &zif_type
);
1163 /* If linking to another interface, note it. */
1165 link_ifindex
= *(ifindex_t
*)RTA_DATA(tb
[IFLA_LINK
]);
1167 if (tb
[IFLA_IFALIAS
]) {
1168 desc
= (char *)RTA_DATA(tb
[IFLA_IFALIAS
]);
1171 /* If VRF, create or update the VRF structure itself. */
1172 if (zif_type
== ZEBRA_IF_VRF
&& !vrf_is_backend_netns()) {
1173 netlink_vrf_change(h
, tb
[IFLA_LINKINFO
], name
);
1174 vrf_id
= (vrf_id_t
)ifi
->ifi_index
;
1177 /* See if interface is present. */
1178 ifp
= if_lookup_by_name_per_ns(zns
, name
);
1182 XFREE(MTYPE_TMP
, ifp
->desc
);
1184 ifp
->desc
= XSTRDUP(MTYPE_TMP
, desc
);
1187 if (h
->nlmsg_type
== RTM_NEWLINK
) {
1188 if (tb
[IFLA_MASTER
]) {
1189 if (slave_kind
&& (strcmp(slave_kind
, "vrf") == 0)
1190 && !vrf_is_backend_netns()) {
1191 zif_slave_type
= ZEBRA_IF_SLAVE_VRF
;
1192 vrf_id
= *(uint32_t *)RTA_DATA(tb
[IFLA_MASTER
]);
1193 } else if (slave_kind
1194 && (strcmp(slave_kind
, "bridge") == 0)) {
1195 zif_slave_type
= ZEBRA_IF_SLAVE_BRIDGE
;
1197 *(ifindex_t
*)RTA_DATA(tb
[IFLA_MASTER
]);
1198 } else if (slave_kind
1199 && (strcmp(slave_kind
, "bond") == 0)) {
1200 zif_slave_type
= ZEBRA_IF_SLAVE_BOND
;
1202 *(ifindex_t
*)RTA_DATA(tb
[IFLA_MASTER
]);
1204 zif_slave_type
= ZEBRA_IF_SLAVE_OTHER
;
1206 if (vrf_is_backend_netns())
1207 vrf_id
= (vrf_id_t
)ns_id
;
1209 || !CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
1210 /* Add interface notification from kernel */
1211 if (IS_ZEBRA_DEBUG_KERNEL
)
1213 "RTM_NEWLINK ADD for %s(%u) vrf_id %u type %d "
1214 "sl_type %d master %u flags 0x%x",
1215 name
, ifi
->ifi_index
, vrf_id
, zif_type
,
1216 zif_slave_type
, bridge_ifindex
,
1220 /* unknown interface */
1221 ifp
= if_get_by_name(name
, vrf_id
);
1223 /* pre-configured interface, learnt now */
1224 if (ifp
->vrf_id
!= vrf_id
)
1225 if_update_to_new_vrf(ifp
, vrf_id
);
1228 /* Update interface information. */
1229 set_ifindex(ifp
, ifi
->ifi_index
, zns
);
1230 ifp
->flags
= ifi
->ifi_flags
& 0x0000fffff;
1231 if (!tb
[IFLA_MTU
]) {
1233 "RTM_NEWLINK for interface %s(%u) without MTU set",
1234 name
, ifi
->ifi_index
);
1237 ifp
->mtu6
= ifp
->mtu
= *(int *)RTA_DATA(tb
[IFLA_MTU
]);
1239 ifp
->ptm_status
= ZEBRA_PTM_STATUS_UNKNOWN
;
1241 /* Set interface type */
1242 zebra_if_set_ziftype(ifp
, zif_type
, zif_slave_type
);
1243 if (IS_ZEBRA_IF_VRF(ifp
))
1244 SET_FLAG(ifp
->status
,
1245 ZEBRA_INTERFACE_VRF_LOOPBACK
);
1248 zebra_if_update_link(ifp
, link_ifindex
, ns_id
);
1250 netlink_interface_update_hw_addr(tb
, ifp
);
1252 /* Inform clients, install any configured addresses. */
1255 /* Extract and save L2 interface information, take
1256 * additional actions. */
1257 netlink_interface_update_l2info(
1258 ifp
, linkinfo
[IFLA_INFO_DATA
], 1);
1259 if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp
))
1260 zebra_l2if_update_bridge_slave(ifp
,
1262 else if (IS_ZEBRA_IF_BOND_SLAVE(ifp
))
1263 zebra_l2if_update_bond_slave(ifp
, bond_ifindex
);
1264 } else if (ifp
->vrf_id
!= vrf_id
) {
1265 /* VRF change for an interface. */
1266 if (IS_ZEBRA_DEBUG_KERNEL
)
1268 "RTM_NEWLINK vrf-change for %s(%u) "
1269 "vrf_id %u -> %u flags 0x%x",
1270 name
, ifp
->ifindex
, ifp
->vrf_id
, vrf_id
,
1273 if_handle_vrf_change(ifp
, vrf_id
);
1275 bool was_bridge_slave
, was_bond_slave
;
1277 /* Interface update. */
1278 if (IS_ZEBRA_DEBUG_KERNEL
)
1280 "RTM_NEWLINK update for %s(%u) "
1281 "sl_type %d master %u flags 0x%x",
1282 name
, ifp
->ifindex
, zif_slave_type
,
1283 bridge_ifindex
, ifi
->ifi_flags
);
1285 set_ifindex(ifp
, ifi
->ifi_index
, zns
);
1286 if (!tb
[IFLA_MTU
]) {
1288 "RTM_NEWLINK for interface %s(%u) without MTU set",
1289 name
, ifi
->ifi_index
);
1292 ifp
->mtu6
= ifp
->mtu
= *(int *)RTA_DATA(tb
[IFLA_MTU
]);
1295 /* Update interface type - NOTE: Only slave_type can
1297 was_bridge_slave
= IS_ZEBRA_IF_BRIDGE_SLAVE(ifp
);
1298 was_bond_slave
= IS_ZEBRA_IF_BOND_SLAVE(ifp
);
1299 zebra_if_set_ziftype(ifp
, zif_type
, zif_slave_type
);
1301 netlink_interface_update_hw_addr(tb
, ifp
);
1303 if (if_is_no_ptm_operative(ifp
)) {
1304 ifp
->flags
= ifi
->ifi_flags
& 0x0000fffff;
1305 if (!if_is_no_ptm_operative(ifp
)) {
1306 if (IS_ZEBRA_DEBUG_KERNEL
)
1308 "Intf %s(%u) has gone DOWN",
1309 name
, ifp
->ifindex
);
1311 } else if (if_is_operative(ifp
)) {
1312 /* Must notify client daemons of new
1313 * interface status. */
1314 if (IS_ZEBRA_DEBUG_KERNEL
)
1316 "Intf %s(%u) PTM up, notifying clients",
1317 name
, ifp
->ifindex
);
1318 zebra_interface_up_update(ifp
);
1321 ifp
->flags
= ifi
->ifi_flags
& 0x0000fffff;
1322 if (if_is_operative(ifp
)) {
1323 if (IS_ZEBRA_DEBUG_KERNEL
)
1325 "Intf %s(%u) has come UP",
1326 name
, ifp
->ifindex
);
1331 /* Extract and save L2 interface information, take
1332 * additional actions. */
1333 netlink_interface_update_l2info(
1334 ifp
, linkinfo
[IFLA_INFO_DATA
], 0);
1335 if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp
) || was_bridge_slave
)
1336 zebra_l2if_update_bridge_slave(ifp
,
1338 else if (IS_ZEBRA_IF_BOND_SLAVE(ifp
) || was_bond_slave
)
1339 zebra_l2if_update_bond_slave(ifp
, bond_ifindex
);
1342 /* Delete interface notification from kernel */
1344 if (IS_ZEBRA_DEBUG_KERNEL
)
1346 "RTM_DELLINK for unknown interface %s(%u)",
1347 name
, ifi
->ifi_index
);
1351 if (IS_ZEBRA_DEBUG_KERNEL
)
1352 zlog_debug("RTM_DELLINK for %s(%u)", name
,
1355 UNSET_FLAG(ifp
->status
, ZEBRA_INTERFACE_VRF_LOOPBACK
);
1357 /* Special handling for bridge or VxLAN interfaces. */
1358 if (IS_ZEBRA_IF_BRIDGE(ifp
))
1359 zebra_l2_bridge_del(ifp
);
1360 else if (IS_ZEBRA_IF_VXLAN(ifp
))
1361 zebra_l2_vxlanif_del(ifp
);
1363 if (!IS_ZEBRA_IF_VRF(ifp
))
1364 if_delete_update(ifp
);
1370 /* Interface information read by netlink. */
1371 void interface_list(struct zebra_ns
*zns
)
1373 interface_lookup_netlink(zns
);
1376 #endif /* GNU_LINUX */