[Git][NTPsec/ntpsec][master] 6 commits: libisc; merge initialize_action() into initialize()
Gary E. Miller
gitlab at mg.gitlab.com
Wed Jun 7 00:50:13 UTC 2017
Gary E. Miller pushed to branch master at NTPsec / ntpsec
Commits:
14affc0e by Gary E. Miller at 2017-06-06T17:05:06-07:00
libisc; merge initialize_action() into initialize()
Only initialize() used initialize_action()
- - - - -
5e38f508 by Gary E. Miller at 2017-06-06T17:11:18-07:00
libisc: merge try_ipv6only() into initialize_ipv6only()
try_ipv6only() was only called from initialize_ipv6only()
- - - - -
975b37e2 by Gary E. Miller at 2017-06-06T17:17:12-07:00
libisc: remove assert() that duplicates INSIST().
- - - - -
f1972907 by Gary E. Miller at 2017-06-06T17:22:36-07:00
libisc: move isc_netaddr_fromsockaddr() into ntp_io.c
isc_netaddr_fromsockaddr() only used in ntp_io.c, now it can be
static.
- - - - -
36c88fb3 by Gary E. Miller at 2017-06-06T17:34:29-07:00
libisc: move -isc_netaddr_eqprefix() into ntp_io.c
rename isc_netaddr_eqprefix() to netaddr_eqprefix(). Now the
function can be static.
- - - - -
3ce5a5f0 by Gary E. Miller at 2017-06-06T17:48:25-07:00
libisc: merge libisc/netaddr.c into libisc/interfaceiter.c
This allowed several functions to be made static.
Bonus, discovered isc_netaddr_fromin() was unused. It was removed.
- - - - -
6 changed files:
- libisc/include/isc/netaddr.h
- libisc/interfaceiter.c
- libisc/net.c
- − libisc/netaddr.c
- libisc/wscript
- ntpd/ntp_io.c
Changes:
=====================================
libisc/include/isc/netaddr.h
=====================================
--- a/libisc/include/isc/netaddr.h
+++ b/libisc/include/isc/netaddr.h
@@ -100,25 +100,4 @@ struct isc_netaddr {
uint32_t zone;
};
-bool
-isc_netaddr_eqprefix(const isc_netaddr_t *, const isc_netaddr_t *,
- unsigned int) __attribute__((pure));
-void
-isc_netaddr_fromsockaddr(isc_netaddr_t *netaddr, const isc_sockaddr_t *source);
-
-void
-isc_netaddr_fromin(isc_netaddr_t *netaddr, const struct in_addr *ina);
-
-void
-isc_netaddr_fromin6(isc_netaddr_t *netaddr, const struct in6_addr *ina6);
-
-void
-isc_netaddr_setzone(isc_netaddr_t *netaddr, uint32_t zone);
-
-bool
-isc_netaddr_islinklocal(isc_netaddr_t *na) __attribute__((pure));
-/*%<
- * Returns #true if the address is a link local address.
- */
-
#endif /* GUARD_ISC_NETADDR_H */
=====================================
libisc/interfaceiter.c
=====================================
--- a/libisc/interfaceiter.c
+++ b/libisc/interfaceiter.c
@@ -36,6 +36,46 @@
# include <linux/if_addr.h>
#endif
+#define ISC_TF(x) ((x) ? true : false)
+
+static void
+isc_netaddr_fromin6(isc_netaddr_t *netaddr, const struct in6_addr *ina6);
+
+static void
+isc_netaddr_setzone(isc_netaddr_t *netaddr, uint32_t zone);
+
+static bool
+isc_netaddr_islinklocal(isc_netaddr_t *na) __attribute__((pure));
+
+static void
+isc_netaddr_fromin6(isc_netaddr_t *netaddr, const struct in6_addr *ina6) {
+ memset(netaddr, 0, sizeof(*netaddr));
+ netaddr->family = AF_INET6;
+ netaddr->type.in6 = *ina6;
+}
+
+static void
+isc_netaddr_setzone(isc_netaddr_t *netaddr, uint32_t zone) {
+ /* we currently only support AF_INET6. */
+ REQUIRE(netaddr->family == AF_INET6);
+
+ netaddr->zone = zone;
+}
+
+/*
+ * Returns #true if the address is a link local address.
+ */
+static bool
+isc_netaddr_islinklocal(isc_netaddr_t *na) {
+ switch (na->family) {
+ case AF_INET:
+ return (false);
+ case AF_INET6:
+ return (ISC_TF(IN6_IS_ADDR_LINKLOCAL(&na->type.in6)));
+ default:
+ return (false);
+ }
+}
typedef struct {
unsigned int magic;
=====================================
libisc/net.c
=====================================
--- a/libisc/net.c
+++ b/libisc/net.c
@@ -22,10 +22,6 @@
#include "isc/error.h"
#include "isc/result.h"
-static bool once_ipv6only = false;
-
-static bool once = false;
-
static isc_result_t ipv4_result = ISC_R_NOTFOUND;
static isc_result_t ipv6_result = ISC_R_NOTFOUND;
static isc_result_t ipv6only_result = ISC_R_NOTFOUND;
@@ -102,16 +98,13 @@ try_proto(int domain) {
}
static void
-initialize_action(void) {
- ipv4_result = try_proto(PF_INET);
- ipv6_result = try_proto(PF_INET6);
-}
-
-static void
initialize(void) {
+ static bool once = false;
+
if (once) return;
once = true;
- initialize_action();
+ ipv4_result = try_proto(PF_INET);
+ ipv6_result = try_proto(PF_INET6);
}
bool
@@ -132,11 +125,15 @@ isc_net_probeipv6(void) {
}
static void
-try_ipv6only(void) {
+initialize_ipv6only(void) {
+ static bool once_ipv6only = false;
#ifdef IPV6_V6ONLY
int s, on;
char strbuf[BUFSIZ];
#endif
+
+ if (once_ipv6only) return;
+ once_ipv6only = true;
isc_result_t result;
result = isc_net_probeipv6();
@@ -189,13 +186,6 @@ close:
#endif /* IPV6_V6ONLY */
}
-static void
-initialize_ipv6only(void) {
- if (once_ipv6only) return;
- once_ipv6only = true;
- try_ipv6only();
-}
-
bool
isc_net_probe_ipv6only_bool(void) {
initialize_ipv6only();
=====================================
libisc/netaddr.c deleted
=====================================
--- a/libisc/netaddr.c
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Copyright (C) 2004, 2005, 2007, 2010-2012 Internet Systems Consortium, Inc. ("ISC")
- * Copyright (C) 1999-2002 Internet Software Consortium.
- * Copyright 2015 by the NTPsec project contributors
- * SPDX-License-Identifier: ISC
- */
-
-/*! \file */
-
-#include "config.h"
-
-#include <stdio.h>
-
-#include "isc/netaddr.h"
-#include "isc/sockaddr.h"
-#include "ntp_assert.h"
-#include "ntp_stdlib.h" /* NTP change for strlcpy, strlcat */
-
-#define ISC_TF(x) ((x) ? true : false)
-
-bool
-isc_netaddr_eqprefix(const isc_netaddr_t *a, const isc_netaddr_t *b,
- unsigned int prefixlen)
-{
- const unsigned char *pa = NULL, *pb = NULL;
- unsigned int ipabytes = 0; /* Length of whole IP address in bytes */
- unsigned int nbytes; /* Number of significant whole bytes */
- unsigned int nbits; /* Number of significant leftover bits */
-
- REQUIRE(a != NULL && b != NULL);
-
- if (a->family != b->family)
- return (false);
-
- if (a->zone != b->zone && b->zone != 0)
- return (false);
-
- switch (a->family) {
- case AF_INET:
- pa = (const unsigned char *) &a->type.in;
- pb = (const unsigned char *) &b->type.in;
- ipabytes = 4;
- break;
- case AF_INET6:
- pa = (const unsigned char *) &a->type.in6;
- pb = (const unsigned char *) &b->type.in6;
- ipabytes = 16;
- break;
- default:
- return (false);
- }
-
- /*
- * Don't crash if we get a pattern like 10.0.0.1/9999999.
- */
- if (prefixlen > ipabytes * 8)
- prefixlen = ipabytes * 8;
-
- nbytes = prefixlen / 8;
- nbits = prefixlen % 8;
-
- if (nbytes > 0) {
- if (memcmp(pa, pb, nbytes) != 0)
- return (false);
- }
- if (nbits > 0) {
- unsigned int bytea, byteb, mask;
- INSIST(nbytes < ipabytes);
- INSIST(nbits < 8);
-#ifdef __COVERITY__
- /* head off CID 117240 */
- assert(nbytes < ipabytes);
-#endif /* __COVERITY__ */
- bytea = pa[nbytes];
- byteb = pb[nbytes];
- mask = (0xFF << (8-nbits)) & 0xFF;
- if ((bytea & mask) != (byteb & mask))
- return (false);
- }
- return (true);
-}
-
-void
-isc_netaddr_fromin(isc_netaddr_t *netaddr, const struct in_addr *ina) {
- memset(netaddr, 0, sizeof(*netaddr));
- netaddr->family = AF_INET;
- netaddr->type.in = *ina;
-}
-
-void
-isc_netaddr_fromin6(isc_netaddr_t *netaddr, const struct in6_addr *ina6) {
- memset(netaddr, 0, sizeof(*netaddr));
- netaddr->family = AF_INET6;
- netaddr->type.in6 = *ina6;
-}
-
-void
-isc_netaddr_setzone(isc_netaddr_t *netaddr, uint32_t zone) {
- /* we currently only support AF_INET6. */
- REQUIRE(netaddr->family == AF_INET6);
-
- netaddr->zone = zone;
-}
-
-void
-isc_netaddr_fromsockaddr(isc_netaddr_t *t, const isc_sockaddr_t *s) {
- int family = s->type.sa.sa_family;
- t->family = (unsigned int)family;
- switch (family) {
- case AF_INET:
- t->type.in = s->type.sin.sin_addr;
- t->zone = 0;
- break;
- case AF_INET6:
- memcpy(&t->type.in6, &s->type.sin6.sin6_addr, 16);
- t->zone = s->type.sin6.sin6_scope_id;
- break;
- default:
- INSIST(0);
- }
-}
-
-bool
-isc_netaddr_islinklocal(isc_netaddr_t *na) {
- switch (na->family) {
- case AF_INET:
- return (false);
- case AF_INET6:
- return (ISC_TF(IN6_IS_ADDR_LINKLOCAL(&na->type.in6)));
- default:
- return (false);
- }
-}
-
=====================================
libisc/wscript
=====================================
--- a/libisc/wscript
+++ b/libisc/wscript
@@ -3,7 +3,6 @@ def build(ctx):
libisc_source = [
"error.c",
- "netaddr.c",
"interfaceiter.c",
"net.c"
]
=====================================
ntpd/ntp_io.c
=====================================
--- a/ntpd/ntp_io.c
+++ b/ntpd/ntp_io.c
@@ -121,6 +121,14 @@ static int ninterfaces; /* total # of interfaces */
bool disable_dynamic_updates; /* if true, scan interfaces once only */
+static bool
+netaddr_eqprefix(const isc_netaddr_t *, const isc_netaddr_t *,
+ unsigned int) __attribute__((pure));
+
+static void
+netaddr_fromsockaddr(isc_netaddr_t *netaddr, const isc_sockaddr_t *source);
+
+
#ifdef REFCLOCK
/*
* Refclock stuff. We keep a chain of structures with data concerning
@@ -547,6 +555,82 @@ remove_asyncio_reader(
}
#endif /* defined(USE_ROUTING_SOCKET) */
+static void
+netaddr_fromsockaddr(isc_netaddr_t *t, const isc_sockaddr_t *s) {
+ int family = s->type.sa.sa_family;
+ t->family = (unsigned int)family;
+ switch (family) {
+ case AF_INET:
+ t->type.in = s->type.sin.sin_addr;
+ t->zone = 0;
+ break;
+ case AF_INET6:
+ memcpy(&t->type.in6, &s->type.sin6.sin6_addr, 16);
+ t->zone = s->type.sin6.sin6_scope_id;
+ break;
+ default:
+ INSIST(0);
+ }
+}
+
+static bool
+netaddr_eqprefix(const isc_netaddr_t *a, const isc_netaddr_t *b,
+ unsigned int prefixlen)
+{
+ const unsigned char *pa = NULL, *pb = NULL;
+ unsigned int ipabytes = 0; /* Length of whole IP address in bytes */
+ unsigned int nbytes; /* Number of significant whole bytes */
+ unsigned int nbits; /* Number of significant leftover bits */
+
+ REQUIRE(a != NULL && b != NULL);
+
+ if (a->family != b->family)
+ return (false);
+
+ if (a->zone != b->zone && b->zone != 0)
+ return (false);
+
+ switch (a->family) {
+ case AF_INET:
+ pa = (const unsigned char *) &a->type.in;
+ pb = (const unsigned char *) &b->type.in;
+ ipabytes = 4;
+ break;
+ case AF_INET6:
+ pa = (const unsigned char *) &a->type.in6;
+ pb = (const unsigned char *) &b->type.in6;
+ ipabytes = 16;
+ break;
+ default:
+ return (false);
+ }
+
+ /*
+ * Don't crash if we get a pattern like 10.0.0.1/9999999.
+ */
+ if (prefixlen > ipabytes * 8)
+ prefixlen = ipabytes * 8;
+
+ nbytes = prefixlen / 8;
+ nbits = prefixlen % 8;
+
+ if (nbytes > 0) {
+ if (memcmp(pa, pb, nbytes) != 0)
+ return (false);
+ }
+ if (nbits > 0) {
+ unsigned int bytea, byteb, mask;
+ INSIST(nbytes < ipabytes);
+ INSIST(nbits < 8);
+ bytea = pa[nbytes];
+ byteb = pb[nbytes];
+ mask = (0xFF << (8-nbits)) & 0xFF;
+ if ((bytea & mask) != (byteb & mask))
+ return (false);
+ }
+ return (true);
+}
+
/* compare two sockaddr prefixes */
static bool
@@ -562,13 +646,13 @@ addr_eqprefix(
ZERO(isc_sa);
memcpy(&isc_sa.type, a, min(sizeof(isc_sa.type), sizeof(*a)));
- isc_netaddr_fromsockaddr(&isc_a, &isc_sa);
+ netaddr_fromsockaddr(&isc_a, &isc_sa);
ZERO(isc_sa);
memcpy(&isc_sa.type, b, min(sizeof(isc_sa.type), sizeof(*b)));
- isc_netaddr_fromsockaddr(&isc_b, &isc_sa);
+ netaddr_fromsockaddr(&isc_b, &isc_sa);
- return isc_netaddr_eqprefix(&isc_a, &isc_b,
+ return netaddr_eqprefix(&isc_a, &isc_b,
(u_int)prefixlen);
}
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/866534e8c1984954c4b580a89e73c2ac7711c6d9...3ce5a5f0766e20b61378a75f851feffc7b9fd7b6
---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/866534e8c1984954c4b580a89e73c2ac7711c6d9...3ce5a5f0766e20b61378a75f851feffc7b9fd7b6
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/20170607/9f701841/attachment.html>
More information about the vc
mailing list