tc: policing requires a rate estimator
authorStephen Hemminger <shemminger@vyatta.com>
Wed, 26 Nov 2008 05:14:06 +0000 (21:14 -0800)
committerDavid S. Miller <davem@davemloft.net>
Wed, 26 Nov 2008 05:14:06 +0000 (21:14 -0800)
Found that while trying average rate policing, it was possible to
request average rate policing without a rate estimator. This results
in no policing which is harmless but incorrect.

Since policing could be setup in two steps, need to check
in the kernel.

Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/gen_stats.h
net/core/gen_estimator.c
net/sched/act_police.c

index 8cd8185fa2ed59a320b393d96812c32eb7ab0748..dcf5bfa7d4f1e6724007ce0b21e886387fbbda53 100644 (file)
@@ -45,5 +45,6 @@ extern void gen_kill_estimator(struct gnet_stats_basic *bstats,
 extern int gen_replace_estimator(struct gnet_stats_basic *bstats,
                                 struct gnet_stats_rate_est *rate_est,
                                 spinlock_t *stats_lock, struct nlattr *opt);
+extern int gen_estimator_active(const struct gnet_stats_rate_est *rate_est);
 
 #endif
index 80aa160877e93bf4e4198c4dd4153b3b958784bc..3885550f01876b61dcc0b98594c0284f663b205b 100644 (file)
@@ -242,6 +242,7 @@ int gen_new_estimator(struct gnet_stats_basic *bstats,
 
        return 0;
 }
+EXPORT_SYMBOL(gen_new_estimator);
 
 static void __gen_kill_estimator(struct rcu_head *head)
 {
@@ -275,6 +276,7 @@ void gen_kill_estimator(struct gnet_stats_basic *bstats,
                call_rcu(&e->e_rcu, __gen_kill_estimator);
        }
 }
+EXPORT_SYMBOL(gen_kill_estimator);
 
 /**
  * gen_replace_estimator - replace rate estimator configuration
@@ -295,8 +297,30 @@ int gen_replace_estimator(struct gnet_stats_basic *bstats,
        gen_kill_estimator(bstats, rate_est);
        return gen_new_estimator(bstats, rate_est, stats_lock, opt);
 }
+EXPORT_SYMBOL(gen_replace_estimator);
+
+/**
+ * gen_estimator_active - test if estimator is currently in use
+ * @rate_est: rate estimator statistics
+ *
+ * Returns 1 if estimator is active, and 0 if not.
+ */
+int gen_estimator_active(const struct gnet_stats_rate_est *rate_est)
+{
+       int idx;
+       struct gen_estimator *e;
 
+       ASSERT_RTNL();
 
-EXPORT_SYMBOL(gen_kill_estimator);
-EXPORT_SYMBOL(gen_new_estimator);
-EXPORT_SYMBOL(gen_replace_estimator);
+       for (idx=0; idx <= EST_MAX_INTERVAL; idx++) {
+               if (!elist[idx].timer.function)
+                       continue;
+
+               list_for_each_entry(e, &elist[idx].list, list) {
+                       if (e->rate_est == rate_est)
+                               return 1;
+               }
+       }
+       return 0;
+}
+EXPORT_SYMBOL(gen_estimator_active);
index e19a0261144a9bcc794838c48971a9c7d4b896e2..c39f60cea6ee7d3e2857d0fca56538f0432ff621 100644 (file)
@@ -182,6 +182,12 @@ override:
                R_tab = qdisc_get_rtab(&parm->rate, tb[TCA_POLICE_RATE]);
                if (R_tab == NULL)
                        goto failure;
+
+               if (!est && !gen_estimator_active(&police->tcf_rate_est)) {
+                       err = -EINVAL;
+                       goto failure;
+               }
+
                if (parm->peakrate.rate) {
                        P_tab = qdisc_get_rtab(&parm->peakrate,
                                               tb[TCA_POLICE_PEAKRATE]);