Commit 4083c805 authored by David S. Miller's avatar David S. Miller

Merge branch 'net_next_ovs' of git://git.kernel.org/pub/scm/linux/kernel/git/pshelar/openvswitch

Pravin B Shelar says:

====================
Open vSwitch

Following batch of patches brings feature parity between upstream
ovs and out of tree ovs module.

Two features are added, first adds support to export egress
tunnel information for a packet. This is used to improve
visibility in network traffic. Second feature allows userspace
vswitchd process to probe ovs module features. Other patches
are optimization and code cleanup.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents a2ae6007 05da5898
...@@ -157,6 +157,11 @@ enum ovs_packet_cmd { ...@@ -157,6 +157,11 @@ enum ovs_packet_cmd {
* notification if the %OVS_ACTION_ATTR_USERSPACE action specified an * notification if the %OVS_ACTION_ATTR_USERSPACE action specified an
* %OVS_USERSPACE_ATTR_USERDATA attribute, with the same length and content * %OVS_USERSPACE_ATTR_USERDATA attribute, with the same length and content
* specified there. * specified there.
* @OVS_PACKET_ATTR_EGRESS_TUN_KEY: Present for an %OVS_PACKET_CMD_ACTION
* notification if the %OVS_ACTION_ATTR_USERSPACE action specified an
* %OVS_USERSPACE_ATTR_EGRESS_TUN_PORT attribute, which is sent only if the
* output port is actually a tunnel port. Contains the output tunnel key
* extracted from the packet as nested %OVS_TUNNEL_KEY_ATTR_* attributes.
* *
* These attributes follow the &struct ovs_header within the Generic Netlink * These attributes follow the &struct ovs_header within the Generic Netlink
* payload for %OVS_PACKET_* commands. * payload for %OVS_PACKET_* commands.
...@@ -167,6 +172,8 @@ enum ovs_packet_attr { ...@@ -167,6 +172,8 @@ enum ovs_packet_attr {
OVS_PACKET_ATTR_KEY, /* Nested OVS_KEY_ATTR_* attributes. */ OVS_PACKET_ATTR_KEY, /* Nested OVS_KEY_ATTR_* attributes. */
OVS_PACKET_ATTR_ACTIONS, /* Nested OVS_ACTION_ATTR_* attributes. */ OVS_PACKET_ATTR_ACTIONS, /* Nested OVS_ACTION_ATTR_* attributes. */
OVS_PACKET_ATTR_USERDATA, /* OVS_ACTION_ATTR_USERSPACE arg. */ OVS_PACKET_ATTR_USERDATA, /* OVS_ACTION_ATTR_USERSPACE arg. */
OVS_PACKET_ATTR_EGRESS_TUN_KEY, /* Nested OVS_TUNNEL_KEY_ATTR_*
attributes. */
__OVS_PACKET_ATTR_MAX __OVS_PACKET_ATTR_MAX
}; };
...@@ -315,6 +322,8 @@ enum ovs_tunnel_key_attr { ...@@ -315,6 +322,8 @@ enum ovs_tunnel_key_attr {
OVS_TUNNEL_KEY_ATTR_CSUM, /* No argument. CSUM packet. */ OVS_TUNNEL_KEY_ATTR_CSUM, /* No argument. CSUM packet. */
OVS_TUNNEL_KEY_ATTR_OAM, /* No argument. OAM frame. */ OVS_TUNNEL_KEY_ATTR_OAM, /* No argument. OAM frame. */
OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS, /* Array of Geneve options. */ OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS, /* Array of Geneve options. */
OVS_TUNNEL_KEY_ATTR_TP_SRC, /* be16 src Transport Port. */
OVS_TUNNEL_KEY_ATTR_TP_DST, /* be16 dst Transport Port. */
__OVS_TUNNEL_KEY_ATTR_MAX __OVS_TUNNEL_KEY_ATTR_MAX
}; };
...@@ -448,6 +457,8 @@ enum ovs_flow_attr { ...@@ -448,6 +457,8 @@ enum ovs_flow_attr {
OVS_FLOW_ATTR_USED, /* u64 msecs last used in monotonic time. */ OVS_FLOW_ATTR_USED, /* u64 msecs last used in monotonic time. */
OVS_FLOW_ATTR_CLEAR, /* Flag to clear stats, tcp_flags, used. */ OVS_FLOW_ATTR_CLEAR, /* Flag to clear stats, tcp_flags, used. */
OVS_FLOW_ATTR_MASK, /* Sequence of OVS_KEY_ATTR_* attributes. */ OVS_FLOW_ATTR_MASK, /* Sequence of OVS_KEY_ATTR_* attributes. */
OVS_FLOW_ATTR_PROBE, /* Flow operation is a feature probe, error
* logging should be suppressed. */
__OVS_FLOW_ATTR_MAX __OVS_FLOW_ATTR_MAX
}; };
...@@ -480,11 +491,15 @@ enum ovs_sample_attr { ...@@ -480,11 +491,15 @@ enum ovs_sample_attr {
* message should be sent. Required. * message should be sent. Required.
* @OVS_USERSPACE_ATTR_USERDATA: If present, its variable-length argument is * @OVS_USERSPACE_ATTR_USERDATA: If present, its variable-length argument is
* copied to the %OVS_PACKET_CMD_ACTION message as %OVS_PACKET_ATTR_USERDATA. * copied to the %OVS_PACKET_CMD_ACTION message as %OVS_PACKET_ATTR_USERDATA.
* @OVS_USERSPACE_ATTR_EGRESS_TUN_PORT: If present, u32 output port to get
* tunnel info.
*/ */
enum ovs_userspace_attr { enum ovs_userspace_attr {
OVS_USERSPACE_ATTR_UNSPEC, OVS_USERSPACE_ATTR_UNSPEC,
OVS_USERSPACE_ATTR_PID, /* u32 Netlink PID to receive upcalls. */ OVS_USERSPACE_ATTR_PID, /* u32 Netlink PID to receive upcalls. */
OVS_USERSPACE_ATTR_USERDATA, /* Optional user-specified cookie. */ OVS_USERSPACE_ATTR_USERDATA, /* Optional user-specified cookie. */
OVS_USERSPACE_ATTR_EGRESS_TUN_PORT, /* Optional, u32 output port
* to get tunnel info. */
__OVS_USERSPACE_ATTR_MAX __OVS_USERSPACE_ATTR_MAX
}; };
......
This diff is collapsed.
This diff is collapsed.
...@@ -108,18 +108,18 @@ struct ovs_skb_cb { ...@@ -108,18 +108,18 @@ struct ovs_skb_cb {
/** /**
* struct dp_upcall - metadata to include with a packet to send to userspace * struct dp_upcall - metadata to include with a packet to send to userspace
* @cmd: One of %OVS_PACKET_CMD_*. * @cmd: One of %OVS_PACKET_CMD_*.
* @key: Becomes %OVS_PACKET_ATTR_KEY. Must be nonnull.
* @userdata: If nonnull, its variable-length value is passed to userspace as * @userdata: If nonnull, its variable-length value is passed to userspace as
* %OVS_PACKET_ATTR_USERDATA. * %OVS_PACKET_ATTR_USERDATA.
* @pid: Netlink PID to which packet should be sent. If @pid is 0 then no * @portid: Netlink portid to which packet should be sent. If @portid is 0
* packet is sent and the packet is accounted in the datapath's @n_lost * then no packet is sent and the packet is accounted in the datapath's @n_lost
* counter. * counter.
* @egress_tun_info: If nonnull, becomes %OVS_PACKET_ATTR_EGRESS_TUN_KEY.
*/ */
struct dp_upcall_info { struct dp_upcall_info {
u8 cmd; const struct ovs_tunnel_info *egress_tun_info;
const struct sw_flow_key *key;
const struct nlattr *userdata; const struct nlattr *userdata;
u32 portid; u32 portid;
u8 cmd;
}; };
/** /**
...@@ -149,7 +149,7 @@ int lockdep_ovsl_is_held(void); ...@@ -149,7 +149,7 @@ int lockdep_ovsl_is_held(void);
#define rcu_dereference_ovsl(p) \ #define rcu_dereference_ovsl(p) \
rcu_dereference_check(p, lockdep_ovsl_is_held()) rcu_dereference_check(p, lockdep_ovsl_is_held())
static inline struct net *ovs_dp_get_net(struct datapath *dp) static inline struct net *ovs_dp_get_net(const struct datapath *dp)
{ {
return read_pnet(&dp->net); return read_pnet(&dp->net);
} }
...@@ -185,23 +185,23 @@ extern struct genl_family dp_vport_genl_family; ...@@ -185,23 +185,23 @@ extern struct genl_family dp_vport_genl_family;
void ovs_dp_process_packet(struct sk_buff *skb, struct sw_flow_key *key); void ovs_dp_process_packet(struct sk_buff *skb, struct sw_flow_key *key);
void ovs_dp_detach_port(struct vport *); void ovs_dp_detach_port(struct vport *);
int ovs_dp_upcall(struct datapath *, struct sk_buff *, int ovs_dp_upcall(struct datapath *, struct sk_buff *,
const struct dp_upcall_info *); const struct sw_flow_key *, const struct dp_upcall_info *);
const char *ovs_dp_name(const struct datapath *dp); const char *ovs_dp_name(const struct datapath *dp);
struct sk_buff *ovs_vport_cmd_build_info(struct vport *, u32 pid, u32 seq, struct sk_buff *ovs_vport_cmd_build_info(struct vport *, u32 pid, u32 seq,
u8 cmd); u8 cmd);
int ovs_execute_actions(struct datapath *dp, struct sk_buff *skb, int ovs_execute_actions(struct datapath *dp, struct sk_buff *skb,
struct sw_flow_actions *acts, struct sw_flow_key *); const struct sw_flow_actions *, struct sw_flow_key *);
void ovs_dp_notify_wq(struct work_struct *work); void ovs_dp_notify_wq(struct work_struct *work);
int action_fifos_init(void); int action_fifos_init(void);
void action_fifos_exit(void); void action_fifos_exit(void);
#define OVS_NLERR(fmt, ...) \ #define OVS_NLERR(logging_allowed, fmt, ...) \
do { \ do { \
if (net_ratelimit()) \ if (logging_allowed && net_ratelimit()) \
pr_info("netlink: " fmt, ##__VA_ARGS__); \ pr_info("netlink: " fmt "\n", ##__VA_ARGS__); \
} while (0) } while (0)
#endif /* datapath.h */ #endif /* datapath.h */
...@@ -66,7 +66,7 @@ u64 ovs_flow_used_time(unsigned long flow_jiffies) ...@@ -66,7 +66,7 @@ u64 ovs_flow_used_time(unsigned long flow_jiffies)
#define TCP_FLAGS_BE16(tp) (*(__be16 *)&tcp_flag_word(tp) & htons(0x0FFF)) #define TCP_FLAGS_BE16(tp) (*(__be16 *)&tcp_flag_word(tp) & htons(0x0FFF))
void ovs_flow_stats_update(struct sw_flow *flow, __be16 tcp_flags, void ovs_flow_stats_update(struct sw_flow *flow, __be16 tcp_flags,
struct sk_buff *skb) const struct sk_buff *skb)
{ {
struct flow_stats *stats; struct flow_stats *stats;
int node = numa_node_id(); int node = numa_node_id();
...@@ -679,7 +679,7 @@ int ovs_flow_key_update(struct sk_buff *skb, struct sw_flow_key *key) ...@@ -679,7 +679,7 @@ int ovs_flow_key_update(struct sk_buff *skb, struct sw_flow_key *key)
return key_extract(skb, key); return key_extract(skb, key);
} }
int ovs_flow_key_extract(struct ovs_tunnel_info *tun_info, int ovs_flow_key_extract(const struct ovs_tunnel_info *tun_info,
struct sk_buff *skb, struct sw_flow_key *key) struct sk_buff *skb, struct sw_flow_key *key)
{ {
/* Extract metadata from packet. */ /* Extract metadata from packet. */
...@@ -712,12 +712,12 @@ int ovs_flow_key_extract(struct ovs_tunnel_info *tun_info, ...@@ -712,12 +712,12 @@ int ovs_flow_key_extract(struct ovs_tunnel_info *tun_info,
int ovs_flow_key_extract_userspace(const struct nlattr *attr, int ovs_flow_key_extract_userspace(const struct nlattr *attr,
struct sk_buff *skb, struct sk_buff *skb,
struct sw_flow_key *key) struct sw_flow_key *key, bool log)
{ {
int err; int err;
/* Extract metadata from netlink attributes. */ /* Extract metadata from netlink attributes. */
err = ovs_nla_get_flow_metadata(attr, key); err = ovs_nla_get_flow_metadata(attr, key, log);
if (err) if (err)
return err; return err;
......
...@@ -37,8 +37,8 @@ struct sk_buff; ...@@ -37,8 +37,8 @@ struct sk_buff;
/* Used to memset ovs_key_ipv4_tunnel padding. */ /* Used to memset ovs_key_ipv4_tunnel padding. */
#define OVS_TUNNEL_KEY_SIZE \ #define OVS_TUNNEL_KEY_SIZE \
(offsetof(struct ovs_key_ipv4_tunnel, ipv4_ttl) + \ (offsetof(struct ovs_key_ipv4_tunnel, tp_dst) + \
FIELD_SIZEOF(struct ovs_key_ipv4_tunnel, ipv4_ttl)) FIELD_SIZEOF(struct ovs_key_ipv4_tunnel, tp_dst))
struct ovs_key_ipv4_tunnel { struct ovs_key_ipv4_tunnel {
__be64 tun_id; __be64 tun_id;
...@@ -47,11 +47,13 @@ struct ovs_key_ipv4_tunnel { ...@@ -47,11 +47,13 @@ struct ovs_key_ipv4_tunnel {
__be16 tun_flags; __be16 tun_flags;
u8 ipv4_tos; u8 ipv4_tos;
u8 ipv4_ttl; u8 ipv4_ttl;
__be16 tp_src;
__be16 tp_dst;
} __packed __aligned(4); /* Minimize padding. */ } __packed __aligned(4); /* Minimize padding. */
struct ovs_tunnel_info { struct ovs_tunnel_info {
struct ovs_key_ipv4_tunnel tunnel; struct ovs_key_ipv4_tunnel tunnel;
struct geneve_opt *options; const struct geneve_opt *options;
u8 options_len; u8 options_len;
}; };
...@@ -64,27 +66,59 @@ struct ovs_tunnel_info { ...@@ -64,27 +66,59 @@ struct ovs_tunnel_info {
FIELD_SIZEOF(struct sw_flow_key, tun_opts) - \ FIELD_SIZEOF(struct sw_flow_key, tun_opts) - \
opt_len)) opt_len))
static inline void ovs_flow_tun_info_init(struct ovs_tunnel_info *tun_info, static inline void __ovs_flow_tun_info_init(struct ovs_tunnel_info *tun_info,
const struct iphdr *iph, __be32 saddr, __be32 daddr,
__be64 tun_id, __be16 tun_flags, u8 tos, u8 ttl,
struct geneve_opt *opts, __be16 tp_src,
u8 opts_len) __be16 tp_dst,
__be64 tun_id,
__be16 tun_flags,
const struct geneve_opt *opts,
u8 opts_len)
{ {
tun_info->tunnel.tun_id = tun_id; tun_info->tunnel.tun_id = tun_id;
tun_info->tunnel.ipv4_src = iph->saddr; tun_info->tunnel.ipv4_src = saddr;
tun_info->tunnel.ipv4_dst = iph->daddr; tun_info->tunnel.ipv4_dst = daddr;
tun_info->tunnel.ipv4_tos = iph->tos; tun_info->tunnel.ipv4_tos = tos;
tun_info->tunnel.ipv4_ttl = iph->ttl; tun_info->tunnel.ipv4_ttl = ttl;
tun_info->tunnel.tun_flags = tun_flags; tun_info->tunnel.tun_flags = tun_flags;
/* clear struct padding. */ /* For the tunnel types on the top of IPsec, the tp_src and tp_dst of
memset((unsigned char *)&tun_info->tunnel + OVS_TUNNEL_KEY_SIZE, 0, * the upper tunnel are used.
sizeof(tun_info->tunnel) - OVS_TUNNEL_KEY_SIZE); * E.g: GRE over IPSEC, the tp_src and tp_port are zero.
*/
tun_info->tunnel.tp_src = tp_src;
tun_info->tunnel.tp_dst = tp_dst;
/* Clear struct padding. */
if (sizeof(tun_info->tunnel) != OVS_TUNNEL_KEY_SIZE)
memset((unsigned char *)&tun_info->tunnel + OVS_TUNNEL_KEY_SIZE,
0, sizeof(tun_info->tunnel) - OVS_TUNNEL_KEY_SIZE);
tun_info->options = opts; tun_info->options = opts;
tun_info->options_len = opts_len; tun_info->options_len = opts_len;
} }
static inline void ovs_flow_tun_info_init(struct ovs_tunnel_info *tun_info,
const struct iphdr *iph,
__be16 tp_src,
__be16 tp_dst,
__be64 tun_id,
__be16 tun_flags,
const struct geneve_opt *opts,
u8 opts_len)
{
__ovs_flow_tun_info_init(tun_info, iph->saddr, iph->daddr,
iph->tos, iph->ttl,
tp_src, tp_dst,
tun_id, tun_flags,
opts, opts_len);
}
#define OVS_SW_FLOW_KEY_METADATA_SIZE \
(offsetof(struct sw_flow_key, recirc_id) + \
FIELD_SIZEOF(struct sw_flow_key, recirc_id))
struct sw_flow_key { struct sw_flow_key {
u8 tun_opts[255]; u8 tun_opts[255];
u8 tun_opts_len; u8 tun_opts_len;
...@@ -210,18 +244,19 @@ struct arp_eth_header { ...@@ -210,18 +244,19 @@ struct arp_eth_header {
} __packed; } __packed;
void ovs_flow_stats_update(struct sw_flow *, __be16 tcp_flags, void ovs_flow_stats_update(struct sw_flow *, __be16 tcp_flags,
struct sk_buff *); const struct sk_buff *);
void ovs_flow_stats_get(const struct sw_flow *, struct ovs_flow_stats *, void ovs_flow_stats_get(const struct sw_flow *, struct ovs_flow_stats *,
unsigned long *used, __be16 *tcp_flags); unsigned long *used, __be16 *tcp_flags);
void ovs_flow_stats_clear(struct sw_flow *); void ovs_flow_stats_clear(struct sw_flow *);
u64 ovs_flow_used_time(unsigned long flow_jiffies); u64 ovs_flow_used_time(unsigned long flow_jiffies);
int ovs_flow_key_update(struct sk_buff *skb, struct sw_flow_key *key); int ovs_flow_key_update(struct sk_buff *skb, struct sw_flow_key *key);
int ovs_flow_key_extract(struct ovs_tunnel_info *tun_info, struct sk_buff *skb, int ovs_flow_key_extract(const struct ovs_tunnel_info *tun_info,
struct sk_buff *skb,
struct sw_flow_key *key); struct sw_flow_key *key);
/* Extract key from packet coming from userspace. */ /* Extract key from packet coming from userspace. */
int ovs_flow_key_extract_userspace(const struct nlattr *attr, int ovs_flow_key_extract_userspace(const struct nlattr *attr,
struct sk_buff *skb, struct sk_buff *skb,
struct sw_flow_key *key); struct sw_flow_key *key, bool log);
#endif /* flow.h */ #endif /* flow.h */
This diff is collapsed.
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "flow.h" #include "flow.h"
size_t ovs_tun_key_attr_size(void);
size_t ovs_key_attr_size(void); size_t ovs_key_attr_size(void);
void ovs_match_init(struct sw_flow_match *match, void ovs_match_init(struct sw_flow_match *match,
...@@ -44,15 +45,17 @@ void ovs_match_init(struct sw_flow_match *match, ...@@ -44,15 +45,17 @@ void ovs_match_init(struct sw_flow_match *match,
int ovs_nla_put_flow(const struct sw_flow_key *, int ovs_nla_put_flow(const struct sw_flow_key *,
const struct sw_flow_key *, struct sk_buff *); const struct sw_flow_key *, struct sk_buff *);
int ovs_nla_get_flow_metadata(const struct nlattr *, struct sw_flow_key *); int ovs_nla_get_flow_metadata(const struct nlattr *, struct sw_flow_key *,
bool log);
int ovs_nla_get_match(struct sw_flow_match *match, int ovs_nla_get_match(struct sw_flow_match *, const struct nlattr *key,
const struct nlattr *, const struct nlattr *mask, bool log);
const struct nlattr *); int ovs_nla_put_egress_tunnel_key(struct sk_buff *,
const struct ovs_tunnel_info *);
int ovs_nla_copy_actions(const struct nlattr *attr, int ovs_nla_copy_actions(const struct nlattr *attr,
const struct sw_flow_key *key, const struct sw_flow_key *key,
struct sw_flow_actions **sfa); struct sw_flow_actions **sfa, bool log);
int ovs_nla_put_actions(const struct nlattr *attr, int ovs_nla_put_actions(const struct nlattr *attr,
int len, struct sk_buff *skb); int len, struct sk_buff *skb);
......
...@@ -107,7 +107,7 @@ struct sw_flow *ovs_flow_alloc(void) ...@@ -107,7 +107,7 @@ struct sw_flow *ovs_flow_alloc(void)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
int ovs_flow_tbl_count(struct flow_table *table) int ovs_flow_tbl_count(const struct flow_table *table)
{ {
return table->count; return table->count;
} }
...@@ -401,7 +401,7 @@ static bool flow_cmp_masked_key(const struct sw_flow *flow, ...@@ -401,7 +401,7 @@ static bool flow_cmp_masked_key(const struct sw_flow *flow,
} }
bool ovs_flow_cmp_unmasked_key(const struct sw_flow *flow, bool ovs_flow_cmp_unmasked_key(const struct sw_flow *flow,
struct sw_flow_match *match) const struct sw_flow_match *match)
{ {
struct sw_flow_key *key = match->key; struct sw_flow_key *key = match->key;
int key_start = flow_key_start(key); int key_start = flow_key_start(key);
...@@ -412,7 +412,7 @@ bool ovs_flow_cmp_unmasked_key(const struct sw_flow *flow, ...@@ -412,7 +412,7 @@ bool ovs_flow_cmp_unmasked_key(const struct sw_flow *flow,
static struct sw_flow *masked_flow_lookup(struct table_instance *ti, static struct sw_flow *masked_flow_lookup(struct table_instance *ti,
const struct sw_flow_key *unmasked, const struct sw_flow_key *unmasked,
struct sw_flow_mask *mask) const struct sw_flow_mask *mask)
{ {
struct sw_flow *flow; struct sw_flow *flow;
struct hlist_head *head; struct hlist_head *head;
...@@ -460,7 +460,7 @@ struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *tbl, ...@@ -460,7 +460,7 @@ struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *tbl,
} }
struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl, struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl,
struct sw_flow_match *match) const struct sw_flow_match *match)
{ {
struct table_instance *ti = rcu_dereference_ovsl(tbl->ti); struct table_instance *ti = rcu_dereference_ovsl(tbl->ti);
struct sw_flow_mask *mask; struct sw_flow_mask *mask;
...@@ -563,7 +563,7 @@ static struct sw_flow_mask *flow_mask_find(const struct flow_table *tbl, ...@@ -563,7 +563,7 @@ static struct sw_flow_mask *flow_mask_find(const struct flow_table *tbl,
/* Add 'mask' into the mask list, if it is not already there. */ /* Add 'mask' into the mask list, if it is not already there. */
static int flow_mask_insert(struct flow_table *tbl, struct sw_flow *flow, static int flow_mask_insert(struct flow_table *tbl, struct sw_flow *flow,
struct sw_flow_mask *new) const struct sw_flow_mask *new)
{ {
struct sw_flow_mask *mask; struct sw_flow_mask *mask;
mask = flow_mask_find(tbl, new); mask = flow_mask_find(tbl, new);
...@@ -586,7 +586,7 @@ static int flow_mask_insert(struct flow_table *tbl, struct sw_flow *flow, ...@@ -586,7 +586,7 @@ static int flow_mask_insert(struct flow_table *tbl, struct sw_flow *flow,
/* Must be called with OVS mutex held. */ /* Must be called with OVS mutex held. */
int ovs_flow_tbl_insert(struct flow_table *table, struct sw_flow *flow, int ovs_flow_tbl_insert(struct flow_table *table, struct sw_flow *flow,
struct sw_flow_mask *mask) const struct sw_flow_mask *mask)
{ {
struct table_instance *new_ti = NULL; struct table_instance *new_ti = NULL;
struct table_instance *ti; struct table_instance *ti;
......
...@@ -61,12 +61,12 @@ struct sw_flow *ovs_flow_alloc(void); ...@@ -61,12 +61,12 @@ struct sw_flow *ovs_flow_alloc(void);
void ovs_flow_free(struct sw_flow *, bool deferred); void ovs_flow_free(struct sw_flow *, bool deferred);
int ovs_flow_tbl_init(struct flow_table *); int ovs_flow_tbl_init(struct flow_table *);
int ovs_flow_tbl_count(struct flow_table *table); int ovs_flow_tbl_count(const struct flow_table *table);
void ovs_flow_tbl_destroy(struct flow_table *table); void ovs_flow_tbl_destroy(struct flow_table *table);
int ovs_flow_tbl_flush(struct flow_table *flow_table); int ovs_flow_tbl_flush(struct flow_table *flow_table);
int ovs_flow_tbl_insert(struct flow_table *table, struct sw_flow *flow, int ovs_flow_tbl_insert(struct flow_table *table, struct sw_flow *flow,
struct sw_flow_mask *mask); const struct sw_flow_mask *mask);
void ovs_flow_tbl_remove(struct flow_table *table, struct sw_flow *flow); void ovs_flow_tbl_remove(struct flow_table *table, struct sw_flow *flow);
int ovs_flow_tbl_num_masks(const struct flow_table *table); int ovs_flow_tbl_num_masks(const struct flow_table *table);
struct sw_flow *ovs_flow_tbl_dump_next(struct table_instance *table, struct sw_flow *ovs_flow_tbl_dump_next(struct table_instance *table,
...@@ -77,9 +77,9 @@ struct sw_flow *ovs_flow_tbl_lookup_stats(struct flow_table *, ...@@ -77,9 +77,9 @@ struct sw_flow *ovs_flow_tbl_lookup_stats(struct flow_table *,
struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *, struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *,
const struct sw_flow_key *); const struct sw_flow_key *);
struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl, struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl,
struct sw_flow_match *match); const struct sw_flow_match *match);
bool ovs_flow_cmp_unmasked_key(const struct sw_flow *flow, bool ovs_flow_cmp_unmasked_key(const struct sw_flow *flow,
struct sw_flow_match *match); const struct sw_flow_match *match);
void ovs_flow_mask_key(struct sw_flow_key *dst, const struct sw_flow_key *src, void ovs_flow_mask_key(struct sw_flow_key *dst, const struct sw_flow_key *src,
const struct sw_flow_mask *mask); const struct sw_flow_mask *mask);
......
...@@ -68,7 +68,7 @@ static void tunnel_id_to_vni(__be64 tun_id, __u8 *vni) ...@@ -68,7 +68,7 @@ static void tunnel_id_to_vni(__be64 tun_id, __u8 *vni)
} }
/* Convert 24 bit VNI to 64 bit tunnel ID. */ /* Convert 24 bit VNI to 64 bit tunnel ID. */
static __be64 vni_to_tunnel_id(__u8 *vni) static __be64 vni_to_tunnel_id(const __u8 *vni)
{ {
#ifdef __BIG_ENDIAN #ifdef __BIG_ENDIAN
return (vni[0] << 16) | (vni[1] << 8) | vni[2]; return (vni[0] << 16) | (vni[1] << 8) | vni[2];
...@@ -97,7 +97,9 @@ static void geneve_rcv(struct geneve_sock *gs, struct sk_buff *skb) ...@@ -97,7 +97,9 @@ static void geneve_rcv(struct geneve_sock *gs, struct sk_buff *skb)
key = vni_to_tunnel_id(geneveh->vni); key = vni_to_tunnel_id(geneveh->vni);
ovs_flow_tun_info_init(&tun_info, ip_hdr(skb), key, flags, ovs_flow_tun_info_init(&tun_info, ip_hdr(skb),
udp_hdr(skb)->source, udp_hdr(skb)->dest,
key, flags,
geneveh->options, opts_len); geneveh->options, opts_len);
ovs_vport_receive(vport, skb, &tun_info); ovs_vport_receive(vport, skb, &tun_info);
...@@ -228,6 +230,22 @@ static const char *geneve_get_name(const struct vport *vport) ...@@ -228,6 +230,22 @@ static const char *geneve_get_name(const struct vport *vport)
return geneve_port->name; return geneve_port->name;
} }
static int geneve_get_egress_tun_info(struct vport *vport, struct sk_buff *skb,
struct ovs_tunnel_info *egress_tun_info)
{
struct geneve_port *geneve_port = geneve_vport(vport);
struct net *net = ovs_dp_get_net(vport->dp);
__be16 dport = inet_sk(geneve_port->gs->sock->sk)->inet_sport;
__be16 sport = udp_flow_src_port(net, skb, 1, USHRT_MAX, true);
/* Get tp_src and tp_dst, refert to geneve_build_header().
*/
return ovs_tunnel_get_egress_info(egress_tun_info,
ovs_dp_get_net(vport->dp),
OVS_CB(skb)->egress_tun_info,
IPPROTO_UDP, skb->mark, sport, dport);
}
static struct vport_ops ovs_geneve_vport_ops = { static struct vport_ops ovs_geneve_vport_ops = {
.type = OVS_VPORT_TYPE_GENEVE, .type = OVS_VPORT_TYPE_GENEVE,
.create = geneve_tnl_create, .create = geneve_tnl_create,
...@@ -236,6 +254,7 @@ static struct vport_ops ovs_geneve_vport_ops = { ...@@ -236,6 +254,7 @@ static struct vport_ops ovs_geneve_vport_ops = {
.get_options = geneve_get_options, .get_options = geneve_get_options,
.send = geneve_tnl_send, .send = geneve_tnl_send,
.owner = THIS_MODULE, .owner = THIS_MODULE,
.get_egress_tun_info = geneve_get_egress_tun_info,
}; };
static int __init ovs_geneve_tnl_init(void) static int __init ovs_geneve_tnl_init(void)
......
...@@ -108,7 +108,7 @@ static int gre_rcv(struct sk_buff *skb, ...@@ -108,7 +108,7 @@ static int gre_rcv(struct sk_buff *skb,
return PACKET_REJECT; return PACKET_REJECT;
key = key_to_tunnel_id(tpi->key, tpi->seq); key = key_to_tunnel_id(tpi->key, tpi->seq);
ovs_flow_tun_info_init(&tun_info, ip_hdr(skb), key, ovs_flow_tun_info_init(&tun_info, ip_hdr(skb), 0, 0, key,
filter_tnl_flags(tpi->flags), NULL, 0); filter_tnl_flags(tpi->flags), NULL, 0);
ovs_vport_receive(vport, skb, &tun_info); ovs_vport_receive(vport, skb, &tun_info);
...@@ -284,12 +284,22 @@ static void gre_tnl_destroy(struct vport *vport) ...@@ -284,12 +284,22 @@ static void gre_tnl_destroy(struct vport *vport)
gre_exit(); gre_exit();
} }
static int gre_get_egress_tun_info(struct vport *vport, struct sk_buff *skb,
struct ovs_tunnel_info *egress_tun_info)
{
return ovs_tunnel_get_egress_info(egress_tun_info,
ovs_dp_get_net(vport->dp),
OVS_CB(skb)->egress_tun_info,
IPPROTO_GRE, skb->mark, 0, 0);
}
static struct vport_ops ovs_gre_vport_ops = { static struct vport_ops ovs_gre_vport_ops = {
.type = OVS_VPORT_TYPE_GRE, .type = OVS_VPORT_TYPE_GRE,
.create = gre_create, .create = gre_create,
.destroy = gre_tnl_destroy, .destroy = gre_tnl_destroy,
.get_name = gre_get_name, .get_name = gre_get_name,
.send = gre_tnl_send, .send = gre_tnl_send,
.get_egress_tun_info = gre_get_egress_tun_info,
.owner = THIS_MODULE, .owner = THIS_MODULE,
}; };
......
...@@ -77,7 +77,7 @@ static rx_handler_result_t netdev_frame_hook(struct sk_buff **pskb) ...@@ -77,7 +77,7 @@ static rx_handler_result_t netdev_frame_hook(struct sk_buff **pskb)
return RX_HANDLER_CONSUMED; return RX_HANDLER_CONSUMED;
} }
static struct net_device *get_dpdev(struct datapath *dp) static struct net_device *get_dpdev(const struct datapath *dp)
{ {
struct vport *local; struct vport *local;
......
...@@ -69,7 +69,9 @@ static void vxlan_rcv(struct vxlan_sock *vs, struct sk_buff *skb, __be32 vx_vni) ...@@ -69,7 +69,9 @@ static void vxlan_rcv(struct vxlan_sock *vs, struct sk_buff *skb, __be32 vx_vni)
/* Save outer tunnel values */ /* Save outer tunnel values */
iph = ip_hdr(skb); iph = ip_hdr(skb);
key = cpu_to_be64(ntohl(vx_vni) >> 8); key = cpu_to_be64(ntohl(vx_vni) >> 8);
ovs_flow_tun_info_init(&tun_info, iph, key, TUNNEL_KEY, NULL, 0); ovs_flow_tun_info_init(&tun_info, iph,
udp_hdr(skb)->source, udp_hdr(skb)->dest,
key, TUNNEL_KEY, NULL, 0);
ovs_vport_receive(vport, skb, &tun_info); ovs_vport_receive(vport, skb, &tun_info);
} }
...@@ -189,6 +191,25 @@ static int vxlan_tnl_send(struct vport *vport, struct sk_buff *skb) ...@@ -189,6 +191,25 @@ static int vxlan_tnl_send(struct vport *vport, struct sk_buff *skb)
return err; return err;
} }
static int vxlan_get_egress_tun_info(struct vport *vport, struct sk_buff *skb,
struct ovs_tunnel_info *egress_tun_info)
{
struct net *net = ovs_dp_get_net(vport->dp);
struct vxlan_port *vxlan_port = vxlan_vport(vport);
__be16 dst_port = inet_sk(vxlan_port->vs->sock->sk)->inet_sport;
__be16 src_port;
int port_min;
int port_max;
inet_get_local_port_range(net, &port_min, &port_max);
src_port = udp_flow_src_port(net, skb, 0, 0, true);
return ovs_tunnel_get_egress_info(egress_tun_info, net,
OVS_CB(skb)->egress_tun_info,
IPPROTO_UDP, skb->mark,
src_port, dst_port);
}
static const char *vxlan_get_name(const struct vport *vport) static const char *vxlan_get_name(const struct vport *vport)
{ {
struct vxlan_port *vxlan_port = vxlan_vport(vport); struct vxlan_port *vxlan_port = vxlan_vport(vport);
...@@ -202,6 +223,7 @@ static struct vport_ops ovs_vxlan_vport_ops = { ...@@ -202,6 +223,7 @@ static struct vport_ops ovs_vxlan_vport_ops = {
.get_name = vxlan_get_name, .get_name = vxlan_get_name,
.get_options = vxlan_get_options, .get_options = vxlan_get_options,
.send = vxlan_tnl_send, .send = vxlan_tnl_send,
.get_egress_tun_info = vxlan_get_egress_tun_info,
.owner = THIS_MODULE, .owner = THIS_MODULE,
}; };
......
...@@ -68,7 +68,7 @@ void ovs_vport_exit(void) ...@@ -68,7 +68,7 @@ void ovs_vport_exit(void)
kfree(dev_table); kfree(dev_table);
} }
static struct hlist_head *hash_bucket(struct net *net, const char *name) static struct hlist_head *hash_bucket(const struct net *net, const char *name)
{ {
unsigned int hash = jhash(name, strlen(name), (unsigned long) net); unsigned int hash = jhash(name, strlen(name), (unsigned long) net);
return &dev_table[hash & (VPORT_HASH_BUCKETS - 1)]; return &dev_table[hash & (VPORT_HASH_BUCKETS - 1)];
...@@ -90,7 +90,7 @@ int ovs_vport_ops_register(struct vport_ops *ops) ...@@ -90,7 +90,7 @@ int ovs_vport_ops_register(struct vport_ops *ops)
ovs_unlock(); ovs_unlock();
return err; return err;
} }
EXPORT_SYMBOL(ovs_vport_ops_register); EXPORT_SYMBOL_GPL(ovs_vport_ops_register);
void ovs_vport_ops_unregister(struct vport_ops *ops) void ovs_vport_ops_unregister(struct vport_ops *ops)
{ {
...@@ -98,7 +98,7 @@ void ovs_vport_ops_unregister(struct vport_ops *ops) ...@@ -98,7 +98,7 @@ void ovs_vport_ops_unregister(struct vport_ops *ops)
list_del(&ops->list); list_del(&ops->list);
ovs_unlock(); ovs_unlock();
} }
EXPORT_SYMBOL(ovs_vport_ops_unregister); EXPORT_SYMBOL_GPL(ovs_vport_ops_unregister);
/** /**
* ovs_vport_locate - find a port that has already been created * ovs_vport_locate - find a port that has already been created
...@@ -107,7 +107,7 @@ EXPORT_SYMBOL(ovs_vport_ops_unregister); ...@@ -107,7 +107,7 @@ EXPORT_SYMBOL(ovs_vport_ops_unregister);
* *
* Must be called with ovs or RCU read lock. * Must be called with ovs or RCU read lock.
*/ */
struct vport *ovs_vport_locate(struct net *net, const char *name) struct vport *ovs_vport_locate(const struct net *net, const char *name)
{ {
struct hlist_head *bucket = hash_bucket(net, name); struct hlist_head *bucket = hash_bucket(net, name);
struct vport *vport; struct vport *vport;
...@@ -165,7 +165,7 @@ struct vport *ovs_vport_alloc(int priv_size, const struct vport_ops *ops, ...@@ -165,7 +165,7 @@ struct vport *ovs_vport_alloc(int priv_size, const struct vport_ops *ops,
return vport; return vport;
} }
EXPORT_SYMBOL(ovs_vport_alloc); EXPORT_SYMBOL_GPL(ovs_vport_alloc);
/** /**
* ovs_vport_free - uninitialize and free vport * ovs_vport_free - uninitialize and free vport
...@@ -186,7 +186,7 @@ void ovs_vport_free(struct vport *vport) ...@@ -186,7 +186,7 @@ void ovs_vport_free(struct vport *vport)
free_percpu(vport->percpu_stats); free_percpu(vport->percpu_stats);
kfree(vport); kfree(vport);
} }
EXPORT_SYMBOL(ovs_vport_free); EXPORT_SYMBOL_GPL(ovs_vport_free);
static struct vport_ops *ovs_vport_lookup(const struct vport_parms *parms) static struct vport_ops *ovs_vport_lookup(const struct vport_parms *parms)
{ {
...@@ -380,7 +380,7 @@ int ovs_vport_get_options(const struct vport *vport, struct sk_buff *skb) ...@@ -380,7 +380,7 @@ int ovs_vport_get_options(const struct vport *vport, struct sk_buff *skb)
* *
* Must be called with ovs_mutex. * Must be called with ovs_mutex.
*/ */
int ovs_vport_set_upcall_portids(struct vport *vport, struct nlattr *ids) int ovs_vport_set_upcall_portids(struct vport *vport, const struct nlattr *ids)
{ {
struct vport_portids *old, *vport_portids; struct vport_portids *old, *vport_portids;
...@@ -471,7 +471,7 @@ u32 ovs_vport_find_upcall_portid(const struct vport *vport, struct sk_buff *skb) ...@@ -471,7 +471,7 @@ u32 ovs_vport_find_upcall_portid(const struct vport *vport, struct sk_buff *skb)
* skb->data should point to the Ethernet header. * skb->data should point to the Ethernet header.
*/ */
void ovs_vport_receive(struct vport *vport, struct sk_buff *skb, void ovs_vport_receive(struct vport *vport, struct sk_buff *skb,
struct ovs_tunnel_info *tun_info) const struct ovs_tunnel_info *tun_info)
{ {
struct pcpu_sw_netstats *stats; struct pcpu_sw_netstats *stats;
struct sw_flow_key key; struct sw_flow_key key;
...@@ -493,7 +493,7 @@ void ovs_vport_receive(struct vport *vport, struct sk_buff *skb, ...@@ -493,7 +493,7 @@ void ovs_vport_receive(struct vport *vport, struct sk_buff *skb,
} }
ovs_dp_process_packet(skb, &key); ovs_dp_process_packet(skb, &key);
} }
EXPORT_SYMBOL(ovs_vport_receive); EXPORT_SYMBOL_GPL(ovs_vport_receive);
/** /**
* ovs_vport_send - send a packet on a device * ovs_vport_send - send a packet on a device
...@@ -572,4 +572,65 @@ void ovs_vport_deferred_free(struct vport *vport) ...@@ -572,4 +572,65 @@ void ovs_vport_deferred_free(struct vport *vport)
call_rcu(&vport->rcu, free_vport_rcu); call_rcu(&vport->rcu, free_vport_rcu);
} }
EXPORT_SYMBOL(ovs_vport_deferred_free); EXPORT_SYMBOL_GPL(ovs_vport_deferred_free);
int ovs_tunnel_get_egress_info(struct ovs_tunnel_info *egress_tun_info,
struct net *net,
const struct ovs_tunnel_info *tun_info,
u8 ipproto,
u32 skb_mark,
__be16 tp_src,
__be16 tp_dst)
{
const struct ovs_key_ipv4_tunnel *tun_key;
struct rtable *rt;
struct flowi4 fl;
if (unlikely(!tun_info))
return -EINVAL;
tun_key = &tun_info->tunnel;
/* Route lookup to get srouce IP address.
* The process may need to be changed if the corresponding process
* in vports ops changed.
*/
memset(&fl, 0, sizeof(fl));
fl.daddr = tun_key->ipv4_dst;
fl.saddr = tun_key->ipv4_src;
fl.flowi4_tos = RT_TOS(tun_key->ipv4_tos);
fl.flowi4_mark = skb_mark;
fl.flowi4_proto = IPPROTO_GRE;
rt = ip_route_output_key(net, &fl);
if (IS_ERR(rt))
return PTR_ERR(rt);
ip_rt_put(rt);
/* Generate egress_tun_info based on tun_info,
* saddr, tp_src and tp_dst
*/
__ovs_flow_tun_info_init(egress_tun_info,
fl.saddr, tun_key->ipv4_dst,
tun_key->ipv4_tos,
tun_key->ipv4_ttl,
tp_src, tp_dst,
tun_key->tun_id,
tun_key->tun_flags,
tun_info->options,
tun_info->options_len);
return 0;
}
EXPORT_SYMBOL_GPL(ovs_tunnel_get_egress_info);
int ovs_vport_get_egress_tun_info(struct vport *vport, struct sk_buff *skb,
struct ovs_tunnel_info *info)
{
/* get_egress_tun_info() is only implemented on tunnel ports. */
if (unlikely(!vport->ops->get_egress_tun_info))
return -EINVAL;
return vport->ops->get_egress_tun_info(vport, skb, info);
}
...@@ -45,19 +45,29 @@ void ovs_vport_exit(void); ...@@ -45,19 +45,29 @@ void ovs_vport_exit(void);
struct vport *ovs_vport_add(const struct vport_parms *); struct vport *ovs_vport_add(const struct vport_parms *);
void ovs_vport_del(struct vport *); void ovs_vport_del(struct vport *);
struct vport *ovs_vport_locate(struct net *net, const char *name); struct vport *ovs_vport_locate(const struct net *net, const char *name);
void ovs_vport_get_stats(struct vport *, struct ovs_vport_stats *); void ovs_vport_get_stats(struct vport *, struct ovs_vport_stats *);
int ovs_vport_set_options(struct vport *, struct nlattr *options); int ovs_vport_set_options(struct vport *, struct nlattr *options);
int ovs_vport_get_options(const struct vport *, struct sk_buff *); int ovs_vport_get_options(const struct vport *, struct sk_buff *);
int ovs_vport_set_upcall_portids(struct vport *, struct nlattr *pids); int ovs_vport_set_upcall_portids(struct vport *, const struct nlattr *pids);
int ovs_vport_get_upcall_portids(const struct vport *, struct sk_buff *); int ovs_vport_get_upcall_portids(const struct vport *, struct sk_buff *);
u32 ovs_vport_find_upcall_portid(const struct vport *, struct sk_buff *); u32 ovs_vport_find_upcall_portid(const struct vport *, struct sk_buff *);
int ovs_vport_send(struct vport *, struct sk_buff *); int ovs_vport_send(struct vport *, struct sk_buff *);
int ovs_tunnel_get_egress_info(struct ovs_tunnel_info *egress_tun_info,
struct net *net,
const struct ovs_tunnel_info *tun_info,
u8 ipproto,
u32 skb_mark,
__be16 tp_src,
__be16 tp_dst);
int ovs_vport_get_egress_tun_info(struct vport *vport, struct sk_buff *skb,
struct ovs_tunnel_info *info);
/* The following definitions are for implementers of vport devices: */ /* The following definitions are for implementers of vport devices: */
struct vport_err_stats { struct vport_err_stats {
...@@ -146,6 +156,8 @@ struct vport_parms { ...@@ -146,6 +156,8 @@ struct vport_parms {
* @get_name: Get the device's name. * @get_name: Get the device's name.
* @send: Send a packet on the device. Returns the length of the packet sent, * @send: Send a packet on the device. Returns the length of the packet sent,
* zero for dropped packets or negative for error. * zero for dropped packets or negative for error.
* @get_egress_tun_info: Get the egress tunnel 5-tuple and other info for
* a packet.
*/ */
struct vport_ops { struct vport_ops {
enum ovs_vport_type type; enum ovs_vport_type type;
...@@ -161,6 +173,8 @@ struct vport_ops { ...@@ -161,6 +173,8 @@ struct vport_ops {
const char *(*get_name)(const struct vport *); const char *(*get_name)(const struct vport *);
int (*send)(struct vport *, struct sk_buff *); int (*send)(struct vport *, struct sk_buff *);
int (*get_egress_tun_info)(struct vport *, struct sk_buff *,
struct ovs_tunnel_info *);
struct module *owner; struct module *owner;
struct list_head list; struct list_head list;
...@@ -210,7 +224,7 @@ static inline struct vport *vport_from_priv(void *priv) ...@@ -210,7 +224,7 @@ static inline struct vport *vport_from_priv(void *priv)
} }
void ovs_vport_receive(struct vport *, struct sk_buff *, void ovs_vport_receive(struct vport *, struct sk_buff *,
struct ovs_tunnel_info *); const struct ovs_tunnel_info *);
static inline void ovs_skb_postpush_rcsum(struct sk_buff *skb, static inline void ovs_skb_postpush_rcsum(struct sk_buff *skb,
const void *start, unsigned int len) const void *start, unsigned int len)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment