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
5 * Copyright (C) 2000-2004 Netfilter Core Team <coreteam@netfilter.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/module.h>
13 #include <linux/moduleparam.h>
14 #include <linux/netfilter_ipv6/ip6_tables.h>
16 MODULE_LICENSE("GPL");
17 MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
18 MODULE_DESCRIPTION("ip6tables filter table");
20 #define FILTER_VALID_HOOKS ((1 << NF_IP6_LOCAL_IN) | (1 << NF_IP6_FORWARD) | (1 << NF_IP6_LOCAL_OUT))
25 struct ip6t_entry entry;
26 struct ip6t_standard_target target;
29 struct ip6t_error_target
31 struct ip6t_entry_target target;
32 char errorname[IP6T_FUNCTION_MAXNAMELEN];
37 struct ip6t_entry entry;
38 struct ip6t_error_target target;
43 struct ip6t_replace repl;
44 struct ip6t_standard entries[3];
45 struct ip6t_error term;
46 } initial_table __initdata
47 = { { "filter", FILTER_VALID_HOOKS, 4,
48 sizeof(struct ip6t_standard) * 3 + sizeof(struct ip6t_error),
49 { [NF_IP6_LOCAL_IN] = 0,
50 [NF_IP6_FORWARD] = sizeof(struct ip6t_standard),
51 [NF_IP6_LOCAL_OUT] = sizeof(struct ip6t_standard) * 2 },
52 { [NF_IP6_LOCAL_IN] = 0,
53 [NF_IP6_FORWARD] = sizeof(struct ip6t_standard),
54 [NF_IP6_LOCAL_OUT] = sizeof(struct ip6t_standard) * 2 },
58 { { { { { { 0 } } }, { { { 0 } } }, { { { 0 } } }, { { { 0 } } }, "", "", { 0 }, { 0 }, 0, 0, 0 },
60 sizeof(struct ip6t_entry),
61 sizeof(struct ip6t_standard),
63 { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
66 { { { { { { 0 } } }, { { { 0 } } }, { { { 0 } } }, { { { 0 } } }, "", "", { 0 }, { 0 }, 0, 0, 0 },
68 sizeof(struct ip6t_entry),
69 sizeof(struct ip6t_standard),
71 { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
74 { { { { { { 0 } } }, { { { 0 } } }, { { { 0 } } }, { { { 0 } } }, "", "", { 0 }, { 0 }, 0, 0, 0 },
76 sizeof(struct ip6t_entry),
77 sizeof(struct ip6t_standard),
79 { { { { IP6T_ALIGN(sizeof(struct ip6t_standard_target)), "" } }, { } },
83 { { { { { { 0 } } }, { { { 0 } } }, { { { 0 } } }, { { { 0 } } }, "", "", { 0 }, { 0 }, 0, 0, 0 },
85 sizeof(struct ip6t_entry),
86 sizeof(struct ip6t_error),
88 { { { { IP6T_ALIGN(sizeof(struct ip6t_error_target)), IP6T_ERROR_TARGET } },
95 static struct ip6t_table packet_filter = {
97 .valid_hooks = FILTER_VALID_HOOKS,
98 .lock = RW_LOCK_UNLOCKED,
102 /* The work comes in here from netfilter.c. */
104 ip6t_hook(unsigned int hook,
105 struct sk_buff **pskb,
106 const struct net_device *in,
107 const struct net_device *out,
108 int (*okfn)(struct sk_buff *))
110 return ip6t_do_table(pskb, hook, in, out, &packet_filter, NULL);
114 ip6t_local_out_hook(unsigned int hook,
115 struct sk_buff **pskb,
116 const struct net_device *in,
117 const struct net_device *out,
118 int (*okfn)(struct sk_buff *))
121 /* root is playing with raw sockets. */
122 if ((*pskb)->len < sizeof(struct iphdr)
123 || (*pskb)->nh.iph->ihl * 4 < sizeof(struct iphdr)) {
125 printk("ip6t_hook: happy cracking.\n");
130 return ip6t_do_table(pskb, hook, in, out, &packet_filter, NULL);
133 static struct nf_hook_ops ip6t_ops[] = {
136 .owner = THIS_MODULE,
138 .hooknum = NF_IP6_LOCAL_IN,
139 .priority = NF_IP6_PRI_FILTER,
143 .owner = THIS_MODULE,
145 .hooknum = NF_IP6_FORWARD,
146 .priority = NF_IP6_PRI_FILTER,
149 .hook = ip6t_local_out_hook,
150 .owner = THIS_MODULE,
152 .hooknum = NF_IP6_LOCAL_OUT,
153 .priority = NF_IP6_PRI_FILTER,
157 /* Default to forward because I got too much mail already. */
158 static int forward = NF_ACCEPT;
159 module_param(forward, bool, 0000);
161 static int __init init(void)
165 if (forward < 0 || forward > NF_MAX_VERDICT) {
166 printk("iptables forward must be 0 or 1\n");
170 /* Entry 1 is the FORWARD hook */
171 initial_table.entries[1].target.verdict = -forward - 1;
174 ret = ip6t_register_table(&packet_filter, &initial_table.repl);
179 ret = nf_register_hook(&ip6t_ops[0]);
183 ret = nf_register_hook(&ip6t_ops[1]);
187 ret = nf_register_hook(&ip6t_ops[2]);
194 nf_unregister_hook(&ip6t_ops[1]);
196 nf_unregister_hook(&ip6t_ops[0]);
198 ip6t_unregister_table(&packet_filter);
203 static void __exit fini(void)
207 for (i = 0; i < sizeof(ip6t_ops)/sizeof(struct nf_hook_ops); i++)
208 nf_unregister_hook(&ip6t_ops[i]);
210 ip6t_unregister_table(&packet_filter);