+}
static int
parse_check_pkt_len_action(struct netdev *netdev, struct tc_flower *flower,
- struct offload_info *info, struct tc_action *action,
- const struct nlattr *nla, bool last_action,
+ struct offload_info *info,
+ const struct flow_tnl *tnl,
+ struct tc_action *action, const struct nlattr *nla,
+ bool last_action,
struct tc_action **need_jump_update,
bool *recirc_act)
{
@@ -2070,7 +2283,7 @@ parse_check_pkt_len_action(struct netdev *netdev, struct
tc_flower *flower,
* NOTE: The last_action parameter means that there are no more actions
* after the if () then ... else () case. */
nl_actions = a[OVS_CHECK_PKT_LEN_ATTR_ACTIONS_IF_GREATER];
- err = netdev_tc_parse_nl_actions(netdev, flower, info,
+ err = netdev_tc_parse_nl_actions(netdev, flower, info, tnl,
nl_attr_get(nl_actions),
nl_attr_get_size(nl_actions),
recirc_act, !last_action,
@@ -2086,7 +2299,7 @@ parse_check_pkt_len_action(struct netdev *netdev, struct
tc_flower *flower,
/* Parse and add the less than action(s). */
nl_actions = a[OVS_CHECK_PKT_LEN_ATTR_ACTIONS_IF_LESS_EQUAL];
- err = netdev_tc_parse_nl_actions(netdev, flower, info,
+ err = netdev_tc_parse_nl_actions(netdev, flower, info, tnl,
nl_attr_get(nl_actions),
nl_attr_get_size(nl_actions),
recirc_act, !last_action,
@@ -2139,6 +2352,7 @@ parse_check_pkt_len_action(struct netdev *netdev, struct
tc_flower *flower,
static int
netdev_tc_parse_nl_actions(struct netdev *netdev, struct tc_flower *flower,
struct offload_info *info,
+ const struct flow_tnl *tnl,
const struct nlattr *actions, size_t actions_len,
bool *recirc_act, bool more_actions,
struct tc_action **need_jump_update)
@@ -2268,7 +2482,8 @@ netdev_tc_parse_nl_actions(struct netdev *netdev, struct
tc_flower *flower,
action->police.index = police_index;
flower->action_count++;
} else if (nl_attr_type(nla) == OVS_ACTION_ATTR_CHECK_PKT_LEN) {
- err = parse_check_pkt_len_action(netdev, flower, info, action, nla,
+ err = parse_check_pkt_len_action(netdev, flower, info, tnl,
+ action, nla,
nl_attr_len_pad(nla,
left) >= left
&& !more_actions,
@@ -2277,14 +2492,28 @@ netdev_tc_parse_nl_actions(struct netdev *netdev,
struct tc_flower *flower,
if (err) {
return err;
}
- } else if (nl_attr_type(nla) == OVS_ACTION_ATTR_SAMPLE) {
- struct offload_sample sample;
- uint32_t sgid;
-
- memset(&sample, 0, sizeof sample);
- sgid = sgid_alloc(&sample);
- sgid_free(sgid);
- return EOPNOTSUPP;
+ } else if (nl_attr_type(nla) == OVS_ACTION_ATTR_SAMPLE ||
+ nl_attr_type(nla) == OVS_ACTION_ATTR_USERSPACE) {
+ if (!psample_supported()) {
+ VLOG_DBG_RL(&rl, "Unsupported put action type: %d, psample is "
+ "not initialized successfully", nl_attr_type(nla));
+ return EOPNOTSUPP;
+ }
+ if (get_flower_sgid_count(flower) >= MAX_TC_SAMPLES_PER_FLOW) {
+ VLOG_ERR_RL(&error_rl, "Only %u TC_SAMPLE action per "
+ "flow is supported", MAX_TC_SAMPLES_PER_FLOW);
+ return EOPNOTSUPP;
+ }
+ if (nl_attr_type(nla) == OVS_ACTION_ATTR_SAMPLE) {
+ err = parse_sample_action(flower, action, actions, actions_len,
+ nla, tnl);
+ } else {
+ err = parse_userspace_action(flower, action, actions,
+ actions_len, nla, tnl);
+ }
+ if (err) {
+ return err;
+ }
} else {
VLOG_DBG_RL(&rl, "unsupported put action type: %d",
nl_attr_type(nla));
@@ -2324,6 +2553,7 @@ netdev_tc_flow_put(struct netdev *netdev, struct match
*match,
}
memset(&flower, 0, sizeof flower);
+ flower.ifindex = ifindex;
chain = key->recirc_id;
mask->recirc_id = 0;
@@ -2589,16 +2819,17 @@ netdev_tc_flow_put(struct netdev *netdev, struct match
*match,
}
/* Parse all (nested) actions. */
- err = netdev_tc_parse_nl_actions(netdev, &flower, info,
+ err = netdev_tc_parse_nl_actions(netdev, &flower, info, tnl,
actions, actions_len, &recirc_act,
false, NULL);
if (err) {
- return err;
+ goto error_out;
}
if ((chain || recirc_act) && !info->recirc_id_shared_with_tc) {
VLOG_DBG_RL(&rl, "flow_put: recirc_id sharing not supported");
- return EOPNOTSUPP;
+ err = EOPNOTSUPP;
+ goto error_out;
}
memset(&adjust_stats, 0, sizeof adjust_stats);
@@ -2612,7 +2843,8 @@ netdev_tc_flow_put(struct netdev *netdev, struct match
*match,
prio = get_prio_for_tc_flower(&flower);
if (prio == 0) {
VLOG_ERR_RL(&rl, "couldn't get tc prio: %s", ovs_strerror(ENOSPC));
- return ENOSPC;
+ err = ENOSPC;
+ goto error_out;
}
flower.act_cookie.data = ufid;
@@ -2621,14 +2853,20 @@ netdev_tc_flow_put(struct netdev *netdev, struct match
*match,
block_id = get_block_id_from_netdev(netdev);
id = tc_make_tcf_id_chain(ifindex, block_id, chain, prio, hook);
err = tc_replace_flower(&id, &flower);
- if (!err) {
- if (stats) {
- memset(stats, 0, sizeof *stats);
- netdev_tc_adjust_stats(stats, &adjust_stats);
- }
- add_ufid_tc_mapping(netdev, ufid, &id, &adjust_stats);
+ if (err) {
+ goto error_out;
}
+ if (stats) {
+ memset(stats, 0, sizeof *stats);
+ netdev_tc_adjust_stats(stats, &adjust_stats);
+ }
+
+ add_ufid_tc_mapping(netdev, ufid, &id, &adjust_stats, &flower);
+ return 0;
+
+error_out:
+ free_all_flower_sgids(&flower);
return err;
}
diff --git a/lib/tc.c b/lib/tc.c
index 5c32c6f97..28ca6325a 100644
--- a/lib/tc.c
+++ b/lib/tc.c
@@ -23,14 +23,15 @@
#include <linux/if_packet.h>
#include <linux/rtnetlink.h>
#include <linux/tc_act/tc_csum.h>
+#include <linux/tc_act/tc_ct.h>
#include <linux/tc_act/tc_gact.h>
#include <linux/tc_act/tc_mirred.h>
#include <linux/tc_act/tc_mpls.h>
#include <linux/tc_act/tc_pedit.h>
+#include <linux/tc_act/tc_sample.h>
#include <linux/tc_act/tc_skbedit.h>
#include <linux/tc_act/tc_tunnel_key.h>
#include <linux/tc_act/tc_vlan.h>
-#include <linux/tc_act/tc_ct.h>
#include <linux/gen_stats.h>
#include <net/if.h>
#include <unistd.h>
@@ -1484,6 +1485,38 @@ nl_parse_act_police(const struct nlattr *options, struct
tc_flower *flower)
return 0;
}
+static const struct nl_policy sample_policy[] = {
+ [TCA_SAMPLE_PARMS] = { .type = NL_A_UNSPEC,
+ .min_len = sizeof(struct tc_sample),
+ .optional = false, },
+ [TCA_SAMPLE_PSAMPLE_GROUP] = { .type = NL_A_U32,
+ .optional = false, },
+ [TCA_SAMPLE_RATE] = { .type = NL_A_U32,
+ .optional = false, },
+};
+
+static int
+nl_parse_act_sample(struct nlattr *options, struct tc_flower *flower)
+{
+ struct nlattr *sample_attrs[ARRAY_SIZE(sample_policy)];
+ struct tc_action *action;
+
+ if (!nl_parse_nested(options, sample_policy, sample_attrs,
+ ARRAY_SIZE(sample_policy))) {
+ VLOG_ERR_RL(&error_rl, "Failed to parse sample action options");
+ return EPROTO;
+ }
+
+ action = &flower->actions[flower->action_count++];
+ action->type = TC_ACT_SAMPLE;
+ action->sample.group_id =
+ nl_attr_get_u32(sample_attrs[TCA_SAMPLE_PSAMPLE_GROUP]);
+ action->sample.rate =
+ nl_attr_get_u32(sample_attrs[TCA_SAMPLE_RATE]);
+
+ return 0;
+}
+
static const struct nl_policy mirred_policy[] = {
[TCA_MIRRED_PARMS] = { .type = NL_A_UNSPEC,
.min_len = sizeof(struct tc_mirred),
@@ -1999,6 +2032,8 @@ nl_parse_single_action(struct nlattr *action, struct
tc_flower *flower,
nl_parse_act_ct(act_options, flower);
} else if (!strcmp(act_kind, "police")) {
nl_parse_act_police(act_options, flower);
+ } else if (!strcmp(act_kind, "sample")) {
+ nl_parse_act_sample(act_options, flower);
} else {
VLOG_ERR_RL(&error_rl, "unknown tc action kind: %s", act_kind);
err = EINVAL;
@@ -2791,6 +2826,24 @@ nl_msg_put_act_mirred(struct ofpbuf *request, int
ifindex, int action,
nl_msg_end_nested(request, offset);
}
+static void
+nl_msg_put_act_sample(struct ofpbuf *request, uint32_t rate, uint32_t group_id,
+ uint32_t action_pc)
+{
+ size_t offset;
+
+ nl_msg_put_string(request, TCA_ACT_KIND, "sample");
+ offset = nl_msg_start_nested(request, TCA_ACT_OPTIONS | NLA_F_NESTED);
+ {
+ struct tc_sample parm = { .action = action_pc };
+
+ nl_msg_put_unspec(request, TCA_SAMPLE_PARMS, &parm, sizeof parm);
+ nl_msg_put_u32(request, TCA_SAMPLE_RATE, rate);
+ nl_msg_put_u32(request, TCA_SAMPLE_PSAMPLE_GROUP, group_id);
+ }
+ nl_msg_end_nested(request, offset);
+}
+
static inline void
nl_msg_put_act_cookie(struct ofpbuf *request, struct tc_cookie *ck) {
if (ck->len) {
@@ -3103,6 +3156,7 @@ get_action_index_for_tc_actions(struct tc_flower *flower,
uint16_t act_index,
case TC_ACT_MPLS_SET:
case TC_ACT_GOTO:
case TC_ACT_CT:
+ case TC_ACT_SAMPLE:
/* Increase act_index by one if we are sure this type of action
* will only add one tc action in the kernel. */
act_index++;
@@ -3310,6 +3364,13 @@ nl_msg_put_flower_acts(struct ofpbuf *request, struct
tc_flower *flower)
nl_msg_end_nested(request, act_offset);
}
break;
+ case TC_ACT_SAMPLE: {
+ act_offset = nl_msg_start_nested(request, act_index++);
+ nl_msg_put_act_sample(request, action->sample.rate,
+ action->sample.group_id, action_pc);
+ nl_msg_end_nested(request, act_offset);
+ }
+ break;
case TC_ACT_OUTPUT: {
if (!released && flower->tunnel) {
nl_msg_put_flower_acts_release(request, act_index++);
diff --git a/lib/tc.h b/lib/tc.h
index cdd3b4f60..5f6e15d5c 100644
--- a/lib/tc.h
+++ b/lib/tc.h
@@ -192,6 +192,7 @@ enum tc_action_type {
TC_ACT_CT,
TC_ACT_POLICE,
TC_ACT_POLICE_MTU,
+ TC_ACT_SAMPLE,
};
enum nat_type {
@@ -283,6 +284,10 @@ struct tc_action {
uint32_t result_jump;
uint16_t mtu;
} police;
+ struct {
+ uint32_t rate;
+ uint32_t group_id;
+ } sample;
};
enum tc_action_type type;
@@ -380,6 +385,7 @@ struct tc_flower {
enum tc_offloaded_state offloaded_state;
/* Used to force skip_hw when probing tc features. */
enum tc_offload_policy tc_policy;
+ uint16_t ifindex;
};
int tc_replace_flower(struct tcf_id *id, struct tc_flower *flower);
--
2.26.3