Skip to content

Commit

Permalink
add openbsd
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed May 21, 2024
1 parent fc0bd9d commit 76bf133
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 4 deletions.
4 changes: 4 additions & 0 deletions iroh-net/src/net/interfaces/bsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions iroh-net/src/net/interfaces/bsd/freebsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions iroh-net/src/net/interfaces/bsd/netbsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
96 changes: 96 additions & 0 deletions iroh-net/src/net/interfaces/bsd/openbsd.rs
Original file line number Diff line number Diff line change
@@ -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,
}
}

0 comments on commit 76bf133

Please sign in to comment.