netfilter: nft_log: fix coccinelle warnings
[deliverable/linux.git] / net / ipv4 / netfilter / nf_defrag_ipv4.c
CommitLineData
73e4022f
KK
1/* (C) 1999-2001 Paul `Rusty' Russell
2 * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9#include <linux/types.h>
10#include <linux/ip.h>
11#include <linux/netfilter.h>
12#include <linux/module.h>
13#include <linux/skbuff.h>
14#include <net/route.h>
15#include <net/ip.h>
16
8fa9ff68 17#include <linux/netfilter_bridge.h>
73e4022f
KK
18#include <linux/netfilter_ipv4.h>
19#include <net/netfilter/ipv4/nf_defrag_ipv4.h>
37ee3d5b 20#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
76780373 21#include <net/netfilter/nf_conntrack.h>
37ee3d5b
PM
22#endif
23#include <net/netfilter/nf_conntrack_zones.h>
73e4022f 24
73e4022f
KK
25static int nf_ct_ipv4_gather_frags(struct sk_buff *skb, u_int32_t user)
26{
27 int err;
28
29 skb_orphan(skb);
30
31 local_bh_disable();
32 err = ip_defrag(skb, user);
33 local_bh_enable();
34
895162b1 35 if (!err) {
73e4022f 36 ip_send_check(ip_hdr(skb));
60ff7467 37 skb->ignore_df = 1;
895162b1 38 }
73e4022f
KK
39
40 return err;
41}
42
8fa9ff68
PM
43static enum ip_defrag_users nf_ct_defrag_user(unsigned int hooknum,
44 struct sk_buff *skb)
45{
5d0aa2cc
PM
46 u16 zone = NF_CT_DEFAULT_ZONE;
47
37ee3d5b 48#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
5d0aa2cc
PM
49 if (skb->nfct)
50 zone = nf_ct_zone((struct nf_conn *)skb->nfct);
37ee3d5b 51#endif
5d0aa2cc 52
8fa9ff68
PM
53#ifdef CONFIG_BRIDGE_NETFILTER
54 if (skb->nf_bridge &&
55 skb->nf_bridge->mask & BRNF_NF_BRIDGE_PREROUTING)
5d0aa2cc 56 return IP_DEFRAG_CONNTRACK_BRIDGE_IN + zone;
8fa9ff68
PM
57#endif
58 if (hooknum == NF_INET_PRE_ROUTING)
5d0aa2cc 59 return IP_DEFRAG_CONNTRACK_IN + zone;
8fa9ff68 60 else
5d0aa2cc 61 return IP_DEFRAG_CONNTRACK_OUT + zone;
8fa9ff68
PM
62}
63
795aa6ef 64static unsigned int ipv4_conntrack_defrag(const struct nf_hook_ops *ops,
73e4022f
KK
65 struct sk_buff *skb,
66 const struct net_device *in,
67 const struct net_device *out,
68 int (*okfn)(struct sk_buff *))
69{
cbdd769a 70 struct sock *sk = skb->sk;
7b2ff18e
JO
71 struct inet_sock *inet = inet_sk(skb->sk);
72
cbdd769a
JO
73 if (sk && (sk->sk_family == PF_INET) &&
74 inet->nodefrag)
7b2ff18e
JO
75 return NF_ACCEPT;
76
73e4022f 77#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
38f7ac3e 78#if !defined(CONFIG_NF_NAT) && !defined(CONFIG_NF_NAT_MODULE)
73e4022f
KK
79 /* Previously seen (loopback)? Ignore. Do this before
80 fragment check. */
b2a15a60 81 if (skb->nfct && !nf_ct_is_template((struct nf_conn *)skb->nfct))
73e4022f
KK
82 return NF_ACCEPT;
83#endif
38f7ac3e 84#endif
73e4022f 85 /* Gather fragments. */
56f8a75c 86 if (ip_is_fragment(ip_hdr(skb))) {
795aa6ef
PM
87 enum ip_defrag_users user =
88 nf_ct_defrag_user(ops->hooknum, skb);
89
8fa9ff68 90 if (nf_ct_ipv4_gather_frags(skb, user))
73e4022f
KK
91 return NF_STOLEN;
92 }
93 return NF_ACCEPT;
94}
95
96static struct nf_hook_ops ipv4_defrag_ops[] = {
97 {
98 .hook = ipv4_conntrack_defrag,
99 .owner = THIS_MODULE,
89a48e35 100 .pf = NFPROTO_IPV4,
73e4022f
KK
101 .hooknum = NF_INET_PRE_ROUTING,
102 .priority = NF_IP_PRI_CONNTRACK_DEFRAG,
103 },
104 {
105 .hook = ipv4_conntrack_defrag,
106 .owner = THIS_MODULE,
89a48e35 107 .pf = NFPROTO_IPV4,
73e4022f
KK
108 .hooknum = NF_INET_LOCAL_OUT,
109 .priority = NF_IP_PRI_CONNTRACK_DEFRAG,
110 },
111};
112
113static int __init nf_defrag_init(void)
114{
115 return nf_register_hooks(ipv4_defrag_ops, ARRAY_SIZE(ipv4_defrag_ops));
116}
117
118static void __exit nf_defrag_fini(void)
119{
120 nf_unregister_hooks(ipv4_defrag_ops, ARRAY_SIZE(ipv4_defrag_ops));
121}
122
123void nf_defrag_ipv4_enable(void)
124{
125}
126EXPORT_SYMBOL_GPL(nf_defrag_ipv4_enable);
127
128module_init(nf_defrag_init);
129module_exit(nf_defrag_fini);
130
131MODULE_LICENSE("GPL");
This page took 0.323763 seconds and 5 git commands to generate.