~ubuntu-branches/ubuntu/quantal/iptables/quantal-proposed

« back to all changes in this revision

Viewing changes to ip6tables-save.c

  • Committer: Bazaar Package Importer
  • Author(s): Nicolas Valcárcel Scerpella
  • Date: 2009-05-06 16:35:21 UTC
  • mfrom: (5.1.6 upstream) (2.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20090506163521-2hbruo0m33h04wxf
Tags: 1.4.3.2-2ubuntu1
* Merge from debian unstable (LP: #372920), remaining changes:
  - Don't fail to run iptables-save if iptables module isn't loaded.
  - debian/patches/0901-build-libipq_pic.a.patch - Build libipq_pic.a with
    -fPIC. Upstream changed build system and patch modified accordingly.
  - Revert changes between 1.4.1.1-3 and 1.4.1.1-4, thus bringing back
    the howtos.
* Droped unexistent patches from debian/patches/series
* Droped 0903-autoload-module-in-iptables-save.diff, fixed upstream
* Added linuxdoc-tools to Build-Depends
* Modified debian/iptables{,-dev}.install to match DM syntax 
  (removed debian/tmp)

Show diffs side-by-side

added added

removed removed

Lines of Context:
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'},
32
33
        {NULL},
33
34
};
34
35
 
42
43
 
43
44
        procfile = fopen("/proc/net/ip6_tables_names", "r");
44
45
        if (!procfile)
45
 
                exit_error(OTHER_PROBLEM,
46
 
                           "Unable to open /proc/net/ip6_tables_names: %s\n",
47
 
                           strerror(errno));
 
46
                return ret;
48
47
 
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",
53
52
                                   tablename);
54
53
                tablename[strlen(tablename) - 1] = '\0';
61
60
 
62
61
static int do_output(const char *tablename)
63
62
{
64
 
        ip6tc_handle_t h;
 
63
        struct ip6tc_handle *h;
65
64
        const char *chain = NULL;
66
65
 
67
66
        if (!tablename)
68
67
                return for_each_table(&do_output);
69
68
 
70
69
        h = ip6tc_init(tablename);
 
70
        if (h == NULL) {
 
71
                xtables_load_ko(xtables_modprobe_program, false);
 
72
                h = ip6tc_init(tablename);
 
73
        }
71
74
        if (!h)
72
 
                exit_error(OTHER_PROBLEM, "Can't initialize: %s\n",
 
75
                xtables_error(OTHER_PROBLEM, "Cannot initialize: %s\n",
73
76
                           ip6tc_strerror(errno));
74
77
 
75
78
        if (!show_binary) {
76
79
                time_t now = time(NULL);
77
80
 
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);
81
84
 
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);
85
88
                     chain;
86
 
                     chain = ip6tc_next_chain(&h)) {
 
89
                     chain = ip6tc_next_chain(h)) {
87
90
 
88
91
                        printf(":%s ", chain);
89
92
                        if (ip6tc_builtin(chain, h)) {
90
93
                                struct ip6t_counters count;
91
94
                                printf("%s ",
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);
94
97
                        } else {
95
98
                                printf("- [0:0]\n");
97
100
                }
98
101
 
99
102
 
100
 
                for (chain = ip6tc_first_chain(&h);
 
103
                for (chain = ip6tc_first_chain(h);
101
104
                     chain;
102
 
                     chain = ip6tc_next_chain(&h)) {
 
105
                     chain = ip6tc_next_chain(h)) {
103
106
                        const struct ip6t_entry *e;
104
107
 
105
108
                        /* Dump out rules */
106
 
                        e = ip6tc_first_rule(chain, &h);
 
109
                        e = ip6tc_first_rule(chain, h);
107
110
                        while(e) {
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);
110
113
                        }
111
114
                }
112
115
 
115
118
                printf("# Completed on %s", ctime(&now));
116
119
        } else {
117
120
                /* Binary, huh?  OK. */
118
 
                exit_error(OTHER_PROBLEM, "Binary NYI\n");
 
121
                xtables_error(OTHER_PROBLEM, "Binary NYI\n");
119
122
        }
120
123
 
121
 
        ip6tc_free(&h);
 
124
        ip6tc_free(h);
122
125
 
123
126
        return 1;
124
127
}
136
139
        const char *tablename = NULL;
137
140
        int c;
138
141
 
139
 
        program_name = "ip6tables-save";
140
 
        program_version = XTABLES_VERSION;
141
 
 
142
 
        lib_dir = getenv("XTABLES_LIBDIR");
143
 
        if (lib_dir == NULL) {
144
 
                lib_dir = getenv("IP6TABLES_LIB_DIR");
145
 
                if (lib_dir != NULL)
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);
 
144
        if (c < 0) {
 
145
                fprintf(stderr, "%s/%s Failed to initialize xtables\n",
 
146
                                ip6tables_globals.program_name,
 
147
                                ip6tables_globals.program_version);
 
148
                exit(1);
147
149
        }
148
 
        if (lib_dir == NULL)
149
 
                lib_dir = XTABLES_LIBDIR;
150
 
 
151
150
#ifdef NO_SHARED_LIBS
152
151
        init_extensions();
153
152
#endif
166
165
                        /* Select specific table. */
167
166
                        tablename = optarg;
168
167
                        break;
 
168
                case 'M':
 
169
                        xtables_modprobe_program = optarg;
 
170
                        break;
169
171
                case 'd':
170
172
                        do_output(tablename);
171
173
                        exit(0);