Busybox: Upgrade to 1.21.1 (stable). lsof active.
[tomato.git] / release / src / router / iproute2 / tc / q_sfq.c
blob05385cfdc45cae909e39560d3bb4a376c6d52bb3
1 /*
2 * q_sfq.c SFQ.
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.
9 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
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>
23 #include "utils.h"
24 #include "tc_util.h"
26 static void explain(void)
28 fprintf(stderr, "Usage: ... sfq [ limit NUMBER ] [ perturb SECS ] [ quantum BYTES ]\n");
31 #define usage() return(-1)
33 static int sfq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
35 int ok=0;
36 struct tc_sfq_qopt opt;
38 memset(&opt, 0, sizeof(opt));
40 while (argc > 0) {
41 if (strcmp(*argv, "quantum") == 0) {
42 NEXT_ARG();
43 if (get_size(&opt.quantum, *argv)) {
44 fprintf(stderr, "Illegal \"limit\"\n");
45 return -1;
47 ok++;
48 } else if (strcmp(*argv, "perturb") == 0) {
49 NEXT_ARG();
50 if (get_integer(&opt.perturb_period, *argv, 0)) {
51 fprintf(stderr, "Illegal \"perturb\"\n");
52 return -1;
54 ok++;
55 } else if (strcmp(*argv, "limit") == 0) {
56 NEXT_ARG();
57 if (get_u32(&opt.limit, *argv, 0)) {
58 fprintf(stderr, "Illegal \"limit\"\n");
59 return -1;
61 if (opt.limit < 2) {
62 fprintf(stderr, "Illegal \"limit\", must be > 1\n");
63 return -1;
65 ok++;
66 } else if (strcmp(*argv, "help") == 0) {
67 explain();
68 return -1;
69 } else {
70 fprintf(stderr, "What is \"%s\"?\n", *argv);
71 explain();
72 return -1;
74 argc--; argv++;
77 if (ok)
78 addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
79 return 0;
82 static int sfq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
84 struct tc_sfq_qopt *qopt;
85 SPRINT_BUF(b1);
87 if (opt == NULL)
88 return 0;
90 if (RTA_PAYLOAD(opt) < sizeof(*qopt))
91 return -1;
92 qopt = RTA_DATA(opt);
93 fprintf(f, "limit %up ", qopt->limit);
94 fprintf(f, "quantum %s ", sprint_size(qopt->quantum, b1));
95 if (show_details) {
96 fprintf(f, "flows %u/%u ", qopt->flows, qopt->divisor);
98 if (qopt->perturb_period)
99 fprintf(f, "perturb %dsec ", qopt->perturb_period);
100 return 0;
103 struct qdisc_util sfq_qdisc_util = {
104 .id = "sfq",
105 .parse_qopt = sfq_parse_opt,
106 .print_qopt = sfq_print_opt,