2 * This is the 1999 rewrite of IP Firewalling, aiming for kernel 2.3.x.
4 * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
6 #include <linux/module.h>
7 #include <linux/netfilter_ipv6/ip6_tables.h>
9 #define FILTER_VALID_HOOKS ((1 << NF_IP6_LOCAL_IN) | (1 << NF_IP6_FORWARD) | (1 << NF_IP6_LOCAL_OUT))
14 struct ip6t_entry entry;
15 struct ip6t_standard_target target;
18 struct ip6t_error_target
20 struct ip6t_entry_target target;
21 char errorname[IP6T_FUNCTION_MAXNAMELEN];
26 struct ip6t_entry entry;
27 struct ip6t_error_target target;
32 struct ip6t_replace repl;
33 struct ip6t_standard entries[3];
34 struct ip6t_error term;
35 } initial_table __initdata
36 = { { "filter", FILTER_VALID_HOOKS, 4,
37 sizeof(struct ip6t_standard) * 3 + sizeof(struct ip6t_error),
38 { [NF_IP6_LOCAL_IN] 0,
39 [NF_IP6_FORWARD] sizeof(struct ip6t_standard),
40 [NF_IP6_LOCAL_OUT] sizeof(struct ip6t_standard) * 2 },
41 { [NF_IP6_LOCAL_IN] 0,
42 [NF_IP6_FORWARD] sizeof(struct ip6t_standard),
43 [NF_IP6_LOCAL_OUT] sizeof(struct ip6t_standard) * 2 },
47 { { { { { { 0 } } }, { { { 0 } } }, { { { 0 } } }, { { { 0 } } }, "", "", { 0 }, { 0 }, 0, 0, 0 },
49 sizeof(struct ip6t_entry),
50 sizeof(struct ip6t_standard),
52 { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
55 { { { { { { 0 } } }, { { { 0 } } }, { { { 0 } } }, { { { 0 } } }, "", "", { 0 }, { 0 }, 0, 0, 0 },
57 sizeof(struct ip6t_entry),
58 sizeof(struct ip6t_standard),
60 { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
63 { { { { { { 0 } } }, { { { 0 } } }, { { { 0 } } }, { { { 0 } } }, "", "", { 0 }, { 0 }, 0, 0, 0 },
65 sizeof(struct ip6t_entry),
66 sizeof(struct ip6t_standard),
68 { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
72 { { { { { { 0 } } }, { { { 0 } } }, { { { 0 } } }, { { { 0 } } }, "", "", { 0 }, { 0 }, 0, 0, 0 },
74 sizeof(struct ip6t_entry),
75 sizeof(struct ip6t_error),
77 { { { { IP6T_ALIGN(sizeof(struct ip6t_error_target)), IP6T_ERROR_TARGET } },
84 static struct ip6t_table packet_filter
85 = { { NULL, NULL }, "filter", &initial_table.repl,
86 FILTER_VALID_HOOKS, RW_LOCK_UNLOCKED, NULL, THIS_MODULE };
88 /* The work comes in here from netfilter.c. */
90 ip6t_hook(unsigned int hook,
91 struct sk_buff **pskb,
92 const struct net_device *in,
93 const struct net_device *out,
94 int (*okfn)(struct sk_buff *))
96 return ip6t_do_table(pskb, hook, in, out, &packet_filter, NULL);
100 ip6t_local_out_hook(unsigned int hook,
101 struct sk_buff **pskb,
102 const struct net_device *in,
103 const struct net_device *out,
104 int (*okfn)(struct sk_buff *))
107 /* root is playing with raw sockets. */
108 if ((*pskb)->len < sizeof(struct iphdr)
109 || (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr)) {
111 printk("ip6t_hook: happy cracking.\n");
116 return ip6t_do_table(pskb, hook, in, out, &packet_filter, NULL);
119 static struct nf_hook_ops ip6t_ops[]
120 = { { { NULL, NULL }, ip6t_hook, PF_INET6, NF_IP6_LOCAL_IN, NF_IP6_PRI_FILTER },
121 { { NULL, NULL }, ip6t_hook, PF_INET6, NF_IP6_FORWARD, NF_IP6_PRI_FILTER },
122 { { NULL, NULL }, ip6t_local_out_hook, PF_INET6, NF_IP6_LOCAL_OUT,
126 /* Default to forward because I got too much mail already. */
127 static int forward = NF_ACCEPT;
128 MODULE_PARM(forward, "i");
130 static int __init init(void)
134 if (forward < 0 || forward > NF_MAX_VERDICT) {
135 printk("iptables forward must be 0 or 1\n");
139 /* Entry 1 is the FORWARD hook */
140 initial_table.entries[1].target.verdict = -forward - 1;
143 ret = ip6t_register_table(&packet_filter);
148 ret = nf_register_hook(&ip6t_ops[0]);
152 ret = nf_register_hook(&ip6t_ops[1]);
156 ret = nf_register_hook(&ip6t_ops[2]);
163 nf_unregister_hook(&ip6t_ops[1]);
165 nf_unregister_hook(&ip6t_ops[0]);
167 ip6t_unregister_table(&packet_filter);
172 static void __exit fini(void)
176 for (i = 0; i < sizeof(ip6t_ops)/sizeof(struct nf_hook_ops); i++)
177 nf_unregister_hook(&ip6t_ops[i]);
179 ip6t_unregister_table(&packet_filter);
184 MODULE_LICENSE("GPL");