def kernelEvent(data): type, dir = data.split("@", 1) if not dir.startswith("/class/net/"): return devname = dir[11:] flag = 1 if type == "add": ifc = netutils.IF(devname) if ifc.isWireless(): return devuid = ifc.deviceUID() notify("Net.Link", "deviceChanged", ("add", "net", devuid, netutils.deviceName(devuid))) conns = DB.listDB() for conn in conns: dev = Dev(conn) if dev.ifc and dev.ifc.name == devname: if dev.state == "up": dev.up() return flag = 0 if flag: notify("Net.Link", "deviceChanged", ("new", "net", devuid, netutils.deviceName(devuid))) elif type == "remove": conns = DB.listDB() for conn in conns: dev = Dev(conn) # FIXME: dev.ifc is not enough :( if dev.ifc and dev.ifc.name == devname: if dev.state == "up": notify("Net.Link", "stateChanged", (dev.name, "inaccessible", "Device removed")) notify("Net.Link", "deviceChanged", ("removed", "net", devname, ""))
def kernelEvent(data): type, dir = data.split("@", 1) if not "/net/" in dir: return device = dir.split("/net/")[-1] new = True if type == "add": # Get device information ifc = netutils.IF(device) device_id = ifc.deviceUID() if not ifc.isWireless(): return # Notify clients notify("Network.Link", "deviceChanged", ("add", "wifi", device_id, netutils.deviceName(device_id))) # Bring related connection up for pn in listProfiles(): profile = Profile(pn) if profile.info.get("device", None) == device_id: new = False if profile.info.get("state", "down").startswith("unplugged"): setState(pn, "up") break # Notify clients if device has no connections if new: notify("Network.Link", "deviceChanged", ("new", "wifi", device_id, netutils.deviceName(device_id))) elif type == "remove": # Bring related connection down for pn in listProfiles(): profile = Profile(pn) if profile.info.get("device", "").split(":")[-1].split("_")[-1] == device: if profile.info.get("state", "down").startswith("up"): # Stop ifplug daemon plugService(device, "down", wireless=True) setState(pn, "unplugged") break # Notify clients notify("Network.Link", "deviceChanged", ("removed", "wifi", device, ""))
def plugService(device, state, wireless=False): # Do nothing if ifplugd is missing if not os.path.exists("/usr/sbin/ifplugd"): return if state == "up": # Do nothing if device is missing if not netutils.IF(device): return # Load service configuration config = loadConfig("/etc/conf.d/ifplugd") # Get arguments if wireless: args = config.get("IFPLUGD_WLAN_ARGS", "") else: args = config.get("IFPLUGD_ARGS", "") # Start service startService(command="/usr/sbin/ifplugd", args="%s -i %s" % (args, device), pidfile="/var/run/ifplugd.%s.pid" % device, detach=True, donotify=False) else: # Stop service stopService(pidfile="/var/run/ifplugd.%s.pid" % device, donotify=False)
#!/usr/bin/python import os from pardus import netutils as network action = os.environ.get("ACTION", None) devpath = os.environ.get("DEVPATH", None) ifc = network.IF(devpath.split("/")[-1]) if action in ["add", "remove"]: os.system('/usr/bin/hav call net_tools Network.Link kernelEvent "%s@%s"' % (action, devpath))
def isWireless(if_name): from pardus import netutils ifc = netutils.IF(if_name) if ifc.isWireless(): return True