diff options
| author | David Härdeman | 2025-11-30 20:59:33 +0000 |
|---|---|---|
| committer | Álvaro Fernández Rojas | 2025-12-09 15:38:25 +0000 |
| commit | a64760b30f67eee8f64d3a06790216de5e49b038 (patch) | |
| tree | 6b692e90a3bb0092b3ee3d4f07fba09486419881 | |
| parent | 6779344a8c8a96cfdb90bfd2ccd98f4e303b30c4 (diff) | |
| download | odhcpd-a64760b30f67eee8f64d3a06790216de5e49b038.tar.gz | |
odhcpd: rename piofolder to piodir
A "folder" is a Windows concept, rename the cfg option from "piofolder"
to "piodir", which will also make it more consistent with other cfg
options.
Signed-off-by: David Härdeman <david@hardeman.nu>
Link: https://github.com/openwrt/odhcpd/pull/333
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | src/config.c | 16 | ||||
| -rw-r--r-- | src/odhcpd.h | 4 | ||||
| -rw-r--r-- | src/statefiles.c | 51 |
4 files changed, 33 insertions, 40 deletions
@@ -66,7 +66,7 @@ and may also receive information from ubus | leasetrigger | string| | Lease trigger script | | hostsdir | string| | DHCPv4/v6 hostfile directory (one file per interface will be created) | | loglevel |integer| 6 | Syslog level priority (0-7) | -| piofolder |string | | Folder to store IPv6 prefix information (to detect stale prefixes, see RFC9096, §3.5) | +| piodir |string | | Directory to store IPv6 prefix information (to detect stale prefixes, see RFC9096, §3.5) | | enable_tz |bool | 1 | Toggle whether RFC4833 timezone information is sent to clients, if set in system | diff --git a/src/config.c b/src/config.c index d81bb85..a79284c 100644 --- a/src/config.c +++ b/src/config.c @@ -46,8 +46,8 @@ struct config config = { .dhcp_statedir_fd = -1, .dhcp_hostsdir = NULL, .dhcp_hostsdir_fd = -1, - .ra_piofolder = NULL, - .ra_piofolder_fd = -1, + .ra_piodir = NULL, + .ra_piodir_fd = -1, .uci_cfgdir = NULL, .log_level = LOG_WARNING, .log_level_cmdline = false, @@ -221,7 +221,7 @@ enum { ODHCPD_ATTR_LEASETRIGGER, ODHCPD_ATTR_LOGLEVEL, ODHCPD_ATTR_HOSTSDIR, - ODHCPD_ATTR_PIOFOLDER, + ODHCPD_ATTR_PIODIR, ODHCPD_ATTR_ENABLE_TZ, ODHCPD_ATTR_MAX }; @@ -232,7 +232,7 @@ static const struct blobmsg_policy odhcpd_attrs[ODHCPD_ATTR_MAX] = { [ODHCPD_ATTR_LEASETRIGGER] = { .name = "leasetrigger", .type = BLOBMSG_TYPE_STRING }, [ODHCPD_ATTR_LOGLEVEL] = { .name = "loglevel", .type = BLOBMSG_TYPE_INT32 }, [ODHCPD_ATTR_HOSTSDIR] = { .name = "hostsdir", .type = BLOBMSG_TYPE_STRING }, - [ODHCPD_ATTR_PIOFOLDER] = { .name = "piofolder", .type = BLOBMSG_TYPE_STRING }, + [ODHCPD_ATTR_PIODIR] = { .name = "piodir", .type = BLOBMSG_TYPE_STRING }, [ODHCPD_ATTR_ENABLE_TZ] = { .name = "enable_tz", .type = BLOBMSG_TYPE_BOOL }, }; @@ -468,9 +468,9 @@ static void set_config(struct uci_section *s) config.dhcp_hostsdir = strdup(blobmsg_get_string(c)); } - if ((c = tb[ODHCPD_ATTR_PIOFOLDER])) { - free(config.ra_piofolder); - config.ra_piofolder = strdup(blobmsg_get_string(c)); + if ((c = tb[ODHCPD_ATTR_PIODIR])) { + free(config.ra_piodir); + config.ra_piodir = strdup(blobmsg_get_string(c)); } if ((c = tb[ODHCPD_ATTR_LEASETRIGGER])) { @@ -2092,7 +2092,7 @@ void odhcpd_reload(void) statefiles_setup_dirfd(NULL, &config.dhcp_statedir_fd); } statefiles_setup_dirfd(config.dhcp_hostsdir, &config.dhcp_hostsdir_fd); - statefiles_setup_dirfd(config.ra_piofolder, &config.ra_piofolder_fd); + statefiles_setup_dirfd(config.ra_piodir, &config.ra_piodir_fd); vlist_flush(&lease_cfgs); diff --git a/src/odhcpd.h b/src/odhcpd.h index 3ddbb0c..7b6ac6c 100644 --- a/src/odhcpd.h +++ b/src/odhcpd.h @@ -218,8 +218,8 @@ struct config { char *dhcp_hostsdir; int dhcp_hostsdir_fd; - char *ra_piofolder; - int ra_piofolder_fd; + char *ra_piodir; + int ra_piodir_fd; char *uci_cfgdir; int log_level; diff --git a/src/statefiles.c b/src/statefiles.c index 3252336..9e774ee 100644 --- a/src/statefiles.c +++ b/src/statefiles.c @@ -138,7 +138,7 @@ static inline time_t statefiles_time_to_json(time_t config_time) static inline bool statefiles_ra_pio_enabled(struct interface *iface) { - return config.ra_piofolder_fd >= 0 && iface->ra == MODE_SERVER && !iface->master; + return config.ra_piodir_fd >= 0 && iface->ra == MODE_SERVER && !iface->master; } static bool statefiles_ra_pio_time(json_object *slaac_json, time_t *slaac_time) @@ -170,7 +170,7 @@ static json_object *statefiles_load_ra_pio_json(struct interface *iface) int fd; sprintf(filename, "%s.%s", ODHCPD_PIO_FILE_PREFIX, iface->ifname); - fd = openat(config.ra_piofolder_fd, filename, O_RDONLY | O_CLOEXEC); + fd = openat(config.ra_piodir_fd, filename, O_RDONLY | O_CLOEXEC); if (fd < 0) return NULL; @@ -269,32 +269,12 @@ void statefiles_read_prefix_information(struct interface *iface) } } -static void statefiles_save_ra_pio_json(struct interface *iface, struct json_object *json) -{ - FILE *fp; - - fp = statefiles_open_tmp_file(config.ra_piofolder_fd); - if (!fp) - return; - - if (json_object_to_fd(fileno(fp), json, JSON_C_TO_STRING_PLAIN)) { - error("rfc9096: %s: json write error %s", - iface->ifname, - json_util_get_last_err()); - statefiles_finish_tmp_file(config.ra_piofolder_fd, &fp, NULL, NULL); - return; - } - - statefiles_finish_tmp_file(config.ra_piofolder_fd, &fp, ODHCPD_PIO_FILE_PREFIX, iface->ifname); - iface->pio_update = false; - warn("rfc9096: %s: piofile updated", iface->ifname); -} - void statefiles_write_prefix_information(struct interface *iface) { struct json_object *json, *slaac_json; char ipv6_str[INET6_ADDRSTRLEN]; time_t now; + FILE *fp; if (!statefiles_ra_pio_enabled(iface)) return; @@ -302,17 +282,19 @@ void statefiles_write_prefix_information(struct interface *iface) if (!iface->pio_update) return; + fp = statefiles_open_tmp_file(config.ra_piodir_fd); + if (!fp) + return; + now = odhcpd_time(); json = json_object_new_object(); if (!json) - return; + goto out; slaac_json = json_object_new_array_ext(iface->pio_cnt); - if (!slaac_json) { - json_object_put(slaac_json); - return; - } + if (!slaac_json) + goto out; json_object_object_add(json, JSON_SLAAC, slaac_json); @@ -359,9 +341,20 @@ void statefiles_write_prefix_information(struct interface *iface) json_object_array_add(slaac_json, cur_pio_json); } - statefiles_save_ra_pio_json(iface, json); + if (json_object_to_fd(fileno(fp), json, JSON_C_TO_STRING_PLAIN)) { + error("rfc9096: %s: json write error %s", + iface->ifname, + json_util_get_last_err()); + goto out; + } + + statefiles_finish_tmp_file(config.ra_piodir_fd, &fp, ODHCPD_PIO_FILE_PREFIX, iface->ifname); + iface->pio_update = false; + warn("rfc9096: %s: piofile updated", iface->ifname); +out: json_object_put(json); + statefiles_finish_tmp_file(config.ra_piodir_fd, &fp, NULL, NULL); } static void statefiles_write_host(const char *ipbuf, const char *hostname, struct write_ctxt *ctxt) |