From 7d152294b9fd9da1470b0266c63287f6f69a9607 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Wed, 30 Dec 1998 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1998-12-30 --- ip/rudp.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/ip/rudp.c b/ip/rudp.c index 6bed2d98028e330c6709589abfd0a32b31cdbc0d..1b2680044ee1e4c3e8465333ad755881c5738aa9 100644 --- a/ip/rudp.c +++ b/ip/rudp.c @@ -301,7 +301,7 @@ doipoput(Conv *c, Fs *f, Block *bp, int x, int ttl) Rudpcb *ucb; ucb = (Rudpcb*)c->ptcl; - if(ucb->randdrop && nrand(10) == 1) + if(ucb->randdrop && nrand(100) < ucb->randdrop) freeblist(bp); else ipoput(f, bp, x, ttl); @@ -603,25 +603,34 @@ rudpiput(Proto *rudp, uchar *ia, Block *bp) qunlock(ucb); } +static char *rudpunknown = "unknown rudp ctl request"; + char* rudpctl(Conv *c, char **f, int n) { Rudpcb *ucb; + int x; ucb = (Rudpcb*)c->ptcl; - if(n == 1){ - if(strcmp(f[0], "headers4") == 0){ - ucb->headers = 4; - return nil; - } else if(strcmp(f[0], "headers") == 0){ - ucb->headers = 6; - return nil; - } else if(strcmp(f[0], "randdrop") == 0){ - ucb->randdrop = 1; - return nil; - } + if(n < 1) + return rudpunknown; + + if(strcmp(f[0], "headers4") == 0){ + ucb->headers = 4; + return nil; + } else if(strcmp(f[0], "headers") == 0){ + ucb->headers = 6; + return nil; + } else if(strcmp(f[0], "randdrop") == 0){ + x = 10; /* default is 10% */ + if(n > 1) + x = atoi(f[1]); + if(x > 100 || x < 0) + return "illegal rudp drop rate"; + ucb->randdrop = x; + return nil; } - return "unknown control request"; + return rudpunknown; } void