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>
10 #define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT))
14 struct ipt_replace repl
;
15 struct ipt_standard entries
[2];
16 struct ipt_error term
;
17 } initial_table __net_initdata
= {
20 .valid_hooks
= RAW_VALID_HOOKS
,
22 .size
= sizeof(struct ipt_standard
) * 2 + sizeof(struct ipt_error
),
24 [NF_INET_PRE_ROUTING
] = 0,
25 [NF_INET_LOCAL_OUT
] = sizeof(struct ipt_standard
)
28 [NF_INET_PRE_ROUTING
] = 0,
29 [NF_INET_LOCAL_OUT
] = sizeof(struct ipt_standard
)
33 IPT_STANDARD_INIT(NF_ACCEPT
), /* PRE_ROUTING */
34 IPT_STANDARD_INIT(NF_ACCEPT
), /* LOCAL_OUT */
36 .term
= IPT_ERROR_INIT
, /* ERROR */
39 static const struct xt_table packet_raw
= {
41 .valid_hooks
= RAW_VALID_HOOKS
,
46 /* The work comes in here from netfilter.c. */
48 iptable_raw_hook(unsigned int hook
, struct sk_buff
*skb
,
49 const struct net_device
*in
, const struct net_device
*out
,
50 int (*okfn
)(struct sk_buff
*))
52 const struct net
*net
;
54 if (hook
== NF_INET_LOCAL_OUT
&&
55 (skb
->len
< sizeof(struct iphdr
) ||
56 ip_hdrlen(skb
) < sizeof(struct iphdr
)))
57 /* root is playing with raw sockets. */
60 net
= dev_net((in
!= NULL
) ? in
: out
);
61 return ipt_do_table(skb
, hook
, in
, out
, net
->ipv4
.iptable_raw
);
64 /* 'raw' is the very first table. */
65 static struct nf_hook_ops ipt_ops
[] __read_mostly
= {
67 .hook
= iptable_raw_hook
,
69 .hooknum
= NF_INET_PRE_ROUTING
,
70 .priority
= NF_IP_PRI_RAW
,
74 .hook
= iptable_raw_hook
,
76 .hooknum
= NF_INET_LOCAL_OUT
,
77 .priority
= NF_IP_PRI_RAW
,
82 static int __net_init
iptable_raw_net_init(struct net
*net
)
85 net
->ipv4
.iptable_raw
=
86 ipt_register_table(net
, &packet_raw
, &initial_table
.repl
);
87 if (IS_ERR(net
->ipv4
.iptable_raw
))
88 return PTR_ERR(net
->ipv4
.iptable_raw
);
92 static void __net_exit
iptable_raw_net_exit(struct net
*net
)
94 ipt_unregister_table(net
, net
->ipv4
.iptable_raw
);
97 static struct pernet_operations iptable_raw_net_ops
= {
98 .init
= iptable_raw_net_init
,
99 .exit
= iptable_raw_net_exit
,
102 static int __init
iptable_raw_init(void)
106 ret
= register_pernet_subsys(&iptable_raw_net_ops
);
111 ret
= nf_register_hooks(ipt_ops
, ARRAY_SIZE(ipt_ops
));
118 unregister_pernet_subsys(&iptable_raw_net_ops
);
122 static void __exit
iptable_raw_fini(void)
124 nf_unregister_hooks(ipt_ops
, ARRAY_SIZE(ipt_ops
));
125 unregister_pernet_subsys(&iptable_raw_net_ops
);
128 module_init(iptable_raw_init
);
129 module_exit(iptable_raw_fini
);
130 MODULE_LICENSE("GPL");