Slight adjustment to how pfil_head's are registered. Instead of a

"key" and a "dlt", use a "type" (PFIL_TYPE_{AF,IFNET} for now) and
a val/ptr appropriate for that type.  This allows for more future
flexibility with the pfil_hook mechanism.
This commit is contained in:
thorpej 2000-12-22 20:01:17 +00:00
parent 2ac441ddfb
commit d0357bdb4f
5 changed files with 32 additions and 25 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: pfil.c,v 1.16 2000/11/11 00:52:36 thorpej Exp $ */
/* $NetBSD: pfil.c,v 1.17 2000/12/22 20:01:17 thorpej Exp $ */
/*
* Copyright (c) 1996 Matthew R. Green
@ -84,8 +84,8 @@ pfil_head_register(struct pfil_head *ph)
for (lph = LIST_FIRST(&pfil_head_list); lph != NULL;
lph = LIST_NEXT(lph, ph_list)) {
if (lph->ph_key == ph->ph_key &&
lph->ph_dlt == ph->ph_dlt)
if (ph->ph_type == lph->ph_type &&
ph->ph_un.phu_val == lph->ph_un.phu_val)
return EEXIST;
}
@ -113,13 +113,14 @@ pfil_head_unregister(struct pfil_head *pfh)
* pfil_head_get() returns the pfil_head for a given key/dlt.
*/
struct pfil_head *
pfil_head_get(void *key, int dlt)
pfil_head_get(int type, u_long val)
{
struct pfil_head *ph;
for (ph = LIST_FIRST(&pfil_head_list); ph != NULL;
ph = LIST_NEXT(ph, ph_list)) {
if (ph->ph_key == key && ph->ph_dlt == dlt)
if (ph->ph_type == type &&
ph->ph_un.phu_val == val)
break;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pfil.h,v 1.15 2000/12/12 18:03:25 thorpej Exp $ */
/* $NetBSD: pfil.h,v 1.16 2000/12/22 20:01:17 thorpej Exp $ */
/*
* Copyright (c) 1996 Matthew R. Green
@ -55,11 +55,19 @@ 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;
void *ph_key;
int ph_dlt;
int ph_type;
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;
};
typedef struct pfil_head pfil_head_t;
@ -75,7 +83,7 @@ int pfil_remove_hook(int (*func)(void *, struct mbuf **,
int pfil_head_register(struct pfil_head *);
int pfil_head_unregister(struct pfil_head *);
struct pfil_head *pfil_head_get(void *, int);
struct pfil_head *pfil_head_get(int, u_long);
static __inline struct packet_filter_hook *
pfil_hook_get(int dir, struct pfil_head *ph)

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip_fil.c,v 1.60 2000/11/11 00:52:38 thorpej Exp $ */
/* $NetBSD: ip_fil.c,v 1.61 2000/12/22 20:01:18 thorpej Exp $ */
/*
* Copyright (C) 1993-2000 by Darren Reed.
@ -9,7 +9,7 @@
*/
#if !defined(lint)
#if defined(__NetBSD__)
static const char rcsid[] = "$NetBSD: ip_fil.c,v 1.60 2000/11/11 00:52:38 thorpej Exp $";
static const char rcsid[] = "$NetBSD: ip_fil.c,v 1.61 2000/12/22 20:01:18 thorpej Exp $";
#else
static const char sccsid[] = "@(#)ip_fil.c 2.41 6/5/96 (C) 1993-2000 Darren Reed";
static const char rcsid[] = "@(#)Id: ip_fil.c,v 2.42.2.15 2000/08/05 14:49:08 darrenr Exp";
@ -270,10 +270,10 @@ int iplattach()
return EIO;
# ifdef NETBSD_PF
# if __NetBSD_Version__ >= 105110000
ph_inet = pfil_head_get((void *)(u_long) AF_INET, DLT_RAW);
# if __NetBSD_Version__ >= 105150000
ph_inet = pfil_head_get(PFIL_TYPE_AF, AF_INET);
#ifdef USE_INET6
ph_inet6 = pfil_head_get((void *)(u_long) AF_INET6, DLT_RAW);
ph_inet6 = pfil_head_get(PFIL_TYPE_AF, AF_INET);
#endif
if (ph_inet == NULL
#ifdef USE_INET6
@ -393,12 +393,10 @@ int ipldetach()
{
int s, i = FR_INQUE|FR_OUTQUE;
#if defined(NETBSD_PF) && (__NetBSD_Version__ >= 104200000)
# if __NetBSD_Version__ >= 105110000
struct pfil_head *ph_inet = pfil_head_get((void *)(u_long) AF_INET,
DLT_RAW);
# if __NetBSD_Version__ >= 105150000
struct pfil_head *ph_inet = pfil_head_get(PFIL_TYPE_AF, AF_INET);
#ifdef USE_INET6
struct pfil_head *ph_inet6 = pfil_head_get((void *)(u_long) AF_INET6,
DLT_RAW);
struct pfil_head *ph_inet6 = pfil_head_get(PFIL_TYPE_AF, AF_INET6);
#endif
# endif
int error = 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip_input.c,v 1.123 2000/12/14 17:36:44 thorpej Exp $ */
/* $NetBSD: ip_input.c,v 1.124 2000/12/22 20:01:18 thorpej Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -319,8 +319,8 @@ ip_init()
#ifdef PFIL_HOOKS
/* Register our Packet Filter hook. */
inet_pfil_hook.ph_key = (void *)(u_long) AF_INET;
inet_pfil_hook.ph_dlt = DLT_RAW;
inet_pfil_hook.ph_type = PFIL_TYPE_AF;
inet_pfil_hook.ph_af = AF_INET;
i = pfil_head_register(&inet_pfil_hook);
if (i != 0)
printf("ip_init: WARNING: unable to register pfil hook, "

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip6_input.c,v 1.30 2000/12/14 17:36:45 thorpej Exp $ */
/* $NetBSD: ip6_input.c,v 1.31 2000/12/22 20:01:18 thorpej Exp $ */
/* $KAME: ip6_input.c,v 1.121 2000/08/31 06:07:29 itojun Exp $ */
/*
@ -188,8 +188,8 @@ ip6_init()
#ifdef PFIL_HOOKS
/* Register our Packet Filter hook. */
inet6_pfil_hook.ph_key = (void *)(u_long) AF_INET6;
inet6_pfil_hook.ph_dlt = DLT_RAW;
inet6_pfil_hook.ph_type = PFIL_TYPE_AF;
inet6_pfil_hook.ph_af = AF_INET6;
i = pfil_head_register(&inet6_pfil_hook);
if (i != 0)
printf("ip6_init: WARNING: unable to register pfil hook, "