2
0
mirror of https://github.com/openvswitch/ovs synced 2025-09-03 15:55:19 +00:00

lib/tc: add ICMP type and code match offload

Add TC offload support for classifying ICMPv4/6 type and code.

$ ovs-appctl dpctl/add-flow 'recirc_id(0),in_port(3),eth(),\
  eth_type(0x0800),ipv4(proto=1),icmp(type=9,code=0)' 2

$ ovs-appctl dpctl/dump-flows
  ... icmp(type=9,code=0) ...

$ tc filter show dev <ethx> ingress
  ...
  eth_type ipv4
  ip_proto icmp
  icmp_type 9
  icmp_code 0
  not_in_hw
  action order 1: mirred (Egress Redirect to device <ethy>) stolen
  ...

Signed-off-by: Maor Dickman <maord@nvidia.com>
Reviewed-by: Roi Dayan <roid@nvidia.com>
Signed-off-by: Simon Horman <simon.horman@netronome.com>
This commit is contained in:
Maor Dickman
2021-01-28 15:51:08 +02:00
committed by Simon Horman
parent d5c429a303
commit 75e1e6fd2d
3 changed files with 65 additions and 24 deletions

View File

@@ -650,6 +650,12 @@ parse_tc_flower_to_match(struct tc_flower *flower,
} else if (key->ip_proto == IPPROTO_SCTP) { } else if (key->ip_proto == IPPROTO_SCTP) {
match_set_tp_dst_masked(match, key->sctp_dst, mask->sctp_dst); match_set_tp_dst_masked(match, key->sctp_dst, mask->sctp_dst);
match_set_tp_src_masked(match, key->sctp_src, mask->sctp_src); match_set_tp_src_masked(match, key->sctp_src, mask->sctp_src);
} else if (key->ip_proto == IPPROTO_ICMP ||
key->ip_proto == IPPROTO_ICMPV6) {
match_set_tp_dst_masked(match, htons(key->icmp_code),
htons(mask->icmp_code));
match_set_tp_src_masked(match, htons(key->icmp_type),
htons(mask->icmp_type));
} }
if (mask->ct_state) { if (mask->ct_state) {
@@ -1329,18 +1335,6 @@ test_key_and_mask(struct match *match)
} }
if (key->dl_type == htons(ETH_TYPE_IP) && if (key->dl_type == htons(ETH_TYPE_IP) &&
key->nw_proto == IPPROTO_ICMP) {
if (mask->tp_src) {
VLOG_DBG_RL(&rl,
"offloading attribute icmp_type isn't supported");
return EOPNOTSUPP;
}
if (mask->tp_dst) {
VLOG_DBG_RL(&rl,
"offloading attribute icmp_code isn't supported");
return EOPNOTSUPP;
}
} else if (key->dl_type == htons(ETH_TYPE_IP) &&
key->nw_proto == IPPROTO_IGMP) { key->nw_proto == IPPROTO_IGMP) {
if (mask->tp_src) { if (mask->tp_src) {
VLOG_DBG_RL(&rl, VLOG_DBG_RL(&rl,
@@ -1352,18 +1346,6 @@ test_key_and_mask(struct match *match)
"offloading attribute igmp_code isn't supported"); "offloading attribute igmp_code isn't supported");
return EOPNOTSUPP; return EOPNOTSUPP;
} }
} else if (key->dl_type == htons(ETH_TYPE_IPV6) &&
key->nw_proto == IPPROTO_ICMPV6) {
if (mask->tp_src) {
VLOG_DBG_RL(&rl,
"offloading attribute icmpv6_type isn't supported");
return EOPNOTSUPP;
}
if (mask->tp_dst) {
VLOG_DBG_RL(&rl,
"offloading attribute icmpv6_code isn't supported");
return EOPNOTSUPP;
}
} else if (key->dl_type == htons(OFP_DL_TYPE_NOT_ETH_TYPE)) { } else if (key->dl_type == htons(OFP_DL_TYPE_NOT_ETH_TYPE)) {
VLOG_DBG_RL(&rl, VLOG_DBG_RL(&rl,
"offloading of non-ethernet packets isn't supported"); "offloading of non-ethernet packets isn't supported");
@@ -1631,6 +1613,14 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match,
flower.mask.sctp_src = mask->tp_src; flower.mask.sctp_src = mask->tp_src;
mask->tp_src = 0; mask->tp_src = 0;
mask->tp_dst = 0; mask->tp_dst = 0;
} else if (key->nw_proto == IPPROTO_ICMP ||
key->nw_proto == IPPROTO_ICMPV6) {
flower.key.icmp_code = (uint8_t) ntohs(key->tp_dst);
flower.mask.icmp_code = (uint8_t) ntohs (mask->tp_dst);
flower.key.icmp_type = (uint8_t) ntohs(key->tp_src);
flower.mask.icmp_type = (uint8_t) ntohs(mask->tp_src);
mask->tp_src = 0;
mask->tp_dst = 0;
} }
if (key->dl_type == htons(ETH_P_IP)) { if (key->dl_type == htons(ETH_P_IP)) {

View File

@@ -426,6 +426,22 @@ static const struct nl_policy tca_flower_policy[] = {
[TCA_FLOWER_KEY_CT_LABELS] = { .type = NL_A_U128, .optional = true, }, [TCA_FLOWER_KEY_CT_LABELS] = { .type = NL_A_U128, .optional = true, },
[TCA_FLOWER_KEY_CT_LABELS_MASK] = { .type = NL_A_U128, [TCA_FLOWER_KEY_CT_LABELS_MASK] = { .type = NL_A_U128,
.optional = true, }, .optional = true, },
[TCA_FLOWER_KEY_ICMPV4_CODE] = { .type = NL_A_U8,
.optional = true, },
[TCA_FLOWER_KEY_ICMPV4_CODE_MASK] = { .type = NL_A_U8,
.optional = true, },
[TCA_FLOWER_KEY_ICMPV4_TYPE] = { .type = NL_A_U8,
.optional = true, },
[TCA_FLOWER_KEY_ICMPV4_TYPE_MASK] = { .type = NL_A_U8,
.optional = true, },
[TCA_FLOWER_KEY_ICMPV6_CODE] = { .type = NL_A_U8,
.optional = true, },
[TCA_FLOWER_KEY_ICMPV6_CODE_MASK] = { .type = NL_A_U8,
.optional = true, },
[TCA_FLOWER_KEY_ICMPV6_TYPE] = { .type = NL_A_U8,
.optional = true, },
[TCA_FLOWER_KEY_ICMPV6_TYPE_MASK] = { .type = NL_A_U8,
.optional = true, },
}; };
static const struct nl_policy tca_flower_terse_policy[] = { static const struct nl_policy tca_flower_terse_policy[] = {
@@ -908,6 +924,32 @@ nl_parse_flower_ip(struct nlattr **attrs, struct tc_flower *flower) {
mask->sctp_dst = mask->sctp_dst =
nl_attr_get_be16(attrs[TCA_FLOWER_KEY_SCTP_DST_MASK]); nl_attr_get_be16(attrs[TCA_FLOWER_KEY_SCTP_DST_MASK]);
} }
} else if (ip_proto == IPPROTO_ICMP) {
if (attrs[TCA_FLOWER_KEY_ICMPV4_CODE_MASK]) {
key->icmp_code =
nl_attr_get_u8(attrs[TCA_FLOWER_KEY_ICMPV4_CODE]);
mask->icmp_code =
nl_attr_get_u8(attrs[TCA_FLOWER_KEY_ICMPV4_CODE]);
}
if (attrs[TCA_FLOWER_KEY_ICMPV4_TYPE_MASK]) {
key->icmp_type =
nl_attr_get_u8(attrs[TCA_FLOWER_KEY_ICMPV4_TYPE_MASK]);
mask->icmp_type =
nl_attr_get_u8(attrs[TCA_FLOWER_KEY_ICMPV4_TYPE_MASK]);
}
} else if (ip_proto == IPPROTO_ICMPV6) {
if (attrs[TCA_FLOWER_KEY_ICMPV6_CODE_MASK]) {
key->icmp_code =
nl_attr_get_u8(attrs[TCA_FLOWER_KEY_ICMPV6_CODE]);
mask->icmp_code =
nl_attr_get_u8(attrs[TCA_FLOWER_KEY_ICMPV6_CODE]);
}
if (attrs[TCA_FLOWER_KEY_ICMPV6_TYPE_MASK]) {
key->icmp_type =
nl_attr_get_u8(attrs[TCA_FLOWER_KEY_ICMPV6_TYPE_MASK]);
mask->icmp_type =
nl_attr_get_u8(attrs[TCA_FLOWER_KEY_ICMPV6_TYPE_MASK]);
}
} }
if (attrs[TCA_FLOWER_KEY_IP_TTL_MASK]) { if (attrs[TCA_FLOWER_KEY_IP_TTL_MASK]) {
@@ -2812,6 +2854,12 @@ nl_msg_put_flower_options(struct ofpbuf *request, struct tc_flower *flower)
} else if (flower->key.ip_proto == IPPROTO_SCTP) { } else if (flower->key.ip_proto == IPPROTO_SCTP) {
FLOWER_PUT_MASKED_VALUE(sctp_src, TCA_FLOWER_KEY_SCTP_SRC); FLOWER_PUT_MASKED_VALUE(sctp_src, TCA_FLOWER_KEY_SCTP_SRC);
FLOWER_PUT_MASKED_VALUE(sctp_dst, TCA_FLOWER_KEY_SCTP_DST); FLOWER_PUT_MASKED_VALUE(sctp_dst, TCA_FLOWER_KEY_SCTP_DST);
} else if (flower->key.ip_proto == IPPROTO_ICMP) {
FLOWER_PUT_MASKED_VALUE(icmp_code, TCA_FLOWER_KEY_ICMPV4_CODE);
FLOWER_PUT_MASKED_VALUE(icmp_type, TCA_FLOWER_KEY_ICMPV4_TYPE);
} else if (flower->key.ip_proto == IPPROTO_ICMPV6) {
FLOWER_PUT_MASKED_VALUE(icmp_code, TCA_FLOWER_KEY_ICMPV6_CODE);
FLOWER_PUT_MASKED_VALUE(icmp_type, TCA_FLOWER_KEY_ICMPV6_TYPE);
} }
FLOWER_PUT_MASKED_VALUE(ct_state, TCA_FLOWER_KEY_CT_STATE); FLOWER_PUT_MASKED_VALUE(ct_state, TCA_FLOWER_KEY_CT_STATE);

View File

@@ -107,6 +107,9 @@ struct tc_flower_key {
ovs_be16 sctp_src; ovs_be16 sctp_src;
ovs_be16 sctp_dst; ovs_be16 sctp_dst;
uint8_t icmp_code;
uint8_t icmp_type;
uint16_t vlan_id[FLOW_MAX_VLAN_HEADERS]; uint16_t vlan_id[FLOW_MAX_VLAN_HEADERS];
uint8_t vlan_prio[FLOW_MAX_VLAN_HEADERS]; uint8_t vlan_prio[FLOW_MAX_VLAN_HEADERS];