8#include <netlink/cli/utils.h>
9#include <netlink/cli/tc.h>
10#include <netlink/route/qdisc/htb.h>
12static void print_qdisc_usage(
void)
15"Usage: nl-qdisc-add [...] htb [OPTIONS]...\n"
18" --help Show this help text.\n"
19" --r2q=DIV Rate to quantum divisor (default: 10)\n"
20" --default=ID Default class for unclassified traffic.\n"
23" # Create htb root qdisc 1: and direct unclassified traffic to class 1:10\n"
24" nl-qdisc-add --dev=eth1 --parent=root --handle=1: htb --default=10\n");
27static void htb_parse_qdisc_argv(
struct rtnl_tc *tc,
int argc,
char **argv)
37 static struct option long_opts[] = {
38 {
"help", 0, 0,
'h' },
39 {
"r2q", 1, 0, ARG_R2Q },
40 {
"default", 1, 0, ARG_DEFAULT },
44 c = getopt_long(argc, argv,
"hv", long_opts, &optidx);
64static void print_class_usage(
void)
67"Usage: nl-class-add [...] htb [OPTIONS]...\n"
70" --help Show this help text.\n"
71" --rate=RATE Rate limit.\n"
72" --ceil=RATE Rate limit while borrowing (default: equal to --rate).\n"
73" --prio=PRIO Priority, lower is served first (default: 0).\n"
74" --quantum=SIZE Amount of bytes to serve at once (default: rate/r2q).\n"
75" --burst=SIZE Max charge size of rate burst buffer (default: auto).\n"
76" --cburst=SIZE Max charge size of ceil rate burst buffer (default: auto)\n"
79" # Attach class 1:1 to htb qdisc 1: and rate limit it to 20mbit\n"
80" nl-class-add --dev=eth1 --parent=1: --classid=1:1 htb --rate=20mbit\n");
83static void htb_parse_class_argv(
struct rtnl_tc *tc,
int argc,
char **argv)
98 static struct option long_opts[] = {
99 {
"help", 0, 0,
'h' },
100 {
"rate", 1, 0, ARG_RATE },
101 {
"quantum", 1, 0, ARG_QUANTUM },
102 {
"ceil", 1, 0, ARG_CEIL },
103 {
"prio", 1, 0, ARG_PRIO },
104 {
"burst", 1, 0, ARG_BURST },
105 {
"cburst", 1, 0, ARG_CBURST },
109 c = getopt_long(argc, argv,
"h", long_opts, &optidx);
122 "\"%s\": Invalid format.", optarg);
132 "\"%s\": Invalid format.", optarg);
146 "\"%s\": Invalid format.", optarg);
156 "\"%s\": Invalid format.", optarg);
166 "\"%s\": Invalid format.", optarg);
178 .tm_type = RTNL_TC_TYPE_QDISC,
179 .tm_parse_argv = htb_parse_qdisc_argv,
185 .tm_type = RTNL_TC_TYPE_CLASS,
186 .tm_parse_argv = htb_parse_class_argv,
189static void _nl_init htb_init(
void)
191 nl_cli_tc_register(&htb_qdisc_module);
192 nl_cli_tc_register(&htb_class_module);
195static void _nl_exit htb_exit(
void)
197 nl_cli_tc_unregister(&htb_class_module);
198 nl_cli_tc_unregister(&htb_qdisc_module);
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
uint32_t nl_cli_parse_u32(const char *arg)
Parse a text based 32 bit unsigned integer argument.
int rtnl_htb_set_rbuffer(struct rtnl_class *class, uint32_t rbuffer)
Set size of the rate bucket of HTB class.
int rtnl_htb_set_defcls(struct rtnl_qdisc *qdisc, uint32_t defcls)
Set default class of the htb qdisc to the specified value.
int rtnl_htb_set_quantum(struct rtnl_class *class, uint32_t quantum)
Set quantum of HTB class (overwrites value calculated based on r2q)
int rtnl_htb_set_rate(struct rtnl_class *class, uint32_t rate)
Set rate of HTB class.
int rtnl_htb_set_ceil(struct rtnl_class *class, uint32_t ceil)
Set ceil rate of HTB class.
int rtnl_htb_set_cbuffer(struct rtnl_class *class, uint32_t cbuffer)
Set size of the ceil bucket of HTB class.
long nl_size2int(const char *str)
Convert a character string to a size.