[Git][NTPsec/ntpsec][master] 2 commits: Dead-code removal and typo fix.

Eric S. Raymond gitlab at mg.gitlab.com
Thu Dec 31 04:15:16 UTC 2015


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
f5761efd by Eric S. Raymond at 2015-12-30T12:27:31Z
Dead-code removal and typo fix.

- - - - -
6d4c48dd by Eric S. Raymond at 2015-12-30T23:14:24Z
Replay - force synchronous DNS lookup in capture and replay mode.

- - - - -


3 changed files:

- include/ntp_config.h
- ntpd/ntp_config.c
- ntpd/ntp_intercept.c


Changes:

=====================================
include/ntp_config.h
=====================================
--- a/include/ntp_config.h
+++ b/include/ntp_config.h
@@ -43,6 +43,7 @@
 /* list of servers from command line for config_peers() */
 extern	int	cmdline_server_count;
 extern	char **	cmdline_servers;
+extern	bool	force_synchronous_dns;
 
 /* set to false if admin doesn't want memory locked */
 extern	bool	do_memlock;


=====================================
ntpd/ntp_config.c
=====================================
--- a/ntpd/ntp_config.c
+++ b/ntpd/ntp_config.c
@@ -53,6 +53,7 @@
 /* list of servers from command line for config_peers() */
 int	cmdline_server_count;
 char **	cmdline_servers;
+bool	force_synchronous_dns;
 
 /* set to false if admin doesn't want memory locked */
 bool	do_memlock = true;
@@ -3687,7 +3688,6 @@ peerflag_bits(
 	return peerflags;
 }
 
-
 static void
 config_peers(
 	config_tree *ptree
@@ -3728,6 +3728,53 @@ config_peers(
 					0,
 					0,
 					NULL);
+		} else if (force_synchronous_dns) {
+			sockaddr_u		peeraddr;
+			struct addrinfo		hints;
+
+			struct addrinfo *res;
+			int a_info;
+			size_t octets;
+
+			ZERO(hints);
+			hints.ai_family = AF_UNSPEC;
+			hints.ai_socktype = SOCK_DGRAM;
+			hints.ai_protocol = IPPROTO_UDP;
+			a_info = getaddrinfo(*cmdline_servers,
+					     "ntp", &hints,
+					     &res);
+			if (a_info == EAI_NONAME
+#ifdef EAI_NODATA
+			    || a_info == EAI_NODATA
+#endif
+			   ) {
+				hints.ai_flags = AI_CANONNAME;
+				hints.ai_flags |= AI_ADDRCONFIG;
+				a_info = getaddrinfo(*cmdline_servers, "ntp", &hints, &res);
+			}
+			if (a_info != 0) {
+				msyslog(LOG_ERR,
+					"hostname %s can not be used (%s), please use IP address.",
+					*cmdline_servers, gai_strerror(a_info));
+			} else {
+				INSIST(res != NULL);
+				ZERO(peeraddr);
+				octets = min(sizeof(peeraddr), res->ai_addrlen);
+				memcpy(&peeraddr, res->ai_addr, octets);
+
+				peer_config(
+					&peeraddr,
+					NULL,
+					NULL,
+					MODE_CLIENT,
+					NTP_VERSION,
+					0,
+					0,
+					FLAG_IBURST,
+					0,
+					0,
+					NULL);
+			}
 		} else {
 			/* we have a hostname to resolve */
 # ifdef USE_WORKER
@@ -3750,8 +3797,8 @@ config_peers(
 					     (void *)ctx);
 # else	/* !USE_WORKER follows */
 			msyslog(LOG_ERR,
-				"hostname %s can not be used, please use IP address instead.",
-				curr_peer->addr->address);
+				"hostname %s can not be used (%s), please use IP address instead.",
+				curr_peer->addr->address, gai_strerror(a_info));
 # endif
 		}
 	}
@@ -3780,8 +3827,7 @@ config_peers(
 				curr_peer->group);
 		/*
 		 * If we have a numeric address, we can safely
-		 * proceed in the mainline with it.  Otherwise, hand
-		 * the hostname off to the blocking child.
+		 * proceed in the mainline with it.
 		 */
 		} else if (is_ip_address(curr_peer->addr->address,
 				  curr_peer->addr->type, &peeraddr)) {
@@ -3801,8 +3847,58 @@ config_peers(
 					curr_peer->ttl,
 					curr_peer->peerkey,
 					curr_peer->group);
+		/*
+		 * synchronous lookup may be forced.
+		 */
+		} else if (force_synchronous_dns) {
+			sockaddr_u		peeraddr;
+			struct addrinfo		hints;
+
+			struct addrinfo *res;
+			int a_info;
+			size_t octets;
+
+			ZERO(hints);
+			hints.ai_family = curr_peer->addr->type;
+			hints.ai_socktype = SOCK_DGRAM;
+			hints.ai_protocol = IPPROTO_UDP;
+			a_info = getaddrinfo(curr_peer->addr->address,
+					     "ntp", &hints,
+					     &res);
+			if (a_info == EAI_NONAME
+#ifdef EAI_NODATA
+			    || a_info == EAI_NODATA
+#endif
+			   ) {
+				hints.ai_flags = AI_CANONNAME;
+				hints.ai_flags |= AI_ADDRCONFIG;
+				a_info = getaddrinfo(curr_peer->addr->address, "ntp", &hints, &res);
+			}
+			if (a_info != 0) {
+				msyslog(LOG_ERR,
+					"hostname %s can not be used, please use IP address.",
+					curr_peer->addr->address);
+			} else {
+				INSIST(res != NULL);
+				ZERO(peeraddr);
+				octets = min(sizeof(peeraddr), res->ai_addrlen);
+				memcpy(&peeraddr, res->ai_addr, octets);
+
+				peer_config(
+					&peeraddr,
+					NULL,
+					NULL,
+					hmode,
+					curr_peer->peerversion,
+					curr_peer->minpoll,
+					curr_peer->maxpoll,
+					peerflag_bits(curr_peer),
+					curr_peer->ttl,
+					curr_peer->peerkey,
+					curr_peer->group);
+			}
 		} else {
-			/* we have a hostname to resolve */
+			/* hand the hostname off to the blocking child */
 # ifdef USE_WORKER
 			ctx = emalloc_zero(sizeof(*ctx));
 			ctx->family = curr_peer->addr->type;


=====================================
ntpd/ntp_intercept.c
=====================================
--- a/ntpd/ntp_intercept.c
+++ b/ntpd/ntp_intercept.c
@@ -123,6 +123,7 @@ void intercept_set_mode(intercept_mode newmode)
     if (mode != none) {
 	syslogit = false;
 	hashprefix = true;
+	force_synchronous_dns = true;
     }
 }
 
@@ -381,7 +382,7 @@ void intercept_drift_write(char *driftfile, double drift)
 	 */
 	float df;
 	get_operation("drift-write ");
-	/* See the comment of drift-read chwxcking. */ 
+	/* See the comment of drift-read checking. */ 
 	if (sscanf(linebuf, "drift-write %f'", &df) != 1) {
 	    fprintf(stderr, "ntpd: garbled drift-write format, line %d\n",lineno);
 	    exit(1);
@@ -614,13 +615,6 @@ intercept_leapsec_load_file(
     return loaded;
 }
 
-#define LFPTOUINT64(lfp)	((lfp)->l_uf | ((lfp)->l_ui << ))
-
-/*
- * These functions are requited beaus dplfptoa() is lodssy and won't
- * invert properly thrpugh atolfp().
- */
-
 static char *lfpdump(l_fp *fp)
 {
     char *buf;



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/73f0adacf1a7412a382fe936c59ac0155015a94b...6d4c48dda9f9071aba63bc11f300e9e92d8fdceb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20151231/643ed5fa/attachment.html>


More information about the vc mailing list