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>
18 #include <sys/socket.h>
19 #include <netinet/in.h>
20 #include <arpa/inet.h>
26 static void explain(void)
29 "Usage: ... rlim limit PACKETS rate KBPS [ overhead BYTES ]\n");
32 static void explain1(char *arg
)
34 fprintf(stderr
, "Illegal \"%s\"\n", arg
);
38 #define usage() return(-1)
40 static int rlim_parse_opt(struct qdisc_util
*qu
, int argc
, char **argv
, struct nlmsghdr
*n
)
43 struct tc_rlim_qopt opt
= {
44 .overhead
= 24, /* Ether IPG + Preamble + CRC */
49 if (matches(*argv
, "limit") == 0) {
52 fprintf(stderr
, "Double \"limit\" spec\n");
55 if (get_size(&opt
.limit
, *argv
)) {
59 } else if (strcmp(*argv
, "rate") == 0) {
62 fprintf(stderr
, "Double \"rate\" spec\n");
66 if (get_rate(&x
, *argv
)) {
71 } else if (strcmp(*argv
, "help") == 0) {
75 fprintf(stderr
, "What is \"%s\"?\n", *argv
);
83 fprintf(stderr
, "\"rate\" is required.\n");
91 addattr_l(n
, 1024, TCA_OPTIONS
, NULL
, 0);
92 addattr_l(n
, 2024, TCA_RLIM_PARMS
, &opt
, sizeof(opt
));
93 tail
->rta_len
= (void *) NLMSG_TAIL(n
) - (void *) tail
;
98 static int rlim_print_opt(struct qdisc_util
*qu
, FILE *f
, struct rtattr
*opt
)
100 struct rtattr
*tb
[TCA_RLIM_PARMS
+1];
101 struct tc_rlim_qopt
*qopt
;
108 parse_rtattr_nested(tb
, TCA_RLIM_PARMS
, opt
);
109 if (tb
[TCA_RLIM_PARMS
] == NULL
)
112 qopt
= RTA_DATA(tb
[TCA_RLIM_PARMS
]);
113 if (RTA_PAYLOAD(tb
[TCA_RLIM_PARMS
]) < sizeof(*qopt
))
116 fprintf(f
, "limit %s rate %s overhead %u",
117 sprint_size(qopt
->limit
, b1
),
118 sprint_rate(qopt
->rate
, b2
),
124 struct qdisc_util rlim_qdisc_util
= {
126 .parse_qopt
= rlim_parse_opt
,
127 .print_qopt
= rlim_print_opt
,