-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add support of freebsd #3
Comments
you mean, just simplely add a tag
|
it appears that the provided patch is not sufficient. Let's keep it open for the future improvement.
|
This patch is sufficient to build narrowlink. |
I think there are multiple minor changes that are required to get this working:
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
pub mod linux;
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
pub use self::linux::{create, Configuration, Device, Queue};
[target.'cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos", target_os = "android"))'.dependencies]
ioctl = { version = "0.8", package = "ioctl-sys" } In the initial comment by @ssrlive, the Could you try this again with the suggested changes? I do not have a FreeBSD VM available to me at the moment. |
|
Since we have replaced
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
pub mod linux;
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
pub use self::linux::{create, Device, PlatformConfig};
[target.'cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos", target_os = "android"))'.dependencies]
nix = { version = "0.27", features = ["ioctl"] } If it works, I think changing the name of the module |
emm. sounds good. |
@xmh0511: FreeBSD uses slightly different APIs. I believe https://github.com/LaKabane/libtuntap/blob/master/tuntap-unix-freebsd.c could be inspiring for implementation. root@freebsd:/home/test/rust-tun # git diff
diff --git a/Cargo.toml b/Cargo.toml
index be374c1..79eb3c8 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -27,7 +27,7 @@ tokio = { version = "1", features = [
], optional = true }
tokio-util = { version = "0.7", features = ["codec"], optional = true }
-[target.'cfg(any(target_os = "linux", target_os = "macos", target_os = "android"))'.dependencies]
+[target.'cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos", target_os = "android"))'.dependencies]
nix = { version = "0.27", features = ["ioctl"] }
[target.'cfg(target_os = "windows")'.dependencies]
diff --git a/src/platform/mod.rs b/src/platform/mod.rs
index 7bb628d..ac175ab 100644
--- a/src/platform/mod.rs
+++ b/src/platform/mod.rs
@@ -17,9 +17,9 @@
#[cfg(unix)]
pub mod posix;
-#[cfg(target_os = "linux")]
+#[cfg(any(target_os = "linux", target_os = "freebsd"))]
pub mod linux;
-#[cfg(target_os = "linux")]
+#[cfg(any(target_os = "linux", target_os = "freebsd"))]
pub use self::linux::{create, Device, PlatformConfig};
#[cfg(target_os = "macos")]
root@freebsd:/home/test/rust-tun # cargo check
Checking tun2 v1.1.1 (/home/test/rust-tun)
error[E0432]: unresolved imports `libc::IFF_MULTI_QUEUE`, `libc::IFF_NO_PI`, `libc::IFF_TAP`, `libc::IFF_TUN`
--> src/platform/linux/device.rs:16:44
|
16 | self, c_char, c_short, ifreq, AF_INET, IFF_MULTI_QUEUE, IFF_NO_PI, IFF_RUNNING, IFF_TAP,
| ^^^^^^^^^^^^^^^ ^^^^^^^^^ ^^^^^^^ no `IFF_TAP` in the root
| | |
| | no `IFF_NO_PI` in the root
| no `IFF_MULTI_QUEUE` in the root
17 | IFF_TUN, IFF_UP, IFNAMSIZ, O_RDWR, SOCK_DGRAM,
| ^^^^^^^ no `IFF_TUN` in the root
|
help: a similar name exists in the module
|
16 | self, c_char, c_short, ifreq, AF_INET, IFF_MULTI_QUEUE, IFF_NOARP, IFF_RUNNING, IFF_TAP,
| ~~~~~~~~~
help: a similar name exists in the module
|
16 | self, c_char, c_short, ifreq, AF_INET, IFF_MULTI_QUEUE, IFF_NO_PI, IFF_RUNNING, IFF_UP,
| ~~~~~~
help: a similar name exists in the module
|
17 | IFF_UP, IFF_UP, IFNAMSIZ, O_RDWR, SOCK_DGRAM,
| ~~~~~~
error[E0425]: cannot find value `TUN_PROTO_IP6` in this scope
--> src/platform/posix/split.rs:52:25
|
52 | return Some(TUN_PROTO_IP6);
| ^^^^^^^^^^^^^ not found in this scope
error[E0425]: cannot find value `TUN_PROTO_IP4` in this scope
--> src/platform/posix/split.rs:54:25
|
54 | return Some(TUN_PROTO_IP4);
| ^^^^^^^^^^^^^ not found in this scope
error[E0308]: mismatched types
--> src/platform/linux/device.rs:94:39
|
94 | req.ifr_ifru.ifru_flags = device_type
| _____________-----------------------___^
| | |
| | expected due to the type of this binding
95 | | | if packet_information { 0 } else { iff_no_pi }
96 | | | if queues_num > 1 { iff_multi_queue } else { 0 };
| |__________________________________________________________________^ expected `[i16; 2]`, found `i16`
error[E0609]: no field `ifru_newname` on type `__c_anonymous_ifr_ifru`
--> src/platform/linux/device.rs:227:30
|
227 | req.ifr_ifru.ifru_newname.as_mut_ptr(),
| ^^^^^^^^^^^^ unknown field
|
= note: available fields are: `ifru_addr`, `ifru_dstaddr`, `ifru_broadaddr`, `ifru_buffer`, `ifru_flags` ... and 10 others
error[E0368]: binary assignment operation `|=` cannot be applied to type `[i16; 2]`
--> src/platform/linux/device.rs:250:17
|
250 | req.ifr_ifru.ifru_flags |= (IFF_UP | IFF_RUNNING) as c_short;
| -----------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| cannot use `|=` on type `[i16; 2]`
error[E0368]: binary assignment operation `&=` cannot be applied to type `[i16; 2]`
--> src/platform/linux/device.rs:252:17
|
252 | req.ifr_ifru.ifru_flags &= !(IFF_UP as c_short);
| -----------------------^^^^^^^^^^^^^^^^^^^^^^^^
| |
| cannot use `&=` on type `[i16; 2]`
error[E0609]: no field `ifru_netmask` on type `__c_anonymous_ifr_ifru`
--> src/platform/linux/device.rs:362:45
|
362 | SockAddr::new(&req.ifr_ifru.ifru_netmask).map(Into::into)?,
| ^^^^^^^^^^^^ unknown field
|
= note: available fields are: `ifru_addr`, `ifru_dstaddr`, `ifru_broadaddr`, `ifru_buffer`, `ifru_flags` ... and 10 others
error[E0609]: no field `ifru_netmask` on type `__c_anonymous_ifr_ifru`
--> src/platform/linux/device.rs:373:26
|
373 | req.ifr_ifru.ifru_netmask = SockAddr::from(value).into();
| ^^^^^^^^^^^^ unknown field
|
= note: available fields are: `ifru_addr`, `ifru_dstaddr`, `ifru_broadaddr`, `ifru_buffer`, `ifru_flags` ... and 10 others
Some errors have detailed explanations: E0308, E0368, E0425, E0432, E0609.
For more information about an error, try `rustc --explain E0308`.
error: could not compile `tun2` (lib) due to 9 previous errors
I am a bit busy with the investigation, but I have some plans to execute. |
For |
@SajjadPourali I searched the imported names in Do you try to update the dependencies and test them? |
@SajjadPourali @yurivict @M0dEx @ssrlive This PR #51 prepares to fix this issue, which has made The generated Reference: https://github.com/osmocom/openggsn/blob/master/lib/tun.c |
@xmh0511 I think in freebsd we should call http://dostf.blogspot.com/2010/10/programmatic-interface-alias-creation.html |
I tried this scheme. However, it still cannot work
|
Seems a relevant issue https://wiki.strongswan.org/issues/566 |
The relevant resolution is http://fxr.watson.org/fxr/source/netinet/in_var.h?v=FREEBSD-13-STABLE;im=bigexc, and using https://svnweb.freebsd.org/base/head/sbin/ifconfig/ifconfig.c?revision=281143&view=markup#l1012 |
Now, |
I found that the created tun interface remains in the resulting list of running the command Any enhancement to this "issue" is appreciated. |
Based on the patch provided by @yurivict for 'tun', it appears that FreeBSD and Linux APIs are the same. We just need to add FreeBSD to the target lists in the platform module. For more information, refer to this link
The text was updated successfully, but these errors were encountered: