Skip to content

Commit 6e60901

Browse files
committed
Merge branch 'add-socket-pair-builtin' into combined
2 parents 3fbd815 + 03c68ce commit 6e60901

3 files changed

Lines changed: 43 additions & 2 deletions

File tree

src/builtins/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ pub mod user_id;
170170
pub use self::{
171171
basic::BasicCapabilities,
172172
kill::Kill,
173-
network::{Netlink, Networking},
173+
network::{Netlink, Networking, SocketPair},
174174
systemio::SystemIO,
175175
time::Time,
176176
truncate::Truncate,

src/builtins/network/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Contains a [`RuleSet`] for allowing networking-related syscalls.
22
33
pub mod netlink;
4+
pub mod socket_pair;
45

56
use {
67
super::YesReally,
@@ -9,7 +10,7 @@ use {
910
syscalls::Sysno,
1011
};
1112

12-
pub use self::netlink::Netlink;
13+
pub use self::{netlink::Netlink, socket_pair::SocketPair};
1314

1415
// TODO: make bind calls conditional on the DGRAM/UNIX/STREAM flag in each function
1516

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//! Allow `sys_socketpair`.
2+
3+
use {crate::RuleSet, syscalls::Sysno};
4+
5+
/// Allow the syscall `socketpair` to create a pair of connected sockets.
6+
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq, PartialOrd)]
7+
#[must_use]
8+
pub struct SocketPair;
9+
10+
impl RuleSet for SocketPair {
11+
fn simple_rules(&self) -> Vec<Sysno> {
12+
Vec::from([Sysno::socketpair])
13+
}
14+
15+
fn name(&self) -> &'static str {
16+
"SocketPair"
17+
}
18+
}
19+
20+
#[cfg(test)]
21+
mod tests {
22+
use {super::SocketPair, crate::RuleSet as _, syscalls::Sysno};
23+
24+
#[test]
25+
fn name() {
26+
assert_eq!(SocketPair.name(), "SocketPair");
27+
}
28+
29+
#[test]
30+
fn simple_rules() {
31+
let rules = SocketPair.simple_rules();
32+
assert_eq!(rules.len(), 1);
33+
assert!(rules.contains(&Sysno::socketpair));
34+
}
35+
36+
#[test]
37+
fn conditional_rules() {
38+
assert!(SocketPair.conditional_rules().is_empty());
39+
}
40+
}

0 commit comments

Comments
 (0)