aboutsummaryrefslogtreecommitdiffstats
path: root/src/firejail/dhcp.c
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kris7topher@gmail.com>2019-12-30 20:56:03 +0100
committerLibravatar Kristóf Marussy <kris7topher@gmail.com>2020-01-01 03:40:19 +0100
commitc082d90be6396149404704e127f10ec7c9aa79ad (patch)
tree2301e5c31f352d7d1465dcb7d268cb3c55e4a879 /src/firejail/dhcp.c
parentRun dhclient inside the sandbox (diff)
downloadfirejail-c082d90be6396149404704e127f10ec7c9aa79ad.tar.gz
firejail-c082d90be6396149404704e127f10ec7c9aa79ad.tar.zst
firejail-c082d90be6396149404704e127f10ec7c9aa79ad.zip
Wait for link-local address for DHCPv6
dhclient -6 fails if the interface to be configures has no link-local address. This is especially problematic when only DHCPv6 is used (e.g., --ip=none --ip6=dhcp), because the wait for a DHCPv4 lease is usually ample time for the LL address to become available on the IPv6 link. The LL address must not be tenative. Therefore, this patch implements waiting for a non-tentative link-local address in fnet for DHCPv6 configured interfaces. The command fnet waitll <if> waits for an LL address on the interface <if>. Currently, the maximum waiting time is 30 seconds, and the kernel is polled through rtnetlink every 500 milliseconds. These values seem sufficient for virtual bridged networks, e.g., libvirt NAT networks.
Diffstat (limited to 'src/firejail/dhcp.c')
-rw-r--r--src/firejail/dhcp.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/firejail/dhcp.c b/src/firejail/dhcp.c
index c9bbb4d8f..7ce9a2b18 100644
--- a/src/firejail/dhcp.c
+++ b/src/firejail/dhcp.c
@@ -117,6 +117,21 @@ static void dhcp_start_dhclient(const Dhclient *client) {
117 *(client->pid) = dhcp_read_pidfile(client); 117 *(client->pid) = dhcp_read_pidfile(client);
118} 118}
119 119
120static void dhcp_waitll(const char *ifname) {
121 sbox_run(SBOX_ROOT | SBOX_CAPS_NETWORK | SBOX_SECCOMP, 3, PATH_FNET, "waitll", ifname);
122}
123
124static void dhcp_waitll_all() {
125 if (cfg.bridge0.arg_ip6_dhcp)
126 dhcp_waitll(cfg.bridge0.devsandbox);
127 if (cfg.bridge1.arg_ip6_dhcp)
128 dhcp_waitll(cfg.bridge1.devsandbox);
129 if (cfg.bridge2.arg_ip6_dhcp)
130 dhcp_waitll(cfg.bridge2.devsandbox);
131 if (cfg.bridge3.arg_ip6_dhcp)
132 dhcp_waitll(cfg.bridge3.devsandbox);
133}
134
120void dhcp_start(void) { 135void dhcp_start(void) {
121 if (!any_dhcp()) 136 if (!any_dhcp())
122 return; 137 return;
@@ -131,6 +146,7 @@ void dhcp_start(void) {
131 printf("Running dhclient -4 in the background as pid %ld\n", (long) dhclient4_pid); 146 printf("Running dhclient -4 in the background as pid %ld\n", (long) dhclient4_pid);
132 } 147 }
133 if (any_ip6_dhcp()) { 148 if (any_ip6_dhcp()) {
149 dhcp_waitll_all();
134 dhcp_start_dhclient(&dhclient6); 150 dhcp_start_dhclient(&dhclient6);
135 if (arg_debug) 151 if (arg_debug)
136 printf("Running dhclient -6 in the background as pid %ld\n", (long) dhclient6_pid); 152 printf("Running dhclient -6 in the background as pid %ld\n", (long) dhclient6_pid);