]>
Commit | Line | Data |
---|---|---|
c86f3494 PM |
1 | /* |
2 | * q_drr.c DRR. | |
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: Patrick McHardy <kaber@trash.net> | |
10 | * | |
11 | */ | |
12 | ||
13 | #include <stdio.h> | |
14 | #include <stdlib.h> | |
15 | #include <unistd.h> | |
c86f3494 PM |
16 | #include <fcntl.h> |
17 | #include <sys/socket.h> | |
18 | #include <netinet/in.h> | |
19 | #include <arpa/inet.h> | |
20 | #include <string.h> | |
21 | ||
22 | #include "utils.h" | |
23 | #include "tc_util.h" | |
24 | ||
25 | static void explain(void) | |
26 | { | |
27 | fprintf(stderr, "Usage: ... drr\n"); | |
28 | } | |
29 | ||
30 | static void explain2(void) | |
31 | { | |
32 | fprintf(stderr, "Usage: ... drr quantum SIZE\n"); | |
33 | } | |
34 | ||
c86f3494 | 35 | |
859af0a5 SH |
36 | static int drr_parse_opt(struct qdisc_util *qu, int argc, char **argv, |
37 | struct nlmsghdr *n, const char *dev) | |
c86f3494 | 38 | { |
5582c0cf | 39 | while (argc) { |
c86f3494 PM |
40 | if (strcmp(*argv, "help") == 0) { |
41 | explain(); | |
42 | return -1; | |
43 | } else { | |
44 | fprintf(stderr, "What is \"%s\"?\n", *argv); | |
45 | explain(); | |
46 | return -1; | |
47 | } | |
c86f3494 PM |
48 | } |
49 | return 0; | |
50 | } | |
51 | ||
52 | static int drr_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, | |
927e3cfb | 53 | struct nlmsghdr *n, const char *dev) |
c86f3494 PM |
54 | { |
55 | struct rtattr *tail; | |
56 | __u32 tmp; | |
57 | ||
58 | tail = NLMSG_TAIL(n); | |
59 | addattr_l(n, 1024, TCA_OPTIONS, NULL, 0); | |
60 | ||
61 | while (argc > 0) { | |
62 | if (strcmp(*argv, "quantum") == 0) { | |
63 | NEXT_ARG(); | |
64 | if (get_size(&tmp, *argv)) { | |
65 | fprintf(stderr, "Illegal \"quantum\"\n"); | |
66 | return -1; | |
67 | } | |
68 | addattr_l(n, 1024, TCA_DRR_QUANTUM, &tmp, sizeof(tmp)); | |
69 | } else if (strcmp(*argv, "help") == 0) { | |
70 | explain2(); | |
71 | return -1; | |
72 | } else { | |
73 | fprintf(stderr, "What is \"%s\"?\n", *argv); | |
74 | explain2(); | |
75 | return -1; | |
76 | } | |
77 | argc--; argv++; | |
78 | } | |
79 | ||
80 | tail->rta_len = (void *) NLMSG_TAIL(n) - (void *)tail; | |
81 | return 0; | |
82 | } | |
83 | ||
84 | static int drr_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) | |
85 | { | |
86 | struct rtattr *tb[TCA_DRR_MAX + 1]; | |
32a121cb | 87 | |
c86f3494 PM |
88 | SPRINT_BUF(b1); |
89 | ||
90 | if (opt == NULL) | |
91 | return 0; | |
92 | ||
93 | parse_rtattr_nested(tb, TCA_DRR_MAX, opt); | |
94 | ||
95 | if (tb[TCA_DRR_QUANTUM]) | |
96 | fprintf(f, "quantum %s ", | |
ff24746c | 97 | sprint_size(rta_getattr_u32(tb[TCA_DRR_QUANTUM]), b1)); |
c86f3494 PM |
98 | return 0; |
99 | } | |
100 | ||
101 | static int drr_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats) | |
102 | { | |
103 | struct tc_drr_stats *x; | |
32a121cb | 104 | |
c86f3494 PM |
105 | SPRINT_BUF(b1); |
106 | ||
107 | if (xstats == NULL) | |
108 | return 0; | |
109 | if (RTA_PAYLOAD(xstats) < sizeof(*x)) | |
110 | return -1; | |
111 | x = RTA_DATA(xstats); | |
112 | ||
113 | fprintf(f, " deficit %s ", sprint_size(x->deficit, b1)); | |
114 | return 0; | |
115 | } | |
116 | ||
117 | struct qdisc_util drr_qdisc_util = { | |
118 | .id = "drr", | |
119 | .parse_qopt = drr_parse_opt, | |
120 | .print_qopt = drr_print_opt, | |
121 | .print_xstats = drr_print_xstats, | |
122 | .parse_copt = drr_parse_class_opt, | |
123 | .print_copt = drr_print_opt, | |
124 | }; |