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);
54 if (interactive && !nl_cli_confirm(obj, ¶ms, default_yes))
58 nl_cli_fatal(err,
"Unable to delete class: %s\n", nl_geterror(err));
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);
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;
118 nl_cli_fatal(EINVAL,
"You must specify a network device (--dev=XXX)");
125 printf(
"Deleted %d classs\n", deleted);