From 59fb6cd9fa09f8f1b861310b2f6ae81fb4203257 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Sun, 19 May 2024 20:39:11 +0200 Subject: [PATCH 01/34] ci: add bsd variants --- .github/workflows/ci.yml | 41 +++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0022321c76..43d304e518 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,7 +25,8 @@ jobs: if: "github.event_name != 'pull_request' || ! contains(github.event.pull_request.labels.*.name, 'flaky-test')" uses: './.github/workflows/tests.yaml' - cross: + cross_build: + name: Cross Build Only if: "github.event_name != 'pull_request' || ! contains(github.event.pull_request.labels.*.name, 'flaky-test')" timeout-minutes: 30 name: Cross compile @@ -34,7 +35,8 @@ jobs: fail-fast: false matrix: target: - - i686-unknown-linux-gnu + # cross tests are currently broken vor armv7 and aarch64 + # see https://github.com/cross-rs/cross/issues/1311 - armv7-linux-androideabi - aarch64-linux-android steps: @@ -64,10 +66,39 @@ jobs: env: RUST_LOG: ${{ runner.debug && 'TRACE' || 'DEBUG'}} + cross_test: + name: Cross Test + if: "github.event_name != 'pull_request' || ! contains(github.event.pull_request.labels.*.name, 'flaky-test')" + timeout-minutes: 30 + name: Cross compile + runs-on: [self-hosted, linux, X64] + strategy: + fail-fast: false + matrix: + target: + - i686-unknown-linux-gnu + - x86_64-unknown-freebsd + - x86_64-unknown-netbsd + - i686-unknown-freebsd + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Install rust stable + uses: dtolnay/rust-toolchain@stable + + - name: Cleanup Docker + continue-on-error: true + run: | + docker kill $(docker ps -q) + + - name: Install cross + # See https://github.com/cross-rs/cross/issues/1222 + run: cargo install cross --git https://github.com/cross-rs/cross + - name: test - # cross tests are currently broken vor armv7 and aarch64 - # see https://github.com/cross-rs/cross/issues/1311 - if: matrix.target == 'i686-unknown-linux-gnu' run: cross test --all --target ${{ matrix.target }} -- --test-threads=12 env: RUST_LOG: ${{ runner.debug && 'TRACE' || 'DEBUG' }} From 843dd11da045dfcf8a7327466c9b46b1106ab73a Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Sun, 19 May 2024 20:41:42 +0200 Subject: [PATCH 02/34] fixup --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 43d304e518..d5513d7b76 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,7 +29,6 @@ jobs: name: Cross Build Only if: "github.event_name != 'pull_request' || ! contains(github.event.pull_request.labels.*.name, 'flaky-test')" timeout-minutes: 30 - name: Cross compile runs-on: [self-hosted, linux, X64] strategy: fail-fast: false @@ -70,7 +69,6 @@ jobs: name: Cross Test if: "github.event_name != 'pull_request' || ! contains(github.event.pull_request.labels.*.name, 'flaky-test')" timeout-minutes: 30 - name: Cross compile runs-on: [self-hosted, linux, X64] strategy: fail-fast: false From 17e420a12b08a7808a0e3ca39a2c572d0c18be8b Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Sun, 19 May 2024 21:05:02 +0200 Subject: [PATCH 03/34] first pass at applying patch --- .github/workflows/ci.yml | 4 +- iroh-net/src/net/interfaces/bsd.rs | 201 ++++++++++++++++++++++++++++- 2 files changed, 198 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d5513d7b76..29597d7f7f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,7 +60,6 @@ jobs: # cross tests are currently broken vor armv7 and aarch64 # see https://github.com/cross-rs/cross/issues/1311. So on # those platforms we only build but do not run tests. - if: matrix.target != 'i686-unknown-linux-gnu' run: cross build --all --target ${{ matrix.target }} env: RUST_LOG: ${{ runner.debug && 'TRACE' || 'DEBUG'}} @@ -75,9 +74,8 @@ jobs: matrix: target: - i686-unknown-linux-gnu - - x86_64-unknown-freebsd - - x86_64-unknown-netbsd - i686-unknown-freebsd + - x86_64-unknown-freebsd steps: - name: Checkout uses: actions/checkout@v4 diff --git a/iroh-net/src/net/interfaces/bsd.rs b/iroh-net/src/net/interfaces/bsd.rs index 51c3f67728..f767e8f85a 100644 --- a/iroh-net/src/net/interfaces/bsd.rs +++ b/iroh-net/src/net/interfaces/bsd.rs @@ -12,6 +12,8 @@ use tracing::warn; use super::DefaultRouteDetails; +#[cfg(target_os = "freebsd")] +use freebsd::*; #[cfg(any(target_os = "macos", target_os = "ios"))] use macos::*; @@ -82,6 +84,7 @@ fn is_default_gateway(rm: &RouteMessage) -> bool { return false; } + #[cfg(any(target_os = "macos", target_os = "ios"))] if rm.flags & libc::RTF_IFSCOPE as u32 != 0 { return false; } @@ -114,7 +117,7 @@ fn is_default_gateway(rm: &RouteMessage) -> bool { false } -#[cfg(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd",))] +#[cfg(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))] fn fetch_routing_table() -> Option> { match fetch_rib(libc::AF_UNSPEC, libc::NET_RT_DUMP, 0) { Ok(res) => Some(res), @@ -125,10 +128,19 @@ fn fetch_routing_table() -> Option> { } } -#[cfg(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd",))] +#[cfg(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))] fn parse_routing_table(rib: &[u8]) -> Option> { match parse_rib(libc::NET_RT_IFLIST, rib) { - Ok(res) => Some(res), + Ok(res) => { + let res = res + .into_iter() + .filter_map(|m| match m { + WireMessage::Route(r) => Some(r), + _ => None, + }) + .collect(); + Some(res) + } Err(err) => { warn!("parse_rib failed: {:?}", err); None @@ -178,7 +190,7 @@ const fn is_valid_rib_type(typ: RIBType) -> bool { true } -#[cfg(any(target_os = "free", target_os = "netbsd"))] +#[cfg(any(target_os = "freebsd", target_os = "netbsd"))] const fn is_valid_rib_type(typ: RIBType) -> bool { true } @@ -606,6 +618,187 @@ mod macos { } } +#[cfg(target_os = "freebsd")] +mod freebsd { + use super::*; + + // Hardcoded based on the generated values here: https://cs.opensource.google/go/x/net/+/master:route/zsys_freebsd_amd64.go + + #[cfg(target_pointer_width = "64")] + pub(super) const SIZEOF_IF_MSGHDRL_FREEBSD10: usize = 0xb0; + #[cfg(target_pointer_width = "32")] + pub(super) const SIZEOF_IF_MSGHDRL_FREEBSD10: usize = 0x68; + pub(super) const SIZEOF_IFA_MSGHDR_FREEBSD10: usize = 0x14; + + #[cfg(target_pointer_width = "64")] + pub(super) const SIZEOF_IFA_MSGHDRL_FREEBSD10: usize = 0xb0; + #[cfg(target_pointer_width = "32")] + pub(super) const SIZEOF_IFA_MSGHDRL_FREEBSD10: usize = 0x6c; + + pub(super) const SIZEOF_IFMA_MSGHDR_FREEBSD10: usize = 0x10; + pub(super) const SIZEOF_IF_ANNOUNCEMSGHDR_FREEBSD10: usize = 0x18; + + #[cfg(target_pointer_width = "64")] + pub(super) const SIZEOF_RT_MSGHDR_FREEBSD10: usize = 0x98; + #[cfg(target_pointer_width = "32")] + pub(super) const SIZEOF_RT_MSGHDR_FREEBSD10: usize = 0x5c; + #[cfg(target_pointer_width = "64")] + pub(super) const SIZEOF_RT_METRICS_FREEBSD10: usize = 0x70; + #[cfg(target_pointer_width = "32")] + pub(super) const SIZEOF_RT_METRICS_FREEBSD10: usize = 0x38; + + #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] + pub(super) const SIZEOF_IF_MSGHDR_FREEBSD7: usize = 0xa8; + #[cfg(target_arch = "x86")] + pub(super) const SIZEOF_IF_MSGHDR_FREEBSD7: usize = 0x60; + #[cfg(target_arch = "arm")] + pub(super) const SIZEOF_IF_MSGHDR_FREEBSD7: usize = 0x70; + + #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] + pub(super) const SIZEOF_IF_MSGHDR_FREEBSD8: usize = 0xa8; + #[cfg(target_arch = "x86")] + pub(super) const SIZEOF_IF_MSGHDR_FREEBSD8: usize = 0x60; + #[cfg(target_arch = "arm")] + pub(super) const SIZEOF_IF_MSGHDR_FREEBSD8: usize = 0x70; + + #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] + pub(super) const SIZEOF_IF_MSGHDR_FREEBSD9: usize = 0xa8; + #[cfg(target_arch = "x86")] + pub(super) const SIZEOF_IF_MSGHDR_FREEBSD9: usize = 0x60; + #[cfg(target_arch = "arm")] + pub(super) const SIZEOF_IF_MSGHDR_FREEBSD9: usize = 0x70; + + #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] + pub(super) const SIZEOF_IF_MSGHDR_FREEBSD10: usize = 0xa8; + #[cfg(target_arch = "x86")] + pub(super) const SIZEOF_IF_MSGHDR_FREEBSD10: usize = 0x64; + #[cfg(target_arch = "arm")] + pub(super) const SIZEOF_IF_MSGHDR_FREEBSD10: usize = 0x70; + + #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] + pub(super) const SIZEOF_IF_MSGHDR_FREEBSD11: usize = 0xa8; + #[cfg(target_arch = "x86")] + pub(super) const SIZEOF_IF_MSGHDR_FREEBSD11: usize = 0xa8; + #[cfg(target_arch = "arm")] + pub(super) const SIZEOF_IF_MSGHDR_FREEBSD11: usize = 0xa8; + + #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] + pub(super) const SIZE_OF_IF_DATA_FREEBSD7: usize = 0x98; + #[cfg(target_arch = "x86")] + pub(super) const SIZEOF_IF_DATA_FREEBSD7: usize = 0x50; + #[cfg(target_arch = "arm")] + pub(super) const SIZEOF_IF_DATA_FREEBSD7: usize = 0x60; + + #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] + pub(super) const SIZE_OF_IF_DATA_FREEBSD8: usize = 0x98; + #[cfg(target_arch = "x86")] + pub(super) const SIZEOF_IF_DATA_FREEBSD8: usize = 0x50; + #[cfg(target_arch = "arm")] + pub(super) const SIZEOF_IF_DATA_FREEBSD8: usize = 0x60; + + #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] + pub(super) const SIZE_OF_IF_DATA_FREEBSD9: usize = 0x98; + #[cfg(target_arch = "x86")] + pub(super) const SIZEOF_IF_DATA_FREEBSD9: usize = 0x50; + #[cfg(target_arch = "arm")] + pub(super) const SIZEOF_IF_DATA_FREEBSD9: usize = 0x60; + + #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] + pub(super) const SIZE_OF_IF_DATA_FREEBSD10: usize = 0x98; + #[cfg(target_arch = "x86")] + pub(super) const SIZEOF_IF_DATA_FREEBSD10: usize = 0x54; + #[cfg(target_arch = "arm")] + pub(super) const SIZEOF_IF_DATA_FREEBSD10: usize = 0x60; + + #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] + pub(super) const SIZE_OF_IF_DATA_FREEBSD11: usize = 0x98; + #[cfg(target_arch = "x86")] + pub(super) const SIZEOF_IF_DATA_FREEBSD11: usize = 0x98; + #[cfg(target_arch = "arm")] + pub(super) const SIZEOF_IF_DATA_FREEBSD11: usize = 0x98; + + pub(super) const SIZEOF_IF_MSGHDRL_FREEBSD10_EMU: usize = 0xb0; + pub(super) const SIZEOF_IFA_MSGHDR_FREEBSD10_EMU: usize = 0x14; + pub(super) const SIZEOF_IFA_MSGHDRL_FREEBSD10_EMU: usize = 0xb0; + pub(super) const SIZEOF_IFMA_MSGHDR_FREEBSD10_EMU: usize = 0x10; + pub(super) const SIZEOF_IF_ANNOUNCEMSGHDR_FREEBSD10_EMU: usize = 0x18; + + pub(super) const SIZEOF_RT_MSGHDR_FREEBSD10_EMU: usize = 0x98; + pub(super) const SIZEOF_RT_METRICS_FREEBSD10_EMU: usize = 0x70; + + pub(super) const SIZEOF_IF_MSGHDR_FREEBSD7_EMU: usize = 0xa8; + pub(super) const SIZEOF_IF_MSGHDR_FREEBSD8_EMU: usize = 0xa8; + pub(super) const SIZEOF_IF_MSGHDR_FREEBSD9_EMU: usize = 0xa8; + pub(super) const SIZEOF_IF_MSGHDR_FREEBSD10_EMU: usize = 0xa8; + pub(super) const SIZEOF_IF_MSGHDR_FREEBSD11_EMU: usize = 0xa8; + + pub(super) const SIZEOF_IF_DATA_FREEBSD7_EMU: usize = 0x98; + pub(super) const SIZEOF_IF_DATA_FREEBSD8_EMU: usize = 0x98; + pub(super) const SIZEOF_IF_DATA_FREEBSD9_EMU: usize = 0x98; + pub(super) const SIZEOF_IF_DATA_FREEBSD10_EMU: usize = 0x98; + pub(super) const SIZEOF_IF_DATA_FREEBSD11_EMU: usize = 0x98; + + pub(super) const SIZEOF_SOCKADDR_STORAGE: usize = 0x80; + pub(super) const SIZEOF_SOCKADDR_INET: usize = 0x10; + pub(super) const SIZEOF_SOCKADDR_INET6: usize = 0x1c; + + pub(super) fn probe_routing_stack() -> RoutingStack { + let rtm_version = libc::RTM_VERSION; + + let rtm = WireFormat { + ext_off: SIZEOF_RT_MSGHDR_FREEBSD10, + body_off: SIZEOF_RT_MSGHDR_FREEBSD10, + typ: MessageType::Route, + }; + let ifm = WireFormat { + ext_off: SIZEOF_IF_MSGHDR_FREEBSD11, + body_off: SIZEOF_IF_MSGHDR_FREEBSD11, + typ: MessageType::Interface, + }; + let ifam = WireFormat { + ext_off: SIZEOF_IFA_MSGHDR_FREEBSD10, + body_off: SIZEOF_IFA_MSGHDR_FREEBSD10, + typ: MessageType::InterfaceAddr, + }; + let ifmam = WireFormat { + ext_off: SIZEOF_IFMA_MSGHDR_FREEBSD10, + body_off: SIZEOF_IFMA_MSGHDR_FREEBSD10, + typ: MessageType::InterfaceMulticastAddr, + }; + let ifannm = WireFormat { + ext_off: SIZEOF_IF_ANNOUNCEMSGHDR_FREEBSD10, + body_off: SIZEOF_IF_ANNOUNCEMSGHDR_FREEBSD10, + typ: MessageType::Interface, + }; + + let wire_formats = [ + (libc::RTM_ADD, rtm), + (libc::RTM_DELETE, rtm), + (libc::RTM_CHANGE, rtm), + (libc::RTM_GET, rtm), + (libc::RTM_LOSING, rtm), + (libc::RTM_REDIRECT, rtm), + (libc::RTM_MISS, rtm), + (libc::RTM_LOCK, rtm), + (libc::RTM_RESOLVE, rtm), + (libc::RTM_NEWADDR, ifam), + (libc::RTM_DELADDR, ifam), + (libc::RTM_IFINFO, ifm), + (libc::RTM_NEWMADDR, ifmam), + (libc::RTM_DELMADDR, ifmam), + (libc::RTM_IFANNOUNCE, ifannm), + (libc::RTM_IEEE80211, ifannm), + ] + .into_iter() + .collect(); + RoutingStack { + rtm_version, + wire_formats, + kernel_align: 4, + } + } +} + /// Represents a type of routing information base. type RIBType = i32; From 300458207765877057e493a3fe2dc0d1b64bc963 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Sun, 19 May 2024 21:15:19 +0200 Subject: [PATCH 04/34] start patching libc --- iroh-net/src/net/interfaces/bsd.rs | 142 ++++++++++++++++++++--------- 1 file changed, 99 insertions(+), 43 deletions(-) diff --git a/iroh-net/src/net/interfaces/bsd.rs b/iroh-net/src/net/interfaces/bsd.rs index f767e8f85a..2e5dbe8b14 100644 --- a/iroh-net/src/net/interfaces/bsd.rs +++ b/iroh-net/src/net/interfaces/bsd.rs @@ -7,6 +7,12 @@ use std::{ net::{IpAddr, Ipv4Addr, Ipv6Addr}, }; +use libc::{ + uintptr_t, AF_INET, AF_INET6, AF_LINK, AF_ROUTE, AF_UNSPEC, CTL_NET, RTAX_BRD, RTAX_DST, + RTAX_GATEWAY, RTAX_MAX, RTAX_NETMASK, RTF_GATEWAY, +}; +#[cfg(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))] +use libc::{AF_UNSPEC, NET_RT_DUMP, NET_RT_IFLIST, NET_RT_STATS, NET_RT_TABLE}; use once_cell::sync::Lazy; use tracing::warn; @@ -14,6 +20,8 @@ use super::DefaultRouteDetails; #[cfg(target_os = "freebsd")] use freebsd::*; +#[cfg(target_os = "freebsd")] +use freebsd_libc::*; #[cfg(any(target_os = "macos", target_os = "ios"))] use macos::*; @@ -35,7 +43,7 @@ pub fn likely_home_router() -> Option { continue; } - if let Some(gw) = rm.addrs.get(libc::RTAX_GATEWAY as usize) { + if let Some(gw) = rm.addrs.get(RTAX_GATEWAY as usize) { if let Addr::Inet4 { ip } = gw { return Some(IpAddr::V4(*ip)); } @@ -80,7 +88,7 @@ const V4_DEFAULT: [u8; 4] = [0u8; 4]; const V6_DEFAULT: [u8; 16] = [0u8; 16]; fn is_default_gateway(rm: &RouteMessage) -> bool { - if rm.flags & libc::RTF_GATEWAY as u32 == 0 { + if rm.flags & RTF_GATEWAY as u32 == 0 { return false; } @@ -90,14 +98,14 @@ fn is_default_gateway(rm: &RouteMessage) -> bool { } // Addrs is [RTAX_DST, RTAX_GATEWAY, RTAX_NETMASK, ...] - if rm.addrs.len() <= libc::RTAX_NETMASK as usize { + if rm.addrs.len() <= RTAX_NETMASK as usize { return false; } - let Some(dst) = rm.addrs.get(libc::RTAX_DST as usize) else { + let Some(dst) = rm.addrs.get(RTAX_DST as usize) else { return false; }; - let Some(netmask) = rm.addrs.get(libc::RTAX_NETMASK as usize) else { + let Some(netmask) = rm.addrs.get(RTAX_NETMASK as usize) else { return false; }; @@ -119,7 +127,7 @@ fn is_default_gateway(rm: &RouteMessage) -> bool { #[cfg(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))] fn fetch_routing_table() -> Option> { - match fetch_rib(libc::AF_UNSPEC, libc::NET_RT_DUMP, 0) { + match fetch_rib(AF_UNSPEC, NET_RT_DUMP, 0) { Ok(res) => Some(res), Err(err) => { warn!("fetch_rib failed: {:?}", err); @@ -130,7 +138,7 @@ fn fetch_routing_table() -> Option> { #[cfg(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))] fn parse_routing_table(rib: &[u8]) -> Option> { - match parse_rib(libc::NET_RT_IFLIST, rib) { + match parse_rib(NET_RT_IFLIST, rib) { Ok(res) => { let res = res .into_iter() @@ -197,7 +205,7 @@ const fn is_valid_rib_type(typ: RIBType) -> bool { #[cfg(target_os = "openbsd")] const fn is_valid_rib_type(_typ: RIBType) -> bool { - if typ == libc::NET_RT_STATS || typ == libc::NET_RT_TABLE { + if typ == NET_RT_STATS || typ == NET_RT_TABLE { return false; } true @@ -250,6 +258,8 @@ impl WireFormat { target_os = "ios" ))] fn parse(&self, _typ: RIBType, data: &[u8]) -> Result, RouteError> { + use libc::{c_int, RTA_IFP}; + match self.typ { MessageType::Route => { if data.len() < self.body_off { @@ -291,7 +301,7 @@ impl WireFormat { } let attrs = u32_from_ne_range(data, 4..8)?; - if attrs as libc::c_int & libc::RTA_IFP == 0 { + if attrs as c_int & RTA_IFP == 0 { return Ok(None); } let addr = parse_link_addr(&data[self.body_off..])?; @@ -466,7 +476,7 @@ pub struct RouteMessage { /// interface index when attached pub index: u16, /// sender's identifier; usually process ID - pub id: libc::uintptr_t, + pub id: uintptr_t, /// sequence number pub seq: u32, // error on requested operation @@ -618,10 +628,54 @@ mod macos { } } +// Patch libc on freebsd +#[cfg(target_os = "freebsd")] +mod freebsd_libc { + use libc::c_int; + pub const LOCAL_PEERCRED: c_int = 1; + + // net/route.h + pub const RTF_GATEWAY: c_int = 0x2; + pub const RTA_IFP: c_int = 0x10; + pub const RTAX_DST: c_int = 0; + pub const RTAX_GATEWAY: c_int = 1; + pub const RTAX_NETMASK: c_int = 2; + pub const RTAX_IFP: c_int = 4; + pub const RTAX_BRD: c_int = 7; + pub const RTAX_MAX: c_int = 8; + pub const RTM_VERSION: c_int = 5; + + // Message types + pub const RTM_ADD: c_int = 0x1; + pub const RTM_DELETE: c_int = 0x2; + pub const RTM_CHANGE: c_int = 0x3; + pub const RTM_GET: c_int = 0x4; + pub const RTM_LOSING: c_int = 0x5; + pub const RTM_REDIRECT: c_int = 0x6; + pub const RTM_MISS: c_int = 0x7; + pub const RTM_LOCK: c_int = 0x8; + pub const RTM_OLDADD: c_int = 0x9; + pub const RTM_OLDDEL: c_int = 0xa; + pub const RTM_RESOLVE: c_int = 0xb; + pub const RTM_NEWADDR: c_int = 0xc; + pub const RTM_DELADDR: c_int = 0xd; + pub const RTM_IFINFO: c_int = 0xe; + pub const RTM_NEWMADDR: c_int = 0xf; + pub const RTM_DELMADDR: c_int = 0x10; + pub const RTM_IFANNOUNCE: c_int = 0x11; + pub const RTM_IEEE80211: c_int = 0x12; + + pub const SHUT_RD: c_int = 0; + pub const SHUT_WR: c_int = 1; + pub const SHUT_RDWR: c_int = 2; +} + #[cfg(target_os = "freebsd")] mod freebsd { use super::*; + use super::freebsd_libc::*; + // Hardcoded based on the generated values here: https://cs.opensource.google/go/x/net/+/master:route/zsys_freebsd_amd64.go #[cfg(target_pointer_width = "64")] @@ -743,7 +797,7 @@ mod freebsd { pub(super) const SIZEOF_SOCKADDR_INET6: usize = 0x1c; pub(super) fn probe_routing_stack() -> RoutingStack { - let rtm_version = libc::RTM_VERSION; + let rtm_version = RTM_VERSION; let rtm = WireFormat { ext_off: SIZEOF_RT_MSGHDR_FREEBSD10, @@ -772,22 +826,22 @@ mod freebsd { }; let wire_formats = [ - (libc::RTM_ADD, rtm), - (libc::RTM_DELETE, rtm), - (libc::RTM_CHANGE, rtm), - (libc::RTM_GET, rtm), - (libc::RTM_LOSING, rtm), - (libc::RTM_REDIRECT, rtm), - (libc::RTM_MISS, rtm), - (libc::RTM_LOCK, rtm), - (libc::RTM_RESOLVE, rtm), - (libc::RTM_NEWADDR, ifam), - (libc::RTM_DELADDR, ifam), - (libc::RTM_IFINFO, ifm), - (libc::RTM_NEWMADDR, ifmam), - (libc::RTM_DELMADDR, ifmam), - (libc::RTM_IFANNOUNCE, ifannm), - (libc::RTM_IEEE80211, ifannm), + (RTM_ADD, rtm), + (RTM_DELETE, rtm), + (RTM_CHANGE, rtm), + (RTM_GET, rtm), + (RTM_LOSING, rtm), + (RTM_REDIRECT, rtm), + (RTM_MISS, rtm), + (RTM_LOCK, rtm), + (RTM_RESOLVE, rtm), + (RTM_NEWADDR, ifam), + (RTM_DELADDR, ifam), + (RTM_IFINFO, ifm), + (RTM_NEWMADDR, ifmam), + (RTM_DELMADDR, ifmam), + (RTM_IFANNOUNCE, ifannm), + (RTM_IEEE80211, ifannm), ] .into_iter() .collect(); @@ -832,7 +886,7 @@ fn fetch_rib(af: i32, typ: RIBType, arg: i32) -> Result, RouteError> { loop { round += 1; - let mut mib: [i32; 6] = [libc::CTL_NET, libc::AF_ROUTE, 0, af, typ, arg]; + let mut mib: [i32; 6] = [CTL_NET, AF_ROUTE, 0, af, typ, arg]; let mut n: libc::size_t = 0; let err = unsafe { libc::sysctl( @@ -904,9 +958,9 @@ pub enum Addr { impl Addr { pub fn family(&self) -> i32 { match self { - Addr::Link { .. } => libc::AF_LINK, - Addr::Inet4 { .. } => libc::AF_INET, - Addr::Inet6 { .. } => libc::AF_INET6, + Addr::Link { .. } => AF_LINK, + Addr::Inet4 { .. } => AF_INET, + Addr::Inet6 { .. } => AF_INET6, Addr::Default { af, .. } => *af, } } @@ -943,11 +997,11 @@ fn parse_addrs(attrs: i32, default_fn: F, data: &[u8]) -> Result, R where F: Fn(i32, &[u8]) -> Result<(i32, Addr), RouteError>, { - let mut addrs = Vec::with_capacity(libc::RTAX_MAX as usize); - let af = libc::AF_UNSPEC; + let mut addrs = Vec::with_capacity(RTAX_MAX as usize); + let af = AF_UNSPEC; let mut b = data; - for i in 0..libc::RTAX_MAX as usize { + for i in 0..RTAX_MAX as usize { if b.len() < roundup(0) { break; } @@ -955,9 +1009,9 @@ where if attrs & (1 << i) == 0 { continue; } - if i <= libc::RTAX_BRD as usize { + if i <= RTAX_BRD as usize { match b[1] as i32 { - libc::AF_LINK => { + AF_LINK => { let a = parse_link_addr(b)?; addrs.push(a); let l = roundup(b[0] as usize); @@ -966,7 +1020,7 @@ where } b = &b[l..]; } - libc::AF_INET | libc::AF_INET6 => { + AF_INET | AF_INET6 => { let af = b[1] as i32; let a = parse_inet_addr(af, b)?; addrs.push(a); @@ -1007,7 +1061,7 @@ where /// Parses `b` as an internet address for IPv4 or IPv6. fn parse_inet_addr(af: i32, b: &[u8]) -> Result { match af { - libc::AF_INET => { + AF_INET => { if b.len() < SIZEOF_SOCKADDR_INET { return Err(RouteError::InvalidAddress); } @@ -1015,7 +1069,7 @@ fn parse_inet_addr(af: i32, b: &[u8]) -> Result { let ip = Ipv4Addr::new(b[4], b[5], b[6], b[7]); Ok(Addr::Inet4 { ip }) } - libc::AF_INET6 => { + AF_INET6 => { if b.len() < SIZEOF_SOCKADDR_INET6 { return Err(RouteError::InvalidAddress); } @@ -1103,7 +1157,7 @@ fn parse_kernel_inet_addr(af: i32, b: &[u8]) -> Result<(i32, Addr), RouteError> .ok_or(RouteError::InvalidMessage)?; let ip = Ipv6Addr::from(octets); Addr::Inet6 { ip, zone: 0 } - } else if af == libc::AF_INET6 { + } else if af == AF_INET6 { let mut octets = [0u8; 16]; if l - 1 < OFF6 { octets[..l - 1].copy_from_slice(&b[1..l]); @@ -1138,7 +1192,7 @@ fn parse_link_addr(b: &[u8]) -> Result { if b.len() < 8 { return Err(RouteError::InvalidAddress); } - let (_, mut a) = parse_kernel_link_addr(libc::AF_LINK, &b[4..])?; + let (_, mut a) = parse_kernel_link_addr(AF_LINK, &b[4..])?; if let Addr::Link { index, .. } = &mut a { *index = u16_from_ne_range(b, 2..4)? as _; @@ -1244,9 +1298,11 @@ mod tests { #[test] #[cfg(target_endian = "little")] fn test_parse_addrs() { + use libc::{RTA_BRD, RTA_DST, RTA_GATEWAY, RTA_IFA, RTA_IFP, RTA_NETMASK}; + let parse_addrs_little_endian_tests = [ ParseAddrsTest { - attrs: libc::RTA_DST | libc::RTA_GATEWAY | libc::RTA_NETMASK | libc::RTA_BRD, + attrs: RTA_DST | RTA_GATEWAY | RTA_NETMASK | RTA_BRD, parse_fn: Box::new(parse_kernel_inet_addr), b: vec![ 0x38, 0x12, 0x0, 0x0, 0xff, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, @@ -1284,7 +1340,7 @@ mod tests { ], }, ParseAddrsTest { - attrs: libc::RTA_NETMASK | libc::RTA_IFP | libc::RTA_IFA, + attrs: RTA_NETMASK | RTA_IFP | RTA_IFA, parse_fn: Box::new(parse_kernel_inet_addr), b: vec![ 0x7, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0x0, 0x18, 0x12, 0xa, 0x0, 0x87, 0x8, From 2667ef9b35e426c2eb90840766c3e7b7b381e189 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Sun, 19 May 2024 21:29:35 +0200 Subject: [PATCH 05/34] more import fixes --- iroh-net/src/net/interfaces/bsd.rs | 13 +++++-------- iroh-net/src/net/netmon/bsd.rs | 9 +++++++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/iroh-net/src/net/interfaces/bsd.rs b/iroh-net/src/net/interfaces/bsd.rs index 2e5dbe8b14..4ab70fc811 100644 --- a/iroh-net/src/net/interfaces/bsd.rs +++ b/iroh-net/src/net/interfaces/bsd.rs @@ -7,12 +7,11 @@ use std::{ net::{IpAddr, Ipv4Addr, Ipv6Addr}, }; -use libc::{ - uintptr_t, AF_INET, AF_INET6, AF_LINK, AF_ROUTE, AF_UNSPEC, CTL_NET, RTAX_BRD, RTAX_DST, - RTAX_GATEWAY, RTAX_MAX, RTAX_NETMASK, RTF_GATEWAY, -}; +use libc::{c_int, uintptr_t, AF_INET, AF_INET6, AF_LINK, AF_ROUTE, AF_UNSPEC, CTL_NET}; #[cfg(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))] -use libc::{AF_UNSPEC, NET_RT_DUMP, NET_RT_IFLIST, NET_RT_STATS, NET_RT_TABLE}; +use libc::{AF_NET_RT_DUMP, NET_RT_IFLIST}; +#[cfg(any(target_os = "macos", target_os = "ios"))] +use libc::{RTAX_BRD, RTAX_DST, RTAX_GATEWAY, RTAX_MAX, RTAX_NETMASK, RTF_GATEWAY}; use once_cell::sync::Lazy; use tracing::warn; @@ -258,8 +257,6 @@ impl WireFormat { target_os = "ios" ))] fn parse(&self, _typ: RIBType, data: &[u8]) -> Result, RouteError> { - use libc::{c_int, RTA_IFP}; - match self.typ { MessageType::Route => { if data.len() < self.body_off { @@ -630,7 +627,7 @@ mod macos { // Patch libc on freebsd #[cfg(target_os = "freebsd")] -mod freebsd_libc { +pub(crate) mod freebsd_libc { use libc::c_int; pub const LOCAL_PEERCRED: c_int = 1; diff --git a/iroh-net/src/net/netmon/bsd.rs b/iroh-net/src/net/netmon/bsd.rs index 8d498f20c4..4d0907a39e 100644 --- a/iroh-net/src/net/netmon/bsd.rs +++ b/iroh-net/src/net/netmon/bsd.rs @@ -2,6 +2,11 @@ use anyhow::Result; use tokio::{io::AsyncReadExt, task::JoinHandle}; use tracing::{trace, warn}; +#[cfg(target_os = "freebsd")] +use crate::net::interfaces::bsd::freebsd_libc::{RTAX_DST, RTAX_IFP}; +#[cfg(any(target_os = "macos", target_os = "ios"))] +use libc::{RTAX_DST, RTAX_IFP}; + use crate::net::{interfaces::bsd::WireMessage, ip::is_link_local}; use super::actor::NetworkMessage; @@ -67,7 +72,7 @@ pub(super) fn is_interesting_message(msg: &WireMessage) -> bool { WireMessage::InterfaceMulticastAddr(_) => true, WireMessage::Interface(_) => false, WireMessage::InterfaceAddr(msg) => { - if let Some(addr) = msg.addrs.get(libc::RTAX_IFP as usize) { + if let Some(addr) = msg.addrs.get(RTAX_IFP as usize) { if let Some(name) = addr.name() { if !is_interesting_interface(name) { return false; @@ -78,7 +83,7 @@ pub(super) fn is_interesting_message(msg: &WireMessage) -> bool { } WireMessage::Route(msg) => { // Ignore local unicast - if let Some(addr) = msg.addrs.get(libc::RTAX_DST as usize) { + if let Some(addr) = msg.addrs.get(RTAX_DST as usize) { if let Some(ip) = addr.ip() { if is_link_local(ip) { return false; From 172c2b81dd80820fa04bd04579be27f64974100a Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Sun, 19 May 2024 21:37:25 +0200 Subject: [PATCH 06/34] more libc fixes --- iroh-net/src/net/interfaces/bsd.rs | 22 ++++++++++++++++------ iroh-net/src/net/netmon/bsd.rs | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/iroh-net/src/net/interfaces/bsd.rs b/iroh-net/src/net/interfaces/bsd.rs index 4ab70fc811..06c8b9cc9b 100644 --- a/iroh-net/src/net/interfaces/bsd.rs +++ b/iroh-net/src/net/interfaces/bsd.rs @@ -8,10 +8,10 @@ use std::{ }; use libc::{c_int, uintptr_t, AF_INET, AF_INET6, AF_LINK, AF_ROUTE, AF_UNSPEC, CTL_NET}; -#[cfg(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))] -use libc::{AF_NET_RT_DUMP, NET_RT_IFLIST}; #[cfg(any(target_os = "macos", target_os = "ios"))] -use libc::{RTAX_BRD, RTAX_DST, RTAX_GATEWAY, RTAX_MAX, RTAX_NETMASK, RTF_GATEWAY}; +use libc::{ + NET_RT_DUMP, RTAX_BRD, RTAX_DST, RTAX_GATEWAY, RTAX_MAX, RTAX_NETMASK, RTA_IFP, RTF_GATEWAY, +}; use once_cell::sync::Lazy; use tracing::warn; @@ -126,7 +126,7 @@ fn is_default_gateway(rm: &RouteMessage) -> bool { #[cfg(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))] fn fetch_routing_table() -> Option> { - match fetch_rib(AF_UNSPEC, NET_RT_DUMP, 0) { + match fetch_rib(AF_UNSPEC, libc::NET_RT_DUMP, 0) { Ok(res) => Some(res), Err(err) => { warn!("fetch_rib failed: {:?}", err); @@ -137,7 +137,7 @@ fn fetch_routing_table() -> Option> { #[cfg(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))] fn parse_routing_table(rib: &[u8]) -> Option> { - match parse_rib(NET_RT_IFLIST, rib) { + match parse_rib(libc::NET_RT_IFLIST, rib) { Ok(res) => { let res = res .into_iter() @@ -626,7 +626,8 @@ mod macos { } // Patch libc on freebsd -#[cfg(target_os = "freebsd")] +// https://github.com/rust-lang/libc/issues/3711 +#[cfg(any(target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))] pub(crate) mod freebsd_libc { use libc::c_int; pub const LOCAL_PEERCRED: c_int = 1; @@ -641,6 +642,14 @@ pub(crate) mod freebsd_libc { pub const RTAX_BRD: c_int = 7; pub const RTAX_MAX: c_int = 8; pub const RTM_VERSION: c_int = 5; + pub const RTA_DST: c_int = 0x1; + pub const RTA_GATEWAY: c_int = 0x2; + pub const RTA_NETMASK: c_int = 0x4; + pub const RTA_GENMASK: c_int = 0x8; + pub const RTA_IFP: c_int = 0x10; + pub const RTA_IFA: c_int = 0x20; + pub const RTA_AUTHOR: c_int = 0x40; + pub const RTA_BRD: c_int = 0x80; // Message types pub const RTM_ADD: c_int = 0x1; @@ -1295,6 +1304,7 @@ mod tests { #[test] #[cfg(target_endian = "little")] fn test_parse_addrs() { + #[cfg(any(target_os = "macos", target_os = "ios"))] use libc::{RTA_BRD, RTA_DST, RTA_GATEWAY, RTA_IFA, RTA_IFP, RTA_NETMASK}; let parse_addrs_little_endian_tests = [ diff --git a/iroh-net/src/net/netmon/bsd.rs b/iroh-net/src/net/netmon/bsd.rs index 4d0907a39e..e8e18590d2 100644 --- a/iroh-net/src/net/netmon/bsd.rs +++ b/iroh-net/src/net/netmon/bsd.rs @@ -2,7 +2,7 @@ use anyhow::Result; use tokio::{io::AsyncReadExt, task::JoinHandle}; use tracing::{trace, warn}; -#[cfg(target_os = "freebsd")] +#[cfg(any(target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))] use crate::net::interfaces::bsd::freebsd_libc::{RTAX_DST, RTAX_IFP}; #[cfg(any(target_os = "macos", target_os = "ios"))] use libc::{RTAX_DST, RTAX_IFP}; From 4fa710b45fb39bab691200a60efbc067dde6e214 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Sun, 19 May 2024 21:38:31 +0200 Subject: [PATCH 07/34] fixups --- iroh-net/src/net/interfaces/bsd.rs | 7 +++---- iroh-net/src/net/netmon/bsd.rs | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/iroh-net/src/net/interfaces/bsd.rs b/iroh-net/src/net/interfaces/bsd.rs index 06c8b9cc9b..dcef802fb1 100644 --- a/iroh-net/src/net/interfaces/bsd.rs +++ b/iroh-net/src/net/interfaces/bsd.rs @@ -19,8 +19,8 @@ use super::DefaultRouteDetails; #[cfg(target_os = "freebsd")] use freebsd::*; -#[cfg(target_os = "freebsd")] -use freebsd_libc::*; +#[cfg(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))] +use bsd_libc::*; #[cfg(any(target_os = "macos", target_os = "ios"))] use macos::*; @@ -628,13 +628,12 @@ mod macos { // Patch libc on freebsd // https://github.com/rust-lang/libc/issues/3711 #[cfg(any(target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))] -pub(crate) mod freebsd_libc { +pub(crate) mod bsd_libc { use libc::c_int; pub const LOCAL_PEERCRED: c_int = 1; // net/route.h pub const RTF_GATEWAY: c_int = 0x2; - pub const RTA_IFP: c_int = 0x10; pub const RTAX_DST: c_int = 0; pub const RTAX_GATEWAY: c_int = 1; pub const RTAX_NETMASK: c_int = 2; diff --git a/iroh-net/src/net/netmon/bsd.rs b/iroh-net/src/net/netmon/bsd.rs index e8e18590d2..92028629f1 100644 --- a/iroh-net/src/net/netmon/bsd.rs +++ b/iroh-net/src/net/netmon/bsd.rs @@ -3,7 +3,7 @@ use tokio::{io::AsyncReadExt, task::JoinHandle}; use tracing::{trace, warn}; #[cfg(any(target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))] -use crate::net::interfaces::bsd::freebsd_libc::{RTAX_DST, RTAX_IFP}; +use crate::net::interfaces::bsd::bsd_libc::{RTAX_DST, RTAX_IFP}; #[cfg(any(target_os = "macos", target_os = "ios"))] use libc::{RTAX_DST, RTAX_IFP}; From 03286666c60067f0c14745c71d660f6b63f4a23a Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Sun, 19 May 2024 21:39:29 +0200 Subject: [PATCH 08/34] naming is hard --- iroh-net/src/net/interfaces/bsd.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iroh-net/src/net/interfaces/bsd.rs b/iroh-net/src/net/interfaces/bsd.rs index dcef802fb1..e51175459c 100644 --- a/iroh-net/src/net/interfaces/bsd.rs +++ b/iroh-net/src/net/interfaces/bsd.rs @@ -679,7 +679,7 @@ pub(crate) mod bsd_libc { mod freebsd { use super::*; - use super::freebsd_libc::*; + use super::bsd_libc::*; // Hardcoded based on the generated values here: https://cs.opensource.google/go/x/net/+/master:route/zsys_freebsd_amd64.go From 851661f4e4aff98b7d5636defebf2bf52254d16e Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Sun, 19 May 2024 21:43:45 +0200 Subject: [PATCH 09/34] fmt --- iroh-net/src/net/interfaces/bsd.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iroh-net/src/net/interfaces/bsd.rs b/iroh-net/src/net/interfaces/bsd.rs index e51175459c..4e183ff442 100644 --- a/iroh-net/src/net/interfaces/bsd.rs +++ b/iroh-net/src/net/interfaces/bsd.rs @@ -17,10 +17,10 @@ use tracing::warn; use super::DefaultRouteDetails; -#[cfg(target_os = "freebsd")] -use freebsd::*; #[cfg(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))] use bsd_libc::*; +#[cfg(target_os = "freebsd")] +use freebsd::*; #[cfg(any(target_os = "macos", target_os = "ios"))] use macos::*; From cddd3baf562da4e194eab8af3a681258993331f7 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Sun, 19 May 2024 21:45:21 +0200 Subject: [PATCH 10/34] move freebsd to build only for now --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 29597d7f7f..cd0b3e3168 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,6 +38,9 @@ jobs: # see https://github.com/cross-rs/cross/issues/1311 - armv7-linux-androideabi - aarch64-linux-android + # Freebsd execution fails in cross + - i686-unknown-freebsd + - x86_64-unknown-freebsd steps: - name: Checkout uses: actions/checkout@v4 @@ -74,8 +77,6 @@ jobs: matrix: target: - i686-unknown-linux-gnu - - i686-unknown-freebsd - - x86_64-unknown-freebsd steps: - name: Checkout uses: actions/checkout@v4 From 821d7e8e84e38db1c0903a41c228ad6e1ff2909c Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Tue, 21 May 2024 13:00:39 +0200 Subject: [PATCH 11/34] restructure --- iroh-net/src/net/interfaces/bsd.rs | 335 +-------------------- iroh-net/src/net/interfaces/bsd/freebsd.rs | 317 +++++++++++++++++++ iroh-net/src/net/interfaces/bsd/macos.rs | 86 ++++++ 3 files changed, 410 insertions(+), 328 deletions(-) create mode 100644 iroh-net/src/net/interfaces/bsd/freebsd.rs create mode 100644 iroh-net/src/net/interfaces/bsd/macos.rs diff --git a/iroh-net/src/net/interfaces/bsd.rs b/iroh-net/src/net/interfaces/bsd.rs index 4e183ff442..cdd62db056 100644 --- a/iroh-net/src/net/interfaces/bsd.rs +++ b/iroh-net/src/net/interfaces/bsd.rs @@ -17,12 +17,15 @@ use tracing::warn; use super::DefaultRouteDetails; -#[cfg(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))] -use bsd_libc::*; #[cfg(target_os = "freebsd")] -use freebsd::*; +mod freebsd; +#[cfg(target_os = "freebsd")] +use self::freebsd::*; + #[cfg(any(target_os = "macos", target_os = "ios"))] -use macos::*; +mod macos; +#[cfg(any(target_os = "macos", target_os = "ios"))] +use self::macos::*; pub async fn default_route() -> Option { let idx = default_route_interface_index()?; @@ -534,330 +537,6 @@ pub struct InterfaceMulticastAddrMessage { pub addrs: Vec, } -#[cfg(any(target_os = "macos", target_os = "ios"))] -mod macos { - use super::*; - - // Hardcoded based on the generated values here: https://cs.opensource.google/go/x/net/+/master:route/zsys_darwin.go - - pub(super) const SIZEOF_IF_MSGHDR_DARWIN15: usize = 0x70; - pub(super) const SIZEOF_IFA_MSGHDR_DARWIN15: usize = 0x14; - pub(super) const SIZEOF_IFMA_MSGHDR_DARWIN15: usize = 0x10; - pub(super) const SIZEOF_IF_MSGHDR2_DARWIN15: usize = 0xa0; - pub(super) const SIZEOF_IFMA_MSGHDR2_DARWIN15: usize = 0x14; - pub(super) const SIZEOF_IF_DATA_DARWIN15: usize = 0x60; - pub(super) const SIZEOF_IF_DATA64_DARWIN15: usize = 0x80; - - pub(super) const SIZEOF_RT_MSGHDR_DARWIN15: usize = 0x5c; - pub(super) const SIZEOF_RT_MSGHDR2_DARWIN15: usize = 0x5c; - pub(super) const SIZEOF_RT_METRICS_DARWIN15: usize = 0x38; - - pub(super) const SIZEOF_SOCKADDR_STORAGE: usize = 0x80; - pub(super) const SIZEOF_SOCKADDR_INET: usize = 0x10; - pub(super) const SIZEOF_SOCKADDR_INET6: usize = 0x1c; - - pub(super) fn probe_routing_stack() -> RoutingStack { - let rtm_version = libc::RTM_VERSION; - - let rtm = WireFormat { - ext_off: 36, - body_off: SIZEOF_RT_MSGHDR_DARWIN15, - typ: MessageType::Route, - }; - let rtm2 = WireFormat { - ext_off: 36, - body_off: SIZEOF_RT_MSGHDR2_DARWIN15, - typ: MessageType::Route, - }; - let ifm = WireFormat { - ext_off: 16, - body_off: SIZEOF_IF_MSGHDR_DARWIN15, - typ: MessageType::Interface, - }; - let ifm2 = WireFormat { - ext_off: 32, - body_off: SIZEOF_IF_MSGHDR2_DARWIN15, - typ: MessageType::Interface, - }; - let ifam = WireFormat { - ext_off: SIZEOF_IFA_MSGHDR_DARWIN15, - body_off: SIZEOF_IFA_MSGHDR_DARWIN15, - typ: MessageType::InterfaceAddr, - }; - let ifmam = WireFormat { - ext_off: SIZEOF_IFMA_MSGHDR_DARWIN15, - body_off: SIZEOF_IFMA_MSGHDR_DARWIN15, - typ: MessageType::InterfaceMulticastAddr, - }; - let ifmam2 = WireFormat { - ext_off: SIZEOF_IFMA_MSGHDR2_DARWIN15, - body_off: SIZEOF_IFMA_MSGHDR2_DARWIN15, - typ: MessageType::InterfaceMulticastAddr, - }; - - let wire_formats = [ - (libc::RTM_ADD, rtm), - (libc::RTM_DELETE, rtm), - (libc::RTM_CHANGE, rtm), - (libc::RTM_GET, rtm), - (libc::RTM_LOSING, rtm), - (libc::RTM_REDIRECT, rtm), - (libc::RTM_MISS, rtm), - (libc::RTM_LOCK, rtm), - (libc::RTM_RESOLVE, rtm), - (libc::RTM_NEWADDR, ifam), - (libc::RTM_DELADDR, ifam), - (libc::RTM_IFINFO, ifm), - (libc::RTM_NEWMADDR, ifmam), - (libc::RTM_DELMADDR, ifmam), - (libc::RTM_IFINFO2, ifm2), - (libc::RTM_NEWMADDR2, ifmam2), - (libc::RTM_GET2, rtm2), - ] - .into_iter() - .collect(); - - RoutingStack { - rtm_version, - wire_formats, - kernel_align: 4, - } - } -} - -// Patch libc on freebsd -// https://github.com/rust-lang/libc/issues/3711 -#[cfg(any(target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))] -pub(crate) mod bsd_libc { - use libc::c_int; - pub const LOCAL_PEERCRED: c_int = 1; - - // net/route.h - pub const RTF_GATEWAY: c_int = 0x2; - pub const RTAX_DST: c_int = 0; - pub const RTAX_GATEWAY: c_int = 1; - pub const RTAX_NETMASK: c_int = 2; - pub const RTAX_IFP: c_int = 4; - pub const RTAX_BRD: c_int = 7; - pub const RTAX_MAX: c_int = 8; - pub const RTM_VERSION: c_int = 5; - pub const RTA_DST: c_int = 0x1; - pub const RTA_GATEWAY: c_int = 0x2; - pub const RTA_NETMASK: c_int = 0x4; - pub const RTA_GENMASK: c_int = 0x8; - pub const RTA_IFP: c_int = 0x10; - pub const RTA_IFA: c_int = 0x20; - pub const RTA_AUTHOR: c_int = 0x40; - pub const RTA_BRD: c_int = 0x80; - - // Message types - pub const RTM_ADD: c_int = 0x1; - pub const RTM_DELETE: c_int = 0x2; - pub const RTM_CHANGE: c_int = 0x3; - pub const RTM_GET: c_int = 0x4; - pub const RTM_LOSING: c_int = 0x5; - pub const RTM_REDIRECT: c_int = 0x6; - pub const RTM_MISS: c_int = 0x7; - pub const RTM_LOCK: c_int = 0x8; - pub const RTM_OLDADD: c_int = 0x9; - pub const RTM_OLDDEL: c_int = 0xa; - pub const RTM_RESOLVE: c_int = 0xb; - pub const RTM_NEWADDR: c_int = 0xc; - pub const RTM_DELADDR: c_int = 0xd; - pub const RTM_IFINFO: c_int = 0xe; - pub const RTM_NEWMADDR: c_int = 0xf; - pub const RTM_DELMADDR: c_int = 0x10; - pub const RTM_IFANNOUNCE: c_int = 0x11; - pub const RTM_IEEE80211: c_int = 0x12; - - pub const SHUT_RD: c_int = 0; - pub const SHUT_WR: c_int = 1; - pub const SHUT_RDWR: c_int = 2; -} - -#[cfg(target_os = "freebsd")] -mod freebsd { - use super::*; - - use super::bsd_libc::*; - - // Hardcoded based on the generated values here: https://cs.opensource.google/go/x/net/+/master:route/zsys_freebsd_amd64.go - - #[cfg(target_pointer_width = "64")] - pub(super) const SIZEOF_IF_MSGHDRL_FREEBSD10: usize = 0xb0; - #[cfg(target_pointer_width = "32")] - pub(super) const SIZEOF_IF_MSGHDRL_FREEBSD10: usize = 0x68; - pub(super) const SIZEOF_IFA_MSGHDR_FREEBSD10: usize = 0x14; - - #[cfg(target_pointer_width = "64")] - pub(super) const SIZEOF_IFA_MSGHDRL_FREEBSD10: usize = 0xb0; - #[cfg(target_pointer_width = "32")] - pub(super) const SIZEOF_IFA_MSGHDRL_FREEBSD10: usize = 0x6c; - - pub(super) const SIZEOF_IFMA_MSGHDR_FREEBSD10: usize = 0x10; - pub(super) const SIZEOF_IF_ANNOUNCEMSGHDR_FREEBSD10: usize = 0x18; - - #[cfg(target_pointer_width = "64")] - pub(super) const SIZEOF_RT_MSGHDR_FREEBSD10: usize = 0x98; - #[cfg(target_pointer_width = "32")] - pub(super) const SIZEOF_RT_MSGHDR_FREEBSD10: usize = 0x5c; - #[cfg(target_pointer_width = "64")] - pub(super) const SIZEOF_RT_METRICS_FREEBSD10: usize = 0x70; - #[cfg(target_pointer_width = "32")] - pub(super) const SIZEOF_RT_METRICS_FREEBSD10: usize = 0x38; - - #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] - pub(super) const SIZEOF_IF_MSGHDR_FREEBSD7: usize = 0xa8; - #[cfg(target_arch = "x86")] - pub(super) const SIZEOF_IF_MSGHDR_FREEBSD7: usize = 0x60; - #[cfg(target_arch = "arm")] - pub(super) const SIZEOF_IF_MSGHDR_FREEBSD7: usize = 0x70; - - #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] - pub(super) const SIZEOF_IF_MSGHDR_FREEBSD8: usize = 0xa8; - #[cfg(target_arch = "x86")] - pub(super) const SIZEOF_IF_MSGHDR_FREEBSD8: usize = 0x60; - #[cfg(target_arch = "arm")] - pub(super) const SIZEOF_IF_MSGHDR_FREEBSD8: usize = 0x70; - - #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] - pub(super) const SIZEOF_IF_MSGHDR_FREEBSD9: usize = 0xa8; - #[cfg(target_arch = "x86")] - pub(super) const SIZEOF_IF_MSGHDR_FREEBSD9: usize = 0x60; - #[cfg(target_arch = "arm")] - pub(super) const SIZEOF_IF_MSGHDR_FREEBSD9: usize = 0x70; - - #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] - pub(super) const SIZEOF_IF_MSGHDR_FREEBSD10: usize = 0xa8; - #[cfg(target_arch = "x86")] - pub(super) const SIZEOF_IF_MSGHDR_FREEBSD10: usize = 0x64; - #[cfg(target_arch = "arm")] - pub(super) const SIZEOF_IF_MSGHDR_FREEBSD10: usize = 0x70; - - #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] - pub(super) const SIZEOF_IF_MSGHDR_FREEBSD11: usize = 0xa8; - #[cfg(target_arch = "x86")] - pub(super) const SIZEOF_IF_MSGHDR_FREEBSD11: usize = 0xa8; - #[cfg(target_arch = "arm")] - pub(super) const SIZEOF_IF_MSGHDR_FREEBSD11: usize = 0xa8; - - #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] - pub(super) const SIZE_OF_IF_DATA_FREEBSD7: usize = 0x98; - #[cfg(target_arch = "x86")] - pub(super) const SIZEOF_IF_DATA_FREEBSD7: usize = 0x50; - #[cfg(target_arch = "arm")] - pub(super) const SIZEOF_IF_DATA_FREEBSD7: usize = 0x60; - - #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] - pub(super) const SIZE_OF_IF_DATA_FREEBSD8: usize = 0x98; - #[cfg(target_arch = "x86")] - pub(super) const SIZEOF_IF_DATA_FREEBSD8: usize = 0x50; - #[cfg(target_arch = "arm")] - pub(super) const SIZEOF_IF_DATA_FREEBSD8: usize = 0x60; - - #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] - pub(super) const SIZE_OF_IF_DATA_FREEBSD9: usize = 0x98; - #[cfg(target_arch = "x86")] - pub(super) const SIZEOF_IF_DATA_FREEBSD9: usize = 0x50; - #[cfg(target_arch = "arm")] - pub(super) const SIZEOF_IF_DATA_FREEBSD9: usize = 0x60; - - #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] - pub(super) const SIZE_OF_IF_DATA_FREEBSD10: usize = 0x98; - #[cfg(target_arch = "x86")] - pub(super) const SIZEOF_IF_DATA_FREEBSD10: usize = 0x54; - #[cfg(target_arch = "arm")] - pub(super) const SIZEOF_IF_DATA_FREEBSD10: usize = 0x60; - - #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] - pub(super) const SIZE_OF_IF_DATA_FREEBSD11: usize = 0x98; - #[cfg(target_arch = "x86")] - pub(super) const SIZEOF_IF_DATA_FREEBSD11: usize = 0x98; - #[cfg(target_arch = "arm")] - pub(super) const SIZEOF_IF_DATA_FREEBSD11: usize = 0x98; - - pub(super) const SIZEOF_IF_MSGHDRL_FREEBSD10_EMU: usize = 0xb0; - pub(super) const SIZEOF_IFA_MSGHDR_FREEBSD10_EMU: usize = 0x14; - pub(super) const SIZEOF_IFA_MSGHDRL_FREEBSD10_EMU: usize = 0xb0; - pub(super) const SIZEOF_IFMA_MSGHDR_FREEBSD10_EMU: usize = 0x10; - pub(super) const SIZEOF_IF_ANNOUNCEMSGHDR_FREEBSD10_EMU: usize = 0x18; - - pub(super) const SIZEOF_RT_MSGHDR_FREEBSD10_EMU: usize = 0x98; - pub(super) const SIZEOF_RT_METRICS_FREEBSD10_EMU: usize = 0x70; - - pub(super) const SIZEOF_IF_MSGHDR_FREEBSD7_EMU: usize = 0xa8; - pub(super) const SIZEOF_IF_MSGHDR_FREEBSD8_EMU: usize = 0xa8; - pub(super) const SIZEOF_IF_MSGHDR_FREEBSD9_EMU: usize = 0xa8; - pub(super) const SIZEOF_IF_MSGHDR_FREEBSD10_EMU: usize = 0xa8; - pub(super) const SIZEOF_IF_MSGHDR_FREEBSD11_EMU: usize = 0xa8; - - pub(super) const SIZEOF_IF_DATA_FREEBSD7_EMU: usize = 0x98; - pub(super) const SIZEOF_IF_DATA_FREEBSD8_EMU: usize = 0x98; - pub(super) const SIZEOF_IF_DATA_FREEBSD9_EMU: usize = 0x98; - pub(super) const SIZEOF_IF_DATA_FREEBSD10_EMU: usize = 0x98; - pub(super) const SIZEOF_IF_DATA_FREEBSD11_EMU: usize = 0x98; - - pub(super) const SIZEOF_SOCKADDR_STORAGE: usize = 0x80; - pub(super) const SIZEOF_SOCKADDR_INET: usize = 0x10; - pub(super) const SIZEOF_SOCKADDR_INET6: usize = 0x1c; - - pub(super) fn probe_routing_stack() -> RoutingStack { - let rtm_version = RTM_VERSION; - - let rtm = WireFormat { - ext_off: SIZEOF_RT_MSGHDR_FREEBSD10, - body_off: SIZEOF_RT_MSGHDR_FREEBSD10, - typ: MessageType::Route, - }; - let ifm = WireFormat { - ext_off: SIZEOF_IF_MSGHDR_FREEBSD11, - body_off: SIZEOF_IF_MSGHDR_FREEBSD11, - typ: MessageType::Interface, - }; - let ifam = WireFormat { - ext_off: SIZEOF_IFA_MSGHDR_FREEBSD10, - body_off: SIZEOF_IFA_MSGHDR_FREEBSD10, - typ: MessageType::InterfaceAddr, - }; - let ifmam = WireFormat { - ext_off: SIZEOF_IFMA_MSGHDR_FREEBSD10, - body_off: SIZEOF_IFMA_MSGHDR_FREEBSD10, - typ: MessageType::InterfaceMulticastAddr, - }; - let ifannm = WireFormat { - ext_off: SIZEOF_IF_ANNOUNCEMSGHDR_FREEBSD10, - body_off: SIZEOF_IF_ANNOUNCEMSGHDR_FREEBSD10, - typ: MessageType::Interface, - }; - - let wire_formats = [ - (RTM_ADD, rtm), - (RTM_DELETE, rtm), - (RTM_CHANGE, rtm), - (RTM_GET, rtm), - (RTM_LOSING, rtm), - (RTM_REDIRECT, rtm), - (RTM_MISS, rtm), - (RTM_LOCK, rtm), - (RTM_RESOLVE, rtm), - (RTM_NEWADDR, ifam), - (RTM_DELADDR, ifam), - (RTM_IFINFO, ifm), - (RTM_NEWMADDR, ifmam), - (RTM_DELMADDR, ifmam), - (RTM_IFANNOUNCE, ifannm), - (RTM_IEEE80211, ifannm), - ] - .into_iter() - .collect(); - RoutingStack { - rtm_version, - wire_formats, - kernel_align: 4, - } - } -} - /// Represents a type of routing information base. type RIBType = i32; diff --git a/iroh-net/src/net/interfaces/bsd/freebsd.rs b/iroh-net/src/net/interfaces/bsd/freebsd.rs new file mode 100644 index 0000000000..d4705699fa --- /dev/null +++ b/iroh-net/src/net/interfaces/bsd/freebsd.rs @@ -0,0 +1,317 @@ +use super::{MessageType, RoutingStack, WireFormat}; + +use libc::c_int; + +// Missing constants from libc. +// https://github.com/rust-lang/libc/issues/3711 + +const LOCAL_PEERCRED: c_int = 1; + +// net/route.h +const RTF_GATEWAY: c_int = 0x2; +const RTAX_DST: c_int = 0; +const RTAX_GATEWAY: c_int = 1; +const RTAX_NETMASK: c_int = 2; +const RTAX_IFP: c_int = 4; +const RTAX_BRD: c_int = 7; +const RTAX_MAX: c_int = 8; +const RTM_VERSION: c_int = 5; +const RTA_DST: c_int = 0x1; +const RTA_GATEWAY: c_int = 0x2; +const RTA_NETMASK: c_int = 0x4; +const RTA_GENMASK: c_int = 0x8; +const RTA_IFP: c_int = 0x10; +const RTA_IFA: c_int = 0x20; +const RTA_AUTHOR: c_int = 0x40; +const RTA_BRD: c_int = 0x80; + +// Message types +const RTM_ADD: c_int = 0x1; +const RTM_DELETE: c_int = 0x2; +const RTM_CHANGE: c_int = 0x3; +const RTM_GET: c_int = 0x4; +const RTM_LOSING: c_int = 0x5; +const RTM_REDIRECT: c_int = 0x6; +const RTM_MISS: c_int = 0x7; +const RTM_LOCK: c_int = 0x8; +const RTM_OLDADD: c_int = 0x9; +const RTM_OLDDEL: c_int = 0xa; +const RTM_RESOLVE: c_int = 0xb; +const RTM_NEWADDR: c_int = 0xc; +const RTM_DELADDR: c_int = 0xd; +const RTM_IFINFO: c_int = 0xe; +const RTM_NEWMADDR: c_int = 0xf; +const RTM_DELMADDR: c_int = 0x10; +const RTM_IFANNOUNCE: c_int = 0x11; +const RTM_IEEE80211: c_int = 0x12; + +const SHUT_RD: c_int = 0; +const SHUT_WR: c_int = 1; +const SHUT_RDWR: c_int = 2; + +// Hardcoded based on the generated values here: https://cs.opensource.google/go/x/net/+/master:route/zsys_freebsd_amd64.go +#[cfg(target_arch = "x86_64")] +use self::amd64::*; +#[cfg(target_arch = "x86_64")] +mod amd64 { + pub(super) const SIZEOF_IF_MSGHDRL_FREE_BSD10: usize = 0xb0; + pub(super) const SIZEOF_IFA_MSGHDR_FREE_BSD10: usize = 0x14; + pub(super) const SIZEOF_IFA_MSGHDRL_FREE_BSD10: usize = 0xb0; + pub(super) const SIZEOF_IFMA_MSGHDR_FREE_BSD10: usize = 0x10; + pub(super) const SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10: usize = 0x18; + + pub(super) const SIZEOF_RT_MSGHDR_FREE_BSD10: usize = 0x98; + pub(super) const SIZEOF_RT_METRICS_FREE_BSD10: usize = 0x70; + + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD7: usize = 0xa8; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD8: usize = 0xa8; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD9: usize = 0xa8; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD10: usize = 0xa8; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD11: usize = 0xa8; + + pub(super) const SIZEOF_IF_DATA_FREE_BSD7: usize = 0x98; + pub(super) const SIZEOF_IF_DATA_FREE_BSD8: usize = 0x98; + pub(super) const SIZEOF_IF_DATA_FREE_BSD9: usize = 0x98; + pub(super) const SIZEOF_IF_DATA_FREE_BSD10: usize = 0x98; + pub(super) const SIZEOF_IF_DATA_FREE_BSD11: usize = 0x98; + + pub(super) const SIZEOF_IF_MSGHDRL_FREE_BSD10_EMU: usize = 0xb0; + pub(super) const SIZEOF_IFA_MSGHDR_FREE_BSD10_EMU: usize = 0x14; + pub(super) const SIZEOF_IFA_MSGHDRL_FREE_BSD10_EMU: usize = 0xb0; + pub(super) const SIZEOF_IFMA_MSGHDR_FREE_BSD10_EMU: usize = 0x10; + pub(super) const SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10_EMU: usize = 0x18; + + pub(super) const SIZEOF_RT_MSGHDR_FREE_BSD10_EMU: usize = 0x98; + pub(super) const SIZEOF_RT_METRICS_FREE_BSD10_EMU: usize = 0x70; + + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD7_EMU: usize = 0xa8; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD8_EMU: usize = 0xa8; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD9_EMU: usize = 0xa8; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD10_EMU: usize = 0xa8; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD11_EMU: usize = 0xa8; + + pub(super) const SIZEOF_IF_DATA_FREE_BSD7_EMU: usize = 0x98; + pub(super) const SIZEOF_IF_DATA_FREE_BSD8_EMU: usize = 0x98; + pub(super) const SIZEOF_IF_DATA_FREE_BSD9_EMU: usize = 0x98; + pub(super) const SIZEOF_IF_DATA_FREE_BSD10_EMU: usize = 0x98; + pub(super) const SIZEOF_IF_DATA_FREE_BSD11_EMU: usize = 0x98; + + pub(super) const SIZEOF_SOCKADDR_STORAGE: usize = 0x80; + pub(super) const SIZEOF_SOCKADDR_INET: usize = 0x10; + pub(super) const SIZEOF_SOCKADDR_INET6: usize = 0x1c; +} + +// Hardcoded based on the generated values here: https://cs.opensource.google/go/x/net/+/master:route/zsys_freebsd_386.go +#[cfg(target_arch = "x86")] +use self::i686::*; +#[cfg(target_arch = "x86")] +mod i686 { + pub(super) const SIZEOF_IF_MSGHDRL_FREE_BSD10: usize = 0x68; + pub(super) const SIZEOF_IFA_MSGHDR_FREE_BSD10: usize = 0x14; + pub(super) const SIZEOF_IFA_MSGHDRL_FREE_BSD10: usize = 0x6c; + pub(super) const SIZEOF_IFMA_MSGHDR_FREE_BSD10: usize = 0x10; + pub(super) const SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10: usize = 0x18; + + pub(super) const SIZEOF_RT_MSGHDR_FREE_BSD10: usize = 0x5c; + pub(super) const SIZEOF_RT_METRICS_FREE_BSD10: usize = 0x38; + + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD7: usize = 0x60; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD8: usize = 0x60; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD9: usize = 0x60; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD10: usize = 0x64; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD11: usize = 0xa8; + + pub(super) const SIZEOF_IF_DATA_FREE_BSD7: usize = 0x50; + pub(super) const SIZEOF_IF_DATA_FREE_BSD8: usize = 0x50; + pub(super) const SIZEOF_IF_DATA_FREE_BSD9: usize = 0x50; + pub(super) const SIZEOF_IF_DATA_FREE_BSD10: usize = 0x54; + pub(super) const SIZEOF_IF_DATA_FREE_BSD11: usize = 0x98; + + // MODIFIED BY HAND FOR 386 EMULATION ON AMD64 + // 386 EMULATION USES THE UNDERLYING RAW DATA LAYOUT + + pub(super) const SIZEOF_IF_MSGHDRL_FREE_BSD10_EMU: usize = 0xb0; + pub(super) const SIZEOF_IFA_MSGHDR_FREE_BSD10_EMU: usize = 0x14; + pub(super) const SIZEOF_IFA_MSGHDRL_FREE_BSD10_EMU: usize = 0xb0; + pub(super) const SIZEOF_IFMA_MSGHDR_FREE_BSD10_EMU: usize = 0x10; + pub(super) const SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10_EMU: usize = 0x18; + + pub(super) const SIZEOF_RT_MSGHDR_FREE_BSD10_EMU: usize = 0x98; + pub(super) const SIZEOF_RT_METRICS_FREE_BSD10_EMU: usize = 0x70; + + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD7_EMU: usize = 0xa8; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD8_EMU: usize = 0xa8; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD9_EMU: usize = 0xa8; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD10_EMU: usize = 0xa8; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD11_EMU: usize = 0xa8; + + pub(super) const SIZEOF_IF_DATA_FREE_BSD7_EMU: usize = 0x98; + pub(super) const SIZEOF_IF_DATA_FREE_BSD8_EMU: usize = 0x98; + pub(super) const SIZEOF_IF_DATA_FREE_BSD9_EMU: usize = 0x98; + pub(super) const SIZEOF_IF_DATA_FREE_BSD10_EMU: usize = 0x98; + pub(super) const SIZEOF_IF_DATA_FREE_BSD11_EMU: usize = 0x98; + + pub(super) const SIZEOF_SOCKADDR_STORAGE: usize = 0x80; + pub(super) const SIZEOF_SOCKADDR_INET: usize = 0x10; + pub(super) const SIZEOF_SOCKADDR_INET6: usize = 0x1c; +} + +// Hardcoded based on the generated values here: https://cs.opensource.google/go/x/net/+/master:route/zsys_freebsd_arm.go +#[cfg(target_arch = "arm")] +use self::arm::*; +#[cfg(target_arch = "arm")] +mod arm { + pub(super) const SIZEOF_IF_MSGHDRL_FREE_BSD10: usize = 0x68; + pub(super) const SIZEOF_IFA_MSGHDR_FREE_BSD10: usize = 0x14; + pub(super) const SIZEOF_IFA_MSGHDRL_FREE_BSD10: usize = 0x6c; + pub(super) const SIZEOF_IFMA_MSGHDR_FREE_BSD10: usize = 0x10; + pub(super) const SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10: usize = 0x18; + + pub(super) const SIZEOF_RT_MSGHDR_FREE_BSD10: usize = 0x5c; + pub(super) const SIZEOF_RT_METRICS_FREE_BSD10: usize = 0x38; + + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD7: usize = 0x70; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD8: usize = 0x70; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD9: usize = 0x70; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD10: usize = 0x70; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD11: usize = 0xa8; + + pub(super) const SIZEOF_IF_DATA_FREE_BSD7: usize = 0x60; + pub(super) const SIZEOF_IF_DATA_FREE_BSD8: usize = 0x60; + pub(super) const SIZEOF_IF_DATA_FREE_BSD9: usize = 0x60; + pub(super) const SIZEOF_IF_DATA_FREE_BSD10: usize = 0x60; + pub(super) const SIZEOF_IF_DATA_FREE_BSD11: usize = 0x98; + + pub(super) const SIZEOF_IF_MSGHDRL_FREE_BSD10_EMU: usize = 0x68; + pub(super) const SIZEOF_IFA_MSGHDR_FREE_BSD10_EMU: usize = 0x14; + pub(super) const SIZEOF_IFA_MSGHDRL_FREE_BSD10_EMU: usize = 0x6c; + pub(super) const SIZEOF_IFMA_MSGHDR_FREE_BSD10_EMU: usize = 0x10; + pub(super) const SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10_EMU: usize = 0x18; + + pub(super) const SIZEOF_RT_MSGHDR_FREE_BSD10_EMU: usize = 0x5c; + pub(super) const SIZEOF_RT_METRICS_FREE_BSD10_EMU: usize = 0x38; + + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD7_EMU: usize = 0x70; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD8_EMU: usize = 0x70; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD9_EMU: usize = 0x70; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD10_EMU: usize = 0x70; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD11_EMU: usize = 0xa8; + + pub(super) const SIZEOF_IF_DATA_FREE_BSD7_EMU: usize = 0x60; + pub(super) const SIZEOF_IF_DATA_FREE_BSD8_EMU: usize = 0x60; + pub(super) const SIZEOF_IF_DATA_FREE_BSD9_EMU: usize = 0x60; + pub(super) const SIZEOF_IF_DATA_FREE_BSD10_EMU: usize = 0x60; + pub(super) const SIZEOF_IF_DATA_FREE_BSD11_EMU: usize = 0x98; + + pub(super) const SIZEOF_SOCKADDR_STORAGE: usize = 0x80; + pub(super) const SIZEOF_SOCKADDR_INET: usize = 0x10; + pub(super) const SIZEOF_SOCKADDR_INET6: usize = 0x1c; +} + +// Hardcoded based on the generated values here: https://cs.opensource.google/go/x/net/+/master:route/zsys_freebsd_arm.go +#[cfg(target_arch = "aarch64")] +use self::arm64::*; +#[cfg(target_arch = "aarch64")] +mod arm64 { + pub(super) const SIZEOF_IF_MSGHDRL_FREE_BSD10: usize = 0xb0; + pub(super) const SIZEOF_IFA_MSGHDR_FREE_BSD10: usize = 0x14; + pub(super) const SIZEOF_IFA_MSGHDRL_FREE_BSD10: usize = 0xb0; + pub(super) const SIZEOF_IFMA_MSGHDR_FREE_BSD10: usize = 0x10; + pub(super) const SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10: usize = 0x18; + + pub(super) const SIZEOF_RT_MSGHDR_FREE_BSD10: usize = 0x98; + pub(super) const SIZEOF_RT_METRICS_FREE_BSD10: usize = 0x70; + + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD7: usize = 0xa8; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD8: usize = 0xa8; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD9: usize = 0xa8; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD10: usize = 0xa8; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD11: usize = 0xa8; + + pub(super) const SIZEOF_IF_DATA_FREE_BSD7: usize = 0x98; + pub(super) const SIZEOF_IF_DATA_FREE_BSD8: usize = 0x98; + pub(super) const SIZEOF_IF_DATA_FREE_BSD9: usize = 0x98; + pub(super) const SIZEOF_IF_DATA_FREE_BSD10: usize = 0x98; + pub(super) const SIZEOF_IF_DATA_FREE_BSD11: usize = 0x98; + + pub(super) const SIZEOF_IF_MSGHDRL_FREE_BSD10_EMU: usize = 0xb0; + pub(super) const SIZEOF_IFA_MSGHDR_FREE_BSD10_EMU: usize = 0x14; + pub(super) const SIZEOF_IFA_MSGHDRL_FREE_BSD10_EMU: usize = 0xb0; + pub(super) const SIZEOF_IFMA_MSGHDR_FREE_BSD10_EMU: usize = 0x10; + pub(super) const SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10_EMU: usize = 0x18; + + pub(super) const SIZEOF_RT_MSGHDR_FREE_BSD10_EMU: usize = 0x98; + pub(super) const SIZEOF_RT_METRICS_FREE_BSD10_EMU: usize = 0x70; + + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD7_EMU: usize = 0xa8; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD8_EMU: usize = 0xa8; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD9_EMU: usize = 0xa8; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD10_EMU: usize = 0xa8; + pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD11_EMU: usize = 0xa8; + + pub(super) const SIZEOF_IF_DATA_FREE_BSD7_EMU: usize = 0x98; + pub(super) const SIZEOF_IF_DATA_FREE_BSD8_EMU: usize = 0x98; + pub(super) const SIZEOF_IF_DATA_FREE_BSD9_EMU: usize = 0x98; + pub(super) const SIZEOF_IF_DATA_FREE_BSD10_EMU: usize = 0x98; + pub(super) const SIZEOF_IF_DATA_FREE_BSD11_EMU: usize = 0x98; + + pub(super) const SIZEOF_SOCKADDR_STORAGE: usize = 0x80; + pub(super) const SIZEOF_SOCKADDR_INET: usize = 0x10; + pub(super) const SIZEOF_SOCKADDR_INET6: usize = 0x1c; +} + +pub(super) fn probe_routing_stack() -> RoutingStack { + let rtm_version = RTM_VERSION; + + let rtm = WireFormat { + ext_off: SIZEOF_RT_MSGHDR_FREE_BSD10, + body_off: SIZEOF_RT_MSGHDR_FREE_BSD10, + typ: MessageType::Route, + }; + let ifm = WireFormat { + ext_off: SIZEOF_IF_MSGHDR_FREE_BSD11, + body_off: SIZEOF_IF_MSGHDR_FREE_BSD11, + typ: MessageType::Interface, + }; + let ifam = WireFormat { + ext_off: SIZEOF_IFA_MSGHDR_FREE_BSD10, + body_off: SIZEOF_IFA_MSGHDR_FREE_BSD10, + typ: MessageType::InterfaceAddr, + }; + let ifmam = WireFormat { + ext_off: SIZEOF_IFMA_MSGHDR_FREE_BSD10, + body_off: SIZEOF_IFMA_MSGHDR_FREE_BSD10, + typ: MessageType::InterfaceMulticastAddr, + }; + let ifannm = WireFormat { + ext_off: SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10, + body_off: SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10, + typ: MessageType::Interface, + }; + + let wire_formats = [ + (RTM_ADD, rtm), + (RTM_DELETE, rtm), + (RTM_CHANGE, rtm), + (RTM_GET, rtm), + (RTM_LOSING, rtm), + (RTM_REDIRECT, rtm), + (RTM_MISS, rtm), + (RTM_LOCK, rtm), + (RTM_RESOLVE, rtm), + (RTM_NEWADDR, ifam), + (RTM_DELADDR, ifam), + (RTM_IFINFO, ifm), + (RTM_NEWMADDR, ifmam), + (RTM_DELMADDR, ifmam), + (RTM_IFANNOUNCE, ifannm), + (RTM_IEEE80211, ifannm), + ] + .into_iter() + .collect(); + RoutingStack { + rtm_version, + wire_formats, + kernel_align: 4, + } +} diff --git a/iroh-net/src/net/interfaces/bsd/macos.rs b/iroh-net/src/net/interfaces/bsd/macos.rs new file mode 100644 index 0000000000..02d46c34ca --- /dev/null +++ b/iroh-net/src/net/interfaces/bsd/macos.rs @@ -0,0 +1,86 @@ +use super::{RoutingStack, WireFormat, MessageType}; + +// Hardcoded based on the generated values here: https://cs.opensource.google/go/x/net/+/master:route/zsys_darwin.go +const SIZEOF_IF_MSGHDR_DARWIN15: usize = 0x70; +const SIZEOF_IFA_MSGHDR_DARWIN15: usize = 0x14; +const SIZEOF_IFMA_MSGHDR_DARWIN15: usize = 0x10; +const SIZEOF_IF_MSGHDR2_DARWIN15: usize = 0xa0; +const SIZEOF_IFMA_MSGHDR2_DARWIN15: usize = 0x14; +const SIZEOF_IF_DATA_DARWIN15: usize = 0x60; +const SIZEOF_IF_DATA64_DARWIN15: usize = 0x80; + +const SIZEOF_RT_MSGHDR_DARWIN15: usize = 0x5c; +const SIZEOF_RT_MSGHDR2_DARWIN15: usize = 0x5c; +const SIZEOF_RT_METRICS_DARWIN15: usize = 0x38; + +const SIZEOF_SOCKADDR_STORAGE: usize = 0x80; +pub(super) const SIZEOF_SOCKADDR_INET: usize = 0x10; +pub(super) const SIZEOF_SOCKADDR_INET6: usize = 0x1c; + +pub(super) fn probe_routing_stack() -> RoutingStack { + let rtm_version = libc::RTM_VERSION; + + let rtm = WireFormat { + ext_off: 36, + body_off: SIZEOF_RT_MSGHDR_DARWIN15, + typ: MessageType::Route, + }; + let rtm2 = WireFormat { + ext_off: 36, + body_off: SIZEOF_RT_MSGHDR2_DARWIN15, + typ: MessageType::Route, + }; + let ifm = WireFormat { + ext_off: 16, + body_off: SIZEOF_IF_MSGHDR_DARWIN15, + typ: MessageType::Interface, + }; + let ifm2 = WireFormat { + ext_off: 32, + body_off: SIZEOF_IF_MSGHDR2_DARWIN15, + typ: MessageType::Interface, + }; + let ifam = WireFormat { + ext_off: SIZEOF_IFA_MSGHDR_DARWIN15, + body_off: SIZEOF_IFA_MSGHDR_DARWIN15, + typ: MessageType::InterfaceAddr, + }; + let ifmam = WireFormat { + ext_off: SIZEOF_IFMA_MSGHDR_DARWIN15, + body_off: SIZEOF_IFMA_MSGHDR_DARWIN15, + typ: MessageType::InterfaceMulticastAddr, + }; + let ifmam2 = WireFormat { + ext_off: SIZEOF_IFMA_MSGHDR2_DARWIN15, + body_off: SIZEOF_IFMA_MSGHDR2_DARWIN15, + typ: MessageType::InterfaceMulticastAddr, + }; + + let wire_formats = [ + (libc::RTM_ADD, rtm), + (libc::RTM_DELETE, rtm), + (libc::RTM_CHANGE, rtm), + (libc::RTM_GET, rtm), + (libc::RTM_LOSING, rtm), + (libc::RTM_REDIRECT, rtm), + (libc::RTM_MISS, rtm), + (libc::RTM_LOCK, rtm), + (libc::RTM_RESOLVE, rtm), + (libc::RTM_NEWADDR, ifam), + (libc::RTM_DELADDR, ifam), + (libc::RTM_IFINFO, ifm), + (libc::RTM_NEWMADDR, ifmam), + (libc::RTM_DELMADDR, ifmam), + (libc::RTM_IFINFO2, ifm2), + (libc::RTM_NEWMADDR2, ifmam2), + (libc::RTM_GET2, rtm2), + ] + .into_iter() + .collect(); + + RoutingStack { + rtm_version, + wire_formats, + kernel_align: 4, + } +} From fd697d9e99e689c70fc3cd508c759aa3a2a25015 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Tue, 21 May 2024 13:24:48 +0200 Subject: [PATCH 12/34] add netbsd, improve freebsd --- iroh-net/src/net/interfaces/bsd.rs | 5 + iroh-net/src/net/interfaces/bsd/freebsd.rs | 63 ++++++----- iroh-net/src/net/interfaces/bsd/netbsd.rs | 115 +++++++++++++++++++++ 3 files changed, 159 insertions(+), 24 deletions(-) create mode 100644 iroh-net/src/net/interfaces/bsd/netbsd.rs diff --git a/iroh-net/src/net/interfaces/bsd.rs b/iroh-net/src/net/interfaces/bsd.rs index cdd62db056..29bfb11df6 100644 --- a/iroh-net/src/net/interfaces/bsd.rs +++ b/iroh-net/src/net/interfaces/bsd.rs @@ -21,6 +21,10 @@ use super::DefaultRouteDetails; mod freebsd; #[cfg(target_os = "freebsd")] use self::freebsd::*; +#[cfg(target_os = "netbsd")] +mod netbsd; +#[cfg(target_os = "netbsd")] +use self::netbsd::*; #[cfg(any(target_os = "macos", target_os = "ios"))] mod macos; @@ -385,6 +389,7 @@ enum MessageType { Interface, InterfaceAddr, InterfaceMulticastAddr, + InterfaceAnnounce, } static ROUTING_STACK: Lazy = Lazy::new(probe_routing_stack); diff --git a/iroh-net/src/net/interfaces/bsd/freebsd.rs b/iroh-net/src/net/interfaces/bsd/freebsd.rs index d4705699fa..ec6352ce6e 100644 --- a/iroh-net/src/net/interfaces/bsd/freebsd.rs +++ b/iroh-net/src/net/interfaces/bsd/freebsd.rs @@ -260,33 +260,48 @@ mod arm64 { pub(super) const SIZEOF_SOCKADDR_INET6: usize = 0x1c; } +/// 386 emulation on amd64 +fn detect_compat_freebsd32() -> bool { + // TODO: implement detection when someone actually needs it + false +} + pub(super) fn probe_routing_stack() -> RoutingStack { let rtm_version = RTM_VERSION; - let rtm = WireFormat { - ext_off: SIZEOF_RT_MSGHDR_FREE_BSD10, - body_off: SIZEOF_RT_MSGHDR_FREE_BSD10, - typ: MessageType::Route, - }; - let ifm = WireFormat { - ext_off: SIZEOF_IF_MSGHDR_FREE_BSD11, - body_off: SIZEOF_IF_MSGHDR_FREE_BSD11, - typ: MessageType::Interface, - }; - let ifam = WireFormat { - ext_off: SIZEOF_IFA_MSGHDR_FREE_BSD10, - body_off: SIZEOF_IFA_MSGHDR_FREE_BSD10, - typ: MessageType::InterfaceAddr, - }; - let ifmam = WireFormat { - ext_off: SIZEOF_IFMA_MSGHDR_FREE_BSD10, - body_off: SIZEOF_IFMA_MSGHDR_FREE_BSD10, - typ: MessageType::InterfaceMulticastAddr, - }; - let ifannm = WireFormat { - ext_off: SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10, - body_off: SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10, - typ: MessageType::Interface, + // Currently only BSD11 support is implemented. + // At the time of this writing rust supports 10 and 11, if this is a problem + // please file an issue. + + let (rtm, ifm, ifam, ifmam, ifanm) = if detect_compat_freebsd32() { + unimplemented!() + } else { + let rtm = WireFormat { + ext_off: SIZEOF_RT_MSGHDR_FREE_BSD10 - SIZEOF_RT_METRICS_FREE_BSD10, + body_off: SIZEOF_RT_MSGHDR_FREE_BSD10, + typ: MessageType::Route, + }; + let ifm = WireFormat { + ext_off: 16, + body_off: SIZEOF_IF_MSGHDR_FREE_BSD11, + typ: MessageType::Interface, + }; + let ifam = WireFormat { + ext_off: SIZEOF_IFA_MSGHDR_FREE_BSD10, + body_off: SIZEOF_IFA_MSGHDR_FREE_BSD10, + typ: MessageType::InterfaceAddr, + }; + let ifmam = WireFormat { + ext_off: SIZEOF_IFMA_MSGHDR_FREE_BSD10, + body_off: SIZEOF_IFMA_MSGHDR_FREE_BSD10, + typ: MessageType::InterfaceMulticastAddr, + }; + let ifannm = WireFormat { + ext_off: SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10, + body_off: SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10, + typ: MessageType::InterfaceAnnounce, + }; + (rtm, ifm, ifam, ifmam, ifanm) }; let wire_formats = [ diff --git a/iroh-net/src/net/interfaces/bsd/netbsd.rs b/iroh-net/src/net/interfaces/bsd/netbsd.rs new file mode 100644 index 0000000000..c520564051 --- /dev/null +++ b/iroh-net/src/net/interfaces/bsd/netbsd.rs @@ -0,0 +1,115 @@ +use super::{MessageType, RoutingStack, WireFormat}; + +use libc::c_int; + +// Missing constants from libc. +// https://github.com/rust-lang/libc/issues/3711 + +const LOCAL_PEERCRED: c_int = 1; + +// net/route.h +const RTF_GATEWAY: c_int = 0x2; +const RTAX_DST: c_int = 0; +const RTAX_GATEWAY: c_int = 1; +const RTAX_NETMASK: c_int = 2; +const RTAX_IFP: c_int = 4; +const RTAX_BRD: c_int = 7; +const RTAX_MAX: c_int = 8; +const RTM_VERSION: c_int = 5; +const RTA_DST: c_int = 0x1; +const RTA_GATEWAY: c_int = 0x2; +const RTA_NETMASK: c_int = 0x4; +const RTA_GENMASK: c_int = 0x8; +const RTA_IFP: c_int = 0x10; +const RTA_IFA: c_int = 0x20; +const RTA_AUTHOR: c_int = 0x40; +const RTA_BRD: c_int = 0x80; + +// Message types +const RTM_ADD: c_int = 0x1; +const RTM_DELETE: c_int = 0x2; +const RTM_CHANGE: c_int = 0x3; +const RTM_GET: c_int = 0x4; +const RTM_LOSING: c_int = 0x5; +const RTM_REDIRECT: c_int = 0x6; +const RTM_MISS: c_int = 0x7; +const RTM_LOCK: c_int = 0x8; +const RTM_OLDADD: c_int = 0x9; +const RTM_OLDDEL: c_int = 0xa; +const RTM_RESOLVE: c_int = 0xb; +const RTM_NEWADDR: c_int = 0xc; +const RTM_DELADDR: c_int = 0xd; +const RTM_IFINFO: c_int = 0xe; +const RTM_NEWMADDR: c_int = 0xf; +const RTM_DELMADDR: c_int = 0x10; +const RTM_IFANNOUNCE: c_int = 0x11; +const RTM_IEEE80211: c_int = 0x12; + +const SHUT_RD: c_int = 0; +const SHUT_WR: c_int = 1; +const SHUT_RDWR: c_int = 2; + + +// Hardcoded based on the generated values here: https://cs.opensource.google/go/x/net/+/master:route/zsys_netbsd.go + +pub(super) const SIZEOF_IF_MSGHDR_NET_BSD7: usize = 0x98; +pub(super) const SIZEOF_IFA_MSGHDR_NET_BSD7: usize = 0x18; +pub(super) const SIZEOF_IF_ANNOUNCEMSGHDR_NET_BSD7: usize = 0x18; + +pub(super) const SIZEOF_RT_MSGHDR_NET_BSD7: usize = 0x78; +pub(super) const SIZEOF_RT_METRICS_NET_BSD7: usize = 0x50; + +pub(super) const SIZEOF_SOCKADDR_STORAGE: usize = 0x80; +pub(super) const SIZEOF_SOCKADDR_INET: usize = 0x10; +pub(super) const SIZEOF_SOCKADDR_INET6: usize = 0x1c; + + +pub(super) fn probe_routing_stack() -> RoutingStack { + let rtm_version = RTM_VERSION; + + let rtm = WireFormat { + ext_off: 40, + body_off: SIZEOF_RT_MSGHDR_NET_BSD7, + typ: MessageType::Route, + }; + let ifm = WireFormat { + ext_off: 16, + body_off: SIZEOF_IF_MSGHDR_NET_BSD7, + typ: MessageType::Interface, + }; + let ifam = WireFormat { + ext_off: SIZEOF_IFA_MSGHDR_NET_BSD7, + body_off: SIZEOF_IFA_MSGHDR_NET_BSD7, + typ: MessageType::InterfaceAddr, + }; + let ifannm = WireFormat { + ext_off: SIZEOF_IF_ANNOUNCEMSGHDR_NET_BSD7, + body_off: SIZEOF_IF_ANNOUNCEMSGHDR_NET_BSD7, + typ: MessageType::InterfaceAnnounce, + }; + + let wire_formats = [ + (RTM_ADD, rtm), + (RTM_DELETE, rtm), + (RTM_CHANGE, rtm), + (RTM_GET, rtm), + (RTM_LOSING, rtm), + (RTM_REDIRECT, rtm), + (RTM_MISS, rtm), + (RTM_LOCK, rtm), + (RTM_RESOLVE, rtm), + (RTM_NEWADDR, ifam), + (RTM_DELADDR, ifam), + (RTM_IFANNOUNCE, ifannm), + (RTM_IFINFO, ifm), + ] + .into_iter() + .collect(); + + // NetBSD 6 and above kernels require 64-bit aligned access to routing facilities. + RoutingStack { + rtm_version, + wire_formats, + kernel_align: 8, + } +} From 87199b497cc0ffb087ce0e7fb074990fc94e4e0d Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Tue, 21 May 2024 13:29:30 +0200 Subject: [PATCH 13/34] fixups --- iroh-net/src/net/interfaces/bsd.rs | 4 ++-- iroh-net/src/net/interfaces/bsd/freebsd.rs | 10 +++++----- iroh-net/src/net/netmon/bsd.rs | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/iroh-net/src/net/interfaces/bsd.rs b/iroh-net/src/net/interfaces/bsd.rs index 29bfb11df6..bc24919413 100644 --- a/iroh-net/src/net/interfaces/bsd.rs +++ b/iroh-net/src/net/interfaces/bsd.rs @@ -20,11 +20,11 @@ use super::DefaultRouteDetails; #[cfg(target_os = "freebsd")] mod freebsd; #[cfg(target_os = "freebsd")] -use self::freebsd::*; +pub use self::freebsd::*; #[cfg(target_os = "netbsd")] mod netbsd; #[cfg(target_os = "netbsd")] -use self::netbsd::*; +pub use self::netbsd::*; #[cfg(any(target_os = "macos", target_os = "ios"))] mod macos; diff --git a/iroh-net/src/net/interfaces/bsd/freebsd.rs b/iroh-net/src/net/interfaces/bsd/freebsd.rs index ec6352ce6e..299eefe36f 100644 --- a/iroh-net/src/net/interfaces/bsd/freebsd.rs +++ b/iroh-net/src/net/interfaces/bsd/freebsd.rs @@ -9,10 +9,10 @@ const LOCAL_PEERCRED: c_int = 1; // net/route.h const RTF_GATEWAY: c_int = 0x2; -const RTAX_DST: c_int = 0; +pub const RTAX_DST: c_int = 0; const RTAX_GATEWAY: c_int = 1; const RTAX_NETMASK: c_int = 2; -const RTAX_IFP: c_int = 4; +pub const RTAX_IFP: c_int = 4; const RTAX_BRD: c_int = 7; const RTAX_MAX: c_int = 8; const RTM_VERSION: c_int = 5; @@ -296,7 +296,7 @@ pub(super) fn probe_routing_stack() -> RoutingStack { body_off: SIZEOF_IFMA_MSGHDR_FREE_BSD10, typ: MessageType::InterfaceMulticastAddr, }; - let ifannm = WireFormat { + let ifanm = WireFormat { ext_off: SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10, body_off: SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10, typ: MessageType::InterfaceAnnounce, @@ -319,8 +319,8 @@ pub(super) fn probe_routing_stack() -> RoutingStack { (RTM_IFINFO, ifm), (RTM_NEWMADDR, ifmam), (RTM_DELMADDR, ifmam), - (RTM_IFANNOUNCE, ifannm), - (RTM_IEEE80211, ifannm), + (RTM_IFANNOUNCE, ifanm), + (RTM_IEEE80211, ifanm), ] .into_iter() .collect(); diff --git a/iroh-net/src/net/netmon/bsd.rs b/iroh-net/src/net/netmon/bsd.rs index 92028629f1..0956f5337f 100644 --- a/iroh-net/src/net/netmon/bsd.rs +++ b/iroh-net/src/net/netmon/bsd.rs @@ -3,7 +3,7 @@ use tokio::{io::AsyncReadExt, task::JoinHandle}; use tracing::{trace, warn}; #[cfg(any(target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))] -use crate::net::interfaces::bsd::bsd_libc::{RTAX_DST, RTAX_IFP}; +use crate::net::interfaces::bsd::{RTAX_DST, RTAX_IFP}; #[cfg(any(target_os = "macos", target_os = "ios"))] use libc::{RTAX_DST, RTAX_IFP}; From 3b182543275f403b43c5c476a7519b43c202d44a Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Tue, 21 May 2024 13:31:14 +0200 Subject: [PATCH 14/34] exports --- iroh-net/src/net/interfaces/bsd.rs | 4 +- iroh-net/src/net/interfaces/bsd/freebsd.rs | 82 +++++++++++----------- 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/iroh-net/src/net/interfaces/bsd.rs b/iroh-net/src/net/interfaces/bsd.rs index bc24919413..60354cb67f 100644 --- a/iroh-net/src/net/interfaces/bsd.rs +++ b/iroh-net/src/net/interfaces/bsd.rs @@ -20,11 +20,11 @@ use super::DefaultRouteDetails; #[cfg(target_os = "freebsd")] mod freebsd; #[cfg(target_os = "freebsd")] -pub use self::freebsd::*; +pub(crate) use self::freebsd::*; #[cfg(target_os = "netbsd")] mod netbsd; #[cfg(target_os = "netbsd")] -pub use self::netbsd::*; +pub(crate) use self::netbsd::*; #[cfg(any(target_os = "macos", target_os = "ios"))] mod macos; diff --git a/iroh-net/src/net/interfaces/bsd/freebsd.rs b/iroh-net/src/net/interfaces/bsd/freebsd.rs index 299eefe36f..0c9f5885e8 100644 --- a/iroh-net/src/net/interfaces/bsd/freebsd.rs +++ b/iroh-net/src/net/interfaces/bsd/freebsd.rs @@ -5,53 +5,53 @@ use libc::c_int; // Missing constants from libc. // https://github.com/rust-lang/libc/issues/3711 -const LOCAL_PEERCRED: c_int = 1; +pub const LOCAL_PEERCRED: c_int = 1; // net/route.h -const RTF_GATEWAY: c_int = 0x2; +pub const RTF_GATEWAY: c_int = 0x2; pub const RTAX_DST: c_int = 0; -const RTAX_GATEWAY: c_int = 1; -const RTAX_NETMASK: c_int = 2; +pub const RTAX_GATEWAY: c_int = 1; +pub const RTAX_NETMASK: c_int = 2; pub const RTAX_IFP: c_int = 4; -const RTAX_BRD: c_int = 7; -const RTAX_MAX: c_int = 8; -const RTM_VERSION: c_int = 5; -const RTA_DST: c_int = 0x1; -const RTA_GATEWAY: c_int = 0x2; -const RTA_NETMASK: c_int = 0x4; -const RTA_GENMASK: c_int = 0x8; -const RTA_IFP: c_int = 0x10; -const RTA_IFA: c_int = 0x20; -const RTA_AUTHOR: c_int = 0x40; -const RTA_BRD: c_int = 0x80; +pub const RTAX_BRD: c_int = 7; +pub const RTAX_MAX: c_int = 8; +pub const RTM_VERSION: c_int = 5; +pub const RTA_DST: c_int = 0x1; +pub const RTA_GATEWAY: c_int = 0x2; +pub const RTA_NETMASK: c_int = 0x4; +pub const RTA_GENMASK: c_int = 0x8; +pub const RTA_IFP: c_int = 0x10; +pub const RTA_IFA: c_int = 0x20; +pub const RTA_AUTHOR: c_int = 0x40; +pub const RTA_BRD: c_int = 0x80; // Message types -const RTM_ADD: c_int = 0x1; -const RTM_DELETE: c_int = 0x2; -const RTM_CHANGE: c_int = 0x3; -const RTM_GET: c_int = 0x4; -const RTM_LOSING: c_int = 0x5; -const RTM_REDIRECT: c_int = 0x6; -const RTM_MISS: c_int = 0x7; -const RTM_LOCK: c_int = 0x8; -const RTM_OLDADD: c_int = 0x9; -const RTM_OLDDEL: c_int = 0xa; -const RTM_RESOLVE: c_int = 0xb; -const RTM_NEWADDR: c_int = 0xc; -const RTM_DELADDR: c_int = 0xd; -const RTM_IFINFO: c_int = 0xe; -const RTM_NEWMADDR: c_int = 0xf; -const RTM_DELMADDR: c_int = 0x10; -const RTM_IFANNOUNCE: c_int = 0x11; -const RTM_IEEE80211: c_int = 0x12; - -const SHUT_RD: c_int = 0; -const SHUT_WR: c_int = 1; -const SHUT_RDWR: c_int = 2; +pub const RTM_ADD: c_int = 0x1; +pub const RTM_DELETE: c_int = 0x2; +pub const RTM_CHANGE: c_int = 0x3; +pub const RTM_GET: c_int = 0x4; +pub const RTM_LOSING: c_int = 0x5; +pub const RTM_REDIRECT: c_int = 0x6; +pub const RTM_MISS: c_int = 0x7; +pub const RTM_LOCK: c_int = 0x8; +pub const RTM_OLDADD: c_int = 0x9; +pub const RTM_OLDDEL: c_int = 0xa; +pub const RTM_RESOLVE: c_int = 0xb; +pub const RTM_NEWADDR: c_int = 0xc; +pub const RTM_DELADDR: c_int = 0xd; +pub const RTM_IFINFO: c_int = 0xe; +pub const RTM_NEWMADDR: c_int = 0xf; +pub const RTM_DELMADDR: c_int = 0x10; +pub const RTM_IFANNOUNCE: c_int = 0x11; +pub const RTM_IEEE80211: c_int = 0x12; + +pub const SHUT_RD: c_int = 0; +pub const SHUT_WR: c_int = 1; +pub const SHUT_RDWR: c_int = 2; // Hardcoded based on the generated values here: https://cs.opensource.google/go/x/net/+/master:route/zsys_freebsd_amd64.go #[cfg(target_arch = "x86_64")] -use self::amd64::*; +pub use self::amd64::*; #[cfg(target_arch = "x86_64")] mod amd64 { pub(super) const SIZEOF_IF_MSGHDRL_FREE_BSD10: usize = 0xb0; @@ -103,7 +103,7 @@ mod amd64 { // Hardcoded based on the generated values here: https://cs.opensource.google/go/x/net/+/master:route/zsys_freebsd_386.go #[cfg(target_arch = "x86")] -use self::i686::*; +pub use self::i686::*; #[cfg(target_arch = "x86")] mod i686 { pub(super) const SIZEOF_IF_MSGHDRL_FREE_BSD10: usize = 0x68; @@ -158,7 +158,7 @@ mod i686 { // Hardcoded based on the generated values here: https://cs.opensource.google/go/x/net/+/master:route/zsys_freebsd_arm.go #[cfg(target_arch = "arm")] -use self::arm::*; +pub use self::arm::*; #[cfg(target_arch = "arm")] mod arm { pub(super) const SIZEOF_IF_MSGHDRL_FREE_BSD10: usize = 0x68; @@ -210,7 +210,7 @@ mod arm { // Hardcoded based on the generated values here: https://cs.opensource.google/go/x/net/+/master:route/zsys_freebsd_arm.go #[cfg(target_arch = "aarch64")] -use self::arm64::*; +pub use self::arm64::*; #[cfg(target_arch = "aarch64")] mod arm64 { pub(super) const SIZEOF_IF_MSGHDRL_FREE_BSD10: usize = 0xb0; From 59b80a6ebd3c257fcb8305898cd10135c699a7a6 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Tue, 21 May 2024 13:32:45 +0200 Subject: [PATCH 15/34] exports --- iroh-net/src/net/interfaces/bsd/freebsd.rs | 360 ++++++++++----------- iroh-net/src/net/interfaces/bsd/macos.rs | 2 +- iroh-net/src/net/interfaces/bsd/netbsd.rs | 12 +- 3 files changed, 186 insertions(+), 188 deletions(-) diff --git a/iroh-net/src/net/interfaces/bsd/freebsd.rs b/iroh-net/src/net/interfaces/bsd/freebsd.rs index 0c9f5885e8..6f3c4c1851 100644 --- a/iroh-net/src/net/interfaces/bsd/freebsd.rs +++ b/iroh-net/src/net/interfaces/bsd/freebsd.rs @@ -54,51 +54,51 @@ pub const SHUT_RDWR: c_int = 2; pub use self::amd64::*; #[cfg(target_arch = "x86_64")] mod amd64 { - pub(super) const SIZEOF_IF_MSGHDRL_FREE_BSD10: usize = 0xb0; - pub(super) const SIZEOF_IFA_MSGHDR_FREE_BSD10: usize = 0x14; - pub(super) const SIZEOF_IFA_MSGHDRL_FREE_BSD10: usize = 0xb0; - pub(super) const SIZEOF_IFMA_MSGHDR_FREE_BSD10: usize = 0x10; - pub(super) const SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10: usize = 0x18; - - pub(super) const SIZEOF_RT_MSGHDR_FREE_BSD10: usize = 0x98; - pub(super) const SIZEOF_RT_METRICS_FREE_BSD10: usize = 0x70; - - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD7: usize = 0xa8; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD8: usize = 0xa8; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD9: usize = 0xa8; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD10: usize = 0xa8; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD11: usize = 0xa8; - - pub(super) const SIZEOF_IF_DATA_FREE_BSD7: usize = 0x98; - pub(super) const SIZEOF_IF_DATA_FREE_BSD8: usize = 0x98; - pub(super) const SIZEOF_IF_DATA_FREE_BSD9: usize = 0x98; - pub(super) const SIZEOF_IF_DATA_FREE_BSD10: usize = 0x98; - pub(super) const SIZEOF_IF_DATA_FREE_BSD11: usize = 0x98; - - pub(super) const SIZEOF_IF_MSGHDRL_FREE_BSD10_EMU: usize = 0xb0; - pub(super) const SIZEOF_IFA_MSGHDR_FREE_BSD10_EMU: usize = 0x14; - pub(super) const SIZEOF_IFA_MSGHDRL_FREE_BSD10_EMU: usize = 0xb0; - pub(super) const SIZEOF_IFMA_MSGHDR_FREE_BSD10_EMU: usize = 0x10; - pub(super) const SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10_EMU: usize = 0x18; - - pub(super) const SIZEOF_RT_MSGHDR_FREE_BSD10_EMU: usize = 0x98; - pub(super) const SIZEOF_RT_METRICS_FREE_BSD10_EMU: usize = 0x70; - - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD7_EMU: usize = 0xa8; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD8_EMU: usize = 0xa8; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD9_EMU: usize = 0xa8; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD10_EMU: usize = 0xa8; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD11_EMU: usize = 0xa8; - - pub(super) const SIZEOF_IF_DATA_FREE_BSD7_EMU: usize = 0x98; - pub(super) const SIZEOF_IF_DATA_FREE_BSD8_EMU: usize = 0x98; - pub(super) const SIZEOF_IF_DATA_FREE_BSD9_EMU: usize = 0x98; - pub(super) const SIZEOF_IF_DATA_FREE_BSD10_EMU: usize = 0x98; - pub(super) const SIZEOF_IF_DATA_FREE_BSD11_EMU: usize = 0x98; - - pub(super) const SIZEOF_SOCKADDR_STORAGE: usize = 0x80; - pub(super) const SIZEOF_SOCKADDR_INET: usize = 0x10; - pub(super) const SIZEOF_SOCKADDR_INET6: usize = 0x1c; + pub const SIZEOF_IF_MSGHDRL_FREE_BSD10: usize = 0xb0; + pub const SIZEOF_IFA_MSGHDR_FREE_BSD10: usize = 0x14; + pub const SIZEOF_IFA_MSGHDRL_FREE_BSD10: usize = 0xb0; + pub const SIZEOF_IFMA_MSGHDR_FREE_BSD10: usize = 0x10; + pub const SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10: usize = 0x18; + + pub const SIZEOF_RT_MSGHDR_FREE_BSD10: usize = 0x98; + pub const SIZEOF_RT_METRICS_FREE_BSD10: usize = 0x70; + + pub const SIZEOF_IF_MSGHDR_FREE_BSD7: usize = 0xa8; + pub const SIZEOF_IF_MSGHDR_FREE_BSD8: usize = 0xa8; + pub const SIZEOF_IF_MSGHDR_FREE_BSD9: usize = 0xa8; + pub const SIZEOF_IF_MSGHDR_FREE_BSD10: usize = 0xa8; + pub const SIZEOF_IF_MSGHDR_FREE_BSD11: usize = 0xa8; + + pub const SIZEOF_IF_DATA_FREE_BSD7: usize = 0x98; + pub const SIZEOF_IF_DATA_FREE_BSD8: usize = 0x98; + pub const SIZEOF_IF_DATA_FREE_BSD9: usize = 0x98; + pub const SIZEOF_IF_DATA_FREE_BSD10: usize = 0x98; + pub const SIZEOF_IF_DATA_FREE_BSD11: usize = 0x98; + + pub const SIZEOF_IF_MSGHDRL_FREE_BSD10_EMU: usize = 0xb0; + pub const SIZEOF_IFA_MSGHDR_FREE_BSD10_EMU: usize = 0x14; + pub const SIZEOF_IFA_MSGHDRL_FREE_BSD10_EMU: usize = 0xb0; + pub const SIZEOF_IFMA_MSGHDR_FREE_BSD10_EMU: usize = 0x10; + pub const SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10_EMU: usize = 0x18; + + pub const SIZEOF_RT_MSGHDR_FREE_BSD10_EMU: usize = 0x98; + pub const SIZEOF_RT_METRICS_FREE_BSD10_EMU: usize = 0x70; + + pub const SIZEOF_IF_MSGHDR_FREE_BSD7_EMU: usize = 0xa8; + pub const SIZEOF_IF_MSGHDR_FREE_BSD8_EMU: usize = 0xa8; + pub const SIZEOF_IF_MSGHDR_FREE_BSD9_EMU: usize = 0xa8; + pub const SIZEOF_IF_MSGHDR_FREE_BSD10_EMU: usize = 0xa8; + pub const SIZEOF_IF_MSGHDR_FREE_BSD11_EMU: usize = 0xa8; + + pub const SIZEOF_IF_DATA_FREE_BSD7_EMU: usize = 0x98; + pub const SIZEOF_IF_DATA_FREE_BSD8_EMU: usize = 0x98; + pub const SIZEOF_IF_DATA_FREE_BSD9_EMU: usize = 0x98; + pub const SIZEOF_IF_DATA_FREE_BSD10_EMU: usize = 0x98; + pub const SIZEOF_IF_DATA_FREE_BSD11_EMU: usize = 0x98; + + pub const SIZEOF_SOCKADDR_STORAGE: usize = 0x80; + pub const SIZEOF_SOCKADDR_INET: usize = 0x10; + pub const SIZEOF_SOCKADDR_INET6: usize = 0x1c; } // Hardcoded based on the generated values here: https://cs.opensource.google/go/x/net/+/master:route/zsys_freebsd_386.go @@ -106,54 +106,54 @@ mod amd64 { pub use self::i686::*; #[cfg(target_arch = "x86")] mod i686 { - pub(super) const SIZEOF_IF_MSGHDRL_FREE_BSD10: usize = 0x68; - pub(super) const SIZEOF_IFA_MSGHDR_FREE_BSD10: usize = 0x14; - pub(super) const SIZEOF_IFA_MSGHDRL_FREE_BSD10: usize = 0x6c; - pub(super) const SIZEOF_IFMA_MSGHDR_FREE_BSD10: usize = 0x10; - pub(super) const SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10: usize = 0x18; - - pub(super) const SIZEOF_RT_MSGHDR_FREE_BSD10: usize = 0x5c; - pub(super) const SIZEOF_RT_METRICS_FREE_BSD10: usize = 0x38; - - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD7: usize = 0x60; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD8: usize = 0x60; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD9: usize = 0x60; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD10: usize = 0x64; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD11: usize = 0xa8; - - pub(super) const SIZEOF_IF_DATA_FREE_BSD7: usize = 0x50; - pub(super) const SIZEOF_IF_DATA_FREE_BSD8: usize = 0x50; - pub(super) const SIZEOF_IF_DATA_FREE_BSD9: usize = 0x50; - pub(super) const SIZEOF_IF_DATA_FREE_BSD10: usize = 0x54; - pub(super) const SIZEOF_IF_DATA_FREE_BSD11: usize = 0x98; + pub const SIZEOF_IF_MSGHDRL_FREE_BSD10: usize = 0x68; + pub const SIZEOF_IFA_MSGHDR_FREE_BSD10: usize = 0x14; + pub const SIZEOF_IFA_MSGHDRL_FREE_BSD10: usize = 0x6c; + pub const SIZEOF_IFMA_MSGHDR_FREE_BSD10: usize = 0x10; + pub const SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10: usize = 0x18; + + pub const SIZEOF_RT_MSGHDR_FREE_BSD10: usize = 0x5c; + pub const SIZEOF_RT_METRICS_FREE_BSD10: usize = 0x38; + + pub const SIZEOF_IF_MSGHDR_FREE_BSD7: usize = 0x60; + pub const SIZEOF_IF_MSGHDR_FREE_BSD8: usize = 0x60; + pub const SIZEOF_IF_MSGHDR_FREE_BSD9: usize = 0x60; + pub const SIZEOF_IF_MSGHDR_FREE_BSD10: usize = 0x64; + pub const SIZEOF_IF_MSGHDR_FREE_BSD11: usize = 0xa8; + + pub const SIZEOF_IF_DATA_FREE_BSD7: usize = 0x50; + pub const SIZEOF_IF_DATA_FREE_BSD8: usize = 0x50; + pub const SIZEOF_IF_DATA_FREE_BSD9: usize = 0x50; + pub const SIZEOF_IF_DATA_FREE_BSD10: usize = 0x54; + pub const SIZEOF_IF_DATA_FREE_BSD11: usize = 0x98; // MODIFIED BY HAND FOR 386 EMULATION ON AMD64 // 386 EMULATION USES THE UNDERLYING RAW DATA LAYOUT - pub(super) const SIZEOF_IF_MSGHDRL_FREE_BSD10_EMU: usize = 0xb0; - pub(super) const SIZEOF_IFA_MSGHDR_FREE_BSD10_EMU: usize = 0x14; - pub(super) const SIZEOF_IFA_MSGHDRL_FREE_BSD10_EMU: usize = 0xb0; - pub(super) const SIZEOF_IFMA_MSGHDR_FREE_BSD10_EMU: usize = 0x10; - pub(super) const SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10_EMU: usize = 0x18; - - pub(super) const SIZEOF_RT_MSGHDR_FREE_BSD10_EMU: usize = 0x98; - pub(super) const SIZEOF_RT_METRICS_FREE_BSD10_EMU: usize = 0x70; - - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD7_EMU: usize = 0xa8; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD8_EMU: usize = 0xa8; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD9_EMU: usize = 0xa8; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD10_EMU: usize = 0xa8; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD11_EMU: usize = 0xa8; - - pub(super) const SIZEOF_IF_DATA_FREE_BSD7_EMU: usize = 0x98; - pub(super) const SIZEOF_IF_DATA_FREE_BSD8_EMU: usize = 0x98; - pub(super) const SIZEOF_IF_DATA_FREE_BSD9_EMU: usize = 0x98; - pub(super) const SIZEOF_IF_DATA_FREE_BSD10_EMU: usize = 0x98; - pub(super) const SIZEOF_IF_DATA_FREE_BSD11_EMU: usize = 0x98; - - pub(super) const SIZEOF_SOCKADDR_STORAGE: usize = 0x80; - pub(super) const SIZEOF_SOCKADDR_INET: usize = 0x10; - pub(super) const SIZEOF_SOCKADDR_INET6: usize = 0x1c; + pub const SIZEOF_IF_MSGHDRL_FREE_BSD10_EMU: usize = 0xb0; + pub const SIZEOF_IFA_MSGHDR_FREE_BSD10_EMU: usize = 0x14; + pub const SIZEOF_IFA_MSGHDRL_FREE_BSD10_EMU: usize = 0xb0; + pub const SIZEOF_IFMA_MSGHDR_FREE_BSD10_EMU: usize = 0x10; + pub const SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10_EMU: usize = 0x18; + + pub const SIZEOF_RT_MSGHDR_FREE_BSD10_EMU: usize = 0x98; + pub const SIZEOF_RT_METRICS_FREE_BSD10_EMU: usize = 0x70; + + pub const SIZEOF_IF_MSGHDR_FREE_BSD7_EMU: usize = 0xa8; + pub const SIZEOF_IF_MSGHDR_FREE_BSD8_EMU: usize = 0xa8; + pub const SIZEOF_IF_MSGHDR_FREE_BSD9_EMU: usize = 0xa8; + pub const SIZEOF_IF_MSGHDR_FREE_BSD10_EMU: usize = 0xa8; + pub const SIZEOF_IF_MSGHDR_FREE_BSD11_EMU: usize = 0xa8; + + pub const SIZEOF_IF_DATA_FREE_BSD7_EMU: usize = 0x98; + pub const SIZEOF_IF_DATA_FREE_BSD8_EMU: usize = 0x98; + pub const SIZEOF_IF_DATA_FREE_BSD9_EMU: usize = 0x98; + pub const SIZEOF_IF_DATA_FREE_BSD10_EMU: usize = 0x98; + pub const SIZEOF_IF_DATA_FREE_BSD11_EMU: usize = 0x98; + + pub const SIZEOF_SOCKADDR_STORAGE: usize = 0x80; + pub const SIZEOF_SOCKADDR_INET: usize = 0x10; + pub const SIZEOF_SOCKADDR_INET6: usize = 0x1c; } // Hardcoded based on the generated values here: https://cs.opensource.google/go/x/net/+/master:route/zsys_freebsd_arm.go @@ -161,51 +161,51 @@ mod i686 { pub use self::arm::*; #[cfg(target_arch = "arm")] mod arm { - pub(super) const SIZEOF_IF_MSGHDRL_FREE_BSD10: usize = 0x68; - pub(super) const SIZEOF_IFA_MSGHDR_FREE_BSD10: usize = 0x14; - pub(super) const SIZEOF_IFA_MSGHDRL_FREE_BSD10: usize = 0x6c; - pub(super) const SIZEOF_IFMA_MSGHDR_FREE_BSD10: usize = 0x10; - pub(super) const SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10: usize = 0x18; - - pub(super) const SIZEOF_RT_MSGHDR_FREE_BSD10: usize = 0x5c; - pub(super) const SIZEOF_RT_METRICS_FREE_BSD10: usize = 0x38; - - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD7: usize = 0x70; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD8: usize = 0x70; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD9: usize = 0x70; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD10: usize = 0x70; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD11: usize = 0xa8; - - pub(super) const SIZEOF_IF_DATA_FREE_BSD7: usize = 0x60; - pub(super) const SIZEOF_IF_DATA_FREE_BSD8: usize = 0x60; - pub(super) const SIZEOF_IF_DATA_FREE_BSD9: usize = 0x60; - pub(super) const SIZEOF_IF_DATA_FREE_BSD10: usize = 0x60; - pub(super) const SIZEOF_IF_DATA_FREE_BSD11: usize = 0x98; - - pub(super) const SIZEOF_IF_MSGHDRL_FREE_BSD10_EMU: usize = 0x68; - pub(super) const SIZEOF_IFA_MSGHDR_FREE_BSD10_EMU: usize = 0x14; - pub(super) const SIZEOF_IFA_MSGHDRL_FREE_BSD10_EMU: usize = 0x6c; - pub(super) const SIZEOF_IFMA_MSGHDR_FREE_BSD10_EMU: usize = 0x10; - pub(super) const SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10_EMU: usize = 0x18; - - pub(super) const SIZEOF_RT_MSGHDR_FREE_BSD10_EMU: usize = 0x5c; - pub(super) const SIZEOF_RT_METRICS_FREE_BSD10_EMU: usize = 0x38; - - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD7_EMU: usize = 0x70; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD8_EMU: usize = 0x70; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD9_EMU: usize = 0x70; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD10_EMU: usize = 0x70; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD11_EMU: usize = 0xa8; - - pub(super) const SIZEOF_IF_DATA_FREE_BSD7_EMU: usize = 0x60; - pub(super) const SIZEOF_IF_DATA_FREE_BSD8_EMU: usize = 0x60; - pub(super) const SIZEOF_IF_DATA_FREE_BSD9_EMU: usize = 0x60; - pub(super) const SIZEOF_IF_DATA_FREE_BSD10_EMU: usize = 0x60; - pub(super) const SIZEOF_IF_DATA_FREE_BSD11_EMU: usize = 0x98; - - pub(super) const SIZEOF_SOCKADDR_STORAGE: usize = 0x80; - pub(super) const SIZEOF_SOCKADDR_INET: usize = 0x10; - pub(super) const SIZEOF_SOCKADDR_INET6: usize = 0x1c; + pub const SIZEOF_IF_MSGHDRL_FREE_BSD10: usize = 0x68; + pub const SIZEOF_IFA_MSGHDR_FREE_BSD10: usize = 0x14; + pub const SIZEOF_IFA_MSGHDRL_FREE_BSD10: usize = 0x6c; + pub const SIZEOF_IFMA_MSGHDR_FREE_BSD10: usize = 0x10; + pub const SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10: usize = 0x18; + + pub const SIZEOF_RT_MSGHDR_FREE_BSD10: usize = 0x5c; + pub const SIZEOF_RT_METRICS_FREE_BSD10: usize = 0x38; + + pub const SIZEOF_IF_MSGHDR_FREE_BSD7: usize = 0x70; + pub const SIZEOF_IF_MSGHDR_FREE_BSD8: usize = 0x70; + pub const SIZEOF_IF_MSGHDR_FREE_BSD9: usize = 0x70; + pub const SIZEOF_IF_MSGHDR_FREE_BSD10: usize = 0x70; + pub const SIZEOF_IF_MSGHDR_FREE_BSD11: usize = 0xa8; + + pub const SIZEOF_IF_DATA_FREE_BSD7: usize = 0x60; + pub const SIZEOF_IF_DATA_FREE_BSD8: usize = 0x60; + pub const SIZEOF_IF_DATA_FREE_BSD9: usize = 0x60; + pub const SIZEOF_IF_DATA_FREE_BSD10: usize = 0x60; + pub const SIZEOF_IF_DATA_FREE_BSD11: usize = 0x98; + + pub const SIZEOF_IF_MSGHDRL_FREE_BSD10_EMU: usize = 0x68; + pub const SIZEOF_IFA_MSGHDR_FREE_BSD10_EMU: usize = 0x14; + pub const SIZEOF_IFA_MSGHDRL_FREE_BSD10_EMU: usize = 0x6c; + pub const SIZEOF_IFMA_MSGHDR_FREE_BSD10_EMU: usize = 0x10; + pub const SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10_EMU: usize = 0x18; + + pub const SIZEOF_RT_MSGHDR_FREE_BSD10_EMU: usize = 0x5c; + pub const SIZEOF_RT_METRICS_FREE_BSD10_EMU: usize = 0x38; + + pub const SIZEOF_IF_MSGHDR_FREE_BSD7_EMU: usize = 0x70; + pub const SIZEOF_IF_MSGHDR_FREE_BSD8_EMU: usize = 0x70; + pub const SIZEOF_IF_MSGHDR_FREE_BSD9_EMU: usize = 0x70; + pub const SIZEOF_IF_MSGHDR_FREE_BSD10_EMU: usize = 0x70; + pub const SIZEOF_IF_MSGHDR_FREE_BSD11_EMU: usize = 0xa8; + + pub const SIZEOF_IF_DATA_FREE_BSD7_EMU: usize = 0x60; + pub const SIZEOF_IF_DATA_FREE_BSD8_EMU: usize = 0x60; + pub const SIZEOF_IF_DATA_FREE_BSD9_EMU: usize = 0x60; + pub const SIZEOF_IF_DATA_FREE_BSD10_EMU: usize = 0x60; + pub const SIZEOF_IF_DATA_FREE_BSD11_EMU: usize = 0x98; + + pub const SIZEOF_SOCKADDR_STORAGE: usize = 0x80; + pub const SIZEOF_SOCKADDR_INET: usize = 0x10; + pub const SIZEOF_SOCKADDR_INET6: usize = 0x1c; } // Hardcoded based on the generated values here: https://cs.opensource.google/go/x/net/+/master:route/zsys_freebsd_arm.go @@ -213,51 +213,51 @@ mod arm { pub use self::arm64::*; #[cfg(target_arch = "aarch64")] mod arm64 { - pub(super) const SIZEOF_IF_MSGHDRL_FREE_BSD10: usize = 0xb0; - pub(super) const SIZEOF_IFA_MSGHDR_FREE_BSD10: usize = 0x14; - pub(super) const SIZEOF_IFA_MSGHDRL_FREE_BSD10: usize = 0xb0; - pub(super) const SIZEOF_IFMA_MSGHDR_FREE_BSD10: usize = 0x10; - pub(super) const SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10: usize = 0x18; - - pub(super) const SIZEOF_RT_MSGHDR_FREE_BSD10: usize = 0x98; - pub(super) const SIZEOF_RT_METRICS_FREE_BSD10: usize = 0x70; - - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD7: usize = 0xa8; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD8: usize = 0xa8; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD9: usize = 0xa8; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD10: usize = 0xa8; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD11: usize = 0xa8; - - pub(super) const SIZEOF_IF_DATA_FREE_BSD7: usize = 0x98; - pub(super) const SIZEOF_IF_DATA_FREE_BSD8: usize = 0x98; - pub(super) const SIZEOF_IF_DATA_FREE_BSD9: usize = 0x98; - pub(super) const SIZEOF_IF_DATA_FREE_BSD10: usize = 0x98; - pub(super) const SIZEOF_IF_DATA_FREE_BSD11: usize = 0x98; - - pub(super) const SIZEOF_IF_MSGHDRL_FREE_BSD10_EMU: usize = 0xb0; - pub(super) const SIZEOF_IFA_MSGHDR_FREE_BSD10_EMU: usize = 0x14; - pub(super) const SIZEOF_IFA_MSGHDRL_FREE_BSD10_EMU: usize = 0xb0; - pub(super) const SIZEOF_IFMA_MSGHDR_FREE_BSD10_EMU: usize = 0x10; - pub(super) const SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10_EMU: usize = 0x18; - - pub(super) const SIZEOF_RT_MSGHDR_FREE_BSD10_EMU: usize = 0x98; - pub(super) const SIZEOF_RT_METRICS_FREE_BSD10_EMU: usize = 0x70; - - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD7_EMU: usize = 0xa8; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD8_EMU: usize = 0xa8; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD9_EMU: usize = 0xa8; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD10_EMU: usize = 0xa8; - pub(super) const SIZEOF_IF_MSGHDR_FREE_BSD11_EMU: usize = 0xa8; - - pub(super) const SIZEOF_IF_DATA_FREE_BSD7_EMU: usize = 0x98; - pub(super) const SIZEOF_IF_DATA_FREE_BSD8_EMU: usize = 0x98; - pub(super) const SIZEOF_IF_DATA_FREE_BSD9_EMU: usize = 0x98; - pub(super) const SIZEOF_IF_DATA_FREE_BSD10_EMU: usize = 0x98; - pub(super) const SIZEOF_IF_DATA_FREE_BSD11_EMU: usize = 0x98; - - pub(super) const SIZEOF_SOCKADDR_STORAGE: usize = 0x80; - pub(super) const SIZEOF_SOCKADDR_INET: usize = 0x10; - pub(super) const SIZEOF_SOCKADDR_INET6: usize = 0x1c; + pub const SIZEOF_IF_MSGHDRL_FREE_BSD10: usize = 0xb0; + pub const SIZEOF_IFA_MSGHDR_FREE_BSD10: usize = 0x14; + pub const SIZEOF_IFA_MSGHDRL_FREE_BSD10: usize = 0xb0; + pub const SIZEOF_IFMA_MSGHDR_FREE_BSD10: usize = 0x10; + pub const SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10: usize = 0x18; + + pub const SIZEOF_RT_MSGHDR_FREE_BSD10: usize = 0x98; + pub const SIZEOF_RT_METRICS_FREE_BSD10: usize = 0x70; + + pub const SIZEOF_IF_MSGHDR_FREE_BSD7: usize = 0xa8; + pub const SIZEOF_IF_MSGHDR_FREE_BSD8: usize = 0xa8; + pub const SIZEOF_IF_MSGHDR_FREE_BSD9: usize = 0xa8; + pub const SIZEOF_IF_MSGHDR_FREE_BSD10: usize = 0xa8; + pub const SIZEOF_IF_MSGHDR_FREE_BSD11: usize = 0xa8; + + pub const SIZEOF_IF_DATA_FREE_BSD7: usize = 0x98; + pub const SIZEOF_IF_DATA_FREE_BSD8: usize = 0x98; + pub const SIZEOF_IF_DATA_FREE_BSD9: usize = 0x98; + pub const SIZEOF_IF_DATA_FREE_BSD10: usize = 0x98; + pub const SIZEOF_IF_DATA_FREE_BSD11: usize = 0x98; + + pub const SIZEOF_IF_MSGHDRL_FREE_BSD10_EMU: usize = 0xb0; + pub const SIZEOF_IFA_MSGHDR_FREE_BSD10_EMU: usize = 0x14; + pub const SIZEOF_IFA_MSGHDRL_FREE_BSD10_EMU: usize = 0xb0; + pub const SIZEOF_IFMA_MSGHDR_FREE_BSD10_EMU: usize = 0x10; + pub const SIZEOF_IF_ANNOUNCEMSGHDR_FREE_BSD10_EMU: usize = 0x18; + + pub const SIZEOF_RT_MSGHDR_FREE_BSD10_EMU: usize = 0x98; + pub const SIZEOF_RT_METRICS_FREE_BSD10_EMU: usize = 0x70; + + pub const SIZEOF_IF_MSGHDR_FREE_BSD7_EMU: usize = 0xa8; + pub const SIZEOF_IF_MSGHDR_FREE_BSD8_EMU: usize = 0xa8; + pub const SIZEOF_IF_MSGHDR_FREE_BSD9_EMU: usize = 0xa8; + pub const SIZEOF_IF_MSGHDR_FREE_BSD10_EMU: usize = 0xa8; + pub const SIZEOF_IF_MSGHDR_FREE_BSD11_EMU: usize = 0xa8; + + pub const SIZEOF_IF_DATA_FREE_BSD7_EMU: usize = 0x98; + pub const SIZEOF_IF_DATA_FREE_BSD8_EMU: usize = 0x98; + pub const SIZEOF_IF_DATA_FREE_BSD9_EMU: usize = 0x98; + pub const SIZEOF_IF_DATA_FREE_BSD10_EMU: usize = 0x98; + pub const SIZEOF_IF_DATA_FREE_BSD11_EMU: usize = 0x98; + + pub const SIZEOF_SOCKADDR_STORAGE: usize = 0x80; + pub const SIZEOF_SOCKADDR_INET: usize = 0x10; + pub const SIZEOF_SOCKADDR_INET6: usize = 0x1c; } /// 386 emulation on amd64 @@ -266,7 +266,7 @@ fn detect_compat_freebsd32() -> bool { false } -pub(super) fn probe_routing_stack() -> RoutingStack { +pub fn probe_routing_stack() -> RoutingStack { let rtm_version = RTM_VERSION; // Currently only BSD11 support is implemented. diff --git a/iroh-net/src/net/interfaces/bsd/macos.rs b/iroh-net/src/net/interfaces/bsd/macos.rs index 02d46c34ca..5c29ff943a 100644 --- a/iroh-net/src/net/interfaces/bsd/macos.rs +++ b/iroh-net/src/net/interfaces/bsd/macos.rs @@ -1,4 +1,4 @@ -use super::{RoutingStack, WireFormat, MessageType}; +use super::{MessageType, RoutingStack, WireFormat}; // Hardcoded based on the generated values here: https://cs.opensource.google/go/x/net/+/master:route/zsys_darwin.go const SIZEOF_IF_MSGHDR_DARWIN15: usize = 0x70; diff --git a/iroh-net/src/net/interfaces/bsd/netbsd.rs b/iroh-net/src/net/interfaces/bsd/netbsd.rs index c520564051..55851df727 100644 --- a/iroh-net/src/net/interfaces/bsd/netbsd.rs +++ b/iroh-net/src/net/interfaces/bsd/netbsd.rs @@ -49,20 +49,18 @@ const SHUT_RD: c_int = 0; const SHUT_WR: c_int = 1; const SHUT_RDWR: c_int = 2; - // Hardcoded based on the generated values here: https://cs.opensource.google/go/x/net/+/master:route/zsys_netbsd.go -pub(super) const SIZEOF_IF_MSGHDR_NET_BSD7: usize = 0x98; -pub(super) const SIZEOF_IFA_MSGHDR_NET_BSD7: usize = 0x18; +pub(super) const SIZEOF_IF_MSGHDR_NET_BSD7: usize = 0x98; +pub(super) const SIZEOF_IFA_MSGHDR_NET_BSD7: usize = 0x18; pub(super) const SIZEOF_IF_ANNOUNCEMSGHDR_NET_BSD7: usize = 0x18; -pub(super) const SIZEOF_RT_MSGHDR_NET_BSD7: usize = 0x78; +pub(super) const SIZEOF_RT_MSGHDR_NET_BSD7: usize = 0x78; pub(super) const SIZEOF_RT_METRICS_NET_BSD7: usize = 0x50; pub(super) const SIZEOF_SOCKADDR_STORAGE: usize = 0x80; -pub(super) const SIZEOF_SOCKADDR_INET: usize = 0x10; -pub(super) const SIZEOF_SOCKADDR_INET6: usize = 0x1c; - +pub(super) const SIZEOF_SOCKADDR_INET: usize = 0x10; +pub(super) const SIZEOF_SOCKADDR_INET6: usize = 0x1c; pub(super) fn probe_routing_stack() -> RoutingStack { let rtm_version = RTM_VERSION; From 78e95a74a58404e355f0fae3157d547ab6cd6f5e Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Tue, 21 May 2024 13:40:35 +0200 Subject: [PATCH 16/34] todo --- iroh-net/src/net/interfaces/bsd.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/iroh-net/src/net/interfaces/bsd.rs b/iroh-net/src/net/interfaces/bsd.rs index 60354cb67f..cc6f5a7574 100644 --- a/iroh-net/src/net/interfaces/bsd.rs +++ b/iroh-net/src/net/interfaces/bsd.rs @@ -373,6 +373,9 @@ impl WireFormat { }; Ok(Some(WireMessage::InterfaceMulticastAddr(m))) } + MessageType::InterfaceAnnounce => { + todo!() + } } } From 96dec5a4c4efb8d1a4e90820711b529a15b2a245 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Tue, 21 May 2024 13:41:53 +0200 Subject: [PATCH 17/34] fixup --- iroh-net/src/net/interfaces/bsd/freebsd.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iroh-net/src/net/interfaces/bsd/freebsd.rs b/iroh-net/src/net/interfaces/bsd/freebsd.rs index 6f3c4c1851..df6dbdc0a3 100644 --- a/iroh-net/src/net/interfaces/bsd/freebsd.rs +++ b/iroh-net/src/net/interfaces/bsd/freebsd.rs @@ -266,7 +266,7 @@ fn detect_compat_freebsd32() -> bool { false } -pub fn probe_routing_stack() -> RoutingStack { +pub(super) fn probe_routing_stack() -> RoutingStack { let rtm_version = RTM_VERSION; // Currently only BSD11 support is implemented. From e6debd2dd402adf2b0850530f046715b7100f437 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Tue, 21 May 2024 14:05:33 +0200 Subject: [PATCH 18/34] parse interface announce message --- iroh-net/src/net/interfaces/bsd.rs | 45 +++++++++++++++++++++++++++++- iroh-net/src/net/netmon/bsd.rs | 1 + 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/iroh-net/src/net/interfaces/bsd.rs b/iroh-net/src/net/interfaces/bsd.rs index cc6f5a7574..072ee25495 100644 --- a/iroh-net/src/net/interfaces/bsd.rs +++ b/iroh-net/src/net/interfaces/bsd.rs @@ -232,6 +232,7 @@ pub enum WireMessage { Interface(InterfaceMessage), InterfaceAddr(InterfaceAddrMessage), InterfaceMulticastAddr(InterfaceMulticastAddrMessage), + InterfaceAnnounce(InterfaceAnnounceMessage), } /// Safely convert a some bytes from a slice into a u16. @@ -374,7 +375,34 @@ impl WireFormat { Ok(Some(WireMessage::InterfaceMulticastAddr(m))) } MessageType::InterfaceAnnounce => { - todo!() + if data.len() < self.body_off { + return Err(RouteError::MessageTooShort); + } + let l = u16_from_ne_range(data, ..2)?; + if data.len() < l as usize { + return Err(RouteError::InvalidMessage); + } + + let mut name = String::new(); + for i in 0..16 { + if data[6 + i] != 0 { + continue; + } + name = std::str::from_utf8(&data[6..6 + i]) + .map_err(|_| RouteError::InvalidAddress)? + .to_string(); + break; + } + + let m = InterfaceAnnounceMessage { + version: data[2] as _, + r#type: data[3] as _, + index: u16_from_ne_range(data, 4..6)? as _, + what: u16_from_ne_range(data, 22..24)? as _, + name, + }; + + Ok(Some(WireMessage::InterfaceAnnounce(m))) } } } @@ -545,6 +573,21 @@ pub struct InterfaceMulticastAddrMessage { pub addrs: Vec, } +/// Interface announce message. +#[derive(Debug)] +pub struct InterfaceAnnounceMessage { + /// message version + pub version: isize, + /// message type + pub r#type: isize, + /// interface index + pub index: isize, + /// interface name + pub name: String, + /// what type of announcement + pub what: isize, +} + /// Represents a type of routing information base. type RIBType = i32; diff --git a/iroh-net/src/net/netmon/bsd.rs b/iroh-net/src/net/netmon/bsd.rs index 0956f5337f..aa3bc7c47a 100644 --- a/iroh-net/src/net/netmon/bsd.rs +++ b/iroh-net/src/net/netmon/bsd.rs @@ -93,6 +93,7 @@ pub(super) fn is_interesting_message(msg: &WireMessage) -> bool { true } + WireMessage::InterfaceAnnounce(_) => false, } } From 11ad5d8c78a00d79d529ea841aa99aef56eabed0 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Tue, 21 May 2024 14:39:24 +0200 Subject: [PATCH 19/34] patched iroh-quinn --- Cargo.lock | 251 +++++++++-------------------------------------------- Cargo.toml | 5 ++ 2 files changed, 44 insertions(+), 212 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 31aac2e02a..e521af1177 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -353,10 +353,10 @@ dependencies = [ "hyper 1.3.1", "hyper-util", "pin-project-lite", - "rustls 0.21.12", + "rustls", "rustls-pemfile 2.1.2", "tokio", - "tokio-rustls 0.24.1", + "tokio-rustls", "tower", "tower-service", ] @@ -1969,13 +1969,13 @@ dependencies = [ "once_cell", "rand", "ring 0.16.20", - "rustls 0.21.12", + "rustls", "rustls-pemfile 1.0.4", "serde", "thiserror", "tinyvec", "tokio", - "tokio-rustls 0.24.1", + "tokio-rustls", "tracing", "url", ] @@ -1995,12 +1995,12 @@ dependencies = [ "parking_lot", "rand", "resolv-conf", - "rustls 0.21.12", + "rustls", "serde", "smallvec", "thiserror", "tokio", - "tokio-rustls 0.24.1", + "tokio-rustls", "tracing", ] @@ -2017,12 +2017,12 @@ dependencies = [ "futures-util", "hickory-proto", "hickory-resolver", - "rustls 0.21.12", + "rustls", "serde", "thiserror", "time", "tokio", - "tokio-rustls 0.24.1", + "tokio-rustls", "tokio-util", "tracing", ] @@ -2219,26 +2219,9 @@ dependencies = [ "futures-util", "http 0.2.12", "hyper 0.14.28", - "rustls 0.21.12", + "rustls", "tokio", - "tokio-rustls 0.24.1", -] - -[[package]] -name = "hyper-rustls" -version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0bea761b46ae2b24eb4aef630d8d1c398157b6fc29e6350ecf090a0b70c952c" -dependencies = [ - "futures-util", - "http 1.1.0", - "hyper 1.3.1", - "hyper-util", - "rustls 0.22.4", - "rustls-pki-types", - "tokio", - "tokio-rustls 0.25.0", - "tower-service", + "tokio-rustls", ] [[package]] @@ -2248,7 +2231,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" dependencies = [ "bytes", - "futures-channel", "futures-util", "http 1.1.0", "http-body 1.0.0", @@ -2256,9 +2238,6 @@ dependencies = [ "pin-project-lite", "socket2", "tokio", - "tower", - "tower-service", - "tracing", ] [[package]] @@ -2401,7 +2380,7 @@ dependencies = [ "socket2", "widestring", "windows-sys 0.48.0", - "winreg 0.50.0", + "winreg", ] [[package]] @@ -2537,7 +2516,7 @@ dependencies = [ "redb 1.5.1", "redb 2.1.0", "reflink-copy", - "rustls 0.21.12", + "rustls", "self_cell", "serde", "serde_json", @@ -2585,7 +2564,7 @@ dependencies = [ "rand", "ratatui", "regex", - "reqwest 0.12.4", + "reqwest", "rustyline", "serde", "serde_with", @@ -2633,13 +2612,13 @@ dependencies = [ "rcgen 0.12.1", "redb 2.1.0", "regex", - "rustls 0.21.12", + "rustls", "rustls-pemfile 1.0.4", "serde", "struct_iterable", "strum 0.26.2", "tokio", - "tokio-rustls 0.24.1", + "tokio-rustls", "tokio-rustls-acme", "tokio-stream", "tokio-util", @@ -2743,7 +2722,7 @@ dependencies = [ "hyper-util", "once_cell", "prometheus-client", - "reqwest 0.12.4", + "reqwest", "serde", "struct_iterable", "time", @@ -2759,7 +2738,6 @@ dependencies = [ "anyhow", "axum", "backoff", - "base64 0.22.1", "bytes", "clap", "criterion", @@ -2808,12 +2786,12 @@ dependencies = [ "rand_core", "rcgen 0.11.3", "regex", - "reqwest 0.12.4", + "reqwest", "ring 0.17.8", "rtnetlink", - "rustls 0.21.12", + "rustls", "rustls-pemfile 1.0.4", - "rustls-webpki 0.101.7", + "rustls-webpki", "serde", "serde_json", "serde_with", @@ -2826,7 +2804,7 @@ dependencies = [ "thiserror", "time", "tokio", - "tokio-rustls 0.24.1", + "tokio-rustls", "tokio-rustls-acme", "tokio-util", "toml", @@ -2834,7 +2812,7 @@ dependencies = [ "tracing-subscriber", "url", "watchable", - "webpki-roots 0.25.4", + "webpki-roots", "windows 0.51.1", "wmi", "x509-parser 0.15.1", @@ -2850,10 +2828,6 @@ dependencies = [ "clap", "hdrhistogram", "iroh-net", - "quinn", - "rcgen 0.11.3", - "rustls 0.21.12", - "socket2", "tokio", "tracing", "tracing-subscriber", @@ -2862,15 +2836,14 @@ dependencies = [ [[package]] name = "iroh-quinn" version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b934380145fd5d53a583d01ae9500f4807efe6b0f0fe115c7be4afa2b35db99f" +source = "git+https://github.com/n0-computer/quinn?branch=fix-netbsd#7428ed1a879d2734db1c85b6d74ef4fd8c440476" dependencies = [ "bytes", "iroh-quinn-proto", "iroh-quinn-udp", "pin-project-lite", "rustc-hash", - "rustls 0.21.12", + "rustls", "thiserror", "tokio", "tracing", @@ -2879,14 +2852,13 @@ dependencies = [ [[package]] name = "iroh-quinn-proto" version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16f2656b322c7f6cf3eb95e632d1c0f2fa546841915b0270da581f918c70c4be" +source = "git+https://github.com/n0-computer/quinn?branch=fix-netbsd#7428ed1a879d2734db1c85b6d74ef4fd8c440476" dependencies = [ "bytes", "rand", - "ring 0.16.20", + "ring 0.17.8", "rustc-hash", - "rustls 0.21.12", + "rustls", "rustls-native-certs", "slab", "thiserror", @@ -2897,8 +2869,7 @@ dependencies = [ [[package]] name = "iroh-quinn-udp" version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6679979a7271c24f9dae9622c0b4a543881508aa3a7396f55dfbaaa56f01c063" +source = "git+https://github.com/n0-computer/quinn?branch=fix-netbsd#7428ed1a879d2734db1c85b6d74ef4fd8c440476" dependencies = [ "bytes", "libc", @@ -3711,7 +3682,7 @@ dependencies = [ "ed25519-dalek", "mainline", "rand", - "reqwest 0.11.27", + "reqwest", "self_cell", "simple-dns", "thiserror", @@ -4068,54 +4039,6 @@ version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" -[[package]] -name = "quinn" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cc2c5017e4b43d5995dcea317bc46c1e09404c0a9664d2908f7f02dfe943d75" -dependencies = [ - "bytes", - "pin-project-lite", - "quinn-proto", - "quinn-udp", - "rustc-hash", - "rustls 0.21.12", - "thiserror", - "tokio", - "tracing", -] - -[[package]] -name = "quinn-proto" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "141bf7dfde2fbc246bfd3fe12f2455aa24b0fbd9af535d8c86c7bd1381ff2b1a" -dependencies = [ - "bytes", - "rand", - "ring 0.16.20", - "rustc-hash", - "rustls 0.21.12", - "rustls-native-certs", - "slab", - "thiserror", - "tinyvec", - "tracing", -] - -[[package]] -name = "quinn-udp" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "055b4e778e8feb9f93c4e439f71dc2156ef13360b432b799e179a8c4cdf0b1d7" -dependencies = [ - "bytes", - "libc", - "socket2", - "tracing", - "windows-sys 0.48.0", -] - [[package]] name = "quote" version = "1.0.36" @@ -4418,7 +4341,7 @@ dependencies = [ "http 0.2.12", "http-body 0.4.6", "hyper 0.14.28", - "hyper-rustls 0.24.2", + "hyper-rustls", "ipnet", "js-sys", "log", @@ -4426,7 +4349,7 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", - "rustls 0.21.12", + "rustls", "rustls-pemfile 1.0.4", "serde", "serde_json", @@ -4434,55 +4357,14 @@ dependencies = [ "sync_wrapper 0.1.2", "system-configuration 0.5.1", "tokio", - "tokio-rustls 0.24.1", - "tower-service", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "webpki-roots 0.25.4", - "winreg 0.50.0", -] - -[[package]] -name = "reqwest" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "566cafdd92868e0939d3fb961bd0dc25fcfaaed179291093b3d43e6b3150ea10" -dependencies = [ - "base64 0.22.1", - "bytes", - "futures-core", - "futures-util", - "http 1.1.0", - "http-body 1.0.0", - "http-body-util", - "hyper 1.3.1", - "hyper-rustls 0.26.0", - "hyper-util", - "ipnet", - "js-sys", - "log", - "mime", - "once_cell", - "percent-encoding", - "pin-project-lite", - "rustls 0.22.4", - "rustls-pemfile 2.1.2", - "rustls-pki-types", - "serde", - "serde_json", - "serde_urlencoded", - "sync_wrapper 0.1.2", - "tokio", - "tokio-rustls 0.25.0", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots 0.26.1", - "winreg 0.52.0", + "webpki-roots", + "winreg", ] [[package]] @@ -4625,24 +4507,10 @@ checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" dependencies = [ "log", "ring 0.17.8", - "rustls-webpki 0.101.7", + "rustls-webpki", "sct", ] -[[package]] -name = "rustls" -version = "0.22.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf4ef73721ac7bcd79b2b315da7779d8fc09718c6b3d2d1b2d94850eb8c18432" -dependencies = [ - "log", - "ring 0.17.8", - "rustls-pki-types", - "rustls-webpki 0.102.4", - "subtle", - "zeroize", -] - [[package]] name = "rustls-native-certs" version = "0.6.3" @@ -4690,17 +4558,6 @@ dependencies = [ "untrusted 0.9.0", ] -[[package]] -name = "rustls-webpki" -version = "0.102.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff448f7e92e913c4b7d4c6d8e4540a1724b319b4152b8aef6d4cf8339712b33e" -dependencies = [ - "ring 0.17.8", - "rustls-pki-types", - "untrusted 0.9.0", -] - [[package]] name = "rustversion" version = "1.0.17" @@ -5665,18 +5522,7 @@ version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" dependencies = [ - "rustls 0.21.12", - "tokio", -] - -[[package]] -name = "tokio-rustls" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "775e0c0f0adb3a2f22a00c4745d728b479985fc15ee7ca6a2608388c5569860f" -dependencies = [ - "rustls 0.22.4", - "rustls-pki-types", + "rustls", "tokio", ] @@ -5696,16 +5542,16 @@ dependencies = [ "pem", "proc-macro2", "rcgen 0.12.1", - "reqwest 0.11.27", + "reqwest", "ring 0.17.8", - "rustls 0.21.12", + "rustls", "serde", "serde_json", "thiserror", "tokio", - "tokio-rustls 0.24.1", + "tokio-rustls", "url", - "webpki-roots 0.25.4", + "webpki-roots", "x509-parser 0.16.0", ] @@ -6227,15 +6073,6 @@ version = "0.25.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" -[[package]] -name = "webpki-roots" -version = "0.26.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3de34ae270483955a94f4b21bdaaeb83d508bb84a01435f393818edb0012009" -dependencies = [ - "rustls-pki-types", -] - [[package]] name = "whoami" version = "1.5.1" @@ -6586,16 +6423,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "winreg" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a277a57398d4bfa075df44f501a17cfdf8542d224f0d36095a2adc7aee4ef0a5" -dependencies = [ - "cfg-if", - "windows-sys 0.48.0", -] - [[package]] name = "wmi" version = "0.13.3" diff --git a/Cargo.toml b/Cargo.toml index a6099c70fa..2938863038 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,3 +32,8 @@ missing_debug_implementations = "warn" [workspace.lints.clippy] unused-async = "warn" + +[patch.crates-io] +iroh-quinn = { git = "https://github.com/n0-computer/quinn", branch = "fix-netbsd" } +iroh-quinn-udp = { git = "https://github.com/n0-computer/quinn", branch = "fix-netbsd" } +iroh-quinn-proto = { git = "https://github.com/n0-computer/quinn", branch = "fix-netbsd" } From c528eebd217c529eac5dac14c79274dba6463dfe Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Tue, 21 May 2024 14:46:59 +0200 Subject: [PATCH 20/34] exports --- Cargo.lock | 6 +- iroh-net/src/net/interfaces/bsd/netbsd.rs | 76 +++++++++++------------ 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e521af1177..69cb2e5e32 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2836,7 +2836,7 @@ dependencies = [ [[package]] name = "iroh-quinn" version = "0.10.4" -source = "git+https://github.com/n0-computer/quinn?branch=fix-netbsd#7428ed1a879d2734db1c85b6d74ef4fd8c440476" +source = "git+https://github.com/n0-computer/quinn?branch=fix-netbsd#a5f5fffa4d61e98d5cbde423934dae24572a6527" dependencies = [ "bytes", "iroh-quinn-proto", @@ -2852,7 +2852,7 @@ dependencies = [ [[package]] name = "iroh-quinn-proto" version = "0.10.7" -source = "git+https://github.com/n0-computer/quinn?branch=fix-netbsd#7428ed1a879d2734db1c85b6d74ef4fd8c440476" +source = "git+https://github.com/n0-computer/quinn?branch=fix-netbsd#a5f5fffa4d61e98d5cbde423934dae24572a6527" dependencies = [ "bytes", "rand", @@ -2869,7 +2869,7 @@ dependencies = [ [[package]] name = "iroh-quinn-udp" version = "0.4.1" -source = "git+https://github.com/n0-computer/quinn?branch=fix-netbsd#7428ed1a879d2734db1c85b6d74ef4fd8c440476" +source = "git+https://github.com/n0-computer/quinn?branch=fix-netbsd#a5f5fffa4d61e98d5cbde423934dae24572a6527" dependencies = [ "bytes", "libc", diff --git a/iroh-net/src/net/interfaces/bsd/netbsd.rs b/iroh-net/src/net/interfaces/bsd/netbsd.rs index 55851df727..d02f235582 100644 --- a/iroh-net/src/net/interfaces/bsd/netbsd.rs +++ b/iroh-net/src/net/interfaces/bsd/netbsd.rs @@ -5,49 +5,49 @@ use libc::c_int; // Missing constants from libc. // https://github.com/rust-lang/libc/issues/3711 -const LOCAL_PEERCRED: c_int = 1; +pub const LOCAL_PEERCRED: c_int = 1; // net/route.h -const RTF_GATEWAY: c_int = 0x2; -const RTAX_DST: c_int = 0; -const RTAX_GATEWAY: c_int = 1; -const RTAX_NETMASK: c_int = 2; -const RTAX_IFP: c_int = 4; -const RTAX_BRD: c_int = 7; -const RTAX_MAX: c_int = 8; -const RTM_VERSION: c_int = 5; -const RTA_DST: c_int = 0x1; -const RTA_GATEWAY: c_int = 0x2; -const RTA_NETMASK: c_int = 0x4; -const RTA_GENMASK: c_int = 0x8; -const RTA_IFP: c_int = 0x10; -const RTA_IFA: c_int = 0x20; -const RTA_AUTHOR: c_int = 0x40; -const RTA_BRD: c_int = 0x80; +pub const RTF_GATEWAY: c_int = 0x2; +pub const RTAX_DST: c_int = 0; +pub const RTAX_GATEWAY: c_int = 1; +pub const RTAX_NETMASK: c_int = 2; +pub const RTAX_IFP: c_int = 4; +pub const RTAX_BRD: c_int = 7; +pub const RTAX_MAX: c_int = 8; +pub const RTM_VERSION: c_int = 5; +pub const RTA_DST: c_int = 0x1; +pub const RTA_GATEWAY: c_int = 0x2; +pub const RTA_NETMASK: c_int = 0x4; +pub const RTA_GENMASK: c_int = 0x8; +pub const RTA_IFP: c_int = 0x10; +pub const RTA_IFA: c_int = 0x20; +pub const RTA_AUTHOR: c_int = 0x40; +pub const RTA_BRD: c_int = 0x80; // Message types -const RTM_ADD: c_int = 0x1; -const RTM_DELETE: c_int = 0x2; -const RTM_CHANGE: c_int = 0x3; -const RTM_GET: c_int = 0x4; -const RTM_LOSING: c_int = 0x5; -const RTM_REDIRECT: c_int = 0x6; -const RTM_MISS: c_int = 0x7; -const RTM_LOCK: c_int = 0x8; -const RTM_OLDADD: c_int = 0x9; -const RTM_OLDDEL: c_int = 0xa; -const RTM_RESOLVE: c_int = 0xb; -const RTM_NEWADDR: c_int = 0xc; -const RTM_DELADDR: c_int = 0xd; -const RTM_IFINFO: c_int = 0xe; -const RTM_NEWMADDR: c_int = 0xf; -const RTM_DELMADDR: c_int = 0x10; -const RTM_IFANNOUNCE: c_int = 0x11; -const RTM_IEEE80211: c_int = 0x12; +pub const RTM_ADD: c_int = 0x1; +pub const RTM_DELETE: c_int = 0x2; +pub const RTM_CHANGE: c_int = 0x3; +pub const RTM_GET: c_int = 0x4; +pub const RTM_LOSING: c_int = 0x5; +pub const RTM_REDIRECT: c_int = 0x6; +pub const RTM_MISS: c_int = 0x7; +pub const RTM_LOCK: c_int = 0x8; +pub const RTM_OLDADD: c_int = 0x9; +pub const RTM_OLDDEL: c_int = 0xa; +pub const RTM_RESOLVE: c_int = 0xb; +pub const RTM_NEWADDR: c_int = 0xc; +pub const RTM_DELADDR: c_int = 0xd; +pub const RTM_IFINFO: c_int = 0xe; +pub const RTM_NEWMADDR: c_int = 0xf; +pub const RTM_DELMADDR: c_int = 0x10; +pub const RTM_IFANNOUNCE: c_int = 0x11; +pub const RTM_IEEE80211: c_int = 0x12; -const SHUT_RD: c_int = 0; -const SHUT_WR: c_int = 1; -const SHUT_RDWR: c_int = 2; +pub const SHUT_RD: c_int = 0; +pub const SHUT_WR: c_int = 1; +pub const SHUT_RDWR: c_int = 2; // Hardcoded based on the generated values here: https://cs.opensource.google/go/x/net/+/master:route/zsys_netbsd.go From c027227e35580086fda0fabad1d11b31ad9a8bee Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Tue, 21 May 2024 14:58:45 +0200 Subject: [PATCH 21/34] implement openbsd route parsing --- iroh-net/src/net/interfaces/bsd.rs | 56 +++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/iroh-net/src/net/interfaces/bsd.rs b/iroh-net/src/net/interfaces/bsd.rs index 072ee25495..6a751d619b 100644 --- a/iroh-net/src/net/interfaces/bsd.rs +++ b/iroh-net/src/net/interfaces/bsd.rs @@ -258,14 +258,14 @@ fn u32_from_ne_range( } impl WireFormat { - #[cfg(any( - target_os = "freebsd", - target_os = "netbsd", - target_os = "macos", - target_os = "ios" - ))] fn parse(&self, _typ: RIBType, data: &[u8]) -> Result, RouteError> { match self.typ { + #[cfg(any( + target_os = "freebsd", + target_os = "netbsd", + target_os = "macos", + target_os = "ios" + ))] MessageType::Route => { if data.len() < self.body_off { return Err(RouteError::MessageTooShort); @@ -296,6 +296,44 @@ impl WireFormat { Ok(Some(WireMessage::Route(m))) } + #[cfg(any(target_os = "openbsd",))] + MessageType::Route => { + if data.len() < self.body_off { + return Err(RouteError::MessageTooShort); + } + let l = u16_from_ne_range(data, ..2)?; + if data.len() < l as usize { + return Err(RouteError::InvalidMessage); + } + let ll = u16_from_ne_range(data, 4..6)?; + if data.len() < ll as usize { + return Err(RouteError::InvalidMessage); + } + + let addrs = parse_addrs( + u32_from_ne_range(data, 12..6)? as _, + parse_kernel_inet_addr, + &data[ll..], + )?; + + let mut m = RouteMessage { + version: data[2] as _, + r#type: data[3] as _, + flags: u32_from_ne_range(data, 16..20)?, + index: u16_from_ne_range(data, 6..8)?, + id: u32_from_ne_range(data, 24..28)? as _, + seq: u32_from_ne_range(data, 28..32)?, + ext_off: self.ext_off, + error: None, + addrs, + }; + let errno = u32_from_ne_range(data, 32..36)?; + if errno != 0 { + m.error = Some(std::io::Error::from_raw_os_error(errno as _)); + } + + Ok(Some(WireMessage::Route(m))) + } MessageType::Interface => { if data.len() < self.body_off { return Err(RouteError::MessageTooShort); @@ -406,12 +444,6 @@ impl WireFormat { } } } - - #[cfg(target_os = "openbsd")] - fn parse(&self, typ: RIBType, data: &[u8]) -> Result, RouteError> { - // https://cs.opensource.google/go/x/net/+/master:route/route_openbsd.go - todo!() - } } #[derive(Debug, Copy, Clone)] From 71e3ad0f4fe7df980f66737006d14688d34c51df Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Tue, 21 May 2024 15:12:16 +0200 Subject: [PATCH 22/34] add openbsd --- iroh-net/src/net/interfaces/bsd.rs | 4 + iroh-net/src/net/interfaces/bsd/freebsd.rs | 2 - iroh-net/src/net/interfaces/bsd/netbsd.rs | 2 - iroh-net/src/net/interfaces/bsd/openbsd.rs | 96 ++++++++++++++++++++++ 4 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 iroh-net/src/net/interfaces/bsd/openbsd.rs diff --git a/iroh-net/src/net/interfaces/bsd.rs b/iroh-net/src/net/interfaces/bsd.rs index 6a751d619b..18d203eabb 100644 --- a/iroh-net/src/net/interfaces/bsd.rs +++ b/iroh-net/src/net/interfaces/bsd.rs @@ -25,6 +25,10 @@ pub(crate) use self::freebsd::*; mod netbsd; #[cfg(target_os = "netbsd")] pub(crate) use self::netbsd::*; +#[cfg(target_os = "openbsd")] +mod openbsd; +#[cfg(target_os = "openbsd")] +pub(crate) use self::openbsd::*; #[cfg(any(target_os = "macos", target_os = "ios"))] mod macos; diff --git a/iroh-net/src/net/interfaces/bsd/freebsd.rs b/iroh-net/src/net/interfaces/bsd/freebsd.rs index df6dbdc0a3..c5708bdc1b 100644 --- a/iroh-net/src/net/interfaces/bsd/freebsd.rs +++ b/iroh-net/src/net/interfaces/bsd/freebsd.rs @@ -5,8 +5,6 @@ use libc::c_int; // Missing constants from libc. // https://github.com/rust-lang/libc/issues/3711 -pub const LOCAL_PEERCRED: c_int = 1; - // net/route.h pub const RTF_GATEWAY: c_int = 0x2; pub const RTAX_DST: c_int = 0; diff --git a/iroh-net/src/net/interfaces/bsd/netbsd.rs b/iroh-net/src/net/interfaces/bsd/netbsd.rs index d02f235582..ee3ed62a3f 100644 --- a/iroh-net/src/net/interfaces/bsd/netbsd.rs +++ b/iroh-net/src/net/interfaces/bsd/netbsd.rs @@ -5,8 +5,6 @@ use libc::c_int; // Missing constants from libc. // https://github.com/rust-lang/libc/issues/3711 -pub const LOCAL_PEERCRED: c_int = 1; - // net/route.h pub const RTF_GATEWAY: c_int = 0x2; pub const RTAX_DST: c_int = 0; diff --git a/iroh-net/src/net/interfaces/bsd/openbsd.rs b/iroh-net/src/net/interfaces/bsd/openbsd.rs new file mode 100644 index 0000000000..75877e9473 --- /dev/null +++ b/iroh-net/src/net/interfaces/bsd/openbsd.rs @@ -0,0 +1,96 @@ +use super::{MessageType, RoutingStack, WireFormat}; + +use libc::c_int; + +// Missing constants from libc. +// https://github.com/rust-lang/libc/issues/3711 + +// net/route.h +pub const RTF_GATEWAY: c_int = 0x2; +pub const RTAX_DST: c_int = 0; +pub const RTAX_GATEWAY: c_int = 1; +pub const RTAX_NETMASK: c_int = 2; +pub const RTAX_IFP: c_int = 4; +pub const RTAX_BRD: c_int = 7; +pub const RTAX_MAX: c_int = 8; +pub const RTM_VERSION: c_int = 5; +pub const RTA_DST: c_int = 0x1; +pub const RTA_GATEWAY: c_int = 0x2; +pub const RTA_NETMASK: c_int = 0x4; +pub const RTA_GENMASK: c_int = 0x8; +pub const RTA_IFP: c_int = 0x10; +pub const RTA_IFA: c_int = 0x20; +pub const RTA_AUTHOR: c_int = 0x40; +pub const RTA_BRD: c_int = 0x80; + +// Message types +pub const RTM_ADD: c_int = 0x1; +pub const RTM_DELETE: c_int = 0x2; +pub const RTM_CHANGE: c_int = 0x3; +pub const RTM_GET: c_int = 0x4; +pub const RTM_LOSING: c_int = 0x5; +pub const RTM_REDIRECT: c_int = 0x6; +pub const RTM_MISS: c_int = 0x7; +pub const RTM_RESOLVE: c_int = 0xb; +pub const RTM_NEWADDR: c_int = 0xc; +pub const RTM_DELADDR: c_int = 0xd; +pub const RTM_IFINFO: c_int = 0xe; +pub const RTM_IFANNOUNCE: c_int = 0xf; +pub const RTM_DESYNC: c_int = 0x10; +pub const RTM_INVALIDATE: c_int = 0x11; + +pub const SHUT_RD: c_int = 0; +pub const SHUT_WR: c_int = 1; +pub const SHUT_RDWR: c_int = 2; + +// Hardcoded based on the generated values here: https://cs.opensource.google/go/x/net/+/master:route/sys_openbsd.go + +pub(super) fn probe_routing_stack() -> RoutingStack { + let rtm_version = RTM_VERSION; + + let rtm = WireFormat { + ext_off: 0, + body_off: 0, + typ: MessageType::Route, + }; + let ifm = WireFormat { + ext_off: 0, + body_off: 0, + typ: MessageType::Interface, + }; + let ifam = WireFormat { + ext_off: 0, + body_off: 0, + typ: MessageType::InterfaceAddr, + }; + let ifannm = WireFormat { + ext_off: 0, + body_off: 0, + typ: MessageType::InterfaceAnnounce, + }; + + let wire_formats = [ + (RTM_ADD, rtm), + (RTM_DELETE, rtm), + (RTM_CHANGE, rtm), + (RTM_GET, rtm), + (RTM_LOSING, rtm), + (RTM_REDIRECT, rtm), + (RTM_MISS, rtm), + (RTM_RESOLVE, rtm), + (RTM_NEWADDR, ifam), + (RTM_DELADDR, ifam), + (RTM_IFINFO, ifm), + (RTM_IFANNOUNCE, ifannm), + (RTM_DESYNC, ifannm), + ] + .into_iter() + .collect(); + + // NetBSD 6 and above kernels require 64-bit aligned access to routing facilities. + RoutingStack { + rtm_version, + wire_formats, + kernel_align: 8, + } +} From f931e73b3b5a34c112d2e0375687d5794da5ff81 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Tue, 21 May 2024 15:15:48 +0200 Subject: [PATCH 23/34] openbsd fixes --- iroh-net/src/net/interfaces/bsd.rs | 6 +++--- iroh-net/src/net/interfaces/bsd/openbsd.rs | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/iroh-net/src/net/interfaces/bsd.rs b/iroh-net/src/net/interfaces/bsd.rs index 18d203eabb..e7959da8c7 100644 --- a/iroh-net/src/net/interfaces/bsd.rs +++ b/iroh-net/src/net/interfaces/bsd.rs @@ -214,7 +214,7 @@ const fn is_valid_rib_type(typ: RIBType) -> bool { } #[cfg(target_os = "openbsd")] -const fn is_valid_rib_type(_typ: RIBType) -> bool { +const fn is_valid_rib_type(typ: RIBType) -> bool { if typ == NET_RT_STATS || typ == NET_RT_TABLE { return false; } @@ -309,8 +309,8 @@ impl WireFormat { if data.len() < l as usize { return Err(RouteError::InvalidMessage); } - let ll = u16_from_ne_range(data, 4..6)?; - if data.len() < ll as usize { + let ll = u16_from_ne_range(data, 4..6)? as usize; + if data.len() < ll { return Err(RouteError::InvalidMessage); } diff --git a/iroh-net/src/net/interfaces/bsd/openbsd.rs b/iroh-net/src/net/interfaces/bsd/openbsd.rs index 75877e9473..04721e0df4 100644 --- a/iroh-net/src/net/interfaces/bsd/openbsd.rs +++ b/iroh-net/src/net/interfaces/bsd/openbsd.rs @@ -43,6 +43,14 @@ pub const SHUT_RD: c_int = 0; pub const SHUT_WR: c_int = 1; pub const SHUT_RDWR: c_int = 2; +// socket.h +pub const NET_RT_STATS: c_int = 5; +pub const NET_RT_TABLE: c_int = 5; + +pub const SIZEOF_SOCKADDR_STORAGE: usize = 0x80; +pub const SIZEOF_SOCKADDR_INET: usize = 0x10; +pub const SIZEOF_SOCKADDR_INET6: usize = 0x1c; + // Hardcoded based on the generated values here: https://cs.opensource.google/go/x/net/+/master:route/sys_openbsd.go pub(super) fn probe_routing_stack() -> RoutingStack { From 2ed39c33c2247f9bd0042454996119d33119f6f2 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Tue, 21 May 2024 15:34:12 +0200 Subject: [PATCH 24/34] update rcgen --- Cargo.lock | 242 +++++++++++++++++++++++++++++++++++++------- iroh-net/Cargo.toml | 2 +- 2 files changed, 207 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 69cb2e5e32..653aaabc4a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -353,10 +353,10 @@ dependencies = [ "hyper 1.3.1", "hyper-util", "pin-project-lite", - "rustls", + "rustls 0.21.12", "rustls-pemfile 2.1.2", "tokio", - "tokio-rustls", + "tokio-rustls 0.24.1", "tower", "tower-service", ] @@ -1969,13 +1969,13 @@ dependencies = [ "once_cell", "rand", "ring 0.16.20", - "rustls", + "rustls 0.21.12", "rustls-pemfile 1.0.4", "serde", "thiserror", "tinyvec", "tokio", - "tokio-rustls", + "tokio-rustls 0.24.1", "tracing", "url", ] @@ -1995,12 +1995,12 @@ dependencies = [ "parking_lot", "rand", "resolv-conf", - "rustls", + "rustls 0.21.12", "serde", "smallvec", "thiserror", "tokio", - "tokio-rustls", + "tokio-rustls 0.24.1", "tracing", ] @@ -2017,12 +2017,12 @@ dependencies = [ "futures-util", "hickory-proto", "hickory-resolver", - "rustls", + "rustls 0.21.12", "serde", "thiserror", "time", "tokio", - "tokio-rustls", + "tokio-rustls 0.24.1", "tokio-util", "tracing", ] @@ -2219,9 +2219,26 @@ dependencies = [ "futures-util", "http 0.2.12", "hyper 0.14.28", - "rustls", + "rustls 0.21.12", "tokio", - "tokio-rustls", + "tokio-rustls 0.24.1", +] + +[[package]] +name = "hyper-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0bea761b46ae2b24eb4aef630d8d1c398157b6fc29e6350ecf090a0b70c952c" +dependencies = [ + "futures-util", + "http 1.1.0", + "hyper 1.3.1", + "hyper-util", + "rustls 0.22.4", + "rustls-pki-types", + "tokio", + "tokio-rustls 0.25.0", + "tower-service", ] [[package]] @@ -2231,6 +2248,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" dependencies = [ "bytes", + "futures-channel", "futures-util", "http 1.1.0", "http-body 1.0.0", @@ -2238,6 +2256,9 @@ dependencies = [ "pin-project-lite", "socket2", "tokio", + "tower", + "tower-service", + "tracing", ] [[package]] @@ -2380,7 +2401,7 @@ dependencies = [ "socket2", "widestring", "windows-sys 0.48.0", - "winreg", + "winreg 0.50.0", ] [[package]] @@ -2516,7 +2537,7 @@ dependencies = [ "redb 1.5.1", "redb 2.1.0", "reflink-copy", - "rustls", + "rustls 0.21.12", "self_cell", "serde", "serde_json", @@ -2564,7 +2585,7 @@ dependencies = [ "rand", "ratatui", "regex", - "reqwest", + "reqwest 0.12.4", "rustyline", "serde", "serde_with", @@ -2612,13 +2633,13 @@ dependencies = [ "rcgen 0.12.1", "redb 2.1.0", "regex", - "rustls", + "rustls 0.21.12", "rustls-pemfile 1.0.4", "serde", "struct_iterable", "strum 0.26.2", "tokio", - "tokio-rustls", + "tokio-rustls 0.24.1", "tokio-rustls-acme", "tokio-stream", "tokio-util", @@ -2722,7 +2743,7 @@ dependencies = [ "hyper-util", "once_cell", "prometheus-client", - "reqwest", + "reqwest 0.12.4", "serde", "struct_iterable", "time", @@ -2738,6 +2759,7 @@ dependencies = [ "anyhow", "axum", "backoff", + "base64 0.22.1", "bytes", "clap", "criterion", @@ -2784,14 +2806,14 @@ dependencies = [ "rand", "rand_chacha", "rand_core", - "rcgen 0.11.3", + "rcgen 0.12.1", "regex", - "reqwest", + "reqwest 0.12.4", "ring 0.17.8", "rtnetlink", - "rustls", + "rustls 0.21.12", "rustls-pemfile 1.0.4", - "rustls-webpki", + "rustls-webpki 0.101.7", "serde", "serde_json", "serde_with", @@ -2804,7 +2826,7 @@ dependencies = [ "thiserror", "time", "tokio", - "tokio-rustls", + "tokio-rustls 0.24.1", "tokio-rustls-acme", "tokio-util", "toml", @@ -2812,7 +2834,7 @@ dependencies = [ "tracing-subscriber", "url", "watchable", - "webpki-roots", + "webpki-roots 0.25.4", "windows 0.51.1", "wmi", "x509-parser 0.15.1", @@ -2828,6 +2850,10 @@ dependencies = [ "clap", "hdrhistogram", "iroh-net", + "quinn", + "rcgen 0.11.3", + "rustls 0.21.12", + "socket2", "tokio", "tracing", "tracing-subscriber", @@ -2843,7 +2869,7 @@ dependencies = [ "iroh-quinn-udp", "pin-project-lite", "rustc-hash", - "rustls", + "rustls 0.21.12", "thiserror", "tokio", "tracing", @@ -2858,7 +2884,7 @@ dependencies = [ "rand", "ring 0.17.8", "rustc-hash", - "rustls", + "rustls 0.21.12", "rustls-native-certs", "slab", "thiserror", @@ -3682,7 +3708,7 @@ dependencies = [ "ed25519-dalek", "mainline", "rand", - "reqwest", + "reqwest 0.11.27", "self_cell", "simple-dns", "thiserror", @@ -4039,6 +4065,54 @@ version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" +[[package]] +name = "quinn" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cc2c5017e4b43d5995dcea317bc46c1e09404c0a9664d2908f7f02dfe943d75" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls 0.21.12", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "141bf7dfde2fbc246bfd3fe12f2455aa24b0fbd9af535d8c86c7bd1381ff2b1a" +dependencies = [ + "bytes", + "rand", + "ring 0.16.20", + "rustc-hash", + "rustls 0.21.12", + "rustls-native-certs", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "055b4e778e8feb9f93c4e439f71dc2156ef13360b432b799e179a8c4cdf0b1d7" +dependencies = [ + "bytes", + "libc", + "socket2", + "tracing", + "windows-sys 0.48.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -4341,7 +4415,7 @@ dependencies = [ "http 0.2.12", "http-body 0.4.6", "hyper 0.14.28", - "hyper-rustls", + "hyper-rustls 0.24.2", "ipnet", "js-sys", "log", @@ -4349,7 +4423,7 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", - "rustls", + "rustls 0.21.12", "rustls-pemfile 1.0.4", "serde", "serde_json", @@ -4357,14 +4431,55 @@ dependencies = [ "sync_wrapper 0.1.2", "system-configuration 0.5.1", "tokio", - "tokio-rustls", + "tokio-rustls 0.24.1", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots", - "winreg", + "webpki-roots 0.25.4", + "winreg 0.50.0", +] + +[[package]] +name = "reqwest" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "566cafdd92868e0939d3fb961bd0dc25fcfaaed179291093b3d43e6b3150ea10" +dependencies = [ + "base64 0.22.1", + "bytes", + "futures-core", + "futures-util", + "http 1.1.0", + "http-body 1.0.0", + "http-body-util", + "hyper 1.3.1", + "hyper-rustls 0.26.0", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls 0.22.4", + "rustls-pemfile 2.1.2", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper 0.1.2", + "tokio", + "tokio-rustls 0.25.0", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots 0.26.1", + "winreg 0.52.0", ] [[package]] @@ -4507,10 +4622,24 @@ checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" dependencies = [ "log", "ring 0.17.8", - "rustls-webpki", + "rustls-webpki 0.101.7", "sct", ] +[[package]] +name = "rustls" +version = "0.22.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf4ef73721ac7bcd79b2b315da7779d8fc09718c6b3d2d1b2d94850eb8c18432" +dependencies = [ + "log", + "ring 0.17.8", + "rustls-pki-types", + "rustls-webpki 0.102.4", + "subtle", + "zeroize", +] + [[package]] name = "rustls-native-certs" version = "0.6.3" @@ -4558,6 +4687,17 @@ dependencies = [ "untrusted 0.9.0", ] +[[package]] +name = "rustls-webpki" +version = "0.102.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff448f7e92e913c4b7d4c6d8e4540a1724b319b4152b8aef6d4cf8339712b33e" +dependencies = [ + "ring 0.17.8", + "rustls-pki-types", + "untrusted 0.9.0", +] + [[package]] name = "rustversion" version = "1.0.17" @@ -5522,7 +5662,18 @@ version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" dependencies = [ - "rustls", + "rustls 0.21.12", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "775e0c0f0adb3a2f22a00c4745d728b479985fc15ee7ca6a2608388c5569860f" +dependencies = [ + "rustls 0.22.4", + "rustls-pki-types", "tokio", ] @@ -5542,16 +5693,16 @@ dependencies = [ "pem", "proc-macro2", "rcgen 0.12.1", - "reqwest", + "reqwest 0.11.27", "ring 0.17.8", - "rustls", + "rustls 0.21.12", "serde", "serde_json", "thiserror", "tokio", - "tokio-rustls", + "tokio-rustls 0.24.1", "url", - "webpki-roots", + "webpki-roots 0.25.4", "x509-parser 0.16.0", ] @@ -6073,6 +6224,15 @@ version = "0.25.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" +[[package]] +name = "webpki-roots" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3de34ae270483955a94f4b21bdaaeb83d508bb84a01435f393818edb0012009" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "whoami" version = "1.5.1" @@ -6423,6 +6583,16 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "winreg" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a277a57398d4bfa075df44f501a17cfdf8542d224f0d36095a2adc7aee4ef0a5" +dependencies = [ + "cfg-if", + "windows-sys 0.48.0", +] + [[package]] name = "wmi" version = "0.13.3" diff --git a/iroh-net/Cargo.toml b/iroh-net/Cargo.toml index 9d0f7cdc36..92363d6b96 100644 --- a/iroh-net/Cargo.toml +++ b/iroh-net/Cargo.toml @@ -54,7 +54,7 @@ quinn-proto = { package = "iroh-quinn-proto", version = "0.10.7" } quinn-udp = { package = "iroh-quinn-udp", version = "0.4" } rand = "0.8" rand_core = "0.6.4" -rcgen = "0.11" +rcgen = "0.12" reqwest = { version = "0.12.4", default-features = false, features = ["rustls-tls"] } ring = "0.17" rustls = { version = "0.21.11", default-features = false, features = ["dangerous_configuration"] } From 5f449e20affa82591b60a9b3d476a4d6d2570fa2 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Tue, 21 May 2024 15:35:50 +0200 Subject: [PATCH 25/34] fixup warnings --- iroh-net/src/tls/certificate.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iroh-net/src/tls/certificate.rs b/iroh-net/src/tls/certificate.rs index b26e6d87a9..a31209f51b 100644 --- a/iroh-net/src/tls/certificate.rs +++ b/iroh-net/src/tls/certificate.rs @@ -100,7 +100,7 @@ pub struct P2pExtension { /// An error that occurs during certificate generation. #[derive(Debug, thiserror::Error)] #[error(transparent)] -pub struct GenError(#[from] rcgen::RcgenError); +pub struct GenError(#[from] rcgen::Error); /// An error that occurs during certificate parsing. #[derive(Debug, thiserror::Error)] @@ -173,7 +173,7 @@ fn parse_unverified(der_input: &[u8]) -> Result { fn make_libp2p_extension( identity_secret_key: &SecretKey, certificate_keypair: &rcgen::KeyPair, -) -> Result { +) -> Result { // The peer signs the concatenation of the string `libp2p-tls-handshake:` // and the public key that it used to generate the certificate carrying // the libp2p Public Key Extension, using its private host key. @@ -187,10 +187,10 @@ fn make_libp2p_extension( let public_key = identity_secret_key.public(); let public_key_ref = OctetStringRef::new(&public_key.as_bytes()[..]) - .map_err(|_| rcgen::RcgenError::CouldNotParseKeyPair)?; + .map_err(|_| rcgen::Error::CouldNotParseKeyPair)?; let signature = signature.to_bytes(); let signature_ref = - OctetStringRef::new(&signature).map_err(|_| rcgen::RcgenError::CouldNotParseCertificate)?; + OctetStringRef::new(&signature).map_err(|_| rcgen::Error::CouldNotParseCertificate)?; let key = SignedKey { public_key: public_key_ref, signature: signature_ref, From 0e8d8245dd0080fe228aab63ea59efdf0eed8ae5 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Tue, 21 May 2024 16:55:16 +0200 Subject: [PATCH 26/34] fix openbsd --- iroh-net/src/net/interfaces/bsd.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/iroh-net/src/net/interfaces/bsd.rs b/iroh-net/src/net/interfaces/bsd.rs index e7959da8c7..dd6ca7e3ca 100644 --- a/iroh-net/src/net/interfaces/bsd.rs +++ b/iroh-net/src/net/interfaces/bsd.rs @@ -315,7 +315,7 @@ impl WireFormat { } let addrs = parse_addrs( - u32_from_ne_range(data, 12..6)? as _, + u32_from_ne_range(data, 12..16)? as _, parse_kernel_inet_addr, &data[ll..], )?; @@ -698,6 +698,9 @@ fn fetch_rib(af: i32, typ: RIBType, arg: i32) -> Result, RouteError> { } return Err(RouteError::Io("sysctl", io_err)); } + // Truncate b, to the new length + b.truncate(n); + return Ok(b); } } From 6aa9b41798d864f08a301216d28c00cc0f468fc0 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Tue, 21 May 2024 17:01:09 +0200 Subject: [PATCH 27/34] ci: disable i686 freebsd, link errors --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cd0b3e3168..41d36d1345 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,7 +39,7 @@ jobs: - armv7-linux-androideabi - aarch64-linux-android # Freebsd execution fails in cross - - i686-unknown-freebsd + # - i686-unknown-freebsd # Linking fails :/ - x86_64-unknown-freebsd steps: - name: Checkout From cb9482106746ad86b2bb8e72bab798000243d40e Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Tue, 21 May 2024 17:01:36 +0200 Subject: [PATCH 28/34] ci: add netbsd compile check --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 41d36d1345..6697998203 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,6 +41,7 @@ jobs: # Freebsd execution fails in cross # - i686-unknown-freebsd # Linking fails :/ - x86_64-unknown-freebsd + - x86_64-unknown-netbsd steps: - name: Checkout uses: actions/checkout@v4 From 0a8385c9a3e5f99c0cf93e93645f27653d7fc369 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Tue, 21 May 2024 17:07:20 +0200 Subject: [PATCH 29/34] removed unused constants --- iroh-net/src/net/interfaces/bsd/freebsd.rs | 4 ---- iroh-net/src/net/interfaces/bsd/netbsd.rs | 4 ---- iroh-net/src/net/interfaces/bsd/openbsd.rs | 4 ---- 3 files changed, 12 deletions(-) diff --git a/iroh-net/src/net/interfaces/bsd/freebsd.rs b/iroh-net/src/net/interfaces/bsd/freebsd.rs index c5708bdc1b..b5efc288dc 100644 --- a/iroh-net/src/net/interfaces/bsd/freebsd.rs +++ b/iroh-net/src/net/interfaces/bsd/freebsd.rs @@ -43,10 +43,6 @@ pub const RTM_DELMADDR: c_int = 0x10; pub const RTM_IFANNOUNCE: c_int = 0x11; pub const RTM_IEEE80211: c_int = 0x12; -pub const SHUT_RD: c_int = 0; -pub const SHUT_WR: c_int = 1; -pub const SHUT_RDWR: c_int = 2; - // Hardcoded based on the generated values here: https://cs.opensource.google/go/x/net/+/master:route/zsys_freebsd_amd64.go #[cfg(target_arch = "x86_64")] pub use self::amd64::*; diff --git a/iroh-net/src/net/interfaces/bsd/netbsd.rs b/iroh-net/src/net/interfaces/bsd/netbsd.rs index ee3ed62a3f..233c2ff718 100644 --- a/iroh-net/src/net/interfaces/bsd/netbsd.rs +++ b/iroh-net/src/net/interfaces/bsd/netbsd.rs @@ -43,10 +43,6 @@ pub const RTM_DELMADDR: c_int = 0x10; pub const RTM_IFANNOUNCE: c_int = 0x11; pub const RTM_IEEE80211: c_int = 0x12; -pub const SHUT_RD: c_int = 0; -pub const SHUT_WR: c_int = 1; -pub const SHUT_RDWR: c_int = 2; - // Hardcoded based on the generated values here: https://cs.opensource.google/go/x/net/+/master:route/zsys_netbsd.go pub(super) const SIZEOF_IF_MSGHDR_NET_BSD7: usize = 0x98; diff --git a/iroh-net/src/net/interfaces/bsd/openbsd.rs b/iroh-net/src/net/interfaces/bsd/openbsd.rs index 04721e0df4..7a7373f655 100644 --- a/iroh-net/src/net/interfaces/bsd/openbsd.rs +++ b/iroh-net/src/net/interfaces/bsd/openbsd.rs @@ -39,10 +39,6 @@ pub const RTM_IFANNOUNCE: c_int = 0xf; pub const RTM_DESYNC: c_int = 0x10; pub const RTM_INVALIDATE: c_int = 0x11; -pub const SHUT_RD: c_int = 0; -pub const SHUT_WR: c_int = 1; -pub const SHUT_RDWR: c_int = 2; - // socket.h pub const NET_RT_STATS: c_int = 5; pub const NET_RT_TABLE: c_int = 5; From 13e34f30bf0953bb93e3de8102149048b746130c Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Tue, 21 May 2024 17:12:24 +0200 Subject: [PATCH 30/34] update some constants --- iroh-net/src/net/interfaces/bsd/netbsd.rs | 4 ++-- iroh-net/src/net/interfaces/bsd/openbsd.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iroh-net/src/net/interfaces/bsd/netbsd.rs b/iroh-net/src/net/interfaces/bsd/netbsd.rs index 233c2ff718..d04b493554 100644 --- a/iroh-net/src/net/interfaces/bsd/netbsd.rs +++ b/iroh-net/src/net/interfaces/bsd/netbsd.rs @@ -12,8 +12,8 @@ pub const RTAX_GATEWAY: c_int = 1; pub const RTAX_NETMASK: c_int = 2; pub const RTAX_IFP: c_int = 4; pub const RTAX_BRD: c_int = 7; -pub const RTAX_MAX: c_int = 8; -pub const RTM_VERSION: c_int = 5; +pub const RTAX_MAX: c_int = 9; +pub const RTM_VERSION: c_int = 4; pub const RTA_DST: c_int = 0x1; pub const RTA_GATEWAY: c_int = 0x2; pub const RTA_NETMASK: c_int = 0x4; diff --git a/iroh-net/src/net/interfaces/bsd/openbsd.rs b/iroh-net/src/net/interfaces/bsd/openbsd.rs index 7a7373f655..3209009797 100644 --- a/iroh-net/src/net/interfaces/bsd/openbsd.rs +++ b/iroh-net/src/net/interfaces/bsd/openbsd.rs @@ -12,7 +12,7 @@ pub const RTAX_GATEWAY: c_int = 1; pub const RTAX_NETMASK: c_int = 2; pub const RTAX_IFP: c_int = 4; pub const RTAX_BRD: c_int = 7; -pub const RTAX_MAX: c_int = 8; +pub const RTAX_MAX: c_int = 15; pub const RTM_VERSION: c_int = 5; pub const RTA_DST: c_int = 0x1; pub const RTA_GATEWAY: c_int = 0x2; From 9bb11a1b91035918cc52614f37927d646a853bd8 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Tue, 21 May 2024 17:21:04 +0200 Subject: [PATCH 31/34] update constants --- iroh-net/src/net/interfaces/bsd/netbsd.rs | 23 +++++++++++++++------- iroh-net/src/net/interfaces/bsd/openbsd.rs | 5 +++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/iroh-net/src/net/interfaces/bsd/netbsd.rs b/iroh-net/src/net/interfaces/bsd/netbsd.rs index d04b493554..898a41c315 100644 --- a/iroh-net/src/net/interfaces/bsd/netbsd.rs +++ b/iroh-net/src/net/interfaces/bsd/netbsd.rs @@ -34,14 +34,23 @@ pub const RTM_MISS: c_int = 0x7; pub const RTM_LOCK: c_int = 0x8; pub const RTM_OLDADD: c_int = 0x9; pub const RTM_OLDDEL: c_int = 0xa; -pub const RTM_RESOLVE: c_int = 0xb; -pub const RTM_NEWADDR: c_int = 0xc; -pub const RTM_DELADDR: c_int = 0xd; -pub const RTM_IFINFO: c_int = 0xe; +// pub const RTM_RESOLVE: c_int = 0xb; +pub const RTM_ONEWADDR: c_int = 0xc; +pub const RTM_ODELADDR: c_int = 0xd; +pub const RTM_OOIFINFO: c_int = 0xe; +pub const RTM_OIFINFO: c_int = 0xf; pub const RTM_NEWMADDR: c_int = 0xf; -pub const RTM_DELMADDR: c_int = 0x10; -pub const RTM_IFANNOUNCE: c_int = 0x11; -pub const RTM_IEEE80211: c_int = 0x12; +pub const RTM_IFANNOUNCE: c_int = 0x10; +pub const RTM_IEEE80211: c_int = 0x11; +pub const RTM_SETGATE: c_int = 0x12; + +pub const RTM_LLINFO_UPD: c_int = 0x13; + +pub const RTM_IFINFO: c_int = 0x14; +pub const RTM_OCHGADDR: c_int = 0x15; +pub const RTM_NEWADDR: c_int = 0x16; +pub const RTM_DELADDR: c_int = 0x17; +pub const RTM_CHGADDR: c_int = 0x18; // Hardcoded based on the generated values here: https://cs.opensource.google/go/x/net/+/master:route/zsys_netbsd.go diff --git a/iroh-net/src/net/interfaces/bsd/openbsd.rs b/iroh-net/src/net/interfaces/bsd/openbsd.rs index 3209009797..2e9faf8df5 100644 --- a/iroh-net/src/net/interfaces/bsd/openbsd.rs +++ b/iroh-net/src/net/interfaces/bsd/openbsd.rs @@ -38,6 +38,11 @@ pub const RTM_IFINFO: c_int = 0xe; pub const RTM_IFANNOUNCE: c_int = 0xf; pub const RTM_DESYNC: c_int = 0x10; pub const RTM_INVALIDATE: c_int = 0x11; +pub const RTM_BFD: c_int = 0x12; +pub const RTM_PROPOSAL: c_int = 0x13; +pub const RTM_CHGADDRATTR: c_int = 0x14; +pub const RTM_80211INFO: c_int = 0x15; +pub const RTM_SOURCE: c_int = 0x16; // socket.h pub const NET_RT_STATS: c_int = 5; From 29112cf39981f3b9fc84137cf817cfa404d6d5ef Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Wed, 22 May 2024 12:36:19 +0200 Subject: [PATCH 32/34] netbsd: remove resolve --- iroh-net/src/net/interfaces/bsd/netbsd.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/iroh-net/src/net/interfaces/bsd/netbsd.rs b/iroh-net/src/net/interfaces/bsd/netbsd.rs index 898a41c315..f3a286cb84 100644 --- a/iroh-net/src/net/interfaces/bsd/netbsd.rs +++ b/iroh-net/src/net/interfaces/bsd/netbsd.rs @@ -98,7 +98,6 @@ pub(super) fn probe_routing_stack() -> RoutingStack { (RTM_REDIRECT, rtm), (RTM_MISS, rtm), (RTM_LOCK, rtm), - (RTM_RESOLVE, rtm), (RTM_NEWADDR, ifam), (RTM_DELADDR, ifam), (RTM_IFANNOUNCE, ifannm), From 323abbccb559c2afa03034af2ac9234f84038bd5 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Fri, 24 May 2024 13:54:15 +0200 Subject: [PATCH 33/34] switch to release quinn --- Cargo.lock | 15 +++++++++------ Cargo.toml | 5 ----- iroh-net/Cargo.toml | 6 +++--- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 653aaabc4a..93d516abf9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2861,8 +2861,9 @@ dependencies = [ [[package]] name = "iroh-quinn" -version = "0.10.4" -source = "git+https://github.com/n0-computer/quinn?branch=fix-netbsd#a5f5fffa4d61e98d5cbde423934dae24572a6527" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "906875956feb75d3d41d708ddaffeb11fdb10cd05f23efbcb17600037e411779" dependencies = [ "bytes", "iroh-quinn-proto", @@ -2877,8 +2878,9 @@ dependencies = [ [[package]] name = "iroh-quinn-proto" -version = "0.10.7" -source = "git+https://github.com/n0-computer/quinn?branch=fix-netbsd#a5f5fffa4d61e98d5cbde423934dae24572a6527" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6bf92478805e67f2320459285496e1137edf5171411001a0d4d85f9bbafb792" dependencies = [ "bytes", "rand", @@ -2894,8 +2896,9 @@ dependencies = [ [[package]] name = "iroh-quinn-udp" -version = "0.4.1" -source = "git+https://github.com/n0-computer/quinn?branch=fix-netbsd#a5f5fffa4d61e98d5cbde423934dae24572a6527" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edc7915b3a31f08ee0bc02f73f4d61a5d5be146a1081ef7f70622a11627fd314" dependencies = [ "bytes", "libc", diff --git a/Cargo.toml b/Cargo.toml index 2938863038..a6099c70fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,8 +32,3 @@ missing_debug_implementations = "warn" [workspace.lints.clippy] unused-async = "warn" - -[patch.crates-io] -iroh-quinn = { git = "https://github.com/n0-computer/quinn", branch = "fix-netbsd" } -iroh-quinn-udp = { git = "https://github.com/n0-computer/quinn", branch = "fix-netbsd" } -iroh-quinn-proto = { git = "https://github.com/n0-computer/quinn", branch = "fix-netbsd" } diff --git a/iroh-net/Cargo.toml b/iroh-net/Cargo.toml index 92363d6b96..cab29f77ad 100644 --- a/iroh-net/Cargo.toml +++ b/iroh-net/Cargo.toml @@ -49,9 +49,9 @@ parking_lot = "0.12.1" pin-project = "1" pkarr = { version = "1.1.4", default-features = false, features = ["async", "relay"] } postcard = { version = "1", default-features = false, features = ["alloc", "use-std", "experimental-derive"] } -quinn = { package = "iroh-quinn", version = "0.10.4" } -quinn-proto = { package = "iroh-quinn-proto", version = "0.10.7" } -quinn-udp = { package = "iroh-quinn-udp", version = "0.4" } +quinn = { package = "iroh-quinn", version = "0.10.5" } +quinn-proto = { package = "iroh-quinn-proto", version = "0.10.8" } +quinn-udp = { package = "iroh-quinn-udp", version = "0.4.2" } rand = "0.8" rand_core = "0.6.4" rcgen = "0.12" From d4e7ba39e0526d507d0b416ba330df55a9160c25 Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Fri, 24 May 2024 14:58:15 +0000 Subject: [PATCH 34/34] Disable upstream quinn on bsd Currently upstream quinn 0.10.x does not work on bsd yet. Simply disable that test for now. --- iroh-net/bench/Cargo.toml | 4 +++- iroh-net/bench/src/bin/bulk.rs | 6 +++++- iroh-net/bench/src/lib.rs | 12 ++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/iroh-net/bench/Cargo.toml b/iroh-net/bench/Cargo.toml index b5c7048e0a..c947025f9b 100644 --- a/iroh-net/bench/Cargo.toml +++ b/iroh-net/bench/Cargo.toml @@ -10,7 +10,6 @@ anyhow = "1.0.22" bytes = "1" hdrhistogram = { version = "7.2", default-features = false } iroh-net = { path = ".." } -quinn = "0.10" rcgen = "0.11.1" rustls = { version = "0.21.0", default-features = false, features = ["quic"] } clap = { version = "4", features = ["derive"] } @@ -18,3 +17,6 @@ tokio = { version = "1.0.1", features = ["rt", "sync"] } tracing = "0.1" tracing-subscriber = { version = "0.3.0", default-features = false, features = ["env-filter", "fmt", "ansi", "time", "local-time"] } socket2 = "0.5" + +[target.'cfg(not(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd")))'.dependencies] +quinn = "0.10" \ No newline at end of file diff --git a/iroh-net/bench/src/bin/bulk.rs b/iroh-net/bench/src/bin/bulk.rs index 5c7e956249..a0c6933876 100644 --- a/iroh-net/bench/src/bin/bulk.rs +++ b/iroh-net/bench/src/bin/bulk.rs @@ -1,7 +1,9 @@ use anyhow::Result; use clap::Parser; -use iroh_net_bench::{configure_tracing_subscriber, iroh, quinn, rt, s2n, Commands, Opt}; +#[cfg(not(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd")))] +use iroh_net_bench::quinn; +use iroh_net_bench::{configure_tracing_subscriber, iroh, rt, s2n, Commands, Opt}; fn main() { let cmd = Commands::parse(); @@ -13,6 +15,7 @@ fn main() { eprintln!("failed: {e:#}"); } } + #[cfg(not(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd")))] Commands::Quinn(opt) => { if let Err(e) = run_quinn(opt) { eprintln!("failed: {e:#}"); @@ -70,6 +73,7 @@ pub fn run_iroh(opt: Opt) -> Result<()> { Ok(()) } +#[cfg(not(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd")))] pub fn run_quinn(opt: Opt) -> Result<()> { let server_span = tracing::error_span!("server"); let runtime = rt(); diff --git a/iroh-net/bench/src/lib.rs b/iroh-net/bench/src/lib.rs index b92665e77e..cf1ecab6c0 100644 --- a/iroh-net/bench/src/lib.rs +++ b/iroh-net/bench/src/lib.rs @@ -13,6 +13,7 @@ use tokio::sync::Semaphore; use tracing::info; pub mod iroh; +#[cfg(not(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd")))] pub mod quinn; pub mod s2n; pub mod stats; @@ -21,6 +22,7 @@ pub mod stats; #[clap(name = "bulk")] pub enum Commands { Iroh(Opt), + #[cfg(not(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd")))] Quinn(Opt), S2n(s2n::Opt), } @@ -62,6 +64,7 @@ pub struct Opt { pub enum EndpointSelector { Iroh(iroh_net::Endpoint), + #[cfg(not(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd")))] Quinn(::quinn::Endpoint), } @@ -71,6 +74,7 @@ impl EndpointSelector { EndpointSelector::Iroh(endpoint) => { endpoint.close(0u32.into(), b"").await?; } + #[cfg(not(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd")))] EndpointSelector::Quinn(endpoint) => { endpoint.close(0u32.into(), b""); } @@ -81,6 +85,7 @@ impl EndpointSelector { pub enum ConnectionSelector { Iroh(iroh_net::endpoint::Connection), + #[cfg(not(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd")))] Quinn(::quinn::Connection), } @@ -90,6 +95,7 @@ impl ConnectionSelector { ConnectionSelector::Iroh(connection) => { println!("{:#?}", connection.stats()); } + #[cfg(not(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd")))] ConnectionSelector::Quinn(connection) => { println!("{:#?}", connection.stats()); } @@ -101,6 +107,7 @@ impl ConnectionSelector { ConnectionSelector::Iroh(connection) => { connection.close(error_code.into(), reason); } + #[cfg(not(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd")))] ConnectionSelector::Quinn(connection) => { connection.close(error_code.into(), reason); } @@ -193,6 +200,11 @@ pub async fn client_handler( iroh::handle_client_stream(connection, opt.upload_size, opt.read_unordered) .await } + #[cfg(not(any( + target_os = "freebsd", + target_os = "openbsd", + target_os = "netbsd" + )))] ConnectionSelector::Quinn(connection) => { quinn::handle_client_stream(connection, opt.upload_size, opt.read_unordered) .await