Commit 20f9ccd8 authored by Dan Williams's avatar Dan Williams
Browse files

2005-04-27 Dan Williams <dcbw@redhat.com>

	Patch from Tom Parker:
	* Update debian backend


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@588 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
parent 149167df
2005-04-27 Dan Williams <dcbw@redhat.com>
Patch from Tom Parker:
* Update debian backend
2005-04-27 Dan Williams <dcbw@redhat.com>
* Merge the applet and the info-daemon, and move the converged
......
......@@ -45,37 +45,49 @@ void nm_system_init (void)
{
}
/*
* 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 @@ void nm_system_device_add_default_route_via_device (NMDevice *dev)
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_add_default_route_via_device (NMDevice *dev)
*/
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 @@ void nm_system_device_flush_addresses (NMDevice *dev)
* FALSE on error
*
*/
#if 0
gboolean nm_system_device_setup_static_ip4_config (NMDevice *dev)
{
#define IPBITS (sizeof (guint32) * 8)
......@@ -224,7 +263,7 @@ error:
nm_system_device_flush_routes (dev);
return (FALSE);
}
#endif
/*
* nm_system_enable_loopback
......@@ -354,6 +393,11 @@ void nm_system_device_add_ip6_link_address (NMDevice *dev)
g_free (buf);
}
typedef struct DebSystemConfigData
{
NMIP4Config * config;
gboolean use_dhcp;
} DebSystemConfigData;
/*
* nm_system_device_update_config_info
......@@ -363,25 +407,17 @@ void nm_system_device_add_ip6_link_address (NMDevice *dev)
* 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 @@ void nm_system_device_update_config_info (NMDevice *dev)
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 @@ void nm_system_device_update_config_info (NMDevice *dev)
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;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment