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