X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fnetifd.git;a=blobdiff_plain;f=proto.c;h=c72a00572cc4c8de44d6f9995be42d4e6d1267da;hp=8266e81ed71d995cc201cd8f1cada82af0a4aa57;hb=d7ce353d5656690b993acbfe73001b96fa788c97;hpb=2dc0f134aa7ec68ea7892a0d5e18d2e70b59a40e diff --git a/proto.c b/proto.c index 8266e81..c72a005 100644 --- a/proto.c +++ b/proto.c @@ -32,8 +32,6 @@ enum { OPT_BROADCAST, OPT_GATEWAY, OPT_IP6GW, - OPT_DNS, - OPT_DNS_SEARCH, __OPT_MAX, }; @@ -44,14 +42,11 @@ static const struct blobmsg_policy proto_ip_attributes[__OPT_MAX] = { [OPT_BROADCAST] = { .name = "broadcast", .type = BLOBMSG_TYPE_STRING }, [OPT_GATEWAY] = { .name = "gateway", .type = BLOBMSG_TYPE_STRING }, [OPT_IP6GW] = { .name = "ip6gw", .type = BLOBMSG_TYPE_STRING }, - [OPT_DNS] = { .name = "dns", .type = BLOBMSG_TYPE_ARRAY }, - [OPT_DNS_SEARCH] = { .name = "dns_search", .type = BLOBMSG_TYPE_ARRAY }, }; static const union config_param_info proto_ip_attr_info[__OPT_MAX] = { [OPT_IPADDR] = { .type = BLOBMSG_TYPE_STRING }, [OPT_IP6ADDR] = { .type = BLOBMSG_TYPE_STRING }, - [OPT_DNS] = { .type = BLOBMSG_TYPE_STRING }, }; const struct config_param_list proto_ip_attr = { @@ -75,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) { @@ -339,12 +274,6 @@ proto_apply_static_ip_settings(struct interface *iface, struct blob_attr *attr) goto out; } - if ((cur = tb[OPT_DNS])) - interface_add_dns_server_list(&iface->proto_ip, cur); - - if ((cur = tb[OPT_DNS_SEARCH])) - interface_add_dns_search_list(&iface->proto_ip, cur); - return 0; error: @@ -387,12 +316,6 @@ proto_apply_ip_settings(struct interface *iface, struct blob_attr *attr, bool ex goto out; } - if ((cur = tb[OPT_DNS])) - interface_add_dns_server_list(&iface->proto_ip, cur); - - if ((cur = tb[OPT_DNS_SEARCH])) - interface_add_dns_search_list(&iface->proto_ip, cur); - return 0; error: @@ -467,6 +390,19 @@ get_proto_handler(const char *name) } void +proto_dump_handlers(struct blob_buf *b) +{ + struct proto_handler *p; + void *c; + + avl_for_each_element(&handlers, p, avl) { + c = blobmsg_open_table(b, p->name); + blobmsg_add_u8(b, "no_device", !!(p->flags & PROTO_FLAG_NODEV)); + blobmsg_close_table(b, c); + } +} + +void proto_init_interface(struct interface *iface, struct blob_attr *attr) { const struct proto_handler *proto = iface->proto_handler;