summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThomas Graf <tgraf@suug.ch>2011-03-21 14:51:52 (GMT)
committerThomas Graf <tgraf@suug.ch>2011-03-21 14:51:52 (GMT)
commit8eb5b5532eae985a5f0911dccf2db8cb4e0a5de4 (patch)
tree0fec48d114edbb535bd234f2684acccf81447d13 /src
parent5dc897d5de9f54078221b241e0122713207f5e0c (diff)
downloadlibnl-8eb5b5532eae985a5f0911dccf2db8cb4e0a5de4.zip
libnl-8eb5b5532eae985a5f0911dccf2db8cb4e0a5de4.tar.gz
libnl-8eb5b5532eae985a5f0911dccf2db8cb4e0a5de4.tar.bz2
Unified TC API
Finally got rid of all the qdisc/class/cls code duplication in the tc module API. The API takes care of allocation/freeing the tc object specific data. I hope I got it right this time.
Diffstat (limited to 'src')
-rw-r--r--src/lib/class.c10
-rw-r--r--src/lib/cls.c65
-rw-r--r--src/lib/qdisc.c96
-rw-r--r--src/lib/tc.c77
-rw-r--r--src/nl-class-add.c12
-rw-r--r--src/nl-class-delete.c2
-rw-r--r--src/nl-class-list.c2
-rw-r--r--src/nl-cls-add.c15
-rw-r--r--src/nl-cls-delete.c2
-rw-r--r--src/nl-cls-list.c2
-rw-r--r--src/nl-qdisc-add.c12
-rw-r--r--src/nl-qdisc-delete.c2
-rw-r--r--src/nl-qdisc-list.c2
13 files changed, 107 insertions, 192 deletions
diff --git a/src/lib/class.c b/src/lib/class.c
index c6b5525..96f60cd 100644
--- a/src/lib/class.c
+++ b/src/lib/class.c
@@ -6,7 +6,7 @@
* License as published by the Free Software Foundation version 2.1
* of the License.
*
- * Copyright (c) 2010 Thomas Graf <tgraf@suug.ch>
+ * Copyright (c) 2010-2011 Thomas Graf <tgraf@suug.ch>
*/
/**
@@ -22,8 +22,7 @@ struct rtnl_class *nl_cli_class_alloc(void)
{
struct rtnl_class *class;
- class = rtnl_class_alloc();
- if (!class)
+ if (!(class = rtnl_class_alloc()))
nl_cli_fatal(ENOMEM, "Unable to allocate class object");
return class;
@@ -43,9 +42,4 @@ struct nl_cache *nl_cli_class_alloc_cache(struct nl_sock *sock, int ifindex)
return cache;
}
-void nl_cli_class_parse_kind(struct rtnl_class *class, char *arg)
-{
- rtnl_class_set_kind(class, arg);
-}
-
/** @} */
diff --git a/src/lib/cls.c b/src/lib/cls.c
index 7ada3d6..86d775d 100644
--- a/src/lib/cls.c
+++ b/src/lib/cls.c
@@ -6,7 +6,7 @@
* License as published by the Free Software Foundation version 2.1
* of the License.
*
- * Copyright (c) 2010 Thomas Graf <tgraf@suug.ch>
+ * Copyright (c) 2010-2011 Thomas Graf <tgraf@suug.ch>
*/
/**
@@ -23,8 +23,7 @@ struct rtnl_cls *nl_cli_cls_alloc(void)
{
struct rtnl_cls *cls;
- cls = rtnl_cls_alloc();
- if (!cls)
+ if (!(cls = rtnl_cls_alloc()))
nl_cli_fatal(ENOMEM, "Unable to allocate classifier object");
return cls;
@@ -43,11 +42,6 @@ struct nl_cache *nl_cli_cls_alloc_cache(struct nl_sock *sock, int ifindex,
return cache;
}
-void nl_cli_cls_parse_kind(struct rtnl_cls *cls, char *arg)
-{
- rtnl_cls_set_kind(cls, arg);
-}
-
void nl_cli_cls_parse_proto(struct rtnl_cls *cls, char *arg)
{
int proto;
@@ -74,59 +68,4 @@ struct rtnl_ematch_tree *nl_cli_cls_parse_ematch(struct rtnl_cls *cls, char *arg
return tree;
}
-static NL_LIST_HEAD(cls_modules);
-
-struct nl_cli_cls_module *__nl_cli_cls_lookup(struct rtnl_cls_ops *ops)
-{
- struct nl_cli_cls_module *cm;
-
- nl_list_for_each_entry(cm, &cls_modules, cm_list)
- if (cm->cm_ops == ops)
- return cm;
-
- return NULL;
-}
-
-struct nl_cli_cls_module *nl_cli_cls_lookup(struct rtnl_cls_ops *ops)
-{
- struct nl_cli_cls_module *cm;
-
- if ((cm = __nl_cli_cls_lookup(ops)))
- return cm;
-
- nl_cli_load_module("cli/cls", ops->co_kind);
-
- if (!(cm = __nl_cli_cls_lookup(ops))) {
- nl_cli_fatal(EINVAL, "Application bug: The shared library for "
- "the classifier \"%s\" was successfully loaded but it "
- "seems that module did not register itself");
- }
-
- return cm;
-}
-
-void nl_cli_cls_register(struct nl_cli_cls_module *cm)
-{
- struct rtnl_cls_ops *ops;
-
- if (!(ops = __rtnl_cls_lookup_ops(cm->cm_name))) {
- nl_cli_fatal(ENOENT, "Unable to register CLI classifier module "
- "\"%s\": No matching libnl cls module found.", cm->cm_name);
- }
-
- if (__nl_cli_cls_lookup(ops)) {
- nl_cli_fatal(EEXIST, "Unable to register CLI classifier module "
- "\"%s\": Module already registered.", cm->cm_name);
- }
-
- cm->cm_ops = ops;
-
- nl_list_add_tail(&cm->cm_list, &cls_modules);
-}
-
-void nl_cli_cls_unregister(struct nl_cli_cls_module *cm)
-{
- nl_list_del(&cm->cm_list);
-}
-
/** @} */
diff --git a/src/lib/qdisc.c b/src/lib/qdisc.c
index 4c64e7b..ccf7d26 100644
--- a/src/lib/qdisc.c
+++ b/src/lib/qdisc.c
@@ -6,7 +6,7 @@
* License as published by the Free Software Foundation version 2.1
* of the License.
*
- * Copyright (c) 2008-2010 Thomas Graf <tgraf@suug.ch>
+ * Copyright (c) 2008-2011 Thomas Graf <tgraf@suug.ch>
*/
/**
@@ -18,107 +18,15 @@
#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)
{
struct rtnl_qdisc *qdisc;
- qdisc = rtnl_qdisc_alloc();
- if (!qdisc)
+ if (!(qdisc = rtnl_qdisc_alloc()))
nl_cli_fatal(ENOMEM, "Unable to allocate qdisc object");
return qdisc;
}
-void nl_cli_qdisc_parse_kind(struct rtnl_qdisc *qdisc, char *arg)
-{
- rtnl_qdisc_set_kind(qdisc, arg);
-}
-
-static NL_LIST_HEAD(qdisc_modules);
-
-struct nl_cli_qdisc_module *__nl_cli_qdisc_lookup(struct rtnl_qdisc_ops *ops)
-{
- struct nl_cli_qdisc_module *qm;
-
- nl_list_for_each_entry(qm, &qdisc_modules, qm_list)
- if (qm->qm_ops == ops)
- return qm;
-
- 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;
-
- if ((qm = __nl_cli_qdisc_lookup(ops)))
- return qm;
-
- nl_cli_load_module("cli/qdisc", ops->qo_kind);
-
- if (!(qm = __nl_cli_qdisc_lookup(ops))) {
- nl_cli_fatal(EINVAL, "Application bug: The shared library for "
- "the qdisc \"%s\" was successfully loaded but it "
- "seems that module did not register itself");
- }
-
- 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;
-
- if (!(ops = __rtnl_qdisc_lookup_ops(qm->qm_name))) {
- nl_cli_fatal(ENOENT, "Unable to register CLI qdisc module "
- "\"%s\": No matching libnl qdisc module found.", qm->qm_name);
- }
-
- if (__nl_cli_qdisc_lookup(ops)) {
- nl_cli_fatal(EEXIST, "Unable to register CLI qdisc module "
- "\"%s\": Module already registered.", qm->qm_name);
- }
-
- qm->qm_ops = ops;
- qm->qm_class_ops = __rtnl_class_lookup_ops(qm->qm_name);
-
- nl_list_add_tail(&qm->qm_list, &qdisc_modules);
-}
-
-void nl_cli_qdisc_unregister(struct nl_cli_qdisc_module *qm)
-{
- nl_list_del(&qm->qm_list);
-}
-
/** @} */
diff --git a/src/lib/tc.c b/src/lib/tc.c
index 72407cf..8d013f9 100644
--- a/src/lib/tc.c
+++ b/src/lib/tc.c
@@ -11,7 +11,7 @@
#include <netlink/cli/utils.h>
#include <netlink/cli/tc.h>
-#include <netlink/route/tc.h>
+#include <netlink/route/tc-api.h>
/**
* @ingroup cli
@@ -76,6 +76,11 @@ void nl_cli_tc_parse_overhead(struct rtnl_tc *tc, char *arg)
rtnl_tc_set_overhead(tc, nl_cli_parse_u32(arg));
}
+void nl_cli_tc_parse_kind(struct rtnl_tc *tc, char *arg)
+{
+ rtnl_tc_set_kind(tc, arg);
+}
+
void nl_cli_tc_parse_linktype(struct rtnl_tc *tc, char *arg)
{
int type;
@@ -87,4 +92,74 @@ void nl_cli_tc_parse_linktype(struct rtnl_tc *tc, char *arg)
rtnl_tc_set_linktype(tc, type);
}
+static NL_LIST_HEAD(tc_modules);
+
+struct nl_cli_tc_module *__nl_cli_tc_lookup(struct rtnl_tc_ops *ops)
+{
+ struct nl_cli_tc_module *tm;
+
+ nl_list_for_each_entry(tm, &tc_modules, tm_list)
+ if (tm->tm_ops == ops)
+ return tm;
+
+ return NULL;
+}
+
+struct nl_cli_tc_module *nl_cli_tc_lookup(struct rtnl_tc_ops *ops)
+{
+ struct nl_cli_tc_module *tm;
+
+ if ((tm = __nl_cli_tc_lookup(ops)))
+ return tm;
+
+ switch (ops->to_type) {
+ case RTNL_TC_TYPE_QDISC:
+ case RTNL_TC_TYPE_CLASS:
+ nl_cli_load_module("cli/qdisc", ops->to_kind);
+ break;
+
+ case RTNL_TC_TYPE_CLS:
+ nl_cli_load_module("cli/cls", ops->to_kind);
+ break;
+
+ default:
+ nl_cli_fatal(EINVAL, "BUG: unhandled TC object type %d",
+ ops->to_type);
+ }
+
+ if (!(tm = __nl_cli_tc_lookup(ops))) {
+ nl_cli_fatal(EINVAL, "Application bug: The shared library for "
+ "the tc object \"%s\" was successfully loaded but it "
+ "seems that module did not register itself",
+ ops->to_kind);
+ }
+
+ return tm;
+}
+
+void nl_cli_tc_register(struct nl_cli_tc_module *tm)
+{
+ struct rtnl_tc_ops *ops;
+
+ if (!(ops = rtnl_tc_lookup_ops(tm->tm_type, tm->tm_name))) {
+ nl_cli_fatal(ENOENT, "Unable to register CLI TC module "
+ "\"%s\": No matching libnl TC module found.", tm->tm_name);
+ }
+
+ if (__nl_cli_tc_lookup(ops)) {
+ nl_cli_fatal(EEXIST, "Unable to register CLI TC module "
+ "\"%s\": Module already registered.", tm->tm_name);
+ }
+
+ tm->tm_ops = ops;
+
+ nl_list_add_tail(&tm->tm_list, &tc_modules);
+}
+
+void nl_cli_tc_unregister(struct nl_cli_tc_module *tm)
+{
+ nl_list_del(&tm->tm_list);
+}
+
+
/** @} */
diff --git a/src/nl-class-add.c b/src/nl-class-add.c
index 80ea826..9698f0d 100644
--- a/src/nl-class-add.c
+++ b/src/nl-class-add.c
@@ -56,8 +56,8 @@ int main(int argc, char *argv[])
.dp_type = NL_DUMP_DETAILS,
.dp_fd = stdout,
};
- struct nl_cli_qdisc_module *qm;
- struct rtnl_class_ops *ops;
+ struct nl_cli_tc_module *tm;
+ struct rtnl_tc_ops *ops;
int err, flags = NLM_F_CREATE | NLM_F_EXCL;
char *kind, *id = NULL;
@@ -131,15 +131,15 @@ int main(int argc, char *argv[])
}
kind = argv[optind++];
- rtnl_class_set_kind(class, kind);
+ rtnl_tc_set_kind(tc, kind);
- if (!(ops = rtnl_class_lookup_ops(class)))
+ if (!(ops = rtnl_tc_get_ops(tc)))
nl_cli_fatal(ENOENT, "Unknown class \"%s\"", kind);
- if (!(qm = nl_cli_qdisc_lookup_by_class(ops)))
+ if (!(tm = nl_cli_tc_lookup(ops)))
nl_cli_fatal(ENOTSUP, "class type \"%s\" not supported.", kind);
- qm->qm_parse_class_argv(class, argc, argv);
+ tm->tm_parse_argv(tc, argc, argv);
if (!quiet) {
printf("Adding ");
diff --git a/src/nl-class-delete.c b/src/nl-class-delete.c
index 3c5cdc1..3df5a9a 100644
--- a/src/nl-class-delete.c
+++ b/src/nl-class-delete.c
@@ -110,7 +110,7 @@ int main(int argc, char *argv[])
case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg); break;
case 'p': nl_cli_tc_parse_parent(tc, optarg); break;
case 'i': nl_cli_tc_parse_handle(tc, optarg, 0); break;
- case 'k': nl_cli_class_parse_kind(class, optarg); break;
+ case 'k': nl_cli_tc_parse_kind(tc, optarg); break;
}
}
diff --git a/src/nl-class-list.c b/src/nl-class-list.c
index fccc512..44ca49b 100644
--- a/src/nl-class-list.c
+++ b/src/nl-class-list.c
@@ -104,7 +104,7 @@ int main(int argc, char *argv[])
case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg); break;
case 'p': nl_cli_tc_parse_parent(tc, optarg); break;
case 'i': nl_cli_tc_parse_handle(tc, optarg, 0); break;
- case 'k': nl_cli_class_parse_kind(class, optarg); break;
+ case 'k': nl_cli_tc_parse_kind(tc, optarg); break;
}
}
diff --git a/src/nl-cls-add.c b/src/nl-cls-add.c
index fad9313..054bab3 100644
--- a/src/nl-cls-add.c
+++ b/src/nl-cls-add.c
@@ -5,7 +5,7 @@
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation version 2 of the License.
*
- * Copyright (c) 2003-2010 Thomas Graf <tgraf@suug.ch>
+ * Copyright (c) 2003-2011 Thomas Graf <tgraf@suug.ch>
*/
#include <netlink/cli/utils.h>
@@ -56,8 +56,8 @@ int main(int argc, char *argv[])
.dp_type = NL_DUMP_DETAILS,
.dp_fd = stdout,
};
- struct nl_cli_cls_module *cm;
- struct rtnl_cls_ops *ops;
+ struct nl_cli_tc_module *tm;
+ struct rtnl_tc_ops *ops;
int err, flags = NLM_F_CREATE | NLM_F_EXCL;
char *kind, *id = NULL;
@@ -139,16 +139,15 @@ int main(int argc, char *argv[])
}
kind = argv[optind++];
- rtnl_cls_set_kind(cls, kind);
+ rtnl_tc_set_kind(tc, kind);
- if (!(ops = rtnl_cls_lookup_ops(cls)))
+ if (!(ops = rtnl_tc_get_ops(tc)))
nl_cli_fatal(ENOENT, "Unknown classifier \"%s\".", kind);
- if (!(cm = nl_cli_cls_lookup(ops)))
+ if (!(tm = nl_cli_tc_lookup(ops)))
nl_cli_fatal(ENOTSUP, "Classifier type \"%s\" not supported.", kind);
- if ((err = cm->cm_parse_argv(cls, argc, argv)) < 0)
- nl_cli_fatal(err, "Unable to parse classifier options");
+ tm->tm_parse_argv(tc, argc, argv);
if (!quiet) {
printf("Adding ");
diff --git a/src/nl-cls-delete.c b/src/nl-cls-delete.c
index 359d15e..7d998fd 100644
--- a/src/nl-cls-delete.c
+++ b/src/nl-cls-delete.c
@@ -135,7 +135,7 @@ int main(int argc, char *argv[])
case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg); break;
case 'p': nl_cli_tc_parse_parent(tc, optarg); break;
case 'i': nl_cli_tc_parse_handle(tc, optarg, 0); break;
- case 'k': nl_cli_cls_parse_kind(cls, optarg); break;
+ case 'k': nl_cli_tc_parse_kind(tc, optarg); break;
case ARG_PROTO: nl_cli_cls_parse_proto(cls, optarg); break;
case ARG_PRIO:
rtnl_cls_set_prio(cls, nl_cli_parse_u32(optarg));
diff --git a/src/nl-cls-list.c b/src/nl-cls-list.c
index e7c9a12..fcb5dcb 100644
--- a/src/nl-cls-list.c
+++ b/src/nl-cls-list.c
@@ -112,7 +112,7 @@ int main(int argc, char *argv[])
case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg); break;
case 'p': nl_cli_tc_parse_parent(tc, optarg); break;
case 'i': nl_cli_tc_parse_handle(tc, optarg, 0); break;
- case 'k': nl_cli_cls_parse_kind(cls, optarg); break;
+ case 'k': nl_cli_tc_parse_kind(tc, optarg); break;
case ARG_PROTO: nl_cli_cls_parse_proto(cls, optarg); break;
case ARG_PRIO:
rtnl_cls_set_prio(cls, nl_cli_parse_u32(optarg));
diff --git a/src/nl-qdisc-add.c b/src/nl-qdisc-add.c
index 9da0f18..dd2ed2b 100644
--- a/src/nl-qdisc-add.c
+++ b/src/nl-qdisc-add.c
@@ -53,8 +53,8 @@ int main(int argc, char *argv[])
.dp_type = NL_DUMP_DETAILS,
.dp_fd = stdout,
};
- struct nl_cli_qdisc_module *qm;
- struct rtnl_qdisc_ops *ops;
+ struct nl_cli_tc_module *tm;
+ struct rtnl_tc_ops *ops;
int err, flags = NLM_F_CREATE | NLM_F_EXCL;
char *kind, *id = NULL;
@@ -122,15 +122,15 @@ int main(int argc, char *argv[])
}
kind = argv[optind++];
- rtnl_qdisc_set_kind(qdisc, kind);
+ rtnl_tc_set_kind(tc, kind);
- if (!(ops = rtnl_qdisc_lookup_ops(qdisc)))
+ if (!(ops = rtnl_tc_get_ops(tc)))
nl_cli_fatal(ENOENT, "Unknown qdisc \"%s\"", kind);
- if (!(qm = nl_cli_qdisc_lookup(ops)))
+ if (!(tm = nl_cli_tc_lookup(ops)))
nl_cli_fatal(ENOTSUP, "Qdisc type \"%s\" not supported.", kind);
- qm->qm_parse_qdisc_argv(qdisc, argc, argv);
+ tm->tm_parse_argv(tc, argc, argv);
if (!quiet) {
printf("Adding ");
diff --git a/src/nl-qdisc-delete.c b/src/nl-qdisc-delete.c
index b230063..9c7ec14 100644
--- a/src/nl-qdisc-delete.c
+++ b/src/nl-qdisc-delete.c
@@ -123,7 +123,7 @@ int main(int argc, char *argv[])
break;
case 'k':
nfilter++;
- nl_cli_qdisc_parse_kind(qdisc, optarg);
+ nl_cli_tc_parse_kind(tc, optarg);
break;
}
}
diff --git a/src/nl-qdisc-list.c b/src/nl-qdisc-list.c
index 670fa3d..5b0a3f0 100644
--- a/src/nl-qdisc-list.c
+++ b/src/nl-qdisc-list.c
@@ -170,7 +170,7 @@ int main(int argc, char *argv[])
case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg); break;
case 'p': nl_cli_tc_parse_parent(tc, optarg); break;
case 'i': nl_cli_tc_parse_handle(tc, optarg, 0); break;
- case 'k': nl_cli_qdisc_parse_kind(qdisc, optarg); break;
+ case 'k': nl_cli_tc_parse_kind(tc, optarg); break;
}
}