From 02b867f01eca1fefbe8b29205c8a8d4c13d2ffd0 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Fri, 28 Sep 2018 18:13:01 +0200 Subject: devip: only add interface route for "on-link" prefixes when a prefix is added with the onlink flag clear, packets towards that prefix needs to be send to the default gateway so we omit adding the interface route. when the on-link flag gets changed to 1 later, we add the interface route. the on-link flag is sticky, so theres no way to clear it back to zero except removing and re-adding the prefix. --- sys/src/9/ip/ipifc.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/sys/src/9/ip/ipifc.c b/sys/src/9/ip/ipifc.c index 0a078077f..c72a55971 100644 --- a/sys/src/9/ip/ipifc.c +++ b/sys/src/9/ip/ipifc.c @@ -505,7 +505,14 @@ ipifcadd(Ipifc *ifc, char **argv, int argc, int tentative, Iplifc *lifcp) /* ignore if this is already a local address for this ifc */ if((lifc = iplocalonifc(ifc, ip)) != nil){ if(lifcp != nil) { - lifc->onlink = lifcp->onlink; + if(!lifc->onlink && lifcp->onlink){ + lifc->onlink = 1; + addroute(f, lifc->remote, lifc->mask, ip, IPallbits, + lifc->remote, lifc->type, ifc, tifc); + if(v6addrtype(ip) != linklocalv6) + addroute(f, lifc->remote, lifc->mask, ip, IPnoaddr, + lifc->remote, lifc->type, ifc, tifc); + } lifc->autoflag = lifcp->autoflag; lifc->validlt = lifcp->validlt; lifc->preflt = lifcp->preflt; @@ -546,9 +553,11 @@ ipifcadd(Ipifc *ifc, char **argv, int argc, int tentative, Iplifc *lifcp) *l = lifc; /* add route for this logical interface */ - addroute(f, rem, mask, ip, IPallbits, rem, type, ifc, tifc); - if(v6addrtype(ip) != linklocalv6) - addroute(f, rem, mask, ip, IPnoaddr, rem, type, ifc, tifc); + if(lifc->onlink){ + addroute(f, rem, mask, ip, IPallbits, rem, type, ifc, tifc); + if(v6addrtype(ip) != linklocalv6) + addroute(f, rem, mask, ip, IPnoaddr, rem, type, ifc, tifc); + } addselfcache(f, ifc, lifc, ip, Runi); @@ -635,13 +644,15 @@ ipifcremlifc(Ipifc *ifc, Iplifc **l) remselfcache(f, ifc, lifc, lifc->link->self->a); /* remove the route for this logical interface */ - remroute(f, lifc->remote, lifc->mask, - lifc->local, IPallbits, - lifc->remote, lifc->type, ifc, tifc); - if(v6addrtype(lifc->local) != linklocalv6) + if(lifc->onlink){ remroute(f, lifc->remote, lifc->mask, - lifc->local, IPnoaddr, + lifc->local, IPallbits, lifc->remote, lifc->type, ifc, tifc); + if(v6addrtype(lifc->local) != linklocalv6) + remroute(f, lifc->remote, lifc->mask, + lifc->local, IPnoaddr, + lifc->remote, lifc->type, ifc, tifc); + } /* unregister proxy */ if(lifc->type & Rptpt){ -- cgit v1.2.3