-
Notifications
You must be signed in to change notification settings - Fork 620
/
Copy pathnetns_sub_sysctl.c
87 lines (73 loc) · 1.79 KB
/
netns_sub_sysctl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <sched.h>
#include "zdtmtst.h"
#include "sysctl.h"
const char *test_doc = "Check dump and restore of sysctls in subns";
const char *test_author = "Alexander Mikhalitsyn <alexander@mihalicyn.com>";
#define MAX_STR_SYSCTL_LEN 200
enum {
SYSCTL_INT,
SYSCTL_STR,
};
typedef struct {
const char *path;
int type;
int old;
int new;
char s_old[MAX_STR_SYSCTL_LEN];
char s_new[MAX_STR_SYSCTL_LEN];
} sysctl_opt_t;
#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", 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 ret = 0;
sysctl_opt_t *p;
test_init(argc, argv);
for (p = net_unix_params; p->path != NULL; p++) {
if (p->type == SYSCTL_INT) {
p->old = (((unsigned)lrand48()) % 1023) + 1;
if (sysctl_write_int(p->path, p->old)) {
pr_perror("Can't change %s", p->path);
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_waitsig();
for (p = net_unix_params; p->path != NULL; p++) {
if (p->type == SYSCTL_INT) {
if (sysctl_read_int(p->path, &p->new))
ret = 1;
if (p->old != p->new) {
errno = EINVAL;
pr_perror("%s changed: %d ---> %d", p->path, p->old, p->new);
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)
fail();
else
pass();
return ret;
}