summaryrefslogtreecommitdiff
path: root/src/nl-qdisc-add.c
diff options
context:
space:
mode:
authorThomas Graf <tgraf@suug.ch>2010-11-01 08:17:40 +0100
committerThomas Graf <tgraf@suug.ch>2010-11-01 08:17:40 +0100
commit4267d8f336b11e8fbbf1a4b54499ee19012b1b28 (patch)
tree4349cb1f09cc204f50a2555565359d486d2ce694 /src/nl-qdisc-add.c
parent7903d6ab4bc54421463517a116e93eef2448e92c (diff)
downloadlibnl-4267d8f336b11e8fbbf1a4b54499ee19012b1b28.tar.gz
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-qdisc-add.c')
-rw-r--r--src/nl-qdisc-add.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/nl-qdisc-add.c b/src/nl-qdisc-add.c
index 57603b05..9da0f18d 100644
--- a/src/nl-qdisc-add.c
+++ b/src/nl-qdisc-add.c
@@ -56,7 +56,7 @@ int main(int argc, char *argv[])
struct nl_cli_qdisc_module *qm;
struct rtnl_qdisc_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);
@@ -99,7 +99,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_REPLACE: flags = NLM_F_CREATE | NLM_F_REPLACE; break;
case ARG_UPDATE_ONLY: flags = 0; break;
@@ -116,6 +116,11 @@ int main(int argc, char *argv[])
if (!rtnl_tc_get_parent(tc))
nl_cli_fatal(EINVAL, "You must specify a parent");
+ if (id) {
+ nl_cli_tc_parse_handle(tc, id, 1);
+ free(id);
+ }
+
kind = argv[optind++];
rtnl_qdisc_set_kind(qdisc, kind);