2019-05-19 12:08:20 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2005-04-16 22:20:36 +00:00
|
|
|
/* net/sched/sch_atm.c - ATM VC selection "queueing discipline" */
|
|
|
|
|
|
|
|
/* Written 1998-2000 by Werner Almesberger, EPFL ICA */
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
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 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/init.h>
|
2011-06-06 10:43:46 +00:00
|
|
|
#include <linux/interrupt.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/atmdev.h>
|
|
|
|
#include <linux/atmclip.h>
|
|
|
|
#include <linux/rtnetlink.h>
|
2007-07-15 07:01:25 +00:00
|
|
|
#include <linux/file.h> /* for fput */
|
2007-03-26 06:06:12 +00:00
|
|
|
#include <net/netlink.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <net/pkt_sched.h>
|
2017-02-09 13:38:56 +00:00
|
|
|
#include <net/pkt_cls.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The ATM queuing discipline provides a framework for invoking classifiers
|
|
|
|
* (aka "filters"), which in turn select classes of this queuing discipline.
|
|
|
|
* Each class maps the flow(s) it is handling to a given VC. Multiple classes
|
|
|
|
* may share the same VC.
|
|
|
|
*
|
|
|
|
* When creating a class, VCs are specified by passing the number of the open
|
|
|
|
* socket descriptor by which the calling process references the VC. The kernel
|
|
|
|
* keeps the VC open at least until all classes using it are removed.
|
|
|
|
*
|
|
|
|
* In this file, most functions are named atm_tc_* to avoid confusion with all
|
|
|
|
* the atm_* in net/atm. This naming convention differs from what's used in the
|
|
|
|
* rest of net/sched.
|
|
|
|
*
|
|
|
|
* Known bugs:
|
|
|
|
* - sometimes messes up the IP stack
|
|
|
|
* - any manipulations besides the few operations described in the README, are
|
|
|
|
* untested and likely to crash the system
|
|
|
|
* - should lock the flow while there is data in the queue (?)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define VCC2FLOW(vcc) ((struct atm_flow_data *) ((vcc)->user_back))
|
|
|
|
|
|
|
|
struct atm_flow_data {
|
2017-08-04 12:28:56 +00:00
|
|
|
struct Qdisc_class_common common;
|
2007-07-15 07:01:25 +00:00
|
|
|
struct Qdisc *q; /* FIFO, TBF, etc. */
|
2014-09-13 03:05:27 +00:00
|
|
|
struct tcf_proto __rcu *filter_list;
|
2017-05-17 09:07:55 +00:00
|
|
|
struct tcf_block *block;
|
2007-07-15 07:01:25 +00:00
|
|
|
struct atm_vcc *vcc; /* VCC; NULL if VCC is closed */
|
|
|
|
void (*old_pop)(struct atm_vcc *vcc,
|
2008-01-21 10:25:29 +00:00
|
|
|
struct sk_buff *skb); /* chaining */
|
2005-04-16 22:20:36 +00:00
|
|
|
struct atm_qdisc_data *parent; /* parent qdisc */
|
|
|
|
struct socket *sock; /* for closing */
|
|
|
|
int ref; /* reference count */
|
2009-08-16 09:36:49 +00:00
|
|
|
struct gnet_stats_basic_packed bstats;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct gnet_stats_queue qstats;
|
2010-07-19 02:52:55 +00:00
|
|
|
struct list_head list;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct atm_flow_data *excess; /* flow for excess traffic;
|
|
|
|
NULL to set CLP instead */
|
|
|
|
int hdr_len;
|
2020-02-27 20:58:44 +00:00
|
|
|
unsigned char hdr[]; /* header data; MUST BE LAST */
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct atm_qdisc_data {
|
|
|
|
struct atm_flow_data link; /* unclassified skbs go here */
|
2010-07-19 02:52:55 +00:00
|
|
|
struct list_head flows; /* NB: "link" is also on this
|
2005-04-16 22:20:36 +00:00
|
|
|
list */
|
2008-11-14 06:56:30 +00:00
|
|
|
struct tasklet_struct task; /* dequeue tasklet */
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* ------------------------- Class/flow operations ------------------------- */
|
|
|
|
|
2007-07-15 07:01:25 +00:00
|
|
|
static inline struct atm_flow_data *lookup_flow(struct Qdisc *sch, u32 classid)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-01-21 10:25:29 +00:00
|
|
|
struct atm_qdisc_data *p = qdisc_priv(sch);
|
2005-04-16 22:20:36 +00:00
|
|
|
struct atm_flow_data *flow;
|
|
|
|
|
2010-07-19 02:52:55 +00:00
|
|
|
list_for_each_entry(flow, &p->flows, list) {
|
2017-08-04 12:28:56 +00:00
|
|
|
if (flow->common.classid == classid)
|
2010-07-19 02:52:55 +00:00
|
|
|
return flow;
|
|
|
|
}
|
|
|
|
return NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-07-15 07:01:25 +00:00
|
|
|
static int atm_tc_graft(struct Qdisc *sch, unsigned long arg,
|
2017-12-20 17:35:17 +00:00
|
|
|
struct Qdisc *new, struct Qdisc **old,
|
|
|
|
struct netlink_ext_ack *extack)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-01-21 10:25:29 +00:00
|
|
|
struct atm_qdisc_data *p = qdisc_priv(sch);
|
2007-07-15 07:01:25 +00:00
|
|
|
struct atm_flow_data *flow = (struct atm_flow_data *)arg;
|
|
|
|
|
2008-01-21 10:25:29 +00:00
|
|
|
pr_debug("atm_tc_graft(sch %p,[qdisc %p],flow %p,new %p,old %p)\n",
|
2007-07-15 07:01:25 +00:00
|
|
|
sch, p, flow, new, old);
|
2010-07-19 02:52:55 +00:00
|
|
|
if (list_empty(&flow->list))
|
2007-07-15 07:01:25 +00:00
|
|
|
return -EINVAL;
|
|
|
|
if (!new)
|
|
|
|
new = &noop_qdisc;
|
2008-11-20 12:11:36 +00:00
|
|
|
*old = flow->q;
|
|
|
|
flow->q = new;
|
2007-07-15 07:01:25 +00:00
|
|
|
if (*old)
|
|
|
|
qdisc_reset(*old);
|
2007-02-09 14:25:16 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2007-07-15 07:01:25 +00:00
|
|
|
static struct Qdisc *atm_tc_leaf(struct Qdisc *sch, unsigned long cl)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2007-07-15 07:01:25 +00:00
|
|
|
struct atm_flow_data *flow = (struct atm_flow_data *)cl;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-01-21 10:25:29 +00:00
|
|
|
pr_debug("atm_tc_leaf(sch %p,flow %p)\n", sch, flow);
|
2005-04-16 22:20:36 +00:00
|
|
|
return flow ? flow->q : NULL;
|
|
|
|
}
|
|
|
|
|
net_sched: remove tc class reference counting
For TC classes, their ->get() and ->put() are always paired, and the
reference counting is completely useless, because:
1) For class modification and dumping paths, we already hold RTNL lock,
so all of these ->get(),->change(),->put() are atomic.
2) For filter bindiing/unbinding, we use other reference counter than
this one, and they should have RTNL lock too.
3) For ->qlen_notify(), it is special because it is called on ->enqueue()
path, but we already hold qdisc tree lock there, and we hold this
tree lock when graft or delete the class too, so it should not be gone
or changed until we release the tree lock.
Therefore, this patch removes ->get() and ->put(), but:
1) Adds a new ->find() to find the pointer to a class by classid, no
refcnt.
2) Move the original class destroy upon the last refcnt into ->delete(),
right after releasing tree lock. This is fine because the class is
already removed from hash when holding the lock.
For those who also use ->put() as ->unbind(), just rename them to reflect
this change.
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-08-24 23:51:29 +00:00
|
|
|
static unsigned long atm_tc_find(struct Qdisc *sch, u32 classid)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-01-21 10:25:29 +00:00
|
|
|
struct atm_qdisc_data *p __maybe_unused = qdisc_priv(sch);
|
2005-04-16 22:20:36 +00:00
|
|
|
struct atm_flow_data *flow;
|
|
|
|
|
net_sched: remove tc class reference counting
For TC classes, their ->get() and ->put() are always paired, and the
reference counting is completely useless, because:
1) For class modification and dumping paths, we already hold RTNL lock,
so all of these ->get(),->change(),->put() are atomic.
2) For filter bindiing/unbinding, we use other reference counter than
this one, and they should have RTNL lock too.
3) For ->qlen_notify(), it is special because it is called on ->enqueue()
path, but we already hold qdisc tree lock there, and we hold this
tree lock when graft or delete the class too, so it should not be gone
or changed until we release the tree lock.
Therefore, this patch removes ->get() and ->put(), but:
1) Adds a new ->find() to find the pointer to a class by classid, no
refcnt.
2) Move the original class destroy upon the last refcnt into ->delete(),
right after releasing tree lock. This is fine because the class is
already removed from hash when holding the lock.
For those who also use ->put() as ->unbind(), just rename them to reflect
this change.
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-08-24 23:51:29 +00:00
|
|
|
pr_debug("%s(sch %p,[qdisc %p],classid %x)\n", __func__, sch, p, classid);
|
2007-07-15 07:01:25 +00:00
|
|
|
flow = lookup_flow(sch, classid);
|
net_sched: remove tc class reference counting
For TC classes, their ->get() and ->put() are always paired, and the
reference counting is completely useless, because:
1) For class modification and dumping paths, we already hold RTNL lock,
so all of these ->get(),->change(),->put() are atomic.
2) For filter bindiing/unbinding, we use other reference counter than
this one, and they should have RTNL lock too.
3) For ->qlen_notify(), it is special because it is called on ->enqueue()
path, but we already hold qdisc tree lock there, and we hold this
tree lock when graft or delete the class too, so it should not be gone
or changed until we release the tree lock.
Therefore, this patch removes ->get() and ->put(), but:
1) Adds a new ->find() to find the pointer to a class by classid, no
refcnt.
2) Move the original class destroy upon the last refcnt into ->delete(),
right after releasing tree lock. This is fine because the class is
already removed from hash when holding the lock.
For those who also use ->put() as ->unbind(), just rename them to reflect
this change.
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-08-24 23:51:29 +00:00
|
|
|
pr_debug("%s: flow %p\n", __func__, flow);
|
2007-07-15 07:01:25 +00:00
|
|
|
return (unsigned long)flow;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long atm_tc_bind_filter(struct Qdisc *sch,
|
2007-07-15 07:01:25 +00:00
|
|
|
unsigned long parent, u32 classid)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
net_sched: remove tc class reference counting
For TC classes, their ->get() and ->put() are always paired, and the
reference counting is completely useless, because:
1) For class modification and dumping paths, we already hold RTNL lock,
so all of these ->get(),->change(),->put() are atomic.
2) For filter bindiing/unbinding, we use other reference counter than
this one, and they should have RTNL lock too.
3) For ->qlen_notify(), it is special because it is called on ->enqueue()
path, but we already hold qdisc tree lock there, and we hold this
tree lock when graft or delete the class too, so it should not be gone
or changed until we release the tree lock.
Therefore, this patch removes ->get() and ->put(), but:
1) Adds a new ->find() to find the pointer to a class by classid, no
refcnt.
2) Move the original class destroy upon the last refcnt into ->delete(),
right after releasing tree lock. This is fine because the class is
already removed from hash when holding the lock.
For those who also use ->put() as ->unbind(), just rename them to reflect
this change.
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-08-24 23:51:29 +00:00
|
|
|
struct atm_qdisc_data *p __maybe_unused = qdisc_priv(sch);
|
|
|
|
struct atm_flow_data *flow;
|
|
|
|
|
|
|
|
pr_debug("%s(sch %p,[qdisc %p],classid %x)\n", __func__, sch, p, classid);
|
|
|
|
flow = lookup_flow(sch, classid);
|
|
|
|
if (flow)
|
|
|
|
flow->ref++;
|
|
|
|
pr_debug("%s: flow %p\n", __func__, flow);
|
|
|
|
return (unsigned long)flow;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* atm_tc_put handles all destructions, including the ones that are explicitly
|
|
|
|
* requested (atm_tc_destroy, etc.). The assumption here is that we never drop
|
|
|
|
* anything that still seems to be in use.
|
|
|
|
*/
|
|
|
|
static void atm_tc_put(struct Qdisc *sch, unsigned long cl)
|
|
|
|
{
|
2008-01-21 10:25:29 +00:00
|
|
|
struct atm_qdisc_data *p = qdisc_priv(sch);
|
2007-07-15 07:01:25 +00:00
|
|
|
struct atm_flow_data *flow = (struct atm_flow_data *)cl;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-01-21 10:25:29 +00:00
|
|
|
pr_debug("atm_tc_put(sch %p,[qdisc %p],flow %p)\n", sch, p, flow);
|
2007-07-15 07:01:25 +00:00
|
|
|
if (--flow->ref)
|
|
|
|
return;
|
2008-01-21 10:25:29 +00:00
|
|
|
pr_debug("atm_tc_put: destroying\n");
|
2010-07-19 02:52:55 +00:00
|
|
|
list_del_init(&flow->list);
|
2008-01-21 10:25:29 +00:00
|
|
|
pr_debug("atm_tc_put: qdisc %p\n", flow->q);
|
2018-09-24 16:22:50 +00:00
|
|
|
qdisc_put(flow->q);
|
2017-05-17 09:07:55 +00:00
|
|
|
tcf_block_put(flow->block);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (flow->sock) {
|
2008-07-26 04:39:17 +00:00
|
|
|
pr_debug("atm_tc_put: f_count %ld\n",
|
2007-07-15 07:01:25 +00:00
|
|
|
file_count(flow->sock->file));
|
2005-04-16 22:20:36 +00:00
|
|
|
flow->vcc->pop = flow->old_pop;
|
|
|
|
sockfd_put(flow->sock);
|
|
|
|
}
|
2007-07-15 07:01:25 +00:00
|
|
|
if (flow->excess)
|
|
|
|
atm_tc_put(sch, (unsigned long)flow->excess);
|
|
|
|
if (flow != &p->link)
|
|
|
|
kfree(flow);
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* If flow == &p->link, the qdisc no longer works at this point and
|
|
|
|
* needs to be removed. (By the caller of atm_tc_put.)
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2007-07-15 07:01:25 +00:00
|
|
|
static void sch_atm_pop(struct atm_vcc *vcc, struct sk_buff *skb)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct atm_qdisc_data *p = VCC2FLOW(vcc)->parent;
|
|
|
|
|
2008-01-21 10:25:29 +00:00
|
|
|
pr_debug("sch_atm_pop(vcc %p,skb %p,[qdisc %p])\n", vcc, skb, p);
|
2007-07-15 07:01:25 +00:00
|
|
|
VCC2FLOW(vcc)->old_pop(vcc, skb);
|
2005-04-16 22:20:36 +00:00
|
|
|
tasklet_schedule(&p->task);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const u8 llc_oui_ip[] = {
|
2007-07-15 07:01:25 +00:00
|
|
|
0xaa, /* DSAP: non-ISO */
|
|
|
|
0xaa, /* SSAP: non-ISO */
|
|
|
|
0x03, /* Ctrl: Unnumbered Information Command PDU */
|
|
|
|
0x00, /* OUI: EtherType */
|
2005-04-16 22:20:36 +00:00
|
|
|
0x00, 0x00,
|
2007-07-15 07:01:25 +00:00
|
|
|
0x08, 0x00
|
|
|
|
}; /* Ethertype IP (0800) */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-01-24 04:35:39 +00:00
|
|
|
static const struct nla_policy atm_policy[TCA_ATM_MAX + 1] = {
|
|
|
|
[TCA_ATM_FD] = { .type = NLA_U32 },
|
|
|
|
[TCA_ATM_EXCESS] = { .type = NLA_U32 },
|
|
|
|
};
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent,
|
2017-12-20 17:35:15 +00:00
|
|
|
struct nlattr **tca, unsigned long *arg,
|
|
|
|
struct netlink_ext_ack *extack)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-01-21 10:25:29 +00:00
|
|
|
struct atm_qdisc_data *p = qdisc_priv(sch);
|
2007-07-15 07:01:25 +00:00
|
|
|
struct atm_flow_data *flow = (struct atm_flow_data *)*arg;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct atm_flow_data *excess = NULL;
|
2008-01-23 06:11:17 +00:00
|
|
|
struct nlattr *opt = tca[TCA_OPTIONS];
|
|
|
|
struct nlattr *tb[TCA_ATM_MAX + 1];
|
2005-04-16 22:20:36 +00:00
|
|
|
struct socket *sock;
|
2007-07-15 07:01:25 +00:00
|
|
|
int fd, error, hdr_len;
|
2005-04-16 22:20:36 +00:00
|
|
|
void *hdr;
|
|
|
|
|
2008-01-21 10:25:29 +00:00
|
|
|
pr_debug("atm_tc_change(sch %p,[qdisc %p],classid %x,parent %x,"
|
2007-07-15 07:01:25 +00:00
|
|
|
"flow %p,opt %p)\n", sch, p, classid, parent, flow, opt);
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* The concept of parents doesn't apply for this qdisc.
|
|
|
|
*/
|
|
|
|
if (parent && parent != TC_H_ROOT && parent != sch->handle)
|
|
|
|
return -EINVAL;
|
|
|
|
/*
|
|
|
|
* ATM classes cannot be changed. In order to change properties of the
|
|
|
|
* ATM connection, that socket needs to be modified directly (via the
|
|
|
|
* native ATM API. In order to send a flow to a different VC, the old
|
|
|
|
* class needs to be removed and a new one added. (This may be changed
|
|
|
|
* later.)
|
|
|
|
*/
|
2007-07-15 07:01:25 +00:00
|
|
|
if (flow)
|
|
|
|
return -EBUSY;
|
2008-01-24 04:33:32 +00:00
|
|
|
if (opt == NULL)
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
2008-01-24 04:35:39 +00: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 12:07:28 +00:00
|
|
|
error = nla_parse_nested_deprecated(tb, TCA_ATM_MAX, opt, atm_policy,
|
|
|
|
NULL);
|
2008-01-24 04:33:32 +00:00
|
|
|
if (error < 0)
|
|
|
|
return error;
|
|
|
|
|
2008-01-24 04:35:39 +00:00
|
|
|
if (!tb[TCA_ATM_FD])
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
2008-01-24 04:35:03 +00:00
|
|
|
fd = nla_get_u32(tb[TCA_ATM_FD]);
|
2008-01-21 10:25:29 +00:00
|
|
|
pr_debug("atm_tc_change: fd %d\n", fd);
|
2008-01-23 06:11:17 +00:00
|
|
|
if (tb[TCA_ATM_HDR]) {
|
|
|
|
hdr_len = nla_len(tb[TCA_ATM_HDR]);
|
|
|
|
hdr = nla_data(tb[TCA_ATM_HDR]);
|
2007-07-15 07:01:25 +00:00
|
|
|
} else {
|
2005-04-16 22:20:36 +00:00
|
|
|
hdr_len = RFC1483LLC_LEN;
|
2007-07-15 07:01:25 +00:00
|
|
|
hdr = NULL; /* default LLC/SNAP for IP */
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2008-01-23 06:11:17 +00:00
|
|
|
if (!tb[TCA_ATM_EXCESS])
|
2007-07-15 07:01:25 +00:00
|
|
|
excess = NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
else {
|
2007-07-15 07:01:25 +00:00
|
|
|
excess = (struct atm_flow_data *)
|
net_sched: remove tc class reference counting
For TC classes, their ->get() and ->put() are always paired, and the
reference counting is completely useless, because:
1) For class modification and dumping paths, we already hold RTNL lock,
so all of these ->get(),->change(),->put() are atomic.
2) For filter bindiing/unbinding, we use other reference counter than
this one, and they should have RTNL lock too.
3) For ->qlen_notify(), it is special because it is called on ->enqueue()
path, but we already hold qdisc tree lock there, and we hold this
tree lock when graft or delete the class too, so it should not be gone
or changed until we release the tree lock.
Therefore, this patch removes ->get() and ->put(), but:
1) Adds a new ->find() to find the pointer to a class by classid, no
refcnt.
2) Move the original class destroy upon the last refcnt into ->delete(),
right after releasing tree lock. This is fine because the class is
already removed from hash when holding the lock.
For those who also use ->put() as ->unbind(), just rename them to reflect
this change.
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-08-24 23:51:29 +00:00
|
|
|
atm_tc_find(sch, nla_get_u32(tb[TCA_ATM_EXCESS]));
|
2007-07-15 07:01:25 +00:00
|
|
|
if (!excess)
|
|
|
|
return -ENOENT;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2008-01-24 04:32:06 +00:00
|
|
|
pr_debug("atm_tc_change: type %d, payload %d, hdr_len %d\n",
|
2008-01-23 06:11:17 +00:00
|
|
|
opt->nla_type, nla_len(opt), hdr_len);
|
2008-01-21 10:25:29 +00:00
|
|
|
sock = sockfd_lookup(fd, &error);
|
|
|
|
if (!sock)
|
2007-07-15 07:01:25 +00:00
|
|
|
return error; /* f_count++ */
|
2008-07-26 04:39:17 +00:00
|
|
|
pr_debug("atm_tc_change: f_count %ld\n", file_count(sock->file));
|
2007-02-09 14:25:16 +00:00
|
|
|
if (sock->ops->family != PF_ATMSVC && sock->ops->family != PF_ATMPVC) {
|
2005-04-16 22:20:36 +00:00
|
|
|
error = -EPROTOTYPE;
|
2007-02-09 14:25:16 +00:00
|
|
|
goto err_out;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
/* @@@ should check if the socket is really operational or we'll crash
|
|
|
|
on vcc->send */
|
|
|
|
if (classid) {
|
|
|
|
if (TC_H_MAJ(classid ^ sch->handle)) {
|
2008-01-21 10:25:29 +00:00
|
|
|
pr_debug("atm_tc_change: classid mismatch\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
error = -EINVAL;
|
|
|
|
goto err_out;
|
|
|
|
}
|
2007-07-15 07:01:25 +00:00
|
|
|
} else {
|
2005-04-16 22:20:36 +00:00
|
|
|
int i;
|
|
|
|
unsigned long cl;
|
|
|
|
|
|
|
|
for (i = 1; i < 0x8000; i++) {
|
2007-07-15 07:01:25 +00:00
|
|
|
classid = TC_H_MAKE(sch->handle, 0x8000 | i);
|
net_sched: remove tc class reference counting
For TC classes, their ->get() and ->put() are always paired, and the
reference counting is completely useless, because:
1) For class modification and dumping paths, we already hold RTNL lock,
so all of these ->get(),->change(),->put() are atomic.
2) For filter bindiing/unbinding, we use other reference counter than
this one, and they should have RTNL lock too.
3) For ->qlen_notify(), it is special because it is called on ->enqueue()
path, but we already hold qdisc tree lock there, and we hold this
tree lock when graft or delete the class too, so it should not be gone
or changed until we release the tree lock.
Therefore, this patch removes ->get() and ->put(), but:
1) Adds a new ->find() to find the pointer to a class by classid, no
refcnt.
2) Move the original class destroy upon the last refcnt into ->delete(),
right after releasing tree lock. This is fine because the class is
already removed from hash when holding the lock.
For those who also use ->put() as ->unbind(), just rename them to reflect
this change.
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-08-24 23:51:29 +00:00
|
|
|
cl = atm_tc_find(sch, classid);
|
2008-01-21 10:25:29 +00:00
|
|
|
if (!cl)
|
2007-07-15 07:01:25 +00:00
|
|
|
break;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-21 10:25:29 +00:00
|
|
|
pr_debug("atm_tc_change: new id %x\n", classid);
|
2007-07-17 01:30:36 +00:00
|
|
|
flow = kzalloc(sizeof(struct atm_flow_data) + hdr_len, GFP_KERNEL);
|
2008-01-21 10:25:29 +00:00
|
|
|
pr_debug("atm_tc_change: flow %p\n", flow);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!flow) {
|
|
|
|
error = -ENOBUFS;
|
|
|
|
goto err_out;
|
|
|
|
}
|
2017-05-17 09:07:55 +00:00
|
|
|
|
2017-12-20 17:35:19 +00:00
|
|
|
error = tcf_block_get(&flow->block, &flow->filter_list, sch,
|
|
|
|
extack);
|
2017-05-17 09:07:55 +00:00
|
|
|
if (error) {
|
|
|
|
kfree(flow);
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
2017-12-20 17:35:21 +00:00
|
|
|
flow->q = qdisc_create_dflt(sch->dev_queue, &pfifo_qdisc_ops, classid,
|
|
|
|
extack);
|
2008-01-21 10:25:29 +00:00
|
|
|
if (!flow->q)
|
2005-04-16 22:20:36 +00:00
|
|
|
flow->q = &noop_qdisc;
|
2008-01-21 10:25:29 +00:00
|
|
|
pr_debug("atm_tc_change: qdisc %p\n", flow->q);
|
2005-04-16 22:20:36 +00:00
|
|
|
flow->sock = sock;
|
2007-07-15 07:01:25 +00:00
|
|
|
flow->vcc = ATM_SD(sock); /* speedup */
|
2005-04-16 22:20:36 +00:00
|
|
|
flow->vcc->user_back = flow;
|
2008-01-21 10:25:29 +00:00
|
|
|
pr_debug("atm_tc_change: vcc %p\n", flow->vcc);
|
2005-04-16 22:20:36 +00:00
|
|
|
flow->old_pop = flow->vcc->pop;
|
|
|
|
flow->parent = p;
|
|
|
|
flow->vcc->pop = sch_atm_pop;
|
2017-08-04 12:28:56 +00:00
|
|
|
flow->common.classid = classid;
|
2005-04-16 22:20:36 +00:00
|
|
|
flow->ref = 1;
|
|
|
|
flow->excess = excess;
|
2010-07-19 02:52:55 +00:00
|
|
|
list_add(&flow->list, &p->link.list);
|
2005-04-16 22:20:36 +00:00
|
|
|
flow->hdr_len = hdr_len;
|
|
|
|
if (hdr)
|
2007-07-15 07:01:25 +00:00
|
|
|
memcpy(flow->hdr, hdr, hdr_len);
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
2007-07-15 07:01:25 +00:00
|
|
|
memcpy(flow->hdr, llc_oui_ip, sizeof(llc_oui_ip));
|
|
|
|
*arg = (unsigned long)flow;
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
err_out:
|
|
|
|
sockfd_put(sock);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2007-07-15 07:01:25 +00:00
|
|
|
static int atm_tc_delete(struct Qdisc *sch, unsigned long arg)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-01-21 10:25:29 +00:00
|
|
|
struct atm_qdisc_data *p = qdisc_priv(sch);
|
2007-07-15 07:01:25 +00:00
|
|
|
struct atm_flow_data *flow = (struct atm_flow_data *)arg;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-01-21 10:25:29 +00:00
|
|
|
pr_debug("atm_tc_delete(sch %p,[qdisc %p],flow %p)\n", sch, p, flow);
|
2010-07-19 02:52:55 +00:00
|
|
|
if (list_empty(&flow->list))
|
2007-07-15 07:01:25 +00:00
|
|
|
return -EINVAL;
|
2014-09-13 03:05:27 +00:00
|
|
|
if (rcu_access_pointer(flow->filter_list) || flow == &p->link)
|
2007-07-15 07:01:25 +00:00
|
|
|
return -EBUSY;
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Reference count must be 2: one for "keepalive" (set at class
|
|
|
|
* creation), and one for the reference held when calling delete.
|
|
|
|
*/
|
|
|
|
if (flow->ref < 2) {
|
2011-01-19 19:26:56 +00:00
|
|
|
pr_err("atm_tc_delete: flow->ref == %d\n", flow->ref);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2007-07-15 07:01:25 +00:00
|
|
|
if (flow->ref > 2)
|
|
|
|
return -EBUSY; /* catch references via excess, etc. */
|
|
|
|
atm_tc_put(sch, arg);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-15 07:01:25 +00:00
|
|
|
static void atm_tc_walk(struct Qdisc *sch, struct qdisc_walker *walker)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-01-21 10:25:29 +00:00
|
|
|
struct atm_qdisc_data *p = qdisc_priv(sch);
|
2005-04-16 22:20:36 +00:00
|
|
|
struct atm_flow_data *flow;
|
|
|
|
|
2008-01-21 10:25:29 +00:00
|
|
|
pr_debug("atm_tc_walk(sch %p,[qdisc %p],walker %p)\n", sch, p, walker);
|
2007-07-15 07:01:25 +00:00
|
|
|
if (walker->stop)
|
|
|
|
return;
|
2010-07-19 02:52:55 +00:00
|
|
|
list_for_each_entry(flow, &p->flows, list) {
|
|
|
|
if (walker->count >= walker->skip &&
|
|
|
|
walker->fn(sch, (unsigned long)flow, walker) < 0) {
|
|
|
|
walker->stop = 1;
|
|
|
|
break;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
walker->count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-20 17:35:16 +00:00
|
|
|
static struct tcf_block *atm_tc_tcf_block(struct Qdisc *sch, unsigned long cl,
|
|
|
|
struct netlink_ext_ack *extack)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-01-21 10:25:29 +00:00
|
|
|
struct atm_qdisc_data *p = qdisc_priv(sch);
|
2007-07-15 07:01:25 +00:00
|
|
|
struct atm_flow_data *flow = (struct atm_flow_data *)cl;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-01-21 10:25:29 +00:00
|
|
|
pr_debug("atm_tc_find_tcf(sch %p,[qdisc %p],flow %p)\n", sch, p, flow);
|
2017-05-17 09:07:55 +00:00
|
|
|
return flow ? flow->block : p->link.block;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------- Qdisc operations ---------------------------- */
|
|
|
|
|
2020-07-14 17:03:08 +00:00
|
|
|
static int atm_tc_enqueue(struct sk_buff *skb, struct Qdisc *sch,
|
2016-06-22 06:16:49 +00:00
|
|
|
struct sk_buff **to_free)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-01-21 10:25:29 +00:00
|
|
|
struct atm_qdisc_data *p = qdisc_priv(sch);
|
2010-07-19 02:52:55 +00:00
|
|
|
struct atm_flow_data *flow;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct tcf_result res;
|
|
|
|
int result;
|
2016-06-11 10:46:04 +00:00
|
|
|
int ret = NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-01-21 10:25:29 +00:00
|
|
|
pr_debug("atm_tc_enqueue(skb %p,sch %p,[qdisc %p])\n", skb, sch, p);
|
2016-06-13 17:47:43 +00:00
|
|
|
result = TC_ACT_OK; /* be nice to gcc */
|
2010-07-19 02:52:55 +00:00
|
|
|
flow = NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (TC_H_MAJ(skb->priority) != sch->handle ||
|
net_sched: remove tc class reference counting
For TC classes, their ->get() and ->put() are always paired, and the
reference counting is completely useless, because:
1) For class modification and dumping paths, we already hold RTNL lock,
so all of these ->get(),->change(),->put() are atomic.
2) For filter bindiing/unbinding, we use other reference counter than
this one, and they should have RTNL lock too.
3) For ->qlen_notify(), it is special because it is called on ->enqueue()
path, but we already hold qdisc tree lock there, and we hold this
tree lock when graft or delete the class too, so it should not be gone
or changed until we release the tree lock.
Therefore, this patch removes ->get() and ->put(), but:
1) Adds a new ->find() to find the pointer to a class by classid, no
refcnt.
2) Move the original class destroy upon the last refcnt into ->delete(),
right after releasing tree lock. This is fine because the class is
already removed from hash when holding the lock.
For those who also use ->put() as ->unbind(), just rename them to reflect
this change.
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-08-24 23:51:29 +00:00
|
|
|
!(flow = (struct atm_flow_data *)atm_tc_find(sch, skb->priority))) {
|
2014-09-13 03:05:27 +00:00
|
|
|
struct tcf_proto *fl;
|
|
|
|
|
2010-07-19 02:52:55 +00:00
|
|
|
list_for_each_entry(flow, &p->flows, list) {
|
2014-09-13 03:05:27 +00:00
|
|
|
fl = rcu_dereference_bh(flow->filter_list);
|
|
|
|
if (fl) {
|
2017-05-17 09:07:54 +00:00
|
|
|
result = tcf_classify(skb, fl, &res, true);
|
2007-07-15 07:01:25 +00:00
|
|
|
if (result < 0)
|
|
|
|
continue;
|
|
|
|
flow = (struct atm_flow_data *)res.class;
|
|
|
|
if (!flow)
|
|
|
|
flow = lookup_flow(sch, res.classid);
|
2010-07-19 02:52:55 +00:00
|
|
|
goto done;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2010-07-19 02:52:55 +00:00
|
|
|
}
|
|
|
|
flow = NULL;
|
2011-01-19 19:26:56 +00:00
|
|
|
done:
|
|
|
|
;
|
2010-07-19 02:52:55 +00:00
|
|
|
}
|
2011-01-19 19:26:56 +00:00
|
|
|
if (!flow) {
|
2007-07-15 07:01:25 +00:00
|
|
|
flow = &p->link;
|
2011-01-19 19:26:56 +00:00
|
|
|
} else {
|
2005-04-16 22:20:36 +00:00
|
|
|
if (flow->vcc)
|
|
|
|
ATM_SKB(skb)->atm_options = flow->vcc->atm_options;
|
2007-07-15 07:01:25 +00:00
|
|
|
/*@@@ looks good ... but it's not supposed to work :-) */
|
2007-07-15 07:01:49 +00:00
|
|
|
#ifdef CONFIG_NET_CLS_ACT
|
|
|
|
switch (result) {
|
|
|
|
case TC_ACT_QUEUED:
|
|
|
|
case TC_ACT_STOLEN:
|
2017-06-06 12:12:02 +00:00
|
|
|
case TC_ACT_TRAP:
|
2016-06-22 06:16:49 +00:00
|
|
|
__qdisc_drop(skb, to_free);
|
2008-08-05 05:31:03 +00:00
|
|
|
return NET_XMIT_SUCCESS | __NET_XMIT_STOLEN;
|
2007-07-15 07:01:49 +00:00
|
|
|
case TC_ACT_SHOT:
|
2016-06-22 06:16:49 +00:00
|
|
|
__qdisc_drop(skb, to_free);
|
2007-07-15 07:01:49 +00:00
|
|
|
goto drop;
|
2016-06-13 17:47:43 +00:00
|
|
|
case TC_ACT_RECLASSIFY:
|
2007-07-15 07:02:31 +00:00
|
|
|
if (flow->excess)
|
|
|
|
flow = flow->excess;
|
|
|
|
else
|
|
|
|
ATM_SKB(skb)->atm_options |= ATM_ATMOPT_CLP;
|
|
|
|
break;
|
2007-07-15 07:01:49 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
|
|
|
}
|
2007-07-15 07:03:05 +00:00
|
|
|
|
2020-07-14 17:03:08 +00:00
|
|
|
ret = qdisc_enqueue(skb, flow->q, to_free);
|
2010-08-10 08:45:40 +00:00
|
|
|
if (ret != NET_XMIT_SUCCESS) {
|
2007-07-15 07:01:49 +00:00
|
|
|
drop: __maybe_unused
|
2008-08-05 05:31:03 +00:00
|
|
|
if (net_xmit_drop_count(ret)) {
|
2014-09-28 18:53:29 +00:00
|
|
|
qdisc_qstats_drop(sch);
|
2008-08-05 05:31:03 +00:00
|
|
|
if (flow)
|
|
|
|
flow->qstats.drops++;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Okay, this may seem weird. We pretend we've dropped the packet if
|
|
|
|
* it goes via ATM. The reason for this is that the outer qdisc
|
|
|
|
* expects to be able to q->dequeue the packet later on if we return
|
|
|
|
* success at this place. Also, sch->q.qdisc needs to reflect whether
|
|
|
|
* there is a packet egligible for dequeuing or not. Note that the
|
|
|
|
* statistics of the outer qdisc are necessarily wrong because of all
|
|
|
|
* this. There's currently no correct solution for this.
|
|
|
|
*/
|
|
|
|
if (flow == &p->link) {
|
|
|
|
sch->q.qlen++;
|
2010-08-10 08:45:40 +00:00
|
|
|
return NET_XMIT_SUCCESS;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
tasklet_schedule(&p->task);
|
2008-08-05 05:39:11 +00:00
|
|
|
return NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dequeue packets and send them over ATM. Note that we quite deliberately
|
|
|
|
* avoid checking net_device's flow control here, simply because sch_atm
|
|
|
|
* uses its own channels, which have nothing to do with any CLIP/LANE/or
|
|
|
|
* non-ATM interfaces.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void sch_atm_dequeue(unsigned long data)
|
|
|
|
{
|
2007-07-15 07:01:25 +00:00
|
|
|
struct Qdisc *sch = (struct Qdisc *)data;
|
2008-01-21 10:25:29 +00:00
|
|
|
struct atm_qdisc_data *p = qdisc_priv(sch);
|
2005-04-16 22:20:36 +00:00
|
|
|
struct atm_flow_data *flow;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
|
2008-01-21 10:25:29 +00:00
|
|
|
pr_debug("sch_atm_dequeue(sch %p,[qdisc %p])\n", sch, p);
|
2010-07-19 02:52:55 +00:00
|
|
|
list_for_each_entry(flow, &p->flows, list) {
|
|
|
|
if (flow == &p->link)
|
|
|
|
continue;
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* If traffic is properly shaped, this won't generate nasty
|
|
|
|
* little bursts. Otherwise, it may ... (but that's okay)
|
|
|
|
*/
|
2008-10-31 07:46:19 +00:00
|
|
|
while ((skb = flow->q->ops->peek(flow->q))) {
|
|
|
|
if (!atm_may_send(flow->vcc, skb->truesize))
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
2008-10-31 07:46:19 +00:00
|
|
|
|
2008-10-31 07:47:01 +00:00
|
|
|
skb = qdisc_dequeue_peeked(flow->q);
|
2008-10-31 07:46:19 +00:00
|
|
|
if (unlikely(!skb))
|
|
|
|
break;
|
|
|
|
|
2012-05-10 05:36:34 +00:00
|
|
|
qdisc_bstats_update(sch, skb);
|
|
|
|
bstats_update(&flow->bstats, skb);
|
2008-01-21 10:25:29 +00:00
|
|
|
pr_debug("atm_tc_dequeue: sending on class %p\n", flow);
|
2005-04-16 22:20:36 +00:00
|
|
|
/* remove any LL header somebody else has attached */
|
2007-04-21 05:47:35 +00:00
|
|
|
skb_pull(skb, skb_network_offset(skb));
|
2005-04-16 22:20:36 +00:00
|
|
|
if (skb_headroom(skb) < flow->hdr_len) {
|
|
|
|
struct sk_buff *new;
|
|
|
|
|
2007-07-15 07:01:25 +00:00
|
|
|
new = skb_realloc_headroom(skb, flow->hdr_len);
|
2005-04-16 22:20:36 +00:00
|
|
|
dev_kfree_skb(skb);
|
2007-07-15 07:01:25 +00:00
|
|
|
if (!new)
|
|
|
|
continue;
|
2005-04-16 22:20:36 +00:00
|
|
|
skb = new;
|
|
|
|
}
|
2008-01-21 10:25:29 +00:00
|
|
|
pr_debug("sch_atm_dequeue: ip %p, data %p\n",
|
2007-04-21 05:47:35 +00:00
|
|
|
skb_network_header(skb), skb->data);
|
2005-04-16 22:20:36 +00:00
|
|
|
ATM_SKB(skb)->vcc = flow->vcc;
|
2007-07-15 07:01:25 +00:00
|
|
|
memcpy(skb_push(skb, flow->hdr_len), flow->hdr,
|
|
|
|
flow->hdr_len);
|
2017-06-30 10:08:00 +00:00
|
|
|
refcount_add(skb->truesize,
|
2005-04-16 22:20:36 +00:00
|
|
|
&sk_atm(flow->vcc)->sk_wmem_alloc);
|
|
|
|
/* atm.atm_options are already set by atm_tc_enqueue */
|
2007-07-15 07:01:25 +00:00
|
|
|
flow->vcc->send(flow->vcc, skb);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2010-07-19 02:52:55 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct sk_buff *atm_tc_dequeue(struct Qdisc *sch)
|
|
|
|
{
|
2008-01-21 10:25:29 +00:00
|
|
|
struct atm_qdisc_data *p = qdisc_priv(sch);
|
2005-04-16 22:20:36 +00:00
|
|
|
struct sk_buff *skb;
|
|
|
|
|
2008-01-21 10:25:29 +00:00
|
|
|
pr_debug("atm_tc_dequeue(sch %p,[qdisc %p])\n", sch, p);
|
2005-04-16 22:20:36 +00:00
|
|
|
tasklet_schedule(&p->task);
|
2008-10-31 07:47:01 +00:00
|
|
|
skb = qdisc_dequeue_peeked(p->link.q);
|
2007-07-15 07:01:25 +00:00
|
|
|
if (skb)
|
|
|
|
sch->q.qlen--;
|
2005-04-16 22:20:36 +00:00
|
|
|
return skb;
|
|
|
|
}
|
|
|
|
|
2008-10-31 07:45:55 +00:00
|
|
|
static struct sk_buff *atm_tc_peek(struct Qdisc *sch)
|
|
|
|
{
|
|
|
|
struct atm_qdisc_data *p = qdisc_priv(sch);
|
|
|
|
|
|
|
|
pr_debug("atm_tc_peek(sch %p,[qdisc %p])\n", sch, p);
|
|
|
|
|
|
|
|
return p->link.q->ops->peek(p->link.q);
|
|
|
|
}
|
|
|
|
|
2017-12-20 17:35:13 +00:00
|
|
|
static int atm_tc_init(struct Qdisc *sch, struct nlattr *opt,
|
|
|
|
struct netlink_ext_ack *extack)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-01-21 10:25:29 +00:00
|
|
|
struct atm_qdisc_data *p = qdisc_priv(sch);
|
2017-05-17 09:07:55 +00:00
|
|
|
int err;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-01-21 10:25:29 +00:00
|
|
|
pr_debug("atm_tc_init(sch %p,[qdisc %p],opt %p)\n", sch, p, opt);
|
2010-07-19 02:52:55 +00:00
|
|
|
INIT_LIST_HEAD(&p->flows);
|
|
|
|
INIT_LIST_HEAD(&p->link.list);
|
|
|
|
list_add(&p->link.list, &p->flows);
|
2010-10-16 13:04:08 +00:00
|
|
|
p->link.q = qdisc_create_dflt(sch->dev_queue,
|
2017-12-20 17:35:21 +00:00
|
|
|
&pfifo_qdisc_ops, sch->handle, extack);
|
2008-01-21 10:25:29 +00:00
|
|
|
if (!p->link.q)
|
2005-04-16 22:20:36 +00:00
|
|
|
p->link.q = &noop_qdisc;
|
2008-01-21 10:25:29 +00:00
|
|
|
pr_debug("atm_tc_init: link (%p) qdisc %p\n", &p->link, p->link.q);
|
2020-07-09 03:13:59 +00:00
|
|
|
p->link.vcc = NULL;
|
|
|
|
p->link.sock = NULL;
|
|
|
|
p->link.common.classid = sch->handle;
|
|
|
|
p->link.ref = 1;
|
2017-05-17 09:07:55 +00:00
|
|
|
|
2017-12-20 17:35:19 +00:00
|
|
|
err = tcf_block_get(&p->link.block, &p->link.filter_list, sch,
|
|
|
|
extack);
|
2017-05-17 09:07:55 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2007-07-15 07:01:25 +00:00
|
|
|
tasklet_init(&p->task, sch_atm_dequeue, (unsigned long)sch);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void atm_tc_reset(struct Qdisc *sch)
|
|
|
|
{
|
2008-01-21 10:25:29 +00:00
|
|
|
struct atm_qdisc_data *p = qdisc_priv(sch);
|
2005-04-16 22:20:36 +00:00
|
|
|
struct atm_flow_data *flow;
|
|
|
|
|
2008-01-21 10:25:29 +00:00
|
|
|
pr_debug("atm_tc_reset(sch %p,[qdisc %p])\n", sch, p);
|
2010-07-19 02:52:55 +00:00
|
|
|
list_for_each_entry(flow, &p->flows, list)
|
2007-07-15 07:01:25 +00:00
|
|
|
qdisc_reset(flow->q);
|
2005-04-16 22:20:36 +00:00
|
|
|
sch->q.qlen = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void atm_tc_destroy(struct Qdisc *sch)
|
|
|
|
{
|
2008-01-21 10:25:29 +00:00
|
|
|
struct atm_qdisc_data *p = qdisc_priv(sch);
|
2010-07-19 02:52:55 +00:00
|
|
|
struct atm_flow_data *flow, *tmp;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-01-21 10:25:29 +00:00
|
|
|
pr_debug("atm_tc_destroy(sch %p,[qdisc %p])\n", sch, p);
|
2017-08-15 13:35:21 +00:00
|
|
|
list_for_each_entry(flow, &p->flows, list) {
|
2017-05-17 09:07:55 +00:00
|
|
|
tcf_block_put(flow->block);
|
2017-08-15 13:35:21 +00:00
|
|
|
flow->block = NULL;
|
|
|
|
}
|
2008-07-02 02:53:09 +00:00
|
|
|
|
2010-07-19 02:52:55 +00:00
|
|
|
list_for_each_entry_safe(flow, tmp, &p->flows, list) {
|
2005-04-16 22:20:36 +00:00
|
|
|
if (flow->ref > 1)
|
2011-01-19 19:26:56 +00:00
|
|
|
pr_err("atm_destroy: %p->ref = %d\n", flow, flow->ref);
|
2007-07-15 07:01:25 +00:00
|
|
|
atm_tc_put(sch, (unsigned long)flow);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
tasklet_kill(&p->task);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int atm_tc_dump_class(struct Qdisc *sch, unsigned long cl,
|
2007-07-15 07:01:25 +00:00
|
|
|
struct sk_buff *skb, struct tcmsg *tcm)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-01-21 10:25:29 +00:00
|
|
|
struct atm_qdisc_data *p = qdisc_priv(sch);
|
2007-07-15 07:01:25 +00:00
|
|
|
struct atm_flow_data *flow = (struct atm_flow_data *)cl;
|
2008-01-24 04:34:11 +00:00
|
|
|
struct nlattr *nest;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-01-21 10:25:29 +00:00
|
|
|
pr_debug("atm_tc_dump_class(sch %p,[qdisc %p],flow %p,skb %p,tcm %p)\n",
|
2007-07-15 07:01:25 +00:00
|
|
|
sch, p, flow, skb, tcm);
|
2010-07-19 02:52:55 +00:00
|
|
|
if (list_empty(&flow->list))
|
2007-07-15 07:01:25 +00:00
|
|
|
return -EINVAL;
|
2017-08-04 12:28:56 +00:00
|
|
|
tcm->tcm_handle = flow->common.classid;
|
2006-03-21 03:01:06 +00:00
|
|
|
tcm->tcm_info = flow->q->handle;
|
2008-01-24 04:34:11 +00:00
|
|
|
|
2019-04-26 09:13:06 +00:00
|
|
|
nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
|
2008-01-24 04:34:11 +00:00
|
|
|
if (nest == NULL)
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
2012-03-29 09:11:39 +00:00
|
|
|
if (nla_put(skb, TCA_ATM_HDR, flow->hdr_len, flow->hdr))
|
|
|
|
goto nla_put_failure;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (flow->vcc) {
|
|
|
|
struct sockaddr_atmpvc pvc;
|
|
|
|
int state;
|
|
|
|
|
2013-07-30 10:23:39 +00:00
|
|
|
memset(&pvc, 0, sizeof(pvc));
|
2005-04-16 22:20:36 +00:00
|
|
|
pvc.sap_family = AF_ATMPVC;
|
|
|
|
pvc.sap_addr.itf = flow->vcc->dev ? flow->vcc->dev->number : -1;
|
|
|
|
pvc.sap_addr.vpi = flow->vcc->vpi;
|
|
|
|
pvc.sap_addr.vci = flow->vcc->vci;
|
2012-03-29 09:11:39 +00:00
|
|
|
if (nla_put(skb, TCA_ATM_ADDR, sizeof(pvc), &pvc))
|
|
|
|
goto nla_put_failure;
|
2005-04-16 22:20:36 +00:00
|
|
|
state = ATM_VF2VS(flow->vcc->flags);
|
2012-03-29 09:11:39 +00:00
|
|
|
if (nla_put_u32(skb, TCA_ATM_STATE, state))
|
|
|
|
goto nla_put_failure;
|
|
|
|
}
|
|
|
|
if (flow->excess) {
|
2017-08-04 12:28:56 +00:00
|
|
|
if (nla_put_u32(skb, TCA_ATM_EXCESS, flow->common.classid))
|
2012-03-29 09:11:39 +00:00
|
|
|
goto nla_put_failure;
|
|
|
|
} else {
|
|
|
|
if (nla_put_u32(skb, TCA_ATM_EXCESS, 0))
|
|
|
|
goto nla_put_failure;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2014-03-12 02:20:32 +00:00
|
|
|
return nla_nest_end(skb, nest);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-01-23 06:11:17 +00:00
|
|
|
nla_put_failure:
|
2008-01-24 04:34:11 +00:00
|
|
|
nla_nest_cancel(skb, nest);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
static int
|
|
|
|
atm_tc_dump_class_stats(struct Qdisc *sch, unsigned long arg,
|
2007-07-15 07:01:25 +00:00
|
|
|
struct gnet_dump *d)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2007-07-15 07:01:25 +00:00
|
|
|
struct atm_flow_data *flow = (struct atm_flow_data *)arg;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2016-06-06 16:37:16 +00:00
|
|
|
if (gnet_stats_copy_basic(qdisc_root_sleeping_running(sch),
|
|
|
|
d, NULL, &flow->bstats) < 0 ||
|
2014-09-28 18:54:24 +00:00
|
|
|
gnet_stats_copy_queue(d, NULL, &flow->qstats, flow->q->q.qlen) < 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int atm_tc_dump(struct Qdisc *sch, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-11-14 09:44:41 +00:00
|
|
|
static const struct Qdisc_class_ops atm_class_ops = {
|
2007-07-15 07:01:25 +00:00
|
|
|
.graft = atm_tc_graft,
|
|
|
|
.leaf = atm_tc_leaf,
|
net_sched: remove tc class reference counting
For TC classes, their ->get() and ->put() are always paired, and the
reference counting is completely useless, because:
1) For class modification and dumping paths, we already hold RTNL lock,
so all of these ->get(),->change(),->put() are atomic.
2) For filter bindiing/unbinding, we use other reference counter than
this one, and they should have RTNL lock too.
3) For ->qlen_notify(), it is special because it is called on ->enqueue()
path, but we already hold qdisc tree lock there, and we hold this
tree lock when graft or delete the class too, so it should not be gone
or changed until we release the tree lock.
Therefore, this patch removes ->get() and ->put(), but:
1) Adds a new ->find() to find the pointer to a class by classid, no
refcnt.
2) Move the original class destroy upon the last refcnt into ->delete(),
right after releasing tree lock. This is fine because the class is
already removed from hash when holding the lock.
For those who also use ->put() as ->unbind(), just rename them to reflect
this change.
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-08-24 23:51:29 +00:00
|
|
|
.find = atm_tc_find,
|
2007-07-15 07:01:25 +00:00
|
|
|
.change = atm_tc_change,
|
|
|
|
.delete = atm_tc_delete,
|
|
|
|
.walk = atm_tc_walk,
|
2017-05-17 09:07:55 +00:00
|
|
|
.tcf_block = atm_tc_tcf_block,
|
2007-07-15 07:01:25 +00:00
|
|
|
.bind_tcf = atm_tc_bind_filter,
|
|
|
|
.unbind_tcf = atm_tc_put,
|
|
|
|
.dump = atm_tc_dump_class,
|
|
|
|
.dump_stats = atm_tc_dump_class_stats,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
2007-11-14 09:44:41 +00:00
|
|
|
static struct Qdisc_ops atm_qdisc_ops __read_mostly = {
|
2007-07-15 07:01:25 +00:00
|
|
|
.cl_ops = &atm_class_ops,
|
|
|
|
.id = "atm",
|
|
|
|
.priv_size = sizeof(struct atm_qdisc_data),
|
|
|
|
.enqueue = atm_tc_enqueue,
|
|
|
|
.dequeue = atm_tc_dequeue,
|
2008-10-31 07:45:55 +00:00
|
|
|
.peek = atm_tc_peek,
|
2007-07-15 07:01:25 +00:00
|
|
|
.init = atm_tc_init,
|
|
|
|
.reset = atm_tc_reset,
|
|
|
|
.destroy = atm_tc_destroy,
|
|
|
|
.dump = atm_tc_dump,
|
|
|
|
.owner = THIS_MODULE,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init atm_init(void)
|
|
|
|
{
|
|
|
|
return register_qdisc(&atm_qdisc_ops);
|
|
|
|
}
|
|
|
|
|
2007-02-09 14:25:16 +00:00
|
|
|
static void __exit atm_exit(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unregister_qdisc(&atm_qdisc_ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(atm_init)
|
|
|
|
module_exit(atm_exit)
|
|
|
|
MODULE_LICENSE("GPL");
|