72
69
unsigned int lev = -1;
73
70
unsigned int set = 0;
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;
81
78
if (strncasecmp(level, ipt_log_names[i].name,
82
79
strlen(level)) == 0) {
84
exit_error(PARAMETER_PROBLEM,
81
xtables_error(PARAMETER_PROBLEM,
85
82
"log-level `%s' ambiguous",
87
84
lev = ipt_log_names[i].level;
92
exit_error(PARAMETER_PROBLEM,
89
xtables_error(PARAMETER_PROBLEM,
93
90
"log-level `%s' unknown", level);
99
96
#define IPT_LOG_OPT_LEVEL 0x01
103
100
#define IPT_LOG_OPT_IPOPT 0x10
104
101
#define IPT_LOG_OPT_UID 0x20
106
/* Function which parses command options; returns true if it
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)
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");
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");
123
118
loginfo->level = parse_level(optarg);
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");
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");
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);
141
136
if (strlen(optarg) == 0)
142
exit_error(PARAMETER_PROBLEM,
137
xtables_error(PARAMETER_PROBLEM,
143
138
"No prefix specified for --log-prefix");
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");
149
144
strcpy(loginfo->prefix, optarg);
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 "
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");
168
163
loginfo->logflags |= IPT_LOG_TCPOPT;
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");
177
172
loginfo->logflags |= IPT_LOG_IPOPT;
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");
186
181
loginfo->logflags |= IPT_LOG_UID;
233
227
printf("prefix `%s' ", loginfo->prefix);
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)
239
232
const struct ipt_log_info *loginfo
242
235
if (strcmp(loginfo->prefix, "") != 0) {
243
236
printf("--log-prefix ");
244
save_string(loginfo->prefix);
237
xtables_save_string(loginfo->prefix);
247
240
if (loginfo->level != LOG_DEFAULT_LEVEL)
260
253
static struct xtables_target log_tg_reg = {
262
255
.version = XTABLES_VERSION,
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,