Skip to content

FreeBSD support #49

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

Merged
merged 3 commits into from
Feb 1, 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
5 changes: 5 additions & 0 deletions examples/add_netns.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
// SPDX-License-Identifier: MIT

#[cfg(not(target_os = "freebsd"))]
use rtnetlink::NetworkNamespace;
use std::env;

#[cfg(target_os = "freebsd")]
fn main() -> () {}

#[cfg(not(target_os = "freebsd"))]
#[tokio::main]
async fn main() -> Result<(), String> {
env_logger::init();
Expand Down
5 changes: 5 additions & 0 deletions examples/add_netns_async.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
// SPDX-License-Identifier: MIT

#[cfg(not(target_os = "freebsd"))]
use rtnetlink::NetworkNamespace;
use std::env;

#[cfg(target_os = "freebsd")]
fn main() -> () {}

#[cfg(not(target_os = "freebsd"))]
#[async_std::main]
async fn main() -> Result<(), String> {
env_logger::init();
Expand Down
4 changes: 4 additions & 0 deletions examples/add_tc_qdisc_ingress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ use std::env;

use rtnetlink::new_connection;

#[cfg(target_os = "freebsd")]
fn main() -> () {}

#[cfg(not(target_os = "freebsd"))]
#[tokio::main]
async fn main() -> Result<(), ()> {
env_logger::init();
Expand Down
5 changes: 5 additions & 0 deletions examples/del_netns.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
// SPDX-License-Identifier: MIT

#[cfg(not(target_os = "freebsd"))]
use rtnetlink::NetworkNamespace;
use std::env;

#[cfg(target_os = "freebsd")]
fn main() -> () {}

#[cfg(not(target_os = "freebsd"))]
#[tokio::main]
async fn main() -> Result<(), String> {
let args: Vec<String> = env::args().collect();
Expand Down
5 changes: 5 additions & 0 deletions examples/del_netns_async.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
// SPDX-License-Identifier: MIT

#[cfg(not(target_os = "freebsd"))]
use rtnetlink::NetworkNamespace;
use std::env;

#[cfg(target_os = "freebsd")]
fn main() -> () {}

#[cfg(not(target_os = "freebsd"))]
#[async_std::main]
async fn main() -> Result<(), String> {
let args: Vec<String> = env::args().collect();
Expand Down
5 changes: 5 additions & 0 deletions examples/get_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ use netlink_packet_route::{
};
use rtnetlink::{new_connection, Error, Handle};

#[cfg(target_os = "freebsd")]
fn main() -> () {}

#[cfg(not(target_os = "freebsd"))]
#[tokio::main]
async fn main() -> Result<(), ()> {
env_logger::init();
Expand Down Expand Up @@ -90,6 +94,7 @@ async fn dump_links(handle: Handle) -> Result<(), Error> {
Ok(())
}

#[cfg(not(target_os = "freebsd"))]
async fn dump_bridge_filter_info(handle: Handle) -> Result<(), Error> {
let mut links = handle
.link()
Expand Down
5 changes: 5 additions & 0 deletions examples/get_links_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ use netlink_packet_route::{
};
use rtnetlink::{new_connection, Error, Handle};

#[cfg(target_os = "freebsd")]
fn main() -> () {}

#[cfg(not(target_os = "freebsd"))]
#[async_std::main]
async fn main() -> Result<(), ()> {
env_logger::init();
Expand Down Expand Up @@ -90,6 +94,7 @@ async fn dump_links(handle: Handle) -> Result<(), Error> {
Ok(())
}

#[cfg(not(target_os = "freebsd"))]
async fn dump_bridge_filter_info(handle: Handle) -> Result<(), Error> {
let mut links = handle
.link()
Expand Down
10 changes: 9 additions & 1 deletion examples/get_links_thread_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ use netlink_packet_route::{
link::{LinkAttribute, LinkExtentMask},
AddressFamily,
};
use rtnetlink::{new_connection, Error, Handle};
#[cfg(not(target_os = "freebsd"))]
use rtnetlink::new_connection;
use rtnetlink::{Error, Handle};

#[cfg(not(target_os = "freebsd"))]
async fn do_it(rt: &tokio::runtime::Runtime) -> Result<(), ()> {
env_logger::init();
let (connection, handle, _) = new_connection().unwrap();
Expand Down Expand Up @@ -89,6 +92,7 @@ async fn dump_links(handle: Handle) -> Result<(), Error> {
Ok(())
}

#[cfg(not(target_os = "freebsd"))]
async fn dump_bridge_filter_info(handle: Handle) -> Result<(), Error> {
let mut links = handle
.link()
Expand All @@ -109,6 +113,10 @@ async fn dump_bridge_filter_info(handle: Handle) -> Result<(), Error> {
Ok(())
}

#[cfg(target_os = "freebsd")]
fn main() -> () {}

#[cfg(not(target_os = "freebsd"))]
fn main() -> Result<(), String> {
let rt = tokio::runtime::Builder::new_multi_thread()
.enable_io()
Expand Down
12 changes: 9 additions & 3 deletions src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ use netlink_packet_route::RouteNetlinkMessage;
use netlink_proto::{sys::SocketAddr, ConnectionHandle};

use crate::{
AddressHandle, Error, LinkHandle, NeighbourHandle, QDiscHandle,
RouteHandle, RuleHandle, TrafficChainHandle, TrafficClassHandle,
TrafficFilterHandle,
AddressHandle, Error, LinkHandle, NeighbourHandle, RouteHandle, RuleHandle,
};
#[cfg(not(target_os = "freebsd"))]
use crate::{
QDiscHandle, TrafficChainHandle, TrafficClassHandle, TrafficFilterHandle,
};

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -71,24 +73,28 @@ impl Handle {

/// Create a new handle, specifically for traffic control qdisc requests
/// (equivalent to `tc qdisc show` commands)
#[cfg(not(target_os = "freebsd"))]
pub fn qdisc(&self) -> QDiscHandle {
QDiscHandle::new(self.clone())
}

/// Create a new handle, specifically for traffic control class requests
/// (equivalent to `tc class show dev <interface_name>` commands)
#[cfg(not(target_os = "freebsd"))]
pub fn traffic_class(&self, ifindex: i32) -> TrafficClassHandle {
TrafficClassHandle::new(self.clone(), ifindex)
}

/// Create a new handle, specifically for traffic control filter requests
/// (equivalent to `tc filter show dev <interface_name>` commands)
#[cfg(not(target_os = "freebsd"))]
pub fn traffic_filter(&self, ifindex: i32) -> TrafficFilterHandle {
TrafficFilterHandle::new(self.clone(), ifindex)
}

/// Create a new handle, specifically for traffic control chain requests
/// (equivalent to `tc chain show dev <interface_name>` commands)
#[cfg(not(target_os = "freebsd"))]
pub fn traffic_chain(&self, ifindex: i32) -> TrafficChainHandle {
TrafficChainHandle::new(self.clone(), ifindex)
}
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
mod handle;
pub use crate::handle::*;

#[cfg(not(target_os = "freebsd"))]
mod ns;
#[cfg(not(target_os = "freebsd"))]
pub use crate::ns::*;

mod errors;
Expand All @@ -29,7 +31,9 @@ pub use crate::rule::*;
mod connection;
pub use crate::connection::*;

#[cfg(not(target_os = "freebsd"))]
mod traffic_control;
#[cfg(not(target_os = "freebsd"))]
pub use crate::traffic_control::*;

mod neighbour;
Expand Down
1 change: 1 addition & 0 deletions src/neighbour/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ impl NeighbourAddRequest {
}
}

#[cfg(not(target_os = "freebsd"))]
pub(crate) fn new_bridge(handle: Handle, index: u32, lla: &[u8]) -> Self {
let mut message = NeighbourMessage::default();

Expand Down
1 change: 1 addition & 0 deletions src/neighbour/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ impl NeighbourHandle {
NeighbourAddRequest::new(self.0.clone(), index, destination)
}

#[cfg(not(target_os = "freebsd"))]
/// Add a new fdb entry (equivalent to `bridge fdb add`)
pub fn add_bridge(&self, index: u32, lla: &[u8]) -> NeighbourAddRequest {
NeighbourAddRequest::new_bridge(self.0.clone(), index, lla)
Expand Down