ref: 874701d1934617a5992511b713c8a0fe08491dd9
parent: eac7a2b12a9a6df73164132def672c681cf36820
author: cinap_lenrek <[email protected]>
date: Wed Apr 11 18:56:25 EDT 2018
devip: make v4 ifc broadcast and multicast routes specific to address this allows one to access the same network via multiple interfaces, the local address then determines which interface is used.
--- a/sys/src/9/ip/ipifc.c
+++ b/sys/src/9/ip/ipifc.c
@@ -86,14 +86,6 @@
#define v6addrcurr(lifc) ((lifc)->preflt == ~0L || \
(lifc)->origint + (lifc)->preflt >= NOW/1000)
-static uchar*
-defsmask(uchar *a)
-{
- if(v6addrtype(a) == linklocalv6)
- return IPallbits;
- return IPnoaddr;
-}
-
static int
comprefixlen(uchar *a, uchar *b, int n)
{
@@ -516,7 +508,10 @@
;
*l = lifc;
- addroute(f, rem, mask, ip, defsmask(ip), rem, type, ifc, tifc);
+ /* 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);
addselfcache(f, ifc, lifc, ip, Runi);
@@ -606,8 +601,12 @@
/* remove the route for this logical interface */
remroute(f, lifc->remote, lifc->mask,
- lifc->local, defsmask(lifc->local),
+ 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){
@@ -887,7 +886,9 @@
/* add to routing table */
addroute(f, a, IPallbits,
- lifc->local, defsmask(a),
+ lifc->local,
+ ((type & (Rbcast|Rmulti)) != 0 || v6addrtype(a) == linklocalv6) ?
+ IPallbits : IPnoaddr,
a, type, ifc, tifc);
if((type & Rmulti) && ifc->m->addmulti != nil)
@@ -1005,7 +1006,9 @@
/* remove from routing table */
remroute(f, a, IPallbits,
- lifc->local, defsmask(a),
+ lifc->local,
+ ((p->type & (Rbcast|Rmulti)) != 0 || v6addrtype(a) == linklocalv6) ?
+ IPallbits : IPnoaddr,
a, p->type, ifc, tifc);
if((p->type & Rmulti) && ifc->m->remmulti != nil){