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, 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_ip(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
412 char **argv = *argv_p;
417 if (strcmp(*argv, "src") == 0) {
419 res = parse_ip_addr(&argc, &argv, sel, 12);
422 if (strcmp(*argv, "dst") == 0) {
424 res = parse_ip_addr(&argc, &argv, sel, 16);
427 if (strcmp(*argv, "tos") == 0 ||
428 matches(*argv, "dsfield") == 0) {
430 res = parse_u8(&argc, &argv, sel, 1, 0);
433 if (strcmp(*argv, "ihl") == 0) {
435 res = parse_u8(&argc, &argv, sel, 0, 0);
438 if (strcmp(*argv, "protocol") == 0) {
440 res = parse_u8(&argc, &argv, sel, 9, 0);
443 if (matches(*argv, "precedence") == 0) {
445 res = parse_u8(&argc, &argv, sel, 1, 0);
448 if (strcmp(*argv, "nofrag") == 0) {
450 res = pack_key16(sel, 0, 0x3FFF, 6, 0);
453 if (strcmp(*argv, "firstfrag") == 0) {
455 res = pack_key16(sel, 0, 0x1FFF, 6, 0);
458 if (strcmp(*argv, "df") == 0) {
460 res = pack_key16(sel, 0x4000, 0x4000, 6, 0);
463 if (strcmp(*argv, "mf") == 0) {
465 res = pack_key16(sel, 0x2000, 0x2000, 6, 0);
468 if (strcmp(*argv, "dport") == 0) {
470 res = parse_u16(&argc, &argv, sel, 22, 0);
473 if (strcmp(*argv, "sport") == 0) {
475 res = parse_u16(&argc, &argv, sel, 20, 0);
478 if (strcmp(*argv, "icmp_type") == 0) {
480 res = parse_u8(&argc, &argv, sel, 20, 0);
483 if (strcmp(*argv, "icmp_code") == 0) {
485 res = parse_u8(&argc, &argv, sel, 20, 1);
496 static int parse_ip6(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
500 char **argv = *argv_p;
505 if (strcmp(*argv, "src") == 0) {
507 res = parse_ip6_addr(&argc, &argv, sel, 8);
510 if (strcmp(*argv, "dst") == 0) {
512 res = parse_ip6_addr(&argc, &argv, sel, 24);
515 if (strcmp(*argv, "priority") == 0) {
517 res = parse_u8(&argc, &argv, sel, 4, 0);
520 if (strcmp(*argv, "protocol") == 0) {
522 res = parse_u8(&argc, &argv, sel, 6, 0);
525 if (strcmp(*argv, "flowlabel") == 0) {
527 res = parse_u32(&argc, &argv, sel, 0, 0);
530 if (strcmp(*argv, "dport") == 0) {
532 res = parse_u16(&argc, &argv, sel, 42, 0);
535 if (strcmp(*argv, "sport") == 0) {
537 res = parse_u16(&argc, &argv, sel, 40, 0);
540 if (strcmp(*argv, "icmp_type") == 0) {
542 res = parse_u8(&argc, &argv, sel, 40, 0);
545 if (strcmp(*argv, "icmp_code") == 0) {
547 res = parse_u8(&argc, &argv, sel, 41, 1);
558 #define parse_tcp parse_udp
559 static int parse_udp(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
563 char **argv = *argv_p;
568 if (strcmp(*argv, "src") == 0) {
570 res = parse_u16(&argc, &argv, sel, 0, -1);
573 if (strcmp(*argv, "dst") == 0) {
575 res = parse_u16(&argc, &argv, sel, 2, -1);
587 static int parse_icmp(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
591 char **argv = *argv_p;
596 if (strcmp(*argv, "type") == 0) {
598 res = parse_u8(&argc, &argv, sel, 0, -1);
601 if (strcmp(*argv, "code") == 0) {
603 res = parse_u8(&argc, &argv, sel, 1, -1);
614 static int parse_mark(int *argc_p, char ***argv_p, struct nlmsghdr *n)
618 char **argv = *argv_p;
619 struct tc_u32_mark mark;
624 if (get_u32(&mark.val, *argv, 0)) {
625 fprintf(stderr, "Illegal \"mark\" value\n");
630 if (get_u32(&mark.mask, *argv, 0)) {
631 fprintf(stderr, "Illegal \"mark\" mask\n");
636 if ((mark.val & mark.mask) != mark.val) {
637 fprintf(stderr, "Illegal \"mark\" (impossible combination)\n");
641 addattr_l(n, MAX_MSG, TCA_U32_MARK, &mark, sizeof(mark));
649 static int parse_selector(int *argc_p, char ***argv_p,
650 struct tc_u32_sel *sel, struct nlmsghdr *n)
653 char **argv = *argv_p;
659 if (matches(*argv, "u32") == 0) {
661 res = parse_u32(&argc, &argv, sel, 0, 0);
664 if (matches(*argv, "u16") == 0) {
666 res = parse_u16(&argc, &argv, sel, 0, 0);
669 if (matches(*argv, "u8") == 0) {
671 res = parse_u8(&argc, &argv, sel, 0, 0);
674 if (matches(*argv, "ip") == 0) {
676 res = parse_ip(&argc, &argv, sel);
679 if (matches(*argv, "ip6") == 0) {
681 res = parse_ip6(&argc, &argv, sel);
684 if (matches(*argv, "udp") == 0) {
686 res = parse_udp(&argc, &argv, sel);
689 if (matches(*argv, "tcp") == 0) {
691 res = parse_tcp(&argc, &argv, sel);
694 if (matches(*argv, "icmp") == 0) {
696 res = parse_icmp(&argc, &argv, sel);
699 if (matches(*argv, "mark") == 0) {
701 res = parse_mark(&argc, &argv, n);
713 static int parse_offset(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
716 char **argv = *argv_p;
719 if (matches(*argv, "plus") == 0) {
722 if (get_integer(&off, *argv, 0))
725 sel->flags |= TC_U32_OFFSET;
726 } else if (matches(*argv, "at") == 0) {
729 if (get_integer(&off, *argv, 0))
733 fprintf(stderr, "offset \"at\" must be even\n");
736 sel->flags |= TC_U32_VAROFFSET;
737 } else if (matches(*argv, "mask") == 0) {
740 if (get_u16(&mask, *argv, 16))
742 sel->offmask = htons(mask);
743 sel->flags |= TC_U32_VAROFFSET;
744 } else if (matches(*argv, "shift") == 0) {
747 if (get_integer(&shift, *argv, 0))
749 sel->offshift = shift;
750 sel->flags |= TC_U32_VAROFFSET;
751 } else if (matches(*argv, "eat") == 0) {
752 sel->flags |= TC_U32_EAT;
764 static int parse_hashkey(int *argc_p, char ***argv_p, struct tc_u32_sel *sel)
767 char **argv = *argv_p;
770 if (matches(*argv, "mask") == 0) {
773 if (get_u32(&mask, *argv, 16))
775 sel->hmask = htonl(mask);
776 } else if (matches(*argv, "at") == 0) {
779 if (get_integer(&num, *argv, 0))
795 static void print_ipv4(FILE *f, const struct tc_u32_key *key)
801 switch (ntohl(key->mask)) {
803 fprintf(f, "\n match IP ihl %u", ntohl(key->val) >> 24);
806 fprintf(f, "\n match IP dsfield %#x", ntohl(key->val) >> 16);
811 if (ntohl(key->mask) == 0x00ff0000) {
812 fprintf(f, "\n match IP protocol %d", ntohl(key->val) >> 16);
818 int bits = mask2bits(key->mask);
820 fprintf(f, "\n %s %s/%d",
821 key->off == 12 ? "match IP src" : "match IP dst",
822 inet_ntop(AF_INET, &key->val,
831 switch (ntohl(key->mask)) {
833 fprintf(f, "\n match sport %u",
834 ntohl(key->val) & 0xffff);
837 fprintf(f, "\n match dport %u",
838 ntohl(key->val) >> 16);
841 fprintf(f, "\n match sport %u, match dport %u",
842 ntohl(key->val) & 0xffff,
843 ntohl(key->val) >> 16);
847 /* XXX: Default print_raw */
851 static void print_raw(FILE *f, const struct tc_u32_key *key)
853 fprintf(f, "\n match %08x/%08x at %s%d",
854 (unsigned int)ntohl(key->val),
855 (unsigned int)ntohl(key->mask),
856 key->offmask ? "nexthdr+" : "",
860 static const struct {
863 void (*pprinter)(FILE *f, const struct tc_u32_key *key);
864 } u32_pprinters[] = {
866 {ETH_P_IP, 0, print_ipv4},
869 static void show_keys(FILE *f, const struct tc_u32_key *key)
876 for (i = 0; i < sizeof(u32_pprinters) / sizeof(u32_pprinters[0]); i++) {
877 if (u32_pprinters[i].proto == ntohs(f_proto)) {
879 u32_pprinters[i].pprinter(f, key);
888 static int u32_parse_opt(struct filter_util *qu, char *handle,
889 int argc, char **argv, struct nlmsghdr *n)
892 struct tc_u32_sel sel;
893 struct tc_u32_key keys[128];
895 struct tcmsg *t = NLMSG_DATA(n);
897 int sel_ok = 0, terminal_ok = 0;
902 memset(&sel, 0, sizeof(sel));
904 if (handle && get_u32_handle(&t->tcm_handle, handle)) {
905 fprintf(stderr, "Illegal filter ID\n");
912 tail = NLMSG_TAIL(n);
913 addattr_l(n, MAX_MSG, TCA_OPTIONS, NULL, 0);
916 if (matches(*argv, "match") == 0) {
918 if (parse_selector(&argc, &argv, &sel.sel, n)) {
919 fprintf(stderr, "Illegal \"match\"\n");
924 } else if (matches(*argv, "offset") == 0) {
926 if (parse_offset(&argc, &argv, &sel.sel)) {
927 fprintf(stderr, "Illegal \"offset\"\n");
931 } else if (matches(*argv, "hashkey") == 0) {
933 if (parse_hashkey(&argc, &argv, &sel.sel)) {
934 fprintf(stderr, "Illegal \"hashkey\"\n");
938 } else if (matches(*argv, "classid") == 0 ||
939 strcmp(*argv, "flowid") == 0) {
942 if (get_tc_classid(&handle, *argv)) {
943 fprintf(stderr, "Illegal \"classid\"\n");
946 addattr_l(n, MAX_MSG, TCA_U32_CLASSID, &handle, 4);
947 sel.sel.flags |= TC_U32_TERMINAL;
948 } else if (matches(*argv, "divisor") == 0) {
951 if (get_unsigned(&divisor, *argv, 0) ||
953 divisor > 0x100 || ((divisor - 1) & divisor)) {
954 fprintf(stderr, "Illegal \"divisor\"\n");
957 addattr_l(n, MAX_MSG, TCA_U32_DIVISOR, &divisor, 4);
958 } else if (matches(*argv, "order") == 0) {
960 if (get_u32(&order, *argv, 0)) {
961 fprintf(stderr, "Illegal \"order\"\n");
964 } else if (strcmp(*argv, "link") == 0) {
967 if (get_u32_handle(&handle, *argv)) {
968 fprintf(stderr, "Illegal \"link\"\n");
971 if (handle && TC_U32_NODE(handle)) {
972 fprintf(stderr, "\"link\" must be a hash table.\n");
975 addattr_l(n, MAX_MSG, TCA_U32_LINK, &handle, 4);
976 } else if (strcmp(*argv, "ht") == 0) {
979 if (get_u32_handle(&handle, *argv)) {
980 fprintf(stderr, "Illegal \"ht\"\n");
983 if (handle && TC_U32_NODE(handle)) {
984 fprintf(stderr, "\"ht\" must be a hash table.\n");
988 htid = (htid&0xFF000)|(handle&0xFFF00000);
990 htid = (handle&0xFFFFF000);
991 } else if (strcmp(*argv, "sample") == 0) {
993 unsigned divisor = 0x100;
996 struct tc_u32_sel sel;
997 struct tc_u32_key keys[4];
999 memset(&sel2, 0, sizeof(sel2));
1001 if (parse_selector(&argc, &argv, &sel2.sel, n)) {
1002 fprintf(stderr, "Illegal \"sample\"\n");
1005 if (sel2.sel.nkeys != 1) {
1006 fprintf(stderr, "\"sample\" must contain"
1007 " exactly ONE key.\n");
1010 if (*argv != 0 && strcmp(*argv, "divisor") == 0) {
1012 if (get_unsigned(&divisor, *argv, 0) || divisor == 0 ||
1013 divisor > 0x100 || ((divisor - 1) & divisor)) {
1014 fprintf(stderr, "Illegal sample \"divisor\"\n");
1019 hash = sel2.sel.keys[0].val&sel2.sel.keys[0].mask;
1022 htid = ((hash%divisor)<<12)|(htid&0xFFF00000);
1025 } else if (strcmp(*argv, "indev") == 0) {
1026 char ind[IFNAMSIZ + 1];
1027 memset(ind, 0, sizeof (ind));
1031 fprintf(stderr, "Illegal indev\n");
1034 strncpy(ind, *argv, sizeof (ind) - 1);
1035 addattr_l(n, MAX_MSG, TCA_U32_INDEV, ind, strlen(ind) + 1);
1037 } else if (matches(*argv, "action") == 0) {
1039 if (parse_action(&argc, &argv, TCA_U32_ACT, n)) {
1040 fprintf(stderr, "Illegal \"action\"\n");
1046 } else if (matches(*argv, "police") == 0) {
1048 if (parse_police(&argc, &argv, TCA_U32_POLICE, n)) {
1049 fprintf(stderr, "Illegal \"police\"\n");
1054 } else if (strcmp(*argv, "help") == 0) {
1058 fprintf(stderr, "What is \"%s\"?\n", *argv);
1065 /* We dont necessarily need class/flowids */
1067 sel.sel.flags |= TC_U32_TERMINAL;
1070 if (TC_U32_NODE(t->tcm_handle) && order != TC_U32_NODE(t->tcm_handle)) {
1071 fprintf(stderr, "\"order\" contradicts \"handle\"\n");
1074 t->tcm_handle |= order;
1078 addattr_l(n, MAX_MSG, TCA_U32_HASH, &htid, 4);
1080 addattr_l(n, MAX_MSG, TCA_U32_SEL, &sel,
1081 sizeof(sel.sel)+sel.sel.nkeys*sizeof(struct tc_u32_key));
1082 tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
1086 static int u32_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt,
1089 struct rtattr *tb[TCA_U32_MAX+1];
1090 struct tc_u32_sel *sel = NULL;
1091 struct tc_u32_pcnt *pf = NULL;
1096 parse_rtattr_nested(tb, TCA_U32_MAX, opt);
1100 fprintf(f, "fh %s ", sprint_u32_handle(handle, b1));
1102 if (TC_U32_NODE(handle)) {
1103 fprintf(f, "order %d ", TC_U32_NODE(handle));
1106 if (tb[TCA_U32_SEL]) {
1107 if (RTA_PAYLOAD(tb[TCA_U32_SEL]) < sizeof(*sel))
1110 sel = RTA_DATA(tb[TCA_U32_SEL]);
1113 if (tb[TCA_U32_DIVISOR]) {
1114 fprintf(f, "ht divisor %d ", *(__u32*)RTA_DATA(tb[TCA_U32_DIVISOR]));
1115 } else if (tb[TCA_U32_HASH]) {
1116 __u32 htid = *(__u32*)RTA_DATA(tb[TCA_U32_HASH]);
1117 fprintf(f, "key ht %x bkt %x ", TC_U32_USERHTID(htid),
1122 if (tb[TCA_U32_CLASSID]) {
1124 fprintf(f, "%sflowid %s ",
1125 !sel || !(sel->flags&TC_U32_TERMINAL) ? "*" : "",
1126 sprint_tc_classid(*(__u32*)RTA_DATA(tb[TCA_U32_CLASSID]), b1));
1127 } else if (sel && sel->flags&TC_U32_TERMINAL) {
1128 fprintf(f, "terminal flowid ??? ");
1130 if (tb[TCA_U32_LINK]) {
1132 fprintf(f, "link %s ",
1133 sprint_u32_handle(*(__u32*)RTA_DATA(tb[TCA_U32_LINK]), b1));
1136 if (tb[TCA_U32_PCNT]) {
1137 if (RTA_PAYLOAD(tb[TCA_U32_PCNT]) < sizeof(*pf)) {
1138 fprintf(f, "Broken perf counters \n");
1141 pf = RTA_DATA(tb[TCA_U32_PCNT]);
1144 if (sel && show_stats && NULL != pf)
1145 fprintf(f, " (rule hit %llu success %llu)",
1146 (unsigned long long) pf->rcnt,
1147 (unsigned long long) pf->rhit);
1149 if (tb[TCA_U32_MARK]) {
1150 struct tc_u32_mark *mark = RTA_DATA(tb[TCA_U32_MARK]);
1151 if (RTA_PAYLOAD(tb[TCA_U32_MARK]) < sizeof(*mark)) {
1152 fprintf(f, "\n Invalid mark (kernel&iproute2 mismatch)\n");
1154 fprintf(f, "\n mark 0x%04x 0x%04x (success %d)",
1155 mark->val, mark->mask, mark->success);
1162 for (i=0; i<sel->nkeys; i++) {
1163 show_keys(f, sel->keys + i);
1164 if (show_stats && NULL != pf)
1165 fprintf(f, " (success %llu ) ",
1166 (unsigned long long) pf->kcnts[i]);
1170 if (sel->flags&(TC_U32_VAROFFSET|TC_U32_OFFSET)) {
1171 fprintf(f, "\n offset ");
1172 if (sel->flags&TC_U32_VAROFFSET)
1173 fprintf(f, "%04x>>%d at %d ",
1174 ntohs(sel->offmask),
1175 sel->offshift, sel->offoff);
1177 fprintf(f, "plus %d ", sel->off);
1179 if (sel->flags&TC_U32_EAT)
1180 fprintf(f, " eat ");
1183 fprintf(f, "\n hash mask %08x at %d ",
1184 (unsigned int)htonl(sel->hmask), sel->hoff);
1188 if (tb[TCA_U32_POLICE]) {
1190 tc_print_police(f, tb[TCA_U32_POLICE]);
1192 if (tb[TCA_U32_INDEV]) {
1193 struct rtattr *idev = tb[TCA_U32_INDEV];
1194 fprintf(f, "\n input dev %s\n", (char *) RTA_DATA(idev));
1196 if (tb[TCA_U32_ACT]) {
1197 tc_print_action(f, tb[TCA_U32_ACT]);
1203 struct filter_util u32_filter_util = {
1205 .parse_fopt = u32_parse_opt,
1206 .print_fopt = u32_print_opt,