libnl 2.0

/tmp/buildd/libnl2-2.0/src/lib/qdisc.c

00001 /*
00002  * src/lib/qdisc.c     CLI QDisc Helpers
00003  *
00004  *      This library is free software; you can redistribute it and/or
00005  *      modify it under the terms of the GNU Lesser General Public
00006  *      License as published by the Free Software Foundation version 2.1
00007  *      of the License.
00008  *
00009  * Copyright (c) 2008-2009 Thomas Graf <tgraf@suug.ch>
00010  */
00011 
00012 /**
00013  * @ingroup cli
00014  * @defgroup cli_qdisc Queueing Disciplines
00015  *
00016  * @{
00017  */
00018 
00019 #include <netlink/cli/utils.h>
00020 #include <netlink/cli/qdisc.h>
00021 
00022 struct rtnl_qdisc *nl_cli_qdisc_alloc(void)
00023 {
00024         struct rtnl_qdisc *qdisc;
00025 
00026         qdisc = rtnl_qdisc_alloc();
00027         if (!qdisc)
00028                 nl_cli_fatal(ENOMEM, "Unable to allocate qdisc object");
00029 
00030         return qdisc;
00031 }
00032 
00033 void nl_cli_qdisc_parse_dev(struct rtnl_qdisc *qdisc, struct nl_cache *link_cache, char *arg)
00034 {
00035         int ival;
00036 
00037         if (!(ival = rtnl_link_name2i(link_cache, arg)))
00038                 nl_cli_fatal(ENOENT, "Link \"%s\" does not exist", arg);
00039 
00040         rtnl_qdisc_set_ifindex(qdisc, ival);
00041 }
00042 
00043 void nl_cli_qdisc_parse_parent(struct rtnl_qdisc *qdisc, char *arg)
00044 {
00045         uint32_t parent;
00046         int err;
00047 
00048         if ((err = rtnl_tc_str2handle(arg, &parent)) < 0)
00049                 nl_cli_fatal(err, "Unable to parse handle \"%s\": %s",
00050                       arg, nl_geterror(err));
00051 
00052         rtnl_qdisc_set_parent(qdisc, parent);
00053 }
00054 
00055 void nl_cli_qdisc_parse_handle(struct rtnl_qdisc *qdisc, char *arg)
00056 {
00057         uint32_t handle;
00058         int err;
00059 
00060         if ((err = rtnl_tc_str2handle(arg, &handle)) < 0)
00061                 nl_cli_fatal(err, "Unable to parse handle \"%s\": %s",
00062                       arg, nl_geterror(err));
00063 
00064         rtnl_qdisc_set_handle(qdisc, handle);
00065 }
00066 
00067 void nl_cli_qdisc_parse_kind(struct rtnl_qdisc *qdisc, char *arg)
00068 {
00069         rtnl_qdisc_set_kind(qdisc, arg);
00070 }
00071 
00072 /** @} */