From mboxrd@z Thu Jan 1 00:00:00 1970 From: Artem Letko Subject: Re: [9fans] fs sntp fix for multiple interfaces To: 9fans@cse.psu.edu Message-id: <001501c26adb$3f1ad3a0$1c742544@rosele01.nj.comcast.net> MIME-version: 1.0 Content-type: text/plain; charset=koi8-r Content-transfer-encoding: 7BIT References: <3b2aa572be4fd0636f951b8d9df9f9da@collyer.net> Date: Thu, 3 Oct 2002 08:48:58 -0400 Topicbox-Message-UUID: fc2705a4-eaca-11e9-9e20-41e7f4b1d025 Shouldn't IP routing take care of this? Art. ----- Original Message ----- From: "Geoff Collyer" To: <9fans@collyer.net> Sent: Thursday, October 03, 2002 5:53 AM Subject: [9fans] fs sntp fix for multiple interfaces > 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);