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

« back to all changes in this revision

Viewing changes to extensions/libipt_LOG.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:
5
5
#include <stdlib.h>
6
6
#include <syslog.h>
7
7
#include <getopt.h>
8
 
#include <iptables.h>
9
 
#include <linux/netfilter_ipv4/ip_tables.h>
 
8
#include <xtables.h>
10
9
#include <linux/netfilter_ipv4/ipt_LOG.h>
11
10
 
12
11
#define LOG_DEFAULT_LEVEL LOG_WARNING
17
16
#define IPT_LOG_MASK    0x0f
18
17
#endif
19
18
 
20
 
/* Function which prints out usage message. */
21
19
static void LOG_help(void)
22
20
{
23
21
        printf(
40
38
        { .name = NULL }
41
39
};
42
40
 
43
 
/* Initialize the target. */
44
41
static void LOG_init(struct xt_entry_target *t)
45
42
{
46
43
        struct ipt_log_info *loginfo = (struct ipt_log_info *)t->data;
72
69
        unsigned int lev = -1;
73
70
        unsigned int set = 0;
74
71
 
75
 
        if (string_to_number(level, 0, 7, &lev) == -1) {
 
72
        if (!xtables_strtoui(level, NULL, &lev, 0, 7)) {
76
73
                unsigned int i = 0;
77
74
 
78
75
                for (i = 0;
81
78
                        if (strncasecmp(level, ipt_log_names[i].name,
82
79
                                        strlen(level)) == 0) {
83
80
                                if (set++)
84
 
                                        exit_error(PARAMETER_PROBLEM,
 
81
                                        xtables_error(PARAMETER_PROBLEM,
85
82
                                                   "log-level `%s' ambiguous",
86
83
                                                   level);
87
84
                                lev = ipt_log_names[i].level;
89
86
                }
90
87
 
91
88
                if (!set)
92
 
                        exit_error(PARAMETER_PROBLEM,
 
89
                        xtables_error(PARAMETER_PROBLEM,
93
90
                                   "log-level `%s' unknown", level);
94
91
        }
95
92
 
96
 
        return (u_int8_t)lev;
 
93
        return lev;
97
94
}
98
95
 
99
96
#define IPT_LOG_OPT_LEVEL 0x01
103
100
#define IPT_LOG_OPT_IPOPT 0x10
104
101
#define IPT_LOG_OPT_UID 0x20
105
102
 
106
 
/* Function which parses command options; returns true if it
107
 
   ate an option */
108
103
static int LOG_parse(int c, char **argv, int invert, unsigned int *flags,
109
104
                     const void *entry, struct xt_entry_target **target)
110
105
{
113
108
        switch (c) {
114
109
        case '!':
115
110
                if (*flags & IPT_LOG_OPT_LEVEL)
116
 
                        exit_error(PARAMETER_PROBLEM,
 
111
                        xtables_error(PARAMETER_PROBLEM,
117
112
                                   "Can't specify --log-level twice");
118
113
 
119
 
                if (check_inverse(optarg, &invert, NULL, 0))
120
 
                        exit_error(PARAMETER_PROBLEM,
 
114
                if (xtables_check_inverse(optarg, &invert, NULL, 0))
 
115
                        xtables_error(PARAMETER_PROBLEM,
121
116
                                   "Unexpected `!' after --log-level");
122
117
 
123
118
                loginfo->level = parse_level(optarg);
126
121
 
127
122
        case '#':
128
123
                if (*flags & IPT_LOG_OPT_PREFIX)
129
 
                        exit_error(PARAMETER_PROBLEM,
 
124
                        xtables_error(PARAMETER_PROBLEM,
130
125
                                   "Can't specify --log-prefix twice");
131
126
 
132
 
                if (check_inverse(optarg, &invert, NULL, 0))
133
 
                        exit_error(PARAMETER_PROBLEM,
 
127
                if (xtables_check_inverse(optarg, &invert, NULL, 0))
 
128
                        xtables_error(PARAMETER_PROBLEM,
134
129
                                   "Unexpected `!' after --log-prefix");
135
130
 
136
131
                if (strlen(optarg) > sizeof(loginfo->prefix) - 1)
137
 
                        exit_error(PARAMETER_PROBLEM,
 
132
                        xtables_error(PARAMETER_PROBLEM,
138
133
                                   "Maximum prefix length %u for --log-prefix",
139
134
                                   (unsigned int)sizeof(loginfo->prefix) - 1);
140
135
 
141
136
                if (strlen(optarg) == 0)
142
 
                        exit_error(PARAMETER_PROBLEM,
 
137
                        xtables_error(PARAMETER_PROBLEM,
143
138
                                   "No prefix specified for --log-prefix");
144
139
 
145
140
                if (strlen(optarg) != strlen(strtok(optarg, "\n")))
146
 
                        exit_error(PARAMETER_PROBLEM,
 
141
                        xtables_error(PARAMETER_PROBLEM,
147
142
                                   "Newlines not allowed in --log-prefix");
148
143
 
149
144
                strcpy(loginfo->prefix, optarg);
152
147
 
153
148
        case '1':
154
149
                if (*flags & IPT_LOG_OPT_TCPSEQ)
155
 
                        exit_error(PARAMETER_PROBLEM,
 
150
                        xtables_error(PARAMETER_PROBLEM,
156
151
                                   "Can't specify --log-tcp-sequence "
157
152
                                   "twice");
158
153
 
162
157
 
163
158
        case '2':
164
159
                if (*flags & IPT_LOG_OPT_TCPOPT)
165
 
                        exit_error(PARAMETER_PROBLEM,
 
160
                        xtables_error(PARAMETER_PROBLEM,
166
161
                                   "Can't specify --log-tcp-options twice");
167
162
 
168
163
                loginfo->logflags |= IPT_LOG_TCPOPT;
171
166
 
172
167
        case '3':
173
168
                if (*flags & IPT_LOG_OPT_IPOPT)
174
 
                        exit_error(PARAMETER_PROBLEM,
 
169
                        xtables_error(PARAMETER_PROBLEM,
175
170
                                   "Can't specify --log-ip-options twice");
176
171
 
177
172
                loginfo->logflags |= IPT_LOG_IPOPT;
180
175
 
181
176
        case '4':
182
177
                if (*flags & IPT_LOG_OPT_UID)
183
 
                        exit_error(PARAMETER_PROBLEM,
 
178
                        xtables_error(PARAMETER_PROBLEM,
184
179
                                   "Can't specify --log-uid twice");
185
180
 
186
181
                loginfo->logflags |= IPT_LOG_UID;
194
189
        return 1;
195
190
}
196
191
 
197
 
/* Prints out the targinfo. */
198
192
static void LOG_print(const void *ip, const struct xt_entry_target *target,
199
193
                      int numeric)
200
194
{
233
227
                printf("prefix `%s' ", loginfo->prefix);
234
228
}
235
229
 
236
 
/* Saves the union ipt_targinfo in parsable form to stdout. */
237
230
static void LOG_save(const void *ip, const struct xt_entry_target *target)
238
231
{
239
232
        const struct ipt_log_info *loginfo
241
234
 
242
235
        if (strcmp(loginfo->prefix, "") != 0) {
243
236
                printf("--log-prefix ");
244
 
                save_string(loginfo->prefix);
 
237
                xtables_save_string(loginfo->prefix);
245
238
        }
246
239
 
247
240
        if (loginfo->level != LOG_DEFAULT_LEVEL)
260
253
static struct xtables_target log_tg_reg = {
261
254
    .name          = "LOG",
262
255
    .version       = XTABLES_VERSION,
263
 
    .family        = PF_INET,
 
256
    .family        = NFPROTO_IPV4,
264
257
    .size          = XT_ALIGN(sizeof(struct ipt_log_info)),
265
258
    .userspacesize = XT_ALIGN(sizeof(struct ipt_log_info)),
266
259
    .help          = LOG_help,