diff options
author | Thomas Graf <tgraf@suug.ch> | 2010-10-19 11:06:42 (GMT) |
---|---|---|
committer | Thomas Graf <tgraf@suug.ch> | 2010-10-19 11:06:42 (GMT) |
commit | c0cd587dfc46ca8e8e5f9da51e878e0678950f23 (patch) | |
tree | 10aaa6c61ac3416f2fd579c3d05c9210c7d4ef83 /lib | |
parent | 3229b32e39363c439f0d042b561417e7b48aa786 (diff) | |
download | libnl-c0cd587dfc46ca8e8e5f9da51e878e0678950f23.zip libnl-c0cd587dfc46ca8e8e5f9da51e878e0678950f23.tar.gz libnl-c0cd587dfc46ca8e8e5f9da51e878e0678950f23.tar.bz2 |
nl-qdisc-add tool
Adds a cli based tool to add/update/replace qdiscs. This tool requires
each qdisc to be supported via a dynamic loadable module in
pkglibdir/cli/qdisc/$name.so.
So far HTB and blackhole have been implemented.
Syntax:
nl-qdisc-add --dev eth2 --parent root --id 1: htb --r2q=5
nl-qdisc-add --update-only --dev eth2 --id 1: htb --r2q=10
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile.am | 10 | ||||
-rw-r--r-- | lib/cli/qdisc/blackhole.c | 63 | ||||
-rw-r--r-- | lib/cli/qdisc/htb.c | 79 |
3 files changed, 152 insertions, 0 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index ba64a99..afb08ea 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -52,3 +52,13 @@ libnl_route_la_SOURCES = \ fib_lookup/lookup.c fib_lookup/request.c \ \ route/pktloc_syntax.c route/pktloc_grammar.c route/pktloc.c + + +if ENABLE_CLI +nobase_pkglib_LTLIBRARIES = \ + cli/qdisc/htb.la \ + cli/qdisc/blackhole.la + +cli_qdisc_htb_la_LDFLAGS = -module -version-info 0:0:0 +cli_qdisc_blackhole_la_LDFLAGS = -module -version-info 0:0:0 +endif diff --git a/lib/cli/qdisc/blackhole.c b/lib/cli/qdisc/blackhole.c new file mode 100644 index 0000000..176f463 --- /dev/null +++ b/lib/cli/qdisc/blackhole.c @@ -0,0 +1,63 @@ +/* + * src/lib/blackhole.c Blackhole module for CLI lib + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * Copyright (c) 2010 Thomas Graf <tgraf@suug.ch> + */ + +#include <netlink/cli/utils.h> +#include <netlink/cli/qdisc.h> + +static void print_usage(void) +{ + printf( +"Usage: nl-qdisc-add [...] blackhole [OPTIONS]...\n" +"\n" +"OPTIONS\n" +" --help Show this help text.\n" +"\n" +"EXAMPLE" +" # Drop all outgoing packets on eth1\n" +" nl-qdisc-add --dev=eth1 --parent=root blackhole\n"); +} + +static void blackhole_parse_argv(struct rtnl_qdisc *qdisc, int argc, char **argv) +{ + for (;;) { + int c, optidx = 0; + static struct option long_opts[] = { + { "help", 0, 0, 'h' }, + { 0, 0, 0, 0 } + }; + + c = getopt_long(argc, argv, "h", long_opts, &optidx); + if (c == -1) + break; + + switch (c) { + case 'h': + print_usage(); + return; + } + } +} + +static struct nl_cli_qdisc_module blackhole_module = +{ + .qm_name = "blackhole", + .qm_parse_argv = blackhole_parse_argv, +}; + +static void __init blackhole_init(void) +{ + nl_cli_qdisc_register(&blackhole_module); +} + +static void __exit blackhole_exit(void) +{ + nl_cli_qdisc_unregister(&blackhole_module); +} diff --git a/lib/cli/qdisc/htb.c b/lib/cli/qdisc/htb.c new file mode 100644 index 0000000..9ce8e25 --- /dev/null +++ b/lib/cli/qdisc/htb.c @@ -0,0 +1,79 @@ +/* + * src/lib/htb.c HTB module for CLI lib + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * Copyright (c) 2010 Thomas Graf <tgraf@suug.ch> + */ + +#include <netlink/cli/utils.h> +#include <netlink/cli/qdisc.h> + +static void print_usage(void) +{ + printf( +"Usage: nl-qdisc-add [...] htb [OPTIONS]...\n" +"\n" +"OPTIONS\n" +" --help Show this help text.\n" +" --r2q=DIV Rate to quantum divisor (default: 10)\n" +" --default=ID Default class for unclassified traffic.\n" +"\n" +"EXAMPLE" +" # Create htb root qdisc 1: and direct unclassified traffic to class 1:10\n" +" nl-qdisc-add --dev=eth1 --parent=root --handle=1: htb --default=10\n"); +} + +static void htb_parse_argv(struct rtnl_qdisc *qdisc, int argc, char **argv) +{ + for (;;) { + int c, optidx = 0; + enum { + ARG_R2Q = 257, + ARG_DEFAULT = 258, + }; + static struct option long_opts[] = { + { "help", 0, 0, 'h' }, + { "r2q", 1, 0, ARG_R2Q }, + { "default", 1, 0, ARG_DEFAULT }, + { 0, 0, 0, 0 } + }; + + c = getopt_long(argc, argv, "hv", long_opts, &optidx); + if (c == -1) + break; + + switch (c) { + case 'h': + print_usage(); + return; + + case ARG_R2Q: + rtnl_htb_set_rate2quantum(qdisc, nl_cli_parse_u32(optarg)); + break; + + case ARG_DEFAULT: + rtnl_htb_set_defcls(qdisc, nl_cli_parse_u32(optarg)); + break; + } + } +} + +static struct nl_cli_qdisc_module htb_module = +{ + .qm_name = "htb", + .qm_parse_argv = htb_parse_argv, +}; + +static void __init htb_init(void) +{ + nl_cli_qdisc_register(&htb_module); +} + +static void __exit htb_exit(void) +{ + nl_cli_qdisc_unregister(&htb_module); +} |