2006-07-24 Dan Williams <dcbw@redhat.com>

Patch from Timothée Lecomte <timothee.lecomte@ens.fr>
	* src/backends/Makefile.am
	  src/backends/NetworkManagerArch.c
	  src/backends/NetworkManagerDebian.c
	  src/backends/NetworkManagerGeneric.c
	  src/backends/NetworkManagerGeneric.h
	  src/backends/NetworkManagerGentoo.c
	  src/backends/NetworkManagerPaldo.c
	  src/backends/NetworkManagerRedHat.c
	  src/backends/NetworkManagerSlackware.c
	  src/backends/NetworkManagerSuSE.c
		- Genericize common backend functions


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1894 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Dan Williams
2006-07-24 05:49:14 +00:00
parent 0899079c0c
commit c1a97b29b4
11 changed files with 703 additions and 861 deletions

View File

@@ -31,6 +31,7 @@
#include <sys/types.h>
#include <signal.h>
#include <arpa/inet.h>
#include "NetworkManagerGeneric.h"
#include "NetworkManagerSystem.h"
#include "NetworkManagerUtils.h"
#include "nm-device.h"
@@ -50,6 +51,7 @@
*/
void nm_system_init (void)
{
nm_generic_init ();
}
/*
@@ -60,13 +62,7 @@ void nm_system_init (void)
*/
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_generic_device_add_default_route_via_device (dev);
}
@@ -78,14 +74,7 @@ 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 (IP_BINARY_PATH " route add default dev %s", iface);
nm_spawn_process (buf);
g_free (buf);
nm_generic_device_add_default_route_via_device_with_iface (iface);
}
/*
@@ -96,14 +85,7 @@ void nm_system_device_add_default_route_via_device_with_iface (const char *iface
*/
void nm_system_device_add_route_via_device_with_iface (const char *iface, const char *route)
{
char *buf;
g_return_if_fail (iface != NULL);
/* Add default gateway */
buf = g_strdup_printf (IP_BINARY_PATH " route add %s dev %s", route, iface);
nm_spawn_process (buf);
g_free (buf);
nm_generic_device_add_route_via_device_with_iface (iface, route);
}
@@ -115,13 +97,7 @@ void nm_system_device_add_route_via_device_with_iface (const char *iface, const
*/
void nm_system_device_flush_routes (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_flush_routes_with_iface (nm_device_get_iface (dev));
nm_generic_device_flush_routes (dev);
}
/*
@@ -132,14 +108,7 @@ void nm_system_device_flush_routes (NMDevice *dev)
*/
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 (IP_BINARY_PATH " route flush dev %s", iface);
nm_spawn_process (buf);
g_free (buf);
nm_generic_device_flush_routes_with_iface (iface);
}
/*
@@ -150,13 +119,7 @@ void nm_system_device_flush_routes_with_iface (const char *iface)
*/
void nm_system_device_flush_addresses (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_flush_addresses_with_iface (nm_device_get_iface (dev));
nm_generic_device_flush_addresses (dev);
}
@@ -168,14 +131,7 @@ void nm_system_device_flush_addresses (NMDevice *dev)
*/
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 (IP_BINARY_PATH " addr flush dev %s", iface);
nm_spawn_process (buf);
g_free (buf);
nm_generic_device_flush_addresses_with_iface (iface);
}
/*
@@ -199,7 +155,7 @@ void nm_system_enable_loopback (void)
*/
void nm_system_flush_loopback_routes (void)
{
nm_system_device_flush_routes_with_iface ("lo");
nm_generic_flush_loopback_routes ();
}
@@ -211,7 +167,7 @@ void nm_system_flush_loopback_routes (void)
*/
void nm_system_delete_default_route (void)
{
nm_spawn_process (IP_BINARY_PATH " route del default");
nm_generic_delete_default_route ();
}
@@ -223,7 +179,7 @@ void nm_system_delete_default_route (void)
*/
void nm_system_flush_arp_cache (void)
{
nm_spawn_process (IP_BINARY_PATH " neigh flush all");
nm_generic_flush_arp_cache ();
}
@@ -274,28 +230,7 @@ void nm_system_restart_mdns_responder (void)
*/
void nm_system_device_add_ip6_link_address (NMDevice *dev)
{
char *buf;
struct ether_addr hw_addr;
unsigned char eui[8];
if (nm_device_is_802_3_ethernet (dev))
nm_device_802_3_ethernet_get_address (NM_DEVICE_802_3_ETHERNET (dev), &hw_addr);
else if (nm_device_is_802_11_wireless (dev))
nm_device_802_11_wireless_get_address (NM_DEVICE_802_11_WIRELESS (dev), &hw_addr);
memcpy (eui, &(hw_addr.ether_addr_octet), sizeof (hw_addr.ether_addr_octet));
memmove(eui+5, eui+3, 3);
eui[3] = 0xff;
eui[4] = 0xfe;
eui[0] ^= 2;
/* Add the default link-local IPv6 address to a device */
buf = g_strdup_printf (IP_BINARY_PATH " -6 addr add fe80::%x%02x:%x%02x:%x%02x:%x%02x/64 dev %s",
eui[0], eui[1], eui[2], eui[3],
eui[4], eui[5],
eui[6], eui[7], nm_device_get_iface (dev));
nm_spawn_process (buf);
g_free (buf);
nm_generic_device_add_ip6_link_address (dev);
}
typedef struct DebSystemConfigData
@@ -304,82 +239,6 @@ typedef struct DebSystemConfigData
gboolean use_dhcp;
} DebSystemConfigData;
/*
* set_ip4_config_from_resolv_conf
*
* Add nameservers and search names from a resolv.conf format file.
*
*/
static void set_ip4_config_from_resolv_conf (const char *filename, NMIP4Config *ip4_config)
{
char * contents = NULL;
char ** split_contents = NULL;
int i, len;
g_return_if_fail (filename != NULL);
g_return_if_fail (ip4_config != NULL);
if (!g_file_get_contents (filename, &contents, NULL, NULL) || (contents == NULL))
return;
if (!(split_contents = g_strsplit (contents, "\n", 0)))
goto out;
len = g_strv_length (split_contents);
for (i = 0; i < len; i++)
{
char *line = split_contents[i];
/* Ignore comments */
if (!line || (line[0] == ';') || (line[0] == '#'))
continue;
line = g_strstrip (line);
if ((strncmp (line, "search", 6) == 0) && (strlen (line) > 6))
{
char *searches = g_strdup (line + 7);
char **split_searches = NULL;
if (!searches || !strlen (searches))
continue;
/* Allow space-separated search domains */
if ((split_searches = g_strsplit (searches, " ", 0)))
{
int m, srch_len;
srch_len = g_strv_length (split_searches);
for (m = 0; m < srch_len; m++)
{
if (split_searches[m])
nm_ip4_config_add_domain (ip4_config, split_searches[m]);
}
g_strfreev (split_searches);
}
else
{
/* Only 1 item, add the whole line */
nm_ip4_config_add_domain (ip4_config, searches);
}
g_free (searches);
}
else if ((strncmp (line, "nameserver", 10) == 0) && (strlen (line) > 10))
{
guint32 addr = (guint32) (inet_addr (line + 11));
if (addr != (guint32) -1)
nm_ip4_config_add_nameserver (ip4_config, addr);
}
}
g_strfreev (split_contents);
out:
g_free (contents);
}
/*
* nm_system_device_get_system_config
*
@@ -451,7 +310,7 @@ void* nm_system_device_get_system_config (NMDevice *dev, NMData *app_data)
}
if (!sys_data->use_dhcp)
set_ip4_config_from_resolv_conf (SYSCONFDIR"/resolv.conf", sys_data->config);
nm_generic_set_ip4_config_from_resolv_conf (SYSCONFDIR"/resolv.conf", sys_data->config);
#if 0
nm_debug ("------ Config (%s)", nm_device_get_iface (dev));