12 #include <netlink/cli/utils.h> 13 #include <netlink/cli/tc.h> 14 #include <netlink/route/qdisc/htb.h> 16 static void print_qdisc_usage(
void)
19 "Usage: nl-qdisc-add [...] htb [OPTIONS]...\n" 22 " --help Show this help text.\n" 23 " --r2q=DIV Rate to quantum divisor (default: 10)\n" 24 " --default=ID Default class for unclassified traffic.\n" 27 " # Create htb root qdisc 1: and direct unclassified traffic to class 1:10\n" 28 " nl-qdisc-add --dev=eth1 --parent=root --handle=1: htb --default=10\n");
31 static void htb_parse_qdisc_argv(
struct rtnl_tc *tc,
int argc,
char **argv)
33 struct rtnl_qdisc *qdisc = (
struct rtnl_qdisc *) tc;
41 static struct option long_opts[] = {
42 {
"help", 0, 0,
'h' },
43 {
"r2q", 1, 0, ARG_R2Q },
44 {
"default", 1, 0, ARG_DEFAULT },
48 c = getopt_long(argc, argv,
"hv", long_opts, &optidx);
68 static void print_class_usage(
void)
71 "Usage: nl-class-add [...] htb [OPTIONS]...\n" 74 " --help Show this help text.\n" 75 " --rate=RATE Rate limit.\n" 76 " --ceil=RATE Rate limit while borrowing (default: equal to --rate).\n" 77 " --prio=PRIO Priority, lower is served first (default: 0).\n" 78 " --quantum=SIZE Amount of bytes to serve at once (default: rate/r2q).\n" 79 " --burst=SIZE Max charge size of rate burst buffer (default: auto).\n" 80 " --cburst=SIZE Max charge size of ceil rate burst buffer (default: auto)\n" 83 " # Attach class 1:1 to htb qdisc 1: and rate limit it to 20mbit\n" 84 " nl-class-add --dev=eth1 --parent=1: --classid=1:1 htb --rate=20mbit\n");
87 static void htb_parse_class_argv(
struct rtnl_tc *tc,
int argc,
char **argv)
89 struct rtnl_class *
class = (struct rtnl_class *) tc;
102 static struct option long_opts[] = {
103 {
"help", 0, 0,
'h' },
104 {
"rate", 1, 0, ARG_RATE },
105 {
"quantum", 1, 0, ARG_QUANTUM },
106 {
"ceil", 1, 0, ARG_CEIL },
107 {
"prio", 1, 0, ARG_PRIO },
108 {
"burst", 1, 0, ARG_BURST },
109 {
"cburst", 1, 0, ARG_CBURST },
113 c = getopt_long(argc, argv,
"h", long_opts, &optidx);
126 "\"%s\": Invalid format.", optarg);
136 "\"%s\": Invalid format.", optarg);
150 "\"%s\": Invalid format.", optarg);
160 "\"%s\": Invalid format.", optarg);
170 "\"%s\": Invalid format.", optarg);
182 .tm_type = RTNL_TC_TYPE_QDISC,
183 .tm_parse_argv = htb_parse_qdisc_argv,
189 .tm_type = RTNL_TC_TYPE_CLASS,
190 .tm_parse_argv = htb_parse_class_argv,
193 static void __init htb_init(
void)
195 nl_cli_tc_register(&htb_qdisc_module);
196 nl_cli_tc_register(&htb_class_module);
199 static void __exit htb_exit(
void)
201 nl_cli_tc_unregister(&htb_class_module);
202 nl_cli_tc_unregister(&htb_qdisc_module);
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_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.
uint32_t nl_cli_parse_u32(const char *arg)
Parse a text based 32 bit unsigned integer argument.
int rtnl_htb_set_ceil(struct rtnl_class *class, uint32_t ceil)
Set ceil rate of HTB class.
int rtnl_htb_set_rate(struct rtnl_class *class, uint32_t rate)
Set rate of HTB class.
int rtnl_htb_set_quantum(struct rtnl_class *class, uint32_t quantum)
Set quantum of HTB class (overwrites value calculated based on r2q)
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
int rtnl_htb_set_defcls(struct rtnl_qdisc *qdisc, uint32_t defcls)
Set default class of the htb qdisc to the specified value.