15 #include <linux/module.h>
16 #include <linux/types.h>
17 #include <linux/kernel.h>
18 #include <linux/string.h>
19 #include <linux/errno.h>
117 #define L2T(q, L) qdisc_l2t((q)->R_tab, L)
118 #define L2T_P(q, L) qdisc_l2t((q)->P_tab, L)
125 if (qdisc_pkt_len(skb) > q->
max_size)
126 return qdisc_reshape_fail(skb, sch);
128 ret = qdisc_enqueue(skb, q->
qdisc);
139 static unsigned int tbf_drop(
struct Qdisc *
sch)
142 unsigned int len = 0;
144 if (q->
qdisc->ops->drop && (len = q->
qdisc->ops->drop(q->
qdisc)) != 0) {
162 unsigned int len = qdisc_pkt_len(skb);
164 now = psched_get_time();
165 toks = psched_tdiff_bounded(now, q->
t_c, q->
buffer);
169 if (ptoks > (
long)q->
mtu)
171 ptoks -=
L2T_P(q, len);
174 if (toks > (
long)q->
buffer)
178 if ((toks|ptoks) >= 0) {
179 skb = qdisc_dequeue_peeked(q->
qdisc);
187 qdisc_unthrottled(sch);
188 qdisc_bstats_update(sch, skb);
193 now +
max_t(
long, -toks, -ptoks));
211 static void tbf_reset(
struct Qdisc *sch)
217 q->
t_c = psched_get_time();
240 err = nla_parse_nested(tb,
TCA_TBF_PTAB, opt, tbf_policy);
260 for (n = 0; n < 256; n++)
263 max_size = (n << qopt->
rate.cell_log) - 1;
267 for (n = 0; n < 256; n++)
270 size = (n << qopt->
peakrate.cell_log) - 1;
281 }
else if (qopt->
limit > 0) {
284 err = PTR_ERR(child);
305 sch_tree_unlock(sch);
315 static int tbf_init(
struct Qdisc *sch,
struct nlattr *opt)
322 q->
t_c = psched_get_time();
326 return tbf_change(sch, opt);
329 static void tbf_destroy(
struct Qdisc *sch)
343 static int tbf_dump(
struct Qdisc *sch,
struct sk_buff *skb)
352 goto nla_put_failure;
354 opt.limit = q->
limit;
355 opt.rate = q->
R_tab->rate;
357 opt.peakrate = q->
P_tab->rate;
359 memset(&opt.peakrate, 0,
sizeof(opt.peakrate));
363 goto nla_put_failure;
365 nla_nest_end(skb, nest);
369 nla_nest_cancel(skb, nest);
373 static int tbf_dump_class(
struct Qdisc *sch,
unsigned long cl,
384 static int tbf_graft(
struct Qdisc *sch,
unsigned long arg,
struct Qdisc *
new,
397 sch_tree_unlock(sch);
402 static struct Qdisc *tbf_leaf(
struct Qdisc *sch,
unsigned long arg)
408 static unsigned long tbf_get(
struct Qdisc *sch,
u32 classid)
413 static void tbf_put(
struct Qdisc *sch,
unsigned long arg)
421 if (walker->
fn(sch, 1, walker) < 0) {
435 .dump = tbf_dump_class,
440 .cl_ops = &tbf_class_ops,
443 .enqueue = tbf_enqueue,
444 .dequeue = tbf_dequeue,
445 .peek = qdisc_peek_dequeued,
449 .destroy = tbf_destroy,
450 .change = tbf_change,
455 static int __init tbf_module_init(
void)
460 static void __exit tbf_module_exit(
void)