aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar netblue30 <netblue30@protonmail.com>2023-03-07 08:30:53 -0500
committerLibravatar netblue30 <netblue30@protonmail.com>2023-03-07 08:30:53 -0500
commita12601f02aecefd6fde2f227bd3536840f7f7b14 (patch)
treee35164d4ad8b63157170f355be3e0160eb6f172c
parentRun make codespell (diff)
downloadfirejail-a12601f02aecefd6fde2f227bd3536840f7f7b14.tar.gz
firejail-a12601f02aecefd6fde2f227bd3536840f7f7b14.tar.zst
firejail-a12601f02aecefd6fde2f227bd3536840f7f7b14.zip
testing
-rwxr-xr-xgcov.sh46
-rw-r--r--src/firejail/network.c24
-rw-r--r--src/firejail/sbox.c2
-rwxr-xr-xtest/network/ip6_netfilter.exp31
-rw-r--r--test/network/ip6_netfilter.profile8
-rwxr-xr-xtest/network/net_bandwidth.exp51
-rwxr-xr-xtest/network/net_ip.exp40
-rw-r--r--test/network/net_ip.profile6
-rwxr-xr-xtest/network/network.sh6
9 files changed, 167 insertions, 47 deletions
diff --git a/gcov.sh b/gcov.sh
index 9b02d801c..0f2808ace 100755
--- a/gcov.sh
+++ b/gcov.sh
@@ -13,7 +13,7 @@ gcov_generate() {
13 USER="$(whoami)" 13 USER="$(whoami)"
14 find . -exec sudo chown "$USER:$USER" '{}' + 14 find . -exec sudo chown "$USER:$USER" '{}' +
15 lcov -q --capture -d src/firejail -d src/lib -d src/firecfg -d src/firemon \ 15 lcov -q --capture -d src/firejail -d src/lib -d src/firecfg -d src/firemon \
16 -d src/fnet -d src/fnetfilter --output-file gcov-file 16 -d src/fnet -d src/fnetfilter -d src/fcopy --output-file gcov-file
17 genhtml -q gcov-file --output-directory gcov-dir 17 genhtml -q gcov-file --output-directory gcov-dir
18} 18}
19 19
@@ -21,29 +21,29 @@ rm -fr gcov-dir gcov-file
21firejail --version 21firejail --version
22gcov_generate 22gcov_generate
23 23
24#make test-firecfg | grep TESTING 24make test-firecfg | grep TESTING
25#gcov_generate 25gcov_generate
26#make test-apparmor | grep TESTING 26make test-apparmor | grep TESTING
27#gcov_generate 27gcov_generate
28make test-network | grep TESTING 28make test-network | grep TESTING
29gcov_generate 29gcov_generate
30#make test-appimage | grep TESTING 30make test-appimage | grep TESTING
31#gcov_generate 31gcov_generate
32#make test-chroot | grep TESTING 32make test-chroot | grep TESTING
33#gcov_generate 33gcov_generate
34#make test-sysutils | grep TESTING 34make test-sysutils | grep TESTING
35#gcov_generate 35gcov_generate
36#make test-private-etc | grep TESTING 36make test-private-etc | grep TESTING
37#gcov_generate 37gcov_generate
38#make test-profiles | grep TESTING 38make test-profiles | grep TESTING
39#gcov_generate 39gcov_generate
40#make test-fcopy | grep TESTING 40make test-fcopy | grep TESTING
41#gcov_generate 41gcov_generate
42make test-fnetfilter | grep TESTING 42make test-fnetfilter | grep TESTING
43gcov_generate 43gcov_generate
44#make test-fs | grep TESTING 44make test-fs | grep TESTING
45#gcov_generate 45gcov_generate
46#make test-utils | grep TESTING 46make test-utils | grep TESTING
47#gcov_generate 47gcov_generate
48#make test-environment | grep TESTING 48make test-environment | grep TESTING
49#gcov_generate 49gcov_generate
diff --git a/src/firejail/network.c b/src/firejail/network.c
index 0d2d53fca..3da51e195 100644
--- a/src/firejail/network.c
+++ b/src/firejail/network.c
@@ -89,30 +89,6 @@ int net_get_mtu(const char *ifname) {
89 return mtu; 89 return mtu;
90} 90}
91 91
92//void net_set_mtu(const char *ifname, int mtu) {
93// if (strlen(ifname) > IFNAMSIZ) {
94// fprintf(stderr, "Error: invalid network device name %s\n", ifname);
95// exit(1);
96// }
97//
98// if (arg_debug)
99// printf("set interface %s MTU %d.\n", ifname, mtu);
100//
101// int s;
102// struct ifreq ifr;
103//
104// if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
105// errExit("socket");
106//
107// memset(&ifr, 0, sizeof(ifr));
108// ifr.ifr_addr.sa_family = AF_INET;
109// strncpy(ifr.ifr_name, ifname, IFNAMSIZ - 1);
110// ifr.ifr_mtu = mtu;
111// if (ioctl(s, SIOCSIFMTU, (caddr_t)&ifr) != 0)
112// fwarning("cannot set mtu for interface %s\n", ifname);
113// close(s);
114//}
115
116// return -1 if the interface was not found; if the interface was found return 0 and fill in IP address and mask 92// return -1 if the interface was not found; if the interface was found return 0 and fill in IP address and mask
117int net_get_if_addr(const char *bridge, uint32_t *ip, uint32_t *mask, uint8_t mac[6], int *mtu) { 93int net_get_if_addr(const char *bridge, uint32_t *ip, uint32_t *mask, uint8_t mac[6], int *mtu) {
118 assert(bridge); 94 assert(bridge);
diff --git a/src/firejail/sbox.c b/src/firejail/sbox.c
index 11ea5b036..ce43b4832 100644
--- a/src/firejail/sbox.c
+++ b/src/firejail/sbox.c
@@ -26,6 +26,7 @@
26#include <sys/resource.h> 26#include <sys/resource.h>
27#include <sys/wait.h> 27#include <sys/wait.h>
28#include "../include/seccomp.h" 28#include "../include/seccomp.h"
29#include "../include/gcov_wrapper.h"
29 30
30#include <fcntl.h> 31#include <fcntl.h>
31#ifndef O_PATH 32#ifndef O_PATH
@@ -238,6 +239,7 @@ static int __attribute__((noreturn)) sbox_do_exec_v(unsigned filtermask, char *
238 fprintf(stderr, "Error: %s is world writable, refusing to execute\n", arg[0]); 239 fprintf(stderr, "Error: %s is world writable, refusing to execute\n", arg[0]);
239 exit(1); 240 exit(1);
240 } 241 }
242 __gcov_dump();
241 fexecve(fd, arg, new_environment); 243 fexecve(fd, arg, new_environment);
242 } else { 244 } else {
243 assert(0); 245 assert(0);
diff --git a/test/network/ip6_netfilter.exp b/test/network/ip6_netfilter.exp
new file mode 100755
index 000000000..6c478d9e7
--- /dev/null
+++ b/test/network/ip6_netfilter.exp
@@ -0,0 +1,31 @@
1#!/usr/bin/expect -f
2# This file is part of Firejail project
3# Copyright (C) 2014-2023 Firejail Authors
4# License GPL v2
5
6set timeout 10
7spawn $env(SHELL)
8match_max 100000
9
10# check default netfilter on br0
11send -- "firejail --name=test --net=br0 --netfilter6=ip6_netfilter.profile\r"
12expect {
13 timeout {puts "TESTING ERROR 0\n";exit}
14 -re "Child process initialized in \[0-9\]+.\[0-9\]+ ms"
15}
16sleep 2
17spawn $env(SHELL)
18
19# check default netfilter no new network
20send -- "firejail --netfilter6.print=test\r"
21expect {
22 timeout {puts "TESTING ERROR 1\n";exit}
23 "DROP"
24}
25expect {
26 timeout {puts "TESTING ERROR 2\n";exit}
27 "2001:db8:1f0a:3ec::2"
28}
29
30after 500
31puts "all done\n"
diff --git a/test/network/ip6_netfilter.profile b/test/network/ip6_netfilter.profile
new file mode 100644
index 000000000..cc8f22943
--- /dev/null
+++ b/test/network/ip6_netfilter.profile
@@ -0,0 +1,8 @@
1# Generated by ip6tables-save v1.4.14 on Wed Jan 13 10:53:40 2016
2*filter
3:INPUT ACCEPT [0:0]
4:FORWARD ACCEPT [0:0]
5:OUTPUT ACCEPT [0:0]
6-A INPUT -s 2001:db8:1f0a:3ec::2/128 -j DROP
7COMMIT
8# Completed on Wed Jan 13 10:53:40 2016
diff --git a/test/network/net_bandwidth.exp b/test/network/net_bandwidth.exp
new file mode 100755
index 000000000..0ec3b59ef
--- /dev/null
+++ b/test/network/net_bandwidth.exp
@@ -0,0 +1,51 @@
1#!/usr/bin/expect -f
2# This file is part of Firejail project
3# Copyright (C) 2014-2023 Firejail Authors
4# License GPL v2
5
6set timeout 10
7spawn $env(SHELL)
8match_max 100000
9
10send -- "firejail --name=test --net=br0\r"
11expect {
12 timeout {puts "TESTING ERROR 1\n";exit}
13 -re "Child process initialized in \[0-9\]+.\[0-9\]+ ms"
14}
15sleep 2
16
17spawn $env(SHELL)
18send -- "firejail --bandwidth=test set br0 10 20\r"
19expect {
20 timeout {puts "TESTING ERROR 2\n";exit}
21 "Download speed 80kbps"
22}
23expect {
24 timeout {puts "TESTING ERROR 3\n";exit}
25 "Upload speed 160kbps"
26}
27expect {
28 timeout {puts "TESTING ERROR 4\n";exit}
29 "configuring tc ingress"
30}
31expect {
32 timeout {puts "TESTING ERROR 5\n";exit}
33 "configuring tc egress"
34}
35after 500
36
37send -- "firejail --bandwidth=test status\r"
38expect {
39 timeout {puts "TESTING ERROR 6\n";exit}
40 "rate 160Kbit burst 10Kb"
41}
42after 500
43
44send -- "firejail --bandwidth=test clear br0\r"
45expect {
46 timeout {puts "TESTING ERROR 7\n";exit}
47 "Removing bandwidth limits"
48}
49sleep 1
50
51puts "\nall done\n"
diff --git a/test/network/net_ip.exp b/test/network/net_ip.exp
index 251b55362..0cccf93a0 100755
--- a/test/network/net_ip.exp
+++ b/test/network/net_ip.exp
@@ -130,4 +130,44 @@ expect {
130} 130}
131 131
132after 500 132after 500
133
134send -- "firejail --profile=net_ip.profile ip addr show\r"
135expect {
136 timeout {puts "TESTING ERROR 26\n";exit}
137 "eth0"
138}
139expect {
140 timeout {puts "TESTING ERROR 27\n";exit}
141 "00:11:22:33:44:55"
142}
143expect {
144 timeout {puts "TESTING ERROR 28\n";exit}
145 "10.10.20.55"
146}
147expect {
148 timeout {puts "TESTING ERROR 29\n";exit}
149 "Default gateway 10.10.20.9"
150}
151expect {
152 timeout {puts "TESTING ERROR 30\n";exit}
153 "00:11:22:33:44:55"
154}
155expect {
156 timeout {puts "TESTING ERROR 31\n";exit}
157 "10.10.20.55"
158}
159after 500
160
161send -- "firejail --profile=net_ip.profile ip route show\r"
162expect {
163 timeout {puts "TESTING ERROR 32\n";exit}
164 "default via 10.10.20.9"
165}
166expect {
167 timeout {puts "TESTING ERROR 33\n";exit}
168 "10.10.20.0/24 dev eth0 proto kernel scope link src 10.10.20.55"
169}
170after 500
171
172
133puts "\nall done\n" 173puts "\nall done\n"
diff --git a/test/network/net_ip.profile b/test/network/net_ip.profile
new file mode 100644
index 000000000..72910d77e
--- /dev/null
+++ b/test/network/net_ip.profile
@@ -0,0 +1,6 @@
1net br0
2ip 10.10.20.55
3defaultgw 10.10.20.9
4mac 00:11:22:33:44:55
5mtu 1000
6
diff --git a/test/network/network.sh b/test/network/network.sh
index 877f16156..e062358d4 100755
--- a/test/network/network.sh
+++ b/test/network/network.sh
@@ -33,8 +33,14 @@ echo "TESTING: print network (net-print.exp)"
33echo "TESTING: print dns (dns-print.exp)" 33echo "TESTING: print dns (dns-print.exp)"
34./dns-print.exp 34./dns-print.exp
35 35
36echo "TESTING: bandwidth (net_bandwidth.exp)"
37./net_bandwidth.exp
38
36echo "TESTING: ipv6 (ip6.exp)" 39echo "TESTING: ipv6 (ip6.exp)"
37./ip6.exp 40./ip6.exp
38 41
42#echo "TESTING: ipv6 netfilter(ip6_netfilter.exp)"
43#./ip6_netfilter.exp
44
39sudo ip link set br0 down 45sudo ip link set br0 down
40sudo brctl delbr br0 46sudo brctl delbr br0