osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 1 | /* |
| 2 | * q_prio.c PRIO. |
| 3 | * |
| 4 | * This program is free software; you can redistribute 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. |
| 8 | * |
| 9 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> |
| 10 | * |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <stdio.h> |
| 14 | #include <stdlib.h> |
| 15 | #include <unistd.h> |
| 16 | #include <syslog.h> |
| 17 | #include <fcntl.h> |
| 18 | #include <sys/socket.h> |
| 19 | #include <netinet/in.h> |
| 20 | #include <arpa/inet.h> |
| 21 | #include <string.h> |
| 22 | |
| 23 | #include "utils.h" |
| 24 | #include "tc_util.h" |
| 25 | |
| 26 | static void explain(void) |
| 27 | { |
PJ Waskiewicz | 292ce96 | 2007-08-14 11:21:24 -0700 | [diff] [blame] | 28 | fprintf(stderr, "Usage: ... prio bands NUMBER priomap P1 P2...[multiqueue]\n"); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 29 | } |
| 30 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 31 | static int prio_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) |
| 32 | { |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 33 | int pmap_mode = 0; |
| 34 | int idx = 0; |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame^] | 35 | struct tc_prio_qopt opt = {3, { 1, 2, 2, 2, 1, 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 } }; |
PJ Waskiewicz | 292ce96 | 2007-08-14 11:21:24 -0700 | [diff] [blame] | 36 | struct rtattr *nest; |
| 37 | unsigned char mq = 0; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 38 | |
| 39 | while (argc > 0) { |
| 40 | if (strcmp(*argv, "bands") == 0) { |
| 41 | if (pmap_mode) |
| 42 | explain(); |
| 43 | NEXT_ARG(); |
| 44 | if (get_integer(&opt.bands, *argv, 10)) { |
| 45 | fprintf(stderr, "Illegal \"bands\"\n"); |
| 46 | return -1; |
| 47 | } |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 48 | } else if (strcmp(*argv, "priomap") == 0) { |
| 49 | if (pmap_mode) { |
| 50 | fprintf(stderr, "Error: duplicate priomap\n"); |
| 51 | return -1; |
| 52 | } |
| 53 | pmap_mode = 1; |
PJ Waskiewicz | 292ce96 | 2007-08-14 11:21:24 -0700 | [diff] [blame] | 54 | } else if (strcmp(*argv, "multiqueue") == 0) { |
| 55 | mq = 1; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 56 | } else if (strcmp(*argv, "help") == 0) { |
| 57 | explain(); |
| 58 | return -1; |
| 59 | } else { |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame^] | 60 | unsigned int band; |
| 61 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 62 | if (!pmap_mode) { |
| 63 | fprintf(stderr, "What is \"%s\"?\n", *argv); |
| 64 | explain(); |
| 65 | return -1; |
| 66 | } |
| 67 | if (get_unsigned(&band, *argv, 10)) { |
| 68 | fprintf(stderr, "Illegal \"priomap\" element\n"); |
| 69 | return -1; |
| 70 | } |
Li Wei | 3c4f545 | 2012-06-18 14:33:38 +0800 | [diff] [blame] | 71 | if (band >= opt.bands) { |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 72 | fprintf(stderr, "\"priomap\" element is out of bands\n"); |
| 73 | return -1; |
| 74 | } |
| 75 | if (idx > TC_PRIO_MAX) { |
| 76 | fprintf(stderr, "\"priomap\" index > TC_PRIO_MAX=%u\n", TC_PRIO_MAX); |
| 77 | return -1; |
| 78 | } |
| 79 | opt.priomap[idx++] = band; |
| 80 | } |
| 81 | argc--; argv++; |
| 82 | } |
| 83 | |
| 84 | /* |
| 85 | if (pmap_mode) { |
| 86 | for (; idx < TC_PRIO_MAX; idx++) |
| 87 | opt.priomap[idx] = opt.priomap[TC_PRIO_BESTEFFORT]; |
| 88 | } |
| 89 | */ |
PJ Waskiewicz | 292ce96 | 2007-08-14 11:21:24 -0700 | [diff] [blame] | 90 | nest = addattr_nest_compat(n, 1024, TCA_OPTIONS, &opt, sizeof(opt)); |
| 91 | if (mq) |
| 92 | addattr_l(n, 1024, TCA_PRIO_MQ, NULL, 0); |
| 93 | addattr_nest_compat_end(n, nest); |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 94 | return 0; |
| 95 | } |
| 96 | |
osdl.org!shemminger | 78d55b6 | 2004-06-02 20:22:08 +0000 | [diff] [blame] | 97 | int prio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 98 | { |
| 99 | int i; |
| 100 | struct tc_prio_qopt *qopt; |
PJ Waskiewicz | 292ce96 | 2007-08-14 11:21:24 -0700 | [diff] [blame] | 101 | struct rtattr *tb[TCA_PRIO_MAX+1]; |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 102 | |
| 103 | if (opt == NULL) |
| 104 | return 0; |
| 105 | |
PJ Waskiewicz | 292ce96 | 2007-08-14 11:21:24 -0700 | [diff] [blame] | 106 | if (parse_rtattr_nested_compat(tb, TCA_PRIO_MAX, opt, qopt, |
| 107 | sizeof(*qopt))) |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame^] | 108 | return -1; |
PJ Waskiewicz | 292ce96 | 2007-08-14 11:21:24 -0700 | [diff] [blame] | 109 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 110 | fprintf(f, "bands %u priomap ", qopt->bands); |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame^] | 111 | for (i = 0; i <= TC_PRIO_MAX; i++) |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 112 | fprintf(f, " %d", qopt->priomap[i]); |
PJ Waskiewicz | 292ce96 | 2007-08-14 11:21:24 -0700 | [diff] [blame] | 113 | |
| 114 | if (tb[TCA_PRIO_MQ]) |
| 115 | fprintf(f, " multiqueue: %s ", |
Stephen Hemminger | ff24746 | 2012-04-10 08:47:55 -0700 | [diff] [blame] | 116 | rta_getattr_u8(tb[TCA_PRIO_MQ]) ? "on" : "off"); |
PJ Waskiewicz | 292ce96 | 2007-08-14 11:21:24 -0700 | [diff] [blame] | 117 | |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 118 | return 0; |
| 119 | } |
| 120 | |
net[shemminger]!kaber | 95812b5 | 2004-09-28 18:35:49 +0000 | [diff] [blame] | 121 | struct qdisc_util prio_qdisc_util = { |
Stephen Hemminger | 32a121c | 2016-03-21 11:48:36 -0700 | [diff] [blame^] | 122 | .id = "prio", |
osdl.net!shemminger | f2f99e2 | 2004-08-31 17:45:21 +0000 | [diff] [blame] | 123 | .parse_qopt = prio_parse_opt, |
| 124 | .print_qopt = prio_print_opt, |
osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 125 | }; |