예제 #1
0
    def find(self, ippkt):
        if ippkt in self.__cache: return self.__cache[ippkt]

        tmp_dict = self.__tree
        t_net_v = utils.ip4b_2_number(ippkt)

        values = []
        _values = None

        for n in ippkt:
            if n not in tmp_dict:
                if "values" not in tmp_dict:
                    self.__add_to_cache(ippkt, from_wl=False)
                    return False
                _values = tmp_dict["values"]
                break
            values.append(n)
            tmp_dict = tmp_dict[n]

        is_find = False

        for m in _values:
            mask_v = 0
            for i in range(m): mask_v |= 1 << (31 - i)
            for t in _values[m]:
                subn = self.__get_subn(values, t)
                if t_net_v & mask_v == subn:
                    is_find = True
                    break
                ''''''
            ''''''
        self.__add_to_cache(ippkt, from_wl=is_find)

        return is_find
예제 #2
0
    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
예제 #3
0
    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
예제 #4
0
    def udp_timeout(self):
        if not self.__is_auth:
            self.print_access_log("not_get_server_response")
            self.dispatcher.ctunnel_fail()
            return
        self.__nat.recyle_ips()
        if not fnc_config.configs["udp_global"]: self.__udp_whitelist.recycle_cache()
        filter_ips = self.__timer.get_timeout_names()

        for ip in filter_ips:
            n = utils.ip4b_2_number(ip)
            fdsl_ctl.tf_record_del(self.__traffic_fetch_fd, n)
            if self.__timer.exists(ip): self.__timer.drop(ip)

        self.set_timeout(self.fileno, self.__TIMEOUT)
        # 尝试发送ping 5 次
        if self.__sent_ping_cnt < 5:
            self.__send_ping()
            return
        # 如果发送5次ping都没有响应,那么暂时取消会话
        self.__sent_ping_cnt = 0
        self.__handle_close()
예제 #5
0
 def tcp_timeout(self):
     self.__static_nat.recyle_ips()
     if not fnc_config.configs["udp_global"]: self.__udp_whitelist.recycle_cache()
     if not self.is_conn_ok():
         self.print_access_log("connect_failed")
         self.delete_handler(self.fileno)
         return
     if self.__is_sent_ping and self.__auth_ok:
         self.print_access_log("timeout")
         self.delete_handler(self.fileno)
         return
     if self.__auth_ok:
         self.set_timeout(self.fileno, self.__TIMEOUT)
         self.__is_sent_ping = True
         self.__send_ping()
         tunnel_ips = self.__timer.get_timeout_names()
         for ip in tunnel_ips:
             n = utils.ip4b_2_number(ip)
             fdsl_ctl.tf_record_del(self.__traffic_fetch_fd, n)
             if self.__timer.exists(ip): self.__timer.drop(ip)
         return
     self.print_access_log("auth_timeout")
     self.delete_handler(self.fileno)
예제 #6
0
    def udp_timeout(self):
        if not self.__is_auth:
            self.print_access_log("not_get_server_response")
            self.dispatcher.ctunnel_fail()
            return
        self.__nat.recyle_ips()
        if not fnc_config.configs["udp_global"]:
            self.__udp_whitelist.recycle_cache()
        filter_ips = self.__timer.get_timeout_names()

        for ip in filter_ips:
            n = utils.ip4b_2_number(ip)
            fdsl_ctl.tf_record_del(self.__traffic_fetch_fd, n)
            if self.__timer.exists(ip): self.__timer.drop(ip)

        self.set_timeout(self.fileno, self.__TIMEOUT)
        # 尝试发送ping 5 次
        if self.__sent_ping_cnt < 5:
            self.__send_ping()
            return
        # 如果发送5次ping都没有响应,那么暂时取消会话
        self.__sent_ping_cnt = 0
        self.__handle_close()
예제 #7
0
 def tcp_timeout(self):
     self.__static_nat.recyle_ips()
     if not fnc_config.configs["udp_global"]: self.__udp_whitelist.recycle_cache()
     if not self.is_conn_ok():
         self.print_access_log("connect_failed")
         self.delete_handler(self.fileno)
         return
     if self.__is_sent_ping and self.__auth_ok:
         self.print_access_log("timeout")
         self.delete_handler(self.fileno)
         return
     if self.__auth_ok:
         self.set_timeout(self.fileno, self.__TIMEOUT)
         self.__is_sent_ping = True
         self.__send_ping()
         tunnel_ips = self.__timer.get_timeout_names()
         for ip in tunnel_ips:
             n = utils.ip4b_2_number(ip)
             fdsl_ctl.tf_record_del(self.__traffic_fetch_fd, n)
             if self.__timer.exists(ip): self.__timer.drop(ip)
         return
     self.print_access_log("auth_timeout")
     self.delete_handler(self.fileno)
예제 #8
0
    def find(self, ippkt):
        if ippkt in self.__cache:
            return self.__cache[ippkt]

        tmp_dict = self.__tree
        t_net_v = utils.ip4b_2_number(ippkt)

        values = []
        _values = None

        for n in ippkt:
            if n not in tmp_dict:
                if "values" not in tmp_dict:
                    self.__add_to_cache(ippkt, from_wl=False)
                    return False
                _values = tmp_dict["values"]
                break
            values.append(n)
            tmp_dict = tmp_dict[n]

        is_find = False

        for m in _values:
            mask_v = 0
            for i in range(m):
                mask_v |= 1 << (31 - i)
            for t in _values[m]:
                subn = self.__get_subn(values, t)
                if t_net_v & mask_v == subn:
                    is_find = True
                    break
                """"""
            """"""
        self.__add_to_cache(ippkt, from_wl=is_find)

        return is_find