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
148
149 bool xt_label;
150};
151
152extern unsigned int ovs_net_id;
153void ovs_lock(void);
154void ovs_unlock(void);
155
156#ifdef CONFIG_LOCKDEP
157int lockdep_ovsl_is_held(void);
158#else
159#define lockdep_ovsl_is_held() 1
160#endif
161
162#define ASSERT_OVSL() WARN_ON(!lockdep_ovsl_is_held())
163#define ovsl_dereference(p) \
164 rcu_dereference_protected(p, lockdep_ovsl_is_held())
165#define rcu_dereference_ovsl(p) \
166 rcu_dereference_check(p, lockdep_ovsl_is_held())
167
168static inline struct net *ovs_dp_get_net(const struct datapath *dp)
169{
170 return read_pnet(&dp->net);
171}
172
173static inline void ovs_dp_set_net(struct datapath *dp, struct net *net)
174{
175 write_pnet(&dp->net, net);
176}
177
178struct vport *ovs_lookup_vport(const struct datapath *dp, u16 port_no);
179
180static inline struct vport *ovs_vport_rcu(const struct datapath *dp, int port_no)
181{
182 WARN_ON_ONCE(!rcu_read_lock_held());
183 return ovs_lookup_vport(dp, port_no);
184}
185
186static inline struct vport *ovs_vport_ovsl_rcu(const struct datapath *dp, int port_no)
187{
188 WARN_ON_ONCE(!rcu_read_lock_held() && !lockdep_ovsl_is_held());
189 return ovs_lookup_vport(dp, port_no);
190}
191
192static inline struct vport *ovs_vport_ovsl(const struct datapath *dp, int port_no)
193{
194 ASSERT_OVSL();
195 return ovs_lookup_vport(dp, port_no);
196}
197
198
199static inline struct datapath *get_dp_rcu(struct net *net, int dp_ifindex)
200{
201 struct net_device *dev = dev_get_by_index_rcu(net, dp_ifindex);
202
203 if (dev) {
204 struct vport *vport = ovs_internal_dev_get_vport(dev);
205
206 if (vport)
207 return vport->dp;
208 }
209
210 return NULL;
211}
212
213
214
215
216static inline struct datapath *get_dp(struct net *net, int dp_ifindex)
217{
218 struct datapath *dp;
219
220 WARN_ON_ONCE(!rcu_read_lock_held() && !lockdep_ovsl_is_held());
221 rcu_read_lock();
222 dp = get_dp_rcu(net, dp_ifindex);
223 rcu_read_unlock();
224
225 return dp;
226}
227
228extern struct notifier_block ovs_dp_device_notifier;
229extern struct genl_family dp_vport_genl_family;
230
231void ovs_dp_process_packet(struct sk_buff *skb, struct sw_flow_key *key);
232void ovs_dp_detach_port(struct vport *);
233int ovs_dp_upcall(struct datapath *, struct sk_buff *,
234 const struct sw_flow_key *, const struct dp_upcall_info *,
235 uint32_t cutlen);
236
237const char *ovs_dp_name(const struct datapath *dp);
238struct sk_buff *ovs_vport_cmd_build_info(struct vport *vport, struct net *net,
239 u32 portid, u32 seq, u8 cmd);
240
241int ovs_execute_actions(struct datapath *dp, struct sk_buff *skb,
242 const struct sw_flow_actions *, struct sw_flow_key *);
243
244void ovs_dp_notify_wq(struct work_struct *work);
245
246int action_fifos_init(void);
247void action_fifos_exit(void);
248
249
250#define OVS_MASKED(OLD, KEY, MASK) ((KEY) | ((OLD) & ~(MASK)))
251#define OVS_SET_MASKED(OLD, KEY, MASK) ((OLD) = OVS_MASKED(OLD, KEY, MASK))
252
253#define OVS_NLERR(logging_allowed, fmt, ...) \
254do { \
255 if (logging_allowed && net_ratelimit()) \
256 pr_info("netlink: " fmt "\n", ##__VA_ARGS__); \
257} while (0)
258#endif
259