diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2020-01-05 18:20:47 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2020-01-05 18:20:47 +0100 |
commit | f12744b5db76e862de58aaa54cbd5ddfc63905b0 (patch) | |
tree | 3823443b6a66fd8a5d4114fba5257bed1554cc76 /sys/src/9/ip/netdevmedium.c | |
parent | 645b5f8724c0116d974680bdb591320256cc36e0 (diff) |
devip: fix packet loss when interface is wlocked
to prevent deadlock on media unbind (which is called with
the interface wlock()'ed), the medias reader processes
that unbind was waiting for used to discard packets when
the interface could not be rlocked.
this has the unfortunate side effect that when we change
addresses on a interface that packets are getting lost.
this is problematic for the processing of ipv6 router
advertisements when multiple RA's are getting received
in quick succession.
this change removes that packet dropping behaviour and
instead changes the unbind process to avoid the deadlock
by wunlock()ing the interface temporarily while waiting
for the reader processes to finish. the interface media
is also changed to the mullmedium before unlocking (see
the comment).
Diffstat (limited to 'sys/src/9/ip/netdevmedium.c')
-rw-r--r-- | sys/src/9/ip/netdevmedium.c | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/sys/src/9/ip/netdevmedium.c b/sys/src/9/ip/netdevmedium.c index f3d9ac1a4..6d56420fd 100644 --- a/sys/src/9/ip/netdevmedium.c +++ b/sys/src/9/ip/netdevmedium.c @@ -66,6 +66,9 @@ netdevunbind(Ipifc *ifc) { Netdevrock *er = ifc->arg; + while(waserror()) + ; + /* wait for reader to start */ while(er->readp == (void*)-1) tsleep(&up->sleep, return0, 0, 300); @@ -73,10 +76,19 @@ netdevunbind(Ipifc *ifc) if(er->readp != nil) postnote(er->readp, 1, "unbind", 0); + poperror(); + + wunlock(ifc); + while(waserror()) + ; + /* wait for reader to die */ while(er->readp != nil) tsleep(&up->sleep, return0, 0, 300); + poperror(); + wlock(ifc); + if(er->mchan != nil) cclose(er->mchan); @@ -107,33 +119,22 @@ netdevread(void *a) Ipifc *ifc; Block *bp; Netdevrock *er; - char *argv[1]; ifc = a; er = ifc->arg; er->readp = up; /* hide identity under a rock for unbind */ - if(waserror()){ - er->readp = nil; - pexit("hangup", 1); - } + if(!waserror()) for(;;){ bp = devtab[er->mchan->type]->bread(er->mchan, ifc->maxtu, 0); if(bp == nil){ - /* - * get here if mchan is a pipe and other side hangs up - * clean up this interface & get out - */ poperror(); - er->readp = nil; - argv[0] = "unbind"; - if(!waserror()) + if(!waserror()){ + static char *argv[] = { "unbind" }; ifc->conv->p->ctl(ifc->conv, argv, 1); - pexit("hangup", 1); - } - if(!canrlock(ifc)){ - freeb(bp); - continue; + } + break; } + rlock(ifc); if(waserror()){ runlock(ifc); nexterror(); @@ -146,6 +147,8 @@ netdevread(void *a) runlock(ifc); poperror(); } + er->readp = nil; + pexit("hangup", 1); } void |