2 * 'raw' table, which is the very first hooked in at PRE_ROUTING and LOCAL_OUT .
6 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
7 #include <linux/module.h>
8 #include <linux/netfilter_ipv4/ip_tables.h>
9 #include <linux/slab.h>
12 #define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT))
14 static int __net_init iptable_raw_table_init(struct net *net);
16 static bool raw_before_defrag __read_mostly;
17 MODULE_PARM_DESC(raw_before_defrag, "Enable raw table before defrag");
18 module_param(raw_before_defrag, bool, 0000);
20 static const struct xt_table packet_raw = {
22 .valid_hooks = RAW_VALID_HOOKS,
25 .priority = NF_IP_PRI_RAW,
26 .table_init = iptable_raw_table_init,
29 static const struct xt_table packet_raw_before_defrag = {
31 .valid_hooks = RAW_VALID_HOOKS,
34 .priority = NF_IP_PRI_RAW_BEFORE_DEFRAG,
35 .table_init = iptable_raw_table_init,
38 /* The work comes in here from netfilter.c. */
40 iptable_raw_hook(void *priv, struct sk_buff *skb,
41 const struct nf_hook_state *state)
43 return ipt_do_table(skb, state, state->net->ipv4.iptable_raw);
46 static struct nf_hook_ops *rawtable_ops __read_mostly;
48 static int __net_init iptable_raw_table_init(struct net *net)
50 struct ipt_replace *repl;
51 const struct xt_table *table = &packet_raw;
54 if (raw_before_defrag)
55 table = &packet_raw_before_defrag;
57 if (net->ipv4.iptable_raw)
60 repl = ipt_alloc_initial_table(table);
63 ret = ipt_register_table(net, table, repl, rawtable_ops,
64 &net->ipv4.iptable_raw);
69 static void __net_exit iptable_raw_net_exit(struct net *net)
71 if (!net->ipv4.iptable_raw)
73 ipt_unregister_table(net, net->ipv4.iptable_raw, rawtable_ops);
74 net->ipv4.iptable_raw = NULL;
77 static struct pernet_operations iptable_raw_net_ops = {
78 .exit = iptable_raw_net_exit,
81 static int __init iptable_raw_init(void)
84 const struct xt_table *table = &packet_raw;
86 if (raw_before_defrag) {
87 table = &packet_raw_before_defrag;
89 pr_info("Enabling raw table before defrag\n");
92 rawtable_ops = xt_hook_ops_alloc(table, iptable_raw_hook);
93 if (IS_ERR(rawtable_ops))
94 return PTR_ERR(rawtable_ops);
96 ret = register_pernet_subsys(&iptable_raw_net_ops);
102 ret = iptable_raw_table_init(&init_net);
104 unregister_pernet_subsys(&iptable_raw_net_ops);
111 static void __exit iptable_raw_fini(void)
113 unregister_pernet_subsys(&iptable_raw_net_ops);
117 module_init(iptable_raw_init);
118 module_exit(iptable_raw_fini);
119 MODULE_LICENSE("GPL");