Bring eventhandler callbacks for pf.

This enables pf to track dynamic address changes on interfaces (dailup) with
the "on (<ifname>)"-syntax. This also brings hooks in anticipation of
tracking cloned interfaces, which will be in future versions of pf.

Approved by: bms(mentor)
This commit is contained in:
Max Laier 2004-02-26 04:27:55 +00:00
parent cc5934f5af
commit 25a4adcec4
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=126264
4 changed files with 28 additions and 0 deletions

View File

@ -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;

View File

@ -78,6 +78,7 @@ struct ether_header;
#ifdef _KERNEL
#include <sys/mbuf.h>
#include <sys/eventhandler.h>
#endif /* _KERNEL */
#include <sys/lock.h> /* XXX */
#include <sys/mutex.h> /* 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)

View File

@ -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;

View File

@ -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;
}