11590Srgrimes/*	$NetBSD$	*/
21590Srgrimes
31590Srgrimes/*
41590Srgrimes * Copyright (C) 2012 by Darren Reed.
51590Srgrimes *
61590Srgrimes * See the IPFILTER.LICENCE file for details on licencing.
71590Srgrimes *
81590Srgrimes */
91590Srgrimes
101590Srgrimes#include <sys/param.h>
111590Srgrimes#include <sys/systm.h>
121590Srgrimes#include <sys/conf.h>
131590Srgrimes#include <sys/proc.h>
141590Srgrimes#include <sys/ioctl.h>
151590Srgrimes#include <sys/kernel.h>
161590Srgrimes#include <sys/mbuf.h>
171590Srgrimes#include <sys/exec.h>
181590Srgrimes#include <sys/socket.h>
191590Srgrimes#include <net/if.h>
201590Srgrimes#include <netinet/in_systm.h>
211590Srgrimes#include <netinet/in.h>
221590Srgrimes#include <netinet/ip.h>
231590Srgrimes#include <net/route.h>
24#include <netinet/ip_var.h>
25#include <netinet/tcp.h>
26#include <netinet/tcpip.h>
27#include <sys/lkm.h>
28#include "ip_compat.h"
29#include "ip_fil.h"
30#include "ip_rules.h"
31
32
33static int ipfruleaction __P((struct lkm_table *, int));
34
35#ifdef IPFILTER_LKM
36# if NetBSD >= 199706
37int	ipfrule_lkmentry __P((struct lkm_table *, int, int));
38# else
39int	xxxinit __P((struct lkm_table *, int, int));
40# endif
41
42
43MOD_MISC("IPFilter Rules");
44
45# if NetBSD >= 199706
46int ipfrule_lkmentry(lkmtp, cmd, ver)
47# else
48int xxxinit(lkmtp, cmd, ver)
49# endif
50	struct lkm_table *lkmtp;
51	int cmd, ver;
52{
53	DISPATCH(lkmtp, cmd, ver, ipfruleaction, ipfruleaction, ipfruleaction);
54}
55
56static int ipfruleaction(lkmtp, cmd)
57	struct lkm_table *lkmtp;
58	int cmd;
59{
60	int err = 0;
61
62	switch (cmd)
63	{
64	case LKM_E_LOAD :
65		if (lkmexists(lkmtp))
66			return EEXIST;
67
68		err = ipfrule_add();
69		if (!err)
70			ipf_refcnt++;
71		break;
72	case LKM_E_UNLOAD :
73		err = ipfrule_remove();
74		if (!err)
75			ipf_refcnt--;
76		break;
77	case LKM_E_STAT :
78		break;
79	default:
80		err = EIO;
81		break;
82	}
83	return err;
84}
85#endif /* IPFILTER_LKM */
86