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 21, 2018
1 parent fdc5b83 commit 3be575a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]

### Added
- Added `SO_MARK` on Linux.
- ([#873](https://github.com/nix-rust/nix/pull/873))
- Added `getsid` in `::nix::unistd`
([#850](https://github.com/nix-rust/nix/pull/850))
- Added `alarm`. ([#830](https://github.com/nix-rust/nix/pull/830))
Expand Down
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 3be575a

Please sign in to comment.