2 * (C) 2012 by Pablo Neira Ayuso <pablo@netfilter.org>
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.
10 #include <linux/skbuff.h>
11 #include <linux/netfilter.h>
12 #include <linux/netfilter/nfnetlink.h>
13 #include <linux/netfilter/nfnetlink_queue.h>
14 #include <net/netfilter/nf_conntrack.h>
15 #include <net/netfilter/nfnetlink_queue.h>
17 struct nf_conn
*nfqnl_ct_get(struct sk_buff
*entskb
, size_t *size
,
18 enum ip_conntrack_info
*ctinfo
)
20 struct nfq_ct_hook
*nfq_ct
;
23 /* rcu_read_lock()ed by __nf_queue already. */
24 nfq_ct
= rcu_dereference(nfq_ct_hook
);
28 ct
= nf_ct_get(entskb
, ctinfo
);
30 if (!nf_ct_is_untracked(ct
))
31 *size
+= nfq_ct
->build_size(ct
);
39 nfqnl_ct_parse(const struct sk_buff
*skb
, const struct nlattr
*attr
,
40 enum ip_conntrack_info
*ctinfo
)
42 struct nfq_ct_hook
*nfq_ct
;
45 /* rcu_read_lock()ed by __nf_queue already. */
46 nfq_ct
= rcu_dereference(nfq_ct_hook
);
50 ct
= nf_ct_get(skb
, ctinfo
);
51 if (ct
&& !nf_ct_is_untracked(ct
))
52 nfq_ct
->parse(attr
, ct
);
57 int nfqnl_ct_put(struct sk_buff
*skb
, struct nf_conn
*ct
,
58 enum ip_conntrack_info ctinfo
)
60 struct nfq_ct_hook
*nfq_ct
;
61 struct nlattr
*nest_parms
;
64 nfq_ct
= rcu_dereference(nfq_ct_hook
);
68 nest_parms
= nla_nest_start(skb
, NFQA_CT
| NLA_F_NESTED
);
72 if (nfq_ct
->build(skb
, ct
) < 0)
75 nla_nest_end(skb
, nest_parms
);
78 if (nla_put_be32(skb
, NFQA_CT_INFO
, htonl(tmp
)))
87 void nfqnl_ct_seq_adjust(struct sk_buff
*skb
, struct nf_conn
*ct
,
88 enum ip_conntrack_info ctinfo
, int diff
)
90 struct nfq_ct_nat_hook
*nfq_nat_ct
;
92 nfq_nat_ct
= rcu_dereference(nfq_ct_nat_hook
);
93 if (nfq_nat_ct
== NULL
)
96 if ((ct
->status
& IPS_NAT_MASK
) && diff
)
97 nfq_nat_ct
->seq_adjust(skb
, ct
, ctinfo
, diff
);