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

Freebsd #51

Merged
merged 161 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
161 commits
Select commit Hold shift + click to select a range
2ed17dd
migrate to ipnet
xmh0511 Feb 6, 2024
6044ed6
Merge branch 'ssrlive:v2' into v2
xmh0511 Feb 6, 2024
b6463ff
bump version
xmh0511 Feb 6, 2024
88f0010
update
xmh0511 Feb 28, 2024
409ac38
Merge branch 'ssrlive:v2' into v2
xmh0511 Feb 29, 2024
6fc3c1e
freebsd
xmh0511 Feb 29, 2024
e90e0fa
update
xmh0511 Feb 29, 2024
30d226a
update
xmh0511 Feb 29, 2024
06d54e8
update
xmh0511 Feb 29, 2024
53e86fa
update
xmh0511 Feb 29, 2024
d4d8bcb
update
xmh0511 Feb 29, 2024
f55455b
update
xmh0511 Feb 29, 2024
5ab648f
update
xmh0511 Feb 29, 2024
d801d7c
update
xmh0511 Feb 29, 2024
5dcdd32
update
xmh0511 Feb 29, 2024
ef44fdc
update
xmh0511 Feb 29, 2024
19010d3
update
xmh0511 Feb 29, 2024
6314752
update
xmh0511 Feb 29, 2024
2c09799
update
xmh0511 Feb 29, 2024
7eb6268
update
xmh0511 Feb 29, 2024
b022645
cargo fmt
xmh0511 Feb 29, 2024
d56abc1
update
xmh0511 Feb 29, 2024
7315cb3
update
xmh0511 Feb 29, 2024
7b25559
update
xmh0511 Feb 29, 2024
bd56df7
update
xmh0511 Feb 29, 2024
e568b50
update
xmh0511 Feb 29, 2024
19670f6
update
xmh0511 Feb 29, 2024
1d2264a
update
xmh0511 Feb 29, 2024
cfdb689
update
xmh0511 Feb 29, 2024
ec8316f
update
xmh0511 Feb 29, 2024
66035ef
update
xmh0511 Feb 29, 2024
69d0491
update
xmh0511 Feb 29, 2024
9c66b2d
update
xmh0511 Feb 29, 2024
0b209cf
update
xmh0511 Feb 29, 2024
f7b9b5b
update
xmh0511 Feb 29, 2024
f02f4a9
update
xmh0511 Feb 29, 2024
1c29d33
update
xmh0511 Feb 29, 2024
d3551d0
update
xmh0511 Feb 29, 2024
7ac1c7e
update
xmh0511 Feb 29, 2024
365529c
update
xmh0511 Feb 29, 2024
698f322
update
xmh0511 Feb 29, 2024
e2638fa
update
xmh0511 Feb 29, 2024
92d2921
update
xmh0511 Feb 29, 2024
83584d4
update
xmh0511 Feb 29, 2024
15b1b6c
update
xmh0511 Feb 29, 2024
1d16f02
update
xmh0511 Feb 29, 2024
8a46983
update
xmh0511 Feb 29, 2024
f21d636
cargo fmt
xmh0511 Feb 29, 2024
7e5ff14
update
xmh0511 Feb 29, 2024
9302121
update
xmh0511 Feb 29, 2024
5ca4ed8
update
xmh0511 Feb 29, 2024
f0ba5a9
update
xmh0511 Feb 29, 2024
046d5e2
update
xmh0511 Feb 29, 2024
9c6479f
update
xmh0511 Feb 29, 2024
acffe2a
update
xmh0511 Feb 29, 2024
ee473c6
update
xmh0511 Feb 29, 2024
a042dcc
update
xmh0511 Feb 29, 2024
66c3555
update
xmh0511 Feb 29, 2024
dec8227
update
xmh0511 Feb 29, 2024
118c076
update
xmh0511 Feb 29, 2024
3e4cb50
update
xmh0511 Feb 29, 2024
6f157a9
update
xmh0511 Feb 29, 2024
f87c1ac
update
xmh0511 Feb 29, 2024
69cf356
update
xmh0511 Feb 29, 2024
9ee0b0e
update
xmh0511 Feb 29, 2024
ab5aac0
update
xmh0511 Feb 29, 2024
e347299
update
xmh0511 Feb 29, 2024
9f18434
update
xmh0511 Feb 29, 2024
52b26b3
update
xmh0511 Feb 29, 2024
08e5bc7
update
xmh0511 Feb 29, 2024
97e52b3
update
xmh0511 Feb 29, 2024
69c9bbc
update
xmh0511 Feb 29, 2024
5edb7d9
update
xmh0511 Feb 29, 2024
1179c7e
update
xmh0511 Feb 29, 2024
a32d00a
fix ioctrl inappropriate issue
xmh0511 Feb 29, 2024
f4abdb8
update
xmh0511 Feb 29, 2024
6569b5b
update
xmh0511 Feb 29, 2024
82e5364
update
xmh0511 Mar 1, 2024
bca16c1
update
xmh0511 Mar 1, 2024
fc7fa4d
update
xmh0511 Mar 1, 2024
cc7ae37
update
xmh0511 Mar 1, 2024
ea7e4ad
update
xmh0511 Mar 1, 2024
bd29d49
update
xmh0511 Mar 1, 2024
d08b40f
update
xmh0511 Mar 1, 2024
f36b72a
update
xmh0511 Mar 1, 2024
7d77ba4
update
xmh0511 Mar 1, 2024
2ee347d
update
xmh0511 Mar 1, 2024
fa89d48
update
xmh0511 Mar 1, 2024
7b201b4
update
xmh0511 Mar 1, 2024
a61d3e5
update
xmh0511 Mar 1, 2024
676aca6
update
xmh0511 Mar 1, 2024
1517996
update
xmh0511 Mar 1, 2024
9eedeef
update
xmh0511 Mar 1, 2024
31331ed
update
xmh0511 Mar 1, 2024
1e46099
update
xmh0511 Mar 1, 2024
df60753
update
xmh0511 Mar 1, 2024
2ce3c34
update
xmh0511 Mar 1, 2024
5025a53
update
xmh0511 Mar 1, 2024
1e63a11
update
xmh0511 Mar 1, 2024
fdc4ffe
update
xmh0511 Mar 1, 2024
1833457
update
xmh0511 Mar 1, 2024
e36f44e
update
xmh0511 Mar 1, 2024
0dfdd3c
update
xmh0511 Mar 1, 2024
75c9d7a
update
xmh0511 Mar 1, 2024
4abad71
update
xmh0511 Mar 1, 2024
aef01bd
update
xmh0511 Mar 1, 2024
cb494b4
update
xmh0511 Mar 1, 2024
0fc3ebd
update
xmh0511 Mar 1, 2024
9f6723b
update
xmh0511 Mar 1, 2024
44d2ed6
update
xmh0511 Mar 1, 2024
d55db85
update
xmh0511 Mar 1, 2024
f6c7c6c
update
xmh0511 Mar 1, 2024
b1438d1
update
xmh0511 Mar 1, 2024
94c65a7
update
xmh0511 Mar 1, 2024
2939028
update
xmh0511 Mar 1, 2024
48e5615
update
xmh0511 Mar 1, 2024
2d132aa
update
xmh0511 Mar 1, 2024
30baec8
update
xmh0511 Mar 1, 2024
7d92156
update
xmh0511 Mar 1, 2024
16065e7
update
xmh0511 Mar 1, 2024
76ac7a6
update
xmh0511 Mar 1, 2024
3404a15
update
xmh0511 Mar 1, 2024
d98086d
update
xmh0511 Mar 1, 2024
5ae3ffd
update
xmh0511 Mar 1, 2024
81cb89e
update
xmh0511 Mar 1, 2024
be029eb
update
xmh0511 Mar 1, 2024
5df01aa
update
xmh0511 Mar 1, 2024
8c7c338
update
xmh0511 Mar 1, 2024
6fc409c
update
xmh0511 Mar 1, 2024
25bf2b0
update
xmh0511 Mar 1, 2024
3b4bab4
update
xmh0511 Mar 1, 2024
ddae503
update
xmh0511 Mar 1, 2024
ae2c8a1
update
xmh0511 Mar 1, 2024
5d3cdb1
update
xmh0511 Mar 1, 2024
cd1d480
update
xmh0511 Mar 1, 2024
86c9069
update
xmh0511 Mar 1, 2024
d089e20
update
xmh0511 Mar 1, 2024
47806c6
update
xmh0511 Mar 1, 2024
bbae0f5
update
xmh0511 Mar 1, 2024
a18c019
update
xmh0511 Mar 1, 2024
aa64a98
update
xmh0511 Mar 1, 2024
95f63cf
update
xmh0511 Mar 1, 2024
900c2f2
update
xmh0511 Mar 1, 2024
e5ae92e
update
xmh0511 Mar 1, 2024
0df1790
update
xmh0511 Mar 1, 2024
0c7741c
update
xmh0511 Mar 1, 2024
f1d7427
update
xmh0511 Mar 1, 2024
5e552fa
update
xmh0511 Mar 1, 2024
bfd6bb0
update
xmh0511 Mar 1, 2024
771c294
update
xmh0511 Mar 1, 2024
dcadea9
update
xmh0511 Mar 1, 2024
9114dc8
make freebsd usable
xmh0511 Mar 1, 2024
832843e
make freebsd usable
xmh0511 Mar 1, 2024
48ac075
make freebsd usable
xmh0511 Mar 1, 2024
600131a
update sockaddr
xmh0511 Mar 1, 2024
91f5561
cargo fmt
xmh0511 Mar 1, 2024
a0eeefa
fix ubuntu error
xmh0511 Mar 1, 2024
c393896
github flow
xmh0511 Mar 1, 2024
95f9c59
cargo fmt
xmh0511 Mar 1, 2024
55f098b
add example
xmh0511 Mar 1, 2024
5480f80
cargo fmt
xmh0511 Mar 1, 2024
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ 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 = "macos", target_os = "android", target_os="freebsd"))'.dependencies]
nix = { version = "0.28", features = ["ioctl"] }

[target.'cfg(target_os = "windows")'.dependencies]
wintun = { version = "0.4", features = ["panic_on_unsent_packets"] }

[target.'cfg(target_os = "macos")'.dependencies]
[target.'cfg(any(target_os = "macos", target_os = "freebsd"))'.dependencies]
ipnet = "2"

[dev-dependencies]
Expand Down
104 changes: 104 additions & 0 deletions examples/dev-config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
// Version 2, December 2004
//
// Copyleft (ↄ) meh. <meh@schizofreni.co> | http://meh.schizofreni.co
//
// Everyone is permitted to copy and distribute verbatim or modified
// copies of this license document, and changing it is allowed as long
// as the name is changed.
//
// DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
// TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
//
// 0. You just DO WHAT THE FUCK YOU WANT TO.

use packet::{builder::Builder, icmp, ip, Packet};
use std::io::{Read, Write};
use std::{net::Ipv4Addr, sync::mpsc::Receiver};
use tun2::{AbstractDevice, BoxError};

fn main() -> Result<(), BoxError> {
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("trace")).init();
let (tx, rx) = std::sync::mpsc::channel();

let handle = ctrlc2::set_handler(move || {
tx.send(()).expect("Signal error.");
true
})
.expect("Error setting Ctrl-C handler");

main_entry(rx)?;
handle.join().unwrap();
Ok(())
}

fn main_entry(quit: Receiver<()>) -> Result<(), BoxError> {
let mut config = tun2::Configuration::default();

config
.address((10, 0, 0, 9))
.netmask((255, 255, 255, 0))
.destination((10, 0, 0, 1))
.up();

#[cfg(target_os = "linux")]
config.platform_config(|config| {
config.ensure_root_privileges(true);
});

let mut dev = tun2::create(&config)?;
let r = dev.address()?;
println!("{:?}", r);

let r = dev.destination()?;
println!("{:?}", r);

let r = dev.netmask()?;
println!("{:?}", r);

dev.set_address(std::net::IpAddr::V4(Ipv4Addr::new(10, 0, 0, 20)))?;
dev.set_destination(std::net::IpAddr::V4(Ipv4Addr::new(10, 0, 0, 66)))?;
dev.set_netmask(std::net::IpAddr::V4(Ipv4Addr::new(255, 255, 0, 0)))?;

// let r = dev.broadcast()?;
// println!("{:?}",r);

let mut buf = [0; 4096];

std::thread::spawn(move || {
loop {
let amount = dev.read(&mut buf)?;
let pkt = &buf[0..amount];
match ip::Packet::new(pkt) {
Ok(ip::Packet::V4(pkt)) => {
if let Ok(icmp) = icmp::Packet::new(pkt.payload()) {
if let Ok(icmp) = icmp.echo() {
println!("{:?} - {:?}", icmp.sequence(), pkt.destination());
let reply = ip::v4::Builder::default()
.id(0x42)?
.ttl(64)?
.source(pkt.destination())?
.destination(pkt.source())?
.icmp()?
.echo()?
.reply()?
.identifier(icmp.identifier())?
.sequence(icmp.sequence())?
.payload(icmp.payload())?
.build()?;
let size = dev.write(&reply[..])?;
println!("write {size} len {}", reply.len());
}
}
}
Err(err) => println!("Received an invalid packet: {:?}", err),
_ => {}
}
}
#[allow(unreachable_code)]
Ok::<(), BoxError>(())
});

quit.recv().expect("Quit error.");
Ok(())
}
Loading
Loading