]> git.proxmox.com Git - mirror_frr.git/blob - zebra/if_netlink.c
Merge pull request #1009 from donaldsharp/show_cmds
[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 else if (strcmp(kind, "macvlan") == 0)
255 *zif_type = ZEBRA_IF_MACVLAN;
256 }
257
258 // Temporary Assignments to compile on older platforms.
259 #ifndef IFLA_BR_MAX
260 #define IFLA_BR_MAX 39
261 #endif
262
263 #ifndef IFLA_VXLAN_ID
264 #define IFLA_VXLAN_ID 1
265 #endif
266
267 #ifndef IFLA_VXLAN_LOCAL
268 #define IFLA_VXLAN_LOCAL 4
269 #endif
270
271 #ifndef IFLA_VXLAN_MAX
272 #define IFLA_VXLAN_MAX 26
273 #endif
274
275 #ifndef IFLA_BRIDGE_MAX
276 #define IFLA_BRIDGE_MAX 2
277 #endif
278
279 #ifndef IFLA_BRIDGE_VLAN_INFO
280 #define IFLA_BRIDGE_VLAN_INFO 2
281 #endif
282
283 #ifndef BRIDGE_VLAN_INFO_PVID
284 #define BRIDGE_VLAN_INFO_PVID (1<<1)
285 #endif
286
287 #ifndef RTEXT_FILTER_BRVLAN
288 #define RTEXT_FILTER_BRVLAN (1<<1)
289 #endif
290
291 #ifndef NTF_SELF
292 #define NTF_SELF 0x02
293 #endif
294
295 #ifndef IFLA_BR_VLAN_FILTERING
296 #define IFLA_BR_VLAN_FILTERING 7
297 #endif
298
299 #define parse_rtattr_nested(tb, max, rta) \
300 netlink_parse_rtattr((tb), (max), RTA_DATA(rta), RTA_PAYLOAD(rta))
301
302 static void netlink_vrf_change(struct nlmsghdr *h, struct rtattr *tb,
303 const char *name)
304 {
305 struct ifinfomsg *ifi;
306 struct rtattr *linkinfo[IFLA_INFO_MAX + 1];
307 struct rtattr *attr[IFLA_VRF_MAX + 1];
308 struct vrf *vrf;
309 struct zebra_vrf *zvrf;
310 u_int32_t nl_table_id;
311
312 ifi = NLMSG_DATA(h);
313
314 memset(linkinfo, 0, sizeof linkinfo);
315 parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb);
316
317 if (!linkinfo[IFLA_INFO_DATA]) {
318 if (IS_ZEBRA_DEBUG_KERNEL)
319 zlog_debug(
320 "%s: IFLA_INFO_DATA missing from VRF message: %s",
321 __func__, name);
322 return;
323 }
324
325 memset(attr, 0, sizeof attr);
326 parse_rtattr_nested(attr, IFLA_VRF_MAX, linkinfo[IFLA_INFO_DATA]);
327 if (!attr[IFLA_VRF_TABLE]) {
328 if (IS_ZEBRA_DEBUG_KERNEL)
329 zlog_debug(
330 "%s: IFLA_VRF_TABLE missing from VRF message: %s",
331 __func__, name);
332 return;
333 }
334
335 nl_table_id = *(u_int32_t *)RTA_DATA(attr[IFLA_VRF_TABLE]);
336
337 if (h->nlmsg_type == RTM_NEWLINK) {
338 if (IS_ZEBRA_DEBUG_KERNEL)
339 zlog_debug("RTM_NEWLINK for VRF %s(%u) table %u", name,
340 ifi->ifi_index, nl_table_id);
341
342 /*
343 * vrf_get is implied creation if it does not exist
344 */
345 vrf = vrf_get((vrf_id_t)ifi->ifi_index,
346 name); // It would create vrf
347 if (!vrf) {
348 zlog_err("VRF %s id %u not created", name,
349 ifi->ifi_index);
350 return;
351 }
352
353 /* Enable the created VRF. */
354 if (!vrf_enable(vrf)) {
355 zlog_err("Failed to enable VRF %s id %u", name,
356 ifi->ifi_index);
357 return;
358 }
359
360 /*
361 * This is the only place that we get the actual kernel table_id
362 * being used. We need it to set the table_id of the routes
363 * we are passing to the kernel.... And to throw some totally
364 * awesome parties. that too.
365 */
366 zvrf = (struct zebra_vrf *)vrf->info;
367 zvrf->table_id = nl_table_id;
368 } else // h->nlmsg_type == RTM_DELLINK
369 {
370 if (IS_ZEBRA_DEBUG_KERNEL)
371 zlog_debug("RTM_DELLINK for VRF %s(%u)", name,
372 ifi->ifi_index);
373
374 vrf = vrf_lookup_by_id((vrf_id_t)ifi->ifi_index);
375
376 if (!vrf) {
377 zlog_warn("%s: vrf not found", __func__);
378 return;
379 }
380
381 vrf_delete(vrf);
382 }
383 }
384
385 static int get_iflink_speed(const char *ifname)
386 {
387 struct ifreq ifdata;
388 struct ethtool_cmd ecmd;
389 int sd;
390 int rc;
391
392 /* initialize struct */
393 memset(&ifdata, 0, sizeof(ifdata));
394
395 /* set interface name */
396 strcpy(ifdata.ifr_name, ifname);
397
398 /* initialize ethtool interface */
399 memset(&ecmd, 0, sizeof(ecmd));
400 ecmd.cmd = ETHTOOL_GSET; /* ETHTOOL_GLINK */
401 ifdata.ifr_data = (__caddr_t)&ecmd;
402
403 /* use ioctl to get IP address of an interface */
404 sd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
405 if (sd < 0) {
406 if (IS_ZEBRA_DEBUG_KERNEL)
407 zlog_debug("Failure to read interface %s speed: %d %s",
408 ifname, errno, safe_strerror(errno));
409 return 0;
410 }
411
412 /* Get the current link state for the interface */
413 rc = ioctl(sd, SIOCETHTOOL, (char *)&ifdata);
414 if (rc < 0) {
415 if (IS_ZEBRA_DEBUG_KERNEL)
416 zlog_debug(
417 "IOCTL failure to read interface %s speed: %d %s",
418 ifname, errno, safe_strerror(errno));
419 ecmd.speed_hi = 0;
420 ecmd.speed = 0;
421 }
422
423 close(sd);
424
425 return (ecmd.speed_hi << 16) | ecmd.speed;
426 }
427
428 static int netlink_extract_bridge_info(struct rtattr *link_data,
429 struct zebra_l2info_bridge *bridge_info)
430 {
431 struct rtattr *attr[IFLA_BR_MAX + 1];
432
433 memset(bridge_info, 0, sizeof(*bridge_info));
434 memset(attr, 0, sizeof attr);
435 parse_rtattr_nested(attr, IFLA_BR_MAX, link_data);
436 if (attr[IFLA_BR_VLAN_FILTERING])
437 bridge_info->vlan_aware =
438 *(u_char *)RTA_DATA(attr[IFLA_BR_VLAN_FILTERING]);
439 return 0;
440 }
441
442 static int netlink_extract_vlan_info(struct rtattr *link_data,
443 struct zebra_l2info_vlan *vlan_info)
444 {
445 struct rtattr *attr[IFLA_VLAN_MAX + 1];
446 vlanid_t vid_in_msg;
447
448 memset(vlan_info, 0, sizeof(*vlan_info));
449 memset(attr, 0, sizeof attr);
450 parse_rtattr_nested(attr, IFLA_VLAN_MAX, link_data);
451 if (!attr[IFLA_VLAN_ID]) {
452 if (IS_ZEBRA_DEBUG_KERNEL)
453 zlog_debug("IFLA_VLAN_ID missing from VLAN IF message");
454 return -1;
455 }
456
457 vid_in_msg = *(vlanid_t *)RTA_DATA(attr[IFLA_VLAN_ID]);
458 vlan_info->vid = vid_in_msg;
459 return 0;
460 }
461
462 static int netlink_extract_vxlan_info(struct rtattr *link_data,
463 struct zebra_l2info_vxlan *vxl_info)
464 {
465 struct rtattr *attr[IFLA_VXLAN_MAX + 1];
466 vni_t vni_in_msg;
467 struct in_addr vtep_ip_in_msg;
468
469 memset(vxl_info, 0, sizeof(*vxl_info));
470 memset(attr, 0, sizeof attr);
471 parse_rtattr_nested(attr, IFLA_VXLAN_MAX, link_data);
472 if (!attr[IFLA_VXLAN_ID]) {
473 if (IS_ZEBRA_DEBUG_KERNEL)
474 zlog_debug(
475 "IFLA_VXLAN_ID missing from VXLAN IF message");
476 return -1;
477 }
478
479 vni_in_msg = *(vni_t *)RTA_DATA(attr[IFLA_VXLAN_ID]);
480 vxl_info->vni = vni_in_msg;
481 if (!attr[IFLA_VXLAN_LOCAL]) {
482 if (IS_ZEBRA_DEBUG_KERNEL)
483 zlog_debug(
484 "IFLA_VXLAN_LOCAL missing from VXLAN IF message");
485 } else {
486 vtep_ip_in_msg =
487 *(struct in_addr *)RTA_DATA(attr[IFLA_VXLAN_LOCAL]);
488 vxl_info->vtep_ip = vtep_ip_in_msg;
489 }
490
491 return 0;
492 }
493
494 /*
495 * Extract and save L2 params (of interest) for an interface. When a
496 * bridge interface is added or updated, take further actions to map
497 * its members. Likewise, for VxLAN interface.
498 */
499 static void netlink_interface_update_l2info(struct interface *ifp,
500 struct rtattr *link_data, int add)
501 {
502 if (!link_data)
503 return;
504
505 if (IS_ZEBRA_IF_BRIDGE(ifp)) {
506 struct zebra_l2info_bridge bridge_info;
507
508 netlink_extract_bridge_info(link_data, &bridge_info);
509 zebra_l2_bridge_add_update(ifp, &bridge_info, add);
510 } else if (IS_ZEBRA_IF_VLAN(ifp)) {
511 struct zebra_l2info_vlan vlan_info;
512
513 netlink_extract_vlan_info(link_data, &vlan_info);
514 zebra_l2_vlanif_update(ifp, &vlan_info);
515 } else if (IS_ZEBRA_IF_VXLAN(ifp)) {
516 struct zebra_l2info_vxlan vxlan_info;
517
518 netlink_extract_vxlan_info(link_data, &vxlan_info);
519 zebra_l2_vxlanif_add_update(ifp, &vxlan_info, add);
520 }
521 }
522
523 static int netlink_bridge_interface(struct nlmsghdr *h, int len, ns_id_t ns_id,
524 int startup)
525 {
526 char *name = NULL;
527 struct ifinfomsg *ifi;
528 struct rtattr *tb[IFLA_MAX + 1];
529 struct interface *ifp;
530 struct rtattr *aftb[IFLA_BRIDGE_MAX + 1];
531 struct {
532 u_int16_t flags;
533 u_int16_t vid;
534 } * vinfo;
535 vlanid_t access_vlan;
536
537 /* Fetch name and ifindex */
538 ifi = NLMSG_DATA(h);
539 memset(tb, 0, sizeof tb);
540 netlink_parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
541
542 if (tb[IFLA_IFNAME] == NULL)
543 return -1;
544 name = (char *)RTA_DATA(tb[IFLA_IFNAME]);
545
546 /* The interface should already be known, if not discard. */
547 ifp = if_lookup_by_index_per_ns(zebra_ns_lookup(ns_id), ifi->ifi_index);
548 if (!ifp) {
549 zlog_warn("Cannot find bridge IF %s(%u)", name, ifi->ifi_index);
550 return 0;
551 }
552 if (!IS_ZEBRA_IF_VXLAN(ifp))
553 return 0;
554
555 /* We are only interested in the access VLAN i.e., AF_SPEC */
556 if (!tb[IFLA_AF_SPEC])
557 return 0;
558
559 /* There is a 1-to-1 mapping of VLAN to VxLAN - hence
560 * only 1 access VLAN is accepted.
561 */
562 memset(aftb, 0, sizeof aftb);
563 parse_rtattr_nested(aftb, IFLA_BRIDGE_MAX, tb[IFLA_AF_SPEC]);
564 if (!aftb[IFLA_BRIDGE_VLAN_INFO])
565 return 0;
566
567 vinfo = RTA_DATA(aftb[IFLA_BRIDGE_VLAN_INFO]);
568 if (!(vinfo->flags & BRIDGE_VLAN_INFO_PVID))
569 return 0;
570
571 access_vlan = (vlanid_t)vinfo->vid;
572 if (IS_ZEBRA_DEBUG_KERNEL)
573 zlog_debug("Access VLAN %u for VxLAN IF %s(%u)", access_vlan,
574 name, ifi->ifi_index);
575 zebra_l2_vxlanif_update_access_vlan(ifp, access_vlan);
576 return 0;
577 }
578
579 /* Called from interface_lookup_netlink(). This function is only used
580 during bootstrap. */
581 static int netlink_interface(struct sockaddr_nl *snl, struct nlmsghdr *h,
582 ns_id_t ns_id, int startup)
583 {
584 int len;
585 struct ifinfomsg *ifi;
586 struct rtattr *tb[IFLA_MAX + 1];
587 struct rtattr *linkinfo[IFLA_MAX + 1];
588 struct interface *ifp;
589 char *name = NULL;
590 char *kind = NULL;
591 char *slave_kind = NULL;
592 struct zebra_ns *zns;
593 vrf_id_t vrf_id = VRF_DEFAULT;
594 zebra_iftype_t zif_type = ZEBRA_IF_OTHER;
595 zebra_slave_iftype_t zif_slave_type = ZEBRA_IF_SLAVE_NONE;
596 ifindex_t bridge_ifindex = IFINDEX_INTERNAL;
597 ifindex_t link_ifindex = IFINDEX_INTERNAL;
598
599 zns = zebra_ns_lookup(ns_id);
600 ifi = NLMSG_DATA(h);
601
602 if (h->nlmsg_type != RTM_NEWLINK)
603 return 0;
604
605 len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifinfomsg));
606 if (len < 0)
607 return -1;
608
609 /* We are interested in some AF_BRIDGE notifications. */
610 if (ifi->ifi_family == AF_BRIDGE)
611 return netlink_bridge_interface(h, len, ns_id, startup);
612
613 /* Looking up interface name. */
614 memset(tb, 0, sizeof tb);
615 memset(linkinfo, 0, sizeof linkinfo);
616 netlink_parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
617
618 #ifdef IFLA_WIRELESS
619 /* check for wireless messages to ignore */
620 if ((tb[IFLA_WIRELESS] != NULL) && (ifi->ifi_change == 0)) {
621 if (IS_ZEBRA_DEBUG_KERNEL)
622 zlog_debug("%s: ignoring IFLA_WIRELESS message",
623 __func__);
624 return 0;
625 }
626 #endif /* IFLA_WIRELESS */
627
628 if (tb[IFLA_IFNAME] == NULL)
629 return -1;
630 name = (char *)RTA_DATA(tb[IFLA_IFNAME]);
631
632 if (tb[IFLA_LINKINFO]) {
633 parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb[IFLA_LINKINFO]);
634
635 if (linkinfo[IFLA_INFO_KIND])
636 kind = RTA_DATA(linkinfo[IFLA_INFO_KIND]);
637
638 #if HAVE_DECL_IFLA_INFO_SLAVE_KIND
639 if (linkinfo[IFLA_INFO_SLAVE_KIND])
640 slave_kind = RTA_DATA(linkinfo[IFLA_INFO_SLAVE_KIND]);
641 #endif
642
643 netlink_determine_zebra_iftype(kind, &zif_type);
644 }
645
646 /* If VRF, create the VRF structure itself. */
647 if (zif_type == ZEBRA_IF_VRF) {
648 netlink_vrf_change(h, tb[IFLA_LINKINFO], name);
649 vrf_id = (vrf_id_t)ifi->ifi_index;
650 }
651
652 if (tb[IFLA_MASTER]) {
653 if (slave_kind && (strcmp(slave_kind, "vrf") == 0)) {
654 zif_slave_type = ZEBRA_IF_SLAVE_VRF;
655 vrf_id = *(u_int32_t *)RTA_DATA(tb[IFLA_MASTER]);
656 } else if (slave_kind && (strcmp(slave_kind, "bridge") == 0)) {
657 zif_slave_type = ZEBRA_IF_SLAVE_BRIDGE;
658 bridge_ifindex =
659 *(ifindex_t *)RTA_DATA(tb[IFLA_MASTER]);
660 } else
661 zif_slave_type = ZEBRA_IF_SLAVE_OTHER;
662 }
663
664 /* If linking to another interface, note it. */
665 if (tb[IFLA_LINK])
666 link_ifindex = *(ifindex_t *)RTA_DATA(tb[IFLA_LINK]);
667
668 /* Add interface. */
669 ifp = if_get_by_name(name, vrf_id);
670 set_ifindex(ifp, ifi->ifi_index, zns);
671 ifp->flags = ifi->ifi_flags & 0x0000fffff;
672 if (IS_ZEBRA_IF_VRF(ifp))
673 SET_FLAG(ifp->status, ZEBRA_INTERFACE_VRF_LOOPBACK);
674 ifp->mtu6 = ifp->mtu = *(uint32_t *)RTA_DATA(tb[IFLA_MTU]);
675 ifp->metric = 0;
676 ifp->speed = get_iflink_speed(name);
677 ifp->ptm_status = ZEBRA_PTM_STATUS_UNKNOWN;
678
679 /* Set zebra interface type */
680 zebra_if_set_ziftype(ifp, zif_type, zif_slave_type);
681
682 /* Update link. */
683 zebra_if_update_link(ifp, link_ifindex);
684
685 /* Hardware type and address. */
686 ifp->ll_type = netlink_to_zebra_link_type(ifi->ifi_type);
687 netlink_interface_update_hw_addr(tb, ifp);
688
689 if_add_update(ifp);
690
691 /* Extract and save L2 interface information, take additional actions.
692 */
693 netlink_interface_update_l2info(ifp, linkinfo[IFLA_INFO_DATA], 1);
694 if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp))
695 zebra_l2if_update_bridge_slave(ifp, bridge_ifindex);
696
697 return 0;
698 }
699
700 /* Request for specific interface or address information from the kernel */
701 static int netlink_request_intf_addr(struct zebra_ns *zns, int family, int type,
702 u_int32_t filter_mask)
703 {
704 struct {
705 struct nlmsghdr n;
706 struct ifinfomsg ifm;
707 char buf[256];
708 } req;
709
710 /* Form the request, specifying filter (rtattr) if needed. */
711 memset(&req, 0, sizeof(req));
712 req.n.nlmsg_type = type;
713 req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
714 req.ifm.ifi_family = family;
715
716 /* Include filter, if specified. */
717 if (filter_mask)
718 addattr32(&req.n, sizeof(req), IFLA_EXT_MASK, filter_mask);
719
720 return netlink_request(&zns->netlink_cmd, &req.n);
721 }
722
723 /* Interface lookup by netlink socket. */
724 int interface_lookup_netlink(struct zebra_ns *zns)
725 {
726 int ret;
727
728 /* Get interface information. */
729 ret = netlink_request_intf_addr(zns, AF_PACKET, RTM_GETLINK, 0);
730 if (ret < 0)
731 return ret;
732 ret = netlink_parse_info(netlink_interface, &zns->netlink_cmd, zns, 0,
733 1);
734 if (ret < 0)
735 return ret;
736
737 /* Get interface information - for bridge interfaces. */
738 ret = netlink_request_intf_addr(zns, AF_BRIDGE, RTM_GETLINK,
739 RTEXT_FILTER_BRVLAN);
740 if (ret < 0)
741 return ret;
742 ret = netlink_parse_info(netlink_interface, &zns->netlink_cmd, zns, 0,
743 0);
744 if (ret < 0)
745 return ret;
746
747 /* Get interface information - for bridge interfaces. */
748 ret = netlink_request_intf_addr(zns, AF_BRIDGE, RTM_GETLINK,
749 RTEXT_FILTER_BRVLAN);
750 if (ret < 0)
751 return ret;
752 ret = netlink_parse_info(netlink_interface, &zns->netlink_cmd, zns, 0,
753 0);
754 if (ret < 0)
755 return ret;
756
757 /* Get IPv4 address of the interfaces. */
758 ret = netlink_request_intf_addr(zns, AF_INET, RTM_GETADDR, 0);
759 if (ret < 0)
760 return ret;
761 ret = netlink_parse_info(netlink_interface_addr, &zns->netlink_cmd, zns,
762 0, 1);
763 if (ret < 0)
764 return ret;
765
766 /* Get IPv6 address of the interfaces. */
767 ret = netlink_request_intf_addr(zns, AF_INET6, RTM_GETADDR, 0);
768 if (ret < 0)
769 return ret;
770 ret = netlink_parse_info(netlink_interface_addr, &zns->netlink_cmd, zns,
771 0, 1);
772 if (ret < 0)
773 return ret;
774
775 return 0;
776 }
777
778 int kernel_interface_set_master(struct interface *master,
779 struct interface *slave)
780 {
781 struct zebra_ns *zns = zebra_ns_lookup(NS_DEFAULT);
782
783 struct {
784 struct nlmsghdr n;
785 struct ifinfomsg ifa;
786 char buf[NL_PKT_BUF_SIZE];
787 } req;
788
789 memset(&req, 0, sizeof req);
790
791 req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
792 req.n.nlmsg_flags = NLM_F_REQUEST;
793 req.n.nlmsg_type = RTM_SETLINK;
794 req.n.nlmsg_pid = zns->netlink_cmd.snl.nl_pid;
795
796 req.ifa.ifi_index = slave->ifindex;
797
798 addattr_l(&req.n, sizeof req, IFLA_MASTER, &master->ifindex, 4);
799 addattr_l(&req.n, sizeof req, IFLA_LINK, &slave->ifindex, 4);
800
801 return netlink_talk(netlink_talk_filter, &req.n, &zns->netlink_cmd, zns,
802 0);
803 }
804
805 /* Interface address modification. */
806 static int netlink_address(int cmd, int family, struct interface *ifp,
807 struct connected *ifc)
808 {
809 int bytelen;
810 struct prefix *p;
811
812 struct {
813 struct nlmsghdr n;
814 struct ifaddrmsg ifa;
815 char buf[NL_PKT_BUF_SIZE];
816 } req;
817
818 struct zebra_ns *zns = zebra_ns_lookup(NS_DEFAULT);
819
820 p = ifc->address;
821 memset(&req, 0, sizeof req - NL_PKT_BUF_SIZE);
822
823 bytelen = (family == AF_INET ? 4 : 16);
824
825 req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
826 req.n.nlmsg_flags = NLM_F_REQUEST;
827 req.n.nlmsg_type = cmd;
828 req.n.nlmsg_pid = zns->netlink_cmd.snl.nl_pid;
829
830 req.ifa.ifa_family = family;
831
832 req.ifa.ifa_index = ifp->ifindex;
833 req.ifa.ifa_prefixlen = p->prefixlen;
834
835 addattr_l(&req.n, sizeof req, IFA_LOCAL, &p->u.prefix, bytelen);
836
837 if (family == AF_INET && cmd == RTM_NEWADDR) {
838 if (!CONNECTED_PEER(ifc) && ifc->destination) {
839 p = ifc->destination;
840 addattr_l(&req.n, sizeof req, IFA_BROADCAST,
841 &p->u.prefix, bytelen);
842 }
843 }
844
845 if (CHECK_FLAG(ifc->flags, ZEBRA_IFA_SECONDARY))
846 SET_FLAG(req.ifa.ifa_flags, IFA_F_SECONDARY);
847
848 if (ifc->label)
849 addattr_l(&req.n, sizeof req, IFA_LABEL, ifc->label,
850 strlen(ifc->label) + 1);
851
852 return netlink_talk(netlink_talk_filter, &req.n, &zns->netlink_cmd, zns,
853 0);
854 }
855
856 int kernel_address_add_ipv4(struct interface *ifp, struct connected *ifc)
857 {
858 return netlink_address(RTM_NEWADDR, AF_INET, ifp, ifc);
859 }
860
861 int kernel_address_delete_ipv4(struct interface *ifp, struct connected *ifc)
862 {
863 return netlink_address(RTM_DELADDR, AF_INET, ifp, ifc);
864 }
865
866 int netlink_interface_addr(struct sockaddr_nl *snl, struct nlmsghdr *h,
867 ns_id_t ns_id, int startup)
868 {
869 int len;
870 struct ifaddrmsg *ifa;
871 struct rtattr *tb[IFA_MAX + 1];
872 struct interface *ifp;
873 void *addr;
874 void *broad;
875 u_char flags = 0;
876 char *label = NULL;
877 struct zebra_ns *zns;
878
879 zns = zebra_ns_lookup(ns_id);
880 ifa = NLMSG_DATA(h);
881
882 if (ifa->ifa_family != AF_INET && ifa->ifa_family != AF_INET6)
883 return 0;
884
885 if (h->nlmsg_type != RTM_NEWADDR && h->nlmsg_type != RTM_DELADDR)
886 return 0;
887
888 len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifaddrmsg));
889 if (len < 0)
890 return -1;
891
892 memset(tb, 0, sizeof tb);
893 netlink_parse_rtattr(tb, IFA_MAX, IFA_RTA(ifa), len);
894
895 ifp = if_lookup_by_index_per_ns(zns, ifa->ifa_index);
896 if (ifp == NULL) {
897 zlog_err(
898 "netlink_interface_addr can't find interface by index %d",
899 ifa->ifa_index);
900 return -1;
901 }
902
903 if (IS_ZEBRA_DEBUG_KERNEL) /* remove this line to see initial ifcfg */
904 {
905 char buf[BUFSIZ];
906 zlog_debug("netlink_interface_addr %s %s flags 0x%x:",
907 nl_msg_type_to_str(h->nlmsg_type), ifp->name,
908 ifa->ifa_flags);
909 if (tb[IFA_LOCAL])
910 zlog_debug(" IFA_LOCAL %s/%d",
911 inet_ntop(ifa->ifa_family,
912 RTA_DATA(tb[IFA_LOCAL]), buf,
913 BUFSIZ),
914 ifa->ifa_prefixlen);
915 if (tb[IFA_ADDRESS])
916 zlog_debug(" IFA_ADDRESS %s/%d",
917 inet_ntop(ifa->ifa_family,
918 RTA_DATA(tb[IFA_ADDRESS]), buf,
919 BUFSIZ),
920 ifa->ifa_prefixlen);
921 if (tb[IFA_BROADCAST])
922 zlog_debug(" IFA_BROADCAST %s/%d",
923 inet_ntop(ifa->ifa_family,
924 RTA_DATA(tb[IFA_BROADCAST]), buf,
925 BUFSIZ),
926 ifa->ifa_prefixlen);
927 if (tb[IFA_LABEL] && strcmp(ifp->name, RTA_DATA(tb[IFA_LABEL])))
928 zlog_debug(" IFA_LABEL %s",
929 (char *)RTA_DATA(tb[IFA_LABEL]));
930
931 if (tb[IFA_CACHEINFO]) {
932 struct ifa_cacheinfo *ci = RTA_DATA(tb[IFA_CACHEINFO]);
933 zlog_debug(" IFA_CACHEINFO pref %d, valid %d",
934 ci->ifa_prefered, ci->ifa_valid);
935 }
936 }
937
938 /* logic copied from iproute2/ip/ipaddress.c:print_addrinfo() */
939 if (tb[IFA_LOCAL] == NULL)
940 tb[IFA_LOCAL] = tb[IFA_ADDRESS];
941 if (tb[IFA_ADDRESS] == NULL)
942 tb[IFA_ADDRESS] = tb[IFA_LOCAL];
943
944 /* local interface address */
945 addr = (tb[IFA_LOCAL] ? RTA_DATA(tb[IFA_LOCAL]) : NULL);
946
947 /* is there a peer address? */
948 if (tb[IFA_ADDRESS]
949 && memcmp(RTA_DATA(tb[IFA_ADDRESS]), RTA_DATA(tb[IFA_LOCAL]),
950 RTA_PAYLOAD(tb[IFA_ADDRESS]))) {
951 broad = RTA_DATA(tb[IFA_ADDRESS]);
952 SET_FLAG(flags, ZEBRA_IFA_PEER);
953 } else
954 /* seeking a broadcast address */
955 broad = (tb[IFA_BROADCAST] ? RTA_DATA(tb[IFA_BROADCAST])
956 : NULL);
957
958 /* addr is primary key, SOL if we don't have one */
959 if (addr == NULL) {
960 zlog_debug("%s: NULL address", __func__);
961 return -1;
962 }
963
964 /* Flags. */
965 if (ifa->ifa_flags & IFA_F_SECONDARY)
966 SET_FLAG(flags, ZEBRA_IFA_SECONDARY);
967
968 /* Label */
969 if (tb[IFA_LABEL])
970 label = (char *)RTA_DATA(tb[IFA_LABEL]);
971
972 if (ifp && label && strcmp(ifp->name, label) == 0)
973 label = NULL;
974
975 /* Register interface address to the interface. */
976 if (ifa->ifa_family == AF_INET) {
977 if (h->nlmsg_type == RTM_NEWADDR)
978 connected_add_ipv4(ifp, flags, (struct in_addr *)addr,
979 ifa->ifa_prefixlen,
980 (struct in_addr *)broad, label);
981 else
982 connected_delete_ipv4(
983 ifp, flags, (struct in_addr *)addr,
984 ifa->ifa_prefixlen, (struct in_addr *)broad);
985 }
986 if (ifa->ifa_family == AF_INET6) {
987 if (h->nlmsg_type == RTM_NEWADDR) {
988 /* Only consider valid addresses; we'll not get a
989 * notification from
990 * the kernel till IPv6 DAD has completed, but at init
991 * time, Quagga
992 * does query for and will receive all addresses.
993 */
994 if (!(ifa->ifa_flags
995 & (IFA_F_DADFAILED | IFA_F_TENTATIVE)))
996 connected_add_ipv6(
997 ifp, flags, (struct in6_addr *)addr,
998 ifa->ifa_prefixlen,
999 (struct in6_addr *)broad, label);
1000 } else
1001 connected_delete_ipv6(ifp, (struct in6_addr *)addr,
1002 ifa->ifa_prefixlen,
1003 (struct in6_addr *)broad);
1004 }
1005
1006 return 0;
1007 }
1008
1009 int netlink_link_change(struct sockaddr_nl *snl, struct nlmsghdr *h,
1010 ns_id_t ns_id, int startup)
1011 {
1012 int len;
1013 struct ifinfomsg *ifi;
1014 struct rtattr *tb[IFLA_MAX + 1];
1015 struct rtattr *linkinfo[IFLA_MAX + 1];
1016 struct interface *ifp;
1017 char *name = NULL;
1018 char *kind = NULL;
1019 char *slave_kind = NULL;
1020 struct zebra_ns *zns;
1021 vrf_id_t vrf_id = VRF_DEFAULT;
1022 zebra_iftype_t zif_type = ZEBRA_IF_OTHER;
1023 zebra_slave_iftype_t zif_slave_type = ZEBRA_IF_SLAVE_NONE;
1024 ifindex_t bridge_ifindex = IFINDEX_INTERNAL;
1025 ifindex_t link_ifindex = IFINDEX_INTERNAL;
1026
1027
1028 zns = zebra_ns_lookup(ns_id);
1029 ifi = NLMSG_DATA(h);
1030
1031 if (!(h->nlmsg_type == RTM_NEWLINK || h->nlmsg_type == RTM_DELLINK)) {
1032 /* If this is not link add/delete message so print warning. */
1033 zlog_warn("netlink_link_change: wrong kernel message %d",
1034 h->nlmsg_type);
1035 return 0;
1036 }
1037
1038 len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifinfomsg));
1039 if (len < 0)
1040 return -1;
1041
1042 /* We are interested in some AF_BRIDGE notifications. */
1043 if (ifi->ifi_family == AF_BRIDGE)
1044 return netlink_bridge_interface(h, len, ns_id, startup);
1045
1046 /* Looking up interface name. */
1047 memset(tb, 0, sizeof tb);
1048 memset(linkinfo, 0, sizeof linkinfo);
1049 netlink_parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
1050
1051 #ifdef IFLA_WIRELESS
1052 /* check for wireless messages to ignore */
1053 if ((tb[IFLA_WIRELESS] != NULL) && (ifi->ifi_change == 0)) {
1054 if (IS_ZEBRA_DEBUG_KERNEL)
1055 zlog_debug("%s: ignoring IFLA_WIRELESS message",
1056 __func__);
1057 return 0;
1058 }
1059 #endif /* IFLA_WIRELESS */
1060
1061 if (tb[IFLA_IFNAME] == NULL)
1062 return -1;
1063 name = (char *)RTA_DATA(tb[IFLA_IFNAME]);
1064
1065 if (tb[IFLA_LINKINFO]) {
1066 parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb[IFLA_LINKINFO]);
1067
1068 if (linkinfo[IFLA_INFO_KIND])
1069 kind = RTA_DATA(linkinfo[IFLA_INFO_KIND]);
1070
1071 #if HAVE_DECL_IFLA_INFO_SLAVE_KIND
1072 if (linkinfo[IFLA_INFO_SLAVE_KIND])
1073 slave_kind = RTA_DATA(linkinfo[IFLA_INFO_SLAVE_KIND]);
1074 #endif
1075
1076 netlink_determine_zebra_iftype(kind, &zif_type);
1077 }
1078
1079 /* If linking to another interface, note it. */
1080 if (tb[IFLA_LINK])
1081 link_ifindex = *(ifindex_t *)RTA_DATA(tb[IFLA_LINK]);
1082
1083 /* If VRF, create or update the VRF structure itself. */
1084 if (zif_type == ZEBRA_IF_VRF) {
1085 netlink_vrf_change(h, tb[IFLA_LINKINFO], name);
1086 vrf_id = (vrf_id_t)ifi->ifi_index;
1087 }
1088
1089 /* See if interface is present. */
1090 ifp = if_lookup_by_name_per_ns(zns, name);
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);
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 */