NETFILTER: remove unnecessary goto statement for error recovery
[tomato.git] / release / src-rt / linux / linux-2.6 / net / ipv4 / netfilter / ipt_MACSAVE.c
blob5aeee5db9ede9397a2245dc696274f892c27c50b
1 /*
3 MACSAVE target
4 Copyright (C) 2006 Jonathan Zarate
6 Licensed under GNU GPL v2 or later.
8 */
9 #include <linux/module.h>
10 #include <linux/skbuff.h>
11 #include <linux/version.h>
12 #include <linux/if_ether.h>
14 #include <net/netfilter/nf_conntrack.h>
15 #include <linux/netfilter_ipv4/ip_tables.h>
16 #include <linux/netfilter_ipv4/ipt_MACSAVE.h>
18 static unsigned int
19 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
20 target(struct sk_buff **pskb,
21 const struct net_device *in,
22 const struct net_device *out,
23 unsigned int hooknum,
24 const struct xt_target *target,
25 const void *targinfo)
26 #elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
27 target(struct sk_buff *skb,
28 const struct net_device *in,
29 const struct net_device *out,
30 unsigned int hooknum,
31 const struct xt_target *target,
32 const void *targinfo)
33 #else /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28) */
34 target(struct sk_buff *skb,
35 const struct xt_target_param *par)
36 #endif
38 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
39 // const struct ipt_MACSAVE_target_info *info = targinfo;
40 #else
41 // const struct ipt_MACSAVE_target_info *info = par->targinfo;
42 #endif
43 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
44 struct sk_buff *skb = *pskb;
45 #endif
46 struct nf_conn *ct;
47 enum ip_conntrack_info ctinfo;
49 if ((skb_mac_header(skb) >= skb->head) && ((skb_mac_header(skb) + ETH_HLEN) <= skb->data)) {
50 ct = nf_ct_get(skb, &ctinfo);
51 if (ct) {
52 memcpy(ct->macsave, eth_hdr(skb)->h_source, sizeof(ct->macsave));
55 return IPT_CONTINUE;
58 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
59 static int
60 checkentry(const char *tablename,
61 const void *e,
62 const struct xt_target *target,
63 void *targinfo,
64 unsigned int hook_mask)
65 #elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
66 static bool
67 checkentry(const char *tablename,
68 const void *e,
69 const struct xt_target *target,
70 void *targinfo,
71 unsigned int hook_mask)
72 #else /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28) */
73 static bool
74 checkentry(const struct xt_tgchk_param *par)
75 #endif
77 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
78 unsigned int hook_mask = par->hook_mask;
79 #endif
80 if (hook_mask & ~((1 << NF_IP_PRE_ROUTING) | (1 << NF_IP_FORWARD) | (1 << NF_IP_LOCAL_IN))) {
81 printk(KERN_ERR "MACSAVE: Valid only in PREROUTING, FORWARD and INPUT\n");
82 return 0;
84 return 1;
87 static struct ipt_target macsave_target = {
88 .name = "MACSAVE",
89 .family = AF_INET,
90 .target = target,
91 .targetsize = sizeof(struct ipt_MACSAVE_target_info),
92 .checkentry = checkentry,
93 .me = THIS_MODULE,
96 static int __init init(void)
98 return xt_register_target(&macsave_target);
101 static void __exit fini(void)
103 xt_unregister_target(&macsave_target);
106 module_init(init);
107 module_exit(fini);
108 MODULE_LICENSE("GPL");