2 * src/nl-class-delete.c Delete Traffic Classes
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation version 2.1
9 * Copyright (c) 2010 Thomas Graf <tgraf@suug.ch>
12 #include <netlink/cli/utils.h>
13 #include <netlink/cli/class.h>
14 #include <netlink/cli/link.h>
16 static int quiet = 0, default_yes = 0, deleted = 0, interactive = 0;
17 static struct nl_sock *sock;
19 static void print_usage(void)
22 "Usage: nl-class-delete [OPTION]... [class]\n"
25 " --interactive Run interactively.\n"
26 " --yes Set default answer to yes.\n"
27 " -q, --quiet Do not print informal notifications.\n"
28 " -h, --help Show this help text and exit.\n"
29 " -v, --version Show versioning information and exit.\n"
31 " -d, --dev=DEV Device the class is attached to.\n"
32 " -p, --parent=ID Identifier of parent qdisc/class.\n"
33 " -i, --id=ID Identifier\n"
34 " -k, --kind=NAME Kind of class (e.g. pfifo_fast)\n"
37 " # Delete all classes on eth0 attached to parent 1:\n"
38 " $ nl-class-delete --dev eth0 --parent 1:\n"
45 static void delete_cb(struct nl_object *obj, void *arg)
47 struct rtnl_class *class = nl_object_priv(obj);
48 struct nl_dump_params params = {
49 .dp_type = NL_DUMP_LINE,
54 if (interactive && !nl_cli_confirm(obj, ¶ms, default_yes))
57 if ((err = rtnl_class_delete(sock, class)) < 0)
58 nl_cli_fatal(err, "Unable to delete class: %s\n", nl_geterror(err));
62 nl_object_dump(obj, ¶ms);
68 int main(int argc, char *argv[])
70 struct rtnl_class *class;
72 struct nl_cache *link_cache, *class_cache;
74 sock = nl_cli_alloc_socket();
75 nl_cli_connect(sock, NETLINK_ROUTE);
76 link_cache = nl_cli_link_alloc_cache(sock);
77 class = nl_cli_class_alloc();
78 tc = (struct rtnl_tc *) class;
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);
104 case '?': nl_cli_fatal(EINVAL, "Invalid options");
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;
110 case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg); break;
111 case 'p': nl_cli_tc_parse_parent(tc, optarg); break;
112 case 'i': nl_cli_tc_parse_handle(tc, optarg, 0); break;
113 case 'k': nl_cli_tc_parse_kind(tc, optarg); break;
117 if (!rtnl_tc_get_ifindex(tc))
118 nl_cli_fatal(EINVAL, "You must specify a network device (--dev=XXX)");
120 class_cache = nl_cli_class_alloc_cache(sock, rtnl_tc_get_ifindex(tc));
122 nl_cache_foreach_filter(class_cache, OBJ_CAST(class), delete_cb, NULL);
125 printf("Deleted %d classs\n", deleted);