linux/net/sched/sch_fifo.c
<<
>>
Prefs
   1   2   3   4   5   6   7   8   9  10  11
  12#include <linux/module.h>
  13#include <linux/slab.h>
  14#include <linux/types.h>
  15#include <linux/kernel.h>
  16#include <linux/errno.h>
  17#include <linux/skbuff.h>
  18#include <net/pkt_sched.h>
  19
  20  21
  22static int bfifo_enqueue(struct sk_buff *skb, struct Qdisc *sch)
  23{
  24        if (likely(sch->qstats.backlog + qdisc_pkt_len(skb) <= sch->limit))
  25                return qdisc_enqueue_tail(skb, sch);
  26
  27        return qdisc_reshape_fail(skb, sch);
  28}
  29
  30static int pfifo_enqueue(struct sk_buff *skb, struct Qdisc *sch)
  31{
  32        if (likely(skb_queue_len(&sch->q) < sch->limit))
  33                return qdisc_enqueue_tail(skb, sch);
  34
  35        return qdisc_reshape_fail(skb, sch);
  36}
  37
  38static int pfifo_tail_enqueue(struct sk_buff *skb, struct Qdisc *sch)
  39{
  40        if (likely(skb_queue_len(&sch->q) < sch->limit))
  41                return qdisc_enqueue_tail(skb, sch);
  42
  43          44        __qdisc_queue_drop_head(sch, &sch->q);
  45        sch->qstats.drops++;
  46        qdisc_enqueue_tail(skb, sch);
  47
  48        return NET_XMIT_CN;
  49}
  50
  51static int fifo_init(struct Qdisc *sch, struct nlattr *opt)
  52{
  53        bool bypass;
  54        bool is_bfifo = sch->ops == &bfifo_qdisc_ops;
  55
  56        if (opt == NULL) {
  57                u32 limit = qdisc_dev(sch)->tx_queue_len ? : 1;
  58
  59                if (is_bfifo)
  60                        limit *= psched_mtu(qdisc_dev(sch));
  61
  62                sch->limit = limit;
  63        } else {
  64                struct tc_fifo_qopt *ctl = nla_data(opt);
  65
  66                if (nla_len(opt) < sizeof(*ctl))
  67                        return -EINVAL;
  68
  69                sch->limit = ctl->limit;
  70        }
  71
  72        if (is_bfifo)
  73                bypass = sch->limit >= psched_mtu(qdisc_dev(sch));
  74        else
  75                bypass = sch->limit >= 1;
  76
  77        if (bypass)
  78                sch->flags |= TCQ_F_CAN_BYPASS;
  79        else
  80                sch->flags &= ~TCQ_F_CAN_BYPASS;
  81        return 0;
  82}
  83
  84static int fifo_dump(struct Qdisc *sch, struct sk_buff *skb)
  85{
  86        struct tc_fifo_qopt opt = { .limit = sch->limit };
  87
  88        if (nla_put(skb, TCA_OPTIONS, sizeof(opt), &opt))
  89                goto nla_put_failure;
  90        return skb->len;
  91
  92nla_put_failure:
  93        return -1;
  94}
  95
  96struct Qdisc_ops pfifo_qdisc_ops __read_mostly = {
  97        .id             =       "pfifo",
  98        .priv_size      =       0,
  99        .enqueue        =       pfifo_enqueue,
 100        .dequeue        =       qdisc_dequeue_head,
 101        .peek           =       qdisc_peek_head,
 102        .drop           =       qdisc_queue_drop,
 103        .init           =       fifo_init,
 104        .reset          >fifo155"
	  2.6.16.29