aboutsummaryrefslogtreecommitdiffstats
path: root/net/sched
diff options
context:
space:
mode:
Diffstat (limited to 'net/sched')
-rw-r--r--net/sched/Kconfig50
-rw-r--r--net/sched/Makefile3
-rw-r--r--net/sched/act_api.c10
-rw-r--r--net/sched/cls_api.c2
-rw-r--r--net/sched/cls_rsvp.h1
-rw-r--r--net/sched/em_meta.c68
-rw-r--r--net/sched/em_text.c154
-rw-r--r--net/sched/sch_api.c65
-rw-r--r--net/sched/sch_blackhole.c54
-rw-r--r--net/sched/sch_cbq.c3
-rw-r--r--net/sched/sch_generic.c43
-rw-r--r--net/sched/sch_red.c2
12 files changed, 343 insertions, 112 deletions
diff --git a/net/sched/Kconfig b/net/sched/Kconfig
index b22c9beb604d..59d3e71f8b85 100644
--- a/net/sched/Kconfig
+++ b/net/sched/Kconfig
@@ -1,6 +1,43 @@
1# 1#
2# Traffic control configuration. 2# Traffic control configuration.
3# 3#
4
5menuconfig NET_SCHED
6 bool "QoS and/or fair queueing"
7 ---help---
8 When the kernel has several packets to send out over a network
9 device, it has to decide which ones to send first, which ones to
10 delay, and which ones to drop. This is the job of the packet
11 scheduler, and several different algorithms for how to do this
12 "fairly" have been proposed.
13
14 If you say N here, you will get the standard packet scheduler, which
15 is a FIFO (first come, first served). If you say Y here, you will be
16 able to choose from among several alternative algorithms which can
17 then be attached to different network devices. This is useful for
18 example if some of your network devices are real time devices that
19 need a certain minimum data flow rate, or if you need to limit the
20 maximum data flow rate for traffic which matches specified criteria.
21 This code is considered to be experimental.
22
23 To administer these schedulers, you'll need the user-level utilities
24 from the package iproute2+tc at <ftp://ftp.tux.org/pub/net/ip-routing/>.
25 That package also contains some documentation; for more, check out
26 <http://snafu.freedom.org/linux2.2/iproute-notes.html>.
27
28 This Quality of Service (QoS) support will enable you to use
29 Differentiated Services (diffserv) and Resource Reservation Protocol
30 (RSVP) on your Linux router if you also say Y to "QoS support",
31 "Packet classifier API" and to some classifiers below. Documentation
32 and software is at <http://diffserv.sourceforge.net/>.
33
34 If you say Y here and to "/proc file system" below, you will be able
35 to read status information about packet schedulers from the file
36 /proc/net/psched.
37
38 The available schedulers are listed in the following questions; you
39 can say Y to as many as you like. If unsure, say N now.
40
4choice 41choice
5 prompt "Packet scheduler clock source" 42 prompt "Packet scheduler clock source"
6 depends on NET_SCHED 43 depends on NET_SCHED
@@ -449,6 +486,19 @@ config NET_EMATCH_META
449 To compile this code as a module, choose M here: the 486 To compile this code as a module, choose M here: the
450 module will be called em_meta. 487 module will be called em_meta.
451 488
489config NET_EMATCH_TEXT
490 tristate "Textsearch"
491 depends on NET_EMATCH
492 select TEXTSEARCH
493 select TEXTSEARCH_KMP
494 select TEXTSEARCH_FSM
495 ---help---
496 Say Y here if you want to be ablt to classify packets based on
497 textsearch comparisons.
498
499 To compile this code as a module, choose M here: the
500 module will be called em_text.
501
452config NET_CLS_ACT 502config NET_CLS_ACT
453 bool "Packet ACTION" 503 bool "Packet ACTION"
454 depends on EXPERIMENTAL && NET_CLS && NET_QOS 504 depends on EXPERIMENTAL && NET_CLS && NET_QOS
diff --git a/net/sched/Makefile b/net/sched/Makefile
index eb3fe583eba8..e48d0d456b3e 100644
--- a/net/sched/Makefile
+++ b/net/sched/Makefile
@@ -4,7 +4,7 @@
4 4
5obj-y := sch_generic.o 5obj-y := sch_generic.o
6 6
7obj-$(CONFIG_NET_SCHED) += sch_api.o sch_fifo.o 7obj-$(CONFIG_NET_SCHED) += sch_api.o sch_fifo.o sch_blackhole.o
8obj-$(CONFIG_NET_CLS) += cls_api.o 8obj-$(CONFIG_NET_CLS) += cls_api.o
9obj-$(CONFIG_NET_CLS_ACT) += act_api.o 9obj-$(CONFIG_NET_CLS_ACT) += act_api.o
10obj-$(CONFIG_NET_ACT_POLICE) += police.o 10obj-$(CONFIG_NET_ACT_POLICE) += police.o
@@ -40,3 +40,4 @@ obj-$(CONFIG_NET_EMATCH_CMP) += em_cmp.o
40obj-$(CONFIG_NET_EMATCH_NBYTE) += em_nbyte.o 40obj-$(CONFIG_NET_EMATCH_NBYTE) += em_nbyte.o
41obj-$(CONFIG_NET_EMATCH_U32) += em_u32.o 41obj-$(CONFIG_NET_EMATCH_U32) += em_u32.o
42obj-$(CONFIG_NET_EMATCH_META) += em_meta.o 42obj-$(CONFIG_NET_EMATCH_META) += em_meta.o
43obj-$(CONFIG_NET_EMATCH_TEXT) += em_text.o
diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index 9594206e6035..249c61936ea0 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -439,6 +439,8 @@ tca_get_fill(struct sk_buff *skb, struct tc_action *a, u32 pid, u32 seq,
439 439
440 t = NLMSG_DATA(nlh); 440 t = NLMSG_DATA(nlh);
441 t->tca_family = AF_UNSPEC; 441 t->tca_family = AF_UNSPEC;
442 t->tca__pad1 = 0;
443 t->tca__pad2 = 0;
442 444
443 x = (struct rtattr*) skb->tail; 445 x = (struct rtattr*) skb->tail;
444 RTA_PUT(skb, TCA_ACT_TAB, 0, NULL); 446 RTA_PUT(skb, TCA_ACT_TAB, 0, NULL);
@@ -580,6 +582,8 @@ static int tca_action_flush(struct rtattr *rta, struct nlmsghdr *n, u32 pid)
580 nlh = NLMSG_PUT(skb, pid, n->nlmsg_seq, RTM_DELACTION, sizeof(*t)); 582 nlh = NLMSG_PUT(skb, pid, n->nlmsg_seq, RTM_DELACTION, sizeof(*t));
581 t = NLMSG_DATA(nlh); 583 t = NLMSG_DATA(nlh);
582 t->tca_family = AF_UNSPEC; 584 t->tca_family = AF_UNSPEC;
585 t->tca__pad1 = 0;
586 t->tca__pad2 = 0;
583 587
584 x = (struct rtattr *) skb->tail; 588 x = (struct rtattr *) skb->tail;
585 RTA_PUT(skb, TCA_ACT_TAB, 0, NULL); 589 RTA_PUT(skb, TCA_ACT_TAB, 0, NULL);
@@ -687,7 +691,9 @@ static int tcf_add_notify(struct tc_action *a, u32 pid, u32 seq, int event,
687 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*t), flags); 691 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*t), flags);
688 t = NLMSG_DATA(nlh); 692 t = NLMSG_DATA(nlh);
689 t->tca_family = AF_UNSPEC; 693 t->tca_family = AF_UNSPEC;
690 694 t->tca__pad1 = 0;
695 t->tca__pad2 = 0;
696
691 x = (struct rtattr*) skb->tail; 697 x = (struct rtattr*) skb->tail;
692 RTA_PUT(skb, TCA_ACT_TAB, 0, NULL); 698 RTA_PUT(skb, TCA_ACT_TAB, 0, NULL);
693 699
@@ -842,6 +848,8 @@ tc_dump_action(struct sk_buff *skb, struct netlink_callback *cb)
842 cb->nlh->nlmsg_type, sizeof(*t)); 848 cb->nlh->nlmsg_type, sizeof(*t));
843 t = NLMSG_DATA(nlh); 849 t = NLMSG_DATA(nlh);
844 t->tca_family = AF_UNSPEC; 850 t->tca_family = AF_UNSPEC;
851 t->tca__pad1 = 0;
852 t->tca__pad2 = 0;
845 853
846 x = (struct rtattr *) skb->tail; 854 x = (struct rtattr *) skb->tail;
847 RTA_PUT(skb, TCA_ACT_TAB, 0, NULL); 855 RTA_PUT(skb, TCA_ACT_TAB, 0, NULL);
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index 1616bf5c9627..3b5714ef4d1a 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -331,6 +331,8 @@ tcf_fill_node(struct sk_buff *skb, struct tcf_proto *tp, unsigned long fh,
331 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*tcm), flags); 331 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*tcm), flags);
332 tcm = NLMSG_DATA(nlh); 332 tcm = NLMSG_DATA(nlh);
333 tcm->tcm_family = AF_UNSPEC; 333 tcm->tcm_family = AF_UNSPEC;
334 tcm->tcm__pad1 = 0;
335 tcm->tcm__pad1 = 0;
334 tcm->tcm_ifindex = tp->q->dev->ifindex; 336 tcm->tcm_ifindex = tp->q->dev->ifindex;
335 tcm->tcm_parent = tp->classid; 337 tcm->tcm_parent = tp->classid;
336 tcm->tcm_info = TC_H_MAKE(tp->prio, tp->protocol); 338 tcm->tcm_info = TC_H_MAKE(tp->prio, tp->protocol);
diff --git a/net/sched/cls_rsvp.h b/net/sched/cls_rsvp.h
index 232fb9196810..006168d69376 100644
--- a/net/sched/cls_rsvp.h
+++ b/net/sched/cls_rsvp.h
@@ -618,6 +618,7 @@ static int rsvp_dump(struct tcf_proto *tp, unsigned long fh,
618 pinfo.protocol = s->protocol; 618 pinfo.protocol = s->protocol;
619 pinfo.tunnelid = s->tunnelid; 619 pinfo.tunnelid = s->tunnelid;
620 pinfo.tunnelhdr = f->tunnelhdr; 620 pinfo.tunnelhdr = f->tunnelhdr;
621 pinfo.pad = 0;
621 RTA_PUT(skb, TCA_RSVP_PINFO, sizeof(pinfo), &pinfo); 622 RTA_PUT(skb, TCA_RSVP_PINFO, sizeof(pinfo), &pinfo);
622 if (f->res.classid) 623 if (f->res.classid)
623 RTA_PUT(skb, TCA_RSVP_CLASSID, 4, &f->res.classid); 624 RTA_PUT(skb, TCA_RSVP_CLASSID, 4, &f->res.classid);
diff --git a/net/sched/em_meta.c b/net/sched/em_meta.c
index 48bb23c2a35a..00eae5f9a01a 100644
--- a/net/sched/em_meta.c
+++ b/net/sched/em_meta.c
@@ -27,17 +27,17 @@
27 * lvalue rvalue 27 * lvalue rvalue
28 * +-----------+ +-----------+ 28 * +-----------+ +-----------+
29 * | type: INT | | type: INT | 29 * | type: INT | | type: INT |
30 * def | id: INDEV | | id: VALUE | 30 * def | id: DEV | | id: VALUE |
31 * | data: | | data: 3 | 31 * | data: | | data: 3 |
32 * +-----------+ +-----------+ 32 * +-----------+ +-----------+
33 * | | 33 * | |
34 * ---> meta_ops[INT][INDEV](...) | 34 * ---> meta_ops[INT][DEV](...) |
35 * | | 35 * | |
36 * ----------- | 36 * ----------- |
37 * V V 37 * V V
38 * +-----------+ +-----------+ 38 * +-----------+ +-----------+
39 * | type: INT | | type: INT | 39 * | type: INT | | type: INT |
40 * obj | id: INDEV | | id: VALUE | 40 * obj | id: DEV | | id: VALUE |
41 * | data: 2 |<--data got filled out | data: 3 | 41 * | data: 2 |<--data got filled out | data: 3 |
42 * +-----------+ +-----------+ 42 * +-----------+ +-----------+
43 * | | 43 * | |
@@ -170,26 +170,6 @@ META_COLLECTOR(var_dev)
170 *err = var_dev(skb->dev, dst); 170 *err = var_dev(skb->dev, dst);
171} 171}
172 172
173META_COLLECTOR(int_indev)
174{
175 *err = int_dev(skb->input_dev, dst);
176}
177
178META_COLLECTOR(var_indev)
179{
180 *err = var_dev(skb->input_dev, dst);
181}
182
183META_COLLECTOR(int_realdev)
184{
185 *err = int_dev(skb->real_dev, dst);
186}
187
188META_COLLECTOR(var_realdev)
189{
190 *err = var_dev(skb->real_dev, dst);
191}
192
193/************************************************************************** 173/**************************************************************************
194 * skb attributes 174 * skb attributes
195 **************************************************************************/ 175 **************************************************************************/
@@ -205,11 +185,6 @@ META_COLLECTOR(int_protocol)
205 dst->value = skb->protocol; 185 dst->value = skb->protocol;
206} 186}
207 187
208META_COLLECTOR(int_security)
209{
210 dst->value = skb->security;
211}
212
213META_COLLECTOR(int_pkttype) 188META_COLLECTOR(int_pkttype)
214{ 189{
215 dst->value = skb->pkt_type; 190 dst->value = skb->pkt_type;
@@ -234,12 +209,14 @@ META_COLLECTOR(int_maclen)
234 * Netfilter 209 * Netfilter
235 **************************************************************************/ 210 **************************************************************************/
236 211
237#ifdef CONFIG_NETFILTER
238META_COLLECTOR(int_nfmark) 212META_COLLECTOR(int_nfmark)
239{ 213{
214#ifdef CONFIG_NETFILTER
240 dst->value = skb->nfmark; 215 dst->value = skb->nfmark;
241} 216#else
217 dst->value = 0;
242#endif 218#endif
219}
243 220
244/************************************************************************** 221/**************************************************************************
245 * Traffic Control 222 * Traffic Control
@@ -250,31 +227,21 @@ META_COLLECTOR(int_tcindex)
250 dst->value = skb->tc_index; 227 dst->value = skb->tc_index;
251} 228}
252 229
253#ifdef CONFIG_NET_CLS_ACT
254META_COLLECTOR(int_tcverd)
255{
256 dst->value = skb->tc_verd;
257}
258
259META_COLLECTOR(int_tcclassid)
260{
261 dst->value = skb->tc_classid;
262}
263#endif
264
265/************************************************************************** 230/**************************************************************************
266 * Routing 231 * Routing
267 **************************************************************************/ 232 **************************************************************************/
268 233
269#ifdef CONFIG_NET_CLS_ROUTE
270META_COLLECTOR(int_rtclassid) 234META_COLLECTOR(int_rtclassid)
271{ 235{
272 if (unlikely(skb->dst == NULL)) 236 if (unlikely(skb->dst == NULL))
273 *err = -1; 237 *err = -1;
274 else 238 else
239#ifdef CONFIG_NET_CLS_ROUTE
275 dst->value = skb->dst->tclassid; 240 dst->value = skb->dst->tclassid;
276} 241#else
242 dst->value = 0;
277#endif 243#endif
244}
278 245
279META_COLLECTOR(int_rtiif) 246META_COLLECTOR(int_rtiif)
280{ 247{
@@ -510,8 +477,6 @@ struct meta_ops
510static struct meta_ops __meta_ops[TCF_META_TYPE_MAX+1][TCF_META_ID_MAX+1] = { 477static struct meta_ops __meta_ops[TCF_META_TYPE_MAX+1][TCF_META_ID_MAX+1] = {
511 [TCF_META_TYPE_VAR] = { 478 [TCF_META_TYPE_VAR] = {
512 [META_ID(DEV)] = META_FUNC(var_dev), 479 [META_ID(DEV)] = META_FUNC(var_dev),
513 [META_ID(INDEV)] = META_FUNC(var_indev),
514 [META_ID(REALDEV)] = META_FUNC(var_realdev),
515 [META_ID(SK_BOUND_IF)] = META_FUNC(var_sk_bound_if), 480 [META_ID(SK_BOUND_IF)] = META_FUNC(var_sk_bound_if),
516 }, 481 },
517 [TCF_META_TYPE_INT] = { 482 [TCF_META_TYPE_INT] = {
@@ -520,26 +485,15 @@ static struct meta_ops __meta_ops[TCF_META_TYPE_MAX+1][TCF_META_ID_MAX+1] = {
520 [META_ID(LOADAVG_1)] = META_FUNC(int_loadavg_1), 485 [META_ID(LOADAVG_1)] = META_FUNC(int_loadavg_1),
521 [META_ID(LOADAVG_2)] = META_FUNC(int_loadavg_2), 486 [META_ID(LOADAVG_2)] = META_FUNC(int_loadavg_2),
522 [META_ID(DEV)] = META_FUNC(int_dev), 487 [META_ID(DEV)] = META_FUNC(int_dev),
523 [META_ID(INDEV)] = META_FUNC(int_indev),
524 [META_ID(REALDEV)] = META_FUNC(int_realdev),
525 [META_ID(PRIORITY)] = META_FUNC(int_priority), 488 [META_ID(PRIORITY)] = META_FUNC(int_priority),
526 [META_ID(PROTOCOL)] = META_FUNC(int_protocol), 489 [META_ID(PROTOCOL)] = META_FUNC(int_protocol),
527 [META_ID(SECURITY)] = META_FUNC(int_security),
528 [META_ID(PKTTYPE)] = META_FUNC(int_pkttype), 490 [META_ID(PKTTYPE)] = META_FUNC(int_pkttype),
529 [META_ID(PKTLEN)] = META_FUNC(int_pktlen), 491 [META_ID(PKTLEN)] = META_FUNC(int_pktlen),
530 [META_ID(DATALEN)] = META_FUNC(int_datalen), 492 [META_ID(DATALEN)] = META_FUNC(int_datalen),
531 [META_ID(MACLEN)] = META_FUNC(int_maclen), 493 [META_ID(MACLEN)] = META_FUNC(int_maclen),
532#ifdef CONFIG_NETFILTER
533 [META_ID(NFMARK)] = META_FUNC(int_nfmark), 494 [META_ID(NFMARK)] = META_FUNC(int_nfmark),
534#endif
535 [META_ID(TCINDEX)] = META_FUNC(int_tcindex), 495 [META_ID(TCINDEX)] = META_FUNC(int_tcindex),
536#ifdef CONFIG_NET_CLS_ACT
537 [META_ID(TCVERDICT)] = META_FUNC(int_tcverd),
538 [META_ID(TCCLASSID)] = META_FUNC(int_tcclassid),
539#endif
540#ifdef CONFIG_NET_CLS_ROUTE
541 [META_ID(RTCLASSID)] = META_FUNC(int_rtclassid), 496 [META_ID(RTCLASSID)] = META_FUNC(int_rtclassid),
542#endif
543 [META_ID(RTIIF)] = META_FUNC(int_rtiif), 497 [META_ID(RTIIF)] = META_FUNC(int_rtiif),
544 [META_ID(SK_FAMILY)] = META_FUNC(int_sk_family), 498 [META_ID(SK_FAMILY)] = META_FUNC(int_sk_family),
545 [META_ID(SK_STATE)] = META_FUNC(int_sk_state), 499 [META_ID(SK_STATE)] = META_FUNC(int_sk_state),
diff --git a/net/sched/em_text.c b/net/sched/em_text.c
new file mode 100644
index 000000000000..77beabc91fa3
--- /dev/null
+++ b/net/sched/em_text.c
@@ -0,0 +1,154 @@
1/*
2 * net/sched/em_text.c Textsearch ematch
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *
9 * Authors: Thomas Graf <tgraf@suug.ch>
10 */
11
12#include <linux/config.h>
13#include <linux/module.h>
14#include <linux/types.h>
15#include <linux/kernel.h>
16#include <linux/sched.h>
17#include <linux/string.h>
18#include <linux/skbuff.h>
19#include <linux/textsearch.h>
20#include <linux/tc_ematch/tc_em_text.h>
21#include <net/pkt_cls.h>
22
23struct text_match
24{
25 u16 from_offset;
26 u16 to_offset;
27 u8 from_layer;
28 u8 to_layer;
29 struct ts_config *config;
30};
31
32#define EM_TEXT_PRIV(m) ((struct text_match *) (m)->data)
33
34static int em_text_match(struct sk_buff *skb, struct tcf_ematch *m,
35 struct tcf_pkt_info *info)
36{
37 struct text_match *tm = EM_TEXT_PRIV(m);
38 int from, to;
39 struct ts_state state;
40
41 from = tcf_get_base_ptr(skb, tm->from_layer) - skb->data;
42 from += tm->from_offset;
43
44 to = tcf_get_base_ptr(skb, tm->to_layer) - skb->data;
45 to += tm->to_offset;
46
47 return skb_find_text(skb, from, to, tm->config, &state) != UINT_MAX;
48}
49
50static int em_text_change(struct tcf_proto *tp, void *data, int len,
51 struct tcf_ematch *m)
52{
53 struct text_match *tm;
54 struct tcf_em_text *conf = data;
55 struct ts_config *ts_conf;
56 int flags = 0;
57
58 if (len < sizeof(*conf) || len < (sizeof(*conf) + conf->pattern_len))
59 return -EINVAL;
60
61 if (conf->from_layer > conf->to_layer)
62 return -EINVAL;
63
64 if (conf->from_layer == conf->to_layer &&
65 conf->from_offset > conf->to_offset)
66 return -EINVAL;
67
68retry:
69 ts_conf = textsearch_prepare(conf->algo, (u8 *) conf + sizeof(*conf),
70 conf->pattern_len, GFP_KERNEL, flags);
71
72 if (flags & TS_AUTOLOAD)
73 rtnl_lock();
74
75 if (IS_ERR(ts_conf)) {
76 if (PTR_ERR(ts_conf) == -ENOENT && !(flags & TS_AUTOLOAD)) {
77 rtnl_unlock();
78 flags |= TS_AUTOLOAD;
79 goto retry;
80 } else
81 return PTR_ERR(ts_conf);
82 } else if (flags & TS_AUTOLOAD) {
83 textsearch_destroy(ts_conf);
84 return -EAGAIN;
85 }
86
87 tm = kmalloc(sizeof(*tm), GFP_KERNEL);
88 if (tm == NULL) {
89 textsearch_destroy(ts_conf);
90 return -ENOBUFS;
91 }
92
93 tm->from_offset = conf->from_offset;
94 tm->to_offset = conf->to_offset;
95 tm->from_layer = conf->from_layer;
96 tm->to_layer = conf->to_layer;
97 tm->config = ts_conf;
98
99 m->datalen = sizeof(*tm);
100 m->data = (unsigned long) tm;
101
102 return 0;
103}
104
105static void em_text_destroy(struct tcf_proto *tp, struct tcf_ematch *m)
106{
107 textsearch_destroy(EM_TEXT_PRIV(m)->config);
108}
109
110static int em_text_dump(struct sk_buff *skb, struct tcf_ematch *m)
111{
112 struct text_match *tm = EM_TEXT_PRIV(m);
113 struct tcf_em_text conf;
114
115 strncpy(conf.algo, tm->config->ops->name, sizeof(conf.algo) - 1);
116 conf.from_offset = tm->from_offset;
117 conf.to_offset = tm->to_offset;
118 conf.from_layer = tm->from_layer;
119 conf.to_layer = tm->to_layer;
120 conf.pattern_len = textsearch_get_pattern_len(tm->config);
121 conf.pad = 0;
122
123 RTA_PUT_NOHDR(skb, sizeof(conf), &conf);
124 RTA_APPEND(skb, conf.pattern_len, textsearch_get_pattern(tm->config));
125 return 0;
126
127rtattr_failure:
128 return -1;
129}
130
131static struct tcf_ematch_ops em_text_ops = {
132 .kind = TCF_EM_TEXT,
133 .change = em_text_change,
134 .match = em_text_match,
135 .destroy = em_text_destroy,
136 .dump = em_text_dump,
137 .owner = THIS_MODULE,
138 .link = LIST_HEAD_INIT(em_text_ops.link)
139};
140
141static int __init init_em_text(void)
142{
143 return tcf_em_register(&em_text_ops);
144}
145
146static void __exit exit_em_text(void)
147{
148 tcf_em_unregister(&em_text_ops);
149}
150
151MODULE_LICENSE("GPL");
152
153module_init(init_em_text);
154module_exit(exit_em_text);
diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c
index 97c1c75d5c78..b9a069af4a02 100644
--- a/net/sched/sch_api.c
+++ b/net/sched/sch_api.c
@@ -399,10 +399,8 @@ qdisc_create(struct net_device *dev, u32 handle, struct rtattr **tca, int *errp)
399{ 399{
400 int err; 400 int err;
401 struct rtattr *kind = tca[TCA_KIND-1]; 401 struct rtattr *kind = tca[TCA_KIND-1];
402 void *p = NULL;
403 struct Qdisc *sch; 402 struct Qdisc *sch;
404 struct Qdisc_ops *ops; 403 struct Qdisc_ops *ops;
405 int size;
406 404
407 ops = qdisc_lookup_ops(kind); 405 ops = qdisc_lookup_ops(kind);
408#ifdef CONFIG_KMOD 406#ifdef CONFIG_KMOD
@@ -437,64 +435,55 @@ qdisc_create(struct net_device *dev, u32 handle, struct rtattr **tca, int *errp)
437 if (ops == NULL) 435 if (ops == NULL)
438 goto err_out; 436 goto err_out;
439 437
440 /* ensure that the Qdisc and the private data are 32-byte aligned */ 438 sch = qdisc_alloc(dev, ops);
441 size = ((sizeof(*sch) + QDISC_ALIGN_CONST) & ~QDISC_ALIGN_CONST); 439 if (IS_ERR(sch)) {
442 size += ops->priv_size + QDISC_ALIGN_CONST; 440 err = PTR_ERR(sch);
443
444 p = kmalloc(size, GFP_KERNEL);
445 err = -ENOBUFS;
446 if (!p)
447 goto err_out2; 441 goto err_out2;
448 memset(p, 0, size); 442 }
449 sch = (struct Qdisc *)(((unsigned long)p + QDISC_ALIGN_CONST)
450 & ~QDISC_ALIGN_CONST);
451 sch->padded = (char *)sch - (char *)p;
452
453 INIT_LIST_HEAD(&sch->list);
454 skb_queue_head_init(&sch->q);
455 443
456 if (handle == TC_H_INGRESS) 444 if (handle == TC_H_INGRESS) {
457 sch->flags |= TCQ_F_INGRESS; 445 sch->flags |= TCQ_F_INGRESS;
458 446 handle = TC_H_MAKE(TC_H_INGRESS, 0);
459 sch->ops = ops; 447 } else if (handle == 0) {
460 sch->enqueue = ops->enqueue;
461 sch->dequeue = ops->dequeue;
462 sch->dev = dev;
463 dev_hold(dev);
464 atomic_set(&sch->refcnt, 1);
465 sch->stats_lock = &dev->queue_lock;
466 if (handle == 0) {
467 handle = qdisc_alloc_handle(dev); 448 handle = qdisc_alloc_handle(dev);
468 err = -ENOMEM; 449 err = -ENOMEM;
469 if (handle == 0) 450 if (handle == 0)
470 goto err_out3; 451 goto err_out3;
471 } 452 }
472 453
473 if (handle == TC_H_INGRESS) 454 sch->handle = handle;
474 sch->handle =TC_H_MAKE(TC_H_INGRESS, 0);
475 else
476 sch->handle = handle;
477 455
478 if (!ops->init || (err = ops->init(sch, tca[TCA_OPTIONS-1])) == 0) { 456 if (!ops->init || (err = ops->init(sch, tca[TCA_OPTIONS-1])) == 0) {
457#ifdef CONFIG_NET_ESTIMATOR
458 if (tca[TCA_RATE-1]) {
459 err = gen_new_estimator(&sch->bstats, &sch->rate_est,
460 sch->stats_lock,
461 tca[TCA_RATE-1]);
462 if (err) {
463 /*
464 * Any broken qdiscs that would require
465 * a ops->reset() here? The qdisc was never
466 * in action so it shouldn't be necessary.
467 */
468 if (ops->destroy)
469 ops->destroy(sch);
470 goto err_out3;
471 }
472 }
473#endif
479 qdisc_lock_tree(dev); 474 qdisc_lock_tree(dev);
480 list_add_tail(&sch->list, &dev->qdisc_list); 475 list_add_tail(&sch->list, &dev->qdisc_list);
481 qdisc_unlock_tree(dev); 476 qdisc_unlock_tree(dev);
482 477
483#ifdef CONFIG_NET_ESTIMATOR
484 if (tca[TCA_RATE-1])
485 gen_new_estimator(&sch->bstats, &sch->rate_est,
486 sch->stats_lock, tca[TCA_RATE-1]);
487#endif
488 return sch; 478 return sch;
489 } 479 }
490err_out3: 480err_out3:
491 dev_put(dev); 481 dev_put(dev);
482 kfree((char *) sch - sch->padded);
492err_out2: 483err_out2:
493 module_put(ops->owner); 484 module_put(ops->owner);
494err_out: 485err_out:
495 *errp = err; 486 *errp = err;
496 if (p)
497 kfree(p);
498 return NULL; 487 return NULL;
499} 488}
500 489
@@ -770,6 +759,8 @@ static int tc_fill_qdisc(struct sk_buff *skb, struct Qdisc *q, u32 clid,
770 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*tcm), flags); 759 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*tcm), flags);
771 tcm = NLMSG_DATA(nlh); 760 tcm = NLMSG_DATA(nlh);
772 tcm->tcm_family = AF_UNSPEC; 761 tcm->tcm_family = AF_UNSPEC;
762 tcm->tcm__pad1 = 0;
763 tcm->tcm__pad2 = 0;
773 tcm->tcm_ifindex = q->dev->ifindex; 764 tcm->tcm_ifindex = q->dev->ifindex;
774 tcm->tcm_parent = clid; 765 tcm->tcm_parent = clid;
775 tcm->tcm_handle = q->handle; 766 tcm->tcm_handle = q->handle;
diff --git a/net/sched/sch_blackhole.c b/net/sched/sch_blackhole.c
new file mode 100644
index 000000000000..81f0b8346d17
--- /dev/null
+++ b/net/sched/sch_blackhole.c
@@ -0,0 +1,54 @@
1/*
2 * net/sched/sch_blackhole.c Black hole queue
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *
9 * Authors: Thomas Graf <tgraf@suug.ch>
10 *
11 * Note: Quantum tunneling is not supported.
12 */
13
14#include <linux/config.h>
15#include <linux/module.h>
16#include <linux/types.h>
17#include <linux/kernel.h>
18#include <linux/netdevice.h>
19#include <linux/skbuff.h>
20#include <net/pkt_sched.h>
21
22static int blackhole_enqueue(struct sk_buff *skb, struct Qdisc *sch)
23{
24 qdisc_drop(skb, sch);
25 return NET_XMIT_SUCCESS;
26}
27
28static struct sk_buff *blackhole_dequeue(struct Qdisc *sch)
29{
30 return NULL;
31}
32
33static struct Qdisc_ops blackhole_qdisc_ops = {
34 .id = "blackhole",
35 .priv_size = 0,
36 .enqueue = blackhole_enqueue,
37 .dequeue = blackhole_dequeue,
38 .owner = THIS_MODULE,
39};
40
41static int __init blackhole_module_init(void)
42{
43 return register_qdisc(&blackhole_qdisc_ops);
44}
45
46static void __exit blackhole_module_exit(void)
47{
48 unregister_qdisc(&blackhole_qdisc_ops);
49}
50
51module_init(blackhole_module_init)
52module_exit(blackhole_module_exit)
53
54MODULE_LICENSE("GPL");
diff --git a/net/sched/sch_cbq.c b/net/sched/sch_cbq.c
index d43e3b8cbf6a..09453f997d8c 100644
--- a/net/sched/sch_cbq.c
+++ b/net/sched/sch_cbq.c
@@ -1528,6 +1528,7 @@ static __inline__ int cbq_dump_ovl(struct sk_buff *skb, struct cbq_class *cl)
1528 1528
1529 opt.strategy = cl->ovl_strategy; 1529 opt.strategy = cl->ovl_strategy;
1530 opt.priority2 = cl->priority2+1; 1530 opt.priority2 = cl->priority2+1;
1531 opt.pad = 0;
1531 opt.penalty = (cl->penalty*1000)/HZ; 1532 opt.penalty = (cl->penalty*1000)/HZ;
1532 RTA_PUT(skb, TCA_CBQ_OVL_STRATEGY, sizeof(opt), &opt); 1533 RTA_PUT(skb, TCA_CBQ_OVL_STRATEGY, sizeof(opt), &opt);
1533 return skb->len; 1534 return skb->len;
@@ -1563,6 +1564,8 @@ static __inline__ int cbq_dump_police(struct sk_buff *skb, struct cbq_class *cl)
1563 1564
1564 if (cl->police) { 1565 if (cl->police) {
1565 opt.police = cl->police; 1566 opt.police = cl->police;
1567 opt.__res1 = 0;
1568 opt.__res2 = 0;
1566 RTA_PUT(skb, TCA_CBQ_POLICE, sizeof(opt), &opt); 1569 RTA_PUT(skb, TCA_CBQ_POLICE, sizeof(opt), &opt);
1567 } 1570 }
1568 return skb->len; 1571 return skb->len;
diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
index 7683b34dc6a9..0d066c965342 100644
--- a/net/sched/sch_generic.c
+++ b/net/sched/sch_generic.c
@@ -331,11 +331,10 @@ static struct sk_buff *pfifo_fast_dequeue(struct Qdisc* qdisc)
331 int prio; 331 int prio;
332 struct sk_buff_head *list = qdisc_priv(qdisc); 332 struct sk_buff_head *list = qdisc_priv(qdisc);
333 333
334 for (prio = 0; prio < PFIFO_FAST_BANDS; prio++, list++) { 334 for (prio = 0; prio < PFIFO_FAST_BANDS; prio++) {
335 struct sk_buff *skb = __qdisc_dequeue_head(qdisc, list); 335 if (!skb_queue_empty(list + prio)) {
336 if (skb) {
337 qdisc->q.qlen--; 336 qdisc->q.qlen--;
338 return skb; 337 return __qdisc_dequeue_head(qdisc, list + prio);
339 } 338 }
340 } 339 }
341 340
@@ -395,24 +394,23 @@ static struct Qdisc_ops pfifo_fast_ops = {
395 .owner = THIS_MODULE, 394 .owner = THIS_MODULE,
396}; 395};
397 396
398struct Qdisc * qdisc_create_dflt(struct net_device *dev, struct Qdisc_ops *ops) 397struct Qdisc *qdisc_alloc(struct net_device *dev, struct Qdisc_ops *ops)
399{ 398{
400 void *p; 399 void *p;
401 struct Qdisc *sch; 400 struct Qdisc *sch;
402 int size; 401 unsigned int size;
402 int err = -ENOBUFS;
403 403
404 /* ensure that the Qdisc and the private data are 32-byte aligned */ 404 /* ensure that the Qdisc and the private data are 32-byte aligned */
405 size = ((sizeof(*sch) + QDISC_ALIGN_CONST) & ~QDISC_ALIGN_CONST); 405 size = QDISC_ALIGN(sizeof(*sch));
406 size += ops->priv_size + QDISC_ALIGN_CONST; 406 size += ops->priv_size + (QDISC_ALIGNTO - 1);
407 407
408 p = kmalloc(size, GFP_KERNEL); 408 p = kmalloc(size, GFP_KERNEL);
409 if (!p) 409 if (!p)
410 return NULL; 410 goto errout;
411 memset(p, 0, size); 411 memset(p, 0, size);
412 412 sch = (struct Qdisc *) QDISC_ALIGN((unsigned long) p);
413 sch = (struct Qdisc *)(((unsigned long)p + QDISC_ALIGN_CONST) 413 sch->padded = (char *) sch - (char *) p;
414 & ~QDISC_ALIGN_CONST);
415 sch->padded = (char *)sch - (char *)p;
416 414
417 INIT_LIST_HEAD(&sch->list); 415 INIT_LIST_HEAD(&sch->list);
418 skb_queue_head_init(&sch->q); 416 skb_queue_head_init(&sch->q);
@@ -423,11 +421,25 @@ struct Qdisc * qdisc_create_dflt(struct net_device *dev, struct Qdisc_ops *ops)
423 dev_hold(dev); 421 dev_hold(dev);
424 sch->stats_lock = &dev->queue_lock; 422 sch->stats_lock = &dev->queue_lock;
425 atomic_set(&sch->refcnt, 1); 423 atomic_set(&sch->refcnt, 1);
424
425 return sch;
426errout:
427 return ERR_PTR(-err);
428}
429
430struct Qdisc * qdisc_create_dflt(struct net_device *dev, struct Qdisc_ops *ops)
431{
432 struct Qdisc *sch;
433
434 sch = qdisc_alloc(dev, ops);
435 if (IS_ERR(sch))
436 goto errout;
437
426 if (!ops->init || ops->init(sch, NULL) == 0) 438 if (!ops->init || ops->init(sch, NULL) == 0)
427 return sch; 439 return sch;
428 440
429 dev_put(dev); 441 qdisc_destroy(sch);
430 kfree(p); 442errout:
431 return NULL; 443 return NULL;
432} 444}
433 445
@@ -591,6 +603,7 @@ EXPORT_SYMBOL(__netdev_watchdog_up);
591EXPORT_SYMBOL(noop_qdisc); 603EXPORT_SYMBOL(noop_qdisc);
592EXPORT_SYMBOL(noop_qdisc_ops); 604EXPORT_SYMBOL(noop_qdisc_ops);
593EXPORT_SYMBOL(qdisc_create_dflt); 605EXPORT_SYMBOL(qdisc_create_dflt);
606EXPORT_SYMBOL(qdisc_alloc);
594EXPORT_SYMBOL(qdisc_destroy); 607EXPORT_SYMBOL(qdisc_destroy);
595EXPORT_SYMBOL(qdisc_reset); 608EXPORT_SYMBOL(qdisc_reset);
596EXPORT_SYMBOL(qdisc_restart); 609EXPORT_SYMBOL(qdisc_restart);
diff --git a/net/sched/sch_red.c b/net/sched/sch_red.c
index 664d0e47374f..7845d045eec4 100644
--- a/net/sched/sch_red.c
+++ b/net/sched/sch_red.c
@@ -385,7 +385,7 @@ static int red_change(struct Qdisc *sch, struct rtattr *opt)
385 memcpy(q->Stab, RTA_DATA(tb[TCA_RED_STAB-1]), 256); 385 memcpy(q->Stab, RTA_DATA(tb[TCA_RED_STAB-1]), 256);
386 386
387 q->qcount = -1; 387 q->qcount = -1;
388 if (skb_queue_len(&sch->q) == 0) 388 if (skb_queue_empty(&sch->q))
389 PSCHED_SET_PASTPERFECT(q->qidlestart); 389 PSCHED_SET_PASTPERFECT(q->qidlestart);
390 sch_tree_unlock(sch); 390 sch_tree_unlock(sch);
391 return 0; 391 return 0;