X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fnetifd.git;a=blobdiff_plain;f=proto.c;h=3d611a274f5ef067bc2511e77d93db3a2ac01e3b;hp=40e7fc81237c2e84d56b2337c4bf85e9e9fec9a2;hb=486aa750a164d41905beb61afec89268e3eb7f48;hpb=d7f7f002e3d168aedb5f2bc92180f5966482d7d9 diff --git a/proto.c b/proto.c index 40e7fc8..3d611a2 100644 --- a/proto.c +++ b/proto.c @@ -66,6 +66,9 @@ enum { ADDR_MASK, ADDR_BROADCAST, ADDR_PTP, + ADDR_PREFERRED, + ADDR_VALID, + ADDR_OFFLINK, __ADDR_MAX }; @@ -74,6 +77,9 @@ static const struct blobmsg_policy proto_ip_addr[__ADDR_MAX] = { [ADDR_MASK] = { .name = "mask", .type = BLOBMSG_TYPE_STRING }, [ADDR_BROADCAST] = { .name = "broadcast", .type = BLOBMSG_TYPE_STRING }, [ADDR_PTP] = { .name = "ptp", .type = BLOBMSG_TYPE_STRING }, + [ADDR_PREFERRED] = { .name = "preferred", .type = BLOBMSG_TYPE_INT32 }, + [ADDR_VALID] = { .name = "valid", .type = BLOBMSG_TYPE_INT32 }, + [ADDR_OFFLINK] = { .name = "offlink", .type = BLOBMSG_TYPE_BOOL }, }; static struct device_addr * @@ -169,6 +175,9 @@ parse_address_item(struct blob_attr *attr, bool v6, bool ext) if (!inet_pton(v6 ? AF_INET6 : AF_INET, blobmsg_data(cur), &addr->addr)) goto error; + if ((cur = tb[ADDR_OFFLINK]) && blobmsg_get_bool(cur)) + addr->flags |= DEVADDR_OFFLINK; + if (!v6) { if ((cur = tb[ADDR_BROADCAST]) && !inet_pton(AF_INET, blobmsg_data(cur), &addr->broadcast)) @@ -176,6 +185,27 @@ parse_address_item(struct blob_attr *attr, bool v6, bool ext) if ((cur = tb[ADDR_PTP]) && !inet_pton(AF_INET, blobmsg_data(cur), &addr->point_to_point)) goto error; + } else { + time_t now = system_get_rtime(); + if ((cur = tb[ADDR_PREFERRED])) { + uint32_t preferred = blobmsg_get_u32(cur); + if (preferred < UINT32_MAX) + addr->preferred_until = now + preferred; + } + + if ((cur = tb[ADDR_VALID])) { + uint32_t valid = blobmsg_get_u32(cur); + if (valid < UINT32_MAX) + addr->valid_until = now + valid; + + } + + if (addr->valid_until) { + if (!addr->preferred_until) + addr->preferred_until = addr->valid_until; + else if (addr->preferred_until > addr->valid_until) + goto error; + } } return addr; @@ -343,19 +373,12 @@ proto_apply_static_ip_settings(struct interface *iface, struct blob_attr *attr) if ((cur = tb[OPT_IP6ADDR])) n_v6 = parse_static_address_option(iface, cur, true, - netmask, false, 0); + 128, false, 0); if ((cur = tb[OPT_IP6PREFIX])) if (parse_prefix_list(iface, cur) < 0) goto out; -/* TODO: Clarify - if (!n_v4 && !n_v6) { - error = "NO_ADDRESS"; - goto error; - } -*/ - if (n_v4 < 0 || n_v6 < 0) goto out; @@ -386,7 +409,6 @@ proto_apply_ip_settings(struct interface *iface, struct blob_attr *attr, bool ex { struct blob_attr *tb[__OPT_MAX]; struct blob_attr *cur; -// const char *error; int n_v4 = 0, n_v6 = 0; blobmsg_parse(proto_ip_attributes, __OPT_MAX, tb, blob_data(attr), blob_len(attr)); @@ -401,13 +423,6 @@ proto_apply_ip_settings(struct interface *iface, struct blob_attr *attr, bool ex if (parse_prefix_list(iface, cur) < 0) goto out; -/* TODO: clarify - if (!n_v4 && !n_v6) { - error = "NO_ADDRESS"; - goto error; - } -*/ - if (n_v4 < 0 || n_v6 < 0) goto out; @@ -427,10 +442,6 @@ proto_apply_ip_settings(struct interface *iface, struct blob_attr *attr, bool ex return 0; -/* TODO: clarify -error: - interface_add_error(iface, "proto", error, NULL, 0); -*/ out: return -1; }