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
35 #include <netinet/if_ether.h>
36 #include <linux/if_bridge.h>
37 #include <linux/if_link.h>
38 #include <linux/if_tunnel.h>
39 #include <net/if_arp.h>
40 #include <linux/sockios.h>
41 #include <linux/ethtool.h>
47 #include "connected.h"
57 #include "lib_errors.h"
60 #include "zebra/zserv.h"
61 #include "zebra/zebra_ns.h"
62 #include "zebra/zebra_vrf.h"
64 #include "zebra/redistribute.h"
65 #include "zebra/interface.h"
66 #include "zebra/debug.h"
67 #include "zebra/rtadv.h"
68 #include "zebra/zebra_ptm.h"
69 #include "zebra/zebra_mpls.h"
70 #include "zebra/kernel_netlink.h"
71 #include "zebra/rt_netlink.h"
72 #include "zebra/if_netlink.h"
73 #include "zebra/zebra_errors.h"
74 #include "zebra/zebra_vxlan.h"
75 #include "zebra/zebra_evpn_mh.h"
76 #include "zebra/zebra_l2.h"
78 extern struct zebra_privs_t zserv_privs
;
80 /* Note: on netlink systems, there should be a 1-to-1 mapping between interface
81 names and ifindex values. */
82 static void set_ifindex(struct interface
*ifp
, ifindex_t ifi_index
,
85 struct interface
*oifp
;
87 if (((oifp
= if_lookup_by_index_per_ns(zns
, ifi_index
)) != NULL
)
89 if (ifi_index
== IFINDEX_INTERNAL
)
92 "Netlink is setting interface %s ifindex to reserved internal value %u",
93 ifp
->name
, ifi_index
);
95 if (IS_ZEBRA_DEBUG_KERNEL
)
97 "interface index %d was renamed from %s to %s",
98 ifi_index
, oifp
->name
, ifp
->name
);
102 "interface rename detected on up interface: index %d was renamed from %s to %s, results are uncertain!",
103 ifi_index
, oifp
->name
, ifp
->name
);
104 if_delete_update(oifp
);
107 if_set_index(ifp
, ifi_index
);
110 /* Utility function to parse hardware link-layer address and update ifp */
111 static void netlink_interface_update_hw_addr(struct rtattr
**tb
,
112 struct interface
*ifp
)
116 if (tb
[IFLA_ADDRESS
]) {
119 hw_addr_len
= RTA_PAYLOAD(tb
[IFLA_ADDRESS
]);
121 if (hw_addr_len
> INTERFACE_HWADDR_MAX
)
122 zlog_debug("Hardware address is too large: %d",
125 ifp
->hw_addr_len
= hw_addr_len
;
126 memcpy(ifp
->hw_addr
, RTA_DATA(tb
[IFLA_ADDRESS
]),
129 for (i
= 0; i
< hw_addr_len
; i
++)
130 if (ifp
->hw_addr
[i
] != 0)
133 if (i
== hw_addr_len
)
134 ifp
->hw_addr_len
= 0;
136 ifp
->hw_addr_len
= hw_addr_len
;
141 static enum zebra_link_type
netlink_to_zebra_link_type(unsigned int hwt
)
145 return ZEBRA_LLT_ETHER
;
147 return ZEBRA_LLT_EETHER
;
149 return ZEBRA_LLT_AX25
;
151 return ZEBRA_LLT_PRONET
;
153 return ZEBRA_LLT_IEEE802
;
155 return ZEBRA_LLT_ARCNET
;
156 case ARPHRD_APPLETLK
:
157 return ZEBRA_LLT_APPLETLK
;
159 return ZEBRA_LLT_DLCI
;
161 return ZEBRA_LLT_ATM
;
162 case ARPHRD_METRICOM
:
163 return ZEBRA_LLT_METRICOM
;
164 case ARPHRD_IEEE1394
:
165 return ZEBRA_LLT_IEEE1394
;
167 return ZEBRA_LLT_EUI64
;
168 case ARPHRD_INFINIBAND
:
169 return ZEBRA_LLT_INFINIBAND
;
171 return ZEBRA_LLT_SLIP
;
173 return ZEBRA_LLT_CSLIP
;
175 return ZEBRA_LLT_SLIP6
;
177 return ZEBRA_LLT_CSLIP6
;
179 return ZEBRA_LLT_RSRVD
;
181 return ZEBRA_LLT_ADAPT
;
183 return ZEBRA_LLT_ROSE
;
185 return ZEBRA_LLT_X25
;
187 return ZEBRA_LLT_PPP
;
189 return ZEBRA_LLT_CHDLC
;
191 return ZEBRA_LLT_LAPB
;
193 return ZEBRA_LLT_RAWHDLC
;
195 return ZEBRA_LLT_IPIP
;
197 return ZEBRA_LLT_IPIP6
;
199 return ZEBRA_LLT_FRAD
;
201 return ZEBRA_LLT_SKIP
;
202 case ARPHRD_LOOPBACK
:
203 return ZEBRA_LLT_LOOPBACK
;
204 case ARPHRD_LOCALTLK
:
205 return ZEBRA_LLT_LOCALTLK
;
207 return ZEBRA_LLT_FDDI
;
209 return ZEBRA_LLT_SIT
;
211 return ZEBRA_LLT_IPDDP
;
213 return ZEBRA_LLT_IPGRE
;
215 return ZEBRA_LLT_PIMREG
;
217 return ZEBRA_LLT_HIPPI
;
219 return ZEBRA_LLT_ECONET
;
221 return ZEBRA_LLT_IRDA
;
223 return ZEBRA_LLT_FCPP
;
225 return ZEBRA_LLT_FCAL
;
227 return ZEBRA_LLT_FCPL
;
228 case ARPHRD_FCFABRIC
:
229 return ZEBRA_LLT_FCFABRIC
;
230 case ARPHRD_IEEE802_TR
:
231 return ZEBRA_LLT_IEEE802_TR
;
232 case ARPHRD_IEEE80211
:
233 return ZEBRA_LLT_IEEE80211
;
234 #ifdef ARPHRD_IEEE802154
235 case ARPHRD_IEEE802154
:
236 return ZEBRA_LLT_IEEE802154
;
240 return ZEBRA_LLT_IP6GRE
;
242 #ifdef ARPHRD_IEEE802154_PHY
243 case ARPHRD_IEEE802154_PHY
:
244 return ZEBRA_LLT_IEEE802154_PHY
;
248 return ZEBRA_LLT_UNKNOWN
;
252 static inline void zebra_if_set_ziftype(struct interface
*ifp
,
253 enum zebra_iftype zif_type
,
254 enum zebra_slave_iftype zif_slave_type
)
256 struct zebra_if
*zif
;
258 zif
= (struct zebra_if
*)ifp
->info
;
259 zif
->zif_slave_type
= zif_slave_type
;
261 if (zif
->zif_type
!= zif_type
) {
262 zif
->zif_type
= zif_type
;
263 /* If the if_type has been set to bond initialize ES info
264 * against it. XXX - note that we don't handle the case where
265 * a zif changes from bond to non-bond; it is really
266 * an unexpected/error condition.
268 zebra_evpn_if_init(zif
);
272 static void netlink_determine_zebra_iftype(const char *kind
,
273 enum zebra_iftype
*zif_type
)
275 *zif_type
= ZEBRA_IF_OTHER
;
280 if (strcmp(kind
, "vrf") == 0)
281 *zif_type
= ZEBRA_IF_VRF
;
282 else if (strcmp(kind
, "bridge") == 0)
283 *zif_type
= ZEBRA_IF_BRIDGE
;
284 else if (strcmp(kind
, "vlan") == 0)
285 *zif_type
= ZEBRA_IF_VLAN
;
286 else if (strcmp(kind
, "vxlan") == 0)
287 *zif_type
= ZEBRA_IF_VXLAN
;
288 else if (strcmp(kind
, "macvlan") == 0)
289 *zif_type
= ZEBRA_IF_MACVLAN
;
290 else if (strcmp(kind
, "veth") == 0)
291 *zif_type
= ZEBRA_IF_VETH
;
292 else if (strcmp(kind
, "bond") == 0)
293 *zif_type
= ZEBRA_IF_BOND
;
294 else if (strcmp(kind
, "bond_slave") == 0)
295 *zif_type
= ZEBRA_IF_BOND_SLAVE
;
296 else if (strcmp(kind
, "gre") == 0)
297 *zif_type
= ZEBRA_IF_GRE
;
300 static void netlink_vrf_change(struct nlmsghdr
*h
, struct rtattr
*tb
,
301 uint32_t ns_id
, const char *name
)
303 struct ifinfomsg
*ifi
;
304 struct rtattr
*linkinfo
[IFLA_INFO_MAX
+ 1];
305 struct rtattr
*attr
[IFLA_VRF_MAX
+ 1];
306 struct vrf
*vrf
= NULL
;
307 struct zebra_vrf
*zvrf
;
308 uint32_t nl_table_id
;
312 netlink_parse_rtattr_nested(linkinfo
, IFLA_INFO_MAX
, tb
);
314 if (!linkinfo
[IFLA_INFO_DATA
]) {
315 if (IS_ZEBRA_DEBUG_KERNEL
)
317 "%s: IFLA_INFO_DATA missing from VRF message: %s",
322 netlink_parse_rtattr_nested(attr
, IFLA_VRF_MAX
,
323 linkinfo
[IFLA_INFO_DATA
]);
324 if (!attr
[IFLA_VRF_TABLE
]) {
325 if (IS_ZEBRA_DEBUG_KERNEL
)
327 "%s: IFLA_VRF_TABLE missing from VRF message: %s",
332 nl_table_id
= *(uint32_t *)RTA_DATA(attr
[IFLA_VRF_TABLE
]);
334 if (h
->nlmsg_type
== RTM_NEWLINK
) {
335 if (IS_ZEBRA_DEBUG_KERNEL
)
336 zlog_debug("RTM_NEWLINK for VRF %s(%u) table %u", name
,
337 ifi
->ifi_index
, nl_table_id
);
339 if (!vrf_lookup_by_id((vrf_id_t
)ifi
->ifi_index
)) {
342 exist_id
= vrf_lookup_by_table(nl_table_id
, ns_id
);
343 if (exist_id
!= VRF_DEFAULT
) {
344 vrf
= vrf_lookup_by_id(exist_id
);
347 EC_ZEBRA_VRF_MISCONFIGURED
,
348 "VRF %s id %u table id overlaps existing vrf %s, misconfiguration exiting",
349 name
, ifi
->ifi_index
, vrf
->name
);
354 vrf
= vrf_update((vrf_id_t
)ifi
->ifi_index
, name
);
356 flog_err(EC_LIB_INTERFACE
, "VRF %s id %u not created",
357 name
, ifi
->ifi_index
);
362 * This is the only place that we get the actual kernel table_id
363 * being used. We need it to set the table_id of the routes
364 * we are passing to the kernel.... And to throw some totally
365 * awesome parties. that too.
367 * At this point we *must* have a zvrf because the vrf_create
368 * callback creates one. We *must* set the table id
369 * before the vrf_enable because of( at the very least )
370 * static routes being delayed for installation until
371 * during the vrf_enable callbacks.
373 zvrf
= (struct zebra_vrf
*)vrf
->info
;
374 zvrf
->table_id
= nl_table_id
;
376 /* Enable the created VRF. */
377 if (!vrf_enable(vrf
)) {
378 flog_err(EC_LIB_INTERFACE
,
379 "Failed to enable VRF %s id %u", name
,
384 } else // h->nlmsg_type == RTM_DELLINK
386 if (IS_ZEBRA_DEBUG_KERNEL
)
387 zlog_debug("RTM_DELLINK for VRF %s(%u)", name
,
390 vrf
= vrf_lookup_by_id((vrf_id_t
)ifi
->ifi_index
);
393 flog_warn(EC_ZEBRA_VRF_NOT_FOUND
, "%s: vrf not found",
402 static uint32_t get_iflink_speed(struct interface
*interface
, int *error
)
405 struct ethtool_cmd ecmd
;
408 const char *ifname
= interface
->name
;
412 /* initialize struct */
413 memset(&ifdata
, 0, sizeof(ifdata
));
415 /* set interface name */
416 strlcpy(ifdata
.ifr_name
, ifname
, sizeof(ifdata
.ifr_name
));
418 /* initialize ethtool interface */
419 memset(&ecmd
, 0, sizeof(ecmd
));
420 ecmd
.cmd
= ETHTOOL_GSET
; /* ETHTOOL_GLINK */
421 ifdata
.ifr_data
= (caddr_t
)&ecmd
;
423 /* use ioctl to get IP address of an interface */
424 frr_with_privs(&zserv_privs
) {
425 sd
= vrf_socket(PF_INET
, SOCK_DGRAM
, IPPROTO_IP
,
429 if (IS_ZEBRA_DEBUG_KERNEL
)
430 zlog_debug("Failure to read interface %s speed: %d %s",
431 ifname
, errno
, safe_strerror(errno
));
432 /* no vrf socket creation may probably mean vrf issue */
437 /* Get the current link state for the interface */
438 rc
= vrf_ioctl(interface
->vrf_id
, sd
, SIOCETHTOOL
,
442 if (errno
!= EOPNOTSUPP
&& IS_ZEBRA_DEBUG_KERNEL
)
444 "IOCTL failure to read interface %s speed: %d %s",
445 ifname
, errno
, safe_strerror(errno
));
446 /* no device means interface unreachable */
447 if (errno
== ENODEV
&& error
)
455 return ((uint32_t)ecmd
.speed_hi
<< 16) | ecmd
.speed
;
458 uint32_t kernel_get_speed(struct interface
*ifp
, int *error
)
460 return get_iflink_speed(ifp
, error
);
464 netlink_gre_set_msg_encoder(struct zebra_dplane_ctx
*ctx
, void *buf
,
469 struct ifinfomsg ifi
;
474 struct rtattr
*rta_info
, *rta_data
;
475 const struct zebra_l2info_gre
*gre_info
;
477 if (buflen
< sizeof(*req
))
479 memset(req
, 0, sizeof(*req
));
481 req
->n
.nlmsg_type
= RTM_NEWLINK
;
482 req
->n
.nlmsg_len
= NLMSG_LENGTH(sizeof(struct ifinfomsg
));
483 req
->n
.nlmsg_flags
= NLM_F_REQUEST
;
485 req
->ifi
.ifi_index
= dplane_ctx_get_ifindex(ctx
);
487 gre_info
= dplane_ctx_gre_get_info(ctx
);
491 req
->ifi
.ifi_change
= 0xFFFFFFFF;
492 link_idx
= dplane_ctx_gre_get_link_ifindex(ctx
);
493 mtu
= dplane_ctx_gre_get_mtu(ctx
);
495 if (mtu
&& !nl_attr_put32(&req
->n
, buflen
, IFLA_MTU
, mtu
))
498 rta_info
= nl_attr_nest(&req
->n
, buflen
, IFLA_LINKINFO
);
502 if (!nl_attr_put(&req
->n
, buflen
, IFLA_INFO_KIND
, "gre", 3))
505 rta_data
= nl_attr_nest(&req
->n
, buflen
, IFLA_INFO_DATA
);
509 if (!nl_attr_put32(&req
->n
, buflen
, IFLA_GRE_LINK
, link_idx
))
512 if (gre_info
->vtep_ip
.s_addr
&&
513 !nl_attr_put32(&req
->n
, buflen
, IFLA_GRE_LOCAL
,
514 gre_info
->vtep_ip
.s_addr
))
517 if (gre_info
->vtep_ip_remote
.s_addr
&&
518 !nl_attr_put32(&req
->n
, buflen
, IFLA_GRE_REMOTE
,
519 gre_info
->vtep_ip_remote
.s_addr
))
522 if (gre_info
->ikey
&&
523 !nl_attr_put32(&req
->n
, buflen
, IFLA_GRE_IKEY
,
526 if (gre_info
->okey
&&
527 !nl_attr_put32(&req
->n
, buflen
, IFLA_GRE_IKEY
,
531 nl_attr_nest_end(&req
->n
, rta_data
);
532 nl_attr_nest_end(&req
->n
, rta_info
);
534 return NLMSG_ALIGN(req
->n
.nlmsg_len
);
537 static int netlink_extract_bridge_info(struct rtattr
*link_data
,
538 struct zebra_l2info_bridge
*bridge_info
)
540 struct rtattr
*attr
[IFLA_BR_MAX
+ 1];
542 memset(bridge_info
, 0, sizeof(*bridge_info
));
543 netlink_parse_rtattr_nested(attr
, IFLA_BR_MAX
, link_data
);
544 if (attr
[IFLA_BR_VLAN_FILTERING
])
545 bridge_info
->vlan_aware
=
546 *(uint8_t *)RTA_DATA(attr
[IFLA_BR_VLAN_FILTERING
]);
550 static int netlink_extract_vlan_info(struct rtattr
*link_data
,
551 struct zebra_l2info_vlan
*vlan_info
)
553 struct rtattr
*attr
[IFLA_VLAN_MAX
+ 1];
556 memset(vlan_info
, 0, sizeof(*vlan_info
));
557 netlink_parse_rtattr_nested(attr
, IFLA_VLAN_MAX
, link_data
);
558 if (!attr
[IFLA_VLAN_ID
]) {
559 if (IS_ZEBRA_DEBUG_KERNEL
)
560 zlog_debug("IFLA_VLAN_ID missing from VLAN IF message");
564 vid_in_msg
= *(vlanid_t
*)RTA_DATA(attr
[IFLA_VLAN_ID
]);
565 vlan_info
->vid
= vid_in_msg
;
569 static int netlink_extract_gre_info(struct rtattr
*link_data
,
570 struct zebra_l2info_gre
*gre_info
)
572 struct rtattr
*attr
[IFLA_GRE_MAX
+ 1];
574 memset(gre_info
, 0, sizeof(*gre_info
));
575 memset(attr
, 0, sizeof(attr
));
576 netlink_parse_rtattr_nested(attr
, IFLA_GRE_MAX
, link_data
);
578 if (!attr
[IFLA_GRE_LOCAL
]) {
579 if (IS_ZEBRA_DEBUG_KERNEL
)
581 "IFLA_GRE_LOCAL missing from GRE IF message");
584 *(struct in_addr
*)RTA_DATA(attr
[IFLA_GRE_LOCAL
]);
585 if (!attr
[IFLA_GRE_REMOTE
]) {
586 if (IS_ZEBRA_DEBUG_KERNEL
)
588 "IFLA_GRE_REMOTE missing from GRE IF message");
590 gre_info
->vtep_ip_remote
=
591 *(struct in_addr
*)RTA_DATA(attr
[IFLA_GRE_REMOTE
]);
593 if (!attr
[IFLA_GRE_LINK
]) {
594 if (IS_ZEBRA_DEBUG_KERNEL
)
595 zlog_debug("IFLA_GRE_LINK missing from GRE IF message");
597 gre_info
->ifindex_link
=
598 *(ifindex_t
*)RTA_DATA(attr
[IFLA_GRE_LINK
]);
599 if (IS_ZEBRA_DEBUG_KERNEL
)
600 zlog_debug("IFLA_GRE_LINK obtained is %u",
601 gre_info
->ifindex_link
);
603 if (attr
[IFLA_GRE_IKEY
])
604 gre_info
->ikey
= *(uint32_t *)RTA_DATA(attr
[IFLA_GRE_IKEY
]);
605 if (attr
[IFLA_GRE_OKEY
])
606 gre_info
->okey
= *(uint32_t *)RTA_DATA(attr
[IFLA_GRE_OKEY
]);
610 static int netlink_extract_vxlan_info(struct rtattr
*link_data
,
611 struct zebra_l2info_vxlan
*vxl_info
)
613 struct rtattr
*attr
[IFLA_VXLAN_MAX
+ 1];
615 struct in_addr vtep_ip_in_msg
;
616 ifindex_t ifindex_link
;
618 memset(vxl_info
, 0, sizeof(*vxl_info
));
619 netlink_parse_rtattr_nested(attr
, IFLA_VXLAN_MAX
, link_data
);
620 if (!attr
[IFLA_VXLAN_ID
]) {
621 if (IS_ZEBRA_DEBUG_KERNEL
)
623 "IFLA_VXLAN_ID missing from VXLAN IF message");
627 vni_in_msg
= *(vni_t
*)RTA_DATA(attr
[IFLA_VXLAN_ID
]);
628 vxl_info
->vni
= vni_in_msg
;
629 if (!attr
[IFLA_VXLAN_LOCAL
]) {
630 if (IS_ZEBRA_DEBUG_KERNEL
)
632 "IFLA_VXLAN_LOCAL missing from VXLAN IF message");
635 *(struct in_addr
*)RTA_DATA(attr
[IFLA_VXLAN_LOCAL
]);
636 vxl_info
->vtep_ip
= vtep_ip_in_msg
;
639 if (attr
[IFLA_VXLAN_GROUP
]) {
640 vxl_info
->mcast_grp
=
641 *(struct in_addr
*)RTA_DATA(attr
[IFLA_VXLAN_GROUP
]);
644 if (!attr
[IFLA_VXLAN_LINK
]) {
645 if (IS_ZEBRA_DEBUG_KERNEL
)
646 zlog_debug("IFLA_VXLAN_LINK missing from VXLAN IF message");
649 *(ifindex_t
*)RTA_DATA(attr
[IFLA_VXLAN_LINK
]);
650 vxl_info
->ifindex_link
= ifindex_link
;
656 * Extract and save L2 params (of interest) for an interface. When a
657 * bridge interface is added or updated, take further actions to map
658 * its members. Likewise, for VxLAN interface.
660 static void netlink_interface_update_l2info(struct interface
*ifp
,
661 struct rtattr
*link_data
, int add
,
667 if (IS_ZEBRA_IF_BRIDGE(ifp
)) {
668 struct zebra_l2info_bridge bridge_info
;
670 netlink_extract_bridge_info(link_data
, &bridge_info
);
671 zebra_l2_bridge_add_update(ifp
, &bridge_info
, add
);
672 } else if (IS_ZEBRA_IF_VLAN(ifp
)) {
673 struct zebra_l2info_vlan vlan_info
;
675 netlink_extract_vlan_info(link_data
, &vlan_info
);
676 zebra_l2_vlanif_update(ifp
, &vlan_info
);
677 zebra_evpn_acc_bd_svi_set(ifp
->info
, NULL
,
678 !!if_is_operative(ifp
));
679 } else if (IS_ZEBRA_IF_VXLAN(ifp
)) {
680 struct zebra_l2info_vxlan vxlan_info
;
682 netlink_extract_vxlan_info(link_data
, &vxlan_info
);
683 vxlan_info
.link_nsid
= link_nsid
;
684 zebra_l2_vxlanif_add_update(ifp
, &vxlan_info
, add
);
685 if (link_nsid
!= NS_UNKNOWN
&&
686 vxlan_info
.ifindex_link
)
687 zebra_if_update_link(ifp
, vxlan_info
.ifindex_link
,
689 } else if (IS_ZEBRA_IF_GRE(ifp
)) {
690 struct zebra_l2info_gre gre_info
;
692 netlink_extract_gre_info(link_data
, &gre_info
);
693 gre_info
.link_nsid
= link_nsid
;
694 zebra_l2_greif_add_update(ifp
, &gre_info
, add
);
695 if (link_nsid
!= NS_UNKNOWN
&&
696 gre_info
.ifindex_link
)
697 zebra_if_update_link(ifp
, gre_info
.ifindex_link
,
702 static int netlink_bridge_vxlan_update(struct interface
*ifp
,
703 struct rtattr
*af_spec
)
705 struct rtattr
*aftb
[IFLA_BRIDGE_MAX
+ 1];
706 struct bridge_vlan_info
*vinfo
;
707 vlanid_t access_vlan
;
712 /* There is a 1-to-1 mapping of VLAN to VxLAN - hence
713 * only 1 access VLAN is accepted.
715 netlink_parse_rtattr_nested(aftb
, IFLA_BRIDGE_MAX
, af_spec
);
716 if (!aftb
[IFLA_BRIDGE_VLAN_INFO
])
719 vinfo
= RTA_DATA(aftb
[IFLA_BRIDGE_VLAN_INFO
]);
720 if (!(vinfo
->flags
& BRIDGE_VLAN_INFO_PVID
))
723 access_vlan
= (vlanid_t
)vinfo
->vid
;
724 if (IS_ZEBRA_DEBUG_KERNEL
)
725 zlog_debug("Access VLAN %u for VxLAN IF %s(%u)", access_vlan
,
726 ifp
->name
, ifp
->ifindex
);
727 zebra_l2_vxlanif_update_access_vlan(ifp
, access_vlan
);
731 static void netlink_bridge_vlan_update(struct interface
*ifp
,
732 struct rtattr
*af_spec
)
736 uint16_t vid_range_start
= 0;
737 struct zebra_if
*zif
;
738 bitfield_t old_vlan_bitmap
;
739 struct bridge_vlan_info
*vinfo
;
741 zif
= (struct zebra_if
*)ifp
->info
;
743 /* cache the old bitmap addrs */
744 old_vlan_bitmap
= zif
->vlan_bitmap
;
745 /* create a new bitmap space for re-eval */
746 bf_init(zif
->vlan_bitmap
, IF_VLAN_BITMAP_MAX
);
749 for (i
= RTA_DATA(af_spec
), rem
= RTA_PAYLOAD(af_spec
);
750 RTA_OK(i
, rem
); i
= RTA_NEXT(i
, rem
)) {
752 if (i
->rta_type
!= IFLA_BRIDGE_VLAN_INFO
)
757 if (vinfo
->flags
& BRIDGE_VLAN_INFO_RANGE_BEGIN
) {
758 vid_range_start
= vinfo
->vid
;
762 if (!(vinfo
->flags
& BRIDGE_VLAN_INFO_RANGE_END
))
763 vid_range_start
= vinfo
->vid
;
765 zebra_vlan_bitmap_compute(ifp
, vid_range_start
,
770 zebra_vlan_mbr_re_eval(ifp
, old_vlan_bitmap
);
772 bf_free(old_vlan_bitmap
);
775 static int netlink_bridge_interface(struct nlmsghdr
*h
, int len
, ns_id_t ns_id
,
779 struct ifinfomsg
*ifi
;
780 struct rtattr
*tb
[IFLA_MAX
+ 1];
781 struct interface
*ifp
;
782 struct zebra_if
*zif
;
783 struct rtattr
*af_spec
;
785 /* Fetch name and ifindex */
787 netlink_parse_rtattr(tb
, IFLA_MAX
, IFLA_RTA(ifi
), len
);
789 if (tb
[IFLA_IFNAME
] == NULL
)
791 name
= (char *)RTA_DATA(tb
[IFLA_IFNAME
]);
793 /* The interface should already be known, if not discard. */
794 ifp
= if_lookup_by_index_per_ns(zebra_ns_lookup(ns_id
), ifi
->ifi_index
);
796 zlog_debug("Cannot find bridge IF %s(%u)", name
,
801 /* We are only interested in the access VLAN i.e., AF_SPEC */
802 af_spec
= tb
[IFLA_AF_SPEC
];
804 if (IS_ZEBRA_IF_VXLAN(ifp
))
805 return netlink_bridge_vxlan_update(ifp
, af_spec
);
807 /* build vlan bitmap associated with this interface if that
808 * device type is interested in the vlans
810 zif
= (struct zebra_if
*)ifp
->info
;
811 if (bf_is_inited(zif
->vlan_bitmap
))
812 netlink_bridge_vlan_update(ifp
, af_spec
);
817 /* If the interface is an es bond member then it must follow EVPN's
820 static void netlink_proc_dplane_if_protodown(struct zebra_if
*zif
,
825 zif_protodown
= !!(zif
->flags
& ZIF_FLAG_PROTODOWN
);
826 if (protodown
== zif_protodown
)
829 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
|| IS_ZEBRA_DEBUG_KERNEL
)
830 zlog_debug("interface %s dplane change, protdown %s",
831 zif
->ifp
->name
, protodown
? "on" : "off");
833 if (zebra_evpn_is_es_bond_member(zif
->ifp
)) {
834 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
|| IS_ZEBRA_DEBUG_KERNEL
)
836 "bond mbr %s re-instate protdown %s in the dplane",
837 zif
->ifp
->name
, zif_protodown
? "on" : "off");
838 netlink_protodown(zif
->ifp
, zif_protodown
);
841 zif
->flags
|= ZIF_FLAG_PROTODOWN
;
843 zif
->flags
&= ~ZIF_FLAG_PROTODOWN
;
847 static uint8_t netlink_parse_lacp_bypass(struct rtattr
**linkinfo
)
850 struct rtattr
*mbrinfo
[IFLA_BOND_SLAVE_MAX
+ 1];
852 netlink_parse_rtattr_nested(mbrinfo
, IFLA_BOND_SLAVE_MAX
,
853 linkinfo
[IFLA_INFO_SLAVE_DATA
]);
854 if (mbrinfo
[IFLA_BOND_SLAVE_AD_RX_BYPASS
])
855 bypass
= *(uint8_t *)RTA_DATA(
856 mbrinfo
[IFLA_BOND_SLAVE_AD_RX_BYPASS
]);
862 * Called from interface_lookup_netlink(). This function is only used
865 static int netlink_interface(struct nlmsghdr
*h
, ns_id_t ns_id
, int startup
)
868 struct ifinfomsg
*ifi
;
869 struct rtattr
*tb
[IFLA_MAX
+ 1];
870 struct rtattr
*linkinfo
[IFLA_MAX
+ 1];
871 struct interface
*ifp
;
875 char *slave_kind
= NULL
;
876 struct zebra_ns
*zns
= NULL
;
877 vrf_id_t vrf_id
= VRF_DEFAULT
;
878 enum zebra_iftype zif_type
= ZEBRA_IF_OTHER
;
879 enum zebra_slave_iftype zif_slave_type
= ZEBRA_IF_SLAVE_NONE
;
880 ifindex_t bridge_ifindex
= IFINDEX_INTERNAL
;
881 ifindex_t link_ifindex
= IFINDEX_INTERNAL
;
882 ifindex_t bond_ifindex
= IFINDEX_INTERNAL
;
883 struct zebra_if
*zif
;
884 ns_id_t link_nsid
= ns_id
;
887 zns
= zebra_ns_lookup(ns_id
);
890 if (h
->nlmsg_type
!= RTM_NEWLINK
)
893 len
= h
->nlmsg_len
- NLMSG_LENGTH(sizeof(struct ifinfomsg
));
896 "%s: Message received from netlink is of a broken size: %d %zu",
897 __func__
, h
->nlmsg_len
,
898 (size_t)NLMSG_LENGTH(sizeof(struct ifinfomsg
)));
902 /* We are interested in some AF_BRIDGE notifications. */
903 if (ifi
->ifi_family
== AF_BRIDGE
)
904 return netlink_bridge_interface(h
, len
, ns_id
, startup
);
906 /* Looking up interface name. */
907 memset(linkinfo
, 0, sizeof(linkinfo
));
908 netlink_parse_rtattr(tb
, IFLA_MAX
, IFLA_RTA(ifi
), len
);
910 /* check for wireless messages to ignore */
911 if ((tb
[IFLA_WIRELESS
] != NULL
) && (ifi
->ifi_change
== 0)) {
912 if (IS_ZEBRA_DEBUG_KERNEL
)
913 zlog_debug("%s: ignoring IFLA_WIRELESS message",
918 if (tb
[IFLA_IFNAME
] == NULL
)
920 name
= (char *)RTA_DATA(tb
[IFLA_IFNAME
]);
922 if (tb
[IFLA_IFALIAS
])
923 desc
= (char *)RTA_DATA(tb
[IFLA_IFALIAS
]);
925 if (tb
[IFLA_LINKINFO
]) {
926 netlink_parse_rtattr_nested(linkinfo
, IFLA_INFO_MAX
,
929 if (linkinfo
[IFLA_INFO_KIND
])
930 kind
= RTA_DATA(linkinfo
[IFLA_INFO_KIND
]);
932 if (linkinfo
[IFLA_INFO_SLAVE_KIND
])
933 slave_kind
= RTA_DATA(linkinfo
[IFLA_INFO_SLAVE_KIND
]);
935 if ((slave_kind
!= NULL
) && strcmp(slave_kind
, "bond") == 0)
936 netlink_determine_zebra_iftype("bond_slave", &zif_type
);
938 netlink_determine_zebra_iftype(kind
, &zif_type
);
941 /* If VRF, create the VRF structure itself. */
942 if (zif_type
== ZEBRA_IF_VRF
&& !vrf_is_backend_netns()) {
943 netlink_vrf_change(h
, tb
[IFLA_LINKINFO
], ns_id
, name
);
944 vrf_id
= (vrf_id_t
)ifi
->ifi_index
;
947 if (tb
[IFLA_MASTER
]) {
948 if (slave_kind
&& (strcmp(slave_kind
, "vrf") == 0)
949 && !vrf_is_backend_netns()) {
950 zif_slave_type
= ZEBRA_IF_SLAVE_VRF
;
951 vrf_id
= *(uint32_t *)RTA_DATA(tb
[IFLA_MASTER
]);
952 } else if (slave_kind
&& (strcmp(slave_kind
, "bridge") == 0)) {
953 zif_slave_type
= ZEBRA_IF_SLAVE_BRIDGE
;
955 *(ifindex_t
*)RTA_DATA(tb
[IFLA_MASTER
]);
956 } else if (slave_kind
&& (strcmp(slave_kind
, "bond") == 0)) {
957 zif_slave_type
= ZEBRA_IF_SLAVE_BOND
;
958 bond_ifindex
= *(ifindex_t
*)RTA_DATA(tb
[IFLA_MASTER
]);
959 bypass
= netlink_parse_lacp_bypass(linkinfo
);
961 zif_slave_type
= ZEBRA_IF_SLAVE_OTHER
;
963 if (vrf_is_backend_netns())
964 vrf_id
= (vrf_id_t
)ns_id
;
966 /* If linking to another interface, note it. */
968 link_ifindex
= *(ifindex_t
*)RTA_DATA(tb
[IFLA_LINK
]);
970 if (tb
[IFLA_LINK_NETNSID
]) {
971 link_nsid
= *(ns_id_t
*)RTA_DATA(tb
[IFLA_LINK_NETNSID
]);
972 link_nsid
= ns_id_get_absolute(ns_id
, link_nsid
);
976 * We add by index first because in some cases such as the master
977 * interface, we have the index before we have the name. Fixing
978 * back references on the slave interfaces is painful if not done
979 * this way, i.e. by creating by ifindex.
981 ifp
= if_get_by_ifindex(ifi
->ifi_index
, vrf_id
);
982 set_ifindex(ifp
, ifi
->ifi_index
, zns
); /* add it to ns struct */
984 if_set_name(ifp
, name
);
986 ifp
->flags
= ifi
->ifi_flags
& 0x0000fffff;
987 ifp
->mtu6
= ifp
->mtu
= *(uint32_t *)RTA_DATA(tb
[IFLA_MTU
]);
989 ifp
->speed
= get_iflink_speed(ifp
, NULL
);
990 ifp
->ptm_status
= ZEBRA_PTM_STATUS_UNKNOWN
;
992 /* Set zebra interface type */
993 zebra_if_set_ziftype(ifp
, zif_type
, zif_slave_type
);
994 if (IS_ZEBRA_IF_VRF(ifp
))
995 SET_FLAG(ifp
->status
, ZEBRA_INTERFACE_VRF_LOOPBACK
);
998 * Just set the @link/lower-device ifindex. During nldump interfaces are
999 * not ordered in any fashion so we may end up getting upper devices
1000 * before lower devices. We will setup the real linkage once the dump
1003 zif
= (struct zebra_if
*)ifp
->info
;
1004 zif
->link_ifindex
= link_ifindex
;
1007 XFREE(MTYPE_TMP
, zif
->desc
);
1008 zif
->desc
= XSTRDUP(MTYPE_TMP
, desc
);
1011 /* Hardware type and address. */
1012 ifp
->ll_type
= netlink_to_zebra_link_type(ifi
->ifi_type
);
1013 netlink_interface_update_hw_addr(tb
, ifp
);
1017 /* Extract and save L2 interface information, take additional actions.
1019 netlink_interface_update_l2info(ifp
, linkinfo
[IFLA_INFO_DATA
],
1021 if (IS_ZEBRA_IF_BOND(ifp
))
1022 zebra_l2if_update_bond(ifp
, true);
1023 if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp
))
1024 zebra_l2if_update_bridge_slave(ifp
, bridge_ifindex
, ns_id
,
1025 ZEBRA_BRIDGE_NO_ACTION
);
1026 else if (IS_ZEBRA_IF_BOND_SLAVE(ifp
))
1027 zebra_l2if_update_bond_slave(ifp
, bond_ifindex
, !!bypass
);
1029 if (tb
[IFLA_PROTO_DOWN
]) {
1032 protodown
= *(uint8_t *)RTA_DATA(tb
[IFLA_PROTO_DOWN
]);
1033 netlink_proc_dplane_if_protodown(zif
, !!protodown
);
1039 /* Request for specific interface or address information from the kernel */
1040 static int netlink_request_intf_addr(struct nlsock
*netlink_cmd
, int family
,
1041 int type
, uint32_t filter_mask
)
1045 struct ifinfomsg ifm
;
1049 /* Form the request, specifying filter (rtattr) if needed. */
1050 memset(&req
, 0, sizeof(req
));
1051 req
.n
.nlmsg_type
= type
;
1052 req
.n
.nlmsg_flags
= NLM_F_ROOT
| NLM_F_MATCH
| NLM_F_REQUEST
;
1053 req
.n
.nlmsg_len
= NLMSG_LENGTH(sizeof(struct ifinfomsg
));
1054 req
.ifm
.ifi_family
= family
;
1056 /* Include filter, if specified. */
1058 nl_attr_put32(&req
.n
, sizeof(req
), IFLA_EXT_MASK
, filter_mask
);
1060 return netlink_request(netlink_cmd
, &req
);
1063 enum netlink_msg_status
1064 netlink_put_gre_set_msg(struct nl_batch
*bth
, struct zebra_dplane_ctx
*ctx
)
1066 enum dplane_op_e op
;
1067 enum netlink_msg_status ret
;
1069 op
= dplane_ctx_get_op(ctx
);
1070 assert(op
== DPLANE_OP_GRE_SET
);
1072 ret
= netlink_batch_add_msg(bth
, ctx
, netlink_gre_set_msg_encoder
, false);
1077 /* Interface lookup by netlink socket. */
1078 int interface_lookup_netlink(struct zebra_ns
*zns
)
1081 struct zebra_dplane_info dp_info
;
1082 struct nlsock
*netlink_cmd
= &zns
->netlink_cmd
;
1084 /* Capture key info from ns struct */
1085 zebra_dplane_info_from_zns(&dp_info
, zns
, true /*is_cmd*/);
1087 /* Get interface information. */
1088 ret
= netlink_request_intf_addr(netlink_cmd
, AF_PACKET
, RTM_GETLINK
, 0);
1091 ret
= netlink_parse_info(netlink_interface
, netlink_cmd
, &dp_info
, 0,
1096 /* Get interface information - for bridge interfaces. */
1097 ret
= netlink_request_intf_addr(netlink_cmd
, AF_BRIDGE
, RTM_GETLINK
,
1098 RTEXT_FILTER_BRVLAN
);
1101 ret
= netlink_parse_info(netlink_interface
, netlink_cmd
, &dp_info
, 0,
1106 /* Get interface information - for bridge interfaces. */
1107 ret
= netlink_request_intf_addr(netlink_cmd
, AF_BRIDGE
, RTM_GETLINK
,
1108 RTEXT_FILTER_BRVLAN
);
1111 ret
= netlink_parse_info(netlink_interface
, netlink_cmd
, &dp_info
, 0,
1116 /* fixup linkages */
1117 zebra_if_update_all_links(zns
);
1122 * interface_addr_lookup_netlink() - Look up interface addresses
1124 * @zns: Zebra netlink socket
1125 * Return: Result status
1127 static int interface_addr_lookup_netlink(struct zebra_ns
*zns
)
1130 struct zebra_dplane_info dp_info
;
1131 struct nlsock
*netlink_cmd
= &zns
->netlink_cmd
;
1133 /* Capture key info from ns struct */
1134 zebra_dplane_info_from_zns(&dp_info
, zns
, true /*is_cmd*/);
1136 /* Get IPv4 address of the interfaces. */
1137 ret
= netlink_request_intf_addr(netlink_cmd
, AF_INET
, RTM_GETADDR
, 0);
1140 ret
= netlink_parse_info(netlink_interface_addr
, netlink_cmd
, &dp_info
,
1145 /* Get IPv6 address of the interfaces. */
1146 ret
= netlink_request_intf_addr(netlink_cmd
, AF_INET6
, RTM_GETADDR
, 0);
1149 ret
= netlink_parse_info(netlink_interface_addr
, netlink_cmd
, &dp_info
,
1157 int kernel_interface_set_master(struct interface
*master
,
1158 struct interface
*slave
)
1160 struct zebra_ns
*zns
= zebra_ns_lookup(NS_DEFAULT
);
1164 struct ifinfomsg ifa
;
1165 char buf
[NL_PKT_BUF_SIZE
];
1168 memset(&req
, 0, sizeof(req
));
1170 req
.n
.nlmsg_len
= NLMSG_LENGTH(sizeof(struct ifinfomsg
));
1171 req
.n
.nlmsg_flags
= NLM_F_REQUEST
;
1172 req
.n
.nlmsg_type
= RTM_SETLINK
;
1173 req
.n
.nlmsg_pid
= zns
->netlink_cmd
.snl
.nl_pid
;
1175 req
.ifa
.ifi_index
= slave
->ifindex
;
1177 nl_attr_put32(&req
.n
, sizeof(req
), IFLA_MASTER
, master
->ifindex
);
1178 nl_attr_put32(&req
.n
, sizeof(req
), IFLA_LINK
, slave
->ifindex
);
1180 return netlink_talk(netlink_talk_filter
, &req
.n
, &zns
->netlink_cmd
, zns
,
1184 /* Interface address modification. */
1185 static ssize_t
netlink_address_msg_encoder(struct zebra_dplane_ctx
*ctx
,
1186 void *buf
, size_t buflen
)
1189 const struct prefix
*p
;
1195 struct ifaddrmsg ifa
;
1199 if (buflen
< sizeof(*req
))
1202 p
= dplane_ctx_get_intf_addr(ctx
);
1203 memset(req
, 0, sizeof(*req
));
1205 bytelen
= (p
->family
== AF_INET
? 4 : 16);
1207 req
->n
.nlmsg_len
= NLMSG_LENGTH(sizeof(struct ifaddrmsg
));
1208 req
->n
.nlmsg_flags
= NLM_F_REQUEST
;
1210 if (dplane_ctx_get_op(ctx
) == DPLANE_OP_ADDR_INSTALL
)
1215 req
->n
.nlmsg_type
= cmd
;
1216 req
->ifa
.ifa_family
= p
->family
;
1218 req
->ifa
.ifa_index
= dplane_ctx_get_ifindex(ctx
);
1220 if (!nl_attr_put(&req
->n
, buflen
, IFA_LOCAL
, &p
->u
.prefix
, bytelen
))
1223 if (p
->family
== AF_INET
) {
1224 if (dplane_ctx_intf_is_connected(ctx
)) {
1225 p
= dplane_ctx_get_intf_dest(ctx
);
1226 if (!nl_attr_put(&req
->n
, buflen
, IFA_ADDRESS
,
1227 &p
->u
.prefix
, bytelen
))
1229 } else if (cmd
== RTM_NEWADDR
) {
1230 struct in_addr broad
= {
1231 .s_addr
= ipv4_broadcast_addr(p
->u
.prefix4
.s_addr
,
1234 if (!nl_attr_put(&req
->n
, buflen
, IFA_BROADCAST
, &broad
,
1240 /* p is now either address or destination/bcast addr */
1241 req
->ifa
.ifa_prefixlen
= p
->prefixlen
;
1243 if (dplane_ctx_intf_is_secondary(ctx
))
1244 SET_FLAG(req
->ifa
.ifa_flags
, IFA_F_SECONDARY
);
1246 if (dplane_ctx_intf_has_label(ctx
)) {
1247 label
= dplane_ctx_get_intf_label(ctx
);
1248 if (!nl_attr_put(&req
->n
, buflen
, IFA_LABEL
, label
,
1253 return NLMSG_ALIGN(req
->n
.nlmsg_len
);
1256 enum netlink_msg_status
1257 netlink_put_address_update_msg(struct nl_batch
*bth
,
1258 struct zebra_dplane_ctx
*ctx
)
1260 return netlink_batch_add_msg(bth
, ctx
, netlink_address_msg_encoder
,
1264 int netlink_interface_addr(struct nlmsghdr
*h
, ns_id_t ns_id
, int startup
)
1267 struct ifaddrmsg
*ifa
;
1268 struct rtattr
*tb
[IFA_MAX
+ 1];
1269 struct interface
*ifp
;
1274 struct zebra_ns
*zns
;
1275 uint32_t metric
= METRIC_MAX
;
1276 uint32_t kernel_flags
= 0;
1278 zns
= zebra_ns_lookup(ns_id
);
1279 ifa
= NLMSG_DATA(h
);
1281 if (ifa
->ifa_family
!= AF_INET
&& ifa
->ifa_family
!= AF_INET6
) {
1283 EC_ZEBRA_UNKNOWN_FAMILY
,
1284 "Invalid address family: %u received from kernel interface addr change: %s",
1285 ifa
->ifa_family
, nl_msg_type_to_str(h
->nlmsg_type
));
1289 if (h
->nlmsg_type
!= RTM_NEWADDR
&& h
->nlmsg_type
!= RTM_DELADDR
)
1292 len
= h
->nlmsg_len
- NLMSG_LENGTH(sizeof(struct ifaddrmsg
));
1295 "%s: Message received from netlink is of a broken size: %d %zu",
1296 __func__
, h
->nlmsg_len
,
1297 (size_t)NLMSG_LENGTH(sizeof(struct ifaddrmsg
)));
1301 netlink_parse_rtattr(tb
, IFA_MAX
, IFA_RTA(ifa
), len
);
1303 ifp
= if_lookup_by_index_per_ns(zns
, ifa
->ifa_index
);
1307 "netlink_interface_addr can't find interface by index %d",
1312 /* Flags passed through */
1314 kernel_flags
= *(int *)RTA_DATA(tb
[IFA_FLAGS
]);
1316 kernel_flags
= ifa
->ifa_flags
;
1318 if (IS_ZEBRA_DEBUG_KERNEL
) /* remove this line to see initial ifcfg */
1321 zlog_debug("netlink_interface_addr %s %s flags 0x%x:",
1322 nl_msg_type_to_str(h
->nlmsg_type
), ifp
->name
,
1325 zlog_debug(" IFA_LOCAL %s/%d",
1326 inet_ntop(ifa
->ifa_family
,
1327 RTA_DATA(tb
[IFA_LOCAL
]), buf
,
1329 ifa
->ifa_prefixlen
);
1330 if (tb
[IFA_ADDRESS
])
1331 zlog_debug(" IFA_ADDRESS %s/%d",
1332 inet_ntop(ifa
->ifa_family
,
1333 RTA_DATA(tb
[IFA_ADDRESS
]), buf
,
1335 ifa
->ifa_prefixlen
);
1336 if (tb
[IFA_BROADCAST
])
1337 zlog_debug(" IFA_BROADCAST %s/%d",
1338 inet_ntop(ifa
->ifa_family
,
1339 RTA_DATA(tb
[IFA_BROADCAST
]), buf
,
1341 ifa
->ifa_prefixlen
);
1342 if (tb
[IFA_LABEL
] && strcmp(ifp
->name
, RTA_DATA(tb
[IFA_LABEL
])))
1343 zlog_debug(" IFA_LABEL %s",
1344 (char *)RTA_DATA(tb
[IFA_LABEL
]));
1346 if (tb
[IFA_CACHEINFO
]) {
1347 struct ifa_cacheinfo
*ci
= RTA_DATA(tb
[IFA_CACHEINFO
]);
1348 zlog_debug(" IFA_CACHEINFO pref %d, valid %d",
1349 ci
->ifa_prefered
, ci
->ifa_valid
);
1353 /* logic copied from iproute2/ip/ipaddress.c:print_addrinfo() */
1354 if (tb
[IFA_LOCAL
] == NULL
)
1355 tb
[IFA_LOCAL
] = tb
[IFA_ADDRESS
];
1356 if (tb
[IFA_ADDRESS
] == NULL
)
1357 tb
[IFA_ADDRESS
] = tb
[IFA_LOCAL
];
1359 /* local interface address */
1360 addr
= (tb
[IFA_LOCAL
] ? RTA_DATA(tb
[IFA_LOCAL
]) : NULL
);
1362 /* is there a peer address? */
1364 && memcmp(RTA_DATA(tb
[IFA_ADDRESS
]), RTA_DATA(tb
[IFA_LOCAL
]),
1365 RTA_PAYLOAD(tb
[IFA_ADDRESS
]))) {
1366 broad
= RTA_DATA(tb
[IFA_ADDRESS
]);
1367 SET_FLAG(flags
, ZEBRA_IFA_PEER
);
1369 /* seeking a broadcast address */
1370 broad
= (tb
[IFA_BROADCAST
] ? RTA_DATA(tb
[IFA_BROADCAST
])
1373 /* addr is primary key, SOL if we don't have one */
1375 zlog_debug("%s: Local Interface Address is NULL for %s",
1376 __func__
, ifp
->name
);
1381 if (kernel_flags
& IFA_F_SECONDARY
)
1382 SET_FLAG(flags
, ZEBRA_IFA_SECONDARY
);
1386 label
= (char *)RTA_DATA(tb
[IFA_LABEL
]);
1388 if (label
&& strcmp(ifp
->name
, label
) == 0)
1391 if (tb
[IFA_RT_PRIORITY
])
1392 metric
= *(uint32_t *)RTA_DATA(tb
[IFA_RT_PRIORITY
]);
1394 /* Register interface address to the interface. */
1395 if (ifa
->ifa_family
== AF_INET
) {
1396 if (ifa
->ifa_prefixlen
> IPV4_MAX_BITLEN
) {
1398 "Invalid prefix length: %u received from kernel interface addr change: %s",
1400 nl_msg_type_to_str(h
->nlmsg_type
));
1404 if (h
->nlmsg_type
== RTM_NEWADDR
)
1405 connected_add_ipv4(ifp
, flags
, (struct in_addr
*)addr
,
1407 (struct in_addr
*)broad
, label
,
1409 else if (CHECK_FLAG(flags
, ZEBRA_IFA_PEER
)) {
1410 /* Delete with a peer address */
1411 connected_delete_ipv4(
1412 ifp
, flags
, (struct in_addr
*)addr
,
1413 ifa
->ifa_prefixlen
, broad
);
1415 connected_delete_ipv4(
1416 ifp
, flags
, (struct in_addr
*)addr
,
1417 ifa
->ifa_prefixlen
, NULL
);
1420 if (ifa
->ifa_family
== AF_INET6
) {
1421 if (ifa
->ifa_prefixlen
> IPV6_MAX_BITLEN
) {
1423 "Invalid prefix length: %u received from kernel interface addr change: %s",
1425 nl_msg_type_to_str(h
->nlmsg_type
));
1428 if (h
->nlmsg_type
== RTM_NEWADDR
) {
1429 /* Only consider valid addresses; we'll not get a
1431 * the kernel till IPv6 DAD has completed, but at init
1433 * does query for and will receive all addresses.
1436 & (IFA_F_DADFAILED
| IFA_F_TENTATIVE
)))
1437 connected_add_ipv6(ifp
, flags
,
1438 (struct in6_addr
*)addr
,
1439 (struct in6_addr
*)broad
,
1440 ifa
->ifa_prefixlen
, label
,
1443 connected_delete_ipv6(ifp
, (struct in6_addr
*)addr
,
1444 NULL
, ifa
->ifa_prefixlen
);
1448 * Linux kernel does not send route delete on interface down/addr del
1449 * so we have to re-process routes it owns (i.e. kernel routes)
1451 if (h
->nlmsg_type
!= RTM_NEWADDR
)
1452 rib_update(RIB_UPDATE_KERNEL
);
1458 * Parse and validate an incoming interface address change message,
1459 * generating a dplane context object.
1460 * This runs in the dplane pthread; the context is enqueued to the
1461 * main pthread for processing.
1463 int netlink_interface_addr_dplane(struct nlmsghdr
*h
, ns_id_t ns_id
,
1464 int startup
/*ignored*/)
1467 struct ifaddrmsg
*ifa
;
1468 struct rtattr
*tb
[IFA_MAX
+ 1];
1472 uint32_t metric
= METRIC_MAX
;
1473 uint32_t kernel_flags
= 0;
1474 struct zebra_dplane_ctx
*ctx
;
1477 ifa
= NLMSG_DATA(h
);
1479 /* Validate message types */
1480 if (h
->nlmsg_type
!= RTM_NEWADDR
&& h
->nlmsg_type
!= RTM_DELADDR
)
1483 if (ifa
->ifa_family
!= AF_INET
&& ifa
->ifa_family
!= AF_INET6
) {
1484 if (IS_ZEBRA_DEBUG_KERNEL
)
1485 zlog_debug("%s: %s: Invalid address family: %u",
1486 __func__
, nl_msg_type_to_str(h
->nlmsg_type
),
1491 len
= h
->nlmsg_len
- NLMSG_LENGTH(sizeof(struct ifaddrmsg
));
1493 if (IS_ZEBRA_DEBUG_KERNEL
)
1494 zlog_debug("%s: %s: netlink msg bad size: %d %zu",
1495 __func__
, nl_msg_type_to_str(h
->nlmsg_type
),
1497 (size_t)NLMSG_LENGTH(
1498 sizeof(struct ifaddrmsg
)));
1502 netlink_parse_rtattr(tb
, IFA_MAX
, IFA_RTA(ifa
), len
);
1504 /* Flags passed through */
1506 kernel_flags
= *(int *)RTA_DATA(tb
[IFA_FLAGS
]);
1508 kernel_flags
= ifa
->ifa_flags
;
1510 if (IS_ZEBRA_DEBUG_KERNEL
) { /* remove this line to see initial ifcfg */
1511 char buf
[PREFIX_STRLEN
];
1513 zlog_debug("%s: %s nsid %u ifindex %u flags 0x%x:", __func__
,
1514 nl_msg_type_to_str(h
->nlmsg_type
), ns_id
,
1515 ifa
->ifa_index
, kernel_flags
);
1517 zlog_debug(" IFA_LOCAL %s/%d",
1518 inet_ntop(ifa
->ifa_family
,
1519 RTA_DATA(tb
[IFA_LOCAL
]), buf
,
1521 ifa
->ifa_prefixlen
);
1522 if (tb
[IFA_ADDRESS
])
1523 zlog_debug(" IFA_ADDRESS %s/%d",
1524 inet_ntop(ifa
->ifa_family
,
1525 RTA_DATA(tb
[IFA_ADDRESS
]), buf
,
1527 ifa
->ifa_prefixlen
);
1528 if (tb
[IFA_BROADCAST
])
1529 zlog_debug(" IFA_BROADCAST %s/%d",
1530 inet_ntop(ifa
->ifa_family
,
1531 RTA_DATA(tb
[IFA_BROADCAST
]), buf
,
1533 ifa
->ifa_prefixlen
);
1535 zlog_debug(" IFA_LABEL %s",
1536 (const char *)RTA_DATA(tb
[IFA_LABEL
]));
1538 if (tb
[IFA_CACHEINFO
]) {
1539 struct ifa_cacheinfo
*ci
= RTA_DATA(tb
[IFA_CACHEINFO
]);
1541 zlog_debug(" IFA_CACHEINFO pref %d, valid %d",
1542 ci
->ifa_prefered
, ci
->ifa_valid
);
1546 /* Validate prefix length */
1548 if (ifa
->ifa_family
== AF_INET
1549 && ifa
->ifa_prefixlen
> IPV4_MAX_BITLEN
) {
1550 if (IS_ZEBRA_DEBUG_KERNEL
)
1551 zlog_debug("%s: %s: Invalid prefix length: %u",
1552 __func__
, nl_msg_type_to_str(h
->nlmsg_type
),
1553 ifa
->ifa_prefixlen
);
1557 if (ifa
->ifa_family
== AF_INET6
) {
1558 if (ifa
->ifa_prefixlen
> IPV6_MAX_BITLEN
) {
1559 if (IS_ZEBRA_DEBUG_KERNEL
)
1560 zlog_debug("%s: %s: Invalid prefix length: %u",
1562 nl_msg_type_to_str(h
->nlmsg_type
),
1563 ifa
->ifa_prefixlen
);
1567 /* Only consider valid addresses; we'll not get a kernel
1568 * notification till IPv6 DAD has completed, but at init
1569 * time, FRR does query for and will receive all addresses.
1571 if (h
->nlmsg_type
== RTM_NEWADDR
1572 && (kernel_flags
& (IFA_F_DADFAILED
| IFA_F_TENTATIVE
))) {
1573 if (IS_ZEBRA_DEBUG_KERNEL
)
1574 zlog_debug("%s: %s: Invalid/tentative addr",
1576 nl_msg_type_to_str(h
->nlmsg_type
));
1581 /* logic copied from iproute2/ip/ipaddress.c:print_addrinfo() */
1582 if (tb
[IFA_LOCAL
] == NULL
)
1583 tb
[IFA_LOCAL
] = tb
[IFA_ADDRESS
];
1584 if (tb
[IFA_ADDRESS
] == NULL
)
1585 tb
[IFA_ADDRESS
] = tb
[IFA_LOCAL
];
1587 /* local interface address */
1588 addr
= (tb
[IFA_LOCAL
] ? RTA_DATA(tb
[IFA_LOCAL
]) : NULL
);
1590 /* addr is primary key, SOL if we don't have one */
1592 if (IS_ZEBRA_DEBUG_KERNEL
)
1593 zlog_debug("%s: %s: No local interface address",
1594 __func__
, nl_msg_type_to_str(h
->nlmsg_type
));
1598 /* Allocate a context object, now that validation is done. */
1599 ctx
= dplane_ctx_alloc();
1600 if (h
->nlmsg_type
== RTM_NEWADDR
)
1601 dplane_ctx_set_op(ctx
, DPLANE_OP_INTF_ADDR_ADD
);
1603 dplane_ctx_set_op(ctx
, DPLANE_OP_INTF_ADDR_DEL
);
1605 dplane_ctx_set_ifindex(ctx
, ifa
->ifa_index
);
1606 dplane_ctx_set_ns_id(ctx
, ns_id
);
1608 /* Convert addr to prefix */
1609 memset(&p
, 0, sizeof(p
));
1610 p
.family
= ifa
->ifa_family
;
1611 p
.prefixlen
= ifa
->ifa_prefixlen
;
1612 if (p
.family
== AF_INET
)
1613 p
.u
.prefix4
= *(struct in_addr
*)addr
;
1615 p
.u
.prefix6
= *(struct in6_addr
*)addr
;
1617 dplane_ctx_set_intf_addr(ctx
, &p
);
1619 /* is there a peer address? */
1621 && memcmp(RTA_DATA(tb
[IFA_ADDRESS
]), RTA_DATA(tb
[IFA_LOCAL
]),
1622 RTA_PAYLOAD(tb
[IFA_ADDRESS
]))) {
1623 broad
= RTA_DATA(tb
[IFA_ADDRESS
]);
1624 dplane_ctx_intf_set_connected(ctx
);
1625 } else if (tb
[IFA_BROADCAST
]) {
1626 /* seeking a broadcast address */
1627 broad
= RTA_DATA(tb
[IFA_BROADCAST
]);
1628 dplane_ctx_intf_set_broadcast(ctx
);
1633 /* Convert addr to prefix */
1634 memset(&p
, 0, sizeof(p
));
1635 p
.family
= ifa
->ifa_family
;
1636 p
.prefixlen
= ifa
->ifa_prefixlen
;
1637 if (p
.family
== AF_INET
)
1638 p
.u
.prefix4
= *(struct in_addr
*)broad
;
1640 p
.u
.prefix6
= *(struct in6_addr
*)broad
;
1642 dplane_ctx_set_intf_dest(ctx
, &p
);
1646 if (kernel_flags
& IFA_F_SECONDARY
)
1647 dplane_ctx_intf_set_secondary(ctx
);
1650 if (tb
[IFA_LABEL
]) {
1651 label
= (char *)RTA_DATA(tb
[IFA_LABEL
]);
1652 dplane_ctx_set_intf_label(ctx
, label
);
1655 if (tb
[IFA_RT_PRIORITY
])
1656 metric
= *(uint32_t *)RTA_DATA(tb
[IFA_RT_PRIORITY
]);
1658 dplane_ctx_set_intf_metric(ctx
, metric
);
1660 /* Enqueue ctx for main pthread to process */
1661 dplane_provider_enqueue_to_zebra(ctx
);
1666 int netlink_link_change(struct nlmsghdr
*h
, ns_id_t ns_id
, int startup
)
1669 struct ifinfomsg
*ifi
;
1670 struct rtattr
*tb
[IFLA_MAX
+ 1];
1671 struct rtattr
*linkinfo
[IFLA_MAX
+ 1];
1672 struct interface
*ifp
;
1676 char *slave_kind
= NULL
;
1677 struct zebra_ns
*zns
;
1678 vrf_id_t vrf_id
= VRF_DEFAULT
;
1679 enum zebra_iftype zif_type
= ZEBRA_IF_OTHER
;
1680 enum zebra_slave_iftype zif_slave_type
= ZEBRA_IF_SLAVE_NONE
;
1681 ifindex_t bridge_ifindex
= IFINDEX_INTERNAL
;
1682 ifindex_t bond_ifindex
= IFINDEX_INTERNAL
;
1683 ifindex_t link_ifindex
= IFINDEX_INTERNAL
;
1684 uint8_t old_hw_addr
[INTERFACE_HWADDR_MAX
];
1685 struct zebra_if
*zif
;
1686 ns_id_t link_nsid
= ns_id
;
1687 ifindex_t master_infindex
= IFINDEX_INTERNAL
;
1690 zns
= zebra_ns_lookup(ns_id
);
1691 ifi
= NLMSG_DATA(h
);
1693 /* assume if not default zns, then new VRF */
1694 if (!(h
->nlmsg_type
== RTM_NEWLINK
|| h
->nlmsg_type
== RTM_DELLINK
)) {
1695 /* If this is not link add/delete message so print warning. */
1696 zlog_debug("netlink_link_change: wrong kernel message %s",
1697 nl_msg_type_to_str(h
->nlmsg_type
));
1701 if (!(ifi
->ifi_family
== AF_UNSPEC
|| ifi
->ifi_family
== AF_BRIDGE
1702 || ifi
->ifi_family
== AF_INET6
)) {
1704 EC_ZEBRA_UNKNOWN_FAMILY
,
1705 "Invalid address family: %u received from kernel link change: %s",
1706 ifi
->ifi_family
, nl_msg_type_to_str(h
->nlmsg_type
));
1710 len
= h
->nlmsg_len
- NLMSG_LENGTH(sizeof(struct ifinfomsg
));
1713 "%s: Message received from netlink is of a broken size %d %zu",
1714 __func__
, h
->nlmsg_len
,
1715 (size_t)NLMSG_LENGTH(sizeof(struct ifinfomsg
)));
1719 /* We are interested in some AF_BRIDGE notifications. */
1720 if (ifi
->ifi_family
== AF_BRIDGE
)
1721 return netlink_bridge_interface(h
, len
, ns_id
, startup
);
1723 /* Looking up interface name. */
1724 memset(linkinfo
, 0, sizeof(linkinfo
));
1725 netlink_parse_rtattr(tb
, IFLA_MAX
, IFLA_RTA(ifi
), len
);
1727 /* check for wireless messages to ignore */
1728 if ((tb
[IFLA_WIRELESS
] != NULL
) && (ifi
->ifi_change
== 0)) {
1729 if (IS_ZEBRA_DEBUG_KERNEL
)
1730 zlog_debug("%s: ignoring IFLA_WIRELESS message",
1735 if (tb
[IFLA_IFNAME
] == NULL
)
1737 name
= (char *)RTA_DATA(tb
[IFLA_IFNAME
]);
1739 /* Must be valid string. */
1740 len
= RTA_PAYLOAD(tb
[IFLA_IFNAME
]);
1741 if (len
< 2 || name
[len
- 1] != '\0') {
1742 if (IS_ZEBRA_DEBUG_KERNEL
)
1743 zlog_debug("%s: invalid intf name", __func__
);
1747 if (tb
[IFLA_LINKINFO
]) {
1748 netlink_parse_rtattr_nested(linkinfo
, IFLA_INFO_MAX
,
1751 if (linkinfo
[IFLA_INFO_KIND
])
1752 kind
= RTA_DATA(linkinfo
[IFLA_INFO_KIND
]);
1754 if (linkinfo
[IFLA_INFO_SLAVE_KIND
])
1755 slave_kind
= RTA_DATA(linkinfo
[IFLA_INFO_SLAVE_KIND
]);
1757 netlink_determine_zebra_iftype(kind
, &zif_type
);
1760 /* If linking to another interface, note it. */
1762 link_ifindex
= *(ifindex_t
*)RTA_DATA(tb
[IFLA_LINK
]);
1764 if (tb
[IFLA_LINK_NETNSID
]) {
1765 link_nsid
= *(ns_id_t
*)RTA_DATA(tb
[IFLA_LINK_NETNSID
]);
1766 link_nsid
= ns_id_get_absolute(ns_id
, link_nsid
);
1768 if (tb
[IFLA_IFALIAS
]) {
1769 desc
= (char *)RTA_DATA(tb
[IFLA_IFALIAS
]);
1772 /* If VRF, create or update the VRF structure itself. */
1773 if (zif_type
== ZEBRA_IF_VRF
&& !vrf_is_backend_netns()) {
1774 netlink_vrf_change(h
, tb
[IFLA_LINKINFO
], ns_id
, name
);
1775 vrf_id
= (vrf_id_t
)ifi
->ifi_index
;
1778 /* See if interface is present. */
1779 ifp
= if_lookup_by_name_per_ns(zns
, name
);
1781 if (h
->nlmsg_type
== RTM_NEWLINK
) {
1782 if (tb
[IFLA_MASTER
]) {
1783 if (slave_kind
&& (strcmp(slave_kind
, "vrf") == 0)
1784 && !vrf_is_backend_netns()) {
1785 zif_slave_type
= ZEBRA_IF_SLAVE_VRF
;
1786 master_infindex
= vrf_id
=
1787 *(uint32_t *)RTA_DATA(tb
[IFLA_MASTER
]);
1788 } else if (slave_kind
1789 && (strcmp(slave_kind
, "bridge") == 0)) {
1790 zif_slave_type
= ZEBRA_IF_SLAVE_BRIDGE
;
1791 master_infindex
= bridge_ifindex
=
1792 *(ifindex_t
*)RTA_DATA(tb
[IFLA_MASTER
]);
1793 } else if (slave_kind
1794 && (strcmp(slave_kind
, "bond") == 0)) {
1795 zif_slave_type
= ZEBRA_IF_SLAVE_BOND
;
1796 master_infindex
= bond_ifindex
=
1797 *(ifindex_t
*)RTA_DATA(tb
[IFLA_MASTER
]);
1798 bypass
= netlink_parse_lacp_bypass(linkinfo
);
1800 zif_slave_type
= ZEBRA_IF_SLAVE_OTHER
;
1802 if (vrf_is_backend_netns())
1803 vrf_id
= (vrf_id_t
)ns_id
;
1805 || !CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
1806 /* Add interface notification from kernel */
1807 if (IS_ZEBRA_DEBUG_KERNEL
)
1809 "RTM_NEWLINK ADD for %s(%u) vrf_id %u type %d sl_type %d master %u flags 0x%x",
1810 name
, ifi
->ifi_index
, vrf_id
, zif_type
,
1811 zif_slave_type
, master_infindex
,
1815 /* unknown interface */
1816 ifp
= if_get_by_name(name
, vrf_id
);
1818 /* pre-configured interface, learnt now */
1819 if (ifp
->vrf_id
!= vrf_id
)
1820 if_update_to_new_vrf(ifp
, vrf_id
);
1823 /* Update interface information. */
1824 set_ifindex(ifp
, ifi
->ifi_index
, zns
);
1825 ifp
->flags
= ifi
->ifi_flags
& 0x0000fffff;
1826 if (!tb
[IFLA_MTU
]) {
1828 "RTM_NEWLINK for interface %s(%u) without MTU set",
1829 name
, ifi
->ifi_index
);
1832 ifp
->mtu6
= ifp
->mtu
= *(int *)RTA_DATA(tb
[IFLA_MTU
]);
1834 ifp
->ptm_status
= ZEBRA_PTM_STATUS_UNKNOWN
;
1836 /* Set interface type */
1837 zebra_if_set_ziftype(ifp
, zif_type
, zif_slave_type
);
1838 if (IS_ZEBRA_IF_VRF(ifp
))
1839 SET_FLAG(ifp
->status
,
1840 ZEBRA_INTERFACE_VRF_LOOPBACK
);
1843 zebra_if_update_link(ifp
, link_ifindex
, ns_id
);
1845 netlink_interface_update_hw_addr(tb
, ifp
);
1847 /* Inform clients, install any configured addresses. */
1850 /* Extract and save L2 interface information, take
1851 * additional actions. */
1852 netlink_interface_update_l2info(
1853 ifp
, linkinfo
[IFLA_INFO_DATA
],
1855 if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp
))
1856 zebra_l2if_update_bridge_slave(
1857 ifp
, bridge_ifindex
, ns_id
,
1858 ZEBRA_BRIDGE_NO_ACTION
);
1859 else if (IS_ZEBRA_IF_BOND_SLAVE(ifp
))
1860 zebra_l2if_update_bond_slave(ifp
, bond_ifindex
,
1863 if (tb
[IFLA_PROTO_DOWN
]) {
1866 protodown
= *(uint8_t *)RTA_DATA(
1867 tb
[IFLA_PROTO_DOWN
]);
1868 netlink_proc_dplane_if_protodown(ifp
->info
,
1871 } else if (ifp
->vrf_id
!= vrf_id
) {
1872 /* VRF change for an interface. */
1873 if (IS_ZEBRA_DEBUG_KERNEL
)
1875 "RTM_NEWLINK vrf-change for %s(%u) vrf_id %u -> %u flags 0x%x",
1876 name
, ifp
->ifindex
, ifp
->vrf_id
, vrf_id
,
1879 if_handle_vrf_change(ifp
, vrf_id
);
1881 bool was_bridge_slave
, was_bond_slave
;
1882 uint8_t chgflags
= ZEBRA_BRIDGE_NO_ACTION
;
1884 /* Interface update. */
1885 if (IS_ZEBRA_DEBUG_KERNEL
)
1887 "RTM_NEWLINK update for %s(%u) sl_type %d master %u flags 0x%x",
1888 name
, ifp
->ifindex
, zif_slave_type
,
1889 master_infindex
, ifi
->ifi_flags
);
1891 set_ifindex(ifp
, ifi
->ifi_index
, zns
);
1892 if (!tb
[IFLA_MTU
]) {
1894 "RTM_NEWLINK for interface %s(%u) without MTU set",
1895 name
, ifi
->ifi_index
);
1898 ifp
->mtu6
= ifp
->mtu
= *(int *)RTA_DATA(tb
[IFLA_MTU
]);
1901 /* Update interface type - NOTE: Only slave_type can
1903 was_bridge_slave
= IS_ZEBRA_IF_BRIDGE_SLAVE(ifp
);
1904 was_bond_slave
= IS_ZEBRA_IF_BOND_SLAVE(ifp
);
1905 zebra_if_set_ziftype(ifp
, zif_type
, zif_slave_type
);
1907 memcpy(old_hw_addr
, ifp
->hw_addr
, INTERFACE_HWADDR_MAX
);
1910 zebra_if_update_link(ifp
, link_ifindex
, ns_id
);
1912 netlink_interface_update_hw_addr(tb
, ifp
);
1914 if (if_is_no_ptm_operative(ifp
)) {
1915 ifp
->flags
= ifi
->ifi_flags
& 0x0000fffff;
1916 if (!if_is_no_ptm_operative(ifp
)) {
1917 if (IS_ZEBRA_DEBUG_KERNEL
)
1919 "Intf %s(%u) has gone DOWN",
1920 name
, ifp
->ifindex
);
1922 rib_update(RIB_UPDATE_KERNEL
);
1923 } else if (if_is_operative(ifp
)) {
1924 bool mac_updated
= false;
1926 /* Must notify client daemons of new
1927 * interface status. */
1928 if (IS_ZEBRA_DEBUG_KERNEL
)
1930 "Intf %s(%u) PTM up, notifying clients",
1931 name
, ifp
->ifindex
);
1932 zebra_interface_up_update(ifp
);
1934 /* Update EVPN VNI when SVI MAC change
1936 if (memcmp(old_hw_addr
, ifp
->hw_addr
,
1937 INTERFACE_HWADDR_MAX
))
1939 if (IS_ZEBRA_IF_VLAN(ifp
)
1941 struct interface
*link_if
;
1944 if_lookup_by_index_per_ns(
1945 zebra_ns_lookup(NS_DEFAULT
),
1948 zebra_vxlan_svi_up(ifp
,
1950 } else if (mac_updated
1951 && IS_ZEBRA_IF_BRIDGE(ifp
)) {
1953 "Intf %s(%u) bridge changed MAC address",
1954 name
, ifp
->ifindex
);
1956 ZEBRA_BRIDGE_MASTER_MAC_CHANGE
;
1960 ifp
->flags
= ifi
->ifi_flags
& 0x0000fffff;
1961 if (if_is_operative(ifp
)) {
1962 if (IS_ZEBRA_DEBUG_KERNEL
)
1964 "Intf %s(%u) has come UP",
1965 name
, ifp
->ifindex
);
1967 if (IS_ZEBRA_IF_BRIDGE(ifp
))
1969 ZEBRA_BRIDGE_MASTER_UP
;
1971 if (IS_ZEBRA_DEBUG_KERNEL
)
1973 "Intf %s(%u) has gone DOWN",
1974 name
, ifp
->ifindex
);
1976 rib_update(RIB_UPDATE_KERNEL
);
1980 /* Extract and save L2 interface information, take
1981 * additional actions. */
1982 netlink_interface_update_l2info(
1983 ifp
, linkinfo
[IFLA_INFO_DATA
],
1985 if (IS_ZEBRA_IF_BRIDGE(ifp
))
1986 zebra_l2if_update_bridge(ifp
, chgflags
);
1987 if (IS_ZEBRA_IF_BOND(ifp
))
1988 zebra_l2if_update_bond(ifp
, true);
1989 if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp
) || was_bridge_slave
)
1990 zebra_l2if_update_bridge_slave(
1991 ifp
, bridge_ifindex
, ns_id
, chgflags
);
1992 else if (IS_ZEBRA_IF_BOND_SLAVE(ifp
) || was_bond_slave
)
1993 zebra_l2if_update_bond_slave(ifp
, bond_ifindex
,
1996 if (tb
[IFLA_PROTO_DOWN
]) {
1999 protodown
= *(uint8_t *)RTA_DATA(
2000 tb
[IFLA_PROTO_DOWN
]);
2001 netlink_proc_dplane_if_protodown(ifp
->info
,
2008 XFREE(MTYPE_TMP
, zif
->desc
);
2010 zif
->desc
= XSTRDUP(MTYPE_TMP
, desc
);
2013 /* Delete interface notification from kernel */
2015 if (IS_ZEBRA_DEBUG_KERNEL
)
2017 "RTM_DELLINK for unknown interface %s(%u)",
2018 name
, ifi
->ifi_index
);
2022 if (IS_ZEBRA_DEBUG_KERNEL
)
2023 zlog_debug("RTM_DELLINK for %s(%u)", name
,
2026 UNSET_FLAG(ifp
->status
, ZEBRA_INTERFACE_VRF_LOOPBACK
);
2028 if (IS_ZEBRA_IF_BOND(ifp
))
2029 zebra_l2if_update_bond(ifp
, false);
2030 if (IS_ZEBRA_IF_BOND_SLAVE(ifp
))
2031 zebra_l2if_update_bond_slave(ifp
, bond_ifindex
, false);
2032 /* Special handling for bridge or VxLAN interfaces. */
2033 if (IS_ZEBRA_IF_BRIDGE(ifp
))
2034 zebra_l2_bridge_del(ifp
);
2035 else if (IS_ZEBRA_IF_VXLAN(ifp
))
2036 zebra_l2_vxlanif_del(ifp
);
2038 if_delete_update(ifp
);
2044 int netlink_protodown(struct interface
*ifp
, bool down
)
2046 struct zebra_ns
*zns
= zebra_ns_lookup(NS_DEFAULT
);
2050 struct ifinfomsg ifa
;
2051 char buf
[NL_PKT_BUF_SIZE
];
2054 memset(&req
, 0, sizeof(req
));
2056 req
.n
.nlmsg_len
= NLMSG_LENGTH(sizeof(struct ifinfomsg
));
2057 req
.n
.nlmsg_flags
= NLM_F_REQUEST
;
2058 req
.n
.nlmsg_type
= RTM_SETLINK
;
2059 req
.n
.nlmsg_pid
= zns
->netlink_cmd
.snl
.nl_pid
;
2061 req
.ifa
.ifi_index
= ifp
->ifindex
;
2063 nl_attr_put(&req
.n
, sizeof(req
), IFLA_PROTO_DOWN
, &down
, sizeof(down
));
2064 nl_attr_put32(&req
.n
, sizeof(req
), IFLA_LINK
, ifp
->ifindex
);
2066 return netlink_talk(netlink_talk_filter
, &req
.n
, &zns
->netlink_cmd
, zns
,
2070 /* Interface information read by netlink. */
2071 void interface_list(struct zebra_ns
*zns
)
2073 interface_lookup_netlink(zns
);
2074 /* We add routes for interface address,
2075 * so we need to get the nexthop info
2076 * from the kernel before we can do that
2078 netlink_nexthop_read(zns
);
2080 interface_addr_lookup_netlink(zns
);
2083 #endif /* GNU_LINUX */