pkt_sched: sch_generic: Add generic qdisc->ops->peek() implementation.
authorJarek Poplawski <jarkao2@gmail.com>
Fri, 31 Oct 2008 07:45:27 +0000 (00:45 -0700)
committerDavid S. Miller <davem@davemloft.net>
Fri, 31 Oct 2008 07:45:27 +0000 (00:45 -0700)
With feedback from Patrick McHardy.

Signed-off-by: Jarek Poplawski <jarkao2@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/sched/sch_api.c
net/sched/sch_generic.c

index b16ad2972c6b527dc2013a5dfb4108ad35ef8197..e5646614e88d83733acf9ccd105885358fe0a12e 100644 (file)
@@ -102,6 +102,10 @@ static int tclass_notify(struct sk_buff *oskb, struct nlmsghdr *n,
    requeues once dequeued packet. It is used for non-standard or
    just buggy devices, which can defer output even if netif_queue_stopped()=0.
 
+   ---peek
+
+   like dequeue but without removing a packet from the queue
+
    ---reset
 
    returns qdisc to initial state: purge all buffers, clear all
@@ -149,6 +153,14 @@ int register_qdisc(struct Qdisc_ops *qops)
                qops->enqueue = noop_qdisc_ops.enqueue;
        if (qops->requeue == NULL)
                qops->requeue = noop_qdisc_ops.requeue;
+       if (qops->peek == NULL) {
+               if (qops->dequeue == NULL) {
+                       qops->peek = noop_qdisc_ops.peek;
+               } else {
+                       rc = -EINVAL;
+                       goto out;
+               }
+       }
        if (qops->dequeue == NULL)
                qops->dequeue = noop_qdisc_ops.dequeue;
 
index 93cd30ce65011d2b84541277c15664ed6287fc3d..318c9f656e8e0a41aed5e6c7cd0841fce88e7a5b 100644 (file)
@@ -320,6 +320,7 @@ struct Qdisc_ops noop_qdisc_ops __read_mostly = {
        .priv_size      =       0,
        .enqueue        =       noop_enqueue,
        .dequeue        =       noop_dequeue,
+       .peek           =       noop_dequeue,
        .requeue        =       noop_requeue,
        .owner          =       THIS_MODULE,
 };
@@ -346,6 +347,7 @@ static struct Qdisc_ops noqueue_qdisc_ops __read_mostly = {
        .priv_size      =       0,
        .enqueue        =       noop_enqueue,
        .dequeue        =       noop_dequeue,
+       .peek           =       noop_dequeue,
        .requeue        =       noop_requeue,
        .owner          =       THIS_MODULE,
 };
@@ -411,6 +413,19 @@ static struct sk_buff *pfifo_fast_dequeue(struct Qdisc* qdisc)
        return NULL;
 }
 
+static struct sk_buff *pfifo_fast_peek(struct Qdisc* qdisc)
+{
+       int prio;
+       struct sk_buff_head *list = qdisc_priv(qdisc);
+
+       for (prio = 0; prio < PFIFO_FAST_BANDS; prio++) {
+               if (!skb_queue_empty(list + prio))
+                       return skb_peek(list + prio);
+       }
+
+       return NULL;
+}
+
 static int pfifo_fast_requeue(struct sk_buff *skb, struct Qdisc* qdisc)
 {
        qdisc->q.qlen++;
@@ -457,6 +472,7 @@ static struct Qdisc_ops pfifo_fast_ops __read_mostly = {
        .priv_size      =       PFIFO_FAST_BANDS * sizeof(struct sk_buff_head),
        .enqueue        =       pfifo_fast_enqueue,
        .dequeue        =       pfifo_fast_dequeue,
+       .peek           =       pfifo_fast_peek,
        .requeue        =       pfifo_fast_requeue,
        .init           =       pfifo_fast_init,
        .reset          =       pfifo_fast_reset,