diff options
author | 2021-01-19 17:38:41 +0000 | |
---|---|---|
committer | 2021-01-19 17:38:41 +0000 | |
commit | 8bc29b820807e94cd7a87be6d72b638be07660e4 (patch) | |
tree | 486d11014fce76d8e4effa25a7a7615b373d773b | |
parent | Make imsg event structs static to fix -fno-common. (diff) | |
download | wireguard-openbsd-8bc29b820807e94cd7a87be6d72b638be07660e4.tar.xz wireguard-openbsd-8bc29b820807e94cd7a87be6d72b638be07660e4.zip |
Get rid of inet_net_pton and inet_net_ntop.
This is not an api that seems to have caught on (especially the
AF_INET6 variant), maybe we can get rid of it entirely.
It is not difficult to hand-roll the AF_INET6 variant.
OK tb
-rw-r--r-- | usr.sbin/rad/parse.y | 25 | ||||
-rw-r--r-- | usr.sbin/rad/printconf.c | 10 |
2 files changed, 23 insertions, 12 deletions
diff --git a/usr.sbin/rad/parse.y b/usr.sbin/rad/parse.y index 8f32f11250d..fe2e922c958 100644 --- a/usr.sbin/rad/parse.y +++ b/usr.sbin/rad/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.16 2020/03/30 17:47:48 florian Exp $ */ +/* $OpenBSD: parse.y,v 1.17 2021/01/19 17:38:41 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser <florian@openbsd.org> @@ -260,17 +260,28 @@ ra_ifaceoptsl : NO AUTO PREFIX { | PREFIX STRING { struct in6_addr addr; int prefixlen; + char *p; + const char *errstr; memset(&addr, 0, sizeof(addr)); - prefixlen = inet_net_pton(AF_INET6, $2, &addr, - sizeof(addr)); - if (prefixlen == -1) { - yyerror("error parsing prefix"); + p = strchr($2, '/'); + if (p != NULL) { + *p++ = '\0'; + prefixlen = strtonum(p, 0, 128, &errstr); + if (errstr != NULL) { + yyerror("error parsing prefix " + "\"%s/%s\"", $2, p); + free($2); + YYERROR; + } + } else + prefixlen = 64; + if(inet_pton(AF_INET6, $2, &addr) == 0) { + yyerror("error parsing prefix \"%s/%d\"", $2, + prefixlen); free($2); YYERROR; } - if (prefixlen == 128 && strchr($2, '/') == NULL) - prefixlen = 64; mask_prefix(&addr, prefixlen); ra_prefix_conf = conf_get_ra_prefix(&addr, prefixlen); } ra_prefix_block { diff --git a/usr.sbin/rad/printconf.c b/usr.sbin/rad/printconf.c index d42890da518..78099534812 100644 --- a/usr.sbin/rad/printconf.c +++ b/usr.sbin/rad/printconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: printconf.c,v 1.5 2018/08/03 13:14:46 florian Exp $ */ +/* $OpenBSD: printconf.c,v 1.6 2021/01/19 17:38:41 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser <florian@openbsd.org> @@ -102,7 +102,7 @@ print_config(struct rad_conf *conf) { struct ra_iface_conf *iface; struct ra_prefix_conf *prefix; - char buf[INET6_ADDRSTRLEN], *bufp; + char buf[INET6_ADDRSTRLEN]; print_ra_options("", &conf->ra_options); printf("\n"); @@ -120,9 +120,9 @@ print_config(struct rad_conf *conf) printf("\tno auto prefix\n"); SIMPLEQ_FOREACH(prefix, &iface->ra_prefix_list, entry) { - bufp = inet_net_ntop(AF_INET6, &prefix->prefix, - prefix->prefixlen, buf, sizeof(buf)); - printf("\tprefix %s {\n", bufp); + printf("\tprefix %s/%d {\n", inet_ntop(AF_INET6, + &prefix->prefix, buf, sizeof(buf)), + prefix->prefixlen); print_prefix_options("\t\t", prefix); printf("\t}\n"); } |