From 2e783b2277665c467138e7685309622456c41db4 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 4 Mar 2018 09:28:58 +0100 Subject: 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 Signed-off-by: Pablo Neira Ayuso --- useful_functions.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'useful_functions.c') 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; } -- cgit v1.2.3