Fix build break in 64bit architectures
[platform/upstream/iproute2.git] / tc / q_qfq.c
1 /*
2  * q_qfq.c      QFQ.
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:     Stephen Hemminger <shemminger@vyatta.com>
10  *              Fabio Checconi <fabio@gandalf.sssup.it>
11  *
12  */
13 #include <fcntl.h>
14 #include <sys/socket.h>
15 #include <netinet/in.h>
16 #include <arpa/inet.h>
17 #include <string.h>
18
19 #include "utils.h"
20 #include "tc_util.h"
21
22 static void explain(void)
23 {
24         fprintf(stderr, "Usage: ... qfq\n");
25 }
26
27 static void explain1(const char *arg)
28 {
29         fprintf(stderr, "Illegal \"%s\"\n", arg);
30 }
31
32 static void explain_class(void)
33 {
34         fprintf(stderr, "Usage: ... qfq weight NUMBER maxpkt BYTES\n");
35 }
36
37 static int qfq_parse_opt(struct qdisc_util *qu, int argc, char **argv,
38                          struct nlmsghdr *n, const char *dev)
39 {
40         if (argc > 0) {
41                 if (matches(*argv, "help") != 0)
42                         fprintf(stderr, "What is \"%s\"?\n", *argv);
43                 explain();
44                 return -1;
45         }
46
47         return 0;
48 }
49
50 static int qfq_parse_class_opt(struct qdisc_util *qu, int argc, char **argv,
51                                struct nlmsghdr *n, const char *dev)
52 {
53         struct rtattr *tail;
54         __u32 tmp;
55
56         tail = addattr_nest(n, 4096, TCA_OPTIONS);
57
58         while (argc > 0) {
59                 if (matches(*argv, "weight") == 0) {
60                         NEXT_ARG();
61                         if (get_u32(&tmp, *argv, 10)) {
62                                 explain1("weight"); return -1;
63                         }
64                         addattr32(n, 4096, TCA_QFQ_WEIGHT, tmp);
65                 } else if (matches(*argv, "maxpkt") == 0) {
66                         NEXT_ARG();
67                         if (get_u32(&tmp, *argv, 10)) {
68                                 explain1("maxpkt"); return -1;
69                         }
70                         addattr32(n, 4096, TCA_QFQ_LMAX, tmp);
71                 } else if (strcmp(*argv, "help") == 0) {
72                         explain_class();
73                         return -1;
74                 } else {
75                         fprintf(stderr, "What is \"%s\"?\n", *argv);
76                         explain_class();
77                         return -1;
78                 }
79                 argc--; argv++;
80         }
81
82         addattr_nest_end(n, tail);
83
84         return 0;
85 }
86
87 static int qfq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
88 {
89         struct rtattr *tb[TCA_QFQ_MAX + 1];
90
91         if (opt == NULL)
92                 return 0;
93
94         parse_rtattr_nested(tb, TCA_QFQ_MAX, opt);
95
96         if (tb[TCA_QFQ_WEIGHT]) {
97                 fprintf(f, "weight %u ",
98                         rta_getattr_u32(tb[TCA_QFQ_WEIGHT]));
99         }
100
101         if (tb[TCA_QFQ_LMAX]) {
102                 fprintf(f, "maxpkt %u ",
103                         rta_getattr_u32(tb[TCA_QFQ_LMAX]));
104         }
105
106         return 0;
107 }
108
109 struct qdisc_util qfq_qdisc_util = {
110         .id             = "qfq",
111         .parse_qopt     = qfq_parse_opt,
112         .print_qopt     = qfq_print_opt,
113         .parse_copt     = qfq_parse_class_opt,
114         .print_copt     = qfq_print_opt,
115 };