4 Copyright (C) 2006 Jonathan Zarate
6 Licensed under GNU GPL v2 or later.
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>
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
,
24 const struct xt_target
*target
,
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
,
31 const struct xt_target
*target
,
33 #else /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28) */
34 target(struct sk_buff
*skb
,
35 const struct xt_target_param
*par
)
38 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
39 // const struct ipt_MACSAVE_target_info *info = targinfo;
41 // const struct ipt_MACSAVE_target_info *info = par->targinfo;
43 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
44 struct sk_buff
*skb
= *pskb
;
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
);
52 memcpy(ct
->macsave
, eth_hdr(skb
)->h_source
, sizeof(ct
->macsave
));
58 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
60 checkentry(const char *tablename
,
62 const struct xt_target
*target
,
64 unsigned int hook_mask
)
65 #elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
67 checkentry(const char *tablename
,
69 const struct xt_target
*target
,
71 unsigned int hook_mask
)
72 #else /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28) */
74 checkentry(const struct xt_tgchk_param
*par
)
77 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
78 unsigned int hook_mask
= par
->hook_mask
;
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");
87 static struct ipt_target macsave_target
= {
91 .targetsize
= sizeof(struct ipt_MACSAVE_target_info
),
92 .checkentry
= checkentry
,
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
);
108 MODULE_LICENSE("GPL");