aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake McGinty <me@jake.su>2018-04-17 17:17:20 -0700
committerJake McGinty <me@jake.su>2018-04-22 14:08:57 -0700
commit06a34476cc1fffdab6bf11d857506df0a122ba76 (patch)
tree9489cecd8f9a78d3c4b184c5dd8429a7a849529c
parentudp: sendmsg ipv4 pktinfo working (macos) (diff)
downloadwireguard-rs-06a34476cc1fffdab6bf11d857506df0a122ba76.tar.xz
wireguard-rs-06a34476cc1fffdab6bf11d857506df0a122ba76.zip
udp: use nix's setsockopt
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/udp/mod.rs35
3 files changed, 7 insertions, 32 deletions
diff --git a/Cargo.lock b/Cargo.lock
index a6dedf7..772f42c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -650,7 +650,7 @@ dependencies = [
[[package]]
name = "nix"
version = "0.11.0-pre"
-source = "git+https://github.com/mcginty/nix?branch=ipv6-pktinfo#45f2d52f40cef1655d4b6631d9994a964724d449"
+source = "git+https://github.com/mcginty/nix?branch=ipv6-pktinfo#b69ee99536f250978cbb529569e84ad3879f4da8"
dependencies = [
"bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cc 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/Cargo.toml b/Cargo.toml
index aea5708..eb62b15 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -47,7 +47,7 @@ nix = { git = "https://github.com/mcginty/nix", branch = "ipv6-pktinfo"}
mio = "^0.6"
pnet_packet = "^0.21"
snow = { git = "https://github.com/mcginty/snow", features = ["ring-accelerated"], branch = "wireguard" }
-socket2 = { version = "^0.3", features = ["reuseport"] }
+socket2 = "^0.3"
subtle = "^0.5"
tokio-io = "^0.1"
tokio-core = "^0.1"
diff --git a/src/udp/mod.rs b/src/udp/mod.rs
index 1c79750..01303af 100644
--- a/src/udp/mod.rs
+++ b/src/udp/mod.rs
@@ -19,7 +19,9 @@ use nix::sys::{uio::IoVec,
MsgFlags,
SockAddr,
recvmsg,
- sendmsg
+ sendmsg,
+ setsockopt,
+ sockopt
}};
use socket2::{Socket, Domain, Type, Protocol};
@@ -75,11 +77,6 @@ impl From<SocketAddr> for Endpoint {
}
}
-// TODO: support linux
-/// IPV6_RECVPKTINFO is missing from the libc crate. Value taken from https://git.io/vxNel.
-pub const IPV6_RECVPKTINFO : i32 = 61;
-pub const IP_PKTINFO : i32 = 26;
-
#[derive(Clone, Copy, Debug)]
pub enum PktInfo {
V4(in_pktinfo),
@@ -91,30 +88,8 @@ impl UdpSocket {
let socket4 = Socket::new(Domain::ipv4(), Type::dgram(), Some(Protocol::udp()))?;
let socket6 = Socket::new(Domain::ipv6(), Type::dgram(), Some(Protocol::udp()))?;
- let on: libc::c_int = 1;
- unsafe {
- let ret = libc::setsockopt(socket4.as_raw_fd(),
- libc::IPPROTO_IP,
- IP_PKTINFO,
- &on as *const _ as *const libc::c_void,
- mem::size_of_val(&on) as libc::socklen_t);
- if ret != 0 {
- let err: Result<(), _> = Err(io::Error::last_os_error());
- err.expect("setsockopt IP_PKTINFO failed");
- }
- }
-
- unsafe {
- let ret = libc::setsockopt(socket6.as_raw_fd(),
- libc::IPPROTO_IPV6,
- IPV6_RECVPKTINFO,
- &on as *const _ as *const libc::c_void,
- mem::size_of_val(&on) as libc::socklen_t);
- if ret != 0 {
- let err: Result<(), _> = Err(io::Error::last_os_error());
- err.expect("setsockopt IPV6_RECVPKTINFO failed");
- }
- }
+ setsockopt(socket4.as_raw_fd(), sockopt::Ipv4PacketInfo, &true);
+ setsockopt(socket6.as_raw_fd(), sockopt::Ipv6RecvPacketInfo, &true);
socket4.set_nonblocking(true)?;
socket4.set_reuse_address(true)?;