xref: /openbmc/linux/net/openvswitch/conntrack.h (revision 4a075bd4)
1 /*
2  * Copyright (c) 2015 Nicira, Inc.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of version 2 of the GNU General Public
6  * License as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * General Public License for more details.
12  */
13 
14 #ifndef OVS_CONNTRACK_H
15 #define OVS_CONNTRACK_H 1
16 
17 #include "flow.h"
18 
19 struct ovs_conntrack_info;
20 struct ovs_ct_limit_info;
21 enum ovs_key_attr;
22 
23 #if IS_ENABLED(CONFIG_NF_CONNTRACK)
24 int ovs_ct_init(struct net *);
25 void ovs_ct_exit(struct net *);
26 bool ovs_ct_verify(struct net *, enum ovs_key_attr attr);
27 int ovs_ct_copy_action(struct net *, const struct nlattr *,
28 		       const struct sw_flow_key *, struct sw_flow_actions **,
29 		       bool log);
30 int ovs_ct_action_to_attr(const struct ovs_conntrack_info *, struct sk_buff *);
31 
32 int ovs_ct_execute(struct net *, struct sk_buff *, struct sw_flow_key *,
33 		   const struct ovs_conntrack_info *);
34 int ovs_ct_clear(struct sk_buff *skb, struct sw_flow_key *key);
35 
36 void ovs_ct_fill_key(const struct sk_buff *skb, struct sw_flow_key *key);
37 int ovs_ct_put_key(const struct sw_flow_key *swkey,
38 		   const struct sw_flow_key *output, struct sk_buff *skb);
39 void ovs_ct_free_action(const struct nlattr *a);
40 
41 #define CT_SUPPORTED_MASK (OVS_CS_F_NEW | OVS_CS_F_ESTABLISHED | \
42 			   OVS_CS_F_RELATED | OVS_CS_F_REPLY_DIR | \
43 			   OVS_CS_F_INVALID | OVS_CS_F_TRACKED | \
44 			   OVS_CS_F_SRC_NAT | OVS_CS_F_DST_NAT)
45 #else
46 #include <linux/errno.h>
47 
48 static inline int ovs_ct_init(struct net *net) { return 0; }
49 
50 static inline void ovs_ct_exit(struct net *net) { }
51 
52 static inline bool ovs_ct_verify(struct net *net, int attr)
53 {
54 	return false;
55 }
56 
57 static inline int ovs_ct_copy_action(struct net *net, const struct nlattr *nla,
58 				     const struct sw_flow_key *key,
59 				     struct sw_flow_actions **acts, bool log)
60 {
61 	return -ENOTSUPP;
62 }
63 
64 static inline int ovs_ct_action_to_attr(const struct ovs_conntrack_info *info,
65 					struct sk_buff *skb)
66 {
67 	return -ENOTSUPP;
68 }
69 
70 static inline int ovs_ct_execute(struct net *net, struct sk_buff *skb,
71 				 struct sw_flow_key *key,
72 				 const struct ovs_conntrack_info *info)
73 {
74 	kfree_skb(skb);
75 	return -ENOTSUPP;
76 }
77 
78 static inline int ovs_ct_clear(struct sk_buff *skb,
79 			       struct sw_flow_key *key)
80 {
81 	return -ENOTSUPP;
82 }
83 
84 static inline void ovs_ct_fill_key(const struct sk_buff *skb,
85 				   struct sw_flow_key *key)
86 {
87 	key->ct_state = 0;
88 	key->ct_zone = 0;
89 	key->ct.mark = 0;
90 	memset(&key->ct.labels, 0, sizeof(key->ct.labels));
91 	/* Clear 'ct_orig_proto' to mark the non-existence of original
92 	 * direction key fields.
93 	 */
94 	key->ct_orig_proto = 0;
95 }
96 
97 static inline int ovs_ct_put_key(const struct sw_flow_key *swkey,
98 				 const struct sw_flow_key *output,
99 				 struct sk_buff *skb)
100 {
101 	return 0;
102 }
103 
104 static inline void ovs_ct_free_action(const struct nlattr *a) { }
105 
106 #define CT_SUPPORTED_MASK 0
107 #endif /* CONFIG_NF_CONNTRACK */
108 
109 #if IS_ENABLED(CONFIG_NETFILTER_CONNCOUNT)
110 extern struct genl_family dp_ct_limit_genl_family;
111 #endif
112 #endif /* ovs_conntrack.h */
113