2 * Interface looking up by netlink.
3 * Copyright (C) 1998 Kunihiro Ishiguro
5 * This file is part of GNU Zebra.
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
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.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 #include <net/if_arp.h>
25 #include <linux/sockios.h>
26 #include <linux/ethtool.h>
32 #include "connected.h"
35 #include "zebra_memory.h"
44 #include "zebra/zserv.h"
45 #include "zebra/zebra_ns.h"
46 #include "zebra/zebra_vrf.h"
48 #include "zebra/redistribute.h"
49 #include "zebra/interface.h"
50 #include "zebra/debug.h"
51 #include "zebra/rtadv.h"
52 #include "zebra/zebra_ptm.h"
53 #include "zebra/zebra_mpls.h"
54 #include "zebra/kernel_netlink.h"
55 #include "zebra/if_netlink.h"
58 /* Note: on netlink systems, there should be a 1-to-1 mapping between interface
59 names and ifindex values. */
60 static void set_ifindex(struct interface
*ifp
, ifindex_t ifi_index
,
63 struct interface
*oifp
;
65 if (((oifp
= if_lookup_by_index_per_ns(zns
, ifi_index
)) != NULL
)
67 if (ifi_index
== IFINDEX_INTERNAL
)
69 "Netlink is setting interface %s ifindex to reserved "
71 ifp
->name
, ifi_index
);
73 if (IS_ZEBRA_DEBUG_KERNEL
)
75 "interface index %d was renamed from %s to %s",
76 ifi_index
, oifp
->name
, ifp
->name
);
79 "interface rename detected on up interface: index %d "
80 "was renamed from %s to %s, results are uncertain!",
81 ifi_index
, oifp
->name
, ifp
->name
);
82 if_delete_update(oifp
);
85 ifp
->ifindex
= ifi_index
;
88 /* Utility function to parse hardware link-layer address and update ifp */
89 static void netlink_interface_update_hw_addr(struct rtattr
**tb
,
90 struct interface
*ifp
)
94 if (tb
[IFLA_ADDRESS
]) {
97 hw_addr_len
= RTA_PAYLOAD(tb
[IFLA_ADDRESS
]);
99 if (hw_addr_len
> INTERFACE_HWADDR_MAX
)
100 zlog_warn("Hardware address is too large: %d",
103 ifp
->hw_addr_len
= hw_addr_len
;
104 memcpy(ifp
->hw_addr
, RTA_DATA(tb
[IFLA_ADDRESS
]),
107 for (i
= 0; i
< hw_addr_len
; i
++)
108 if (ifp
->hw_addr
[i
] != 0)
111 if (i
== hw_addr_len
)
112 ifp
->hw_addr_len
= 0;
114 ifp
->hw_addr_len
= hw_addr_len
;
119 static enum zebra_link_type
netlink_to_zebra_link_type(unsigned int hwt
)
123 return ZEBRA_LLT_ETHER
;
125 return ZEBRA_LLT_EETHER
;
127 return ZEBRA_LLT_AX25
;
129 return ZEBRA_LLT_PRONET
;
131 return ZEBRA_LLT_IEEE802
;
133 return ZEBRA_LLT_ARCNET
;
134 case ARPHRD_APPLETLK
:
135 return ZEBRA_LLT_APPLETLK
;
137 return ZEBRA_LLT_DLCI
;
139 return ZEBRA_LLT_ATM
;
140 case ARPHRD_METRICOM
:
141 return ZEBRA_LLT_METRICOM
;
142 case ARPHRD_IEEE1394
:
143 return ZEBRA_LLT_IEEE1394
;
145 return ZEBRA_LLT_EUI64
;
146 case ARPHRD_INFINIBAND
:
147 return ZEBRA_LLT_INFINIBAND
;
149 return ZEBRA_LLT_SLIP
;
151 return ZEBRA_LLT_CSLIP
;
153 return ZEBRA_LLT_SLIP6
;
155 return ZEBRA_LLT_CSLIP6
;
157 return ZEBRA_LLT_RSRVD
;
159 return ZEBRA_LLT_ADAPT
;
161 return ZEBRA_LLT_ROSE
;
163 return ZEBRA_LLT_X25
;
165 return ZEBRA_LLT_PPP
;
167 return ZEBRA_LLT_CHDLC
;
169 return ZEBRA_LLT_LAPB
;
171 return ZEBRA_LLT_RAWHDLC
;
173 return ZEBRA_LLT_IPIP
;
175 return ZEBRA_LLT_IPIP6
;
177 return ZEBRA_LLT_FRAD
;
179 return ZEBRA_LLT_SKIP
;
180 case ARPHRD_LOOPBACK
:
181 return ZEBRA_LLT_LOOPBACK
;
182 case ARPHRD_LOCALTLK
:
183 return ZEBRA_LLT_LOCALTLK
;
185 return ZEBRA_LLT_FDDI
;
187 return ZEBRA_LLT_SIT
;
189 return ZEBRA_LLT_IPDDP
;
191 return ZEBRA_LLT_IPGRE
;
193 return ZEBRA_LLT_PIMREG
;
195 return ZEBRA_LLT_HIPPI
;
197 return ZEBRA_LLT_ECONET
;
199 return ZEBRA_LLT_IRDA
;
201 return ZEBRA_LLT_FCPP
;
203 return ZEBRA_LLT_FCAL
;
205 return ZEBRA_LLT_FCPL
;
206 case ARPHRD_FCFABRIC
:
207 return ZEBRA_LLT_FCFABRIC
;
208 case ARPHRD_IEEE802_TR
:
209 return ZEBRA_LLT_IEEE802_TR
;
210 case ARPHRD_IEEE80211
:
211 return ZEBRA_LLT_IEEE80211
;
212 case ARPHRD_IEEE802154
:
213 return ZEBRA_LLT_IEEE802154
;
216 return ZEBRA_LLT_IP6GRE
;
218 #ifdef ARPHRD_IEEE802154_PHY
219 case ARPHRD_IEEE802154_PHY
:
220 return ZEBRA_LLT_IEEE802154_PHY
;
224 return ZEBRA_LLT_UNKNOWN
;
229 // Temporary Assignments to compile on older platforms.
231 #define IFLA_BR_MAX 39
234 #ifndef IFLA_VXLAN_ID
235 #define IFLA_VXLAN_ID 1
238 #ifndef IFLA_VXLAN_LOCAL
239 #define IFLA_VXLAN_LOCAL 4
242 #ifndef IFLA_VXLAN_MAX
243 #define IFLA_VXLAN_MAX 26
246 #ifndef IFLA_BRIDGE_MAX
247 #define IFLA_BRIDGE_MAX 2
250 #ifndef IFLA_BRIDGE_VLAN_INFO
251 #define IFLA_BRIDGE_VLAN_INFO 2
254 #ifndef BRIDGE_VLAN_INFO_PVID
255 #define BRIDGE_VLAN_INFO_PVID (1<<1)
258 #ifndef RTEXT_FILTER_BRVLAN
259 #define RTEXT_FILTER_BRVLAN (1<<1)
263 #define NTF_SELF 0x02
266 #ifndef IFLA_BR_VLAN_FILTERING
267 #define IFLA_BR_VLAN_FILTERING 7
270 #define parse_rtattr_nested(tb, max, rta) \
271 netlink_parse_rtattr((tb), (max), RTA_DATA(rta), RTA_PAYLOAD(rta))
273 static void netlink_vrf_change(struct nlmsghdr
*h
, struct rtattr
*tb
,
276 struct ifinfomsg
*ifi
;
277 struct rtattr
*linkinfo
[IFLA_INFO_MAX
+ 1];
278 struct rtattr
*attr
[IFLA_VRF_MAX
+ 1];
280 struct zebra_vrf
*zvrf
;
281 u_int32_t nl_table_id
;
285 memset(linkinfo
, 0, sizeof linkinfo
);
286 parse_rtattr_nested(linkinfo
, IFLA_INFO_MAX
, tb
);
288 if (!linkinfo
[IFLA_INFO_DATA
]) {
289 if (IS_ZEBRA_DEBUG_KERNEL
)
291 "%s: IFLA_INFO_DATA missing from VRF message: %s",
296 memset(attr
, 0, sizeof attr
);
297 parse_rtattr_nested(attr
, IFLA_VRF_MAX
, linkinfo
[IFLA_INFO_DATA
]);
298 if (!attr
[IFLA_VRF_TABLE
]) {
299 if (IS_ZEBRA_DEBUG_KERNEL
)
301 "%s: IFLA_VRF_TABLE missing from VRF message: %s",
306 nl_table_id
= *(u_int32_t
*)RTA_DATA(attr
[IFLA_VRF_TABLE
]);
308 if (h
->nlmsg_type
== RTM_NEWLINK
) {
309 if (IS_ZEBRA_DEBUG_KERNEL
)
310 zlog_debug("RTM_NEWLINK for VRF %s(%u) table %u", name
,
311 ifi
->ifi_index
, nl_table_id
);
314 * vrf_get is implied creation if it does not exist
316 vrf
= vrf_get((vrf_id_t
)ifi
->ifi_index
,
317 name
); // It would create vrf
319 zlog_err("VRF %s id %u not created", name
,
324 /* Enable the created VRF. */
325 if (!vrf_enable(vrf
)) {
326 zlog_err("Failed to enable VRF %s id %u", name
,
332 * This is the only place that we get the actual kernel table_id
333 * being used. We need it to set the table_id of the routes
334 * we are passing to the kernel.... And to throw some totally
335 * awesome parties. that too.
337 zvrf
= (struct zebra_vrf
*)vrf
->info
;
338 zvrf
->table_id
= nl_table_id
;
339 } else // h->nlmsg_type == RTM_DELLINK
341 if (IS_ZEBRA_DEBUG_KERNEL
)
342 zlog_debug("RTM_DELLINK for VRF %s(%u)", name
,
345 vrf
= vrf_lookup_by_id((vrf_id_t
)ifi
->ifi_index
);
348 zlog_warn("%s: vrf not found", __func__
);
356 static int get_iflink_speed(const char *ifname
)
359 struct ethtool_cmd ecmd
;
363 /* initialize struct */
364 memset(&ifdata
, 0, sizeof(ifdata
));
366 /* set interface name */
367 strcpy(ifdata
.ifr_name
, ifname
);
369 /* initialize ethtool interface */
370 memset(&ecmd
, 0, sizeof(ecmd
));
371 ecmd
.cmd
= ETHTOOL_GSET
; /* ETHTOOL_GLINK */
372 ifdata
.ifr_data
= (__caddr_t
)&ecmd
;
374 /* use ioctl to get IP address of an interface */
375 sd
= socket(PF_INET
, SOCK_DGRAM
, IPPROTO_IP
);
377 zlog_debug("Failure to read interface %s speed: %d %s", ifname
,
378 errno
, safe_strerror(errno
));
382 /* Get the current link state for the interface */
383 rc
= ioctl(sd
, SIOCETHTOOL
, (char *)&ifdata
);
385 zlog_debug("IOCTL failure to read interface %s speed: %d %s",
386 ifname
, errno
, safe_strerror(errno
));
393 return (ecmd
.speed_hi
<< 16) | ecmd
.speed
;
396 /* Called from interface_lookup_netlink(). This function is only used
398 static int netlink_interface(struct sockaddr_nl
*snl
, struct nlmsghdr
*h
,
399 ns_id_t ns_id
, int startup
)
402 struct ifinfomsg
*ifi
;
403 struct rtattr
*tb
[IFLA_MAX
+ 1];
404 struct rtattr
*linkinfo
[IFLA_MAX
+ 1];
405 struct interface
*ifp
;
408 char *slave_kind
= NULL
;
410 struct zebra_ns
*zns
;
411 vrf_id_t vrf_id
= VRF_DEFAULT
;
413 zns
= zebra_ns_lookup(ns_id
);
416 if (h
->nlmsg_type
!= RTM_NEWLINK
)
419 len
= h
->nlmsg_len
- NLMSG_LENGTH(sizeof(struct ifinfomsg
));
423 if (ifi
->ifi_family
== AF_BRIDGE
)
426 /* Looking up interface name. */
427 memset(tb
, 0, sizeof tb
);
428 netlink_parse_rtattr(tb
, IFLA_MAX
, IFLA_RTA(ifi
), len
);
431 /* check for wireless messages to ignore */
432 if ((tb
[IFLA_WIRELESS
] != NULL
) && (ifi
->ifi_change
== 0)) {
433 if (IS_ZEBRA_DEBUG_KERNEL
)
434 zlog_debug("%s: ignoring IFLA_WIRELESS message",
438 #endif /* IFLA_WIRELESS */
440 if (tb
[IFLA_IFNAME
] == NULL
)
442 name
= (char *)RTA_DATA(tb
[IFLA_IFNAME
]);
444 if (tb
[IFLA_LINKINFO
]) {
445 memset(linkinfo
, 0, sizeof linkinfo
);
446 parse_rtattr_nested(linkinfo
, IFLA_INFO_MAX
, tb
[IFLA_LINKINFO
]);
448 if (linkinfo
[IFLA_INFO_KIND
])
449 kind
= RTA_DATA(linkinfo
[IFLA_INFO_KIND
]);
451 #if HAVE_DECL_IFLA_INFO_SLAVE_KIND
452 if (linkinfo
[IFLA_INFO_SLAVE_KIND
])
453 slave_kind
= RTA_DATA(linkinfo
[IFLA_INFO_SLAVE_KIND
]);
456 if (kind
&& strcmp(kind
, "vrf") == 0) {
458 netlink_vrf_change(h
, tb
[IFLA_LINKINFO
], name
);
459 vrf_id
= (vrf_id_t
)ifi
->ifi_index
;
463 if (tb
[IFLA_MASTER
]) {
464 if (slave_kind
&& (strcmp(slave_kind
, "vrf") == 0))
465 vrf_id
= *(u_int32_t
*)RTA_DATA(tb
[IFLA_MASTER
]);
469 ifp
= if_get_by_name(name
, vrf_id
);
470 set_ifindex(ifp
, ifi
->ifi_index
, zns
);
471 ifp
->flags
= ifi
->ifi_flags
& 0x0000fffff;
473 SET_FLAG(ifp
->status
, ZEBRA_INTERFACE_VRF_LOOPBACK
);
474 ifp
->mtu6
= ifp
->mtu
= *(uint32_t *)RTA_DATA(tb
[IFLA_MTU
]);
476 ifp
->speed
= get_iflink_speed(name
);
477 ifp
->ptm_status
= ZEBRA_PTM_STATUS_UNKNOWN
;
479 /* Hardware type and address. */
480 ifp
->ll_type
= netlink_to_zebra_link_type(ifi
->ifi_type
);
481 netlink_interface_update_hw_addr(tb
, ifp
);
488 /* Interface lookup by netlink socket. */
489 int interface_lookup_netlink(struct zebra_ns
*zns
)
493 /* Get interface information. */
494 ret
= netlink_request(AF_PACKET
, RTM_GETLINK
, &zns
->netlink_cmd
);
497 ret
= netlink_parse_info(netlink_interface
, &zns
->netlink_cmd
, zns
, 0,
502 /* Get IPv4 address of the interfaces. */
503 ret
= netlink_request(AF_INET
, RTM_GETADDR
, &zns
->netlink_cmd
);
506 ret
= netlink_parse_info(netlink_interface_addr
, &zns
->netlink_cmd
, zns
,
511 /* Get IPv6 address of the interfaces. */
512 ret
= netlink_request(AF_INET6
, RTM_GETADDR
, &zns
->netlink_cmd
);
515 ret
= netlink_parse_info(netlink_interface_addr
, &zns
->netlink_cmd
, zns
,
523 /* Interface address modification. */
524 static int netlink_address(int cmd
, int family
, struct interface
*ifp
,
525 struct connected
*ifc
)
532 struct ifaddrmsg ifa
;
533 char buf
[NL_PKT_BUF_SIZE
];
536 struct zebra_ns
*zns
= zebra_ns_lookup(NS_DEFAULT
);
539 memset(&req
, 0, sizeof req
- NL_PKT_BUF_SIZE
);
541 bytelen
= (family
== AF_INET
? 4 : 16);
543 req
.n
.nlmsg_len
= NLMSG_LENGTH(sizeof(struct ifaddrmsg
));
544 req
.n
.nlmsg_flags
= NLM_F_REQUEST
;
545 req
.n
.nlmsg_type
= cmd
;
546 req
.ifa
.ifa_family
= family
;
548 req
.ifa
.ifa_index
= ifp
->ifindex
;
549 req
.ifa
.ifa_prefixlen
= p
->prefixlen
;
551 addattr_l(&req
.n
, sizeof req
, IFA_LOCAL
, &p
->u
.prefix
, bytelen
);
553 if (family
== AF_INET
&& cmd
== RTM_NEWADDR
) {
554 if (!CONNECTED_PEER(ifc
) && ifc
->destination
) {
555 p
= ifc
->destination
;
556 addattr_l(&req
.n
, sizeof req
, IFA_BROADCAST
,
557 &p
->u
.prefix
, bytelen
);
561 if (CHECK_FLAG(ifc
->flags
, ZEBRA_IFA_SECONDARY
))
562 SET_FLAG(req
.ifa
.ifa_flags
, IFA_F_SECONDARY
);
565 addattr_l(&req
.n
, sizeof req
, IFA_LABEL
, ifc
->label
,
566 strlen(ifc
->label
) + 1);
568 return netlink_talk(netlink_talk_filter
, &req
.n
, &zns
->netlink_cmd
, zns
,
572 int kernel_address_add_ipv4(struct interface
*ifp
, struct connected
*ifc
)
574 return netlink_address(RTM_NEWADDR
, AF_INET
, ifp
, ifc
);
577 int kernel_address_delete_ipv4(struct interface
*ifp
, struct connected
*ifc
)
579 return netlink_address(RTM_DELADDR
, AF_INET
, ifp
, ifc
);
582 int netlink_interface_addr(struct sockaddr_nl
*snl
, struct nlmsghdr
*h
,
583 ns_id_t ns_id
, int startup
)
586 struct ifaddrmsg
*ifa
;
587 struct rtattr
*tb
[IFA_MAX
+ 1];
588 struct interface
*ifp
;
593 struct zebra_ns
*zns
;
595 zns
= zebra_ns_lookup(ns_id
);
598 if (ifa
->ifa_family
!= AF_INET
&& ifa
->ifa_family
!= AF_INET6
)
601 if (h
->nlmsg_type
!= RTM_NEWADDR
&& h
->nlmsg_type
!= RTM_DELADDR
)
604 len
= h
->nlmsg_len
- NLMSG_LENGTH(sizeof(struct ifaddrmsg
));
608 memset(tb
, 0, sizeof tb
);
609 netlink_parse_rtattr(tb
, IFA_MAX
, IFA_RTA(ifa
), len
);
611 ifp
= if_lookup_by_index_per_ns(zns
, ifa
->ifa_index
);
614 "netlink_interface_addr can't find interface by index %d",
619 if (IS_ZEBRA_DEBUG_KERNEL
) /* remove this line to see initial ifcfg */
622 zlog_debug("netlink_interface_addr %s %s flags 0x%x:",
623 nl_msg_type_to_str(h
->nlmsg_type
), ifp
->name
,
626 zlog_debug(" IFA_LOCAL %s/%d",
627 inet_ntop(ifa
->ifa_family
,
628 RTA_DATA(tb
[IFA_LOCAL
]), buf
,
632 zlog_debug(" IFA_ADDRESS %s/%d",
633 inet_ntop(ifa
->ifa_family
,
634 RTA_DATA(tb
[IFA_ADDRESS
]), buf
,
637 if (tb
[IFA_BROADCAST
])
638 zlog_debug(" IFA_BROADCAST %s/%d",
639 inet_ntop(ifa
->ifa_family
,
640 RTA_DATA(tb
[IFA_BROADCAST
]), buf
,
643 if (tb
[IFA_LABEL
] && strcmp(ifp
->name
, RTA_DATA(tb
[IFA_LABEL
])))
644 zlog_debug(" IFA_LABEL %s",
645 (char *)RTA_DATA(tb
[IFA_LABEL
]));
647 if (tb
[IFA_CACHEINFO
]) {
648 struct ifa_cacheinfo
*ci
= RTA_DATA(tb
[IFA_CACHEINFO
]);
649 zlog_debug(" IFA_CACHEINFO pref %d, valid %d",
650 ci
->ifa_prefered
, ci
->ifa_valid
);
654 /* logic copied from iproute2/ip/ipaddress.c:print_addrinfo() */
655 if (tb
[IFA_LOCAL
] == NULL
)
656 tb
[IFA_LOCAL
] = tb
[IFA_ADDRESS
];
657 if (tb
[IFA_ADDRESS
] == NULL
)
658 tb
[IFA_ADDRESS
] = tb
[IFA_LOCAL
];
660 /* local interface address */
661 addr
= (tb
[IFA_LOCAL
] ? RTA_DATA(tb
[IFA_LOCAL
]) : NULL
);
663 /* is there a peer address? */
665 && memcmp(RTA_DATA(tb
[IFA_ADDRESS
]), RTA_DATA(tb
[IFA_LOCAL
]),
666 RTA_PAYLOAD(tb
[IFA_ADDRESS
]))) {
667 broad
= RTA_DATA(tb
[IFA_ADDRESS
]);
668 SET_FLAG(flags
, ZEBRA_IFA_PEER
);
670 /* seeking a broadcast address */
671 broad
= (tb
[IFA_BROADCAST
] ? RTA_DATA(tb
[IFA_BROADCAST
])
674 /* addr is primary key, SOL if we don't have one */
676 zlog_debug("%s: NULL address", __func__
);
681 if (ifa
->ifa_flags
& IFA_F_SECONDARY
)
682 SET_FLAG(flags
, ZEBRA_IFA_SECONDARY
);
686 label
= (char *)RTA_DATA(tb
[IFA_LABEL
]);
688 if (ifp
&& label
&& strcmp(ifp
->name
, label
) == 0)
691 /* Register interface address to the interface. */
692 if (ifa
->ifa_family
== AF_INET
) {
693 if (h
->nlmsg_type
== RTM_NEWADDR
)
694 connected_add_ipv4(ifp
, flags
, (struct in_addr
*)addr
,
696 (struct in_addr
*)broad
, label
);
698 connected_delete_ipv4(
699 ifp
, flags
, (struct in_addr
*)addr
,
700 ifa
->ifa_prefixlen
, (struct in_addr
*)broad
);
702 if (ifa
->ifa_family
== AF_INET6
) {
703 if (h
->nlmsg_type
== RTM_NEWADDR
) {
704 /* Only consider valid addresses; we'll not get a
706 * the kernel till IPv6 DAD has completed, but at init
708 * does query for and will receive all addresses.
711 & (IFA_F_DADFAILED
| IFA_F_TENTATIVE
)))
713 ifp
, flags
, (struct in6_addr
*)addr
,
715 (struct in6_addr
*)broad
, label
);
717 connected_delete_ipv6(ifp
, (struct in6_addr
*)addr
,
719 (struct in6_addr
*)broad
);
725 int netlink_link_change(struct sockaddr_nl
*snl
, struct nlmsghdr
*h
,
726 ns_id_t ns_id
, int startup
)
729 struct ifinfomsg
*ifi
;
730 struct rtattr
*tb
[IFLA_MAX
+ 1];
731 struct rtattr
*linkinfo
[IFLA_MAX
+ 1];
732 struct interface
*ifp
;
735 char *slave_kind
= NULL
;
737 struct zebra_ns
*zns
;
738 vrf_id_t vrf_id
= VRF_DEFAULT
;
740 zns
= zebra_ns_lookup(ns_id
);
743 if (!(h
->nlmsg_type
== RTM_NEWLINK
|| h
->nlmsg_type
== RTM_DELLINK
)) {
744 /* If this is not link add/delete message so print warning. */
745 zlog_warn("netlink_link_change: wrong kernel message %d",
750 len
= h
->nlmsg_len
- NLMSG_LENGTH(sizeof(struct ifinfomsg
));
754 if (ifi
->ifi_family
== AF_BRIDGE
)
757 /* Looking up interface name. */
758 memset(tb
, 0, sizeof tb
);
759 netlink_parse_rtattr(tb
, IFLA_MAX
, IFLA_RTA(ifi
), len
);
762 /* check for wireless messages to ignore */
763 if ((tb
[IFLA_WIRELESS
] != NULL
) && (ifi
->ifi_change
== 0)) {
764 if (IS_ZEBRA_DEBUG_KERNEL
)
765 zlog_debug("%s: ignoring IFLA_WIRELESS message",
769 #endif /* IFLA_WIRELESS */
771 if (tb
[IFLA_IFNAME
] == NULL
)
773 name
= (char *)RTA_DATA(tb
[IFLA_IFNAME
]);
775 if (tb
[IFLA_LINKINFO
]) {
776 memset(linkinfo
, 0, sizeof linkinfo
);
777 parse_rtattr_nested(linkinfo
, IFLA_INFO_MAX
, tb
[IFLA_LINKINFO
]);
779 if (linkinfo
[IFLA_INFO_KIND
])
780 kind
= RTA_DATA(linkinfo
[IFLA_INFO_KIND
]);
782 #if HAVE_DECL_IFLA_INFO_SLAVE_KIND
783 if (linkinfo
[IFLA_INFO_SLAVE_KIND
])
784 slave_kind
= RTA_DATA(linkinfo
[IFLA_INFO_SLAVE_KIND
]);
787 if (kind
&& strcmp(kind
, "vrf") == 0) {
789 netlink_vrf_change(h
, tb
[IFLA_LINKINFO
], name
);
790 vrf_id
= (vrf_id_t
)ifi
->ifi_index
;
794 /* See if interface is present. */
795 ifp
= if_lookup_by_name_per_ns(zns
, name
);
797 if (h
->nlmsg_type
== RTM_NEWLINK
) {
798 if (tb
[IFLA_MASTER
]) {
799 if (slave_kind
&& (strcmp(slave_kind
, "vrf") == 0))
801 *(u_int32_t
*)RTA_DATA(tb
[IFLA_MASTER
]);
805 || !CHECK_FLAG(ifp
->status
, ZEBRA_INTERFACE_ACTIVE
)) {
806 /* Add interface notification from kernel */
807 if (IS_ZEBRA_DEBUG_KERNEL
)
809 "RTM_NEWLINK for %s(%u) (ifp %p) vrf_id %u flags 0x%x",
810 name
, ifi
->ifi_index
, ifp
, vrf_id
,
814 /* unknown interface */
815 ifp
= if_get_by_name(name
, vrf_id
);
817 /* pre-configured interface, learnt now */
818 if (ifp
->vrf_id
!= vrf_id
)
819 if_update(ifp
, name
, strlen(name
),
823 /* Update interface information. */
824 set_ifindex(ifp
, ifi
->ifi_index
, zns
);
825 ifp
->flags
= ifi
->ifi_flags
& 0x0000fffff;
827 SET_FLAG(ifp
->status
,
828 ZEBRA_INTERFACE_VRF_LOOPBACK
);
829 ifp
->mtu6
= ifp
->mtu
= *(int *)RTA_DATA(tb
[IFLA_MTU
]);
831 ifp
->ptm_status
= ZEBRA_PTM_STATUS_UNKNOWN
;
833 netlink_interface_update_hw_addr(tb
, ifp
);
835 /* Inform clients, install any configured addresses. */
837 } else if (ifp
->vrf_id
!= vrf_id
) {
838 /* VRF change for an interface. */
839 if (IS_ZEBRA_DEBUG_KERNEL
)
841 "RTM_NEWLINK vrf-change for %s(%u) "
842 "vrf_id %u -> %u flags 0x%x",
843 name
, ifp
->ifindex
, ifp
->vrf_id
, vrf_id
,
846 if_handle_vrf_change(ifp
, vrf_id
);
848 /* Interface status change. */
849 if (IS_ZEBRA_DEBUG_KERNEL
)
851 "RTM_NEWLINK status for %s(%u) flags 0x%x",
852 name
, ifp
->ifindex
, ifi
->ifi_flags
);
854 set_ifindex(ifp
, ifi
->ifi_index
, zns
);
855 ifp
->mtu6
= ifp
->mtu
= *(int *)RTA_DATA(tb
[IFLA_MTU
]);
858 netlink_interface_update_hw_addr(tb
, ifp
);
860 if (if_is_no_ptm_operative(ifp
)) {
861 ifp
->flags
= ifi
->ifi_flags
& 0x0000fffff;
862 if (!if_is_no_ptm_operative(ifp
))
864 else if (if_is_operative(ifp
))
865 /* Must notify client daemons of new
866 * interface status. */
867 zebra_interface_up_update(ifp
);
869 ifp
->flags
= ifi
->ifi_flags
& 0x0000fffff;
870 if (if_is_operative(ifp
))
875 /* Delete interface notification from kernel */
877 zlog_warn("RTM_DELLINK for unknown interface %s(%u)",
878 name
, ifi
->ifi_index
);
882 if (IS_ZEBRA_DEBUG_KERNEL
)
883 zlog_debug("RTM_DELLINK for %s(%u)", name
,
886 UNSET_FLAG(ifp
->status
, ZEBRA_INTERFACE_VRF_LOOPBACK
);
889 if_delete_update(ifp
);
895 /* Interface information read by netlink. */
896 void interface_list(struct zebra_ns
*zns
)
898 interface_lookup_netlink(zns
);