Debian backedn update+backend proposal
- From: Tom Parker <palfrey tevp net>
- To: networkmanager-list gnome org
- Subject: Debian backedn update+backend proposal
- Date: Wed, 20 Apr 2005 13:59:44 +0200
I've just attached a patch to update the Debian backend to use the latest
changes. However, I keep noting that most of the changes here are copy+paste
from the Redhat backend. I'm thinking that a bunch more work can be done on some
better merging of the backends - or at least some way to mark a backend as "like
this one, except for these functions". Some sort of kernel-like function pointer
structure pointing to the correct routines for a platform perhaps?
Ideas anyone?
Tom
--
palfrey tevp net - http://tevp.net
Illegitimus non carborundum
Index: src/backends/NetworkManagerDebian.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/src/backends/NetworkManagerDebian.c,v
retrieving revision 1.21
diff -u -r1.21 NetworkManagerDebian.c
--- src/backends/NetworkManagerDebian.c 4 Apr 2005 16:24:36 -0000 1.21
+++ src/backends/NetworkManagerDebian.c 20 Apr 2005 11:56:41 -0000
@@ -45,37 +45,49 @@
{
}
-
/*
- * nm_system_device_flush_routes
+ * nm_system_device_add_default_route_via_device
*
- * Flush all routes associated with a network device
+ * Add default route to the given device
*
*/
-void nm_system_device_flush_routes (NMDevice *dev)
+void nm_system_device_add_default_route_via_device (NMDevice *dev)
{
- char *buf;
-
g_return_if_fail (dev != NULL);
/* Not really applicable for test devices */
if (nm_device_is_test_device (dev))
return;
- /* Remove routing table entries */
- buf = g_strdup_printf ("/sbin/ip route flush dev %s", nm_device_get_iface (dev));
- nm_spawn_process (buf);
- g_free (buf);
+ nm_system_device_add_default_route_via_device_with_iface (nm_device_get_iface (dev));
}
/*
- * nm_system_device_add_default_route_via_device
+ * nm_system_device_add_default_route_via_device_with_iface
*
* Add default route to the given device
*
*/
-void nm_system_device_add_default_route_via_device (NMDevice *dev)
+void nm_system_device_add_default_route_via_device_with_iface (const char *iface)
+{
+ char *buf;
+
+ g_return_if_fail (iface != NULL);
+
+ /* Add default gateway */
+ buf = g_strdup_printf ("/sbin/ip route add default dev %s", iface);
+ nm_spawn_process (buf);
+ g_free (buf);
+}
+
+/*
+ * nm_system_device_flush_addresses
+ *
+ * Flush all network addresses associated with a network device
+ *
+ */
+void nm_system_device_flush_routes (NMDevice *dev)
{
char *buf;
@@ -85,13 +97,27 @@
if (nm_device_is_test_device (dev))
return;
- /* Add default gateway */
- buf = g_strdup_printf ("/sbin/ip route add default dev %s", nm_device_get_iface (dev));
+ nm_system_device_flush_routes_with_iface (nm_device_get_iface (dev));
+}
+
+/*
+ * nm_system_device_flush_routes_with_iface
+ *
+ * Flush all routes associated with a network device
+ *
+ */
+void nm_system_device_flush_routes_with_iface (const char *iface)
+{
+ char *buf;
+
+ g_return_if_fail (iface != NULL);
+
+ /* Remove routing table entries */
+ buf = g_strdup_printf ("/sbin/ip route flush dev %s", iface);
nm_spawn_process (buf);
g_free (buf);
}
-
/*
* nm_system_device_flush_addresses
*
@@ -100,22 +126,34 @@
*/
void nm_system_device_flush_addresses (NMDevice *dev)
{
- char *buf;
-
g_return_if_fail (dev != NULL);
/* Not really applicable for test devices */
if (nm_device_is_test_device (dev))
return;
+ nm_system_device_flush_addresses_with_iface (nm_device_get_iface (dev));
+}
+
+
+/*
+ * nm_system_device_flush_addresses_with_iface
+ *
+ * Flush all network addresses associated with a network device
+ *
+ */
+void nm_system_device_flush_addresses_with_iface (const char *iface)
+{
+ char *buf;
+
+ g_return_if_fail (iface != NULL);
+
/* Remove all IP addresses for a device */
- buf = g_strdup_printf ("/sbin/ip address flush dev %s",
- nm_device_get_iface (dev));
+ buf = g_strdup_printf ("/sbin/ip address flush dev %s", iface);
nm_spawn_process (buf);
- g_free (buf);
+ g_free (buf);
}
-
/*
* nm_system_device_setup_static_ip4_config
*
@@ -125,6 +163,7 @@
* FALSE on error
*
*/
+#if 0
gboolean nm_system_device_setup_static_ip4_config (NMDevice *dev)
{
#define IPBITS (sizeof (guint32) * 8)
@@ -224,7 +263,7 @@
nm_system_device_flush_routes (dev);
return (FALSE);
}
-
+#endif
/*
* nm_system_enable_loopback
@@ -354,6 +393,11 @@
g_free (buf);
}
+typedef struct DebSystemConfigData
+{
+ NMIP4Config * config;
+ gboolean use_dhcp;
+} DebSystemConfigData;
/*
* nm_system_device_update_config_info
@@ -363,25 +407,17 @@
* info before setting stuff too.
*
*/
-void nm_system_device_update_config_info (NMDevice *dev)
+void* nm_system_device_get_system_config (NMDevice *dev)
{
- gboolean use_dhcp = TRUE;
- guint32 ip4_address = 0;
- guint32 ip4_netmask = 0;
- guint32 ip4_gateway = 0;
- guint32 ip4_broadcast = 0;
+ DebSystemConfigData * sys_data = NULL;
if_block *curr_device;
const char *buf;
+ gboolean error = FALSE;
- g_return_if_fail (dev != NULL);
-
- /* We use DHCP on an interface unless told not to */
- nm_device_config_set_use_dhcp (dev, TRUE);
- nm_device_config_set_ip4_address (dev, 0);
- nm_device_config_set_ip4_gateway (dev, 0);
- nm_device_config_set_ip4_netmask (dev, 0);
- nm_device_config_set_ip4_broadcast (dev, 0);
+ g_return_val_if_fail (dev != NULL, NULL);
+ sys_data = g_malloc0 (sizeof (DebSystemConfigData));
+ sys_data->use_dhcp = TRUE;
ifparser_init();
@@ -394,56 +430,43 @@
if (buf)
{
if (strcmp (buf, "dhcp")!=0)
- use_dhcp = FALSE;
+ sys_data->use_dhcp = FALSE;
}
buf = ifparser_getkey (curr_device, "address");
if (buf)
- ip4_address = inet_addr (buf);
+ nm_ip4_config_set_address (sys_data->config, inet_addr (buf));
buf = ifparser_getkey (curr_device, "gateway");
if (buf)
- ip4_gateway = inet_addr (buf);
+ nm_ip4_config_set_gateway (sys_data->config, inet_addr (buf));
buf = ifparser_getkey (curr_device, "netmask");
if (buf)
- ip4_netmask = inet_addr (buf);
+ nm_ip4_config_set_netmask (sys_data->config, inet_addr (buf));
else
{
+ guint32 addr = nm_ip4_config_get_address (sys_data->config);
+
/* Make a default netmask if we have an IP address */
- if (ip4_address)
- {
- if (((ntohl (ip4_address) & 0xFF000000) >> 24) <= 127)
- ip4_netmask = htonl (0xFF000000);
- else if (((ntohl (ip4_address) & 0xFF000000) >> 24) <= 191)
- ip4_netmask = htonl (0xFFFF0000);
- else
- ip4_netmask = htonl (0xFFFFFF00);
- }
+ if (((ntohl (addr) & 0xFF000000) >> 24) <= 127)
+ nm_ip4_config_set_netmask (sys_data->config, htonl (0xFF000000));
+ else if (((ntohl (addr) & 0xFF000000) >> 24) <= 191)
+ nm_ip4_config_set_netmask (sys_data->config, htonl (0xFFFF0000));
+ else
+ nm_ip4_config_set_netmask (sys_data->config, htonl (0xFFFFFF00));
}
buf = ifparser_getkey (curr_device, "broadcast");
if (buf)
- ip4_broadcast = inet_addr (buf);
-
- if (!use_dhcp && (!ip4_address || !ip4_gateway || !ip4_netmask))
+ nm_ip4_config_set_broadcast (sys_data->config, inet_addr (buf));
+ else
{
- nm_warning ("Error: network configuration for device '%s' was invalid (non-DHCP configuration,"
- " but no address/gateway specificed). Will use DHCP instead.\n", nm_device_get_iface (dev));
- use_dhcp = TRUE;
+ guint32 broadcast = ((nm_ip4_config_get_address (sys_data->config) & nm_ip4_config_get_netmask (sys_data->config))
+ | ~nm_ip4_config_get_netmask (sys_data->config));
+ nm_ip4_config_set_broadcast (sys_data->config, broadcast);
}
- /* If successful, set values on the device */
- nm_device_config_set_use_dhcp (dev, use_dhcp);
- if (ip4_address)
- nm_device_config_set_ip4_address (dev, ip4_address);
- if (ip4_gateway)
- nm_device_config_set_ip4_gateway (dev, ip4_gateway);
- if (ip4_netmask)
- nm_device_config_set_ip4_netmask (dev, ip4_netmask);
- if (ip4_broadcast)
- nm_device_config_set_ip4_broadcast (dev, ip4_broadcast);
-
#if 0
nm_debug ("------ Config (%s)", nm_device_get_iface (dev));
nm_debug (" DHCP=%d\n", use_dhcp);
@@ -455,4 +478,45 @@
out:
ifparser_destroy();
+ if (error)
+ {
+ sys_data->use_dhcp = TRUE;
+ /* Clear out the config */
+ nm_ip4_config_unref (sys_data->config);
+ sys_data->config = NULL;
+ }
+
+ return (void *)sys_data;
+}
+
+/*
+ * nm_system_device_free_system_config
+ *
+ * Free stored system config data
+ *
+ */
+void nm_system_device_free_system_config (NMDevice *dev, void *system_config_data)
+{
+ DebSystemConfigData *sys_data = (DebSystemConfigData *)system_config_data;
+
+ g_return_if_fail (dev != NULL);
+
+ if (!sys_data)
+ return;
+
+ if (sys_data->config)
+ nm_ip4_config_unref (sys_data->config);
+}
+
+NMIP4Config *nm_system_device_new_ip4_system_config (NMDevice *dev)
+{
+ DebSystemConfigData *sys_data;
+ NMIP4Config *new_config = NULL;
+
+ g_return_val_if_fail (dev != NULL, NULL);
+
+ if ((sys_data = nm_device_get_system_config_data (dev)))
+ new_config = nm_ip4_config_copy (sys_data->config);
+
+ return new_config;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]