]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
decode the output of u32 matches
authorStephen Hemminger <stephen.hemminger@vyatta.com>
Mon, 18 Feb 2008 19:35:29 +0000 (11:35 -0800)
committerStephen Hemminger <stephen.hemminger@vyatta.com>
Mon, 18 Feb 2008 19:35:29 +0000 (11:35 -0800)
reverse the match offset/mask values into ip header matches.

tc/f_u32.c

index 7e606d7d41126ce294893402d2ba6eb7770f7e45..9bc4bb5de9b728e494ca21a3cc14b254c9252093 100644 (file)
@@ -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;
                }
        }