diff options
Diffstat (limited to 'sys/net/pfil.h')
-rw-r--r-- | sys/net/pfil.h | 68 |
1 files changed, 50 insertions, 18 deletions
diff --git a/sys/net/pfil.h b/sys/net/pfil.h index 057a531..b1f29ae 100644 --- a/sys/net/pfil.h +++ b/sys/net/pfil.h @@ -1,4 +1,5 @@ -/* $FreeBSD$ */ +/* $FreeBSD$ */ +/* $NetBSD: pfil.h,v 1.22 2003/06/23 12:57:08 martin Exp $ */ /* * Copyright (c) 1996 Matthew R. Green @@ -31,6 +32,10 @@ #ifndef _NET_PFIL_H_ #define _NET_PFIL_H_ +#include <sys/systm.h> +#include <sys/_lock.h> +#include <sys/_mutex.h> +#include <sys/condvar.h> /* XXX */ #include <sys/queue.h> struct mbuf; @@ -42,7 +47,8 @@ struct ifnet; */ struct packet_filter_hook { TAILQ_ENTRY(packet_filter_hook) pfil_link; - int (*pfil_func)(void *, int, struct ifnet *, int, struct mbuf **); + int (*pfil_func)(void *, struct mbuf **, struct ifnet *, int); + void *pfil_arg; int pfil_flags; }; @@ -53,28 +59,54 @@ struct packet_filter_hook { typedef TAILQ_HEAD(pfil_list, packet_filter_hook) pfil_list_t; +#define PFIL_TYPE_AF 1 /* key is AF_* type */ +#define PFIL_TYPE_IFNET 2 /* key is ifnet pointer */ + struct pfil_head { pfil_list_t ph_in; pfil_list_t ph_out; - int ph_init; + int ph_type; + /* + * Locking: use a busycounter per pfil_head. + * Use ph_busy_count = -1 to indicate pfil_head is empty. + */ + int ph_busy_count; /* count of threads with read lock */ + int ph_want_write; /* want write lock flag */ + struct cv ph_cv; /* for waking up writers */ + struct mtx ph_mtx; /* mutex on locking state */ + union { + u_long phu_val; + void *phu_ptr; + } ph_un; +#define ph_af ph_un.phu_val +#define ph_ifnet ph_un.phu_ptr + LIST_ENTRY(pfil_head) ph_list; }; -struct packet_filter_hook *pfil_hook_get(int, struct pfil_head *); -int pfil_add_hook(int (*func)(void *, int, - struct ifnet *, int, struct mbuf **), int, struct pfil_head *); -int pfil_remove_hook(int (*func)(void *, int, - struct ifnet *, int, struct mbuf **), int, struct pfil_head *); +int pfil_run_hooks(struct pfil_head *, struct mbuf **, struct ifnet *, + int); + +int pfil_add_hook(int (*func)(void *, struct mbuf **, + struct ifnet *, int), void *, int, struct pfil_head *); +int pfil_remove_hook(int (*func)(void *, struct mbuf **, + struct ifnet *, int), void *, int, struct pfil_head *); + +int pfil_head_register(struct pfil_head *); +int pfil_head_unregister(struct pfil_head *); -/* XXX */ -#if defined(_KERNEL) && !defined(KLD_MODULE) -#include "opt_ipfilter.h" -#endif +struct pfil_head *pfil_head_get(int, u_long); -#if IPFILTER > 0 -#ifdef PFIL_HOOKS -#undef PFIL_HOOKS -#endif -#define PFIL_HOOKS -#endif /* IPFILTER */ +static __inline struct packet_filter_hook * +pfil_hook_get(int dir, struct pfil_head *ph) +{ + KASSERT(ph->ph_busy_count > 0, + ("pfil_hook_get: called on unbusy pfil_head")); + if (dir == PFIL_IN) + return (TAILQ_FIRST(&ph->ph_in)); + else if (dir == PFIL_OUT) + return (TAILQ_FIRST(&ph->ph_out)); + else + return (NULL); +} #endif /* _NET_PFIL_H_ */ |