1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-23 06:37:59 +01:00

Fix bug where interface name was being passed to the dhcp client executable twice.

Tweak connect/disconnect to not kill any processes.  Instead it releases leases and terminates the wpa_supplicant instance through its ctrl interface.  This should make wicd handle multiple connections better.
This commit is contained in:
Dan O'Reilly
2009-02-06 19:26:09 -05:00
parent cbbf438f34
commit 450677c83d
5 changed files with 66 additions and 45 deletions

View File

@@ -445,6 +445,12 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
cmd = 'wpa_cli -i' + self.iface + ' scan' cmd = 'wpa_cli -i' + self.iface + ' scan'
misc.Run(cmd) misc.Run(cmd)
def StopWPA(self):
""" Terminates wpa using wpa_cli"""
cmd = 'wpa_cli -i %s terminate' % self.iface
if self.verbose: print cmd
misc.Run(cmd)
def GetBSSID(self, iwconfig=None): def GetBSSID(self, iwconfig=None):
""" Get the MAC address for the interface. """ """ Get the MAC address for the interface. """
if not iwconfig: if not iwconfig:

View File

@@ -273,7 +273,11 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
print "GetNetworks caught an exception: %s" % e print "GetNetworks caught an exception: %s" % e
return [] return []
results = self.scan_iface.Scan() try:
results = self.scan_iface.Scan()
except iwscan.error, e:
print "ERROR: %s"
return []
return filter(None, [self._parse_ap(cell) for cell in results]) return filter(None, [self._parse_ap(cell) for cell in results])
def _parse_ap(self, cell): def _parse_ap(self, cell):
@@ -334,6 +338,18 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
return ap return ap
def _connect_to_wpa_ctrl_iface(self):
""" Connect to the wpa ctrl interface. """
ctrl_iface = '/var/run/wpa_supplicant'
try:
socket = [os.path.join(ctrl_iface, s) \
for s in os.listdir(ctrl_iface) if s == self.iface][0]
except OSError, error:
print error
return None
return wpactrl.WPACtrl(socket)
def ValidateAuthentication(self, auth_time): def ValidateAuthentication(self, auth_time):
""" Validate WPA authentication. """ Validate WPA authentication.
@@ -359,15 +375,10 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
if self.wpa_driver == RALINK_DRIVER: if self.wpa_driver == RALINK_DRIVER:
return True return True
ctrl_iface = '/var/run/wpa_supplicant' wpa = self._connect_to_wpa_ctrl_iface()
try: if not wpa:
socket = [os.path.join(ctrl_iface, s) \ print "Failed to open ctrl interface"
for s in os.listdir(ctrl_iface) if s == self.iface][0] return False
except OSError:
print error
return True
wpa = wpactrl.WPACtrl(socket)
MAX_TIME = 35 MAX_TIME = 35
MAX_DISCONNECTED_TIME = 3 MAX_DISCONNECTED_TIME = 3
@@ -403,6 +414,13 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
print 'wpa_supplicant authentication may have failed.' print 'wpa_supplicant authentication may have failed.'
return False return False
def StopWPA(self):
""" Terminates wpa_supplicant using its ctrl interface. """
wpa = self._connect_to_wpa_ctrl_iface()
if not wpa:
return
wpa.request("TERMINATE")
def _AuthenticateRalinkLegacy(self, network): def _AuthenticateRalinkLegacy(self, network):
""" Authenticate with the specified wireless network. """ Authenticate with the specified wireless network.

View File

@@ -151,11 +151,11 @@ class Controller(object):
self.iface = None self.iface = None
self.backend_manager = BackendManager() self.backend_manager = BackendManager()
def get_debug(self): return self._debug
def set_debug(self, value): def set_debug(self, value):
self._debug = value self._debug = value
if self.iface: if self.iface:
self.iface.SetDebugMode(value) self.iface.SetDebugMode(value)
def get_debug(self): return self._debug
debug = property(get_debug, set_debug) debug = property(get_debug, set_debug)
def set_dhcp_client(self, value): def set_dhcp_client(self, value):
@@ -187,10 +187,6 @@ class Controller(object):
else: else:
return True return True
def StopDHCP(self):
""" Stops all running DHCP clients. """
return BACKEND.StopDHCP()
def GetIP(self, ifconfig=""): def GetIP(self, ifconfig=""):
""" Get the IP of the interface. """ Get the IP of the interface.
@@ -208,9 +204,14 @@ class Controller(object):
misc.ExecuteScript(expand_script_macros(self.disconnect_script, 'disconnection', *args)) misc.ExecuteScript(expand_script_macros(self.disconnect_script, 'disconnection', *args))
iface.ReleaseDHCP() iface.ReleaseDHCP()
iface.SetAddress('0.0.0.0') iface.SetAddress('0.0.0.0')
iface.FlushRoutes()
iface.Down() iface.Down()
iface.Up() iface.Up()
def ReleaseDHCP(self):
""" Release the DHCP lease for this interface. """
return self.iface.ReleaseDHCP()
def IsUp(self): def IsUp(self):
""" Calls the IsUp method for the wired interface. """ Calls the IsUp method for the wired interface.
@@ -435,12 +436,6 @@ class ConnectThread(threading.Thread):
print "Releasing DHCP leases..." print "Releasing DHCP leases..."
iface.ReleaseDHCP() iface.ReleaseDHCP()
@abortable
def stop_dhcp_clients(self, iface):
""" Stop and running DHCP clients. """
print 'Stopping DHCP clients'
BACKEND.StopDHCP()
def connect_aborted(self, reason): def connect_aborted(self, reason):
""" Sets the thread status to aborted. """ """ Sets the thread status to aborted. """
if self.abort_reason: if self.abort_reason:
@@ -643,8 +638,8 @@ class Wireless(Controller):
""" """
wiface = self.wiface wiface = self.wiface
print 'Creating ad-hoc network' print 'Creating ad-hoc network'
print 'Killing dhclient and wpa_supplicant' print 'Stopping dhcp client and wpa_supplicant'
BACKEND.StopDHCP() BACKEND.ReleaseDHCP()
wiface.StopWPA() wiface.StopWPA()
print 'Putting wireless interface down' print 'Putting wireless interface down'
wiface.Down() wiface.Down()
@@ -761,7 +756,6 @@ class WirelessConnectThread(ConnectThread):
self.put_iface_down(wiface) self.put_iface_down(wiface)
self.release_dhcp_clients(wiface) self.release_dhcp_clients(wiface)
self.reset_ip_addresses(wiface) self.reset_ip_addresses(wiface)
self.stop_dhcp_clients(wiface)
self.stop_wpa(wiface) self.stop_wpa(wiface)
self.flush_routes(wiface) self.flush_routes(wiface)
@@ -971,7 +965,6 @@ class WiredConnectThread(ConnectThread):
self.put_iface_down(liface) self.put_iface_down(liface)
self.release_dhcp_clients(liface) self.release_dhcp_clients(liface)
self.reset_ip_addresses(liface) self.reset_ip_addresses(liface)
self.stop_dhcp_clients(liface)
self.flush_routes(liface) self.flush_routes(liface)
# Bring up interface. # Bring up interface.

View File

@@ -379,12 +379,12 @@ class WicdDaemon(dbus.service.Object):
print 'canceling connection attempt' print 'canceling connection attempt'
if self.wifi.connecting_thread: if self.wifi.connecting_thread:
self.wifi.connecting_thread.should_die = True self.wifi.connecting_thread.should_die = True
self.wifi.StopDHCP() self.wifi.ReleaseDHCP()
self.wifi.StopWPA() self.wifi.StopWPA()
self.wifi.connecting_thread.connect_result = 'aborted' self.wifi.connecting_thread.connect_result = 'aborted'
if self.wired.connecting_thread: if self.wired.connecting_thread:
self.wired.connecting_thread.should_die = True self.wired.connecting_thread.should_die = True
self.wired.StopDHCP() self.wired.ReleaseDHCP()
self.wired.connecting_thread.connect_result = 'aborted' self.wired.connecting_thread.connect_result = 'aborted'
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')

View File

@@ -47,7 +47,7 @@ blacklist_strict = '!"#$%&\'()*+,./:;<=>?@[\\]^`{|}~ '
blacklist_norm = ";`$!*|><&\\" blacklist_norm = ";`$!*|><&\\"
blank_trans = maketrans("", "") blank_trans = maketrans("", "")
__all__ = ["SetDNS", "GetDefaultGateway", "GetWiredInterfaces", "StopDHCP", __all__ = ["SetDNS", "GetDefaultGateway", "GetWiredInterfaces",
"GetWirelessInterfaces", "IsValidWpaSuppDriver", "NeedsExternalCalls"] "GetWirelessInterfaces", "IsValidWpaSuppDriver", "NeedsExternalCalls"]
def _sanitize_string(string): def _sanitize_string(string):
@@ -107,11 +107,6 @@ def GetDefaultGateway():
print 'couldn\'t retrieve default gateway from route -n' print 'couldn\'t retrieve default gateway from route -n'
return gateway return gateway
def StopDHCP():
""" Stop the DHCP client. """
cmd = 'killall dhclient dhclient3 pump dhcpcd-bin'
misc.Run(cmd)
def GetWirelessInterfaces(): def GetWirelessInterfaces():
""" Get available wireless interfaces. """ Get available wireless interfaces.
@@ -455,7 +450,7 @@ class BaseInterface(object):
""" """
if not self.iface: return False if not self.iface: return False
cmd = "%s %s" % (self._get_dhcp_command('connect'), self.iface) cmd = self._get_dhcp_command('connect')
#cmd = self.DHCP_CMD + " " + self.iface #cmd = self.DHCP_CMD + " " + self.iface
if self.verbose: print cmd if self.verbose: print cmd
pipe = misc.Run(cmd, include_stderr=True, return_pipe=True) pipe = misc.Run(cmd, include_stderr=True, return_pipe=True)
@@ -471,20 +466,31 @@ class BaseInterface(object):
def ReleaseDHCP(self): def ReleaseDHCP(self):
""" Release the DHCP lease for this interface. """ """ Release the DHCP lease for this interface. """
if not self.iface: return False if not self.iface: return False
cmd = "%s %s" % (self._get_dhcp_command("release"), self.iface) cmd = self._get_dhcp_command("release")
#cmd = self.DHCP_RELEASE + " " + self.iface
if self.verbose: print cmd if self.verbose: print cmd
misc.Run(cmd) misc.Run(cmd)
def FlushRoutes(self): def DelDefaultRoute(self):
""" Flush all network routes. """ """ Delete only the default route for a device. """
if not self.iface: return False if not self.iface: return False
if self.ip_cmd and self.flush_tool in [misc.AUTO, misc.IP]: if self.ip_cmd and self.flush_tool in [misc.AUTO, misc.IP]:
#cmd = "ip route flush dev " + self.iface cmd = '%s route del default dev %s' % (self.ip_cmd, self.iface)
cmds = ['%s route flush all' % self.ip_cmd]
elif self.route_cmd and self.flush_tool in [misc.AUTO, misc.ROUTE]: elif self.route_cmd and self.flush_tool in [misc.AUTO, misc.ROUTE]:
cmds = ['%s del default' % self.route_cmd] cmd = '%s del default dev %s' % (self.route_cmd, self.iface)
cmds.append('route del dev %s' % self.iface) else:
print "No route manipulation command available!"
return
if self.verbose: print cmd
misc.Run(cmd)
def FlushRoutes(self):
""" Flush network routes for this device. """
if not self.iface: return False
if self.ip_cmd and self.flush_tool in [misc.AUTO, misc.IP]:
cmds = ['%s route flush dev %s' % (self.ip_cmd, self.iface)]
elif self.route_cmd and self.flush_tool in [misc.AUTO, misc.ROUTE]:
cmds = ['%s del dev %s' % (self.route_cmd, self.iface)]
else: else:
print "No flush command available!" print "No flush command available!"
cmds = [] cmds = []
@@ -583,9 +589,7 @@ class BaseWirelessInterface(BaseInterface):
def StopWPA(self): def StopWPA(self):
""" Stop wireless encryption. """ """ Stop wireless encryption. """
cmd = 'killall wpa_supplicant' raise NotImplementedError
if self.verbose: print cmd
misc.Run(cmd)
def GetKillSwitchStatus(self): def GetKillSwitchStatus(self):
""" Determines if the wireless killswitch is enabled. """ Determines if the wireless killswitch is enabled.