0001
0002
0003
0004
0005
0006 #ifndef DATAPATH_H
0007 #define DATAPATH_H 1
0008
0009 #include <asm/page.h>
0010 #include <linux/kernel.h>
0011 #include <linux/mutex.h>
0012 #include <linux/netdevice.h>
0013 #include <linux/skbuff.h>
0014 #include <linux/u64_stats_sync.h>
0015 #include <net/ip_tunnels.h>
0016
0017 #include "conntrack.h"
0018 #include "flow.h"
0019 #include "flow_table.h"
0020 #include "meter.h"
0021 #include "vport-internal_dev.h"
0022
0023 #define DP_MAX_PORTS USHRT_MAX
0024 #define DP_VPORT_HASH_BUCKETS 1024
0025 #define DP_MASKS_REBALANCE_INTERVAL 4000
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 struct dp_stats_percpu {
0045 u64 n_hit;
0046 u64 n_missed;
0047 u64 n_lost;
0048 u64 n_mask_hit;
0049 u64 n_cache_hit;
0050 struct u64_stats_sync syncp;
0051 };
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062 struct dp_nlsk_pids {
0063 struct rcu_head rcu;
0064 u32 n_pids;
0065 u32 pids[];
0066 };
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084 struct datapath {
0085 struct rcu_head rcu;
0086 struct list_head list_node;
0087
0088
0089 struct flow_table table;
0090
0091
0092 struct hlist_head *ports;
0093
0094
0095 struct dp_stats_percpu __percpu *stats_percpu;
0096
0097
0098 possible_net_t net;
0099
0100 u32 user_features;
0101
0102 u32 max_headroom;
0103
0104
0105 struct dp_meter_table meter_tbl;
0106
0107 struct dp_nlsk_pids __rcu *upcall_portids;
0108 };
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119 struct ovs_skb_cb {
0120 struct vport *input_vport;
0121 u16 mru;
0122 u16 acts_origlen;
0123 u32 cutlen;
0124 };
0125 #define OVS_CB(skb) ((struct ovs_skb_cb *)(skb)->cb)
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138 struct dp_upcall_info {
0139 struct ip_tunnel_info *egress_tun_info;
0140 const struct nlattr *userdata;
0141 const struct nlattr *actions;
0142 int actions_len;
0143 u32 portid;
0144 u8 cmd;
0145 u16 mru;
0146 };
0147
0148
0149
0150
0151
0152
0153 struct ovs_net {
0154 struct list_head dps;
0155 struct work_struct dp_notify_work;
0156 struct delayed_work masks_rebalance;
0157 #if IS_ENABLED(CONFIG_NETFILTER_CONNCOUNT)
0158 struct ovs_ct_limit_info *ct_limit_info;
0159 #endif
0160
0161
0162 bool xt_label;
0163 };
0164
0165
0166
0167
0168
0169
0170
0171
0172 enum ovs_pkt_hash_types {
0173 OVS_PACKET_HASH_SW_BIT = (1ULL << 32),
0174 OVS_PACKET_HASH_L4_BIT = (1ULL << 33),
0175 };
0176
0177 extern unsigned int ovs_net_id;
0178 void ovs_lock(void);
0179 void ovs_unlock(void);
0180
0181 #ifdef CONFIG_LOCKDEP
0182 int lockdep_ovsl_is_held(void);
0183 #else
0184 #define lockdep_ovsl_is_held() 1
0185 #endif
0186
0187 #define ASSERT_OVSL() WARN_ON(!lockdep_ovsl_is_held())
0188 #define ovsl_dereference(p) \
0189 rcu_dereference_protected(p, lockdep_ovsl_is_held())
0190 #define rcu_dereference_ovsl(p) \
0191 rcu_dereference_check(p, lockdep_ovsl_is_held())
0192
0193 static inline struct net *ovs_dp_get_net(const struct datapath *dp)
0194 {
0195 return read_pnet(&dp->net);
0196 }
0197
0198 static inline void ovs_dp_set_net(struct datapath *dp, struct net *net)
0199 {
0200 write_pnet(&dp->net, net);
0201 }
0202
0203 struct vport *ovs_lookup_vport(const struct datapath *dp, u16 port_no);
0204
0205 static inline struct vport *ovs_vport_rcu(const struct datapath *dp, int port_no)
0206 {
0207 WARN_ON_ONCE(!rcu_read_lock_held());
0208 return ovs_lookup_vport(dp, port_no);
0209 }
0210
0211 static inline struct vport *ovs_vport_ovsl_rcu(const struct datapath *dp, int port_no)
0212 {
0213 WARN_ON_ONCE(!rcu_read_lock_held() && !lockdep_ovsl_is_held());
0214 return ovs_lookup_vport(dp, port_no);
0215 }
0216
0217 static inline struct vport *ovs_vport_ovsl(const struct datapath *dp, int port_no)
0218 {
0219 ASSERT_OVSL();
0220 return ovs_lookup_vport(dp, port_no);
0221 }
0222
0223
0224 static inline struct datapath *get_dp_rcu(struct net *net, int dp_ifindex)
0225 {
0226 struct net_device *dev = dev_get_by_index_rcu(net, dp_ifindex);
0227
0228 if (dev) {
0229 struct vport *vport = ovs_internal_dev_get_vport(dev);
0230
0231 if (vport)
0232 return vport->dp;
0233 }
0234
0235 return NULL;
0236 }
0237
0238
0239
0240
0241 static inline struct datapath *get_dp(struct net *net, int dp_ifindex)
0242 {
0243 struct datapath *dp;
0244
0245 WARN_ON_ONCE(!rcu_read_lock_held() && !lockdep_ovsl_is_held());
0246 rcu_read_lock();
0247 dp = get_dp_rcu(net, dp_ifindex);
0248 rcu_read_unlock();
0249
0250 return dp;
0251 }
0252
0253 extern struct notifier_block ovs_dp_device_notifier;
0254 extern struct genl_family dp_vport_genl_family;
0255
0256 void ovs_dp_process_packet(struct sk_buff *skb, struct sw_flow_key *key);
0257 void ovs_dp_detach_port(struct vport *);
0258 int ovs_dp_upcall(struct datapath *, struct sk_buff *,
0259 const struct sw_flow_key *, const struct dp_upcall_info *,
0260 uint32_t cutlen);
0261
0262 u32 ovs_dp_get_upcall_portid(const struct datapath *dp, uint32_t cpu_id);
0263
0264 const char *ovs_dp_name(const struct datapath *dp);
0265 struct sk_buff *ovs_vport_cmd_build_info(struct vport *vport, struct net *net,
0266 u32 portid, u32 seq, u8 cmd);
0267
0268 int ovs_execute_actions(struct datapath *dp, struct sk_buff *skb,
0269 const struct sw_flow_actions *, struct sw_flow_key *);
0270
0271 void ovs_dp_notify_wq(struct work_struct *work);
0272
0273 int action_fifos_init(void);
0274 void action_fifos_exit(void);
0275
0276
0277 #define OVS_MASKED(OLD, KEY, MASK) ((KEY) | ((OLD) & ~(MASK)))
0278 #define OVS_SET_MASKED(OLD, KEY, MASK) ((OLD) = OVS_MASKED(OLD, KEY, MASK))
0279
0280 #define OVS_NLERR(logging_allowed, fmt, ...) \
0281 do { \
0282 if (logging_allowed && net_ratelimit()) \
0283 pr_info("netlink: " fmt "\n", ##__VA_ARGS__); \
0284 } while (0)
0285 #endif