summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorThomas Graf <tgraf@suug.ch>2010-10-20 14:57:39 +0200
committerThomas Graf <tgraf@suug.ch>2010-10-20 14:57:39 +0200
commit27883b0f9b0da6bb33ccc185107a2870df25d030 (patch)
treefbda57a6026fbc6653648ecb9d588d2d9e938b5e /src/lib
parent18848090f99cae37ac1a3052369ab4d26ed9ada0 (diff)
nl-class-add tool
Adds a cli based tool to add/update traffic classes. This tool requires each class to be supported via the respetive qdisc module in pkglibdir/cli/qdisc/$name.so. Syntax: nl-class-add --dev eth2 --parent 1: --id 1:1 htb --rate 100mbit nl-class-add --update --dev eth2 --id 1:1 htb --rate 200mbit
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Makefile.am2
-rw-r--r--src/lib/class.c71
-rw-r--r--src/lib/qdisc.c33
3 files changed, 105 insertions, 1 deletions
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 2b48876..1ed5912 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -34,6 +34,6 @@ libnl_cli_la_LIBADD = ${top_builddir}/lib/libnl.la \
${top_builddir}/lib/libnl-genl.la
libnl_cli_la_SOURCES = \
- utils.c addr.c ct.c link.c neigh.c qdisc.c rule.c route.c
+ utils.c addr.c ct.c link.c neigh.c qdisc.c class.c rule.c route.c
# cls/ematch_syntax.c cls/ematch_grammar.c cls/ematch.c
# cls/pktloc_syntax.c cls/pktloc_grammar.c cls/utils.c
diff --git a/src/lib/class.c b/src/lib/class.c
new file mode 100644
index 0000000..93346d5
--- /dev/null
+++ b/src/lib/class.c
@@ -0,0 +1,71 @@
+/*
+ * src/lib/class.c CLI Class Helpers
+ *
+ * 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>
+ */
+
+/**
+ * @ingroup cli
+ * @defgroup cli_class Traffic Classes
+ * @{
+ */
+
+#include <netlink/cli/utils.h>
+#include <netlink/cli/class.h>
+
+struct rtnl_class *nl_cli_class_alloc(void)
+{
+ struct rtnl_class *class;
+
+ class = rtnl_class_alloc();
+ if (!class)
+ nl_cli_fatal(ENOMEM, "Unable to allocate class object");
+
+ return class;
+}
+
+void nl_cli_class_parse_dev(struct rtnl_class *class, struct nl_cache *link_cache, char *arg)
+{
+ int ival;
+
+ if (!(ival = rtnl_link_name2i(link_cache, arg)))
+ nl_cli_fatal(ENOENT, "Link \"%s\" does not exist", arg);
+
+ rtnl_class_set_ifindex(class, ival);
+}
+
+void nl_cli_class_parse_parent(struct rtnl_class *class, char *arg)
+{
+ uint32_t parent;
+ int err;
+
+ if ((err = rtnl_tc_str2handle(arg, &parent)) < 0)
+ nl_cli_fatal(err, "Unable to parse handle \"%s\": %s",
+ arg, nl_geterror(err));
+
+ rtnl_class_set_parent(class, parent);
+}
+
+void nl_cli_class_parse_handle(struct rtnl_class *class, char *arg)
+{
+ uint32_t handle;
+ int err;
+
+ if ((err = rtnl_tc_str2handle(arg, &handle)) < 0)
+ nl_cli_fatal(err, "Unable to parse classid \"%s\": %s",
+ arg, nl_geterror(err));
+
+ rtnl_class_set_handle(class, handle);
+}
+
+void nl_cli_class_parse_kind(struct rtnl_class *class, char *arg)
+{
+ rtnl_class_set_kind(class, arg);
+}
+
+/** @} */
diff --git a/src/lib/qdisc.c b/src/lib/qdisc.c
index 52b7a6a..8b16f3f 100644
--- a/src/lib/qdisc.c
+++ b/src/lib/qdisc.c
@@ -17,6 +17,8 @@
#include <netlink/cli/utils.h>
#include <netlink/cli/qdisc.h>
+#include <netlink/route/class.h>
+#include <netlink/route/class-modules.h>
struct rtnl_qdisc *nl_cli_qdisc_alloc(void)
{
@@ -81,6 +83,17 @@ struct nl_cli_qdisc_module *__nl_cli_qdisc_lookup(struct rtnl_qdisc_ops *ops)
return NULL;
}
+struct nl_cli_qdisc_module *__nl_cli_class_lookup(struct rtnl_class_ops *ops)
+{
+ struct nl_cli_qdisc_module *qm;
+
+ nl_list_for_each_entry(qm, &qdisc_modules, qm_list)
+ if (qm->qm_class_ops == ops)
+ return qm;
+
+ return NULL;
+}
+
struct nl_cli_qdisc_module *nl_cli_qdisc_lookup(struct rtnl_qdisc_ops *ops)
{
struct nl_cli_qdisc_module *qm;
@@ -99,6 +112,24 @@ struct nl_cli_qdisc_module *nl_cli_qdisc_lookup(struct rtnl_qdisc_ops *ops)
return qm;
}
+struct nl_cli_qdisc_module *nl_cli_qdisc_lookup_by_class(struct rtnl_class_ops *ops)
+{
+ struct nl_cli_qdisc_module *qm;
+
+ if ((qm = __nl_cli_class_lookup(ops)))
+ return qm;
+
+ nl_cli_load_module("cli/qdisc", ops->co_kind);
+
+ if (!(qm = __nl_cli_class_lookup(ops))) {
+ nl_cli_fatal(EINVAL, "Application bug: The shared library for "
+ "the class \"%s\" was successfully loaded but it "
+ "seems that module did not register itself");
+ }
+
+ return qm;
+}
+
void nl_cli_qdisc_register(struct nl_cli_qdisc_module *qm)
{
struct rtnl_qdisc_ops *ops;
@@ -114,6 +145,8 @@ void nl_cli_qdisc_register(struct nl_cli_qdisc_module *qm)
}
qm->qm_ops = ops;
+ qm->qm_class_ops = __rtnl_class_lookup_ops(qm->qm_name);
+
nl_list_add_tail(&qm->qm_list, &qdisc_modules);
}