]>
git.proxmox.com Git - mirror_ovs.git/blob - datapath/linux/compat/nf_conntrack_proto.c
1 #include <linux/types.h>
3 #include <net/netfilter/nf_conntrack.h>
4 #ifdef HAVE_NF_CONNTRACK_L3PROATO_H
5 #include <net/netfilter/nf_conntrack_l3proto.h>
9 * Upstream net-next commmit 7e35ec0e8044
10 * ("netfilter: conntrack: move nf_ct_netns_{get,put}() to core")
11 * is introduced in v4.15, and it supports NFPROTO_INET in
12 * nf_ct_netns_{get,put}() that OVS conntrack uses this feature.
14 * However, we only need this feature if the underlying nf_conntrack_l3proto
15 * supports net_ns_get/put. Thus, we just mock the functions if
16 * HAVE_NET_NS_GET is false.
18 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,15,0)
19 #ifdef HAVE_NET_NS_GET
20 static int nf_ct_netns_do_get(struct net
*net
, u8 nfproto
)
22 const struct nf_conntrack_l3proto
*l3proto
;
27 ret
= nf_ct_l3proto_try_module_get(nfproto
);
31 /* we already have a reference, can't fail */
33 l3proto
= __nf_ct_l3proto_find(nfproto
);
36 if (!l3proto
->net_ns_get
)
39 ret
= l3proto
->net_ns_get(net
);
41 nf_ct_l3proto_module_put(nfproto
);
46 int rpl_nf_ct_netns_get(struct net
*net
, u8 nfproto
)
50 if (nfproto
== NFPROTO_INET
) {
51 err
= nf_ct_netns_do_get(net
, NFPROTO_IPV4
);
54 err
= nf_ct_netns_do_get(net
, NFPROTO_IPV6
);
58 err
= nf_ct_netns_do_get(net
, nfproto
);
65 nf_ct_netns_put(net
, NFPROTO_IPV4
);
69 EXPORT_SYMBOL_GPL(rpl_nf_ct_netns_get
);
71 static void nf_ct_netns_do_put(struct net
*net
, u8 nfproto
)
73 const struct nf_conntrack_l3proto
*l3proto
;
77 /* same as nf_conntrack_netns_get(), reference assumed */
79 l3proto
= __nf_ct_l3proto_find(nfproto
);
82 if (WARN_ON(!l3proto
))
85 if (l3proto
->net_ns_put
)
86 l3proto
->net_ns_put(net
);
88 nf_ct_l3proto_module_put(nfproto
);
91 void rpl_nf_ct_netns_put(struct net
*net
, uint8_t nfproto
)
93 if (nfproto
== NFPROTO_INET
) {
94 nf_ct_netns_do_put(net
, NFPROTO_IPV4
);
95 nf_ct_netns_do_put(net
, NFPROTO_IPV6
);
97 nf_ct_netns_do_put(net
, nfproto
);
99 EXPORT_SYMBOL_GPL(rpl_nf_ct_netns_put
);
101 #else /* !HAVE_NET_NS_GET */
102 void rpl_nf_ct_netns_put(struct net
*net
, uint8_t nfproto
)
105 EXPORT_SYMBOL_GPL(rpl_nf_ct_netns_put
);
107 int rpl_nf_ct_netns_get(struct net
*net
, u8 nfproto
)
111 EXPORT_SYMBOL_GPL(rpl_nf_ct_netns_get
);
113 #endif /* HAVE_NET_NS_GET */
114 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(4,15,0) */