def init_func(self, creator_fd, gw_configs, enable_ipv6=False): """ :param creator_fd: :param tunnel_ip: 隧道IPV4或者IPV6地址 :param gw_configs: :param enable_ipv6:是否开启ipv6支持 :return: """ dgram_proxy_subnet, prefix = utils.extract_subnet_info( gw_configs["dgram_proxy_subnet"]) dgram_proxy_subnet6, prefix6 = utils.extract_subnet_info( gw_configs["dgram_proxy_subnet6"]) dev_path = "/dev/%s" % fdsl_ctl.FDSL_DEV_NAME fileno = os.open(dev_path, os.O_RDONLY) subnet = utils.calc_subnet(dgram_proxy_subnet, prefix, is_ipv6=False) subnet6 = utils.calc_subnet(dgram_proxy_subnet6, prefix6, is_ipv6=True) byte_subnet = socket.inet_aton(subnet) byte_subnet6 = socket.inet_pton(socket.AF_INET6, subnet6) r = fdsl_ctl.set_udp_proxy_subnet(fileno, byte_subnet, prefix, False) if enable_ipv6: r = fdsl_ctl.set_udp_proxy_subnet(fileno, byte_subnet6, prefix, True) self.__tunnel_fd = creator_fd self.set_fileno(fileno) self.register(self.fileno) self.add_evt_read(self.fileno) return self.fileno
def init_func(self, creator_fd, gw_configs, enable_ipv6=False): """ :param creator_fd: :param tunnel_ip: 隧道IPV4或者IPV6地址 :param gw_configs: :param enable_ipv6:是否开启ipv6支持 :return: """ dgram_proxy_subnet, prefix = utils.extract_subnet_info(gw_configs["dgram_proxy_subnet"]) dgram_proxy_subnet6, prefix6 = utils.extract_subnet_info(gw_configs["dgram_proxy_subnet6"]) dev_path = "/dev/%s" % fdsl_ctl.FDSL_DEV_NAME fileno = os.open(dev_path, os.O_RDONLY) subnet = utils.calc_subnet(dgram_proxy_subnet, prefix, is_ipv6=False) subnet6 = utils.calc_subnet(dgram_proxy_subnet6, prefix6, is_ipv6=True) byte_subnet = socket.inet_aton(subnet) byte_subnet6 = socket.inet_pton(socket.AF_INET6, subnet6) r = fdsl_ctl.set_udp_proxy_subnet(fileno, byte_subnet, prefix, False) if enable_ipv6: r = fdsl_ctl.set_udp_proxy_subnet(fileno, byte_subnet6, prefix, True) self.__tunnel_fd = creator_fd self.set_fileno(fileno) self.register(self.fileno) self.add_evt_read(self.fileno) return self.fileno
def init_func(self, debug, configs, enable_nat_module=False): self.create_poll() self.__configs = configs self.__debug = debug self.__ip6_dgram = {} self.__dgram_proxy = {} self.__ip4_fragment = {} self.__enable_nat_module = enable_nat_module if enable_nat_module: self.__load_nat_module() signal.signal(signal.SIGINT, self.__exit) signal.signal(signal.SIGUSR1, self.__handle_user_change_signal) conn_config = self.__configs["connection"] mod_name = "freenet.access.%s" % conn_config["access_module"] try: access = importlib.import_module(mod_name) except ImportError: print("cannot found access module") sys.exit(-1) crypto_mod_name = conn_config["crypto_module"] tcp_crypto = "freenet.lib.crypto.%s.%s_tcp" % (crypto_mod_name, crypto_mod_name) udp_crypto = "freenet.lib.crypto.%s.%s_udp" % (crypto_mod_name, crypto_mod_name) crypto_configfile = "%s/fdslight_etc/%s" % ( BASE_DIR, conn_config["crypto_configfile"]) try: self.__tcp_crypto = importlib.import_module(tcp_crypto) self.__udp_crypto = importlib.import_module(udp_crypto) except ImportError: print("cannot found tcp or udp crypto module") sys.exit(-1) if not os.path.isfile(crypto_configfile): print("cannot found crypto configfile") sys.exit(-1) try: self.__crypto_configs = proto_utils.load_crypto_configfile( crypto_configfile) except: print("crypto configfile should be json file") sys.exit(-1) enable_ipv6 = bool(int(conn_config["enable_ipv6"])) listen_port = int(conn_config["listen_port"]) conn_timeout = int(conn_config["conn_timeout"]) listen_ip = conn_config["listen_ip"] listen_ip6 = conn_config["listen_ip6"] listen = ( listen_ip, listen_port, ) listen6 = (listen_ip6, listen_port) over_http = bool(int(conn_config["tunnel_over_http"])) if enable_ipv6: self.__tcp6_fileno = self.create_handler(-1, tunnels.tcp_tunnel, listen6, self.__tcp_crypto, self.__crypto_configs, conn_timeout=conn_timeout, is_ipv6=True, over_http=over_http) self.__udp6_fileno = self.create_handler(-1, tunnels.udp_tunnel, listen6, self.__udp_crypto, self.__crypto_configs, is_ipv6=True) self.__tcp_fileno = self.create_handler(-1, tunnels.tcp_tunnel, listen, self.__tcp_crypto, self.__crypto_configs, conn_timeout=conn_timeout, is_ipv6=False, over_http=over_http) self.__udp_fileno = self.create_handler(-1, tunnels.udp_tunnel, listen, self.__udp_crypto, self.__crypto_configs, is_ipv6=False) self.__tundev_fileno = self.create_handler(-1, tundev.tundevs, self.__DEVNAME) self.__raw_fileno = self.create_handler(-1, traffic_pass.ip4_raw_send) self.__access = access.access(self) self.__mbuf = utils.mbuf() nat_config = configs["nat"] try: self.__ip4_mtu = int(nat_config["p2p_mtu"]) except KeyError: self.__ip4_mtu = 1400 try: self.__ip6_mtu = int(nat_config["p2p6_mtu"]) except KeyError: self.__ip6_mtu = 1280 dns_addr = nat_config["dns"] if utils.is_ipv6_address(dns_addr): is_ipv6 = True else: is_ipv6 = False self.__dns_is_ipv6 = is_ipv6 self.__dns_addr = dns_addr self.__dns_fileno = self.create_handler(-1, dns_proxy.dnsd_proxy, dns_addr, is_ipv6=is_ipv6) enable_ipv6 = bool(int(nat_config["enable_nat66"])) subnet, prefix = utils.extract_subnet_info( nat_config["virtual_ip6_subnet"]) eth_name = nat_config["eth_name"] ip6_gw = nat_config["ip6_gw"] self.__ip6_udp_cone_nat = bool( int(nat_config.get("ip6_udp_cone_nat", 0))) if enable_ipv6: self.__nat6 = nat.nat(( subnet, prefix, ), is_ipv6=True) self.__enable_nat6 = True self.__config_gateway6(subnet, prefix, ip6_gw, eth_name) subnet, prefix = utils.extract_subnet_info( nat_config["virtual_ip_subnet"]) self.__nat4 = nat.nat(( subnet, prefix, ), is_ipv6=False) self.__config_gateway(subnet, prefix, eth_name) if not debug: sys.stdout = open(LOG_FILE, "a+") sys.stderr = open(ERR_FILE, "a+")
def init_func(self, debug, configs): self.create_poll() self.__configs = configs self.__debug = debug self.__ip6_dgram = {} self.__dgram_proxy = {} self.__ip4_fragment = {} signal.signal(signal.SIGINT, self.__exit) conn_config = self.__configs["connection"] mod_name = "freenet.access.%s" % conn_config["access_module"] try: access = importlib.import_module(mod_name) except ImportError: print("cannot found access module") sys.exit(-1) crypto_mod_name = conn_config["crypto_module"] tcp_crypto = "freenet.lib.crypto.%s.%s_tcp" % (crypto_mod_name, crypto_mod_name) udp_crypto = "freenet.lib.crypto.%s.%s_udp" % (crypto_mod_name, crypto_mod_name) crypto_configfile = "%s/fdslight_etc/%s" % (BASE_DIR, conn_config["crypto_configfile"]) try: self.__tcp_crypto = importlib.import_module(tcp_crypto) self.__udp_crypto = importlib.import_module(udp_crypto) except ImportError: print("cannot found tcp or udp crypto module") sys.exit(-1) if not os.path.isfile(crypto_configfile): print("cannot found crypto configfile") sys.exit(-1) try: self.__crypto_configs = proto_utils.load_crypto_configfile(crypto_configfile) except: print("crypto configfile should be json file") sys.exit(-1) enable_ipv6 = bool(int(conn_config["enable_ipv6"])) listen_port = int(conn_config["listen_port"]) conn_timeout = int(conn_config["conn_timeout"]) listen_ip = conn_config["listen_ip"] listen_ip6 = conn_config["listen_ip6"] listen = (listen_ip, listen_port,) listen6 = (listen_ip6, listen_port) if enable_ipv6: self.__tcp6_fileno = self.create_handler(-1, tunnels.tcp_tunnel, listen6, self.__tcp_crypto, self.__crypto_configs, conn_timeout=conn_timeout, is_ipv6=True) self.__udp6_fileno = self.create_handler(-1, tunnels.udp_tunnel, listen6, self.__udp_crypto, self.__crypto_configs, is_ipv6=True) self.__tcp_fileno = self.create_handler(-1, tunnels.tcp_tunnel, listen, self.__tcp_crypto, self.__crypto_configs, conn_timeout=conn_timeout, is_ipv6=False) self.__udp_fileno = self.create_handler(-1, tunnels.udp_tunnel, listen, self.__udp_crypto, self.__crypto_configs, is_ipv6=False) self.__tundev_fileno = self.create_handler(-1, tundev.tundevs, self.__DEVNAME) self.__raw_fileno = self.create_handler(-1, traffic_pass.ip4_raw_send) self.__access = access.access(self) self.__mbuf = utils.mbuf() nat_config = configs["nat"] try: self.__ip4_mtu = int(nat_config["p2p_mtu"]) except KeyError: self.__ip4_mtu = 1400 try: self.__ip6_mtu = int(nat_config["p2p6_mtu"]) except KeyError: self.__ip6_mtu = 1280 dns_addr = nat_config["dns"] if utils.is_ipv6_address(dns_addr): is_ipv6 = True else: is_ipv6 = False self.__dns_is_ipv6 = is_ipv6 self.__dns_addr = dns_addr self.__dns_fileno = self.create_handler(-1, dns_proxy.dnsd_proxy, dns_addr, is_ipv6=is_ipv6) enable_ipv6 = bool(int(nat_config["enable_nat66"])) subnet, prefix = utils.extract_subnet_info(nat_config["virtual_ip6_subnet"]) eth_name = nat_config["eth_name"] ip6_gw = nat_config["ip6_gw"] self.__ip6_udp_cone_nat = bool(int(nat_config.get("ip6_udp_cone_nat", 0))) if enable_ipv6: self.__nat6 = nat.nat((subnet, prefix,), is_ipv6=True) self.__enable_nat6 = True self.__config_gateway6(subnet, prefix, ip6_gw, eth_name) subnet, prefix = utils.extract_subnet_info(nat_config["virtual_ip_subnet"]) self.__nat4 = nat.nat((subnet, prefix,), is_ipv6=False) self.__config_gateway(subnet, prefix, eth_name) if not debug: sys.stdout = open(LOG_FILE, "a+") sys.stderr = open(ERR_FILE, "a+")
def init_func(self, debug, configs): self.create_poll() self.__configs = configs self.__debug = debug self.__ipfragments = {} self.__dgram_proxy = {} signal.signal(signal.SIGINT, self.__exit) conn_config = self.__configs["connection"] mod_name = "freenet.access.%s" % conn_config["access_module"] try: access = importlib.import_module(mod_name) except ImportError: print("cannot found access module") sys.exit(-1) crypto_mod_name = conn_config["crypto_module"] tcp_crypto = "freenet.lib.crypto.%s.%s_tcp" % (crypto_mod_name, crypto_mod_name) udp_crypto = "freenet.lib.crypto.%s.%s_udp" % (crypto_mod_name, crypto_mod_name) crypto_configfile = "./fdslight_etc/%s" % conn_config["crypto_configfile"] try: self.__tcp_crypto = importlib.import_module(tcp_crypto) self.__udp_crypto = importlib.import_module(udp_crypto) except ImportError: print("cannot found tcp or udp crypto module") sys.exit(-1) if not os.path.isfile(crypto_configfile): print("cannot found crypto configfile") sys.exit(-1) try: self.__crypto_configs = proto_utils.load_crypto_configfile(crypto_configfile) except: print("crypto configfile should be json file") sys.exit(-1) enable_ipv6 = bool(int(conn_config["enable_ipv6"])) tcp_port = int(conn_config["listen_tcp_port"]) udp_port = int(conn_config["listen_udp_port"]) conn_timeout = int(conn_config["conn_timeout"]) listen_ip = conn_config["listen_ip"] listen_ip6 = conn_config["listen_ip6"] listen_tcp = (listen_ip, tcp_port,) listen_udp = (listen_ip, udp_port,) listen6_tcp = (listen_ip6, tcp_port,) listen6_udp = (listen_ip6, udp_port,) if enable_ipv6: self.__tcp6_fileno = self.create_handler( -1, tunnels.tcp_tunnel, listen6_tcp, self.__tcp_crypto, self.__crypto_configs, conn_timeout=conn_timeout, is_ipv6=True ) self.__udp6_fileno = self.create_handler( -1, tunnels.udp_tunnel, listen6_udp, self.__udp_crypto, self.__crypto_configs, is_ipv6=True ) self.__tcp_fileno = self.create_handler( -1, tunnels.tcp_tunnel, listen_tcp, self.__tcp_crypto, self.__crypto_configs, conn_timeout=conn_timeout, is_ipv6=False ) self.__udp_fileno = self.create_handler( -1, tunnels.udp_tunnel, listen_udp, self.__udp_crypto, self.__crypto_configs, is_ipv6=False ) self.__tundev_fileno = self.create_handler( -1, tundev.tundevs, self.__DEVNAME ) self.__access = access.access(self) self.__mbuf = utils.mbuf() nat_config = configs["nat"] dns_addr = nat_config["dns"] if utils.is_ipv6_address(dns_addr): is_ipv6 = True else: is_ipv6 = False self.__dns_fileno = self.create_handler( -1, dns_proxy.dnsd_proxy, dns_addr, is_ipv6=is_ipv6 ) enable_ipv6 = bool(int(nat_config["enable_nat66"])) subnet, prefix = utils.extract_subnet_info(nat_config["virtual_ip6_subnet"]) eth_name = nat_config["eth_name"] ip6_gw = nat_config["ip6_gw"] if enable_ipv6: self.__nat6 = nat.nat((subnet, prefix,), is_ipv6=True) self.__enable_nat6 = True self.__config_gateway6(subnet, prefix, ip6_gw, eth_name) subnet, prefix = utils.extract_subnet_info(nat_config["virtual_ip_subnet"]) self.__nat4 = nat.nat((subnet, prefix,), is_ipv6=False) self.__config_gateway(subnet, prefix, eth_name) if not debug: sys.stdout = open(LOG_FILE, "a+") sys.stderr = open(ERR_FILE, "a+")