Get rid of inet_net_pton and inet_net_ntop.
authorflorian <florian@openbsd.org>
Tue, 19 Jan 2021 17:38:41 +0000 (17:38 +0000)
committerflorian <florian@openbsd.org>
Tue, 19 Jan 2021 17:38:41 +0000 (17:38 +0000)
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

usr.sbin/rad/parse.y
usr.sbin/rad/printconf.c

index 8f32f11..fe2e922 100644 (file)
@@ -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 {
index d42890d..7809953 100644 (file)
@@ -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");
                }