]> git.proxmox.com Git - mirror_frr.git/blob - zebra/if_netlink.c
*: reindent
[mirror_frr.git] / zebra / if_netlink.c
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 *
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
20 */
21
22 #include <zebra.h>
23
24 /* The following definition is to workaround an issue in the Linux kernel
25 * header files with redefinition of 'struct in6_addr' in both
26 * netinet/in.h and linux/in6.h.
27 * Reference - https://sourceware.org/ml/libc-alpha/2013-01/msg00599.html
28 */
29 #define _LINUX_IN6_H
30
31 #include <linux/if_bridge.h>
32 #include <net/if_arp.h>
33 #include <linux/sockios.h>
34 #include <linux/ethtool.h>
35
36 #include "linklist.h"
37 #include "if.h"
38 #include "log.h"
39 #include "prefix.h"
40 #include "connected.h"
41 #include "table.h"
42 #include "memory.h"
43 #include "zebra_memory.h"
44 #include "rib.h"
45 #include "thread.h"
46 #include "privs.h"
47 #include "nexthop.h"
48 #include "vrf.h"
49 #include "vrf_int.h"
50 #include "mpls.h"
51
52 #include "vty.h"
53 #include "zebra/zserv.h"
54 #include "zebra/zebra_ns.h"
55 #include "zebra/zebra_vrf.h"
56 #include "zebra/rt.h"
57 #include "zebra/redistribute.h"
58 #include "zebra/interface.h"
59 #include "zebra/debug.h"
60 #include "zebra/rtadv.h"
61 #include "zebra/zebra_ptm.h"
62 #include "zebra/zebra_mpls.h"
63 #include "zebra/kernel_netlink.h"
64 #include "zebra/if_netlink.h"
65
66
67 /* Note: on netlink systems, there should be a 1-to-1 mapping between interface
68 names and ifindex values. */
69 static void set_ifindex(struct interface *ifp, ifindex_t ifi_index,
70 struct zebra_ns *zns)
71 {
72 struct interface *oifp;
73
74 if (((oifp = if_lookup_by_index_per_ns(zns, ifi_index)) != NULL)
75 && (oifp != ifp)) {
76 if (ifi_index == IFINDEX_INTERNAL)
77 zlog_err(
78 "Netlink is setting interface %s ifindex to reserved "
79 "internal value %u",
80 ifp->name, ifi_index);
81 else {
82 if (IS_ZEBRA_DEBUG_KERNEL)
83 zlog_debug(
84 "interface index %d was renamed from %s to %s",
85 ifi_index, oifp->name, ifp->name);
86 if (if_is_up(oifp))
87 zlog_err(
88 "interface rename detected on up interface: index %d "
89 "was renamed from %s to %s, results are uncertain!",
90 ifi_index, oifp->name, ifp->name);
91 if_delete_update(oifp);
92 }
93 }
94 ifp->ifindex = ifi_index;
95 }
96
97 /* Utility function to parse hardware link-layer address and update ifp */
98 static void netlink_interface_update_hw_addr(struct rtattr **tb,
99 struct interface *ifp)
100 {
101 int i;
102
103 if (tb[IFLA_ADDRESS]) {
104 int hw_addr_len;
105
106 hw_addr_len = RTA_PAYLOAD(tb[IFLA_ADDRESS]);
107
108 if (hw_addr_len > INTERFACE_HWADDR_MAX)
109 zlog_warn("Hardware address is too large: %d",
110 hw_addr_len);
111 else {
112 ifp->hw_addr_len = hw_addr_len;
113 memcpy(ifp->hw_addr, RTA_DATA(tb[IFLA_ADDRESS]),
114 hw_addr_len);
115
116 for (i = 0; i < hw_addr_len; i++)
117 if (ifp->hw_addr[i] != 0)
118 break;
119
120 if (i == hw_addr_len)
121 ifp->hw_addr_len = 0;
122 else
123 ifp->hw_addr_len = hw_addr_len;
124 }
125 }
126 }
127
128 static enum zebra_link_type netlink_to_zebra_link_type(unsigned int hwt)
129 {
130 switch (hwt) {
131 case ARPHRD_ETHER:
132 return ZEBRA_LLT_ETHER;
133 case ARPHRD_EETHER:
134 return ZEBRA_LLT_EETHER;
135 case ARPHRD_AX25:
136 return ZEBRA_LLT_AX25;
137 case ARPHRD_PRONET:
138 return ZEBRA_LLT_PRONET;
139 case ARPHRD_IEEE802:
140 return ZEBRA_LLT_IEEE802;
141 case ARPHRD_ARCNET:
142 return ZEBRA_LLT_ARCNET;
143 case ARPHRD_APPLETLK:
144 return ZEBRA_LLT_APPLETLK;
145 case ARPHRD_DLCI:
146 return ZEBRA_LLT_DLCI;
147 case ARPHRD_ATM:
148 return ZEBRA_LLT_ATM;
149 case ARPHRD_METRICOM:
150 return ZEBRA_LLT_METRICOM;
151 case ARPHRD_IEEE1394:
152 return ZEBRA_LLT_IEEE1394;
153 case ARPHRD_EUI64:
154 return ZEBRA_LLT_EUI64;
155 case ARPHRD_INFINIBAND:
156 return ZEBRA_LLT_INFINIBAND;
157 case ARPHRD_SLIP:
158 return ZEBRA_LLT_SLIP;
159 case ARPHRD_CSLIP:
160 return ZEBRA_LLT_CSLIP;
161 case ARPHRD_SLIP6:
162 return ZEBRA_LLT_SLIP6;
163 case ARPHRD_CSLIP6:
164 return ZEBRA_LLT_CSLIP6;
165 case ARPHRD_RSRVD:
166 return ZEBRA_LLT_RSRVD;
167 case ARPHRD_ADAPT:
168 return ZEBRA_LLT_ADAPT;
169 case ARPHRD_ROSE:
170 return ZEBRA_LLT_ROSE;
171 case ARPHRD_X25:
172 return ZEBRA_LLT_X25;
173 case ARPHRD_PPP:
174 return ZEBRA_LLT_PPP;
175 case ARPHRD_CISCO:
176 return ZEBRA_LLT_CHDLC;
177 case ARPHRD_LAPB:
178 return ZEBRA_LLT_LAPB;
179 case ARPHRD_RAWHDLC:
180 return ZEBRA_LLT_RAWHDLC;
181 case ARPHRD_TUNNEL:
182 return ZEBRA_LLT_IPIP;
183 case ARPHRD_TUNNEL6:
184 return ZEBRA_LLT_IPIP6;
185 case ARPHRD_FRAD:
186 return ZEBRA_LLT_FRAD;
187 case ARPHRD_SKIP:
188 return ZEBRA_LLT_SKIP;
189 case ARPHRD_LOOPBACK:
190 return ZEBRA_LLT_LOOPBACK;
191 case ARPHRD_LOCALTLK:
192 return ZEBRA_LLT_LOCALTLK;
193 case ARPHRD_FDDI:
194 return ZEBRA_LLT_FDDI;
195 case ARPHRD_SIT:
196 return ZEBRA_LLT_SIT;
197 case ARPHRD_IPDDP:
198 return ZEBRA_LLT_IPDDP;
199 case ARPHRD_IPGRE:
200 return ZEBRA_LLT_IPGRE;
201 case ARPHRD_PIMREG:
202 return ZEBRA_LLT_PIMREG;
203 case ARPHRD_HIPPI:
204 return ZEBRA_LLT_HIPPI;
205 case ARPHRD_ECONET:
206 return ZEBRA_LLT_ECONET;
207 case ARPHRD_IRDA:
208 return ZEBRA_LLT_IRDA;
209 case ARPHRD_FCPP:
210 return ZEBRA_LLT_FCPP;
211 case ARPHRD_FCAL:
212 return ZEBRA_LLT_FCAL;
213 case ARPHRD_FCPL:
214 return ZEBRA_LLT_FCPL;
215 case ARPHRD_FCFABRIC:
216 return ZEBRA_LLT_FCFABRIC;
217 case ARPHRD_IEEE802_TR:
218 return ZEBRA_LLT_IEEE802_TR;
219 case ARPHRD_IEEE80211:
220 return ZEBRA_LLT_IEEE80211;
221 case ARPHRD_IEEE802154:
222 return ZEBRA_LLT_IEEE802154;
223 #ifdef ARPHRD_IP6GRE
224 case ARPHRD_IP6GRE:
225 return ZEBRA_LLT_IP6GRE;
226 #endif
227 #ifdef ARPHRD_IEEE802154_PHY
228 case ARPHRD_IEEE802154_PHY:
229 return ZEBRA_LLT_IEEE802154_PHY;
230 #endif
231
232 default:
233 return ZEBRA_LLT_UNKNOWN;
234 }
235 }
236
237 static void netlink_determine_zebra_iftype(char *kind, zebra_iftype_t *zif_type)
238 {
239 *zif_type = ZEBRA_IF_OTHER;
240
241 if (!kind)
242 return;
243
244 if (strcmp(kind, "vrf") == 0)
245 *zif_type = ZEBRA_IF_VRF;
246 else if (strcmp(kind, "bridge") == 0)
247 *zif_type = ZEBRA_IF_BRIDGE;
248 else if (strcmp(kind, "vlan") == 0)
249 *zif_type = ZEBRA_IF_VLAN;
250 else if (strcmp(kind, "vxlan") == 0)
251 *zif_type = ZEBRA_IF_VXLAN;
252 }
253
254 // Temporary Assignments to compile on older platforms.
255 #ifndef IFLA_BR_MAX
256 #define IFLA_BR_MAX 39
257 #endif
258
259 #ifndef IFLA_VXLAN_ID
260 #define IFLA_VXLAN_ID 1
261 #endif
262
263 #ifndef IFLA_VXLAN_LOCAL
264 #define IFLA_VXLAN_LOCAL 4
265 #endif
266
267 #ifndef IFLA_VXLAN_MAX
268 #define IFLA_VXLAN_MAX 26
269 #endif
270
271 #ifndef IFLA_BRIDGE_MAX
272 #define IFLA_BRIDGE_MAX 2
273 #endif
274
275 #ifndef IFLA_BRIDGE_VLAN_INFO
276 #define IFLA_BRIDGE_VLAN_INFO 2
277 #endif
278
279 #ifndef BRIDGE_VLAN_INFO_PVID
280 #define BRIDGE_VLAN_INFO_PVID (1<<1)
281 #endif
282
283 #ifndef RTEXT_FILTER_BRVLAN
284 #define RTEXT_FILTER_BRVLAN (1<<1)
285 #endif
286
287 #ifndef NTF_SELF
288 #define NTF_SELF 0x02
289 #endif
290
291 #ifndef IFLA_BR_VLAN_FILTERING
292 #define IFLA_BR_VLAN_FILTERING 7
293 #endif
294
295 #define parse_rtattr_nested(tb, max, rta) \
296 netlink_parse_rtattr((tb), (max), RTA_DATA(rta), RTA_PAYLOAD(rta))
297
298 static void netlink_vrf_change(struct nlmsghdr *h, struct rtattr *tb,
299 const char *name)
300 {
301 struct ifinfomsg *ifi;
302 struct rtattr *linkinfo[IFLA_INFO_MAX + 1];
303 struct rtattr *attr[IFLA_VRF_MAX + 1];
304 struct vrf *vrf;
305 struct zebra_vrf *zvrf;
306 u_int32_t nl_table_id;
307
308 ifi = NLMSG_DATA(h);
309
310 memset(linkinfo, 0, sizeof linkinfo);
311 parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb);
312
313 if (!linkinfo[IFLA_INFO_DATA]) {
314 if (IS_ZEBRA_DEBUG_KERNEL)
315 zlog_debug(
316 "%s: IFLA_INFO_DATA missing from VRF message: %s",
317 __func__, name);
318 return;
319 }
320
321 memset(attr, 0, sizeof attr);
322 parse_rtattr_nested(attr, IFLA_VRF_MAX, linkinfo[IFLA_INFO_DATA]);
323 if (!attr[IFLA_VRF_TABLE]) {
324 if (IS_ZEBRA_DEBUG_KERNEL)
325 zlog_debug(
326 "%s: IFLA_VRF_TABLE missing from VRF message: %s",
327 __func__, name);
328 return;
329 }
330
331 nl_table_id = *(u_int32_t *)RTA_DATA(attr[IFLA_VRF_TABLE]);
332
333 if (h->nlmsg_type == RTM_NEWLINK) {
334 if (IS_ZEBRA_DEBUG_KERNEL)
335 zlog_debug("RTM_NEWLINK for VRF %s(%u) table %u", name,
336 ifi->ifi_index, nl_table_id);
337
338 /*
339 * vrf_get is implied creation if it does not exist
340 */
341 vrf = vrf_get((vrf_id_t)ifi->ifi_index,
342 name); // It would create vrf
343 if (!vrf) {
344 zlog_err("VRF %s id %u not created", name,
345 ifi->ifi_index);
346 return;
347 }
348
349 /* Enable the created VRF. */
350 if (!vrf_enable(vrf)) {
351 zlog_err("Failed to enable VRF %s id %u", name,
352 ifi->ifi_index);
353 return;
354 }
355
356 /*
357 * This is the only place that we get the actual kernel table_id
358 * being used. We need it to set the table_id of the routes
359 * we are passing to the kernel.... And to throw some totally
360 * awesome parties. that too.
361 */
362 zvrf = (struct zebra_vrf *)vrf->info;
363 zvrf->table_id = nl_table_id;
364 } else // h->nlmsg_type == RTM_DELLINK
365 {
366 if (IS_ZEBRA_DEBUG_KERNEL)
367 zlog_debug("RTM_DELLINK for VRF %s(%u)", name,
368 ifi->ifi_index);
369
370 vrf = vrf_lookup_by_id((vrf_id_t)ifi->ifi_index);
371
372 if (!vrf) {
373 zlog_warn("%s: vrf not found", __func__);
374 return;
375 }
376
377 vrf_delete(vrf);
378 }
379 }
380
381 static int get_iflink_speed(const char *ifname)
382 {
383 struct ifreq ifdata;
384 struct ethtool_cmd ecmd;
385 int sd;
386 int rc;
387
388 /* initialize struct */
389 memset(&ifdata, 0, sizeof(ifdata));
390
391 /* set interface name */
392 strcpy(ifdata.ifr_name, ifname);
393
394 /* initialize ethtool interface */
395 memset(&ecmd, 0, sizeof(ecmd));
396 ecmd.cmd = ETHTOOL_GSET; /* ETHTOOL_GLINK */
397 ifdata.ifr_data = (__caddr_t)&ecmd;
398
399 /* use ioctl to get IP address of an interface */
400 sd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
401 if (sd < 0) {
402 zlog_debug("Failure to read interface %s speed: %d %s", ifname,
403 errno, safe_strerror(errno));
404 return 0;
405 }
406
407 /* Get the current link state for the interface */
408 rc = ioctl(sd, SIOCETHTOOL, (char *)&ifdata);
409 if (rc < 0) {
410 zlog_debug("IOCTL failure to read interface %s speed: %d %s",
411 ifname, errno, safe_strerror(errno));
412 ecmd.speed_hi = 0;
413 ecmd.speed = 0;
414 }
415
416 close(sd);
417
418 return (ecmd.speed_hi << 16) | ecmd.speed;
419 }
420
421 static int netlink_extract_bridge_info(struct rtattr *link_data,
422 struct zebra_l2info_bridge *bridge_info)
423 {
424 struct rtattr *attr[IFLA_BR_MAX + 1];
425
426 memset(bridge_info, 0, sizeof(*bridge_info));
427 memset(attr, 0, sizeof attr);
428 parse_rtattr_nested(attr, IFLA_BR_MAX, link_data);
429 if (attr[IFLA_BR_VLAN_FILTERING])
430 bridge_info->vlan_aware =
431 *(u_char *)RTA_DATA(attr[IFLA_BR_VLAN_FILTERING]);
432 return 0;
433 }
434
435 static int netlink_extract_vlan_info(struct rtattr *link_data,
436 struct zebra_l2info_vlan *vlan_info)
437 {
438 struct rtattr *attr[IFLA_VLAN_MAX + 1];
439 vlanid_t vid_in_msg;
440
441 memset(vlan_info, 0, sizeof(*vlan_info));
442 memset(attr, 0, sizeof attr);
443 parse_rtattr_nested(attr, IFLA_VLAN_MAX, link_data);
444 if (!attr[IFLA_VLAN_ID]) {
445 if (IS_ZEBRA_DEBUG_KERNEL)
446 zlog_debug("IFLA_VLAN_ID missing from VLAN IF message");
447 return -1;
448 }
449
450 vid_in_msg = *(vlanid_t *)RTA_DATA(attr[IFLA_VLAN_ID]);
451 vlan_info->vid = vid_in_msg;
452 return 0;
453 }
454
455 static int netlink_extract_vxlan_info(struct rtattr *link_data,
456 struct zebra_l2info_vxlan *vxl_info)
457 {
458 struct rtattr *attr[IFLA_VXLAN_MAX + 1];
459 vni_t vni_in_msg;
460 struct in_addr vtep_ip_in_msg;
461
462 memset(vxl_info, 0, sizeof(*vxl_info));
463 memset(attr, 0, sizeof attr);
464 parse_rtattr_nested(attr, IFLA_VXLAN_MAX, link_data);
465 if (!attr[IFLA_VXLAN_ID]) {
466 if (IS_ZEBRA_DEBUG_KERNEL)
467 zlog_debug(
468 "IFLA_VXLAN_ID missing from VXLAN IF message");
469 return -1;
470 }
471
472 vni_in_msg = *(vni_t *)RTA_DATA(attr[IFLA_VXLAN_ID]);
473 vxl_info->vni = vni_in_msg;
474 if (!attr[IFLA_VXLAN_LOCAL]) {
475 if (IS_ZEBRA_DEBUG_KERNEL)
476 zlog_debug(
477 "IFLA_VXLAN_LOCAL missing from VXLAN IF message");
478 } else {
479 vtep_ip_in_msg =
480 *(struct in_addr *)RTA_DATA(attr[IFLA_VXLAN_LOCAL]);
481 vxl_info->vtep_ip = vtep_ip_in_msg;
482 }
483
484 return 0;
485 }
486
487 /*
488 * Extract and save L2 params (of interest) for an interface. When a
489 * bridge interface is added or updated, take further actions to map
490 * its members. Likewise, for VxLAN interface.
491 */
492 static void netlink_interface_update_l2info(struct interface *ifp,
493 struct rtattr *link_data, int add)
494 {
495 if (!link_data)
496 return;
497
498 if (IS_ZEBRA_IF_BRIDGE(ifp)) {
499 struct zebra_l2info_bridge bridge_info;
500
501 netlink_extract_bridge_info(link_data, &bridge_info);
502 zebra_l2_bridge_add_update(ifp, &bridge_info, add);
503 } else if (IS_ZEBRA_IF_VLAN(ifp)) {
504 struct zebra_l2info_vlan vlan_info;
505
506 netlink_extract_vlan_info(link_data, &vlan_info);
507 zebra_l2_vlanif_update(ifp, &vlan_info);
508 } else if (IS_ZEBRA_IF_VXLAN(ifp)) {
509 struct zebra_l2info_vxlan vxlan_info;
510
511 netlink_extract_vxlan_info(link_data, &vxlan_info);
512 zebra_l2_vxlanif_add_update(ifp, &vxlan_info, add);
513 }
514 }
515
516 static int netlink_bridge_interface(struct nlmsghdr *h, int len, ns_id_t ns_id,
517 int startup)
518 {
519 char *name = NULL;
520 struct ifinfomsg *ifi;
521 struct rtattr *tb[IFLA_MAX + 1];
522 struct interface *ifp;
523 struct rtattr *aftb[IFLA_BRIDGE_MAX + 1];
524 struct {
525 u_int16_t flags;
526 u_int16_t vid;
527 } * vinfo;
528 vlanid_t access_vlan;
529
530 /* Fetch name and ifindex */
531 ifi = NLMSG_DATA(h);
532 memset(tb, 0, sizeof tb);
533 netlink_parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
534
535 if (tb[IFLA_IFNAME] == NULL)
536 return -1;
537 name = (char *)RTA_DATA(tb[IFLA_IFNAME]);
538
539 /* The interface should already be known, if not discard. */
540 ifp = if_lookup_by_index_per_ns(zebra_ns_lookup(ns_id), ifi->ifi_index);
541 if (!ifp) {
542 zlog_warn("Cannot find bridge IF %s(%u)", name, ifi->ifi_index);
543 return 0;
544 }
545 if (!IS_ZEBRA_IF_VXLAN(ifp))
546 return 0;
547
548 /* We are only interested in the access VLAN i.e., AF_SPEC */
549 if (!tb[IFLA_AF_SPEC])
550 return 0;
551
552 /* There is a 1-to-1 mapping of VLAN to VxLAN - hence
553 * only 1 access VLAN is accepted.
554 */
555 memset(aftb, 0, sizeof aftb);
556 parse_rtattr_nested(aftb, IFLA_BRIDGE_MAX, tb[IFLA_AF_SPEC]);
557 if (!aftb[IFLA_BRIDGE_VLAN_INFO])
558 return 0;
559
560 vinfo = RTA_DATA(aftb[IFLA_BRIDGE_VLAN_INFO]);
561 if (!(vinfo->flags & BRIDGE_VLAN_INFO_PVID))
562 return 0;
563
564 access_vlan = (vlanid_t)vinfo->vid;
565 if (IS_ZEBRA_DEBUG_KERNEL)
566 zlog_debug("Access VLAN %u for VxLAN IF %s(%u)", access_vlan,
567 name, ifi->ifi_index);
568 zebra_l2_vxlanif_update_access_vlan(ifp, access_vlan);
569 return 0;
570 }
571
572 /* Called from interface_lookup_netlink(). This function is only used
573 during bootstrap. */
574 static int netlink_interface(struct sockaddr_nl *snl, struct nlmsghdr *h,
575 ns_id_t ns_id, int startup)
576 {
577 int len;
578 struct ifinfomsg *ifi;
579 struct rtattr *tb[IFLA_MAX + 1];
580 struct rtattr *linkinfo[IFLA_MAX + 1];
581 struct interface *ifp;
582 char *name = NULL;
583 char *kind = NULL;
584 char *slave_kind = NULL;
585 struct zebra_ns *zns;
586 vrf_id_t vrf_id = VRF_DEFAULT;
587 zebra_iftype_t zif_type = ZEBRA_IF_OTHER;
588 zebra_slave_iftype_t zif_slave_type = ZEBRA_IF_SLAVE_NONE;
589 ifindex_t bridge_ifindex = IFINDEX_INTERNAL;
590 ifindex_t link_ifindex = IFINDEX_INTERNAL;
591
592 zns = zebra_ns_lookup(ns_id);
593 ifi = NLMSG_DATA(h);
594
595 if (h->nlmsg_type != RTM_NEWLINK)
596 return 0;
597
598 len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifinfomsg));
599 if (len < 0)
600 return -1;
601
602 /* We are interested in some AF_BRIDGE notifications. */
603 if (ifi->ifi_family == AF_BRIDGE)
604 return netlink_bridge_interface(h, len, ns_id, startup);
605
606 /* Looking up interface name. */
607 memset(tb, 0, sizeof tb);
608 memset(linkinfo, 0, sizeof linkinfo);
609 netlink_parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
610
611 #ifdef IFLA_WIRELESS
612 /* check for wireless messages to ignore */
613 if ((tb[IFLA_WIRELESS] != NULL) && (ifi->ifi_change == 0)) {
614 if (IS_ZEBRA_DEBUG_KERNEL)
615 zlog_debug("%s: ignoring IFLA_WIRELESS message",
616 __func__);
617 return 0;
618 }
619 #endif /* IFLA_WIRELESS */
620
621 if (tb[IFLA_IFNAME] == NULL)
622 return -1;
623 name = (char *)RTA_DATA(tb[IFLA_IFNAME]);
624
625 if (tb[IFLA_LINKINFO]) {
626 parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb[IFLA_LINKINFO]);
627
628 if (linkinfo[IFLA_INFO_KIND])
629 kind = RTA_DATA(linkinfo[IFLA_INFO_KIND]);
630
631 #if HAVE_DECL_IFLA_INFO_SLAVE_KIND
632 if (linkinfo[IFLA_INFO_SLAVE_KIND])
633 slave_kind = RTA_DATA(linkinfo[IFLA_INFO_SLAVE_KIND]);
634 #endif
635
636 netlink_determine_zebra_iftype(kind, &zif_type);
637 }
638
639 /* If VRF, create the VRF structure itself. */
640 if (zif_type == ZEBRA_IF_VRF) {
641 netlink_vrf_change(h, tb[IFLA_LINKINFO], name);
642 vrf_id = (vrf_id_t)ifi->ifi_index;
643 }
644
645 if (tb[IFLA_MASTER]) {
646 if (slave_kind && (strcmp(slave_kind, "vrf") == 0)) {
647 zif_slave_type = ZEBRA_IF_SLAVE_VRF;
648 vrf_id = *(u_int32_t *)RTA_DATA(tb[IFLA_MASTER]);
649 } else if (slave_kind && (strcmp(slave_kind, "bridge") == 0)) {
650 zif_slave_type = ZEBRA_IF_SLAVE_BRIDGE;
651 bridge_ifindex =
652 *(ifindex_t *)RTA_DATA(tb[IFLA_MASTER]);
653 } else
654 zif_slave_type = ZEBRA_IF_SLAVE_OTHER;
655 }
656
657 /* If linking to another interface, note it. */
658 if (tb[IFLA_LINK])
659 link_ifindex = *(ifindex_t *)RTA_DATA(tb[IFLA_LINK]);
660
661 /* Add interface. */
662 ifp = if_get_by_name(name, vrf_id);
663 set_ifindex(ifp, ifi->ifi_index, zns);
664 ifp->flags = ifi->ifi_flags & 0x0000fffff;
665 if (IS_ZEBRA_IF_VRF(ifp))
666 SET_FLAG(ifp->status, ZEBRA_INTERFACE_VRF_LOOPBACK);
667 ifp->mtu6 = ifp->mtu = *(uint32_t *)RTA_DATA(tb[IFLA_MTU]);
668 ifp->metric = 0;
669 ifp->speed = get_iflink_speed(name);
670 ifp->ptm_status = ZEBRA_PTM_STATUS_UNKNOWN;
671
672 /* Set zebra interface type */
673 zebra_if_set_ziftype(ifp, zif_type, zif_slave_type);
674
675 /* Update link. */
676 zebra_if_update_link(ifp, link_ifindex);
677
678 /* Hardware type and address. */
679 ifp->ll_type = netlink_to_zebra_link_type(ifi->ifi_type);
680 netlink_interface_update_hw_addr(tb, ifp);
681
682 if_add_update(ifp);
683
684 /* Extract and save L2 interface information, take additional actions.
685 */
686 netlink_interface_update_l2info(ifp, linkinfo[IFLA_INFO_DATA], 1);
687 if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp))
688 zebra_l2if_update_bridge_slave(ifp, bridge_ifindex);
689
690 return 0;
691 }
692
693 /* Request for specific interface or address information from the kernel */
694 static int netlink_request_intf_addr(struct zebra_ns *zns, int family, int type,
695 u_int32_t filter_mask)
696 {
697 struct {
698 struct nlmsghdr n;
699 struct ifinfomsg ifm;
700 char buf[256];
701 } req;
702
703 /* Form the request, specifying filter (rtattr) if needed. */
704 memset(&req, 0, sizeof(req));
705 req.n.nlmsg_type = type;
706 req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
707 req.ifm.ifi_family = family;
708
709 /* Include filter, if specified. */
710 if (filter_mask)
711 addattr32(&req.n, sizeof(req), IFLA_EXT_MASK, filter_mask);
712
713 return netlink_request(&zns->netlink_cmd, &req.n);
714 }
715
716 /* Interface lookup by netlink socket. */
717 int interface_lookup_netlink(struct zebra_ns *zns)
718 {
719 int ret;
720
721 /* Get interface information. */
722 ret = netlink_request_intf_addr(zns, AF_PACKET, RTM_GETLINK, 0);
723 if (ret < 0)
724 return ret;
725 ret = netlink_parse_info(netlink_interface, &zns->netlink_cmd, zns, 0,
726 1);
727 if (ret < 0)
728 return ret;
729
730 /* Get interface information - for bridge interfaces. */
731 ret = netlink_request_intf_addr(zns, AF_BRIDGE, RTM_GETLINK,
732 RTEXT_FILTER_BRVLAN);
733 if (ret < 0)
734 return ret;
735 ret = netlink_parse_info(netlink_interface, &zns->netlink_cmd, zns, 0,
736 0);
737 if (ret < 0)
738 return ret;
739
740 /* Get interface information - for bridge interfaces. */
741 ret = netlink_request_intf_addr(zns, AF_BRIDGE, RTM_GETLINK,
742 RTEXT_FILTER_BRVLAN);
743 if (ret < 0)
744 return ret;
745 ret = netlink_parse_info(netlink_interface, &zns->netlink_cmd, zns, 0,
746 0);
747 if (ret < 0)
748 return ret;
749
750 /* Get IPv4 address of the interfaces. */
751 ret = netlink_request_intf_addr(zns, AF_INET, RTM_GETADDR, 0);
752 if (ret < 0)
753 return ret;
754 ret = netlink_parse_info(netlink_interface_addr, &zns->netlink_cmd, zns,
755 0, 1);
756 if (ret < 0)
757 return ret;
758
759 /* Get IPv6 address of the interfaces. */
760 ret = netlink_request_intf_addr(zns, AF_INET6, RTM_GETADDR, 0);
761 if (ret < 0)
762 return ret;
763 ret = netlink_parse_info(netlink_interface_addr, &zns->netlink_cmd, zns,
764 0, 1);
765 if (ret < 0)
766 return ret;
767
768 return 0;
769 }
770
771 /* Interface address modification. */
772 static int netlink_address(int cmd, int family, struct interface *ifp,
773 struct connected *ifc)
774 {
775 int bytelen;
776 struct prefix *p;
777
778 struct {
779 struct nlmsghdr n;
780 struct ifaddrmsg ifa;
781 char buf[NL_PKT_BUF_SIZE];
782 } req;
783
784 struct zebra_ns *zns = zebra_ns_lookup(NS_DEFAULT);
785
786 p = ifc->address;
787 memset(&req, 0, sizeof req - NL_PKT_BUF_SIZE);
788
789 bytelen = (family == AF_INET ? 4 : 16);
790
791 req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
792 req.n.nlmsg_flags = NLM_F_REQUEST;
793 req.n.nlmsg_type = cmd;
794 req.n.nlmsg_pid = zns->netlink_cmd.snl.nl_pid;
795
796 req.ifa.ifa_family = family;
797
798 req.ifa.ifa_index = ifp->ifindex;
799 req.ifa.ifa_prefixlen = p->prefixlen;
800
801 addattr_l(&req.n, sizeof req, IFA_LOCAL, &p->u.prefix, bytelen);
802
803 if (family == AF_INET && cmd == RTM_NEWADDR) {
804 if (!CONNECTED_PEER(ifc) && ifc->destination) {
805 p = ifc->destination;
806 addattr_l(&req.n, sizeof req, IFA_BROADCAST,
807 &p->u.prefix, bytelen);
808 }
809 }
810
811 if (CHECK_FLAG(ifc->flags, ZEBRA_IFA_SECONDARY))
812 SET_FLAG(req.ifa.ifa_flags, IFA_F_SECONDARY);
813
814 if (ifc->label)
815 addattr_l(&req.n, sizeof req, IFA_LABEL, ifc->label,
816 strlen(ifc->label) + 1);
817
818 return netlink_talk(netlink_talk_filter, &req.n, &zns->netlink_cmd, zns,
819 0);
820 }
821
822 int kernel_address_add_ipv4(struct interface *ifp, struct connected *ifc)
823 {
824 return netlink_address(RTM_NEWADDR, AF_INET, ifp, ifc);
825 }
826
827 int kernel_address_delete_ipv4(struct interface *ifp, struct connected *ifc)
828 {
829 return netlink_address(RTM_DELADDR, AF_INET, ifp, ifc);
830 }
831
832 int netlink_interface_addr(struct sockaddr_nl *snl, struct nlmsghdr *h,
833 ns_id_t ns_id, int startup)
834 {
835 int len;
836 struct ifaddrmsg *ifa;
837 struct rtattr *tb[IFA_MAX + 1];
838 struct interface *ifp;
839 void *addr;
840 void *broad;
841 u_char flags = 0;
842 char *label = NULL;
843 struct zebra_ns *zns;
844
845 zns = zebra_ns_lookup(ns_id);
846 ifa = NLMSG_DATA(h);
847
848 if (ifa->ifa_family != AF_INET && ifa->ifa_family != AF_INET6)
849 return 0;
850
851 if (h->nlmsg_type != RTM_NEWADDR && h->nlmsg_type != RTM_DELADDR)
852 return 0;
853
854 len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifaddrmsg));
855 if (len < 0)
856 return -1;
857
858 memset(tb, 0, sizeof tb);
859 netlink_parse_rtattr(tb, IFA_MAX, IFA_RTA(ifa), len);
860
861 ifp = if_lookup_by_index_per_ns(zns, ifa->ifa_index);
862 if (ifp == NULL) {
863 zlog_err(
864 "netlink_interface_addr can't find interface by index %d",
865 ifa->ifa_index);
866 return -1;
867 }
868
869 if (IS_ZEBRA_DEBUG_KERNEL) /* remove this line to see initial ifcfg */
870 {
871 char buf[BUFSIZ];
872 zlog_debug("netlink_interface_addr %s %s flags 0x%x:",
873 nl_msg_type_to_str(h->nlmsg_type), ifp->name,
874 ifa->ifa_flags);
875 if (tb[IFA_LOCAL])
876 zlog_debug(" IFA_LOCAL %s/%d",
877 inet_ntop(ifa->ifa_family,
878 RTA_DATA(tb[IFA_LOCAL]), buf,
879 BUFSIZ),
880 ifa->ifa_prefixlen);
881 if (tb[IFA_ADDRESS])
882 zlog_debug(" IFA_ADDRESS %s/%d",
883 inet_ntop(ifa->ifa_family,
884 RTA_DATA(tb[IFA_ADDRESS]), buf,
885 BUFSIZ),
886 ifa->ifa_prefixlen);
887 if (tb[IFA_BROADCAST])
888 zlog_debug(" IFA_BROADCAST %s/%d",
889 inet_ntop(ifa->ifa_family,
890 RTA_DATA(tb[IFA_BROADCAST]), buf,
891 BUFSIZ),
892 ifa->ifa_prefixlen);
893 if (tb[IFA_LABEL] && strcmp(ifp->name, RTA_DATA(tb[IFA_LABEL])))
894 zlog_debug(" IFA_LABEL %s",
895 (char *)RTA_DATA(tb[IFA_LABEL]));
896
897 if (tb[IFA_CACHEINFO]) {
898 struct ifa_cacheinfo *ci = RTA_DATA(tb[IFA_CACHEINFO]);
899 zlog_debug(" IFA_CACHEINFO pref %d, valid %d",
900 ci->ifa_prefered, ci->ifa_valid);
901 }
902 }
903
904 /* logic copied from iproute2/ip/ipaddress.c:print_addrinfo() */
905 if (tb[IFA_LOCAL] == NULL)
906 tb[IFA_LOCAL] = tb[IFA_ADDRESS];
907 if (tb[IFA_ADDRESS] == NULL)
908 tb[IFA_ADDRESS] = tb[IFA_LOCAL];
909
910 /* local interface address */
911 addr = (tb[IFA_LOCAL] ? RTA_DATA(tb[IFA_LOCAL]) : NULL);
912
913 /* is there a peer address? */
914 if (tb[IFA_ADDRESS]
915 && memcmp(RTA_DATA(tb[IFA_ADDRESS]), RTA_DATA(tb[IFA_LOCAL]),
916 RTA_PAYLOAD(tb[IFA_ADDRESS]))) {
917 broad = RTA_DATA(tb[IFA_ADDRESS]);
918 SET_FLAG(flags, ZEBRA_IFA_PEER);
919 } else
920 /* seeking a broadcast address */
921 broad = (tb[IFA_BROADCAST] ? RTA_DATA(tb[IFA_BROADCAST])
922 : NULL);
923
924 /* addr is primary key, SOL if we don't have one */
925 if (addr == NULL) {
926 zlog_debug("%s: NULL address", __func__);
927 return -1;
928 }
929
930 /* Flags. */
931 if (ifa->ifa_flags & IFA_F_SECONDARY)
932 SET_FLAG(flags, ZEBRA_IFA_SECONDARY);
933
934 /* Label */
935 if (tb[IFA_LABEL])
936 label = (char *)RTA_DATA(tb[IFA_LABEL]);
937
938 if (ifp && label && strcmp(ifp->name, label) == 0)
939 label = NULL;
940
941 /* Register interface address to the interface. */
942 if (ifa->ifa_family == AF_INET) {
943 if (h->nlmsg_type == RTM_NEWADDR)
944 connected_add_ipv4(ifp, flags, (struct in_addr *)addr,
945 ifa->ifa_prefixlen,
946 (struct in_addr *)broad, label);
947 else
948 connected_delete_ipv4(
949 ifp, flags, (struct in_addr *)addr,
950 ifa->ifa_prefixlen, (struct in_addr *)broad);
951 }
952 if (ifa->ifa_family == AF_INET6) {
953 if (h->nlmsg_type == RTM_NEWADDR) {
954 /* Only consider valid addresses; we'll not get a
955 * notification from
956 * the kernel till IPv6 DAD has completed, but at init
957 * time, Quagga
958 * does query for and will receive all addresses.
959 */
960 if (!(ifa->ifa_flags
961 & (IFA_F_DADFAILED | IFA_F_TENTATIVE)))
962 connected_add_ipv6(
963 ifp, flags, (struct in6_addr *)addr,
964 ifa->ifa_prefixlen,
965 (struct in6_addr *)broad, label);
966 } else
967 connected_delete_ipv6(ifp, (struct in6_addr *)addr,
968 ifa->ifa_prefixlen,
969 (struct in6_addr *)broad);
970 }
971
972 return 0;
973 }
974
975 int netlink_link_change(struct sockaddr_nl *snl, struct nlmsghdr *h,
976 ns_id_t ns_id, int startup)
977 {
978 int len;
979 struct ifinfomsg *ifi;
980 struct rtattr *tb[IFLA_MAX + 1];
981 struct rtattr *linkinfo[IFLA_MAX + 1];
982 struct interface *ifp;
983 char *name = NULL;
984 char *kind = NULL;
985 char *slave_kind = NULL;
986 struct zebra_ns *zns;
987 vrf_id_t vrf_id = VRF_DEFAULT;
988 zebra_iftype_t zif_type = ZEBRA_IF_OTHER;
989 zebra_slave_iftype_t zif_slave_type = ZEBRA_IF_SLAVE_NONE;
990 ifindex_t bridge_ifindex = IFINDEX_INTERNAL;
991 ifindex_t link_ifindex = IFINDEX_INTERNAL;
992
993
994 zns = zebra_ns_lookup(ns_id);
995 ifi = NLMSG_DATA(h);
996
997 if (!(h->nlmsg_type == RTM_NEWLINK || h->nlmsg_type == RTM_DELLINK)) {
998 /* If this is not link add/delete message so print warning. */
999 zlog_warn("netlink_link_change: wrong kernel message %d",
1000 h->nlmsg_type);
1001 return 0;
1002 }
1003
1004 len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifinfomsg));
1005 if (len < 0)
1006 return -1;
1007
1008 /* We are interested in some AF_BRIDGE notifications. */
1009 if (ifi->ifi_family == AF_BRIDGE)
1010 return netlink_bridge_interface(h, len, ns_id, startup);
1011
1012 /* Looking up interface name. */
1013 memset(tb, 0, sizeof tb);
1014 memset(linkinfo, 0, sizeof linkinfo);
1015 netlink_parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
1016
1017 #ifdef IFLA_WIRELESS
1018 /* check for wireless messages to ignore */
1019 if ((tb[IFLA_WIRELESS] != NULL) && (ifi->ifi_change == 0)) {
1020 if (IS_ZEBRA_DEBUG_KERNEL)
1021 zlog_debug("%s: ignoring IFLA_WIRELESS message",
1022 __func__);
1023 return 0;
1024 }
1025 #endif /* IFLA_WIRELESS */
1026
1027 if (tb[IFLA_IFNAME] == NULL)
1028 return -1;
1029 name = (char *)RTA_DATA(tb[IFLA_IFNAME]);
1030
1031 if (tb[IFLA_LINKINFO]) {
1032 parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb[IFLA_LINKINFO]);
1033
1034 if (linkinfo[IFLA_INFO_KIND])
1035 kind = RTA_DATA(linkinfo[IFLA_INFO_KIND]);
1036
1037 #if HAVE_DECL_IFLA_INFO_SLAVE_KIND
1038 if (linkinfo[IFLA_INFO_SLAVE_KIND])
1039 slave_kind = RTA_DATA(linkinfo[IFLA_INFO_SLAVE_KIND]);
1040 #endif
1041
1042 netlink_determine_zebra_iftype(kind, &zif_type);
1043 }
1044
1045 /* If linking to another interface, note it. */
1046 if (tb[IFLA_LINK])
1047 link_ifindex = *(ifindex_t *)RTA_DATA(tb[IFLA_LINK]);
1048
1049 /* If VRF, create or update the VRF structure itself. */
1050 if (zif_type == ZEBRA_IF_VRF) {
1051 netlink_vrf_change(h, tb[IFLA_LINKINFO], name);
1052 vrf_id = (vrf_id_t)ifi->ifi_index;
1053 }
1054
1055 /* See if interface is present. */
1056 ifp = if_lookup_by_name_per_ns(zns, name);
1057
1058 if (h->nlmsg_type == RTM_NEWLINK) {
1059 if (tb[IFLA_MASTER]) {
1060 if (slave_kind && (strcmp(slave_kind, "vrf") == 0)) {
1061 zif_slave_type = ZEBRA_IF_SLAVE_VRF;
1062 vrf_id =
1063 *(u_int32_t *)RTA_DATA(tb[IFLA_MASTER]);
1064 } else if (slave_kind
1065 && (strcmp(slave_kind, "bridge") == 0)) {
1066 zif_slave_type = ZEBRA_IF_SLAVE_BRIDGE;
1067 bridge_ifindex =
1068 *(ifindex_t *)RTA_DATA(tb[IFLA_MASTER]);
1069 } else
1070 zif_slave_type = ZEBRA_IF_SLAVE_OTHER;
1071 }
1072
1073 if (ifp == NULL
1074 || !CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) {
1075 /* Add interface notification from kernel */
1076 if (IS_ZEBRA_DEBUG_KERNEL)
1077 zlog_debug(
1078 "RTM_NEWLINK ADD for %s(%u) vrf_id %u type %d "
1079 "sl_type %d master %u flags 0x%x",
1080 name, ifi->ifi_index, vrf_id, zif_type,
1081 zif_slave_type, bridge_ifindex,
1082 ifi->ifi_flags);
1083
1084 if (ifp == NULL) {
1085 /* unknown interface */
1086 ifp = if_get_by_name(name, vrf_id);
1087 } else {
1088 /* pre-configured interface, learnt now */
1089 if (ifp->vrf_id != vrf_id)
1090 if_update_to_new_vrf(ifp, vrf_id);
1091 }
1092
1093 /* Update interface information. */
1094 set_ifindex(ifp, ifi->ifi_index, zns);
1095 ifp->flags = ifi->ifi_flags & 0x0000fffff;
1096 if (IS_ZEBRA_IF_VRF(ifp))
1097 SET_FLAG(ifp->status,
1098 ZEBRA_INTERFACE_VRF_LOOPBACK);
1099 ifp->mtu6 = ifp->mtu = *(int *)RTA_DATA(tb[IFLA_MTU]);
1100 ifp->metric = 0;
1101 ifp->ptm_status = ZEBRA_PTM_STATUS_UNKNOWN;
1102
1103 /* Set interface type */
1104 zebra_if_set_ziftype(ifp, zif_type, zif_slave_type);
1105
1106 /* Update link. */
1107 zebra_if_update_link(ifp, link_ifindex);
1108
1109 netlink_interface_update_hw_addr(tb, ifp);
1110
1111 /* Inform clients, install any configured addresses. */
1112 if_add_update(ifp);
1113
1114 /* Extract and save L2 interface information, take
1115 * additional actions. */
1116 netlink_interface_update_l2info(
1117 ifp, linkinfo[IFLA_INFO_DATA], 1);
1118 if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp))
1119 zebra_l2if_update_bridge_slave(ifp,
1120 bridge_ifindex);
1121 } else if (ifp->vrf_id != vrf_id) {
1122 /* VRF change for an interface. */
1123 if (IS_ZEBRA_DEBUG_KERNEL)
1124 zlog_debug(
1125 "RTM_NEWLINK vrf-change for %s(%u) "
1126 "vrf_id %u -> %u flags 0x%x",
1127 name, ifp->ifindex, ifp->vrf_id, vrf_id,
1128 ifi->ifi_flags);
1129
1130 if_handle_vrf_change(ifp, vrf_id);
1131 } else {
1132 int was_bridge_slave;
1133
1134 /* Interface update. */
1135 if (IS_ZEBRA_DEBUG_KERNEL)
1136 zlog_debug(
1137 "RTM_NEWLINK update for %s(%u) "
1138 "sl_type %d master %u flags 0x%x",
1139 name, ifp->ifindex, zif_slave_type,
1140 bridge_ifindex, ifi->ifi_flags);
1141
1142 set_ifindex(ifp, ifi->ifi_index, zns);
1143 ifp->mtu6 = ifp->mtu = *(int *)RTA_DATA(tb[IFLA_MTU]);
1144 ifp->metric = 0;
1145
1146 /* Update interface type - NOTE: Only slave_type can
1147 * change. */
1148 was_bridge_slave = IS_ZEBRA_IF_BRIDGE_SLAVE(ifp);
1149 zebra_if_set_ziftype(ifp, zif_type, zif_slave_type);
1150
1151 netlink_interface_update_hw_addr(tb, ifp);
1152
1153 if (if_is_no_ptm_operative(ifp)) {
1154 ifp->flags = ifi->ifi_flags & 0x0000fffff;
1155 if (!if_is_no_ptm_operative(ifp)) {
1156 if (IS_ZEBRA_DEBUG_KERNEL)
1157 zlog_debug(
1158 "Intf %s(%u) has gone DOWN",
1159 name, ifp->ifindex);
1160 if_down(ifp);
1161 } else if (if_is_operative(ifp)) {
1162 /* Must notify client daemons of new
1163 * interface status. */
1164 if (IS_ZEBRA_DEBUG_KERNEL)
1165 zlog_debug(
1166 "Intf %s(%u) PTM up, notifying clients",
1167 name, ifp->ifindex);
1168 zebra_interface_up_update(ifp);
1169 }
1170 } else {
1171 ifp->flags = ifi->ifi_flags & 0x0000fffff;
1172 if (if_is_operative(ifp)) {
1173 if (IS_ZEBRA_DEBUG_KERNEL)
1174 zlog_debug(
1175 "Intf %s(%u) has come UP",
1176 name, ifp->ifindex);
1177 if_up(ifp);
1178 }
1179 }
1180
1181 /* Extract and save L2 interface information, take
1182 * additional actions. */
1183 netlink_interface_update_l2info(
1184 ifp, linkinfo[IFLA_INFO_DATA], 0);
1185 if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp) || was_bridge_slave)
1186 zebra_l2if_update_bridge_slave(ifp,
1187 bridge_ifindex);
1188 }
1189 } else {
1190 /* Delete interface notification from kernel */
1191 if (ifp == NULL) {
1192 zlog_warn("RTM_DELLINK for unknown interface %s(%u)",
1193 name, ifi->ifi_index);
1194 return 0;
1195 }
1196
1197 if (IS_ZEBRA_DEBUG_KERNEL)
1198 zlog_debug("RTM_DELLINK for %s(%u)", name,
1199 ifp->ifindex);
1200
1201 UNSET_FLAG(ifp->status, ZEBRA_INTERFACE_VRF_LOOPBACK);
1202
1203 /* Special handling for bridge or VxLAN interfaces. */
1204 if (IS_ZEBRA_IF_BRIDGE(ifp))
1205 zebra_l2_bridge_del(ifp);
1206 else if (IS_ZEBRA_IF_VXLAN(ifp))
1207 zebra_l2_vxlanif_del(ifp);
1208
1209 if (!IS_ZEBRA_IF_VRF(ifp))
1210 if_delete_update(ifp);
1211 }
1212
1213 return 0;
1214 }
1215
1216 /* Interface information read by netlink. */
1217 void interface_list(struct zebra_ns *zns)
1218 {
1219 interface_lookup_netlink(zns);
1220 }