X-Git-Url: http://git.archive.openwrt.org/?a=blobdiff_plain;f=proto.c;h=45eeb4b985937f8c1a95e0173639e09cc0c5a34c;hb=5df548d8edd3f9be39d409d1eeeaef99fbb27aa0;hp=e4465eb14e2a1900d3b38a3296dfc4c75f6ea47e;hpb=05e0d8f717f16e2076599742191e497cf8d04f0a;p=project%2Fnetifd.git diff --git a/proto.c b/proto.c index e4465eb..45eeb4b 100644 --- a/proto.c +++ b/proto.c @@ -55,9 +55,20 @@ static const struct uci_blob_param_info proto_ip_attr_info[__OPT_MAX] = { [OPT_IP6PREFIX] = { .type = BLOBMSG_TYPE_STRING }, }; +static const char * const proto_ip_validate[__OPT_MAX] = { + [OPT_IPADDR] = "ip4addr", + [OPT_IP6ADDR] = "ip6addr", + [OPT_NETMASK] = "netmask", + [OPT_BROADCAST] = "ipaddr", + [OPT_GATEWAY] = "ip4addr", + [OPT_IP6GW] = "ip6addr", + [OPT_IP6PREFIX] = "ip6addr", +}; + const struct uci_blob_param_list proto_ip_attr = { .n_params = __OPT_MAX, .params = proto_ip_attributes, + .validate = proto_ip_validate, .info = proto_ip_attr_info, }; @@ -90,6 +101,9 @@ alloc_device_addr(bool v6, bool ext) struct device_addr *addr; addr = calloc(1, sizeof(*addr)); + if (!addr) + return NULL; + addr->flags = v6 ? DEVADDR_INET6 : DEVADDR_INET4; if (ext) addr->flags |= DEVADDR_EXTERNAL; @@ -251,6 +265,9 @@ parse_gateway_option(struct interface *iface, struct blob_attr *attr, bool v6) int af = v6 ? AF_INET6 : AF_INET; route = calloc(1, sizeof(*route)); + if (!route) + return NULL; + if (!inet_pton(af, str, &route->nexthop)) { interface_add_error(iface, "proto", "INVALID_GATEWAY", &str, 1); free(route); @@ -259,6 +276,7 @@ parse_gateway_option(struct interface *iface, struct blob_attr *attr, bool v6) route->mask = 0; route->flags = (v6 ? DEVADDR_INET6 : DEVADDR_INET4); + route->metric = iface->metric; unsigned int table = (v6) ? iface->ip6table : iface->ip4table; if (table) { @@ -275,7 +293,7 @@ static bool parse_prefix_option(struct interface *iface, const char *str, size_t len) { char buf[128] = {0}, *saveptr; - if (len > sizeof(buf)) + if (len >= sizeof(buf)) return false; memcpy(buf, str, len); @@ -502,6 +520,9 @@ default_proto_attach(const struct proto_handler *h, struct interface_proto_state *proto; proto = calloc(1, sizeof(*proto)); + if (!proto) + return NULL; + proto->free = default_proto_free; proto->cb = no_proto_handler; @@ -574,16 +595,20 @@ void proto_attach_interface(struct interface *iface, const char *proto_name) { const struct proto_handler *proto = &no_proto; + const char *error = NULL; if (proto_name) { proto = get_proto_handler(proto_name); if (!proto) { - interface_add_error(iface, "proto", "INVALID_PROTO", NULL, 0); + error = "INVALID_PROTO"; proto = &no_proto; } } iface->proto_handler = proto; + + if (error) + interface_add_error(iface, "proto", error, NULL, 0); } int @@ -604,6 +629,9 @@ interface_proto_event(struct interface_proto_state *proto, case PROTO_CMD_TEARDOWN: ev = IFPEV_DOWN; break; + case PROTO_CMD_RENEW: + ev = IFPEV_RENEW; + break; default: return -EINVAL; }