2 * src/nl-qdisc-delete.c Delete Queuing Disciplines
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
9 * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch>
12 #include <netlink/cli/utils.h>
13 #include <netlink/cli/qdisc.h>
14 #include <netlink/cli/link.h>
16 static int quiet = 0, default_yes = 0, deleted = 0, interactive = 0;
19 static void print_usage(void)
22 "Usage: nl-qdisc-delete [OPTION]... [QDISC]\n"
25 " -i, --interactive Run interactively\n"
26 " --yes Set default answer to yes\n"
27 " -q, --quiet Do not print informal notifications\n"
28 " -h, --help Show this help\n"
29 " -v, --version Show versioning information\n"
32 " -d, --dev=DEV Device the qdisc is attached to\n"
33 " -p, --parent=HANDLE Identifier of parent qdisc\n"
34 " -H, --handle=HANDLE Identifier\n"
35 " -k, --kind=NAME Kind of qdisc (e.g. pfifo_fast)\n"
41 static void delete_cb(struct nl_object *obj, void *arg)
43 struct rtnl_qdisc *qdisc = nl_object_priv(obj);
44 struct nl_dump_params params = {
45 .dp_type = NL_DUMP_LINE,
50 if (interactive && !nl_cli_confirm(obj, ¶ms, default_yes))
53 if ((err = rtnl_qdisc_delete(sock, qdisc)) < 0)
54 nl_cli_fatal(err, "Unable to delete qdisc: %s\n", nl_geterror(err));
58 nl_object_dump(obj, ¶ms);
64 int main(int argc, char *argv[])
66 struct rtnl_qdisc *qdisc;
67 struct nl_cache *link_cache, *qdisc_cache;
69 sock = nl_cli_alloc_socket();
70 nl_cli_connect(sock, NETLINK_ROUTE);
71 link_cache = nl_cli_link_alloc_cache(sock);
72 qdisc_cache = nl_cli_qdisc_alloc_cache(sock);
73 qdisc = nl_cli_qdisc_alloc();
80 static struct option long_opts[] = {
81 { "interactive", 0, 0, 'i' },
82 { "yes", 0, 0, ARG_YES },
83 { "quiet", 0, 0, 'q' },
84 { "help", 0, 0, 'h' },
85 { "version", 0, 0, 'v' },
87 { "parent", 1, 0, 'p' },
88 { "handle", 1, 0, 'H' },
89 { "kind", 1, 0, 'k' },
93 c = getopt_long(argc, argv, "iqhvd:p:H:k:", long_opts, &optidx);
98 case 'i': interactive = 1; break;
99 case ARG_YES: default_yes = 1; break;
100 case 'q': quiet = 1; break;
101 case 'h': print_usage(); break;
102 case 'v': nl_cli_print_version(); break;
103 case 'd': nl_cli_qdisc_parse_dev(qdisc, link_cache, optarg); break;
104 case 'p': nl_cli_qdisc_parse_parent(qdisc, optarg); break;
105 case 'H': nl_cli_qdisc_parse_handle(qdisc, optarg); break;
106 case 'k': nl_cli_qdisc_parse_kind(qdisc, optarg); break;
110 nl_cache_foreach_filter(qdisc_cache, OBJ_CAST(qdisc), delete_cb, NULL);
113 printf("Deleted %d qdiscs\n", deleted);