git: f5de03cb2c69 - stable/13 - rtsock: subscribe to ifnet eventhandlers instead of direct calls.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 13 Jan 2023 21:25:41 UTC
The branch stable/13 has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=f5de03cb2c693e8eb3170992d3aab8cd1a940478 commit f5de03cb2c693e8eb3170992d3aab8cd1a940478 Author: Alexander V. Chernikov <melifaro@FreeBSD.org> AuthorDate: 2022-08-11 20:09:45 +0000 Commit: Alexander V. Chernikov <melifaro@FreeBSD.org> CommitDate: 2023-01-13 21:24:11 +0000 rtsock: subscribe to ifnet eventhandlers instead of direct calls. Stop treating rtsock as a "special" consumer and use already-provided ifaddr arrival/departure notifications. MFC after: 2 weeks Test Plan: ``` 21:05 [0] m@devel0 route -n monitor -> ifconfig vtnet0.2 create got message of size 24 on Tue Aug 9 21:05:44 2022 RTM_IFANNOUNCE: interface arrival/departure: len 24, if# 3, what: arrival got message of size 168 on Tue Aug 9 21:05:54 2022 RTM_IFINFO: iface status change: len 168, if# 3, link: up, flags:<BROADCAST,RUNNING,SIMPLEX,MULTICAST> -> ifconfig vtnet0.2 destroy got message of size 24 on Tue Aug 9 21:05:54 2022 RTM_IFANNOUNCE: interface arrival/departure: len 24, if# 3, what: departure ``` Reviewed By: glebius Differential Revision: https://reviews.freebsd.org/D36095 MFC after: 2 weeks (cherry picked from commit d8b42ddcac5cb86af679968d09c45c9a7cc3e4fb) --- sys/net/if.c | 9 --------- sys/net/route.h | 1 - sys/net/rtsock.c | 17 ++++++++++++++++- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/sys/net/if.c b/sys/net/if.c index bcebd84306c8..d42b642e8d18 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1006,9 +1006,6 @@ if_attach_internal(struct ifnet *ifp, int vmove, struct if_clone *ifc) EVENTHANDLER_INVOKE(ifnet_arrival_event, ifp); if (IS_DEFAULT_VNET(curvnet)) devctl_notify("IFNET", ifp->if_xname, "ATTACH", NULL); - - /* Announce the interface. */ - rt_ifannouncemsg(ifp, IFAN_ARRIVAL); } static void @@ -1258,8 +1255,6 @@ if_detach_internal(struct ifnet *ifp, int vmove, struct if_clone **ifcp) #endif if_purgemaddrs(ifp); - /* Announce that the interface is gone. */ - rt_ifannouncemsg(ifp, IFAN_DEPARTURE); EVENTHANDLER_INVOKE(ifnet_departure_event, ifp); if (IS_DEFAULT_VNET(curvnet)) devctl_notify("IFNET", ifp->if_xname, "DETACH", NULL); @@ -2691,8 +2686,6 @@ ifhwioctl(u_long cmd, struct ifnet *ifp, caddr_t data, struct thread *td) */ ifp->if_flags |= IFF_RENAMING; - /* Announce the departure of the interface. */ - rt_ifannouncemsg(ifp, IFAN_DEPARTURE); EVENTHANDLER_INVOKE(ifnet_departure_event, ifp); if_printf(ifp, "changing name to '%s'\n", new_name); @@ -2721,8 +2714,6 @@ ifhwioctl(u_long cmd, struct ifnet *ifp, caddr_t data, struct thread *td) IF_ADDR_WUNLOCK(ifp); EVENTHANDLER_INVOKE(ifnet_arrival_event, ifp); - /* Announce the return of the interface. */ - rt_ifannouncemsg(ifp, IFAN_ARRIVAL); ifp->if_flags &= ~IFF_RENAMING; break; diff --git a/sys/net/route.h b/sys/net/route.h index 53b54493b6c4..a2394d54b92f 100644 --- a/sys/net/route.h +++ b/sys/net/route.h @@ -415,7 +415,6 @@ struct ifmultiaddr; struct rib_head; void rt_ieee80211msg(struct ifnet *, int, void *, size_t); -void rt_ifannouncemsg(struct ifnet *, int); void rt_ifmsg(struct ifnet *); void rt_missmsg(int, struct rt_addrinfo *, int, int); void rt_missmsg_fib(int, struct rt_addrinfo *, int, int, int); diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index 85f1c2472742..0a5a58ad3c05 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -198,6 +198,7 @@ static int route_output(struct mbuf *m, struct socket *so, ...); static void rt_getmetrics(const struct rtentry *rt, const struct nhop_object *nh, struct rt_metrics *out); static void rt_dispatch(struct mbuf *, sa_family_t); +static void rt_ifannouncemsg(struct ifnet *ifp, int what); static int handle_rtm_get(struct rt_addrinfo *info, u_int fibnum, struct rt_msghdr *rtm, struct rib_cmd_info *rc); static int update_rtm_from_rc(struct rt_addrinfo *info, @@ -263,6 +264,20 @@ VNET_SYSUNINIT(vnet_rts_uninit, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, vnet_rts_uninit, 0); #endif +static void +rts_handle_ifnet_arrival(void *arg __unused, struct ifnet *ifp) +{ + rt_ifannouncemsg(ifp, IFAN_ARRIVAL); +} +EVENTHANDLER_DEFINE(ifnet_arrival_event, rts_handle_ifnet_arrival, NULL, 0); + +static void +rts_handle_ifnet_departure(void *arg __unused, struct ifnet *ifp) +{ + rt_ifannouncemsg(ifp, IFAN_DEPARTURE); +} +EVENTHANDLER_DEFINE(ifnet_departure_event, rts_handle_ifnet_departure, NULL, 0); + static int raw_input_rts_cb(struct mbuf *m, struct sockproto *proto, struct sockaddr *src, struct rawcb *rp) @@ -2169,7 +2184,7 @@ rt_ieee80211msg(struct ifnet *ifp, int what, void *data, size_t data_len) * This is called to generate routing socket messages indicating * network interface arrival and departure. */ -void +static void rt_ifannouncemsg(struct ifnet *ifp, int what) { struct mbuf *m;