]> rtime.felk.cvut.cz Git - lisovros/iproute2_canprio.git/blob - tc/q_sfq.c
iproute2: detect iptables modules dir in configure.
[lisovros/iproute2_canprio.git] / tc / q_sfq.c
1 /*
2  * q_sfq.c              SFQ.
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  *
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 {
28         fprintf(stderr, "Usage: ... sfq [ limit NUMBER ] [ perturb SECS ] [ quantum BYTES ]\n");
29 }
30
31 static int sfq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
32 {
33         int ok=0;
34         struct tc_sfq_qopt opt;
35
36         memset(&opt, 0, sizeof(opt));
37
38         while (argc > 0) {
39                 if (strcmp(*argv, "quantum") == 0) {
40                         NEXT_ARG();
41                         if (get_size(&opt.quantum, *argv)) {
42                                 fprintf(stderr, "Illegal \"limit\"\n");
43                                 return -1;
44                         }
45                         ok++;
46                 } else if (strcmp(*argv, "perturb") == 0) {
47                         NEXT_ARG();
48                         if (get_integer(&opt.perturb_period, *argv, 0)) {
49                                 fprintf(stderr, "Illegal \"perturb\"\n");
50                                 return -1;
51                         }
52                         ok++;
53                 } else if (strcmp(*argv, "limit") == 0) {
54                         NEXT_ARG();
55                         if (get_u32(&opt.limit, *argv, 0)) {
56                                 fprintf(stderr, "Illegal \"limit\"\n");
57                                 return -1;
58                         }
59                         if (opt.limit < 2) {
60                                 fprintf(stderr, "Illegal \"limit\", must be > 1\n");
61                                 return -1;
62                         }
63                         ok++;
64                 } else if (strcmp(*argv, "help") == 0) {
65                         explain();
66                         return -1;
67                 } else {
68                         fprintf(stderr, "What is \"%s\"?\n", *argv);
69                         explain();
70                         return -1;
71                 }
72                 argc--; argv++;
73         }
74
75         if (ok)
76                 addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
77         return 0;
78 }
79
80 static int sfq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
81 {
82         struct tc_sfq_qopt *qopt;
83         SPRINT_BUF(b1);
84
85         if (opt == NULL)
86                 return 0;
87
88         if (RTA_PAYLOAD(opt)  < sizeof(*qopt))
89                 return -1;
90         qopt = RTA_DATA(opt);
91         fprintf(f, "limit %up ", qopt->limit);
92         fprintf(f, "quantum %s ", sprint_size(qopt->quantum, b1));
93         if (show_details) {
94                 fprintf(f, "flows %u/%u ", qopt->flows, qopt->divisor);
95         }
96         if (qopt->perturb_period)
97                 fprintf(f, "perturb %dsec ", qopt->perturb_period);
98         return 0;
99 }
100
101 static int sfq_print_xstats(struct qdisc_util *qu, FILE *f,
102                             struct rtattr *xstats)
103 {
104         struct tc_sfq_xstats *st;
105
106         if (xstats == NULL)
107                 return 0;
108         if (RTA_PAYLOAD(xstats) < sizeof(*st))
109                 return -1;
110         st = RTA_DATA(xstats);
111
112         fprintf(f, " allot %d ", st->allot);
113         fprintf(f, "\n");
114         return 0;
115 }
116
117 struct qdisc_util sfq_qdisc_util = {
118         .id             = "sfq",
119         .parse_qopt     = sfq_parse_opt,
120         .print_qopt     = sfq_print_opt,
121         .print_xstats   = sfq_print_xstats,
122 };