1
2
3
4
5
6#ifndef DATAPATH_H
7#define DATAPATH_H 1
8
9#include <asm/page.h>
10#include <linux/kernel.h>
11#include <linux/mutex.h>
12#include <linux/netdevice.h>
13#include <linux/skbuff.h>
14#include <linux/u64_stats_sync.h>
15#include <net/ip_tunnels.h>
16
17#include "conntrack.h"
18#include "flow.h"
19#include "flow_table.h"
20#include "meter.h"
21#include "vport-internal_dev.h"
22
23#define DP_MAX_PORTS USHRT_MAX
24#define DP_VPORT_HASH_BUCKETS 1024
25#define DP_MASKS_REBALANCE_INTERVAL 4000
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44struct dp_stats_percpu {
45 u64 n_hit;
46 u64 n_missed;
47 u64 n_lost;
48 u64 n_mask_hit;
49 u64 n_cache_hit;
50 struct u64_stats_sync syncp;
51};
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68struct datapath {
69 struct rcu_head rcu;
70 struct list_head list_node;
71
72
73 struct flow_table table;
74
75
76 struct hlist_head *ports;
77
78
79 struct dp_stats_percpu __percpu *stats_percpu;
80
81
82 possible_net_t net;
83
84 u32 user_features;
85
86 u32 max_headroom;
87
88
89 struct dp_meter_table meter_tbl;
90};
91
92
93
94
95
96
97
98
99
100
101struct ovs_skb_cb {
102 struct vport *input_vport;
103 u16 mru;
104 u16 acts_origlen;
105 u32 cutlen;
106};
107#define OVS_CB(skb) ((struct ovs_skb_cb *)(skb)->cb)
108
109
110
111
112
113
114
115
116
117
118
119
120struct dp_upcall_info {
121 struct ip_tunnel_info *egress_tun_info;
122 const struct nlattr *userdata;
123 const struct nlattr *actions;
124 int actions_len;
125 u32 portid;
126 u8 cmd;
127 u16 mru;
128};
129
130
131
132
133
134
135struct ovs_net {
136 struct list_head dps;
137 struct work_struct dp_notify_work;
138 struct delayed_work masks_rebalance;
139#if IS_ENABLED(CONFIG_NETFILTER_CONNCOUNT)
140 struct ovs_ct_limit_info *ct_limit_info;
141#endif
142
143
144 bool xt_label;
145};
146
147
148
149
150
151
152
153
154enum ovs_pkt_hash_types {
155 OVS_PACKET_HASH_SW_BIT = (1ULL << 32),
156 OVS_PACKET_HASH_L4_BIT = (1ULL << 33),
157};
158
159extern unsigned int ovs_net_id;
160void ovs_lock(void);
161void ovs_unlock(void);
162
163#ifdef CONFIG_LOCKDEP
164int lockdep_ovsl_is_held(void);
165#else
166#define lockdep_ovsl_is_held() 1
167#endif
168
169#define ASSERT_OVSL() WARN_ON(!lockdep_ovsl_is_held())
170#define ovsl_dereference(p) \
171 rcu_dereference_protected(p, lockdep_ovsl_is_held())
172#define rcu_dereference_ovsl(p) \
173 rcu_dereference_check(p, lockdep_ovsl_is_held())
174
175static inline struct net *ovs_dp_get_net(const struct datapath *dp)
176{
177 return read_pnet(&dp->net);
178}
179
180static inline void ovs_dp_set_net(struct datapath *dp, struct net *net)
181{
182 write_pnet(&dp->net, net);
183}
184
185struct vport *ovs_lookup_vport(const struct datapath *dp, u16 port_no);
186
187static inline struct vport *ovs_vport_rcu(const struct datapath *dp, int port_no)
188{
189 WARN_ON_ONCE(!rcu_read_lock_held());
190 return ovs_lookup_vport(dp, port_no);
191}
192
193static inline struct vport *ovs_vport_ovsl_rcu(const struct datapath *dp, int port_no)
194{
195 WARN_ON_ONCE(!rcu_read_lock_held() && !lockdep_ovsl_is_held());
196 return ovs_lookup_vport(dp, port_no);
197}
198
199static inline struct vport *ovs_vport_ovsl(const struct datapath *dp, int port_no)
200{
201 ASSERT_OVSL();
202 return ovs_lookup_vport(dp, port_no);
203}
204
205
206static inline struct datapath *get_dp_rcu(struct net *net, int dp_ifindex)
207{
208 struct net_device *dev = dev_get_by_index_rcu(net, dp_ifindex);
209
210 if (dev) {
211 struct vport *vport = ovs_internal_dev_get_vport(dev);
212
213 if (vport)
214 return vport->dp;
215 }
216
217 return NULL;
218}
219
220
221
222
223static inline struct datapath *get_dp(struct net *net, int dp_ifindex)
224{
225 struct datapath *dp;
226
227 WARN_ON_ONCE(!rcu_read_lock_held() && !lockdep_ovsl_is_held());
228 rcu_read_lock();
229 dp = get_dp_rcu(net, dp_ifindex);
230 rcu_read_unlock();
231
232 return dp;
233}
234
235extern struct notifier_block ovs_dp_device_notifier;
236extern struct genl_family dp_vport_genl_family;
237
238DECLARE_STATIC_KEY_FALSE(tc_recirc_sharing_support);
239
240void ovs_dp_process_packet(struct sk_buff *skb, struct sw_flow_key *key);
241void ovs_dp_detach_port(struct vport *);
242int ovs_dp_upcall(struct datapath *, struct sk_buff *,
243 const struct sw_flow_key *, const struct dp_upcall_info *,
244 uint32_t cutlen);
245
246const char *ovs_dp_name(const struct datapath *dp);
247struct sk_buff *ovs_vport_cmd_build_info(struct vport *vport, struct net *net,
248 u32 portid, u32 seq, u8 cmd);
249
250int ovs_execute_actions(struct datapath *dp, struct sk_buff *skb,
251 const struct sw_flow_actions *, struct sw_flow_key *);
252
253void ovs_dp_notify_wq(struct work_struct *work);
254
255int action_fifos_init(void);
256void action_fifos_exit(void);
257
258
259#define OVS_MASKED(OLD, KEY, MASK) ((KEY) | ((OLD) & ~(MASK)))
260#define OVS_SET_MASKED(OLD, KEY, MASK) ((OLD) = OVS_MASKED(OLD, KEY, MASK))
261
262#define OVS_NLERR(logging_allowed, fmt, ...) \
263do { \
264 if (logging_allowed && net_ratelimit()) \
265 pr_info("netlink: " fmt "\n", ##__VA_ARGS__); \
266} while (0)
267#endif
268