lokinet/llarp/net/net.hpp
Thomas Winget 4c630e0437 Large collection of changes to make android work
- Previous android java and jni code updated to work, but with much love
  still needed to make it work nicely, e.g. handling when the VPN is
  turned off.

- DNS handling refactored to allow android to intercept and handle DNS
  requests as we can't set the system DNS to use a high port
  (and apparently Chrome ignores system DNS settings anyway)

- add packet router structure to allow separate handling of specific
  intercepted traffic, e.g. UDP traffic to port 53 gets handled by our
  DNS handler rather than being naively forwarded as exit traffic.

- For now, android lokinet is exit-only and hard-coded to use exit.loki
  as its exit.  The exit will be configurable before release, but
  allowing to not use exit-only mode is more of a challenge.

- some old gitignore remnants which were matching to things we don't
  want them to (and are no longer relevant) removed

- some minor changes to CI configuration
2021-03-02 13:18:22 -05:00

99 lines
1.9 KiB
C++

#ifndef LLARP_NET_HPP
#define LLARP_NET_HPP
#include <net/uint128.hpp>
#include <net/address_info.hpp>
#include <net/ip_address.hpp>
#include <net/net_int.hpp>
#include <net/net.h>
#include <net/ip_range.hpp>
#include <util/mem.hpp>
#include <util/bits.hpp>
#include <functional>
#include <cstdlib> // for itoa
#include <vector>
// for addrinfo
#ifndef _WIN32
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#else
#include <winsock2.h>
#include <ws2tcpip.h>
#include <wspiapi.h>
#define inet_aton(x, y) inet_pton(AF_INET, x, y)
#endif
#ifndef _WIN32
#include <arpa/inet.h>
#endif
bool
operator==(const sockaddr& a, const sockaddr& b);
bool
operator==(const sockaddr_in& a, const sockaddr_in& b);
bool
operator==(const sockaddr_in6& a, const sockaddr_in6& b);
bool
operator<(const sockaddr_in6& a, const sockaddr_in6& b);
bool
operator<(const in6_addr& a, const in6_addr& b);
bool
operator==(const in6_addr& a, const in6_addr& b);
namespace llarp
{
bool
IsIPv4Bogon(const huint32_t& addr);
bool
IsBogon(const in6_addr& addr);
bool
IsBogon(const huint128_t addr);
bool
IsBogonRange(const in6_addr& host, const in6_addr& mask);
bool
AllInterfaces(int af, SockAddr& addr);
/// get first network interface with public address
bool
GetBestNetIF(std::string& ifname, int af = AF_INET);
/// look at adapter ranges and find a free one
std::optional<IPRange>
FindFreeRange();
/// look at adapter names and find a free one
std::optional<std::string>
FindFreeTun();
/// get network interface address for network interface with ifname
std::optional<SockAddr>
GetInterfaceAddr(const std::string& ifname, int af = AF_INET);
/// get an interface's ip6 address
std::optional<huint128_t>
GetInterfaceIPv6Address(std::string ifname);
#ifdef _WIN32
namespace net
{
std::optional<int>
GetInterfaceIndex(huint32_t ip);
}
#endif
} // namespace llarp
#endif