4 * This program is free software; you can u32istribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
10 * Match mark added by Catalin(ux aka Dino) BOIE <catab at umbrella.ro> [5 nov 2004]
19 #include <sys/socket.h>
20 #include <netinet/in.h>
21 #include <arpa/inet.h>
24 #include <linux/if_ether.h>
29 extern int show_pretty;
31 static void explain(void)
33 fprintf(stderr, "Usage: ... u32 [ match SELECTOR ... ] [ link HTID ]"
34 " [ classid CLASSID ]\n");
35 fprintf(stderr, " [ police POLICE_SPEC ]"
36 " [ offset OFFSET_SPEC ]\n");
37 fprintf(stderr, " [ ht HTID ] [ hashkey HASHKEY_SPEC ]\n");
38 fprintf(stderr, " [ sample SAMPLE ]\n");
39 fprintf(stderr, "or u32 divisor DIVISOR\n");
40 fprintf(stderr, "\n");
41 fprintf(stderr, "Where: SELECTOR := SAMPLE SAMPLE ...\n");
42 fprintf(stderr, " SAMPLE := { ip | ip6 | udp | tcp | icmp |"
43 " u{32|16|8} | mark } SAMPLE_ARGS [divisor DIVISOR]\n");
44 fprintf(stderr, " FILTERID := X:Y:Z\n");
45 fprintf(stderr, "\nNOTE: CLASSID is parsed at hexadecimal input.\n");
48 #define usage() return(-1)
50 int get_u32_handle(__u32 *handle, const char *str)
52 __u32 htid=0, hash=0, nodeid=0;
53 char *tmp = strchr(str, ':');
56 if (memcmp("0x", str, 2) == 0)
57 return get_u32(handle, str, 16);
60 htid = strtoul(str, &tmp, 16);
61 if (tmp == str && *str != ':' && *str != 0)
67 hash = strtoul(str, &tmp, 16);
68 if (tmp == str && *str != ':' && *str != 0)
74 nodeid = strtoul(str, &tmp, 16);
75 if (tmp == str && *str != 0)
81 *handle = (htid<<20)|(hash<<12)|nodeid;
85 char * sprint_u32_handle(__u32 handle, char *buf)
87 int bsize = SPRINT_BSIZE-1;
88 __u32 htid = TC_U32_HTID(handle);
89 __u32 hash = TC_U32_HASH(handle);
90 __u32 nodeid = TC_U32_NODE(handle);
94 snprintf(b, bsize, "none");
98 int l = snprintf(b, bsize, "%x:", htid>>20);
104 int l = snprintf(b, bsize, "%x", hash);
109 int l = snprintf(b, bsize, ":%x", nodeid);
115 snprintf(b, bsize, "[%08x] ", handle);
119 static int pack_key(struct tc_u32_sel *sel, __u32 key, __u32 mask,
120 int off, int offmask)
123 int hwm = sel->nkeys;
127 for (i=0; i<hwm; i++) {
128 if (sel->keys[i].off == off && sel->keys[i].offmask == offmask) {
129 __u32 intersect = mask&sel->keys[i].mask;
131 if ((key^sel->keys[i].val) & intersect)
133 sel->keys[i].val |= key;
134 sel->keys[i].mask |= mask;
143 sel->keys[hwm].val = key;
144 sel->keys[hwm].mask = mask;
145 sel->keys[hwm].off = off;
146 sel->keys[hwm].offmask = offmask;
151 static int pack_key32(struct tc_u32_sel *sel, __u32 key, __u32 mask,
152 int off, int offmask)
156 return pack_key(sel, key, mask, off, offmask);
159 static int pack_key16(struct tc_u32_sel *sel, __u32 key, __u32 mask,
160 int off, int offmask)
162 if (key > 0xFFFF || mask > 0xFFFF)
165 if ((off & 3) == 0) {
173 return pack_key(sel, key, mask, off, offmask);
176 static int pack_key8(struct tc_u32_sel *sel, __u32 key, __u32 mask, int off, int offmask)
178 if (key > 0xFF || mask > 0xFF)
181 if ((off & 3) == 0) {
184 } else if ((off & 3) == 1) {
187 } else if ((off & 3) == 2) {
195 return pack_key(sel, key, mask, off, offmask);
199 int parse_at(int *argc_p, char ***argv_p, int *off, int *offmask)
202 char **argv = *argv_p;
208 if (strlen(p) > strlen("nexthdr+") &&
209 memcmp(p, "nexthdr+", strlen("nexthdr+")) == 0) {
211 p += strlen("nexthdr+");
212 } else if (matches(*argv, "nexthdr+") == 0) {
218 if (get_integer(off, p, 0))
228 static int parse_u32(int *argc_p, char ***argv_p, struct tc_u32_sel *sel,
229 int off, int offmask)
233 char **argv = *argv_p;
240 if (get_u32(&key, *argv, 0))
244 if (get_u32(&mask, *argv, 16))
248 if (argc > 0 && strcmp(argv[0], "at") == 0) {
250 if (parse_at(&argc, &argv, &off, &offmask))
254 res = pack_key32(sel, key, mask, off, offmask);
260 static int parse_u16(int *argc_p, char ***argv_p, struct tc_u32_sel *sel,
261 int off, int offmask)
265 char **argv = *argv_p;
272 if (get_u32(&key, *argv, 0))
276 if (get_u32(&mask, *argv, 16))
280 if (argc > 0 && strcmp(argv[0], "at") == 0) {
282 if (parse_at(&argc, &argv, &off, &offmask))
285 res = pack_key16(sel, key, mask, off, offmask);
291 static int parse_u8(int *argc_p, char ***argv_p, struct tc_u32_sel *sel,
292 int off, int offmask)
296 char **argv = *argv_p;
303 if (get_u32(&key, *argv, 0))
307 if (get_u32(&mask, *argv, 16))
311 if (key > 0xFF || mask > 0xFF)
314 if (argc > 0 && strcmp(argv[0], "at") == 0) {
316 if (parse_at(&argc, &argv, &off, &offmask))
320 res = pack_key8(sel, key, mask, off, offmask);
326 static int parse_ip_addr(int *argc_p, char ***argv_p, struct tc_u32_sel *sel,
331 char **argv = *argv_p;
339 if (get_prefix_1(&addr, *argv, AF_INET))
343 if (argc > 0 && strcmp(argv[0], "at") == 0) {
345 if (parse_at(&argc, &argv, &off, &offmask))
351 mask = htonl(0xFFFFFFFF<<(32-addr.bitlen));
352 if (pack_key(sel, addr.data[0], mask, off, offmask) < 0)
361 static int parse_ip6_addr(int *argc_p, char ***argv_p,
362 struct tc_u32_sel *sel, int off)
366 char **argv = *argv_p;
375 if (get_prefix_1(&addr, *argv, AF_INET6))
379 if (argc > 0 && strcmp(argv[0], "at") == 0) {
381 if (parse_at(&argc, &argv, &off, &offmask))
386 for (i=0; i<plen; i+=32) {
387 // if (((i+31)&~0x1F)<=plen) {
388 if (i + 31 <= plen) {
389 res = pack_key(sel, addr.data[i/32],
390 0xFFFFFFFF, off+4*(i/32), offmask);
393 } else if (i < plen) {
394 __u32 mask = htonl(0xFFFFFFFF << (32 - (plen -i )));
395 res = pack_key(sel, addr.data[i/32],
396 mask, off+4*(i/32), offmask);
408 static int parse_ether_addr(int *argc_p, char ***argv_p,
409 struct tc_u32_sel *sel, int off)
413 char **argv = *argv_p;
422 if (sscanf(*argv, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
423 addr + 0, addr + 1, addr + 2,
424 addr + 3, addr + 4, addr + 5) != 6) {
425 fprintf(stderr, "parse_ether_addr: improperly formed address '%s'\n",
431 if (argc > 0 && strcmp(argv[0], "at") == 0) {
433 if (parse_at(&argc, &argv, &off, &offmask))
437 for (i = 0; i < 6; i += 2) {
438 key = *(__u16 *) (addr + i);
440 res = pack_key16(sel, key, 0xFFFF, off + i, offmask);
450 static int parse_ip(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
454 char **argv = *argv_p;
459 if (strcmp(*argv, "src") == 0) {
461 res = parse_ip_addr(&argc, &argv, sel, 12);
462 } else if (strcmp(*argv, "dst") == 0) {
464 res = parse_ip_addr(&argc, &argv, sel, 16);
465 } else if (strcmp(*argv, "tos") == 0 ||
466 matches(*argv, "dsfield") == 0) {
468 res = parse_u8(&argc, &argv, sel, 1, 0);
469 } else if (strcmp(*argv, "ihl") == 0) {
471 res = parse_u8(&argc, &argv, sel, 0, 0);
472 } else if (strcmp(*argv, "protocol") == 0) {
474 res = parse_u8(&argc, &argv, sel, 9, 0);
475 } else if (matches(*argv, "precedence") == 0) {
477 res = parse_u8(&argc, &argv, sel, 1, 0);
478 } else if (strcmp(*argv, "nofrag") == 0) {
480 res = pack_key16(sel, 0, 0x3FFF, 6, 0);
481 } else if (strcmp(*argv, "firstfrag") == 0) {
483 res = pack_key16(sel, 0, 0x1FFF, 6, 0);
484 } else if (strcmp(*argv, "df") == 0) {
486 res = pack_key16(sel, 0x4000, 0x4000, 6, 0);
487 } else if (strcmp(*argv, "mf") == 0) {
489 res = pack_key16(sel, 0x2000, 0x2000, 6, 0);
490 } else if (strcmp(*argv, "dport") == 0) {
492 res = parse_u16(&argc, &argv, sel, 22, 0);
493 } else if (strcmp(*argv, "sport") == 0) {
495 res = parse_u16(&argc, &argv, sel, 20, 0);
496 } else if (strcmp(*argv, "icmp_type") == 0) {
498 res = parse_u8(&argc, &argv, sel, 20, 0);
499 } else if (strcmp(*argv, "icmp_code") == 0) {
501 res = parse_u8(&argc, &argv, sel, 20, 1);
510 static int parse_ip6(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
514 char **argv = *argv_p;
519 if (strcmp(*argv, "src") == 0) {
521 res = parse_ip6_addr(&argc, &argv, sel, 8);
522 } else if (strcmp(*argv, "dst") == 0) {
524 res = parse_ip6_addr(&argc, &argv, sel, 24);
525 } else if (strcmp(*argv, "priority") == 0) {
527 res = parse_u8(&argc, &argv, sel, 4, 0);
528 } else if (strcmp(*argv, "protocol") == 0) {
530 res = parse_u8(&argc, &argv, sel, 6, 0);
531 } else if (strcmp(*argv, "flowlabel") == 0) {
533 res = parse_u32(&argc, &argv, sel, 0, 0);
534 } else if (strcmp(*argv, "dport") == 0) {
536 res = parse_u16(&argc, &argv, sel, 42, 0);
537 } else if (strcmp(*argv, "sport") == 0) {
539 res = parse_u16(&argc, &argv, sel, 40, 0);
540 } else if (strcmp(*argv, "icmp_type") == 0) {
542 res = parse_u8(&argc, &argv, sel, 40, 0);
543 } else if (strcmp(*argv, "icmp_code") == 0) {
545 res = parse_u8(&argc, &argv, sel, 41, 1);
554 static int parse_ether(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
558 char **argv = *argv_p;
563 if (strcmp(*argv, "src") == 0) {
565 res = parse_ether_addr(&argc, &argv, sel, -8);
566 } else if (strcmp(*argv, "dst") == 0) {
568 res = parse_ether_addr(&argc, &argv, sel, -14);
570 fprintf(stderr, "Unknown match: ether %s\n", *argv);
579 #define parse_tcp parse_udp
580 static int parse_udp(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
584 char **argv = *argv_p;
589 if (strcmp(*argv, "src") == 0) {
591 res = parse_u16(&argc, &argv, sel, 0, -1);
592 } else if (strcmp(*argv, "dst") == 0) {
594 res = parse_u16(&argc, &argv, sel, 2, -1);
604 static int parse_icmp(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
608 char **argv = *argv_p;
613 if (strcmp(*argv, "type") == 0) {
615 res = parse_u8(&argc, &argv, sel, 0, -1);
616 } else if (strcmp(*argv, "code") == 0) {
618 res = parse_u8(&argc, &argv, sel, 1, -1);
627 static int parse_mark(int *argc_p, char ***argv_p, struct nlmsghdr *n)
631 char **argv = *argv_p;
632 struct tc_u32_mark mark;
637 if (get_u32(&mark.val, *argv, 0)) {
638 fprintf(stderr, "Illegal \"mark\" value\n");
643 if (get_u32(&mark.mask, *argv, 0)) {
644 fprintf(stderr, "Illegal \"mark\" mask\n");
649 if ((mark.val & mark.mask) != mark.val) {
650 fprintf(stderr, "Illegal \"mark\" (impossible combination)\n");
654 addattr_l(n, MAX_MSG, TCA_U32_MARK, &mark, sizeof(mark));
662 static int parse_selector(int *argc_p, char ***argv_p,
663 struct tc_u32_sel *sel, struct nlmsghdr *n)
666 char **argv = *argv_p;
672 if (matches(*argv, "u32") == 0) {
674 res = parse_u32(&argc, &argv, sel, 0, 0);
675 } else if (matches(*argv, "u16") == 0) {
677 res = parse_u16(&argc, &argv, sel, 0, 0);
678 } else if (matches(*argv, "u8") == 0) {
680 res = parse_u8(&argc, &argv, sel, 0, 0);
681 } else if (matches(*argv, "ip") == 0) {
683 res = parse_ip(&argc, &argv, sel);
684 } else if (matches(*argv, "ip6") == 0) {
686 res = parse_ip6(&argc, &argv, sel);
687 } else if (matches(*argv, "udp") == 0) {
689 res = parse_udp(&argc, &argv, sel);
690 } else if (matches(*argv, "tcp") == 0) {
692 res = parse_tcp(&argc, &argv, sel);
693 } else if (matches(*argv, "icmp") == 0) {
695 res = parse_icmp(&argc, &argv, sel);
696 } else if (matches(*argv, "mark") == 0) {
698 res = parse_mark(&argc, &argv, n);
699 } else if (matches(*argv, "ether") == 0) {
701 res = parse_ether(&argc, &argv, sel);
710 static int parse_offset(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
713 char **argv = *argv_p;
716 if (matches(*argv, "plus") == 0) {
719 if (get_integer(&off, *argv, 0))
722 sel->flags |= TC_U32_OFFSET;
723 } else if (matches(*argv, "at") == 0) {
726 if (get_integer(&off, *argv, 0))
730 fprintf(stderr, "offset \"at\" must be even\n");
733 sel->flags |= TC_U32_VAROFFSET;
734 } else if (matches(*argv, "mask") == 0) {
737 if (get_u16(&mask, *argv, 16))
739 sel->offmask = htons(mask);
740 sel->flags |= TC_U32_VAROFFSET;
741 } else if (matches(*argv, "shift") == 0) {
744 if (get_integer(&shift, *argv, 0))
746 sel->offshift = shift;
747 sel->flags |= TC_U32_VAROFFSET;
748 } else if (matches(*argv, "eat") == 0) {
749 sel->flags |= TC_U32_EAT;
761 static int parse_hashkey(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
764 char **argv = *argv_p;
767 if (matches(*argv, "mask") == 0) {
770 if (get_u32(&mask, *argv, 16))
772 sel->hmask = htonl(mask);
773 } else if (matches(*argv, "at") == 0) {
776 if (get_integer(&num, *argv, 0))
792 static void print_ipv4(FILE *f, const struct tc_u32_key *key)
798 switch (ntohl(key->mask)) {
800 fprintf(f, "\n match IP ihl %u", ntohl(key->val) >> 24);
803 fprintf(f, "\n match IP dsfield %#x", ntohl(key->val) >> 16);
808 if (ntohl(key->mask) == 0x00ff0000) {
809 fprintf(f, "\n match IP protocol %d", ntohl(key->val) >> 16);
815 int bits = mask2bits(key->mask);
817 fprintf(f, "\n %s %s/%d",
818 key->off == 12 ? "match IP src" : "match IP dst",
819 inet_ntop(AF_INET, &key->val,
828 switch (ntohl(key->mask)) {
830 fprintf(f, "\n match sport %u",
831 ntohl(key->val) & 0xffff);
834 fprintf(f, "\n match dport %u",
835 ntohl(key->val) >> 16);
838 fprintf(f, "\n match sport %u, match dport %u",
839 ntohl(key->val) & 0xffff,
840 ntohl(key->val) >> 16);
844 /* XXX: Default print_raw */
848 static void print_raw(FILE *f, const struct tc_u32_key *key)
850 fprintf(f, "\n match %08x/%08x at %s%d",
851 (unsigned int)ntohl(key->val),
852 (unsigned int)ntohl(key->mask),
853 key->offmask ? "nexthdr+" : "",
857 static const struct {
860 void (*pprinter)(FILE *f, const struct tc_u32_key *key);
861 } u32_pprinters[] = {
863 {ETH_P_IP, 0, print_ipv4},
866 static void show_keys(FILE *f, const struct tc_u32_key *key)
873 for (i = 0; i < sizeof(u32_pprinters) / sizeof(u32_pprinters[0]); i++) {
874 if (u32_pprinters[i].proto == ntohs(f_proto)) {
876 u32_pprinters[i].pprinter(f, key);
885 static int u32_parse_opt(struct filter_util *qu, char *handle,
886 int argc, char **argv, struct nlmsghdr *n)
889 struct tc_u32_sel sel;
890 struct tc_u32_key keys[128];
892 struct tcmsg *t = NLMSG_DATA(n);
894 int sel_ok = 0, terminal_ok = 0;
899 memset(&sel, 0, sizeof(sel));
901 if (handle && get_u32_handle(&t->tcm_handle, handle)) {
902 fprintf(stderr, "Illegal filter ID\n");
909 tail = NLMSG_TAIL(n);
910 addattr_l(n, MAX_MSG, TCA_OPTIONS, NULL, 0);
913 if (matches(*argv, "match") == 0) {
915 if (parse_selector(&argc, &argv, &sel.sel, n)) {
916 fprintf(stderr, "Illegal \"match\"\n");
921 } else if (matches(*argv, "offset") == 0) {
923 if (parse_offset(&argc, &argv, &sel.sel)) {
924 fprintf(stderr, "Illegal \"offset\"\n");
928 } else if (matches(*argv, "hashkey") == 0) {
930 if (parse_hashkey(&argc, &argv, &sel.sel)) {
931 fprintf(stderr, "Illegal \"hashkey\"\n");
935 } else if (matches(*argv, "classid") == 0 ||
936 strcmp(*argv, "flowid") == 0) {
939 if (get_tc_classid(&handle, *argv)) {
940 fprintf(stderr, "Illegal \"classid\"\n");
943 addattr_l(n, MAX_MSG, TCA_U32_CLASSID, &handle, 4);
944 sel.sel.flags |= TC_U32_TERMINAL;
945 } else if (matches(*argv, "divisor") == 0) {
948 if (get_unsigned(&divisor, *argv, 0) ||
950 divisor > 0x100 || ((divisor - 1) & divisor)) {
951 fprintf(stderr, "Illegal \"divisor\"\n");
954 addattr_l(n, MAX_MSG, TCA_U32_DIVISOR, &divisor, 4);
955 } else if (matches(*argv, "order") == 0) {
957 if (get_u32(&order, *argv, 0)) {
958 fprintf(stderr, "Illegal \"order\"\n");
961 } else if (strcmp(*argv, "link") == 0) {
964 if (get_u32_handle(&handle, *argv)) {
965 fprintf(stderr, "Illegal \"link\"\n");
968 if (handle && TC_U32_NODE(handle)) {
969 fprintf(stderr, "\"link\" must be a hash table.\n");
972 addattr_l(n, MAX_MSG, TCA_U32_LINK, &handle, 4);
973 } else if (strcmp(*argv, "ht") == 0) {
976 if (get_u32_handle(&handle, *argv)) {
977 fprintf(stderr, "Illegal \"ht\"\n");
980 if (handle && TC_U32_NODE(handle)) {
981 fprintf(stderr, "\"ht\" must be a hash table.\n");
985 htid = (htid&0xFF000)|(handle&0xFFF00000);
987 htid = (handle&0xFFFFF000);
988 } else if (strcmp(*argv, "sample") == 0) {
990 unsigned divisor = 0x100;
993 struct tc_u32_sel sel;
994 struct tc_u32_key keys[4];
996 memset(&sel2, 0, sizeof(sel2));
998 if (parse_selector(&argc, &argv, &sel2.sel, n)) {
999 fprintf(stderr, "Illegal \"sample\"\n");
1002 if (sel2.sel.nkeys != 1) {
1003 fprintf(stderr, "\"sample\" must contain"
1004 " exactly ONE key.\n");
1007 if (*argv != 0 && strcmp(*argv, "divisor") == 0) {
1009 if (get_unsigned(&divisor, *argv, 0) || divisor == 0 ||
1010 divisor > 0x100 || ((divisor - 1) & divisor)) {
1011 fprintf(stderr, "Illegal sample \"divisor\"\n");
1016 hash = sel2.sel.keys[0].val&sel2.sel.keys[0].mask;
1019 htid = ((hash%divisor)<<12)|(htid&0xFFF00000);
1022 } else if (strcmp(*argv, "indev") == 0) {
1023 char ind[IFNAMSIZ + 1];
1024 memset(ind, 0, sizeof (ind));
1028 fprintf(stderr, "Illegal indev\n");
1031 strncpy(ind, *argv, sizeof (ind) - 1);
1032 addattr_l(n, MAX_MSG, TCA_U32_INDEV, ind, strlen(ind) + 1);
1034 } else if (matches(*argv, "action") == 0) {
1036 if (parse_action(&argc, &argv, TCA_U32_ACT, n)) {
1037 fprintf(stderr, "Illegal \"action\"\n");
1043 } else if (matches(*argv, "police") == 0) {
1045 if (parse_police(&argc, &argv, TCA_U32_POLICE, n)) {
1046 fprintf(stderr, "Illegal \"police\"\n");
1051 } else if (strcmp(*argv, "help") == 0) {
1055 fprintf(stderr, "What is \"%s\"?\n", *argv);
1062 /* We dont necessarily need class/flowids */
1064 sel.sel.flags |= TC_U32_TERMINAL;
1067 if (TC_U32_NODE(t->tcm_handle) && order != TC_U32_NODE(t->tcm_handle)) {
1068 fprintf(stderr, "\"order\" contradicts \"handle\"\n");
1071 t->tcm_handle |= order;
1075 addattr_l(n, MAX_MSG, TCA_U32_HASH, &htid, 4);
1077 addattr_l(n, MAX_MSG, TCA_U32_SEL, &sel,
1078 sizeof(sel.sel)+sel.sel.nkeys*sizeof(struct tc_u32_key));
1079 tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
1083 static int u32_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt,
1086 struct rtattr *tb[TCA_U32_MAX+1];
1087 struct tc_u32_sel *sel = NULL;
1088 struct tc_u32_pcnt *pf = NULL;
1093 parse_rtattr_nested(tb, TCA_U32_MAX, opt);
1097 fprintf(f, "fh %s ", sprint_u32_handle(handle, b1));
1099 if (TC_U32_NODE(handle)) {
1100 fprintf(f, "order %d ", TC_U32_NODE(handle));
1103 if (tb[TCA_U32_SEL]) {
1104 if (RTA_PAYLOAD(tb[TCA_U32_SEL]) < sizeof(*sel))
1107 sel = RTA_DATA(tb[TCA_U32_SEL]);
1110 if (tb[TCA_U32_DIVISOR]) {
1111 fprintf(f, "ht divisor %d ", *(__u32*)RTA_DATA(tb[TCA_U32_DIVISOR]));
1112 } else if (tb[TCA_U32_HASH]) {
1113 __u32 htid = *(__u32*)RTA_DATA(tb[TCA_U32_HASH]);
1114 fprintf(f, "key ht %x bkt %x ", TC_U32_USERHTID(htid),
1119 if (tb[TCA_U32_CLASSID]) {
1121 fprintf(f, "%sflowid %s ",
1122 !sel || !(sel->flags&TC_U32_TERMINAL) ? "*" : "",
1123 sprint_tc_classid(*(__u32*)RTA_DATA(tb[TCA_U32_CLASSID]), b1));
1124 } else if (sel && sel->flags&TC_U32_TERMINAL) {
1125 fprintf(f, "terminal flowid ??? ");
1127 if (tb[TCA_U32_LINK]) {
1129 fprintf(f, "link %s ",
1130 sprint_u32_handle(*(__u32*)RTA_DATA(tb[TCA_U32_LINK]), b1));
1133 if (tb[TCA_U32_PCNT]) {
1134 if (RTA_PAYLOAD(tb[TCA_U32_PCNT]) < sizeof(*pf)) {
1135 fprintf(f, "Broken perf counters \n");
1138 pf = RTA_DATA(tb[TCA_U32_PCNT]);
1141 if (sel && show_stats && NULL != pf)
1142 fprintf(f, " (rule hit %llu success %llu)",
1143 (unsigned long long) pf->rcnt,
1144 (unsigned long long) pf->rhit);
1146 if (tb[TCA_U32_MARK]) {
1147 struct tc_u32_mark *mark = RTA_DATA(tb[TCA_U32_MARK]);
1148 if (RTA_PAYLOAD(tb[TCA_U32_MARK]) < sizeof(*mark)) {
1149 fprintf(f, "\n Invalid mark (kernel&iproute2 mismatch)\n");
1151 fprintf(f, "\n mark 0x%04x 0x%04x (success %d)",
1152 mark->val, mark->mask, mark->success);
1159 for (i=0; i<sel->nkeys; i++) {
1160 show_keys(f, sel->keys + i);
1161 if (show_stats && NULL != pf)
1162 fprintf(f, " (success %llu ) ",
1163 (unsigned long long) pf->kcnts[i]);
1167 if (sel->flags&(TC_U32_VAROFFSET|TC_U32_OFFSET)) {
1168 fprintf(f, "\n offset ");
1169 if (sel->flags&TC_U32_VAROFFSET)
1170 fprintf(f, "%04x>>%d at %d ",
1171 ntohs(sel->offmask),
1172 sel->offshift, sel->offoff);
1174 fprintf(f, "plus %d ", sel->off);
1176 if (sel->flags&TC_U32_EAT)
1177 fprintf(f, " eat ");
1180 fprintf(f, "\n hash mask %08x at %d ",
1181 (unsigned int)htonl(sel->hmask), sel->hoff);
1185 if (tb[TCA_U32_POLICE]) {
1187 tc_print_police(f, tb[TCA_U32_POLICE]);
1189 if (tb[TCA_U32_INDEV]) {
1190 struct rtattr *idev = tb[TCA_U32_INDEV];
1191 fprintf(f, "\n input dev %s\n", (char *) RTA_DATA(idev));
1193 if (tb[TCA_U32_ACT]) {
1194 tc_print_action(f, tb[TCA_U32_ACT]);
1200 struct filter_util u32_filter_util = {
1202 .parse_fopt = u32_parse_opt,
1203 .print_fopt = u32_print_opt,