Lines 106-117
Link Here
|
106 |
}; |
106 |
}; |
107 |
|
107 |
|
108 |
static unsigned int |
108 |
static unsigned int |
109 |
parse_icmp(const char *icmptype, u_int8_t *type, u_int8_t code[]) |
109 |
parse_icmp(const char *icmptype, u_int8_t *type, u_int8_t code[], u_int8_t *flags) |
110 |
{ |
110 |
{ |
111 |
unsigned int limit = sizeof(icmp_codes)/sizeof(struct icmp_names); |
111 |
unsigned int limit = sizeof(icmp_codes)/sizeof(struct icmp_names); |
112 |
unsigned int match = limit; |
112 |
unsigned int match = limit; |
113 |
unsigned int i; |
113 |
unsigned int i; |
114 |
|
114 |
|
|
|
115 |
*flags &= ~IPT_ICMP_TYPE_ANY; |
116 |
|
115 |
for (i = 0; i < limit; i++) { |
117 |
for (i = 0; i < limit; i++) { |
116 |
if (strncasecmp(icmp_codes[i].name, icmptype, strlen(icmptype)) |
118 |
if (strncasecmp(icmp_codes[i].name, icmptype, strlen(icmptype)) |
117 |
== 0) { |
119 |
== 0) { |
Lines 141-149
Link Here
|
141 |
if (slash) |
143 |
if (slash) |
142 |
*slash = '\0'; |
144 |
*slash = '\0'; |
143 |
|
145 |
|
144 |
if (string_to_number(buffer, 0, 255, &number) == -1) |
146 |
if(!strncasecmp(buffer, "any", 3)) { |
145 |
exit_error(PARAMETER_PROBLEM, |
147 |
number = 0; |
146 |
"Invalid ICMP type `%s'\n", buffer); |
148 |
*flags |= IPT_ICMP_TYPE_ANY; |
|
|
149 |
} else { |
150 |
if (string_to_number(buffer, 0, 255, &number) == -1) |
151 |
exit_error(PARAMETER_PROBLEM, |
152 |
"Invalid ICMP type `%s'\n", buffer); |
153 |
} |
147 |
*type = number; |
154 |
*type = number; |
148 |
if (slash) { |
155 |
if (slash) { |
149 |
if (string_to_number(slash+1, 0, 255, &number) == -1) |
156 |
if (string_to_number(slash+1, 0, 255, &number) == -1) |
Lines 168-173
Link Here
|
168 |
{ |
175 |
{ |
169 |
struct ipt_icmp *icmpinfo = (struct ipt_icmp *)m->data; |
176 |
struct ipt_icmp *icmpinfo = (struct ipt_icmp *)m->data; |
170 |
|
177 |
|
|
|
178 |
icmpinfo->flags = IPT_ICMP_TYPE_ANY; |
171 |
icmpinfo->code[1] = 0xFF; |
179 |
icmpinfo->code[1] = 0xFF; |
172 |
} |
180 |
} |
173 |
|
181 |
|
Lines 186-194
Link Here
|
186 |
check_inverse(optarg, &invert, &optind, 0); |
194 |
check_inverse(optarg, &invert, &optind, 0); |
187 |
*nfcache |= parse_icmp(argv[optind-1], |
195 |
*nfcache |= parse_icmp(argv[optind-1], |
188 |
&icmpinfo->type, |
196 |
&icmpinfo->type, |
189 |
icmpinfo->code); |
197 |
icmpinfo->code, |
|
|
198 |
&icmpinfo->flags); |
190 |
if (invert) |
199 |
if (invert) |
191 |
icmpinfo->invflags |= IPT_ICMP_INV; |
200 |
icmpinfo->flags |= IPT_ICMP_INV; |
192 |
break; |
201 |
break; |
193 |
|
202 |
|
194 |
default: |
203 |
default: |
Lines 200-209
Link Here
|
200 |
|
209 |
|
201 |
static void print_icmptype(u_int8_t type, |
210 |
static void print_icmptype(u_int8_t type, |
202 |
u_int8_t code_min, u_int8_t code_max, |
211 |
u_int8_t code_min, u_int8_t code_max, |
203 |
int invert, |
212 |
u_int8_t flags, |
204 |
int numeric) |
213 |
int numeric) |
205 |
{ |
214 |
{ |
206 |
if (!numeric) { |
215 |
int invert = flags & IPT_ICMP_INV; |
|
|
216 |
|
217 |
if (!numeric && (!flags & IPT_ICMP_TYPE_ANY)) { |
207 |
unsigned int i; |
218 |
unsigned int i; |
208 |
|
219 |
|
209 |
for (i = 0; |
220 |
for (i = 0; |
Lines 226-232
Link Here
|
226 |
if (invert) |
237 |
if (invert) |
227 |
printf("!"); |
238 |
printf("!"); |
228 |
|
239 |
|
229 |
printf("type %u", type); |
240 |
|
|
|
241 |
if(flags & IPT_ICMP_TYPE_ANY) |
242 |
printf("type any"); |
243 |
else |
244 |
printf("type %u", type); |
245 |
|
230 |
if (code_min == 0 && code_max == 0xFF) |
246 |
if (code_min == 0 && code_max == 0xFF) |
231 |
printf(" "); |
247 |
printf(" "); |
232 |
else if (code_min == code_max) |
248 |
else if (code_min == code_max) |
Lines 245-256
Link Here
|
245 |
|
261 |
|
246 |
printf("icmp "); |
262 |
printf("icmp "); |
247 |
print_icmptype(icmp->type, icmp->code[0], icmp->code[1], |
263 |
print_icmptype(icmp->type, icmp->code[0], icmp->code[1], |
248 |
icmp->invflags & IPT_ICMP_INV, |
264 |
icmp->flags, |
249 |
numeric); |
265 |
numeric); |
250 |
|
266 |
|
251 |
if (icmp->invflags & ~IPT_ICMP_INV) |
267 |
if (icmp->flags & ~(IPT_ICMP_INV|IPT_ICMP_TYPE_ANY)) |
252 |
printf("Unknown invflags: 0x%X ", |
268 |
printf("Unknown icmp flags: 0x%X ", |
253 |
icmp->invflags & ~IPT_ICMP_INV); |
269 |
icmp->flags & ~(IPT_ICMP_INV|IPT_ICMP_TYPE_ANY)); |
254 |
} |
270 |
} |
255 |
|
271 |
|
256 |
/* Saves the match in parsable form to stdout. */ |
272 |
/* Saves the match in parsable form to stdout. */ |
Lines 258-267
Link Here
|
258 |
{ |
274 |
{ |
259 |
const struct ipt_icmp *icmp = (struct ipt_icmp *)match->data; |
275 |
const struct ipt_icmp *icmp = (struct ipt_icmp *)match->data; |
260 |
|
276 |
|
261 |
if (icmp->invflags & IPT_ICMP_INV) |
277 |
if (icmp->flags & IPT_ICMP_INV) |
262 |
printf("! "); |
278 |
printf("! "); |
263 |
|
279 |
|
264 |
printf("--icmp-type %u", icmp->type); |
280 |
if(icmp->flags & IPT_ICMP_TYPE_ANY) |
|
|
281 |
printf("--icmp-type any"); |
282 |
else |
283 |
printf("--icmp-type %u", icmp->type); |
265 |
if (icmp->code[0] != 0 || icmp->code[1] != 0xFF) |
284 |
if (icmp->code[0] != 0 || icmp->code[1] != 0xFF) |
266 |
printf("/%u", icmp->code[0]); |
285 |
printf("/%u", icmp->code[0]); |
267 |
printf(" "); |
286 |
printf(" "); |