Commit 44cd7aee authored by Franco Fichtner's avatar Franco Fichtner

openvpn: create devices before running initial configure; closes #980

parent 546a7157
...@@ -382,7 +382,7 @@ function openvpn_add_keyfile(&$data, &$conf, $mode_id, $directive, $opt = '') ...@@ -382,7 +382,7 @@ function openvpn_add_keyfile(&$data, &$conf, $mode_id, $directive, $opt = '')
$conf .= "{$directive} {$fpath} {$opt}\n"; $conf .= "{$directive} {$fpath} {$opt}\n";
} }
function openvpn_reconfigure($mode, $settings) function openvpn_reconfigure($mode, $settings, $device_only = false)
{ {
global $config; global $config;
...@@ -425,6 +425,10 @@ function openvpn_reconfigure($mode, $settings) ...@@ -425,6 +425,10 @@ function openvpn_reconfigure($mode, $settings)
mwexec("/sbin/ifconfig " . escapeshellarg($devname) . " group openvpn"); mwexec("/sbin/ifconfig " . escapeshellarg($devname) . " group openvpn");
} }
if ($device_only) {
return;
}
$proto = strtolower($settings['protocol']); $proto = strtolower($settings['protocol']);
if (substr($settings['protocol'], 0, 3) == "TCP") { if (substr($settings['protocol'], 0, 3) == "TCP") {
$proto = "{$proto}-{$mode}"; $proto = "{$proto}-{$mode}";
...@@ -1005,6 +1009,24 @@ function openvpn_resync_csc() ...@@ -1005,6 +1009,24 @@ function openvpn_resync_csc()
} }
} }
function openvpn_prepare_all()
{
global $config;
if (!isset($config['openvpn'])) {
return;
}
log_error('Creating OpenVPN instances.');
foreach (array('server', 'client') as $mode) {
if (isset($config['openvpn']["openvpn-{$mode}"])) {
foreach ($config['openvpn']["openvpn-{$mode}"] as &$settings) {
openvpn_reconfigure($mode, $settings, true);
}
}
}
}
function openvpn_resync($mode, $settings) function openvpn_resync($mode, $settings)
{ {
...@@ -1012,43 +1034,38 @@ function openvpn_resync($mode, $settings) ...@@ -1012,43 +1034,38 @@ function openvpn_resync($mode, $settings)
openvpn_restart($mode, $settings); openvpn_restart($mode, $settings);
} }
function openvpn_resync_all($interface = '') function openvpn_resync_all($interface = null)
{ {
global $config; global $config;
openvpn_create_dirs(); openvpn_create_dirs();
if (!isset($config['openvpn']) || !is_array($config['openvpn'])) { if (!isset($config['openvpn'])) {
return; return;
} }
if ($interface <> "") { if (!empty($interface)) {
log_error("Resyncing OpenVPN instances for interface " . convert_friendly_interface_to_friendly_descr($interface) . "."); log_error(sprintf(
'Resyncing OpenVPN instances for interface %s.',
convert_friendly_interface_to_friendly_descr($interface)
));
} else { } else {
log_error("Resyncing OpenVPN instances."); log_error('Resyncing OpenVPN instances.');
} }
if (is_array($config['openvpn']['openvpn-server'])) { foreach (array('server', 'client') as $mode) {
foreach ($config['openvpn']['openvpn-server'] as & $settings) { if (isset($config['openvpn']["openvpn-{$mode}"])) {
if ($interface <> "" && $interface != $settings['interface']) { foreach ($config['openvpn']["openvpn-{$mode}"] as &$settings) {
continue; if (empty($interface) || $interface == $settings['interface']) {
openvpn_resync($mode, $settings);
}
} }
openvpn_resync('server', $settings);
} }
} }
if (is_array($config['openvpn']['openvpn-client'])) {
foreach ($config['openvpn']['openvpn-client'] as & $settings) {
if ($interface <> "" && $interface != $settings['interface']) {
continue;
}
openvpn_resync('client', $settings);
}
}
openvpn_resync_csc(); openvpn_resync_csc();
} }
function openvpn_get_active_servers($type = 'multipoint') function openvpn_get_active_servers($type = 'multipoint')
{ {
global $config; global $config;
......
...@@ -232,6 +232,7 @@ echo "done.\n"; ...@@ -232,6 +232,7 @@ echo "done.\n";
/* set up interfaces */ /* set up interfaces */
mute_kernel_msgs(); mute_kernel_msgs();
openvpn_prepare_all();
interfaces_configure(); interfaces_configure();
unmute_kernel_msgs(); unmute_kernel_msgs();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment