summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBaowen Zheng <baowen.zheng@corigine.com>2022-09-30 14:07:56 +0800
committerSimon Horman <simon.horman@corigine.com>2022-11-01 10:18:16 +0100
commitffcb6f115fe5e00be3ca8fb9a940a3224e687e23 (patch)
tree2aeb478eabd799933e30218adfee15698d8bca70 /lib
parent743499607bdd0dcb3541a179ba2bb41ea10c4b3b (diff)
downloadopenvswitch-ffcb6f115fe5e00be3ca8fb9a940a3224e687e23.tar.gz
netdev-linux: Allow meter to work in tc software datapath when tc-policy is specified
Add tc action flags when adding police action to offload meter table. There is a restriction that the flag of skip_sw/skip_hw should be same for filter rule and the independent created tc actions the rule uses. In this case, if we configure the tc-policy as skip_hw, filter rule will be created with skip_hw flag and the police action according to meter table will have no action flag, then flower rule will fail to add to tc kernel system. To fix this issue, we will add tc action flag when adding police action to offload a meter table, so it will allow meter table to work in tc software datapath. Fixes: 5c039ddc64ff ("netdev-linux: Add functions to manipulate tc police action") Signed-off-by: Baowen Zheng <baowen.zheng@corigine.com> Acked-by: Ilya Maximets <i.maximets@ovn.org> Signed-off-by: Simon Horman <simon.horman@corigine.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/netdev-linux.c20
-rw-r--r--lib/tc.c21
-rw-r--r--lib/tc.h2
3 files changed, 37 insertions, 6 deletions
diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index cdc66246c..7ea4070c2 100644
--- a/lib/netdev-linux.c
+++ b/lib/netdev-linux.c
@@ -2623,10 +2623,17 @@ tc_matchall_fill_police(uint32_t kbits_rate, uint32_t kbits_burst)
static void
nl_msg_act_police_start_nest(struct ofpbuf *request, uint32_t prio,
- size_t *offset, size_t *act_offset)
+ size_t *offset, size_t *act_offset,
+ bool single_action)
{
*act_offset = nl_msg_start_nested(request, prio);
nl_msg_put_string(request, TCA_ACT_KIND, "police");
+
+ /* If police action is added independently from filter, we need to
+ * add action flag according to tc-policy. */
+ if (single_action) {
+ nl_msg_put_act_tc_policy_flag(request);
+ }
*offset = nl_msg_start_nested(request, TCA_ACT_OPTIONS);
}
@@ -2642,7 +2649,7 @@ nl_msg_act_police_end_nest(struct ofpbuf *request, size_t offset,
static void
nl_msg_put_act_police(struct ofpbuf *request, struct tc_police *police,
uint64_t pkts_rate, uint64_t pkts_burst,
- uint32_t notexceed_act)
+ uint32_t notexceed_act, bool single_action)
{
size_t offset, act_offset;
uint32_t prio = 0;
@@ -2651,7 +2658,8 @@ nl_msg_put_act_police(struct ofpbuf *request, struct tc_police *police,
return;
}
- nl_msg_act_police_start_nest(request, ++prio, &offset, &act_offset);
+ nl_msg_act_police_start_nest(request, ++prio, &offset, &act_offset,
+ single_action);
if (police->rate.rate) {
tc_put_rtab(request, TCA_POLICE_RATE, &police->rate);
}
@@ -2698,7 +2706,7 @@ tc_add_matchall_policer(struct netdev *netdev, uint32_t kbits_rate,
basic_offset = nl_msg_start_nested(&request, TCA_OPTIONS);
action_offset = nl_msg_start_nested(&request, TCA_MATCHALL_ACT);
nl_msg_put_act_police(&request, &pol_act, kpkts_rate * 1000,
- kpkts_burst * 1000, TC_ACT_UNSPEC);
+ kpkts_burst * 1000, TC_ACT_UNSPEC, false);
nl_msg_end_nested(&request, action_offset);
nl_msg_end_nested(&request, basic_offset);
@@ -5667,7 +5675,7 @@ tc_add_policer(struct netdev *netdev, uint32_t kbits_rate,
police_offset = nl_msg_start_nested(&request, TCA_BASIC_ACT);
tc_policer_init(&tc_police, kbits_rate, kbits_burst);
nl_msg_put_act_police(&request, &tc_police, kpkts_rate * 1000ULL,
- kpkts_burst * 1000ULL, TC_ACT_UNSPEC);
+ kpkts_burst * 1000ULL, TC_ACT_UNSPEC, false);
nl_msg_end_nested(&request, police_offset);
nl_msg_end_nested(&request, basic_offset);
@@ -5702,7 +5710,7 @@ tc_add_policer_action(uint32_t index, uint32_t kbits_rate,
offset = nl_msg_start_nested(&request, TCA_ACT_TAB);
nl_msg_put_act_police(&request, &tc_police, pkts_rate, pkts_burst,
- TC_ACT_PIPE);
+ TC_ACT_PIPE, true);
nl_msg_end_nested(&request, offset);
error = tc_transact(&request, NULL);
diff --git a/lib/tc.c b/lib/tc.c
index 3b591975b..4d7de8add 100644
--- a/lib/tc.c
+++ b/lib/tc.c
@@ -3810,3 +3810,24 @@ tc_set_policy(const char *policy)
VLOG_INFO("tc: Using policy '%s'", policy);
}
+
+void
+nl_msg_put_act_tc_policy_flag(struct ofpbuf *request)
+{
+ int flag = 0;
+
+ if (!request) {
+ return;
+ }
+
+ if (tc_policy == TC_POLICY_SKIP_HW) {
+ flag = TCA_ACT_FLAGS_SKIP_HW;
+ } else if (tc_policy == TC_POLICY_SKIP_SW) {
+ flag = TCA_ACT_FLAGS_SKIP_SW;
+ }
+
+ if (flag) {
+ struct nla_bitfield32 flags = { flag, flag };
+ nl_msg_put_unspec(request, TCA_ACT_FLAGS, &flags, sizeof flags);
+ }
+}
diff --git a/lib/tc.h b/lib/tc.h
index 2e64ad372..161f43812 100644
--- a/lib/tc.h
+++ b/lib/tc.h
@@ -399,4 +399,6 @@ int tc_parse_action_stats(struct nlattr *action,
int tc_dump_tc_action_start(char *name, struct nl_dump *dump);
int parse_netlink_to_tc_policer(struct ofpbuf *reply, uint32_t police_idx[]);
+void nl_msg_put_act_tc_policy_flag(struct ofpbuf *request);
+
#endif /* tc.h */