2007-09-26 Tambet Ingo <tambet@gmail.com>

* libnm-glib/nm-vpn-plugin.c (nm_vpn_plugin_connect): Update the
        * plugin activation
        method.
        (impl_vpn_plugin_connect): Convert properties hash to
NMConnection, activate, and
        unreference the connection.

        * introspection/nm-vpn-plugin.xml: Modify the 'Connect' method
        * arguments: instead of
        passing properties hash and routes string list, pass
NMConnection (in hashed form).

        * src/vpn-manager/nm-vpn-connection.c
        * (nm_vpn_connection_get_routes): Return routes
        as GSList, no need to copy stuff around anymore.
        (nm_vpn_connection_activate): Update the plugin activation
method.

        * src/NetworkManagerSystem.c
        * (nm_system_vpn_device_set_from_ip4_config): Convert
        routes argument to GSList.

        * vpn-daemons/vpnc/src/nm-vpnc-service.c (real_connect):
        The arguments have changed, update.



git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2890 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Tambet Ingo 2007-09-26 15:42:09 +00:00
parent 95e0ef0922
commit 571812b40c
9 changed files with 53 additions and 63 deletions

View file

@ -1,3 +1,20 @@
2007-09-26 Tambet Ingo <tambet@gmail.com>
* libnm-glib/nm-vpn-plugin.c (nm_vpn_plugin_connect): Update the plugin activation
method.
(impl_vpn_plugin_connect): Convert properties hash to NMConnection, activate, and
unreference the connection.
* introspection/nm-vpn-plugin.xml: Modify the 'Connect' method arguments: instead of
passing properties hash and routes string list, pass NMConnection (in hashed form).
* src/vpn-manager/nm-vpn-connection.c (nm_vpn_connection_get_routes): Return routes
as GSList, no need to copy stuff around anymore.
(nm_vpn_connection_activate): Update the plugin activation method.
* src/NetworkManagerSystem.c (nm_system_vpn_device_set_from_ip4_config): Convert
routes argument to GSList.
2007-09-26 Tambet Ingo <tambet@gmail.com>
* src/nm-manager.c (manager_device_state_changed): Listen to device' NEED_AUTH

View file

@ -4,8 +4,7 @@
<interface name="org.freedesktop.NetworkManager.VPN.Plugin">
<method name="Connect">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_vpn_plugin_connect"/>
<arg name="connection" type="a{sv}" direction="in"/>
<arg name="routes" type="as" direction="in"/>
<arg name="connection" type="a{sa{sv}}" direction="in"/>
</method>
<method name="Disconnect">

View file

@ -6,7 +6,6 @@
static gboolean impl_vpn_plugin_connect (NMVPNPlugin *plugin,
GHashTable *connection,
char **routes,
GError **err);
static gboolean impl_vpn_plugin_disconnect (NMVPNPlugin *plugin,
@ -247,8 +246,7 @@ quit_timer_expired (gpointer data)
static gboolean
nm_vpn_plugin_connect (NMVPNPlugin *plugin,
GHashTable *properties,
char **routes,
NMConnection *connection,
GError **err)
{
gboolean ret = FALSE;
@ -282,7 +280,7 @@ nm_vpn_plugin_connect (NMVPNPlugin *plugin,
case NM_VPN_SERVICE_STATE_STOPPED:
case NM_VPN_SERVICE_STATE_INIT:
nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_STARTING);
ret = NM_VPN_PLUGIN_GET_CLASS (plugin)->connect (plugin, properties, routes, err);
ret = NM_VPN_PLUGIN_GET_CLASS (plugin)->connect (plugin, connection, err);
if (!ret)
nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_STOPPED);
break;
@ -311,10 +309,16 @@ nm_vpn_plugin_set_ip4_config (NMVPNPlugin *plugin,
static gboolean
impl_vpn_plugin_connect (NMVPNPlugin *plugin,
GHashTable *properties,
char **routes,
GError **err)
{
return nm_vpn_plugin_connect (plugin, properties, routes, err);
NMConnection *connection;
gboolean success;
connection = nm_connection_new_from_hash (properties);
success = nm_vpn_plugin_connect (plugin, connection, err);
g_object_unref (connection);
return success;
}
static gboolean

View file

@ -7,6 +7,7 @@
#include <glib-object.h>
#include <dbus/dbus-glib.h>
#include <NetworkManagerVPN.h>
#include <nm-connection.h>
G_BEGIN_DECLS
@ -49,8 +50,7 @@ typedef struct {
/* virtual methods */
gboolean (*connect) (NMVPNPlugin *plugin,
GHashTable *properties,
char **routes,
NMConnection *connection,
GError **err);
gboolean (*disconnect) (NMVPNPlugin *plugin,

View file

@ -314,13 +314,12 @@ gboolean
nm_system_vpn_device_set_from_ip4_config (NMDevice *active_device,
const char *iface,
NMIP4Config *config,
char **routes)
GSList *routes)
{
NMIP4Config * ad_config = NULL;
struct nl_handle * nlh = NULL;
struct rtnl_addr * addr = NULL;
struct rtnl_link * request = NULL;
int num_routes;
NMNamedManager *named_mgr;
g_return_val_if_fail (config != NULL, FALSE);
@ -371,20 +370,18 @@ nm_system_vpn_device_set_from_ip4_config (NMDevice *active_device,
sleep (1);
num_routes = g_strv_length (routes);
nm_system_device_flush_routes_with_iface (iface);
if (num_routes <= 0)
if (g_slist_length (routes) == 0)
{
nm_system_delete_default_route ();
nm_system_device_add_default_route_via_device_with_iface (iface);
}
else
{
int i;
for (i = 0; i < num_routes; i++)
{
GSList *iter;
for (iter = routes; iter; iter = iter->next) {
char *valid_ip4_route;
/* Make sure the route is valid, otherwise it's a security risk as the route
@ -395,7 +392,7 @@ nm_system_vpn_device_set_from_ip4_config (NMDevice *active_device,
*
* where `rm -rf /` was the route text. As UID 0 (root), we have to be careful.
*/
if ((valid_ip4_route = validate_ip4_route (routes[i])))
if ((valid_ip4_route = validate_ip4_route ((char *) iter->data)))
{
nm_system_device_add_route_via_device_with_iface (iface, valid_ip4_route);
g_free (valid_ip4_route);

View file

@ -65,7 +65,7 @@ gboolean nm_system_device_set_from_ip4_config (NMDevice *dev);
gboolean nm_system_vpn_device_set_from_ip4_config (NMDevice *active_device,
const char *iface,
NMIP4Config *config,
char **routes);
GSList *routes);
gboolean nm_system_vpn_device_unset_from_ip4_config (NMDevice *active_device,
const char *iface,

View file

@ -133,36 +133,15 @@ nm_vpn_connection_get_service (NMVPNConnection *connection)
return setting->service_type;
}
static char **
static GSList *
nm_vpn_connection_get_routes (NMVPNConnection *connection)
{
NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection);
NMSettingVPN *setting;
char **routes;
int i;
GSList *iter;
setting = (NMSettingVPN *) nm_connection_get_setting (priv->connection, NM_SETTING_VPN);
setting = (NMSettingVPN *) nm_connection_get_setting (NM_VPN_CONNECTION_GET_PRIVATE (connection)->connection,
NM_SETTING_VPN);
routes = g_new (gchar*, g_slist_length (setting->routes) + 1);
i = 0;
for (iter = setting->routes; iter; iter = iter->next)
routes[i++] = g_strdup (iter->data);
routes[i] = NULL;
return routes;
}
static GHashTable *
nm_vpn_connection_get_vpn_data (NMVPNConnection *connection)
{
NMVPNConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection);
NMSettingVPNProperties *setting;
setting = (NMSettingVPNProperties *) nm_connection_get_setting (priv->connection, NM_SETTING_VPN_PROPERTIES);
return setting->data;
return setting->routes;
}
static void
@ -238,7 +217,6 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy,
NMIP4Config *config;
GValue *val;
const char *banner = NULL;
char **routes;
int i;
nm_info ("VPN connection '%s' (IP Config Get) reply received.",
@ -310,9 +288,8 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy,
priv = NM_VPN_CONNECTION_GET_PRIVATE (connection);
priv->ip4_config = config;
routes = nm_vpn_connection_get_routes (connection);
if (nm_system_vpn_device_set_from_ip4_config (priv->parent_dev, priv->tundev, priv->ip4_config, routes)) {
if (nm_system_vpn_device_set_from_ip4_config (priv->parent_dev, priv->tundev, priv->ip4_config,
nm_vpn_connection_get_routes (connection))) {
nm_info ("VPN connection '%s' (IP Config Get) complete.",
nm_vpn_connection_get_name (connection));
nm_vpn_connection_set_state (connection, NM_VPN_CONNECTION_STATE_ACTIVATED);
@ -321,9 +298,6 @@ nm_vpn_connection_ip4_config_get (DBusGProxy *proxy,
nm_vpn_connection_get_name (connection));
nm_vpn_connection_set_state (connection, NM_VPN_CONNECTION_STATE_FAILED);
}
if (routes)
g_strfreev (routes);
}
static gboolean
@ -373,7 +347,6 @@ nm_vpn_connection_activate (NMVPNConnection *connection)
{
NMVPNConnectionPrivate *priv;
NMDBusManager *dbus_mgr;
char **routes;
g_return_if_fail (NM_IS_VPN_CONNECTION (connection));
g_return_if_fail (nm_vpn_connection_get_state (connection) == NM_VPN_CONNECTION_STATE_PREPARE);
@ -403,16 +376,11 @@ nm_vpn_connection_activate (NMVPNConnection *connection)
G_CALLBACK (nm_vpn_connection_ip4_config_get),
connection, NULL);
routes = nm_vpn_connection_get_routes (connection);
org_freedesktop_NetworkManager_VPN_Plugin_connect_async (priv->proxy,
nm_vpn_connection_get_vpn_data (connection),
(const char**)routes,
nm_connection_to_hash (priv->connection),
nm_vpn_connection_connect_cb,
connection);
if (routes)
g_strfreev (routes);
nm_vpn_connection_set_state (connection, NM_VPN_CONNECTION_STATE_CONNECT);
}

View file

@ -1,3 +1,7 @@
2007-09-26 Tambet Ingo <tambet@gmail.com>
* src/nm-vpnc-service.c (real_connect): The arguments have changed, update.
2007-09-12 Tambet Ingo <tambet@gmail.com>
* src/nm-vpnc-service.[ch]: Rewrite. Derive from NMVPNPlugin.

View file

@ -240,13 +240,14 @@ nm_vpnc_config_write (gint vpnc_fd, GHashTable *properties)
static gboolean
real_connect (NMVPNPlugin *plugin,
GHashTable *properties,
char **routes,
NMConnection *connection,
GError **err)
{
NMSettingVPNProperties *properties;
gint vpnc_fd;
if (!nm_vpnc_properties_validate (properties)) {
properties = (NMSettingVPNProperties *) nm_connection_get_setting (connection, NM_SETTING_VPN_PROPERTIES);
if (!properties || !nm_vpnc_properties_validate (properties->data)) {
g_set_error (err,
NM_VPN_PLUGIN_ERROR,
NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
@ -256,7 +257,7 @@ real_connect (NMVPNPlugin *plugin,
}
if ((vpnc_fd = nm_vpnc_start_vpnc_binary (NM_VPNC_PLUGIN (plugin))) >= 0)
nm_vpnc_config_write (vpnc_fd, properties);
nm_vpnc_config_write (vpnc_fd, properties->data);
else {
g_set_error (err,
NM_VPN_PLUGIN_ERROR,