diff options
author | Thomas Graf <tgraf@suug.ch> | 2010-10-20 12:57:39 (GMT) |
---|---|---|
committer | Thomas Graf <tgraf@suug.ch> | 2010-10-20 12:57:39 (GMT) |
commit | 27883b0f9b0da6bb33ccc185107a2870df25d030 (patch) | |
tree | fbda57a6026fbc6653648ecb9d588d2d9e938b5e /src/lib/class.c | |
parent | 18848090f99cae37ac1a3052369ab4d26ed9ada0 (diff) | |
download | libnl-27883b0f9b0da6bb33ccc185107a2870df25d030.zip libnl-27883b0f9b0da6bb33ccc185107a2870df25d030.tar.gz libnl-27883b0f9b0da6bb33ccc185107a2870df25d030.tar.bz2 |
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/class.c')
-rw-r--r-- | src/lib/class.c | 71 |
1 files changed, 71 insertions, 0 deletions
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); +} + +/** @} */ |