6#include <netlink/cli/utils.h>
7#include <netlink/cli/tc.h>
8#include <netlink/cli/qdisc.h>
9#include <netlink/cli/link.h>
11#include <netlink-private/route/tc-api.h>
13#include <linux/netlink.h>
17static void print_usage(
void)
20"Usage: nl-qdisc-add [OPTIONS]... QDISC [CONFIGURATION]...\n"
23" -q, --quiet Do not print informal notifications.\n"
24" -h, --help Show this help text.\n"
25" -v, --version Show versioning information.\n"
26" --update Update qdisc if it exists.\n"
27" --replace Replace or update qdisc if it exists.\n"
28" --update-only Only update qdisc, never create it.\n"
29" --replace-only Only replace or update qdisc, never create it.\n"
30" -d, --dev=DEV Network device the qdisc should be attached to.\n"
31" -i, --id=ID ID of new qdisc (default: auto-generated)r\n"
32" -p, --parent=ID ID of parent { root | ingress | QDISC-ID }\n"
35" -h, --help Show help text of qdisc specific options.\n"
38" $ nl-qdisc-add --dev=eth1 --parent=root htb --rate=100mbit\n"
44int main(
int argc,
char *argv[])
47 struct rtnl_qdisc *qdisc;
49 struct nl_cache *link_cache;
55 struct rtnl_tc_ops *ops;
56 int err, flags = NLM_F_CREATE | NLM_F_EXCL;
57 char *kind, *
id = NULL;
59 sock = nl_cli_alloc_socket();
60 nl_cli_connect(sock, NETLINK_ROUTE);
62 link_cache = nl_cli_link_alloc_cache(sock);
64 qdisc = nl_cli_qdisc_alloc();
65 tc = (
struct rtnl_tc *) qdisc;
75 static struct option long_opts[] = {
76 {
"quiet", 0, 0,
'q' },
77 {
"help", 0, 0,
'h' },
78 {
"version", 0, 0,
'v' },
80 {
"parent", 1, 0,
'p' },
82 {
"replace", 0, 0, ARG_REPLACE },
83 {
"update", 0, 0, ARG_UPDATE },
84 {
"replace-only", 0, 0, ARG_REPLACE_ONLY },
85 {
"update-only", 0, 0, ARG_UPDATE_ONLY },
89 c = getopt_long(argc, argv,
"+qhvd:p:i:",
95 case 'q': quiet = 1;
break;
96 case 'h': print_usage();
break;
97 case 'v': nl_cli_print_version();
break;
98 case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg);
break;
99 case 'p': nl_cli_tc_parse_parent(tc, optarg);
break;
100 case 'i':
id = strdup(optarg);
break;
101 case ARG_UPDATE: flags = NLM_F_CREATE;
break;
102 case ARG_REPLACE: flags = NLM_F_CREATE | NLM_F_REPLACE;
break;
103 case ARG_UPDATE_ONLY: flags = 0;
break;
104 case ARG_REPLACE_ONLY: flags = NLM_F_REPLACE;
break;
112 nl_cli_fatal(EINVAL,
"You must specify a network device (--dev=XXX)");
118 nl_cli_tc_parse_handle(tc,
id, 1);
122 kind = argv[optind++];
125 if (!(ops = rtnl_tc_get_ops(tc)))
128 if (!(tm = nl_cli_tc_lookup(ops)))
129 nl_cli_fatal(ENOTSUP,
"Qdisc type \"%s\" not supported.", kind);
131 tm->tm_parse_argv(tc, argc, argv);
139 nl_cli_fatal(EINVAL,
"Unable to add qdisc: %s", nl_geterror(err));
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
void nl_object_dump(struct nl_object *obj, struct nl_dump_params *params)
Dump this object according to the specified parameters.
int rtnl_qdisc_add(struct nl_sock *sk, struct rtnl_qdisc *qdisc, int flags)
Add qdisc.
uint32_t rtnl_tc_get_parent(struct rtnl_tc *tc)
Return parent identifier of a traffic control object.
int rtnl_tc_set_kind(struct rtnl_tc *tc, const char *kind)
Define the type of traffic control object.
int rtnl_tc_get_ifindex(struct rtnl_tc *tc)
Return interface index of traffic control object.
@ NL_DUMP_DETAILS
Dump all attributes but no statistics.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.