diff options
author | Thomas Graf <tgraf@suug.ch> | 2010-11-01 07:17:40 (GMT) |
---|---|---|
committer | Thomas Graf <tgraf@suug.ch> | 2010-11-01 07:17:40 (GMT) |
commit | 4267d8f336b11e8fbbf1a4b54499ee19012b1b28 (patch) | |
tree | 4349cb1f09cc204f50a2555565359d486d2ce694 /src/nl-cls-add.c | |
parent | 7903d6ab4bc54421463517a116e93eef2448e92c (diff) | |
download | libnl-4267d8f336b11e8fbbf1a4b54499ee19012b1b28.zip libnl-4267d8f336b11e8fbbf1a4b54499ee19012b1b28.tar.gz libnl-4267d8f336b11e8fbbf1a4b54499ee19012b1b28.tar.bz2 |
classid auto generation if provided tc name does not exist
Manually editing etc/libnl/classid before adding tc objects is a pain.
This patch adds code to attempt auto generating a unique tc id which
will then be assigned to the provided name and added to the classid
file.
This will make the following commands work with prior definitions of
the names "top" and "test"
sudo sbin/nl-qdisc-add --dev eth0 --parent root --id top htb
sudo sbin/nl-class-add --dev eth0 --parent top --id test htb --rate 100mbit
It will generate the following ids automatically:
4001: top
4001:1 test
Diffstat (limited to 'src/nl-cls-add.c')
-rw-r--r-- | src/nl-cls-add.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/nl-cls-add.c b/src/nl-cls-add.c index 5e2c2dc..fad9313 100644 --- a/src/nl-cls-add.c +++ b/src/nl-cls-add.c @@ -59,7 +59,7 @@ int main(int argc, char *argv[]) struct nl_cli_cls_module *cm; struct rtnl_cls_ops *ops; int err, flags = NLM_F_CREATE | NLM_F_EXCL; - char *kind; + char *kind, *id = NULL; sock = nl_cli_alloc_socket(); nl_cli_connect(sock, NETLINK_ROUTE); @@ -110,7 +110,7 @@ int main(int argc, char *argv[]) case 'v': nl_cli_print_version(); 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 'i': id = strdup(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; @@ -133,6 +133,11 @@ int main(int argc, char *argv[]) if (!rtnl_tc_get_parent(tc)) nl_cli_fatal(EINVAL, "You must specify a parent (--parent=XXX)"); + if (id) { + nl_cli_tc_parse_handle(tc, id, 1); + free(id); + } + kind = argv[optind++]; rtnl_cls_set_kind(cls, kind); |