Skip to content

Commit

Permalink
net: redirect nftables stdout and stderr to CRIU's log file
Browse files Browse the repository at this point in the history
When using the nftables network locking backend and restoring a process
a second time the network locking has already been deleted by the first
restore. The second restore will print out to the console text like:

Error: Could not process rule: No such file or directory
delete table inet CRIU-202621

With this change CRIU's log FD is used by libnftables stdout and stderr.

Signed-off-by: Adrian Reber <[email protected]>
  • Loading branch information
adrianreber committed Jan 15, 2025
1 parent d4d3937 commit c079a61
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions criu/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -3066,6 +3066,32 @@ static int iptables_restore(bool ipv6, char *buf, int size)
return ret;
}

#if defined(CONFIG_HAS_NFTABLES_LIB_API_0) || defined(CONFIG_HAS_NFTABLES_LIB_API_1)
static inline int redirect_nftables_output(struct nft_ctx *nft)
{
FILE *fp;

fp = fdopen(log_get_fd(), "w");
if (!fp) {
pr_perror("fdopen() to redirect nftables output failed");
return -1;
}

/**
* Without setvbuf() the output from libnftables will be
* somewhere in the log file, probably at the end.
* With setvbuf() potential output will be at the correct
* position.
*/
setvbuf(fp, NULL, _IONBF, 0);

nft_ctx_set_output(nft, fp);
nft_ctx_set_error(nft, fp);

return 0;
}
#endif

static inline int nftables_lock_network_internal(void)
{
#if defined(CONFIG_HAS_NFTABLES_LIB_API_0) || defined(CONFIG_HAS_NFTABLES_LIB_API_1)
Expand All @@ -3081,6 +3107,9 @@ static inline int nftables_lock_network_internal(void)
if (!nft)
return -1;

if (redirect_nftables_output(nft))
goto out;

snprintf(buf, sizeof(buf), "create table %s", table);
if (NFT_RUN_CMD(nft, buf))
goto err2;
Expand Down Expand Up @@ -3179,6 +3208,9 @@ static inline int nftables_network_unlock(void)
if (!nft)
return -1;

if (redirect_nftables_output(nft))
return -1;

snprintf(buf, sizeof(buf), "delete table %s", table);
if (NFT_RUN_CMD(nft, buf))
ret = -1;
Expand Down

0 comments on commit c079a61

Please sign in to comment.