[network-manager-openvpn/dcbw/openvpn-restart: 2/5] core: fix protocol and port specified with remote address
- From: Dan Williams <dcbw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-openvpn/dcbw/openvpn-restart: 2/5] core: fix protocol and port specified with remote address
- Date: Mon, 27 Oct 2014 18:21:01 +0000 (UTC)
commit 0718413438e4db504383c9ee13c3c6377162d504
Author: Dan Williams <dcbw redhat com>
Date: Fri Oct 10 09:31:43 2014 -0500
core: fix protocol and port specified with remote address
If the port and protocol were specified in the remote address
option (eg, "host[:port[:proto]]") nm-openvpn-service still
added explicit --proto and --port options later, which confused
openvpn.
Let the port/proto of the 'remote' take precedence, and fallback
to using the separately configured port or protocol options if
the 'remote' didn't specify any.
src/nm-openvpn-service.c | 53 +++++++++++++++++++++------------------------
1 files changed, 25 insertions(+), 28 deletions(-)
---
diff --git a/src/nm-openvpn-service.c b/src/nm-openvpn-service.c
index 57d5684..4af69cb 100644
--- a/src/nm-openvpn-service.c
+++ b/src/nm-openvpn-service.c
@@ -867,6 +867,7 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
GPid pid;
gboolean dev_type_is_tap;
char *stmp;
+ const char *defport, *proto_tcp;
/* Find openvpn */
openvpn_binary = nm_find_openvpn ();
@@ -904,6 +905,14 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
args = g_ptr_array_new ();
add_openvpn_arg (args, openvpn_binary);
+ defport = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_PORT);
+ if (defport && !defport[0])
+ defport = NULL;
+
+ proto_tcp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_PROTO_TCP);
+ if (proto_tcp && !proto_tcp[0])
+ proto_tcp = NULL;
+
tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_REMOTE);
if (tmp && *tmp) {
char *tok, *port, *proto;
@@ -929,8 +938,19 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
g_free (tmp_dup);
return FALSE;
}
+ } else if (defport) {
+ if (!add_openvpn_arg_int (args, defport)) {
+ g_set_error (error,
+ NM_VPN_PLUGIN_ERROR,
+ NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
+ _("Invalid port number '%s'."),
+ defport);
+ free_openvpn_args (args);
+ return FALSE;
+ }
} else
- add_openvpn_arg (args, "1194"); /* use default IANA port */
+ add_openvpn_arg (args, "1194"); /* default IANA port */
+
if (proto) {
if (!strcmp (proto, "udp") || !strcmp (proto, "tcp"))
add_openvpn_arg (args, proto);
@@ -943,7 +963,10 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
g_free (tmp_dup);
return FALSE;
}
- }
+ } else if (proto_tcp && !strcmp (proto_tcp, "yes"))
+ add_openvpn_arg (args, "tcp");
+ else
+ add_openvpn_arg (args, "udp");
}
}
g_free (tmp_dup);
@@ -1014,32 +1037,6 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
dev_type_is_tap = (g_strcmp0 (tmp2, "tap") == 0);
}
- /* Protocol, either tcp or udp */
- add_openvpn_arg (args, "--proto");
- tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_PROTO_TCP);
- if (tmp && !strcmp (tmp, "yes"))
- add_openvpn_arg (args, "tcp-client");
- else
- add_openvpn_arg (args, "udp");
-
- /* Port */
- add_openvpn_arg (args, "--port");
- tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_PORT);
- if (tmp && strlen (tmp)) {
- if (!add_openvpn_arg_int (args, tmp)) {
- g_set_error (error,
- NM_VPN_PLUGIN_ERROR,
- NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
- _("Invalid port number '%s'."),
- tmp);
- free_openvpn_args (args);
- return FALSE;
- }
- } else {
- /* Default to IANA assigned port 1194 */
- add_openvpn_arg (args, "1194");
- }
-
/* Cipher */
tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_CIPHER);
if (tmp && strlen (tmp)) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]