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

@@ -42,6 +42,7 @@
#include <arpa/inet.h>
#include <glib/gprintf.h>
#include <glib/gfileutils.h>
#include "NetworkManagerGeneric.h"
#include "NetworkManagerSystem.h"
#include "NetworkManagerUtils.h"
#include "nm-device.h"
@@ -61,6 +62,7 @@
*/
void nm_system_init (void)
{
nm_generic_init ();
}
/*
@@ -71,13 +73,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);
}
@@ -89,14 +85,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);
}
/*
@@ -107,14 +96,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);
}
@@ -126,14 +108,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);
}
/*
@@ -144,14 +119,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);
}
/*
@@ -162,13 +130,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);
}
@@ -180,14 +142,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);
}
/*
@@ -322,7 +277,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 ();
}
@@ -334,7 +289,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 ();
}
@@ -346,7 +301,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 ();
}
@@ -404,104 +359,7 @@ void nm_system_restart_mdns_responder (void)
*/
void nm_system_device_add_ip6_link_address (NMDevice *dev)
{
char *buf;
char *addr;
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);
}
/*
* 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_generic_device_add_ip6_link_address (dev);
}
/*
@@ -728,7 +586,7 @@ void* nm_system_device_get_system_config (NMDevice * dev, NMData *app_data)
nm_ip4_config_set_broadcast (sys_data->config, broadcast);
}
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
{
int j;
@@ -985,4 +843,3 @@ guint32 nm_system_get_mtu (NMDevice *dev)
return 0;
}