From: Tianyu Yuan <tianyu.y...@corigine.com> Retrieve configuration of meter actions in TC flower classifiers (flows in the TC datapath). These actions are TC police action instances referred to by index.
Signed-off-by: Tianyu Yuan <tianyu.y...@corigine.com> Signed-off-by: Simon Horman <simon.hor...@corigine.com> --- lib/netdev-offload-tc.c | 5 +++++ lib/tc.c | 28 ++++++++++++++++++++++++++++ lib/tc.h | 2 ++ 3 files changed, 35 insertions(+) diff --git a/lib/netdev-offload-tc.c b/lib/netdev-offload-tc.c index 0387b9b2e..3222f9e54 100644 --- a/lib/netdev-offload-tc.c +++ b/lib/netdev-offload-tc.c @@ -1015,6 +1015,11 @@ parse_tc_flower_to_match(struct tc_flower *flower, nl_msg_put_u32(buf, OVS_ACTION_ATTR_RECIRC, action->chain); } break; + case TC_ACT_METER: { + nl_msg_put_u32(buf, OVS_ACTION_ATTR_METER, + action->meter.meter_id); + } + break; } } } diff --git a/lib/tc.c b/lib/tc.c index 9fb7eba07..3993498b0 100644 --- a/lib/tc.c +++ b/lib/tc.c @@ -1704,6 +1704,32 @@ nl_parse_act_csum(struct nlattr *options, struct tc_flower *flower) return 0; } +static const struct nl_policy police_policy[] = { + [TCA_POLICE_TBF] = { .type = NL_A_UNSPEC, + .min_len = sizeof(struct tc_police), + .optional = false, }, +}; + +static int nl_parse_act_meter(struct nlattr *options, struct tc_flower *flower) +{ + struct nlattr *attrs[__TCA_POLICE_MAX]; + const struct tc_police *tc_police; + const struct nlattr *meter_parms; + struct tc_action *action; + + action = &flower->actions[flower->action_count++]; + if (!nl_parse_nested(options, police_policy, attrs, + ARRAY_SIZE(police_policy))){ + VLOG_ERR_RL(&error_rl, "failed to parse meter action options"); + return EPROTO; + } + meter_parms = attrs[TCA_POLICE_TBF]; + tc_police = nl_attr_get_unspec(meter_parms, sizeof *tc_police); + action->meter.meter_id = POLICY_INDEX_TO_METER_ID(tc_police->index); + action->type = TC_ACT_METER; + return 0; +} + static const struct nl_policy act_policy[] = { [TCA_ACT_KIND] = { .type = NL_A_STRING, .optional = false, }, [TCA_ACT_COOKIE] = { .type = NL_A_UNSPEC, .optional = true, }, @@ -1762,6 +1788,8 @@ nl_parse_single_action(struct nlattr *action, struct tc_flower *flower, /* Added for TC rule only (not in OvS rule) so ignore. */ } else if (!strcmp(act_kind, "ct")) { nl_parse_act_ct(act_options, flower); + } else if (!strcmp(act_kind, "police")){ + nl_parse_act_meter(act_options, flower); } else { VLOG_ERR_RL(&error_rl, "unknown tc action kind: %s", act_kind); err = EINVAL; diff --git a/lib/tc.h b/lib/tc.h index 6ba7f946c..0f7de8677 100644 --- a/lib/tc.h +++ b/lib/tc.h @@ -56,6 +56,8 @@ enum tc_flower_reserved_prio { * the prefix of meter related policy, following 16 bits are mapped by * meter_id, last 8 bits are reserved for bands in further. */ #define METER_ID_TO_POLICY_INDEX(meter_id) 0xff << 24 | (meter_id + 1) << 8 +/* Mapping policy_index to meter_id */ +#define POLICY_INDEX_TO_METER_ID(index) (((index >> 8) & 0xffff) - 1) enum tc_qdisc_hook { TC_INGRESS, -- 2.20.1 _______________________________________________ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev