netfilter: xtables: add struct xt_mtdtor_param::net
[deliverable/linux.git] / net / ipv6 / netfilter / ip6table_filter.c
CommitLineData
1da177e4
LT
1/*
2 * This is the 1999 rewrite of IP Firewalling, aiming for kernel 2.3.x.
3 *
4 * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
5 * Copyright (C) 2000-2004 Netfilter Core Team <coreteam@netfilter.org>
6 *
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.
10 */
11
12#include <linux/module.h>
13#include <linux/moduleparam.h>
14#include <linux/netfilter_ipv6/ip6_tables.h>
15
16MODULE_LICENSE("GPL");
17MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
18MODULE_DESCRIPTION("ip6tables filter table");
19
6e23ae2a
PM
20#define FILTER_VALID_HOOKS ((1 << NF_INET_LOCAL_IN) | \
21 (1 << NF_INET_FORWARD) | \
22 (1 << NF_INET_LOCAL_OUT))
1da177e4 23
1da177e4
LT
24static struct
25{
26 struct ip6t_replace repl;
27 struct ip6t_standard entries[3];
28 struct ip6t_error term;
8280aa61 29} initial_table __net_initdata = {
3c2ad469
PM
30 .repl = {
31 .name = "filter",
32 .valid_hooks = FILTER_VALID_HOOKS,
33 .num_entries = 4,
34 .size = sizeof(struct ip6t_standard) * 3 + sizeof(struct ip6t_error),
35 .hook_entry = {
6e23ae2a
PM
36 [NF_INET_LOCAL_IN] = 0,
37 [NF_INET_FORWARD] = sizeof(struct ip6t_standard),
38 [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard) * 2
3c2ad469
PM
39 },
40 .underflow = {
6e23ae2a
PM
41 [NF_INET_LOCAL_IN] = 0,
42 [NF_INET_FORWARD] = sizeof(struct ip6t_standard),
43 [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard) * 2
3c2ad469
PM
44 },
45 },
46 .entries = {
47 IP6T_STANDARD_INIT(NF_ACCEPT), /* LOCAL_IN */
48 IP6T_STANDARD_INIT(NF_ACCEPT), /* FORWARD */
49 IP6T_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */
50 },
51 .term = IP6T_ERROR_INIT, /* ERROR */
1da177e4
LT
52};
53
35aad0ff 54static const struct xt_table packet_filter = {
1da177e4
LT
55 .name = "filter",
56 .valid_hooks = FILTER_VALID_HOOKS,
1da177e4 57 .me = THIS_MODULE,
f88e6a8a 58 .af = NFPROTO_IPV6,
1da177e4
LT
59};
60
61/* The work comes in here from netfilter.c. */
62static unsigned int
61d30158 63ip6t_in_hook(unsigned int hook,
43de9dfe
AD
64 struct sk_buff *skb,
65 const struct net_device *in,
66 const struct net_device *out,
67 int (*okfn)(struct sk_buff *))
68{
69 return ip6t_do_table(skb, hook, in, out,
48dc7865 70 dev_net(in)->ipv6.ip6table_filter);
43de9dfe
AD
71}
72
1da177e4
LT
73static unsigned int
74ip6t_local_out_hook(unsigned int hook,
3db05fea 75 struct sk_buff *skb,
1da177e4
LT
76 const struct net_device *in,
77 const struct net_device *out,
78 int (*okfn)(struct sk_buff *))
79{
80#if 0
81 /* root is playing with raw sockets. */
3666ed1c
JP
82 if (skb->len < sizeof(struct iphdr) ||
83 ip_hdrlen(skb) < sizeof(struct iphdr)) {
1da177e4
LT
84 if (net_ratelimit())
85 printk("ip6t_hook: happy cracking.\n");
86 return NF_ACCEPT;
87 }
88#endif
89
43de9dfe 90 return ip6t_do_table(skb, hook, in, out,
48dc7865 91 dev_net(out)->ipv6.ip6table_filter);
1da177e4
LT
92}
93
1999414a 94static struct nf_hook_ops ip6t_ops[] __read_mostly = {
1da177e4 95 {
61d30158 96 .hook = ip6t_in_hook,
1da177e4 97 .owner = THIS_MODULE,
24c232d8 98 .pf = NFPROTO_IPV6,
6e23ae2a 99 .hooknum = NF_INET_LOCAL_IN,
1da177e4
LT
100 .priority = NF_IP6_PRI_FILTER,
101 },
102 {
61d30158 103 .hook = ip6t_in_hook,
1da177e4 104 .owner = THIS_MODULE,
24c232d8 105 .pf = NFPROTO_IPV6,
6e23ae2a 106 .hooknum = NF_INET_FORWARD,
1da177e4
LT
107 .priority = NF_IP6_PRI_FILTER,
108 },
109 {
110 .hook = ip6t_local_out_hook,
111 .owner = THIS_MODULE,
24c232d8 112 .pf = NFPROTO_IPV6,
6e23ae2a 113 .hooknum = NF_INET_LOCAL_OUT,
1da177e4
LT
114 .priority = NF_IP6_PRI_FILTER,
115 },
116};
117
118/* Default to forward because I got too much mail already. */
119static int forward = NF_ACCEPT;
120module_param(forward, bool, 0000);
121
8280aa61
AD
122static int __net_init ip6table_filter_net_init(struct net *net)
123{
124 /* Register table */
125 net->ipv6.ip6table_filter =
126 ip6t_register_table(net, &packet_filter, &initial_table.repl);
127 if (IS_ERR(net->ipv6.ip6table_filter))
128 return PTR_ERR(net->ipv6.ip6table_filter);
129 return 0;
130}
131
132static void __net_exit ip6table_filter_net_exit(struct net *net)
133{
f54e9367 134 ip6t_unregister_table(net, net->ipv6.ip6table_filter);
8280aa61
AD
135}
136
137static struct pernet_operations ip6table_filter_net_ops = {
138 .init = ip6table_filter_net_init,
139 .exit = ip6table_filter_net_exit,
140};
141
65b4b4e8 142static int __init ip6table_filter_init(void)
1da177e4
LT
143{
144 int ret;
145
146 if (forward < 0 || forward > NF_MAX_VERDICT) {
147 printk("iptables forward must be 0 or 1\n");
148 return -EINVAL;
149 }
150
151 /* Entry 1 is the FORWARD hook */
152 initial_table.entries[1].target.verdict = -forward - 1;
153
8280aa61
AD
154 ret = register_pernet_subsys(&ip6table_filter_net_ops);
155 if (ret < 0)
156 return ret;
1da177e4
LT
157
158 /* Register hooks */
964ddaa1 159 ret = nf_register_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops));
1da177e4
LT
160 if (ret < 0)
161 goto cleanup_table;
162
1da177e4
LT
163 return ret;
164
1da177e4 165 cleanup_table:
8280aa61 166 unregister_pernet_subsys(&ip6table_filter_net_ops);
1da177e4
LT
167 return ret;
168}
169
65b4b4e8 170static void __exit ip6table_filter_fini(void)
1da177e4 171{
964ddaa1 172 nf_unregister_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops));
8280aa61 173 unregister_pernet_subsys(&ip6table_filter_net_ops);
1da177e4
LT
174}
175
65b4b4e8
AM
176module_init(ip6table_filter_init);
177module_exit(ip6table_filter_fini);
This page took 0.469008 seconds and 5 git commands to generate.