12 #include <netlink/cli/utils.h>
13 #include <netlink/cli/tc.h>
14 #include <netlink/cli/qdisc.h>
15 #include <netlink/cli/link.h>
19 static void print_usage(
void)
22 "Usage: nl-qdisc-add [OPTIONS]... QDISC [CONFIGURATION]...\n"
25 " -q, --quiet Do not print informal notifications.\n"
26 " -h, --help Show this help text.\n"
27 " -v, --version Show versioning information.\n"
28 " --update Update qdisc if it exists.\n"
29 " --replace Replace or update qdisc if it exists.\n"
30 " --update-only Only update qdisc, never create it.\n"
31 " --replace-only Only replace or update qdisc, never create it.\n"
32 " -d, --dev=DEV Network device the qdisc should be attached to.\n"
33 " -i, --id=ID ID of new qdisc (default: auto-generated)r\n"
34 " -p, --parent=ID ID of parent { root | ingress | QDISC-ID }\n"
37 " -h, --help Show help text of qdisc specific options.\n"
40 " $ nl-qdisc-add --dev=eth1 --parent=root htb --rate=100mbit\n"
46 int main(
int argc,
char *argv[])
49 struct rtnl_qdisc *qdisc;
51 struct nl_cache *link_cache;
58 int err, flags = NLM_F_CREATE | NLM_F_EXCL;
59 char *kind, *
id = NULL;
61 sock = nl_cli_alloc_socket();
62 nl_cli_connect(sock, NETLINK_ROUTE);
64 link_cache = nl_cli_link_alloc_cache(sock);
66 qdisc = nl_cli_qdisc_alloc();
67 tc = (
struct rtnl_tc *) qdisc;
77 static struct option long_opts[] = {
78 {
"quiet", 0, 0,
'q' },
79 {
"help", 0, 0,
'h' },
80 {
"version", 0, 0,
'v' },
82 {
"parent", 1, 0,
'p' },
84 {
"replace", 0, 0, ARG_REPLACE },
85 {
"update", 0, 0, ARG_UPDATE },
86 {
"replace-only", 0, 0, ARG_REPLACE_ONLY },
87 {
"update-only", 0, 0, ARG_UPDATE_ONLY },
91 c = getopt_long(argc, argv,
"+qhvd:p:i:",
97 case 'q': quiet = 1;
break;
98 case 'h': print_usage();
break;
99 case 'v': nl_cli_print_version();
break;
100 case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg);
break;
101 case 'p': nl_cli_tc_parse_parent(tc, optarg);
break;
102 case 'i':
id = strdup(optarg);
break;
103 case ARG_UPDATE: flags = NLM_F_CREATE;
break;
104 case ARG_REPLACE: flags = NLM_F_CREATE | NLM_F_REPLACE;
break;
105 case ARG_UPDATE_ONLY: flags = 0;
break;
106 case ARG_REPLACE_ONLY: flags = NLM_F_REPLACE;
break;
114 nl_cli_fatal(EINVAL,
"You must specify a network device (--dev=XXX)");
120 nl_cli_tc_parse_handle(tc,
id, 1);
124 kind = argv[optind++];
127 if (!(ops = rtnl_tc_get_ops(tc)))
130 if (!(tm = nl_cli_tc_lookup(ops)))
131 nl_cli_fatal(ENOTSUP,
"Qdisc type \"%s\" not supported.", kind);
133 tm->tm_parse_argv(tc, argc, argv);
141 nl_cli_fatal(EINVAL,
"Unable to add qdisc: %s", nl_geterror(err));