29
29
{.name = "counters", .has_arg = false, .val = 'c'},
30
30
{.name = "dump", .has_arg = false, .val = 'd'},
31
31
{.name = "table", .has_arg = true, .val = 't'},
32
{.name = "modprobe", .has_arg = true, .val = 'M'},
43
44
procfile = fopen("/proc/net/ip6_tables_names", "r");
45
exit_error(OTHER_PROBLEM,
46
"Unable to open /proc/net/ip6_tables_names: %s\n",
49
48
while (fgets(tablename, sizeof(tablename), procfile)) {
50
49
if (tablename[strlen(tablename) - 1] != '\n')
51
exit_error(OTHER_PROBLEM,
50
xtables_error(OTHER_PROBLEM,
52
51
"Badly formed tablename `%s'\n",
54
53
tablename[strlen(tablename) - 1] = '\0';
62
61
static int do_output(const char *tablename)
63
struct ip6tc_handle *h;
65
64
const char *chain = NULL;
68
67
return for_each_table(&do_output);
70
69
h = ip6tc_init(tablename);
71
xtables_load_ko(xtables_modprobe_program, false);
72
h = ip6tc_init(tablename);
72
exit_error(OTHER_PROBLEM, "Can't initialize: %s\n",
75
xtables_error(OTHER_PROBLEM, "Cannot initialize: %s\n",
73
76
ip6tc_strerror(errno));
75
78
if (!show_binary) {
76
79
time_t now = time(NULL);
78
81
printf("# Generated by ip6tables-save v%s on %s",
79
XTABLES_VERSION, ctime(&now));
82
IPTABLES_VERSION, ctime(&now));
80
83
printf("*%s\n", tablename);
82
85
/* Dump out chain names first,
83
86
* thereby preventing dependency conflicts */
84
for (chain = ip6tc_first_chain(&h);
87
for (chain = ip6tc_first_chain(h);
86
chain = ip6tc_next_chain(&h)) {
89
chain = ip6tc_next_chain(h)) {
88
91
printf(":%s ", chain);
89
92
if (ip6tc_builtin(chain, h)) {
90
93
struct ip6t_counters count;
92
ip6tc_get_policy(chain, &count, &h));
95
ip6tc_get_policy(chain, &count, h));
93
96
printf("[%llu:%llu]\n", (unsigned long long)count.pcnt, (unsigned long long)count.bcnt);
95
98
printf("- [0:0]\n");
100
for (chain = ip6tc_first_chain(&h);
103
for (chain = ip6tc_first_chain(h);
102
chain = ip6tc_next_chain(&h)) {
105
chain = ip6tc_next_chain(h)) {
103
106
const struct ip6t_entry *e;
105
108
/* Dump out rules */
106
e = ip6tc_first_rule(chain, &h);
109
e = ip6tc_first_rule(chain, h);
108
print_rule(e, &h, chain, show_counters);
109
e = ip6tc_next_rule(e, &h);
111
print_rule(e, h, chain, show_counters);
112
e = ip6tc_next_rule(e, h);
115
118
printf("# Completed on %s", ctime(&now));
117
120
/* Binary, huh? OK. */
118
exit_error(OTHER_PROBLEM, "Binary NYI\n");
121
xtables_error(OTHER_PROBLEM, "Binary NYI\n");
136
139
const char *tablename = NULL;
139
program_name = "ip6tables-save";
140
program_version = XTABLES_VERSION;
142
lib_dir = getenv("XTABLES_LIBDIR");
143
if (lib_dir == NULL) {
144
lib_dir = getenv("IP6TABLES_LIB_DIR");
146
fprintf(stderr, "IP6TABLES_LIB_DIR is deprecated\n");
142
ip6tables_globals.program_name = "ip6tables-save";
143
c = xtables_init_all(&ip6tables_globals, NFPROTO_IPV6);
145
fprintf(stderr, "%s/%s Failed to initialize xtables\n",
146
ip6tables_globals.program_name,
147
ip6tables_globals.program_version);
149
lib_dir = XTABLES_LIBDIR;
151
150
#ifdef NO_SHARED_LIBS
152
151
init_extensions();