Implement Wireguard

Implements Wireguard
This commit is contained in:
Jett Chen 2023-12-17 01:20:56 +08:00 committed by Conrad Kramer
parent 60257b256a
commit b008762a5b
59 changed files with 3824 additions and 529 deletions

View file

@ -1,18 +1,21 @@
use std::{
fs::OpenOptions,
io::{Error, Write},
mem,
net::{Ipv4Addr, Ipv6Addr, SocketAddrV4},
os::{
fd::RawFd,
unix::io::{AsRawFd, FromRawFd, IntoRawFd},
},
};
use fehler::throws;
use libc::in6_ifreq;
use socket2::{Domain, SockAddr, Socket, Type};
use std::fs::OpenOptions;
use std::io::{Error, Write};
use std::mem;
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddrV4};
use std::os::fd::RawFd;
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd};
use tracing::{info, instrument};
use libc::in6_ifreq;
use super::{ifname_to_string, string_to_ifname, TunOptions};
use super::{ifname_to_string, string_to_ifname};
use crate::TunOptions;
mod sys;
@ -38,10 +41,10 @@ impl TunInterface {
let mut flags = libc::IFF_TUN as i16;
if options.no_pi.is_some() {
if options.no_pi {
flags |= libc::IFF_NO_PI as i16;
}
if options.tun_excl.is_some() {
if options.tun_excl {
flags |= libc::IFF_TUN_EXCL as i16;
}

View file

@ -1,10 +1,7 @@
use nix::{ioctl_read_bad, ioctl_write_ptr_bad, request_code_read, request_code_write};
use std::mem::size_of;
pub use libc::ifreq;
pub use libc::sockaddr;
pub use libc::sockaddr_in;
pub use libc::sockaddr_in6;
pub use libc::{ifreq, sockaddr, sockaddr_in, sockaddr_in6};
use nix::{ioctl_read_bad, ioctl_write_ptr_bad, request_code_read, request_code_write};
ioctl_write_ptr_bad!(
tun_set_iff,