9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] fs sntp fix for multiple interfaces
@ 2002-10-03  9:53 Geoff Collyer
  2002-10-03 12:48 ` Artem Letko
  0 siblings, 1 reply; 3+ messages in thread
From: Geoff Collyer @ 2002-10-03  9:53 UTC (permalink / raw)
  To: 9fans

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);


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [9fans] fs sntp fix for multiple interfaces
  2002-10-03  9:53 [9fans] fs sntp fix for multiple interfaces Geoff Collyer
@ 2002-10-03 12:48 ` Artem Letko
  0 siblings, 0 replies; 3+ messages in thread
From: Artem Letko @ 2002-10-03 12:48 UTC (permalink / raw)
  To: 9fans

Shouldn't IP routing take care of this?

Art.

----- Original Message -----
From: "Geoff Collyer" <geoff@collyer.net>
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);



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [9fans] fs sntp fix for multiple interfaces
@ 2002-10-03 14:03 nigel
  0 siblings, 0 replies; 3+ messages in thread
From: nigel @ 2002-10-03 14:03 UTC (permalink / raw)
  To: 9fans

> Shouldn't IP routing take care of this?
>

It would if there was any.

Before sntp was added, no IP routing was required in the fileserver.
It did not route.  It did not originate calls, as all it had to do was
reply to messages.  It did this by sending the reply to the interface
it received the request from.  There is inherent security and
simplicity in the server being passive.

When I added sntp, I just chose the first interface, out of laziness.
Essentially Geoff has just implemented routing, and very useful it is
too.



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-10-03 14:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-03  9:53 [9fans] fs sntp fix for multiple interfaces Geoff Collyer
2002-10-03 12:48 ` Artem Letko
2002-10-03 14:03 nigel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).