ifupdown: port to new settings API
This commit is contained in:
@@ -29,13 +29,10 @@
|
|||||||
#include <nm-sysconfig-connection.h>
|
#include <nm-sysconfig-connection.h>
|
||||||
#include <nm-system-config-interface.h>
|
#include <nm-system-config-interface.h>
|
||||||
#include <nm-system-config-error.h>
|
#include <nm-system-config-error.h>
|
||||||
#include <nm-settings.h>
|
|
||||||
#include "nm-ifupdown-connection.h"
|
#include "nm-ifupdown-connection.h"
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
|
|
||||||
G_DEFINE_TYPE (NMIfupdownConnection,
|
G_DEFINE_TYPE (NMIfupdownConnection, nm_ifupdown_connection, NM_TYPE_SYSCONFIG_CONNECTION)
|
||||||
nm_ifupdown_connection,
|
|
||||||
NM_TYPE_SYSCONFIG_CONNECTION)
|
|
||||||
|
|
||||||
#define NM_IFUPDOWN_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_IFUPDOWN_CONNECTION, NMIfupdownConnectionPrivate))
|
#define NM_IFUPDOWN_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_IFUPDOWN_CONNECTION, NMIfupdownConnectionPrivate))
|
||||||
|
|
||||||
@@ -60,36 +57,16 @@ nm_ifupdown_connection_new (if_block *block)
|
|||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
|
||||||
update (NMExportedConnection *exported,
|
|
||||||
GHashTable *new_settings,
|
|
||||||
GError **err)
|
|
||||||
{
|
|
||||||
g_set_error (err, NM_SYSCONFIG_SETTINGS_ERROR,
|
|
||||||
NM_SYSCONFIG_SETTINGS_ERROR_UPDATE_NOT_SUPPORTED,
|
|
||||||
"%s.%d - %s", __FILE__, __LINE__, "connection update not supported (read-only).");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
do_delete (NMExportedConnection *exported, GError **err)
|
|
||||||
{
|
|
||||||
g_set_error (err, NM_SYSCONFIG_SETTINGS_ERROR,
|
|
||||||
NM_SYSCONFIG_SETTINGS_ERROR_DELETE_NOT_SUPPORTED,
|
|
||||||
"%s", "ifupdown - connection delete not supported (read-only).");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
service_get_secrets (NMExportedConnection *exported,
|
get_secrets (NMExportedConnection *exported,
|
||||||
const gchar *setting_name,
|
const gchar *setting_name,
|
||||||
const gchar **hints,
|
const gchar **hints,
|
||||||
gboolean request_new,
|
gboolean request_new,
|
||||||
DBusGMethodInvocation *context)
|
DBusGMethodInvocation *context)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
PLUGIN_PRINT ("SCPlugin-Ifupdown", "get_secrets for setting_name:'%s')", setting_name);
|
PLUGIN_PRINT ("SCPlugin-Ifupdown", "get_secrets() for setting_name:'%s'", setting_name);
|
||||||
|
|
||||||
/* FIXME: Only wifi secrets are supported for now */
|
/* FIXME: Only wifi secrets are supported for now */
|
||||||
if (strcmp (setting_name, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME)) {
|
if (strcmp (setting_name, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME)) {
|
||||||
@@ -104,10 +81,9 @@ service_get_secrets (NMExportedConnection *exported,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NM_EXPORTED_CONNECTION_CLASS (nm_ifupdown_connection_parent_class)->service_get_secrets (exported, setting_name, hints, request_new, context);
|
NM_EXPORTED_CONNECTION_CLASS (nm_ifupdown_connection_parent_class)->get_secrets (exported, setting_name, hints, request_new, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* GObject */
|
|
||||||
static void
|
static void
|
||||||
nm_ifupdown_connection_init (NMIfupdownConnection *connection)
|
nm_ifupdown_connection_init (NMIfupdownConnection *connection)
|
||||||
{
|
{
|
||||||
@@ -120,23 +96,29 @@ constructor (GType type,
|
|||||||
{
|
{
|
||||||
GObject *object;
|
GObject *object;
|
||||||
NMIfupdownConnectionPrivate *priv;
|
NMIfupdownConnectionPrivate *priv;
|
||||||
NMConnection *wrapped = nm_connection_new();
|
GError *error = NULL;
|
||||||
|
|
||||||
object = G_OBJECT_CLASS (nm_ifupdown_connection_parent_class)->constructor (type, n_construct_params, construct_params);
|
object = G_OBJECT_CLASS (nm_ifupdown_connection_parent_class)->constructor (type, n_construct_params, construct_params);
|
||||||
g_return_val_if_fail (object, NULL);
|
g_return_val_if_fail (object, NULL);
|
||||||
|
|
||||||
priv = NM_IFUPDOWN_CONNECTION_GET_PRIVATE (object);
|
priv = NM_IFUPDOWN_CONNECTION_GET_PRIVATE (object);
|
||||||
if (!priv) {
|
if (!priv) {
|
||||||
nm_warning ("%s.%d - no private instance.", __FILE__, __LINE__);
|
g_warning ("%s.%d - no private instance.", __FILE__, __LINE__);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
if (!priv->ifblock) {
|
if (!priv->ifblock) {
|
||||||
nm_warning ("(ifupdown) ifblock not provided to constructor.");
|
g_warning ("(ifupdown) ifblock not provided to constructor.");
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_object_set (object, NM_EXPORTED_CONNECTION_CONNECTION, wrapped, NULL);
|
if (!ifupdown_update_connection_from_if_block (NM_CONNECTION (object), priv->ifblock, &error)) {
|
||||||
g_object_unref (wrapped);
|
g_warning ("%s.%d - invalid connection read from /etc/network/interfaces: (%d) %s",
|
||||||
|
__FILE__,
|
||||||
|
__LINE__,
|
||||||
|
error ? error->code : -1,
|
||||||
|
error && error->message ? error->message : "(unknown)");
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
return object;
|
return object;
|
||||||
|
|
||||||
@@ -145,12 +127,6 @@ constructor (GType type,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
finalize (GObject *object)
|
|
||||||
{
|
|
||||||
G_OBJECT_CLASS (nm_ifupdown_connection_parent_class)->finalize (object);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_property (GObject *object, guint prop_id,
|
set_property (GObject *object, guint prop_id,
|
||||||
const GValue *value, GParamSpec *pspec)
|
const GValue *value, GParamSpec *pspec)
|
||||||
@@ -197,11 +173,8 @@ nm_ifupdown_connection_class_init (NMIfupdownConnectionClass *ifupdown_connectio
|
|||||||
object_class->constructor = constructor;
|
object_class->constructor = constructor;
|
||||||
object_class->set_property = set_property;
|
object_class->set_property = set_property;
|
||||||
object_class->get_property = get_property;
|
object_class->get_property = get_property;
|
||||||
object_class->finalize = finalize;
|
|
||||||
|
|
||||||
connection_class->update = update;
|
connection_class->get_secrets = get_secrets;
|
||||||
connection_class->do_delete = do_delete;
|
|
||||||
connection_class->service_get_secrets = service_get_secrets;
|
|
||||||
|
|
||||||
/* Properties */
|
/* Properties */
|
||||||
g_object_class_install_property
|
g_object_class_install_property
|
||||||
|
@@ -525,58 +525,53 @@ update_ip4_setting_from_if_block(NMConnection *connection,
|
|||||||
nm_connection_add_setting(connection, NM_SETTING(ip4_setting));
|
nm_connection_add_setting(connection, NM_SETTING(ip4_setting));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
gboolean
|
||||||
ifupdown_update_connection_from_if_block(NMConnection *connection,
|
ifupdown_update_connection_from_if_block (NMConnection *connection,
|
||||||
if_block *block)
|
if_block *block,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
const char *type = NULL;
|
const char *type = NULL;
|
||||||
char *idstr = NULL;
|
char *idstr = NULL;
|
||||||
char *uuid_base = NULL;
|
char *uuid_base = NULL;
|
||||||
GError *verify_error = NULL;
|
|
||||||
char *uuid = NULL;
|
char *uuid = NULL;
|
||||||
|
NMSettingConnection *s_con;
|
||||||
|
gboolean success = FALSE;
|
||||||
|
|
||||||
NMSettingConnection *connection_setting =
|
s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
|
||||||
NM_SETTING_CONNECTION(nm_connection_get_setting
|
if(!s_con) {
|
||||||
(connection, NM_TYPE_SETTING_CONNECTION));
|
s_con = NM_SETTING_CONNECTION (nm_setting_connection_new());
|
||||||
|
g_assert (s_con);
|
||||||
if(!connection_setting) {
|
nm_connection_add_setting (connection, NM_SETTING (s_con));
|
||||||
connection_setting = NM_SETTING_CONNECTION(nm_setting_connection_new());
|
|
||||||
nm_connection_add_setting(connection, NM_SETTING(connection_setting));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type = _ifupdownplugin_guess_connection_type (block);
|
type = _ifupdownplugin_guess_connection_type (block);
|
||||||
idstr = g_strconcat("Ifupdown (", block->name,")", NULL);
|
idstr = g_strconcat ("Ifupdown (", block->name, ")", NULL);
|
||||||
uuid_base = idstr;
|
uuid_base = idstr;
|
||||||
|
|
||||||
uuid = nm_utils_uuid_generate_from_string(uuid_base);
|
uuid = nm_utils_uuid_generate_from_string (uuid_base);
|
||||||
g_object_set (connection_setting,
|
g_object_set (s_con,
|
||||||
NM_SETTING_CONNECTION_TYPE, type,
|
NM_SETTING_CONNECTION_TYPE, type,
|
||||||
NM_SETTING_CONNECTION_ID, idstr,
|
NM_SETTING_CONNECTION_ID, idstr,
|
||||||
NM_SETTING_CONNECTION_UUID, uuid,
|
NM_SETTING_CONNECTION_UUID, uuid,
|
||||||
NM_SETTING_CONNECTION_READ_ONLY, TRUE,
|
NM_SETTING_CONNECTION_READ_ONLY, TRUE,
|
||||||
|
NM_SETTING_CONNECTION_AUTOCONNECT, FALSE,
|
||||||
NULL);
|
NULL);
|
||||||
g_free (uuid);
|
g_free (uuid);
|
||||||
|
|
||||||
PLUGIN_PRINT("SCPlugin-Ifupdown", "update_connection_setting_from_if_block: name:%s, type:%s, autoconnect:%d, id:%s, uuid: %s",
|
PLUGIN_PRINT("SCPlugin-Ifupdown", "update_connection_setting_from_if_block: name:%s, type:%s, id:%s, uuid: %s",
|
||||||
block->name, type,
|
block->name, type, idstr, nm_setting_connection_get_uuid (s_con));
|
||||||
((gboolean) strcmp("dhcp", type) == 0),
|
|
||||||
idstr,
|
|
||||||
nm_setting_connection_get_uuid (connection_setting));
|
|
||||||
|
|
||||||
if(!strcmp (NM_SETTING_WIRED_SETTING_NAME, type)) {
|
if (!strcmp (NM_SETTING_WIRED_SETTING_NAME, type))
|
||||||
update_wired_setting_from_if_block (connection, block);
|
update_wired_setting_from_if_block (connection, block);
|
||||||
}
|
else if (!strcmp (NM_SETTING_WIRELESS_SETTING_NAME, type)) {
|
||||||
else if(!strcmp (NM_SETTING_WIRELESS_SETTING_NAME, type)) {
|
|
||||||
update_wireless_setting_from_if_block (connection, block);
|
update_wireless_setting_from_if_block (connection, block);
|
||||||
update_wireless_security_setting_from_if_block (connection, block);
|
update_wireless_security_setting_from_if_block (connection, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
update_ip4_setting_from_if_block(connection, block);
|
update_ip4_setting_from_if_block (connection, block);
|
||||||
|
|
||||||
if(!nm_connection_verify(connection, &verify_error)) {
|
success = nm_connection_verify (connection, error);
|
||||||
nm_warning("connection broken: %s (%d)",
|
|
||||||
verify_error->message, verify_error->code);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free(idstr);
|
g_free (idstr);
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
@@ -26,8 +26,9 @@
|
|||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
void
|
gboolean
|
||||||
ifupdown_update_connection_from_if_block(NMConnection *connection,
|
ifupdown_update_connection_from_if_block (NMConnection *connection,
|
||||||
if_block *block);
|
if_block *block,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
@@ -86,8 +86,8 @@ static void
|
|||||||
system_config_interface_init (NMSystemConfigInterface *system_config_interface_class);
|
system_config_interface_init (NMSystemConfigInterface *system_config_interface_class);
|
||||||
|
|
||||||
G_DEFINE_TYPE_EXTENDED (SCPluginIfupdown, sc_plugin_ifupdown, G_TYPE_OBJECT, 0,
|
G_DEFINE_TYPE_EXTENDED (SCPluginIfupdown, sc_plugin_ifupdown, G_TYPE_OBJECT, 0,
|
||||||
G_IMPLEMENT_INTERFACE (NM_TYPE_SYSTEM_CONFIG_INTERFACE,
|
G_IMPLEMENT_INTERFACE (NM_TYPE_SYSTEM_CONFIG_INTERFACE,
|
||||||
system_config_interface_init))
|
system_config_interface_init))
|
||||||
|
|
||||||
#define SC_PLUGIN_IFUPDOWN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SC_TYPE_PLUGIN_IFUPDOWN, SCPluginIfupdownPrivate))
|
#define SC_PLUGIN_IFUPDOWN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SC_TYPE_PLUGIN_IFUPDOWN, SCPluginIfupdownPrivate))
|
||||||
|
|
||||||
@@ -124,9 +124,6 @@ GObject__set_property (GObject *object, guint prop_id,
|
|||||||
static void
|
static void
|
||||||
GObject__dispose (GObject *object);
|
GObject__dispose (GObject *object);
|
||||||
|
|
||||||
static void
|
|
||||||
GObject__finalize (GObject *object);
|
|
||||||
|
|
||||||
/* other helpers */
|
/* other helpers */
|
||||||
static const char *
|
static const char *
|
||||||
get_hostname (NMSystemConfigInterface *config);
|
get_hostname (NMSystemConfigInterface *config);
|
||||||
@@ -155,7 +152,6 @@ sc_plugin_ifupdown_class_init (SCPluginIfupdownClass *req_class)
|
|||||||
g_type_class_add_private (req_class, sizeof (SCPluginIfupdownPrivate));
|
g_type_class_add_private (req_class, sizeof (SCPluginIfupdownPrivate));
|
||||||
|
|
||||||
object_class->dispose = GObject__dispose;
|
object_class->dispose = GObject__dispose;
|
||||||
object_class->finalize = GObject__finalize;
|
|
||||||
object_class->get_property = GObject__get_property;
|
object_class->get_property = GObject__get_property;
|
||||||
object_class->set_property = GObject__set_property;
|
object_class->set_property = GObject__set_property;
|
||||||
|
|
||||||
@@ -176,13 +172,19 @@ sc_plugin_ifupdown_class_init (SCPluginIfupdownClass *req_class)
|
|||||||
NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME);
|
NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ignore_cb (NMSettingsConnectionInterface *connection,
|
||||||
|
GError *error,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
bind_device_to_connection (SCPluginIfupdown *self,
|
bind_device_to_connection (SCPluginIfupdown *self,
|
||||||
GUdevDevice *device,
|
GUdevDevice *device,
|
||||||
NMExportedConnection *exported)
|
NMIfupdownConnection *exported)
|
||||||
{
|
{
|
||||||
GByteArray *mac_address;
|
GByteArray *mac_address;
|
||||||
NMConnection *connection;
|
|
||||||
NMSetting *s_wired = NULL;
|
NMSetting *s_wired = NULL;
|
||||||
NMSetting *s_wifi = NULL;
|
NMSetting *s_wifi = NULL;
|
||||||
const char *iface, *address;
|
const char *iface, *address;
|
||||||
@@ -194,13 +196,6 @@ bind_device_to_connection (SCPluginIfupdown *self,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
connection = nm_exported_connection_get_connection (exported);
|
|
||||||
if (!connection) {
|
|
||||||
PLUGIN_WARN ("SCPluginIfupdown", "no device locking possible. "
|
|
||||||
"NMExportedConnection doesnt have a real connection.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
address = g_udev_device_get_sysfs_attr (device, "address");
|
address = g_udev_device_get_sysfs_attr (device, "address");
|
||||||
if (!address || !strlen (address)) {
|
if (!address || !strlen (address)) {
|
||||||
PLUGIN_WARN ("SCPluginIfupdown", "failed to get MAC address for %s", iface);
|
PLUGIN_WARN ("SCPluginIfupdown", "failed to get MAC address for %s", iface);
|
||||||
@@ -217,8 +212,8 @@ bind_device_to_connection (SCPluginIfupdown *self,
|
|||||||
mac_address = g_byte_array_sized_new (ETH_ALEN);
|
mac_address = g_byte_array_sized_new (ETH_ALEN);
|
||||||
g_byte_array_append (mac_address, &(tmp_mac->ether_addr_octet[0]), ETH_ALEN);
|
g_byte_array_append (mac_address, &(tmp_mac->ether_addr_octet[0]), ETH_ALEN);
|
||||||
|
|
||||||
s_wired = nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRED);
|
s_wired = nm_connection_get_setting (NM_CONNECTION (exported), NM_TYPE_SETTING_WIRED);
|
||||||
s_wifi = nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS);
|
s_wifi = nm_connection_get_setting (NM_CONNECTION (exported), NM_TYPE_SETTING_WIRELESS);
|
||||||
if (s_wifi) {
|
if (s_wifi) {
|
||||||
PLUGIN_PRINT ("SCPluginIfupdown", "locking wired connection setting");
|
PLUGIN_PRINT ("SCPluginIfupdown", "locking wired connection setting");
|
||||||
g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac_address, NULL);
|
g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac_address, NULL);
|
||||||
@@ -226,8 +221,11 @@ bind_device_to_connection (SCPluginIfupdown *self,
|
|||||||
PLUGIN_PRINT ("SCPluginIfupdown", "locking wireless connection setting");
|
PLUGIN_PRINT ("SCPluginIfupdown", "locking wireless connection setting");
|
||||||
g_object_set (s_wifi, NM_SETTING_WIRELESS_MAC_ADDRESS, mac_address, NULL);
|
g_object_set (s_wifi, NM_SETTING_WIRELESS_MAC_ADDRESS, mac_address, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_byte_array_free (mac_address, TRUE);
|
g_byte_array_free (mac_address, TRUE);
|
||||||
|
|
||||||
|
nm_settings_connection_interface_update (NM_SETTINGS_CONNECTION_INTERFACE (exported),
|
||||||
|
ignore_cb,
|
||||||
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -235,7 +233,7 @@ udev_device_added (SCPluginIfupdown *self, GUdevDevice *device)
|
|||||||
{
|
{
|
||||||
SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (self);
|
SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (self);
|
||||||
const char *iface, *path;
|
const char *iface, *path;
|
||||||
NMExportedConnection *exported;
|
NMIfupdownConnection *exported;
|
||||||
|
|
||||||
iface = g_udev_device_get_name (device);
|
iface = g_udev_device_get_name (device);
|
||||||
path = g_udev_device_get_sysfs_path (device);
|
path = g_udev_device_get_sysfs_path (device);
|
||||||
@@ -248,7 +246,7 @@ udev_device_added (SCPluginIfupdown *self, GUdevDevice *device)
|
|||||||
/* if we have a configured connection for this particular iface
|
/* if we have a configured connection for this particular iface
|
||||||
* we want to either unmanage the device or lock it
|
* we want to either unmanage the device or lock it
|
||||||
*/
|
*/
|
||||||
exported = (NMExportedConnection *) g_hash_table_lookup (priv->iface_connections, iface);
|
exported = (NMIfupdownConnection *) g_hash_table_lookup (priv->iface_connections, iface);
|
||||||
if (!exported)
|
if (!exported)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -352,14 +350,23 @@ SCPluginIfupdown_init (NMSystemConfigInterface *config)
|
|||||||
if(!strcmp ("auto", block->type))
|
if(!strcmp ("auto", block->type))
|
||||||
g_hash_table_insert (auto_ifaces, block->name, GUINT_TO_POINTER (1));
|
g_hash_table_insert (auto_ifaces, block->name, GUINT_TO_POINTER (1));
|
||||||
else if (!strcmp ("iface", block->type) && strcmp ("lo", block->name)) {
|
else if (!strcmp ("iface", block->type) && strcmp ("lo", block->name)) {
|
||||||
NMExportedConnection *exported;
|
NMIfupdownConnection *exported;
|
||||||
|
|
||||||
g_hash_table_remove (priv->iface_connections, block->name);
|
/* Remove any connection for this block that was previously found */
|
||||||
|
exported = g_hash_table_lookup (priv->iface_connections, block->name);
|
||||||
|
if (exported) {
|
||||||
|
nm_settings_connection_interface_delete (NM_SETTINGS_CONNECTION_INTERFACE (exported),
|
||||||
|
ignore_cb,
|
||||||
|
NULL);
|
||||||
|
g_hash_table_remove (priv->iface_connections, block->name);
|
||||||
|
}
|
||||||
|
|
||||||
exported = NM_EXPORTED_CONNECTION (nm_ifupdown_connection_new (block));
|
/* add the new connection */
|
||||||
ifupdown_update_connection_from_if_block (nm_exported_connection_get_connection (exported),
|
exported = nm_ifupdown_connection_new (block);
|
||||||
block);
|
if (exported) {
|
||||||
g_hash_table_insert (priv->iface_connections, block->name, exported);
|
g_hash_table_insert (priv->iface_connections, block->name, exported);
|
||||||
|
g_signal_emit_by_name (self, NM_SYSTEM_CONFIG_INTERFACE_CONNECTION_ADDED, exported);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
block = block->next;
|
block = block->next;
|
||||||
}
|
}
|
||||||
@@ -367,17 +374,20 @@ SCPluginIfupdown_init (NMSystemConfigInterface *config)
|
|||||||
/* Make 'auto' interfaces autoconnect=TRUE */
|
/* Make 'auto' interfaces autoconnect=TRUE */
|
||||||
keys = g_hash_table_get_keys (priv->iface_connections);
|
keys = g_hash_table_get_keys (priv->iface_connections);
|
||||||
for (iter = keys; iter; iter = g_list_next (iter)) {
|
for (iter = keys; iter; iter = g_list_next (iter)) {
|
||||||
NMExportedConnection *exported;
|
NMIfupdownConnection *exported;
|
||||||
NMConnection *wrapped;
|
|
||||||
NMSetting *setting;
|
NMSetting *setting;
|
||||||
|
|
||||||
if (!g_hash_table_lookup (auto_ifaces, iter->data))
|
if (!g_hash_table_lookup (auto_ifaces, iter->data))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
exported = g_hash_table_lookup (priv->iface_connections, iter->data);
|
exported = g_hash_table_lookup (priv->iface_connections, iter->data);
|
||||||
wrapped = nm_exported_connection_get_connection (exported);
|
setting = NM_SETTING (nm_connection_get_setting (NM_CONNECTION (exported), NM_TYPE_SETTING_CONNECTION));
|
||||||
setting = NM_SETTING (nm_connection_get_setting (wrapped, NM_TYPE_SETTING_CONNECTION));
|
|
||||||
g_object_set (setting, NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NULL);
|
g_object_set (setting, NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NULL);
|
||||||
|
|
||||||
|
nm_settings_connection_interface_update (NM_SETTINGS_CONNECTION_INTERFACE (exported),
|
||||||
|
ignore_cb,
|
||||||
|
NULL);
|
||||||
|
|
||||||
PLUGIN_PRINT("SCPlugin-Ifupdown", "autoconnect");
|
PLUGIN_PRINT("SCPlugin-Ifupdown", "autoconnect");
|
||||||
}
|
}
|
||||||
g_list_free (keys);
|
g_list_free (keys);
|
||||||
@@ -433,15 +443,15 @@ SCPluginIfupdown_get_connections (NMSystemConfigInterface *config)
|
|||||||
{
|
{
|
||||||
SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (config);
|
SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (config);
|
||||||
GSList *connections = NULL;
|
GSList *connections = NULL;
|
||||||
GList *priv_list = g_hash_table_get_values(priv->iface_connections);
|
GHashTableIter iter;
|
||||||
GList *it = priv_list;
|
gpointer value;
|
||||||
|
|
||||||
PLUGIN_PRINT("SCPlugin-Ifupdown", "(%d) ... get_connections.", GPOINTER_TO_UINT(config));
|
PLUGIN_PRINT("SCPlugin-Ifupdown", "(%d) ... get_connections.", GPOINTER_TO_UINT(config));
|
||||||
|
|
||||||
while(it) {
|
g_hash_table_iter_init (&iter, priv->iface_connections);
|
||||||
NMExportedConnection *conn = it->data;
|
while (g_hash_table_iter_next (&iter, NULL, &value))
|
||||||
connections = g_slist_append(connections, conn);
|
connections = g_slist_prepend (connections, value);
|
||||||
it = it->next;
|
|
||||||
}
|
|
||||||
PLUGIN_PRINT("SCPlugin-Ifupdown", "(%d) connections count: %d", GPOINTER_TO_UINT(config), g_slist_length(connections));
|
PLUGIN_PRINT("SCPlugin-Ifupdown", "(%d) connections count: %d", GPOINTER_TO_UINT(config), g_slist_length(connections));
|
||||||
return connections;
|
return connections;
|
||||||
}
|
}
|
||||||
@@ -455,28 +465,25 @@ static GSList*
|
|||||||
SCPluginIfupdown_get_unmanaged_specs (NMSystemConfigInterface *config)
|
SCPluginIfupdown_get_unmanaged_specs (NMSystemConfigInterface *config)
|
||||||
{
|
{
|
||||||
SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (config);
|
SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (config);
|
||||||
GList *devs, *iter;
|
|
||||||
GSList *specs = NULL;
|
GSList *specs = NULL;
|
||||||
|
GHashTableIter iter;
|
||||||
|
gpointer value;
|
||||||
|
|
||||||
if (!ALWAYS_UNMANAGE && !priv->unmanage_well_known)
|
if (!ALWAYS_UNMANAGE && !priv->unmanage_well_known)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
devs = g_hash_table_get_values (priv->well_known_ifaces);
|
PLUGIN_PRINT("Ifupdown", "get unmanaged devices count: %d",
|
||||||
PLUGIN_PRINT("Ifupdown", "get unmanaged devices count: %d", g_list_length (devs));
|
g_hash_table_size (priv->well_known_ifaces));
|
||||||
|
|
||||||
for (iter = devs; iter; iter = g_list_next (iter)) {
|
g_hash_table_iter_init (&iter, priv->well_known_ifaces);
|
||||||
GUdevDevice *device = G_UDEV_DEVICE (iter->data);
|
while (g_hash_table_iter_next (&iter, NULL, &value)) {
|
||||||
|
GUdevDevice *device = G_UDEV_DEVICE (value);
|
||||||
const char *address;
|
const char *address;
|
||||||
char *spec;
|
|
||||||
|
|
||||||
address = g_udev_device_get_sysfs_attr (device, "address");
|
address = g_udev_device_get_sysfs_attr (device, "address");
|
||||||
if (!address)
|
if (address)
|
||||||
continue;
|
specs = g_slist_append (specs, g_strdup_printf ("mac:%s", address));
|
||||||
|
|
||||||
spec = g_strdup_printf ("mac:%s", address);
|
|
||||||
specs = g_slist_append (specs, spec);
|
|
||||||
}
|
}
|
||||||
g_list_free (devs);
|
|
||||||
return specs;
|
return specs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -619,12 +626,6 @@ GObject__dispose (GObject *object)
|
|||||||
G_OBJECT_CLASS (sc_plugin_ifupdown_parent_class)->dispose (object);
|
G_OBJECT_CLASS (sc_plugin_ifupdown_parent_class)->dispose (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
GObject__finalize (GObject *object)
|
|
||||||
{
|
|
||||||
G_OBJECT_CLASS (sc_plugin_ifupdown_parent_class)->finalize (object);
|
|
||||||
}
|
|
||||||
|
|
||||||
G_MODULE_EXPORT GObject *
|
G_MODULE_EXPORT GObject *
|
||||||
nm_system_config_factory (void)
|
nm_system_config_factory (void)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user