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 #include <linux/netlink.h> 19 static int quiet = 0, default_yes = 0, deleted = 0, interactive = 0;
20 static struct nl_sock *sock;
22 static void print_usage(
void)
25 "Usage: nl-qdisc-delete [OPTION]... [QDISC]\n" 28 " --interactive Run interactively.\n" 29 " --yes Set default answer to yes.\n" 30 " -q, --quiet Do not print informal notifications.\n" 31 " -h, --help Show this help text and exit.\n" 32 " -v, --version Show versioning information and exit.\n" 34 " -d, --dev=DEV Device the qdisc is attached to.\n" 35 " -p, --parent=ID Identifier of parent qdisc/class.\n" 36 " -i, --id=ID Identifier\n" 37 " -k, --kind=NAME Kind of qdisc (e.g. pfifo_fast)\n" 43 static void delete_cb(
struct nl_object *obj,
void *arg)
45 struct rtnl_qdisc *qdisc = nl_object_priv(obj);
56 if (interactive && !nl_cli_confirm(obj, ¶ms, default_yes))
60 nl_cli_fatal(err,
"Unable to delete qdisc: %s\n", nl_geterror(err));
70 int main(
int argc,
char *argv[])
72 struct rtnl_qdisc *qdisc;
74 struct nl_cache *link_cache, *qdisc_cache;
77 sock = nl_cli_alloc_socket();
78 nl_cli_connect(sock, NETLINK_ROUTE);
79 link_cache = nl_cli_link_alloc_cache(sock);
80 qdisc_cache = nl_cli_qdisc_alloc_cache(sock);
81 qdisc = nl_cli_qdisc_alloc();
82 tc = (
struct rtnl_tc *) qdisc;
88 ARG_INTERACTIVE = 258,
90 static struct option long_opts[] = {
91 {
"interactive", 0, 0, ARG_INTERACTIVE },
92 {
"yes", 0, 0, ARG_YES },
93 {
"quiet", 0, 0,
'q' },
94 {
"help", 0, 0,
'h' },
95 {
"version", 0, 0,
'v' },
97 {
"parent", 1, 0,
'p' },
99 {
"kind", 1, 0,
'k' },
103 c = getopt_long(argc, argv,
"qhvd:p:i:k:", long_opts, &optidx);
109 case ARG_INTERACTIVE: interactive = 1;
break;
110 case ARG_YES: default_yes = 1;
break;
111 case 'q': quiet = 1;
break;
112 case 'h': print_usage();
break;
113 case 'v': nl_cli_print_version();
break;
116 nl_cli_tc_parse_dev(tc, link_cache, optarg);
120 nl_cli_tc_parse_parent(tc, optarg);
124 nl_cli_tc_parse_handle(tc, optarg, 0);
128 nl_cli_tc_parse_kind(tc, optarg);
133 if (nfilter == 0 && !interactive && !default_yes) {
135 "You are attempting to delete all qdiscs on all devices.\n" 136 "If you want to proceed, run nl-qdisc-delete --yes.\n" 143 printf(
"Deleted %d qdiscs\n", deleted);
Dump object briefly on one line.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.
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).
uint32_t rtnl_tc_get_handle(struct rtnl_tc *tc)
Return identifier of a traffic control object.
void nl_object_dump(struct nl_object *obj, struct nl_dump_params *params)
Dump this object according to the specified parameters.
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
int rtnl_qdisc_delete(struct nl_sock *sk, struct rtnl_qdisc *qdisc)
Delete qdisc.