Re: Change the state of iface from disconnected to connected using nmcli



On Mon, 2012-05-14 at 17:36 +0200, Jirka Klimes wrote:
> On Thursday 22 of March 2012 11:10:56 Dan Williams wrote:
> > On Sun, 2012-03-18 at 23:43 +0530, Abhijeet Rastogi wrote:
> > > Hi,
> > > 
> > > 
> > > This is my first post here. I have tried googling and looking at the
> > > manpage but no help.
> > > 
> > > 
> > > We can use
> > > 
> > > 
> > > $nmcli dev disconnect iface eth0
> > > 
> > > 
> > > to change the state of eth0 to disconnect. Is there a command to
> > > change it's state back to connected? I tried looking at the manpage &
> > > I can't seem to find  any option for that.
> > 
> > At the moment, you need to tell NM to reconnect to something, eg 'nmcli
> > con up uuid <uuid>'.  Disconnect places the device into manual mode
> > which requires user action to return to automatic mode.  I suppose we
> > can add an 'autoconnect' property to each device, which Disconnect()
> > would set to false, but which could be changed via the D-Bus properties
> > interface (authenticated of course) back to TRUE.  This property would
> > follow the internal 'autoconnect_inhibit' device member variable and the
> > NMPolicy would listen for changes to this variable and retrigger an auto
> > connection check if it changes back to TRUE.  Patches accepted for that.
> > 
> > Dan
> >
> 
> Attached are patches adding 'Autoconnect' property to NMDevice for core NM
> and libnm-glib as well.

For the API docs, I'd say:

"If TRUE, indicates the device is allowed to autoconnect.  If FALSE,
manual intervention is required before the device will automatically
connect to a known network, such as activating a connection using the
device, or setting this property to TRUE."

There's a redundant NM_DEVICE_GET_PRIVATE() in
nm_device_get_autoconnect().

The other thing we need to do is authenticate the property write call,
which we've got some code for in nm-manager.c::prop_filter().  It's
going to get a bit complicated since that function only works on the
manager object, so we'll have to have something that's a bit more
involved than just strcmp(propiface, NM_DBUS_IFACE).  That said, it
shouldn't be too bad.  We basically want to enforce the same permissions
as manager_device_disconnect_request() does.

The rest of it looks good!

Dan

And while we're at it, to reduce confusion, we should just rename
"autoconnect_inhibit" to autoconnect.  Something like the attached patch
applied on top of yours?


diff --git a/src/nm-device.c b/src/nm-device.c
index 2f69be6..1fd6de7 100644
--- a/src/nm-device.c
+++ b/src/nm-device.c
@@ -223,7 +223,7 @@ typedef struct {
 	NMIP6Config *   dhcp6_ip6_config;
 
 	/* inhibit autoconnect feature */
-	gboolean	autoconnect_inhibit;
+	gboolean	autoconnect;
 
 	/* master interface for bridge, bond, vlan, etc */
 	NMDevice *	master;
@@ -743,10 +743,10 @@ nm_device_autoconnect_allowed (NMDevice *self)
 	g_value_take_object (&instance, self);
 
 	g_value_init (&retval, G_TYPE_BOOLEAN);
-	if (priv->autoconnect_inhibit)
-		g_value_set_boolean (&retval, FALSE);
-	else
+	if (priv->autoconnect)
 		g_value_set_boolean (&retval, TRUE);
+	else
+		g_value_set_boolean (&retval, FALSE);
 
 	/* Use g_signal_emitv() rather than g_signal_emit() to avoid the return
 	 * value being changed if no handlers are connected */
@@ -3145,7 +3145,7 @@ nm_device_disconnect (NMDevice *device, GError **error)
 		return FALSE;
 	}
 
-	priv->autoconnect_inhibit = TRUE;	
+	priv->autoconnect = FALSE;
 	nm_device_state_changed (device,
 	                         NM_DEVICE_STATE_DISCONNECTED,
 	                         NM_DEVICE_STATE_REASON_USER_REQUESTED);
@@ -4335,7 +4335,7 @@ nm_device_state_changed (NMDevice *device,
 			nm_device_deactivate (device, reason);
 		break;
 	default:
-		priv->autoconnect_inhibit = FALSE;
+		priv->autoconnect = TRUE;
 		break;
 	}
 
@@ -4655,12 +4655,3 @@ nm_device_set_dhcp_anycast_address (NMDevice *device, guint8 *addr)
 	}
 }
 
-
-void
-nm_device_clear_autoconnect_inhibit (NMDevice *device)
-{
-	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device);
-	g_return_if_fail (priv);
-	priv->autoconnect_inhibit = FALSE;
-}
-
diff --git a/src/nm-device.h b/src/nm-device.h
index f4495b9..52f5573 100644
--- a/src/nm-device.h
+++ b/src/nm-device.h
@@ -244,8 +244,6 @@ void nm_device_set_managed (NMDevice *device,
                             gboolean managed,
                             NMDeviceStateReason reason);
 
-void nm_device_clear_autoconnect_inhibit (NMDevice *device);
-
 void nm_device_handle_autoip4_event (NMDevice *self,
                                      const char *event,
                                      const char *address);
diff --git a/src/nm-manager.c b/src/nm-manager.c
index e887e57..b669bb8 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -3248,7 +3248,8 @@ do_sleep_wake (NMManager *self)
 					nm_device_set_enabled (device, enabled);
 			}
 
-			nm_device_clear_autoconnect_inhibit (device);
+			g_object_set (G_OBJECT (device), NM_DEVICE_AUTOCONNECT, TRUE, NULL);
+
 			if (nm_device_spec_match_list (device, unmanaged_specs))
 				nm_device_set_managed (device, FALSE, NM_DEVICE_STATE_REASON_NOW_UNMANAGED);
 			else


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