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