From 3c6ae625101aee6ddf94e0fd85ce3a9c9067c3bf Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Sun, 1 May 2022 06:36:34 +0200 Subject: conf, tcp, udp: Allow address specification for forwarded ports This feature is available in slirp4netns but was missing in passt and pasta. Given that we don't do dynamic memory allocation, we need to bind sockets while parsing port configuration. This means we need to process all other options first, as they might affect addressing and IP version support. It also implies a minor rework of how TCP and UDP implementations bind sockets. Signed-off-by: Stefano Brivio --- passt.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'passt.c') diff --git a/passt.c b/passt.c index 8781a7f..e5064f8 100644 --- a/passt.c +++ b/passt.c @@ -370,20 +370,13 @@ int main(int argc, char **argv) __setlogmask(LOG_MASK(LOG_EMERG)); - conf(&c, argc, argv); - trace_init(c.trace); - - if (!c.debug && (c.stderr || isatty(fileno(stdout)))) - __openlog(log_name, LOG_PERROR, LOG_DAEMON); - - c.epollfd = epoll_create1(c.foreground ? O_CLOEXEC : 0); + /* NOLINTNEXTLINE(android-cloexec-epoll-create1): forking in a moment */ + c.epollfd = epoll_create1(0); if (c.epollfd == -1) { perror("epoll_create1"); exit(EXIT_FAILURE); } - quit_fd = pasta_netns_quit_init(&c); - if (getrlimit(RLIMIT_NOFILE, &limit)) { perror("getrlimit"); exit(EXIT_FAILURE); @@ -395,13 +388,20 @@ int main(int argc, char **argv) } sock_probe_mem(&c); + conf(&c, argc, argv); + trace_init(c.trace); + + if (!c.debug && (c.stderr || isatty(fileno(stdout)))) + __openlog(log_name, LOG_PERROR, LOG_DAEMON); + + quit_fd = pasta_netns_quit_init(&c); + c.fd_tap = c.fd_tap_listen = -1; tap_sock_init(&c); clock_gettime(CLOCK_MONOTONIC, &now); - if ((!c.no_udp && udp_sock_init(&c)) || - (!c.no_tcp && tcp_sock_init(&c))) + if ((!c.no_udp && udp_init(&c)) || (!c.no_tcp && tcp_init(&c))) exit(EXIT_FAILURE); proto_update_l2_buf(c.mac_guest, c.mac, &c.addr4); -- cgit v1.2.3