-
Notifications
You must be signed in to change notification settings - Fork 606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net: remember the name of the lock chain (nftables) #2550
base: criu-dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -229,6 +229,8 @@ static const char *unix_conf_entries[] = { | |
"max_dgram_qlen", | ||
}; | ||
|
||
extern char nft_lock_table[32]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess, we don't need this anymore. |
||
|
||
/* | ||
* MAX_CONF_UNIX_PATH = (sizeof(CONF_UNIX_FMT) - strlen("%s")) | ||
* + MAX_CONF_UNIX_OPT_PATH | ||
|
@@ -3073,14 +3075,23 @@ static inline int nftables_lock_network_internal(void) | |
int ret = 0; | ||
char table[32]; | ||
char buf[128]; | ||
FILE *fp; | ||
|
||
if (nftables_get_table(table, sizeof(table))) | ||
if (nftables_get_table(table, sizeof(table), criu_run_id)) | ||
return -1; | ||
|
||
nft = nft_ctx_new(NFT_CTX_DEFAULT); | ||
if (!nft) | ||
return -1; | ||
|
||
fp = fdopen(log_get_fd(), "w"); | ||
if (!fp) { | ||
pr_perror("fdopen() failed"); | ||
goto err3; | ||
} | ||
nft_ctx_set_output(nft, fp); | ||
nft_ctx_set_error(nft, fp); | ||
|
||
snprintf(buf, sizeof(buf), "create table %s", table); | ||
if (NFT_RUN_CMD(nft, buf)) | ||
goto err2; | ||
|
@@ -3107,6 +3118,9 @@ static inline int nftables_lock_network_internal(void) | |
snprintf(buf, sizeof(buf), "delete table %s", table); | ||
NFT_RUN_CMD(nft, buf); | ||
err2: | ||
fflush(fp); | ||
fclose(fp); | ||
err3: | ||
ret = -1; | ||
pr_err("Locking network failed using nftables\n"); | ||
out: | ||
|
@@ -3171,18 +3185,44 @@ static inline int nftables_network_unlock(void) | |
struct nft_ctx *nft; | ||
char table[32]; | ||
char buf[128]; | ||
FILE *fp; | ||
uint64_t locking_run_id; | ||
|
||
/** | ||
* Network unlocking can happen during restore, but also | ||
* during checkpointing. It happens during checkpointing | ||
* if the process is kept on running or if there was some | ||
* error. In that case, checkpointing, dump_criu_run_id | ||
* is not set and we have to use criu_run_id. | ||
*/ | ||
|
||
if (nftables_get_table(table, sizeof(table))) | ||
if (dump_criu_run_id == 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to introduce a boolean parameter here to determine if we are on restore/dump codepath as |
||
locking_run_id = criu_run_id; | ||
else | ||
locking_run_id = dump_criu_run_id; | ||
|
||
if (nftables_get_table(table, sizeof(table), locking_run_id)) | ||
return -1; | ||
|
||
nft = nft_ctx_new(NFT_CTX_DEFAULT); | ||
if (!nft) | ||
return -1; | ||
|
||
fp = fdopen(log_get_fd(), "w"); | ||
if (!fp) { | ||
pr_perror("fdopen() failed"); | ||
nft_ctx_free(nft); | ||
return -1; | ||
} | ||
nft_ctx_set_output(nft, fp); | ||
nft_ctx_set_error(nft, fp); | ||
|
||
snprintf(buf, sizeof(buf), "delete table %s", table); | ||
if (NFT_RUN_CMD(nft, buf)) | ||
ret = -1; | ||
|
||
fflush(fp); | ||
fclose(fp); | ||
nft_ctx_free(nft); | ||
return ret; | ||
#else | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,7 +160,7 @@ int nftables_init_connection_lock(void) | |
int ret = 0; | ||
char table[32]; | ||
|
||
if (nftables_get_table(table, sizeof(table))) | ||
if (nftables_get_table(table, sizeof(table), criu_run_id)) | ||
return -1; | ||
|
||
nft = nft_ctx_new(NFT_CTX_DEFAULT); | ||
|
@@ -243,7 +243,7 @@ static int nftables_lock_connection_raw(int family, u32 *src_addr, u16 src_port, | |
char sip[INET_ADDR_LEN], dip[INET_ADDR_LEN]; | ||
char table[32]; | ||
|
||
if (nftables_get_table(table, sizeof(table))) | ||
if (nftables_get_table(table, sizeof(table), criu_run_id)) | ||
return -1; | ||
|
||
if (family == AF_INET6 && ipv6_addr_mapped(dst_addr)) { | ||
|
@@ -297,9 +297,9 @@ int nftables_lock_connection(struct inet_sk_desc *sk) | |
return ret; | ||
} | ||
|
||
int nftables_get_table(char *table, int n) | ||
int nftables_get_table(char *table, int n, uint64_t id) | ||
{ | ||
if (snprintf(table, n, "inet CRIU-%d", root_item->pid->real) < 0) { | ||
if (snprintf(table, n, "inet CRIU-%" PRIx64, id) < 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
What do you think about this? |
||
pr_err("Cannot generate CRIU's nftables table name\n"); | ||
return -1; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.