2 * 'raw' table, which is the very first hooked in at PRE_ROUTING and LOCAL_OUT .
4 * Copyright (C) 2003 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
6 #include <linux/module.h>
7 #include <linux/netfilter_ipv4/ip_tables.h>
8 #include <linux/slab.h>
11 #define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT))
13 static const struct xt_table packet_raw
= {
15 .valid_hooks
= RAW_VALID_HOOKS
,
18 .priority
= NF_IP_PRI_RAW
,
21 /* The work comes in here from netfilter.c. */
23 iptable_raw_hook(const struct nf_hook_ops
*ops
, struct sk_buff
*skb
,
24 const struct nf_hook_state
*state
)
26 const struct net
*net
;
28 if (ops
->hooknum
== NF_INET_LOCAL_OUT
&&
29 (skb
->len
< sizeof(struct iphdr
) ||
30 ip_hdrlen(skb
) < sizeof(struct iphdr
)))
31 /* root is playing with raw sockets. */
34 net
= dev_net(state
->in
? state
->in
: state
->out
);
35 return ipt_do_table(skb
, ops
->hooknum
, state
, net
->ipv4
.iptable_raw
);
38 static struct nf_hook_ops
*rawtable_ops __read_mostly
;
40 static int __net_init
iptable_raw_net_init(struct net
*net
)
42 struct ipt_replace
*repl
;
44 repl
= ipt_alloc_initial_table(&packet_raw
);
47 net
->ipv4
.iptable_raw
=
48 ipt_register_table(net
, &packet_raw
, repl
);
50 return PTR_ERR_OR_ZERO(net
->ipv4
.iptable_raw
);
53 static void __net_exit
iptable_raw_net_exit(struct net
*net
)
55 ipt_unregister_table(net
, net
->ipv4
.iptable_raw
);
58 static struct pernet_operations iptable_raw_net_ops
= {
59 .init
= iptable_raw_net_init
,
60 .exit
= iptable_raw_net_exit
,
63 static int __init
iptable_raw_init(void)
67 ret
= register_pernet_subsys(&iptable_raw_net_ops
);
72 rawtable_ops
= xt_hook_link(&packet_raw
, iptable_raw_hook
);
73 if (IS_ERR(rawtable_ops
)) {
74 ret
= PTR_ERR(rawtable_ops
);
75 unregister_pernet_subsys(&iptable_raw_net_ops
);
81 static void __exit
iptable_raw_fini(void)
83 xt_hook_unlink(&packet_raw
, rawtable_ops
);
84 unregister_pernet_subsys(&iptable_raw_net_ops
);
87 module_init(iptable_raw_init
);
88 module_exit(iptable_raw_fini
);
89 MODULE_LICENSE("GPL");