odhcpd: rename piofolder to piodir
authorDavid Härdeman <[email protected]>
Sun, 30 Nov 2025 20:59:33 +0000 (21:59 +0100)
committerÁlvaro Fernández Rojas <[email protected]>
Tue, 9 Dec 2025 15:38:25 +0000 (16:38 +0100)
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 <[email protected]>
Link: https://github.com/openwrt/odhcpd/pull/333
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
README.md
src/config.c
src/odhcpd.h
src/statefiles.c

index c375450c13d103f94279472e0b608578736f489e..f85f3473b537abc093d05dff7f8262facb8fd4be 100644 (file)
--- a/README.md
+++ b/README.md
@@ -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  |
 
 
index d81bb85962372500055174160d5c93f14f21d6e9..a79284c7e48f03805298e55857c2faf0948706f5 100644 (file)
@@ -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);
 
index 3ddbb0cd9b15c68b9712e2f6158bccd9d4da8945..7b6ac6c8cc0412291ebf7bdc54a23fc4386fad96 100644 (file)
@@ -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;
index 325233667c63d60e2ee78c2239163003ce6f2140..9e774ee29d7874252ce695cf64a4dcf473267e08 100644 (file)
@@ -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)