diff options
author | Thomas Graf <tgraf@suug.ch> | 2010-10-26 10:54:33 (GMT) |
---|---|---|
committer | Thomas Graf <tgraf@suug.ch> | 2010-10-26 10:54:33 (GMT) |
commit | 4c6d1c5dfb4f7e4a9392895f3da709b55c970e02 (patch) | |
tree | 9303851dcc87e2e3f9c25805ccf24f4a543fe23d /src/lib | |
parent | b9d965b01b42103389b2a2c0cc3133293447a64d (diff) | |
download | libnl-4c6d1c5dfb4f7e4a9392895f3da709b55c970e02.zip libnl-4c6d1c5dfb4f7e4a9392895f3da709b55c970e02.tar.gz libnl-4c6d1c5dfb4f7e4a9392895f3da709b55c970e02.tar.bz2 |
Unified TC attributes interface
So far all common tc atttributes were accessed via specific functions, i.e.
rtnl_class_set_parent(), rtnl_qdisc_set_parent(), rtnl_cls_set_parent()
which implied a lot of code duplication. Since all tc objects are derived
from struct rtnl_tc and these common attributes are already stored in there
this patch removes all type specific functions and makes rtnl_tc_* attribute
functions public.
rtnl_qdisc_set_parent(qdisc, 10);
becomes:
rtnl_tc_set_parent((struct rtnl_tc *) qdisc, 10);
This patch also adds the following new attributes to tc objects therefore
removing them as tc specific attributes:
- mtu
- mpu
- overhead
This allows for the rate table calculations to be unified as well taking into
account the new kernel behavior to take care of overhead automatically.
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Makefile.am | 2 | ||||
-rw-r--r-- | src/lib/class.c | 34 | ||||
-rw-r--r-- | src/lib/qdisc.c | 34 | ||||
-rw-r--r-- | src/lib/tc.c | 83 |
4 files changed, 84 insertions, 69 deletions
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 1ed5912..e806633 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 class.c rule.c route.c + utils.c addr.c ct.c link.c neigh.c tc.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 index 4f6ba30..c6b5525 100644 --- a/src/lib/class.c +++ b/src/lib/class.c @@ -43,40 +43,6 @@ struct nl_cache *nl_cli_class_alloc_cache(struct nl_sock *sock, int ifindex) return cache; } -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 8b16f3f..4c64e7b 100644 --- a/src/lib/qdisc.c +++ b/src/lib/qdisc.c @@ -31,40 +31,6 @@ struct rtnl_qdisc *nl_cli_qdisc_alloc(void) return qdisc; } -void nl_cli_qdisc_parse_dev(struct rtnl_qdisc *qdisc, 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_qdisc_set_ifindex(qdisc, ival); -} - -void nl_cli_qdisc_parse_parent(struct rtnl_qdisc *qdisc, 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_qdisc_set_parent(qdisc, parent); -} - -void nl_cli_qdisc_parse_handle(struct rtnl_qdisc *qdisc, char *arg) -{ - uint32_t handle; - int err; - - if ((err = rtnl_tc_str2handle(arg, &handle)) < 0) - nl_cli_fatal(err, "Unable to parse handle \"%s\": %s", - arg, nl_geterror(err)); - - rtnl_qdisc_set_handle(qdisc, handle); -} - void nl_cli_qdisc_parse_kind(struct rtnl_qdisc *qdisc, char *arg) { rtnl_qdisc_set_kind(qdisc, arg); diff --git a/src/lib/tc.c b/src/lib/tc.c new file mode 100644 index 0000000..5f39498 --- /dev/null +++ b/src/lib/tc.c @@ -0,0 +1,83 @@ +/* + * src/lib/tc.c CLI Traffic Control 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> + */ + +#include <netlink/cli/utils.h> +#include <netlink/cli/tc.h> +#include <netlink/route/tc.h> + +/** + * @ingroup cli + * @defgroup cli_tc Queueing Disciplines + * @{ + */ +void nl_cli_tc_parse_dev(struct rtnl_tc *tc, struct nl_cache *link_cache, char *name) +{ + struct rtnl_link *link; + + link = rtnl_link_get_by_name(link_cache, name); + if (!link) + nl_cli_fatal(ENOENT, "Link \"%s\" does not exist.", name); + + rtnl_tc_set_link(tc, link); + rtnl_link_put(link); +} + +void nl_cli_tc_parse_parent(struct rtnl_tc *tc, 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_tc_set_parent(tc, parent); +} + +void nl_cli_tc_parse_handle(struct rtnl_tc *tc, char *arg) +{ + uint32_t handle; + int err; + + if ((err = rtnl_tc_str2handle(arg, &handle)) < 0) + nl_cli_fatal(err, "Unable to parse handle \"%s\": %s", + arg, nl_geterror(err)); + + rtnl_tc_set_handle(tc, handle); +} + +void nl_cli_tc_parse_mtu(struct rtnl_tc *tc, char *arg) +{ + rtnl_tc_set_mtu(tc, nl_cli_parse_u32(arg)); +} + +void nl_cli_tc_parse_mpu(struct rtnl_tc *tc, char *arg) +{ + rtnl_tc_set_mpu(tc, nl_cli_parse_u32(arg)); +} + +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_linktype(struct rtnl_tc *tc, char *arg) +{ + int type; + + if ((type = nl_str2llproto(arg)) < 0) + nl_cli_fatal(type, "Unable to parse linktype \"%s\": %s", + arg, nl_geterror(type)); + + rtnl_tc_set_linktype(tc, type); +} + +/** @} */ |