diff options
author | Thomas Gschwantner <tharre3@gmail.com> | 2019-12-11 05:48:49 +0100 |
---|---|---|
committer | Thomas Gschwantner <tharre3@gmail.com> | 2019-12-11 06:22:17 +0100 |
commit | 29148632a56939d90fb909b11a8d50a673ddc496 (patch) | |
tree | 8b9f87dff8268d9b3a56ea06e85df0122d128356 | |
parent | radix-trie: fix add() when no poolnodes exist (diff) | |
download | wg-dynamic-29148632a56939d90fb909b11a8d50a673ddc496.tar.xz wg-dynamic-29148632a56939d90fb909b11a8d50a673ddc496.zip |
Allow /32 and /128 to be omitted in ip= keys
-rw-r--r-- | common.c | 27 |
1 files changed, 15 insertions, 12 deletions
@@ -77,24 +77,27 @@ static void (*const deserialize_fptr[])(enum wg_dynamic_key key, static bool parse_ip_cidr(struct wg_combined_ip *ip, char *value) { - uintmax_t res; - char *endptr; char *sep; sep = strchr(value, '/'); - if (!sep) - return false; + if (sep) { + char *endptr; + uintmax_t res = strtoumax(sep + 1, &endptr, 10); + if (res > UINT8_MAX || *endptr != '\0' || sep + 1 == endptr) + return false; - *sep = '\0'; - if (inet_pton(ip->family, value, ip) != 1) - return false; + if ((ip->family == AF_INET && res > 32) || + (ip->family == AF_INET6 && res > 128)) + return false; - res = strtoumax(sep + 1, &endptr, 10); - if (res > UINT8_MAX || *endptr != '\0' || sep + 1 == endptr) - return false; + *sep = '\0'; + ip->cidr = (uint8_t)res; + } else { + ip->cidr = ip->family == AF_INET ? 32 : 128; + } - // TODO: validate cidr range depending on ip->family - ip->cidr = (uint8_t)res; + if (inet_pton(ip->family, value, ip) != 1) + return false; return true; } |