[network-manager-openconnect] service: If VPNGATEWAY is an IPv6 address, send it as such



commit da9b5ab84f487707b20fb246da2a518b81b476e6
Author: Dan Winship <danw gnome org>
Date:   Wed May 23 16:33:04 2012 -0400

    service: If VPNGATEWAY is an IPv6 address, send it as such
    
    If we get connected to the VPN via IPv6, pass that IPv6 address to the
    daemon rather than just bailing out with an error.
    
    With old NetworkManager, this will hit a g_return_if_fail(), and
    result in no explicit route to the endpoint being configured, but
    things may work anyway. It's at least not worse than the current
    situation, where it's guaranteed to not work.

 src/nm-openconnect-service-openconnect-helper.c |   24 +++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)
---
diff --git a/src/nm-openconnect-service-openconnect-helper.c b/src/nm-openconnect-service-openconnect-helper.c
index 7f2d01d..be540ec 100644
--- a/src/nm-openconnect-service-openconnect-helper.c
+++ b/src/nm-openconnect-service-openconnect-helper.c
@@ -200,6 +200,28 @@ addr_list_to_gvalue (const char *str)
 }
 
 static GValue *
+addr6_to_gvalue (const char *str)
+{
+	struct in6_addr temp_addr;
+	GValue *val;
+	GByteArray *ba;
+
+	/* Empty */
+	if (!str || strlen (str) < 1)
+		return NULL;
+
+	if (inet_pton (AF_INET6, str, &temp_addr) <= 0)
+		return NULL;
+
+	val = g_slice_new0 (GValue);
+	g_value_init (val, DBUS_TYPE_G_UCHAR_ARRAY);
+	ba = g_byte_array_new ();
+	g_byte_array_append (ba, (guint8 *) &temp_addr, sizeof (temp_addr));
+	g_value_take_boxed (val, ba);
+	return val;
+}
+
+static GValue *
 get_routes (void)
 {
 	GValue *value = NULL;
@@ -318,6 +340,8 @@ main (int argc, char *argv[])
 
 	/* Gateway */
 	val = addr_to_gvalue (getenv ("VPNGATEWAY"));
+	if (!val)
+		val = addr6_to_gvalue (getenv ("VPNGATEWAY"));
 	if (val)
 		g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_GATEWAY, val);
 	else



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]