Skip to content

WIP: ICMP code/type firewall filters #759

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

Draft
wants to merge 14 commits into
base: optehdl-cleanup
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion crates/opte-api/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use super::encap::Vni;
use super::ip::IpCidr;
use super::mac::MacAddr;
use alloc::string::String;
use alloc::string::ToString;
use alloc::vec::Vec;
use core::fmt::Debug;
use illumos_sys_hdrs::c_int;
Expand Down Expand Up @@ -130,7 +131,7 @@ impl OpteCmdIoctl {
match postcard::from_bytes(resp) {
Ok(cmd_err) => Some(cmd_err),
Err(deser_err) => {
Some(OpteError::DeserCmdErr(format!("{}", deser_err)))
Some(OpteError::DeserCmdErr(deser_err.to_string()))
}
}
} else {
Expand Down
36 changes: 18 additions & 18 deletions crates/opte-api/src/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

// Copyright 2024 Oxide Computer Company
// Copyright 2025 Oxide Computer Company

use super::mac::MacAddr;
use crate::DomainName;
Expand Down Expand Up @@ -348,8 +348,8 @@ impl Default for IpAddr {
impl fmt::Display for IpAddr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
IpAddr::Ip4(ip4) => write!(f, "{}", ip4),
IpAddr::Ip6(ip6) => write!(f, "{}", ip6),
IpAddr::Ip4(ip4) => write!(f, "{ip4}"),
IpAddr::Ip6(ip6) => write!(f, "{ip6}"),
}
}
}
Expand Down Expand Up @@ -402,7 +402,7 @@ impl Ipv4Addr {
/// Return the address after applying the network mask.
pub fn mask(mut self, mask: u8) -> Result<Self, String> {
if mask > 32 {
return Err(format!("bad mask: {}", mask));
return Err(format!("bad mask: {mask}"));
}

if mask == 0 {
Expand Down Expand Up @@ -482,11 +482,11 @@ impl FromStr for Ipv4Addr {
fn from_str(val: &str) -> result::Result<Self, Self::Err> {
let octets: Vec<u8> = val
.split('.')
.map(|s| s.parse().map_err(|e| format!("{}", e)))
.map(|s| s.parse().map_err(|e| format!("{e}")))
.collect::<result::Result<Vec<u8>, _>>()?;

if octets.len() != 4 {
return Err(format!("malformed ip: {}", val));
return Err(format!("malformed ip: {val}"));
}

// At the time of writing there is no TryFrom impl for Vec to
Expand All @@ -510,7 +510,7 @@ impl Display for Ipv4Addr {
// present it in a human-friendly manner.
impl Debug for Ipv4Addr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Ipv4Addr {{ inner: {} }}", self)
write!(f, "Ipv4Addr {{ inner: {self} }}")
}
}

Expand Down Expand Up @@ -648,7 +648,7 @@ impl Ipv6Addr {
/// Return the address after applying the network mask.
pub fn mask(mut self, mask: u8) -> Result<Self, String> {
if mask > 128 {
return Err(format!("bad mask: {}", mask));
return Err(format!("bad mask: {mask}"));
}

if mask == 128 {
Expand Down Expand Up @@ -708,7 +708,7 @@ impl Ipv6Addr {
impl fmt::Display for Ipv6Addr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let sip6 = smoltcp::wire::Ipv6Address(self.bytes());
write!(f, "{}", sip6)
write!(f, "{sip6}")
}
}

Expand Down Expand Up @@ -853,8 +853,8 @@ impl IpCidr {
impl fmt::Display for IpCidr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::Ip4(ip4) => write!(f, "{}", ip4),
Self::Ip6(ip6) => write!(f, "{}", ip6),
Self::Ip4(ip4) => write!(f, "{ip4}"),
Self::Ip6(ip6) => write!(f, "{ip6}"),
}
}
}
Expand Down Expand Up @@ -914,7 +914,7 @@ impl Ipv4PrefixLen {

pub fn new(prefix_len: u8) -> Result<Self, String> {
if prefix_len > 32 {
return Err(format!("bad IPv4 prefix length: {}", prefix_len));
return Err(format!("bad IPv4 prefix length: {prefix_len}"));
}

Ok(Self(prefix_len))
Expand Down Expand Up @@ -967,13 +967,13 @@ impl FromStr for Ipv4Cidr {

let ip = match ip_s.parse() {
Ok(v) => v,
Err(e) => return Err(format!("bad IP: {}", e)),
Err(e) => return Err(format!("bad IP: {e}")),
};

let raw = match prefix_s.parse::<u8>() {
Ok(v) => v,
Err(e) => {
return Err(format!("bad prefix length: {}", e));
return Err(format!("bad prefix length: {e}"));
}
};

Expand Down Expand Up @@ -1076,7 +1076,7 @@ impl core::cmp::PartialOrd for Ipv6Cidr {
impl fmt::Display for Ipv6Cidr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let (ip, prefix_len) = self.parts();
write!(f, "{}/{}", ip, prefix_len.val())
write!(f, "{ip}/{}", prefix_len.val())
}
}

Expand All @@ -1093,14 +1093,14 @@ impl FromStr for Ipv6Cidr {
let ip = match ip_s.parse::<smoltcp::wire::Ipv6Address>() {
Ok(v) => v.into(),
Err(_) => {
return Err(format!("Bad IP address component: '{}'", ip_s));
return Err(format!("Bad IP address component: '{ip_s}'"));
}
};

let prefix_len = match prefix_s.parse::<u8>() {
Ok(v) => v,
Err(e) => {
return Err(format!("bad prefix length: {}", e));
return Err(format!("bad prefix length: {e}"));
}
};

Expand Down Expand Up @@ -1128,7 +1128,7 @@ impl Ipv6PrefixLen {

pub fn new(prefix_len: u8) -> result::Result<Self, String> {
if prefix_len > 128 {
return Err(format!("bad IPv6 prefix length: {}", prefix_len));
return Err(format!("bad IPv6 prefix length: {prefix_len}"));
}

Ok(Self(prefix_len))
Expand Down
8 changes: 4 additions & 4 deletions crates/opte-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

// Copyright 2024 Oxide Computer Company
// Copyright 2025 Oxide Computer Company

#![no_std]
#![deny(unreachable_patterns)]
Expand Down Expand Up @@ -51,7 +51,7 @@ pub use ulp::*;
///
/// We rely on CI and the check-api-version.sh script to verify that
/// this number is incremented anytime the oxide-api code changes.
pub const API_VERSION: u64 = 36;
pub const API_VERSION: u64 = 37;

/// Major version of the OPTE package.
pub const MAJOR_VERSION: u64 = 0;
Expand All @@ -69,7 +69,7 @@ impl core::str::FromStr for Direction {
match s.to_ascii_lowercase().as_str() {
"in" => Ok(Direction::In),
"out" => Ok(Direction::Out),
_ => Err(format!("invalid direction: {}", s)),
_ => Err(format!("invalid direction: {s}")),
}
}
}
Expand All @@ -81,7 +81,7 @@ impl Display for Direction {
Direction::Out => "OUT",
};

write!(f, "{}", dirstr)
write!(f, "{dirstr}")
}
}

Expand Down
7 changes: 3 additions & 4 deletions crates/opte-api/src/mac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

// Copyright 2024 Oxide Computer Company
// Copyright 2025 Oxide Computer Company

use alloc::str::FromStr;
use alloc::string::String;
Expand Down Expand Up @@ -95,8 +95,7 @@ impl FromStr for MacAddr {
let octets: Vec<u8> = s
.split(':')
.map(|s| {
u8::from_str_radix(s, 16)
.map_err(|_| format!("bad octet: {}", s))
u8::from_str_radix(s, 16).map_err(|_| format!("bad octet: {s}"))
})
.collect::<Result<Vec<u8>, _>>()?;

Expand Down Expand Up @@ -133,6 +132,6 @@ impl Display for MacAddr {
// present it in a human-friendly manner.
impl Debug for MacAddr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "MacAddr {{ inner: {} }}", self)
write!(f, "MacAddr {{ inner: {self} }}")
}
}
2 changes: 1 addition & 1 deletion crates/opte-api/src/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ impl Display for TcpState {
TcpState::FinWait2 => "FIN_WAIT_2",
TcpState::TimeWait => "TIME_WAIT",
};
write!(f, "{}", s)
write!(f, "{s}")
}
}
2 changes: 1 addition & 1 deletion lib/opte-ioctl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ where
libc::EPERM => "permission denied".to_string(),

errno => {
format!("unexpected errno: {}", errno)
format!("unexpected errno: {errno}")
}
};

Expand Down
4 changes: 2 additions & 2 deletions lib/opte-test-utils/src/pcap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::io::Write;
fn get_header(offset: &[u8]) -> (&[u8], PcapHeader) {
match pcap::parse_pcap_header(offset) {
Ok((new_offset, header)) => (new_offset, header),
Err(e) => panic!("failed to get header: {:?}", e),
Err(e) => panic!("failed to get header: {e:?}"),
}
}

Expand All @@ -32,7 +32,7 @@ fn next_block(offset: &[u8]) -> (&[u8], LegacyPcapBlock) {
(new_offset, block)
}

Err(e) => panic!("failed to get next block: {:?}", e),
Err(e) => panic!("failed to get next block: {e:?}"),
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/opte/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repository.workspace = true

[features]
default = ["api", "std"]
api = []
api = ["dep:zerocopy"]
engine = [
"api",
"dep:cfg-if",
Expand Down
Loading