From 662111ca924b114b1c90758bfaa4851ea5773272 Mon Sep 17 00:00:00 2001 From: rd235 Date: Tue, 23 Nov 2010 19:47:49 +0000 Subject: [PATCH] bugfixes: 1- priority queue could swap packets in fifo channel on heavy traffic 2- BPDU packets had wrong length (tnx to Michele Cucchi) git-svn-id: https://vde.svn.sourceforge.net/svnroot/vde/trunk@449 d37a7db1-d92d-0410-89df-f68f52f87b57 --- vde-2/src/vde_switch/fstp.c | 4 ++-- vde-2/src/wirefilter.c | 33 +++++++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/vde-2/src/vde_switch/fstp.c b/vde-2/src/vde_switch/fstp.c index a108fda..ac5e313 100644 --- a/vde-2/src/vde_switch/fstp.c +++ b/vde-2/src/vde_switch/fstp.c @@ -153,7 +153,7 @@ struct fsttagbpdu { static struct fstbpdu outpacket = { .header.dest=BPDUADDR, - .header.proto={0x00,0x39}, /* 802.3 packet length */ + .header.proto={0x00,0x27}, /* 802.3 packet length */ .llc={0x42,0x42,0x3}, .stp_protocol={0,0}, .stp_version=2, @@ -163,7 +163,7 @@ static struct fstbpdu outpacket = { static struct fsttagbpdu outtagpacket = { .header.dest=BPDUADDR, .header.proto={0x81,0x00}, - .tag_proto={0x00,0x39}, + .tag_proto={0x00,0x27}, .llc={0x42,0x42,0x3}, .stp_protocol={0,0}, .stp_version=2, diff --git a/vde-2/src/wirefilter.c b/vde-2/src/wirefilter.c index 1ff17f7..72c387b 100644 --- a/vde-2/src/wirefilter.c +++ b/vde-2/src/wirefilter.c @@ -375,15 +375,17 @@ static int read_wirevalue(char *s, int tag) struct packpq { unsigned long long when; + unsigned int counter; int dir; unsigned char *buf; int size; }; struct packpq **pqh; -struct packpq sentinel={0,0,NULL,0}; +struct packpq sentinel={0,0,0,NULL,0}; int npq,maxpq; unsigned long long maxwhen; +unsigned int counter; #define PQCHUNK 100 @@ -459,12 +461,19 @@ static void packet_dequeue() while (k<= npq>>1) { int j= k<<1; - if (jwhen > pqh[j+1]->when) j++; - if (old->when <= pqh[j]->when) { + if (jwhen > pqh[j+1]->when || + (pqh[j]->when == pqh[j+1]->when && + pqh[j]->counter > pqh[j+1]->counter) + ) + ) j++; + if (old->when < pqh[j]->when || + (old->when == pqh[j]->when && + old->counter < pqh[j]->counter) + ) break; - } else { + else pqh[k]=pqh[j];k=j; - } } pqh[k]=old; } @@ -490,8 +499,15 @@ static void packet_enqueue(int dir,const unsigned char *buf,int size,int delms) } gettimeofday(&v,NULL); new->when= ((unsigned long long)v.tv_sec * 1000 + v.tv_usec/1000) + delms; - if (new->when > maxwhen) maxwhen=new->when; - if (!nofifo && new->when < maxwhen) new->when=maxwhen; + if (new->when > maxwhen) { + maxwhen=new->when; + counter=0; + } + if (!nofifo && new->when <= maxwhen) { + new->when=maxwhen; + counter++; + } + new->counter=counter; new->dir=dir; new->buf=malloc(size); if (new->buf==NULL) { @@ -517,7 +533,8 @@ static void packet_enqueue(int dir,const unsigned char *buf,int size,int delms) } } {int k=++npq; - while (new->when < pqh[k>>1]->when) { + while (new->when < pqh[k>>1]->when || + (new->when == pqh[k>>1]->when && new->counter < pqh[k>>1]->counter)) { pqh[k]=pqh[k>>1]; k >>= 1; } -- 2.11.4.GIT