def state_callback(state: str, action: str) -> None: if (state, action) == ("HOTSPOT", "start"): log.debug("Running iptables commands for HOTSPOT") run_cmds(end_cmds) run_cmds(start_cmds) if modemgr.get_mode() == modemgr.MULTI_MODE: run_cmds(appliance_clear) log.debug("Done with iptables commands for HOTSPOT") elif (state, action) == ("CONNECTED", "start"): log.debug("Running iptables commands for CONNECTED") run_cmds(end_cmds) if modemgr.get_mode() == modemgr.MULTI_MODE: run_cmds(appliance_clear) run_cmds(appliance_cmds) defaultdev: Optional[str] = routemgr.defroute_dev() apdev: str = modemgr.get_ap_device().Interface if defaultdev and defaultdev != apdev: run_cmds([ "iptables -w -t nat -I COMITUP-FWD -o " "{} -j MASQUERADE".format(defaultdev) ], ) log.debug("Done with iptables commands for CONNECTED")
def connected_timeout(dummy: int) -> None: active_ssid: Optional[str] active_ssid = nm.get_active_ssid(modemgr.get_state_device("CONNECTED")) log.debug("connected_timeout comparing {} to {}".format( connection, active_ssid)) if connection != active_ssid: log.warning("Connection lost on timeout") dev = modemgr.get_state_device("CONNECTED") set_state("CONNECTING", candidate_connections(dev)) if modemgr.get_mode() == modemgr.MULTI_MODE: wpa.check_wpa(modemgr.get_ap_device().Interface) active_ssid = nm.get_active_ssid(modemgr.get_state_device("HOTSPOT")) if not active_ssid: log.warning("Hotspot lost on timeout") set_state("HOTSPOT") defroute_devname: Optional[str] = routemgr.defroute_dev() ap_dev: NetworkManager.Device = modemgr.get_ap_device() link_dev: NetworkManager.Device = modemgr.get_link_device() if defroute_devname == nm.device_name(ap_dev): # default route is bad. Disconnect link and count on state # processing to restore log.error("AP is holding default route while CONNECTED, kicking") nm.disconnect(link_dev)
def state_callback(state, action): try: (fn_fact, svc_fact) = callmatrix[(state, action, modemgr.get_mode())] except KeyError: return fn_fact()(svc_fact())
def connected_timeout(): log.debug("states: Calling nm.get_active_ssid()") if connection != nm.get_active_ssid(modemgr.get_state_device('CONNECTED')): log.warning("Connection lost on timeout") set_state('HOTSPOT') if modemgr.get_mode() == modemgr.MULTI_MODE: wpa.check_wpa(modemgr.get_ap_device().Interface)
def get_info(conf, data): info = { 'version': pkg_resources.get_distribution("comitup").version, 'apname': expand_ap(conf.ap_name, data), 'hostnames': ';'.join(get_hosts(conf, data)), 'imode': modemgr.get_mode(), } return info
def get_info(self): info = { 'version': pkg_resources.get_distribution("comitup").version, 'basename': conf.base_name, 'id': data.id, 'hostnames': ';'.join(get_hosts(conf, data)), 'imode': modemgr.get_mode(), } return info
def connected_fail(reason: int) -> None: global startup log.warning("Connection lost") active_ssid: Optional[str] active_ssid = nm.get_active_ssid(modemgr.get_state_device("HOTSPOT")) if modemgr.get_mode() == modemgr.MULTI_MODE and not active_ssid: log.warning("Hotspot lost while CONNECTED") set_state("HOTSPOT") else: startup = True set_state("HOTSPOT")
def state_callback(state, action): if (state, action) == ('HOTSPOT', 'start'): log.debug("Running iptables commands for HOTSPOT") run_cmds(end_cmds) run_cmds(start_cmds) if modemgr.get_mode() == 'router': run_cmds(appliance_clear) log.debug("Done with iptables commands for HOTSPOT") elif (state, action) == ('CONNECTED', 'start'): log.debug("Running iptables commands for CONNECTING") run_cmds(end_cmds) if modemgr.get_mode() == 'router': run_cmds(appliance_clear) run_cmds(appliance_cmds) log.debug("Done with iptables commands for CONNECTING")
def get_info(conf: "Config", data: "persist") -> Dict[str, str]: if not conf or not data: sys.exit(1) info = { "version": pkg_resources.get_distribution("comitup").version, "apname": expand_ap(conf.ap_name, data.id), "hostnames": ";".join(get_hosts(conf, data)), "imode": modemgr.get_mode(), } return info
def hotspot_timeout(dummy: int) -> None: if iwscan.ap_conn_count() == 0 or modemgr.get_mode() != "single": log.debug("Periodic connection attempt") dev = modemgr.get_state_device("CONNECTED") conn_list: List[str] = candidate_connections(dev) if conn_list: set_state("CONNECTING", conn_list) else: log.info("No candidates - skipping CONNECTING scan") else: log.info("AP active - skipping CONNECTING scan") wpa.check_wpa(modemgr.get_ap_device().Interface)
def hotspot_timeout(): if iwscan.ap_conn_count() == 0 or modemgr.get_mode() != 'single': log.debug('Periodic connection attempt') dev = modemgr.get_state_device('CONNECTED') conn_list = candidate_connections(dev) if conn_list: set_state('CONNECTING', conn_list) else: log.info('No candidates - skipping CONNECTING scan') else: log.info('AP active - skipping CONNECTING scan') wpa.check_wpa(modemgr.get_ap_device().Interface)
def hotspot_timeout(): if iwscan.ap_conn_count() == 0 or modemgr.get_mode() != 'single': log.debug('Periodic connection attempt') dev = modemgr.get_state_device('CONNECTED') conn_list = candidate_connections(dev) if conn_list: # bug - try the first connection twice set_state('CONNECTING', [conn_list[0], conn_list[0]] + conn_list) else: set_state('CONNECTING') else: log.info('AP active - skipping CONNECTING scan')
def state_monitor(): # NetworkManager is crashing on the first call to attach. In two # interface mode, this leaves the hotspot interface with no IP # configuration. Detect this and recover if com_state != 'HOTSPOT': if modemgr.get_mode() == modemgr.MULTI_MODE: log.debug("state_monitor: Calling nm.get_active_ip()") ip = nm.get_active_ip(modemgr.get_state_device('HOTSPOT')) if not ip: log.warn("Hotspot lost IP configuration - resetting") hs_ssid = dns_to_conn(dns_names[0]) activate_connection(hs_ssid, 'HOTSPOT') # Keep this periodic task running return True
def hotspot_start(dummy: int) -> None: global conn_list log.info("Activating hotspot") if startup: mdns.clear_entries() mdns.add_hosts(dns_names) hs_ssid: str = dns_to_conn(dns_names[0]) if startup and modemgr.get_mode() == modemgr.SINGLE_MODE: log.debug("Passing on hotspot connection for now") timeout_add(100, fake_hs_pass, state_id) elif hs_ssid != nm.get_active_ssid(modemgr.get_state_device("HOTSPOT")): conn_list = [] log.debug("Activating connection {}".format(hs_ssid)) activate_connection(hs_ssid, "HOTSPOT") else: log.debug("Didn't need to reactivate - already running") # the connect callback won't happen - let's 'pass' manually timeout_add(100, fake_hs_pass, state_id)