2021-10-19 12:43:28 +02:00
|
|
|
/* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
* Copyright (c) 2021 Red Hat GmbH
|
|
|
|
* Author: Stefano Brivio <sbrivio@redhat.com>
|
|
|
|
*/
|
|
|
|
|
2022-03-26 00:05:31 +01:00
|
|
|
#ifndef PASTA_H
|
|
|
|
#define PASTA_H
|
|
|
|
|
pasta: Wait for tap to be set up before spawning command
Adapted from a patch by Paul Holzinger: when pasta spawns a command,
operating without a pre-existing user and network namespace, it needs
to wait for the tap device to be configured and its handler ready,
before the command is actually executed.
Otherwise, something like:
pasta --config-net nslookup passt.top
usually fails as the nslookup command is issued before the network
interface is ready.
We can't adopt a simpler approach based on SIGSTOP and SIGCONT here:
the child runs in a separate PID namespace, so it can't send SIGSTOP
to itself as the kernel sees the child as init process and blocks
the delivery of the signal.
We could send SIGSTOP from the parent, but this wouldn't avoid the
possible condition where the child isn't ready to wait for it when
the parent sends it, also raised by Paul -- and SIGSTOP can't be
blocked, so it can never be pending.
Use SIGUSR1 instead: mask it before clone(), so that the child starts
with it blocked, and can safely wait for it. Once the parent is
ready, it sends SIGUSR1 to the child. If SIGUSR1 is sent before the
child is waiting for it, the kernel will queue it for us, because
it's blocked.
Reported-by: Paul Holzinger <pholzing@redhat.com>
Fixes: 1392bc5ca002 ("Allow pasta to take a command to execute")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
2023-02-12 12:22:59 +01:00
|
|
|
extern int pasta_child_pid;
|
|
|
|
|
2022-09-12 14:24:07 +02:00
|
|
|
void pasta_open_ns(struct ctx *c, const char *netns);
|
2022-10-14 06:25:36 +02:00
|
|
|
void pasta_start_ns(struct ctx *c, uid_t uid, gid_t gid,
|
|
|
|
int argc, char *argv[]);
|
2021-10-14 13:40:53 +02:00
|
|
|
void pasta_ns_conf(struct ctx *c);
|
|
|
|
void pasta_child_handler(int signal);
|
2022-02-18 16:12:11 +01:00
|
|
|
int pasta_netns_quit_init(struct ctx *c);
|
|
|
|
void pasta_netns_quit_handler(struct ctx *c, int inotify_fd);
|
2022-03-26 00:05:31 +01:00
|
|
|
|
|
|
|
#endif /* PASTA_H */
|