diff options
author | jim-p <jimp@pfsense.org> | 2010-05-17 15:55:38 -0400 |
---|---|---|
committer | jim-p <jimp@pfsense.org> | 2010-05-17 15:55:38 -0400 |
commit | be58c36ded298a1cb7a0eac40cd2edd62908d882 (patch) | |
tree | 7baa1ba6925677dd0516a2021d5d6a7e8f3b9a75 /etc | |
parent | b65f56f69baec76614296e393a74deedba13da48 (diff) | |
download | pfsense-be58c36ded298a1cb7a0eac40cd2edd62908d882.zip pfsense-be58c36ded298a1cb7a0eac40cd2edd62908d882.tar.gz |
Allow the user to override OpenVPN interface name in custom options (e.g. dev tap99 or dev tun99) and set related options appropriately. ticket #482 Item 2a/2b.
Diffstat (limited to 'etc')
-rw-r--r-- | etc/inc/openvpn.inc | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/etc/inc/openvpn.inc b/etc/inc/openvpn.inc index 72630e7..7840607 100644 --- a/etc/inc/openvpn.inc +++ b/etc/inc/openvpn.inc @@ -278,30 +278,49 @@ function openvpn_reconfigure($mode,& $settings) { $vpnid = $settings['vpnid']; $mode_id = $mode.$vpnid; - if (isset($settings['dev_mode'])) - $tunname = "{$settings['dev_mode']}{$vpnid}"; - else { /* defaults to tun */ - $tunname = "tun{$vpnid}"; - $settings['dev_mode'] = "tun"; + /* Look for device name to override */ + $customdev = ""; + $options = explode(';', $settings['custom_options']); + foreach ($options as $opt) { + if (substr($opt, 0, 4) == "dev ") { + $customdev = substr($opt, 4); + } } - if ($mode == "server") - $devname = "ovpns{$vpnid}"; - else - $devname = "ovpnc{$vpnid}"; + if (empty($customdev)) { + if (isset($settings['dev_mode'])) + $tunname = "{$settings['dev_mode']}{$vpnid}"; + else { /* defaults to tun */ + $tunname = "tun{$vpnid}"; + $settings['dev_mode'] = "tun"; + } + + if ($mode == "server") + $devname = "ovpns{$vpnid}"; + else + $devname = "ovpnc{$vpnid}"; - /* is our device already configured */ - if (mwexec("/sbin/ifconfig {$devname}")) { + /* is our device already configured */ + if (mwexec("/sbin/ifconfig {$devname}")) { - /* create the tap device if required */ - if (!file_exists("/dev/{$tunname}")) - exec("/sbin/ifconfig {$tunname} create"); + /* create the tap device if required */ + if (!file_exists("/dev/{$tunname}")) + exec("/sbin/ifconfig {$tunname} create"); - /* rename the device */ - mwexec("/sbin/ifconfig {$tunname} name {$devname}"); + /* rename the device */ + mwexec("/sbin/ifconfig {$tunname} name {$devname}"); - /* add the device to the openvpn group */ - mwexec("/sbin/ifconfig {$devname} group openvpn"); + /* add the device to the openvpn group */ + mwexec("/sbin/ifconfig {$devname} group openvpn"); + } + $devtype = $settings['dev_mode']; + $conf = "dev {$devname}\n"; + $conf .= "dev-type {$devtype}\n"; + $conf .= "dev-node /dev/{$tunname}\n"; + } else { + $devtype = substr($customdev, 0, 3); + $conf = "dev-type {$devtype}\n"; + $conf .= "dev-node /dev/{$customdev}\n"; } $pfile = $g['varrun_path'] . "/openvpn_{$mode_id}.pid"; @@ -322,9 +341,6 @@ function openvpn_reconfigure($mode,& $settings) { } } - $conf = "dev {$devname}\n"; - $conf .= "dev-type {$settings['dev_mode']}\n"; - $conf .= "dev-node /dev/{$tunname}\n"; $conf .= "writepid {$pfile}\n"; $conf .= "#user nobody\n"; $conf .= "#group nobody\n"; |