2 * 'raw' table, which is the very first hooked in at PRE_ROUTING and LOCAL_OUT .
4 * Copyright (C) 2003 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6 #include <linux/module.h>
7 #include <linux/netfilter_ipv4/ip_tables.h>
10 #define RAW_VALID_HOOKS ((1 << NF_IP_PRE_ROUTING) | (1 << NF_IP_LOCAL_OUT))
14 struct ipt_replace repl;
15 struct ipt_standard entries[2];
16 struct ipt_error term;
17 } initial_table __initdata = {
20 .valid_hooks = RAW_VALID_HOOKS,
22 .size = sizeof(struct ipt_standard) * 2 + sizeof(struct ipt_error),
24 [NF_IP_PRE_ROUTING] = 0,
25 [NF_IP_LOCAL_OUT] = sizeof(struct ipt_standard)
28 [NF_IP_PRE_ROUTING] = 0,
29 [NF_IP_LOCAL_OUT] = sizeof(struct ipt_standard)
33 IPT_STANDARD_INIT(NF_ACCEPT), /* PRE_ROUTING */
34 IPT_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */
36 .term = IPT_ERROR_INIT, /* ERROR */
39 static struct xt_table packet_raw = {
41 .valid_hooks = RAW_VALID_HOOKS,
42 .lock = RW_LOCK_UNLOCKED,
47 /* The work comes in here from netfilter.c. */
49 ipt_hook(unsigned int hook,
50 struct sk_buff **pskb,
51 const struct net_device *in,
52 const struct net_device *out,
53 int (*okfn)(struct sk_buff *))
55 return ipt_do_table(pskb, hook, in, out, &packet_raw);
59 ipt_local_hook(unsigned int hook,
60 struct sk_buff **pskb,
61 const struct net_device *in,
62 const struct net_device *out,
63 int (*okfn)(struct sk_buff *))
65 /* root is playing with raw sockets. */
66 if ((*pskb)->len < sizeof(struct iphdr) ||
67 ip_hdrlen(*pskb) < sizeof(struct iphdr)) {
69 printk("iptable_raw: ignoring short SOCK_RAW"
73 return ipt_do_table(pskb, hook, in, out, &packet_raw);
76 /* 'raw' is the very first table. */
77 static struct nf_hook_ops ipt_ops[] = {
81 .hooknum = NF_IP_PRE_ROUTING,
82 .priority = NF_IP_PRI_RAW,
86 .hook = ipt_local_hook,
88 .hooknum = NF_IP_LOCAL_OUT,
89 .priority = NF_IP_PRI_RAW,
94 static int __init iptable_raw_init(void)
99 ret = ipt_register_table(&packet_raw, &initial_table.repl);
104 ret = nf_register_hooks(ipt_ops, ARRAY_SIZE(ipt_ops));
111 ipt_unregister_table(&packet_raw);
115 static void __exit iptable_raw_fini(void)
117 nf_unregister_hooks(ipt_ops, ARRAY_SIZE(ipt_ops));
118 ipt_unregister_table(&packet_raw);
121 module_init(iptable_raw_init);
122 module_exit(iptable_raw_fini);
123 MODULE_LICENSE("GPL");