xref: /linux/net/openvswitch/conntrack.h (revision 3a2c4d55e32ad65efebdb6de44eef3bfa08bb49d)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2015 Nicira, Inc.
4  */
5 
6 #ifndef OVS_CONNTRACK_H
7 #define OVS_CONNTRACK_H 1
8 
9 #include "flow.h"
10 
11 struct ovs_conntrack_info;
12 struct ovs_ct_limit_info;
13 enum ovs_key_attr;
14 
15 #if IS_ENABLED(CONFIG_NF_CONNTRACK)
16 int ovs_ct_init(struct net *);
17 void ovs_ct_exit_start(struct net *net);
18 void ovs_ct_exit_finish(struct net *net);
19 bool ovs_ct_verify(struct net *, enum ovs_key_attr attr);
20 int ovs_ct_copy_action(struct net *, const struct nlattr *,
21 		       const struct sw_flow_key *, struct sw_flow_actions **,
22 		       bool log);
23 int ovs_ct_action_to_attr(const struct ovs_conntrack_info *, struct sk_buff *);
24 
25 int ovs_ct_execute(struct net *, struct sk_buff *, struct sw_flow_key *,
26 		   const struct ovs_conntrack_info *);
27 int ovs_ct_clear(struct sk_buff *skb, struct sw_flow_key *key);
28 
29 void ovs_ct_fill_key(const struct sk_buff *skb, struct sw_flow_key *key,
30 		     bool post_ct);
31 int ovs_ct_put_key(const struct sw_flow_key *swkey,
32 		   const struct sw_flow_key *output, struct sk_buff *skb);
33 void ovs_ct_free_action(const struct nlattr *a);
34 
35 #define CT_SUPPORTED_MASK (OVS_CS_F_NEW | OVS_CS_F_ESTABLISHED | \
36 			   OVS_CS_F_RELATED | OVS_CS_F_REPLY_DIR | \
37 			   OVS_CS_F_INVALID | OVS_CS_F_TRACKED | \
38 			   OVS_CS_F_SRC_NAT | OVS_CS_F_DST_NAT)
39 #else
40 #include <linux/errno.h>
41 
42 static inline int ovs_ct_init(struct net *net) { return 0; }
43 
44 static inline void ovs_ct_exit_start(struct net *net) { }
45 static inline void ovs_ct_exit_finish(struct net *net) { }
46 
47 static inline bool ovs_ct_verify(struct net *net, int attr)
48 {
49 	return false;
50 }
51 
52 static inline int ovs_ct_copy_action(struct net *net, const struct nlattr *nla,
53 				     const struct sw_flow_key *key,
54 				     struct sw_flow_actions **acts, bool log)
55 {
56 	return -ENOTSUPP;
57 }
58 
59 static inline int ovs_ct_action_to_attr(const struct ovs_conntrack_info *info,
60 					struct sk_buff *skb)
61 {
62 	return -ENOTSUPP;
63 }
64 
65 static inline int ovs_ct_execute(struct net *net, struct sk_buff *skb,
66 				 struct sw_flow_key *key,
67 				 const struct ovs_conntrack_info *info)
68 {
69 	kfree_skb(skb);
70 	return -ENOTSUPP;
71 }
72 
73 static inline int ovs_ct_clear(struct sk_buff *skb,
74 			       struct sw_flow_key *key)
75 {
76 	return -ENOTSUPP;
77 }
78 
79 static inline void ovs_ct_fill_key(const struct sk_buff *skb,
80 				   struct sw_flow_key *key,
81 				   bool post_ct)
82 {
83 	key->ct_state = 0;
84 	key->ct_zone = 0;
85 	key->ct.mark = 0;
86 	memset(&key->ct.labels, 0, sizeof(key->ct.labels));
87 	/* Clear 'ct_orig_proto' to mark the non-existence of original
88 	 * direction key fields.
89 	 */
90 	key->ct_orig_proto = 0;
91 }
92 
93 static inline int ovs_ct_put_key(const struct sw_flow_key *swkey,
94 				 const struct sw_flow_key *output,
95 				 struct sk_buff *skb)
96 {
97 	return 0;
98 }
99 
100 static inline void ovs_ct_free_action(const struct nlattr *a) { }
101 
102 #define CT_SUPPORTED_MASK 0
103 #endif /* CONFIG_NF_CONNTRACK */
104 
105 #if IS_ENABLED(CONFIG_NETFILTER_CONNCOUNT)
106 extern struct genl_family dp_ct_limit_genl_family;
107 #endif
108 #endif /* ovs_conntrack.h */
109