diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2016-10-14 17:21:27 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2016-10-14 17:21:27 +0000 |
commit | a50b256dde29028a056176a2bef99096f6c5b619 (patch) | |
tree | 2380b51100fa82d3f8bbfbe7d6b57447266adb6f | |
parent | 36fa9ff7abbc5a7ab8979073f401d84cba609322 (diff) | |
download | s6-dns-a50b256dde29028a056176a2bef99096f6c5b619.tar.xz |
Port to the new librandom API.
-rw-r--r-- | src/clients/s6-randomip.c | 9 | ||||
-rw-r--r-- | src/include/s6-dns/s6dns.h | 4 | ||||
-rw-r--r-- | src/libs6dns/deps-lib/s6dns | 2 | ||||
-rw-r--r-- | src/libs6dns/s6dns_engine.c | 6 | ||||
-rw-r--r-- | src/libs6dns/s6dns_finish.c | 9 | ||||
-rw-r--r-- | src/libs6dns/s6dns_init.c | 11 |
6 files changed, 30 insertions, 11 deletions
diff --git a/src/clients/s6-randomip.c b/src/clients/s6-randomip.c index b220374..2c1581a 100644 --- a/src/clients/s6-randomip.c +++ b/src/clients/s6-randomip.c @@ -38,19 +38,16 @@ int main (int argc, char const *const *argv) argc -= subgetopt_here.ind ; argv += subgetopt_here.ind ; if (!what) what = 1 ; what = 1 << (1 << what) ; - if (!badrandom_init()) strerr_diefu1sys(111, "init RNG") ; + if (!random_init()) strerr_diefu1sys(111, "init random generator") ; for (i = 0 ; !finite || (i < n) ; i++) { unsigned int len = what ; if (len > 16) { - char c ; - if (badrandom_string(&c, 1) < 1) - strerr_diefu1sys(111, "badrandom_string") ; + unsigned char c = random_char() ; len = (c & 1) ? 16 : 4 ; } - if (badrandom_string(ip, len) < 4) - strerr_diefu1sys(111, "badrandom_string") ; + random_string(ip, len) ; len = (len == 16) ? ip6_fmt(fmt, ip) : ip4_fmt(fmt, ip) ; fmt[len++] = '\n' ; if (buffer_put(buffer_1, fmt, len) < (int)len) diff --git a/src/include/s6-dns/s6dns.h b/src/include/s6-dns/s6dns.h index dbc1138..448f14d 100644 --- a/src/include/s6-dns/s6dns.h +++ b/src/include/s6-dns/s6dns.h @@ -12,7 +12,7 @@ #include <s6-dns/s6dns-resolve.h> #include <s6-dns/s6dns-fmt.h> -#define s6dns_init() s6dns_rci_init(&s6dns_rci_here, "/etc/resolv.conf") -#define s6dns_finish() (s6dns_engine_free(&s6dns_engine_here), s6dns_rci_free(&s6dns_rci_here)) +extern int s6dns_init (void) ; +extern void s6dns_finish (void) ; #endif diff --git a/src/libs6dns/deps-lib/s6dns b/src/libs6dns/deps-lib/s6dns index 1140b6e..b0ae95d 100644 --- a/src/libs6dns/deps-lib/s6dns +++ b/src/libs6dns/deps-lib/s6dns @@ -86,4 +86,6 @@ s6dns_debug_dumpdt_stderr.o s6dns_debug_dumpdt_post_recv.o s6dns_debug_dumpdt_pre_send.o s6dns_debug_dumpdt_post_send.o +s6dns_init.o +s6dns_finish.o -lskarnet diff --git a/src/libs6dns/s6dns_engine.c b/src/libs6dns/s6dns_engine.c index 6cf7797..f903ea9 100644 --- a/src/libs6dns/s6dns_engine.c +++ b/src/libs6dns/s6dns_engine.c @@ -71,7 +71,7 @@ static int randombind (int fd, int flag) { register unsigned int i = 0 ; for (; i < 10 ; i++) - if (socketbind46(fd, S6DNS_ENGINE_LOCAL0, 1025 + badrandom_int(64510), flag) >= 0) return 1 ; + if (socketbind46(fd, S6DNS_ENGINE_LOCAL0, 1025 + random_uint32(64510), flag) >= 0) return 1 ; return (socketbind46(fd, S6DNS_ENGINE_LOCAL0, 0, flag) >= 0) ; } @@ -86,7 +86,7 @@ static int thisudp (s6dns_engine_t *dt, tain_t const *stamp) } if (byte_diff(s6dns_ip46list_ip(&dt->servers, dt->curserver), SKALIBS_IP_SIZE, S6DNS_ENGINE_LOCAL0)) break ; } - if (badrandom_string(dt->sa.s + 2, 2) < 2) return -1 ; /* random query id */ + random_string(dt->sa.s + 2, 2) ; /* random query id */ dt->fd = socketudp46(s6dns_ip46list_is6(&dt->servers, dt->curserver)) ; if (dt->fd < 0) return -1 ; if (!randombind(dt->fd, s6dns_ip46list_is6(&dt->servers, dt->curserver))) @@ -117,7 +117,7 @@ static int thistcp (s6dns_engine_t *dt, tain_t const *stamp) for (; dt->curserver < S6DNS_MAX_SERVERS ; dt->curserver++) if (byte_diff(s6dns_ip46list_ip(&dt->servers, dt->curserver), SKALIBS_IP_SIZE, S6DNS_ENGINE_LOCAL0)) break ; if (dt->curserver >= S6DNS_MAX_SERVERS) return -2 ; - if (badrandom_string(dt->sa.s + 2, 2) < 2) return -1 ; + random_string(dt->sa.s + 2, 2) ; dt->fd = sockettcp46(s6dns_ip46list_is6(&dt->servers, dt->curserver)) ; if (dt->fd < 0) return -1 ; if (!randombind(dt->fd, s6dns_ip46list_is6(&dt->servers, dt->curserver))) diff --git a/src/libs6dns/s6dns_finish.c b/src/libs6dns/s6dns_finish.c new file mode 100644 index 0000000..3520c5d --- /dev/null +++ b/src/libs6dns/s6dns_finish.c @@ -0,0 +1,9 @@ +/* ISC license. */ + +#include <s6dns/s6-dns.h> + +void s6dns_finish () +{ + s6dns_engine_free(&s6dns_engine_here) ; + s6dns_rci_free(&s6dns_rci_here) ; +} diff --git a/src/libs6dns/s6dns_init.c b/src/libs6dns/s6dns_init.c new file mode 100644 index 0000000..04f94d9 --- /dev/null +++ b/src/libs6dns/s6dns_init.c @@ -0,0 +1,11 @@ +/* ISC license. */ + +#include <skalibs/random.h> +#include <s6dns/s6-dns.h> + +int s6dns_init (void) +{ + if (!random_init()) return 0 ; + if (!s6dns_rci_init(&s6dns_rci_here, "/etc/resolv.conf")) return 0 ; + return 1 ; +} |