Skip to content

Commit 00a93ba

Browse files
Jiri Bencdavem330
authored andcommitted
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: Jiri Benc <jbenc@redhat.com> Acked-by: Pravin B Shelar <pshelar@nicira.com> Acked-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 4917a15 commit 00a93ba

4 files changed

Lines changed: 12 additions & 5 deletions

File tree

‎net/openvswitch/flow.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,8 +698,7 @@ int ovs_flow_key_extract(const struct ip_tunnel_info *tun_info,
698698
{
699699
/* Extract metadata from packet. */
700700
if (tun_info) {
701-
if (ip_tunnel_info_af(tun_info) != AF_INET)
702-
return -EINVAL;
701+
key->tun_proto = ip_tunnel_info_af(tun_info);
703702
memcpy(&key->tun_key, &tun_info->key, sizeof(key->tun_key));
704703

705704
if (tun_info->options_len) {
@@ -714,6 +713,7 @@ int ovs_flow_key_extract(const struct ip_tunnel_info *tun_info,
714713
key->tun_opts_len = 0;
715714
}
716715
} else {
716+
key->tun_proto = 0;
717717
key->tun_opts_len = 0;
718718
memset(&key->tun_key, 0, sizeof(key->tun_key));
719719
}

‎net/openvswitch/flow.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ struct sw_flow_key {
6363
u32 skb_mark; /* SKB mark. */
6464
u16 in_port; /* Input switch port (or DP_MAX_PORTS). */
6565
} __packed phy; /* Safe when right after 'tun_key'. */
66+
u8 tun_proto; /* Protocol of encapsulating tunnel. */
6667
u32 ovs_flow_hash; /* Datapath computed hash value. */
6768
u32 recirc_id; /* Recirculation ID. */
6869
struct {

‎net/openvswitch/flow_netlink.c‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,10 @@ static int ipv4_tun_from_nlattr(const struct nlattr *attr,
643643
}
644644

645645
SW_FLOW_KEY_PUT(match, tun_key.tun_flags, tun_flags, is_mask);
646+
if (is_mask)
647+
SW_FLOW_KEY_MEMSET_FIELD(match, tun_proto, 0xff, true);
648+
else
649+
SW_FLOW_KEY_PUT(match, tun_proto, AF_INET, false);
646650

647651
if (rem > 0) {
648652
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,
11941198
/* The userspace does not send tunnel attributes that
11951199
* are 0, but we should not wildcard them nonetheless.
11961200
*/
1197-
if (match->key->tun_key.u.ipv4.dst)
1201+
if (match->key->tun_proto)
11981202
SW_FLOW_KEY_MEMSET_FIELD(match, tun_key,
11991203
0xff, true);
12001204

@@ -1367,7 +1371,7 @@ static int __ovs_nla_put_key(const struct sw_flow_key *swkey,
13671371
if (nla_put_u32(skb, OVS_KEY_ATTR_PRIORITY, output->phy.priority))
13681372
goto nla_put_failure;
13691373

1370-
if ((swkey->tun_key.u.ipv4.dst || is_mask)) {
1374+
if ((swkey->tun_proto || is_mask)) {
13711375
const void *opts = NULL;
13721376

13731377
if (output->tun_key.tun_flags & TUNNEL_OPTIONS_PRESENT)
@@ -1913,6 +1917,8 @@ static int validate_and_copy_set_tun(const struct nlattr *attr,
19131917

19141918
tun_info = &tun_dst->u.tun_info;
19151919
tun_info->mode = IP_TUNNEL_INFO_TX;
1920+
if (key.tun_proto == AF_INET6)
1921+
tun_info->mode |= IP_TUNNEL_INFO_IPV6;
19161922
tun_info->key = key.tun_key;
19171923

19181924
/* We need to store the options in the action itself since

‎net/openvswitch/flow_table.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ static u32 flow_hash(const struct sw_flow_key *key,
427427

428428
static int flow_key_start(const struct sw_flow_key *key)
429429
{
430-
if (key->tun_key.u.ipv4.dst)
430+
if (key->tun_proto)
431431
return 0;
432432
else
433433
return rounddown(offsetof(struct sw_flow_key, phy),

0 commit comments

Comments
 (0)