]> git.proxmox.com Git - ovs.git/blob - datapath/linux/compat/include/net/netfilter/nf_conntrack_core.h
bb3d7947183e808f8b5037dfa0aba65fca078f3e
[ovs.git] / datapath / linux / compat / include / net / netfilter / nf_conntrack_core.h
1 #ifndef _NF_CONNTRACK_CORE_WRAPPER_H
2 #define _NF_CONNTRACK_CORE_WRAPPER_H
3
4 #include_next <net/netfilter/nf_conntrack_core.h>
5
6 #ifndef HAVE_NF_CT_TMPL_ALLOC_TAKES_STRUCT_ZONE
7
8 #include <net/netfilter/nf_conntrack_zones.h>
9
10 /* Released via destroy_conntrack() */
11 static inline struct nf_conn *
12 rpl_nf_ct_tmpl_alloc(struct net *net, const struct nf_conntrack_zone *zone,
13 gfp_t flags)
14 {
15 struct nf_conn *tmpl;
16
17 tmpl = kzalloc(sizeof(*tmpl), flags);
18 if (tmpl == NULL)
19 return NULL;
20
21 tmpl->status = IPS_TEMPLATE;
22 write_pnet(&tmpl->ct_net, net);
23
24 if (nf_ct_zone_add(tmpl, flags, zone) < 0)
25 goto out_free;
26
27 atomic_set(&tmpl->ct_general.use, 0);
28
29 return tmpl;
30 out_free:
31 kfree(tmpl);
32 return NULL;
33 }
34 #define nf_ct_tmpl_alloc rpl_nf_ct_tmpl_alloc
35
36 static void rpl_nf_ct_tmpl_free(struct nf_conn *tmpl)
37 {
38 nf_ct_ext_destroy(tmpl);
39 nf_ct_ext_free(tmpl);
40 kfree(tmpl);
41 }
42 #define nf_ct_tmpl_free rpl_nf_ct_tmpl_free
43
44 static inline struct nf_conntrack_tuple_hash *
45 rpl_nf_conntrack_find_get(struct net *net,
46 const struct nf_conntrack_zone *zone,
47 const struct nf_conntrack_tuple *tuple)
48 {
49 return nf_conntrack_find_get(net, zone->id, tuple);
50 }
51 #define nf_conntrack_find_get rpl_nf_conntrack_find_get
52 #endif /* HAVE_NF_CT_TMPL_ALLOC_TAKES_STRUCT_ZONE */
53
54 #ifndef HAVE_NF_CT_GET_TUPLEPR_TAKES_STRUCT_NET
55 static inline bool rpl_nf_ct_get_tuple(const struct sk_buff *skb,
56 unsigned int nhoff,
57 unsigned int dataoff, u_int16_t l3num,
58 u_int8_t protonum,
59 struct net *net,
60 struct nf_conntrack_tuple *tuple,
61 const struct nf_conntrack_l3proto *l3proto,
62 const struct nf_conntrack_l4proto *l4proto)
63 {
64 return nf_ct_get_tuple(skb, nhoff, dataoff, l3num, protonum, tuple,
65 l3proto, l4proto);
66 }
67 #define nf_ct_get_tuple rpl_nf_ct_get_tuple
68 #endif /* HAVE_NF_CT_GET_TUPLEPR_TAKES_STRUCT_NET */
69
70 #ifdef HAVE_NF_CONN_TIMER
71
72 #ifndef HAVE_NF_CT_DELETE
73 #include <net/netfilter/nf_conntrack_timestamp.h>
74 #endif
75
76 static inline bool rpl_nf_ct_delete(struct nf_conn *ct, u32 portid, int report)
77 {
78 if (del_timer(&ct->timeout))
79 #ifdef HAVE_NF_CT_DELETE
80 return nf_ct_delete(ct, portid, report);
81 #else
82 {
83 struct nf_conn_tstamp *tstamp;
84
85 tstamp = nf_conn_tstamp_find(ct);
86 if (tstamp && tstamp->stop == 0)
87 tstamp->stop = ktime_to_ns(ktime_get_real());
88
89 if (!test_bit(IPS_DYING_BIT, &ct->status) &&
90 unlikely(nf_conntrack_event(IPCT_DESTROY, ct) < 0)) {
91 /* destroy event was not delivered */
92 nf_ct_delete_from_lists(ct);
93 nf_ct_dying_timeout(ct);
94 return false;
95 }
96 set_bit(IPS_DYING_BIT, &ct->status);
97 nf_ct_delete_from_lists(ct);
98 nf_ct_put(ct);
99 return true;
100 }
101 #endif
102 return false;
103 }
104 #define nf_ct_delete rpl_nf_ct_delete
105 #endif /* HAVE_NF_CONN_TIMER */
106
107 #ifndef HAVE_NF_CONNTRACK_IN_TAKES_NF_HOOK_STATE
108 static inline unsigned int
109 rpl_nf_conntrack_in(struct sk_buff *skb, const struct nf_hook_state *state)
110 {
111 return nf_conntrack_in(state->net, state->pf, state->hook, skb);
112 }
113 #define nf_conntrack_in rpl_nf_conntrack_in
114 #endif /* HAVE_NF_CONNTRACK_IN_TAKES_NF_HOOK_STATE */
115
116 #ifdef HAVE_NF_CT_INVERT_TUPLEPR
117 static inline bool rpl_nf_ct_invert_tuple(struct nf_conntrack_tuple *inverse,
118 const struct nf_conntrack_tuple *orig)
119 {
120 return nf_ct_invert_tuplepr(inverse, orig);
121 }
122 #else
123 static inline bool rpl_nf_ct_invert_tuple(struct nf_conntrack_tuple *inverse,
124 const struct nf_conntrack_tuple *orig)
125 {
126 return nf_ct_invert_tuple(inverse, orig);
127 }
128 #endif /* HAVE_NF_CT_INVERT_TUPLEPR */
129
130 #endif /* _NF_CONNTRACK_CORE_WRAPPER_H */