openvpn: ucode proto script improvements
authorPaul Donald <redacted>
Thu, 12 Mar 2026 03:45:27 +0000 (04:45 +0100)
committerHannu Nyman <redacted>
Sun, 15 Mar 2026 06:45:36 +0000 (08:45 +0200)
fix the pop() bug
write options to a config file in case argv length > 63

netifd has a hard limit of 64 argv entries for its ucode
proto.run_command whereby '--param' is one, and its
'option string' is two.

follow-up to affa96dc816653475bebef94d21443434cb1532c

Signed-off-by: Paul Donald <redacted>
net/openvpn/files/lib/netifd/proto/openvpn.uc

index 127cda5e643610dd24c8f6cd4ac5515062bccc6d..c48f164210a2b50cd9deaab1dc1f4ef0545fb9dd 100755 (executable)
@@ -8,6 +8,7 @@ const OPENVPN_PASS   = '/var/run/openvpn.%s.pass';
 const OPENVPN_AUTH   = '/var/run/openvpn.%s.auth';
 const OPENVPN_PID    = '/var/run/openvpn.%s.pid';
 const OPENVPN_STATUS = '/var/run/openvpn.%s.status';
+const OPENVPN_CONF   = '/var/run/openvpn.%s.conf';
 
 
 function openvpn_exists() {
@@ -442,7 +443,7 @@ function proto_setup(proto) {
        if (cfg.config && cfg.config !== '') {
                if (index(cfg.config, '/') >= 0) {
                        let parts = split(cfg.config, '/');
-                       parts.pop();
+                       pop(parts);
                        cd_dir = join('/', parts);
                        if (cd_dir == '') cd_dir = `/etc/openvpn/${iface}`;
                }
@@ -467,18 +468,25 @@ function proto_setup(proto) {
 
        // assemble the final command line
        let cmd = [
-               OPENVPN,
                '--cd', cd_dir,
                '--status', statusfile,
                '--syslog', sprintf('openvpn_%s', iface),
                '--tmp-dir', '/var/run',
                '--writepid', sprintf(OPENVPN_PID, iface),
-               // join(' ', params)
                ...params
        ];
 
+       // netifd has an argv array length hard limit of 64 including final \0
+       if (length(cmd) > 63) {
+               let conffile = sprintf(OPENVPN_CONF, iface);
+               fs.writefile(conffile, replace(join(' ', cmd), '--', '\n'));
+               cmd = [
+                       '--config', conffile,
+               ];
+       }
+
        // run_command needs an argv array
-       proto.run_command(cmd);
+       proto.run_command([OPENVPN, ...cmd]);
 
        // do not call proto.update_link() here - OpenVPN will handle if_up
 }
@@ -506,6 +514,7 @@ function proto_teardown(proto) {
        fs.unlink(sprintf(OPENVPN_AUTH, iface));
        fs.unlink(sprintf(OPENVPN_STATUS, iface));
        fs.unlink(sprintf(OPENVPN_PID, iface));
+       fs.unlink(sprintf(OPENVPN_CONF, iface));
 
        let link_data = {
                ifname: iface
git clone https://git.99rst.org/PROJECT