NETFILTER: remove unnecessary goto statement for error recovery
[tomato.git] / release / src-rt / linux / linux-2.6 / net / ipv4 / netfilter / iptable_filter.c
blobcaa00becbd3dc8f623ab2f99ca1b4d1d68af5d66
1 /*
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.
13 #include <linux/module.h>
14 #include <linux/moduleparam.h>
15 #include <linux/netfilter_ipv4/ip_tables.h>
16 #include <net/ip.h>
18 MODULE_LICENSE("GPL");
19 MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
20 MODULE_DESCRIPTION("iptables filter table");
22 #define FILTER_VALID_HOOKS ((1 << NF_IP_LOCAL_IN) | (1 << NF_IP_FORWARD) | (1 << NF_IP_LOCAL_OUT))
24 static struct
26 struct ipt_replace repl;
27 struct ipt_standard entries[3];
28 struct ipt_error term;
29 } initial_table __initdata = {
30 .repl = {
31 .name = "filter",
32 .valid_hooks = FILTER_VALID_HOOKS,
33 .num_entries = 4,
34 .size = sizeof(struct ipt_standard) * 3 + sizeof(struct ipt_error),
35 .hook_entry = {
36 [NF_IP_LOCAL_IN] = 0,
37 [NF_IP_FORWARD] = sizeof(struct ipt_standard),
38 [NF_IP_LOCAL_OUT] = sizeof(struct ipt_standard) * 2,
40 .underflow = {
41 [NF_IP_LOCAL_IN] = 0,
42 [NF_IP_FORWARD] = sizeof(struct ipt_standard),
43 [NF_IP_LOCAL_OUT] = sizeof(struct ipt_standard) * 2,
46 .entries = {
47 IPT_STANDARD_INIT(NF_ACCEPT), /* LOCAL_IN */
48 IPT_STANDARD_INIT(NF_ACCEPT), /* FORWARD */
49 IPT_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */
51 .term = IPT_ERROR_INIT, /* ERROR */
54 static struct xt_table packet_filter = {
55 .name = "filter",
56 .valid_hooks = FILTER_VALID_HOOKS,
57 .me = THIS_MODULE,
58 .af = AF_INET,
61 /* The work comes in here from netfilter.c. */
62 static unsigned int
63 ipt_hook(unsigned int hook,
64 struct sk_buff *skb,
65 const struct net_device *in,
66 const struct net_device *out,
67 int (*okfn)(struct sk_buff *))
69 return ipt_do_table(skb, hook, in, out, &packet_filter);
72 static unsigned int
73 ipt_local_out_hook(unsigned int hook,
74 struct sk_buff *skb,
75 const struct net_device *in,
76 const struct net_device *out,
77 int (*okfn)(struct sk_buff *))
79 /* root is playing with raw sockets. */
80 if (skb->len < sizeof(struct iphdr) ||
81 ip_hdrlen(skb) < sizeof(struct iphdr)) {
82 if (net_ratelimit())
83 printk("iptable_filter: ignoring short SOCK_RAW "
84 "packet.\n");
85 return NF_ACCEPT;
88 return ipt_do_table(skb, hook, in, out, &packet_filter);
91 static struct nf_hook_ops ipt_ops[] = {
93 .hook = ipt_hook,
94 .owner = THIS_MODULE,
95 .pf = PF_INET,
96 .hooknum = NF_IP_LOCAL_IN,
97 .priority = NF_IP_PRI_FILTER,
100 .hook = ipt_hook,
101 .owner = THIS_MODULE,
102 .pf = PF_INET,
103 .hooknum = NF_IP_FORWARD,
104 .priority = NF_IP_PRI_FILTER,
107 .hook = ipt_local_out_hook,
108 .owner = THIS_MODULE,
109 .pf = PF_INET,
110 .hooknum = NF_IP_LOCAL_OUT,
111 .priority = NF_IP_PRI_FILTER,
115 /* Default to forward because I got too much mail already. */
116 static int forward = NF_ACCEPT;
117 module_param(forward, bool, 0000);
119 static int __init iptable_filter_init(void)
121 int ret;
123 if (forward < 0 || forward > NF_MAX_VERDICT) {
124 printk("iptables forward must be 0 or 1\n");
125 return -EINVAL;
128 /* Entry 1 is the FORWARD hook */
129 initial_table.entries[1].target.verdict = -forward - 1;
131 /* Register table */
132 ret = ipt_register_table(&packet_filter, &initial_table.repl);
133 if (ret < 0)
134 return ret;
136 /* Register hooks */
137 ret = nf_register_hooks(ipt_ops, ARRAY_SIZE(ipt_ops));
138 if (ret < 0) {
139 ipt_unregister_table(&packet_filter);
142 return ret;
145 static void __exit iptable_filter_fini(void)
147 nf_unregister_hooks(ipt_ops, ARRAY_SIZE(ipt_ops));
148 ipt_unregister_table(&packet_filter);
151 module_init(iptable_filter_init);
152 module_exit(iptable_filter_fini);