summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-03-22 15:48:13 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-03-22 15:48:13 +0000
commit0418d346c5343d4b55d580dc9fd66cd2a150a0c3 (patch)
treea6004e6b4b155982917caacbc3e3bf38f902deb2 /src
parentfdc5b834b6c93a9c8b459e48be7dfc6965a77112 (diff)
parent3be575a7a1ca14ebcec43fdee6dba836cedcfae1 (diff)
downloadnix-0418d346c5343d4b55d580dc9fd66cd2a150a0c3.zip
Merge #873
873: add SO_MARK SetSockOpt for Linux r=asomers a=mcginty SO_MARK allows traffic to be filtered by a "tag" using fwmark (see: https://www.linux.org/docs/man8/tc-fw.html). Tested on Linux as root - the test will skip over when not being run as root, as I noticed a few other tests do this in the suite already.
Diffstat (limited to 'src')
-rw-r--r--src/sys/socket/sockopt.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs
index 424d7557..cbfd9249 100644
--- a/src/sys/socket/sockopt.rs
+++ b/src/sys/socket/sockopt.rs
@@ -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);
/*
*
@@ -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);
+ }
}