Commit f8a23d84 authored by David S. Miller's avatar David S. Miller

Merge branch 'net-erspan-add-support-for-openvswitch'

William Tu says:

====================
net: erspan: add support for openvswitch

The first patch refactors the erspan header definitions.
Originally, the erspan fields are defined as a group into a __be16 field,
and use mask and offset to access each field.  This is more costly due to
calling ntohs/htons and error-prone.  The first patch changes it to use
bitfields.  The second patch creates erspan.h in UAPI and move the definition
'struct erspan_metadata' to it for later openvswitch to use.  The final patch
introduces the new OVS tunnel key attribute, OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS,
to program both v1 and v2 erspan tunnel for openvswitch.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents b89d06ce fc1372f8
...@@ -46,6 +46,8 @@ ...@@ -46,6 +46,8 @@
* GRE proto ERSPAN type II = 0x88BE, type III = 0x22EB * GRE proto ERSPAN type II = 0x88BE, type III = 0x22EB
*/ */
#include <uapi/linux/erspan.h>
#define ERSPAN_VERSION 0x1 /* ERSPAN type II */ #define ERSPAN_VERSION 0x1 /* ERSPAN type II */
#define VER_MASK 0xf000 #define VER_MASK 0xf000
#define VLAN_MASK 0x0fff #define VLAN_MASK 0x0fff
...@@ -65,17 +67,8 @@ ...@@ -65,17 +67,8 @@
#define GRA_MASK 0x0006 #define GRA_MASK 0x0006
#define O_MASK 0x0001 #define O_MASK 0x0001
/* ERSPAN version 2 metadata header */
struct erspan_md2 {
__be32 timestamp;
__be16 sgt; /* security group tag */
__be16 flags;
#define P_OFFSET 15
#define FT_OFFSET 10
#define HWID_OFFSET 4 #define HWID_OFFSET 4
#define DIR_OFFSET 3 #define DIR_OFFSET 3
#define GRA_OFFSET 1
};
enum erspan_encap_type { enum erspan_encap_type {
ERSPAN_ENCAP_NOVLAN = 0x0, /* originally without VLAN tag */ ERSPAN_ENCAP_NOVLAN = 0x0, /* originally without VLAN tag */
...@@ -86,24 +79,64 @@ enum erspan_encap_type { ...@@ -86,24 +79,64 @@ enum erspan_encap_type {
#define ERSPAN_V1_MDSIZE 4 #define ERSPAN_V1_MDSIZE 4
#define ERSPAN_V2_MDSIZE 8 #define ERSPAN_V2_MDSIZE 8
struct erspan_metadata {
union {
__be32 index; /* Version 1 (type II)*/
struct erspan_md2 md2; /* Version 2 (type III) */
} u;
int version;
};
struct erspan_base_hdr { struct erspan_base_hdr {
__be16 ver_vlan; #if defined(__LITTLE_ENDIAN_BITFIELD)
#define VER_OFFSET 12 __u8 vlan_upper:4,
__be16 session_id; ver:4;
#define COS_OFFSET 13 __u8 vlan:8;
#define EN_OFFSET 11 __u8 session_id_upper:2,
#define BSO_OFFSET EN_OFFSET t:1,
#define T_OFFSET 10 en:2,
cos:3;
__u8 session_id:8;
#elif defined(__BIG_ENDIAN_BITFIELD)
__u8 ver: 4,
vlan_upper:4;
__u8 vlan:8;
__u8 cos:3,
en:2,
t:1,
session_id_upper:2;
__u8 session_id:8;
#else
#error "Please fix <asm/byteorder.h>"
#endif
}; };
static inline void set_session_id(struct erspan_base_hdr *ershdr, u16 id)
{
ershdr->session_id = id & 0xff;
ershdr->session_id_upper = (id >> 8) & 0x3;
}
static inline u16 get_session_id(const struct erspan_base_hdr *ershdr)
{
return (ershdr->session_id_upper << 8) + ershdr->session_id;
}
static inline void set_vlan(struct erspan_base_hdr *ershdr, u16 vlan)
{
ershdr->vlan = vlan & 0xff;
ershdr->vlan_upper = (vlan >> 8) & 0xf;
}
static inline u16 get_vlan(const struct erspan_base_hdr *ershdr)
{
return (ershdr->vlan_upper << 8) + ershdr->vlan;
}
static inline void set_hwid(struct erspan_md2 *md2, u8 hwid)
{
md2->hwid = hwid & 0xf;
md2->hwid_upper = (hwid >> 4) & 0x3;
}
static inline u8 get_hwid(const struct erspan_md2 *md2)
{
return (md2->hwid_upper << 4) + md2->hwid;
}
static inline int erspan_hdr_len(int version) static inline int erspan_hdr_len(int version)
{ {
return sizeof(struct erspan_base_hdr) + return sizeof(struct erspan_base_hdr) +
...@@ -120,7 +153,7 @@ static inline u8 tos_to_cos(u8 tos) ...@@ -120,7 +153,7 @@ static inline u8 tos_to_cos(u8 tos)
} }
static inline void erspan_build_header(struct sk_buff *skb, static inline void erspan_build_header(struct sk_buff *skb,
__be32 id, u32 index, u32 id, u32 index,
bool truncate, bool is_ipv4) bool truncate, bool is_ipv4)
{ {
struct ethhdr *eth = (struct ethhdr *)skb->data; struct ethhdr *eth = (struct ethhdr *)skb->data;
...@@ -154,12 +187,12 @@ static inline void erspan_build_header(struct sk_buff *skb, ...@@ -154,12 +187,12 @@ static inline void erspan_build_header(struct sk_buff *skb,
memset(ershdr, 0, sizeof(*ershdr) + ERSPAN_V1_MDSIZE); memset(ershdr, 0, sizeof(*ershdr) + ERSPAN_V1_MDSIZE);
/* Build base header */ /* Build base header */
ershdr->ver_vlan = htons((vlan_tci & VLAN_MASK) | ershdr->ver = ERSPAN_VERSION;
(ERSPAN_VERSION << VER_OFFSET)); ershdr->cos = tos_to_cos(tos);
ershdr->session_id = htons((u16)(ntohl(id) & ID_MASK) | ershdr->en = enc_type;
((tos_to_cos(tos) << COS_OFFSET) & COS_MASK) | ershdr->t = truncate;
(enc_type << EN_OFFSET & EN_MASK) | set_vlan(ershdr, vlan_tci);
((truncate << T_OFFSET) & T_MASK)); set_session_id(ershdr, id);
/* Build metadata */ /* Build metadata */
ersmd = (struct erspan_metadata *)(ershdr + 1); ersmd = (struct erspan_metadata *)(ershdr + 1);
...@@ -187,7 +220,7 @@ static inline __be32 erspan_get_timestamp(void) ...@@ -187,7 +220,7 @@ static inline __be32 erspan_get_timestamp(void)
} }
static inline void erspan_build_header_v2(struct sk_buff *skb, static inline void erspan_build_header_v2(struct sk_buff *skb,
__be32 id, u8 direction, u16 hwid, u32 id, u8 direction, u16 hwid,
bool truncate, bool is_ipv4) bool truncate, bool is_ipv4)
{ {
struct ethhdr *eth = (struct ethhdr *)skb->data; struct ethhdr *eth = (struct ethhdr *)skb->data;
...@@ -198,7 +231,6 @@ static inline void erspan_build_header_v2(struct sk_buff *skb, ...@@ -198,7 +231,6 @@ static inline void erspan_build_header_v2(struct sk_buff *skb,
__be16 tci; __be16 tci;
} *qp; } *qp;
u16 vlan_tci = 0; u16 vlan_tci = 0;
u16 session_id;
u8 gra = 0; /* 100 usec */ u8 gra = 0; /* 100 usec */
u8 bso = 0; /* Bad/Short/Oversized */ u8 bso = 0; /* Bad/Short/Oversized */
u8 sgt = 0; u8 sgt = 0;
...@@ -221,22 +253,23 @@ static inline void erspan_build_header_v2(struct sk_buff *skb, ...@@ -221,22 +253,23 @@ static inline void erspan_build_header_v2(struct sk_buff *skb,
memset(ershdr, 0, sizeof(*ershdr) + ERSPAN_V2_MDSIZE); memset(ershdr, 0, sizeof(*ershdr) + ERSPAN_V2_MDSIZE);
/* Build base header */ /* Build base header */
ershdr->ver_vlan = htons((vlan_tci & VLAN_MASK) | ershdr->ver = ERSPAN_VERSION2;
(ERSPAN_VERSION2 << VER_OFFSET)); ershdr->cos = tos_to_cos(tos);
session_id = (u16)(ntohl(id) & ID_MASK) | ershdr->en = bso;
((tos_to_cos(tos) << COS_OFFSET) & COS_MASK) | ershdr->t = truncate;
(bso << BSO_OFFSET & BSO_MASK) | set_vlan(ershdr, vlan_tci);
((truncate << T_OFFSET) & T_MASK); set_session_id(ershdr, id);
ershdr->session_id = htons(session_id);
/* Build metadata */ /* Build metadata */
md = (struct erspan_metadata *)(ershdr + 1); md = (struct erspan_metadata *)(ershdr + 1);
md->u.md2.timestamp = erspan_get_timestamp(); md->u.md2.timestamp = erspan_get_timestamp();
md->u.md2.sgt = htons(sgt); md->u.md2.sgt = htons(sgt);
md->u.md2.flags = htons(((1 << P_OFFSET) & P_MASK) | md->u.md2.p = 1;
((hwid << HWID_OFFSET) & HWID_MASK) | md->u.md2.ft = 0;
((direction << DIR_OFFSET) & DIR_MASK) | md->u.md2.dir = direction;
((gra << GRA_OFFSET) & GRA_MASK)); md->u.md2.gra = gra;
md->u.md2.o = 0;
set_hwid(&md->u.md2, hwid);
} }
#endif #endif
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
/*
* ERSPAN Tunnel Metadata
*
* Copyright (c) 2018 VMware
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* Userspace API for metadata mode ERSPAN tunnel
*/
#ifndef _UAPI_ERSPAN_H
#define _UAPI_ERSPAN_H
#include <linux/types.h> /* For __beXX in userspace */
#include <asm/byteorder.h>
/* ERSPAN version 2 metadata header */
struct erspan_md2 {
__be32 timestamp;
__be16 sgt; /* security group tag */
#if defined(__LITTLE_ENDIAN_BITFIELD)
__u8 hwid_upper:2,
ft:5,
p:1;
__u8 o:1,
gra:2,
dir:1,
hwid:4;
#elif defined(__BIG_ENDIAN_BITFIELD)
__u8 p:1,
ft:5,
hwid_upper:2;
__u8 hwid:4,
dir:1,
gra:2,
o:1;
#else
#error "Please fix <asm/byteorder.h>"
#endif
};
struct erspan_metadata {
int version;
union {
__be32 index; /* Version 1 (type II)*/
struct erspan_md2 md2; /* Version 2 (type III) */
} u;
};
#endif /* _UAPI_ERSPAN_H */
...@@ -363,6 +363,7 @@ enum ovs_tunnel_key_attr { ...@@ -363,6 +363,7 @@ enum ovs_tunnel_key_attr {
OVS_TUNNEL_KEY_ATTR_IPV6_SRC, /* struct in6_addr src IPv6 address. */ OVS_TUNNEL_KEY_ATTR_IPV6_SRC, /* struct in6_addr src IPv6 address. */
OVS_TUNNEL_KEY_ATTR_IPV6_DST, /* struct in6_addr dst IPv6 address. */ OVS_TUNNEL_KEY_ATTR_IPV6_DST, /* struct in6_addr dst IPv6 address. */
OVS_TUNNEL_KEY_ATTR_PAD, OVS_TUNNEL_KEY_ATTR_PAD,
OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS, /* struct erspan_metadata */
__OVS_TUNNEL_KEY_ATTR_MAX __OVS_TUNNEL_KEY_ATTR_MAX
}; };
......
...@@ -114,7 +114,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN"); ...@@ -114,7 +114,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
static struct rtnl_link_ops ipgre_link_ops __read_mostly; static struct rtnl_link_ops ipgre_link_ops __read_mostly;
static int ipgre_tunnel_init(struct net_device *dev); static int ipgre_tunnel_init(struct net_device *dev);
static void erspan_build_header(struct sk_buff *skb, static void erspan_build_header(struct sk_buff *skb,
__be32 id, u32 index, u32 id, u32 index,
bool truncate, bool is_ipv4); bool truncate, bool is_ipv4);
static unsigned int ipgre_net_id __read_mostly; static unsigned int ipgre_net_id __read_mostly;
...@@ -273,12 +273,12 @@ static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi, ...@@ -273,12 +273,12 @@ static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi,
iph = ip_hdr(skb); iph = ip_hdr(skb);
ershdr = (struct erspan_base_hdr *)(skb->data + gre_hdr_len); ershdr = (struct erspan_base_hdr *)(skb->data + gre_hdr_len);
ver = (ntohs(ershdr->ver_vlan) & VER_MASK) >> VER_OFFSET; ver = ershdr->ver;
/* The original GRE header does not have key field, /* The original GRE header does not have key field,
* Use ERSPAN 10-bit session ID as key. * Use ERSPAN 10-bit session ID as key.
*/ */
tpi->key = cpu_to_be32(ntohs(ershdr->session_id) & ID_MASK); tpi->key = cpu_to_be32(get_session_id(ershdr));
tunnel = ip_tunnel_lookup(itn, skb->dev->ifindex, tunnel = ip_tunnel_lookup(itn, skb->dev->ifindex,
tpi->flags | TUNNEL_KEY, tpi->flags | TUNNEL_KEY,
iph->saddr, iph->daddr, tpi->key); iph->saddr, iph->daddr, tpi->key);
...@@ -324,14 +324,8 @@ static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi, ...@@ -324,14 +324,8 @@ static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi,
if (ver == 1) { if (ver == 1) {
tunnel->index = ntohl(pkt_md->u.index); tunnel->index = ntohl(pkt_md->u.index);
} else { } else {
u16 md2_flags; tunnel->dir = pkt_md->u.md2.dir;
u16 dir, hwid; tunnel->hwid = get_hwid(&pkt_md->u.md2);
md2_flags = ntohs(pkt_md->u.md2.flags);
dir = (md2_flags & DIR_MASK) >> DIR_OFFSET;
hwid = (md2_flags & HWID_MASK) >> HWID_OFFSET;
tunnel->dir = dir;
tunnel->hwid = hwid;
} }
} }
...@@ -615,19 +609,14 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev, ...@@ -615,19 +609,14 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev,
} }
if (version == 1) { if (version == 1) {
erspan_build_header(skb, tunnel_id_to_key32(key->tun_id), erspan_build_header(skb, ntohl(tunnel_id_to_key32(key->tun_id)),
ntohl(md->u.index), truncate, true); ntohl(md->u.index), truncate, true);
} else if (version == 2) { } else if (version == 2) {
u16 md2_flags; erspan_build_header_v2(skb,
u8 direction; ntohl(tunnel_id_to_key32(key->tun_id)),
u16 hwid; md->u.md2.dir,
get_hwid(&md->u.md2),
md2_flags = ntohs(md->u.md2.flags); truncate, true);
direction = (md2_flags & DIR_MASK) >> DIR_OFFSET;
hwid = (md2_flags & HWID_MASK) >> HWID_OFFSET;
erspan_build_header_v2(skb, tunnel_id_to_key32(key->tun_id),
direction, hwid, truncate, true);
} else { } else {
goto err_free_rt; goto err_free_rt;
} }
...@@ -733,10 +722,11 @@ static netdev_tx_t erspan_xmit(struct sk_buff *skb, ...@@ -733,10 +722,11 @@ static netdev_tx_t erspan_xmit(struct sk_buff *skb,
/* Push ERSPAN header */ /* Push ERSPAN header */
if (tunnel->erspan_ver == 1) if (tunnel->erspan_ver == 1)
erspan_build_header(skb, tunnel->parms.o_key, tunnel->index, erspan_build_header(skb, ntohl(tunnel->parms.o_key),
tunnel->index,
truncate, true); truncate, true);
else else
erspan_build_header_v2(skb, tunnel->parms.o_key, erspan_build_header_v2(skb, ntohl(tunnel->parms.o_key),
tunnel->dir, tunnel->hwid, tunnel->dir, tunnel->hwid,
truncate, true); truncate, true);
......
...@@ -513,8 +513,8 @@ static int ip6erspan_rcv(struct sk_buff *skb, int gre_hdr_len, ...@@ -513,8 +513,8 @@ static int ip6erspan_rcv(struct sk_buff *skb, int gre_hdr_len,
ipv6h = ipv6_hdr(skb); ipv6h = ipv6_hdr(skb);
ershdr = (struct erspan_base_hdr *)skb->data; ershdr = (struct erspan_base_hdr *)skb->data;
ver = (ntohs(ershdr->ver_vlan) & VER_MASK) >> VER_OFFSET; ver = ershdr->ver;
tpi->key = cpu_to_be32(ntohs(ershdr->session_id) & ID_MASK); tpi->key = cpu_to_be32(get_session_id(ershdr));
tunnel = ip6gre_tunnel_lookup(skb->dev, tunnel = ip6gre_tunnel_lookup(skb->dev,
&ipv6h->saddr, &ipv6h->daddr, tpi->key, &ipv6h->saddr, &ipv6h->daddr, tpi->key,
...@@ -565,14 +565,8 @@ static int ip6erspan_rcv(struct sk_buff *skb, int gre_hdr_len, ...@@ -565,14 +565,8 @@ static int ip6erspan_rcv(struct sk_buff *skb, int gre_hdr_len,
if (ver == 1) { if (ver == 1) {
tunnel->parms.index = ntohl(pkt_md->u.index); tunnel->parms.index = ntohl(pkt_md->u.index);
} else { } else {
u16 md2_flags; tunnel->parms.dir = pkt_md->u.md2.dir;
u16 dir, hwid; tunnel->parms.hwid = get_hwid(&pkt_md->u.md2);
md2_flags = ntohs(pkt_md->u.md2.flags);
dir = (md2_flags & DIR_MASK) >> DIR_OFFSET;
hwid = (md2_flags & HWID_MASK) >> HWID_OFFSET;
tunnel->parms.dir = dir;
tunnel->parms.hwid = hwid;
} }
ip6_tnl_rcv(tunnel, skb, tpi, NULL, log_ecn_error); ip6_tnl_rcv(tunnel, skb, tpi, NULL, log_ecn_error);
...@@ -925,6 +919,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb, ...@@ -925,6 +919,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
struct ip_tunnel_info *tun_info; struct ip_tunnel_info *tun_info;
const struct ip_tunnel_key *key; const struct ip_tunnel_key *key;
struct erspan_metadata *md; struct erspan_metadata *md;
__be32 tun_id;
tun_info = skb_tunnel_info(skb); tun_info = skb_tunnel_info(skb);
if (unlikely(!tun_info || if (unlikely(!tun_info ||
...@@ -944,23 +939,18 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb, ...@@ -944,23 +939,18 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
if (!md) if (!md)
goto tx_err; goto tx_err;
tun_id = tunnel_id_to_key32(key->tun_id);
if (md->version == 1) { if (md->version == 1) {
erspan_build_header(skb, erspan_build_header(skb,
tunnel_id_to_key32(key->tun_id), ntohl(tun_id),
ntohl(md->u.index), truncate, ntohl(md->u.index), truncate,
false); false);
} else if (md->version == 2) { } else if (md->version == 2) {
u16 md2_flags;
u16 dir, hwid;
md2_flags = ntohs(md->u.md2.flags);
dir = (md2_flags & DIR_MASK) >> DIR_OFFSET;
hwid = (md2_flags & HWID_MASK) >> HWID_OFFSET;
erspan_build_header_v2(skb, erspan_build_header_v2(skb,
tunnel_id_to_key32(key->tun_id), ntohl(tun_id),
dir, hwid, truncate, md->u.md2.dir,
false); get_hwid(&md->u.md2),
truncate, false);
} }
} else { } else {
switch (skb->protocol) { switch (skb->protocol) {
...@@ -982,11 +972,11 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb, ...@@ -982,11 +972,11 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
} }
if (t->parms.erspan_ver == 1) if (t->parms.erspan_ver == 1)
erspan_build_header(skb, t->parms.o_key, erspan_build_header(skb, ntohl(t->parms.o_key),
t->parms.index, t->parms.index,
truncate, false); truncate, false);
else else
erspan_build_header_v2(skb, t->parms.o_key, erspan_build_header_v2(skb, ntohl(t->parms.o_key),
t->parms.dir, t->parms.dir,
t->parms.hwid, t->parms.hwid,
truncate, false); truncate, false);
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include <net/mpls.h> #include <net/mpls.h>
#include <net/vxlan.h> #include <net/vxlan.h>
#include <net/tun_proto.h> #include <net/tun_proto.h>
#include <net/erspan.h>
#include "flow_netlink.h" #include "flow_netlink.h"
...@@ -329,7 +330,8 @@ size_t ovs_tun_key_attr_size(void) ...@@ -329,7 +330,8 @@ size_t ovs_tun_key_attr_size(void)
+ nla_total_size(0) /* OVS_TUNNEL_KEY_ATTR_CSUM */ + nla_total_size(0) /* OVS_TUNNEL_KEY_ATTR_CSUM */
+ nla_total_size(0) /* OVS_TUNNEL_KEY_ATTR_OAM */ + nla_total_size(0) /* OVS_TUNNEL_KEY_ATTR_OAM */
+ nla_total_size(256) /* OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS */ + nla_total_size(256) /* OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS */
/* OVS_TUNNEL_KEY_ATTR_VXLAN_OPTS is mutually exclusive with /* OVS_TUNNEL_KEY_ATTR_VXLAN_OPTS and
* OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS is mutually exclusive with
* OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS and covered by it. * OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS and covered by it.
*/ */
+ nla_total_size(2) /* OVS_TUNNEL_KEY_ATTR_TP_SRC */ + 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] ...@@ -400,6 +402,7 @@ static const struct ovs_len_tbl ovs_tunnel_key_lens[OVS_TUNNEL_KEY_ATTR_MAX + 1]
.next = ovs_vxlan_ext_key_lens }, .next = ovs_vxlan_ext_key_lens },
[OVS_TUNNEL_KEY_ATTR_IPV6_SRC] = { .len = sizeof(struct in6_addr) }, [OVS_TUNNEL_KEY_ATTR_IPV6_SRC] = { .len = sizeof(struct in6_addr) },
[OVS_TUNNEL_KEY_ATTR_IPV6_DST] = { .len = sizeof(struct in6_addr) }, [OVS_TUNNEL_KEY_ATTR_IPV6_DST] = { .len = sizeof(struct in6_addr) },
[OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS] = { .len = OVS_ATTR_VARIABLE },
}; };
static const struct ovs_len_tbl static const struct ovs_len_tbl
...@@ -631,6 +634,33 @@ static int vxlan_tun_opt_from_nlattr(const struct nlattr *attr, ...@@ -631,6 +634,33 @@ static int vxlan_tun_opt_from_nlattr(const struct nlattr *attr,
return 0; return 0;
} }
static int erspan_tun_opt_from_nlattr(const struct nlattr *a,
struct sw_flow_match *match, bool is_mask,
bool log)
{
unsigned long opt_key_offset;
BUILD_BUG_ON(sizeof(struct erspan_metadata) >
sizeof(match->key->tun_opts));
if (nla_len(a) > sizeof(match->key->tun_opts)) {
OVS_NLERR(log, "ERSPAN option length err (len %d, max %zu).",
nla_len(a), sizeof(match->key->tun_opts));
return -EINVAL;
}
if (!is_mask)
SW_FLOW_KEY_PUT(match, tun_opts_len,
sizeof(struct erspan_metadata), false);
else
SW_FLOW_KEY_PUT(match, tun_opts_len, 0xff, true);
opt_key_offset = TUN_METADATA_OFFSET(nla_len(a));
SW_FLOW_KEY_MEMCPY_OFFSET(match, opt_key_offset, nla_data(a),
nla_len(a), is_mask);
return 0;
}
static int ip_tun_from_nlattr(const struct nlattr *attr, static int ip_tun_from_nlattr(const struct nlattr *attr,
struct sw_flow_match *match, bool is_mask, struct sw_flow_match *match, bool is_mask,
bool log) bool log)
...@@ -738,6 +768,20 @@ static int ip_tun_from_nlattr(const struct nlattr *attr, ...@@ -738,6 +768,20 @@ static int ip_tun_from_nlattr(const struct nlattr *attr,
break; break;
case OVS_TUNNEL_KEY_ATTR_PAD: case OVS_TUNNEL_KEY_ATTR_PAD:
break; break;
case OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS:
if (opts_type) {
OVS_NLERR(log, "Multiple metadata blocks provided");
return -EINVAL;
}
err = erspan_tun_opt_from_nlattr(a, match, is_mask,
log);
if (err)
return err;
tun_flags |= TUNNEL_ERSPAN_OPT;
opts_type = type;
break;
default: default:
OVS_NLERR(log, "Unknown IP tunnel attribute %d", OVS_NLERR(log, "Unknown IP tunnel attribute %d",
type); type);
...@@ -862,6 +906,10 @@ static int __ip_tun_to_nlattr(struct sk_buff *skb, ...@@ -862,6 +906,10 @@ static int __ip_tun_to_nlattr(struct sk_buff *skb,
else if (output->tun_flags & TUNNEL_VXLAN_OPT && else if (output->tun_flags & TUNNEL_VXLAN_OPT &&
vxlan_opt_to_nlattr(skb, tun_opts, swkey_tun_opts_len)) vxlan_opt_to_nlattr(skb, tun_opts, swkey_tun_opts_len))
return -EMSGSIZE; return -EMSGSIZE;
else if (output->tun_flags & TUNNEL_ERSPAN_OPT &&
nla_put(skb, OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS,
swkey_tun_opts_len, tun_opts))
return -EMSGSIZE;
} }
return 0; return 0;
...@@ -2486,6 +2534,8 @@ static int validate_and_copy_set_tun(const struct nlattr *attr, ...@@ -2486,6 +2534,8 @@ static int validate_and_copy_set_tun(const struct nlattr *attr,
break; break;
case OVS_TUNNEL_KEY_ATTR_VXLAN_OPTS: case OVS_TUNNEL_KEY_ATTR_VXLAN_OPTS:
break; break;
case OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS:
break;
} }
} }
......
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