X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fnetifd.git;a=blobdiff_plain;f=proto.c;h=c72a00572cc4c8de44d6f9995be42d4e6d1267da;hp=ccc5f25a89be4dce52a8c585448af602b37bc740;hb=8cb06c3efe734a521507cba7b5f0ba206e2476e0;hpb=9cabaeb8a525ba050fb2dcf1204b6cb56a65a330 diff --git a/proto.c b/proto.c index ccc5f25..c72a005 100644 --- a/proto.c +++ b/proto.c @@ -70,66 +70,6 @@ static const struct blobmsg_policy proto_ip_addr[__ADDR_MAX] = { [ADDR_PTP] = { .name = "ptp", .type = BLOBMSG_TYPE_STRING }, }; -unsigned int -parse_netmask_string(const char *str, bool v6) -{ - struct in_addr addr; - unsigned int ret; - char *err = NULL; - - if (!strchr(str, '.')) { - ret = strtoul(str, &err, 0); - if (err && *err) - goto error; - - return ret; - } - - if (v6) - goto error; - - if (inet_aton(str, &addr) != 1) - goto error; - - return 32 - fls(~(ntohl(addr.s_addr))); - -error: - return ~0; -} - -static bool -split_netmask(char *str, unsigned int *netmask, bool v6) -{ - char *delim = strchr(str, '/'); - - if (delim) { - *(delim++) = 0; - - *netmask = parse_netmask_string(delim, v6); - } - return true; -} - -static int -parse_ip_and_netmask(int af, const char *str, void *addr, unsigned int *netmask) -{ - char *astr = alloca(strlen(str) + 1); - - strcpy(astr, str); - if (!split_netmask(astr, netmask, af == AF_INET6)) - return 0; - - if (af == AF_INET6) { - if (*netmask > 128) - return 0; - } else { - if (*netmask > 32) - return 0; - } - - return inet_pton(af, astr, addr); -} - static struct device_addr * alloc_device_addr(bool v6, bool ext) {