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 | |
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')
-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 | ||||
-rw-r--r-- | src/nl-class-add.c | 31 | ||||
-rw-r--r-- | src/nl-class-delete.c | 22 | ||||
-rw-r--r-- | src/nl-class-list.c | 11 | ||||
-rw-r--r-- | src/nl-qdisc-add.c | 13 | ||||
-rw-r--r-- | src/nl-qdisc-delete.c | 9 | ||||
-rw-r--r-- | src/nl-qdisc-list.c | 9 | ||||
-rw-r--r-- | src/nl-tctree-list.c | 4 |
11 files changed, 146 insertions, 106 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); +} + +/** @} */ diff --git a/src/nl-class-add.c b/src/nl-class-add.c index 6e1c402..553dec1 100644 --- a/src/nl-class-add.c +++ b/src/nl-class-add.c @@ -10,6 +10,7 @@ */ #include <netlink/cli/utils.h> +#include <netlink/cli/tc.h> #include <netlink/cli/qdisc.h> #include <netlink/cli/class.h> #include <netlink/cli/link.h> @@ -28,8 +29,12 @@ static void print_usage(void) " --update Update class if it exists.\n" " --update-only Only update class, never create it.\n" " -d, --dev=DEV Network device the class should be attached to.\n" -" -i, --id=ID ID of new class (default: auto-generated)r\n" +" -i, --id=ID ID of new class (default: auto-generated)\n" " -p, --parent=ID ID of parent { root | ingress | class-ID }\n" +" --mtu=SIZE Overwrite MTU (default: MTU of network device)\n" +" --mpu=SIZE Minimum packet size on the link (default: 0).\n" +" --overhead=SIZE Overhead in bytes per packet (default: 0).\n" +" --linktype=TYPE Overwrite linktype (default: type of network device)\n" "\n" "CONFIGURATION\n" " -h, --help Show help text of class specific options.\n" @@ -45,6 +50,7 @@ int main(int argc, char *argv[]) { struct nl_sock *sock; struct rtnl_class *class; + struct rtnl_tc *tc; struct nl_cache *link_cache; struct nl_dump_params dp = { .dp_type = NL_DUMP_DETAILS, @@ -61,12 +67,17 @@ int main(int argc, char *argv[]) link_cache = nl_cli_link_alloc_cache(sock); class = nl_cli_class_alloc(); + tc = (struct rtnl_tc *) class; for (;;) { int c, optidx = 0; enum { ARG_UPDATE = 257, ARG_UPDATE_ONLY = 258, + ARG_MTU, + ARG_MPU, + ARG_OVERHEAD, + ARG_LINKTYPE, }; static struct option long_opts[] = { { "quiet", 0, 0, 'q' }, @@ -77,6 +88,10 @@ int main(int argc, char *argv[]) { "id", 1, 0, 'i' }, { "update", 0, 0, ARG_UPDATE }, { "update-only", 0, 0, ARG_UPDATE_ONLY }, + { "mtu", 1, 0, ARG_MTU }, + { "mpu", 1, 0, ARG_MPU }, + { "overhead", 1, 0, ARG_OVERHEAD }, + { "linktype", 1, 0, ARG_LINKTYPE }, { 0, 0, 0, 0 } }; @@ -89,21 +104,25 @@ int main(int argc, char *argv[]) case 'q': quiet = 1; break; case 'h': print_usage(); break; case 'v': nl_cli_print_version(); break; - case 'd': nl_cli_class_parse_dev(class, link_cache, optarg); break; - case 'p': nl_cli_class_parse_parent(class, optarg); break; - case 'i': nl_cli_class_parse_handle(class, optarg); break; + 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); break; case ARG_UPDATE: flags = NLM_F_CREATE; break; case ARG_UPDATE_ONLY: flags = 0; break; + case ARG_MTU: nl_cli_tc_parse_mtu(tc, optarg); break; + case ARG_MPU: nl_cli_tc_parse_mpu(tc, optarg); break; + case ARG_OVERHEAD: nl_cli_tc_parse_overhead(tc, optarg); break; + case ARG_LINKTYPE: nl_cli_tc_parse_linktype(tc, optarg); break; } } if (optind >= argc) print_usage(); - if (!rtnl_class_get_ifindex(class)) + if (!rtnl_tc_get_ifindex(tc)) nl_cli_fatal(EINVAL, "You must specify a network device (--dev=XXX)"); - if (!rtnl_class_get_parent(class)) + if (!rtnl_tc_get_parent(tc)) nl_cli_fatal(EINVAL, "You must specify a parent (--parent=XXX)"); kind = argv[optind++]; diff --git a/src/nl-class-delete.c b/src/nl-class-delete.c index 94b11d0..94a6ab4 100644 --- a/src/nl-class-delete.c +++ b/src/nl-class-delete.c @@ -68,12 +68,14 @@ static void delete_cb(struct nl_object *obj, void *arg) int main(int argc, char *argv[]) { struct rtnl_class *class; + struct rtnl_tc *tc; struct nl_cache *link_cache, *class_cache; sock = nl_cli_alloc_socket(); nl_cli_connect(sock, NETLINK_ROUTE); link_cache = nl_cli_link_alloc_cache(sock); class = nl_cli_class_alloc(); + tc = (struct rtnl_tc *) class; for (;;) { int c, optidx = 0; @@ -105,25 +107,17 @@ int main(int argc, char *argv[]) case 'q': quiet = 1; break; case 'h': print_usage(); break; case 'v': nl_cli_print_version(); break; - case 'd': - nl_cli_class_parse_dev(class, link_cache, optarg); - break; - case 'p': - nl_cli_class_parse_parent(class, optarg); - break; - case 'i': - nl_cli_class_parse_handle(class, optarg); - break; - case 'k': - nl_cli_class_parse_kind(class, optarg); - break; + 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); break; + case 'k': nl_cli_class_parse_kind(class, optarg); break; } } - if (!rtnl_class_get_ifindex(class)) + if (!rtnl_tc_get_ifindex(tc)) nl_cli_fatal(EINVAL, "You must specify a network device (--dev=XXX)"); - class_cache = nl_cli_class_alloc_cache(sock, rtnl_class_get_ifindex(class)); + class_cache = nl_cli_class_alloc_cache(sock, rtnl_tc_get_ifindex(tc)); nl_cache_foreach_filter(class_cache, OBJ_CAST(class), delete_cb, NULL); diff --git a/src/nl-class-list.c b/src/nl-class-list.c index 7c0edff..3a38555 100644 --- a/src/nl-class-list.c +++ b/src/nl-class-list.c @@ -10,6 +10,7 @@ */ #include <netlink/cli/utils.h> +#include <netlink/cli/tc.h> #include <netlink/cli/class.h> #include <netlink/cli/link.h> @@ -61,6 +62,7 @@ static void dump_class(struct nl_object *obj, void *arg) int main(int argc, char *argv[]) { struct rtnl_class *class; + struct rtnl_tc *tc; struct nl_cache *link_cache; int ifindex; @@ -68,6 +70,7 @@ int main(int argc, char *argv[]) nl_cli_connect(sock, NETLINK_ROUTE); link_cache = nl_cli_link_alloc_cache(sock); class = nl_cli_class_alloc(); + tc = (struct rtnl_tc *) class; params.dp_fd = stdout; @@ -98,14 +101,14 @@ int main(int argc, char *argv[]) case ARG_STATS: params.dp_type = NL_DUMP_STATS; break; case 'h': print_usage(); break; case 'v': nl_cli_print_version(); break; - case 'd': nl_cli_class_parse_dev(class, link_cache, optarg); break; - case 'p': nl_cli_class_parse_parent(class, optarg); break; - case 'i': nl_cli_class_parse_handle(class, optarg); break; + 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); break; case 'k': nl_cli_class_parse_kind(class, optarg); break; } } - if ((ifindex = rtnl_class_get_ifindex(class))) + if ((ifindex = rtnl_tc_get_ifindex(tc))) __dump_class(ifindex, class); else nl_cache_foreach(link_cache, dump_class, class); diff --git a/src/nl-qdisc-add.c b/src/nl-qdisc-add.c index 739a6ed..57603b0 100644 --- a/src/nl-qdisc-add.c +++ b/src/nl-qdisc-add.c @@ -10,6 +10,7 @@ */ #include <netlink/cli/utils.h> +#include <netlink/cli/tc.h> #include <netlink/cli/qdisc.h> #include <netlink/cli/link.h> @@ -46,6 +47,7 @@ int main(int argc, char *argv[]) { struct nl_sock *sock; struct rtnl_qdisc *qdisc; + struct rtnl_tc *tc; struct nl_cache *link_cache; struct nl_dump_params dp = { .dp_type = NL_DUMP_DETAILS, @@ -62,6 +64,7 @@ int main(int argc, char *argv[]) link_cache = nl_cli_link_alloc_cache(sock); qdisc = nl_cli_qdisc_alloc(); + tc = (struct rtnl_tc *) qdisc; for (;;) { int c, optidx = 0; @@ -94,9 +97,9 @@ int main(int argc, char *argv[]) case 'q': quiet = 1; break; case 'h': print_usage(); break; case 'v': nl_cli_print_version(); break; - case 'd': nl_cli_qdisc_parse_dev(qdisc, link_cache, optarg); break; - case 'p': nl_cli_qdisc_parse_parent(qdisc, optarg); break; - case 'i': nl_cli_qdisc_parse_handle(qdisc, optarg); break; + 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); break; case ARG_UPDATE: flags = NLM_F_CREATE; break; case ARG_REPLACE: flags = NLM_F_CREATE | NLM_F_REPLACE; break; case ARG_UPDATE_ONLY: flags = 0; break; @@ -107,10 +110,10 @@ int main(int argc, char *argv[]) if (optind >= argc) print_usage(); - if (!rtnl_qdisc_get_ifindex(qdisc)) + if (!rtnl_tc_get_ifindex(tc)) nl_cli_fatal(EINVAL, "You must specify a network device (--dev=XXX)"); - if (!rtnl_qdisc_get_parent(qdisc)) + if (!rtnl_tc_get_parent(tc)) nl_cli_fatal(EINVAL, "You must specify a parent"); kind = argv[optind++]; diff --git a/src/nl-qdisc-delete.c b/src/nl-qdisc-delete.c index 24424a7..e91b054 100644 --- a/src/nl-qdisc-delete.c +++ b/src/nl-qdisc-delete.c @@ -10,6 +10,7 @@ */ #include <netlink/cli/utils.h> +#include <netlink/cli/tc.h> #include <netlink/cli/qdisc.h> #include <netlink/cli/link.h> @@ -63,6 +64,7 @@ static void delete_cb(struct nl_object *obj, void *arg) int main(int argc, char *argv[]) { struct rtnl_qdisc *qdisc; + struct rtnl_tc *tc; struct nl_cache *link_cache, *qdisc_cache; int nfilter = 0; @@ -71,6 +73,7 @@ int main(int argc, char *argv[]) link_cache = nl_cli_link_alloc_cache(sock); qdisc_cache = nl_cli_qdisc_alloc_cache(sock); qdisc = nl_cli_qdisc_alloc(); + tc = (struct rtnl_tc *) qdisc; for (;;) { int c, optidx = 0; @@ -104,15 +107,15 @@ int main(int argc, char *argv[]) case 'v': nl_cli_print_version(); break; case 'd': nfilter++; - nl_cli_qdisc_parse_dev(qdisc, link_cache, optarg); + nl_cli_tc_parse_dev(tc, link_cache, optarg); break; case 'p': nfilter++; - nl_cli_qdisc_parse_parent(qdisc, optarg); + nl_cli_tc_parse_parent(tc, optarg); break; case 'i': nfilter++; - nl_cli_qdisc_parse_handle(qdisc, optarg); + nl_cli_tc_parse_handle(tc, optarg); break; case 'k': nfilter++; diff --git a/src/nl-qdisc-list.c b/src/nl-qdisc-list.c index daea5d2..1ecb9a4 100644 --- a/src/nl-qdisc-list.c +++ b/src/nl-qdisc-list.c @@ -10,6 +10,7 @@ */ #include <netlink/cli/utils.h> +#include <netlink/cli/tc.h> #include <netlink/cli/qdisc.h> #include <netlink/cli/link.h> @@ -41,6 +42,7 @@ int main(int argc, char *argv[]) { struct nl_sock *sock; struct rtnl_qdisc *qdisc; + struct rtnl_tc *tc; struct nl_cache *link_cache, *qdisc_cache; struct nl_dump_params params = { .dp_type = NL_DUMP_LINE, @@ -52,6 +54,7 @@ int main(int argc, char *argv[]) link_cache = nl_cli_link_alloc_cache(sock); qdisc_cache = nl_cli_qdisc_alloc_cache(sock); qdisc = nl_cli_qdisc_alloc(); + tc = (struct rtnl_tc *) qdisc; for (;;) { int c, optidx = 0; @@ -80,9 +83,9 @@ int main(int argc, char *argv[]) case ARG_STATS: params.dp_type = NL_DUMP_STATS; break; case 'h': print_usage(); break; case 'v': nl_cli_print_version(); break; - case 'd': nl_cli_qdisc_parse_dev(qdisc, link_cache, optarg); break; - case 'p': nl_cli_qdisc_parse_parent(qdisc, optarg); break; - case 'i': nl_cli_qdisc_parse_handle(qdisc, optarg); break; + 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); break; case 'k': nl_cli_qdisc_parse_kind(qdisc, optarg); break; } } diff --git a/src/nl-tctree-list.c b/src/nl-tctree-list.c index a074a51..4cd5035 100644 --- a/src/nl-tctree-list.c +++ b/src/nl-tctree-list.c @@ -41,7 +41,7 @@ static void print_class(struct nl_object *obj, void *arg) struct rtnl_qdisc *leaf; struct rtnl_class *class = (struct rtnl_class *) obj; struct nl_cache *cls_cache; - uint32_t parent = rtnl_class_get_handle(class); + uint32_t parent = rtnl_tc_get_handle((struct rtnl_tc *) class); params.dp_prefix = (int)(long) arg; nl_object_dump(obj, ¶ms); @@ -64,7 +64,7 @@ static void print_qdisc(struct nl_object *obj, void *arg) { struct rtnl_qdisc *qdisc = (struct rtnl_qdisc *) obj; struct nl_cache *cls_cache; - uint32_t parent = rtnl_qdisc_get_handle(qdisc); + uint32_t parent = rtnl_tc_get_handle((struct rtnl_tc *) qdisc); params.dp_prefix = (int)(long) arg; nl_object_dump(obj, ¶ms); |