[Git][NTPsec/ntpsec][master] 2 commits: Add decimal gai error code to printout

Hal Murray gitlab at mg.gitlab.com
Sun Jun 18 18:41:06 UTC 2017


Hal Murray pushed to branch master at NTPsec / ntpsec


Commits:
bc9f1b70 by Hal Murray at 2017-06-18T01:13:57-07:00
Add decimal gai error code to printout

I've seen some a case that didn't make sense.
It was probably something broken in DNS.

- - - - -
7dd990ea by Hal Murray at 2017-06-18T01:17:21-07:00
Fix for Issue #340, 100% CPU and segfaults

My recent DNS changes had setup peer->dstadr
without adding it to the list of peers for
this interface.  So this peer didn't get
fixed up when the interface went away.

That left a dnagling pointer to memory that had been free-ed.

- - - - -


4 changed files:

- include/ntpd.h
- libntp/ntp_dns.c
- ntpd/ntp_peer.c
- ntpd/ntp_proto.c


Changes:

=====================================
include/ntpd.h
=====================================
--- a/include/ntpd.h
+++ b/include/ntpd.h
@@ -138,6 +138,7 @@ extern	void	peer_update_hash (struct peer *);
 extern	void	peer_all_reset	(void);
 extern	void	peer_clr_stats	(void);
 extern	void	refresh_all_peerinterfaces(void);
+extern  void	peer_refresh_interface(struct peer *);
 extern	void	unpeer		(struct peer *);
 extern	void	clear_all	(void);
 extern	int	score_all	(struct peer *);


=====================================
libntp/ntp_dns.c
=====================================
--- a/libntp/ntp_dns.c
+++ b/libntp/ntp_dns.c
@@ -94,8 +94,8 @@ void dns_check(void)
 		return;  /* leaves active set */
 	}
 	if (0 != gai_rc) {
-		msyslog(LOG_INFO, "dns_check: DNS error %s",
-			gai_strerror(gai_rc));
+		msyslog(LOG_INFO, "dns_check: DNS error: %d, %s",
+			gai_rc, gai_strerror(gai_rc));
 		answer = NULL;
 	}
 


=====================================
ntpd/ntp_peer.c
=====================================
--- a/ntpd/ntp_peer.c
+++ b/ntpd/ntp_peer.c
@@ -537,7 +537,7 @@ set_peerdstadr(
 		p->dstadr->peercnt--;
 		UNLINK_SLIST(unlinked, p->dstadr->peers, p, ilink,
 			     struct peer);
-		msyslog(LOG_INFO, "%s local addr %s -> %s",
+		msyslog(LOG_INFO, "%s unlink local addr %s -> %s",
 			socktoa(&p->srcadr), latoa(p->dstadr),
 			latoa(dstadr));
 	}
@@ -551,7 +551,7 @@ set_peerdstadr(
 /*
  * attempt to re-rebind interface if necessary
  */
-static void
+void
 peer_refresh_interface(
 	struct peer *p
 	)
@@ -581,6 +581,7 @@ peer_refresh_interface(
 	}
 
 	set_peerdstadr(p, niface);
+
 }
 
 
@@ -600,8 +601,15 @@ refresh_all_peerinterfaces(void)
 	 * or if the one they have hasn't worked for a while.
 	 */
 	for (p = peer_list; p != NULL; p = p->p_link) {
-		if (!(p->dstadr && (p->reach & 0x3)))	// Bug 2849 XOR 2043
-			peer_refresh_interface(p);
+		if ((p->dstadr) && (p->reach & 0x3))	// Bug 2849 XOR 2043
+			/* either of last 2 tries with this dstadr worked */
+			continue;
+		if (MDF_POOL & p->cast_flags)
+			continue;	/* Pool slots don't get interfaces. */
+		if (FLAG_DNS & p->flags)
+			continue;	/* Still doing DNS lookup. */
+		peer_refresh_interface(p);
+
 	}
 }
 


=====================================
ntpd/ntp_proto.c
=====================================
--- a/ntpd/ntp_proto.c
+++ b/ntpd/ntp_proto.c
@@ -913,7 +913,6 @@ transmit(
 	 */
 #ifdef ENABLE_DNS_LOOKUP
 	if (peer->cast_flags & MDF_POOL) {
-		/* FIXME-DNS turn on FLAG_DNS for pool */
 		peer->outdate = current_time;
 		if ((peer_associations <= 2 * sys_maxclock) &&
 		    (peer_associations < sys_maxclock ||
@@ -2426,6 +2425,7 @@ dns_take_server(
 	server->flags &= (unsigned)~FLAG_DNS;
 		
 	server->srcadr = *rmtadr;
+	peer_update_hash(server);
 
 	restrict_mask = restrictions(&server->srcadr);
 	if (RES_FLAGS & restrict_mask) {
@@ -2434,12 +2434,10 @@ dns_take_server(
 		restrict_source(&server->srcadr, false, 0);
 	}
 
-	server->dstadr = findinterface(&server->srcadr);
-if (NULL == server->dstadr)
-  msyslog(LOG_ERR, "dns_take_server: can't find interface for %s", server->hostname);
+	peer_refresh_interface(server);
+
 	server->hpoll = server->minpoll;
 	server->nextdate = current_time;
-	peer_update_hash(server);
 	peer_xmit(server);
 	poll_update(server, server->hpoll);
 }



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/5b35bb89f2bccc87a8eb0cf0c65793a7fe3d44f5...7dd990ea54a44f5009a3a6facd5ab130969bd46f

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/5b35bb89f2bccc87a8eb0cf0c65793a7fe3d44f5...7dd990ea54a44f5009a3a6facd5ab130969bd46f
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170618/f2f4da4f/attachment.html>


More information about the vc mailing list