-/* $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>
| 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 {
-/* $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>
{
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");
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");
}