summaryrefslogtreecommitdiffstats
path: root/lib/cli
diff options
context:
space:
mode:
authorThomas Graf <tgraf@suug.ch>2010-10-26 20:30:02 (GMT)
committerThomas Graf <tgraf@suug.ch>2010-10-26 20:30:02 (GMT)
commitb57a697ef1053a70264e9bedea3d2b98b8b24019 (patch)
treecc5b8f508e85ab3d8a5a44002eb381766df58503 /lib/cli
parent4c6d1c5dfb4f7e4a9392895f3da709b55c970e02 (diff)
downloadlibnl-b57a697ef1053a70264e9bedea3d2b98b8b24019.zip
libnl-b57a697ef1053a70264e9bedea3d2b98b8b24019.tar.gz
libnl-b57a697ef1053a70264e9bedea3d2b98b8b24019.tar.bz2
nl-cls-* tools
cli based tools to add/update/list/delete classifiers
Diffstat (limited to 'lib/cli')
-rw-r--r--lib/cli/cls/basic.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/lib/cli/cls/basic.c b/lib/cli/cls/basic.c
new file mode 100644
index 0000000..fbe2173
--- /dev/null
+++ b/lib/cli/cls/basic.c
@@ -0,0 +1,84 @@
+/*
+ * lib/cli/cls/basic.c basic classifier 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/cls.h>
+#include <netlink/route/cls/basic.h>
+
+static void print_usage(void)
+{
+ printf(
+"Usage: nl-cls-add [...] basic [OPTIONS]...\n"
+"\n"
+"OPTIONS\n"
+" -h, --help Show this help text.\n"
+" -t, --target=ID Target class to send matching packets to\n"
+"\n"
+"EXAMPLE"
+" # Create a \"catch-all\" classifier, attached to \"q_root\", classyfing\n"
+" # all not yet classified packets to class \"c_default\"\n"
+" nl-cls-add --dev=eth0 --parent=q_root basic --target=c_default\n");
+}
+
+static int parse_argv(struct rtnl_cls *cls, int argc, char **argv)
+{
+ uint32_t target;
+ int err;
+
+ for (;;) {
+ int c, optidx = 0;
+ enum {
+ ARG_TARGET = 257,
+ ARG_DEFAULT = 258,
+ };
+ static struct option long_opts[] = {
+ { "help", 0, 0, 'h' },
+ { "target", 1, 0, 't' },
+ { 0, 0, 0, 0 }
+ };
+
+ c = getopt_long(argc, argv, "ht:", long_opts, &optidx);
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'h':
+ print_usage();
+ exit(0);
+
+ case 't':
+ if ((err = rtnl_tc_str2handle(optarg, &target)) < 0)
+ nl_cli_fatal(err, "Unable to parse target \"%s\":",
+ optarg, nl_geterror(err));
+
+ rtnl_basic_set_classid(cls, target);
+ break;
+ }
+ }
+
+ return 0;
+}
+
+static struct nl_cli_cls_module basic_module =
+{
+ .cm_name = "basic",
+ .cm_parse_argv = parse_argv,
+};
+
+static void __init basic_init(void)
+{
+ nl_cli_cls_register(&basic_module);
+}
+
+static void __exit basic_exit(void)
+{
+ nl_cli_cls_unregister(&basic_module);
+}