diff --git a/isolate.c b/isolate.c index 68e3f9f..af808ff 100644 --- a/isolate.c +++ b/isolate.c @@ -696,6 +696,48 @@ setup_orig_credentials(void) die("setresuid: %m"); } +/* https://bazel.googlesource.com/bazel/+/refs/changes/01/2101/5/src/main/tools/network-tools.c */ +#include +#include +#include +#include +#include +#include +#include +#include + +// see +// http://stackoverflow.com/questions/5641427/how-to-make-preprocessor-generate-a-string-for-line-keyword +#define S(x) #x +#define S_(x) S(x) +#define S__LINE__ S_(__LINE__) + +#define CHECK_CALL(x, ...) \ + if ((x) == -1) { \ + fprintf(stderr, __FILE__ ":" S__LINE__ ": " __VA_ARGS__); \ + perror(#x); \ + exit(EXIT_FAILURE); \ + } + +void BringupInterface(const char *name) { + int fd; + + struct ifreq ifr; + + CHECK_CALL(fd = socket(AF_INET, SOCK_DGRAM, 0)); + + memset(&ifr, 0, sizeof(ifr)); + strncpy(ifr.ifr_name, name, IF_NAMESIZE); + + CHECK_CALL(ioctl(fd, SIOCGIFINDEX, &ifr)); + + // Enable the interface + ifr.ifr_flags |= IFF_UP; + CHECK_CALL(ioctl(fd, SIOCSIFFLAGS, &ifr)); + + CHECK_CALL(close(fd)); +} + static int box_proxy(void *arg) { @@ -707,6 +749,10 @@ box_proxy(void *arg) meta_close(); reset_signals(); + if (!share_net) { + BringupInterface("lo"); + } + pid_t inside_pid = fork(); if (inside_pid < 0) die("Cannot run process, fork failed: %m");