Subject: Re: bin/35479: /usr/sbin/timedc fails
To: None <gnats-bugs@NetBSD.org>
From: Christian Biere <christianbiere@gmx.de>
List: netbsd-bugs
Date: 01/25/2007 22:26:58
Woodchuck wrote:
> I determined the fix empirically.
> Print out sin.sin_port with and without the htons, observe
> results of a "clockdiff" command with and without the htons.
> On a little-endian (i386) machine, the original code results in a
> sin.sin_port value in the 63K range, and subsequent code that probes
> the target host for time/udp will fail if the target expects a privileged
> port. perhaps htons belongs *here*, perhaps another one elsewhere is
> spurious.
I checked all ocurrences of "port" in timed and timedc and couldn't find
anything wrong. I've looked with tcpdump and the ports seem to be correct:
22:22:08.986847 IP 192.168.0.2 > 192.168.0.1: icmp 28: time stamp query id 41488 seq 57345
22:22:08.988025 IP 192.168.0.1 > 192.168.0.2: icmp 28: time stamp reply id 41488 seq 57345 : org 0x495d7da recv 0x495d062 xmit 0x495d062
22:22:08.988076 IP 192.168.0.2 > 192.168.0.1: icmp 28: time stamp query id 41488 seq 59905
22:22:08.988588 IP 192.168.0.1 > 192.168.0.2: icmp 28: time stamp reply id 41488 seq 59905 : org 0x495d7dc recv 0x495d063 xmit 0x495d063
22:22:08.988604 IP 192.168.0.2 > 192.168.0.1: icmp 28: time stamp query id 41488 seq 62465
22:22:08.989063 IP 192.168.0.1 > 192.168.0.2: icmp 28: time stamp reply id 41488 seq 62465 : org 0x495d7dc recv 0x495d063 xmit 0x495d063
22:22:08.989078 IP 192.168.0.2 > 192.168.0.1: icmp 28: time stamp query id 41488 seq 65025
22:22:08.989532 IP 192.168.0.1 > 192.168.0.2: icmp 28: time stamp reply id 41488 seq 65025 : org 0x495d7dd recv 0x495d064 xmit 0x495d064
22:22:08.989546 IP 192.168.0.2 > 192.168.0.1: icmp 28: time stamp query id 41488 seq 2050
22:22:08.989997 IP 192.168.0.1 > 192.168.0.2: icmp 28: time stamp reply id 41488 seq 2050 : org 0x495d7dd recv 0x495d064 xmit 0x495d064
22:22:08.990011 IP 192.168.0.2 > 192.168.0.1: icmp 28: time stamp query id 41488 seq 4610
22:22:08.990463 IP 192.168.0.1 > 192.168.0.2: icmp 28: time stamp reply id 41488 seq 4610 : org 0x495d7de recv 0x495d065 xmit 0x495d065
22:22:08.990476 IP 192.168.0.2 > 192.168.0.1: icmp 28: time stamp query id 41488 seq 7170
22:22:08.990929 IP 192.168.0.1 > 192.168.0.2: icmp 28: time stamp reply id 41488 seq 7170 : org 0x495d7de recv 0x495d065 xmit 0x495d065
22:22:08.990942 IP 192.168.0.2 > 192.168.0.1: icmp 28: time stamp query id 41488 seq 9730
22:22:08.991398 IP 192.168.0.1 > 192.168.0.2: icmp 28: time stamp reply id 41488 seq 9730 : org 0x495d7de recv 0x495d066 xmit 0x495d066
22:22:08.991412 IP 192.168.0.2 > 192.168.0.1: icmp 28: time stamp query id 41488 seq 12290
22:22:08.991853 IP 192.168.0.1 > 192.168.0.2: icmp 28: time stamp reply id 41488 seq 12290 : org 0x495d7df recv 0x495d066 xmit 0x495d066
22:22:08.991867 IP 192.168.0.2 > 192.168.0.1: icmp 28: time stamp query id 41488 seq 14850
22:22:08.992364 IP 192.168.0.1 > 192.168.0.2: icmp 28: time stamp reply id 41488 seq 14850 : org 0x495d7df recv 0x495d066 xmit 0x495d066
22:22:08.992377 IP 192.168.0.2 > 192.168.0.1: icmp 28: time stamp query id 41488 seq 17410
22:22:08.992833 IP 192.168.0.1 > 192.168.0.2: icmp 28: time stamp reply id 41488 seq 17410 : org 0x495d7e0 recv 0x495d067 xmit 0x495d067
22:22:08.992847 IP 192.168.0.2 > 192.168.0.1: icmp 28: time stamp query id 41488 seq 19970
22:22:08.993297 IP 192.168.0.1 > 192.168.0.2: icmp 28: time stamp reply id 41488 seq 19970 : org 0x495d7e0 recv 0x495d067 xmit 0x495d067
22:22:08.993311 IP 192.168.0.2 > 192.168.0.1: icmp 28: time stamp query id 41488 seq 22530
22:22:08.993752 IP 192.168.0.1 > 192.168.0.2: icmp 28: time stamp reply id 41488 seq 22530 : org 0x495d7e1 recv 0x495d068 xmit 0x495d068
22:22:08.993766 IP 192.168.0.2 > 192.168.0.1: icmp 28: time stamp query id 41488 seq 25090
22:22:08.994210 IP 192.168.0.1 > 192.168.0.2: icmp 28: time stamp reply id 41488 seq 25090 : org 0x495d7e1 recv 0x495d068 xmit 0x495d068
22:22:08.994279 IP 192.168.0.2 > 192.168.0.1: icmp 28: time stamp query id 41488 seq 27650
22:22:08.994700 IP 192.168.0.1 > 192.168.0.2: icmp 28: time stamp reply id 41488 seq 27650 : org 0x495d7e2 recv 0x495d069 xmit 0x495d069
22:22:08.994725 IP 192.168.0.2 > 192.168.0.1: icmp 28: time stamp query id 41488 seq 30210
22:22:08.995258 IP 192.168.0.1 > 192.168.0.2: icmp 28: time stamp reply id 41488 seq 30210 : org 0x495d7e2 recv 0x495d069 xmit 0x495d069
22:22:08.995289 IP 192.168.0.2.1020 > 192.168.0.1.37: UDP, length: 4
22:22:08.996399 IP 192.168.0.1 > 192.168.0.2: icmp 36: 192.168.0.1 udp port 37 unreachable
22:22:11.003920 IP 192.168.0.2.1020 > 192.168.0.1.37: UDP, length: 4
22:22:11.005250 IP 192.168.0.1 > 192.168.0.2: icmp 36: 192.168.0.1 udp port 37 unreachable
22:22:13.013958 IP 192.168.0.2.1020 > 192.168.0.1.37: UDP, length: 4
22:22:13.015215 IP 192.168.0.1 > 192.168.0.2: icmp 36: 192.168.0.1 udp port 37 unreachable
22:22:15.024009 IP 192.168.0.2.1020 > 192.168.0.1.37: UDP, length: 4
22:22:15.025378 IP 192.168.0.1 > 192.168.0.2: icmp 36: 192.168.0.1 udp port 37 unreachable
22:22:17.034024 IP 192.168.0.2.1020 > 192.168.0.1.37: UDP, length: 4
22:22:17.035286 IP 192.168.0.1 > 192.168.0.2: icmp 36: 192.168.0.1 udp port 37 unreachable
22:22:19.044063 IP 192.168.0.2.1020 > 192.168.0.1.37: UDP, length: 4
22:22:19.045295 IP 192.168.0.1 > 192.168.0.2: icmp 36: 192.168.0.1 udp port 37 unreachable
22:22:21.054076 IP 192.168.0.2.1020 > 192.168.0.1.37: UDP, length: 4
22:22:21.055567 IP 192.168.0.1 > 192.168.0.2: icmp 36: 192.168.0.1 udp port 37 unreachable
22:22:23.064125 IP 192.168.0.2.1020 > 192.168.0.1.37: UDP, length: 4
22:22:23.065866 IP 192.168.0.1 > 192.168.0.2: icmp 36: 192.168.0.1 udp port 37 unreachable
22:22:25.074127 IP 192.168.0.2.1020 > 192.168.0.1.37: UDP, length: 4
22:22:25.075468 IP 192.168.0.1 > 192.168.0.2: icmp 36: 192.168.0.1 udp port 37 unreachable
22:22:27.084163 IP 192.168.0.2.1020 > 192.168.0.1.37: UDP, length: 4
22:22:27.085644 IP 192.168.0.1 > 192.168.0.2: icmp 36: 192.168.0.1 udp port 37 unreachable
Could you provide a trace as well? You probably found a bug but I don't think it's
here.
> The OpenBSD version moves all these calls to timedc.c, and makes
> the bind call with sin.sin_port set to zero. The relevant block
> of code there is :
>
> memset(&sin, 0, sizeof sin);
> sin.sin_family = AF_INET;
> sin.sin_addr.s_addr = INADDR_ANY;
> if (bind(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
> fprintf(stderr, "all reserved ports in use\n");
> (void)close(sock_raw);
> exit(1);
> }
This is better than doing this manually with a loop. I'll modify it to
use bindresvport() instead which picks a port between 600 and 1023.
--
Christian