summaryrefslogtreecommitdiffstats
path: root/useful_functions.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2018-03-04 09:28:58 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2018-04-11 10:09:35 +0200
commit2e783b2277665c467138e7685309622456c41db4 (patch)
tree41092663d581c85047539648cc8be019ec7fc273 /useful_functions.c
parentb5fbb8d786c914d67fa98db2a205f6cc983a166c (diff)
ebt_ip: add support for matching IGMP type
We already have ICMPv6 type/code matches (which can be used to distinguish different types of MLD packets). Add support for IPv4 IGMP matches in the same way. To reuse as much code as possible, the ICMP type/code handling functions are extended to allow passing a NULL code range. Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'useful_functions.c')
-rw-r--r--useful_functions.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/useful_functions.c b/useful_functions.c
index 8f54bae..8a34f82 100644
--- a/useful_functions.c
+++ b/useful_functions.c
@@ -486,8 +486,10 @@ int ebt_parse_icmp(const struct ebt_icmp_names *icmp_codes, size_t n_codes,
if (match < n_codes) {
type[0] = type[1] = icmp_codes[match].type;
- code[0] = icmp_codes[match].code_min;
- code[1] = icmp_codes[match].code_max;
+ if (code) {
+ code[0] = icmp_codes[match].code_min;
+ code[1] = icmp_codes[match].code_max;
+ }
} else {
char *next = parse_range(icmptype, 0, 255, number);
if (!next) {
@@ -499,17 +501,21 @@ int ebt_parse_icmp(const struct ebt_icmp_names *icmp_codes, size_t n_codes,
type[1] = (uint8_t) number[1];
switch (*next) {
case 0:
- code[0] = 0;
- code[1] = 255;
+ if (code) {
+ code[0] = 0;
+ code[1] = 255;
+ }
return 0;
case '/':
- next = parse_range(next+1, 0, 255, number);
- code[0] = (uint8_t) number[0];
- code[1] = (uint8_t) number[1];
- if (next == NULL)
- return -1;
- if (next && *next == 0)
- return 0;
+ if (code) {
+ next = parse_range(next+1, 0, 255, number);
+ code[0] = (uint8_t) number[0];
+ code[1] = (uint8_t) number[1];
+ if (next == NULL)
+ return -1;
+ if (next && *next == 0)
+ return 0;
+ }
/* fallthrough */
default:
ebt_print_error("unknown character %c", *next);
@@ -521,6 +527,9 @@ int ebt_parse_icmp(const struct ebt_icmp_names *icmp_codes, size_t n_codes,
static void print_icmp_code(uint8_t *code)
{
+ if (!code)
+ return;
+
if (code[0] == code[1])
printf("/%"PRIu8 " ", code[0]);
else
@@ -542,8 +551,8 @@ void ebt_print_icmp_type(const struct ebt_icmp_names *icmp_codes,
if (icmp_codes[i].type != type[0])
continue;
- if (icmp_codes[i].code_min == code[0] &&
- icmp_codes[i].code_max == code[1]) {
+ if (!code || (icmp_codes[i].code_min == code[0] &&
+ icmp_codes[i].code_max == code[1])) {
printf("%s ", icmp_codes[i].name);
return;
}