Skip to content

Commit 0418d34

Browse files
committed
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.
2 parents fdc5b83 + 3be575a commit 0418d34

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
66
## [Unreleased]
77

88
### Added
9+
- Added `SO_MARK` on Linux.
10+
- ([#873](https://github.com/nix-rust/nix/pull/873))
911
- Added `getsid` in `::nix::unistd`
1012
([#850](https://github.com/nix-rust/nix/pull/850))
1113
- Added `alarm`. ([#830](https://github.com/nix-rust/nix/pull/830))

src/sys/socket/sockopt.rs

+22
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ sockopt_impl!(Both, IpTransparent, libc::SOL_IP, libc::IP_TRANSPARENT, bool);
253253
sockopt_impl!(Both, BindAny, libc::SOL_SOCKET, libc::SO_BINDANY, bool);
254254
#[cfg(target_os = "freebsd")]
255255
sockopt_impl!(Both, BindAny, libc::IPPROTO_IP, libc::IP_BINDANY, bool);
256+
#[cfg(target_os = "linux")]
257+
sockopt_impl!(Both, Mark, libc::SOL_SOCKET, libc::SO_MARK, u32);
256258

257259
/*
258260
*
@@ -527,4 +529,24 @@ mod test {
527529
assert!(s_listening2);
528530
close(s).unwrap();
529531
}
532+
533+
#[cfg(target_os = "linux")]
534+
#[test]
535+
fn is_so_mark_functional() {
536+
use super::super::*;
537+
use ::unistd::Uid;
538+
use ::std::io::{self, Write};
539+
540+
if !Uid::current().is_root() {
541+
let stderr = io::stderr();
542+
let mut handle = stderr.lock();
543+
writeln!(handle, "SO_MARK requires root privileges. Skipping test.").unwrap();
544+
return;
545+
}
546+
547+
let s = socket(AddressFamily::Inet, SockType::Stream, SockFlag::empty(), None).unwrap();
548+
setsockopt(s, super::Mark, &1337).unwrap();
549+
let mark = getsockopt(s, super::Mark).unwrap();
550+
assert_eq!(mark, 1337);
551+
}
530552
}

0 commit comments

Comments
 (0)