From: Jianbo Liu <[email protected]>

Add function to parse police action from netlink message.

Signed-off-by: Jianbo Liu <[email protected]>
Reviewed-by: Roi Dayan <[email protected]>
---
 lib/tc.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 lib/tc.h |  4 ++++
 2 files changed, 52 insertions(+)

diff --git a/lib/tc.c b/lib/tc.c
index 38a1dfc0ebc8..b351f0e1e65f 100644
--- a/lib/tc.c
+++ b/lib/tc.c
@@ -1341,6 +1341,54 @@ nl_parse_act_gact(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, },
+    [TCA_POLICE_RATE] = { .type = NL_A_UNSPEC,
+                          .min_len = 1024,
+                          .optional = true, },
+    [TCA_POLICE_PEAKRATE] = { .type = NL_A_UNSPEC,
+                              .min_len = 1024,
+                              .optional = true, },
+    [TCA_POLICE_AVRATE] = { .type = NL_A_U32,
+                            .optional = true, },
+    [TCA_POLICE_RESULT] = { .type = NL_A_U32,
+                            .optional = true, },
+    [TCA_POLICE_TM] = { .type = NL_A_UNSPEC,
+                        .min_len = sizeof(struct tcf_t),
+                        .optional = true, },
+};
+
+static int
+nl_parse_act_police(const struct nlattr *options, struct tc_flower *flower)
+{
+    struct nlattr *police_attrs[ARRAY_SIZE(police_policy)] = {};
+    struct tc_action *action;
+    const struct tc_police *police;
+    struct nlattr *police_tm;
+    const struct tcf_t *tm;
+
+    if (!nl_parse_nested(options, police_policy, police_attrs,
+                         ARRAY_SIZE(police_policy))) {
+        VLOG_ERR_RL(&error_rl, "failed to parse police action options");
+        return EPROTO;
+    }
+
+    police = nl_attr_get(police_attrs[TCA_POLICE_TBF]);
+    action = &flower->actions[flower->action_count++];
+    action->type = TC_ACT_POLICE;
+    action->police.index = police->index;
+
+    police_tm = police_attrs[TCA_POLICE_TM];
+    if (police_tm) {
+        tm = nl_attr_get_unspec(police_tm, sizeof *tm);
+        nl_parse_tcf(tm, flower);
+    }
+
+    return 0;
+}
+
 static const struct nl_policy mirred_policy[] = {
     [TCA_MIRRED_PARMS] = { .type = NL_A_UNSPEC,
                            .min_len = sizeof(struct tc_mirred),
diff --git a/lib/tc.h b/lib/tc.h
index a147ca461dc5..85ae5a8908ea 100644
--- a/lib/tc.h
+++ b/lib/tc.h
@@ -174,6 +174,7 @@ enum tc_action_type {
     TC_ACT_MPLS_SET,
     TC_ACT_GOTO,
     TC_ACT_CT,
+    TC_ACT_POLICE,
 };
 
 enum nat_type {
@@ -256,6 +257,9 @@ struct tc_action {
             bool force;
             bool commit;
         } ct;
+        struct {
+            uint32_t index;
+        } police;
      };
 
      enum tc_action_type type;
-- 
2.8.0

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to