Skip to content

Commit fc1372f

Browse files
williamtudavem330
authored andcommitted
openvswitch: add erspan version I and II support
The patch adds support for openvswitch to configure erspan v1 and v2. The OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS attr is added to uapi as a binary blob to support all ERSPAN v1 and v2's fields. Note that Previous commit "openvswitch: Add erspan tunnel support." was reverted since it does not design properly. Signed-off-by: William Tu <[email protected]> Acked-by: Pravin B Shelar <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d350a82 commit fc1372f

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

include/uapi/linux/openvswitch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ enum ovs_tunnel_key_attr {
363363
OVS_TUNNEL_KEY_ATTR_IPV6_SRC, /* struct in6_addr src IPv6 address. */
364364
OVS_TUNNEL_KEY_ATTR_IPV6_DST, /* struct in6_addr dst IPv6 address. */
365365
OVS_TUNNEL_KEY_ATTR_PAD,
366+
OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS, /* struct erspan_metadata */
366367
__OVS_TUNNEL_KEY_ATTR_MAX
367368
};
368369

net/openvswitch/flow_netlink.c

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include <net/mpls.h>
5050
#include <net/vxlan.h>
5151
#include <net/tun_proto.h>
52+
#include <net/erspan.h>
5253

5354
#include "flow_netlink.h"
5455

@@ -329,7 +330,8 @@ size_t ovs_tun_key_attr_size(void)
329330
+ nla_total_size(0) /* OVS_TUNNEL_KEY_ATTR_CSUM */
330331
+ nla_total_size(0) /* OVS_TUNNEL_KEY_ATTR_OAM */
331332
+ nla_total_size(256) /* OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS */
332-
/* OVS_TUNNEL_KEY_ATTR_VXLAN_OPTS is mutually exclusive with
333+
/* OVS_TUNNEL_KEY_ATTR_VXLAN_OPTS and
334+
* OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS is mutually exclusive with
333335
* OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS and covered by it.
334336
*/
335337
+ nla_total_size(2) /* OVS_TUNNEL_KEY_ATTR_TP_SRC */
@@ -400,6 +402,7 @@ static const struct ovs_len_tbl ovs_tunnel_key_lens[OVS_TUNNEL_KEY_ATTR_MAX + 1]
400402
.next = ovs_vxlan_ext_key_lens },
401403
[OVS_TUNNEL_KEY_ATTR_IPV6_SRC] = { .len = sizeof(struct in6_addr) },
402404
[OVS_TUNNEL_KEY_ATTR_IPV6_DST] = { .len = sizeof(struct in6_addr) },
405+
[OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS] = { .len = OVS_ATTR_VARIABLE },
403406
};
404407

405408
static const struct ovs_len_tbl
@@ -631,6 +634,33 @@ static int vxlan_tun_opt_from_nlattr(const struct nlattr *attr,
631634
return 0;
632635
}
633636

637+
static int erspan_tun_opt_from_nlattr(const struct nlattr *a,
638+
struct sw_flow_match *match, bool is_mask,
639+
bool log)
640+
{
641+
unsigned long opt_key_offset;
642+
643+
BUILD_BUG_ON(sizeof(struct erspan_metadata) >
644+
sizeof(match->key->tun_opts));
645+
646+
if (nla_len(a) > sizeof(match->key->tun_opts)) {
647+
OVS_NLERR(log, "ERSPAN option length err (len %d, max %zu).",
648+
nla_len(a), sizeof(match->key->tun_opts));
649+
return -EINVAL;
650+
}
651+
652+
if (!is_mask)
653+
SW_FLOW_KEY_PUT(match, tun_opts_len,
654+
sizeof(struct erspan_metadata), false);
655+
else
656+
SW_FLOW_KEY_PUT(match, tun_opts_len, 0xff, true);
657+
658+
opt_key_offset = TUN_METADATA_OFFSET(nla_len(a));
659+
SW_FLOW_KEY_MEMCPY_OFFSET(match, opt_key_offset, nla_data(a),
660+
nla_len(a), is_mask);
661+
return 0;
662+
}
663+
634664
static int ip_tun_from_nlattr(const struct nlattr *attr,
635665
struct sw_flow_match *match, bool is_mask,
636666
bool log)
@@ -738,6 +768,20 @@ static int ip_tun_from_nlattr(const struct nlattr *attr,
738768
break;
739769
case OVS_TUNNEL_KEY_ATTR_PAD:
740770
break;
771+
case OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS:
772+
if (opts_type) {
773+
OVS_NLERR(log, "Multiple metadata blocks provided");
774+
return -EINVAL;
775+
}
776+
777+
err = erspan_tun_opt_from_nlattr(a, match, is_mask,
778+
log);
779+
if (err)
780+
return err;
781+
782+
tun_flags |= TUNNEL_ERSPAN_OPT;
783+
opts_type = type;
784+
break;
741785
default:
742786
OVS_NLERR(log, "Unknown IP tunnel attribute %d",
743787
type);
@@ -862,6 +906,10 @@ static int __ip_tun_to_nlattr(struct sk_buff *skb,
862906
else if (output->tun_flags & TUNNEL_VXLAN_OPT &&
863907
vxlan_opt_to_nlattr(skb, tun_opts, swkey_tun_opts_len))
864908
return -EMSGSIZE;
909+
else if (output->tun_flags & TUNNEL_ERSPAN_OPT &&
910+
nla_put(skb, OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS,
911+
swkey_tun_opts_len, tun_opts))
912+
return -EMSGSIZE;
865913
}
866914

867915
return 0;
@@ -2486,6 +2534,8 @@ static int validate_and_copy_set_tun(const struct nlattr *attr,
24862534
break;
24872535
case OVS_TUNNEL_KEY_ATTR_VXLAN_OPTS:
24882536
break;
2537+
case OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS:
2538+
break;
24892539
}
24902540
}
24912541

0 commit comments

Comments
 (0)