2019-05-27 09:55:01 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* net/sched/sch_gred.c Generic Random Early Detection queue.
|
|
|
|
*
|
|
|
|
* Authors: J Hadi Salim (hadi@cyberus.ca) 1998-2002
|
|
|
|
*
|
|
|
|
* 991129: - Bug fix with grio mode
|
|
|
|
* - a better sing. AvgQ mode with Grio(WRED)
|
2021-05-31 05:00:48 +03:00
|
|
|
* - A finer grained VQ dequeue based on suggestion
|
2005-04-17 02:20:36 +04:00
|
|
|
* from Ren Liu
|
|
|
|
* - More error checks
|
|
|
|
*
|
2005-11-05 23:14:25 +03:00
|
|
|
* For all the glorious comments look at include/net/red.h
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
|
|
|
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/skbuff.h>
|
2018-11-20 02:21:42 +03:00
|
|
|
#include <net/pkt_cls.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <net/pkt_sched.h>
|
2005-11-05 23:14:16 +03:00
|
|
|
#include <net/red.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-11-05 23:14:15 +03:00
|
|
|
#define GRED_DEF_PRIO (MAX_DPs / 2)
|
2005-11-05 23:14:20 +03:00
|
|
|
#define GRED_VQ_MASK (MAX_DPs - 1)
|
2005-11-05 23:14:15 +03:00
|
|
|
|
2018-11-15 09:23:50 +03:00
|
|
|
#define GRED_VQ_RED_FLAGS (TC_RED_ECN | TC_RED_HARDDROP)
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
struct gred_sched_data;
|
|
|
|
struct gred_sched;
|
|
|
|
|
2011-01-19 22:26:56 +03:00
|
|
|
struct gred_sched_data {
|
2005-04-17 02:20:36 +04:00
|
|
|
u32 limit; /* HARD maximal queue length */
|
2011-12-09 06:46:45 +04:00
|
|
|
u32 DP; /* the drop parameters */
|
2018-11-15 09:23:50 +03:00
|
|
|
u32 red_flags; /* virtualQ version of red_flags */
|
2018-11-15 09:23:48 +03:00
|
|
|
u64 bytesin; /* bytes seen on virtualQ so far*/
|
2005-04-17 02:20:36 +04:00
|
|
|
u32 packetsin; /* packets seen on virtualQ so far*/
|
|
|
|
u32 backlog; /* bytes on the virtualQ */
|
2005-11-05 23:14:25 +03:00
|
|
|
u8 prio; /* the prio of this vq */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-11-05 23:14:16 +03:00
|
|
|
struct red_parms parms;
|
2012-01-05 06:25:16 +04:00
|
|
|
struct red_vars vars;
|
2005-11-05 23:14:16 +03:00
|
|
|
struct red_stats stats;
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
2005-11-05 23:14:09 +03:00
|
|
|
enum {
|
|
|
|
GRED_WRED_MODE = 1,
|
2005-11-05 23:14:10 +03:00
|
|
|
GRED_RIO_MODE,
|
2005-11-05 23:14:09 +03:00
|
|
|
};
|
|
|
|
|
2011-01-19 22:26:56 +03:00
|
|
|
struct gred_sched {
|
2005-04-17 02:20:36 +04:00
|
|
|
struct gred_sched_data *tab[MAX_DPs];
|
2005-11-05 23:14:09 +03:00
|
|
|
unsigned long flags;
|
2005-11-05 23:14:27 +03:00
|
|
|
u32 red_flags;
|
2005-11-05 23:14:25 +03:00
|
|
|
u32 DPs;
|
|
|
|
u32 def;
|
2012-01-05 06:25:16 +04:00
|
|
|
struct red_vars wred_set;
|
2021-10-26 13:07:11 +03:00
|
|
|
struct tc_gred_qopt_offload *opt;
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
2005-11-05 23:14:09 +03:00
|
|
|
static inline int gred_wred_mode(struct gred_sched *table)
|
|
|
|
{
|
|
|
|
return test_bit(GRED_WRED_MODE, &table->flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void gred_enable_wred_mode(struct gred_sched *table)
|
|
|
|
{
|
|
|
|
__set_bit(GRED_WRED_MODE, &table->flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void gred_disable_wred_mode(struct gred_sched *table)
|
|
|
|
{
|
|
|
|
__clear_bit(GRED_WRED_MODE, &table->flags);
|
|
|
|
}
|
|
|
|
|
2005-11-05 23:14:10 +03:00
|
|
|
static inline int gred_rio_mode(struct gred_sched *table)
|
|
|
|
{
|
|
|
|
return test_bit(GRED_RIO_MODE, &table->flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void gred_enable_rio_mode(struct gred_sched *table)
|
|
|
|
{
|
|
|
|
__set_bit(GRED_RIO_MODE, &table->flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void gred_disable_rio_mode(struct gred_sched *table)
|
|
|
|
{
|
|
|
|
__clear_bit(GRED_RIO_MODE, &table->flags);
|
|
|
|
}
|
|
|
|
|
2005-11-05 23:14:09 +03:00
|
|
|
static inline int gred_wred_mode_check(struct Qdisc *sch)
|
|
|
|
{
|
|
|
|
struct gred_sched *table = qdisc_priv(sch);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Really ugly O(n^2) but shouldn't be necessary too frequent. */
|
|
|
|
for (i = 0; i < table->DPs; i++) {
|
|
|
|
struct gred_sched_data *q = table->tab[i];
|
|
|
|
int n;
|
|
|
|
|
|
|
|
if (q == NULL)
|
|
|
|
continue;
|
|
|
|
|
2012-09-13 09:22:33 +04:00
|
|
|
for (n = i + 1; n < table->DPs; n++)
|
|
|
|
if (table->tab[n] && table->tab[n]->prio == q->prio)
|
2005-11-05 23:14:09 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-05 23:14:16 +03:00
|
|
|
static inline unsigned int gred_backlog(struct gred_sched *table,
|
|
|
|
struct gred_sched_data *q,
|
|
|
|
struct Qdisc *sch)
|
|
|
|
{
|
|
|
|
if (gred_wred_mode(table))
|
|
|
|
return sch->qstats.backlog;
|
|
|
|
else
|
|
|
|
return q->backlog;
|
|
|
|
}
|
|
|
|
|
2005-11-05 23:14:20 +03:00
|
|
|
static inline u16 tc_index_to_dp(struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
return skb->tc_index & GRED_VQ_MASK;
|
|
|
|
}
|
|
|
|
|
2012-01-05 06:25:16 +04:00
|
|
|
static inline void gred_load_wred_set(const struct gred_sched *table,
|
2005-11-05 23:14:23 +03:00
|
|
|
struct gred_sched_data *q)
|
|
|
|
{
|
2012-01-05 06:25:16 +04:00
|
|
|
q->vars.qavg = table->wred_set.qavg;
|
|
|
|
q->vars.qidlestart = table->wred_set.qidlestart;
|
2005-11-05 23:14:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void gred_store_wred_set(struct gred_sched *table,
|
|
|
|
struct gred_sched_data *q)
|
|
|
|
{
|
2012-01-05 06:25:16 +04:00
|
|
|
table->wred_set.qavg = q->vars.qavg;
|
2012-09-13 09:22:35 +04:00
|
|
|
table->wred_set.qidlestart = q->vars.qidlestart;
|
2005-11-05 23:14:23 +03:00
|
|
|
}
|
|
|
|
|
2018-11-15 09:23:50 +03:00
|
|
|
static int gred_use_ecn(struct gred_sched_data *q)
|
2005-11-05 23:14:27 +03:00
|
|
|
{
|
2018-11-15 09:23:50 +03:00
|
|
|
return q->red_flags & TC_RED_ECN;
|
2005-11-05 23:14:27 +03:00
|
|
|
}
|
|
|
|
|
2018-11-15 09:23:50 +03:00
|
|
|
static int gred_use_harddrop(struct gred_sched_data *q)
|
2005-11-05 23:14:28 +03:00
|
|
|
{
|
2018-11-15 09:23:50 +03:00
|
|
|
return q->red_flags & TC_RED_HARDDROP;
|
2005-11-05 23:14:28 +03:00
|
|
|
}
|
|
|
|
|
2018-11-15 09:23:51 +03:00
|
|
|
static bool gred_per_vq_red_flags_used(struct gred_sched *table)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
/* Local per-vq flags couldn't have been set unless global are 0 */
|
|
|
|
if (table->red_flags)
|
|
|
|
return false;
|
|
|
|
for (i = 0; i < MAX_DPs; i++)
|
|
|
|
if (table->tab[i] && table->tab[i]->red_flags)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-06-22 09:16:49 +03:00
|
|
|
static int gred_enqueue(struct sk_buff *skb, struct Qdisc *sch,
|
|
|
|
struct sk_buff **to_free)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2011-01-19 22:26:56 +03:00
|
|
|
struct gred_sched_data *q = NULL;
|
|
|
|
struct gred_sched *t = qdisc_priv(sch);
|
2005-11-05 23:14:16 +03:00
|
|
|
unsigned long qavg = 0;
|
2005-11-05 23:14:22 +03:00
|
|
|
u16 dp = tc_index_to_dp(skb);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2011-01-19 22:26:56 +03:00
|
|
|
if (dp >= t->DPs || (q = t->tab[dp]) == NULL) {
|
2005-11-05 23:14:21 +03:00
|
|
|
dp = t->def;
|
|
|
|
|
2011-01-19 22:26:56 +03:00
|
|
|
q = t->tab[dp];
|
|
|
|
if (!q) {
|
2005-11-05 23:14:21 +03:00
|
|
|
/* Pass through packets not assigned to a DP
|
|
|
|
* if no default DP has been configured. This
|
|
|
|
* allows for DP flows to be left untouched.
|
|
|
|
*/
|
2015-05-10 05:01:46 +03:00
|
|
|
if (likely(sch->qstats.backlog + qdisc_pkt_len(skb) <=
|
|
|
|
sch->limit))
|
2005-11-05 23:14:21 +03:00
|
|
|
return qdisc_enqueue_tail(skb, sch);
|
|
|
|
else
|
|
|
|
goto drop;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2005-11-05 23:14:21 +03:00
|
|
|
|
2012-01-05 06:25:16 +04:00
|
|
|
/* fix tc_index? --could be controversial but needed for
|
2005-04-17 02:20:36 +04:00
|
|
|
requeueing */
|
2005-11-05 23:14:21 +03:00
|
|
|
skb->tc_index = (skb->tc_index & ~GRED_VQ_MASK) | dp;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2012-09-13 09:22:32 +04:00
|
|
|
/* sum up all the qaves of prios < ours to get the new qave */
|
2005-11-05 23:14:10 +03:00
|
|
|
if (!gred_wred_mode(t) && gred_rio_mode(t)) {
|
2005-11-05 23:14:25 +03:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < t->DPs; i++) {
|
|
|
|
if (t->tab[i] && t->tab[i]->prio < q->prio &&
|
2012-01-05 06:25:16 +04:00
|
|
|
!red_is_idling(&t->tab[i]->vars))
|
|
|
|
qavg += t->tab[i]->vars.qavg;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2005-11-05 23:14:25 +03:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
q->packetsin++;
|
2008-07-20 11:08:27 +04:00
|
|
|
q->bytesin += qdisc_pkt_len(skb);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-11-05 23:14:25 +03:00
|
|
|
if (gred_wred_mode(t))
|
2005-11-05 23:14:23 +03:00
|
|
|
gred_load_wred_set(t, q);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2012-01-05 06:25:16 +04:00
|
|
|
q->vars.qavg = red_calc_qavg(&q->parms,
|
|
|
|
&q->vars,
|
|
|
|
gred_backlog(t, q, sch));
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2012-01-05 06:25:16 +04:00
|
|
|
if (red_is_idling(&q->vars))
|
|
|
|
red_end_of_idle_period(&q->vars);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-11-05 23:14:09 +03:00
|
|
|
if (gred_wred_mode(t))
|
2005-11-05 23:14:23 +03:00
|
|
|
gred_store_wred_set(t, q);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2012-01-05 06:25:16 +04:00
|
|
|
switch (red_action(&q->parms, &q->vars, q->vars.qavg + qavg)) {
|
2011-01-19 22:26:56 +03:00
|
|
|
case RED_DONT_MARK:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RED_PROB_MARK:
|
2014-09-28 22:53:29 +04:00
|
|
|
qdisc_qstats_overlimit(sch);
|
2018-11-15 09:23:50 +03:00
|
|
|
if (!gred_use_ecn(q) || !INET_ECN_set_ce(skb)) {
|
2011-01-19 22:26:56 +03:00
|
|
|
q->stats.prob_drop++;
|
|
|
|
goto congestion_drop;
|
|
|
|
}
|
|
|
|
|
|
|
|
q->stats.prob_mark++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RED_HARD_MARK:
|
2014-09-28 22:53:29 +04:00
|
|
|
qdisc_qstats_overlimit(sch);
|
2018-11-15 09:23:50 +03:00
|
|
|
if (gred_use_harddrop(q) || !gred_use_ecn(q) ||
|
2011-01-19 22:26:56 +03:00
|
|
|
!INET_ECN_set_ce(skb)) {
|
|
|
|
q->stats.forced_drop++;
|
|
|
|
goto congestion_drop;
|
|
|
|
}
|
|
|
|
q->stats.forced_mark++;
|
|
|
|
break;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2005-11-05 23:14:16 +03:00
|
|
|
|
2015-05-10 05:01:47 +03:00
|
|
|
if (gred_backlog(t, q, sch) + qdisc_pkt_len(skb) <= q->limit) {
|
2008-07-20 11:08:27 +04:00
|
|
|
q->backlog += qdisc_pkt_len(skb);
|
2005-11-05 23:14:19 +03:00
|
|
|
return qdisc_enqueue_tail(skb, sch);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2005-11-05 23:14:16 +03:00
|
|
|
|
|
|
|
q->stats.pdrop++;
|
|
|
|
drop:
|
2016-06-22 09:16:49 +03:00
|
|
|
return qdisc_drop(skb, sch, to_free);
|
2005-11-05 23:14:18 +03:00
|
|
|
|
|
|
|
congestion_drop:
|
2016-06-22 09:16:49 +03:00
|
|
|
qdisc_drop(skb, sch, to_free);
|
2005-11-05 23:14:18 +03:00
|
|
|
return NET_XMIT_CN;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2011-01-19 22:26:56 +03:00
|
|
|
static struct sk_buff *gred_dequeue(struct Qdisc *sch)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct sk_buff *skb;
|
2005-11-05 23:14:25 +03:00
|
|
|
struct gred_sched *t = qdisc_priv(sch);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-11-05 23:14:19 +03:00
|
|
|
skb = qdisc_dequeue_head(sch);
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
if (skb) {
|
2005-11-05 23:14:25 +03:00
|
|
|
struct gred_sched_data *q;
|
2005-11-05 23:14:21 +03:00
|
|
|
u16 dp = tc_index_to_dp(skb);
|
|
|
|
|
|
|
|
if (dp >= t->DPs || (q = t->tab[dp]) == NULL) {
|
2012-05-14 01:56:26 +04:00
|
|
|
net_warn_ratelimited("GRED: Unable to relocate VQ 0x%x after dequeue, screwing up backlog\n",
|
|
|
|
tc_index_to_dp(skb));
|
2005-11-05 23:14:21 +03:00
|
|
|
} else {
|
2008-07-20 11:08:27 +04:00
|
|
|
q->backlog -= qdisc_pkt_len(skb);
|
2005-11-05 23:14:21 +03:00
|
|
|
|
2012-09-13 09:22:35 +04:00
|
|
|
if (gred_wred_mode(t)) {
|
|
|
|
if (!sch->qstats.backlog)
|
|
|
|
red_start_of_idle_period(&t->wred_set);
|
|
|
|
} else {
|
|
|
|
if (!q->backlog)
|
|
|
|
red_start_of_idle_period(&q->vars);
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2005-11-05 23:14:21 +03:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
return skb;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-01-19 22:26:56 +03:00
|
|
|
static void gred_reset(struct Qdisc *sch)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
int i;
|
2005-11-05 23:14:25 +03:00
|
|
|
struct gred_sched *t = qdisc_priv(sch);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-11-05 23:14:19 +03:00
|
|
|
qdisc_reset_queue(sch);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2007-02-09 17:25:16 +03:00
|
|
|
for (i = 0; i < t->DPs; i++) {
|
2005-11-05 23:14:25 +03:00
|
|
|
struct gred_sched_data *q = t->tab[i];
|
|
|
|
|
|
|
|
if (!q)
|
|
|
|
continue;
|
|
|
|
|
2012-01-05 06:25:16 +04:00
|
|
|
red_restart(&q->vars);
|
2005-04-17 02:20:36 +04:00
|
|
|
q->backlog = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-20 02:21:42 +03:00
|
|
|
static void gred_offload(struct Qdisc *sch, enum tc_gred_command command)
|
|
|
|
{
|
|
|
|
struct gred_sched *table = qdisc_priv(sch);
|
|
|
|
struct net_device *dev = qdisc_dev(sch);
|
2021-10-26 13:07:11 +03:00
|
|
|
struct tc_gred_qopt_offload *opt = table->opt;
|
2018-11-20 02:21:42 +03:00
|
|
|
|
|
|
|
if (!tc_can_offload(dev) || !dev->netdev_ops->ndo_setup_tc)
|
|
|
|
return;
|
|
|
|
|
2021-10-26 13:07:11 +03:00
|
|
|
memset(opt, 0, sizeof(*opt));
|
|
|
|
opt->command = command;
|
|
|
|
opt->handle = sch->handle;
|
|
|
|
opt->parent = sch->parent;
|
|
|
|
|
2018-11-20 02:21:42 +03:00
|
|
|
if (command == TC_GRED_REPLACE) {
|
|
|
|
unsigned int i;
|
|
|
|
|
2021-10-26 13:07:11 +03:00
|
|
|
opt->set.grio_on = gred_rio_mode(table);
|
|
|
|
opt->set.wred_on = gred_wred_mode(table);
|
|
|
|
opt->set.dp_cnt = table->DPs;
|
|
|
|
opt->set.dp_def = table->def;
|
2018-11-20 02:21:42 +03:00
|
|
|
|
|
|
|
for (i = 0; i < table->DPs; i++) {
|
|
|
|
struct gred_sched_data *q = table->tab[i];
|
|
|
|
|
|
|
|
if (!q)
|
|
|
|
continue;
|
2021-10-26 13:07:11 +03:00
|
|
|
opt->set.tab[i].present = true;
|
|
|
|
opt->set.tab[i].limit = q->limit;
|
|
|
|
opt->set.tab[i].prio = q->prio;
|
|
|
|
opt->set.tab[i].min = q->parms.qth_min >> q->parms.Wlog;
|
|
|
|
opt->set.tab[i].max = q->parms.qth_max >> q->parms.Wlog;
|
|
|
|
opt->set.tab[i].is_ecn = gred_use_ecn(q);
|
|
|
|
opt->set.tab[i].is_harddrop = gred_use_harddrop(q);
|
|
|
|
opt->set.tab[i].probability = q->parms.max_P;
|
|
|
|
opt->set.tab[i].backlog = &q->backlog;
|
2018-11-20 02:21:42 +03:00
|
|
|
}
|
2021-10-26 13:07:11 +03:00
|
|
|
opt->set.qstats = &sch->qstats;
|
2018-11-20 02:21:42 +03:00
|
|
|
}
|
|
|
|
|
2021-10-26 13:07:11 +03:00
|
|
|
dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_QDISC_GRED, opt);
|
2018-11-20 02:21:42 +03:00
|
|
|
}
|
|
|
|
|
2018-11-20 02:21:43 +03:00
|
|
|
static int gred_offload_dump_stats(struct Qdisc *sch)
|
|
|
|
{
|
|
|
|
struct gred_sched *table = qdisc_priv(sch);
|
|
|
|
struct tc_gred_qopt_offload *hw_stats;
|
2021-10-16 11:49:08 +03:00
|
|
|
u64 bytes = 0, packets = 0;
|
2018-11-20 02:21:43 +03:00
|
|
|
unsigned int i;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
hw_stats = kzalloc(sizeof(*hw_stats), GFP_KERNEL);
|
|
|
|
if (!hw_stats)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
hw_stats->command = TC_GRED_STATS;
|
|
|
|
hw_stats->handle = sch->handle;
|
|
|
|
hw_stats->parent = sch->parent;
|
|
|
|
|
2021-10-16 11:49:07 +03:00
|
|
|
for (i = 0; i < MAX_DPs; i++) {
|
2021-10-16 11:49:09 +03:00
|
|
|
gnet_stats_basic_sync_init(&hw_stats->stats.bstats[i]);
|
2018-11-20 02:21:43 +03:00
|
|
|
if (table->tab[i])
|
|
|
|
hw_stats->stats.xstats[i] = &table->tab[i]->stats;
|
2021-10-16 11:49:07 +03:00
|
|
|
}
|
2018-11-20 02:21:43 +03:00
|
|
|
|
|
|
|
ret = qdisc_offload_dump_helper(sch, TC_SETUP_QDISC_GRED, hw_stats);
|
|
|
|
/* Even if driver returns failure adjust the stats - in case offload
|
|
|
|
* ended but driver still wants to adjust the values.
|
|
|
|
*/
|
2023-01-13 07:41:37 +03:00
|
|
|
sch_tree_lock(sch);
|
2018-11-20 02:21:43 +03:00
|
|
|
for (i = 0; i < MAX_DPs; i++) {
|
|
|
|
if (!table->tab[i])
|
|
|
|
continue;
|
2021-10-16 11:49:09 +03:00
|
|
|
table->tab[i]->packetsin += u64_stats_read(&hw_stats->stats.bstats[i].packets);
|
|
|
|
table->tab[i]->bytesin += u64_stats_read(&hw_stats->stats.bstats[i].bytes);
|
2018-11-20 02:21:43 +03:00
|
|
|
table->tab[i]->backlog += hw_stats->stats.qstats[i].backlog;
|
|
|
|
|
2021-10-16 11:49:09 +03:00
|
|
|
bytes += u64_stats_read(&hw_stats->stats.bstats[i].bytes);
|
|
|
|
packets += u64_stats_read(&hw_stats->stats.bstats[i].packets);
|
2018-11-20 02:21:43 +03:00
|
|
|
sch->qstats.qlen += hw_stats->stats.qstats[i].qlen;
|
|
|
|
sch->qstats.backlog += hw_stats->stats.qstats[i].backlog;
|
|
|
|
sch->qstats.drops += hw_stats->stats.qstats[i].drops;
|
|
|
|
sch->qstats.requeues += hw_stats->stats.qstats[i].requeues;
|
|
|
|
sch->qstats.overlimits += hw_stats->stats.qstats[i].overlimits;
|
|
|
|
}
|
2021-10-16 11:49:08 +03:00
|
|
|
_bstats_update(&sch->bstats, bytes, packets);
|
2023-01-13 07:41:37 +03:00
|
|
|
sch_tree_unlock(sch);
|
2018-11-20 02:21:43 +03:00
|
|
|
|
|
|
|
kfree(hw_stats);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-11-05 23:14:13 +03:00
|
|
|
static inline void gred_destroy_vq(struct gred_sched_data *q)
|
|
|
|
{
|
|
|
|
kfree(q);
|
|
|
|
}
|
|
|
|
|
2018-11-15 09:23:47 +03:00
|
|
|
static int gred_change_table_def(struct Qdisc *sch, struct nlattr *dps,
|
|
|
|
struct netlink_ext_ack *extack)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct gred_sched *table = qdisc_priv(sch);
|
|
|
|
struct tc_gred_sopt *sopt;
|
2018-11-15 09:23:50 +03:00
|
|
|
bool red_flags_changed;
|
2005-11-05 23:14:13 +03:00
|
|
|
int i;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2017-12-20 20:35:11 +03:00
|
|
|
if (!dps)
|
2005-04-17 02:20:36 +04:00
|
|
|
return -EINVAL;
|
|
|
|
|
2008-01-23 09:11:17 +03:00
|
|
|
sopt = nla_data(dps);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2018-11-15 09:23:47 +03:00
|
|
|
if (sopt->DPs > MAX_DPs) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "number of virtual queues too high");
|
2005-11-05 23:14:13 +03:00
|
|
|
return -EINVAL;
|
2018-11-15 09:23:47 +03:00
|
|
|
}
|
|
|
|
if (sopt->DPs == 0) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack,
|
|
|
|
"number of virtual queues can't be 0");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
if (sopt->def_DP >= sopt->DPs) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "default virtual queue above virtual queue count");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2018-11-15 09:23:51 +03:00
|
|
|
if (sopt->flags && gred_per_vq_red_flags_used(table)) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "can't set per-Qdisc RED flags when per-virtual queue flags are used");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-11-05 23:14:13 +03:00
|
|
|
sch_tree_lock(sch);
|
|
|
|
table->DPs = sopt->DPs;
|
|
|
|
table->def = sopt->def_DP;
|
2018-11-15 09:23:50 +03:00
|
|
|
red_flags_changed = table->red_flags != sopt->flags;
|
2005-11-05 23:14:27 +03:00
|
|
|
table->red_flags = sopt->flags;
|
2005-11-05 23:14:09 +03:00
|
|
|
|
2005-11-05 23:14:13 +03:00
|
|
|
/*
|
|
|
|
* Every entry point to GRED is synchronized with the above code
|
|
|
|
* and the DP is checked against DPs, i.e. shadowed VQs can no
|
|
|
|
* longer be found so we can unlock right here.
|
|
|
|
*/
|
|
|
|
sch_tree_unlock(sch);
|
2005-11-05 23:14:09 +03:00
|
|
|
|
2005-11-05 23:14:13 +03:00
|
|
|
if (sopt->grio) {
|
|
|
|
gred_enable_rio_mode(table);
|
|
|
|
gred_disable_wred_mode(table);
|
|
|
|
if (gred_wred_mode_check(sch))
|
|
|
|
gred_enable_wred_mode(table);
|
|
|
|
} else {
|
|
|
|
gred_disable_rio_mode(table);
|
|
|
|
gred_disable_wred_mode(table);
|
|
|
|
}
|
|
|
|
|
2018-11-15 09:23:50 +03:00
|
|
|
if (red_flags_changed)
|
|
|
|
for (i = 0; i < table->DPs; i++)
|
|
|
|
if (table->tab[i])
|
|
|
|
table->tab[i]->red_flags =
|
|
|
|
table->red_flags & GRED_VQ_RED_FLAGS;
|
|
|
|
|
2005-11-05 23:14:13 +03:00
|
|
|
for (i = table->DPs; i < MAX_DPs; i++) {
|
|
|
|
if (table->tab[i]) {
|
2013-12-23 13:38:58 +04:00
|
|
|
pr_warn("GRED: Warning: Destroying shadowed VQ 0x%x\n",
|
|
|
|
i);
|
2005-11-05 23:14:13 +03:00
|
|
|
gred_destroy_vq(table->tab[i]);
|
|
|
|
table->tab[i] = NULL;
|
2007-02-09 17:25:16 +03:00
|
|
|
}
|
2005-11-05 23:14:13 +03:00
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2018-11-20 02:21:42 +03:00
|
|
|
gred_offload(sch, TC_GRED_REPLACE);
|
2005-11-05 23:14:13 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-05 23:14:15 +03:00
|
|
|
static inline int gred_change_vq(struct Qdisc *sch, int dp,
|
2011-12-09 06:46:45 +04:00
|
|
|
struct tc_gred_qopt *ctl, int prio,
|
2011-12-16 02:09:45 +04:00
|
|
|
u8 *stab, u32 max_P,
|
2018-11-15 09:23:47 +03:00
|
|
|
struct gred_sched_data **prealloc,
|
|
|
|
struct netlink_ext_ack *extack)
|
2005-11-05 23:14:13 +03:00
|
|
|
{
|
|
|
|
struct gred_sched *table = qdisc_priv(sch);
|
2011-12-16 02:09:45 +04:00
|
|
|
struct gred_sched_data *q = table->tab[dp];
|
2005-11-05 23:14:15 +03:00
|
|
|
|
2021-03-10 19:26:41 +03:00
|
|
|
if (!red_check_params(ctl->qth_min, ctl->qth_max, ctl->Wlog, ctl->Scell_log, stab)) {
|
2018-11-15 09:23:47 +03:00
|
|
|
NL_SET_ERR_MSG_MOD(extack, "invalid RED parameters");
|
2017-12-04 14:31:11 +03:00
|
|
|
return -EINVAL;
|
2018-11-15 09:23:47 +03:00
|
|
|
}
|
2017-12-04 14:31:11 +03:00
|
|
|
|
2011-12-16 02:09:45 +04:00
|
|
|
if (!q) {
|
|
|
|
table->tab[dp] = q = *prealloc;
|
|
|
|
*prealloc = NULL;
|
|
|
|
if (!q)
|
2005-11-05 23:14:15 +03:00
|
|
|
return -ENOMEM;
|
2018-11-15 09:23:50 +03:00
|
|
|
q->red_flags = table->red_flags & GRED_VQ_RED_FLAGS;
|
2005-11-05 23:14:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
q->DP = dp;
|
|
|
|
q->prio = prio;
|
2015-05-10 05:01:46 +03:00
|
|
|
if (ctl->limit > sch->limit)
|
|
|
|
q->limit = sch->limit;
|
|
|
|
else
|
|
|
|
q->limit = ctl->limit;
|
2005-11-05 23:14:16 +03:00
|
|
|
|
|
|
|
if (q->backlog == 0)
|
2012-01-05 06:25:16 +04:00
|
|
|
red_end_of_idle_period(&q->vars);
|
2005-11-05 23:14:16 +03:00
|
|
|
|
|
|
|
red_set_parms(&q->parms,
|
|
|
|
ctl->qth_min, ctl->qth_max, ctl->Wlog, ctl->Plog,
|
2011-12-09 06:46:45 +04:00
|
|
|
ctl->Scell_log, stab, max_P);
|
2012-01-05 06:25:16 +04:00
|
|
|
red_set_vars(&q->vars);
|
2005-11-05 23:14:15 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-15 09:23:51 +03:00
|
|
|
static const struct nla_policy gred_vq_policy[TCA_GRED_VQ_MAX + 1] = {
|
|
|
|
[TCA_GRED_VQ_DP] = { .type = NLA_U32 },
|
|
|
|
[TCA_GRED_VQ_FLAGS] = { .type = NLA_U32 },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct nla_policy gred_vqe_policy[TCA_GRED_VQ_ENTRY_MAX + 1] = {
|
|
|
|
[TCA_GRED_VQ_ENTRY] = { .type = NLA_NESTED },
|
|
|
|
};
|
|
|
|
|
2008-01-24 07:35:39 +03:00
|
|
|
static const struct nla_policy gred_policy[TCA_GRED_MAX + 1] = {
|
|
|
|
[TCA_GRED_PARMS] = { .len = sizeof(struct tc_gred_qopt) },
|
|
|
|
[TCA_GRED_STAB] = { .len = 256 },
|
|
|
|
[TCA_GRED_DPS] = { .len = sizeof(struct tc_gred_sopt) },
|
2011-12-09 06:46:45 +04:00
|
|
|
[TCA_GRED_MAX_P] = { .type = NLA_U32 },
|
2015-05-10 05:01:46 +03:00
|
|
|
[TCA_GRED_LIMIT] = { .type = NLA_U32 },
|
2018-11-15 09:23:51 +03:00
|
|
|
[TCA_GRED_VQ_LIST] = { .type = NLA_NESTED },
|
2008-01-24 07:35:39 +03:00
|
|
|
};
|
|
|
|
|
2018-11-15 09:23:51 +03:00
|
|
|
static void gred_vq_apply(struct gred_sched *table, const struct nlattr *entry)
|
|
|
|
{
|
|
|
|
struct nlattr *tb[TCA_GRED_VQ_MAX + 1];
|
|
|
|
u32 dp;
|
|
|
|
|
netlink: make validation more configurable for future strictness
We currently have two levels of strict validation:
1) liberal (default)
- undefined (type >= max) & NLA_UNSPEC attributes accepted
- attribute length >= expected accepted
- garbage at end of message accepted
2) strict (opt-in)
- NLA_UNSPEC attributes accepted
- attribute length >= expected accepted
Split out parsing strictness into four different options:
* TRAILING - check that there's no trailing data after parsing
attributes (in message or nested)
* MAXTYPE - reject attrs > max known type
* UNSPEC - reject attributes with NLA_UNSPEC policy entries
* STRICT_ATTRS - strictly validate attribute size
The default for future things should be *everything*.
The current *_strict() is a combination of TRAILING and MAXTYPE,
and is renamed to _deprecated_strict().
The current regular parsing has none of this, and is renamed to
*_parse_deprecated().
Additionally it allows us to selectively set one of the new flags
even on old policies. Notably, the UNSPEC flag could be useful in
this case, since it can be arranged (by filling in the policy) to
not be an incompatible userspace ABI change, but would then going
forward prevent forgetting attribute entries. Similar can apply
to the POLICY flag.
We end up with the following renames:
* nla_parse -> nla_parse_deprecated
* nla_parse_strict -> nla_parse_deprecated_strict
* nlmsg_parse -> nlmsg_parse_deprecated
* nlmsg_parse_strict -> nlmsg_parse_deprecated_strict
* nla_parse_nested -> nla_parse_nested_deprecated
* nla_validate_nested -> nla_validate_nested_deprecated
Using spatch, of course:
@@
expression TB, MAX, HEAD, LEN, POL, EXT;
@@
-nla_parse(TB, MAX, HEAD, LEN, POL, EXT)
+nla_parse_deprecated(TB, MAX, HEAD, LEN, POL, EXT)
@@
expression NLH, HDRLEN, TB, MAX, POL, EXT;
@@
-nlmsg_parse(NLH, HDRLEN, TB, MAX, POL, EXT)
+nlmsg_parse_deprecated(NLH, HDRLEN, TB, MAX, POL, EXT)
@@
expression NLH, HDRLEN, TB, MAX, POL, EXT;
@@
-nlmsg_parse_strict(NLH, HDRLEN, TB, MAX, POL, EXT)
+nlmsg_parse_deprecated_strict(NLH, HDRLEN, TB, MAX, POL, EXT)
@@
expression TB, MAX, NLA, POL, EXT;
@@
-nla_parse_nested(TB, MAX, NLA, POL, EXT)
+nla_parse_nested_deprecated(TB, MAX, NLA, POL, EXT)
@@
expression START, MAX, POL, EXT;
@@
-nla_validate_nested(START, MAX, POL, EXT)
+nla_validate_nested_deprecated(START, MAX, POL, EXT)
@@
expression NLH, HDRLEN, MAX, POL, EXT;
@@
-nlmsg_validate(NLH, HDRLEN, MAX, POL, EXT)
+nlmsg_validate_deprecated(NLH, HDRLEN, MAX, POL, EXT)
For this patch, don't actually add the strict, non-renamed versions
yet so that it breaks compile if I get it wrong.
Also, while at it, make nla_validate and nla_parse go down to a
common __nla_validate_parse() function to avoid code duplication.
Ultimately, this allows us to have very strict validation for every
new caller of nla_parse()/nlmsg_parse() etc as re-introduced in the
next patch, while existing things will continue to work as is.
In effect then, this adds fully strict validation for any new command.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-04-26 15:07:28 +03:00
|
|
|
nla_parse_nested_deprecated(tb, TCA_GRED_VQ_MAX, entry,
|
|
|
|
gred_vq_policy, NULL);
|
2018-11-15 09:23:51 +03:00
|
|
|
|
|
|
|
dp = nla_get_u32(tb[TCA_GRED_VQ_DP]);
|
|
|
|
|
|
|
|
if (tb[TCA_GRED_VQ_FLAGS])
|
|
|
|
table->tab[dp]->red_flags = nla_get_u32(tb[TCA_GRED_VQ_FLAGS]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gred_vqs_apply(struct gred_sched *table, struct nlattr *vqs)
|
|
|
|
{
|
|
|
|
const struct nlattr *attr;
|
|
|
|
int rem;
|
|
|
|
|
|
|
|
nla_for_each_nested(attr, vqs, rem) {
|
|
|
|
switch (nla_type(attr)) {
|
|
|
|
case TCA_GRED_VQ_ENTRY:
|
|
|
|
gred_vq_apply(table, attr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int gred_vq_validate(struct gred_sched *table, u32 cdp,
|
|
|
|
const struct nlattr *entry,
|
|
|
|
struct netlink_ext_ack *extack)
|
|
|
|
{
|
|
|
|
struct nlattr *tb[TCA_GRED_VQ_MAX + 1];
|
|
|
|
int err;
|
|
|
|
u32 dp;
|
|
|
|
|
netlink: make validation more configurable for future strictness
We currently have two levels of strict validation:
1) liberal (default)
- undefined (type >= max) & NLA_UNSPEC attributes accepted
- attribute length >= expected accepted
- garbage at end of message accepted
2) strict (opt-in)
- NLA_UNSPEC attributes accepted
- attribute length >= expected accepted
Split out parsing strictness into four different options:
* TRAILING - check that there's no trailing data after parsing
attributes (in message or nested)
* MAXTYPE - reject attrs > max known type
* UNSPEC - reject attributes with NLA_UNSPEC policy entries
* STRICT_ATTRS - strictly validate attribute size
The default for future things should be *everything*.
The current *_strict() is a combination of TRAILING and MAXTYPE,
and is renamed to _deprecated_strict().
The current regular parsing has none of this, and is renamed to
*_parse_deprecated().
Additionally it allows us to selectively set one of the new flags
even on old policies. Notably, the UNSPEC flag could be useful in
this case, since it can be arranged (by filling in the policy) to
not be an incompatible userspace ABI change, but would then going
forward prevent forgetting attribute entries. Similar can apply
to the POLICY flag.
We end up with the following renames:
* nla_parse -> nla_parse_deprecated
* nla_parse_strict -> nla_parse_deprecated_strict
* nlmsg_parse -> nlmsg_parse_deprecated
* nlmsg_parse_strict -> nlmsg_parse_deprecated_strict
* nla_parse_nested -> nla_parse_nested_deprecated
* nla_validate_nested -> nla_validate_nested_deprecated
Using spatch, of course:
@@
expression TB, MAX, HEAD, LEN, POL, EXT;
@@
-nla_parse(TB, MAX, HEAD, LEN, POL, EXT)
+nla_parse_deprecated(TB, MAX, HEAD, LEN, POL, EXT)
@@
expression NLH, HDRLEN, TB, MAX, POL, EXT;
@@
-nlmsg_parse(NLH, HDRLEN, TB, MAX, POL, EXT)
+nlmsg_parse_deprecated(NLH, HDRLEN, TB, MAX, POL, EXT)
@@
expression NLH, HDRLEN, TB, MAX, POL, EXT;
@@
-nlmsg_parse_strict(NLH, HDRLEN, TB, MAX, POL, EXT)
+nlmsg_parse_deprecated_strict(NLH, HDRLEN, TB, MAX, POL, EXT)
@@
expression TB, MAX, NLA, POL, EXT;
@@
-nla_parse_nested(TB, MAX, NLA, POL, EXT)
+nla_parse_nested_deprecated(TB, MAX, NLA, POL, EXT)
@@
expression START, MAX, POL, EXT;
@@
-nla_validate_nested(START, MAX, POL, EXT)
+nla_validate_nested_deprecated(START, MAX, POL, EXT)
@@
expression NLH, HDRLEN, MAX, POL, EXT;
@@
-nlmsg_validate(NLH, HDRLEN, MAX, POL, EXT)
+nlmsg_validate_deprecated(NLH, HDRLEN, MAX, POL, EXT)
For this patch, don't actually add the strict, non-renamed versions
yet so that it breaks compile if I get it wrong.
Also, while at it, make nla_validate and nla_parse go down to a
common __nla_validate_parse() function to avoid code duplication.
Ultimately, this allows us to have very strict validation for every
new caller of nla_parse()/nlmsg_parse() etc as re-introduced in the
next patch, while existing things will continue to work as is.
In effect then, this adds fully strict validation for any new command.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-04-26 15:07:28 +03:00
|
|
|
err = nla_parse_nested_deprecated(tb, TCA_GRED_VQ_MAX, entry,
|
|
|
|
gred_vq_policy, extack);
|
2018-11-15 09:23:51 +03:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (!tb[TCA_GRED_VQ_DP]) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Virtual queue with no index specified");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
dp = nla_get_u32(tb[TCA_GRED_VQ_DP]);
|
|
|
|
if (dp >= table->DPs) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Virtual queue with index out of bounds");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
if (dp != cdp && !table->tab[dp]) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Virtual queue not yet instantiated");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tb[TCA_GRED_VQ_FLAGS]) {
|
|
|
|
u32 red_flags = nla_get_u32(tb[TCA_GRED_VQ_FLAGS]);
|
|
|
|
|
|
|
|
if (table->red_flags && table->red_flags != red_flags) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "can't change per-virtual queue RED flags when per-Qdisc flags are used");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
if (red_flags & ~GRED_VQ_RED_FLAGS) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack,
|
|
|
|
"invalid RED flags specified");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int gred_vqs_validate(struct gred_sched *table, u32 cdp,
|
|
|
|
struct nlattr *vqs, struct netlink_ext_ack *extack)
|
|
|
|
{
|
|
|
|
const struct nlattr *attr;
|
|
|
|
int rem, err;
|
|
|
|
|
netlink: make validation more configurable for future strictness
We currently have two levels of strict validation:
1) liberal (default)
- undefined (type >= max) & NLA_UNSPEC attributes accepted
- attribute length >= expected accepted
- garbage at end of message accepted
2) strict (opt-in)
- NLA_UNSPEC attributes accepted
- attribute length >= expected accepted
Split out parsing strictness into four different options:
* TRAILING - check that there's no trailing data after parsing
attributes (in message or nested)
* MAXTYPE - reject attrs > max known type
* UNSPEC - reject attributes with NLA_UNSPEC policy entries
* STRICT_ATTRS - strictly validate attribute size
The default for future things should be *everything*.
The current *_strict() is a combination of TRAILING and MAXTYPE,
and is renamed to _deprecated_strict().
The current regular parsing has none of this, and is renamed to
*_parse_deprecated().
Additionally it allows us to selectively set one of the new flags
even on old policies. Notably, the UNSPEC flag could be useful in
this case, since it can be arranged (by filling in the policy) to
not be an incompatible userspace ABI change, but would then going
forward prevent forgetting attribute entries. Similar can apply
to the POLICY flag.
We end up with the following renames:
* nla_parse -> nla_parse_deprecated
* nla_parse_strict -> nla_parse_deprecated_strict
* nlmsg_parse -> nlmsg_parse_deprecated
* nlmsg_parse_strict -> nlmsg_parse_deprecated_strict
* nla_parse_nested -> nla_parse_nested_deprecated
* nla_validate_nested -> nla_validate_nested_deprecated
Using spatch, of course:
@@
expression TB, MAX, HEAD, LEN, POL, EXT;
@@
-nla_parse(TB, MAX, HEAD, LEN, POL, EXT)
+nla_parse_deprecated(TB, MAX, HEAD, LEN, POL, EXT)
@@
expression NLH, HDRLEN, TB, MAX, POL, EXT;
@@
-nlmsg_parse(NLH, HDRLEN, TB, MAX, POL, EXT)
+nlmsg_parse_deprecated(NLH, HDRLEN, TB, MAX, POL, EXT)
@@
expression NLH, HDRLEN, TB, MAX, POL, EXT;
@@
-nlmsg_parse_strict(NLH, HDRLEN, TB, MAX, POL, EXT)
+nlmsg_parse_deprecated_strict(NLH, HDRLEN, TB, MAX, POL, EXT)
@@
expression TB, MAX, NLA, POL, EXT;
@@
-nla_parse_nested(TB, MAX, NLA, POL, EXT)
+nla_parse_nested_deprecated(TB, MAX, NLA, POL, EXT)
@@
expression START, MAX, POL, EXT;
@@
-nla_validate_nested(START, MAX, POL, EXT)
+nla_validate_nested_deprecated(START, MAX, POL, EXT)
@@
expression NLH, HDRLEN, MAX, POL, EXT;
@@
-nlmsg_validate(NLH, HDRLEN, MAX, POL, EXT)
+nlmsg_validate_deprecated(NLH, HDRLEN, MAX, POL, EXT)
For this patch, don't actually add the strict, non-renamed versions
yet so that it breaks compile if I get it wrong.
Also, while at it, make nla_validate and nla_parse go down to a
common __nla_validate_parse() function to avoid code duplication.
Ultimately, this allows us to have very strict validation for every
new caller of nla_parse()/nlmsg_parse() etc as re-introduced in the
next patch, while existing things will continue to work as is.
In effect then, this adds fully strict validation for any new command.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-04-26 15:07:28 +03:00
|
|
|
err = nla_validate_nested_deprecated(vqs, TCA_GRED_VQ_ENTRY_MAX,
|
|
|
|
gred_vqe_policy, extack);
|
2018-11-15 09:23:51 +03:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
nla_for_each_nested(attr, vqs, rem) {
|
|
|
|
switch (nla_type(attr)) {
|
|
|
|
case TCA_GRED_VQ_ENTRY:
|
|
|
|
err = gred_vq_validate(table, cdp, attr, extack);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "GRED_VQ_LIST can contain only entry attributes");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rem > 0) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Trailing data after parsing virtual queue list");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-12-20 20:35:14 +03:00
|
|
|
static int gred_change(struct Qdisc *sch, struct nlattr *opt,
|
|
|
|
struct netlink_ext_ack *extack)
|
2005-11-05 23:14:15 +03:00
|
|
|
{
|
|
|
|
struct gred_sched *table = qdisc_priv(sch);
|
2005-11-05 23:14:13 +03:00
|
|
|
struct tc_gred_qopt *ctl;
|
2008-01-23 09:11:17 +03:00
|
|
|
struct nlattr *tb[TCA_GRED_MAX + 1];
|
2008-01-24 07:33:32 +03:00
|
|
|
int err, prio = GRED_DEF_PRIO;
|
2005-11-05 23:14:15 +03:00
|
|
|
u8 *stab;
|
2011-12-09 06:46:45 +04:00
|
|
|
u32 max_P;
|
2011-12-16 02:09:45 +04:00
|
|
|
struct gred_sched_data *prealloc;
|
2005-11-05 23:14:13 +03:00
|
|
|
|
netlink: make validation more configurable for future strictness
We currently have two levels of strict validation:
1) liberal (default)
- undefined (type >= max) & NLA_UNSPEC attributes accepted
- attribute length >= expected accepted
- garbage at end of message accepted
2) strict (opt-in)
- NLA_UNSPEC attributes accepted
- attribute length >= expected accepted
Split out parsing strictness into four different options:
* TRAILING - check that there's no trailing data after parsing
attributes (in message or nested)
* MAXTYPE - reject attrs > max known type
* UNSPEC - reject attributes with NLA_UNSPEC policy entries
* STRICT_ATTRS - strictly validate attribute size
The default for future things should be *everything*.
The current *_strict() is a combination of TRAILING and MAXTYPE,
and is renamed to _deprecated_strict().
The current regular parsing has none of this, and is renamed to
*_parse_deprecated().
Additionally it allows us to selectively set one of the new flags
even on old policies. Notably, the UNSPEC flag could be useful in
this case, since it can be arranged (by filling in the policy) to
not be an incompatible userspace ABI change, but would then going
forward prevent forgetting attribute entries. Similar can apply
to the POLICY flag.
We end up with the following renames:
* nla_parse -> nla_parse_deprecated
* nla_parse_strict -> nla_parse_deprecated_strict
* nlmsg_parse -> nlmsg_parse_deprecated
* nlmsg_parse_strict -> nlmsg_parse_deprecated_strict
* nla_parse_nested -> nla_parse_nested_deprecated
* nla_validate_nested -> nla_validate_nested_deprecated
Using spatch, of course:
@@
expression TB, MAX, HEAD, LEN, POL, EXT;
@@
-nla_parse(TB, MAX, HEAD, LEN, POL, EXT)
+nla_parse_deprecated(TB, MAX, HEAD, LEN, POL, EXT)
@@
expression NLH, HDRLEN, TB, MAX, POL, EXT;
@@
-nlmsg_parse(NLH, HDRLEN, TB, MAX, POL, EXT)
+nlmsg_parse_deprecated(NLH, HDRLEN, TB, MAX, POL, EXT)
@@
expression NLH, HDRLEN, TB, MAX, POL, EXT;
@@
-nlmsg_parse_strict(NLH, HDRLEN, TB, MAX, POL, EXT)
+nlmsg_parse_deprecated_strict(NLH, HDRLEN, TB, MAX, POL, EXT)
@@
expression TB, MAX, NLA, POL, EXT;
@@
-nla_parse_nested(TB, MAX, NLA, POL, EXT)
+nla_parse_nested_deprecated(TB, MAX, NLA, POL, EXT)
@@
expression START, MAX, POL, EXT;
@@
-nla_validate_nested(START, MAX, POL, EXT)
+nla_validate_nested_deprecated(START, MAX, POL, EXT)
@@
expression NLH, HDRLEN, MAX, POL, EXT;
@@
-nlmsg_validate(NLH, HDRLEN, MAX, POL, EXT)
+nlmsg_validate_deprecated(NLH, HDRLEN, MAX, POL, EXT)
For this patch, don't actually add the strict, non-renamed versions
yet so that it breaks compile if I get it wrong.
Also, while at it, make nla_validate and nla_parse go down to a
common __nla_validate_parse() function to avoid code duplication.
Ultimately, this allows us to have very strict validation for every
new caller of nla_parse()/nlmsg_parse() etc as re-introduced in the
next patch, while existing things will continue to work as is.
In effect then, this adds fully strict validation for any new command.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-04-26 15:07:28 +03:00
|
|
|
err = nla_parse_nested_deprecated(tb, TCA_GRED_MAX, opt, gred_policy,
|
|
|
|
extack);
|
2008-01-24 07:33:32 +03:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
2015-05-10 05:01:46 +03:00
|
|
|
if (tb[TCA_GRED_PARMS] == NULL && tb[TCA_GRED_STAB] == NULL) {
|
|
|
|
if (tb[TCA_GRED_LIMIT] != NULL)
|
|
|
|
sch->limit = nla_get_u32(tb[TCA_GRED_LIMIT]);
|
2018-11-15 09:23:47 +03:00
|
|
|
return gred_change_table_def(sch, tb[TCA_GRED_DPS], extack);
|
2015-05-10 05:01:46 +03:00
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2008-01-23 09:11:17 +03:00
|
|
|
if (tb[TCA_GRED_PARMS] == NULL ||
|
2015-05-10 05:01:46 +03:00
|
|
|
tb[TCA_GRED_STAB] == NULL ||
|
2018-11-15 09:23:47 +03:00
|
|
|
tb[TCA_GRED_LIMIT] != NULL) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "can't configure Qdisc and virtual queue at the same time");
|
2005-11-05 23:14:15 +03:00
|
|
|
return -EINVAL;
|
2018-11-15 09:23:47 +03:00
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2011-12-09 06:46:45 +04:00
|
|
|
max_P = tb[TCA_GRED_MAX_P] ? nla_get_u32(tb[TCA_GRED_MAX_P]) : 0;
|
|
|
|
|
2008-01-23 09:11:17 +03:00
|
|
|
ctl = nla_data(tb[TCA_GRED_PARMS]);
|
|
|
|
stab = nla_data(tb[TCA_GRED_STAB]);
|
2005-11-05 23:14:14 +03:00
|
|
|
|
2018-11-15 09:23:47 +03:00
|
|
|
if (ctl->DP >= table->DPs) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "virtual queue index above virtual queue count");
|
2018-11-15 09:23:45 +03:00
|
|
|
return -EINVAL;
|
2018-11-15 09:23:47 +03:00
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2018-11-15 09:23:51 +03:00
|
|
|
if (tb[TCA_GRED_VQ_LIST]) {
|
|
|
|
err = gred_vqs_validate(table, ctl->DP, tb[TCA_GRED_VQ_LIST],
|
|
|
|
extack);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2005-11-05 23:14:10 +03:00
|
|
|
if (gred_rio_mode(table)) {
|
2005-11-05 23:14:15 +03:00
|
|
|
if (ctl->prio == 0) {
|
|
|
|
int def_prio = GRED_DEF_PRIO;
|
|
|
|
|
|
|
|
if (table->tab[table->def])
|
|
|
|
def_prio = table->tab[table->def]->prio;
|
|
|
|
|
|
|
|
printk(KERN_DEBUG "GRED: DP %u does not have a prio "
|
|
|
|
"setting default to %d\n", ctl->DP, def_prio);
|
|
|
|
|
|
|
|
prio = def_prio;
|
|
|
|
} else
|
|
|
|
prio = ctl->prio;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2011-12-16 02:09:45 +04:00
|
|
|
prealloc = kzalloc(sizeof(*prealloc), GFP_KERNEL);
|
2005-11-05 23:14:15 +03:00
|
|
|
sch_tree_lock(sch);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2018-11-15 09:23:47 +03:00
|
|
|
err = gred_change_vq(sch, ctl->DP, ctl, prio, stab, max_P, &prealloc,
|
|
|
|
extack);
|
2005-11-05 23:14:15 +03:00
|
|
|
if (err < 0)
|
2018-11-15 09:23:45 +03:00
|
|
|
goto err_unlock_free;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2018-11-15 09:23:51 +03:00
|
|
|
if (tb[TCA_GRED_VQ_LIST])
|
|
|
|
gred_vqs_apply(table, tb[TCA_GRED_VQ_LIST]);
|
|
|
|
|
2005-11-05 23:14:10 +03:00
|
|
|
if (gred_rio_mode(table)) {
|
2005-11-05 23:14:09 +03:00
|
|
|
gred_disable_wred_mode(table);
|
|
|
|
if (gred_wred_mode_check(sch))
|
|
|
|
gred_enable_wred_mode(table);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2018-11-15 09:23:45 +03:00
|
|
|
sch_tree_unlock(sch);
|
|
|
|
kfree(prealloc);
|
2018-11-20 02:21:42 +03:00
|
|
|
|
|
|
|
gred_offload(sch, TC_GRED_REPLACE);
|
2018-11-15 09:23:45 +03:00
|
|
|
return 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2018-11-15 09:23:45 +03:00
|
|
|
err_unlock_free:
|
2005-11-05 23:14:15 +03:00
|
|
|
sch_tree_unlock(sch);
|
2011-12-16 02:09:45 +04:00
|
|
|
kfree(prealloc);
|
2005-11-05 23:14:15 +03:00
|
|
|
return err;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2017-12-20 20:35:13 +03:00
|
|
|
static int gred_init(struct Qdisc *sch, struct nlattr *opt,
|
|
|
|
struct netlink_ext_ack *extack)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2021-10-26 13:07:11 +03:00
|
|
|
struct gred_sched *table = qdisc_priv(sch);
|
2008-01-23 09:11:17 +03:00
|
|
|
struct nlattr *tb[TCA_GRED_MAX + 1];
|
2008-01-24 07:33:32 +03:00
|
|
|
int err;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2017-12-20 20:35:11 +03:00
|
|
|
if (!opt)
|
2005-04-17 02:20:36 +04:00
|
|
|
return -EINVAL;
|
|
|
|
|
netlink: make validation more configurable for future strictness
We currently have two levels of strict validation:
1) liberal (default)
- undefined (type >= max) & NLA_UNSPEC attributes accepted
- attribute length >= expected accepted
- garbage at end of message accepted
2) strict (opt-in)
- NLA_UNSPEC attributes accepted
- attribute length >= expected accepted
Split out parsing strictness into four different options:
* TRAILING - check that there's no trailing data after parsing
attributes (in message or nested)
* MAXTYPE - reject attrs > max known type
* UNSPEC - reject attributes with NLA_UNSPEC policy entries
* STRICT_ATTRS - strictly validate attribute size
The default for future things should be *everything*.
The current *_strict() is a combination of TRAILING and MAXTYPE,
and is renamed to _deprecated_strict().
The current regular parsing has none of this, and is renamed to
*_parse_deprecated().
Additionally it allows us to selectively set one of the new flags
even on old policies. Notably, the UNSPEC flag could be useful in
this case, since it can be arranged (by filling in the policy) to
not be an incompatible userspace ABI change, but would then going
forward prevent forgetting attribute entries. Similar can apply
to the POLICY flag.
We end up with the following renames:
* nla_parse -> nla_parse_deprecated
* nla_parse_strict -> nla_parse_deprecated_strict
* nlmsg_parse -> nlmsg_parse_deprecated
* nlmsg_parse_strict -> nlmsg_parse_deprecated_strict
* nla_parse_nested -> nla_parse_nested_deprecated
* nla_validate_nested -> nla_validate_nested_deprecated
Using spatch, of course:
@@
expression TB, MAX, HEAD, LEN, POL, EXT;
@@
-nla_parse(TB, MAX, HEAD, LEN, POL, EXT)
+nla_parse_deprecated(TB, MAX, HEAD, LEN, POL, EXT)
@@
expression NLH, HDRLEN, TB, MAX, POL, EXT;
@@
-nlmsg_parse(NLH, HDRLEN, TB, MAX, POL, EXT)
+nlmsg_parse_deprecated(NLH, HDRLEN, TB, MAX, POL, EXT)
@@
expression NLH, HDRLEN, TB, MAX, POL, EXT;
@@
-nlmsg_parse_strict(NLH, HDRLEN, TB, MAX, POL, EXT)
+nlmsg_parse_deprecated_strict(NLH, HDRLEN, TB, MAX, POL, EXT)
@@
expression TB, MAX, NLA, POL, EXT;
@@
-nla_parse_nested(TB, MAX, NLA, POL, EXT)
+nla_parse_nested_deprecated(TB, MAX, NLA, POL, EXT)
@@
expression START, MAX, POL, EXT;
@@
-nla_validate_nested(START, MAX, POL, EXT)
+nla_validate_nested_deprecated(START, MAX, POL, EXT)
@@
expression NLH, HDRLEN, MAX, POL, EXT;
@@
-nlmsg_validate(NLH, HDRLEN, MAX, POL, EXT)
+nlmsg_validate_deprecated(NLH, HDRLEN, MAX, POL, EXT)
For this patch, don't actually add the strict, non-renamed versions
yet so that it breaks compile if I get it wrong.
Also, while at it, make nla_validate and nla_parse go down to a
common __nla_validate_parse() function to avoid code duplication.
Ultimately, this allows us to have very strict validation for every
new caller of nla_parse()/nlmsg_parse() etc as re-introduced in the
next patch, while existing things will continue to work as is.
In effect then, this adds fully strict validation for any new command.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-04-26 15:07:28 +03:00
|
|
|
err = nla_parse_nested_deprecated(tb, TCA_GRED_MAX, opt, gred_policy,
|
|
|
|
extack);
|
2008-01-24 07:33:32 +03:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
2018-11-15 09:23:47 +03:00
|
|
|
if (tb[TCA_GRED_PARMS] || tb[TCA_GRED_STAB]) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack,
|
|
|
|
"virtual queue configuration can't be specified at initialization time");
|
2005-11-05 23:14:13 +03:00
|
|
|
return -EINVAL;
|
2018-11-15 09:23:47 +03:00
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2015-05-10 05:01:46 +03:00
|
|
|
if (tb[TCA_GRED_LIMIT])
|
|
|
|
sch->limit = nla_get_u32(tb[TCA_GRED_LIMIT]);
|
2015-08-18 11:30:49 +03:00
|
|
|
else
|
|
|
|
sch->limit = qdisc_dev(sch)->tx_queue_len
|
|
|
|
* psched_mtu(qdisc_dev(sch));
|
2015-05-10 05:01:46 +03:00
|
|
|
|
2021-10-26 13:07:11 +03:00
|
|
|
if (qdisc_dev(sch)->netdev_ops->ndo_setup_tc) {
|
|
|
|
table->opt = kzalloc(sizeof(*table->opt), GFP_KERNEL);
|
|
|
|
if (!table->opt)
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2018-11-15 09:23:47 +03:00
|
|
|
return gred_change_table_def(sch, tb[TCA_GRED_DPS], extack);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int gred_dump(struct Qdisc *sch, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct gred_sched *table = qdisc_priv(sch);
|
2018-11-15 09:23:49 +03:00
|
|
|
struct nlattr *parms, *vqs, *opts = NULL;
|
2005-04-17 02:20:36 +04:00
|
|
|
int i;
|
2011-12-09 06:46:45 +04:00
|
|
|
u32 max_p[MAX_DPs];
|
2005-11-05 23:14:12 +03:00
|
|
|
struct tc_gred_sopt sopt = {
|
|
|
|
.DPs = table->DPs,
|
|
|
|
.def_DP = table->def,
|
|
|
|
.grio = gred_rio_mode(table),
|
2005-11-05 23:14:27 +03:00
|
|
|
.flags = table->red_flags,
|
2005-11-05 23:14:12 +03:00
|
|
|
};
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2018-11-20 02:21:43 +03:00
|
|
|
if (gred_offload_dump_stats(sch))
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
2019-04-26 12:13:06 +03:00
|
|
|
opts = nla_nest_start_noflag(skb, TCA_OPTIONS);
|
2008-01-23 09:11:17 +03:00
|
|
|
if (opts == NULL)
|
|
|
|
goto nla_put_failure;
|
2012-03-29 13:11:39 +04:00
|
|
|
if (nla_put(skb, TCA_GRED_DPS, sizeof(sopt), &sopt))
|
|
|
|
goto nla_put_failure;
|
2011-12-09 06:46:45 +04:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_DPs; i++) {
|
|
|
|
struct gred_sched_data *q = table->tab[i];
|
|
|
|
|
|
|
|
max_p[i] = q ? q->parms.max_P : 0;
|
|
|
|
}
|
2012-03-29 13:11:39 +04:00
|
|
|
if (nla_put(skb, TCA_GRED_MAX_P, sizeof(max_p), max_p))
|
|
|
|
goto nla_put_failure;
|
2011-12-09 06:46:45 +04:00
|
|
|
|
2015-05-10 05:01:46 +03:00
|
|
|
if (nla_put_u32(skb, TCA_GRED_LIMIT, sch->limit))
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
2018-11-15 09:23:49 +03:00
|
|
|
/* Old style all-in-one dump of VQs */
|
2019-04-26 12:13:06 +03:00
|
|
|
parms = nla_nest_start_noflag(skb, TCA_GRED_PARMS);
|
2008-01-23 09:11:17 +03:00
|
|
|
if (parms == NULL)
|
|
|
|
goto nla_put_failure;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-11-05 23:14:11 +03:00
|
|
|
for (i = 0; i < MAX_DPs; i++) {
|
|
|
|
struct gred_sched_data *q = table->tab[i];
|
|
|
|
struct tc_gred_qopt opt;
|
2012-09-13 09:22:34 +04:00
|
|
|
unsigned long qavg;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-11-05 23:14:11 +03:00
|
|
|
memset(&opt, 0, sizeof(opt));
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (!q) {
|
|
|
|
/* hack -- fix at some point with proper message
|
|
|
|
This is how we indicate to tc that there is no VQ
|
|
|
|
at this DP */
|
|
|
|
|
2005-11-05 23:14:11 +03:00
|
|
|
opt.DP = MAX_DPs + i;
|
|
|
|
goto append_opt;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2005-11-05 23:14:11 +03:00
|
|
|
opt.limit = q->limit;
|
|
|
|
opt.DP = q->DP;
|
2015-05-10 05:01:47 +03:00
|
|
|
opt.backlog = gred_backlog(table, q, sch);
|
2005-11-05 23:14:11 +03:00
|
|
|
opt.prio = q->prio;
|
2005-11-05 23:14:16 +03:00
|
|
|
opt.qth_min = q->parms.qth_min >> q->parms.Wlog;
|
|
|
|
opt.qth_max = q->parms.qth_max >> q->parms.Wlog;
|
|
|
|
opt.Wlog = q->parms.Wlog;
|
|
|
|
opt.Plog = q->parms.Plog;
|
|
|
|
opt.Scell_log = q->parms.Scell_log;
|
|
|
|
opt.early = q->stats.prob_drop;
|
|
|
|
opt.forced = q->stats.forced_drop;
|
|
|
|
opt.pdrop = q->stats.pdrop;
|
2005-11-05 23:14:11 +03:00
|
|
|
opt.packets = q->packetsin;
|
|
|
|
opt.bytesin = q->bytesin;
|
|
|
|
|
2012-04-15 16:31:45 +04:00
|
|
|
if (gred_wred_mode(table))
|
|
|
|
gred_load_wred_set(table, q);
|
2005-11-05 23:14:11 +03:00
|
|
|
|
2012-09-13 09:22:34 +04:00
|
|
|
qavg = red_calc_qavg(&q->parms, &q->vars,
|
|
|
|
q->vars.qavg >> q->parms.Wlog);
|
|
|
|
opt.qave = qavg >> q->parms.Wlog;
|
2005-11-05 23:14:16 +03:00
|
|
|
|
2005-11-05 23:14:11 +03:00
|
|
|
append_opt:
|
2008-01-23 09:11:17 +03:00
|
|
|
if (nla_append(skb, sizeof(opt), &opt) < 0)
|
|
|
|
goto nla_put_failure;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2008-01-23 09:11:17 +03:00
|
|
|
nla_nest_end(skb, parms);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2018-11-15 09:23:49 +03:00
|
|
|
/* Dump the VQs again, in more structured way */
|
2019-04-26 12:13:06 +03:00
|
|
|
vqs = nla_nest_start_noflag(skb, TCA_GRED_VQ_LIST);
|
2018-11-15 09:23:49 +03:00
|
|
|
if (!vqs)
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_DPs; i++) {
|
|
|
|
struct gred_sched_data *q = table->tab[i];
|
|
|
|
struct nlattr *vq;
|
|
|
|
|
|
|
|
if (!q)
|
|
|
|
continue;
|
|
|
|
|
2019-04-26 12:13:06 +03:00
|
|
|
vq = nla_nest_start_noflag(skb, TCA_GRED_VQ_ENTRY);
|
2018-11-15 09:23:49 +03:00
|
|
|
if (!vq)
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
if (nla_put_u32(skb, TCA_GRED_VQ_DP, q->DP))
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
2018-11-15 09:23:51 +03:00
|
|
|
if (nla_put_u32(skb, TCA_GRED_VQ_FLAGS, q->red_flags))
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
2018-11-15 09:23:49 +03:00
|
|
|
/* Stats */
|
|
|
|
if (nla_put_u64_64bit(skb, TCA_GRED_VQ_STAT_BYTES, q->bytesin,
|
|
|
|
TCA_GRED_VQ_PAD))
|
|
|
|
goto nla_put_failure;
|
|
|
|
if (nla_put_u32(skb, TCA_GRED_VQ_STAT_PACKETS, q->packetsin))
|
|
|
|
goto nla_put_failure;
|
|
|
|
if (nla_put_u32(skb, TCA_GRED_VQ_STAT_BACKLOG,
|
|
|
|
gred_backlog(table, q, sch)))
|
|
|
|
goto nla_put_failure;
|
|
|
|
if (nla_put_u32(skb, TCA_GRED_VQ_STAT_PROB_DROP,
|
|
|
|
q->stats.prob_drop))
|
|
|
|
goto nla_put_failure;
|
|
|
|
if (nla_put_u32(skb, TCA_GRED_VQ_STAT_PROB_MARK,
|
|
|
|
q->stats.prob_mark))
|
|
|
|
goto nla_put_failure;
|
|
|
|
if (nla_put_u32(skb, TCA_GRED_VQ_STAT_FORCED_DROP,
|
|
|
|
q->stats.forced_drop))
|
|
|
|
goto nla_put_failure;
|
|
|
|
if (nla_put_u32(skb, TCA_GRED_VQ_STAT_FORCED_MARK,
|
|
|
|
q->stats.forced_mark))
|
|
|
|
goto nla_put_failure;
|
|
|
|
if (nla_put_u32(skb, TCA_GRED_VQ_STAT_PDROP, q->stats.pdrop))
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
nla_nest_end(skb, vq);
|
|
|
|
}
|
|
|
|
nla_nest_end(skb, vqs);
|
|
|
|
|
2008-01-23 09:11:17 +03:00
|
|
|
return nla_nest_end(skb, opts);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2008-01-23 09:11:17 +03:00
|
|
|
nla_put_failure:
|
2008-06-04 03:36:54 +04:00
|
|
|
nla_nest_cancel(skb, opts);
|
|
|
|
return -EMSGSIZE;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void gred_destroy(struct Qdisc *sch)
|
|
|
|
{
|
|
|
|
struct gred_sched *table = qdisc_priv(sch);
|
|
|
|
int i;
|
|
|
|
|
2022-08-31 07:14:52 +03:00
|
|
|
for (i = 0; i < table->DPs; i++)
|
|
|
|
gred_destroy_vq(table->tab[i]);
|
|
|
|
|
2018-11-20 02:21:42 +03:00
|
|
|
gred_offload(sch, TC_GRED_DESTROY);
|
2021-10-26 13:07:11 +03:00
|
|
|
kfree(table->opt);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2007-11-14 12:44:41 +03:00
|
|
|
static struct Qdisc_ops gred_qdisc_ops __read_mostly = {
|
2005-04-17 02:20:36 +04:00
|
|
|
.id = "gred",
|
|
|
|
.priv_size = sizeof(struct gred_sched),
|
|
|
|
.enqueue = gred_enqueue,
|
|
|
|
.dequeue = gred_dequeue,
|
2008-10-31 10:45:55 +03:00
|
|
|
.peek = qdisc_peek_head,
|
2005-04-17 02:20:36 +04:00
|
|
|
.init = gred_init,
|
|
|
|
.reset = gred_reset,
|
|
|
|
.destroy = gred_destroy,
|
|
|
|
.change = gred_change,
|
|
|
|
.dump = gred_dump,
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init gred_module_init(void)
|
|
|
|
{
|
|
|
|
return register_qdisc(&gred_qdisc_ops);
|
|
|
|
}
|
2005-11-05 23:14:25 +03:00
|
|
|
|
|
|
|
static void __exit gred_module_exit(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
unregister_qdisc(&gred_qdisc_ops);
|
|
|
|
}
|
2005-11-05 23:14:25 +03:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
module_init(gred_module_init)
|
|
|
|
module_exit(gred_module_exit)
|
2005-11-05 23:14:25 +03:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
MODULE_LICENSE("GPL");
|