2004-08-24 Dan Willemsen <dan@willemsen.us>

* src/NetworkManager.c
	  src/backends/NetworkManagerGentoo.c
	  src/backends/NetworkManagerRedHat.c
	  src/backends/NetworkManagerSystem.h
		- Implement preliminary Gentoo support, adding a
			nm_system_init function to the backend specification

	* configure.in
		- Distribution auto-detection, lowercase any user-fed
			distribution names

	* initscript/.cvsignore
	  initscript/Makefile.am
	  initscript/RedHat/Makefile.am
	  initscript/RedHat/NetworkManager
	  initscript/Gentoo/Makefile.am
	  initscript/Gentoo/NetworkManager
		- Refactored initscript code separately for each
			distribution


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@64 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Dan Willemsen
2004-08-25 20:52:19 +00:00
committed by Seth Nickell
parent 5435af273f
commit 6dbc6cfd03
8 changed files with 253 additions and 9 deletions

View File

@@ -1,3 +1,26 @@
2004-08-24 Dan Willemsen <dan@willemsen.us>
* src/NetworkManager.c
src/backends/NetworkManagerGentoo.c
src/backends/NetworkManagerRedHat.c
src/backends/NetworkManagerSystem.h
- Implement preliminary Gentoo support, adding a
nm_system_init function to the backend specification
* configure.in
- Distribution auto-detection, lowercase any user-fed
distribution names
* initscript/.cvsignore
initscript/Makefile.am
initscript/RedHat/Makefile.am
initscript/RedHat/NetworkManager
initscript/Gentoo/Makefile.am
initscript/Gentoo/NetworkManager
- Refactored initscript code separately for each
distribution
2004-08-23 Dan Williams <dcbw@redhat.com> 2004-08-23 Dan Williams <dcbw@redhat.com>
* configure.in * configure.in

View File

@@ -17,20 +17,29 @@ AC_ARG_WITH(distro,
TARGET_DISTRO= TARGET_DISTRO=
SYSTEM_BACKEND_FILE= SYSTEM_BACKEND_FILE=
if test "z$with_distro" = "z"; then if test "z$with_distro" = "z"; then
echo "You must specify the Linux distribution to target using --with-distro=<distro>" AC_CHECK_FILE(/etc/redhat-release,with_distro="redhat")
AC_CHECK_FILE(/etc/fedora-release,with_distro="redhat")
AC_CHECK_FILE(/etc/gentoo-release,with_distro="gentoo")
AC_CHECK_FILE(/etc/debian_version,with_distro="debian")
AC_CHECK_FILE(/etc/mandrake-release,with_distro="mandrake")
fi
if test "z$with_distro" = "z"; then
echo "Linux distribution autodetection failed, you must specify the distribution to target using --with-distro=<distro>"
exit 1 exit 1
else else
with_distro=`echo ${with_distro} | tr '[[:upper:]]' '[[:lower:]]' `
case $with_distro in case $with_distro in
RedHat) redhat)
TARGET_DISTRO=RedHat TARGET_DISTRO=RedHat
SYSTEM_BACKEND_FILE=NetworkManagerRedHat.o SYSTEM_BACKEND_FILE=NetworkManagerRedHat.o
;; ;;
Gentoo) gentoo)
TARGET_DISTRO=Gentoo TARGET_DISTRO=Gentoo
SYSTEM_BACKEND_FILE=NetworkManagerGentoo.o SYSTEM_BACKEND_FILE=NetworkManagerGentoo.o
;; ;;
*) *)
echo "Your distribution is not yet supported! (patches welcome)" echo "Your distribution(${with_distro}) is not yet supported! (patches welcome)"
exit 1 exit 1
;; ;;
esac esac
@@ -96,3 +105,7 @@ panel-applet/Makefile
test/Makefile test/Makefile
initscript/Makefile initscript/Makefile
]) ])
echo
echo Distribution targeting: ${TARGET_DISTRO}
echo 'if this is not correct, please specifiy your distro with --with-distro=<distro>'

View File

@@ -1,2 +1,3 @@
Makefile Makefile
Makefile.in Makefile.in
NMLaunchHelper

View File

@@ -1,3 +1,5 @@
SUBDIRS = $(TARGET_DISTRO)
INCLUDES = \ INCLUDES = \
$(NM_CFLAGS) \ $(NM_CFLAGS) \
-Wall \ -Wall \
@@ -11,8 +13,3 @@ bin_PROGRAMS = NMLaunchHelper
NMLaunchHelper_SOURCES = NMLaunchHelper.c NMLaunchHelper_SOURCES = NMLaunchHelper.c
NMLaunchHelper_LDADD = $(NM_LIBS) NMLaunchHelper_LDADD = $(NM_LIBS)
EXTRA_DIST = NetworkManager
initddir = $(sysconfdir)/rc.d/init.d
initd_SCRIPTS = NetworkManager

View File

@@ -551,6 +551,8 @@ int main( int argc, char *argv[] )
openlog ("NetworkManager", (become_daemon) ? LOG_CONS : LOG_CONS | LOG_PERROR, (become_daemon) ? LOG_DAEMON : LOG_USER); openlog ("NetworkManager", (become_daemon) ? LOG_CONS : LOG_CONS | LOG_PERROR, (become_daemon) ? LOG_DAEMON : LOG_USER);
syslog (LOG_NOTICE, "starting..."); syslog (LOG_NOTICE, "starting...");
nm_system_init();
/* Load all network device kernel modules. /* Load all network device kernel modules.
* NOTE: this hack is temporary until device modules get loaded * NOTE: this hack is temporary until device modules get loaded
* on startup by something else. The problem is that unless * on startup by something else. The problem is that unless

View File

@@ -1,6 +1,7 @@
/* NetworkManager -- Network link manager /* NetworkManager -- Network link manager
* *
* Dan Williams <dcbw@redhat.com> * Dan Williams <dcbw@redhat.com>
* Dan Willemsen <dan@willemsen.us>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@@ -17,6 +18,201 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* *
* (C) Copyright 2004 Red Hat, Inc. * (C) Copyright 2004 Red Hat, Inc.
* (C) Copyright 2004 Dan Willemsen
*/ */
#include <stdio.h>
#include <sys/types.h>
#include <signal.h>
#include "NetworkManagerSystem.h" #include "NetworkManagerSystem.h"
#include "NetworkManagerUtils.h"
typedef enum GENTOOConfType
{
GENTOO_CONF_TYPE_IFCONFIG = 0,
GENTOO_CONF_TYPE_IPROUTE
} GENTOOConfType;
static GENTOOConfType nm_system_gentoo_conf_type;
/*
* nm_system_init
*
* Initializes the distribution-specific system backend
*
*/
void nm_system_init (void)
{
// TODO: autodetect conf type, probably by checking if /sbin/ip exists
nm_system_gentoo_conf_type = GENTOO_CONF_TYPE_IPROUTE;
}
/*
* 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);
iface = nm_device_get_iface (dev);
snprintf (buf, 500, "/sbin/dhcpcd %s", 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);
snprintf (buf, 500, "/var/run/dhcpcd-%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);
if (nm_system_gentoo_conf_type == GENTOO_CONF_TYPE_IPROUTE) {
snprintf (buf, 100, "/sbin/ip route flush dev %s", nm_device_get_iface (dev));
} else if (nm_system_gentoo_conf_type == GENTOO_CONF_TYPE_IFCONFIG) {
// FIXME: this command still isn't right
snprintf (buf, 100, "/sbin/route del dev%s", nm_device_get_iface (dev));
} else {
snprintf (buf, 100, "/bin/false");
}
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);
if (nm_system_gentoo_conf_type == GENTOO_CONF_TYPE_IPROUTE) {
snprintf (buf, 100, "/sbin/ip address flush dev %s", nm_device_get_iface (dev));
} else if (nm_system_gentoo_conf_type == GENTOO_CONF_TYPE_IFCONFIG) {
// FIXME: find the correct command
snprintf (buf, 100, "/bin/false");
} else {
snprintf (buf, 100, "/bin/false");
}
nm_spawn_process (buf);
}
/*
* nm_system_enable_loopback
*
* Bring up the loopback interface
*
*/
void nm_system_enable_loopback (void)
{
if (nm_system_gentoo_conf_type == GENTOO_CONF_TYPE_IPROUTE) {
nm_spawn_process ("/sbin/ip link set dev lo up");
nm_spawn_process ("/sbin/ip addr add 127.0.0.1/8 brd 127.255.255.255 dev lo label loopback");
} else if (nm_system_gentoo_conf_type == GENTOO_CONF_TYPE_IFCONFIG) {
nm_spawn_process ("/sbin/ifconfig lo 127.0.0.1 up");
nm_spawn_process ("/sbin/route add -net 127.0.0.0 netmask 255.0.0.0 gw 127.0.0.1 dev lo");
}
}
/*
* nm_system_delete_default_route
*
* Remove the old default route in preparation for a new one
*
*/
void nm_system_delete_default_route (void)
{
if (nm_system_gentoo_conf_type == GENTOO_CONF_TYPE_IPROUTE) {
nm_spawn_process ("/sbin/ip route del default");
} else if (nm_system_gentoo_conf_type == GENTOO_CONF_TYPE_IFCONFIG) {
nm_spawn_process ("/sbin/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 -q dhcpcd");
}
/*
* nm_system_update_dns
*
* Make glibc/nscd aware of any changes to the resolv.conf file by
* restarting nscd. Only restart if already running.
*
*/
void nm_system_update_dns (void)
{
if(nm_spawn_process ("/etc/init.d/nscd status"))
nm_spawn_process ("/etc/init.d/nscd restart");
}
/*
* nm_system_load_device_modules
*
* Loads any network adapter kernel modules, these should already be loaded
* by /etc/modules.autoload.d/kernel-2.x
*
*/
void nm_system_load_device_modules (void)
{
}

View File

@@ -27,6 +27,16 @@
#include "NetworkManagerDevice.h" #include "NetworkManagerDevice.h"
/*
* nm_system_init
*
* Initializes the distribution-specific system backend
*
*/
void nm_system_init (void)
{
}
/* /*
* nm_system_device_run_dhcp * nm_system_device_run_dhcp
* *

View File

@@ -28,6 +28,8 @@
/* Prototypes for system/distribution dependent functions */ /* Prototypes for system/distribution dependent functions */
void nm_system_init (void);
gboolean nm_system_device_run_dhcp (NMDevice *dev); gboolean nm_system_device_run_dhcp (NMDevice *dev);
void nm_system_device_stop_dhcp (NMDevice *dev); void nm_system_device_stop_dhcp (NMDevice *dev);