From 8819ad852fcc38e42412f60687955b48439e1db7 Mon Sep 17 00:00:00 2001 From: Sepherosa Ziehau Date: Mon, 24 Jul 2017 03:32:10 +0000 Subject: [PATCH] ethernet: Add ethernet interface attached event and devctl notification. ifnet_arrival_event may not be adequate under certain situation; e.g. when the LLADDR is needed. So the ethernet ifattach event is announced after all necessary bits are setup. MFC after: 3 days Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D11617 --- sys/net/ethernet.h | 6 ++++++ sys/net/if_ethersubr.c | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/sys/net/ethernet.h b/sys/net/ethernet.h index bc5fa9cb33f7..5cd1dc501343 100644 --- a/sys/net/ethernet.h +++ b/sys/net/ethernet.h @@ -406,6 +406,12 @@ void ether_vlan_mtap(struct bpf_if *, struct mbuf *, void *, u_int); struct mbuf *ether_vlanencap(struct mbuf *, uint16_t); +#ifdef _SYS_EVENTHANDLER_H_ +/* new ethernet interface attached event */ +typedef void (*ether_ifattach_event_handler_t)(void *, struct ifnet *); +EVENTHANDLER_DECLARE(ether_ifattach_event, ether_ifattach_event_handler_t); +#endif + #else /* _KERNEL */ #include diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c index 7b1ba85c617f..7d5f1dc61c11 100644 --- a/sys/net/if_ethersubr.c +++ b/sys/net/if_ethersubr.c @@ -38,6 +38,8 @@ #include #include +#include +#include #include #include #include @@ -931,6 +933,11 @@ ether_ifattach(struct ifnet *ifp, const u_int8_t *lla) if_printf(ifp, "Ethernet address: %6D\n", lla, ":"); uuid_ether_add(LLADDR(sdl)); + + /* Add necessary bits are setup; announce it now. */ + EVENTHANDLER_INVOKE(ether_ifattach_event, ifp); + if (IS_DEFAULT_VNET(curvnet)) + devctl_notify("ETHERNET", ifp->if_xname, "IFATTACH", NULL); } /*