def set_tunnel_ip(self, tunnel_ip): if utils.is_ipv6_address(tunnel_ip): r = fdsl_ctl.set_tunnel(self.fileno, socket.inet_pton(socket.AF_INET6, tunnel_ip), True) else: r = fdsl_ctl.set_tunnel(self.fileno, socket.inet_aton(tunnel_ip), False) return
def connect_ok(self): # 可能目标主机不可达到 try: n = utils.ip4s_2_number(self.getpeername()[0]) except OSError: self.delete_handler(self.fileno) return self.__conn_time = time.time() self.print_access_log("connect_ok") if fngw_config.configs["udp_global"]: self.__traffic_fetch_fd = self.create_handler( self.fileno, traffic_pass.traffic_read) subnet, prefix = fngw_config.configs["udp_proxy_subnet"] subnet = utils.ip4b_2_number(socket.inet_aton(subnet)) fdsl_ctl.set_udp_proxy_subnet(self.__traffic_fetch_fd, subnet, chr(int(prefix)).encode()) fdsl_ctl.set_tunnel(self.__traffic_fetch_fd, n) self.set_timeout(self.fileno, self.__LOOP_TIMEOUT) self.register(self.fileno) self.add_evt_read(self.fileno) while 1: try: is_dns, msg = self.__wait_sent.pop(0) except IndexError: break if is_dns: self.__send_dns(msg) else: self.__send_data(msg) continue return
def __handle_auth_ok(self, session_id): self.__traffic_fetch_fd = self.create_handler(self.fileno, traffic_pass.traffic_read) n = utils.ip4s_2_number(self.__server_ipaddr) fdsl_ctl.set_tunnel(self.__traffic_fetch_fd, n) self.__is_auth = True self.dispatcher.ctunnel_ok() self.ctl_handler(self.fileno, self.__dns_fd, "as_tunnel_fd") self.ctl_handler(self.fileno, self.__dns_fd, "tunnel_open") self.ctl_handler(self.fileno, self.__dns_fd, "set_filter_dev_fd", self.__traffic_fetch_fd) self.set_timeout(self.fileno, self.__TIMEOUT) return
def __init(self): if not fngw_config.configs["udp_global"]: return self.__traffic_fetch_fd = self.create_handler( self.fileno, traffic_pass.traffic_read) n = utils.ip4s_2_number(self.__server_ipaddr) subnet, prefix = fngw_config.configs["udp_proxy_subnet"] subnet = utils.ip4b_2_number(socket.inet_aton(subnet)) fdsl_ctl.set_udp_proxy_subnet(self.__traffic_fetch_fd, subnet, chr(int(prefix)).encode()) fdsl_ctl.set_tunnel(self.__traffic_fetch_fd, n) return
def __handle_auth_ok(self): self.__auth_ok = True self.print_access_log("auth_ok") self.__traffic_fetch_fd = self.create_handler(self.fileno, traffic_pass.traffic_read) self.set_timeout(self.fileno, self.__TIMEOUT) n = utils.ip4s_2_number(self.getpeername()[0]) fdsl_ctl.set_tunnel(self.__traffic_fetch_fd, n) self.dispatcher.ctunnel_ok() self.ctl_handler(self.fileno, self.__dns_fd, "as_tunnel_fd") self.ctl_handler(self.fileno, self.__dns_fd, "tunnel_open") self.ctl_handler(self.fileno, self.__dns_fd, "set_filter_dev_fd", self.__traffic_fetch_fd) self.set_timeout(self.fileno, self.__TIMEOUT)
def __handle_auth_ok(self, session_id): self.__traffic_fetch_fd = self.create_handler( self.fileno, traffic_pass.traffic_read) n = utils.ip4s_2_number(self.__server_ipaddr) fdsl_ctl.set_tunnel(self.__traffic_fetch_fd, n) self.__is_auth = True self.dispatcher.ctunnel_ok() self.ctl_handler(self.fileno, self.__dns_fd, "as_tunnel_fd") self.ctl_handler(self.fileno, self.__dns_fd, "tunnel_open") self.ctl_handler(self.fileno, self.__dns_fd, "set_filter_dev_fd", self.__traffic_fetch_fd) self.set_timeout(self.fileno, self.__TIMEOUT) return