mirror of
https://github.com/openvswitch/ovs
synced 2025-08-31 06:15:47 +00:00
tc: Add vxlan gbp option flower match offload.
Add TC offload support for filtering vxlan tunnels with gbp option. Reviewed-by: Gavi Teitz <gavi@nvidia.com> Reviewed-by: Roi Dayan <roid@nvidia.com> Reviewed-by: Simon Horman <simon.horman@corigine.com> Signed-off-by: Gavin Li <gavinl@nvidia.com> Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
This commit is contained in:
92
lib/tc.c
92
lib/tc.c
@@ -39,6 +39,7 @@
|
||||
#include "coverage.h"
|
||||
#include "netlink-socket.h"
|
||||
#include "netlink.h"
|
||||
#include "odp-util.h"
|
||||
#include "openvswitch/ofpbuf.h"
|
||||
#include "openvswitch/util.h"
|
||||
#include "openvswitch/vlog.h"
|
||||
@@ -699,6 +700,38 @@ nl_parse_geneve_key(const struct nlattr *in_nlattr,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
nl_parse_vxlan_key(const struct nlattr *in_nlattr,
|
||||
struct tc_flower_tunnel *tunnel)
|
||||
{
|
||||
const struct ofpbuf *msg;
|
||||
struct nlattr *nla;
|
||||
struct ofpbuf buf;
|
||||
uint32_t gbp_raw;
|
||||
size_t left;
|
||||
|
||||
nl_attr_get_nested(in_nlattr, &buf);
|
||||
msg = &buf;
|
||||
|
||||
NL_ATTR_FOR_EACH (nla, left, ofpbuf_at(msg, 0, 0), msg->size) {
|
||||
uint16_t type = nl_attr_type(nla);
|
||||
|
||||
switch (type) {
|
||||
case TCA_FLOWER_KEY_ENC_OPT_VXLAN_GBP:
|
||||
gbp_raw = nl_attr_get_u32(nla);
|
||||
odp_decode_gbp_raw(gbp_raw, &tunnel->gbp.id,
|
||||
&tunnel->gbp.flags);
|
||||
tunnel->gbp.id_present = true;
|
||||
break;
|
||||
default:
|
||||
VLOG_WARN_RL(&error_rl, "failed to parse vxlan tun options");
|
||||
return EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
nl_parse_flower_tunnel_opts(struct nlattr *options,
|
||||
struct tc_flower_tunnel *tunnel)
|
||||
@@ -721,6 +754,13 @@ nl_parse_flower_tunnel_opts(struct nlattr *options,
|
||||
return err;
|
||||
}
|
||||
|
||||
break;
|
||||
case TCA_FLOWER_KEY_ENC_OPTS_VXLAN:
|
||||
err = nl_parse_vxlan_key(nla, tunnel);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -3445,23 +3485,18 @@ nl_msg_put_masked_value(struct ofpbuf *request, uint16_t type,
|
||||
}
|
||||
|
||||
static void
|
||||
nl_msg_put_flower_tunnel_opts(struct ofpbuf *request, uint16_t type,
|
||||
struct tc_flower_tunnel *tunnel)
|
||||
nl_msg_put_flower_geneve(struct ofpbuf *request,
|
||||
const struct tc_flower_tunnel *tunnel)
|
||||
{
|
||||
struct tun_metadata *metadata = &tunnel->metadata;
|
||||
struct geneve_opt *opt;
|
||||
size_t outer, inner;
|
||||
const struct tun_metadata *metadata = &tunnel->metadata;
|
||||
const struct geneve_opt *opt;
|
||||
int len, cnt = 0;
|
||||
size_t offset;
|
||||
|
||||
len = metadata->present.len;
|
||||
if (!len) {
|
||||
return;
|
||||
}
|
||||
|
||||
outer = nl_msg_start_nested(request, type);
|
||||
while (len) {
|
||||
opt = &metadata->opts.gnv[cnt];
|
||||
inner = nl_msg_start_nested(request, TCA_FLOWER_KEY_ENC_OPTS_GENEVE);
|
||||
offset = nl_msg_start_nested(request, TCA_FLOWER_KEY_ENC_OPTS_GENEVE);
|
||||
|
||||
nl_msg_put_be16(request, TCA_FLOWER_KEY_ENC_OPT_GENEVE_CLASS,
|
||||
opt->opt_class);
|
||||
@@ -3472,8 +3507,41 @@ nl_msg_put_flower_tunnel_opts(struct ofpbuf *request, uint16_t type,
|
||||
cnt += sizeof(struct geneve_opt) / 4 + opt->length;
|
||||
len -= sizeof(struct geneve_opt) + opt->length * 4;
|
||||
|
||||
nl_msg_end_nested(request, inner);
|
||||
nl_msg_end_nested(request, offset);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nl_msg_put_flower_vxlan_tun_opts(struct ofpbuf *request,
|
||||
const struct tc_flower_tunnel *tunnel)
|
||||
{
|
||||
uint32_t gbp_raw;
|
||||
size_t offset;
|
||||
|
||||
if (!tunnel->gbp.id_present) {
|
||||
return;
|
||||
}
|
||||
|
||||
gbp_raw = odp_encode_gbp_raw(tunnel->gbp.flags, tunnel->gbp.id);
|
||||
offset = nl_msg_start_nested_with_flag(request,
|
||||
TCA_FLOWER_KEY_ENC_OPTS_VXLAN);
|
||||
nl_msg_put_u32(request, TCA_FLOWER_KEY_ENC_OPT_VXLAN_GBP, gbp_raw);
|
||||
nl_msg_end_nested(request, offset);
|
||||
}
|
||||
|
||||
static void
|
||||
nl_msg_put_flower_tunnel_opts(struct ofpbuf *request, uint16_t type,
|
||||
struct tc_flower_tunnel *tunnel)
|
||||
{
|
||||
size_t outer;
|
||||
|
||||
if (!tunnel->metadata.present.len && !tunnel->gbp.id_present) {
|
||||
return;
|
||||
}
|
||||
|
||||
outer = nl_msg_start_nested(request, type);
|
||||
nl_msg_put_flower_geneve(request, tunnel);
|
||||
nl_msg_put_flower_vxlan_tun_opts(request, tunnel);
|
||||
nl_msg_end_nested(request, outer);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user