Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Ioctl type #43

Merged
merged 4 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ethox-no-std/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ pub extern fn main(_nargs: i32, _args: *const *const u8) -> i32 {
let hostmac = ethernet::Address([0xab,0xff,0xff,0xff,0xff,0xff]);

let mut eth = eth::Endpoint::new(hostmac);
let mut arp_requests = [None; 16];

let mut neighbors = [arp::Neighbor::default(); 10];
let mut ip = ip::Endpoint::new(Slice::One(host.into()),
// No routes at all
ip::Routes::new(Slice::empty()),
// But do automatic arp
arp::NeighborCache::new(&mut neighbors[..]));
{
let neighbors = arp::NeighborCache::new(&mut neighbors[..]);
let buffer = arp::RequestBuffer::new((&mut arp_requests[..]).into());

arp::Endpoint::new(neighbors).with_request_buffer(buffer)
});

let mut icmp = icmp::Endpoint::new();

Expand Down
2 changes: 2 additions & 0 deletions ethox/src/layer/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ impl<P: Payload> Recv<P> for Formatter<ethernet::frame> {
}
}

#[cfg(feature = "std")]
impl<P: Payload, I> Recv<P> for pretty_print::FormatWith<I, ethernet::frame>
where I: Recv<P>
{
Expand All @@ -71,6 +72,7 @@ impl<P: Payload, I> Recv<P> for pretty_print::FormatWith<I, ethernet::frame>
}
}

#[cfg(feature = "std")]
impl<P: Payload, I> Send<P> for pretty_print::FormatWith<I, ethernet::frame>
where I: Send<P>
{
Expand Down
4 changes: 2 additions & 2 deletions ethox/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ macro_rules! enum_with_unknown {
enum_with_unknown! {
$( #[$enum_attr] )*
pub doc enum $name($ty) {
$($(#[$val_attr])* #[doc(shown)] $variant = $value ),+
$($(#[$val_attr])* $variant = $value ),+
}
}
};
(
$( #[$enum_attr:meta] )*
pub doc enum $name:ident($ty:ty) {
$(
$( #[$variant_attr:meta] )+
$( #[$variant_attr:meta] )*
$variant:ident = $value:expr $(,)*
),+
}
Expand Down
2 changes: 2 additions & 0 deletions ethox/src/nic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ impl<H: Handle + ?Sized, P: Payload + ?Sized> Recv<H, P> for Formatter<ethernet:
}
}

#[cfg(feature = "std")]
impl<I, H: Handle + ?Sized, P: Payload + ?Sized> Recv<H, P> for FormatWith<I, ethernet::frame>
where I: Recv<H, P>
{
Expand All @@ -223,6 +224,7 @@ impl<I, H: Handle + ?Sized, P: Payload + ?Sized> Recv<H, P> for FormatWith<I, et
}
}

#[cfg(feature = "std")]
impl<I, H: Handle + ?Sized, P: Payload + ?Sized> Send<H, P> for FormatWith<I, ethernet::frame>
where I: Send<H, P>
{
Expand Down
13 changes: 10 additions & 3 deletions ethox/src/nic/sys/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,18 @@ pub(crate) trait IfIndex {
fn get_if_index(&mut self, fd: libc::c_int) -> Result<libc::c_int, Errno>;
}

// This is freaking stupid: <https://github.com/rust-lang/libc/issues/1036#issuecomment-850765498>
// At some point, the hidden public type def was dropped. Probably out of similar concerns. We only
// support linux-gnu for now. The right type according to the kernel is `c_uint`. BSD does ulong.
// Really we should just be implementing our own syscall wrapper here since the situation of using
// `libc` is so tiring.
type Ioctl = libc::c_ulong;

impl ifreq {
pub(crate) const SIOCGIFMTU: libc::Ioctl = 0x8921;
pub(crate) const SIOCGIFINDEX: libc::Ioctl = 0x8933;
pub(crate) const SIOCGIFMTU: Ioctl = 0x8921;
pub(crate) const SIOCGIFINDEX: Ioctl = 0x8933;

pub(crate) const TUNSETIFF: libc::Ioctl = 0x400454CA;
pub(crate) const TUNSETIFF: Ioctl = 0x400454CA;
pub(crate) const IFF_TAP: libc::c_int = 0x0002;
pub(crate) const IFF_NO_PI: libc::c_int = 0x1000;
}
Expand Down
Loading