1254219Scy/*
2254219Scy * Copyright (C) 2012 by Darren Reed.
3254219Scy *
4254219Scy * See the IPFILTER.LICENCE file for details on licencing.
5254219Scy *
6254219Scy */
7254219Scy
8254219Scy#include <sys/param.h>
9254219Scy#include <sys/systm.h>
10254219Scy#include <sys/conf.h>
11254219Scy#include <sys/proc.h>
12254219Scy#include <sys/ioctl.h>
13254219Scy#include <sys/kernel.h>
14254219Scy#include <sys/mbuf.h>
15254219Scy#include <sys/exec.h>
16254219Scy#include <sys/socket.h>
17254219Scy#include <net/if.h>
18254219Scy#include <netinet/in_systm.h>
19254219Scy#include <netinet/in.h>
20254219Scy#include <netinet/ip.h>
21254219Scy#include <net/route.h>
22254219Scy#include <netinet/ip_var.h>
23254219Scy#include <netinet/tcp.h>
24254219Scy#include <netinet/tcpip.h>
25254219Scy#include <sys/lkm.h>
26254219Scy#include "ip_compat.h"
27254219Scy#include "ip_fil.h"
28254219Scy#include "ip_rules.h"
29254219Scy
30254219Scy
31254219Scystatic int ipfruleaction __P((struct lkm_table *, int));
32254219Scy
33254219Scy#ifdef IPFILTER_LKM
34254219Scy# if NetBSD >= 199706
35254219Scyint	ipfrule_lkmentry __P((struct lkm_table *, int, int));
36254219Scy# else
37254219Scyint	xxxinit __P((struct lkm_table *, int, int));
38254219Scy# endif
39254219Scy
40254219Scy
41254219ScyMOD_MISC("IPFilter Rules");
42254219Scy
43254219Scy# if NetBSD >= 199706
44254219Scyint ipfrule_lkmentry(lkmtp, cmd, ver)
45254219Scy# else
46254219Scyint xxxinit(lkmtp, cmd, ver)
47254219Scy# endif
48254219Scy	struct lkm_table *lkmtp;
49254219Scy	int cmd, ver;
50254219Scy{
51254219Scy	DISPATCH(lkmtp, cmd, ver, ipfruleaction, ipfruleaction, ipfruleaction);
52254219Scy}
53254219Scy
54254219Scystatic int ipfruleaction(lkmtp, cmd)
55254219Scy	struct lkm_table *lkmtp;
56254219Scy	int cmd;
57254219Scy{
58254219Scy	int err = 0;
59254219Scy
60254219Scy	switch (cmd)
61254219Scy	{
62254219Scy	case LKM_E_LOAD :
63254219Scy		if (lkmexists(lkmtp))
64254219Scy			return EEXIST;
65254219Scy
66254219Scy		err = ipfrule_add();
67254219Scy		if (!err)
68254219Scy			ipf_refcnt++;
69254219Scy		break;
70254219Scy	case LKM_E_UNLOAD :
71254219Scy		err = ipfrule_remove();
72254219Scy		if (!err)
73254219Scy			ipf_refcnt--;
74254219Scy		break;
75254219Scy	case LKM_E_STAT :
76254219Scy		break;
77254219Scy	default:
78254219Scy		err = EIO;
79254219Scy		break;
80254219Scy	}
81254219Scy	return err;
82254219Scy}
83254219Scy#endif /* IPFILTER_LKM */
84