Skip to content

Commit

Permalink
lib/tc: Put the tunnel match fields as part of the tc/flower key struct
Browse files Browse the repository at this point in the history
Move the tunnel match fields to be part of the tc/flower key structure.

This is pre-step for being able to apply masked match where needed.

Signed-off-by: Or Gerlitz <[email protected]>
Reviewed-by: Roi Dayan <[email protected]>
Signed-off-by: Simon Horman <[email protected]>
  • Loading branch information
ogerlitz authored and shorman-netronome committed Sep 7, 2018
1 parent 70738f0 commit 105e817
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 60 deletions.
50 changes: 25 additions & 25 deletions lib/netdev-tc-offloads.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,24 +500,24 @@ parse_tc_flower_to_match(struct tc_flower *flower,
}
}

if (flower->tunnel.tunnel) {
match_set_tun_id(match, flower->tunnel.id);
if (flower->tunnel.ipv4.ipv4_dst) {
match_set_tun_src(match, flower->tunnel.ipv4.ipv4_src);
match_set_tun_dst(match, flower->tunnel.ipv4.ipv4_dst);
} else if (!is_all_zeros(&flower->tunnel.ipv6.ipv6_dst,
sizeof flower->tunnel.ipv6.ipv6_dst)) {
match_set_tun_ipv6_src(match, &flower->tunnel.ipv6.ipv6_src);
match_set_tun_ipv6_dst(match, &flower->tunnel.ipv6.ipv6_dst);
if (flower->tunnel) {
match_set_tun_id(match, flower->key.tunnel.id);
if (flower->key.tunnel.ipv4.ipv4_dst) {
match_set_tun_src(match, flower->key.tunnel.ipv4.ipv4_src);
match_set_tun_dst(match, flower->key.tunnel.ipv4.ipv4_dst);
} else if (!is_all_zeros(&flower->key.tunnel.ipv6.ipv6_dst,
sizeof flower->key.tunnel.ipv6.ipv6_dst)) {
match_set_tun_ipv6_src(match, &flower->key.tunnel.ipv6.ipv6_src);
match_set_tun_ipv6_dst(match, &flower->key.tunnel.ipv6.ipv6_dst);
}
if (flower->tunnel.tos) {
match_set_tun_tos(match, flower->tunnel.tos);
if (flower->key.tunnel.tos) {
match_set_tun_tos(match, flower->key.tunnel.tos);
}
if (flower->tunnel.ttl) {
match_set_tun_ttl(match, flower->tunnel.ttl);
if (flower->key.tunnel.ttl) {
match_set_tun_ttl(match, flower->key.tunnel.ttl);
}
if (flower->tunnel.tp_dst) {
match_set_tun_tp_dst(match, flower->tunnel.tp_dst);
if (flower->key.tunnel.tp_dst) {
match_set_tun_tp_dst(match, flower->key.tunnel.tp_dst);
}
}

Expand Down Expand Up @@ -964,16 +964,16 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match,
ntohll(tnl->tun_id),
IP_ARGS(tnl->ip_src), IP_ARGS(tnl->ip_dst),
ntohs(tnl->tp_src), ntohs(tnl->tp_dst));
flower.tunnel.id = tnl->tun_id;
flower.tunnel.ipv4.ipv4_src = tnl->ip_src;
flower.tunnel.ipv4.ipv4_dst = tnl->ip_dst;
flower.tunnel.ipv6.ipv6_src = tnl->ipv6_src;
flower.tunnel.ipv6.ipv6_dst = tnl->ipv6_dst;
flower.tunnel.tos = tnl->ip_tos;
flower.tunnel.ttl = tnl->ip_ttl;
flower.tunnel.tp_src = tnl->tp_src;
flower.tunnel.tp_dst = tnl->tp_dst;
flower.tunnel.tunnel = true;
flower.key.tunnel.id = tnl->tun_id;
flower.key.tunnel.ipv4.ipv4_src = tnl->ip_src;
flower.key.tunnel.ipv4.ipv4_dst = tnl->ip_dst;
flower.key.tunnel.ipv6.ipv6_src = tnl->ipv6_src;
flower.key.tunnel.ipv6.ipv6_dst = tnl->ipv6_dst;
flower.key.tunnel.tos = tnl->ip_tos;
flower.key.tunnel.ttl = tnl->ip_ttl;
flower.key.tunnel.tp_src = tnl->tp_src;
flower.key.tunnel.tp_dst = tnl->tp_dst;
flower.tunnel = true;
}
memset(&mask->tunnel, 0, sizeof mask->tunnel);

Expand Down
38 changes: 19 additions & 19 deletions lib/tc.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,34 +393,34 @@ nl_parse_flower_tunnel(struct nlattr **attrs, struct tc_flower *flower)
if (attrs[TCA_FLOWER_KEY_ENC_KEY_ID]) {
ovs_be32 id = nl_attr_get_be32(attrs[TCA_FLOWER_KEY_ENC_KEY_ID]);

flower->tunnel.id = be32_to_be64(id);
flower->key.tunnel.id = be32_to_be64(id);
}
if (attrs[TCA_FLOWER_KEY_ENC_IPV4_SRC_MASK]) {
flower->tunnel.ipv4.ipv4_src =
flower->key.tunnel.ipv4.ipv4_src =
nl_attr_get_be32(attrs[TCA_FLOWER_KEY_ENC_IPV4_SRC]);
}
if (attrs[TCA_FLOWER_KEY_ENC_IPV4_DST_MASK]) {
flower->tunnel.ipv4.ipv4_dst =
flower->key.tunnel.ipv4.ipv4_dst =
nl_attr_get_be32(attrs[TCA_FLOWER_KEY_ENC_IPV4_DST]);
}
if (attrs[TCA_FLOWER_KEY_ENC_IPV6_SRC_MASK]) {
flower->tunnel.ipv6.ipv6_src =
flower->key.tunnel.ipv6.ipv6_src =
nl_attr_get_in6_addr(attrs[TCA_FLOWER_KEY_ENC_IPV6_SRC]);
}
if (attrs[TCA_FLOWER_KEY_ENC_IPV6_DST_MASK]) {
flower->tunnel.ipv6.ipv6_dst =
flower->key.tunnel.ipv6.ipv6_dst =
nl_attr_get_in6_addr(attrs[TCA_FLOWER_KEY_ENC_IPV6_DST]);
}
if (attrs[TCA_FLOWER_KEY_ENC_UDP_DST_PORT]) {
flower->tunnel.tp_dst =
flower->key.tunnel.tp_dst =
nl_attr_get_be16(attrs[TCA_FLOWER_KEY_ENC_UDP_DST_PORT]);
}
if (attrs[TCA_FLOWER_KEY_ENC_IP_TOS]) {
flower->tunnel.tos =
flower->key.tunnel.tos =
nl_attr_get_u8(attrs[TCA_FLOWER_KEY_ENC_IP_TOS]);
}
if (attrs[TCA_FLOWER_KEY_ENC_IP_TTL]) {
flower->tunnel.ttl =
flower->key.tunnel.ttl =
nl_attr_get_u8(attrs[TCA_FLOWER_KEY_ENC_IP_TTL]);
}
}
Expand Down Expand Up @@ -702,7 +702,7 @@ nl_parse_act_tunnel_key(struct nlattr *options, struct tc_flower *flower)
action->encap.tos = tos ? nl_attr_get_u8(tos) : 0;
action->encap.ttl = ttl ? nl_attr_get_u8(ttl) : 0;
} else if (tun->t_action == TCA_TUNNEL_KEY_ACT_RELEASE) {
flower->tunnel.tunnel = true;
flower->tunnel = true;
} else {
VLOG_ERR_RL(&error_rl, "unknown tunnel actions: %d, %d",
tun->action, tun->t_action);
Expand Down Expand Up @@ -1513,7 +1513,7 @@ nl_msg_put_flower_acts(struct ofpbuf *request, struct tc_flower *flower)
{
int error;

if (flower->tunnel.tunnel) {
if (flower->tunnel) {
act_offset = nl_msg_start_nested(request, act_index++);
nl_msg_put_act_tunnel_key_release(request);
nl_msg_end_nested(request, act_offset);
Expand Down Expand Up @@ -1615,14 +1615,14 @@ nl_msg_put_masked_value(struct ofpbuf *request, uint16_t type,
static void
nl_msg_put_flower_tunnel(struct ofpbuf *request, struct tc_flower *flower)
{
ovs_be32 ipv4_src = flower->tunnel.ipv4.ipv4_src;
ovs_be32 ipv4_dst = flower->tunnel.ipv4.ipv4_dst;
struct in6_addr *ipv6_src = &flower->tunnel.ipv6.ipv6_src;
struct in6_addr *ipv6_dst = &flower->tunnel.ipv6.ipv6_dst;
ovs_be16 tp_dst = flower->tunnel.tp_dst;
ovs_be32 id = be64_to_be32(flower->tunnel.id);
uint8_t tos = flower->tunnel.tos;
uint8_t ttl = flower->tunnel.ttl;
ovs_be32 ipv4_src = flower->key.tunnel.ipv4.ipv4_src;
ovs_be32 ipv4_dst = flower->key.tunnel.ipv4.ipv4_dst;
struct in6_addr *ipv6_src = &flower->key.tunnel.ipv6.ipv6_src;
struct in6_addr *ipv6_dst = &flower->key.tunnel.ipv6.ipv6_dst;
ovs_be16 tp_dst = flower->key.tunnel.tp_dst;
ovs_be32 id = be64_to_be32(flower->key.tunnel.id);
uint8_t tos = flower->key.tunnel.tos;
uint8_t ttl = flower->key.tunnel.ttl;

if (ipv4_dst) {
nl_msg_put_be32(request, TCA_FLOWER_KEY_ENC_IPV4_SRC, ipv4_src);
Expand Down Expand Up @@ -1739,7 +1739,7 @@ nl_msg_put_flower_options(struct ofpbuf *request, struct tc_flower *flower)

nl_msg_put_u32(request, TCA_FLOWER_FLAGS, tc_get_tc_cls_policy(tc_policy));

if (flower->tunnel.tunnel) {
if (flower->tunnel) {
nl_msg_put_flower_tunnel(request, flower);
}

Expand Down
33 changes: 17 additions & 16 deletions lib/tc.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,22 @@ struct tc_flower_key {
struct in6_addr ipv6_src;
struct in6_addr ipv6_dst;
} ipv6;

struct {
struct {
ovs_be32 ipv4_src;
ovs_be32 ipv4_dst;
} ipv4;
struct {
struct in6_addr ipv6_src;
struct in6_addr ipv6_dst;
} ipv6;
uint8_t tos;
uint8_t ttl;
ovs_be16 tp_src;
ovs_be16 tp_dst;
ovs_be64 id;
} tunnel;
};

enum tc_action_type {
Expand Down Expand Up @@ -173,22 +189,7 @@ struct tc_flower {

uint32_t csum_update_flags;

struct {
bool tunnel;
struct {
ovs_be32 ipv4_src;
ovs_be32 ipv4_dst;
} ipv4;
struct {
struct in6_addr ipv6_src;
struct in6_addr ipv6_dst;
} ipv6;
uint8_t tos;
uint8_t ttl;
ovs_be16 tp_src;
ovs_be16 tp_dst;
ovs_be64 id;
} tunnel;
bool tunnel;

struct tc_cookie act_cookie;

Expand Down

0 comments on commit 105e817

Please sign in to comment.