12 #include <netlink/cli/utils.h>
13 #include <netlink/cli/tc.h>
14 #include <netlink/cli/qdisc.h>
15 #include <netlink/cli/link.h>
17 static int quiet = 0, default_yes = 0, deleted = 0, interactive = 0;
18 static struct nl_sock *sock;
20 static void print_usage(
void)
23 "Usage: nl-qdisc-delete [OPTION]... [QDISC]\n"
26 " --interactive Run interactively.\n"
27 " --yes Set default answer to yes.\n"
28 " -q, --quiet Do not print informal notifications.\n"
29 " -h, --help Show this help text and exit.\n"
30 " -v, --version Show versioning information and exit.\n"
32 " -d, --dev=DEV Device the qdisc is attached to.\n"
33 " -p, --parent=ID Identifier of parent qdisc/class.\n"
34 " -i, --id=ID 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);
54 if (interactive && !nl_cli_confirm(obj, ¶ms, default_yes))
58 nl_cli_fatal(err,
"Unable to delete qdisc: %s\n", nl_geterror(err));
68 int main(
int argc,
char *argv[])
70 struct rtnl_qdisc *qdisc;
72 struct nl_cache *link_cache, *qdisc_cache;
75 sock = nl_cli_alloc_socket();
76 nl_cli_connect(sock, NETLINK_ROUTE);
77 link_cache = nl_cli_link_alloc_cache(sock);
78 qdisc_cache = nl_cli_qdisc_alloc_cache(sock);
79 qdisc = nl_cli_qdisc_alloc();
80 tc = (
struct rtnl_tc *) qdisc;
86 ARG_INTERACTIVE = 258,
88 static struct option long_opts[] = {
89 {
"interactive", 0, 0, ARG_INTERACTIVE },
90 {
"yes", 0, 0, ARG_YES },
91 {
"quiet", 0, 0,
'q' },
92 {
"help", 0, 0,
'h' },
93 {
"version", 0, 0,
'v' },
95 {
"parent", 1, 0,
'p' },
97 {
"kind", 1, 0,
'k' },
101 c = getopt_long(argc, argv,
"qhvd:p:i:k:", long_opts, &optidx);
107 case ARG_INTERACTIVE: interactive = 1;
break;
108 case ARG_YES: default_yes = 1;
break;
109 case 'q': quiet = 1;
break;
110 case 'h': print_usage();
break;
111 case 'v': nl_cli_print_version();
break;
114 nl_cli_tc_parse_dev(tc, link_cache, optarg);
118 nl_cli_tc_parse_parent(tc, optarg);
122 nl_cli_tc_parse_handle(tc, optarg, 0);
126 nl_cli_tc_parse_kind(tc, optarg);
131 if (nfilter == 0 && !interactive && !default_yes) {
133 "You are attempting to delete all qdiscs on all devices.\n"
134 "If you want to proceed, run nl-qdisc-delete --yes.\n"
141 printf(
"Deleted %d qdiscs\n", deleted);