1diff -urN linux/net/ipv4/netfilter/ devlinux/net/ipv4/netfilter/
2--- linux/net/ipv4/netfilter/ipt_NETLINK.c	Thu Jan  1 00:00:00 1970
3+++ devlinux/net/ipv4/netfilter/ipt_NETLINK.c	Mon Feb 19 11:47:23 2001
4@@ -0,0 +1,119 @@
5+#include <linux/module.h>
6+#include <linux/version.h>
7+#include <linux/config.h>
8+#include <linux/socket.h>
9+#include <linux/skbuff.h>
10+#include <linux/kernel.h>
11+#include <linux/netlink.h>
12+#include <linux/netdevice.h>
13+#include <linux/mm.h>
14+#include <linux/socket.h>
15+#include <linux/netfilter_ipv4/ip_tables.h>
16+#include <linux/netfilter_ipv4/ipt_NETLINK.h>
17+#include <net/sock.h>
18+
19+MODULE_AUTHOR("Gianni Tedesco <gianni@ecsc.co.uk>");
20+MODULE_DESCRIPTION("Provides iptables NETLINK target similar to ipchains -o");
21+MODULE_LICENSE("GPL");
22+
23+#if 0
24+#define DEBUGP	printk
25+#else
26+#define DEBUGP(format, args...)
27+#endif
28+
29+static struct sock *ipfwsk;
30+
31+static unsigned int ipt_netlink_target(struct sk_buff **pskb,
32+				    unsigned int hooknum,
33+				    const struct net_device *in,
34+				    const struct net_device *out,
35+				    const void *targinfo, void *userinfo)
36+{
37+	struct ipt_nldata *nld = (struct ipt_nldata *)targinfo;
38+	struct iphdr *ip = (*pskb)->nh.iph;
39+	struct sk_buff *outskb;
40+	struct netlink_t nlhdr;
41+	size_t len=0;
42+
43+	/* Allocate a socket buffer */
44+	if ( MASK(nld->flags, USE_SIZE) )
45+		len = nld->size+sizeof(nlhdr);
46+	else
47+		len = ntohs(ip->tot_len)+sizeof(nlhdr);	
48+
49+	outskb=alloc_skb(len, GFP_ATOMIC);
50+
51+	if (outskb) {
52+		nlhdr.len=len;
53+		
54+		if ( MASK(nld->flags, USE_MARK) )
55+			nlhdr.mark=(*pskb)->nfmark=nld->mark;
56+		else
57+			nlhdr.mark=(*pskb)->nfmark;
58+		
59+		if ( in && in->name ) {
60+			strncpy((char *)&nlhdr.iface, in->name, IFNAMSIZ);
61+		}else if ( out && out->name ){
62+			strncpy((char *)&nlhdr.iface, out->name, IFNAMSIZ);
63+		}
64+
65+		skb_put(outskb, len);
66+		memcpy(outskb->data, &nlhdr, sizeof(nlhdr));
67+		memcpy((outskb->data)+sizeof(nlhdr), ip, len-sizeof(nlhdr));
68+		netlink_broadcast(ipfwsk, outskb, 0, ~0, GFP_ATOMIC);
69+	}else{
70+		if (net_ratelimit())
71+			printk(KERN_WARNING "ipt_NETLINK: packet drop due to netlink failure\n");
72+	}
73+
74+	if ( MASK(nld->flags, USE_DROP) )
75+		return NF_DROP;
76+
77+	return IPT_CONTINUE;
78+}
79+
80+static int ipt_netlink_checkentry(const char *tablename,
81+			       const struct ipt_entry *e,
82+			       void *targinfo,
83+			       unsigned int targinfosize,
84+			       unsigned int hookmask)
85+{
86+	//struct ipt_nldata *nld = (struct ipt_nldata *)targinfo;
87+
88+	return 1;
89+}
90+
91+static struct ipt_target ipt_netlink_reg = { 
92+	{NULL, NULL},
93+	"NETLINK",
94+	ipt_netlink_target,
95+	ipt_netlink_checkentry,
96+	NULL,
97+	THIS_MODULE
98+};
99+
100+static int __init init(void)
101+{
102+	DEBUGP("ipt_NETLINK: init module\n");	
103+
104+	if (ipt_register_target(&ipt_netlink_reg) != 0) {
105+		return -EINVAL;
106+	}
107+
108+	if ( !(ipfwsk=netlink_kernel_create(NETLINK_FIREWALL, NULL)) ){
109+		return -EINVAL;
110+	}
111+
112+	return 0;
113+}
114+
115+static void __exit fini(void)
116+{
117+	DEBUGP("ipt_NETLINK: cleanup_module\n");
118+	ipt_unregister_target(&ipt_netlink_reg);
119+	if(ipfwsk->socket) sock_release(ipfwsk->socket);
120+}
121+
122+module_init(init);
123+module_exit(fini);
124diff -urN linux/include/linux/netfilter_ipv4/ipt_NETLINK.h devlinux/include/linux/netfilter_ipv4/ipt_NETLINK.h
125--- linux/include/linux/netfilter_ipv4/ipt_NETLINK.h	Thu Jan  1 00:00:00 1970
126+++ devlinux/include/linux/netfilter_ipv4/ipt_NETLINK.h	Mon Feb 19 11:47:09 2001
127@@ -0,0 +1,27 @@
128+#ifndef _IPT_FWMON_H
129+#define _IPT_FWMON_H
130+
131+/* Bitmask macros */
132+#define MASK(x,y) (x & y)
133+#define MASK_SET(x,y) x |= y
134+#define MASK_UNSET(x,y) x &= ~y
135+
136+#define USE_MARK	0x00000001
137+#define USE_DROP	0x00000002
138+#define USE_SIZE	0x00000004
139+
140+struct ipt_nldata
141+{	
142+	unsigned int flags;
143+	unsigned int mark;
144+	unsigned int size;
145+};
146+
147+/* Old header */
148+struct netlink_t {
149+	unsigned int len;
150+	unsigned int mark;
151+	char iface[IFNAMSIZ];
152+};
153+
154+#endif /*_IPT_FWMON_H*/
155