Skip to content

Commit

Permalink
selinux-testsuite: Enhance inet_socket tests
Browse files Browse the repository at this point in the history
Enhance the tests as follows:
1) Determine number of tests to run with current config.
2) Add CALIPSO STREAM tests (DGRAM not supported in kernel. See [1]).
3) Add support for CIPSO TAGS 1 & 2. Closes [2].
4) Run scripts using /bin/sh.
5) Shorten sleep time as more tests.

[1] SELinuxProject/selinux-kernel#24
[2] #1

Signed-off-by: Richard Haines <[email protected]>
[PM: adjusted file permissions on tests/inet_socket/test ]
Signed-off-by: Paul Moore <[email protected]>
  • Loading branch information
Richard Haines authored and pcmoore committed Jun 12, 2018
1 parent 3aaf349 commit 9d7d40a
Show file tree
Hide file tree
Showing 14 changed files with 310 additions and 88 deletions.
5 changes: 5 additions & 0 deletions tests/inet_socket/calipso-flush
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
# Reset NetLabel configuration to unlabeled after CALIPSO/IPv6 tests.
netlabelctl map del default
netlabelctl calipso del doi:16
netlabelctl map add default protocol:unlbl
7 changes: 7 additions & 0 deletions tests/inet_socket/calipso-load
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
# Define a doi for testing loopback for CALIPSO/IPv6.
netlabelctl calipso add pass doi:16
netlabelctl map del default
netlabelctl map add default address:0.0.0.0/0 protocol:unlbl
netlabelctl map add default address:::/0 protocol:unlbl
netlabelctl map add default address:::1 protocol:calipso,16
Empty file modified tests/inet_socket/cipso-fl-flush
100755 → 100644
Empty file.
Empty file modified tests/inet_socket/cipso-fl-load
100755 → 100644
Empty file.
Empty file modified tests/inet_socket/cipso-flush
100755 → 100644
Empty file.
11 changes: 11 additions & 0 deletions tests/inet_socket/cipso-load-t1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
# Based on http:https://paulmoore.livejournal.com/7234.html.
#
# Modifications:
# - Defined a doi for testing loopback for CIPSOv4.

netlabelctl cipsov4 add pass doi:16 tags:1
netlabelctl map del default
netlabelctl map add default address:0.0.0.0/0 protocol:unlbl
netlabelctl map add default address:::/0 protocol:unlbl
netlabelctl map add default address:127.0.0.1 protocol:cipsov4,16
11 changes: 11 additions & 0 deletions tests/inet_socket/cipso-load-t2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
# Based on http:https://paulmoore.livejournal.com/7234.html.
#
# Modifications:
# - Defined a doi for testing loopback for CIPSOv4.

netlabelctl cipsov4 add pass doi:16 tags:2
netlabelctl map del default
netlabelctl map add default address:0.0.0.0/0 protocol:unlbl
netlabelctl map add default address:::/0 protocol:unlbl
netlabelctl map add default address:127.0.0.1 protocol:cipsov4,16
File renamed without changes.
Empty file modified tests/inet_socket/ipsec-flush
100755 → 100644
Empty file.
Empty file modified tests/inet_socket/ipsec-load
100755 → 100644
Empty file.
Empty file modified tests/inet_socket/iptables-flush
100755 → 100644
Empty file.
Empty file modified tests/inet_socket/iptables-load
100755 → 100644
Empty file.
16 changes: 11 additions & 5 deletions tests/inet_socket/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,17 @@ int main(int argc, char **argv)
perror("socket");
exit(1);
}
result = setsockopt(sock, SOL_IP, IP_PASSSEC, &on, sizeof(on));
if (result < 0) {
perror("setsockopt: SO_PASSSEC");
close(sock);
exit(1);

/* Allow retrieval of UDP/Datagram security contexts for IPv4 as
* IPv6 is not currently supported.
*/
if (hints.ai_socktype == SOCK_DGRAM) {
result = setsockopt(sock, SOL_IP, IP_PASSSEC, &on, sizeof(on));
if (result < 0) {
perror("setsockopt: IP_PASSSEC");
close(sock);
exit(1);
}
}

result = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
Expand Down

0 comments on commit 9d7d40a

Please sign in to comment.