blob: 4c8e994cf0a536a93e56a200102d49294005f291 [file] [log] [blame]
Thomas Gleixner09c434b2019-05-19 13:08:20 +01001// SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/* net/sched/sch_atm.c - ATM VC selection "queueing discipline" */
3
4/* Written 1998-2000 by Werner Almesberger, EPFL ICA */
5
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09007#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/init.h>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +00009#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/string.h>
11#include <linux/errno.h>
12#include <linux/skbuff.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/atmdev.h>
14#include <linux/atmclip.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/rtnetlink.h>
Patrick McHardyb0188d42007-07-15 00:01:25 -070016#include <linux/file.h> /* for fput */
Arnaldo Carvalho de Melodc5fc572007-03-25 23:06:12 -070017#include <net/netlink.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <net/pkt_sched.h>
Jiri Pirkocf1facd2017-02-09 14:38:56 +010019#include <net/pkt_cls.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Linus Torvalds1da177e2005-04-16 15:20:36 -070021/*
22 * The ATM queuing discipline provides a framework for invoking classifiers
23 * (aka "filters"), which in turn select classes of this queuing discipline.
24 * Each class maps the flow(s) it is handling to a given VC. Multiple classes
25 * may share the same VC.
26 *
27 * When creating a class, VCs are specified by passing the number of the open
28 * socket descriptor by which the calling process references the VC. The kernel
29 * keeps the VC open at least until all classes using it are removed.
30 *
31 * In this file, most functions are named atm_tc_* to avoid confusion with all
32 * the atm_* in net/atm. This naming convention differs from what's used in the
33 * rest of net/sched.
34 *
35 * Known bugs:
36 * - sometimes messes up the IP stack
37 * - any manipulations besides the few operations described in the README, are
38 * untested and likely to crash the system
39 * - should lock the flow while there is data in the queue (?)
40 */
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#define VCC2FLOW(vcc) ((struct atm_flow_data *) ((vcc)->user_back))
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044struct atm_flow_data {
Jiri Pirkof7ebdff2017-08-04 14:28:56 +020045 struct Qdisc_class_common common;
Patrick McHardyb0188d42007-07-15 00:01:25 -070046 struct Qdisc *q; /* FIFO, TBF, etc. */
John Fastabend25d8c0d2014-09-12 20:05:27 -070047 struct tcf_proto __rcu *filter_list;
Jiri Pirko6529eab2017-05-17 11:07:55 +020048 struct tcf_block *block;
Patrick McHardyb0188d42007-07-15 00:01:25 -070049 struct atm_vcc *vcc; /* VCC; NULL if VCC is closed */
50 void (*old_pop)(struct atm_vcc *vcc,
Stephen Hemminger786a9032008-01-21 02:25:29 -080051 struct sk_buff *skb); /* chaining */
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 struct atm_qdisc_data *parent; /* parent qdisc */
53 struct socket *sock; /* for closing */
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 int ref; /* reference count */
Ahmed S. Darwish50dc9a82021-10-16 10:49:09 +020055 struct gnet_stats_basic_sync bstats;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 struct gnet_stats_queue qstats;
David S. Miller6accec72010-07-18 19:52:55 -070057 struct list_head list;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 struct atm_flow_data *excess; /* flow for excess traffic;
59 NULL to set CLP instead */
60 int hdr_len;
Gustavo A. R. Silvab90feaf2020-02-27 14:58:44 -060061 unsigned char hdr[]; /* header data; MUST BE LAST */
Linus Torvalds1da177e2005-04-16 15:20:36 -070062};
63
64struct atm_qdisc_data {
65 struct atm_flow_data link; /* unclassified skbs go here */
David S. Miller6accec72010-07-18 19:52:55 -070066 struct list_head flows; /* NB: "link" is also on this
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 list */
Jarek Poplawskif30ab412008-11-13 22:56:30 -080068 struct tasklet_struct task; /* dequeue tasklet */
Linus Torvalds1da177e2005-04-16 15:20:36 -070069};
70
Linus Torvalds1da177e2005-04-16 15:20:36 -070071/* ------------------------- Class/flow operations ------------------------- */
72
Patrick McHardyb0188d42007-07-15 00:01:25 -070073static inline struct atm_flow_data *lookup_flow(struct Qdisc *sch, u32 classid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
Stephen Hemminger786a9032008-01-21 02:25:29 -080075 struct atm_qdisc_data *p = qdisc_priv(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 struct atm_flow_data *flow;
77
David S. Miller6accec72010-07-18 19:52:55 -070078 list_for_each_entry(flow, &p->flows, list) {
Jiri Pirkof7ebdff2017-08-04 14:28:56 +020079 if (flow->common.classid == classid)
David S. Miller6accec72010-07-18 19:52:55 -070080 return flow;
81 }
82 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083}
84
Patrick McHardyb0188d42007-07-15 00:01:25 -070085static int atm_tc_graft(struct Qdisc *sch, unsigned long arg,
Alexander Aring653d6fd2017-12-20 12:35:17 -050086 struct Qdisc *new, struct Qdisc **old,
87 struct netlink_ext_ack *extack)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088{
Stephen Hemminger786a9032008-01-21 02:25:29 -080089 struct atm_qdisc_data *p = qdisc_priv(sch);
Patrick McHardyb0188d42007-07-15 00:01:25 -070090 struct atm_flow_data *flow = (struct atm_flow_data *)arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Stephen Hemminger786a9032008-01-21 02:25:29 -080092 pr_debug("atm_tc_graft(sch %p,[qdisc %p],flow %p,new %p,old %p)\n",
Patrick McHardyb0188d42007-07-15 00:01:25 -070093 sch, p, flow, new, old);
David S. Miller6accec72010-07-18 19:52:55 -070094 if (list_empty(&flow->list))
Patrick McHardyb0188d42007-07-15 00:01:25 -070095 return -EINVAL;
96 if (!new)
97 new = &noop_qdisc;
Patrick McHardyb94c8af2008-11-20 04:11:36 -080098 *old = flow->q;
99 flow->q = new;
Patrick McHardyb0188d42007-07-15 00:01:25 -0700100 if (*old)
101 qdisc_reset(*old);
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900102 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103}
104
Patrick McHardyb0188d42007-07-15 00:01:25 -0700105static struct Qdisc *atm_tc_leaf(struct Qdisc *sch, unsigned long cl)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106{
Patrick McHardyb0188d42007-07-15 00:01:25 -0700107 struct atm_flow_data *flow = (struct atm_flow_data *)cl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Stephen Hemminger786a9032008-01-21 02:25:29 -0800109 pr_debug("atm_tc_leaf(sch %p,flow %p)\n", sch, flow);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 return flow ? flow->q : NULL;
111}
112
WANG Cong143976c2017-08-24 16:51:29 -0700113static unsigned long atm_tc_find(struct Qdisc *sch, u32 classid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114{
Stephen Hemminger786a9032008-01-21 02:25:29 -0800115 struct atm_qdisc_data *p __maybe_unused = qdisc_priv(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 struct atm_flow_data *flow;
117
WANG Cong143976c2017-08-24 16:51:29 -0700118 pr_debug("%s(sch %p,[qdisc %p],classid %x)\n", __func__, sch, p, classid);
Patrick McHardyb0188d42007-07-15 00:01:25 -0700119 flow = lookup_flow(sch, classid);
WANG Cong143976c2017-08-24 16:51:29 -0700120 pr_debug("%s: flow %p\n", __func__, flow);
Patrick McHardyb0188d42007-07-15 00:01:25 -0700121 return (unsigned long)flow;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122}
123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124static unsigned long atm_tc_bind_filter(struct Qdisc *sch,
Patrick McHardyb0188d42007-07-15 00:01:25 -0700125 unsigned long parent, u32 classid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
WANG Cong143976c2017-08-24 16:51:29 -0700127 struct atm_qdisc_data *p __maybe_unused = qdisc_priv(sch);
128 struct atm_flow_data *flow;
129
130 pr_debug("%s(sch %p,[qdisc %p],classid %x)\n", __func__, sch, p, classid);
131 flow = lookup_flow(sch, classid);
132 if (flow)
133 flow->ref++;
134 pr_debug("%s: flow %p\n", __func__, flow);
135 return (unsigned long)flow;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136}
137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138/*
139 * atm_tc_put handles all destructions, including the ones that are explicitly
140 * requested (atm_tc_destroy, etc.). The assumption here is that we never drop
141 * anything that still seems to be in use.
142 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143static void atm_tc_put(struct Qdisc *sch, unsigned long cl)
144{
Stephen Hemminger786a9032008-01-21 02:25:29 -0800145 struct atm_qdisc_data *p = qdisc_priv(sch);
Patrick McHardyb0188d42007-07-15 00:01:25 -0700146 struct atm_flow_data *flow = (struct atm_flow_data *)cl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Stephen Hemminger786a9032008-01-21 02:25:29 -0800148 pr_debug("atm_tc_put(sch %p,[qdisc %p],flow %p)\n", sch, p, flow);
Patrick McHardyb0188d42007-07-15 00:01:25 -0700149 if (--flow->ref)
150 return;
Stephen Hemminger786a9032008-01-21 02:25:29 -0800151 pr_debug("atm_tc_put: destroying\n");
David S. Miller6accec72010-07-18 19:52:55 -0700152 list_del_init(&flow->list);
Stephen Hemminger786a9032008-01-21 02:25:29 -0800153 pr_debug("atm_tc_put: qdisc %p\n", flow->q);
Vlad Buslov86bd4462018-09-24 19:22:50 +0300154 qdisc_put(flow->q);
Jiri Pirko6529eab2017-05-17 11:07:55 +0200155 tcf_block_put(flow->block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 if (flow->sock) {
Al Viro516e0cc2008-07-26 00:39:17 -0400157 pr_debug("atm_tc_put: f_count %ld\n",
Patrick McHardyb0188d42007-07-15 00:01:25 -0700158 file_count(flow->sock->file));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 flow->vcc->pop = flow->old_pop;
160 sockfd_put(flow->sock);
161 }
Patrick McHardyb0188d42007-07-15 00:01:25 -0700162 if (flow->excess)
163 atm_tc_put(sch, (unsigned long)flow->excess);
164 if (flow != &p->link)
165 kfree(flow);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 /*
167 * If flow == &p->link, the qdisc no longer works at this point and
168 * needs to be removed. (By the caller of atm_tc_put.)
169 */
170}
171
Patrick McHardyb0188d42007-07-15 00:01:25 -0700172static void sch_atm_pop(struct atm_vcc *vcc, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
174 struct atm_qdisc_data *p = VCC2FLOW(vcc)->parent;
175
Stephen Hemminger786a9032008-01-21 02:25:29 -0800176 pr_debug("sch_atm_pop(vcc %p,skb %p,[qdisc %p])\n", vcc, skb, p);
Patrick McHardyb0188d42007-07-15 00:01:25 -0700177 VCC2FLOW(vcc)->old_pop(vcc, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 tasklet_schedule(&p->task);
179}
180
181static const u8 llc_oui_ip[] = {
Patrick McHardyb0188d42007-07-15 00:01:25 -0700182 0xaa, /* DSAP: non-ISO */
183 0xaa, /* SSAP: non-ISO */
184 0x03, /* Ctrl: Unnumbered Information Command PDU */
185 0x00, /* OUI: EtherType */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 0x00, 0x00,
Patrick McHardyb0188d42007-07-15 00:01:25 -0700187 0x08, 0x00
188}; /* Ethertype IP (0800) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
Patrick McHardy27a34212008-01-23 20:35:39 -0800190static const struct nla_policy atm_policy[TCA_ATM_MAX + 1] = {
191 [TCA_ATM_FD] = { .type = NLA_U32 },
192 [TCA_ATM_EXCESS] = { .type = NLA_U32 },
193};
194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent,
Alexander Aring793d81d2017-12-20 12:35:15 -0500196 struct nlattr **tca, unsigned long *arg,
197 struct netlink_ext_ack *extack)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198{
Stephen Hemminger786a9032008-01-21 02:25:29 -0800199 struct atm_qdisc_data *p = qdisc_priv(sch);
Patrick McHardyb0188d42007-07-15 00:01:25 -0700200 struct atm_flow_data *flow = (struct atm_flow_data *)*arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 struct atm_flow_data *excess = NULL;
Patrick McHardy1e904742008-01-22 22:11:17 -0800202 struct nlattr *opt = tca[TCA_OPTIONS];
203 struct nlattr *tb[TCA_ATM_MAX + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 struct socket *sock;
Patrick McHardyb0188d42007-07-15 00:01:25 -0700205 int fd, error, hdr_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 void *hdr;
207
Stephen Hemminger786a9032008-01-21 02:25:29 -0800208 pr_debug("atm_tc_change(sch %p,[qdisc %p],classid %x,parent %x,"
Patrick McHardyb0188d42007-07-15 00:01:25 -0700209 "flow %p,opt %p)\n", sch, p, classid, parent, flow, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 /*
211 * The concept of parents doesn't apply for this qdisc.
212 */
213 if (parent && parent != TC_H_ROOT && parent != sch->handle)
214 return -EINVAL;
215 /*
216 * ATM classes cannot be changed. In order to change properties of the
217 * ATM connection, that socket needs to be modified directly (via the
218 * native ATM API. In order to send a flow to a different VC, the old
219 * class needs to be removed and a new one added. (This may be changed
220 * later.)
221 */
Patrick McHardyb0188d42007-07-15 00:01:25 -0700222 if (flow)
223 return -EBUSY;
Patrick McHardycee63722008-01-23 20:33:32 -0800224 if (opt == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 return -EINVAL;
Patrick McHardy27a34212008-01-23 20:35:39 -0800226
Johannes Berg8cb08172019-04-26 14:07:28 +0200227 error = nla_parse_nested_deprecated(tb, TCA_ATM_MAX, opt, atm_policy,
228 NULL);
Patrick McHardycee63722008-01-23 20:33:32 -0800229 if (error < 0)
230 return error;
231
Patrick McHardy27a34212008-01-23 20:35:39 -0800232 if (!tb[TCA_ATM_FD])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 return -EINVAL;
Patrick McHardy1587bac2008-01-23 20:35:03 -0800234 fd = nla_get_u32(tb[TCA_ATM_FD]);
Stephen Hemminger786a9032008-01-21 02:25:29 -0800235 pr_debug("atm_tc_change: fd %d\n", fd);
Patrick McHardy1e904742008-01-22 22:11:17 -0800236 if (tb[TCA_ATM_HDR]) {
237 hdr_len = nla_len(tb[TCA_ATM_HDR]);
238 hdr = nla_data(tb[TCA_ATM_HDR]);
Patrick McHardyb0188d42007-07-15 00:01:25 -0700239 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 hdr_len = RFC1483LLC_LEN;
Patrick McHardyb0188d42007-07-15 00:01:25 -0700241 hdr = NULL; /* default LLC/SNAP for IP */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 }
Patrick McHardy1e904742008-01-22 22:11:17 -0800243 if (!tb[TCA_ATM_EXCESS])
Patrick McHardyb0188d42007-07-15 00:01:25 -0700244 excess = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 else {
Patrick McHardyb0188d42007-07-15 00:01:25 -0700246 excess = (struct atm_flow_data *)
WANG Cong143976c2017-08-24 16:51:29 -0700247 atm_tc_find(sch, nla_get_u32(tb[TCA_ATM_EXCESS]));
Patrick McHardyb0188d42007-07-15 00:01:25 -0700248 if (!excess)
249 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 }
Patrick McHardyf5e5cb72008-01-23 20:32:06 -0800251 pr_debug("atm_tc_change: type %d, payload %d, hdr_len %d\n",
Patrick McHardy1e904742008-01-22 22:11:17 -0800252 opt->nla_type, nla_len(opt), hdr_len);
Stephen Hemminger786a9032008-01-21 02:25:29 -0800253 sock = sockfd_lookup(fd, &error);
254 if (!sock)
Patrick McHardyb0188d42007-07-15 00:01:25 -0700255 return error; /* f_count++ */
Al Viro516e0cc2008-07-26 00:39:17 -0400256 pr_debug("atm_tc_change: f_count %ld\n", file_count(sock->file));
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900257 if (sock->ops->family != PF_ATMSVC && sock->ops->family != PF_ATMPVC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 error = -EPROTOTYPE;
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900259 goto err_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 }
261 /* @@@ should check if the socket is really operational or we'll crash
262 on vcc->send */
263 if (classid) {
264 if (TC_H_MAJ(classid ^ sch->handle)) {
Stephen Hemminger786a9032008-01-21 02:25:29 -0800265 pr_debug("atm_tc_change: classid mismatch\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 error = -EINVAL;
267 goto err_out;
268 }
Patrick McHardyb0188d42007-07-15 00:01:25 -0700269 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 int i;
271 unsigned long cl;
272
273 for (i = 1; i < 0x8000; i++) {
Patrick McHardyb0188d42007-07-15 00:01:25 -0700274 classid = TC_H_MAKE(sch->handle, 0x8000 | i);
WANG Cong143976c2017-08-24 16:51:29 -0700275 cl = atm_tc_find(sch, classid);
Stephen Hemminger786a9032008-01-21 02:25:29 -0800276 if (!cl)
Patrick McHardyb0188d42007-07-15 00:01:25 -0700277 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 }
279 }
Stephen Hemminger786a9032008-01-21 02:25:29 -0800280 pr_debug("atm_tc_change: new id %x\n", classid);
vignesh babu782f7952007-07-16 18:30:36 -0700281 flow = kzalloc(sizeof(struct atm_flow_data) + hdr_len, GFP_KERNEL);
Stephen Hemminger786a9032008-01-21 02:25:29 -0800282 pr_debug("atm_tc_change: flow %p\n", flow);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 if (!flow) {
284 error = -ENOBUFS;
285 goto err_out;
286 }
Jiri Pirko6529eab2017-05-17 11:07:55 +0200287
Alexander Aring8d1a77f2017-12-20 12:35:19 -0500288 error = tcf_block_get(&flow->block, &flow->filter_list, sch,
289 extack);
Jiri Pirko6529eab2017-05-17 11:07:55 +0200290 if (error) {
291 kfree(flow);
292 goto err_out;
293 }
294
Alexander Aringa38a98822017-12-20 12:35:21 -0500295 flow->q = qdisc_create_dflt(sch->dev_queue, &pfifo_qdisc_ops, classid,
296 extack);
Stephen Hemminger786a9032008-01-21 02:25:29 -0800297 if (!flow->q)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 flow->q = &noop_qdisc;
Stephen Hemminger786a9032008-01-21 02:25:29 -0800299 pr_debug("atm_tc_change: qdisc %p\n", flow->q);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 flow->sock = sock;
Patrick McHardyb0188d42007-07-15 00:01:25 -0700301 flow->vcc = ATM_SD(sock); /* speedup */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 flow->vcc->user_back = flow;
Stephen Hemminger786a9032008-01-21 02:25:29 -0800303 pr_debug("atm_tc_change: vcc %p\n", flow->vcc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 flow->old_pop = flow->vcc->pop;
305 flow->parent = p;
306 flow->vcc->pop = sch_atm_pop;
Jiri Pirkof7ebdff2017-08-04 14:28:56 +0200307 flow->common.classid = classid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 flow->ref = 1;
309 flow->excess = excess;
David S. Miller6accec72010-07-18 19:52:55 -0700310 list_add(&flow->list, &p->link.list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 flow->hdr_len = hdr_len;
312 if (hdr)
Patrick McHardyb0188d42007-07-15 00:01:25 -0700313 memcpy(flow->hdr, hdr, hdr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 else
Patrick McHardyb0188d42007-07-15 00:01:25 -0700315 memcpy(flow->hdr, llc_oui_ip, sizeof(llc_oui_ip));
316 *arg = (unsigned long)flow;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 return 0;
318err_out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 sockfd_put(sock);
320 return error;
321}
322
Maxim Mikityanskiy4dd78a72021-01-19 14:08:12 +0200323static int atm_tc_delete(struct Qdisc *sch, unsigned long arg,
324 struct netlink_ext_ack *extack)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325{
Stephen Hemminger786a9032008-01-21 02:25:29 -0800326 struct atm_qdisc_data *p = qdisc_priv(sch);
Patrick McHardyb0188d42007-07-15 00:01:25 -0700327 struct atm_flow_data *flow = (struct atm_flow_data *)arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
Stephen Hemminger786a9032008-01-21 02:25:29 -0800329 pr_debug("atm_tc_delete(sch %p,[qdisc %p],flow %p)\n", sch, p, flow);
David S. Miller6accec72010-07-18 19:52:55 -0700330 if (list_empty(&flow->list))
Patrick McHardyb0188d42007-07-15 00:01:25 -0700331 return -EINVAL;
John Fastabend25d8c0d2014-09-12 20:05:27 -0700332 if (rcu_access_pointer(flow->filter_list) || flow == &p->link)
Patrick McHardyb0188d42007-07-15 00:01:25 -0700333 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 /*
335 * Reference count must be 2: one for "keepalive" (set at class
336 * creation), and one for the reference held when calling delete.
337 */
338 if (flow->ref < 2) {
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000339 pr_err("atm_tc_delete: flow->ref == %d\n", flow->ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 return -EINVAL;
341 }
Patrick McHardyb0188d42007-07-15 00:01:25 -0700342 if (flow->ref > 2)
343 return -EBUSY; /* catch references via excess, etc. */
344 atm_tc_put(sch, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 return 0;
346}
347
Patrick McHardyb0188d42007-07-15 00:01:25 -0700348static void atm_tc_walk(struct Qdisc *sch, struct qdisc_walker *walker)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349{
Stephen Hemminger786a9032008-01-21 02:25:29 -0800350 struct atm_qdisc_data *p = qdisc_priv(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 struct atm_flow_data *flow;
352
Stephen Hemminger786a9032008-01-21 02:25:29 -0800353 pr_debug("atm_tc_walk(sch %p,[qdisc %p],walker %p)\n", sch, p, walker);
Patrick McHardyb0188d42007-07-15 00:01:25 -0700354 if (walker->stop)
355 return;
David S. Miller6accec72010-07-18 19:52:55 -0700356 list_for_each_entry(flow, &p->flows, list) {
357 if (walker->count >= walker->skip &&
358 walker->fn(sch, (unsigned long)flow, walker) < 0) {
359 walker->stop = 1;
360 break;
361 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 walker->count++;
363 }
364}
365
Alexander Aringcbaacc42017-12-20 12:35:16 -0500366static struct tcf_block *atm_tc_tcf_block(struct Qdisc *sch, unsigned long cl,
367 struct netlink_ext_ack *extack)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368{
Stephen Hemminger786a9032008-01-21 02:25:29 -0800369 struct atm_qdisc_data *p = qdisc_priv(sch);
Patrick McHardyb0188d42007-07-15 00:01:25 -0700370 struct atm_flow_data *flow = (struct atm_flow_data *)cl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Stephen Hemminger786a9032008-01-21 02:25:29 -0800372 pr_debug("atm_tc_find_tcf(sch %p,[qdisc %p],flow %p)\n", sch, p, flow);
Jiri Pirko6529eab2017-05-17 11:07:55 +0200373 return flow ? flow->block : p->link.block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374}
375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376/* --------------------------- Qdisc operations ---------------------------- */
377
Eric Dumazet520ac302016-06-21 23:16:49 -0700378static int atm_tc_enqueue(struct sk_buff *skb, struct Qdisc *sch,
379 struct sk_buff **to_free)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380{
Stephen Hemminger786a9032008-01-21 02:25:29 -0800381 struct atm_qdisc_data *p = qdisc_priv(sch);
David S. Miller6accec72010-07-18 19:52:55 -0700382 struct atm_flow_data *flow;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 struct tcf_result res;
384 int result;
Florian Westphal99860202016-06-11 12:46:04 +0200385 int ret = NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
Stephen Hemminger786a9032008-01-21 02:25:29 -0800387 pr_debug("atm_tc_enqueue(skb %p,sch %p,[qdisc %p])\n", skb, sch, p);
WANG Cong95df1b12016-06-13 10:47:43 -0700388 result = TC_ACT_OK; /* be nice to gcc */
David S. Miller6accec72010-07-18 19:52:55 -0700389 flow = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 if (TC_H_MAJ(skb->priority) != sch->handle ||
WANG Cong143976c2017-08-24 16:51:29 -0700391 !(flow = (struct atm_flow_data *)atm_tc_find(sch, skb->priority))) {
John Fastabend25d8c0d2014-09-12 20:05:27 -0700392 struct tcf_proto *fl;
393
David S. Miller6accec72010-07-18 19:52:55 -0700394 list_for_each_entry(flow, &p->flows, list) {
John Fastabend25d8c0d2014-09-12 20:05:27 -0700395 fl = rcu_dereference_bh(flow->filter_list);
396 if (fl) {
Davide Caratti3aa26052021-07-28 20:08:00 +0200397 result = tcf_classify(skb, NULL, fl, &res, true);
Patrick McHardyb0188d42007-07-15 00:01:25 -0700398 if (result < 0)
399 continue;
400 flow = (struct atm_flow_data *)res.class;
401 if (!flow)
402 flow = lookup_flow(sch, res.classid);
David S. Miller6accec72010-07-18 19:52:55 -0700403 goto done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 }
David S. Miller6accec72010-07-18 19:52:55 -0700405 }
406 flow = NULL;
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000407done:
408 ;
David S. Miller6accec72010-07-18 19:52:55 -0700409 }
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000410 if (!flow) {
Patrick McHardyb0188d42007-07-15 00:01:25 -0700411 flow = &p->link;
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000412 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 if (flow->vcc)
414 ATM_SKB(skb)->atm_options = flow->vcc->atm_options;
Patrick McHardyb0188d42007-07-15 00:01:25 -0700415 /*@@@ looks good ... but it's not supposed to work :-) */
Patrick McHardy92100802007-07-15 00:01:49 -0700416#ifdef CONFIG_NET_CLS_ACT
417 switch (result) {
418 case TC_ACT_QUEUED:
419 case TC_ACT_STOLEN:
Jiri Pirkoe25ea212017-06-06 14:12:02 +0200420 case TC_ACT_TRAP:
Eric Dumazet520ac302016-06-21 23:16:49 -0700421 __qdisc_drop(skb, to_free);
Jarek Poplawski378a2f02008-08-04 22:31:03 -0700422 return NET_XMIT_SUCCESS | __NET_XMIT_STOLEN;
Patrick McHardy92100802007-07-15 00:01:49 -0700423 case TC_ACT_SHOT:
Eric Dumazet520ac302016-06-21 23:16:49 -0700424 __qdisc_drop(skb, to_free);
Patrick McHardy92100802007-07-15 00:01:49 -0700425 goto drop;
WANG Cong95df1b12016-06-13 10:47:43 -0700426 case TC_ACT_RECLASSIFY:
Patrick McHardy73ca4912007-07-15 00:02:31 -0700427 if (flow->excess)
428 flow = flow->excess;
429 else
430 ATM_SKB(skb)->atm_options |= ATM_ATMOPT_CLP;
431 break;
Patrick McHardy92100802007-07-15 00:01:49 -0700432 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433#endif
434 }
Patrick McHardyc3bc7cf2007-07-15 00:03:05 -0700435
Eric Dumazet520ac302016-06-21 23:16:49 -0700436 ret = qdisc_enqueue(skb, flow->q, to_free);
Ben Greear9871e502010-08-10 01:45:40 -0700437 if (ret != NET_XMIT_SUCCESS) {
Patrick McHardy92100802007-07-15 00:01:49 -0700438drop: __maybe_unused
Jarek Poplawski378a2f02008-08-04 22:31:03 -0700439 if (net_xmit_drop_count(ret)) {
John Fastabend25331d62014-09-28 11:53:29 -0700440 qdisc_qstats_drop(sch);
Jarek Poplawski378a2f02008-08-04 22:31:03 -0700441 if (flow)
442 flow->qstats.drops++;
443 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 return ret;
445 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 /*
447 * Okay, this may seem weird. We pretend we've dropped the packet if
448 * it goes via ATM. The reason for this is that the outer qdisc
449 * expects to be able to q->dequeue the packet later on if we return
450 * success at this place. Also, sch->q.qdisc needs to reflect whether
451 * there is a packet egligible for dequeuing or not. Note that the
452 * statistics of the outer qdisc are necessarily wrong because of all
453 * this. There's currently no correct solution for this.
454 */
455 if (flow == &p->link) {
456 sch->q.qlen++;
Ben Greear9871e502010-08-10 01:45:40 -0700457 return NET_XMIT_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 }
459 tasklet_schedule(&p->task);
Jarek Poplawskic27f3392008-08-04 22:39:11 -0700460 return NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461}
462
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463/*
464 * Dequeue packets and send them over ATM. Note that we quite deliberately
465 * avoid checking net_device's flow control here, simply because sch_atm
466 * uses its own channels, which have nothing to do with any CLIP/LANE/or
467 * non-ATM interfaces.
468 */
469
Allen Pais6e1978a2020-11-03 14:48:21 +0530470static void sch_atm_dequeue(struct tasklet_struct *t)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471{
Allen Pais6e1978a2020-11-03 14:48:21 +0530472 struct atm_qdisc_data *p = from_tasklet(p, t, task);
473 struct Qdisc *sch = qdisc_from_priv(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 struct atm_flow_data *flow;
475 struct sk_buff *skb;
476
Stephen Hemminger786a9032008-01-21 02:25:29 -0800477 pr_debug("sch_atm_dequeue(sch %p,[qdisc %p])\n", sch, p);
David S. Miller6accec72010-07-18 19:52:55 -0700478 list_for_each_entry(flow, &p->flows, list) {
479 if (flow == &p->link)
480 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 /*
482 * If traffic is properly shaped, this won't generate nasty
483 * little bursts. Otherwise, it may ... (but that's okay)
484 */
Jarek Poplawski03c05f02008-10-31 00:46:19 -0700485 while ((skb = flow->q->ops->peek(flow->q))) {
486 if (!atm_may_send(flow->vcc, skb->truesize))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 break;
Jarek Poplawski03c05f02008-10-31 00:46:19 -0700488
Jarek Poplawski77be1552008-10-31 00:47:01 -0700489 skb = qdisc_dequeue_peeked(flow->q);
Jarek Poplawski03c05f02008-10-31 00:46:19 -0700490 if (unlikely(!skb))
491 break;
492
Eric Dumazet2dd875f2012-05-10 05:36:34 +0000493 qdisc_bstats_update(sch, skb);
494 bstats_update(&flow->bstats, skb);
Stephen Hemminger786a9032008-01-21 02:25:29 -0800495 pr_debug("atm_tc_dequeue: sending on class %p\n", flow);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 /* remove any LL header somebody else has attached */
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -0700497 skb_pull(skb, skb_network_offset(skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 if (skb_headroom(skb) < flow->hdr_len) {
499 struct sk_buff *new;
500
Patrick McHardyb0188d42007-07-15 00:01:25 -0700501 new = skb_realloc_headroom(skb, flow->hdr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 dev_kfree_skb(skb);
Patrick McHardyb0188d42007-07-15 00:01:25 -0700503 if (!new)
504 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 skb = new;
506 }
Stephen Hemminger786a9032008-01-21 02:25:29 -0800507 pr_debug("sch_atm_dequeue: ip %p, data %p\n",
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -0700508 skb_network_header(skb), skb->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 ATM_SKB(skb)->vcc = flow->vcc;
Patrick McHardyb0188d42007-07-15 00:01:25 -0700510 memcpy(skb_push(skb, flow->hdr_len), flow->hdr,
511 flow->hdr_len);
Reshetova, Elena14afee42017-06-30 13:08:00 +0300512 refcount_add(skb->truesize,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 &sk_atm(flow->vcc)->sk_wmem_alloc);
514 /* atm.atm_options are already set by atm_tc_enqueue */
Patrick McHardyb0188d42007-07-15 00:01:25 -0700515 flow->vcc->send(flow->vcc, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 }
David S. Miller6accec72010-07-18 19:52:55 -0700517 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518}
519
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520static struct sk_buff *atm_tc_dequeue(struct Qdisc *sch)
521{
Stephen Hemminger786a9032008-01-21 02:25:29 -0800522 struct atm_qdisc_data *p = qdisc_priv(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 struct sk_buff *skb;
524
Stephen Hemminger786a9032008-01-21 02:25:29 -0800525 pr_debug("atm_tc_dequeue(sch %p,[qdisc %p])\n", sch, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 tasklet_schedule(&p->task);
Jarek Poplawski77be1552008-10-31 00:47:01 -0700527 skb = qdisc_dequeue_peeked(p->link.q);
Patrick McHardyb0188d42007-07-15 00:01:25 -0700528 if (skb)
529 sch->q.qlen--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 return skb;
531}
532
Jarek Poplawski8e3af972008-10-31 00:45:55 -0700533static struct sk_buff *atm_tc_peek(struct Qdisc *sch)
534{
535 struct atm_qdisc_data *p = qdisc_priv(sch);
536
537 pr_debug("atm_tc_peek(sch %p,[qdisc %p])\n", sch, p);
538
539 return p->link.q->ops->peek(p->link.q);
540}
541
Alexander Aringe63d7df2017-12-20 12:35:13 -0500542static int atm_tc_init(struct Qdisc *sch, struct nlattr *opt,
543 struct netlink_ext_ack *extack)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544{
Stephen Hemminger786a9032008-01-21 02:25:29 -0800545 struct atm_qdisc_data *p = qdisc_priv(sch);
Jiri Pirko6529eab2017-05-17 11:07:55 +0200546 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
Stephen Hemminger786a9032008-01-21 02:25:29 -0800548 pr_debug("atm_tc_init(sch %p,[qdisc %p],opt %p)\n", sch, p, opt);
David S. Miller6accec72010-07-18 19:52:55 -0700549 INIT_LIST_HEAD(&p->flows);
550 INIT_LIST_HEAD(&p->link.list);
Ahmed S. Darwish50dc9a82021-10-16 10:49:09 +0200551 gnet_stats_basic_sync_init(&p->link.bstats);
David S. Miller6accec72010-07-18 19:52:55 -0700552 list_add(&p->link.list, &p->flows);
Changli Gao3511c912010-10-16 13:04:08 +0000553 p->link.q = qdisc_create_dflt(sch->dev_queue,
Alexander Aringa38a98822017-12-20 12:35:21 -0500554 &pfifo_qdisc_ops, sch->handle, extack);
Stephen Hemminger786a9032008-01-21 02:25:29 -0800555 if (!p->link.q)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 p->link.q = &noop_qdisc;
Stephen Hemminger786a9032008-01-21 02:25:29 -0800557 pr_debug("atm_tc_init: link (%p) qdisc %p\n", &p->link, p->link.q);
Cong Wang306381a2020-07-08 20:13:59 -0700558 p->link.vcc = NULL;
559 p->link.sock = NULL;
560 p->link.common.classid = sch->handle;
561 p->link.ref = 1;
Jiri Pirko6529eab2017-05-17 11:07:55 +0200562
Alexander Aring8d1a77f2017-12-20 12:35:19 -0500563 err = tcf_block_get(&p->link.block, &p->link.filter_list, sch,
564 extack);
Jiri Pirko6529eab2017-05-17 11:07:55 +0200565 if (err)
566 return err;
567
Allen Pais6e1978a2020-11-03 14:48:21 +0530568 tasklet_setup(&p->task, sch_atm_dequeue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 return 0;
570}
571
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572static void atm_tc_reset(struct Qdisc *sch)
573{
Stephen Hemminger786a9032008-01-21 02:25:29 -0800574 struct atm_qdisc_data *p = qdisc_priv(sch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 struct atm_flow_data *flow;
576
Stephen Hemminger786a9032008-01-21 02:25:29 -0800577 pr_debug("atm_tc_reset(sch %p,[qdisc %p])\n", sch, p);
David S. Miller6accec72010-07-18 19:52:55 -0700578 list_for_each_entry(flow, &p->flows, list)
Patrick McHardyb0188d42007-07-15 00:01:25 -0700579 qdisc_reset(flow->q);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 sch->q.qlen = 0;
581}
582
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583static void atm_tc_destroy(struct Qdisc *sch)
584{
Stephen Hemminger786a9032008-01-21 02:25:29 -0800585 struct atm_qdisc_data *p = qdisc_priv(sch);
David S. Miller6accec72010-07-18 19:52:55 -0700586 struct atm_flow_data *flow, *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
Stephen Hemminger786a9032008-01-21 02:25:29 -0800588 pr_debug("atm_tc_destroy(sch %p,[qdisc %p])\n", sch, p);
Konstantin Khlebnikov89890422017-08-15 16:35:21 +0300589 list_for_each_entry(flow, &p->flows, list) {
Jiri Pirko6529eab2017-05-17 11:07:55 +0200590 tcf_block_put(flow->block);
Konstantin Khlebnikov89890422017-08-15 16:35:21 +0300591 flow->block = NULL;
592 }
Patrick McHardya4aebb82008-07-01 19:53:09 -0700593
David S. Miller6accec72010-07-18 19:52:55 -0700594 list_for_each_entry_safe(flow, tmp, &p->flows, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 if (flow->ref > 1)
Eric Dumazetcc7ec452011-01-19 19:26:56 +0000596 pr_err("atm_destroy: %p->ref = %d\n", flow, flow->ref);
Patrick McHardyb0188d42007-07-15 00:01:25 -0700597 atm_tc_put(sch, (unsigned long)flow);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 }
599 tasklet_kill(&p->task);
600}
601
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602static int atm_tc_dump_class(struct Qdisc *sch, unsigned long cl,
Patrick McHardyb0188d42007-07-15 00:01:25 -0700603 struct sk_buff *skb, struct tcmsg *tcm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604{
Stephen Hemminger786a9032008-01-21 02:25:29 -0800605 struct atm_qdisc_data *p = qdisc_priv(sch);
Patrick McHardyb0188d42007-07-15 00:01:25 -0700606 struct atm_flow_data *flow = (struct atm_flow_data *)cl;
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800607 struct nlattr *nest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
Stephen Hemminger786a9032008-01-21 02:25:29 -0800609 pr_debug("atm_tc_dump_class(sch %p,[qdisc %p],flow %p,skb %p,tcm %p)\n",
Patrick McHardyb0188d42007-07-15 00:01:25 -0700610 sch, p, flow, skb, tcm);
David S. Miller6accec72010-07-18 19:52:55 -0700611 if (list_empty(&flow->list))
Patrick McHardyb0188d42007-07-15 00:01:25 -0700612 return -EINVAL;
Jiri Pirkof7ebdff2017-08-04 14:28:56 +0200613 tcm->tcm_handle = flow->common.classid;
Patrick McHardycdc7f8e2006-03-20 19:01:06 -0800614 tcm->tcm_info = flow->q->handle;
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800615
Michal Kubecekae0be8d2019-04-26 11:13:06 +0200616 nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800617 if (nest == NULL)
618 goto nla_put_failure;
619
David S. Miller1b34ec42012-03-29 05:11:39 -0400620 if (nla_put(skb, TCA_ATM_HDR, flow->hdr_len, flow->hdr))
621 goto nla_put_failure;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 if (flow->vcc) {
623 struct sockaddr_atmpvc pvc;
624 int state;
625
Dan Carpenter8cb3b9c2013-07-30 13:23:39 +0300626 memset(&pvc, 0, sizeof(pvc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 pvc.sap_family = AF_ATMPVC;
628 pvc.sap_addr.itf = flow->vcc->dev ? flow->vcc->dev->number : -1;
629 pvc.sap_addr.vpi = flow->vcc->vpi;
630 pvc.sap_addr.vci = flow->vcc->vci;
David S. Miller1b34ec42012-03-29 05:11:39 -0400631 if (nla_put(skb, TCA_ATM_ADDR, sizeof(pvc), &pvc))
632 goto nla_put_failure;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 state = ATM_VF2VS(flow->vcc->flags);
David S. Miller1b34ec42012-03-29 05:11:39 -0400634 if (nla_put_u32(skb, TCA_ATM_STATE, state))
635 goto nla_put_failure;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 }
David S. Miller1b34ec42012-03-29 05:11:39 -0400637 if (flow->excess) {
Jiri Pirkof7ebdff2017-08-04 14:28:56 +0200638 if (nla_put_u32(skb, TCA_ATM_EXCESS, flow->common.classid))
David S. Miller1b34ec42012-03-29 05:11:39 -0400639 goto nla_put_failure;
640 } else {
641 if (nla_put_u32(skb, TCA_ATM_EXCESS, 0))
642 goto nla_put_failure;
643 }
Yang Yingliangd59b7d82014-03-12 10:20:32 +0800644 return nla_nest_end(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
Patrick McHardy1e904742008-01-22 22:11:17 -0800646nla_put_failure:
Patrick McHardy4b3550ef2008-01-23 20:34:11 -0800647 nla_nest_cancel(skb, nest);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 return -1;
649}
650static int
651atm_tc_dump_class_stats(struct Qdisc *sch, unsigned long arg,
Patrick McHardyb0188d42007-07-15 00:01:25 -0700652 struct gnet_dump *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653{
Patrick McHardyb0188d42007-07-15 00:01:25 -0700654 struct atm_flow_data *flow = (struct atm_flow_data *)arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
Ahmed S. Darwish29cbcd82021-10-16 10:49:10 +0200656 if (gnet_stats_copy_basic(d, NULL, &flow->bstats, true) < 0 ||
John Fastabendb0ab6f92014-09-28 11:54:24 -0700657 gnet_stats_copy_queue(d, NULL, &flow->qstats, flow->q->q.qlen) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 return -1;
659
660 return 0;
661}
662
663static int atm_tc_dump(struct Qdisc *sch, struct sk_buff *skb)
664{
665 return 0;
666}
667
Eric Dumazet20fea082007-11-14 01:44:41 -0800668static const struct Qdisc_class_ops atm_class_ops = {
Patrick McHardyb0188d42007-07-15 00:01:25 -0700669 .graft = atm_tc_graft,
670 .leaf = atm_tc_leaf,
WANG Cong143976c2017-08-24 16:51:29 -0700671 .find = atm_tc_find,
Patrick McHardyb0188d42007-07-15 00:01:25 -0700672 .change = atm_tc_change,
673 .delete = atm_tc_delete,
674 .walk = atm_tc_walk,
Jiri Pirko6529eab2017-05-17 11:07:55 +0200675 .tcf_block = atm_tc_tcf_block,
Patrick McHardyb0188d42007-07-15 00:01:25 -0700676 .bind_tcf = atm_tc_bind_filter,
677 .unbind_tcf = atm_tc_put,
678 .dump = atm_tc_dump_class,
679 .dump_stats = atm_tc_dump_class_stats,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680};
681
Eric Dumazet20fea082007-11-14 01:44:41 -0800682static struct Qdisc_ops atm_qdisc_ops __read_mostly = {
Patrick McHardyb0188d42007-07-15 00:01:25 -0700683 .cl_ops = &atm_class_ops,
684 .id = "atm",
685 .priv_size = sizeof(struct atm_qdisc_data),
686 .enqueue = atm_tc_enqueue,
687 .dequeue = atm_tc_dequeue,
Jarek Poplawski8e3af972008-10-31 00:45:55 -0700688 .peek = atm_tc_peek,
Patrick McHardyb0188d42007-07-15 00:01:25 -0700689 .init = atm_tc_init,
690 .reset = atm_tc_reset,
691 .destroy = atm_tc_destroy,
692 .dump = atm_tc_dump,
693 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694};
695
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696static int __init atm_init(void)
697{
698 return register_qdisc(&atm_qdisc_ops);
699}
700
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +0900701static void __exit atm_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702{
703 unregister_qdisc(&atm_qdisc_ops);
704}
705
706module_init(atm_init)
707module_exit(atm_exit)
708MODULE_LICENSE("GPL");