Commit 00a93bab authored by Jiri Benc's avatar Jiri Benc Committed by David S. Miller

openvswitch: add tunnel protocol to sw_flow_key

Store tunnel protocol (AF_INET or AF_INET6) in sw_flow_key. This field now
also acts as an indicator whether the flow contains tunnel data (this was
previously indicated by tun_key.u.ipv4.dst being set but with IPv6 addresses
in an union with IPv4 ones this won't work anymore).

The new field was added to a hole in sw_flow_key.
Signed-off-by: default avatarJiri Benc <jbenc@redhat.com>
Acked-by: default avatarPravin B Shelar <pshelar@nicira.com>
Acked-by: default avatarThomas Graf <tgraf@suug.ch>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4917a154
...@@ -698,8 +698,7 @@ int ovs_flow_key_extract(const struct ip_tunnel_info *tun_info, ...@@ -698,8 +698,7 @@ int ovs_flow_key_extract(const struct ip_tunnel_info *tun_info,
{ {
/* Extract metadata from packet. */ /* Extract metadata from packet. */
if (tun_info) { if (tun_info) {
if (ip_tunnel_info_af(tun_info) != AF_INET) key->tun_proto = ip_tunnel_info_af(tun_info);
return -EINVAL;
memcpy(&key->tun_key, &tun_info->key, sizeof(key->tun_key)); memcpy(&key->tun_key, &tun_info->key, sizeof(key->tun_key));
if (tun_info->options_len) { if (tun_info->options_len) {
...@@ -714,6 +713,7 @@ int ovs_flow_key_extract(const struct ip_tunnel_info *tun_info, ...@@ -714,6 +713,7 @@ int ovs_flow_key_extract(const struct ip_tunnel_info *tun_info,
key->tun_opts_len = 0; key->tun_opts_len = 0;
} }
} else { } else {
key->tun_proto = 0;
key->tun_opts_len = 0; key->tun_opts_len = 0;
memset(&key->tun_key, 0, sizeof(key->tun_key)); memset(&key->tun_key, 0, sizeof(key->tun_key));
} }
......
...@@ -63,6 +63,7 @@ struct sw_flow_key { ...@@ -63,6 +63,7 @@ struct sw_flow_key {
u32 skb_mark; /* SKB mark. */ u32 skb_mark; /* SKB mark. */
u16 in_port; /* Input switch port (or DP_MAX_PORTS). */ u16 in_port; /* Input switch port (or DP_MAX_PORTS). */
} __packed phy; /* Safe when right after 'tun_key'. */ } __packed phy; /* Safe when right after 'tun_key'. */
u8 tun_proto; /* Protocol of encapsulating tunnel. */
u32 ovs_flow_hash; /* Datapath computed hash value. */ u32 ovs_flow_hash; /* Datapath computed hash value. */
u32 recirc_id; /* Recirculation ID. */ u32 recirc_id; /* Recirculation ID. */
struct { struct {
......
...@@ -643,6 +643,10 @@ static int ipv4_tun_from_nlattr(const struct nlattr *attr, ...@@ -643,6 +643,10 @@ static int ipv4_tun_from_nlattr(const struct nlattr *attr,
} }
SW_FLOW_KEY_PUT(match, tun_key.tun_flags, tun_flags, is_mask); SW_FLOW_KEY_PUT(match, tun_key.tun_flags, tun_flags, is_mask);
if (is_mask)
SW_FLOW_KEY_MEMSET_FIELD(match, tun_proto, 0xff, true);
else
SW_FLOW_KEY_PUT(match, tun_proto, AF_INET, false);
if (rem > 0) { if (rem > 0) {
OVS_NLERR(log, "IPv4 tunnel attribute has %d unknown bytes.", OVS_NLERR(log, "IPv4 tunnel attribute has %d unknown bytes.",
...@@ -1194,7 +1198,7 @@ int ovs_nla_get_match(struct net *net, struct sw_flow_match *match, ...@@ -1194,7 +1198,7 @@ int ovs_nla_get_match(struct net *net, struct sw_flow_match *match,
/* The userspace does not send tunnel attributes that /* The userspace does not send tunnel attributes that
* are 0, but we should not wildcard them nonetheless. * are 0, but we should not wildcard them nonetheless.
*/ */
if (match->key->tun_key.u.ipv4.dst) if (match->key->tun_proto)
SW_FLOW_KEY_MEMSET_FIELD(match, tun_key, SW_FLOW_KEY_MEMSET_FIELD(match, tun_key,
0xff, true); 0xff, true);
...@@ -1367,7 +1371,7 @@ static int __ovs_nla_put_key(const struct sw_flow_key *swkey, ...@@ -1367,7 +1371,7 @@ static int __ovs_nla_put_key(const struct sw_flow_key *swkey,
if (nla_put_u32(skb, OVS_KEY_ATTR_PRIORITY, output->phy.priority)) if (nla_put_u32(skb, OVS_KEY_ATTR_PRIORITY, output->phy.priority))
goto nla_put_failure; goto nla_put_failure;
if ((swkey->tun_key.u.ipv4.dst || is_mask)) { if ((swkey->tun_proto || is_mask)) {
const void *opts = NULL; const void *opts = NULL;
if (output->tun_key.tun_flags & TUNNEL_OPTIONS_PRESENT) if (output->tun_key.tun_flags & TUNNEL_OPTIONS_PRESENT)
...@@ -1913,6 +1917,8 @@ static int validate_and_copy_set_tun(const struct nlattr *attr, ...@@ -1913,6 +1917,8 @@ static int validate_and_copy_set_tun(const struct nlattr *attr,
tun_info = &tun_dst->u.tun_info; tun_info = &tun_dst->u.tun_info;
tun_info->mode = IP_TUNNEL_INFO_TX; tun_info->mode = IP_TUNNEL_INFO_TX;
if (key.tun_proto == AF_INET6)
tun_info->mode |= IP_TUNNEL_INFO_IPV6;
tun_info->key = key.tun_key; tun_info->key = key.tun_key;
/* We need to store the options in the action itself since /* We need to store the options in the action itself since
......
...@@ -427,7 +427,7 @@ static u32 flow_hash(const struct sw_flow_key *key, ...@@ -427,7 +427,7 @@ static u32 flow_hash(const struct sw_flow_key *key,
static int flow_key_start(const struct sw_flow_key *key) static int flow_key_start(const struct sw_flow_key *key)
{ {
if (key->tun_key.u.ipv4.dst) if (key->tun_proto)
return 0; return 0;
else else
return rounddown(offsetof(struct sw_flow_key, phy), return rounddown(offsetof(struct sw_flow_key, phy),
......
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