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