8#include <linux/netlink.h>
10#include <netlink/cli/utils.h>
11#include <netlink/cli/tc.h>
12#include <netlink/cli/qdisc.h>
13#include <netlink/cli/link.h>
15static int quiet = 0, default_yes = 0, deleted = 0, interactive = 0;
16static struct nl_sock *sock;
18static void print_usage(
void)
21 "Usage: nl-qdisc-delete [OPTION]... [QDISC]\n"
24 " --interactive Run interactively.\n"
25 " --yes Set default answer to yes.\n"
26 " -q, --quiet Do not print informal notifications.\n"
27 " -h, --help Show this help text and exit.\n"
28 " -v, --version Show versioning information and exit.\n"
30 " -d, --dev=DEV Device the qdisc is attached to.\n"
31 " -p, --parent=ID Identifier of parent qdisc/class.\n"
32 " -i, --id=ID Identifier\n"
33 " -k, --kind=NAME Kind of qdisc (e.g. pfifo_fast)\n"
39static void delete_cb(
struct nl_object *obj,
void *arg)
41 struct rtnl_qdisc *qdisc = nl_object_priv(obj);
52 if (interactive && !nl_cli_confirm(obj, ¶ms, default_yes))
56 nl_cli_fatal(err,
"Unable to delete qdisc: %s\n", nl_geterror(err));
66int main(
int argc,
char *argv[])
70 struct nl_cache *link_cache, *qdisc_cache;
73 sock = nl_cli_alloc_socket();
74 nl_cli_connect(sock, NETLINK_ROUTE);
75 link_cache = nl_cli_link_alloc_cache(sock);
76 qdisc_cache = nl_cli_qdisc_alloc_cache(sock);
77 qdisc = nl_cli_qdisc_alloc();
84 ARG_INTERACTIVE = 258,
86 static struct option long_opts[] = {
87 {
"interactive", 0, 0, ARG_INTERACTIVE },
88 {
"yes", 0, 0, ARG_YES },
89 {
"quiet", 0, 0,
'q' },
90 {
"help", 0, 0,
'h' },
91 {
"version", 0, 0,
'v' },
93 {
"parent", 1, 0,
'p' },
95 {
"kind", 1, 0,
'k' },
99 c = getopt_long(argc, argv,
"qhvd:p:i:k:", long_opts, &optidx);
105 case ARG_INTERACTIVE: interactive = 1;
break;
106 case ARG_YES: default_yes = 1;
break;
107 case 'q': quiet = 1;
break;
108 case 'h': print_usage();
break;
109 case 'v': nl_cli_print_version();
break;
112 nl_cli_tc_parse_dev(tc, link_cache, optarg);
116 nl_cli_tc_parse_parent(tc, optarg);
120 nl_cli_tc_parse_handle(tc, optarg, 0);
124 nl_cli_tc_parse_kind(tc, optarg);
129 if (nfilter == 0 && !interactive && !default_yes) {
131 "You are attempting to delete all qdiscs on all devices.\n"
132 "If you want to proceed, run nl-qdisc-delete --yes.\n"
139 printf(
"Deleted %d qdiscs\n", deleted);
void nl_cache_foreach_filter(struct nl_cache *cache, struct nl_object *filter, void(*cb)(struct nl_object *, void *), void *arg)
Call a callback on each element of the cache (filtered).
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_delete(struct nl_sock *sk, struct rtnl_qdisc *qdisc)
Delete qdisc.
uint32_t rtnl_tc_get_handle(struct rtnl_tc *tc)
Return identifier of a traffic control object.
@ NL_DUMP_LINE
Dump object briefly on one line.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.