Subject: [PATCH] - sch_htb: Drop packet when direct queue overflows

From: Asim Shankar <[email-masked]>
Date: Thu, 21 Apr 2005 15:41:24 -0500

> > If a packet is classified as HTB_DIRECT but the direct_queue is
> > already full, then the packet doesn't get enqueued but sch->q.qlen++
> > will happen a few lines later. Overflowing of the direct_queue
> > probably rarely happens in practice, but I was playing around and
> > noticed it happen in some corner cases of my testing.
> 
> Yes, that's a bug.
> 
> > Should the packet be dropped instead? Like:
> >
> > if (cl == HTB_DIRECT) {
> >         /* enqueue to helper queue */
> >         if (q->direct_queue.qlen < q->direct_qlen) {
> >                 __skb_queue_tail(&q->direct_queue, skb);
> >                 q->direct_pkts++;
> >         } else {
> >                sch->qstats.drops++;
> >                 kfree_skb(skb);
> >                 return NET_XMIT_DROP;
> >        }
> > }
> 
> Can you send a patch?
> 
Patched pasted and attached:

--- linux-2.6.11.7/net/sched/sch_htb.c	2005-04-07 13:57:45.000000000 -0500
+++ linux-2.6.11.7-new/net/sched/sch_htb.c	2005-04-21 14:17:36.272065816 -0500
@@ -717,6 +717,10 @@
 	if (q->direct_queue.qlen < q->direct_qlen) {
 	    __skb_queue_tail(&q->direct_queue, skb);
 	    q->direct_pkts++;
+	} else {
+	    kfree_skb (skb);
+	    sch->qstats.drops++;
+	    return NET_XMIT_DROP;
 	}
 #ifdef CONFIG_NET_CLS_ACT
     } else if (!cl) {
--- linux-2.6.11.7/net/sched/sch_htb.c	2005-04-07 13:57:45.000000000 -0500
+++ linux-2.6.11.7-new/net/sched/sch_htb.c	2005-04-21 14:17:36.272065816 -0500
@@ -717,6 +717,10 @@
 	if (q->direct_queue.qlen < q->direct_qlen) {
 	    __skb_queue_tail(&q->direct_queue, skb);
 	    q->direct_pkts++;
+	} else {
+	    kfree_skb (skb);
+	    sch->qstats.drops++;
+	    return NET_XMIT_DROP;
 	}
 #ifdef CONFIG_NET_CLS_ACT
     } else if (!cl) {