From 25a4adcec4fbbe1b0686712771fdd8ab6bd3d7a0 Mon Sep 17 00:00:00 2001 From: Max Laier Date: Thu, 26 Feb 2004 04:27:55 +0000 Subject: [PATCH] Bring eventhandler callbacks for pf. This enables pf to track dynamic address changes on interfaces (dailup) with the "on ()"-syntax. This also brings hooks in anticipation of tracking cloned interfaces, which will be in future versions of pf. Approved by: bms(mentor) --- sys/net/if.c | 6 ++++++ sys/net/if_var.h | 14 ++++++++++++++ sys/netinet/in.c | 5 +++++ sys/netinet6/in6.c | 3 +++ 4 files changed, 28 insertions(+) diff --git a/sys/net/if.c b/sys/net/if.c index 8cea0c4fe5d4..1d412f9e7407 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -447,6 +447,8 @@ if_attach(struct ifnet *ifp) if (domains) if_attachdomain1(ifp); + EVENTHANDLER_INVOKE(ifnet_arrival_event, ifp); + /* Announce the interface. */ rt_ifannouncemsg(ifp, IFAN_ARRIVAL); } @@ -513,6 +515,7 @@ if_detach(struct ifnet *ifp) int i; struct domain *dp; + EVENTHANDLER_INVOKE(ifnet_departure_event, ifp); /* * Remove routes and flush queues. */ @@ -843,6 +846,7 @@ if_clone_attach(struct if_clone *ifc) bitoff = unit - (bytoff << 3); ifc->ifc_units[bytoff] |= (1 << bitoff); } + EVENTHANDLER_INVOKE(if_clone_event, ifc); } /* @@ -1378,6 +1382,7 @@ ifhwioctl(u_long cmd, struct ifnet *ifp, caddr_t data, struct thread *td) if (ifunit(new_name) != NULL) return (EEXIST); + EVENTHANDLER_INVOKE(ifnet_departure_event, ifp); /* Announce the departure of the interface. */ rt_ifannouncemsg(ifp, IFAN_DEPARTURE); @@ -1404,6 +1409,7 @@ ifhwioctl(u_long cmd, struct ifnet *ifp, caddr_t data, struct thread *td) sdl->sdl_data[--namelen] = 0xff; IFA_UNLOCK(ifa); + EVENTHANDLER_INVOKE(ifnet_arrival_event, ifp); /* Announce the return of the interface. */ rt_ifannouncemsg(ifp, IFAN_ARRIVAL); break; diff --git a/sys/net/if_var.h b/sys/net/if_var.h index a2f91789aa3f..5ddd72b63442 100644 --- a/sys/net/if_var.h +++ b/sys/net/if_var.h @@ -78,6 +78,7 @@ struct ether_header; #ifdef _KERNEL #include +#include #endif /* _KERNEL */ #include /* XXX */ #include /* XXX */ @@ -293,6 +294,19 @@ typedef void if_init_f_t(void *); } while (0) #ifdef _KERNEL +/* interface address change event */ +typedef void (*ifaddr_event_handler_t)(void *, struct ifnet *); +EVENTHANDLER_DECLARE(ifaddr_event, ifaddr_event_handler_t); +/* new interface arrival event */ +typedef void (*ifnet_arrival_event_handler_t)(void *, struct ifnet *); +EVENTHANDLER_DECLARE(ifnet_arrival_event, ifnet_arrival_event_handler_t); +/* interface departure event */ +typedef void (*ifnet_departure_event_handler_t)(void *, struct ifnet *); +EVENTHANDLER_DECLARE(ifnet_departure_event, ifnet_departure_event_handler_t); +/* interface clone event */ +typedef void (*if_clone_event_handler_t)(void *, struct if_clone *); +EVENTHANDLER_DECLARE(if_clone_event, if_clone_event_handler_t); + #define IF_AFDATA_LOCK_INIT(ifp) \ mtx_init(&(ifp)->if_afdata_mtx, "if_afdata", NULL, MTX_DEF) #define IF_AFDATA_LOCK(ifp) mtx_lock(&(ifp)->if_afdata_mtx) diff --git a/sys/netinet/in.c b/sys/netinet/in.c index 187ed937f9c1..1873ae4ceeaf 100644 --- a/sys/netinet/in.c +++ b/sys/netinet/in.c @@ -363,6 +363,8 @@ in_control(so, cmd, data, ifp, td) (struct sockaddr_in *) &ifr->ifr_addr, 1); if (error != 0 && iaIsNew) break; + if (error == 0) + EVENTHANDLER_INVOKE(ifaddr_event, ifp); return (0); case SIOCSIFNETMASK: @@ -405,6 +407,8 @@ in_control(so, cmd, data, ifp, td) if ((ifp->if_flags & IFF_BROADCAST) && (ifra->ifra_broadaddr.sin_family == AF_INET)) ia->ia_broadaddr = ifra->ifra_broadaddr; + if (error == 0) + EVENTHANDLER_INVOKE(ifaddr_event, ifp); return (error); case SIOCDIFADDR: @@ -427,6 +431,7 @@ in_control(so, cmd, data, ifp, td) in_pcbpurgeif0(&ripcbinfo, ifp); in_pcbpurgeif0(&udbinfo, ifp); } + EVENTHANDLER_INVOKE(ifaddr_event, ifp); error = 0; break; diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c index 801472a9d0b5..4c0dd5bade34 100644 --- a/sys/netinet6/in6.c +++ b/sys/netinet6/in6.c @@ -667,6 +667,8 @@ in6_control(so, cmd, data, ifp, td) */ pfxlist_onlink_check(); } + if (error == 0 && ia) + EVENTHANDLER_INVOKE(ifaddr_event, ifp); break; } @@ -714,6 +716,7 @@ in6_control(so, cmd, data, ifp, td) purgeaddr: in6_purgeaddr(&ia->ia_ifa); + EVENTHANDLER_INVOKE(ifaddr_event, ifp); break; }