1
0
mirror of https://github.com/gryf/wicd.git synced 2026-01-09 07:14:13 +01:00

Add support in the daemon for setting hostnames in dhcpcd, pump, and udhcpc. No client support yet.

This commit is contained in:
Andrew Psaltis
2009-08-22 21:12:33 -04:00
parent 126a4e145e
commit 33ae33e660
3 changed files with 18 additions and 12 deletions

View File

@@ -22,6 +22,7 @@ class WiredConnectThread() -- Connection thread for wired
# Copyright (C) 2007 - 2009 Adam Blackburn # Copyright (C) 2007 - 2009 Adam Blackburn
# Copyright (C) 2007 - 2009 Dan O'Reilly # Copyright (C) 2007 - 2009 Dan O'Reilly
# Copyright (C) 2007 - 2009 Byron Hillis # Copyright (C) 2007 - 2009 Byron Hillis
# Copyright (C) 2009 Andrew Psaltis
# #
# 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 Version 2 as # it under the terms of the GNU General Public License Version 2 as
@@ -281,7 +282,8 @@ class ConnectThread(threading.Thread):
def __init__(self, network, interface_name, before_script, after_script, def __init__(self, network, interface_name, before_script, after_script,
pre_disconnect_script, post_disconnect_script, gdns1, pre_disconnect_script, post_disconnect_script, gdns1,
gdns2, gdns3, gdns_dom, gsearch_dom, iface, debug): gdns2, gdns3, gdns_dom, gsearch_dom, iface,
debug):
""" Initialise the required object variables and the thread. """ Initialise the required object variables and the thread.
Keyword arguments: Keyword arguments:
@@ -316,7 +318,7 @@ class ConnectThread(threading.Thread):
self.global_dns_3 = gdns3 self.global_dns_3 = gdns3
self.global_dns_dom = gdns_dom self.global_dns_dom = gdns_dom
self.global_search_dom = gsearch_dom self.global_search_dom = gsearch_dom
self.iface = iface self.iface = iface
self.connecting_message = None self.connecting_message = None
@@ -436,8 +438,8 @@ class ConnectThread(threading.Thread):
else: else:
# Run dhcp... # Run dhcp...
self.SetStatus('running_dhcp') self.SetStatus('running_dhcp')
print "Running DHCP" print "Running DHCP with hostname",self.network["dhcphostname"]
dhcp_status = iface.StartDHCP() dhcp_status = iface.StartDHCP(self.network["dhcphostname"])
if dhcp_status in ['no_dhcp_offers', 'dhcp_failed']: if dhcp_status in ['no_dhcp_offers', 'dhcp_failed']:
if self.connect_result != "aborted": if self.connect_result != "aborted":
self.abort_connection(dhcp_status) self.abort_connection(dhcp_status)
@@ -1028,7 +1030,8 @@ class WiredConnectThread(ConnectThread):
ConnectThread.__init__(self, network, wired, before_script, ConnectThread.__init__(self, network, wired, before_script,
after_script, pre_disconnect_script, after_script, pre_disconnect_script,
post_disconnect_script, gdns1, gdns2, post_disconnect_script, gdns1, gdns2,
gdns3, gdns_dom, gsearch_dom, liface, debug) gdns3, gdns_dom, gsearch_dom, liface,
debug)
def _connect(self): def _connect(self):
""" The main function of the connection thread. """ The main function of the connection thread.

View File

@@ -18,6 +18,7 @@ class WirelessDaemon() -- DBus interface to managed the wireless network.
# Copyright (C) 2007 - 2009 Adam Blackburn # Copyright (C) 2007 - 2009 Adam Blackburn
# Copyright (C) 2007 - 2009 Dan O'Reilly # Copyright (C) 2007 - 2009 Dan O'Reilly
# Copyright (C) 2007 - 2009 Byron Hillis # Copyright (C) 2007 - 2009 Byron Hillis
# Copyright (C) 2009 Andrew Psaltis
# #
# 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 Version 2 as # it under the terms of the GNU General Public License Version 2 as
@@ -1457,6 +1458,7 @@ class WiredDaemon(dbus.service.Object):
"postdisconnectscript"]: "postdisconnectscript"]:
self.config.set(profilename, option, None) self.config.set(profilename, option, None)
self.config.set(profilename, "default", default) self.config.set(profilename, "default", default)
self.config.set(profilename,"dhcphostname",os.uname()[1])
self.config.write() self.config.write()
return True return True

View File

@@ -16,6 +16,7 @@ class BaseWirelessInterface() -- Control a wireless network interface.
# Copyright (C) 2007 - 2009 Adam Blackburn # Copyright (C) 2007 - 2009 Adam Blackburn
# Copyright (C) 2007 - 2009 Dan O'Reilly # Copyright (C) 2007 - 2009 Dan O'Reilly
# Copyright (C) 2007 - 2009 Byron Hillis # Copyright (C) 2007 - 2009 Byron Hillis
# Copyright (C) 2009 Andrew Psaltis
# #
# 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 Version 2 as # it under the terms of the GNU General Public License Version 2 as
@@ -230,7 +231,7 @@ class BaseInterface(object):
return path return path
def _get_dhcp_command(self, flavor=None): def _get_dhcp_command(self, flavor=None, hostname=None):
""" Returns the correct DHCP client command. """ Returns the correct DHCP client command.
Given a type of DHCP request (create or release a lease), Given a type of DHCP request (create or release a lease),
@@ -266,17 +267,17 @@ class BaseInterface(object):
'id' : misc.DHCLIENT, 'id' : misc.DHCLIENT,
}, },
"pump" : "pump" :
{ 'connect' : r"%(cmd)s -i %(iface)s", { 'connect' : r"%(cmd)s -h '%(hostname)s' -i %(iface)s",
'release' : r"%(cmd)s -r -i %(iface)s", 'release' : r"%(cmd)s -r -i %(iface)s",
'id' : misc.PUMP, 'id' : misc.PUMP,
}, },
"dhcpcd" : "dhcpcd" :
{'connect' : r"%(cmd)s %(iface)s", {'connect' : r"%(cmd)s -h '%(hostname)s' %(iface)s ",
'release' : r"%(cmd)s -k %(iface)s", 'release' : r"%(cmd)s -k %(iface)s",
'id' : misc.DHCPCD, 'id' : misc.DHCPCD,
}, },
"udhcpc": "udhcpc":
{'connect' : r"%(cmd)s -n -i %(iface)s", {'connect' : r"%(cmd)s -H '%(hostname)s' -n -i %(iface)s",
'release' : r"killall -SIGUSR2 %(cmd)s", 'release' : r"killall -SIGUSR2 %(cmd)s",
'id' : misc.UDHCPC, 'id' : misc.UDHCPC,
}, },
@@ -287,7 +288,7 @@ class BaseInterface(object):
return "" return ""
if flavor == "connect": if flavor == "connect":
return client_dict[client_name]['connect'] % {"cmd":cmd, "iface":self.iface} return client_dict[client_name]['connect'] % {"cmd":cmd, "iface":self.iface, "hostname":hostname}
elif flavor == "release": elif flavor == "release":
return client_dict[client_name]['release'] % {"cmd":cmd, "iface":self.iface} return client_dict[client_name]['release'] % {"cmd":cmd, "iface":self.iface}
else: else:
@@ -538,7 +539,7 @@ class BaseInterface(object):
return 'dhcp_failed' return 'dhcp_failed'
@neediface(False) @neediface(False)
def StartDHCP(self): def StartDHCP(self,hostname):
""" Start the DHCP client to obtain an IP address. """ Start the DHCP client to obtain an IP address.
Returns: Returns:
@@ -546,7 +547,7 @@ class BaseInterface(object):
_check_dhcp_result for the possible values. _check_dhcp_result for the possible values.
""" """
cmd = self._get_dhcp_command('connect') cmd = self._get_dhcp_command('connect',hostname)
if self.verbose: print cmd if self.verbose: print cmd
self.dhcp_object = misc.Run(cmd, include_stderr=True, return_obj=True) self.dhcp_object = misc.Run(cmd, include_stderr=True, return_obj=True)
pipe = self.dhcp_object.stdout pipe = self.dhcp_object.stdout