]> git.proxmox.com Git - mirror_frr.git/blame - zebra/if_netlink.c
zebra: check for buffer boundary
[mirror_frr.git] / zebra / if_netlink.c
CommitLineData
718e3744 1/*
2 * Interface looking up by netlink.
3 * Copyright (C) 1998 Kunihiro Ishiguro
4 *
5 * This file is part of GNU Zebra.
6 *
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
10 * later version.
11 *
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.
16 *
896014f4
DL
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
718e3744 20 */
21
22#include <zebra.h>
6675513d 23
ddfeb486
DL
24#ifdef GNU_LINUX
25
6675513d 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
30 */
31#define _LINUX_IN6_H
32
ba85366a 33#include <netinet/if_ether.h>
6675513d 34#include <linux/if_bridge.h>
ba777396 35#include <linux/if_link.h>
1fdc9eae 36#include <net/if_arp.h>
535fe877
DS
37#include <linux/sockios.h>
38#include <linux/ethtool.h>
1fdc9eae 39
40#include "linklist.h"
41#include "if.h"
42#include "log.h"
43#include "prefix.h"
44#include "connected.h"
45#include "table.h"
46#include "memory.h"
47#include "zebra_memory.h"
48#include "rib.h"
49#include "thread.h"
50#include "privs.h"
51#include "nexthop.h"
52#include "vrf.h"
7922fc65 53#include "vrf_int.h"
1fdc9eae 54#include "mpls.h"
174482ef 55#include "lib_errors.h"
718e3744 56
5e6a74d8 57#include "vty.h"
7dbeea9d 58#include "zebra/zserv.h"
1fdc9eae 59#include "zebra/zebra_ns.h"
60#include "zebra/zebra_vrf.h"
61#include "zebra/rt.h"
62#include "zebra/redistribute.h"
63#include "zebra/interface.h"
64#include "zebra/debug.h"
65#include "zebra/rtadv.h"
66#include "zebra/zebra_ptm.h"
67#include "zebra/zebra_mpls.h"
68#include "zebra/kernel_netlink.h"
d9f5b2f5 69#include "zebra/rt_netlink.h"
1fdc9eae 70#include "zebra/if_netlink.h"
9df414fe 71#include "zebra/zebra_errors.h"
97c4e1d0 72#include "zebra/zebra_vxlan.h"
1fdc9eae 73
0268f30e 74extern struct zebra_privs_t zserv_privs;
1fdc9eae 75
76/* Note: on netlink systems, there should be a 1-to-1 mapping between interface
77 names and ifindex values. */
d62a17ae 78static void set_ifindex(struct interface *ifp, ifindex_t ifi_index,
79 struct zebra_ns *zns)
1fdc9eae 80{
d62a17ae 81 struct interface *oifp;
82
83 if (((oifp = if_lookup_by_index_per_ns(zns, ifi_index)) != NULL)
84 && (oifp != ifp)) {
85 if (ifi_index == IFINDEX_INTERNAL)
af4c2728 86 flog_err(
450971aa 87 EC_LIB_INTERFACE,
4d43f68a 88 "Netlink is setting interface %s ifindex to reserved internal value %u",
d62a17ae 89 ifp->name, ifi_index);
90 else {
91 if (IS_ZEBRA_DEBUG_KERNEL)
92 zlog_debug(
93 "interface index %d was renamed from %s to %s",
94 ifi_index, oifp->name, ifp->name);
95 if (if_is_up(oifp))
af4c2728 96 flog_err(
450971aa 97 EC_LIB_INTERFACE,
4d43f68a 98 "interface rename detected on up interface: index %d was renamed from %s to %s, results are uncertain!",
d62a17ae 99 ifi_index, oifp->name, ifp->name);
100 if_delete_update(oifp);
101 }
102 }
ff880b78 103 if_set_index(ifp, ifi_index);
1fdc9eae 104}
105
106/* Utility function to parse hardware link-layer address and update ifp */
d62a17ae 107static void netlink_interface_update_hw_addr(struct rtattr **tb,
108 struct interface *ifp)
1fdc9eae 109{
d62a17ae 110 int i;
111
112 if (tb[IFLA_ADDRESS]) {
113 int hw_addr_len;
114
115 hw_addr_len = RTA_PAYLOAD(tb[IFLA_ADDRESS]);
116
117 if (hw_addr_len > INTERFACE_HWADDR_MAX)
9df414fe
QY
118 zlog_debug("Hardware address is too large: %d",
119 hw_addr_len);
d62a17ae 120 else {
121 ifp->hw_addr_len = hw_addr_len;
122 memcpy(ifp->hw_addr, RTA_DATA(tb[IFLA_ADDRESS]),
123 hw_addr_len);
124
125 for (i = 0; i < hw_addr_len; i++)
126 if (ifp->hw_addr[i] != 0)
127 break;
128
129 if (i == hw_addr_len)
130 ifp->hw_addr_len = 0;
131 else
132 ifp->hw_addr_len = hw_addr_len;
133 }
134 }
1fdc9eae 135}
136
d62a17ae 137static enum zebra_link_type netlink_to_zebra_link_type(unsigned int hwt)
1fdc9eae 138{
d62a17ae 139 switch (hwt) {
140 case ARPHRD_ETHER:
141 return ZEBRA_LLT_ETHER;
142 case ARPHRD_EETHER:
143 return ZEBRA_LLT_EETHER;
144 case ARPHRD_AX25:
145 return ZEBRA_LLT_AX25;
146 case ARPHRD_PRONET:
147 return ZEBRA_LLT_PRONET;
148 case ARPHRD_IEEE802:
149 return ZEBRA_LLT_IEEE802;
150 case ARPHRD_ARCNET:
151 return ZEBRA_LLT_ARCNET;
152 case ARPHRD_APPLETLK:
153 return ZEBRA_LLT_APPLETLK;
154 case ARPHRD_DLCI:
155 return ZEBRA_LLT_DLCI;
156 case ARPHRD_ATM:
157 return ZEBRA_LLT_ATM;
158 case ARPHRD_METRICOM:
159 return ZEBRA_LLT_METRICOM;
160 case ARPHRD_IEEE1394:
161 return ZEBRA_LLT_IEEE1394;
162 case ARPHRD_EUI64:
163 return ZEBRA_LLT_EUI64;
164 case ARPHRD_INFINIBAND:
165 return ZEBRA_LLT_INFINIBAND;
166 case ARPHRD_SLIP:
167 return ZEBRA_LLT_SLIP;
168 case ARPHRD_CSLIP:
169 return ZEBRA_LLT_CSLIP;
170 case ARPHRD_SLIP6:
171 return ZEBRA_LLT_SLIP6;
172 case ARPHRD_CSLIP6:
173 return ZEBRA_LLT_CSLIP6;
174 case ARPHRD_RSRVD:
175 return ZEBRA_LLT_RSRVD;
176 case ARPHRD_ADAPT:
177 return ZEBRA_LLT_ADAPT;
178 case ARPHRD_ROSE:
179 return ZEBRA_LLT_ROSE;
180 case ARPHRD_X25:
181 return ZEBRA_LLT_X25;
182 case ARPHRD_PPP:
183 return ZEBRA_LLT_PPP;
184 case ARPHRD_CISCO:
185 return ZEBRA_LLT_CHDLC;
186 case ARPHRD_LAPB:
187 return ZEBRA_LLT_LAPB;
188 case ARPHRD_RAWHDLC:
189 return ZEBRA_LLT_RAWHDLC;
190 case ARPHRD_TUNNEL:
191 return ZEBRA_LLT_IPIP;
192 case ARPHRD_TUNNEL6:
193 return ZEBRA_LLT_IPIP6;
194 case ARPHRD_FRAD:
195 return ZEBRA_LLT_FRAD;
196 case ARPHRD_SKIP:
197 return ZEBRA_LLT_SKIP;
198 case ARPHRD_LOOPBACK:
199 return ZEBRA_LLT_LOOPBACK;
200 case ARPHRD_LOCALTLK:
201 return ZEBRA_LLT_LOCALTLK;
202 case ARPHRD_FDDI:
203 return ZEBRA_LLT_FDDI;
204 case ARPHRD_SIT:
205 return ZEBRA_LLT_SIT;
206 case ARPHRD_IPDDP:
207 return ZEBRA_LLT_IPDDP;
208 case ARPHRD_IPGRE:
209 return ZEBRA_LLT_IPGRE;
210 case ARPHRD_PIMREG:
211 return ZEBRA_LLT_PIMREG;
212 case ARPHRD_HIPPI:
213 return ZEBRA_LLT_HIPPI;
214 case ARPHRD_ECONET:
215 return ZEBRA_LLT_ECONET;
216 case ARPHRD_IRDA:
217 return ZEBRA_LLT_IRDA;
218 case ARPHRD_FCPP:
219 return ZEBRA_LLT_FCPP;
220 case ARPHRD_FCAL:
221 return ZEBRA_LLT_FCAL;
222 case ARPHRD_FCPL:
223 return ZEBRA_LLT_FCPL;
224 case ARPHRD_FCFABRIC:
225 return ZEBRA_LLT_FCFABRIC;
226 case ARPHRD_IEEE802_TR:
227 return ZEBRA_LLT_IEEE802_TR;
228 case ARPHRD_IEEE80211:
229 return ZEBRA_LLT_IEEE80211;
4268e09e 230#ifdef ARPHRD_IEEE802154
d62a17ae 231 case ARPHRD_IEEE802154:
232 return ZEBRA_LLT_IEEE802154;
4268e09e 233#endif
1fdc9eae 234#ifdef ARPHRD_IP6GRE
d62a17ae 235 case ARPHRD_IP6GRE:
236 return ZEBRA_LLT_IP6GRE;
1fdc9eae 237#endif
238#ifdef ARPHRD_IEEE802154_PHY
d62a17ae 239 case ARPHRD_IEEE802154_PHY:
240 return ZEBRA_LLT_IEEE802154_PHY;
1fdc9eae 241#endif
242
d62a17ae 243 default:
244 return ZEBRA_LLT_UNKNOWN;
245 }
1fdc9eae 246}
247
b9368db9
DD
248static void netlink_determine_zebra_iftype(const char *kind,
249 zebra_iftype_t *zif_type)
6675513d 250{
d62a17ae 251 *zif_type = ZEBRA_IF_OTHER;
252
253 if (!kind)
254 return;
255
256 if (strcmp(kind, "vrf") == 0)
257 *zif_type = ZEBRA_IF_VRF;
258 else if (strcmp(kind, "bridge") == 0)
259 *zif_type = ZEBRA_IF_BRIDGE;
260 else if (strcmp(kind, "vlan") == 0)
261 *zif_type = ZEBRA_IF_VLAN;
262 else if (strcmp(kind, "vxlan") == 0)
263 *zif_type = ZEBRA_IF_VXLAN;
1a98c087
MK
264 else if (strcmp(kind, "macvlan") == 0)
265 *zif_type = ZEBRA_IF_MACVLAN;
0e4864ea
PG
266 else if (strcmp(kind, "veth") == 0)
267 *zif_type = ZEBRA_IF_VETH;
b9368db9
DD
268 else if (strcmp(kind, "bond") == 0)
269 *zif_type = ZEBRA_IF_BOND;
270 else if (strcmp(kind, "bond_slave") == 0)
271 *zif_type = ZEBRA_IF_BOND_SLAVE;
6675513d 272}
52d8f0d8 273
d62a17ae 274#define parse_rtattr_nested(tb, max, rta) \
275 netlink_parse_rtattr((tb), (max), RTA_DATA(rta), RTA_PAYLOAD(rta))
1fdc9eae 276
d62a17ae 277static void netlink_vrf_change(struct nlmsghdr *h, struct rtattr *tb,
5e031198 278 uint32_t ns_id, const char *name)
1fdc9eae 279{
d62a17ae 280 struct ifinfomsg *ifi;
281 struct rtattr *linkinfo[IFLA_INFO_MAX + 1];
282 struct rtattr *attr[IFLA_VRF_MAX + 1];
283 struct vrf *vrf;
284 struct zebra_vrf *zvrf;
d7c0a89a 285 uint32_t nl_table_id;
d62a17ae 286
287 ifi = NLMSG_DATA(h);
288
0d6f7fd6 289 memset(linkinfo, 0, sizeof(linkinfo));
d62a17ae 290 parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb);
291
292 if (!linkinfo[IFLA_INFO_DATA]) {
293 if (IS_ZEBRA_DEBUG_KERNEL)
294 zlog_debug(
295 "%s: IFLA_INFO_DATA missing from VRF message: %s",
296 __func__, name);
297 return;
298 }
299
0d6f7fd6 300 memset(attr, 0, sizeof(attr));
d62a17ae 301 parse_rtattr_nested(attr, IFLA_VRF_MAX, linkinfo[IFLA_INFO_DATA]);
302 if (!attr[IFLA_VRF_TABLE]) {
303 if (IS_ZEBRA_DEBUG_KERNEL)
304 zlog_debug(
305 "%s: IFLA_VRF_TABLE missing from VRF message: %s",
306 __func__, name);
307 return;
1fdc9eae 308 }
309
d7c0a89a 310 nl_table_id = *(uint32_t *)RTA_DATA(attr[IFLA_VRF_TABLE]);
d62a17ae 311
312 if (h->nlmsg_type == RTM_NEWLINK) {
313 if (IS_ZEBRA_DEBUG_KERNEL)
314 zlog_debug("RTM_NEWLINK for VRF %s(%u) table %u", name,
315 ifi->ifi_index, nl_table_id);
316
2e86d16d
RW
317 if (!vrf_lookup_by_id((vrf_id_t)ifi->ifi_index)) {
318 vrf_id_t exist_id;
5e031198 319
2e86d16d
RW
320 exist_id = vrf_lookup_by_table(nl_table_id, ns_id);
321 if (exist_id != VRF_DEFAULT) {
322 vrf = vrf_lookup_by_id(exist_id);
323
324 flog_err(
325 EC_ZEBRA_VRF_MISCONFIGURED,
326 "VRF %s id %u table id overlaps existing vrf %s, misconfiguration exiting",
327 name, ifi->ifi_index, vrf->name);
328 exit(-1);
329 }
5e031198 330 }
2e86d16d 331
d62a17ae 332 /*
333 * vrf_get is implied creation if it does not exist
334 */
335 vrf = vrf_get((vrf_id_t)ifi->ifi_index,
336 name); // It would create vrf
337 if (!vrf) {
450971aa 338 flog_err(EC_LIB_INTERFACE, "VRF %s id %u not created",
1c50c1c0 339 name, ifi->ifi_index);
d62a17ae 340 return;
341 }
342
d62a17ae 343 /*
344 * This is the only place that we get the actual kernel table_id
345 * being used. We need it to set the table_id of the routes
346 * we are passing to the kernel.... And to throw some totally
347 * awesome parties. that too.
593406a1
DS
348 *
349 * At this point we *must* have a zvrf because the vrf_create
350 * callback creates one. We *must* set the table id
351 * before the vrf_enable because of( at the very least )
352 * static routes being delayed for installation until
353 * during the vrf_enable callbacks.
d62a17ae 354 */
355 zvrf = (struct zebra_vrf *)vrf->info;
356 zvrf->table_id = nl_table_id;
593406a1
DS
357
358 /* Enable the created VRF. */
359 if (!vrf_enable(vrf)) {
450971aa 360 flog_err(EC_LIB_INTERFACE,
1c50c1c0
QY
361 "Failed to enable VRF %s id %u", name,
362 ifi->ifi_index);
593406a1
DS
363 return;
364 }
365
d62a17ae 366 } else // h->nlmsg_type == RTM_DELLINK
367 {
368 if (IS_ZEBRA_DEBUG_KERNEL)
369 zlog_debug("RTM_DELLINK for VRF %s(%u)", name,
370 ifi->ifi_index);
371
372 vrf = vrf_lookup_by_id((vrf_id_t)ifi->ifi_index);
373
374 if (!vrf) {
e914ccbe 375 flog_warn(EC_ZEBRA_VRF_NOT_FOUND, "%s: vrf not found",
9df414fe 376 __func__);
d62a17ae 377 return;
378 }
379
380 vrf_delete(vrf);
381 }
1fdc9eae 382}
383
67188ca2 384static uint32_t get_iflink_speed(struct interface *interface, int *error)
535fe877 385{
d62a17ae 386 struct ifreq ifdata;
387 struct ethtool_cmd ecmd;
388 int sd;
389 int rc;
0268f30e 390 const char *ifname = interface->name;
d62a17ae 391
594c2878
JF
392 if (error)
393 *error = 0;
d62a17ae 394 /* initialize struct */
395 memset(&ifdata, 0, sizeof(ifdata));
396
397 /* set interface name */
0af35d90 398 strlcpy(ifdata.ifr_name, ifname, sizeof(ifdata.ifr_name));
d62a17ae 399
400 /* initialize ethtool interface */
401 memset(&ecmd, 0, sizeof(ecmd));
402 ecmd.cmd = ETHTOOL_GSET; /* ETHTOOL_GLINK */
ba85366a 403 ifdata.ifr_data = (caddr_t)&ecmd;
d62a17ae 404
405 /* use ioctl to get IP address of an interface */
0cf6db21 406 frr_with_privs(&zserv_privs) {
01b9e3fd 407 sd = vrf_socket(PF_INET, SOCK_DGRAM, IPPROTO_IP,
a36898e7 408 interface->vrf_id,
01b9e3fd
DL
409 NULL);
410 if (sd < 0) {
411 if (IS_ZEBRA_DEBUG_KERNEL)
412 zlog_debug("Failure to read interface %s speed: %d %s",
413 ifname, errno, safe_strerror(errno));
594c2878
JF
414 /* no vrf socket creation may probably mean vrf issue */
415 if (error)
416 *error = -1;
01b9e3fd
DL
417 return 0;
418 }
d62a17ae 419 /* Get the current link state for the interface */
a36898e7 420 rc = vrf_ioctl(interface->vrf_id, sd, SIOCETHTOOL,
633fc9b1 421 (char *)&ifdata);
01b9e3fd 422 }
d62a17ae 423 if (rc < 0) {
f767cee4 424 if (errno != EOPNOTSUPP && IS_ZEBRA_DEBUG_KERNEL)
bd7d0299
DS
425 zlog_debug(
426 "IOCTL failure to read interface %s speed: %d %s",
427 ifname, errno, safe_strerror(errno));
594c2878
JF
428 /* no device means interface unreachable */
429 if (errno == ENODEV && error)
430 *error = -1;
d62a17ae 431 ecmd.speed_hi = 0;
432 ecmd.speed = 0;
433 }
434
435 close(sd);
436
67188ca2 437 return ((uint32_t)ecmd.speed_hi << 16) | ecmd.speed;
535fe877
DS
438}
439
594c2878 440uint32_t kernel_get_speed(struct interface *ifp, int *error)
dc7b3cae 441{
594c2878 442 return get_iflink_speed(ifp, error);
dc7b3cae
DS
443}
444
d62a17ae 445static int netlink_extract_bridge_info(struct rtattr *link_data,
446 struct zebra_l2info_bridge *bridge_info)
6675513d 447{
d62a17ae 448 struct rtattr *attr[IFLA_BR_MAX + 1];
449
450 memset(bridge_info, 0, sizeof(*bridge_info));
0d6f7fd6 451 memset(attr, 0, sizeof(attr));
d62a17ae 452 parse_rtattr_nested(attr, IFLA_BR_MAX, link_data);
453 if (attr[IFLA_BR_VLAN_FILTERING])
454 bridge_info->vlan_aware =
d7c0a89a 455 *(uint8_t *)RTA_DATA(attr[IFLA_BR_VLAN_FILTERING]);
d62a17ae 456 return 0;
6675513d 457}
458
d62a17ae 459static int netlink_extract_vlan_info(struct rtattr *link_data,
460 struct zebra_l2info_vlan *vlan_info)
6675513d 461{
d62a17ae 462 struct rtattr *attr[IFLA_VLAN_MAX + 1];
463 vlanid_t vid_in_msg;
464
465 memset(vlan_info, 0, sizeof(*vlan_info));
0d6f7fd6 466 memset(attr, 0, sizeof(attr));
d62a17ae 467 parse_rtattr_nested(attr, IFLA_VLAN_MAX, link_data);
468 if (!attr[IFLA_VLAN_ID]) {
469 if (IS_ZEBRA_DEBUG_KERNEL)
470 zlog_debug("IFLA_VLAN_ID missing from VLAN IF message");
471 return -1;
472 }
473
474 vid_in_msg = *(vlanid_t *)RTA_DATA(attr[IFLA_VLAN_ID]);
475 vlan_info->vid = vid_in_msg;
476 return 0;
6675513d 477}
478
d62a17ae 479static int netlink_extract_vxlan_info(struct rtattr *link_data,
480 struct zebra_l2info_vxlan *vxl_info)
6675513d 481{
d62a17ae 482 struct rtattr *attr[IFLA_VXLAN_MAX + 1];
483 vni_t vni_in_msg;
484 struct in_addr vtep_ip_in_msg;
14ddb3d9 485 ifindex_t ifindex_link;
d62a17ae 486
487 memset(vxl_info, 0, sizeof(*vxl_info));
0d6f7fd6 488 memset(attr, 0, sizeof(attr));
d62a17ae 489 parse_rtattr_nested(attr, IFLA_VXLAN_MAX, link_data);
490 if (!attr[IFLA_VXLAN_ID]) {
491 if (IS_ZEBRA_DEBUG_KERNEL)
492 zlog_debug(
493 "IFLA_VXLAN_ID missing from VXLAN IF message");
494 return -1;
495 }
496
497 vni_in_msg = *(vni_t *)RTA_DATA(attr[IFLA_VXLAN_ID]);
498 vxl_info->vni = vni_in_msg;
499 if (!attr[IFLA_VXLAN_LOCAL]) {
500 if (IS_ZEBRA_DEBUG_KERNEL)
501 zlog_debug(
502 "IFLA_VXLAN_LOCAL missing from VXLAN IF message");
503 } else {
504 vtep_ip_in_msg =
505 *(struct in_addr *)RTA_DATA(attr[IFLA_VXLAN_LOCAL]);
506 vxl_info->vtep_ip = vtep_ip_in_msg;
507 }
508
d7fe235c
AK
509 if (attr[IFLA_VXLAN_GROUP]) {
510 vxl_info->mcast_grp =
511 *(struct in_addr *)RTA_DATA(attr[IFLA_VXLAN_GROUP]);
512 }
513
14ddb3d9
PG
514 if (!attr[IFLA_VXLAN_LINK]) {
515 if (IS_ZEBRA_DEBUG_KERNEL)
516 zlog_debug("IFLA_VXLAN_LINK missing "
517 "from VXLAN IF message");
518 } else {
519 ifindex_link =
520 *(ifindex_t *)RTA_DATA(attr[IFLA_VXLAN_LINK]);
521 vxl_info->ifindex_link = ifindex_link;
522 }
d62a17ae 523 return 0;
6675513d 524}
525
526/*
527 * Extract and save L2 params (of interest) for an interface. When a
528 * bridge interface is added or updated, take further actions to map
529 * its members. Likewise, for VxLAN interface.
530 */
d62a17ae 531static void netlink_interface_update_l2info(struct interface *ifp,
14ddb3d9
PG
532 struct rtattr *link_data, int add,
533 ns_id_t link_nsid)
6675513d 534{
d62a17ae 535 if (!link_data)
536 return;
537
538 if (IS_ZEBRA_IF_BRIDGE(ifp)) {
539 struct zebra_l2info_bridge bridge_info;
540
541 netlink_extract_bridge_info(link_data, &bridge_info);
542 zebra_l2_bridge_add_update(ifp, &bridge_info, add);
543 } else if (IS_ZEBRA_IF_VLAN(ifp)) {
544 struct zebra_l2info_vlan vlan_info;
545
546 netlink_extract_vlan_info(link_data, &vlan_info);
547 zebra_l2_vlanif_update(ifp, &vlan_info);
548 } else if (IS_ZEBRA_IF_VXLAN(ifp)) {
549 struct zebra_l2info_vxlan vxlan_info;
550
551 netlink_extract_vxlan_info(link_data, &vxlan_info);
14ddb3d9 552 vxlan_info.link_nsid = link_nsid;
d62a17ae 553 zebra_l2_vxlanif_add_update(ifp, &vxlan_info, add);
14ddb3d9
PG
554 if (link_nsid != NS_UNKNOWN &&
555 vxlan_info.ifindex_link)
556 zebra_if_update_link(ifp, vxlan_info.ifindex_link,
557 link_nsid);
d62a17ae 558 }
6675513d 559}
560
d62a17ae 561static int netlink_bridge_interface(struct nlmsghdr *h, int len, ns_id_t ns_id,
562 int startup)
6675513d 563{
d62a17ae 564 char *name = NULL;
565 struct ifinfomsg *ifi;
566 struct rtattr *tb[IFLA_MAX + 1];
567 struct interface *ifp;
568 struct rtattr *aftb[IFLA_BRIDGE_MAX + 1];
569 struct {
d7c0a89a
QY
570 uint16_t flags;
571 uint16_t vid;
d62a17ae 572 } * vinfo;
573 vlanid_t access_vlan;
574
575 /* Fetch name and ifindex */
576 ifi = NLMSG_DATA(h);
0d6f7fd6 577 memset(tb, 0, sizeof(tb));
d62a17ae 578 netlink_parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
579
580 if (tb[IFLA_IFNAME] == NULL)
581 return -1;
582 name = (char *)RTA_DATA(tb[IFLA_IFNAME]);
583
584 /* The interface should already be known, if not discard. */
585 ifp = if_lookup_by_index_per_ns(zebra_ns_lookup(ns_id), ifi->ifi_index);
586 if (!ifp) {
9df414fe
QY
587 zlog_debug("Cannot find bridge IF %s(%u)", name,
588 ifi->ifi_index);
d62a17ae 589 return 0;
590 }
591 if (!IS_ZEBRA_IF_VXLAN(ifp))
592 return 0;
593
594 /* We are only interested in the access VLAN i.e., AF_SPEC */
595 if (!tb[IFLA_AF_SPEC])
596 return 0;
597
598 /* There is a 1-to-1 mapping of VLAN to VxLAN - hence
599 * only 1 access VLAN is accepted.
600 */
0d6f7fd6 601 memset(aftb, 0, sizeof(aftb));
d62a17ae 602 parse_rtattr_nested(aftb, IFLA_BRIDGE_MAX, tb[IFLA_AF_SPEC]);
603 if (!aftb[IFLA_BRIDGE_VLAN_INFO])
604 return 0;
605
606 vinfo = RTA_DATA(aftb[IFLA_BRIDGE_VLAN_INFO]);
607 if (!(vinfo->flags & BRIDGE_VLAN_INFO_PVID))
608 return 0;
609
610 access_vlan = (vlanid_t)vinfo->vid;
611 if (IS_ZEBRA_DEBUG_KERNEL)
612 zlog_debug("Access VLAN %u for VxLAN IF %s(%u)", access_vlan,
613 name, ifi->ifi_index);
614 zebra_l2_vxlanif_update_access_vlan(ifp, access_vlan);
615 return 0;
6675513d 616}
617
2414abd3
DS
618/*
619 * Called from interface_lookup_netlink(). This function is only used
620 * during bootstrap.
621 */
622static int netlink_interface(struct nlmsghdr *h, ns_id_t ns_id, int startup)
1fdc9eae 623{
d62a17ae 624 int len;
625 struct ifinfomsg *ifi;
626 struct rtattr *tb[IFLA_MAX + 1];
627 struct rtattr *linkinfo[IFLA_MAX + 1];
628 struct interface *ifp;
629 char *name = NULL;
630 char *kind = NULL;
48884c6b 631 char *desc = NULL;
d62a17ae 632 char *slave_kind = NULL;
ea7ec261 633 struct zebra_ns *zns = NULL;
d62a17ae 634 vrf_id_t vrf_id = VRF_DEFAULT;
635 zebra_iftype_t zif_type = ZEBRA_IF_OTHER;
636 zebra_slave_iftype_t zif_slave_type = ZEBRA_IF_SLAVE_NONE;
637 ifindex_t bridge_ifindex = IFINDEX_INTERNAL;
638 ifindex_t link_ifindex = IFINDEX_INTERNAL;
b9368db9 639 ifindex_t bond_ifindex = IFINDEX_INTERNAL;
520ebf72 640 struct zebra_if *zif;
14ddb3d9 641 ns_id_t link_nsid = ns_id;
d62a17ae 642
643 zns = zebra_ns_lookup(ns_id);
644 ifi = NLMSG_DATA(h);
645
646 if (h->nlmsg_type != RTM_NEWLINK)
647 return 0;
648
649 len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifinfomsg));
9bdf8618 650 if (len < 0) {
15569c58
DA
651 zlog_err(
652 "%s: Message received from netlink is of a broken size: %d %zu",
653 __func__, h->nlmsg_len,
654 (size_t)NLMSG_LENGTH(sizeof(struct ifinfomsg)));
d62a17ae 655 return -1;
9bdf8618 656 }
d62a17ae 657
658 /* We are interested in some AF_BRIDGE notifications. */
659 if (ifi->ifi_family == AF_BRIDGE)
660 return netlink_bridge_interface(h, len, ns_id, startup);
661
662 /* Looking up interface name. */
0d6f7fd6
DA
663 memset(tb, 0, sizeof(tb));
664 memset(linkinfo, 0, sizeof(linkinfo));
d62a17ae 665 netlink_parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
1fdc9eae 666
d62a17ae 667 /* check for wireless messages to ignore */
668 if ((tb[IFLA_WIRELESS] != NULL) && (ifi->ifi_change == 0)) {
669 if (IS_ZEBRA_DEBUG_KERNEL)
670 zlog_debug("%s: ignoring IFLA_WIRELESS message",
671 __func__);
672 return 0;
673 }
1fdc9eae 674
d62a17ae 675 if (tb[IFLA_IFNAME] == NULL)
676 return -1;
677 name = (char *)RTA_DATA(tb[IFLA_IFNAME]);
1fdc9eae 678
48884c6b
DS
679 if (tb[IFLA_IFALIAS])
680 desc = (char *)RTA_DATA(tb[IFLA_IFALIAS]);
681
d62a17ae 682 if (tb[IFLA_LINKINFO]) {
683 parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb[IFLA_LINKINFO]);
1fdc9eae 684
d62a17ae 685 if (linkinfo[IFLA_INFO_KIND])
686 kind = RTA_DATA(linkinfo[IFLA_INFO_KIND]);
1fdc9eae 687
d62a17ae 688 if (linkinfo[IFLA_INFO_SLAVE_KIND])
689 slave_kind = RTA_DATA(linkinfo[IFLA_INFO_SLAVE_KIND]);
1fdc9eae 690
b9368db9
DD
691 if ((slave_kind != NULL) && strcmp(slave_kind, "bond") == 0)
692 netlink_determine_zebra_iftype("bond_slave", &zif_type);
693 else
694 netlink_determine_zebra_iftype(kind, &zif_type);
d62a17ae 695 }
696
697 /* If VRF, create the VRF structure itself. */
78dd30b2 698 if (zif_type == ZEBRA_IF_VRF && !vrf_is_backend_netns()) {
5e031198 699 netlink_vrf_change(h, tb[IFLA_LINKINFO], ns_id, name);
d62a17ae 700 vrf_id = (vrf_id_t)ifi->ifi_index;
701 }
702
703 if (tb[IFLA_MASTER]) {
78dd30b2
PG
704 if (slave_kind && (strcmp(slave_kind, "vrf") == 0)
705 && !vrf_is_backend_netns()) {
d62a17ae 706 zif_slave_type = ZEBRA_IF_SLAVE_VRF;
d7c0a89a 707 vrf_id = *(uint32_t *)RTA_DATA(tb[IFLA_MASTER]);
d62a17ae 708 } else if (slave_kind && (strcmp(slave_kind, "bridge") == 0)) {
709 zif_slave_type = ZEBRA_IF_SLAVE_BRIDGE;
710 bridge_ifindex =
711 *(ifindex_t *)RTA_DATA(tb[IFLA_MASTER]);
b9368db9
DD
712 } else if (slave_kind && (strcmp(slave_kind, "bond") == 0)) {
713 zif_slave_type = ZEBRA_IF_SLAVE_BOND;
714 bond_ifindex = *(ifindex_t *)RTA_DATA(tb[IFLA_MASTER]);
d62a17ae 715 } else
716 zif_slave_type = ZEBRA_IF_SLAVE_OTHER;
717 }
78dd30b2
PG
718 if (vrf_is_backend_netns())
719 vrf_id = (vrf_id_t)ns_id;
a36898e7 720
d62a17ae 721 /* If linking to another interface, note it. */
722 if (tb[IFLA_LINK])
723 link_ifindex = *(ifindex_t *)RTA_DATA(tb[IFLA_LINK]);
724
b6ebab34 725 if (tb[IFLA_LINK_NETNSID]) {
14ddb3d9 726 link_nsid = *(ns_id_t *)RTA_DATA(tb[IFLA_LINK_NETNSID]);
b6ebab34
PG
727 link_nsid = ns_id_get_absolute(ns_id, link_nsid);
728 }
14ddb3d9 729
ea7ec261
DD
730 /* Add interface.
731 * We add by index first because in some cases such as the master
732 * interface, we have the index before we have the name. Fixing
733 * back references on the slave interfaces is painful if not done
734 * this way, i.e. by creating by ifindex.
735 */
1f7a68a2 736 ifp = if_get_by_ifindex(ifi->ifi_index, vrf_id, name);
ea7ec261 737 set_ifindex(ifp, ifi->ifi_index, zns); /* add it to ns struct */
d5c65bf1 738
d62a17ae 739 ifp->flags = ifi->ifi_flags & 0x0000fffff;
d62a17ae 740 ifp->mtu6 = ifp->mtu = *(uint32_t *)RTA_DATA(tb[IFLA_MTU]);
741 ifp->metric = 0;
594c2878 742 ifp->speed = get_iflink_speed(ifp, NULL);
d62a17ae 743 ifp->ptm_status = ZEBRA_PTM_STATUS_UNKNOWN;
744
745 /* Set zebra interface type */
746 zebra_if_set_ziftype(ifp, zif_type, zif_slave_type);
b0fa6f6a
CS
747 if (IS_ZEBRA_IF_VRF(ifp))
748 SET_FLAG(ifp->status, ZEBRA_INTERFACE_VRF_LOOPBACK);
d62a17ae 749
98efddf1
DS
750 /*
751 * Just set the @link/lower-device ifindex. During nldump interfaces are
520ebf72
AK
752 * not ordered in any fashion so we may end up getting upper devices
753 * before lower devices. We will setup the real linkage once the dump
98efddf1
DS
754 * is complete.
755 */
520ebf72
AK
756 zif = (struct zebra_if *)ifp->info;
757 zif->link_ifindex = link_ifindex;
d62a17ae 758
ba5165ec
DS
759 if (desc) {
760 XFREE(MTYPE_TMP, zif->desc);
761 zif->desc = XSTRDUP(MTYPE_TMP, desc);
762 }
763
d62a17ae 764 /* Hardware type and address. */
765 ifp->ll_type = netlink_to_zebra_link_type(ifi->ifi_type);
766 netlink_interface_update_hw_addr(tb, ifp);
767
768 if_add_update(ifp);
769
770 /* Extract and save L2 interface information, take additional actions.
771 */
14ddb3d9
PG
772 netlink_interface_update_l2info(ifp, linkinfo[IFLA_INFO_DATA],
773 1, link_nsid);
d62a17ae 774 if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp))
b5b453a2 775 zebra_l2if_update_bridge_slave(ifp, bridge_ifindex, ns_id);
b9368db9
DD
776 else if (IS_ZEBRA_IF_BOND_SLAVE(ifp))
777 zebra_l2if_update_bond_slave(ifp, bond_ifindex);
d62a17ae 778
779 return 0;
1fdc9eae 780}
781
289602d7 782/* Request for specific interface or address information from the kernel */
85a75f1e
MS
783static int netlink_request_intf_addr(struct nlsock *netlink_cmd, int family,
784 int type, uint32_t filter_mask)
289602d7 785{
d62a17ae 786 struct {
787 struct nlmsghdr n;
788 struct ifinfomsg ifm;
789 char buf[256];
790 } req;
791
792 /* Form the request, specifying filter (rtattr) if needed. */
793 memset(&req, 0, sizeof(req));
794 req.n.nlmsg_type = type;
718f9b0f 795 req.n.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST;
d62a17ae 796 req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
797 req.ifm.ifi_family = family;
798
799 /* Include filter, if specified. */
800 if (filter_mask)
312a6bee 801 nl_attr_put32(&req.n, sizeof(req), IFLA_EXT_MASK, filter_mask);
d62a17ae 802
fd3f8e52 803 return netlink_request(netlink_cmd, &req);
289602d7 804}
805
1fdc9eae 806/* Interface lookup by netlink socket. */
d62a17ae 807int interface_lookup_netlink(struct zebra_ns *zns)
1fdc9eae 808{
d62a17ae 809 int ret;
85a75f1e
MS
810 struct zebra_dplane_info dp_info;
811 struct nlsock *netlink_cmd = &zns->netlink_cmd;
812
813 /* Capture key info from ns struct */
814 zebra_dplane_info_from_zns(&dp_info, zns, true /*is_cmd*/);
d62a17ae 815
816 /* Get interface information. */
85a75f1e 817 ret = netlink_request_intf_addr(netlink_cmd, AF_PACKET, RTM_GETLINK, 0);
d62a17ae 818 if (ret < 0)
819 return ret;
85a75f1e 820 ret = netlink_parse_info(netlink_interface, netlink_cmd, &dp_info, 0,
d62a17ae 821 1);
822 if (ret < 0)
823 return ret;
824
825 /* Get interface information - for bridge interfaces. */
85a75f1e 826 ret = netlink_request_intf_addr(netlink_cmd, AF_BRIDGE, RTM_GETLINK,
d62a17ae 827 RTEXT_FILTER_BRVLAN);
828 if (ret < 0)
829 return ret;
85a75f1e 830 ret = netlink_parse_info(netlink_interface, netlink_cmd, &dp_info, 0,
d62a17ae 831 0);
832 if (ret < 0)
833 return ret;
834
835 /* Get interface information - for bridge interfaces. */
85a75f1e 836 ret = netlink_request_intf_addr(netlink_cmd, AF_BRIDGE, RTM_GETLINK,
d62a17ae 837 RTEXT_FILTER_BRVLAN);
838 if (ret < 0)
839 return ret;
85a75f1e 840 ret = netlink_parse_info(netlink_interface, netlink_cmd, &dp_info, 0,
d62a17ae 841 0);
842 if (ret < 0)
843 return ret;
844
520ebf72
AK
845 /* fixup linkages */
846 zebra_if_update_all_links();
d2bec88a
SW
847 return 0;
848}
849
850/**
851 * interface_addr_lookup_netlink() - Look up interface addresses
852 *
853 * @zns: Zebra netlink socket
854 * Return: Result status
855 */
856static int interface_addr_lookup_netlink(struct zebra_ns *zns)
857{
858 int ret;
859 struct zebra_dplane_info dp_info;
860 struct nlsock *netlink_cmd = &zns->netlink_cmd;
861
862 /* Capture key info from ns struct */
863 zebra_dplane_info_from_zns(&dp_info, zns, true /*is_cmd*/);
520ebf72 864
d62a17ae 865 /* Get IPv4 address of the interfaces. */
85a75f1e 866 ret = netlink_request_intf_addr(netlink_cmd, AF_INET, RTM_GETADDR, 0);
d62a17ae 867 if (ret < 0)
868 return ret;
85a75f1e 869 ret = netlink_parse_info(netlink_interface_addr, netlink_cmd, &dp_info,
d62a17ae 870 0, 1);
871 if (ret < 0)
872 return ret;
873
874 /* Get IPv6 address of the interfaces. */
85a75f1e 875 ret = netlink_request_intf_addr(netlink_cmd, AF_INET6, RTM_GETADDR, 0);
d62a17ae 876 if (ret < 0)
877 return ret;
85a75f1e 878 ret = netlink_parse_info(netlink_interface_addr, netlink_cmd, &dp_info,
d62a17ae 879 0, 1);
880 if (ret < 0)
881 return ret;
882
883 return 0;
1fdc9eae 884}
885
e0ae31b8
DS
886int kernel_interface_set_master(struct interface *master,
887 struct interface *slave)
888{
889 struct zebra_ns *zns = zebra_ns_lookup(NS_DEFAULT);
890
891 struct {
892 struct nlmsghdr n;
893 struct ifinfomsg ifa;
894 char buf[NL_PKT_BUF_SIZE];
895 } req;
896
0d6f7fd6 897 memset(&req, 0, sizeof(req));
e0ae31b8
DS
898
899 req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
900 req.n.nlmsg_flags = NLM_F_REQUEST;
901 req.n.nlmsg_type = RTM_SETLINK;
902 req.n.nlmsg_pid = zns->netlink_cmd.snl.nl_pid;
903
904 req.ifa.ifi_index = slave->ifindex;
905
312a6bee
JU
906 nl_attr_put(&req.n, sizeof(req), IFLA_MASTER, &master->ifindex, 4);
907 nl_attr_put(&req.n, sizeof(req), IFLA_LINK, &slave->ifindex, 4);
e0ae31b8
DS
908
909 return netlink_talk(netlink_talk_filter, &req.n, &zns->netlink_cmd, zns,
910 0);
911}
912
1fdc9eae 913/* Interface address modification. */
64168803 914static int netlink_address_ctx(const struct zebra_dplane_ctx *ctx)
1fdc9eae 915{
d62a17ae 916 int bytelen;
64168803
MS
917 const struct prefix *p;
918 int cmd;
919 const char *label;
1fdc9eae 920
d62a17ae 921 struct {
922 struct nlmsghdr n;
923 struct ifaddrmsg ifa;
924 char buf[NL_PKT_BUF_SIZE];
925 } req;
1fdc9eae 926
64168803
MS
927 p = dplane_ctx_get_intf_addr(ctx);
928 memset(&req, 0, sizeof(req) - NL_PKT_BUF_SIZE);
1fdc9eae 929
64168803 930 bytelen = (p->family == AF_INET ? 4 : 16);
1fdc9eae 931
d62a17ae 932 req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
933 req.n.nlmsg_flags = NLM_F_REQUEST;
a55ba23f 934
64168803
MS
935 if (dplane_ctx_get_op(ctx) == DPLANE_OP_ADDR_INSTALL)
936 cmd = RTM_NEWADDR;
937 else
938 cmd = RTM_DELADDR;
939
940 req.n.nlmsg_type = cmd;
941 req.ifa.ifa_family = p->family;
1fdc9eae 942
64168803 943 req.ifa.ifa_index = dplane_ctx_get_ifindex(ctx);
1fdc9eae 944
312a6bee 945 nl_attr_put(&req.n, sizeof(req), IFA_LOCAL, &p->u.prefix, bytelen);
1fdc9eae 946
64168803
MS
947 if (p->family == AF_INET) {
948 if (dplane_ctx_intf_is_connected(ctx)) {
949 p = dplane_ctx_get_intf_dest(ctx);
312a6bee
JU
950 nl_attr_put(&req.n, sizeof(req), IFA_ADDRESS,
951 &p->u.prefix, bytelen);
0f3af738
JW
952 } else if (cmd == RTM_NEWADDR) {
953 struct in_addr broad = {
954 .s_addr = ipv4_broadcast_addr(p->u.prefix4.s_addr,
955 p->prefixlen)
956 };
312a6bee
JU
957 nl_attr_put(&req.n, sizeof(req), IFA_BROADCAST, &broad,
958 bytelen);
d62a17ae 959 }
960 }
1fdc9eae 961
64168803 962 /* p is now either address or destination/bcast addr */
e8d19a05
DL
963 req.ifa.ifa_prefixlen = p->prefixlen;
964
64168803 965 if (dplane_ctx_intf_is_secondary(ctx))
d62a17ae 966 SET_FLAG(req.ifa.ifa_flags, IFA_F_SECONDARY);
1fdc9eae 967
64168803
MS
968 if (dplane_ctx_intf_has_label(ctx)) {
969 label = dplane_ctx_get_intf_label(ctx);
312a6bee
JU
970 nl_attr_put(&req.n, sizeof(req), IFA_LABEL, label,
971 strlen(label) + 1);
64168803 972 }
1fdc9eae 973
64168803
MS
974 return netlink_talk_info(netlink_talk_filter, &req.n,
975 dplane_ctx_get_ns(ctx), 0);
e86b71f1
PG
976}
977
64168803 978enum zebra_dplane_result kernel_address_update_ctx(struct zebra_dplane_ctx *ctx)
e86b71f1 979{
64168803
MS
980 return (netlink_address_ctx(ctx) == 0 ?
981 ZEBRA_DPLANE_REQUEST_SUCCESS : ZEBRA_DPLANE_REQUEST_FAILURE);
e86b71f1
PG
982}
983
2414abd3 984int netlink_interface_addr(struct nlmsghdr *h, ns_id_t ns_id, int startup)
1fdc9eae 985{
d62a17ae 986 int len;
987 struct ifaddrmsg *ifa;
988 struct rtattr *tb[IFA_MAX + 1];
989 struct interface *ifp;
990 void *addr;
991 void *broad;
d7c0a89a 992 uint8_t flags = 0;
d62a17ae 993 char *label = NULL;
994 struct zebra_ns *zns;
cde1af84 995 uint32_t metric = METRIC_MAX;
9254efed 996 uint32_t kernel_flags = 0;
d62a17ae 997
998 zns = zebra_ns_lookup(ns_id);
999 ifa = NLMSG_DATA(h);
1000
8a1b681c 1001 if (ifa->ifa_family != AF_INET && ifa->ifa_family != AF_INET6) {
9df414fe 1002 flog_warn(
e914ccbe 1003 EC_ZEBRA_UNKNOWN_FAMILY,
87b5d1b0
DS
1004 "Invalid address family: %u received from kernel interface addr change: %s",
1005 ifa->ifa_family, nl_msg_type_to_str(h->nlmsg_type));
d62a17ae 1006 return 0;
8a1b681c 1007 }
d62a17ae 1008
1009 if (h->nlmsg_type != RTM_NEWADDR && h->nlmsg_type != RTM_DELADDR)
1010 return 0;
1011
1012 len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifaddrmsg));
9bdf8618 1013 if (len < 0) {
15569c58
DA
1014 zlog_err(
1015 "%s: Message received from netlink is of a broken size: %d %zu",
1016 __func__, h->nlmsg_len,
1017 (size_t)NLMSG_LENGTH(sizeof(struct ifaddrmsg)));
d62a17ae 1018 return -1;
9bdf8618 1019 }
d62a17ae 1020
0d6f7fd6 1021 memset(tb, 0, sizeof(tb));
d62a17ae 1022 netlink_parse_rtattr(tb, IFA_MAX, IFA_RTA(ifa), len);
1023
1024 ifp = if_lookup_by_index_per_ns(zns, ifa->ifa_index);
1025 if (ifp == NULL) {
af4c2728 1026 flog_err(
450971aa 1027 EC_LIB_INTERFACE,
d62a17ae 1028 "netlink_interface_addr can't find interface by index %d",
1029 ifa->ifa_index);
1030 return -1;
1031 }
1032
9254efed
DS
1033 /* Flags passed through */
1034 if (tb[IFA_FLAGS])
1035 kernel_flags = *(int *)RTA_DATA(tb[IFA_FLAGS]);
1036 else
1037 kernel_flags = ifa->ifa_flags;
1038
d62a17ae 1039 if (IS_ZEBRA_DEBUG_KERNEL) /* remove this line to see initial ifcfg */
1040 {
1041 char buf[BUFSIZ];
1042 zlog_debug("netlink_interface_addr %s %s flags 0x%x:",
1043 nl_msg_type_to_str(h->nlmsg_type), ifp->name,
9254efed 1044 kernel_flags);
d62a17ae 1045 if (tb[IFA_LOCAL])
1046 zlog_debug(" IFA_LOCAL %s/%d",
1047 inet_ntop(ifa->ifa_family,
1048 RTA_DATA(tb[IFA_LOCAL]), buf,
1049 BUFSIZ),
1050 ifa->ifa_prefixlen);
1051 if (tb[IFA_ADDRESS])
1052 zlog_debug(" IFA_ADDRESS %s/%d",
1053 inet_ntop(ifa->ifa_family,
1054 RTA_DATA(tb[IFA_ADDRESS]), buf,
1055 BUFSIZ),
1056 ifa->ifa_prefixlen);
1057 if (tb[IFA_BROADCAST])
1058 zlog_debug(" IFA_BROADCAST %s/%d",
1059 inet_ntop(ifa->ifa_family,
1060 RTA_DATA(tb[IFA_BROADCAST]), buf,
1061 BUFSIZ),
1062 ifa->ifa_prefixlen);
1063 if (tb[IFA_LABEL] && strcmp(ifp->name, RTA_DATA(tb[IFA_LABEL])))
1064 zlog_debug(" IFA_LABEL %s",
1065 (char *)RTA_DATA(tb[IFA_LABEL]));
1066
1067 if (tb[IFA_CACHEINFO]) {
1068 struct ifa_cacheinfo *ci = RTA_DATA(tb[IFA_CACHEINFO]);
1069 zlog_debug(" IFA_CACHEINFO pref %d, valid %d",
1070 ci->ifa_prefered, ci->ifa_valid);
1071 }
1072 }
1073
1074 /* logic copied from iproute2/ip/ipaddress.c:print_addrinfo() */
1075 if (tb[IFA_LOCAL] == NULL)
1076 tb[IFA_LOCAL] = tb[IFA_ADDRESS];
1077 if (tb[IFA_ADDRESS] == NULL)
1078 tb[IFA_ADDRESS] = tb[IFA_LOCAL];
1079
1080 /* local interface address */
1081 addr = (tb[IFA_LOCAL] ? RTA_DATA(tb[IFA_LOCAL]) : NULL);
1082
1083 /* is there a peer address? */
1084 if (tb[IFA_ADDRESS]
1085 && memcmp(RTA_DATA(tb[IFA_ADDRESS]), RTA_DATA(tb[IFA_LOCAL]),
1086 RTA_PAYLOAD(tb[IFA_ADDRESS]))) {
1087 broad = RTA_DATA(tb[IFA_ADDRESS]);
1088 SET_FLAG(flags, ZEBRA_IFA_PEER);
1089 } else
1090 /* seeking a broadcast address */
1091 broad = (tb[IFA_BROADCAST] ? RTA_DATA(tb[IFA_BROADCAST])
1092 : NULL);
1093
1094 /* addr is primary key, SOL if we don't have one */
1095 if (addr == NULL) {
14a4d9d0 1096 zlog_debug("%s: Local Interface Address is NULL for %s",
1097 __func__, ifp->name);
d62a17ae 1098 return -1;
1099 }
1100
1101 /* Flags. */
9254efed 1102 if (kernel_flags & IFA_F_SECONDARY)
d62a17ae 1103 SET_FLAG(flags, ZEBRA_IFA_SECONDARY);
1104
1105 /* Label */
1106 if (tb[IFA_LABEL])
1107 label = (char *)RTA_DATA(tb[IFA_LABEL]);
1108
2e1cc436 1109 if (label && strcmp(ifp->name, label) == 0)
d62a17ae 1110 label = NULL;
1111
cde1af84
AK
1112 if (tb[IFA_RT_PRIORITY])
1113 metric = *(uint32_t *)RTA_DATA(tb[IFA_RT_PRIORITY]);
1114
d62a17ae 1115 /* Register interface address to the interface. */
1116 if (ifa->ifa_family == AF_INET) {
930571d2 1117 if (ifa->ifa_prefixlen > IPV4_MAX_BITLEN) {
e17d9b2d 1118 zlog_err(
87b5d1b0
DS
1119 "Invalid prefix length: %u received from kernel interface addr change: %s",
1120 ifa->ifa_prefixlen,
1121 nl_msg_type_to_str(h->nlmsg_type));
e17d9b2d 1122 return -1;
930571d2 1123 }
20e879f9 1124
d62a17ae 1125 if (h->nlmsg_type == RTM_NEWADDR)
1126 connected_add_ipv4(ifp, flags, (struct in_addr *)addr,
1127 ifa->ifa_prefixlen,
cde1af84
AK
1128 (struct in_addr *)broad, label,
1129 metric);
20e879f9
MS
1130 else if (CHECK_FLAG(flags, ZEBRA_IFA_PEER)) {
1131 /* Delete with a peer address */
1132 connected_delete_ipv4(
1133 ifp, flags, (struct in_addr *)addr,
1134 ifa->ifa_prefixlen, broad);
1135 } else
d62a17ae 1136 connected_delete_ipv4(
1137 ifp, flags, (struct in_addr *)addr,
fd267f08 1138 ifa->ifa_prefixlen, NULL);
d62a17ae 1139 }
20e879f9 1140
d62a17ae 1141 if (ifa->ifa_family == AF_INET6) {
930571d2 1142 if (ifa->ifa_prefixlen > IPV6_MAX_BITLEN) {
e17d9b2d 1143 zlog_err(
87b5d1b0
DS
1144 "Invalid prefix length: %u received from kernel interface addr change: %s",
1145 ifa->ifa_prefixlen,
1146 nl_msg_type_to_str(h->nlmsg_type));
e17d9b2d 1147 return -1;
930571d2 1148 }
d62a17ae 1149 if (h->nlmsg_type == RTM_NEWADDR) {
1150 /* Only consider valid addresses; we'll not get a
1151 * notification from
1152 * the kernel till IPv6 DAD has completed, but at init
1153 * time, Quagga
1154 * does query for and will receive all addresses.
1155 */
9254efed 1156 if (!(kernel_flags
d62a17ae 1157 & (IFA_F_DADFAILED | IFA_F_TENTATIVE)))
60466a63
QY
1158 connected_add_ipv6(ifp, flags,
1159 (struct in6_addr *)addr,
60c0687a 1160 (struct in6_addr *)broad,
cde1af84
AK
1161 ifa->ifa_prefixlen, label,
1162 metric);
d62a17ae 1163 } else
1164 connected_delete_ipv6(ifp, (struct in6_addr *)addr,
fd267f08 1165 NULL, ifa->ifa_prefixlen);
d62a17ae 1166 }
1167
2a181147
SW
1168
1169 /*
1170 * Linux kernel does not send route delete on interface down/addr del
1171 * so we have to re-process routes it owns (i.e. kernel routes)
1172 */
1173 if (h->nlmsg_type != RTM_NEWADDR)
1174 rib_update(RIB_UPDATE_KERNEL);
1175
d62a17ae 1176 return 0;
1fdc9eae 1177}
1178
2414abd3 1179int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
1fdc9eae 1180{
d62a17ae 1181 int len;
1182 struct ifinfomsg *ifi;
1183 struct rtattr *tb[IFLA_MAX + 1];
1184 struct rtattr *linkinfo[IFLA_MAX + 1];
1185 struct interface *ifp;
1186 char *name = NULL;
1187 char *kind = NULL;
48884c6b 1188 char *desc = NULL;
d62a17ae 1189 char *slave_kind = NULL;
1190 struct zebra_ns *zns;
1191 vrf_id_t vrf_id = VRF_DEFAULT;
1192 zebra_iftype_t zif_type = ZEBRA_IF_OTHER;
1193 zebra_slave_iftype_t zif_slave_type = ZEBRA_IF_SLAVE_NONE;
1194 ifindex_t bridge_ifindex = IFINDEX_INTERNAL;
b9368db9 1195 ifindex_t bond_ifindex = IFINDEX_INTERNAL;
d62a17ae 1196 ifindex_t link_ifindex = IFINDEX_INTERNAL;
97c4e1d0 1197 uint8_t old_hw_addr[INTERFACE_HWADDR_MAX];
ba5165ec 1198 struct zebra_if *zif;
14ddb3d9 1199 ns_id_t link_nsid = ns_id;
d62a17ae 1200
1201 zns = zebra_ns_lookup(ns_id);
1202 ifi = NLMSG_DATA(h);
1203
fe533c56 1204 /* assume if not default zns, then new VRF */
d62a17ae 1205 if (!(h->nlmsg_type == RTM_NEWLINK || h->nlmsg_type == RTM_DELLINK)) {
1206 /* If this is not link add/delete message so print warning. */
87b5d1b0
DS
1207 zlog_debug("netlink_link_change: wrong kernel message %s",
1208 nl_msg_type_to_str(h->nlmsg_type));
d62a17ae 1209 return 0;
1210 }
1211
8a1b681c
SW
1212 if (!(ifi->ifi_family == AF_UNSPEC || ifi->ifi_family == AF_BRIDGE
1213 || ifi->ifi_family == AF_INET6)) {
9df414fe 1214 flog_warn(
e914ccbe 1215 EC_ZEBRA_UNKNOWN_FAMILY,
87b5d1b0
DS
1216 "Invalid address family: %u received from kernel link change: %s",
1217 ifi->ifi_family, nl_msg_type_to_str(h->nlmsg_type));
8a1b681c
SW
1218 return 0;
1219 }
1220
d62a17ae 1221 len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifinfomsg));
9bdf8618 1222 if (len < 0) {
15569c58
DA
1223 zlog_err(
1224 "%s: Message received from netlink is of a broken size %d %zu",
1225 __func__, h->nlmsg_len,
1226 (size_t)NLMSG_LENGTH(sizeof(struct ifinfomsg)));
d62a17ae 1227 return -1;
9bdf8618 1228 }
d62a17ae 1229
1230 /* We are interested in some AF_BRIDGE notifications. */
1231 if (ifi->ifi_family == AF_BRIDGE)
1232 return netlink_bridge_interface(h, len, ns_id, startup);
1233
1234 /* Looking up interface name. */
0d6f7fd6
DA
1235 memset(tb, 0, sizeof(tb));
1236 memset(linkinfo, 0, sizeof(linkinfo));
d62a17ae 1237 netlink_parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
1fdc9eae 1238
d62a17ae 1239 /* check for wireless messages to ignore */
1240 if ((tb[IFLA_WIRELESS] != NULL) && (ifi->ifi_change == 0)) {
1241 if (IS_ZEBRA_DEBUG_KERNEL)
1242 zlog_debug("%s: ignoring IFLA_WIRELESS message",
1243 __func__);
1244 return 0;
1245 }
1fdc9eae 1246
d62a17ae 1247 if (tb[IFLA_IFNAME] == NULL)
1248 return -1;
1249 name = (char *)RTA_DATA(tb[IFLA_IFNAME]);
1fdc9eae 1250
d62a17ae 1251 if (tb[IFLA_LINKINFO]) {
1252 parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb[IFLA_LINKINFO]);
1fdc9eae 1253
d62a17ae 1254 if (linkinfo[IFLA_INFO_KIND])
1255 kind = RTA_DATA(linkinfo[IFLA_INFO_KIND]);
1fdc9eae 1256
d62a17ae 1257 if (linkinfo[IFLA_INFO_SLAVE_KIND])
1258 slave_kind = RTA_DATA(linkinfo[IFLA_INFO_SLAVE_KIND]);
1fdc9eae 1259
d62a17ae 1260 netlink_determine_zebra_iftype(kind, &zif_type);
1261 }
6675513d 1262
d62a17ae 1263 /* If linking to another interface, note it. */
1264 if (tb[IFLA_LINK])
1265 link_ifindex = *(ifindex_t *)RTA_DATA(tb[IFLA_LINK]);
1fdc9eae 1266
b6ebab34 1267 if (tb[IFLA_LINK_NETNSID]) {
14ddb3d9 1268 link_nsid = *(ns_id_t *)RTA_DATA(tb[IFLA_LINK_NETNSID]);
b6ebab34
PG
1269 link_nsid = ns_id_get_absolute(ns_id, link_nsid);
1270 }
48884c6b
DS
1271 if (tb[IFLA_IFALIAS]) {
1272 desc = (char *)RTA_DATA(tb[IFLA_IFALIAS]);
1273 }
1274
d62a17ae 1275 /* If VRF, create or update the VRF structure itself. */
78dd30b2 1276 if (zif_type == ZEBRA_IF_VRF && !vrf_is_backend_netns()) {
5e031198 1277 netlink_vrf_change(h, tb[IFLA_LINKINFO], ns_id, name);
d62a17ae 1278 vrf_id = (vrf_id_t)ifi->ifi_index;
1279 }
1fdc9eae 1280
d62a17ae 1281 /* See if interface is present. */
1282 ifp = if_lookup_by_name_per_ns(zns, name);
1283
1284 if (h->nlmsg_type == RTM_NEWLINK) {
1285 if (tb[IFLA_MASTER]) {
78dd30b2
PG
1286 if (slave_kind && (strcmp(slave_kind, "vrf") == 0)
1287 && !vrf_is_backend_netns()) {
d62a17ae 1288 zif_slave_type = ZEBRA_IF_SLAVE_VRF;
d7c0a89a 1289 vrf_id = *(uint32_t *)RTA_DATA(tb[IFLA_MASTER]);
d62a17ae 1290 } else if (slave_kind
1291 && (strcmp(slave_kind, "bridge") == 0)) {
1292 zif_slave_type = ZEBRA_IF_SLAVE_BRIDGE;
1293 bridge_ifindex =
1294 *(ifindex_t *)RTA_DATA(tb[IFLA_MASTER]);
b9368db9
DD
1295 } else if (slave_kind
1296 && (strcmp(slave_kind, "bond") == 0)) {
1297 zif_slave_type = ZEBRA_IF_SLAVE_BOND;
1298 bond_ifindex =
1299 *(ifindex_t *)RTA_DATA(tb[IFLA_MASTER]);
d62a17ae 1300 } else
1301 zif_slave_type = ZEBRA_IF_SLAVE_OTHER;
1302 }
fe533c56
PG
1303 if (vrf_is_backend_netns())
1304 vrf_id = (vrf_id_t)ns_id;
d62a17ae 1305 if (ifp == NULL
1306 || !CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) {
1307 /* Add interface notification from kernel */
1308 if (IS_ZEBRA_DEBUG_KERNEL)
1309 zlog_debug(
1310 "RTM_NEWLINK ADD for %s(%u) vrf_id %u type %d "
1311 "sl_type %d master %u flags 0x%x",
1312 name, ifi->ifi_index, vrf_id, zif_type,
1313 zif_slave_type, bridge_ifindex,
1314 ifi->ifi_flags);
1315
1316 if (ifp == NULL) {
1317 /* unknown interface */
a36898e7 1318 ifp = if_get_by_name(name, vrf_id);
d62a17ae 1319 } else {
1320 /* pre-configured interface, learnt now */
a36898e7
DS
1321 if (ifp->vrf_id != vrf_id)
1322 if_update_to_new_vrf(ifp, vrf_id);
d62a17ae 1323 }
1324
1325 /* Update interface information. */
1326 set_ifindex(ifp, ifi->ifi_index, zns);
1327 ifp->flags = ifi->ifi_flags & 0x0000fffff;
d23b983b 1328 if (!tb[IFLA_MTU]) {
9df414fe 1329 zlog_debug(
d23b983b
SW
1330 "RTM_NEWLINK for interface %s(%u) without MTU set",
1331 name, ifi->ifi_index);
1332 return 0;
1333 }
d62a17ae 1334 ifp->mtu6 = ifp->mtu = *(int *)RTA_DATA(tb[IFLA_MTU]);
1335 ifp->metric = 0;
1336 ifp->ptm_status = ZEBRA_PTM_STATUS_UNKNOWN;
1337
1338 /* Set interface type */
1339 zebra_if_set_ziftype(ifp, zif_type, zif_slave_type);
b0fa6f6a
CS
1340 if (IS_ZEBRA_IF_VRF(ifp))
1341 SET_FLAG(ifp->status,
1342 ZEBRA_INTERFACE_VRF_LOOPBACK);
d62a17ae 1343
1344 /* Update link. */
680c278f 1345 zebra_if_update_link(ifp, link_ifindex, ns_id);
d62a17ae 1346
1347 netlink_interface_update_hw_addr(tb, ifp);
1348
1349 /* Inform clients, install any configured addresses. */
1350 if_add_update(ifp);
1351
1352 /* Extract and save L2 interface information, take
1353 * additional actions. */
1354 netlink_interface_update_l2info(
14ddb3d9
PG
1355 ifp, linkinfo[IFLA_INFO_DATA],
1356 1, link_nsid);
d62a17ae 1357 if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp))
1358 zebra_l2if_update_bridge_slave(ifp,
b5b453a2
PG
1359 bridge_ifindex,
1360 ns_id);
b9368db9
DD
1361 else if (IS_ZEBRA_IF_BOND_SLAVE(ifp))
1362 zebra_l2if_update_bond_slave(ifp, bond_ifindex);
a36898e7 1363 } else if (ifp->vrf_id != vrf_id) {
d62a17ae 1364 /* VRF change for an interface. */
1365 if (IS_ZEBRA_DEBUG_KERNEL)
1366 zlog_debug(
1367 "RTM_NEWLINK vrf-change for %s(%u) "
1368 "vrf_id %u -> %u flags 0x%x",
a36898e7
DS
1369 name, ifp->ifindex, ifp->vrf_id, vrf_id,
1370 ifi->ifi_flags);
d62a17ae 1371
a36898e7 1372 if_handle_vrf_change(ifp, vrf_id);
d62a17ae 1373 } else {
b9368db9 1374 bool was_bridge_slave, was_bond_slave;
d62a17ae 1375
1376 /* Interface update. */
1377 if (IS_ZEBRA_DEBUG_KERNEL)
1378 zlog_debug(
1379 "RTM_NEWLINK update for %s(%u) "
1380 "sl_type %d master %u flags 0x%x",
1381 name, ifp->ifindex, zif_slave_type,
1382 bridge_ifindex, ifi->ifi_flags);
1383
1384 set_ifindex(ifp, ifi->ifi_index, zns);
d23b983b 1385 if (!tb[IFLA_MTU]) {
9df414fe 1386 zlog_debug(
d23b983b
SW
1387 "RTM_NEWLINK for interface %s(%u) without MTU set",
1388 name, ifi->ifi_index);
1389 return 0;
1390 }
d62a17ae 1391 ifp->mtu6 = ifp->mtu = *(int *)RTA_DATA(tb[IFLA_MTU]);
1392 ifp->metric = 0;
1393
1394 /* Update interface type - NOTE: Only slave_type can
1395 * change. */
1396 was_bridge_slave = IS_ZEBRA_IF_BRIDGE_SLAVE(ifp);
b9368db9 1397 was_bond_slave = IS_ZEBRA_IF_BOND_SLAVE(ifp);
d62a17ae 1398 zebra_if_set_ziftype(ifp, zif_type, zif_slave_type);
1399
97c4e1d0
CS
1400 memcpy(old_hw_addr, ifp->hw_addr, INTERFACE_HWADDR_MAX);
1401
d62a17ae 1402 netlink_interface_update_hw_addr(tb, ifp);
1403
1404 if (if_is_no_ptm_operative(ifp)) {
1405 ifp->flags = ifi->ifi_flags & 0x0000fffff;
1406 if (!if_is_no_ptm_operative(ifp)) {
1407 if (IS_ZEBRA_DEBUG_KERNEL)
1408 zlog_debug(
1409 "Intf %s(%u) has gone DOWN",
1410 name, ifp->ifindex);
1411 if_down(ifp);
2a181147 1412 rib_update(RIB_UPDATE_KERNEL);
d62a17ae 1413 } else if (if_is_operative(ifp)) {
1414 /* Must notify client daemons of new
1415 * interface status. */
1416 if (IS_ZEBRA_DEBUG_KERNEL)
1417 zlog_debug(
1418 "Intf %s(%u) PTM up, notifying clients",
1419 name, ifp->ifindex);
1420 zebra_interface_up_update(ifp);
97c4e1d0
CS
1421
1422 /* Update EVPN VNI when SVI MAC change
1423 */
1424 if (IS_ZEBRA_IF_VLAN(ifp) &&
1425 memcmp(old_hw_addr, ifp->hw_addr,
1426 INTERFACE_HWADDR_MAX)) {
1427 struct interface *link_if;
1428
1429 link_if =
1430 if_lookup_by_index_per_ns(
1431 zebra_ns_lookup(NS_DEFAULT),
1432 link_ifindex);
1433 if (link_if)
1434 zebra_vxlan_svi_up(ifp,
1435 link_if);
1436 }
d62a17ae 1437 }
1438 } else {
1439 ifp->flags = ifi->ifi_flags & 0x0000fffff;
1440 if (if_is_operative(ifp)) {
1441 if (IS_ZEBRA_DEBUG_KERNEL)
1442 zlog_debug(
1443 "Intf %s(%u) has come UP",
1444 name, ifp->ifindex);
1445 if_up(ifp);
6f908ded
QY
1446 } else {
1447 if (IS_ZEBRA_DEBUG_KERNEL)
1448 zlog_debug(
7913714e 1449 "Intf %s(%u) has gone DOWN",
6f908ded
QY
1450 name, ifp->ifindex);
1451 if_down(ifp);
2a181147 1452 rib_update(RIB_UPDATE_KERNEL);
d62a17ae 1453 }
1454 }
1455
1456 /* Extract and save L2 interface information, take
1457 * additional actions. */
1458 netlink_interface_update_l2info(
14ddb3d9
PG
1459 ifp, linkinfo[IFLA_INFO_DATA],
1460 0, link_nsid);
d62a17ae 1461 if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp) || was_bridge_slave)
1462 zebra_l2if_update_bridge_slave(ifp,
b5b453a2
PG
1463 bridge_ifindex,
1464 ns_id);
b9368db9
DD
1465 else if (IS_ZEBRA_IF_BOND_SLAVE(ifp) || was_bond_slave)
1466 zebra_l2if_update_bond_slave(ifp, bond_ifindex);
d62a17ae 1467 }
26f13577
DS
1468
1469 zif = ifp->info;
1470 if (zif) {
1471 XFREE(MTYPE_TMP, zif->desc);
1472 if (desc)
1473 zif->desc = XSTRDUP(MTYPE_TMP, desc);
1474 }
d62a17ae 1475 } else {
1476 /* Delete interface notification from kernel */
1477 if (ifp == NULL) {
9df414fe
QY
1478 if (IS_ZEBRA_DEBUG_KERNEL)
1479 zlog_debug(
1480 "RTM_DELLINK for unknown interface %s(%u)",
1481 name, ifi->ifi_index);
d62a17ae 1482 return 0;
1483 }
1484
1485 if (IS_ZEBRA_DEBUG_KERNEL)
1486 zlog_debug("RTM_DELLINK for %s(%u)", name,
1487 ifp->ifindex);
1488
1489 UNSET_FLAG(ifp->status, ZEBRA_INTERFACE_VRF_LOOPBACK);
1490
1491 /* Special handling for bridge or VxLAN interfaces. */
1492 if (IS_ZEBRA_IF_BRIDGE(ifp))
1493 zebra_l2_bridge_del(ifp);
1494 else if (IS_ZEBRA_IF_VXLAN(ifp))
1495 zebra_l2_vxlanif_del(ifp);
1496
1497 if (!IS_ZEBRA_IF_VRF(ifp))
1498 if_delete_update(ifp);
1fdc9eae 1499 }
1500
d62a17ae 1501 return 0;
1fdc9eae 1502}
718e3744 1503
c3bd894e
QY
1504int netlink_protodown(struct interface *ifp, bool down)
1505{
1506 struct zebra_ns *zns = zebra_ns_lookup(NS_DEFAULT);
1507
1508 struct {
1509 struct nlmsghdr n;
1510 struct ifinfomsg ifa;
1511 char buf[NL_PKT_BUF_SIZE];
1512 } req;
1513
2fff50ec 1514 memset(&req, 0, sizeof(req));
c3bd894e
QY
1515
1516 req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
1517 req.n.nlmsg_flags = NLM_F_REQUEST;
1518 req.n.nlmsg_type = RTM_SETLINK;
1519 req.n.nlmsg_pid = zns->netlink_cmd.snl.nl_pid;
1520
1521 req.ifa.ifi_index = ifp->ifindex;
1522
312a6bee
JU
1523 nl_attr_put(&req.n, sizeof(req), IFLA_PROTO_DOWN, &down, sizeof(down));
1524 nl_attr_put(&req.n, sizeof(req), IFLA_LINK, &ifp->ifindex, 4);
c3bd894e
QY
1525
1526 return netlink_talk(netlink_talk_filter, &req.n, &zns->netlink_cmd, zns,
1527 0);
1528}
1529
718e3744 1530/* Interface information read by netlink. */
d62a17ae 1531void interface_list(struct zebra_ns *zns)
718e3744 1532{
d62a17ae 1533 interface_lookup_netlink(zns);
d9f5b2f5
SW
1534 /* We add routes for interface address,
1535 * so we need to get the nexthop info
1536 * from the kernel before we can do that
1537 */
81505946 1538 netlink_nexthop_read(zns);
cc4e0650 1539
d2bec88a 1540 interface_addr_lookup_netlink(zns);
718e3744 1541}
ddfeb486
DL
1542
1543#endif /* GNU_LINUX */