Skip to content

Commit

Permalink
add SO_MARK SetSockOpt for Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
mcginty committed Mar 8, 2018
1 parent ad624c8 commit 3621ff6
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/sys/socket/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ sockopt_impl!(Both, IpTransparent, libc::SOL_IP, libc::IP_TRANSPARENT, bool);
sockopt_impl!(Both, BindAny, libc::SOL_SOCKET, libc::SO_BINDANY, bool);
#[cfg(target_os = "freebsd")]
sockopt_impl!(Both, BindAny, libc::IPPROTO_IP, libc::IP_BINDANY, bool);
#[cfg(target_os = "linux")]
sockopt_impl!(Both, Mark, libc::SOL_SOCKET, libc::SO_MARK, u32);

/*
*
Expand Down Expand Up @@ -527,4 +529,24 @@ mod test {
assert!(s_listening2);
close(s).unwrap();
}

#[cfg(target_os = "linux")]
#[test]
fn is_so_mark_functional() {
use super::super::*;
use ::unistd::Uid;
use ::std::io::{self, Write};

if !Uid::current().is_root() {
let stderr = io::stderr();
let mut handle = stderr.lock();
writeln!(handle, "SO_MARK requires root privileges. Skipping test.").unwrap();
return;
}

let s = socket(AddressFamily::Inet, SockType::Stream, SockFlag::empty(), None).unwrap();
setsockopt(s, super::Mark, &1337).unwrap();
let mark = getsockopt(s, super::Mark).unwrap();
assert_eq!(mark, 1337);
}
}

0 comments on commit 3621ff6

Please sign in to comment.