2004-08-23 Dan Williams <dcbw@redhat.com>

* configure.in
	  src/Makefile.am
	  src/NetworkManagerDevice.c
	  src/NetworkManager.c
	  src/NetworkManagerUtils.[ch]
	  src/backends/NetworkManagerSystem.h
	  src/backends/NetworkManagerRedHat.c
	  src/backends/NetworkManagerGentoo.c
		- Refactor system-specific code into separate backends for
			each distribution


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@62 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Dan Williams
2004-08-24 00:31:47 +00:00
parent a4afafce03
commit ae6f88b3dd
10 changed files with 368 additions and 111 deletions

View File

@@ -1,3 +1,16 @@
2004-08-23 Dan Williams <dcbw@redhat.com>
* configure.in
src/Makefile.am
src/NetworkManagerDevice.c
src/NetworkManager.c
src/NetworkManagerUtils.[ch]
src/backends/NetworkManagerSystem.h
src/backends/NetworkManagerRedHat.c
src/backends/NetworkManagerGentoo.c
- Refactor system-specific code into separate backends for
each distribution
2004-08-23 Dan Willemsen <dan@willemsen.us>
* dispatcher-daemon/NetworkManagerDispatcher.c

View File

@@ -1,9 +1,42 @@
AC_PREREQ(2.52)
AC_INIT(NetworkManager, 0.1)
AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
AM_INIT_AUTOMAKE([subdir-objects])
AC_PROG_CC
AM_PROG_CC_C_O
AC_ARG_WITH(distro,
[
--with-distro: Specify the Linux distribution to target with distro-specific
parts of NetworkManager
--with-distro=RedHat
--with-distro=Gentoo
],,)
TARGET_DISTRO=
SYSTEM_BACKEND_FILE=
if test "z$with_distro" = "z"; then
echo "You must specify the Linux distribution to target using --with-distro=<distro>"
exit 1
else
case $with_distro in
RedHat)
TARGET_DISTRO=RedHat
SYSTEM_BACKEND_FILE=NetworkManagerRedHat.o
;;
Gentoo)
TARGET_DISTRO=Gentoo
SYSTEM_BACKEND_FILE=NetworkManagerGentoo.o
;;
*)
echo "Your distribution is not yet supported! (patches welcome)"
exit 1
;;
esac
fi
AC_SUBST(TARGET_DISTRO)
AC_SUBST(SYSTEM_BACKEND_FILE)
AC_CHECK_HEADER(iwlib.h, [],
[AC_MSG_ERROR(iwlib.h not found. Install wireless-tools.)], [])

View File

@@ -26,9 +26,14 @@ NetworkManager_SOURCES = \
NetworkManagerUtils.c \
NetworkManagerUtils.h \
NetworkManagerWireless.c \
NetworkManagerWireless.h
NetworkManagerWireless.h \
backends/NetworkManagerSystem.h
NetworkManager_LDADD = $(NM_LIBS) $(IWLIB) $(OPENSSL_LIBS)
EXTRA_NetworkManager_SOURCES = \
backends/NetworkManagerRedHat.c \
backends/NetworkManagerGentoo.c
NetworkManager_LDADD = $(NM_LIBS) $(IWLIB) $(OPENSSL_LIBS) backends/$(SYSTEM_BACKEND_FILE)
dbusservicedir = $(DBUS_SYS_DIR)
dbusservice_DATA = NetworkManager.conf

View File

@@ -39,6 +39,7 @@
#include "NetworkManagerDbus.h"
#include "NetworkManagerAP.h"
#include "NetworkManagerAPList.h"
#include "backends/NetworkManagerSystem.h"
/*
@@ -556,7 +557,7 @@ int main( int argc, char *argv[] )
* the module is loaded, HAL doesn't know its a network device,
* and therefore can't tell us about it.
*/
nm_spawn_process ("/usr/bin/NMLoadModules");
nm_system_load_device_modules ();
/* Initialize our instance data */
nm_data = nm_data_new ();
@@ -594,10 +595,10 @@ int main( int argc, char *argv[] )
/* We run dhclient when we need to, and we don't want any stray ones
* lying around upon launch.
*/
nm_spawn_process ("/usr/bin/killall dhclient");
nm_system_kill_all_dhcp_daemons ();
/* Bring up the loopback interface. */
nm_enable_loopback ();
nm_system_enable_loopback ();
/* Create a watch function that monitors cards for link status (hal doesn't do
* this for wireless cards yet).
@@ -652,7 +653,7 @@ int main( int argc, char *argv[] )
/* Cleanup */
if (hal_shutdown (nm_data->hal_ctx) != 0)
g_warning ("hal_shutdown() failed\n");
syslog (LOG_NOTICE, "libhal shutdown failed");
nm_data_free (nm_data);

View File

@@ -34,6 +34,7 @@
#include "NetworkManagerWireless.h"
#include "NetworkManagerPolicy.h"
#include "NetworkManagerAPList.h"
#include "backends/NetworkManagerSystem.h"
extern gboolean debug;
@@ -229,6 +230,7 @@ NMDevice *nm_device_new (const char *iface, NMData *app_data)
NMDevice *dev;
g_return_val_if_fail (iface != NULL, NULL);
g_return_val_if_fail (strlen (iface) > 0, NULL);
dev = g_new0 (NMDevice, 1);
if (!dev)
@@ -892,12 +894,8 @@ static gboolean nm_device_activate_wireless (NMDevice *dev)
static gpointer nm_device_activation_worker (gpointer user_data)
{
NMDevice *dev = (NMDevice *)user_data;
unsigned char buf[500];
unsigned char hostname[100] = "\0";
int host_err;
int dhclient_err;
char *iface;
FILE *pidfile;
g_return_val_if_fail (dev != NULL, NULL);
g_return_val_if_fail (dev->app_data != NULL, NULL);
@@ -958,6 +956,9 @@ static gpointer nm_device_activation_worker (gpointer user_data)
return (NULL);
}
}
syslog (LOG_DEBUG, "nm_device_activation_worker(%s): using ESSID '%s'", nm_device_get_iface (dev),
nm_ap_get_essid (nm_device_get_best_ap (dev)));
}
else
{
@@ -966,28 +967,8 @@ static gpointer nm_device_activation_worker (gpointer user_data)
nm_device_bring_up (dev);
}
/* Kill the old default route */
nm_spawn_process ("/sbin/ip route del default");
/* Find and kill the previous dhclient process for this interface */
iface = nm_device_get_iface (dev);
snprintf (buf, 500, "/var/run/dhclient-%s.pid", iface);
pidfile = fopen (buf, "r");
if (pidfile)
{
int len;
unsigned char s_pid[20];
pid_t n_pid = -1;
memset (s_pid, 0, 20);
fgets (s_pid, 19, pidfile);
len = strnlen (s_pid, 20);
fclose (pidfile);
n_pid = atoi (s_pid);
if (n_pid > 0)
kill (n_pid, SIGTERM);
}
nm_system_delete_default_route ();
nm_system_device_stop_dhcp (dev);
/* If we don't have a "best" ap, don't try to get a DHCP address or restart the name service cache */
if (nm_device_is_wired (dev) || (nm_device_is_wireless (dev) && nm_device_get_best_ap (dev)))
@@ -995,20 +976,7 @@ static gpointer nm_device_activation_worker (gpointer user_data)
/* Save machine host name */
host_err = gethostname (&hostname[0], 100);
/* Unfortunately, dhclient can take a long time to get a dhcp address
* (for example, bad WEP key so it can't actually talk to the AP).
*/
snprintf (buf, 500, "/sbin/dhclient -1 -q -lf /var/lib/dhcp/dhclient-%s.leases -pf /var/run/dhclient-%s.pid -cf /etc/dhclient-%s.conf %s\n",
iface, iface, iface, iface);
dhclient_err = nm_spawn_process (buf);
/* Set the hostname back to what it was before so that X11 doesn't
* puke when the hostname changes, and so users can actually launch stuff.
*/
if (host_err >= 0)
sethostname (hostname, strlen (hostname));
if (dhclient_err != 0)
if (!nm_system_device_run_dhcp (dev))
{
/* Interfaces cannot be down if they are the active interface,
* otherwise we cannot use them for scanning or link detection.
@@ -1024,6 +992,12 @@ static gpointer nm_device_activation_worker (gpointer user_data)
nm_device_bring_up (dev);
}
/* Set the hostname back to what it was before so that X11 doesn't
* puke when the hostname changes, and so users can actually launch stuff.
*/
if (host_err >= 0)
sethostname (hostname, strlen (hostname));
/* If we were told to quit activation, stop the thread and return */
if (dev->quit_activation)
{
@@ -1033,8 +1007,8 @@ static gpointer nm_device_activation_worker (gpointer user_data)
return (NULL);
}
/* Restart the nameservice caching daemon to make apps aware of new DNS servers */
nm_spawn_process ("/sbin/service nscd restart");
/* Make system aware of any new DNS settings from resolv.conf */
nm_system_update_dns ();
}
/* If we were told to quit activation, stop the thread and return */
@@ -1114,34 +1088,16 @@ void nm_device_activation_cancel (NMDevice *dev)
*/
gboolean nm_device_deactivate (NMDevice *dev, gboolean just_added)
{
unsigned char buf[500];
unsigned char *iface;
gboolean success = FALSE;
g_return_val_if_fail (dev != NULL, FALSE);
g_return_val_if_fail (dev->app_data != NULL, FALSE);
nm_device_activation_cancel (dev);
/* Take out any entries in the routing table and any IP address the old interface
* had.
*/
iface = nm_device_get_iface (dev);
if (iface && strlen (iface))
{
/* Remove routing table entries */
snprintf (buf, 500, "/sbin/ip route flush dev %s", iface);
nm_spawn_process (buf);
/* Remove ip address */
snprintf (buf, 500, "/sbin/ip address flush dev %s", iface);
nm_spawn_process (buf);
/* Take out any entries in the routing table and any IP address the old device had. */
nm_system_device_flush_routes (dev);
nm_system_device_flush_addresses (dev);
dev->ip4_address = 0;
success = TRUE;
}
if (!just_added)
nm_dbus_signal_device_no_longer_active (dev->app_data->dbus_connection, dev);
@@ -1153,7 +1109,7 @@ gboolean nm_device_deactivate (NMDevice *dev, gboolean just_added)
nm_device_bring_down (dev);
}
return (success);
return (TRUE);
}

View File

@@ -200,16 +200,3 @@ int nm_spawn_process (char *args)
return (-1);
}
/*
* nm_enable_loopback
*
* Bring up the loopback interface
*
*/
void nm_enable_loopback (void)
{
nm_spawn_process ("/sbin/ip link set dev lo up");
nm_spawn_process ("ip addr add 127.0.0.1/8 brd 127.255.255.255 dev lo label loopback");
}

View File

@@ -44,6 +44,4 @@ void nm_dispose_scan_results (wireless_scan *result_list);
int nm_spawn_process (char *args);
void nm_enable_loopback (void);
#endif

View File

@@ -0,0 +1,22 @@
/* NetworkManager -- Network link manager
*
* Dan Williams <dcbw@redhat.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* (C) Copyright 2004 Red Hat, Inc.
*/
#include "NetworkManagerSystem.h"

View File

@@ -0,0 +1,192 @@
/* NetworkManager -- Network link manager
*
* Dan Williams <dcbw@redhat.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* (C) Copyright 2004 Red Hat, Inc.
*/
#include <stdio.h>
#include <sys/types.h>
#include <signal.h>
#include "NetworkManagerSystem.h"
#include "NetworkManagerUtils.h"
#include "NetworkManagerDevice.h"
/*
* nm_system_device_run_dhcp
*
* Run the dhcp daemon for a particular interface.
*
* Returns: TRUE on success
* FALSE on dhcp error
*
*/
gboolean nm_system_device_run_dhcp (NMDevice *dev)
{
char buf [500];
char *iface;
int err;
g_return_val_if_fail (dev != NULL, FALSE);
/* Unfortunately, dhclient can take a long time to get a dhcp address
* (for example, bad WEP key so it can't actually talk to the AP).
*/
iface = nm_device_get_iface (dev);
snprintf (buf, 500, "/sbin/dhclient -1 -q -lf /var/lib/dhcp/dhclient-%s.leases -pf /var/run/dhclient-%s.pid -cf /etc/dhclient-%s.conf %s\n",
iface, iface, iface, iface);
err = nm_spawn_process (buf);
return (err == 0);
}
/*
* nm_system_device_stop_dhcp
*
* Kill any dhcp daemon that happens to be around. We may be changing
* interfaces and we're going to bring the previous one down, so there's
* no sense in keeping the dhcp daemon running on the old interface.
*
*/
void nm_system_device_stop_dhcp (NMDevice *dev)
{
FILE *pidfile;
char buf [500];
g_return_if_fail (dev != NULL);
/* Find and kill the previous dhclient process for this device */
snprintf (buf, 500, "/var/run/dhclient-%s.pid", nm_device_get_iface (dev));
pidfile = fopen (buf, "r");
if (pidfile)
{
int len;
unsigned char s_pid[20];
pid_t n_pid = -1;
memset (s_pid, 0, 20);
fgets (s_pid, 19, pidfile);
len = strnlen (s_pid, 20);
fclose (pidfile);
n_pid = atoi (s_pid);
if (n_pid > 0)
kill (n_pid, SIGTERM);
}
}
/*
* nm_system_device_flush_routes
*
* Flush all routes associated with a network device
*
*/
void nm_system_device_flush_routes (NMDevice *dev)
{
char buf [100];
g_return_if_fail (dev != NULL);
/* Remove routing table entries */
snprintf (buf, 100, "/sbin/ip route flush dev %s", nm_device_get_iface (dev));
nm_spawn_process (buf);
}
/*
* nm_system_device_flush_addresses
*
* Flush all network addresses associated with a network device
*
*/
void nm_system_device_flush_addresses (NMDevice *dev)
{
char buf [100];
g_return_if_fail (dev != NULL);
/* Remove routing table entries */
snprintf (buf, 100, "/sbin/ip address flush dev %s", nm_device_get_iface (dev));
nm_spawn_process (buf);
}
/*
* nm_system_enable_loopback
*
* Bring up the loopback interface
*
*/
void nm_system_enable_loopback (void)
{
nm_spawn_process ("/sbin/ip link set dev lo up");
nm_spawn_process ("ip addr add 127.0.0.1/8 brd 127.255.255.255 dev lo label loopback");
}
/*
* nm_system_delete_default_route
*
* Remove the old default route in preparation for a new one
*
*/
void nm_system_delete_default_route (void)
{
nm_spawn_process ("/sbin/ip route del default");
}
/*
* nm_system_kill_all_dhcp_daemons
*
* Kill all DHCP daemons currently running, done at startup.
*
*/
void nm_system_kill_all_dhcp_daemons (void)
{
nm_spawn_process ("/usr/bin/killall dhclient");
}
/*
* nm_system_update_dns
*
* Make glibc/nscd aware of any changes to the resolv.conf file by
* restarting nscd.
*
*/
void nm_system_update_dns (void)
{
nm_spawn_process ("/sbin/service nscd restart");
}
/*
* nm_system_load_device_modules
*
* Load any network adapter kernel modules that we need to, since Fedora doesn't
* autoload them at this time.
*
*/
void nm_system_load_device_modules (void)
{
nm_spawn_process ("/usr/bin/NMLoadModules");
}

View File

@@ -0,0 +1,50 @@
/* NetworkManager -- Network link manager
*
* Dan Williams <dcbw@redhat.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* (C) Copyright 2004 Red Hat, Inc.
*/
#ifndef NETWORK_MANAGER_SYSTEM_H
#define NETWORK_MANAGER_SYSTEM_H
#include <glib.h>
#include "NetworkManagerDevice.h"
/* Prototypes for system/distribution dependent functions */
gboolean nm_system_device_run_dhcp (NMDevice *dev);
void nm_system_device_stop_dhcp (NMDevice *dev);
void nm_system_device_flush_routes (NMDevice *dev);
void nm_system_device_flush_addresses (NMDevice *dev);
void nm_system_enable_loopback (void);
void nm_system_delete_default_route (void);
void nm_system_kill_all_dhcp_daemons (void);
void nm_system_update_dns (void);
void nm_system_load_device_modules (void);
#endif