From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <3b2aa572be4fd0636f951b8d9df9f9da@collyer.net> From: Geoff Collyer To: 9fans@collyer.net MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Subject: [9fans] fs sntp fix for multiple interfaces Date: Thu, 3 Oct 2002 02:53:48 -0700 Topicbox-Message-UUID: fc02d620-eaca-11e9-9e20-41e7f4b1d025 If you have multiple interfaces, /sys/src/fs/ip/sntp.c transmits on the first one on the list of interfaces with a valid IP address, which isn't necessarily right. I've modified it to pick the first interface on the same subnet as the SNTP server, if there is such an interface. If not, it picks the first interface with a valid default gateway. If there aren't any of those, it gives up. ; history -D sntp.c Oct 3 02:36:52 PDT 2002 sntp.c 5564 [geoff] sntp.c:146 d /n/dump/2002/1002/sys/src/fs/ip/sntp.c:145 < /* find an interface on the same subnet as sntpip, if any */ sntp.c:148,149 c /n/dump/2002/1002/sys/src/fs/ip/sntp.c:147 < if(isvalidip(ifc->ipa) && < (nhgetl(ifc->ipa)&ifc->mask) == (nhgetl(sntpip)&ifc->mask)) --- > if(isvalidip(ifc->ipa)) sntp.c:152 d /n/dump/2002/1002/sys/src/fs/ip/sntp.c:149 < /* if none, find an interface with a default gateway */ sntp.c:154,158 d /n/dump/2002/1002/sys/src/fs/ip/sntp.c:150 < for(ifc = enets; ifc; ifc = ifc->next) < if(isvalidip(ifc->ipa) && isvalidip(ifc->netgate)) < break; < if(ifc == nil) { < DEBUG("sntp: can't send to %I; no ifc on same subnet or with default route\n", sntpip); sntp.c:160 d /n/dump/2002/1002/sys/src/fs/ip/sntp.c:151 < } sntp.c:163 c /n/dump/2002/1002/sys/src/fs/ip/sntp.c:154 < DEBUG("sntp: sending to %I on ifc %I\n", sntpip, ifc->ipa); --- > DEBUG("sntp: sending\n"); Apr 13 11:10:41 PDT 2002 /n/dump/2002/1002/sys/src/fs/ip/sntp.c 5127 [geoff] So the start of sntpsend should look like this: void sntpsend(void) { ushort sum; Msgbuf *mb; Sntppkt *s; uchar tmp[Pasize]; Ifc *ifc; /* find an interface on the same subnet as sntpip, if any */ for(ifc = enets; ifc; ifc = ifc->next) { if(isvalidip(ifc->ipa) && (nhgetl(ifc->ipa)&ifc->mask) == (nhgetl(sntpip)&ifc->mask)) break; } /* if none, find an interface with a default gateway */ if(ifc == nil) for(ifc = enets; ifc; ifc = ifc->next) if(isvalidip(ifc->ipa) && isvalidip(ifc->netgate)) break; if(ifc == nil) { DEBUG("sntp: can't send to %I; no ifc on same subnet or with default route\n", sntpip); return; } /* compose a UDP sntp request */ DEBUG("sntp: sending to %I on ifc %I\n", sntpip, ifc->ipa);