5 * Bart De Schuymer <bdschuym@pandora.be>
11 #include <linux/netfilter_bridge/ebtables.h>
12 #include <linux/netfilter_bridge/ebt_nat.h>
13 #include <linux/module.h>
15 #include <linux/if_arp.h>
18 static int ebt_target_snat(struct sk_buff
**pskb
, unsigned int hooknr
,
19 const struct net_device
*in
, const struct net_device
*out
,
20 const void *data
, unsigned int datalen
)
22 struct ebt_nat_info
*info
= (struct ebt_nat_info
*) data
;
24 if (skb_shared(*pskb
) || skb_cloned(*pskb
)) {
27 nskb
= skb_copy(*pskb
, GFP_ATOMIC
);
31 skb_set_owner_w(nskb
, (*pskb
)->sk
);
35 memcpy(eth_hdr(*pskb
)->h_source
, info
->mac
, ETH_ALEN
);
36 if (!(info
->target
& NAT_ARP_BIT
) &&
37 eth_hdr(*pskb
)->h_proto
== htons(ETH_P_ARP
)) {
38 struct arphdr _ah
, *ap
;
40 ap
= skb_header_pointer(*pskb
, 0, sizeof(_ah
), &_ah
);
43 if (ap
->ar_hln
!= ETH_ALEN
)
45 if (skb_store_bits(*pskb
, sizeof(_ah
), info
->mac
,ETH_ALEN
))
49 return info
->target
| ~EBT_VERDICT_BITS
;
52 static int ebt_target_snat_check(const char *tablename
, unsigned int hookmask
,
53 const struct ebt_entry
*e
, void *data
, unsigned int datalen
)
55 struct ebt_nat_info
*info
= (struct ebt_nat_info
*) data
;
58 if (datalen
!= EBT_ALIGN(sizeof(struct ebt_nat_info
)))
60 tmp
= info
->target
| ~EBT_VERDICT_BITS
;
61 if (BASE_CHAIN
&& tmp
== EBT_RETURN
)
64 if (strcmp(tablename
, "nat"))
66 if (hookmask
& ~(1 << NF_BR_POST_ROUTING
))
69 if (tmp
< -NUM_STANDARD_TARGETS
|| tmp
>= 0)
71 tmp
= info
->target
| EBT_VERDICT_BITS
;
72 if ((tmp
& ~NAT_ARP_BIT
) != ~NAT_ARP_BIT
)
77 static struct ebt_target snat
=
79 .name
= EBT_SNAT_TARGET
,
80 .target
= ebt_target_snat
,
81 .check
= ebt_target_snat_check
,
85 static int __init
ebt_snat_init(void)
87 return ebt_register_target(&snat
);
90 static void __exit
ebt_snat_fini(void)
92 ebt_unregister_target(&snat
);
95 module_init(ebt_snat_init
);
96 module_exit(ebt_snat_fini
);
97 MODULE_LICENSE("GPL");
This page took 0.037551 seconds and 5 git commands to generate.