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 <linux/netlink.h>
13static int quiet = 0, default_yes = 0, deleted = 0, interactive = 0;
14static struct nl_sock *sock;
16static void print_usage(
void)
19 "Usage: nl-qdisc-delete [OPTION]... [QDISC]\n"
22 " --interactive Run interactively.\n"
23 " --yes Set default answer to yes.\n"
24 " -q, --quiet Do not print informal notifications.\n"
25 " -h, --help Show this help text and exit.\n"
26 " -v, --version Show versioning information and exit.\n"
28 " -d, --dev=DEV Device the qdisc is attached to.\n"
29 " -p, --parent=ID Identifier of parent qdisc/class.\n"
30 " -i, --id=ID Identifier\n"
31 " -k, --kind=NAME Kind of qdisc (e.g. pfifo_fast)\n"
37static void delete_cb(
struct nl_object *obj,
void *arg)
39 struct rtnl_qdisc *qdisc = nl_object_priv(obj);
50 if (interactive && !nl_cli_confirm(obj, ¶ms, default_yes))
54 nl_cli_fatal(err,
"Unable to delete qdisc: %s\n", nl_geterror(err));
64int main(
int argc,
char *argv[])
66 struct rtnl_qdisc *qdisc;
68 struct nl_cache *link_cache, *qdisc_cache;
71 sock = nl_cli_alloc_socket();
72 nl_cli_connect(sock, NETLINK_ROUTE);
73 link_cache = nl_cli_link_alloc_cache(sock);
74 qdisc_cache = nl_cli_qdisc_alloc_cache(sock);
75 qdisc = nl_cli_qdisc_alloc();
76 tc = (
struct rtnl_tc *) qdisc;
82 ARG_INTERACTIVE = 258,
84 static struct option long_opts[] = {
85 {
"interactive", 0, 0, ARG_INTERACTIVE },
86 {
"yes", 0, 0, ARG_YES },
87 {
"quiet", 0, 0,
'q' },
88 {
"help", 0, 0,
'h' },
89 {
"version", 0, 0,
'v' },
91 {
"parent", 1, 0,
'p' },
93 {
"kind", 1, 0,
'k' },
97 c = getopt_long(argc, argv,
"qhvd:p:i:k:", long_opts, &optidx);
103 case ARG_INTERACTIVE: interactive = 1;
break;
104 case ARG_YES: default_yes = 1;
break;
105 case 'q': quiet = 1;
break;
106 case 'h': print_usage();
break;
107 case 'v': nl_cli_print_version();
break;
110 nl_cli_tc_parse_dev(tc, link_cache, optarg);
114 nl_cli_tc_parse_parent(tc, optarg);
118 nl_cli_tc_parse_handle(tc, optarg, 0);
122 nl_cli_tc_parse_kind(tc, optarg);
127 if (nfilter == 0 && !interactive && !default_yes) {
129 "You are attempting to delete all qdiscs on all devices.\n"
130 "If you want to proceed, run nl-qdisc-delete --yes.\n"
137 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.