From: Stephen Hemminger Date: Mon, 18 Feb 2008 19:35:29 +0000 (-0800) Subject: decode the output of u32 matches X-Git-Tag: v2.6.25~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4c9ffc2f8cc9e4c4851b8b74ce656eb23fa17b72;p=thirdparty%2Fiproute2.git decode the output of u32 matches reverse the match offset/mask values into ip header matches. --- diff --git a/tc/f_u32.c b/tc/f_u32.c index 7e606d7d4..9bc4bb5de 100644 --- a/tc/f_u32.c +++ b/tc/f_u32.c @@ -797,11 +797,27 @@ static void show_key(FILE *f, const struct tc_u32_key *key) goto raw; switch (key->off) { + case 0: + switch (ntohl(key->mask)) { + case 0x0f000000: + fprintf(f, "\n ihl %u", ntohl(key->val) >> 24); + return; + case 0x00ff0000: + fprintf(f, "\n dsfield %#x", ntohl(key->val) >> 16); + return; + } + break; + case 8: + if (ntohl(key->mask) == 0x00ff0000) { + fprintf(f, "\n protocol %u", ntohl(key->val) >> 16); + return; + } + break; case 12: case 16: { int bits = mask2bits(key->mask); if (bits >= 0) { - fprintf(f, "\n %s %s/%d\n", + fprintf(f, "\n %s %s/%d", key->off == 12 ? "src" : "dst", inet_ntop(AF_INET, &key->val, abuf, sizeof(abuf)), @@ -812,11 +828,20 @@ static void show_key(FILE *f, const struct tc_u32_key *key) break; case 20: - case 22: - if (key->mask == ntohl(0xffff)) { - fprintf(f, "\n %s %u\n", - key->off == 20 ? "sport" : "dport", - (unsigned short) ntohl(key->val)); + switch (ntohl(key->mask)) { + case 0x0000ffff: + fprintf(f, "\n sport %u", + ntohl(key->val) & 0xffff); + return; + case 0xffff0000: + fprintf(f, "\n dport %u", + ntohl(key->val) >> 16); + return; + case 0xffffffff: + fprintf(f, "\n sport %u, port %u", + ntohl(key->val) & 0xffff, + ntohl(key->val) >> 16); + return; } }