diff options
author | Santiago Piccinini <spiccinini@altermundi.net> | 2020-12-02 19:07:05 -0300 |
---|---|---|
committer | Hans Dedecker <dedeckeh@gmail.com> | 2020-12-06 20:44:29 +0100 |
commit | 8f27697b9b82420890cedd429622052c8b67cea1 (patch) | |
tree | fb8ddcb7580e973de1604d8dc995b00977ba0d90 /src/config.c | |
parent | 694148a87fa5a0c964286fdaac1fa490a2fb530b (diff) |
ubus: add add_lease method
Allows sharing leases between odhcpd instances running
in multiple hosts.
Signed-off-by: Santiago Piccinini <spiccinini@altermundi.net>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Diffstat (limited to 'src/config.c')
-rw-r--r-- | src/config.c | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/src/config.c b/src/config.c index 8a6f573..95b745c 100644 --- a/src/config.c +++ b/src/config.c @@ -144,17 +144,7 @@ const struct uci_blob_param_list interface_attr_list = { .info = iface_attr_info, }; -enum { - LEASE_ATTR_IP, - LEASE_ATTR_MAC, - LEASE_ATTR_DUID, - LEASE_ATTR_HOSTID, - LEASE_ATTR_LEASETIME, - LEASE_ATTR_NAME, - LEASE_ATTR_MAX -}; - -static const struct blobmsg_policy lease_attrs[LEASE_ATTR_MAX] = { +const struct blobmsg_policy lease_attrs[LEASE_ATTR_MAX] = { [LEASE_ATTR_IP] = { .name = "ip", .type = BLOBMSG_TYPE_STRING }, [LEASE_ATTR_MAC] = { .name = "mac", .type = BLOBMSG_TYPE_STRING }, [LEASE_ATTR_DUID] = { .name = "duid", .type = BLOBMSG_TYPE_STRING }, @@ -387,16 +377,15 @@ static void free_lease(struct lease *l) free(l); } -static int set_lease(struct uci_section *s) + +int set_lease_from_blobmsg(struct blob_attr *ba) { struct blob_attr *tb[LEASE_ATTR_MAX], *c; struct lease *l; size_t duidlen = 0; uint8_t *duid; - blob_buf_init(&b, 0); - uci_to_blob(&b, s, &lease_attr_list); - blobmsg_parse(lease_attrs, LEASE_ATTR_MAX, tb, blob_data(b.head), blob_len(b.head)); + blobmsg_parse(lease_attrs, LEASE_ATTR_MAX, tb, blob_data(ba), blob_len(ba)); if ((c = tb[LEASE_ATTR_DUID])) duidlen = (blobmsg_data_len(c) - 1) / 2; @@ -460,6 +449,14 @@ err: return -1; } +static int set_lease_from_uci(struct uci_section *s) +{ + blob_buf_init(&b, 0); + uci_to_blob(&b, s, &lease_attr_list); + + return set_lease_from_blobmsg(b.head); +} + int config_parse_interface(void *data, size_t len, const char *name, bool overwrite) { struct interface *iface; @@ -1072,7 +1069,7 @@ void odhcpd_reload(void) uci_foreach_element(&dhcp->sections, e) { struct uci_section* s = uci_to_section(e); if (!strcmp(s->type, "host")) - set_lease(s); + set_lease_from_uci(s); } } |