about summary refs log tree commit diff
path: root/src/vpn-manager
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2011-10-28 23:04:16 +0200
committerMichael Biebl <biebl@debian.org>2011-10-28 23:04:16 +0200
commit485d149fe80915d94ed49ea6c2c0552cf7a3e79a (patch)
tree6a48492b46b8c1e3df1c58626c28f05a978c61f7 /src/vpn-manager
parent263bf4c0c89bb88dc995acd9a6a2de9095fbd461 (diff)
Imported Upstream version 0.9.1.95 upstream/0.9.1.95
Diffstat (limited to 'src/vpn-manager')
-rw-r--r--src/vpn-manager/Makefile.in8
-rw-r--r--src/vpn-manager/nm-vpn-connection-base.c16
-rw-r--r--src/vpn-manager/nm-vpn-connection-base.h5
-rw-r--r--src/vpn-manager/nm-vpn-connection.c62
-rw-r--r--src/vpn-manager/nm-vpn-connection.h3
-rw-r--r--src/vpn-manager/nm-vpn-manager.c24
-rw-r--r--src/vpn-manager/nm-vpn-manager.h8
-rw-r--r--src/vpn-manager/nm-vpn-service.c5
-rw-r--r--src/vpn-manager/nm-vpn-service.h3
9 files changed, 109 insertions, 25 deletions
diff --git a/src/vpn-manager/Makefile.in b/src/vpn-manager/Makefile.in
index 3785667e..8999e831 100644
--- a/src/vpn-manager/Makefile.in
+++ b/src/vpn-manager/Makefile.in
@@ -190,8 +190,16 @@ LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@
 LIBICONV = @LIBICONV@
 LIBINTL = @LIBINTL@
 LIBM = @LIBM@
+LIBNL1_CFLAGS = @LIBNL1_CFLAGS@
+LIBNL1_LIBS = @LIBNL1_LIBS@
+LIBNL2_CFLAGS = @LIBNL2_CFLAGS@
+LIBNL2_LIBS = @LIBNL2_LIBS@
+LIBNL3_CFLAGS = @LIBNL3_CFLAGS@
+LIBNL3_LIBS = @LIBNL3_LIBS@
 LIBNL_CFLAGS = @LIBNL_CFLAGS@
 LIBNL_LIBS = @LIBNL_LIBS@
+LIBNL_ROUTE3_CFLAGS = @LIBNL_ROUTE3_CFLAGS@
+LIBNL_ROUTE3_LIBS = @LIBNL_ROUTE3_LIBS@
 LIBOBJS = @LIBOBJS@
 LIBS = @LIBS@
 LIBTOOL = @LIBTOOL@
diff --git a/src/vpn-manager/nm-vpn-connection-base.c b/src/vpn-manager/nm-vpn-connection-base.c
index c7373627..bc2cffb2 100644
--- a/src/vpn-manager/nm-vpn-connection-base.c
+++ b/src/vpn-manager/nm-vpn-connection-base.c
@@ -36,6 +36,7 @@ typedef struct {
 
 	NMConnection *connection;
 	char *ac_path;
+	char *specific_object;
 	gboolean is_default;
 	gboolean is_default6;
 	NMActiveConnectionState state;
@@ -91,9 +92,16 @@ nm_vpn_connection_base_get_ac_path (NMVpnConnectionBase *self)
 	return NM_VPN_CONNECTION_BASE_GET_PRIVATE (self)->ac_path;
 }
 
+const char *
+nm_vpn_connection_base_get_specific_object (NMVpnConnectionBase *self)
+{
+	return NM_VPN_CONNECTION_BASE_GET_PRIVATE (self)->specific_object;
+}
+
 void
 nm_vpn_connection_base_export (NMVpnConnectionBase *self,
-                               NMConnection *connection)
+                               NMConnection *connection,
+                               const char *specific_object)
 {
 	NMVpnConnectionBasePrivate *priv = NM_VPN_CONNECTION_BASE_GET_PRIVATE (self);
 	NMDBusManager *dbus_mgr;
@@ -101,6 +109,7 @@ nm_vpn_connection_base_export (NMVpnConnectionBase *self,
 	g_return_if_fail (priv->connection == NULL);
 
 	priv->connection = g_object_ref (connection);
+	priv->specific_object = g_strdup (specific_object);
 
 	dbus_mgr = nm_dbus_manager_get ();
 	dbus_g_connection_register_g_object (nm_dbus_manager_get_connection (dbus_mgr),
@@ -128,6 +137,7 @@ dispose (GObject *object)
 		priv->disposed = TRUE;
 
 		g_free (priv->ac_path);
+		g_free (priv->specific_object);
 		g_object_unref (priv->connection);
 	}
 
@@ -145,10 +155,10 @@ get_property (GObject *object, guint prop_id,
 		g_value_set_boxed (value, nm_connection_get_path (priv->connection));
 		break;
 	case PROP_UUID:
-		g_value_set_boxed (value, nm_connection_get_uuid (priv->connection));
+		g_value_set_string (value, nm_connection_get_uuid (priv->connection));
 		break;
 	case PROP_SPECIFIC_OBJECT:
-		g_value_set_boxed (value, priv->ac_path);
+		g_value_set_boxed (value, priv->specific_object);
 		break;
 	case PROP_DEVICES:
 		g_value_take_boxed (value, g_ptr_array_new ());
diff --git a/src/vpn-manager/nm-vpn-connection-base.h b/src/vpn-manager/nm-vpn-connection-base.h
index 0c17d9e8..6f19e7c5 100644
--- a/src/vpn-manager/nm-vpn-connection-base.h
+++ b/src/vpn-manager/nm-vpn-connection-base.h
@@ -44,8 +44,11 @@ GType nm_vpn_connection_base_get_type (void);
 
 const char *nm_vpn_connection_base_get_ac_path (NMVpnConnectionBase *self);
 
+const char *nm_vpn_connection_base_get_specific_object (NMVpnConnectionBase *self);
+
 void nm_vpn_connection_base_export (NMVpnConnectionBase *self,
-                                    NMConnection *connection);
+                                    NMConnection *connection,
+                                    const char *specific_object);
 
 void nm_vpn_connection_base_set_state (NMVpnConnectionBase *self,
                                        NMVPNConnectionState vpn_state);
diff --git a/src/vpn-manager/nm-vpn-connection.c b/src/vpn-manager/nm-vpn-connection.c
index 067b2dce..73f2b553 100644
--- a/src/vpn-manager/nm-vpn-connection.c
+++ b/src/vpn-manager/nm-vpn-connection.c
@@ -46,6 +46,7 @@
 #include "NetworkManagerUtils.h"
 #include "nm-dns-manager.h"
 #include "nm-netlink-monitor.h"
+#include "nm-netlink-utils.h"
 #include "nm-glib-compat.h"
 #include "settings/nm-settings-connection.h"
 
@@ -86,6 +87,7 @@ typedef struct {
 	NMIP4Config *ip4_config;
 	guint32 ip4_internal_gw;
 	char *ip_iface;
+	int ip_ifindex;
 	char *banner;
 
 	struct rtnl_route *gw_route;
@@ -219,6 +221,7 @@ device_ip4_config_changed (NMDevice *device,
 NMVPNConnection *
 nm_vpn_connection_new (NMConnection *connection,
                        NMDevice *parent_device,
+                       const char *specific_object,
                        gboolean user_requested,
                        gulong user_uid)
 {
@@ -247,7 +250,7 @@ nm_vpn_connection_new (NMConnection *connection,
 	                                     G_CALLBACK (device_ip4_config_changed),
 	                                     self);
 
-	nm_vpn_connection_base_export (NM_VPN_CONNECTION_BASE (self), connection);
+	nm_vpn_connection_base_export (NM_VPN_CONNECTION_BASE (self), connection, specific_object);
 
 	return self;
 }
@@ -283,6 +286,28 @@ plugin_failed (DBusGProxy *proxy,
 	}
 }
 
+static const char *
+vpn_state_to_string (NMVPNServiceState state)
+{
+	switch (state) {
+	case NM_VPN_SERVICE_STATE_INIT:
+		return "init";
+	case NM_VPN_SERVICE_STATE_SHUTDOWN:
+		return "shutdown";
+	case NM_VPN_SERVICE_STATE_STARTING:
+		return "starting";
+	case NM_VPN_SERVICE_STATE_STARTED:
+		return "started";
+	case NM_VPN_SERVICE_STATE_STOPPING:
+		return "stopping";
+	case NM_VPN_SERVICE_STATE_STOPPED:
+		return "stopped";
+	default:
+		break;
+	}
+	return "unknown";
+}
+
 static void
 plugin_state_changed (DBusGProxy *proxy,
                       NMVPNServiceState state,
@@ -291,7 +316,8 @@ plugin_state_changed (DBusGProxy *proxy,
 	NMVPNConnection *connection = NM_VPN_CONNECTION (user_data);
 	NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection);
 
-	nm_log_info (LOGD_VPN, "VPN plugin state changed: %d", state);
+	nm_log_info (LOGD_VPN, "VPN plugin state changed: %s (%d)",
+	             vpn_state_to_string (state), state);
 
 	if (state == NM_VPN_SERVICE_STATE_STOPPED) {
 		/* Clear connection secrets to ensure secrets get requested each time the
@@ -424,6 +450,13 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy,
 		goto error;
 	}
 
+	/* Grab the interface index for address/routing operations */
+	priv->ip_ifindex = nm_netlink_iface_to_index (priv->ip_iface);
+	if (!priv->ip_ifindex) {
+		nm_log_err (LOGD_VPN, "(%s): failed to look up VPN interface index", priv->ip_iface);
+		goto error;
+	}
+
 	addr = nm_ip4_address_new ();
 	nm_ip4_address_set_prefix (addr, 24); /* default to class C */
 
@@ -529,9 +562,9 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy,
 	s_ip4 = NM_SETTING_IP4_CONFIG (nm_connection_get_setting (priv->connection, NM_TYPE_SETTING_IP4_CONFIG));
 	nm_utils_merge_ip4_config (config, s_ip4);
 
-	nm_system_device_set_up_down_with_iface (priv->ip_iface, TRUE, NULL);
+	nm_system_iface_set_up (priv->ip_ifindex, TRUE, NULL);
 
-	if (nm_system_apply_ip4_config (priv->ip_iface, config, 0, NM_IP4_COMPARE_FLAG_ALL)) {
+	if (nm_system_apply_ip4_config (priv->ip_ifindex, config, 0, NM_IP4_COMPARE_FLAG_ALL)) {
 		NMDnsManager *dns_mgr;
 
 		/* Add any explicit route to the VPN gateway through the parent device */
@@ -765,6 +798,14 @@ nm_vpn_connection_get_ip_iface (NMVPNConnection *connection)
 	return NM_VPN_CONNECTION_GET_PRIVATE (connection)->ip_iface;
 }
 
+int
+nm_vpn_connection_get_ip_ifindex (NMVPNConnection *connection)
+{
+	g_return_val_if_fail (NM_IS_VPN_CONNECTION (connection), -1);
+
+	return NM_VPN_CONNECTION_GET_PRIVATE (connection)->ip_ifindex;
+}
+
 NMDevice *
 nm_vpn_connection_get_parent_device (NMVPNConnection *connection)
 {
@@ -940,11 +981,11 @@ vpn_cleanup (NMVPNConnection *connection)
 {
 	NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection);
 
-	if (priv->ip_iface) {
-		nm_system_device_set_up_down_with_iface (priv->ip_iface, FALSE, NULL);
+	if (priv->ip_ifindex) {
+		nm_system_iface_set_up (priv->ip_ifindex, FALSE, NULL);
 		/* FIXME: use AF_UNSPEC here when we have IPv6 support */
-		nm_system_device_flush_routes_with_iface (priv->ip_iface, AF_INET);
-		nm_system_device_flush_addresses_with_iface (priv->ip_iface);
+		nm_system_iface_flush_routes (priv->ip_ifindex, AF_INET);
+		nm_system_iface_flush_addresses (priv->ip_ifindex, AF_UNSPEC);
 	}
 
 	if (priv->ip4_config) {
@@ -958,12 +999,12 @@ vpn_cleanup (NMVPNConnection *connection)
 
 		/* Remove any previously added VPN gateway host route */
 		if (priv->gw_route)
-			rtnl_route_del (nm_netlink_get_default_handle (), priv->gw_route, 0);
+			nm_netlink_route_delete (priv->gw_route);
 
 		/* Reset routes and addresses of the currently active device */
 		parent_config = nm_device_get_ip4_config (priv->parent_dev);
 		if (parent_config) {
-			if (!nm_system_apply_ip4_config (nm_device_get_ip_iface (priv->parent_dev),
+			if (!nm_system_apply_ip4_config (nm_device_get_ip_ifindex (priv->parent_dev),
 			                                 nm_device_get_ip4_config (priv->parent_dev),
 			                                 nm_device_get_priority (priv->parent_dev),
 			                                 NM_IP4_COMPARE_FLAG_ADDRESSES | NM_IP4_COMPARE_FLAG_ROUTES)) {
@@ -982,6 +1023,7 @@ vpn_cleanup (NMVPNConnection *connection)
 
 	g_free (priv->ip_iface);
 	priv->ip_iface = NULL;
+	priv->ip_ifindex = 0;
 
 	/* Clear out connection secrets to ensure that the settings service
 	 * gets asked for them next time the connection is activated.
diff --git a/src/vpn-manager/nm-vpn-connection.h b/src/vpn-manager/nm-vpn-connection.h
index ee8eb5b6..c0d15f8a 100644
--- a/src/vpn-manager/nm-vpn-connection.h
+++ b/src/vpn-manager/nm-vpn-connection.h
@@ -57,12 +57,14 @@ GType nm_vpn_connection_get_type (void);
 
 NMVPNConnection * nm_vpn_connection_new (NMConnection *connection,
                                          NMDevice *parent_device,
+                                         const char *specific_object,
                                          gboolean user_requested,
                                          gulong user_uid);
 
 void                 nm_vpn_connection_activate        (NMVPNConnection *connection);
 NMConnection *       nm_vpn_connection_get_connection  (NMVPNConnection *connection);
 const char *         nm_vpn_connection_get_active_connection_path (NMVPNConnection *connection);
+const char *         nm_vpn_connection_get_specific_object_path (NMVPNConnection *connection);
 const char *         nm_vpn_connection_get_name        (NMVPNConnection *connection);
 NMVPNConnectionState nm_vpn_connection_get_vpn_state   (NMVPNConnection *connection);
 const char *         nm_vpn_connection_get_banner      (NMVPNConnection *connection);
@@ -72,6 +74,7 @@ void                 nm_vpn_connection_disconnect      (NMVPNConnection *connect
                                                         NMVPNConnectionStateReason reason);
 NMIP4Config *        nm_vpn_connection_get_ip4_config  (NMVPNConnection *connection);
 const char *         nm_vpn_connection_get_ip_iface    (NMVPNConnection *connection);
+int                  nm_vpn_connection_get_ip_ifindex  (NMVPNConnection *connection);
 NMDevice *           nm_vpn_connection_get_parent_device (NMVPNConnection *connection);
 guint32              nm_vpn_connection_get_ip4_internal_gateway (NMVPNConnection *connection);
 
diff --git a/src/vpn-manager/nm-vpn-manager.c b/src/vpn-manager/nm-vpn-manager.c
index 6772bb18..41e96c0b 100644
--- a/src/vpn-manager/nm-vpn-manager.c
+++ b/src/vpn-manager/nm-vpn-manager.c
@@ -15,7 +15,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * Copyright (C) 2005 - 2010 Red Hat, Inc.
+ * Copyright (C) 2005 - 2011 Red Hat, Inc.
  * Copyright (C) 2006 - 2008 Novell, Inc.
  */
 
@@ -162,6 +162,7 @@ NMVPNConnection *
 nm_vpn_manager_activate_connection (NMVPNManager *manager,
                                     NMConnection *connection,
                                     NMDevice *device,
+                                    const char *specific_object,
                                     gboolean user_requested,
                                     gulong user_uid,
                                     GError **error)
@@ -209,7 +210,7 @@ nm_vpn_manager_activate_connection (NMVPNManager *manager,
 		return NULL;
 	}
 
-	vpn = nm_vpn_service_activate (service, connection, device, user_requested, user_uid, error);
+	vpn = nm_vpn_service_activate (service, connection, device, specific_object, user_requested, user_uid, error);
 	if (vpn) {
 		g_signal_connect (vpn, "vpn-state-changed",
 		                  G_CALLBACK (connection_vpn_state_changed),
@@ -306,9 +307,9 @@ nm_vpn_manager_get_active_connections (NMVPNManager *self)
 	return list;
 }
 
-NMConnection *
-nm_vpn_manager_get_connection_for_active (NMVPNManager *manager,
-                                          const char *active_path)
+NMVPNConnection *
+nm_vpn_manager_get_vpn_connection_for_active (NMVPNManager *manager,
+                                              const char *active_path)
 {
 	NMVPNManagerPrivate *priv;
 	GHashTableIter iter;
@@ -327,13 +328,24 @@ nm_vpn_manager_get_connection_for_active (NMVPNManager *manager,
 
 			ac_path = nm_vpn_connection_get_active_connection_path (vpn);
 			if (ac_path && !strcmp (ac_path, active_path))
-				return nm_vpn_connection_get_connection (vpn);
+				return vpn;
 		}
 	}
 
 	return NULL;
 }
 
+NMConnection *
+nm_vpn_manager_get_connection_for_active (NMVPNManager *manager,
+                                          const char *active_path)
+{
+	NMVPNConnection *vpn_con;
+
+	vpn_con = nm_vpn_manager_get_vpn_connection_for_active (manager, active_path);
+
+	return vpn_con ? nm_vpn_connection_get_connection (vpn_con) : NULL;
+}
+
 static char *
 service_name_from_file (const char *path)
 {
diff --git a/src/vpn-manager/nm-vpn-manager.h b/src/vpn-manager/nm-vpn-manager.h
index a899122c..78a5220b 100644
--- a/src/vpn-manager/nm-vpn-manager.h
+++ b/src/vpn-manager/nm-vpn-manager.h
@@ -15,7 +15,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * Copyright (C) 2005 - 2008 Red Hat, Inc.
+ * Copyright (C) 2005 - 2011 Red Hat, Inc.
  * Copyright (C) 2006 - 2008 Novell, Inc.
  */
 
@@ -69,6 +69,7 @@ NMVPNManager *nm_vpn_manager_get (void);
 NMVPNConnection *nm_vpn_manager_activate_connection (NMVPNManager *manager,
                                                      NMConnection *connection,
                                                      NMDevice *device,
+                                                     const char *specific_object,
                                                      gboolean user_requested,
                                                      gulong user_uid,
                                                      GError **error);
@@ -83,7 +84,10 @@ void nm_vpn_manager_add_active_connections (NMVPNManager *manager,
 
 GSList *nm_vpn_manager_get_active_connections (NMVPNManager *manager);
 
+NMVPNConnection *nm_vpn_manager_get_vpn_connection_for_active (NMVPNManager *manager,
+                                                               const char *active_path);
+
 NMConnection *nm_vpn_manager_get_connection_for_active (NMVPNManager *manager,
                                                         const char *active_path);
 
-#endif /* NM_VPN_VPN_MANAGER_H */
+#endif /* NM_VPN_MANAGER_H */
diff --git a/src/vpn-manager/nm-vpn-service.c b/src/vpn-manager/nm-vpn-service.c
index ed08a40a..95e4f2b1 100644
--- a/src/vpn-manager/nm-vpn-service.c
+++ b/src/vpn-manager/nm-vpn-service.c
@@ -15,7 +15,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * Copyright (C) 2005 - 2010 Red Hat, Inc.
+ * Copyright (C) 2005 - 2011 Red Hat, Inc.
  * Copyright (C) 2005 - 2008 Novell, Inc.
  */
 
@@ -324,6 +324,7 @@ NMVPNConnection *
 nm_vpn_service_activate (NMVPNService *service,
                          NMConnection *connection,
                          NMDevice *device,
+                         const char *specific_object,
                          gboolean user_requested,
                          gulong user_uid,
                          GError **error)
@@ -341,7 +342,7 @@ nm_vpn_service_activate (NMVPNService *service,
 
 	clear_quit_timeout (service);
 
-	vpn = nm_vpn_connection_new (connection, device, user_requested, user_uid);
+	vpn = nm_vpn_connection_new (connection, device, specific_object, user_requested, user_uid);
 	g_signal_connect (vpn, "vpn-state-changed",
 				   G_CALLBACK (connection_vpn_state_changed),
 				   service);
diff --git a/src/vpn-manager/nm-vpn-service.h b/src/vpn-manager/nm-vpn-service.h
index cbe394ca..e8b1cfc4 100644
--- a/src/vpn-manager/nm-vpn-service.h
+++ b/src/vpn-manager/nm-vpn-service.h
@@ -15,7 +15,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * Copyright (C) 2005 - 2008 Red Hat, Inc.
+ * Copyright (C) 2005 - 2011 Red Hat, Inc.
  * Copyright (C) 2005 - 2008 Novell, Inc.
  */
 
@@ -57,6 +57,7 @@ const char *nm_vpn_service_get_name_file (NMVPNService *service);
 NMVPNConnection * nm_vpn_service_activate (NMVPNService *service,
                                            NMConnection *connection,
                                            NMDevice *device,
+                                           const char *specific_object,
                                            gboolean user_requested,
                                            gulong user_uid,
                                            GError **error);