#ifndef _NET_PFIL_H_
#define _NET_PFIL_H_
#include <sys/ioccom.h>
enum pfil_types {
PFIL_TYPE_IP4,
PFIL_TYPE_IP6,
PFIL_TYPE_ETHERNET,
};
#define MAXPFILNAME 64
struct pfilioc_head {
char pio_name[MAXPFILNAME];
int pio_nhooksin;
int pio_nhooksout;
enum pfil_types pio_type;
};
struct pfilioc_hook {
char pio_module[MAXPFILNAME];
char pio_ruleset[MAXPFILNAME];
int pio_flags;
enum pfil_types pio_type;
};
struct pfilioc_list {
u_int pio_nheads;
u_int pio_nhooks;
struct pfilioc_head *pio_heads;
struct pfilioc_hook *pio_hooks;
};
struct pfilioc_link {
char pio_name[MAXPFILNAME];
char pio_module[MAXPFILNAME];
char pio_ruleset[MAXPFILNAME];
int pio_flags;
};
#define PFILDEV "pfil"
#define PFILIOC_LISTHEADS _IOWR('P', 1, struct pfilioc_list)
#define PFILIOC_LISTHOOKS _IOWR('P', 2, struct pfilioc_list)
#define PFILIOC_LINK _IOW('P', 3, struct pfilioc_link)
#define PFIL_IN 0x00010000
#define PFIL_OUT 0x00020000
#define PFIL_FWD 0x00040000
#define PFIL_DIR(f) ((f) & (PFIL_IN|PFIL_OUT))
#define PFIL_HEADPTR 0x00100000
#define PFIL_HOOKPTR 0x00200000
#define PFIL_APPEND 0x00400000
#define PFIL_UNLINK 0x00800000
#ifdef _KERNEL
struct mbuf;
struct ifnet;
struct inpcb;
typedef enum {
PFIL_PASS = 0,
PFIL_DROPPED,
PFIL_CONSUMED,
PFIL_REALLOCED,
} pfil_return_t;
typedef pfil_return_t (*pfil_mbuf_chk_t)(struct mbuf **, struct ifnet *, int,
void *, struct inpcb *);
typedef pfil_return_t (*pfil_mem_chk_t)(void *, u_int, int, struct ifnet *,
void *, struct mbuf **);
typedef struct pfil_hook * pfil_hook_t;
typedef struct pfil_head * pfil_head_t;
#define PFIL_VERSION 2
struct pfil_hook_args {
int pa_version;
int pa_flags;
enum pfil_types pa_type;
pfil_mbuf_chk_t pa_mbuf_chk;
pfil_mem_chk_t pa_mem_chk;
void *pa_ruleset;
const char *pa_modname;
const char *pa_rulname;
};
pfil_hook_t pfil_add_hook(struct pfil_hook_args *);
void pfil_remove_hook(pfil_hook_t);
struct pfil_link_args {
int pa_version;
int pa_flags;
union {
const char *pa_headname;
pfil_head_t pa_head;
};
union {
struct {
const char *pa_modname;
const char *pa_rulname;
};
pfil_hook_t pa_hook;
};
};
int pfil_link(struct pfil_link_args *);
struct pfil_head_args {
int pa_version;
int pa_flags;
enum pfil_types pa_type;
const char *pa_headname;
};
pfil_head_t pfil_head_register(struct pfil_head_args *);
void pfil_head_unregister(pfil_head_t);
int pfil_mem_in(struct pfil_head *, void *, u_int, struct ifnet *,
struct mbuf **);
int pfil_mem_out(struct pfil_head *, void *, u_int, struct ifnet *,
struct mbuf **);
int pfil_mbuf_in(struct pfil_head *, struct mbuf **, struct ifnet *,
struct inpcb *inp);
int pfil_mbuf_out(struct pfil_head *, struct mbuf **, struct ifnet *,
struct inpcb *inp);
int pfil_mbuf_fwd(struct pfil_head *, struct mbuf **, struct ifnet *,
struct inpcb *);
struct _pfil_head {
int head_nhooksin;
int head_nhooksout;
};
#define PFIL_HOOKED_IN(p) (((struct _pfil_head *)(p))->head_nhooksin > 0)
#define PFIL_HOOKED_OUT(p) (((struct _pfil_head *)(p))->head_nhooksout > 0)
#endif
#endif