11 #include <linux/module.h>
12 #include <linux/netfilter_ipv4/ip_tables.h>
13 #include <linux/netdevice.h>
15 #include <linux/slab.h>
25 #define MANGLE_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | \
26 (1 << NF_INET_LOCAL_IN) | \
27 (1 << NF_INET_FORWARD) | \
28 (1 << NF_INET_LOCAL_OUT) | \
29 (1 << NF_INET_POST_ROUTING))
31 static const struct xt_table packet_mangler = {
43 const struct iphdr *iph;
49 if (skb->
len <
sizeof(
struct iphdr) ||
50 ip_hdrlen(skb) <
sizeof(
struct iphdr))
61 dev_net(out)->ipv4.iptable_mangle);
66 if (iph->
saddr != saddr ||
67 iph->
daddr != daddr ||
79 iptable_mangle_hook(
unsigned int hook,
86 return ipt_mangle_out(skb, out);
89 dev_net(out)->ipv4.iptable_mangle);
92 dev_net(in)->ipv4.iptable_mangle);
104 net->
ipv4.iptable_mangle =
107 return PTR_RET(net->
ipv4.iptable_mangle);
110 static void __net_exit iptable_mangle_net_exit(
struct net *net)
116 .init = iptable_mangle_net_init,
117 .exit = iptable_mangle_net_exit,
120 static int __init iptable_mangle_init(
void)
129 mangle_ops =
xt_hook_link(&packet_mangler, iptable_mangle_hook);
130 if (IS_ERR(mangle_ops)) {
131 ret = PTR_ERR(mangle_ops);
138 static void __exit iptable_mangle_fini(
void)