From 3e14ff45285a8f7fcc4d270df927c58bbab0a9af Mon Sep 17 00:00:00 2001 From: dr7ana Date: Fri, 13 Dec 2024 10:47:09 -0800 Subject: [PATCH] squash --- llarp/address/ip_range.cpp | 38 +++-- llarp/address/ip_range.hpp | 58 +++++--- llarp/address/types.hpp | 10 +- llarp/address/utils.hpp | 8 +- llarp/config/config.hpp | 1 + llarp/ev/types.cpp | 14 +- llarp/ev/types.hpp | 4 +- llarp/handlers/session.cpp | 20 ++- llarp/handlers/session.hpp | 1 + llarp/handlers/tun.cpp | 10 +- llarp/handlers/tun.hpp | 2 +- llarp/link/link_manager.cpp | 25 ++-- llarp/messages/session.hpp | 23 +-- llarp/net/net.hpp | 7 +- llarp/net/traffic_policy.cpp | 1 + llarp/net/uint128.hpp | 269 ----------------------------------- llarp/nodedb.cpp | 12 +- llarp/path/path.cpp | 2 +- llarp/path/path_handler.cpp | 4 +- llarp/router/route_poker.cpp | 42 +++--- llarp/router/route_poker.hpp | 12 +- llarp/router/router.cpp | 2 + llarp/session/session.cpp | 20 +-- llarp/session/session.hpp | 12 +- llarp/vpn/linux.hpp | 72 +++++----- llarp/vpn/platform.hpp | 2 +- 26 files changed, 235 insertions(+), 436 deletions(-) delete mode 100644 llarp/net/uint128.hpp diff --git a/llarp/address/ip_range.cpp b/llarp/address/ip_range.cpp index 5ae5d47e53..0dd9506bb7 100644 --- a/llarp/address/ip_range.cpp +++ b/llarp/address/ip_range.cpp @@ -8,15 +8,15 @@ namespace llarp { if (_is_ipv4) { - _base_ip = _addr.to_ipv4().to_base(_mask); - _ip_range = ipv4_range{std::get(_base_ip), _mask}; - _max_ip = std::get(_ip_range).max_ip(); + _ip_net = _addr.to_ipv4() % _mask; + _base_ip = _ipv4_range().ip; + _max_ip = _ipv4_net().max_ip(); } else { - _base_ip = _addr.to_ipv6().to_base(_mask); - _ip_range = ipv6_range{std::get(_base_ip), _mask}; - _max_ip = std::get(_ip_range).max_ip(); + _ip_net = _addr.to_ipv6() % _mask; + _base_ip = _ipv6_range().ip; + _max_ip = _ipv6_net().max_ip(); } } @@ -82,16 +82,34 @@ namespace llarp return is_ipv4() ? _contains(std::get(other)) : _contains(std::get(other)); } + bool IPRange::contains(const ip_net_v& other) const + { + if (is_ipv4() ^ std::holds_alternative(other)) + return false; + + return is_ipv4() ? _contains(std::get(other).to_range().ip) + : _contains(std::get(other).to_range().ip); + } + + ip_v IPRange::net_ip() const + { + if (is_ipv4()) + return _ipv4_net().ip; + return _ipv6_net().ip; + } + std::optional IPRange::find_private_range(const std::list& excluding, bool ipv6_enabled) { if (excluding.empty()) return std::nullopt; - auto filter = [&excluding](const ip_range_v& range) -> bool { + auto filter = [&excluding](const ip_net_v& range) -> bool { for (const auto& e : excluding) - if (e == range) + { + if (e.contains(range)) return false; - log::debug(logcat, "{}", std::get(range).base); + } + log::trace(logcat, "{}", std::get(range).ip); return true; }; @@ -110,7 +128,7 @@ namespace llarp { for (size_t n = 0; n < num_ipv6_private; ++n) { - if (auto v6 = ipv6(0xfd2e, 0x6c6f, 0x6b69, n, 0x0000, 0x0000, 0x0000, 0x0001) / 64; filter(v6)) + if (auto v6 = ipv6(0xfd2e, 0x6c6f, 0x6b69, n, 0x0000, 0x0000, 0x0000, 0x0001) % 64; filter(v6)) return v6; } } diff --git a/llarp/address/ip_range.hpp b/llarp/address/ip_range.hpp index 101b01545c..fa3162f53e 100644 --- a/llarp/address/ip_range.hpp +++ b/llarp/address/ip_range.hpp @@ -14,12 +14,13 @@ namespace llarp struct IPRange { private: + ip_net_v _ip_net; + oxen::quic::Address _addr; uint8_t _mask; bool _is_ipv4; ip_v _base_ip; - ip_range_v _ip_range; ip_v _max_ip; void _init_ip(); @@ -29,10 +30,13 @@ namespace llarp bool _contains(const ipv6& other) const; // getters to DRY out variant access - ipv4_range& _ipv4_range() { return std::get(_ip_range); } - const ipv4_range& _ipv4_range() const { return std::get(_ip_range); } - ipv6_range& _ipv6_range() { return std::get(_ip_range); } - const ipv6_range& _ipv6_range() const { return std::get(_ip_range); } + ipv4_net& _ipv4_net() { return std::get(_ip_net); } + const ipv4_net& _ipv4_net() const { return std::get(_ip_net); } + ipv4_range _ipv4_range() const { return _ipv4_net().to_range(); } + + ipv6_net& _ipv6_net() { return std::get(_ip_net); } + const ipv6_net& _ipv6_net() const { return std::get(_ip_net); } + ipv6_range _ipv6_range() const { return _ipv6_net().to_range(); } public: IPRange() : IPRange{oxen::quic::Address{}, 0} {} @@ -44,21 +48,21 @@ namespace llarp _init_ip(); } - IPRange(const ipv4_range& ipv4) - : _addr{ipv4.base}, - _mask{ipv4.mask}, + IPRange(const ipv4_net& ipv4) + : _ip_net{ipv4}, + _addr{_ipv4_net().ip}, + _mask{_ipv4_net().mask}, _is_ipv4{true}, - _base_ip{ipv4.base}, - _ip_range{ipv4}, - _max_ip{ipv4.max_ip()} + _base_ip{_ipv4_range().ip}, + _max_ip{_ipv4_net().max_ip()} {} - IPRange(const ipv6_range& ipv6) - : _addr{ipv6.base}, + IPRange(const ipv6_net& ipv6) + : _ip_net{ipv6}, + _addr{ipv6.ip}, _mask{ipv6.mask}, _is_ipv4{false}, - _base_ip{ipv6.base}, - _ip_range{ipv6}, + _base_ip{ipv6.ip.to_base(_mask)}, _max_ip{ipv6.max_ip()} {} @@ -67,16 +71,19 @@ namespace llarp void bt_encode(oxenc::bt_list_producer& btlp) const { btlp.append(to_string()); } - std::string to_string() const { return is_ipv4() ? _ipv4_range().to_string() : _ipv6_range().to_string(); } + std::string to_string() const { return is_ipv4() ? _ipv4_net().to_string() : _ipv6_net().to_string(); } static std::optional from_string(std::string arg); bool contains(const IPRange& other) const; bool contains(const ip_v& other) const; + bool contains(const ip_net_v& other) const; bool is_ipv4() const { return _is_ipv4; } - ip_range_v get_ip_range() const { return _ip_range; } + ip_net_v get_ip_net() const { return _ip_net; } + + ip_v net_ip() const; ip_v base_ip() const { return _base_ip; } @@ -85,6 +92,11 @@ namespace llarp const uint8_t& mask() const { return _mask; } uint8_t mask() { return _mask; } + oxen::quic::Address base_address() const + { + return is_ipv4() ? oxen::quic::Address{_ipv4_range().ip} : oxen::quic::Address{_ipv6_range().ip}; + } + const oxen::quic::Address& address() const { return _addr; } oxen::quic::Address address() { return _addr; } @@ -98,12 +110,12 @@ namespace llarp return std::tie(_addr, _mask) == std::tie(other._addr, other._mask); } - bool operator==(const ip_range_v& other) const + bool operator==(const ip_net_v& other) const { - if (_is_ipv4 and std::holds_alternative(other)) - return _ipv4_range() == std::get(other); - if (not _is_ipv4 and std::holds_alternative(other)) - return _ipv6_range() == std::get(other); + if (_is_ipv4 and std::holds_alternative(other)) + return _ipv4_net() == std::get(other); + if (not _is_ipv4 and std::holds_alternative(other)) + return _ipv6_net() == std::get(other); return false; } @@ -165,7 +177,7 @@ namespace llarp IPRangeIterator() = default; IPRangeIterator(const IPRange& range) - : _ip_range{range}, _is_ipv4{range.is_ipv4()}, _current_ip{range.base_ip()}, _max_ip{range.max_ip()} + : _ip_range{range}, _is_ipv4{range.is_ipv4()}, _current_ip{range.net_ip()}, _max_ip{range.max_ip()} {} // Returns the next ip address in the iterating range; returns std::nullopt if range is exhausted diff --git a/llarp/address/types.hpp b/llarp/address/types.hpp index 3120423559..e7469084e2 100644 --- a/llarp/address/types.hpp +++ b/llarp/address/types.hpp @@ -9,9 +9,11 @@ namespace llarp using ipv4 = oxen::quic::ipv4; using ipv6 = oxen::quic::ipv6; using ip_v = std::variant; - using ipv4_range = oxen::quic::ipv4_net; - using ipv6_range = oxen::quic::ipv6_net; - using ip_range_v = std::variant; + using ipv4_range = oxen::quic::ipv4_range; + using ipv6_range = oxen::quic::ipv6_range; + using ipv4_net = oxen::quic::ipv4_net; + using ipv6_net = oxen::quic::ipv6_net; + using ip_net_v = std::variant; namespace concepts { @@ -19,7 +21,7 @@ namespace llarp concept IPType = std::is_same_v || std::is_same_v; template - concept IPRangeType = std::is_same_v || std::is_same_v; + concept IPRangeType = std::is_same_v || std::is_same_v; } // namespace concepts using KeyedAddress = oxen::quic::RemoteAddress; diff --git a/llarp/address/utils.hpp b/llarp/address/utils.hpp index df5c2f995a..62f9af20c4 100644 --- a/llarp/address/utils.hpp +++ b/llarp/address/utils.hpp @@ -108,15 +108,15 @@ namespace llarp inline constexpr size_t num_ipv4_private{272}; - inline constexpr std::array generate_private_ipv4() + inline constexpr std::array generate_private_ipv4() { - std::array ret{}; + std::array ret{}; for (size_t n = 16; n < 32; ++n) - ret[n - 16] = ipv4(172, n, 0, 1) / 16; + ret[n - 16] = ipv4(172, n, 0, 1) % 16; for (size_t n = 0; n < 256; ++n) - ret[n + 16] = ipv4(10, n, 0, 1) / 16; + ret[n + 16] = ipv4(10, n, 0, 1) % 16; return ret; } diff --git a/llarp/config/config.hpp b/llarp/config/config.hpp index f18953e382..485d16c446 100644 --- a/llarp/config/config.hpp +++ b/llarp/config/config.hpp @@ -191,6 +191,7 @@ namespace llarp // Used when in exit mode; pass down to LocalEndpoint // std::set _routed_ranges; // moved into traffic_policy! + // TESTNET: move into ExitConfig! bool enable_route_poker; bool blackhole_routes; diff --git a/llarp/ev/types.cpp b/llarp/ev/types.cpp index af5ff1be02..cd3b807115 100644 --- a/llarp/ev/types.cpp +++ b/llarp/ev/types.cpp @@ -92,7 +92,7 @@ namespace llarp } log::info(logcat, "EventTrigger resuming callback iteration..."); - self->begin(); + self->start(); } catch (const std::exception& e) { @@ -103,7 +103,7 @@ namespace llarp if (start_immediately) { - auto rv = begin(); + auto rv = start(); log::debug(logcat, "EventTrigger started {}successfully!", rv ? "" : "un"); } } @@ -134,7 +134,7 @@ namespace llarp event_add(ev.get(), &_null_tv); } - bool EventTrigger::halt() + bool EventTrigger::stop() { _is_cooling_down = false; _is_iterating = false; @@ -147,7 +147,7 @@ namespace llarp return ret; } - bool EventTrigger::begin() + bool EventTrigger::start() { _is_cooling_down = false; _is_iterating = true; @@ -197,20 +197,20 @@ namespace llarp }, this)); - log::debug(logcat, "Linux poller configured to watch FD: {}", fd); + log::debug(logcat, "Linux poller configured to watch FD {}", fd); } bool LinuxPoller::start() { auto rv = event_add(ev.get(), nullptr) == 0; - log::info(logcat, "Linux poller {} watching FD: {}", rv ? "successfully began" : "failed to start", fd); + log::info(logcat, "Linux poller {} watching FD {}", rv ? "successfully began" : "failed to start", fd); return rv; } bool LinuxPoller::stop() { auto rv = event_del(ev.get()); - log::info(logcat, "Linux poller {} watching FD: {}", rv ? "successfully stopped" : "failed to stop", fd); + log::info(logcat, "Linux poller {} watching FD {}", rv ? "successfully stopped" : "failed to stop", fd); return rv; } } // namespace llarp diff --git a/llarp/ev/types.hpp b/llarp/ev/types.hpp index 6638a063ef..558678086b 100644 --- a/llarp/ev/types.hpp +++ b/llarp/ev/types.hpp @@ -62,10 +62,10 @@ namespace llarp ~EventTrigger(); // Resumes iterative execution after successfully cooling down or being signalled to stop by the callback - bool begin(); + bool start(); // Called by the passed callback to signal that the iterative invocation should STOP - bool halt(); + bool stop(); private: // Invokes the function `f`, incrementing `::current` up to `n` before cooling down diff --git a/llarp/handlers/session.cpp b/llarp/handlers/session.cpp index c3383527de..7699bf2538 100644 --- a/llarp/handlers/session.cpp +++ b/llarp/handlers/session.cpp @@ -162,7 +162,7 @@ namespace llarp::handlers // _router.loop()->call_later(5s, [this]() { // try // { - // RouterID cpk{oxenc::from_base32z("mprqiu67f4gr8hb4zx8kuuqmxanmct4b6fp1nkeeruhxx9tqwc7y")}; + // RouterID cpk{oxenc::from_base32z("p3thqq8toyidz3ssos7tx6xhsje3zfdkmpdw43gtb8cz7a96yedo")}; // log::info(logcat, "Beginning session init to client: {}", cpk.to_network_address(false)); // _initiate_session( // NetworkAddress::from_pubkey(cpk, true), [](ip_v) { log::critical(logcat, "FUCK YEAH"); @@ -431,6 +431,7 @@ namespace llarp::handlers bool SessionEndpoint::prefigure_session( NetworkAddress initiator, SessionTag tag, + HopID remote_pivot_txid, std::shared_ptr path, shared_kx_data kx_data, bool use_tun) @@ -438,7 +439,13 @@ namespace llarp::handlers bool ret = true; auto inbound = std::make_shared( - initiator, std::move(path), *this, std::move(tag), use_tun, std::move(kx_data)); + initiator, + std::move(path), + *this, + std::move(remote_pivot_txid), + std::move(tag), + use_tun, + std::move(kx_data)); auto [session, _] = _sessions.insert_or_assign(std::move(initiator), std::move(inbound)); @@ -578,6 +585,7 @@ namespace llarp::handlers std::tie(inner_payload, kx_data) = InitiateSession::serialize_encrypt( _router.local_rid(), remote.router_id(), + path->pivot_txid(), tag, remote_intro.pivot_txid, fetch_auth_token(remote), @@ -599,9 +607,9 @@ namespace llarp::handlers remote, tag, path, + remote_pivot_txid = remote_intro.pivot_txid, hook = std::move(cb), - session_keys = std::move(kx_data), - remote_intro = std::move(remote_intro)](oxen::quic::message m) mutable { + session_keys = std::move(kx_data)](oxen::quic::message m) mutable { if (m) { log::critical(logcat, "Call to InitiateSession succeeded!"); @@ -610,9 +618,9 @@ namespace llarp::handlers remote, *this, std::move(path), + std::move(remote_pivot_txid), std::move(tag), - std::move(session_keys), - std::move(remote_intro)); + std::move(session_keys)); auto [session, _] = _sessions.insert_or_assign(std::move(remote), std::move(outbound)); diff --git a/llarp/handlers/session.hpp b/llarp/handlers/session.hpp index e70255c066..01d18c6225 100644 --- a/llarp/handlers/session.hpp +++ b/llarp/handlers/session.hpp @@ -124,6 +124,7 @@ namespace llarp bool prefigure_session( NetworkAddress initiator, SessionTag tag, + HopID remote_pivot_txid, std::shared_ptr path, shared_kx_data kx_data, bool use_tun); diff --git a/llarp/handlers/tun.cpp b/llarp/handlers/tun.cpp index 93b4d4c3fa..48b92f6a2b 100644 --- a/llarp/handlers/tun.cpp +++ b/llarp/handlers/tun.cpp @@ -286,7 +286,7 @@ namespace llarp::handlers void TunEndpoint::configure() { return _router.loop()->call_get([&]() { - log::debug(logcat, "{} called", __PRETTY_FUNCTION__); + log::trace(logcat, "{} called", __PRETTY_FUNCTION__); auto& net_conf = _router.config()->network; @@ -329,7 +329,7 @@ namespace llarp::handlers _local_range_iterator = IPRangeIterator(_local_range); _local_netaddr = NetworkAddress::from_pubkey(_router.local_rid(), not _router.is_service_node()); - _local_ip_mapping.insert_or_assign(_local_base_ip, std::move(_local_netaddr)); + _local_ip_mapping.insert_or_assign(_local_range.net_ip(), std::move(_local_netaddr)); vpn::InterfaceInfo info; info.ifname = _if_name; @@ -365,7 +365,7 @@ namespace llarp::handlers log::info(logcat, "{} got network interface:{}", name(), _if_name); - auto pkt_hook = [this]() { + auto pkt_hook = [this]() mutable { for (auto pkt = _net_if->read_next_packet(); not pkt.empty(); pkt = _net_if->read_next_packet()) { log::trace(logcat, "packet router receiving {}", pkt.info_line()); @@ -1034,9 +1034,9 @@ namespace llarp::handlers return std::nullopt; } - void TunEndpoint::send_packet_to_net_if(IPPacket&& pkt) + void TunEndpoint::send_packet_to_net_if(IPPacket pkt) { - _router.loop()->call([this, pkt = std::move(pkt)]() { _net_if->write_packet(std::move(pkt)); }); + _router.loop()->call([this, pkt = std::move(pkt)]() mutable { _net_if->write_packet(std::move(pkt)); }); } void TunEndpoint::rewrite_and_send_packet(IPPacket&& pkt, ip_v src, ip_v dest) diff --git a/llarp/handlers/tun.hpp b/llarp/handlers/tun.hpp index a0952ee1fd..f86676aa45 100644 --- a/llarp/handlers/tun.hpp +++ b/llarp/handlers/tun.hpp @@ -164,7 +164,7 @@ namespace llarp::handlers std::optional obtain_src_for_remote(const NetworkAddress& remote, bool use_ipv4); - void send_packet_to_net_if(IPPacket&& pkt); + void send_packet_to_net_if(IPPacket pkt); }; } // namespace llarp::handlers diff --git a/llarp/link/link_manager.cpp b/llarp/link/link_manager.cpp index a79f86e965..4be414e10a 100644 --- a/llarp/link/link_manager.cpp +++ b/llarp/link/link_manager.cpp @@ -1582,7 +1582,7 @@ namespace llarp std::optional> next_ids = std::nullopt; std::string next_payload; - log::debug( + log::trace( logcat, "We are {} hop for path data: {}: {}", hop->terminal_hop ? "terminal" : "intermediate", @@ -1607,7 +1607,7 @@ namespace llarp return; } - log::debug(logcat, "Inbound path rxid:{}, outbound path txid:{}", hop_id, ihid); + log::trace(logcat, "Inbound path rxid:{}, outbound path txid:{}", hop_id, ihid); auto next_hop = _router.path_context()->get_transit_hop(ihid); @@ -1617,7 +1617,7 @@ namespace llarp return; } - log::debug(logcat, "Bridging path data message to hop: {}", next_hop->to_string()); + log::trace(logcat, "Bridging path data message to hop: {}", next_hop->to_string()); next_ids = next_hop->next_id(ihid); @@ -1692,7 +1692,8 @@ namespace llarp NetworkAddress initiator; SessionTag tag; - HopID pivot_txid; + HopID remote_pivot_txid; + HopID local_pivot_txid; bool use_tun; shared_kx_data kx_data; std::optional maybe_auth = std::nullopt; @@ -1701,10 +1702,10 @@ namespace llarp try { if (inner_body) - std::tie(kx_data, initiator, pivot_txid, tag, use_tun, maybe_auth) = + std::tie(kx_data, initiator, local_pivot_txid, tag, remote_pivot_txid, use_tun, maybe_auth) = InitiateSession::decrypt_deserialize(oxenc::bt_dict_consumer{*inner_body}, _router.identity()); else - std::tie(kx_data, initiator, pivot_txid, tag, use_tun, maybe_auth) = + std::tie(kx_data, initiator, local_pivot_txid, tag, remote_pivot_txid, use_tun, maybe_auth) = InitiateSession::decrypt_deserialize(oxenc::bt_dict_consumer{m.body()}, _router.identity()); if (maybe_auth and not _router.session_endpoint()->validate(initiator, maybe_auth)) @@ -1713,16 +1714,22 @@ namespace llarp return m.respond(InitiateSession::AUTH_ERROR, true); } - path_ptr = _router.path_context()->get_path(pivot_txid); + path_ptr = _router.path_context()->get_path(local_pivot_txid); if (not path_ptr) { - log::warning(logcat, "Failed to find local path for new inbound session over pivot: {}", pivot_txid); + log::warning( + logcat, "Failed to find local path for new inbound session over pivot: {}", local_pivot_txid); return m.respond(InitiateSession::BAD_PATH, true); } if (_router.session_endpoint()->prefigure_session( - std::move(initiator), std::move(tag), std::move(path_ptr), std::move(kx_data), use_tun)) + std::move(initiator), + std::move(tag), + std::move(remote_pivot_txid), + std::move(path_ptr), + std::move(kx_data), + use_tun)) { log::critical(logcat, "InboundSession configured successfully!"); return m.respond(messages::OK_RESPONSE); diff --git a/llarp/messages/session.hpp b/llarp/messages/session.hpp index 9e72c681f2..83b8351cce 100644 --- a/llarp/messages/session.hpp +++ b/llarp/messages/session.hpp @@ -13,7 +13,8 @@ namespace llarp - 'n' : symmetric nonce - 'x' : encrypted payload - 'i' : RouterID of initiator - - 'p' : HopID at the pivot taken from remote ClientIntro + - 'p' : HopID at the pivot taken from local ClientIntro + - 'r' : HopID at the pivot taken from remote's ClientIntro - 's' : SessionTag for current session - 't' : Use Tun interface (bool) - 'u' : Authentication field @@ -29,8 +30,9 @@ namespace llarp inline static std::tuple serialize_encrypt( const RouterID& local, const RouterID& remote, + HopID local_pivot_txid, SessionTag& tag, - HopID pivot_txid, + HopID remote_pivot_txid, std::optional auth_token, bool use_tun) { @@ -42,7 +44,8 @@ namespace llarp oxenc::bt_dict_producer btdp; btdp.append("i", local.to_view()); - btdp.append("p", pivot_txid.to_view()); + btdp.append("p", local_pivot_txid.to_view()); + btdp.append("r", remote_pivot_txid.to_view()); btdp.append("s", tag.to_view()); btdp.append("t", use_tun); // TOTHINK: this auth field @@ -69,8 +72,9 @@ namespace llarp } }; - inline static std::tuple> - decrypt_deserialize(oxenc::bt_dict_consumer&& outer_btdc, const Ed25519SecretKey& local) + inline static std:: + tuple> + decrypt_deserialize(oxenc::bt_dict_consumer&& outer_btdc, const Ed25519SecretKey& local) { SymmNonce nonce; PubKey shared_pubkey; @@ -95,13 +99,15 @@ namespace llarp NetworkAddress initiator; RouterID init_rid; SessionTag tag; - HopID pivot_txid; + HopID remote_pivot_txid; + HopID local_pivot_txid; bool use_tun; std::optional maybe_auth = std::nullopt; init_rid.from_string(btdc.require("i")); initiator = NetworkAddress::from_pubkey(init_rid, true); - pivot_txid.from_string(btdc.require("p")); + remote_pivot_txid.from_string(btdc.require("p")); + local_pivot_txid.from_string(btdc.require("r")); tag.from_string(btdc.require("s")); use_tun = btdc.require("t"); maybe_auth = btdc.maybe("u"); @@ -109,8 +115,9 @@ namespace llarp return { std::move(kx_data), std::move(initiator), - std::move(pivot_txid), + std::move(local_pivot_txid), std::move(tag), + std::move(remote_pivot_txid), use_tun, std::move(maybe_auth)}; } diff --git a/llarp/net/net.hpp b/llarp/net/net.hpp index 4a6bdee6dc..8e6156c88a 100644 --- a/llarp/net/net.hpp +++ b/llarp/net/net.hpp @@ -1,7 +1,6 @@ #pragma once #include "net.h" -#include "uint128.hpp" #include #include @@ -47,7 +46,7 @@ namespace llarp { // TODO: is this needed? /// a gateway we can use if it exists - std::optional _gateway; + std::optional _gateway; /// human readable name of interface std::string name; @@ -70,9 +69,9 @@ namespace llarp std::optional if_name = std::nullopt; std::optional if_addr = std::nullopt; std::optional if_netmask = std::nullopt; - std::optional if_index = std::nullopt; + std::optional if_index = std::nullopt; - operator bool() const { return if_name and if_addr /* and if_netmask */ and if_index; } + operator bool() const { return if_name and if_addr; } }; /// network platform (all methods virtual so it can be mocked by unit tests) diff --git a/llarp/net/traffic_policy.cpp b/llarp/net/traffic_policy.cpp index cd84f89722..5cbd8b8083 100644 --- a/llarp/net/traffic_policy.cpp +++ b/llarp/net/traffic_policy.cpp @@ -69,6 +69,7 @@ namespace llarp::net bool ExitPolicy::allow_ip_traffic(const IPPacket& pkt) { + log::debug(logcat, "{} called", __PRETTY_FUNCTION__); if (protocols.empty() and ranges.empty()) return true; diff --git a/llarp/net/uint128.hpp b/llarp/net/uint128.hpp deleted file mode 100644 index 7c94aa0cc4..0000000000 --- a/llarp/net/uint128.hpp +++ /dev/null @@ -1,269 +0,0 @@ -#pragma once -#include - -#include -#include -#include -#include - -namespace llarp -{ - /// 128-bit unsigned integer. Does *not* support - /// multiplication/division/modulus. - struct uint128_t - { - // Swap order on little/big endian so that the first byte of the struct is - // always most significant on big endian and least significant on little - // endian. -#ifdef __BIG_ENDIAN__ - uint64_t upper, lower; -#else - uint64_t lower, upper; -#endif - - // Initializes with 0s - constexpr uint128_t() : uint128_t{0, 0} {} - - // Initializes with least-significant value - constexpr uint128_t(uint64_t lower) : uint128_t{0, lower} {} - - // Initializes with upper and lower values - constexpr uint128_t(uint64_t upper, uint64_t lower) - // clang-format off -#ifdef __BIG_ENDIAN__ - : upper{upper}, lower{lower} -#else - : lower{lower}, upper{upper} -#endif - // clang-format on - {} - - constexpr uint128_t(const uint128_t&) = default; - constexpr uint128_t(uint128_t&&) = default; - constexpr uint128_t& operator=(const uint128_t&) = default; - constexpr uint128_t& operator=(uint128_t&&) = default; - - // bitwise and - constexpr uint128_t& operator&=(const uint128_t& o) - { - upper &= o.upper; - lower &= o.lower; - return *this; - } - constexpr uint128_t operator&(const uint128_t& o) const - { - uint128_t result = *this; - result &= o; - return result; - } - - // bitwise or - constexpr uint128_t& operator|=(const uint128_t& o) - { - upper |= o.upper; - lower |= o.lower; - return *this; - } - constexpr uint128_t operator|(const uint128_t& o) const - { - uint128_t result = *this; - result |= o; - return result; - } - - // bitwise xor - constexpr uint128_t& operator^=(const uint128_t& o) - { - upper ^= o.upper; - lower ^= o.lower; - return *this; - } - constexpr uint128_t operator^(const uint128_t& o) const - { - uint128_t result = *this; - result ^= o; - return result; - } - - // bitwise not - constexpr uint128_t operator~() const { return {~upper, ~lower}; } - - // bool: true if any bit set - explicit constexpr operator bool() const { return static_cast(lower) || static_cast(upper); } - - // Casting to basic unsigned int types: casts away upper bits - explicit constexpr operator uint8_t() const { return static_cast(lower); } - explicit constexpr operator uint16_t() const { return static_cast(lower); } - explicit constexpr operator uint32_t() const { return static_cast(lower); } - explicit constexpr operator uint64_t() const { return lower; } - - constexpr bool operator==(const uint128_t& b) const { return lower == b.lower && upper == b.upper; } - - constexpr bool operator!=(const uint128_t& b) const { return lower != b.lower || upper != b.upper; } - - constexpr bool operator<(const uint128_t& b) const - { - return std::tie(upper, lower) < std::tie(b.upper, b.lower); - } - - constexpr bool operator<=(const uint128_t& b) const - { - return std::tie(upper, lower) <= std::tie(b.upper, b.lower); - } - - constexpr bool operator>(const uint128_t& b) const - { - return std::tie(upper, lower) > std::tie(b.upper, b.lower); - } - - constexpr bool operator>=(const uint128_t& b) const - { - return std::tie(upper, lower) >= std::tie(b.upper, b.lower); - } - - constexpr uint128_t& operator++() - { - if (++lower == 0) - ++upper; - return *this; - } - - constexpr uint128_t operator++(int) - { - auto copy = *this; - ++*this; - return copy; - } - - constexpr uint128_t& operator+=(const uint128_t& b) - { - lower += b.lower; - if (lower < b.lower) - ++upper; - upper += b.upper; - return *this; - } - constexpr uint128_t operator+(const uint128_t& b) const - { - uint128_t result = *this; - result += b; - return result; - } - - constexpr uint128_t& operator-=(const uint128_t& b) - { - if (b.lower > lower) - --upper; - lower -= b.lower; - upper -= b.upper; - return *this; - } - constexpr uint128_t operator-(const uint128_t& b) const - { - uint128_t result = *this; - result -= b; - return result; - } - - constexpr uint128_t& operator<<=(uint64_t shift) - { - if (shift == 0) - { - } - else if (shift < 64) - { - upper = upper << shift | (lower >> (64 - shift)); - lower <<= shift; - } - else if (shift == 64) - { - upper = lower; - lower = 0; - } - else if (shift < 128) - { - upper = lower << (shift - 64); - lower = 0; - } - else - { - upper = lower = 0; - } - return *this; - } - constexpr uint128_t operator<<(uint64_t shift) const - { - uint128_t result = *this; - result <<= shift; - return result; - } - - constexpr uint128_t& operator>>=(uint64_t shift) - { - if (shift == 0) - { - } - else if (shift < 64) - { - lower = lower >> shift | upper << (64 - shift); - upper >>= shift; - } - else if (shift == 64) - { - lower = upper; - upper = 0; - } - else if (shift < 128) - { - lower = upper >> (shift - 64); - upper = 0; - } - else - { - upper = lower = 0; - } - return *this; - } - - constexpr uint128_t operator>>(uint64_t shift) const - { - uint128_t result = *this; - result >>= shift; - return result; - } - }; - - static_assert(sizeof(uint128_t) == 16, "uint128_t has unexpected size (padding?)"); - -} // namespace llarp - -namespace std -{ - // Hash function for uint128_t - template <> - struct hash - { - size_t operator()(const llarp::uint128_t& i) const - { - size_t h = std::hash()(i.lower); - h ^= std::hash()(i.upper) + 0x9e3779b9 + (h << 6) + (h >> 2); - return h; - } - }; -} // namespace std - -inline llarp::uint128_t ntoh128(llarp::uint128_t i) -{ -#ifdef __BIG_ENDIAN__ - return i; -#else - const auto loSwapped = oxenc::big_to_host(i.lower); - const auto hiSwapped = oxenc::big_to_host(i.upper); - return {/*upper=*/loSwapped, /*lower=*/hiSwapped}; -#endif -} - -inline llarp::uint128_t hton128(llarp::uint128_t i) -{ - return ntoh128(i); // Same bit flipping as n-to-h -} diff --git a/llarp/nodedb.cpp b/llarp/nodedb.cpp index fcadfa5053..7e922fca10 100644 --- a/llarp/nodedb.cpp +++ b/llarp/nodedb.cpp @@ -138,7 +138,7 @@ namespace llarp _is_service_node ? "Relay" : "Client", num_rcs(), MIN_ACTIVE_RCS); - _bootstrap_handler->begin(); + _bootstrap_handler->start(); } return false; @@ -149,6 +149,12 @@ namespace llarp void NodeDB::purge_rcs(std::chrono::milliseconds now) { + if (_router.is_stopping() || not _router.is_running()) + { + log::debug(logcat, "NodeDB unable to continue NodeDB purge -- router is stopped!"); + return; + } + remove_if([&](const RemoteRC& rc) -> bool { // don't purge bootstrap nodes from nodedb if (is_bootstrap_node(rc)) @@ -630,7 +636,7 @@ namespace llarp _is_bootstrapping = false; // this function is only called in success or lokinet shutdown, so we will never need bootstrapping _needs_bootstrap = false; - _bootstrap_handler->halt(); + _bootstrap_handler->stop(); if (success) { @@ -878,7 +884,7 @@ namespace llarp if (_bootstrap_handler) { log::debug(logcat, "NodeDB clearing bootstrap handler..."); - _bootstrap_handler->halt(); + _bootstrap_handler->stop(); _bootstrap_handler.reset(); } diff --git a/llarp/path/path.cpp b/llarp/path/path.cpp index ec310cdfca..64709f922a 100644 --- a/llarp/path/path.cpp +++ b/llarp/path/path.cpp @@ -83,7 +83,7 @@ namespace llarp::path intro.pivot_txid = hops.back()._txid; log::debug( - logcat, "Path client intro holding pivot_rid ({}) and pivot_rxid ({})", intro.pivot_rid, intro.pivot_txid); + logcat, "Path client intro holding pivot_rid ({}) and pivot_txid ({})", intro.pivot_rid, intro.pivot_txid); } void Path::link_session(recv_session_dgram_cb cb) diff --git a/llarp/path/path_handler.cpp b/llarp/path/path_handler.cpp index 2294ac4933..5eed77defa 100644 --- a/llarp/path/path_handler.cpp +++ b/llarp/path/path_handler.cpp @@ -505,7 +505,7 @@ namespace llarp::path // make a copy here to reference rather than creating one in the lambda every iteration std::set to_exclude{exclude.begin(), exclude.end()}; to_exclude.insert(pivot); - std::vector excluded_ranges{}; + std::vector excluded_ranges{}; // excluded_ranges.emplace_back(pivot_rc.addr().to_ipv4() / netmask); if (auto maybe = select_first_hop(to_exclude)) @@ -536,7 +536,7 @@ namespace llarp::path if (not to_exclude.insert(rid).second) return false; - excluded_ranges.emplace_back(v4 / netmask); + excluded_ranges.emplace_back(v4 % netmask); if (_router.router_profiling().is_bad_for_path(rid, 1)) return false; diff --git a/llarp/router/route_poker.cpp b/llarp/router/route_poker.cpp index 1701a3003c..1bc7162313 100644 --- a/llarp/router/route_poker.cpp +++ b/llarp/router/route_poker.cpp @@ -8,9 +8,11 @@ namespace llarp { static auto logcat = log::Cat("route_poker"); + RoutePoker::RoutePoker(Router& r) : _router{r} {} + void RoutePoker::add_route(oxen::quic::Address ip) { - if (not is_up) + if (not _is_up) return; bool has_existing = poked_routes.count(ip); @@ -38,7 +40,7 @@ namespace llarp { if (ip.is_set() and gateway.is_set() and is_enabled()) { - vpn::AbstractRouteManager& route = router.vpn_platform()->RouteManager(); + vpn::AbstractRouteManager& route = _router.vpn_platform()->RouteManager(); route.delete_route(ip, gateway); } } @@ -47,7 +49,7 @@ namespace llarp { if (ip.is_set() and gateway.is_set() and is_enabled()) { - vpn::AbstractRouteManager& route = router.vpn_platform()->RouteManager(); + vpn::AbstractRouteManager& route = _router.vpn_platform()->RouteManager(); route.add_route(ip, gateway); } } @@ -65,7 +67,10 @@ namespace llarp void RoutePoker::start() { if (not is_enabled()) + { + log::info(logcat, "Route poker is NOT enabled for this lokinet instance!"); return; + } // router.loop()->call_every(100ms, weak_from_this(), [self = weak_from_this()]() { // if (auto ptr = self.lock()) @@ -96,10 +101,10 @@ namespace llarp RoutePoker::~RoutePoker() { - if (not router.vpn_platform()) + if (not _router.vpn_platform()) return; - auto& route = router.vpn_platform()->RouteManager(); + auto& route = _router.vpn_platform()->RouteManager(); for (const auto& [ip, gateway] : poked_routes) { if (gateway.is_set() and ip.is_set()) @@ -108,16 +113,6 @@ namespace llarp route.delete_blackhole(); } - bool RoutePoker::is_enabled() const - { - if (router.is_service_node()) - return false; - if (const auto& conf = router.config()) - return conf->network.enable_route_poker; - - throw std::runtime_error{"Attempting to use RoutePoker with router with no config set"}; - } - void RoutePoker::update() { // // ensure we have an endpoint @@ -173,8 +168,9 @@ namespace llarp void RoutePoker::put_up() { - bool was_up = is_up; - is_up = true; + bool was_up = _is_up; + _is_up = true; + if (not was_up) { if (not is_enabled()) @@ -189,17 +185,17 @@ namespace llarp { log::info(logcat, "RoutePoker coming up; poking routes"); - vpn::AbstractRouteManager& route = router.vpn_platform()->RouteManager(); + vpn::AbstractRouteManager& route = _router.vpn_platform()->RouteManager(); // black hole all routes if enabled - if (router.config()->network.blackhole_routes) + if (_router.config()->network.blackhole_routes) route.add_blackhole(); // explicit route pokes for first hops - router.for_each_connection( + _router.for_each_connection( [this](const RouterID&, link::Connection& conn) { add_route(conn.conn->remote()); }); - add_route(router.link_manager()->local()); + add_route(_router.link_manager()->local()); // add default route // const auto ep = router.hidden_service_context().GetDefault(); // if (auto* vpn = ep->GetVPNInterface()) @@ -214,9 +210,9 @@ namespace llarp void RoutePoker::put_down() { // unpoke routes for first hops - router.for_each_connection( + _router.for_each_connection( [this](const RouterID&, link::Connection& conn) { delete_route(conn.conn->remote()); }); - if (is_enabled() and is_up) + if (is_enabled() and _is_up) { // vpn::AbstractRouteManager& route = router.vpn_platform()->RouteManager(); // const auto ep = router.hidden_service_context().GetDefault(); diff --git a/llarp/router/route_poker.hpp b/llarp/router/route_poker.hpp index f5ed1515dc..860b448396 100644 --- a/llarp/router/route_poker.hpp +++ b/llarp/router/route_poker.hpp @@ -13,7 +13,7 @@ namespace llarp struct RoutePoker : public std::enable_shared_from_this { - RoutePoker(Router& r) : router{r} {} + RoutePoker(Router& r); void add_route(oxen::quic::Address ip); @@ -33,11 +33,11 @@ namespace llarp /// pass in if we are using exit node mode right now as a bool void set_dns_mode(bool /// using_exit_mode) const; + bool is_enabled() const { return _is_enabled; } + private: void update(); - bool is_enabled() const; - void delete_all_routes(); void disable_all_routes(); @@ -49,10 +49,10 @@ namespace llarp void disable_route(oxen::quic::Address ip, oxen::quic::Address gateway); std::unordered_map poked_routes; - std::optional current_gateway; - Router& router; - bool is_up{false}; + Router& _router; + bool _is_up{false}; + bool _is_enabled{false}; }; } // namespace llarp diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 00bcfa257c..809c601280 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -1016,6 +1016,8 @@ namespace llarp _loop_ticker = _loop->call_every( ROUTER_TICK_INTERVAL, [this] { tick(); }, false, true); + // _route_poker->start(); + _systemd_ticker = _loop->call_every( SERVICE_MANAGER_REPORT_INTERVAL, []() { sys::service_manager->report_periodic_stats(); }, false, true); diff --git a/llarp/session/session.cpp b/llarp/session/session.cpp index 91ab487dee..a72dfd883e 100644 --- a/llarp/session/session.cpp +++ b/llarp/session/session.cpp @@ -19,22 +19,21 @@ namespace llarp::session std::shared_ptr _p, handlers::SessionEndpoint& parent, NetworkAddress remote, + HopID remote_pivot_txid, SessionTag _t, bool use_tun, bool is_outbound, - std::optional kx_data, - std::optional _remote_intro) + std::optional kx_data) : _r{r}, _parent{parent}, _tag{std::move(_t)}, _remote{std::move(remote)}, + _remote_pivot_txid{std::move(remote_pivot_txid)}, _use_tun{use_tun}, _is_outbound{is_outbound} { if (kx_data.has_value()) session_keys = std::move(*kx_data); - if (_remote_intro.has_value()) - remote_intro = std::move(*_remote_intro); set_new_current_path(std::move(_p)); } @@ -48,8 +47,7 @@ namespace llarp::session bool BaseSession::send_path_data_message(std::string data) { auto inner_payload = PATH::DATA::serialize(std::move(data), _r.local_rid()); - auto intermediate_payload = - PATH::DATA::serialize_intermediate(std::move(inner_payload), remote_intro.pivot_txid); + auto intermediate_payload = PATH::DATA::serialize_intermediate(std::move(inner_payload), _remote_pivot_txid); return _r.send_data_message( _current_path->upstream_rid(), _current_path->make_path_message(std::move(intermediate_payload))); } @@ -163,20 +161,20 @@ namespace llarp::session NetworkAddress remote, handlers::SessionEndpoint& parent, std::shared_ptr path, + HopID remote_pivot_txid, SessionTag _t, - std::optional kx_data, - std::optional remote_intro) + std::optional kx_data) : PathHandler{parent._router, path::DEFAULT_PATHS_HELD}, BaseSession{ _router, std::move(path), parent, std::move(remote), + std::move(remote_pivot_txid), std::move(_t), _router.using_tun_if(), true, - std::move(kx_data), - std::move(remote_intro)}, + std::move(kx_data)}, _is_snode_session{not _remote.is_client()}, _last_use{_router.now()} { @@ -332,6 +330,7 @@ namespace llarp::session NetworkAddress remote, std::shared_ptr _path, handlers::SessionEndpoint& parent, + HopID remote_pivot_txid, SessionTag _t, bool use_tun, std::optional kx_data) @@ -340,6 +339,7 @@ namespace llarp::session std::move(_path), parent, std::move(remote), + std::move(remote_pivot_txid), std::move(_t), use_tun, false, diff --git a/llarp/session/session.hpp b/llarp/session/session.hpp index 71eac6c511..0a5f521130 100644 --- a/llarp/session/session.hpp +++ b/llarp/session/session.hpp @@ -49,7 +49,8 @@ namespace llarp shared_kx_data session_keys{}; - ClientIntro remote_intro; + // used for bridging data messages across aligned paths + HopID _remote_pivot_txid; bool _use_tun; bool _is_outbound; @@ -79,11 +80,11 @@ namespace llarp std::shared_ptr _p, handlers::SessionEndpoint& parent, NetworkAddress remote, + HopID remote_pivot_txid, SessionTag _t, bool use_tun, bool is_outbound, - std::optional kx_data = std::nullopt, - std::optional remote_intro = std::nullopt); + std::optional kx_data = std::nullopt); virtual ~BaseSession() = default; @@ -124,9 +125,9 @@ namespace llarp NetworkAddress _remote, handlers::SessionEndpoint& parent, std::shared_ptr path, + HopID remote_pivot_txid, SessionTag _t, - std::optional kx_data = std::nullopt, - std::optional remote_intro = std::nullopt); + std::optional kx_data = std::nullopt); ~OutboundSession() override; @@ -182,6 +183,7 @@ namespace llarp NetworkAddress _remote, std::shared_ptr _path, handlers::SessionEndpoint& parent, + HopID remote_pivot_txid, SessionTag _t, bool use_tun, std::optional kx_data = std::nullopt); diff --git a/llarp/vpn/linux.hpp b/llarp/vpn/linux.hpp index 1feb8904ae..4772361e43 100644 --- a/llarp/vpn/linux.hpp +++ b/llarp/vpn/linux.hpp @@ -45,28 +45,30 @@ namespace llarp::vpn LinuxInterface(InterfaceInfo info) : NetworkInterface{std::move(info)}, _fd{::open("/dev/net/tun", O_RDWR)} { if (_fd == -1) - throw std::runtime_error("cannot open /dev/net/tun " + std::string{strerror(errno)}); + throw std::runtime_error("cannot open /dev/net/tun {}"_format(strerror(errno))); if (fcntl(_fd, F_SETFL, O_NONBLOCK) == -1) - throw std::runtime_error{"Failed to set Linux interface fd non-block!s"}; + throw std::runtime_error{"Failed to set `O_NONBLOCK` on Linux interface FD!"}; ifreq ifr{}; in6_ifreq ifr6{}; ifr.ifr_flags = IFF_TUN | IFF_NO_PI; - std::copy_n(_info.ifname.c_str(), std::min(_info.ifname.size(), sizeof(ifr.ifr_name)), ifr.ifr_name); + std::memcpy( + ifr.ifr_name, _info.ifname.c_str(), std::min(_info.ifname.size(), static_cast(IFNAMSIZ))); if (::ioctl(_fd, TUNSETIFF, &ifr) == -1) - throw std::runtime_error("cannot set interface name: " + std::string{strerror(errno)}); + throw std::runtime_error("cannot set interface name: {}"_format(strerror(errno))); + ifreq ctrl_ifr{}; IOCTL control{AF_INET}; - control.ioctl(SIOCGIFFLAGS, &ifr); - const int flags = ifr.ifr_flags; - control.ioctl(SIOCGIFINDEX, &ifr); _info.index = ifr.ifr_ifindex; + control.ioctl(SIOCGIFFLAGS, &ctrl_ifr); + short int flags = ctrl_ifr.ifr_flags; + for (const auto& ifaddr : _info.addrs) { auto& range = ifaddr.range; @@ -83,7 +85,7 @@ namespace llarp::vpn control.ioctl(SIOCSIFADDR, &ifr); - auto subnet_mask = (ipv4_subnet / range.mask()).base; + auto subnet_mask = (ipv4_subnet / range.mask()).ip; log::debug(logcat, "IP Range:{}, subnet mask: {}", range, subnet_mask); ((sockaddr_in*)&ifr.ifr_netmask)->sin_addr.s_addr = @@ -111,7 +113,7 @@ namespace llarp::vpn } } - ifr.ifr_flags = static_cast(flags | IFF_UP | IFF_NO_PI); + ifr.ifr_flags |= static_cast(flags | IFF_UP | IFF_RUNNING); control.ioctl(SIOCSIFFLAGS, &ifr); } @@ -121,6 +123,7 @@ namespace llarp::vpn IPPacket read_next_packet() override { + log::debug(logcat, "{} called", __PRETTY_FUNCTION__); std::vector buf; buf.resize(MAX_PACKET_SIZE); const auto sz = read(_fd, buf.data(), buf.capacity()); @@ -135,13 +138,13 @@ namespace llarp::vpn } buf.resize(sz); - return IPPacket{std::move(buf)}; } bool write_packet(IPPacket pkt) override { const auto sz = write(_fd, pkt.data(), pkt.size()); + log::debug(logcat, "{} bytes written to fd {}", sz, _fd); if (sz <= 0) return false; return sz == static_cast(pkt.size()); @@ -190,37 +193,40 @@ namespace llarp::vpn /* Helper structure for ip address data and attributes */ struct _inet_addr { - unsigned char family; - unsigned char bitlen; - unsigned char data[sizeof(struct in6_addr)]; - - _inet_addr() = default; - - _inet_addr(oxen::quic::Address addr) - { - const auto& v4 = addr.is_ipv4(); - - family = (v4) ? AF_INET : AF_INET6; - bitlen = (v4) ? 32 : 128; - std::memcpy(data, addr.host().data(), (v4) ? 4 : 16); - } - - _inet_addr(ipv4 v4) + private: + void _init_internals(const ipv4& v4) { family = AF_INET; bitlen = 32; - - auto bigly = oxenc::host_to_big(v4.addr); - inet_ntop(AF_INET, &bigly, reinterpret_cast(data), sizeof(struct in6_addr)); + oxenc::write_host_as_big(v4.addr, &data); } - _inet_addr(ipv6 v6) + void _init_internals(const ipv6& v6) { family = AF_INET6; bitlen = 128; auto in6 = v6.to_in6(); std::memcpy(&data, &in6, sizeof(in6_addr)); } + + public: + unsigned char family; + unsigned char bitlen; + unsigned char data[sizeof(struct in6_addr)]; + + _inet_addr() = default; + + _inet_addr(oxen::quic::Address addr) + { + if (addr.is_ipv4()) + _init_internals(addr.to_ipv4()); + else + _init_internals(addr.to_ipv6()); + } + + _inet_addr(ipv4 v4) { _init_internals(v4); } + + _inet_addr(ipv6 v6) { _init_internals(v6); } }; void make_blackhole(int cmd, int flags, int af) @@ -237,12 +243,12 @@ namespace llarp::vpn nl_request.r.rtm_scope = RT_SCOPE_UNIVERSE; if (af == AF_INET) { - uint32_t addr{}; - nl_request.AddData(RTA_DST, &addr, sizeof(addr)); + ipv4 addr{}; + nl_request.AddData(RTA_DST, &addr.addr, sizeof(addr.addr)); } else { - uint128_t addr{}; + std::array addr{}; nl_request.AddData(RTA_DST, &addr, sizeof(addr)); } send(fd, &nl_request, sizeof(nl_request), 0); diff --git a/llarp/vpn/platform.hpp b/llarp/vpn/platform.hpp index 4b79670767..c8540abf18 100644 --- a/llarp/vpn/platform.hpp +++ b/llarp/vpn/platform.hpp @@ -32,7 +32,7 @@ namespace llarp::vpn } }; - struct InterfaceInfo + struct [[deprecated("Use net::if_info instead!")]] InterfaceInfo { std::string ifname; unsigned int index;