Skip to content

Commit c1b5687

Browse files
Stephen Hemmingerdavem330
authored andcommitted
tc: policing requires a rate estimator
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>
1 parent 71bcb09 commit c1b5687

3 files changed

Lines changed: 34 additions & 3 deletions

File tree

‎include/net/gen_stats.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@ extern void gen_kill_estimator(struct gnet_stats_basic *bstats,
4545
extern int gen_replace_estimator(struct gnet_stats_basic *bstats,
4646
struct gnet_stats_rate_est *rate_est,
4747
spinlock_t *stats_lock, struct nlattr *opt);
48+
extern int gen_estimator_active(const struct gnet_stats_rate_est *rate_est);
4849

4950
#endif

‎net/core/gen_estimator.c‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ int gen_new_estimator(struct gnet_stats_basic *bstats,
242242

243243
return 0;
244244
}
245+
EXPORT_SYMBOL(gen_new_estimator);
245246

246247
static void __gen_kill_estimator(struct rcu_head *head)
247248
{
@@ -275,6 +276,7 @@ void gen_kill_estimator(struct gnet_stats_basic *bstats,
275276
call_rcu(&e->e_rcu, __gen_kill_estimator);
276277
}
277278
}
279+
EXPORT_SYMBOL(gen_kill_estimator);
278280

279281
/**
280282
* gen_replace_estimator - replace rate estimator configuration
@@ -295,8 +297,30 @@ int gen_replace_estimator(struct gnet_stats_basic *bstats,
295297
gen_kill_estimator(bstats, rate_est);
296298
return gen_new_estimator(bstats, rate_est, stats_lock, opt);
297299
}
300+
EXPORT_SYMBOL(gen_replace_estimator);
301+
302+
/**
303+
* gen_estimator_active - test if estimator is currently in use
304+
* @rate_est: rate estimator statistics
305+
*
306+
* Returns 1 if estimator is active, and 0 if not.
307+
*/
308+
int gen_estimator_active(const struct gnet_stats_rate_est *rate_est)
309+
{
310+
int idx;
311+
struct gen_estimator *e;
298312

313+
ASSERT_RTNL();
299314

300-
EXPORT_SYMBOL(gen_kill_estimator);
301-
EXPORT_SYMBOL(gen_new_estimator);
302-
EXPORT_SYMBOL(gen_replace_estimator);
315+
for (idx=0; idx <= EST_MAX_INTERVAL; idx++) {
316+
if (!elist[idx].timer.function)
317+
continue;
318+
319+
list_for_each_entry(e, &elist[idx].list, list) {
320+
if (e->rate_est == rate_est)
321+
return 1;
322+
}
323+
}
324+
return 0;
325+
}
326+
EXPORT_SYMBOL(gen_estimator_active);

‎net/sched/act_police.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ static int tcf_act_police_locate(struct nlattr *nla, struct nlattr *est,
182182
R_tab = qdisc_get_rtab(&parm->rate, tb[TCA_POLICE_RATE]);
183183
if (R_tab == NULL)
184184
goto failure;
185+
186+
if (!est && !gen_estimator_active(&police->tcf_rate_est)) {
187+
err = -EINVAL;
188+
goto failure;
189+
}
190+
185191
if (parm->peakrate.rate) {
186192
P_tab = qdisc_get_rtab(&parm->peakrate,
187193
tb[TCA_POLICE_PEAKRATE]);

0 commit comments

Comments
 (0)