tags 392250 +patch
thanks

> The perfect solution would be to fix openntpd source to have it clear
> the local socket addresses (using connect() again) when EINVAL is
> encountered with sendto().

It turned out that it's easier to close the socket (and mark it as not
connected) in such a case, and openntpd will connect again in the next
round. The patch is ugly (that -2 return value), but works.

> I haven't checked whether the problem is still present in testing.

It is.

norbi
diff -Naur openntpd-3.9p1/client.c openntpd-3.9p1-fixed/client.c
--- openntpd-3.9p1/client.c     2006-05-14 07:29:21.000000000 +0200
+++ openntpd-3.9p1-fixed/client.c       2006-10-11 02:41:44.000000000 +0200
@@ -116,6 +116,7 @@
 client_query(struct ntp_peer *p)
 {
        int     tos = IPTOS_LOWDELAY;
+       int     result;
 
        if (p->addr == NULL && client_nextaddr(p) == -1) {
                set_next(p, error_interval());
@@ -163,9 +164,17 @@
        p->query->msg.xmttime.fractionl = arc4random();
        p->query->xmttime = gettime();
 
-       if (ntp_sendmsg(p->query->fd, NULL, &p->query->msg,
-           NTP_MSGSIZE_NOAUTH, 0) == -1) {
+       if ((result = ntp_sendmsg(p->query->fd, NULL, &p->query->msg,
+           NTP_MSGSIZE_NOAUTH, 0)) < 0) {
                set_next(p, INTERVAL_QUERY_PATHETIC);
+               if (result == -2) {
+                       /*
+                        * got EINVAL in sendto(), probably the local socket
+                        * address got invalidated -> force re-connect()
+                        */
+                       close(p->query->fd);
+                       p->query->fd = -1;
+               }
                return (-1);
        }
 
diff -Naur openntpd-3.9p1/ntp_msg.c openntpd-3.9p1-fixed/ntp_msg.c
--- openntpd-3.9p1/ntp_msg.c    2006-05-14 07:29:21.000000000 +0200
+++ openntpd-3.9p1-fixed/ntp_msg.c      2006-10-11 02:41:49.000000000 +0200
@@ -98,6 +98,8 @@
                        return (-1);
                }
                log_warn("sendto");
+               if (errno == EINVAL)
+                       return (-2);
                return (-1);
        }
 

Reply via email to