[Git][NTPsec/ntpsec][master] Replay - make synchronous lookup an intercept point.
Eric S. Raymond
gitlab at mg.gitlab.com
Thu Dec 31 05:30:59 UTC 2015
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
95c15ce4 by Eric S. Raymond at 2015-12-31T00:30:17Z
Replay - make synchronous lookup an intercept point.
- - - - -
3 changed files:
- ntpd/ntp_config.c
- ntpd/ntp_intercept.c
- ntpd/ntp_intercept.h
Changes:
=====================================
ntpd/ntp_config.c
=====================================
--- a/ntpd/ntp_config.c
+++ b/ntpd/ntp_config.c
@@ -3688,40 +3688,6 @@ peerflag_bits(
return peerflags;
}
-static bool sync_lookup(char *hname, sockaddr_u *peeraddrp)
-{
- int a_info;
- size_t octets;
- struct addrinfo hints, *res;
-
- ZERO(hints);
- hints.ai_family = AF_UNSPEC;
- hints.ai_socktype = SOCK_DGRAM;
- hints.ai_protocol = IPPROTO_UDP;
- a_info = getaddrinfo(hname, "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(hname, "ntp", &hints, &res);
- }
- if (a_info != 0) {
- msyslog(LOG_ERR,
- "hostname %s can not be used (%s), please use IP address.",
- hname, gai_strerror(a_info));
- return false;
- } else {
- INSIST(res != NULL);
- memset(peeraddrp, '\0', sizeof(*peeraddrp));
- octets = min(sizeof(*peeraddrp), res->ai_addrlen);
- memcpy(peeraddrp, res->ai_addr, octets);
- return true;
- }
-}
-
static void
config_peers(
config_tree *ptree
@@ -3763,7 +3729,7 @@ config_peers(
0,
NULL);
} else if (force_synchronous_dns) {
- if (sync_lookup(*cmdline_servers, &peeraddr)) {
+ if (intercept_getaddrinfo(*cmdline_servers, &peeraddr)) {
peer_config(
&peeraddr,
NULL,
@@ -3853,7 +3819,7 @@ config_peers(
* synchronous lookup may be forced.
*/
} else if (force_synchronous_dns) {
- if (sync_lookup(curr_peer->addr->address, &peeraddr)) {
+ if (intercept_getaddrinfo(curr_peer->addr->address, &peeraddr)) {
peer_config(
&peeraddr,
NULL,
=====================================
ntpd/ntp_intercept.c
=====================================
--- a/ntpd/ntp_intercept.c
+++ b/ntpd/ntp_intercept.c
@@ -238,6 +238,40 @@ static void file_replay(const char *configfile, char *delimiter, char *tempfile)
fclose(tfp);
}
+bool intercept_getaddrinfo(char *hname, sockaddr_u *peeraddrp)
+{
+ int a_info;
+ size_t octets;
+ struct addrinfo hints, *res;
+
+ ZERO(hints);
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_DGRAM;
+ hints.ai_protocol = IPPROTO_UDP;
+ a_info = getaddrinfo(hname, "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(hname, "ntp", &hints, &res);
+ }
+ if (a_info != 0) {
+ msyslog(LOG_ERR,
+ "hostname %s can not be used (%s), please use IP address.",
+ hname, gai_strerror(a_info));
+ return false;
+ } else {
+ INSIST(res != NULL);
+ memset(peeraddrp, '\0', sizeof(*peeraddrp));
+ octets = min(sizeof(*peeraddrp), res->ai_addrlen);
+ memcpy(peeraddrp, res->ai_addr, octets);
+ return true;
+ }
+}
+
void intercept_getconfig(const char *configfile)
{
if (mode == replay) {
=====================================
ntpd/ntp_intercept.h
=====================================
--- a/ntpd/ntp_intercept.h
+++ b/ntpd/ntp_intercept.h
@@ -17,6 +17,7 @@ intercept_mode intercept_get_mode(void);
void intercept_set_mode(intercept_mode);
void intercept_argparse(int *, char ***);
+bool intercept_getaddrinfo(char *, sockaddr_u *);
void intercept_getconfig(const char *);
void intercept_get_systime(const char *, l_fp *);
long intercept_ntp_random(const char *);
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/95c15ce471e25d7d442d30e50fff29fbc07c7dd4
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20151231/9e8cd841/attachment.html>
More information about the vc
mailing list