Blame view
net/sched/sch_atm.c
18.9 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 |
/* net/sched/sch_atm.c - ATM VC selection "queueing discipline" */ /* Written 1998-2000 by Werner Almesberger, EPFL ICA */ |
1da177e4c Linux-2.6.12-rc2 |
4 |
#include <linux/module.h> |
5a0e3ad6a include cleanup: ... |
5 |
#include <linux/slab.h> |
1da177e4c Linux-2.6.12-rc2 |
6 |
#include <linux/init.h> |
a6b7a4078 net: remove inter... |
7 |
#include <linux/interrupt.h> |
1da177e4c Linux-2.6.12-rc2 |
8 9 10 |
#include <linux/string.h> #include <linux/errno.h> #include <linux/skbuff.h> |
1da177e4c Linux-2.6.12-rc2 |
11 12 |
#include <linux/atmdev.h> #include <linux/atmclip.h> |
1da177e4c Linux-2.6.12-rc2 |
13 |
#include <linux/rtnetlink.h> |
b0188d4db [NET_SCHED]: sch_... |
14 |
#include <linux/file.h> /* for fput */ |
dc5fc579b [NETLINK]: Use nl... |
15 |
#include <net/netlink.h> |
1da177e4c Linux-2.6.12-rc2 |
16 |
#include <net/pkt_sched.h> |
1da177e4c Linux-2.6.12-rc2 |
17 |
|
b0188d4db [NET_SCHED]: sch_... |
18 |
extern struct socket *sockfd_lookup(int fd, int *err); /* @@@ fix this */ |
1da177e4c Linux-2.6.12-rc2 |
19 |
|
1da177e4c Linux-2.6.12-rc2 |
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
/* * 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 (?) */ |
1da177e4c Linux-2.6.12-rc2 |
40 |
#define VCC2FLOW(vcc) ((struct atm_flow_data *) ((vcc)->user_back)) |
1da177e4c Linux-2.6.12-rc2 |
41 |
struct atm_flow_data { |
b0188d4db [NET_SCHED]: sch_... |
42 |
struct Qdisc *q; /* FIFO, TBF, etc. */ |
1da177e4c Linux-2.6.12-rc2 |
43 |
struct tcf_proto *filter_list; |
b0188d4db [NET_SCHED]: sch_... |
44 45 |
struct atm_vcc *vcc; /* VCC; NULL if VCC is closed */ void (*old_pop)(struct atm_vcc *vcc, |
786a90366 [PKT_SCHED] sch_a... |
46 |
struct sk_buff *skb); /* chaining */ |
1da177e4c Linux-2.6.12-rc2 |
47 48 49 50 |
struct atm_qdisc_data *parent; /* parent qdisc */ struct socket *sock; /* for closing */ u32 classid; /* x:y type ID */ int ref; /* reference count */ |
c1a8f1f1c net: restore gnet... |
51 |
struct gnet_stats_basic_packed bstats; |
1da177e4c Linux-2.6.12-rc2 |
52 |
struct gnet_stats_queue qstats; |
6accec76f sch_atm: Convert ... |
53 |
struct list_head list; |
1da177e4c Linux-2.6.12-rc2 |
54 55 56 57 58 59 60 61 |
struct atm_flow_data *excess; /* flow for excess traffic; NULL to set CLP instead */ int hdr_len; unsigned char hdr[0]; /* header data; MUST BE LAST */ }; struct atm_qdisc_data { struct atm_flow_data link; /* unclassified skbs go here */ |
6accec76f sch_atm: Convert ... |
62 |
struct list_head flows; /* NB: "link" is also on this |
1da177e4c Linux-2.6.12-rc2 |
63 |
list */ |
f30ab418a pkt_sched: Remove... |
64 |
struct tasklet_struct task; /* dequeue tasklet */ |
1da177e4c Linux-2.6.12-rc2 |
65 |
}; |
1da177e4c Linux-2.6.12-rc2 |
66 |
/* ------------------------- Class/flow operations ------------------------- */ |
b0188d4db [NET_SCHED]: sch_... |
67 |
static inline struct atm_flow_data *lookup_flow(struct Qdisc *sch, u32 classid) |
1da177e4c Linux-2.6.12-rc2 |
68 |
{ |
786a90366 [PKT_SCHED] sch_a... |
69 |
struct atm_qdisc_data *p = qdisc_priv(sch); |
1da177e4c Linux-2.6.12-rc2 |
70 |
struct atm_flow_data *flow; |
6accec76f sch_atm: Convert ... |
71 |
list_for_each_entry(flow, &p->flows, list) { |
b0188d4db [NET_SCHED]: sch_... |
72 |
if (flow->classid == classid) |
6accec76f sch_atm: Convert ... |
73 74 75 |
return flow; } return NULL; |
1da177e4c Linux-2.6.12-rc2 |
76 |
} |
b0188d4db [NET_SCHED]: sch_... |
77 78 |
static int atm_tc_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new, struct Qdisc **old) |
1da177e4c Linux-2.6.12-rc2 |
79 |
{ |
786a90366 [PKT_SCHED] sch_a... |
80 |
struct atm_qdisc_data *p = qdisc_priv(sch); |
b0188d4db [NET_SCHED]: sch_... |
81 |
struct atm_flow_data *flow = (struct atm_flow_data *)arg; |
786a90366 [PKT_SCHED] sch_a... |
82 83 |
pr_debug("atm_tc_graft(sch %p,[qdisc %p],flow %p,new %p,old %p) ", |
b0188d4db [NET_SCHED]: sch_... |
84 |
sch, p, flow, new, old); |
6accec76f sch_atm: Convert ... |
85 |
if (list_empty(&flow->list)) |
b0188d4db [NET_SCHED]: sch_... |
86 87 88 |
return -EINVAL; if (!new) new = &noop_qdisc; |
b94c8afcb pkt_sched: remove... |
89 90 |
*old = flow->q; flow->q = new; |
b0188d4db [NET_SCHED]: sch_... |
91 92 |
if (*old) qdisc_reset(*old); |
10297b993 [NET] SCHED: Fix ... |
93 |
return 0; |
1da177e4c Linux-2.6.12-rc2 |
94 |
} |
b0188d4db [NET_SCHED]: sch_... |
95 |
static struct Qdisc *atm_tc_leaf(struct Qdisc *sch, unsigned long cl) |
1da177e4c Linux-2.6.12-rc2 |
96 |
{ |
b0188d4db [NET_SCHED]: sch_... |
97 |
struct atm_flow_data *flow = (struct atm_flow_data *)cl; |
1da177e4c Linux-2.6.12-rc2 |
98 |
|
786a90366 [PKT_SCHED] sch_a... |
99 100 |
pr_debug("atm_tc_leaf(sch %p,flow %p) ", sch, flow); |
1da177e4c Linux-2.6.12-rc2 |
101 102 |
return flow ? flow->q : NULL; } |
b0188d4db [NET_SCHED]: sch_... |
103 |
static unsigned long atm_tc_get(struct Qdisc *sch, u32 classid) |
1da177e4c Linux-2.6.12-rc2 |
104 |
{ |
786a90366 [PKT_SCHED] sch_a... |
105 |
struct atm_qdisc_data *p __maybe_unused = qdisc_priv(sch); |
1da177e4c Linux-2.6.12-rc2 |
106 |
struct atm_flow_data *flow; |
786a90366 [PKT_SCHED] sch_a... |
107 108 |
pr_debug("atm_tc_get(sch %p,[qdisc %p],classid %x) ", sch, p, classid); |
b0188d4db [NET_SCHED]: sch_... |
109 110 111 |
flow = lookup_flow(sch, classid); if (flow) flow->ref++; |
786a90366 [PKT_SCHED] sch_a... |
112 113 |
pr_debug("atm_tc_get: flow %p ", flow); |
b0188d4db [NET_SCHED]: sch_... |
114 |
return (unsigned long)flow; |
1da177e4c Linux-2.6.12-rc2 |
115 |
} |
1da177e4c Linux-2.6.12-rc2 |
116 |
static unsigned long atm_tc_bind_filter(struct Qdisc *sch, |
b0188d4db [NET_SCHED]: sch_... |
117 |
unsigned long parent, u32 classid) |
1da177e4c Linux-2.6.12-rc2 |
118 |
{ |
b0188d4db [NET_SCHED]: sch_... |
119 |
return atm_tc_get(sch, classid); |
1da177e4c Linux-2.6.12-rc2 |
120 |
} |
1da177e4c Linux-2.6.12-rc2 |
121 122 123 124 125 |
/* * 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. */ |
1da177e4c Linux-2.6.12-rc2 |
126 127 |
static void atm_tc_put(struct Qdisc *sch, unsigned long cl) { |
786a90366 [PKT_SCHED] sch_a... |
128 |
struct atm_qdisc_data *p = qdisc_priv(sch); |
b0188d4db [NET_SCHED]: sch_... |
129 |
struct atm_flow_data *flow = (struct atm_flow_data *)cl; |
1da177e4c Linux-2.6.12-rc2 |
130 |
|
786a90366 [PKT_SCHED] sch_a... |
131 132 |
pr_debug("atm_tc_put(sch %p,[qdisc %p],flow %p) ", sch, p, flow); |
b0188d4db [NET_SCHED]: sch_... |
133 134 |
if (--flow->ref) return; |
786a90366 [PKT_SCHED] sch_a... |
135 136 |
pr_debug("atm_tc_put: destroying "); |
6accec76f sch_atm: Convert ... |
137 |
list_del_init(&flow->list); |
786a90366 [PKT_SCHED] sch_a... |
138 139 |
pr_debug("atm_tc_put: qdisc %p ", flow->q); |
1da177e4c Linux-2.6.12-rc2 |
140 |
qdisc_destroy(flow->q); |
ff31ab56c net-sched: change... |
141 |
tcf_destroy_chain(&flow->filter_list); |
1da177e4c Linux-2.6.12-rc2 |
142 |
if (flow->sock) { |
516e0cc56 [PATCH] f_count m... |
143 144 |
pr_debug("atm_tc_put: f_count %ld ", |
b0188d4db [NET_SCHED]: sch_... |
145 |
file_count(flow->sock->file)); |
1da177e4c Linux-2.6.12-rc2 |
146 147 148 |
flow->vcc->pop = flow->old_pop; sockfd_put(flow->sock); } |
b0188d4db [NET_SCHED]: sch_... |
149 150 151 152 |
if (flow->excess) atm_tc_put(sch, (unsigned long)flow->excess); if (flow != &p->link) kfree(flow); |
1da177e4c Linux-2.6.12-rc2 |
153 154 155 156 157 |
/* * If flow == &p->link, the qdisc no longer works at this point and * needs to be removed. (By the caller of atm_tc_put.) */ } |
b0188d4db [NET_SCHED]: sch_... |
158 |
static void sch_atm_pop(struct atm_vcc *vcc, struct sk_buff *skb) |
1da177e4c Linux-2.6.12-rc2 |
159 160 |
{ struct atm_qdisc_data *p = VCC2FLOW(vcc)->parent; |
786a90366 [PKT_SCHED] sch_a... |
161 162 |
pr_debug("sch_atm_pop(vcc %p,skb %p,[qdisc %p]) ", vcc, skb, p); |
b0188d4db [NET_SCHED]: sch_... |
163 |
VCC2FLOW(vcc)->old_pop(vcc, skb); |
1da177e4c Linux-2.6.12-rc2 |
164 165 166 167 |
tasklet_schedule(&p->task); } static const u8 llc_oui_ip[] = { |
b0188d4db [NET_SCHED]: sch_... |
168 169 170 171 |
0xaa, /* DSAP: non-ISO */ 0xaa, /* SSAP: non-ISO */ 0x03, /* Ctrl: Unnumbered Information Command PDU */ 0x00, /* OUI: EtherType */ |
1da177e4c Linux-2.6.12-rc2 |
172 |
0x00, 0x00, |
b0188d4db [NET_SCHED]: sch_... |
173 174 |
0x08, 0x00 }; /* Ethertype IP (0800) */ |
1da177e4c Linux-2.6.12-rc2 |
175 |
|
27a3421e4 [NET_SCHED]: Use ... |
176 177 178 179 |
static const struct nla_policy atm_policy[TCA_ATM_MAX + 1] = { [TCA_ATM_FD] = { .type = NLA_U32 }, [TCA_ATM_EXCESS] = { .type = NLA_U32 }, }; |
1da177e4c Linux-2.6.12-rc2 |
180 |
static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent, |
1e90474c3 [NET_SCHED]: Conv... |
181 |
struct nlattr **tca, unsigned long *arg) |
1da177e4c Linux-2.6.12-rc2 |
182 |
{ |
786a90366 [PKT_SCHED] sch_a... |
183 |
struct atm_qdisc_data *p = qdisc_priv(sch); |
b0188d4db [NET_SCHED]: sch_... |
184 |
struct atm_flow_data *flow = (struct atm_flow_data *)*arg; |
1da177e4c Linux-2.6.12-rc2 |
185 |
struct atm_flow_data *excess = NULL; |
1e90474c3 [NET_SCHED]: Conv... |
186 187 |
struct nlattr *opt = tca[TCA_OPTIONS]; struct nlattr *tb[TCA_ATM_MAX + 1]; |
1da177e4c Linux-2.6.12-rc2 |
188 |
struct socket *sock; |
b0188d4db [NET_SCHED]: sch_... |
189 |
int fd, error, hdr_len; |
1da177e4c Linux-2.6.12-rc2 |
190 |
void *hdr; |
786a90366 [PKT_SCHED] sch_a... |
191 |
pr_debug("atm_tc_change(sch %p,[qdisc %p],classid %x,parent %x," |
b0188d4db [NET_SCHED]: sch_... |
192 193 |
"flow %p,opt %p) ", sch, p, classid, parent, flow, opt); |
1da177e4c Linux-2.6.12-rc2 |
194 195 196 197 198 199 200 201 202 203 204 205 |
/* * 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.) */ |
b0188d4db [NET_SCHED]: sch_... |
206 207 |
if (flow) return -EBUSY; |
cee63723b [NET_SCHED]: Prop... |
208 |
if (opt == NULL) |
1da177e4c Linux-2.6.12-rc2 |
209 |
return -EINVAL; |
27a3421e4 [NET_SCHED]: Use ... |
210 211 |
error = nla_parse_nested(tb, TCA_ATM_MAX, opt, atm_policy); |
cee63723b [NET_SCHED]: Prop... |
212 213 |
if (error < 0) return error; |
27a3421e4 [NET_SCHED]: Use ... |
214 |
if (!tb[TCA_ATM_FD]) |
1da177e4c Linux-2.6.12-rc2 |
215 |
return -EINVAL; |
1587bac49 [NET_SCHED]: Use ... |
216 |
fd = nla_get_u32(tb[TCA_ATM_FD]); |
786a90366 [PKT_SCHED] sch_a... |
217 218 |
pr_debug("atm_tc_change: fd %d ", fd); |
1e90474c3 [NET_SCHED]: Conv... |
219 220 221 |
if (tb[TCA_ATM_HDR]) { hdr_len = nla_len(tb[TCA_ATM_HDR]); hdr = nla_data(tb[TCA_ATM_HDR]); |
b0188d4db [NET_SCHED]: sch_... |
222 |
} else { |
1da177e4c Linux-2.6.12-rc2 |
223 |
hdr_len = RFC1483LLC_LEN; |
b0188d4db [NET_SCHED]: sch_... |
224 |
hdr = NULL; /* default LLC/SNAP for IP */ |
1da177e4c Linux-2.6.12-rc2 |
225 |
} |
1e90474c3 [NET_SCHED]: Conv... |
226 |
if (!tb[TCA_ATM_EXCESS]) |
b0188d4db [NET_SCHED]: sch_... |
227 |
excess = NULL; |
1da177e4c Linux-2.6.12-rc2 |
228 |
else { |
b0188d4db [NET_SCHED]: sch_... |
229 |
excess = (struct atm_flow_data *) |
1587bac49 [NET_SCHED]: Use ... |
230 |
atm_tc_get(sch, nla_get_u32(tb[TCA_ATM_EXCESS])); |
b0188d4db [NET_SCHED]: sch_... |
231 232 |
if (!excess) return -ENOENT; |
1da177e4c Linux-2.6.12-rc2 |
233 |
} |
f5e5cb755 [NET_SCHED]: sch_... |
234 235 |
pr_debug("atm_tc_change: type %d, payload %d, hdr_len %d ", |
1e90474c3 [NET_SCHED]: Conv... |
236 |
opt->nla_type, nla_len(opt), hdr_len); |
786a90366 [PKT_SCHED] sch_a... |
237 238 |
sock = sockfd_lookup(fd, &error); if (!sock) |
b0188d4db [NET_SCHED]: sch_... |
239 |
return error; /* f_count++ */ |
516e0cc56 [PATCH] f_count m... |
240 241 |
pr_debug("atm_tc_change: f_count %ld ", file_count(sock->file)); |
10297b993 [NET] SCHED: Fix ... |
242 |
if (sock->ops->family != PF_ATMSVC && sock->ops->family != PF_ATMPVC) { |
1da177e4c Linux-2.6.12-rc2 |
243 |
error = -EPROTOTYPE; |
10297b993 [NET] SCHED: Fix ... |
244 |
goto err_out; |
1da177e4c Linux-2.6.12-rc2 |
245 246 247 248 249 |
} /* @@@ should check if the socket is really operational or we'll crash on vcc->send */ if (classid) { if (TC_H_MAJ(classid ^ sch->handle)) { |
786a90366 [PKT_SCHED] sch_a... |
250 251 |
pr_debug("atm_tc_change: classid mismatch "); |
1da177e4c Linux-2.6.12-rc2 |
252 253 254 |
error = -EINVAL; goto err_out; } |
b0188d4db [NET_SCHED]: sch_... |
255 |
} else { |
1da177e4c Linux-2.6.12-rc2 |
256 257 258 259 |
int i; unsigned long cl; for (i = 1; i < 0x8000; i++) { |
b0188d4db [NET_SCHED]: sch_... |
260 |
classid = TC_H_MAKE(sch->handle, 0x8000 | i); |
786a90366 [PKT_SCHED] sch_a... |
261 262 |
cl = atm_tc_get(sch, classid); if (!cl) |
b0188d4db [NET_SCHED]: sch_... |
263 264 |
break; atm_tc_put(sch, cl); |
1da177e4c Linux-2.6.12-rc2 |
265 266 |
} } |
786a90366 [PKT_SCHED] sch_a... |
267 268 |
pr_debug("atm_tc_change: new id %x ", classid); |
782f79568 [ATM]: Replacing ... |
269 |
flow = kzalloc(sizeof(struct atm_flow_data) + hdr_len, GFP_KERNEL); |
786a90366 [PKT_SCHED] sch_a... |
270 271 |
pr_debug("atm_tc_change: flow %p ", flow); |
1da177e4c Linux-2.6.12-rc2 |
272 273 274 275 |
if (!flow) { error = -ENOBUFS; goto err_out; } |
1da177e4c Linux-2.6.12-rc2 |
276 |
flow->filter_list = NULL; |
3511c9132 net_sched: remove... |
277 |
flow->q = qdisc_create_dflt(sch->dev_queue, &pfifo_qdisc_ops, classid); |
786a90366 [PKT_SCHED] sch_a... |
278 |
if (!flow->q) |
1da177e4c Linux-2.6.12-rc2 |
279 |
flow->q = &noop_qdisc; |
786a90366 [PKT_SCHED] sch_a... |
280 281 |
pr_debug("atm_tc_change: qdisc %p ", flow->q); |
1da177e4c Linux-2.6.12-rc2 |
282 |
flow->sock = sock; |
b0188d4db [NET_SCHED]: sch_... |
283 |
flow->vcc = ATM_SD(sock); /* speedup */ |
1da177e4c Linux-2.6.12-rc2 |
284 |
flow->vcc->user_back = flow; |
786a90366 [PKT_SCHED] sch_a... |
285 286 |
pr_debug("atm_tc_change: vcc %p ", flow->vcc); |
1da177e4c Linux-2.6.12-rc2 |
287 288 289 290 291 292 |
flow->old_pop = flow->vcc->pop; flow->parent = p; flow->vcc->pop = sch_atm_pop; flow->classid = classid; flow->ref = 1; flow->excess = excess; |
6accec76f sch_atm: Convert ... |
293 |
list_add(&flow->list, &p->link.list); |
1da177e4c Linux-2.6.12-rc2 |
294 295 |
flow->hdr_len = hdr_len; if (hdr) |
b0188d4db [NET_SCHED]: sch_... |
296 |
memcpy(flow->hdr, hdr, hdr_len); |
1da177e4c Linux-2.6.12-rc2 |
297 |
else |
b0188d4db [NET_SCHED]: sch_... |
298 299 |
memcpy(flow->hdr, llc_oui_ip, sizeof(llc_oui_ip)); *arg = (unsigned long)flow; |
1da177e4c Linux-2.6.12-rc2 |
300 301 |
return 0; err_out: |
b0188d4db [NET_SCHED]: sch_... |
302 303 |
if (excess) atm_tc_put(sch, (unsigned long)excess); |
1da177e4c Linux-2.6.12-rc2 |
304 305 306 |
sockfd_put(sock); return error; } |
b0188d4db [NET_SCHED]: sch_... |
307 |
static int atm_tc_delete(struct Qdisc *sch, unsigned long arg) |
1da177e4c Linux-2.6.12-rc2 |
308 |
{ |
786a90366 [PKT_SCHED] sch_a... |
309 |
struct atm_qdisc_data *p = qdisc_priv(sch); |
b0188d4db [NET_SCHED]: sch_... |
310 |
struct atm_flow_data *flow = (struct atm_flow_data *)arg; |
1da177e4c Linux-2.6.12-rc2 |
311 |
|
786a90366 [PKT_SCHED] sch_a... |
312 313 |
pr_debug("atm_tc_delete(sch %p,[qdisc %p],flow %p) ", sch, p, flow); |
6accec76f sch_atm: Convert ... |
314 |
if (list_empty(&flow->list)) |
b0188d4db [NET_SCHED]: sch_... |
315 316 317 |
return -EINVAL; if (flow->filter_list || flow == &p->link) return -EBUSY; |
1da177e4c Linux-2.6.12-rc2 |
318 319 320 321 322 |
/* * 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) { |
cc7ec456f net_sched: cleanups |
323 324 |
pr_err("atm_tc_delete: flow->ref == %d ", flow->ref); |
1da177e4c Linux-2.6.12-rc2 |
325 326 |
return -EINVAL; } |
b0188d4db [NET_SCHED]: sch_... |
327 328 329 |
if (flow->ref > 2) return -EBUSY; /* catch references via excess, etc. */ atm_tc_put(sch, arg); |
1da177e4c Linux-2.6.12-rc2 |
330 331 |
return 0; } |
b0188d4db [NET_SCHED]: sch_... |
332 |
static void atm_tc_walk(struct Qdisc *sch, struct qdisc_walker *walker) |
1da177e4c Linux-2.6.12-rc2 |
333 |
{ |
786a90366 [PKT_SCHED] sch_a... |
334 |
struct atm_qdisc_data *p = qdisc_priv(sch); |
1da177e4c Linux-2.6.12-rc2 |
335 |
struct atm_flow_data *flow; |
786a90366 [PKT_SCHED] sch_a... |
336 337 |
pr_debug("atm_tc_walk(sch %p,[qdisc %p],walker %p) ", sch, p, walker); |
b0188d4db [NET_SCHED]: sch_... |
338 339 |
if (walker->stop) return; |
6accec76f sch_atm: Convert ... |
340 341 342 343 344 345 |
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; } |
1da177e4c Linux-2.6.12-rc2 |
346 347 348 |
walker->count++; } } |
b0188d4db [NET_SCHED]: sch_... |
349 |
static struct tcf_proto **atm_tc_find_tcf(struct Qdisc *sch, unsigned long cl) |
1da177e4c Linux-2.6.12-rc2 |
350 |
{ |
786a90366 [PKT_SCHED] sch_a... |
351 |
struct atm_qdisc_data *p = qdisc_priv(sch); |
b0188d4db [NET_SCHED]: sch_... |
352 |
struct atm_flow_data *flow = (struct atm_flow_data *)cl; |
1da177e4c Linux-2.6.12-rc2 |
353 |
|
786a90366 [PKT_SCHED] sch_a... |
354 355 |
pr_debug("atm_tc_find_tcf(sch %p,[qdisc %p],flow %p) ", sch, p, flow); |
10297b993 [NET] SCHED: Fix ... |
356 |
return flow ? &flow->filter_list : &p->link.filter_list; |
1da177e4c Linux-2.6.12-rc2 |
357 |
} |
1da177e4c Linux-2.6.12-rc2 |
358 |
/* --------------------------- Qdisc operations ---------------------------- */ |
b0188d4db [NET_SCHED]: sch_... |
359 |
static int atm_tc_enqueue(struct sk_buff *skb, struct Qdisc *sch) |
1da177e4c Linux-2.6.12-rc2 |
360 |
{ |
786a90366 [PKT_SCHED] sch_a... |
361 |
struct atm_qdisc_data *p = qdisc_priv(sch); |
6accec76f sch_atm: Convert ... |
362 |
struct atm_flow_data *flow; |
1da177e4c Linux-2.6.12-rc2 |
363 364 365 |
struct tcf_result res; int result; int ret = NET_XMIT_POLICED; |
786a90366 [PKT_SCHED] sch_a... |
366 367 |
pr_debug("atm_tc_enqueue(skb %p,sch %p,[qdisc %p]) ", skb, sch, p); |
b0188d4db [NET_SCHED]: sch_... |
368 |
result = TC_POLICE_OK; /* be nice to gcc */ |
6accec76f sch_atm: Convert ... |
369 |
flow = NULL; |
1da177e4c Linux-2.6.12-rc2 |
370 |
if (TC_H_MAJ(skb->priority) != sch->handle || |
6accec76f sch_atm: Convert ... |
371 372 |
!(flow = (struct atm_flow_data *)atm_tc_get(sch, skb->priority))) { list_for_each_entry(flow, &p->flows, list) { |
1da177e4c Linux-2.6.12-rc2 |
373 |
if (flow->filter_list) { |
73ca4918f [NET_SCHED]: act_... |
374 375 376 |
result = tc_classify_compat(skb, flow->filter_list, &res); |
b0188d4db [NET_SCHED]: sch_... |
377 378 379 380 381 |
if (result < 0) continue; flow = (struct atm_flow_data *)res.class; if (!flow) flow = lookup_flow(sch, res.classid); |
6accec76f sch_atm: Convert ... |
382 |
goto done; |
1da177e4c Linux-2.6.12-rc2 |
383 |
} |
6accec76f sch_atm: Convert ... |
384 385 |
} flow = NULL; |
cc7ec456f net_sched: cleanups |
386 387 |
done: ; |
6accec76f sch_atm: Convert ... |
388 |
} |
cc7ec456f net_sched: cleanups |
389 |
if (!flow) { |
b0188d4db [NET_SCHED]: sch_... |
390 |
flow = &p->link; |
cc7ec456f net_sched: cleanups |
391 |
} else { |
1da177e4c Linux-2.6.12-rc2 |
392 393 |
if (flow->vcc) ATM_SKB(skb)->atm_options = flow->vcc->atm_options; |
b0188d4db [NET_SCHED]: sch_... |
394 |
/*@@@ looks good ... but it's not supposed to work :-) */ |
921008044 [NET_SCHED]: sch_... |
395 396 397 398 399 |
#ifdef CONFIG_NET_CLS_ACT switch (result) { case TC_ACT_QUEUED: case TC_ACT_STOLEN: kfree_skb(skb); |
378a2f090 net_sched: Add qd... |
400 |
return NET_XMIT_SUCCESS | __NET_XMIT_STOLEN; |
921008044 [NET_SCHED]: sch_... |
401 402 403 |
case TC_ACT_SHOT: kfree_skb(skb); goto drop; |
73ca4918f [NET_SCHED]: act_... |
404 405 406 407 408 409 |
case TC_POLICE_RECLASSIFY: if (flow->excess) flow = flow->excess; else ATM_SKB(skb)->atm_options |= ATM_ATMOPT_CLP; break; |
921008044 [NET_SCHED]: sch_... |
410 |
} |
1da177e4c Linux-2.6.12-rc2 |
411 412 |
#endif } |
c3bc7cff8 [NET_SCHED]: Kill... |
413 |
|
5f86173bd net_sched: Add qd... |
414 |
ret = qdisc_enqueue(skb, flow->q); |
9871e50ed net: Use NET_XMIT... |
415 |
if (ret != NET_XMIT_SUCCESS) { |
921008044 [NET_SCHED]: sch_... |
416 |
drop: __maybe_unused |
378a2f090 net_sched: Add qd... |
417 418 419 420 421 |
if (net_xmit_drop_count(ret)) { sch->qstats.drops++; if (flow) flow->qstats.drops++; } |
1da177e4c Linux-2.6.12-rc2 |
422 423 |
return ret; } |
bfe0d0298 net_sched: factor... |
424 425 |
qdisc_bstats_update(sch, skb); bstats_update(&flow->bstats, skb); |
1da177e4c Linux-2.6.12-rc2 |
426 427 428 429 430 431 432 433 434 435 436 |
/* * 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++; |
9871e50ed net: Use NET_XMIT... |
437 |
return NET_XMIT_SUCCESS; |
1da177e4c Linux-2.6.12-rc2 |
438 439 |
} tasklet_schedule(&p->task); |
c27f339af net_sched: Add qd... |
440 |
return NET_XMIT_SUCCESS | __NET_XMIT_BYPASS; |
1da177e4c Linux-2.6.12-rc2 |
441 |
} |
1da177e4c Linux-2.6.12-rc2 |
442 443 444 445 446 447 |
/* * 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. */ |
1da177e4c Linux-2.6.12-rc2 |
448 449 |
static void sch_atm_dequeue(unsigned long data) { |
b0188d4db [NET_SCHED]: sch_... |
450 |
struct Qdisc *sch = (struct Qdisc *)data; |
786a90366 [PKT_SCHED] sch_a... |
451 |
struct atm_qdisc_data *p = qdisc_priv(sch); |
1da177e4c Linux-2.6.12-rc2 |
452 453 |
struct atm_flow_data *flow; struct sk_buff *skb; |
786a90366 [PKT_SCHED] sch_a... |
454 455 |
pr_debug("sch_atm_dequeue(sch %p,[qdisc %p]) ", sch, p); |
6accec76f sch_atm: Convert ... |
456 457 458 |
list_for_each_entry(flow, &p->flows, list) { if (flow == &p->link) continue; |
1da177e4c Linux-2.6.12-rc2 |
459 460 461 462 |
/* * If traffic is properly shaped, this won't generate nasty * little bursts. Otherwise, it may ... (but that's okay) */ |
03c05f0d4 pkt_sched: Use qd... |
463 464 |
while ((skb = flow->q->ops->peek(flow->q))) { if (!atm_may_send(flow->vcc, skb->truesize)) |
1da177e4c Linux-2.6.12-rc2 |
465 |
break; |
03c05f0d4 pkt_sched: Use qd... |
466 |
|
77be155cb pkt_sched: Add pe... |
467 |
skb = qdisc_dequeue_peeked(flow->q); |
03c05f0d4 pkt_sched: Use qd... |
468 469 |
if (unlikely(!skb)) break; |
786a90366 [PKT_SCHED] sch_a... |
470 471 |
pr_debug("atm_tc_dequeue: sending on class %p ", flow); |
1da177e4c Linux-2.6.12-rc2 |
472 |
/* remove any LL header somebody else has attached */ |
eddc9ec53 [SK_BUFF]: Introd... |
473 |
skb_pull(skb, skb_network_offset(skb)); |
1da177e4c Linux-2.6.12-rc2 |
474 475 |
if (skb_headroom(skb) < flow->hdr_len) { struct sk_buff *new; |
b0188d4db [NET_SCHED]: sch_... |
476 |
new = skb_realloc_headroom(skb, flow->hdr_len); |
1da177e4c Linux-2.6.12-rc2 |
477 |
dev_kfree_skb(skb); |
b0188d4db [NET_SCHED]: sch_... |
478 479 |
if (!new) continue; |
1da177e4c Linux-2.6.12-rc2 |
480 481 |
skb = new; } |
786a90366 [PKT_SCHED] sch_a... |
482 483 |
pr_debug("sch_atm_dequeue: ip %p, data %p ", |
eddc9ec53 [SK_BUFF]: Introd... |
484 |
skb_network_header(skb), skb->data); |
1da177e4c Linux-2.6.12-rc2 |
485 |
ATM_SKB(skb)->vcc = flow->vcc; |
b0188d4db [NET_SCHED]: sch_... |
486 487 |
memcpy(skb_push(skb, flow->hdr_len), flow->hdr, flow->hdr_len); |
1da177e4c Linux-2.6.12-rc2 |
488 489 490 |
atomic_add(skb->truesize, &sk_atm(flow->vcc)->sk_wmem_alloc); /* atm.atm_options are already set by atm_tc_enqueue */ |
b0188d4db [NET_SCHED]: sch_... |
491 |
flow->vcc->send(flow->vcc, skb); |
1da177e4c Linux-2.6.12-rc2 |
492 |
} |
6accec76f sch_atm: Convert ... |
493 |
} |
1da177e4c Linux-2.6.12-rc2 |
494 |
} |
1da177e4c Linux-2.6.12-rc2 |
495 496 |
static struct sk_buff *atm_tc_dequeue(struct Qdisc *sch) { |
786a90366 [PKT_SCHED] sch_a... |
497 |
struct atm_qdisc_data *p = qdisc_priv(sch); |
1da177e4c Linux-2.6.12-rc2 |
498 |
struct sk_buff *skb; |
786a90366 [PKT_SCHED] sch_a... |
499 500 |
pr_debug("atm_tc_dequeue(sch %p,[qdisc %p]) ", sch, p); |
1da177e4c Linux-2.6.12-rc2 |
501 |
tasklet_schedule(&p->task); |
77be155cb pkt_sched: Add pe... |
502 |
skb = qdisc_dequeue_peeked(p->link.q); |
b0188d4db [NET_SCHED]: sch_... |
503 504 |
if (skb) sch->q.qlen--; |
1da177e4c Linux-2.6.12-rc2 |
505 506 |
return skb; } |
8e3af9789 pkt_sched: Add qd... |
507 508 509 510 511 512 513 514 515 |
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]) ", sch, p); return p->link.q->ops->peek(p->link.q); } |
1da177e4c Linux-2.6.12-rc2 |
516 517 |
static unsigned int atm_tc_drop(struct Qdisc *sch) { |
786a90366 [PKT_SCHED] sch_a... |
518 |
struct atm_qdisc_data *p = qdisc_priv(sch); |
1da177e4c Linux-2.6.12-rc2 |
519 520 |
struct atm_flow_data *flow; unsigned int len; |
786a90366 [PKT_SCHED] sch_a... |
521 522 |
pr_debug("atm_tc_drop(sch %p,[qdisc %p]) ", sch, p); |
6accec76f sch_atm: Convert ... |
523 |
list_for_each_entry(flow, &p->flows, list) { |
1da177e4c Linux-2.6.12-rc2 |
524 525 |
if (flow->q->ops->drop && (len = flow->q->ops->drop(flow->q))) return len; |
6accec76f sch_atm: Convert ... |
526 |
} |
1da177e4c Linux-2.6.12-rc2 |
527 528 |
return 0; } |
1e90474c3 [NET_SCHED]: Conv... |
529 |
static int atm_tc_init(struct Qdisc *sch, struct nlattr *opt) |
1da177e4c Linux-2.6.12-rc2 |
530 |
{ |
786a90366 [PKT_SCHED] sch_a... |
531 |
struct atm_qdisc_data *p = qdisc_priv(sch); |
1da177e4c Linux-2.6.12-rc2 |
532 |
|
786a90366 [PKT_SCHED] sch_a... |
533 534 |
pr_debug("atm_tc_init(sch %p,[qdisc %p],opt %p) ", sch, p, opt); |
6accec76f sch_atm: Convert ... |
535 536 537 |
INIT_LIST_HEAD(&p->flows); INIT_LIST_HEAD(&p->link.list); list_add(&p->link.list, &p->flows); |
3511c9132 net_sched: remove... |
538 |
p->link.q = qdisc_create_dflt(sch->dev_queue, |
bb949fbd1 netdev: Create ne... |
539 |
&pfifo_qdisc_ops, sch->handle); |
786a90366 [PKT_SCHED] sch_a... |
540 |
if (!p->link.q) |
1da177e4c Linux-2.6.12-rc2 |
541 |
p->link.q = &noop_qdisc; |
786a90366 [PKT_SCHED] sch_a... |
542 543 |
pr_debug("atm_tc_init: link (%p) qdisc %p ", &p->link, p->link.q); |
1da177e4c Linux-2.6.12-rc2 |
544 545 546 547 548 |
p->link.filter_list = NULL; p->link.vcc = NULL; p->link.sock = NULL; p->link.classid = sch->handle; p->link.ref = 1; |
b0188d4db [NET_SCHED]: sch_... |
549 |
tasklet_init(&p->task, sch_atm_dequeue, (unsigned long)sch); |
1da177e4c Linux-2.6.12-rc2 |
550 551 |
return 0; } |
1da177e4c Linux-2.6.12-rc2 |
552 553 |
static void atm_tc_reset(struct Qdisc *sch) { |
786a90366 [PKT_SCHED] sch_a... |
554 |
struct atm_qdisc_data *p = qdisc_priv(sch); |
1da177e4c Linux-2.6.12-rc2 |
555 |
struct atm_flow_data *flow; |
786a90366 [PKT_SCHED] sch_a... |
556 557 |
pr_debug("atm_tc_reset(sch %p,[qdisc %p]) ", sch, p); |
6accec76f sch_atm: Convert ... |
558 |
list_for_each_entry(flow, &p->flows, list) |
b0188d4db [NET_SCHED]: sch_... |
559 |
qdisc_reset(flow->q); |
1da177e4c Linux-2.6.12-rc2 |
560 561 |
sch->q.qlen = 0; } |
1da177e4c Linux-2.6.12-rc2 |
562 563 |
static void atm_tc_destroy(struct Qdisc *sch) { |
786a90366 [PKT_SCHED] sch_a... |
564 |
struct atm_qdisc_data *p = qdisc_priv(sch); |
6accec76f sch_atm: Convert ... |
565 |
struct atm_flow_data *flow, *tmp; |
1da177e4c Linux-2.6.12-rc2 |
566 |
|
786a90366 [PKT_SCHED] sch_a... |
567 568 |
pr_debug("atm_tc_destroy(sch %p,[qdisc %p]) ", sch, p); |
6accec76f sch_atm: Convert ... |
569 |
list_for_each_entry(flow, &p->flows, list) |
a4aebb83c net-sched: fix fi... |
570 |
tcf_destroy_chain(&flow->filter_list); |
6accec76f sch_atm: Convert ... |
571 |
list_for_each_entry_safe(flow, tmp, &p->flows, list) { |
1da177e4c Linux-2.6.12-rc2 |
572 |
if (flow->ref > 1) |
cc7ec456f net_sched: cleanups |
573 574 |
pr_err("atm_destroy: %p->ref = %d ", flow, flow->ref); |
b0188d4db [NET_SCHED]: sch_... |
575 |
atm_tc_put(sch, (unsigned long)flow); |
1da177e4c Linux-2.6.12-rc2 |
576 577 578 |
} tasklet_kill(&p->task); } |
1da177e4c Linux-2.6.12-rc2 |
579 |
static int atm_tc_dump_class(struct Qdisc *sch, unsigned long cl, |
b0188d4db [NET_SCHED]: sch_... |
580 |
struct sk_buff *skb, struct tcmsg *tcm) |
1da177e4c Linux-2.6.12-rc2 |
581 |
{ |
786a90366 [PKT_SCHED] sch_a... |
582 |
struct atm_qdisc_data *p = qdisc_priv(sch); |
b0188d4db [NET_SCHED]: sch_... |
583 |
struct atm_flow_data *flow = (struct atm_flow_data *)cl; |
4b3550ef5 [NET_SCHED]: Use ... |
584 |
struct nlattr *nest; |
1da177e4c Linux-2.6.12-rc2 |
585 |
|
786a90366 [PKT_SCHED] sch_a... |
586 587 |
pr_debug("atm_tc_dump_class(sch %p,[qdisc %p],flow %p,skb %p,tcm %p) ", |
b0188d4db [NET_SCHED]: sch_... |
588 |
sch, p, flow, skb, tcm); |
6accec76f sch_atm: Convert ... |
589 |
if (list_empty(&flow->list)) |
b0188d4db [NET_SCHED]: sch_... |
590 |
return -EINVAL; |
1da177e4c Linux-2.6.12-rc2 |
591 |
tcm->tcm_handle = flow->classid; |
cdc7f8e36 [PKT_SCHED]: Dump... |
592 |
tcm->tcm_info = flow->q->handle; |
4b3550ef5 [NET_SCHED]: Use ... |
593 594 595 596 |
nest = nla_nest_start(skb, TCA_OPTIONS); if (nest == NULL) goto nla_put_failure; |
1e90474c3 [NET_SCHED]: Conv... |
597 |
NLA_PUT(skb, TCA_ATM_HDR, flow->hdr_len, flow->hdr); |
1da177e4c Linux-2.6.12-rc2 |
598 599 600 601 602 603 604 605 |
if (flow->vcc) { struct sockaddr_atmpvc pvc; int state; 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; |
1e90474c3 [NET_SCHED]: Conv... |
606 |
NLA_PUT(skb, TCA_ATM_ADDR, sizeof(pvc), &pvc); |
1da177e4c Linux-2.6.12-rc2 |
607 |
state = ATM_VF2VS(flow->vcc->flags); |
24beeab53 [NET_SCHED]: Use ... |
608 |
NLA_PUT_U32(skb, TCA_ATM_STATE, state); |
1da177e4c Linux-2.6.12-rc2 |
609 610 |
} if (flow->excess) |
24beeab53 [NET_SCHED]: Use ... |
611 |
NLA_PUT_U32(skb, TCA_ATM_EXCESS, flow->classid); |
cc7ec456f net_sched: cleanups |
612 |
else |
24beeab53 [NET_SCHED]: Use ... |
613 |
NLA_PUT_U32(skb, TCA_ATM_EXCESS, 0); |
4b3550ef5 [NET_SCHED]: Use ... |
614 615 |
nla_nest_end(skb, nest); |
1da177e4c Linux-2.6.12-rc2 |
616 |
return skb->len; |
1e90474c3 [NET_SCHED]: Conv... |
617 |
nla_put_failure: |
4b3550ef5 [NET_SCHED]: Use ... |
618 |
nla_nest_cancel(skb, nest); |
1da177e4c Linux-2.6.12-rc2 |
619 620 621 622 |
return -1; } static int atm_tc_dump_class_stats(struct Qdisc *sch, unsigned long arg, |
b0188d4db [NET_SCHED]: sch_... |
623 |
struct gnet_dump *d) |
1da177e4c Linux-2.6.12-rc2 |
624 |
{ |
b0188d4db [NET_SCHED]: sch_... |
625 |
struct atm_flow_data *flow = (struct atm_flow_data *)arg; |
1da177e4c Linux-2.6.12-rc2 |
626 627 628 629 630 631 632 633 634 635 636 637 638 639 |
flow->qstats.qlen = flow->q->q.qlen; if (gnet_stats_copy_basic(d, &flow->bstats) < 0 || gnet_stats_copy_queue(d, &flow->qstats) < 0) return -1; return 0; } static int atm_tc_dump(struct Qdisc *sch, struct sk_buff *skb) { return 0; } |
20fea08b5 [NET]: Move Qdisc... |
640 |
static const struct Qdisc_class_ops atm_class_ops = { |
b0188d4db [NET_SCHED]: sch_... |
641 642 643 644 645 646 647 648 649 650 651 652 |
.graft = atm_tc_graft, .leaf = atm_tc_leaf, .get = atm_tc_get, .put = atm_tc_put, .change = atm_tc_change, .delete = atm_tc_delete, .walk = atm_tc_walk, .tcf_chain = atm_tc_find_tcf, .bind_tcf = atm_tc_bind_filter, .unbind_tcf = atm_tc_put, .dump = atm_tc_dump_class, .dump_stats = atm_tc_dump_class_stats, |
1da177e4c Linux-2.6.12-rc2 |
653 |
}; |
20fea08b5 [NET]: Move Qdisc... |
654 |
static struct Qdisc_ops atm_qdisc_ops __read_mostly = { |
b0188d4db [NET_SCHED]: sch_... |
655 656 657 658 659 |
.cl_ops = &atm_class_ops, .id = "atm", .priv_size = sizeof(struct atm_qdisc_data), .enqueue = atm_tc_enqueue, .dequeue = atm_tc_dequeue, |
8e3af9789 pkt_sched: Add qd... |
660 |
.peek = atm_tc_peek, |
b0188d4db [NET_SCHED]: sch_... |
661 662 663 664 665 666 |
.drop = atm_tc_drop, .init = atm_tc_init, .reset = atm_tc_reset, .destroy = atm_tc_destroy, .dump = atm_tc_dump, .owner = THIS_MODULE, |
1da177e4c Linux-2.6.12-rc2 |
667 |
}; |
1da177e4c Linux-2.6.12-rc2 |
668 669 670 671 |
static int __init atm_init(void) { return register_qdisc(&atm_qdisc_ops); } |
10297b993 [NET] SCHED: Fix ... |
672 |
static void __exit atm_exit(void) |
1da177e4c Linux-2.6.12-rc2 |
673 674 675 676 677 678 679 |
{ unregister_qdisc(&atm_qdisc_ops); } module_init(atm_init) module_exit(atm_exit) MODULE_LICENSE("GPL"); |