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"
77 #include "zebra/netconf_netlink.h"
79 extern struct zebra_privs_t zserv_privs
;
81 /* Note: on netlink systems, there should be a 1-to-1 mapping between interface
82 names and ifindex values. */
83 static void set_ifindex(struct interface
*ifp
, ifindex_t ifi_index
,
86 struct interface
*oifp
;
88 if (((oifp
= if_lookup_by_index_per_ns(zns
, ifi_index
)) != NULL
)
90 if (ifi_index
== IFINDEX_INTERNAL
)
93 "Netlink is setting interface %s ifindex to reserved internal value %u",
94 ifp
->name
, ifi_index
);
96 if (IS_ZEBRA_DEBUG_KERNEL
)
98 "interface index %d was renamed from %s to %s",
99 ifi_index
, oifp
->name
, ifp
->name
);
103 "interface rename detected on up interface: index %d was renamed from %s to %s, results are uncertain!",
104 ifi_index
, oifp
->name
, ifp
->name
);
105 if_delete_update(oifp
);
108 if_set_index(ifp
, ifi_index
);
111 /* Utility function to parse hardware link-layer address and update ifp */
112 static void netlink_interface_update_hw_addr(struct rtattr
**tb
,
113 struct interface
*ifp
)
117 if (tb
[IFLA_ADDRESS
]) {
120 hw_addr_len
= RTA_PAYLOAD(tb
[IFLA_ADDRESS
]);
122 if (hw_addr_len
> INTERFACE_HWADDR_MAX
)
123 zlog_debug("Hardware address is too large: %d",
126 ifp
->hw_addr_len
= hw_addr_len
;
127 memcpy(ifp
->hw_addr
, RTA_DATA(tb
[IFLA_ADDRESS
]),
130 for (i
= 0; i
< hw_addr_len
; i
++)
131 if (ifp
->hw_addr
[i
] != 0)
134 if (i
== hw_addr_len
)
135 ifp
->hw_addr_len
= 0;
137 ifp
->hw_addr_len
= hw_addr_len
;
142 static enum zebra_link_type
netlink_to_zebra_link_type(unsigned int hwt
)
146 return ZEBRA_LLT_ETHER
;
148 return ZEBRA_LLT_EETHER
;
150 return ZEBRA_LLT_AX25
;
152 return ZEBRA_LLT_PRONET
;
154 return ZEBRA_LLT_IEEE802
;
156 return ZEBRA_LLT_ARCNET
;
157 case ARPHRD_APPLETLK
:
158 return ZEBRA_LLT_APPLETLK
;
160 return ZEBRA_LLT_DLCI
;
162 return ZEBRA_LLT_ATM
;
163 case ARPHRD_METRICOM
:
164 return ZEBRA_LLT_METRICOM
;
165 case ARPHRD_IEEE1394
:
166 return ZEBRA_LLT_IEEE1394
;
168 return ZEBRA_LLT_EUI64
;
169 case ARPHRD_INFINIBAND
:
170 return ZEBRA_LLT_INFINIBAND
;
172 return ZEBRA_LLT_SLIP
;
174 return ZEBRA_LLT_CSLIP
;
176 return ZEBRA_LLT_SLIP6
;
178 return ZEBRA_LLT_CSLIP6
;
180 return ZEBRA_LLT_RSRVD
;
182 return ZEBRA_LLT_ADAPT
;
184 return ZEBRA_LLT_ROSE
;
186 return ZEBRA_LLT_X25
;
188 return ZEBRA_LLT_PPP
;
190 return ZEBRA_LLT_CHDLC
;
192 return ZEBRA_LLT_LAPB
;
194 return ZEBRA_LLT_RAWHDLC
;
196 return ZEBRA_LLT_IPIP
;
198 return ZEBRA_LLT_IPIP6
;
200 return ZEBRA_LLT_FRAD
;
202 return ZEBRA_LLT_SKIP
;
203 case ARPHRD_LOOPBACK
:
204 return ZEBRA_LLT_LOOPBACK
;
205 case ARPHRD_LOCALTLK
:
206 return ZEBRA_LLT_LOCALTLK
;
208 return ZEBRA_LLT_FDDI
;
210 return ZEBRA_LLT_SIT
;
212 return ZEBRA_LLT_IPDDP
;
214 return ZEBRA_LLT_IPGRE
;
216 return ZEBRA_LLT_PIMREG
;
218 return ZEBRA_LLT_HIPPI
;
220 return ZEBRA_LLT_ECONET
;
222 return ZEBRA_LLT_IRDA
;
224 return ZEBRA_LLT_FCPP
;
226 return ZEBRA_LLT_FCAL
;
228 return ZEBRA_LLT_FCPL
;
229 case ARPHRD_FCFABRIC
:
230 return ZEBRA_LLT_FCFABRIC
;
231 case ARPHRD_IEEE802_TR
:
232 return ZEBRA_LLT_IEEE802_TR
;
233 case ARPHRD_IEEE80211
:
234 return ZEBRA_LLT_IEEE80211
;
235 #ifdef ARPHRD_IEEE802154
236 case ARPHRD_IEEE802154
:
237 return ZEBRA_LLT_IEEE802154
;
241 return ZEBRA_LLT_IP6GRE
;
243 #ifdef ARPHRD_IEEE802154_PHY
244 case ARPHRD_IEEE802154_PHY
:
245 return ZEBRA_LLT_IEEE802154_PHY
;
249 return ZEBRA_LLT_UNKNOWN
;
253 static inline void zebra_if_set_ziftype(struct interface
*ifp
,
254 enum zebra_iftype zif_type
,
255 enum zebra_slave_iftype zif_slave_type
)
257 struct zebra_if
*zif
;
259 zif
= (struct zebra_if
*)ifp
->info
;
260 zif
->zif_slave_type
= zif_slave_type
;
262 if (zif
->zif_type
!= zif_type
) {
263 zif
->zif_type
= zif_type
;
264 /* If the if_type has been set to bond initialize ES info
265 * against it. XXX - note that we don't handle the case where
266 * a zif changes from bond to non-bond; it is really
267 * an unexpected/error condition.
269 zebra_evpn_if_init(zif
);
273 static void netlink_determine_zebra_iftype(const char *kind
,
274 enum zebra_iftype
*zif_type
)
276 *zif_type
= ZEBRA_IF_OTHER
;
281 if (strcmp(kind
, "vrf") == 0)
282 *zif_type
= ZEBRA_IF_VRF
;
283 else if (strcmp(kind
, "bridge") == 0)
284 *zif_type
= ZEBRA_IF_BRIDGE
;
285 else if (strcmp(kind
, "vlan") == 0)
286 *zif_type
= ZEBRA_IF_VLAN
;
287 else if (strcmp(kind
, "vxlan") == 0)
288 *zif_type
= ZEBRA_IF_VXLAN
;
289 else if (strcmp(kind
, "macvlan") == 0)
290 *zif_type
= ZEBRA_IF_MACVLAN
;
291 else if (strcmp(kind
, "veth") == 0)
292 *zif_type
= ZEBRA_IF_VETH
;
293 else if (strcmp(kind
, "bond") == 0)
294 *zif_type
= ZEBRA_IF_BOND
;
295 else if (strcmp(kind
, "bond_slave") == 0)
296 *zif_type
= ZEBRA_IF_BOND_SLAVE
;
297 else if (strcmp(kind
, "gre") == 0)
298 *zif_type
= ZEBRA_IF_GRE
;
301 static void netlink_vrf_change(struct nlmsghdr
*h
, struct rtattr
*tb
,
302 uint32_t ns_id
, const char *name
)
304 struct ifinfomsg
*ifi
;
305 struct rtattr
*linkinfo
[IFLA_INFO_MAX
+ 1];
306 struct rtattr
*attr
[IFLA_VRF_MAX
+ 1];
307 struct vrf
*vrf
= NULL
;
308 struct zebra_vrf
*zvrf
;
309 uint32_t nl_table_id
;
313 netlink_parse_rtattr_nested(linkinfo
, IFLA_INFO_MAX
, tb
);
315 if (!linkinfo
[IFLA_INFO_DATA
]) {
316 if (IS_ZEBRA_DEBUG_KERNEL
)
318 "%s: IFLA_INFO_DATA missing from VRF message: %s",
323 netlink_parse_rtattr_nested(attr
, IFLA_VRF_MAX
,
324 linkinfo
[IFLA_INFO_DATA
]);
325 if (!attr
[IFLA_VRF_TABLE
]) {
326 if (IS_ZEBRA_DEBUG_KERNEL
)
328 "%s: IFLA_VRF_TABLE missing from VRF message: %s",
333 nl_table_id
= *(uint32_t *)RTA_DATA(attr
[IFLA_VRF_TABLE
]);
335 if (h
->nlmsg_type
== RTM_NEWLINK
) {
336 if (IS_ZEBRA_DEBUG_KERNEL
)
337 zlog_debug("RTM_NEWLINK for VRF %s(%u) table %u", name
,
338 ifi
->ifi_index
, nl_table_id
);
340 if (!vrf_lookup_by_id((vrf_id_t
)ifi
->ifi_index
)) {
343 exist_id
= vrf_lookup_by_table(nl_table_id
, ns_id
);
344 if (exist_id
!= VRF_DEFAULT
) {
345 vrf
= vrf_lookup_by_id(exist_id
);
348 EC_ZEBRA_VRF_MISCONFIGURED
,
349 "VRF %s id %u table id overlaps existing vrf %s, misconfiguration exiting",
350 name
, ifi
->ifi_index
, vrf
->name
);
355 vrf
= vrf_update((vrf_id_t
)ifi
->ifi_index
, name
);
357 flog_err(EC_LIB_INTERFACE
, "VRF %s id %u not created",
358 name
, ifi
->ifi_index
);
363 * This is the only place that we get the actual kernel table_id
364 * being used. We need it to set the table_id of the routes
365 * we are passing to the kernel.... And to throw some totally
366 * awesome parties. that too.
368 * At this point we *must* have a zvrf because the vrf_create
369 * callback creates one. We *must* set the table id
370 * before the vrf_enable because of( at the very least )
371 * static routes being delayed for installation until
372 * during the vrf_enable callbacks.
374 zvrf
= (struct zebra_vrf
*)vrf
->info
;
375 zvrf
->table_id
= nl_table_id
;
377 /* Enable the created VRF. */
378 if (!vrf_enable(vrf
)) {
379 flog_err(EC_LIB_INTERFACE
,
380 "Failed to enable VRF %s id %u", name
,
385 } else // h->nlmsg_type == RTM_DELLINK
387 if (IS_ZEBRA_DEBUG_KERNEL
)
388 zlog_debug("RTM_DELLINK for VRF %s(%u)", name
,
391 vrf
= vrf_lookup_by_id((vrf_id_t
)ifi
->ifi_index
);
394 flog_warn(EC_ZEBRA_VRF_NOT_FOUND
, "%s: vrf not found",
403 static uint32_t get_iflink_speed(struct interface
*interface
, int *error
)
406 struct ethtool_cmd ecmd
;
409 const char *ifname
= interface
->name
;
413 /* initialize struct */
414 memset(&ifdata
, 0, sizeof(ifdata
));
416 /* set interface name */
417 strlcpy(ifdata
.ifr_name
, ifname
, sizeof(ifdata
.ifr_name
));
419 /* initialize ethtool interface */
420 memset(&ecmd
, 0, sizeof(ecmd
));
421 ecmd
.cmd
= ETHTOOL_GSET
; /* ETHTOOL_GLINK */
422 ifdata
.ifr_data
= (caddr_t
)&ecmd
;
424 /* use ioctl to get IP address of an interface */
425 frr_with_privs(&zserv_privs
) {
426 sd
= vrf_socket(PF_INET
, SOCK_DGRAM
, IPPROTO_IP
,
427 interface
->vrf
->vrf_id
, NULL
);
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
->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
);
975 ifp
= if_get_by_name(name
, vrf_id
, NULL
);
976 set_ifindex(ifp
, ifi
->ifi_index
, zns
); /* add it to ns struct */
978 ifp
->flags
= ifi
->ifi_flags
& 0x0000fffff;
979 ifp
->mtu6
= ifp
->mtu
= *(uint32_t *)RTA_DATA(tb
[IFLA_MTU
]);
981 ifp
->speed
= get_iflink_speed(ifp
, NULL
);
982 ifp
->ptm_status
= ZEBRA_PTM_STATUS_UNKNOWN
;
984 /* Set zebra interface type */
985 zebra_if_set_ziftype(ifp
, zif_type
, zif_slave_type
);
986 if (IS_ZEBRA_IF_VRF(ifp
))
987 SET_FLAG(ifp
->status
, ZEBRA_INTERFACE_VRF_LOOPBACK
);
990 * Just set the @link/lower-device ifindex. During nldump interfaces are
991 * not ordered in any fashion so we may end up getting upper devices
992 * before lower devices. We will setup the real linkage once the dump
995 zif
= (struct zebra_if
*)ifp
->info
;
996 zif
->link_ifindex
= link_ifindex
;
999 XFREE(MTYPE_TMP
, zif
->desc
);
1000 zif
->desc
= XSTRDUP(MTYPE_TMP
, desc
);
1003 /* Hardware type and address. */
1004 ifp
->ll_type
= netlink_to_zebra_link_type(ifi
->ifi_type
);
1006 netlink_interface_update_hw_addr(tb
, ifp
);
1010 /* Extract and save L2 interface information, take additional actions.
1012 netlink_interface_update_l2info(ifp
, linkinfo
[IFLA_INFO_DATA
],
1014 if (IS_ZEBRA_IF_BOND(ifp
))
1015 zebra_l2if_update_bond(ifp
, true);
1016 if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp
))
1017 zebra_l2if_update_bridge_slave(ifp
, bridge_ifindex
, ns_id
,
1018 ZEBRA_BRIDGE_NO_ACTION
);
1019 else if (IS_ZEBRA_IF_BOND_SLAVE(ifp
))
1020 zebra_l2if_update_bond_slave(ifp
, bond_ifindex
, !!bypass
);
1022 if (tb
[IFLA_PROTO_DOWN
]) {
1025 protodown
= *(uint8_t *)RTA_DATA(tb
[IFLA_PROTO_DOWN
]);
1026 netlink_proc_dplane_if_protodown(zif
, !!protodown
);
1032 /* Request for specific interface or address information from the kernel */
1033 static int netlink_request_intf_addr(struct nlsock
*netlink_cmd
, int family
,
1034 int type
, uint32_t filter_mask
)
1038 struct ifinfomsg ifm
;
1042 /* Form the request, specifying filter (rtattr) if needed. */
1043 memset(&req
, 0, sizeof(req
));
1044 req
.n
.nlmsg_type
= type
;
1045 req
.n
.nlmsg_flags
= NLM_F_ROOT
| NLM_F_MATCH
| NLM_F_REQUEST
;
1046 req
.n
.nlmsg_len
= NLMSG_LENGTH(sizeof(struct ifinfomsg
));
1047 req
.ifm
.ifi_family
= family
;
1049 /* Include filter, if specified. */
1051 nl_attr_put32(&req
.n
, sizeof(req
), IFLA_EXT_MASK
, filter_mask
);
1053 return netlink_request(netlink_cmd
, &req
);
1056 enum netlink_msg_status
1057 netlink_put_gre_set_msg(struct nl_batch
*bth
, struct zebra_dplane_ctx
*ctx
)
1059 enum dplane_op_e op
;
1060 enum netlink_msg_status ret
;
1062 op
= dplane_ctx_get_op(ctx
);
1063 assert(op
== DPLANE_OP_GRE_SET
);
1065 ret
= netlink_batch_add_msg(bth
, ctx
, netlink_gre_set_msg_encoder
, false);
1070 /* Interface lookup by netlink socket. */
1071 int interface_lookup_netlink(struct zebra_ns
*zns
)
1074 struct zebra_dplane_info dp_info
;
1075 struct nlsock
*netlink_cmd
= &zns
->netlink_cmd
;
1077 /* Capture key info from ns struct */
1078 zebra_dplane_info_from_zns(&dp_info
, zns
, true /*is_cmd*/);
1080 /* Get interface information. */
1081 ret
= netlink_request_intf_addr(netlink_cmd
, AF_PACKET
, RTM_GETLINK
, 0);
1084 ret
= netlink_parse_info(netlink_interface
, netlink_cmd
, &dp_info
, 0,
1089 /* Get interface information - for bridge interfaces. */
1090 ret
= netlink_request_intf_addr(netlink_cmd
, AF_BRIDGE
, RTM_GETLINK
,
1091 RTEXT_FILTER_BRVLAN
);
1094 ret
= netlink_parse_info(netlink_interface
, netlink_cmd
, &dp_info
, 0,
1099 /* fixup linkages */
1100 zebra_if_update_all_links(zns
);
1105 * interface_addr_lookup_netlink() - Look up interface addresses
1107 * @zns: Zebra netlink socket
1108 * Return: Result status
1110 static int interface_addr_lookup_netlink(struct zebra_ns
*zns
)
1113 struct zebra_dplane_info dp_info
;
1114 struct nlsock
*netlink_cmd
= &zns
->netlink_cmd
;
1116 /* Capture key info from ns struct */
1117 zebra_dplane_info_from_zns(&dp_info
, zns
, true /*is_cmd*/);
1119 /* Get IPv4 address of the interfaces. */
1120 ret
= netlink_request_intf_addr(netlink_cmd
, AF_INET
, RTM_GETADDR
, 0);
1123 ret
= netlink_parse_info(netlink_interface_addr
, netlink_cmd
, &dp_info
,
1128 /* Get IPv6 address of the interfaces. */
1129 ret
= netlink_request_intf_addr(netlink_cmd
, AF_INET6
, RTM_GETADDR
, 0);
1132 ret
= netlink_parse_info(netlink_interface_addr
, netlink_cmd
, &dp_info
,
1140 int kernel_interface_set_master(struct interface
*master
,
1141 struct interface
*slave
)
1143 struct zebra_ns
*zns
= zebra_ns_lookup(NS_DEFAULT
);
1147 struct ifinfomsg ifa
;
1148 char buf
[NL_PKT_BUF_SIZE
];
1151 memset(&req
, 0, sizeof(req
));
1153 req
.n
.nlmsg_len
= NLMSG_LENGTH(sizeof(struct ifinfomsg
));
1154 req
.n
.nlmsg_flags
= NLM_F_REQUEST
;
1155 req
.n
.nlmsg_type
= RTM_SETLINK
;
1156 req
.n
.nlmsg_pid
= zns
->netlink_cmd
.snl
.nl_pid
;
1158 req
.ifa
.ifi_index
= slave
->ifindex
;
1160 nl_attr_put32(&req
.n
, sizeof(req
), IFLA_MASTER
, master
->ifindex
);
1161 nl_attr_put32(&req
.n
, sizeof(req
), IFLA_LINK
, slave
->ifindex
);
1163 return netlink_talk(netlink_talk_filter
, &req
.n
, &zns
->netlink_cmd
, zns
,
1167 /* Interface address modification. */
1168 static ssize_t
netlink_address_msg_encoder(struct zebra_dplane_ctx
*ctx
,
1169 void *buf
, size_t buflen
)
1172 const struct prefix
*p
;
1178 struct ifaddrmsg ifa
;
1182 if (buflen
< sizeof(*req
))
1185 p
= dplane_ctx_get_intf_addr(ctx
);
1186 memset(req
, 0, sizeof(*req
));
1188 bytelen
= (p
->family
== AF_INET
? 4 : 16);
1190 req
->n
.nlmsg_len
= NLMSG_LENGTH(sizeof(struct ifaddrmsg
));
1191 req
->n
.nlmsg_flags
= NLM_F_REQUEST
;
1193 if (dplane_ctx_get_op(ctx
) == DPLANE_OP_ADDR_INSTALL
)
1198 req
->n
.nlmsg_type
= cmd
;
1199 req
->ifa
.ifa_family
= p
->family
;
1201 req
->ifa
.ifa_index
= dplane_ctx_get_ifindex(ctx
);
1203 if (!nl_attr_put(&req
->n
, buflen
, IFA_LOCAL
, &p
->u
.prefix
, bytelen
))
1206 if (p
->family
== AF_INET
) {
1207 if (dplane_ctx_intf_is_connected(ctx
)) {
1208 p
= dplane_ctx_get_intf_dest(ctx
);
1209 if (!nl_attr_put(&req
->n
, buflen
, IFA_ADDRESS
,
1210 &p
->u
.prefix
, bytelen
))
1212 } else if (cmd
== RTM_NEWADDR
) {
1213 struct in_addr broad
= {
1214 .s_addr
= ipv4_broadcast_addr(p
->u
.prefix4
.s_addr
,
1217 if (!nl_attr_put(&req
->n
, buflen
, IFA_BROADCAST
, &broad
,
1223 /* p is now either address or destination/bcast addr */
1224 req
->ifa
.ifa_prefixlen
= p
->prefixlen
;
1226 if (dplane_ctx_intf_is_secondary(ctx
))
1227 SET_FLAG(req
->ifa
.ifa_flags
, IFA_F_SECONDARY
);
1229 if (dplane_ctx_intf_has_label(ctx
)) {
1230 label
= dplane_ctx_get_intf_label(ctx
);
1231 if (!nl_attr_put(&req
->n
, buflen
, IFA_LABEL
, label
,
1236 return NLMSG_ALIGN(req
->n
.nlmsg_len
);
1239 enum netlink_msg_status
1240 netlink_put_address_update_msg(struct nl_batch
*bth
,
1241 struct zebra_dplane_ctx
*ctx
)
1243 return netlink_batch_add_msg(bth
, ctx
, netlink_address_msg_encoder
,
1247 int netlink_interface_addr(struct nlmsghdr
*h
, ns_id_t ns_id
, int startup
)
1250 struct ifaddrmsg
*ifa
;
1251 struct rtattr
*tb
[IFA_MAX
+ 1];
1252 struct interface
*ifp
;
1257 struct zebra_ns
*zns
;
1258 uint32_t metric
= METRIC_MAX
;
1259 uint32_t kernel_flags
= 0;
1261 zns
= zebra_ns_lookup(ns_id
);
1262 ifa
= NLMSG_DATA(h
);
1264 if (ifa
->ifa_family
!= AF_INET
&& ifa
->ifa_family
!= AF_INET6
) {
1266 EC_ZEBRA_UNKNOWN_FAMILY
,
1267 "Invalid address family: %u received from kernel interface addr change: %s",
1268 ifa
->ifa_family
, nl_msg_type_to_str(h
->nlmsg_type
));
1272 if (h
->nlmsg_type
!= RTM_NEWADDR
&& h
->nlmsg_type
!= RTM_DELADDR
)
1275 len
= h
->nlmsg_len
- NLMSG_LENGTH(sizeof(struct ifaddrmsg
));
1278 "%s: Message received from netlink is of a broken size: %d %zu",
1279 __func__
, h
->nlmsg_len
,
1280 (size_t)NLMSG_LENGTH(sizeof(struct ifaddrmsg
)));
1284 netlink_parse_rtattr(tb
, IFA_MAX
, IFA_RTA(ifa
), len
);
1286 ifp
= if_lookup_by_index_per_ns(zns
, ifa
->ifa_index
);
1289 /* During startup, failure to lookup the referenced
1290 * interface should not be an error, so we have
1291 * downgraded this condition to warning, and we permit
1292 * the startup interface state retrieval to continue.
1294 flog_warn(EC_LIB_INTERFACE
,
1295 "%s: can't find interface by index %d",
1296 __func__
, ifa
->ifa_index
);
1299 flog_err(EC_LIB_INTERFACE
,
1300 "%s: can't find interface by index %d",
1301 __func__
, ifa
->ifa_index
);
1306 /* Flags passed through */
1308 kernel_flags
= *(int *)RTA_DATA(tb
[IFA_FLAGS
]);
1310 kernel_flags
= ifa
->ifa_flags
;
1312 if (IS_ZEBRA_DEBUG_KERNEL
) /* remove this line to see initial ifcfg */
1315 zlog_debug("netlink_interface_addr %s %s flags 0x%x:",
1316 nl_msg_type_to_str(h
->nlmsg_type
), ifp
->name
,
1319 zlog_debug(" IFA_LOCAL %s/%d",
1320 inet_ntop(ifa
->ifa_family
,
1321 RTA_DATA(tb
[IFA_LOCAL
]), buf
,
1323 ifa
->ifa_prefixlen
);
1324 if (tb
[IFA_ADDRESS
])
1325 zlog_debug(" IFA_ADDRESS %s/%d",
1326 inet_ntop(ifa
->ifa_family
,
1327 RTA_DATA(tb
[IFA_ADDRESS
]), buf
,
1329 ifa
->ifa_prefixlen
);
1330 if (tb
[IFA_BROADCAST
])
1331 zlog_debug(" IFA_BROADCAST %s/%d",
1332 inet_ntop(ifa
->ifa_family
,
1333 RTA_DATA(tb
[IFA_BROADCAST
]), buf
,
1335 ifa
->ifa_prefixlen
);
1336 if (tb
[IFA_LABEL
] && strcmp(ifp
->name
, RTA_DATA(tb
[IFA_LABEL
])))
1337 zlog_debug(" IFA_LABEL %s",
1338 (char *)RTA_DATA(tb
[IFA_LABEL
]));
1340 if (tb
[IFA_CACHEINFO
]) {
1341 struct ifa_cacheinfo
*ci
= RTA_DATA(tb
[IFA_CACHEINFO
]);
1342 zlog_debug(" IFA_CACHEINFO pref %d, valid %d",
1343 ci
->ifa_prefered
, ci
->ifa_valid
);
1347 /* logic copied from iproute2/ip/ipaddress.c:print_addrinfo() */
1348 if (tb
[IFA_LOCAL
] == NULL
)
1349 tb
[IFA_LOCAL
] = tb
[IFA_ADDRESS
];
1350 if (tb
[IFA_ADDRESS
] == NULL
)
1351 tb
[IFA_ADDRESS
] = tb
[IFA_LOCAL
];
1353 /* local interface address */
1354 addr
= (tb
[IFA_LOCAL
] ? RTA_DATA(tb
[IFA_LOCAL
]) : NULL
);
1356 /* is there a peer address? */
1358 && memcmp(RTA_DATA(tb
[IFA_ADDRESS
]), RTA_DATA(tb
[IFA_LOCAL
]),
1359 RTA_PAYLOAD(tb
[IFA_ADDRESS
]))) {
1360 broad
= RTA_DATA(tb
[IFA_ADDRESS
]);
1361 SET_FLAG(flags
, ZEBRA_IFA_PEER
);
1363 /* seeking a broadcast address */
1364 broad
= (tb
[IFA_BROADCAST
] ? RTA_DATA(tb
[IFA_BROADCAST
])
1367 /* addr is primary key, SOL if we don't have one */
1369 zlog_debug("%s: Local Interface Address is NULL for %s",
1370 __func__
, ifp
->name
);
1375 if (kernel_flags
& IFA_F_SECONDARY
)
1376 SET_FLAG(flags
, ZEBRA_IFA_SECONDARY
);
1380 label
= (char *)RTA_DATA(tb
[IFA_LABEL
]);
1382 if (label
&& strcmp(ifp
->name
, label
) == 0)
1385 if (tb
[IFA_RT_PRIORITY
])
1386 metric
= *(uint32_t *)RTA_DATA(tb
[IFA_RT_PRIORITY
]);
1388 /* Register interface address to the interface. */
1389 if (ifa
->ifa_family
== AF_INET
) {
1390 if (ifa
->ifa_prefixlen
> IPV4_MAX_BITLEN
) {
1392 "Invalid prefix length: %u received from kernel interface addr change: %s",
1394 nl_msg_type_to_str(h
->nlmsg_type
));
1398 if (h
->nlmsg_type
== RTM_NEWADDR
)
1399 connected_add_ipv4(ifp
, flags
, (struct in_addr
*)addr
,
1401 (struct in_addr
*)broad
, label
,
1403 else if (CHECK_FLAG(flags
, ZEBRA_IFA_PEER
)) {
1404 /* Delete with a peer address */
1405 connected_delete_ipv4(
1406 ifp
, flags
, (struct in_addr
*)addr
,
1407 ifa
->ifa_prefixlen
, broad
);
1409 connected_delete_ipv4(
1410 ifp
, flags
, (struct in_addr
*)addr
,
1411 ifa
->ifa_prefixlen
, NULL
);
1414 if (ifa
->ifa_family
== AF_INET6
) {
1415 if (ifa
->ifa_prefixlen
> IPV6_MAX_BITLEN
) {
1417 "Invalid prefix length: %u received from kernel interface addr change: %s",
1419 nl_msg_type_to_str(h
->nlmsg_type
));
1422 if (h
->nlmsg_type
== RTM_NEWADDR
) {
1423 /* Only consider valid addresses; we'll not get a
1425 * the kernel till IPv6 DAD has completed, but at init
1427 * does query for and will receive all addresses.
1430 & (IFA_F_DADFAILED
| IFA_F_TENTATIVE
)))
1431 connected_add_ipv6(ifp
, flags
,
1432 (struct in6_addr
*)addr
,
1433 (struct in6_addr
*)broad
,
1434 ifa
->ifa_prefixlen
, label
,
1437 connected_delete_ipv6(ifp
, (struct in6_addr
*)addr
,
1438 NULL
, ifa
->ifa_prefixlen
);
1442 * Linux kernel does not send route delete on interface down/addr del
1443 * so we have to re-process routes it owns (i.e. kernel routes)
1445 if (h
->nlmsg_type
!= RTM_NEWADDR
)
1446 rib_update(RIB_UPDATE_KERNEL
);
1452 * Parse and validate an incoming interface address change message,
1453 * generating a dplane context object.
1454 * This runs in the dplane pthread; the context is enqueued to the
1455 * main pthread for processing.
1457 int netlink_interface_addr_dplane(struct nlmsghdr
*h
, ns_id_t ns_id
,
1458 int startup
/*ignored*/)
1461 struct ifaddrmsg
*ifa
;
1462 struct rtattr
*tb
[IFA_MAX
+ 1];
1466 uint32_t metric
= METRIC_MAX
;
1467 uint32_t kernel_flags
= 0;
1468 struct zebra_dplane_ctx
*ctx
;
1471 ifa
= NLMSG_DATA(h
);
1473 /* Validate message types */
1474 if (h
->nlmsg_type
!= RTM_NEWADDR
&& h
->nlmsg_type
!= RTM_DELADDR
)
1477 if (ifa
->ifa_family
!= AF_INET
&& ifa
->ifa_family
!= AF_INET6
) {
1478 if (IS_ZEBRA_DEBUG_KERNEL
)
1479 zlog_debug("%s: %s: Invalid address family: %u",
1480 __func__
, nl_msg_type_to_str(h
->nlmsg_type
),
1485 len
= h
->nlmsg_len
- NLMSG_LENGTH(sizeof(struct ifaddrmsg
));
1487 if (IS_ZEBRA_DEBUG_KERNEL
)
1488 zlog_debug("%s: %s: netlink msg bad size: %d %zu",
1489 __func__
, nl_msg_type_to_str(h
->nlmsg_type
),
1491 (size_t)NLMSG_LENGTH(
1492 sizeof(struct ifaddrmsg
)));
1496 netlink_parse_rtattr(tb
, IFA_MAX
, IFA_RTA(ifa
), len
);
1498 /* Flags passed through */
1500 kernel_flags
= *(int *)RTA_DATA(tb
[IFA_FLAGS
]);
1502 kernel_flags
= ifa
->ifa_flags
;
1504 if (IS_ZEBRA_DEBUG_KERNEL
) { /* remove this line to see initial ifcfg */
1505 char buf
[PREFIX_STRLEN
];
1507 zlog_debug("%s: %s nsid %u ifindex %u flags 0x%x:", __func__
,
1508 nl_msg_type_to_str(h
->nlmsg_type
), ns_id
,
1509 ifa
->ifa_index
, kernel_flags
);
1511 zlog_debug(" IFA_LOCAL %s/%d",
1512 inet_ntop(ifa
->ifa_family
,
1513 RTA_DATA(tb
[IFA_LOCAL
]), buf
,
1515 ifa
->ifa_prefixlen
);
1516 if (tb
[IFA_ADDRESS
])
1517 zlog_debug(" IFA_ADDRESS %s/%d",
1518 inet_ntop(ifa
->ifa_family
,
1519 RTA_DATA(tb
[IFA_ADDRESS
]), buf
,
1521 ifa
->ifa_prefixlen
);
1522 if (tb
[IFA_BROADCAST
])
1523 zlog_debug(" IFA_BROADCAST %s/%d",
1524 inet_ntop(ifa
->ifa_family
,
1525 RTA_DATA(tb
[IFA_BROADCAST
]), buf
,
1527 ifa
->ifa_prefixlen
);
1529 zlog_debug(" IFA_LABEL %s",
1530 (const char *)RTA_DATA(tb
[IFA_LABEL
]));
1532 if (tb
[IFA_CACHEINFO
]) {
1533 struct ifa_cacheinfo
*ci
= RTA_DATA(tb
[IFA_CACHEINFO
]);
1535 zlog_debug(" IFA_CACHEINFO pref %d, valid %d",
1536 ci
->ifa_prefered
, ci
->ifa_valid
);
1540 /* Validate prefix length */
1542 if (ifa
->ifa_family
== AF_INET
1543 && ifa
->ifa_prefixlen
> IPV4_MAX_BITLEN
) {
1544 if (IS_ZEBRA_DEBUG_KERNEL
)
1545 zlog_debug("%s: %s: Invalid prefix length: %u",
1546 __func__
, nl_msg_type_to_str(h
->nlmsg_type
),
1547 ifa
->ifa_prefixlen
);
1551 if (ifa
->ifa_family
== AF_INET6
) {
1552 if (ifa
->ifa_prefixlen
> IPV6_MAX_BITLEN
) {
1553 if (IS_ZEBRA_DEBUG_KERNEL
)
1554 zlog_debug("%s: %s: Invalid prefix length: %u",
1556 nl_msg_type_to_str(h
->nlmsg_type
),
1557 ifa
->ifa_prefixlen
);
1561 /* Only consider valid addresses; we'll not get a kernel
1562 * notification till IPv6 DAD has completed, but at init
1563 * time, FRR does query for and will receive all addresses.
1565 if (h
->nlmsg_type
== RTM_NEWADDR
1566 && (kernel_flags
& (IFA_F_DADFAILED
| IFA_F_TENTATIVE
))) {
1567 if (IS_ZEBRA_DEBUG_KERNEL
)
1568 zlog_debug("%s: %s: Invalid/tentative addr",
1570 nl_msg_type_to_str(h
->nlmsg_type
));
1575 /* logic copied from iproute2/ip/ipaddress.c:print_addrinfo() */
1576 if (tb
[IFA_LOCAL
] == NULL
)
1577 tb
[IFA_LOCAL
] = tb
[IFA_ADDRESS
];
1578 if (tb
[IFA_ADDRESS
] == NULL
)
1579 tb
[IFA_ADDRESS
] = tb
[IFA_LOCAL
];
1581 /* local interface address */
1582 addr
= (tb
[IFA_LOCAL
] ? RTA_DATA(tb
[IFA_LOCAL
]) : NULL
);
1584 /* addr is primary key, SOL if we don't have one */
1586 if (IS_ZEBRA_DEBUG_KERNEL
)
1587 zlog_debug("%s: %s: No local interface address",
1588 __func__
, nl_msg_type_to_str(h
->nlmsg_type
));
1592 /* Allocate a context object, now that validation is done. */
1593 ctx
= dplane_ctx_alloc();
1594 if (h
->nlmsg_type
== RTM_NEWADDR
)
1595 dplane_ctx_set_op(ctx
, DPLANE_OP_INTF_ADDR_ADD
);
1597 dplane_ctx_set_op(ctx
, DPLANE_OP_INTF_ADDR_DEL
);
1599 dplane_ctx_set_ifindex(ctx
, ifa
->ifa_index
);
1600 dplane_ctx_set_ns_id(ctx
, ns_id
);
1602 /* Convert addr to prefix */
1603 memset(&p
, 0, sizeof(p
));
1604 p
.family
= ifa
->ifa_family
;
1605 p
.prefixlen
= ifa
->ifa_prefixlen
;
1606 if (p
.family
== AF_INET
)
1607 p
.u
.prefix4
= *(struct in_addr
*)addr
;
1609 p
.u
.prefix6
= *(struct in6_addr
*)addr
;
1611 dplane_ctx_set_intf_addr(ctx
, &p
);
1613 /* is there a peer address? */
1615 && memcmp(RTA_DATA(tb
[IFA_ADDRESS
]), RTA_DATA(tb
[IFA_LOCAL
]),
1616 RTA_PAYLOAD(tb
[IFA_ADDRESS
]))) {
1617 broad
= RTA_DATA(tb
[IFA_ADDRESS
]);
1618 dplane_ctx_intf_set_connected(ctx
);
1619 } else if (tb
[IFA_BROADCAST
]) {
1620 /* seeking a broadcast address */
1621 broad
= RTA_DATA(tb
[IFA_BROADCAST
]);
1622 dplane_ctx_intf_set_broadcast(ctx
);
1627 /* Convert addr to prefix */
1628 memset(&p
, 0, sizeof(p
));
1629 p
.family
= ifa
->ifa_family
;
1630 p
.prefixlen
= ifa
->ifa_prefixlen
;
1631 if (p
.family
== AF_INET
)
1632 p
.u
.prefix4
= *(struct in_addr
*)broad
;
1634 p
.u
.prefix6
= *(struct in6_addr
*)broad
;
1636 dplane_ctx_set_intf_dest(ctx
, &p
);
1640 if (kernel_flags
& IFA_F_SECONDARY
)
1641 dplane_ctx_intf_set_secondary(ctx
);
1644 if (tb
[IFA_LABEL
]) {
1645 label
= (char *)RTA_DATA(tb
[IFA_LABEL
]);
1646 dplane_ctx_set_intf_label(ctx
, label
);
1649 if (tb
[IFA_RT_PRIORITY
])
1650 metric
= *(uint32_t *)RTA_DATA(tb
[IFA_RT_PRIORITY
]);
1652 dplane_ctx_set_intf_metric(ctx
, metric
);
1654 /* Enqueue ctx for main pthread to process */
1655 dplane_provider_enqueue_to_zebra(ctx
);
1660 int netlink_link_change(struct nlmsghdr
*h
, ns_id_t ns_id
, int startup
)
1663 struct ifinfomsg
*ifi
;
1664 struct rtattr
*tb
[IFLA_MAX
+ 1];
1665 struct rtattr
*linkinfo
[IFLA_MAX
+ 1];
1666 struct interface
*ifp
;
1670 char *slave_kind
= NULL
;
1671 struct zebra_ns
*zns
;
1672 vrf_id_t vrf_id
= VRF_DEFAULT
;
1673 enum zebra_iftype zif_type
= ZEBRA_IF_OTHER
;
1674 enum zebra_slave_iftype zif_slave_type
= ZEBRA_IF_SLAVE_NONE
;
1675 ifindex_t bridge_ifindex
= IFINDEX_INTERNAL
;
1676 ifindex_t bond_ifindex
= IFINDEX_INTERNAL
;
1677 ifindex_t link_ifindex
= IFINDEX_INTERNAL
;
1678 uint8_t old_hw_addr
[INTERFACE_HWADDR_MAX
];
1679 struct zebra_if
*zif
;
1680 ns_id_t link_nsid
= ns_id
;
1681 ifindex_t master_infindex
= IFINDEX_INTERNAL
;
1684 zns
= zebra_ns_lookup(ns_id
);
1685 ifi
= NLMSG_DATA(h
);
1687 /* assume if not default zns, then new VRF */
1688 if (!(h
->nlmsg_type
== RTM_NEWLINK
|| h
->nlmsg_type
== RTM_DELLINK
)) {
1689 /* If this is not link add/delete message so print warning. */
1690 zlog_debug("netlink_link_change: wrong kernel message %s",
1691 nl_msg_type_to_str(h
->nlmsg_type
));
1695 if (!(ifi
->ifi_family
== AF_UNSPEC
|| ifi
->ifi_family
== AF_BRIDGE
1696 || ifi
->ifi_family
== AF_INET6
)) {
1698 EC_ZEBRA_UNKNOWN_FAMILY
,
1699 "Invalid address family: %u received from kernel link change: %s",
1700 ifi
->ifi_family
, nl_msg_type_to_str(h
->nlmsg_type
));
1704 len
= h
->nlmsg_len
- NLMSG_LENGTH(sizeof(struct ifinfomsg
));
1707 "%s: Message received from netlink is of a broken size %d %zu",
1708 __func__
, h
->nlmsg_len
,
1709 (size_t)NLMSG_LENGTH(sizeof(struct ifinfomsg
)));
1713 /* We are interested in some AF_BRIDGE notifications. */
1714 if (ifi
->ifi_family
== AF_BRIDGE
)
1715 return netlink_bridge_interface(h
, len
, ns_id
, startup
);
1717 /* Looking up interface name. */
1718 memset(linkinfo
, 0, sizeof(linkinfo
));
1719 netlink_parse_rtattr(tb
, IFLA_MAX
, IFLA_RTA(ifi
), len
);
1721 /* check for wireless messages to ignore */
1722 if ((tb
[IFLA_WIRELESS
] != NULL
) && (ifi
->ifi_change
== 0)) {
1723 if (IS_ZEBRA_DEBUG_KERNEL
)
1724 zlog_debug("%s: ignoring IFLA_WIRELESS message",
1729 if (tb
[IFLA_IFNAME
] == NULL
)
1731 name
= (char *)RTA_DATA(tb
[IFLA_IFNAME
]);
1733 /* Must be valid string. */
1734 len
= RTA_PAYLOAD(tb
[IFLA_IFNAME
]);
1735 if (len
< 2 || name
[len
- 1] != '\0') {
1736 if (IS_ZEBRA_DEBUG_KERNEL
)
1737 zlog_debug("%s: invalid intf name", __func__
);
1741 if (tb
[IFLA_LINKINFO
]) {
1742 netlink_parse_rtattr_nested(linkinfo
, IFLA_INFO_MAX
,
1745 if (linkinfo
[IFLA_INFO_KIND
])
1746 kind
= RTA_DATA(linkinfo
[IFLA_INFO_KIND
]);
1748 if (linkinfo
[IFLA_INFO_SLAVE_KIND
])
1749 slave_kind
= RTA_DATA(linkinfo
[IFLA_INFO_SLAVE_KIND
]);
1751 netlink_determine_zebra_iftype(kind
, &zif_type
);
1754 /* If linking to another interface, note it. */
1756 link_ifindex
= *(ifindex_t
*)RTA_DATA(tb
[IFLA_LINK
]);
1758 if (tb
[IFLA_LINK_NETNSID
]) {
1759 link_nsid
= *(ns_id_t
*)RTA_DATA(tb
[IFLA_LINK_NETNSID
]);
1760 link_nsid
= ns_id_get_absolute(ns_id
, link_nsid
);
1762 if (tb
[IFLA_IFALIAS
]) {
1763 desc
= (char *)RTA_DATA(tb
[IFLA_IFALIAS
]);
1766 /* See if interface is present. */
1767 ifp
= if_lookup_by_name_per_ns(zns
, name
);
1769 if (h
->nlmsg_type
== RTM_NEWLINK
) {
1770 /* If VRF, create or update the VRF structure itself. */
1771 if (zif_type
== ZEBRA_IF_VRF
&& !vrf_is_backend_netns()) {
1772 netlink_vrf_change(h
, tb
[IFLA_LINKINFO
], ns_id
, name
);
1773 vrf_id
= (vrf_id_t
)ifi
->ifi_index
;
1776 if (tb
[IFLA_MASTER
]) {
1777 if (slave_kind
&& (strcmp(slave_kind
, "vrf") == 0)
1778 && !vrf_is_backend_netns()) {
1779 zif_slave_type
= ZEBRA_IF_SLAVE_VRF
;
1780 master_infindex
= vrf_id
=
1781 *(uint32_t *)RTA_DATA(tb
[IFLA_MASTER
]);
1782 } else if (slave_kind
1783 && (strcmp(slave_kind
, "bridge") == 0)) {
1784 zif_slave_type
= ZEBRA_IF_SLAVE_BRIDGE
;
1785 master_infindex
= bridge_ifindex
=
1786 *(ifindex_t
*)RTA_DATA(tb
[IFLA_MASTER
]);
1787 } else if (slave_kind
1788 && (strcmp(slave_kind
, "bond") == 0)) {
1789 zif_slave_type
= ZEBRA_IF_SLAVE_BOND
;
1790 master_infindex
= bond_ifindex
=
1791 *(ifindex_t
*)RTA_DATA(tb
[IFLA_MASTER
]);
1792 bypass
= netlink_parse_lacp_bypass(linkinfo
);
1794 zif_slave_type
= ZEBRA_IF_SLAVE_OTHER
;
1796 if (vrf_is_backend_netns())
1797 vrf_id
= (vrf_id_t
)ns_id
;
1799 || !CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
1800 /* Add interface notification from kernel */
1801 if (IS_ZEBRA_DEBUG_KERNEL
)
1803 "RTM_NEWLINK ADD for %s(%u) vrf_id %u type %d sl_type %d master %u flags 0x%x",
1804 name
, ifi
->ifi_index
, vrf_id
, zif_type
,
1805 zif_slave_type
, master_infindex
,
1809 /* unknown interface */
1810 ifp
= if_get_by_name(name
, vrf_id
, NULL
);
1812 /* pre-configured interface, learnt now */
1813 if (ifp
->vrf
->vrf_id
!= vrf_id
)
1814 if_update_to_new_vrf(ifp
, vrf_id
);
1817 /* Update interface information. */
1818 set_ifindex(ifp
, ifi
->ifi_index
, zns
);
1819 ifp
->flags
= ifi
->ifi_flags
& 0x0000fffff;
1820 if (!tb
[IFLA_MTU
]) {
1822 "RTM_NEWLINK for interface %s(%u) without MTU set",
1823 name
, ifi
->ifi_index
);
1826 ifp
->mtu6
= ifp
->mtu
= *(int *)RTA_DATA(tb
[IFLA_MTU
]);
1828 ifp
->ptm_status
= ZEBRA_PTM_STATUS_UNKNOWN
;
1830 /* Set interface type */
1831 zebra_if_set_ziftype(ifp
, zif_type
, zif_slave_type
);
1832 if (IS_ZEBRA_IF_VRF(ifp
))
1833 SET_FLAG(ifp
->status
,
1834 ZEBRA_INTERFACE_VRF_LOOPBACK
);
1837 zebra_if_update_link(ifp
, link_ifindex
, ns_id
);
1840 netlink_to_zebra_link_type(ifi
->ifi_type
);
1841 netlink_interface_update_hw_addr(tb
, ifp
);
1843 /* Inform clients, install any configured addresses. */
1846 /* Extract and save L2 interface information, take
1847 * additional actions. */
1848 netlink_interface_update_l2info(
1849 ifp
, linkinfo
[IFLA_INFO_DATA
],
1851 if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp
))
1852 zebra_l2if_update_bridge_slave(
1853 ifp
, bridge_ifindex
, ns_id
,
1854 ZEBRA_BRIDGE_NO_ACTION
);
1855 else if (IS_ZEBRA_IF_BOND_SLAVE(ifp
))
1856 zebra_l2if_update_bond_slave(ifp
, bond_ifindex
,
1859 if (tb
[IFLA_PROTO_DOWN
]) {
1862 protodown
= *(uint8_t *)RTA_DATA(
1863 tb
[IFLA_PROTO_DOWN
]);
1864 netlink_proc_dplane_if_protodown(ifp
->info
,
1867 } else if (ifp
->vrf
->vrf_id
!= vrf_id
) {
1868 /* VRF change for an interface. */
1869 if (IS_ZEBRA_DEBUG_KERNEL
)
1871 "RTM_NEWLINK vrf-change for %s(%u) vrf_id %u -> %u flags 0x%x",
1872 name
, ifp
->ifindex
, ifp
->vrf
->vrf_id
,
1873 vrf_id
, ifi
->ifi_flags
);
1875 if_handle_vrf_change(ifp
, vrf_id
);
1877 bool was_bridge_slave
, was_bond_slave
;
1878 uint8_t chgflags
= ZEBRA_BRIDGE_NO_ACTION
;
1881 /* Interface update. */
1882 if (IS_ZEBRA_DEBUG_KERNEL
)
1884 "RTM_NEWLINK update for %s(%u) sl_type %d master %u flags 0x%x",
1885 name
, ifp
->ifindex
, zif_slave_type
,
1886 master_infindex
, ifi
->ifi_flags
);
1888 set_ifindex(ifp
, ifi
->ifi_index
, zns
);
1889 if (!tb
[IFLA_MTU
]) {
1891 "RTM_NEWLINK for interface %s(%u) without MTU set",
1892 name
, ifi
->ifi_index
);
1895 ifp
->mtu6
= ifp
->mtu
= *(int *)RTA_DATA(tb
[IFLA_MTU
]);
1898 /* Update interface type - NOTE: Only slave_type can
1900 was_bridge_slave
= IS_ZEBRA_IF_BRIDGE_SLAVE(ifp
);
1901 was_bond_slave
= IS_ZEBRA_IF_BOND_SLAVE(ifp
);
1902 zebra_if_set_ziftype(ifp
, zif_type
, zif_slave_type
);
1904 memcpy(old_hw_addr
, ifp
->hw_addr
, INTERFACE_HWADDR_MAX
);
1907 zebra_if_update_link(ifp
, link_ifindex
, ns_id
);
1910 netlink_to_zebra_link_type(ifi
->ifi_type
);
1911 netlink_interface_update_hw_addr(tb
, ifp
);
1913 if (tb
[IFLA_PROTO_DOWN
]) {
1916 protodown
= *(uint8_t *)RTA_DATA(
1917 tb
[IFLA_PROTO_DOWN
]);
1918 netlink_proc_dplane_if_protodown(zif
,
1922 if (if_is_no_ptm_operative(ifp
)) {
1923 bool is_up
= if_is_operative(ifp
);
1924 ifp
->flags
= ifi
->ifi_flags
& 0x0000fffff;
1925 if (!if_is_no_ptm_operative(ifp
) ||
1926 CHECK_FLAG(zif
->flags
,
1927 ZIF_FLAG_PROTODOWN
)) {
1928 if (IS_ZEBRA_DEBUG_KERNEL
)
1930 "Intf %s(%u) has gone DOWN",
1931 name
, ifp
->ifindex
);
1933 rib_update(RIB_UPDATE_KERNEL
);
1934 } else if (if_is_operative(ifp
)) {
1935 bool mac_updated
= false;
1937 /* Must notify client daemons of new
1938 * interface status. */
1939 if (IS_ZEBRA_DEBUG_KERNEL
)
1941 "Intf %s(%u) PTM up, notifying clients",
1942 name
, ifp
->ifindex
);
1945 /* Update EVPN VNI when SVI MAC change
1947 if (memcmp(old_hw_addr
, ifp
->hw_addr
,
1948 INTERFACE_HWADDR_MAX
))
1950 if (IS_ZEBRA_IF_VLAN(ifp
)
1952 struct interface
*link_if
;
1955 if_lookup_by_index_per_ns(
1956 zebra_ns_lookup(NS_DEFAULT
),
1959 zebra_vxlan_svi_up(ifp
,
1961 } else if (mac_updated
1962 && IS_ZEBRA_IF_BRIDGE(ifp
)) {
1964 "Intf %s(%u) bridge changed MAC address",
1965 name
, ifp
->ifindex
);
1967 ZEBRA_BRIDGE_MASTER_MAC_CHANGE
;
1971 ifp
->flags
= ifi
->ifi_flags
& 0x0000fffff;
1972 if (if_is_operative(ifp
) &&
1973 !CHECK_FLAG(zif
->flags
,
1974 ZIF_FLAG_PROTODOWN
)) {
1975 if (IS_ZEBRA_DEBUG_KERNEL
)
1977 "Intf %s(%u) has come UP",
1978 name
, ifp
->ifindex
);
1980 if (IS_ZEBRA_IF_BRIDGE(ifp
))
1982 ZEBRA_BRIDGE_MASTER_UP
;
1984 if (IS_ZEBRA_DEBUG_KERNEL
)
1986 "Intf %s(%u) has gone DOWN",
1987 name
, ifp
->ifindex
);
1989 rib_update(RIB_UPDATE_KERNEL
);
1993 /* Extract and save L2 interface information, take
1994 * additional actions. */
1995 netlink_interface_update_l2info(
1996 ifp
, linkinfo
[IFLA_INFO_DATA
],
1998 if (IS_ZEBRA_IF_BRIDGE(ifp
))
1999 zebra_l2if_update_bridge(ifp
, chgflags
);
2000 if (IS_ZEBRA_IF_BOND(ifp
))
2001 zebra_l2if_update_bond(ifp
, true);
2002 if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp
) || was_bridge_slave
)
2003 zebra_l2if_update_bridge_slave(
2004 ifp
, bridge_ifindex
, ns_id
, chgflags
);
2005 else if (IS_ZEBRA_IF_BOND_SLAVE(ifp
) || was_bond_slave
)
2006 zebra_l2if_update_bond_slave(ifp
, bond_ifindex
,
2012 XFREE(MTYPE_TMP
, zif
->desc
);
2014 zif
->desc
= XSTRDUP(MTYPE_TMP
, desc
);
2017 /* Delete interface notification from kernel */
2019 if (IS_ZEBRA_DEBUG_KERNEL
)
2021 "RTM_DELLINK for unknown interface %s(%u)",
2022 name
, ifi
->ifi_index
);
2026 if (IS_ZEBRA_DEBUG_KERNEL
)
2027 zlog_debug("RTM_DELLINK for %s(%u)", name
,
2030 UNSET_FLAG(ifp
->status
, ZEBRA_INTERFACE_VRF_LOOPBACK
);
2032 if (IS_ZEBRA_IF_BOND(ifp
))
2033 zebra_l2if_update_bond(ifp
, false);
2034 if (IS_ZEBRA_IF_BOND_SLAVE(ifp
))
2035 zebra_l2if_update_bond_slave(ifp
, bond_ifindex
, false);
2036 /* Special handling for bridge or VxLAN interfaces. */
2037 if (IS_ZEBRA_IF_BRIDGE(ifp
))
2038 zebra_l2_bridge_del(ifp
);
2039 else if (IS_ZEBRA_IF_VXLAN(ifp
))
2040 zebra_l2_vxlanif_del(ifp
);
2042 if_delete_update(ifp
);
2044 /* If VRF, delete the VRF structure itself. */
2045 if (zif_type
== ZEBRA_IF_VRF
&& !vrf_is_backend_netns())
2046 netlink_vrf_change(h
, tb
[IFLA_LINKINFO
], ns_id
, name
);
2052 int netlink_protodown(struct interface
*ifp
, bool down
)
2054 struct zebra_ns
*zns
= zebra_ns_lookup(NS_DEFAULT
);
2058 struct ifinfomsg ifa
;
2059 char buf
[NL_PKT_BUF_SIZE
];
2062 memset(&req
, 0, sizeof(req
));
2064 req
.n
.nlmsg_len
= NLMSG_LENGTH(sizeof(struct ifinfomsg
));
2065 req
.n
.nlmsg_flags
= NLM_F_REQUEST
;
2066 req
.n
.nlmsg_type
= RTM_SETLINK
;
2067 req
.n
.nlmsg_pid
= zns
->netlink_cmd
.snl
.nl_pid
;
2069 req
.ifa
.ifi_index
= ifp
->ifindex
;
2071 nl_attr_put(&req
.n
, sizeof(req
), IFLA_PROTO_DOWN
, &down
, sizeof(down
));
2072 nl_attr_put32(&req
.n
, sizeof(req
), IFLA_LINK
, ifp
->ifindex
);
2074 return netlink_talk(netlink_talk_filter
, &req
.n
, &zns
->netlink_cmd
, zns
,
2078 /* Interface information read by netlink. */
2079 void interface_list(struct zebra_ns
*zns
)
2081 interface_lookup_netlink(zns
);
2082 /* We add routes for interface address,
2083 * so we need to get the nexthop info
2084 * from the kernel before we can do that
2086 netlink_nexthop_read(zns
);
2088 interface_addr_lookup_netlink(zns
);
2091 #endif /* GNU_LINUX */