1 /*
2 * src/lib/qdisc.c CLI QDisc Helpers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation version 2.1
7 * of the License.
8 *
9 * Copyright (c) 2008-2009 Thomas Graf <tgraf@suug.ch>
10 */
11
12 /**
13 * @ingroup cli
14 * @defgroup cli_qdisc Queueing Disciplines
15 *
16 * @{
17 */
18
19 #include <netlink/cli/utils.h>
20 #include <netlink/cli/qdisc.h>
21
nl_cli_qdisc_alloc(void)22 struct rtnl_qdisc *nl_cli_qdisc_alloc(void)
23 {
24 struct rtnl_qdisc *qdisc;
25
26 qdisc = rtnl_qdisc_alloc();
27 if (!qdisc)
28 nl_cli_fatal(ENOMEM, "Unable to allocate qdisc object");
29
30 return qdisc;
31 }
32
nl_cli_qdisc_parse_dev(struct rtnl_qdisc * qdisc,struct nl_cache * link_cache,char * arg)33 void nl_cli_qdisc_parse_dev(struct rtnl_qdisc *qdisc, struct nl_cache *link_cache, char *arg)
34 {
35 int ival;
36
37 if (!(ival = rtnl_link_name2i(link_cache, arg)))
38 nl_cli_fatal(ENOENT, "Link \"%s\" does not exist", arg);
39
40 rtnl_qdisc_set_ifindex(qdisc, ival);
41 }
42
nl_cli_qdisc_parse_parent(struct rtnl_qdisc * qdisc,char * arg)43 void nl_cli_qdisc_parse_parent(struct rtnl_qdisc *qdisc, char *arg)
44 {
45 uint32_t parent;
46 int err;
47
48 if ((err = rtnl_tc_str2handle(arg, &parent)) < 0)
49 nl_cli_fatal(err, "Unable to parse handle \"%s\": %s",
50 arg, nl_geterror(err));
51
52 rtnl_qdisc_set_parent(qdisc, parent);
53 }
54
nl_cli_qdisc_parse_handle(struct rtnl_qdisc * qdisc,char * arg)55 void nl_cli_qdisc_parse_handle(struct rtnl_qdisc *qdisc, char *arg)
56 {
57 uint32_t handle;
58 int err;
59
60 if ((err = rtnl_tc_str2handle(arg, &handle)) < 0)
61 nl_cli_fatal(err, "Unable to parse handle \"%s\": %s",
62 arg, nl_geterror(err));
63
64 rtnl_qdisc_set_handle(qdisc, handle);
65 }
66
nl_cli_qdisc_parse_kind(struct rtnl_qdisc * qdisc,char * arg)67 void nl_cli_qdisc_parse_kind(struct rtnl_qdisc *qdisc, char *arg)
68 {
69 rtnl_qdisc_set_kind(qdisc, arg);
70 }
71
72 /** @} */
73