-static const struct uci_parse_option opts[__OPT_MAX] = {
- [OPT_IPADDR] = { .name = "ipaddr" },
- [OPT_IP6ADDR] = { .name = "ip6addr" },
- [OPT_NETMASK] = { .name = "netmask", .type = UCI_TYPE_STRING },
- [OPT_GATEWAY] = { .name = "gateway", .type = UCI_TYPE_STRING },
- [OPT_DNS] = { .name = "dns" },
-};
-
-struct interface_proto_state *
-static_attach(struct proto_handler *h, struct interface *iface,
- struct uci_section *s)
-{
- struct uci_option *tb[__OPT_MAX];
- struct uci_element *e;
- struct v4_addr *v4 = NULL;
- struct v6_addr *v6 = NULL;
- int n_v4 = 0, n_v6 = 0;
- struct in_addr ina = {};
- const char *error = NULL;
- int netmask = 32;
- int i;
-
- uci_parse_section(s, opts, __OPT_MAX, tb);
-
- if (tb[OPT_NETMASK]) {
- if (!inet_aton(tb[OPT_NETMASK]->v.string, &ina)) {
- error = "INVALID_NETMASK";
- goto error;
- }
-
- netmask = 32 - fls(~(ntohl(ina.s_addr)));
- }
-
- if (tb[OPT_IPADDR]) {
- if (tb[OPT_IPADDR]->type == UCI_TYPE_STRING) {
- n_v4 = 1;
- v4 = alloca(sizeof(*v4));
- if (!parse_v4(tb[OPT_IPADDR]->v.string, v4, netmask))
- goto invalid_addr;
- } else {
- i = 0;
- n_v4 = count_list_entries(tb[OPT_IPADDR]);
- v4 = alloca(sizeof(*v4) * n_v4);
- uci_foreach_element(&tb[OPT_IPADDR]->v.list, e) {
- if (!parse_v4(e->name, &v4[i++], netmask))
- goto invalid_addr;
- }
- }
- }
-
- if (tb[OPT_IP6ADDR]) {
- if (tb[OPT_IP6ADDR]->type == UCI_TYPE_STRING) {
- n_v6 = 1;
- v6 = alloca(sizeof(*v6));
- v6->prefix = netmask;
- if (!parse_v6(tb[OPT_IP6ADDR]->v.string, v6, netmask))
- goto invalid_addr;
- } else {
- i = 0;
- n_v6 = count_list_entries(tb[OPT_IP6ADDR]);
- v6 = alloca(sizeof(*v6) * n_v6);
- uci_foreach_element(&tb[OPT_IP6ADDR]->v.list, e) {
- if (!parse_v6(e->name, &v6[i++], netmask))
- goto invalid_addr;
- }
- }
- }
-
-
- if (!n_v4 && !n_v6) {
- error = "NO_ADDRESS";