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
This commit is contained in:
@@ -1,3 +1,8 @@
|
|||||||
|
2005-04-27 Dan Williams <dcbw@redhat.com>
|
||||||
|
|
||||||
|
Patch from Tom Parker:
|
||||||
|
* Update debian backend
|
||||||
|
|
||||||
2005-04-27 Dan Williams <dcbw@redhat.com>
|
2005-04-27 Dan Williams <dcbw@redhat.com>
|
||||||
|
|
||||||
* Merge the applet and the info-daemon, and move the converged
|
* Merge the applet and the info-daemon, and move the converged
|
||||||
|
@@ -45,11 +45,46 @@ void nm_system_init (void)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* nm_system_device_add_default_route_via_device
|
||||||
|
*
|
||||||
|
* Add default route to the given device
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void nm_system_device_add_default_route_via_device (NMDevice *dev)
|
||||||
|
{
|
||||||
|
g_return_if_fail (dev != NULL);
|
||||||
|
|
||||||
|
/* Not really applicable for test devices */
|
||||||
|
if (nm_device_is_test_device (dev))
|
||||||
|
return;
|
||||||
|
|
||||||
|
nm_system_device_add_default_route_via_device_with_iface (nm_device_get_iface (dev));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nm_system_device_flush_routes
|
* nm_system_device_add_default_route_via_device_with_iface
|
||||||
*
|
*
|
||||||
* Flush all routes associated with a network device
|
* Add default route to the given device
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
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)
|
void nm_system_device_flush_routes (NMDevice *dev)
|
||||||
@@ -62,36 +97,27 @@ void nm_system_device_flush_routes (NMDevice *dev)
|
|||||||
if (nm_device_is_test_device (dev))
|
if (nm_device_is_test_device (dev))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Remove routing table entries */
|
nm_system_device_flush_routes_with_iface (nm_device_get_iface (dev));
|
||||||
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
|
* nm_system_device_flush_routes_with_iface
|
||||||
*
|
*
|
||||||
* Add default route to the given device
|
* Flush all routes associated with a network device
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void nm_system_device_add_default_route_via_device (NMDevice *dev)
|
void nm_system_device_flush_routes_with_iface (const char *iface)
|
||||||
{
|
{
|
||||||
char *buf;
|
char *buf;
|
||||||
|
|
||||||
g_return_if_fail (dev != NULL);
|
g_return_if_fail (iface != NULL);
|
||||||
|
|
||||||
/* Not really applicable for test devices */
|
/* Remove routing table entries */
|
||||||
if (nm_device_is_test_device (dev))
|
buf = g_strdup_printf ("/sbin/ip route flush dev %s", iface);
|
||||||
return;
|
|
||||||
|
|
||||||
/* Add default gateway */
|
|
||||||
buf = g_strdup_printf ("/sbin/ip route add default dev %s", nm_device_get_iface (dev));
|
|
||||||
nm_spawn_process (buf);
|
nm_spawn_process (buf);
|
||||||
g_free (buf);
|
g_free (buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nm_system_device_flush_addresses
|
* 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)
|
void nm_system_device_flush_addresses (NMDevice *dev)
|
||||||
{
|
{
|
||||||
char *buf;
|
|
||||||
|
|
||||||
g_return_if_fail (dev != NULL);
|
g_return_if_fail (dev != NULL);
|
||||||
|
|
||||||
/* Not really applicable for test devices */
|
/* Not really applicable for test devices */
|
||||||
if (nm_device_is_test_device (dev))
|
if (nm_device_is_test_device (dev))
|
||||||
return;
|
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 */
|
/* Remove all IP addresses for a device */
|
||||||
buf = g_strdup_printf ("/sbin/ip address flush dev %s",
|
buf = g_strdup_printf ("/sbin/ip address flush dev %s", iface);
|
||||||
nm_device_get_iface (dev));
|
|
||||||
nm_spawn_process (buf);
|
nm_spawn_process (buf);
|
||||||
g_free (buf);
|
g_free (buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nm_system_device_setup_static_ip4_config
|
* nm_system_device_setup_static_ip4_config
|
||||||
*
|
*
|
||||||
@@ -125,6 +163,7 @@ void nm_system_device_flush_addresses (NMDevice *dev)
|
|||||||
* FALSE on error
|
* FALSE on error
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
#if 0
|
||||||
gboolean nm_system_device_setup_static_ip4_config (NMDevice *dev)
|
gboolean nm_system_device_setup_static_ip4_config (NMDevice *dev)
|
||||||
{
|
{
|
||||||
#define IPBITS (sizeof (guint32) * 8)
|
#define IPBITS (sizeof (guint32) * 8)
|
||||||
@@ -224,7 +263,7 @@ error:
|
|||||||
nm_system_device_flush_routes (dev);
|
nm_system_device_flush_routes (dev);
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nm_system_enable_loopback
|
* nm_system_enable_loopback
|
||||||
@@ -354,6 +393,11 @@ void nm_system_device_add_ip6_link_address (NMDevice *dev)
|
|||||||
g_free (buf);
|
g_free (buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct DebSystemConfigData
|
||||||
|
{
|
||||||
|
NMIP4Config * config;
|
||||||
|
gboolean use_dhcp;
|
||||||
|
} DebSystemConfigData;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nm_system_device_update_config_info
|
* 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.
|
* 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;
|
DebSystemConfigData * sys_data = NULL;
|
||||||
guint32 ip4_address = 0;
|
|
||||||
guint32 ip4_netmask = 0;
|
|
||||||
guint32 ip4_gateway = 0;
|
|
||||||
guint32 ip4_broadcast = 0;
|
|
||||||
if_block *curr_device;
|
if_block *curr_device;
|
||||||
const char *buf;
|
const char *buf;
|
||||||
|
gboolean error = FALSE;
|
||||||
|
|
||||||
g_return_if_fail (dev != NULL);
|
g_return_val_if_fail (dev != NULL, 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);
|
|
||||||
|
|
||||||
|
sys_data = g_malloc0 (sizeof (DebSystemConfigData));
|
||||||
|
sys_data->use_dhcp = TRUE;
|
||||||
|
|
||||||
ifparser_init();
|
ifparser_init();
|
||||||
|
|
||||||
@@ -394,56 +430,43 @@ void nm_system_device_update_config_info (NMDevice *dev)
|
|||||||
if (buf)
|
if (buf)
|
||||||
{
|
{
|
||||||
if (strcmp (buf, "dhcp")!=0)
|
if (strcmp (buf, "dhcp")!=0)
|
||||||
use_dhcp = FALSE;
|
sys_data->use_dhcp = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = ifparser_getkey (curr_device, "address");
|
buf = ifparser_getkey (curr_device, "address");
|
||||||
if (buf)
|
if (buf)
|
||||||
ip4_address = inet_addr (buf);
|
nm_ip4_config_set_address (sys_data->config, inet_addr (buf));
|
||||||
|
|
||||||
buf = ifparser_getkey (curr_device, "gateway");
|
buf = ifparser_getkey (curr_device, "gateway");
|
||||||
if (buf)
|
if (buf)
|
||||||
ip4_gateway = inet_addr (buf);
|
nm_ip4_config_set_gateway (sys_data->config, inet_addr (buf));
|
||||||
|
|
||||||
buf = ifparser_getkey (curr_device, "netmask");
|
buf = ifparser_getkey (curr_device, "netmask");
|
||||||
if (buf)
|
if (buf)
|
||||||
ip4_netmask = inet_addr (buf);
|
nm_ip4_config_set_netmask (sys_data->config, inet_addr (buf));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
guint32 addr = nm_ip4_config_get_address (sys_data->config);
|
||||||
|
|
||||||
/* Make a default netmask if we have an IP address */
|
/* Make a default netmask if we have an IP address */
|
||||||
if (ip4_address)
|
if (((ntohl (addr) & 0xFF000000) >> 24) <= 127)
|
||||||
{
|
nm_ip4_config_set_netmask (sys_data->config, htonl (0xFF000000));
|
||||||
if (((ntohl (ip4_address) & 0xFF000000) >> 24) <= 127)
|
else if (((ntohl (addr) & 0xFF000000) >> 24) <= 191)
|
||||||
ip4_netmask = htonl (0xFF000000);
|
nm_ip4_config_set_netmask (sys_data->config, htonl (0xFFFF0000));
|
||||||
else if (((ntohl (ip4_address) & 0xFF000000) >> 24) <= 191)
|
|
||||||
ip4_netmask = htonl (0xFFFF0000);
|
|
||||||
else
|
else
|
||||||
ip4_netmask = htonl (0xFFFFFF00);
|
nm_ip4_config_set_netmask (sys_data->config, htonl (0xFFFFFF00));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = ifparser_getkey (curr_device, "broadcast");
|
buf = ifparser_getkey (curr_device, "broadcast");
|
||||||
if (buf)
|
if (buf)
|
||||||
ip4_broadcast = inet_addr (buf);
|
nm_ip4_config_set_broadcast (sys_data->config, inet_addr (buf));
|
||||||
|
else
|
||||||
if (!use_dhcp && (!ip4_address || !ip4_gateway || !ip4_netmask))
|
|
||||||
{
|
{
|
||||||
nm_warning ("Error: network configuration for device '%s' was invalid (non-DHCP configuration,"
|
guint32 broadcast = ((nm_ip4_config_get_address (sys_data->config) & nm_ip4_config_get_netmask (sys_data->config))
|
||||||
" but no address/gateway specificed). Will use DHCP instead.\n", nm_device_get_iface (dev));
|
| ~nm_ip4_config_get_netmask (sys_data->config));
|
||||||
use_dhcp = TRUE;
|
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
|
#if 0
|
||||||
nm_debug ("------ Config (%s)", nm_device_get_iface (dev));
|
nm_debug ("------ Config (%s)", nm_device_get_iface (dev));
|
||||||
nm_debug (" DHCP=%d\n", use_dhcp);
|
nm_debug (" DHCP=%d\n", use_dhcp);
|
||||||
@@ -455,4 +478,45 @@ void nm_system_device_update_config_info (NMDevice *dev)
|
|||||||
|
|
||||||
out:
|
out:
|
||||||
ifparser_destroy();
|
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;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user