9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Geoff Collyer <geoff@collyer.net>
To: 9fans@collyer.net
Subject: [9fans] fs sntp fix for multiple interfaces
Date: Thu,  3 Oct 2002 02:53:48 -0700	[thread overview]
Message-ID: <3b2aa572be4fd0636f951b8d9df9f9da@collyer.net> (raw)

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


             reply	other threads:[~2002-10-03  9:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-03  9:53 Geoff Collyer [this message]
2002-10-03 12:48 ` Artem Letko
2002-10-03 14:03 nigel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3b2aa572be4fd0636f951b8d9df9f9da@collyer.net \
    --to=geoff@collyer.net \
    --cc=9fans@collyer.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).