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"
45 #include "zebra/zserv.h"
46 #include "zebra/zebra_ns.h"
47 #include "zebra/zebra_vrf.h"
49 #include "zebra/redistribute.h"
50 #include "zebra/interface.h"
51 #include "zebra/debug.h"
52 #include "zebra/rtadv.h"
53 #include "zebra/zebra_ptm.h"
54 #include "zebra/zebra_mpls.h"
55 #include "zebra/kernel_netlink.h"
56 #include "zebra/if_netlink.h"
59 /* Note: on netlink systems, there should be a 1-to-1 mapping between interface
60 names and ifindex values. */
62 set_ifindex(struct interface
*ifp
, ifindex_t ifi_index
, struct zebra_ns
*zns
)
64 struct interface
*oifp
;
66 if (((oifp
= if_lookup_by_index_per_ns (zns
, ifi_index
)) != NULL
) && (oifp
!= ifp
))
68 if (ifi_index
== IFINDEX_INTERNAL
)
69 zlog_err("Netlink is setting interface %s ifindex to reserved "
70 "internal value %u", ifp
->name
, ifi_index
);
73 if (IS_ZEBRA_DEBUG_KERNEL
)
74 zlog_debug("interface index %d was renamed from %s to %s",
75 ifi_index
, oifp
->name
, ifp
->name
);
77 zlog_err("interface rename detected on up interface: index %d "
78 "was renamed from %s to %s, results are uncertain!",
79 ifi_index
, oifp
->name
, ifp
->name
);
80 if_delete_update(oifp
);
83 ifp
->ifindex
= ifi_index
;
86 /* Utility function to parse hardware link-layer address and update ifp */
88 netlink_interface_update_hw_addr (struct rtattr
**tb
, struct interface
*ifp
)
96 hw_addr_len
= RTA_PAYLOAD (tb
[IFLA_ADDRESS
]);
98 if (hw_addr_len
> INTERFACE_HWADDR_MAX
)
99 zlog_warn ("Hardware address is too large: %d", hw_addr_len
);
102 ifp
->hw_addr_len
= hw_addr_len
;
103 memcpy (ifp
->hw_addr
, RTA_DATA (tb
[IFLA_ADDRESS
]), hw_addr_len
);
105 for (i
= 0; i
< hw_addr_len
; i
++)
106 if (ifp
->hw_addr
[i
] != 0)
109 if (i
== hw_addr_len
)
110 ifp
->hw_addr_len
= 0;
112 ifp
->hw_addr_len
= hw_addr_len
;
117 static enum zebra_link_type
118 netlink_to_zebra_link_type (unsigned int hwt
)
122 case ARPHRD_ETHER
: return ZEBRA_LLT_ETHER
;
123 case ARPHRD_EETHER
: return ZEBRA_LLT_EETHER
;
124 case ARPHRD_AX25
: return ZEBRA_LLT_AX25
;
125 case ARPHRD_PRONET
: return ZEBRA_LLT_PRONET
;
126 case ARPHRD_IEEE802
: return ZEBRA_LLT_IEEE802
;
127 case ARPHRD_ARCNET
: return ZEBRA_LLT_ARCNET
;
128 case ARPHRD_APPLETLK
: return ZEBRA_LLT_APPLETLK
;
129 case ARPHRD_DLCI
: return ZEBRA_LLT_DLCI
;
130 case ARPHRD_ATM
: return ZEBRA_LLT_ATM
;
131 case ARPHRD_METRICOM
: return ZEBRA_LLT_METRICOM
;
132 case ARPHRD_IEEE1394
: return ZEBRA_LLT_IEEE1394
;
133 case ARPHRD_EUI64
: return ZEBRA_LLT_EUI64
;
134 case ARPHRD_INFINIBAND
: return ZEBRA_LLT_INFINIBAND
;
135 case ARPHRD_SLIP
: return ZEBRA_LLT_SLIP
;
136 case ARPHRD_CSLIP
: return ZEBRA_LLT_CSLIP
;
137 case ARPHRD_SLIP6
: return ZEBRA_LLT_SLIP6
;
138 case ARPHRD_CSLIP6
: return ZEBRA_LLT_CSLIP6
;
139 case ARPHRD_RSRVD
: return ZEBRA_LLT_RSRVD
;
140 case ARPHRD_ADAPT
: return ZEBRA_LLT_ADAPT
;
141 case ARPHRD_ROSE
: return ZEBRA_LLT_ROSE
;
142 case ARPHRD_X25
: return ZEBRA_LLT_X25
;
143 case ARPHRD_PPP
: return ZEBRA_LLT_PPP
;
144 case ARPHRD_CISCO
: return ZEBRA_LLT_CHDLC
;
145 case ARPHRD_LAPB
: return ZEBRA_LLT_LAPB
;
146 case ARPHRD_RAWHDLC
: return ZEBRA_LLT_RAWHDLC
;
147 case ARPHRD_TUNNEL
: return ZEBRA_LLT_IPIP
;
148 case ARPHRD_TUNNEL6
: return ZEBRA_LLT_IPIP6
;
149 case ARPHRD_FRAD
: return ZEBRA_LLT_FRAD
;
150 case ARPHRD_SKIP
: return ZEBRA_LLT_SKIP
;
151 case ARPHRD_LOOPBACK
: return ZEBRA_LLT_LOOPBACK
;
152 case ARPHRD_LOCALTLK
: return ZEBRA_LLT_LOCALTLK
;
153 case ARPHRD_FDDI
: return ZEBRA_LLT_FDDI
;
154 case ARPHRD_SIT
: return ZEBRA_LLT_SIT
;
155 case ARPHRD_IPDDP
: return ZEBRA_LLT_IPDDP
;
156 case ARPHRD_IPGRE
: return ZEBRA_LLT_IPGRE
;
157 case ARPHRD_PIMREG
: return ZEBRA_LLT_PIMREG
;
158 case ARPHRD_HIPPI
: return ZEBRA_LLT_HIPPI
;
159 case ARPHRD_ECONET
: return ZEBRA_LLT_ECONET
;
160 case ARPHRD_IRDA
: return ZEBRA_LLT_IRDA
;
161 case ARPHRD_FCPP
: return ZEBRA_LLT_FCPP
;
162 case ARPHRD_FCAL
: return ZEBRA_LLT_FCAL
;
163 case ARPHRD_FCPL
: return ZEBRA_LLT_FCPL
;
164 case ARPHRD_FCFABRIC
: return ZEBRA_LLT_FCFABRIC
;
165 case ARPHRD_IEEE802_TR
: return ZEBRA_LLT_IEEE802_TR
;
166 case ARPHRD_IEEE80211
: return ZEBRA_LLT_IEEE80211
;
167 case ARPHRD_IEEE802154
: return ZEBRA_LLT_IEEE802154
;
169 case ARPHRD_IP6GRE
: return ZEBRA_LLT_IP6GRE
;
171 #ifdef ARPHRD_IEEE802154_PHY
172 case ARPHRD_IEEE802154_PHY
: return ZEBRA_LLT_IEEE802154_PHY
;
175 default: return ZEBRA_LLT_UNKNOWN
;
180 //Temporary Assignments to compile on older platforms.
182 #define IFLA_BR_MAX 39
185 #ifndef IFLA_VXLAN_ID
186 #define IFLA_VXLAN_ID 1
189 #ifndef IFLA_VXLAN_LOCAL
190 #define IFLA_VXLAN_LOCAL 4
193 #ifndef IFLA_VXLAN_MAX
194 #define IFLA_VXLAN_MAX 26
197 #ifndef IFLA_BRIDGE_MAX
198 #define IFLA_BRIDGE_MAX 2
201 #ifndef IFLA_BRIDGE_VLAN_INFO
202 #define IFLA_BRIDGE_VLAN_INFO 2
205 #ifndef BRIDGE_VLAN_INFO_PVID
206 #define BRIDGE_VLAN_INFO_PVID (1<<1)
209 #ifndef RTEXT_FILTER_BRVLAN
210 #define RTEXT_FILTER_BRVLAN (1<<1)
214 #define NTF_SELF 0x02
217 #ifndef IFLA_BR_VLAN_FILTERING
218 #define IFLA_BR_VLAN_FILTERING 7
221 #define parse_rtattr_nested(tb, max, rta) \
222 netlink_parse_rtattr((tb), (max), RTA_DATA(rta), RTA_PAYLOAD(rta))
225 netlink_vrf_change (struct nlmsghdr
*h
, struct rtattr
*tb
, const char *name
)
227 struct ifinfomsg
*ifi
;
228 struct rtattr
*linkinfo
[IFLA_INFO_MAX
+1];
229 struct rtattr
*attr
[IFLA_VRF_MAX
+1];
231 struct zebra_vrf
*zvrf
;
232 u_int32_t nl_table_id
;
234 ifi
= NLMSG_DATA (h
);
236 memset (linkinfo
, 0, sizeof linkinfo
);
237 parse_rtattr_nested(linkinfo
, IFLA_INFO_MAX
, tb
);
239 if (!linkinfo
[IFLA_INFO_DATA
]) {
240 if (IS_ZEBRA_DEBUG_KERNEL
)
241 zlog_debug ("%s: IFLA_INFO_DATA missing from VRF message: %s", __func__
, name
);
245 memset (attr
, 0, sizeof attr
);
246 parse_rtattr_nested(attr
, IFLA_VRF_MAX
, linkinfo
[IFLA_INFO_DATA
]);
247 if (!attr
[IFLA_VRF_TABLE
]) {
248 if (IS_ZEBRA_DEBUG_KERNEL
)
249 zlog_debug ("%s: IFLA_VRF_TABLE missing from VRF message: %s", __func__
, name
);
253 nl_table_id
= *(u_int32_t
*)RTA_DATA(attr
[IFLA_VRF_TABLE
]);
255 if (h
->nlmsg_type
== RTM_NEWLINK
)
257 if (IS_ZEBRA_DEBUG_KERNEL
)
258 zlog_debug ("RTM_NEWLINK for VRF %s(%u) table %u",
259 name
, ifi
->ifi_index
, nl_table_id
);
262 * vrf_get is implied creation if it does not exist
264 vrf
= vrf_get((vrf_id_t
)ifi
->ifi_index
, name
); // It would create vrf
267 zlog_err ("VRF %s id %u not created", name
, ifi
->ifi_index
);
271 /* Enable the created VRF. */
272 if (!vrf_enable (vrf
))
274 zlog_err ("Failed to enable VRF %s id %u", name
, ifi
->ifi_index
);
279 * This is the only place that we get the actual kernel table_id
280 * being used. We need it to set the table_id of the routes
281 * we are passing to the kernel.... And to throw some totally
282 * awesome parties. that too.
284 zvrf
= (struct zebra_vrf
*)vrf
->info
;
285 zvrf
->table_id
= nl_table_id
;
287 else //h->nlmsg_type == RTM_DELLINK
289 if (IS_ZEBRA_DEBUG_KERNEL
)
290 zlog_debug ("RTM_DELLINK for VRF %s(%u)", name
, ifi
->ifi_index
);
292 vrf
= vrf_lookup_by_id ((vrf_id_t
)ifi
->ifi_index
);
296 zlog_warn ("%s: vrf not found", __func__
);
305 get_iflink_speed (const char *ifname
)
308 struct ethtool_cmd ecmd
;
312 /* initialize struct */
313 memset(&ifdata
, 0, sizeof(ifdata
));
315 /* set interface name */
316 strcpy(ifdata
.ifr_name
, ifname
);
318 /* initialize ethtool interface */
319 memset(&ecmd
, 0, sizeof(ecmd
));
320 ecmd
.cmd
= ETHTOOL_GSET
; /* ETHTOOL_GLINK */
321 ifdata
.ifr_data
= (__caddr_t
) &ecmd
;
323 /* use ioctl to get IP address of an interface */
324 sd
= socket(PF_INET
, SOCK_DGRAM
, IPPROTO_IP
);
326 zlog_debug ("Failure to read interface %s speed: %d %s",
327 ifname
, errno
, safe_strerror(errno
));
331 /* Get the current link state for the interface */
332 rc
= ioctl(sd
, SIOCETHTOOL
, (char *)&ifdata
);
334 zlog_debug("IOCTL failure to read interface %s speed: %d %s",
335 ifname
, errno
, safe_strerror(errno
));
342 return (ecmd
.speed_hi
<< 16 ) | ecmd
.speed
;
345 /* Called from interface_lookup_netlink(). This function is only used
348 netlink_interface (struct sockaddr_nl
*snl
, struct nlmsghdr
*h
,
349 ns_id_t ns_id
, int startup
)
352 struct ifinfomsg
*ifi
;
353 struct rtattr
*tb
[IFLA_MAX
+ 1];
354 struct rtattr
*linkinfo
[IFLA_MAX
+ 1];
355 struct interface
*ifp
;
358 char *slave_kind
= NULL
;
360 struct zebra_ns
*zns
;
361 vrf_id_t vrf_id
= VRF_DEFAULT
;
363 zns
= zebra_ns_lookup (ns_id
);
364 ifi
= NLMSG_DATA (h
);
366 if (h
->nlmsg_type
!= RTM_NEWLINK
)
369 len
= h
->nlmsg_len
- NLMSG_LENGTH (sizeof (struct ifinfomsg
));
373 if (ifi
->ifi_family
== AF_BRIDGE
)
376 /* Looking up interface name. */
377 memset (tb
, 0, sizeof tb
);
378 netlink_parse_rtattr (tb
, IFLA_MAX
, IFLA_RTA (ifi
), len
);
381 /* check for wireless messages to ignore */
382 if ((tb
[IFLA_WIRELESS
] != NULL
) && (ifi
->ifi_change
== 0))
384 if (IS_ZEBRA_DEBUG_KERNEL
)
385 zlog_debug ("%s: ignoring IFLA_WIRELESS message", __func__
);
388 #endif /* IFLA_WIRELESS */
390 if (tb
[IFLA_IFNAME
] == NULL
)
392 name
= (char *) RTA_DATA (tb
[IFLA_IFNAME
]);
394 if (tb
[IFLA_LINKINFO
])
396 memset (linkinfo
, 0, sizeof linkinfo
);
397 parse_rtattr_nested(linkinfo
, IFLA_INFO_MAX
, tb
[IFLA_LINKINFO
]);
399 if (linkinfo
[IFLA_INFO_KIND
])
400 kind
= RTA_DATA(linkinfo
[IFLA_INFO_KIND
]);
402 #if HAVE_DECL_IFLA_INFO_SLAVE_KIND
403 if (linkinfo
[IFLA_INFO_SLAVE_KIND
])
404 slave_kind
= RTA_DATA(linkinfo
[IFLA_INFO_SLAVE_KIND
]);
407 if (kind
&& strcmp(kind
, "vrf") == 0)
410 netlink_vrf_change(h
, tb
[IFLA_LINKINFO
], name
);
411 vrf_id
= (vrf_id_t
)ifi
->ifi_index
;
417 if (slave_kind
&& (strcmp(slave_kind
, "vrf") == 0))
418 vrf_id
= *(u_int32_t
*)RTA_DATA(tb
[IFLA_MASTER
]);
422 ifp
= if_get_by_name (name
, vrf_id
);
423 set_ifindex(ifp
, ifi
->ifi_index
, zns
);
424 ifp
->flags
= ifi
->ifi_flags
& 0x0000fffff;
426 SET_FLAG(ifp
->status
, ZEBRA_INTERFACE_VRF_LOOPBACK
);
427 ifp
->mtu6
= ifp
->mtu
= *(uint32_t *) RTA_DATA (tb
[IFLA_MTU
]);
429 ifp
->speed
= get_iflink_speed (name
);
430 ifp
->ptm_status
= ZEBRA_PTM_STATUS_UNKNOWN
;
432 /* Hardware type and address. */
433 ifp
->ll_type
= netlink_to_zebra_link_type (ifi
->ifi_type
);
434 netlink_interface_update_hw_addr (tb
, ifp
);
441 /* Interface lookup by netlink socket. */
443 interface_lookup_netlink (struct zebra_ns
*zns
)
447 /* Get interface information. */
448 ret
= netlink_request (AF_PACKET
, RTM_GETLINK
, &zns
->netlink_cmd
);
451 ret
= netlink_parse_info (netlink_interface
, &zns
->netlink_cmd
, zns
, 0, 1);
455 /* Get IPv4 address of the interfaces. */
456 ret
= netlink_request (AF_INET
, RTM_GETADDR
, &zns
->netlink_cmd
);
459 ret
= netlink_parse_info (netlink_interface_addr
, &zns
->netlink_cmd
, zns
, 0, 1);
463 /* Get IPv6 address of the interfaces. */
464 ret
= netlink_request (AF_INET6
, RTM_GETADDR
, &zns
->netlink_cmd
);
467 ret
= netlink_parse_info (netlink_interface_addr
, &zns
->netlink_cmd
, zns
, 0, 1);
474 /* Interface address modification. */
476 netlink_address (int cmd
, int family
, struct interface
*ifp
,
477 struct connected
*ifc
)
485 struct ifaddrmsg ifa
;
486 char buf
[NL_PKT_BUF_SIZE
];
489 struct zebra_ns
*zns
= zebra_ns_lookup (NS_DEFAULT
);
492 memset (&req
, 0, sizeof req
- NL_PKT_BUF_SIZE
);
494 bytelen
= (family
== AF_INET
? 4 : 16);
496 req
.n
.nlmsg_len
= NLMSG_LENGTH (sizeof (struct ifaddrmsg
));
497 req
.n
.nlmsg_flags
= NLM_F_REQUEST
;
498 req
.n
.nlmsg_type
= cmd
;
499 req
.ifa
.ifa_family
= family
;
501 req
.ifa
.ifa_index
= ifp
->ifindex
;
502 req
.ifa
.ifa_prefixlen
= p
->prefixlen
;
504 addattr_l (&req
.n
, sizeof req
, IFA_LOCAL
, &p
->u
.prefix
, bytelen
);
506 if (family
== AF_INET
&& cmd
== RTM_NEWADDR
)
508 if (!CONNECTED_PEER(ifc
) && ifc
->destination
)
510 p
= ifc
->destination
;
511 addattr_l (&req
.n
, sizeof req
, IFA_BROADCAST
, &p
->u
.prefix
,
516 if (CHECK_FLAG (ifc
->flags
, ZEBRA_IFA_SECONDARY
))
517 SET_FLAG (req
.ifa
.ifa_flags
, IFA_F_SECONDARY
);
520 addattr_l (&req
.n
, sizeof req
, IFA_LABEL
, ifc
->label
,
521 strlen (ifc
->label
) + 1);
523 return netlink_talk (netlink_talk_filter
, &req
.n
, &zns
->netlink_cmd
, zns
, 0);
527 kernel_address_add_ipv4 (struct interface
*ifp
, struct connected
*ifc
)
529 return netlink_address (RTM_NEWADDR
, AF_INET
, ifp
, ifc
);
533 kernel_address_delete_ipv4 (struct interface
*ifp
, struct connected
*ifc
)
535 return netlink_address (RTM_DELADDR
, AF_INET
, ifp
, ifc
);
539 netlink_interface_addr (struct sockaddr_nl
*snl
, struct nlmsghdr
*h
,
540 ns_id_t ns_id
, int startup
)
543 struct ifaddrmsg
*ifa
;
544 struct rtattr
*tb
[IFA_MAX
+ 1];
545 struct interface
*ifp
;
550 struct zebra_ns
*zns
;
552 zns
= zebra_ns_lookup (ns_id
);
553 ifa
= NLMSG_DATA (h
);
555 if (ifa
->ifa_family
!= AF_INET
&& ifa
->ifa_family
!= AF_INET6
)
558 if (h
->nlmsg_type
!= RTM_NEWADDR
&& h
->nlmsg_type
!= RTM_DELADDR
)
561 len
= h
->nlmsg_len
- NLMSG_LENGTH (sizeof (struct ifaddrmsg
));
565 memset (tb
, 0, sizeof tb
);
566 netlink_parse_rtattr (tb
, IFA_MAX
, IFA_RTA (ifa
), len
);
568 ifp
= if_lookup_by_index_per_ns (zns
, ifa
->ifa_index
);
571 zlog_err ("netlink_interface_addr can't find interface by index %d",
576 if (IS_ZEBRA_DEBUG_KERNEL
) /* remove this line to see initial ifcfg */
579 zlog_debug ("netlink_interface_addr %s %s flags 0x%x:",
580 nl_msg_type_to_str (h
->nlmsg_type
), ifp
->name
,
583 zlog_debug (" IFA_LOCAL %s/%d",
584 inet_ntop (ifa
->ifa_family
, RTA_DATA (tb
[IFA_LOCAL
]),
585 buf
, BUFSIZ
), ifa
->ifa_prefixlen
);
587 zlog_debug (" IFA_ADDRESS %s/%d",
588 inet_ntop (ifa
->ifa_family
, RTA_DATA (tb
[IFA_ADDRESS
]),
589 buf
, BUFSIZ
), ifa
->ifa_prefixlen
);
590 if (tb
[IFA_BROADCAST
])
591 zlog_debug (" IFA_BROADCAST %s/%d",
592 inet_ntop (ifa
->ifa_family
, RTA_DATA (tb
[IFA_BROADCAST
]),
593 buf
, BUFSIZ
), ifa
->ifa_prefixlen
);
594 if (tb
[IFA_LABEL
] && strcmp (ifp
->name
, RTA_DATA (tb
[IFA_LABEL
])))
595 zlog_debug (" IFA_LABEL %s", (char *)RTA_DATA (tb
[IFA_LABEL
]));
597 if (tb
[IFA_CACHEINFO
])
599 struct ifa_cacheinfo
*ci
= RTA_DATA (tb
[IFA_CACHEINFO
]);
600 zlog_debug (" IFA_CACHEINFO pref %d, valid %d",
601 ci
->ifa_prefered
, ci
->ifa_valid
);
605 /* logic copied from iproute2/ip/ipaddress.c:print_addrinfo() */
606 if (tb
[IFA_LOCAL
] == NULL
)
607 tb
[IFA_LOCAL
] = tb
[IFA_ADDRESS
];
608 if (tb
[IFA_ADDRESS
] == NULL
)
609 tb
[IFA_ADDRESS
] = tb
[IFA_LOCAL
];
611 /* local interface address */
612 addr
= (tb
[IFA_LOCAL
] ? RTA_DATA(tb
[IFA_LOCAL
]) : NULL
);
614 /* is there a peer address? */
615 if (tb
[IFA_ADDRESS
] &&
616 memcmp(RTA_DATA(tb
[IFA_ADDRESS
]), RTA_DATA(tb
[IFA_LOCAL
]), RTA_PAYLOAD(tb
[IFA_ADDRESS
])))
618 broad
= RTA_DATA(tb
[IFA_ADDRESS
]);
619 SET_FLAG (flags
, ZEBRA_IFA_PEER
);
622 /* seeking a broadcast address */
623 broad
= (tb
[IFA_BROADCAST
] ? RTA_DATA(tb
[IFA_BROADCAST
]) : NULL
);
625 /* addr is primary key, SOL if we don't have one */
628 zlog_debug ("%s: NULL address", __func__
);
633 if (ifa
->ifa_flags
& IFA_F_SECONDARY
)
634 SET_FLAG (flags
, ZEBRA_IFA_SECONDARY
);
638 label
= (char *) RTA_DATA (tb
[IFA_LABEL
]);
640 if (ifp
&& label
&& strcmp (ifp
->name
, label
) == 0)
643 /* Register interface address to the interface. */
644 if (ifa
->ifa_family
== AF_INET
)
646 if (h
->nlmsg_type
== RTM_NEWADDR
)
647 connected_add_ipv4 (ifp
, flags
,
648 (struct in_addr
*) addr
, ifa
->ifa_prefixlen
,
649 (struct in_addr
*) broad
, label
);
651 connected_delete_ipv4 (ifp
, flags
,
652 (struct in_addr
*) addr
, ifa
->ifa_prefixlen
,
653 (struct in_addr
*) broad
);
655 if (ifa
->ifa_family
== AF_INET6
)
657 if (h
->nlmsg_type
== RTM_NEWADDR
)
659 /* Only consider valid addresses; we'll not get a notification from
660 * the kernel till IPv6 DAD has completed, but at init time, Quagga
661 * does query for and will receive all addresses.
663 if (!(ifa
->ifa_flags
& (IFA_F_DADFAILED
| IFA_F_TENTATIVE
)))
664 connected_add_ipv6 (ifp
, flags
, (struct in6_addr
*) addr
,
665 ifa
->ifa_prefixlen
, (struct in6_addr
*) broad
, label
);
668 connected_delete_ipv6 (ifp
,
669 (struct in6_addr
*) addr
, ifa
->ifa_prefixlen
,
670 (struct in6_addr
*) broad
);
677 netlink_link_change (struct sockaddr_nl
*snl
, struct nlmsghdr
*h
,
678 ns_id_t ns_id
, int startup
)
681 struct ifinfomsg
*ifi
;
682 struct rtattr
*tb
[IFLA_MAX
+ 1];
683 struct rtattr
*linkinfo
[IFLA_MAX
+ 1];
684 struct interface
*ifp
;
687 char *slave_kind
= NULL
;
689 struct zebra_ns
*zns
;
690 vrf_id_t vrf_id
= VRF_DEFAULT
;
692 zns
= zebra_ns_lookup (ns_id
);
693 ifi
= NLMSG_DATA (h
);
695 if (!(h
->nlmsg_type
== RTM_NEWLINK
|| h
->nlmsg_type
== RTM_DELLINK
))
697 /* If this is not link add/delete message so print warning. */
698 zlog_warn ("netlink_link_change: wrong kernel message %d",
703 len
= h
->nlmsg_len
- NLMSG_LENGTH (sizeof (struct ifinfomsg
));
707 if (ifi
->ifi_family
== AF_BRIDGE
)
710 /* Looking up interface name. */
711 memset (tb
, 0, sizeof tb
);
712 netlink_parse_rtattr (tb
, IFLA_MAX
, IFLA_RTA (ifi
), len
);
715 /* check for wireless messages to ignore */
716 if ((tb
[IFLA_WIRELESS
] != NULL
) && (ifi
->ifi_change
== 0))
718 if (IS_ZEBRA_DEBUG_KERNEL
)
719 zlog_debug ("%s: ignoring IFLA_WIRELESS message", __func__
);
722 #endif /* IFLA_WIRELESS */
724 if (tb
[IFLA_IFNAME
] == NULL
)
726 name
= (char *) RTA_DATA (tb
[IFLA_IFNAME
]);
728 if (tb
[IFLA_LINKINFO
])
730 memset (linkinfo
, 0, sizeof linkinfo
);
731 parse_rtattr_nested(linkinfo
, IFLA_INFO_MAX
, tb
[IFLA_LINKINFO
]);
733 if (linkinfo
[IFLA_INFO_KIND
])
734 kind
= RTA_DATA(linkinfo
[IFLA_INFO_KIND
]);
736 #if HAVE_DECL_IFLA_INFO_SLAVE_KIND
737 if (linkinfo
[IFLA_INFO_SLAVE_KIND
])
738 slave_kind
= RTA_DATA(linkinfo
[IFLA_INFO_SLAVE_KIND
]);
741 if (kind
&& strcmp(kind
, "vrf") == 0)
744 netlink_vrf_change(h
, tb
[IFLA_LINKINFO
], name
);
745 vrf_id
= (vrf_id_t
)ifi
->ifi_index
;
749 /* See if interface is present. */
750 ifp
= if_lookup_by_name_per_ns (zns
, name
);
752 if (h
->nlmsg_type
== RTM_NEWLINK
)
756 if (slave_kind
&& (strcmp(slave_kind
, "vrf") == 0))
757 vrf_id
= *(u_int32_t
*)RTA_DATA(tb
[IFLA_MASTER
]);
760 if (ifp
== NULL
|| !CHECK_FLAG (ifp
->status
, ZEBRA_INTERFACE_ACTIVE
))
762 /* Add interface notification from kernel */
763 if (IS_ZEBRA_DEBUG_KERNEL
)
764 zlog_debug ("RTM_NEWLINK for %s(%u) (ifp %p) vrf_id %u flags 0x%x",
765 name
, ifi
->ifi_index
, ifp
, vrf_id
, ifi
->ifi_flags
);
769 /* unknown interface */
770 ifp
= if_get_by_name (name
, vrf_id
);
774 /* pre-configured interface, learnt now */
775 if (ifp
->vrf_id
!= vrf_id
)
776 if_update (ifp
, name
, strlen(name
), vrf_id
);
779 /* Update interface information. */
780 set_ifindex(ifp
, ifi
->ifi_index
, zns
);
781 ifp
->flags
= ifi
->ifi_flags
& 0x0000fffff;
783 SET_FLAG(ifp
->status
, ZEBRA_INTERFACE_VRF_LOOPBACK
);
784 ifp
->mtu6
= ifp
->mtu
= *(int *) RTA_DATA (tb
[IFLA_MTU
]);
786 ifp
->ptm_status
= ZEBRA_PTM_STATUS_UNKNOWN
;
788 netlink_interface_update_hw_addr (tb
, ifp
);
790 /* Inform clients, install any configured addresses. */
793 else if (ifp
->vrf_id
!= vrf_id
)
795 /* VRF change for an interface. */
796 if (IS_ZEBRA_DEBUG_KERNEL
)
797 zlog_debug ("RTM_NEWLINK vrf-change for %s(%u) "
798 "vrf_id %u -> %u flags 0x%x",
799 name
, ifp
->ifindex
, ifp
->vrf_id
,
800 vrf_id
, ifi
->ifi_flags
);
802 if_handle_vrf_change (ifp
, vrf_id
);
806 /* Interface status change. */
807 if (IS_ZEBRA_DEBUG_KERNEL
)
808 zlog_debug ("RTM_NEWLINK status for %s(%u) flags 0x%x",
809 name
, ifp
->ifindex
, ifi
->ifi_flags
);
811 set_ifindex(ifp
, ifi
->ifi_index
, zns
);
812 ifp
->mtu6
= ifp
->mtu
= *(int *) RTA_DATA (tb
[IFLA_MTU
]);
815 netlink_interface_update_hw_addr (tb
, ifp
);
817 if (if_is_no_ptm_operative (ifp
))
819 ifp
->flags
= ifi
->ifi_flags
& 0x0000fffff;
820 if (!if_is_no_ptm_operative (ifp
))
822 else if (if_is_operative (ifp
))
823 /* Must notify client daemons of new interface status. */
824 zebra_interface_up_update (ifp
);
828 ifp
->flags
= ifi
->ifi_flags
& 0x0000fffff;
829 if (if_is_operative (ifp
))
836 /* Delete interface notification from kernel */
839 zlog_warn ("RTM_DELLINK for unknown interface %s(%u)",
840 name
, ifi
->ifi_index
);
844 if (IS_ZEBRA_DEBUG_KERNEL
)
845 zlog_debug ("RTM_DELLINK for %s(%u)", name
, ifp
->ifindex
);
847 UNSET_FLAG(ifp
->status
, ZEBRA_INTERFACE_VRF_LOOPBACK
);
850 if_delete_update (ifp
);
856 /* Interface information read by netlink. */
858 interface_list (struct zebra_ns
*zns
)
860 interface_lookup_netlink (zns
);