mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-28 12:57:57 +00:00
zdtm/netns_sub_sysctl: add ipv4/ping_group_range sysctl check
Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
This commit is contained in:
parent
f38e58836a
commit
1c9fd58ff0
@ -3,6 +3,49 @@
|
|||||||
#include "zdtmtst.h"
|
#include "zdtmtst.h"
|
||||||
#include "sysctl.h"
|
#include "sysctl.h"
|
||||||
|
|
||||||
|
int sysctl_read_str(const char *name, char *data, size_t size)
|
||||||
|
{
|
||||||
|
int fd, ret;
|
||||||
|
|
||||||
|
fd = open(name, O_RDONLY);
|
||||||
|
if (fd < 0) {
|
||||||
|
pr_perror("Can't open %s", name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = read(fd, data, size - 1);
|
||||||
|
if (ret < 0) {
|
||||||
|
pr_perror("Can't read %s", name);
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
data[ret] = '\0';
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int sysctl_write_str(const char *name, char *data)
|
||||||
|
{
|
||||||
|
int fd, ret;
|
||||||
|
|
||||||
|
fd = open(name, O_WRONLY);
|
||||||
|
if (fd < 0) {
|
||||||
|
pr_perror("Can't open %s", name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = write(fd, data, strlen(data));
|
||||||
|
if (ret < 0) {
|
||||||
|
pr_perror("Can't write %s into %s", data, name);
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int sysctl_read_int(const char *name, int *data)
|
int sysctl_read_int(const char *name, int *data)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
@ -3,5 +3,7 @@
|
|||||||
|
|
||||||
extern int sysctl_read_int(const char *name, int *data);
|
extern int sysctl_read_int(const char *name, int *data);
|
||||||
extern int sysctl_write_int(const char *name, int val);
|
extern int sysctl_write_int(const char *name, int val);
|
||||||
|
extern int sysctl_read_str(const char *name, char *data, size_t size);
|
||||||
|
extern int sysctl_write_str(const char *name, char *data);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -3,18 +3,33 @@
|
|||||||
#include "zdtmtst.h"
|
#include "zdtmtst.h"
|
||||||
#include "sysctl.h"
|
#include "sysctl.h"
|
||||||
|
|
||||||
const char *test_doc = "Check dump and restore a net.unix.max_dgram_qlen sysctl parameter in subns";
|
const char *test_doc = "Check dump and restore of sysctls in subns";
|
||||||
const char *test_author = "Alexander Mikhalitsyn <alexander@mihalicyn.com>";
|
const char *test_author = "Alexander Mikhalitsyn <alexander@mihalicyn.com>";
|
||||||
|
|
||||||
|
#define MAX_STR_SYSCTL_LEN 200
|
||||||
|
|
||||||
|
enum {
|
||||||
|
SYSCTL_INT,
|
||||||
|
SYSCTL_STR,
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *path;
|
const char *path;
|
||||||
|
int type;
|
||||||
int old;
|
int old;
|
||||||
int new;
|
int new;
|
||||||
|
char s_old[MAX_STR_SYSCTL_LEN];
|
||||||
|
char s_new[MAX_STR_SYSCTL_LEN];
|
||||||
} sysctl_opt_t;
|
} sysctl_opt_t;
|
||||||
|
|
||||||
#define CONF_UNIX_BASE "/proc/sys/net/unix"
|
#define CONF_UNIX_BASE "/proc/sys/net/unix"
|
||||||
|
#define IPV4_SYSCTL_BASE "/proc/sys/net/ipv4"
|
||||||
|
|
||||||
static sysctl_opt_t net_unix_params[] = { { CONF_UNIX_BASE "/max_dgram_qlen", 0, 0 }, { NULL, 0, 0 } };
|
static sysctl_opt_t net_unix_params[] = {
|
||||||
|
{CONF_UNIX_BASE "/max_dgram_qlen", SYSCTL_INT},
|
||||||
|
{IPV4_SYSCTL_BASE "/ping_group_range", SYSCTL_STR, 0, 0, "40000\t50000\n"},
|
||||||
|
{NULL, 0, 0}
|
||||||
|
};
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
@ -23,17 +38,25 @@ int main(int argc, char **argv)
|
|||||||
test_init(argc, argv);
|
test_init(argc, argv);
|
||||||
|
|
||||||
for (p = net_unix_params; p->path != NULL; p++) {
|
for (p = net_unix_params; p->path != NULL; p++) {
|
||||||
|
if (p->type == SYSCTL_INT) {
|
||||||
p->old = (((unsigned)lrand48()) % 1023) + 1;
|
p->old = (((unsigned)lrand48()) % 1023) + 1;
|
||||||
if (sysctl_write_int(p->path, p->old)) {
|
if (sysctl_write_int(p->path, p->old)) {
|
||||||
pr_perror("Can't change %s", p->path);
|
pr_perror("Can't change %s", p->path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
} else if (p->type == SYSCTL_STR) {
|
||||||
|
if (sysctl_write_str(p->path, p->s_old)) {
|
||||||
|
pr_perror("Can't change %s", p->path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
test_daemon();
|
test_daemon();
|
||||||
test_waitsig();
|
test_waitsig();
|
||||||
|
|
||||||
for (p = net_unix_params; p->path != NULL; p++) {
|
for (p = net_unix_params; p->path != NULL; p++) {
|
||||||
|
if (p->type == SYSCTL_INT) {
|
||||||
if (sysctl_read_int(p->path, &p->new))
|
if (sysctl_read_int(p->path, &p->new))
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
|
||||||
@ -42,6 +65,17 @@ int main(int argc, char **argv)
|
|||||||
pr_perror("%s changed: %d ---> %d", p->path, p->old, p->new);
|
pr_perror("%s changed: %d ---> %d", p->path, p->old, p->new);
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
|
} else if (p->type == SYSCTL_STR) {
|
||||||
|
if (sysctl_read_str(p->path, p->s_new, MAX_STR_SYSCTL_LEN)) {
|
||||||
|
ret = 1;
|
||||||
|
} else {
|
||||||
|
if (strcmp(p->s_old, p->s_new)) {
|
||||||
|
errno = EINVAL;
|
||||||
|
pr_perror("%s changed: %s ---> %s", p->path, p->s_old, p->s_new);
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user