odhcp6c: fix deamon raw buffer inc
authorxuxb <[email protected]>
Sun, 3 Dec 2023 07:11:21 +0000 (02:11 -0500)
committerÁlvaro Fernández Rojas <[email protected]>
Sun, 19 Oct 2025 14:38:16 +0000 (16:38 +0200)
When starting odhcp6c as a daemon using the following command:
  odhcp6c -s /etc/odhcp6c.script -p /var/run/eth0_odhcp6c.pid -P 0 \
    -t 120 eth0"
The DHCPv6 server sends RA packets every 10 seconds.
However, it was observed that the raw socket's receive buffer keeps
increasing continuously. After investigating the code, an error was found:
the I/O signal was bound before starting the daemon, causing the daemon to
not receive the I/O signal. Consequently, the raw socket's recv queue kept
growing indefinitely.

The author of this patch is inactive and didn't include a proper SoB:
https://github.com/Horbivores

Link: https://github.com/openwrt/odhcp6c/pull/80
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
src/odhcp6c.c

index 30bf78f29b87d57bab3ea9f72b1082cb1245d249..4531660c406bd846fafa3d48905ccb253e34e31b 100644 (file)
@@ -433,20 +433,12 @@ int main(_unused int argc, char* const argv[])
        signal(SIGUSR1, sighandler);
        signal(SIGUSR2, sighandler);
 
-       if ((urandom_fd = open("/dev/urandom", O_CLOEXEC | O_RDONLY)) < 0 ||
-                       init_dhcpv6(ifname, client_options, sk_prio, sol_timeout) ||
-                       ra_init(ifname, &ifid, ra_options, ra_holdoff_interval) ||
-                       script_init(script, ifname)) {
-               syslog(LOG_ERR, "failed to initialize: %s", strerror(errno));
-               return 3;
-       }
-
        if (daemonize) {
                openlog("odhcp6c", LOG_PID, LOG_DAEMON); // Disable LOG_PERROR
                if (daemon(0, 0)) {
                        syslog(LOG_ERR, "Failed to daemonize: %s",
                                        strerror(errno));
-                       return 4;
+                       return 3;
                }
 
                if (!pidfile) {
@@ -461,7 +453,15 @@ int main(_unused int argc, char* const argv[])
                }
        }
 
-       script_call("started", 0, false);
+    if ((urandom_fd = open("/dev/urandom", O_CLOEXEC | O_RDONLY)) < 0 ||
+            init_dhcpv6(ifname, client_options, sk_prio, sol_timeout) ||
+            ra_init(ifname, &ifid, ra_options, ra_holdoff_interval) ||
+            script_init(script, ifname)) {
+        syslog(LOG_ERR, "failed to initialize: %s", strerror(errno));
+        return 4;
+     }
+
+    script_call("started", 0, false);
 
        while (!signal_term) { // Main logic
                odhcp6c_clear_state(STATE_SERVER_ID);