private void resolvePolicyIfNecessary(ByteBuffer buffer) {
        if (mPolicy != POLICY_INDETERMINATE) {
            // Resolved.
            return;
        }
        if (!buffer.hasRemaining()) {
            // Invalid buffer remaining, do nothing.
            return;
        }
        if (mSession.protocol != Protocol.TCP) {
            mPolicy = POLICY_ALLOWED;
            return;
        }

        // Now we verify the TCP protocol host
        String domain;
        if (isHttp(buffer)) {
            domain = parseHttpHost(buffer.array(), buffer.position(), buffer.remaining());
        } else {
            domain = parseHttpsHost(buffer.array(), buffer.position(), buffer.remaining());
        }
        if (domain == null) {
            // Maybe not http protocol.
            mPolicy = POLICY_ALLOWED;
            return;
        } else {
            mSession.host = domain;
        }
        NetBareConfig config = NetBare.get().getConfig();
        Set<String> allowedHost = new HashSet<>(config.allowedHosts);
        Set<String> disallowedHost = new HashSet<>(config.disallowedHosts);

        boolean isAllowedHostEmpty = allowedHost.isEmpty();
        boolean isDisallowedHostEmpty = disallowedHost.isEmpty();

        if (isAllowedHostEmpty && isDisallowedHostEmpty) {
            // No white and black list, it means allow everything.
            mPolicy = POLICY_ALLOWED;
            return;
        }

        if (!isDisallowedHostEmpty) {
            // Check domain hosts.
            for (String host : disallowedHost) {
                if (host.equals(domain)) {
                    // Denied host.
                    mPolicy = POLICY_DISALLOWED;
                    return;
                }
            }
            // Check ip hosts.
            for (String host : disallowedHost) {
                if (host.equals(NetBareUtils.convertIp(mSession.remoteIp))) {
                    // Denied host.
                    mPolicy = POLICY_DISALLOWED;
                    return;
                }
            }
        }

        if (!isAllowedHostEmpty) {
            for (String host : allowedHost) {
                if (host.equals(domain)) {
                    mPolicy = POLICY_ALLOWED;
                    return;
                }
            }
            for (String host : allowedHost) {
                if (host.equals(NetBareUtils.convertIp(mSession.remoteIp))) {
                    mPolicy = POLICY_ALLOWED;
                    return;
                }
            }
            mPolicy = POLICY_DISALLOWED;
        } else {
            mPolicy = POLICY_ALLOWED;
        }
    }
This policy doesn't allow data flow to configured virtual gateway.
netbare-core/src/main/java/com/github/megatronking/netbare/NetBareVirtualGateway.java