Patch from Matthew Garrett <mjg59@srcf.ucam.org> for adding

Debian support.

	* src/Makefile.am:
	* src/backends/NetworkManagerDebian.c: (nm_system_device_run_dhcp),
	(nm_system_device_stop_dhcp), (nm_system_device_flush_routes),
	(nm_system_device_flush_addresses), (nm_system_enable_loopback),
	(nm_system_delete_default_route),
	(nm_system_kill_all_dhcp_daemons), (nm_system_update_dns),
	(nm_system_load_device_modules):


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@66 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Seth Nickell
2004-08-25 21:07:19 +00:00
parent c085e3b6c8
commit 594d8393f3
3 changed files with 211 additions and 2 deletions

View File

@@ -1,3 +1,16 @@
2004-08-25 Seth Nickell <seth@gnome.org>
Patch from Matthew Garrett <mjg59@srcf.ucam.org> for adding
Debian support.
* src/Makefile.am:
* src/backends/NetworkManagerDebian.c: (nm_system_device_run_dhcp),
(nm_system_device_stop_dhcp), (nm_system_device_flush_routes),
(nm_system_device_flush_addresses), (nm_system_enable_loopback),
(nm_system_delete_default_route),
(nm_system_kill_all_dhcp_daemons), (nm_system_update_dns),
(nm_system_load_device_modules):
2004-08-24 Dan Willemsen <dan@willemsen.us>
* src/NetworkManager.c

View File

@@ -30,8 +30,10 @@ NetworkManager_SOURCES = \
backends/NetworkManagerSystem.h
EXTRA_NetworkManager_SOURCES = \
backends/NetworkManagerRedHat.c \
backends/NetworkManagerGentoo.c
backends/NetworkManagerDebian.c \
backends/NetworkManagerGentoo.c \
backends/NetworkManagerRedHat.c
NetworkManager_LDADD = $(NM_LIBS) $(IWLIB) $(OPENSSL_LIBS) backends/$(SYSTEM_BACKEND_FILE)

View File

@@ -0,0 +1,194 @@
/* NetworkManager -- Network link manager
*
* Matthew Garrett <mjg59@srcf.ucam.org>
*
* Heavily based on NetworkManagerRedhat.c by 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 Matthew Garrett
* (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 -pf /var/run/dhclient-%s.pid %s\n",
iface, iface);
printf("Running %s",buf);
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/ifup lo");
}
/*
* 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 ("/usr/sbin/invoke-rc.d nscd restart");
}
/*
* nm_system_load_device_modules
*
* This is a null op - all our drivers should already be loaded.
*
*/
void nm_system_load_device_modules (void)
{
return;
}