6#include <netlink/cli/utils.h>
7#include <netlink/cli/class.h>
8#include <netlink/cli/link.h>
10#include <linux/netlink.h>
12static int quiet = 0, default_yes = 0, deleted = 0, interactive = 0;
13static struct nl_sock *sock;
15static void print_usage(
void)
18 "Usage: nl-class-delete [OPTION]... [class]\n"
21 " --interactive Run interactively.\n"
22 " --yes Set default answer to yes.\n"
23 " -q, --quiet Do not print informal notifications.\n"
24 " -h, --help Show this help text and exit.\n"
25 " -v, --version Show versioning information and exit.\n"
27 " -d, --dev=DEV Device the class is attached to.\n"
28 " -p, --parent=ID Identifier of parent qdisc/class.\n"
29 " -i, --id=ID Identifier\n"
30 " -k, --kind=NAME Kind of class (e.g. pfifo_fast)\n"
33 " # Delete all classes on eth0 attached to parent 1:\n"
34 " $ nl-class-delete --dev eth0 --parent 1:\n"
41static void delete_cb(
struct nl_object *obj,
void *arg)
43 struct rtnl_class *
class = nl_object_priv(obj);
50 if (interactive && !nl_cli_confirm(obj, ¶ms, default_yes))
54 nl_cli_fatal(err,
"Unable to delete class: %s\n", nl_geterror(err));
64int main(
int argc,
char *argv[])
66 struct rtnl_class *
class;
68 struct nl_cache *link_cache, *class_cache;
70 sock = nl_cli_alloc_socket();
71 nl_cli_connect(sock, NETLINK_ROUTE);
72 link_cache = nl_cli_link_alloc_cache(sock);
73 class = nl_cli_class_alloc();
74 tc = (
struct rtnl_tc *)
class;
80 ARG_INTERACTIVE = 258,
82 static struct option long_opts[] = {
83 {
"interactive", 0, 0, ARG_INTERACTIVE },
84 {
"yes", 0, 0, ARG_YES },
85 {
"quiet", 0, 0,
'q' },
86 {
"help", 0, 0,
'h' },
87 {
"version", 0, 0,
'v' },
89 {
"parent", 1, 0,
'p' },
91 {
"kind", 1, 0,
'k' },
95 c = getopt_long(argc, argv,
"qhvd:p:i:k:", long_opts, &optidx);
101 case ARG_INTERACTIVE: interactive = 1;
break;
102 case ARG_YES: default_yes = 1;
break;
103 case 'q': quiet = 1;
break;
104 case 'h': print_usage();
break;
105 case 'v': nl_cli_print_version();
break;
106 case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg);
break;
107 case 'p': nl_cli_tc_parse_parent(tc, optarg);
break;
108 case 'i': nl_cli_tc_parse_handle(tc, optarg, 0);
break;
109 case 'k': nl_cli_tc_parse_kind(tc, optarg);
break;
114 nl_cli_fatal(EINVAL,
"You must specify a network device (--dev=XXX)");
121 printf(
"Deleted %d classs\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).
int rtnl_class_delete(struct nl_sock *sk, struct rtnl_class *class)
Delete traffic class.
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_tc_get_ifindex(struct rtnl_tc *tc)
Return interface index of 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.