13 #include <netlink/cli/utils.h> 14 #include <netlink/cli/tc.h> 15 #include <netlink/cli/qdisc.h> 16 #include <netlink/cli/link.h> 18 #include <linux/netlink.h> 20 static int quiet = 0, default_yes = 0, deleted = 0, interactive = 0;
21 static struct nl_sock *sock;
23 static void print_usage(
void)
26 "Usage: nl-qdisc-delete [OPTION]... [QDISC]\n" 29 " --interactive Run interactively.\n" 30 " --yes Set default answer to yes.\n" 31 " -q, --quiet Do not print informal notifications.\n" 32 " -h, --help Show this help text and exit.\n" 33 " -v, --version Show versioning information and exit.\n" 35 " -d, --dev=DEV Device the qdisc is attached to.\n" 36 " -p, --parent=ID Identifier of parent qdisc/class.\n" 37 " -i, --id=ID Identifier\n" 38 " -k, --kind=NAME Kind of qdisc (e.g. pfifo_fast)\n" 44 static void delete_cb(
struct nl_object *obj,
void *arg)
46 struct rtnl_qdisc *qdisc = nl_object_priv(obj);
57 if (interactive && !nl_cli_confirm(obj, ¶ms, default_yes))
61 nl_cli_fatal(err,
"Unable to delete qdisc: %s\n", nl_geterror(err));
71 int main(
int argc,
char *argv[])
73 struct rtnl_qdisc *qdisc;
75 struct nl_cache *link_cache, *qdisc_cache;
78 sock = nl_cli_alloc_socket();
79 nl_cli_connect(sock, NETLINK_ROUTE);
80 link_cache = nl_cli_link_alloc_cache(sock);
81 qdisc_cache = nl_cli_qdisc_alloc_cache(sock);
82 qdisc = nl_cli_qdisc_alloc();
83 tc = (
struct rtnl_tc *) qdisc;
89 ARG_INTERACTIVE = 258,
91 static struct option long_opts[] = {
92 {
"interactive", 0, 0, ARG_INTERACTIVE },
93 {
"yes", 0, 0, ARG_YES },
94 {
"quiet", 0, 0,
'q' },
95 {
"help", 0, 0,
'h' },
96 {
"version", 0, 0,
'v' },
98 {
"parent", 1, 0,
'p' },
100 {
"kind", 1, 0,
'k' },
104 c = getopt_long(argc, argv,
"qhvd:p:i:k:", long_opts, &optidx);
110 case ARG_INTERACTIVE: interactive = 1;
break;
111 case ARG_YES: default_yes = 1;
break;
112 case 'q': quiet = 1;
break;
113 case 'h': print_usage();
break;
114 case 'v': nl_cli_print_version();
break;
117 nl_cli_tc_parse_dev(tc, link_cache, optarg);
121 nl_cli_tc_parse_parent(tc, optarg);
125 nl_cli_tc_parse_handle(tc, optarg, 0);
129 nl_cli_tc_parse_kind(tc, optarg);
134 if (nfilter == 0 && !interactive && !default_yes) {
136 "You are attempting to delete all qdiscs on all devices.\n" 137 "If you want to proceed, run nl-qdisc-delete --yes.\n" 144 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.