Beispiel #1
0
 void RouterContext::UpdateNTCPV6Address (const boost::asio::ip::address& host)
 {
     bool updated = false, found = false;    
     int port = 0;
     auto& addresses = m_RouterInfo.GetAddresses ();
     for (auto& addr : addresses)
     {
         if (addr.host.is_v6 () && addr.transportStyle == i2p::data::RouterInfo::eTransportNTCP)
         {
             if (addr.host != host)
             {
                 addr.host = host;
                 updated = true;
             }
             found = true;   
         }   
         else
             port = addr.port;   
     }   
     if (!found)
     {
         // create new address
         m_RouterInfo.AddNTCPAddress (host.to_string ().c_str (), port);
         auto mtu = i2p::util::net::GetMTU (host);
         if (mtu)
         {   
             LogPrint ("Our v6 MTU=", mtu);
             if (mtu > 1472) mtu = 1472; 
         }   
         m_RouterInfo.AddSSUAddress (host.to_string ().c_str (), port, GetIdentHash (), mtu ? mtu : 1472); // TODO
         updated = true;
     }
     if (updated)
         UpdateRouterInfo ();
 }
bool TcpProxyServer::GetRemoteAddressAndPort(boost::asio::ip::tcp::socket& clientSocket, boost::asio::ip::address& remoteAddress, unsigned short& remotePort)
{
	boost::asio::ip::tcp::socket::endpoint_type userAgentEnpoint = clientSocket.remote_endpoint();
    unsigned short userAgentPort = userAgentEnpoint.port();
	boost::asio::ip::address userAgentIP = userAgentEnpoint.address();
	if(userAgentIP != boost::asio::ip::address_v4::from_string("127.0.0.1")) {
		return false;
	}

	std::pair<u_long, USHORT> remoteAddressPair = WinsockHooker::GetRemoteAddressPair(userAgentPort);
	
	if(remoteAddressPair.first == 0ul) {
		return false;
	}

	boost::asio::ip::address_v4 remote_address(remoteAddressPair.first);
	unsigned short remote_port = remoteAddressPair.second;
	if(remote_address == boost::asio::ip::address_v4::from_string("127.0.0.1") && remote_port == listen_port)
	{
		return false;
	}
	remoteAddress = remote_address;
	remotePort = remote_port;

	TSINFO4CXX("Connect: IP:" << remoteAddress.to_string() << ", Port: " << remotePort);
	return true;
}
Beispiel #3
0
bool Server::IsBlockedAddress(const boost::asio::ip::address& address)
{
    BOOST_FOREACH(const auto& pattern, config_.blocking_address_patterns()) {
        if (network::Utils::MatchWithWildcard(pattern, address.to_string())) {
            return true;
        }
    }
    return false;
}
Beispiel #4
0
bool PeerID::Certificate::checkCommonNames(const boost::asio::ip::address& address) const
{
	std::string ipString = address.to_string();
	return checkCommonNames(
		[&ipString](char const * host, std::size_t len) -> bool
	{
		return boost::iequals(
			ipString,
			std::make_pair(host, host + len));
	});
}
Server::Server(const boost::asio::ip::address &address
		, short unsigned int &port
		, const std::string &docRoot
		, std::size_t threadCount)
	: mThreadCount(threadCount)
	, mAcceptor(mIoService)
	, mRequestHandler(docRoot)
	, mNewConnection(new Session(mIoService, mRequestHandler))
{
	// Open the acceptor with the option to reuse the address (i.e. SO_REUSEADDR).
	boost::asio::ip::tcp::resolver resolver(mIoService);
	boost::asio::ip::tcp::resolver::query query(address.to_string(), std::to_string(port));
	boost::asio::ip::tcp::endpoint endpoint = *resolver.resolve(query);
	mAcceptor.open(endpoint.protocol());
	mAcceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
	mAcceptor.bind(endpoint);
	mAcceptor.listen();
	mAcceptor.async_accept(mNewConnection->socket()
			, boost::bind(&Server::handleAccept, this, boost::asio::placeholders::error));
}
Beispiel #6
0
bool AccessControl::isWhiteListedNetwork(const boost::asio::ip::address& address) const
{
  boost::system::error_code ec;
  std::string ipAddress = address.to_string(ec);
  if (ec)
    return false;

  _packetCounterMutex.lock();
  for (std::set<std::string>::const_iterator iter = _networkWhiteList.begin();
    iter != _networkWhiteList.end(); iter++)
  {
    if (OSS::socket_address_cidr_verify(ipAddress, *iter))
    {
      _packetCounterMutex.unlock();
      return true;
    }
  }
  
  _packetCounterMutex.unlock();
  return false;
}
Beispiel #7
0
bool ClientAllowed(const boost::asio::ip::address& address)
{
    // Make sure that IPv4-compatible and IPv4-mapped IPv6 addresses are treated as IPv4 addresses
    if (address.is_v6()
     && (address.to_v6().is_v4_compatible()
      || address.to_v6().is_v4_mapped()))
        return ClientAllowed(address.to_v6().to_v4());

    if (address == asio::ip::address_v4::loopback()
     || address == asio::ip::address_v6::loopback()
     || (address.is_v4()
         // Check whether IPv4 addresses match 127.0.0.0/8 (loopback subnet)
      && (address.to_v4().to_ulong() & 0xff000000) == 0x7f000000))
        return true;

    const string strAddress = address.to_string();
    const vector<string>& vAllow = SysCfg().GetMultiArgs("-rpcallowip");
    for (auto strAllow : vAllow)
        if (WildcardMatch(strAddress, strAllow))
            return true;
    return false;
}
Beispiel #8
0
  void print()
  {
        show_route_protocol_short(inner.rtmsg_ptr->rtm_protocol);
        show_route_type_short(inner.rtmsg_ptr->rtm_type);
        show_route_scope_short(inner.rtmsg_ptr->rtm_scope);

        for(int i=0; i<indent;i++) printf(" ");
        printf(" %s/%d%s%s ===> ", addr.to_string().c_str(), inner.dest_mask, 
               strlen(inner.gateway) ? " via " : "", inner.gateway);

        rtattr_ptr = (struct rtattr *) RTM_RTA(inner.rtmsg_ptr);
        rtmsg_len = inner.rtmsg_len;

        for(; RTA_OK(rtattr_ptr, rtmsg_len); rtattr_ptr = RTA_NEXT(rtattr_ptr, rtmsg_len)) {
            const char * attr_name = attr_to_name_short(rtattr_ptr->rta_type);

            switch(rtattr_ptr->rta_type) {
              // te parametry już przetworzyliśmy
            case RTA_DST:
            case RTA_GATEWAY:
              break;

            case RTA_SRC:
            case RTA_PREFSRC:
            {
                char buf[128];
                inet_ntop(rtmsg_ptr->rtm_family, RTA_DATA(rtattr_ptr), buf, 128);
                printf("%s %s ", attr_name, buf);
            }
            break;

            case RTA_IIF:
            case RTA_OIF:
            {
                printf("%s %d ", attr_name, *((int *) RTA_DATA(rtattr_ptr)));
            }
            break;

            case RTA_TABLE:
              printf("%s", attr_name);
              show_route_table_short((enum rt_class_t)rtmsg_ptr->rtm_table);
              printf(" ");
                break;

            case RTA_UNSPEC:
            case RTA_PRIORITY:
            case RTA_METRICS:
            case RTA_MULTIPATH:
            case RTA_FLOW:
            case RTA_CACHEINFO:
            case RTA_MARK:
            case RTA_PROTOINFO:
            case RTA_SESSION:
            case RTA_MP_ALGO:
                printf("%s ", attr_name);
                break;

            default:
                printf("Unkown attribute ");
                break;

            }
        }

        printf("\n");
  }
int32_t TXMLProtocol::writeIPADDR(const boost::asio::ip::address& ipaddress) {
  return writePlain(ipaddress.to_string());
}