6#include <netlink/cli/utils.h>
7#include <netlink/cli/cls.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-cls-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 classifer 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 classifier (e.g. basic, u32, fw)\n"
31" --proto=PROTO Protocol to match (default: all)\n"
32" --prio=PRIO Priority (default: 0)\n"
35" # Delete all classifiers on eth0 attached to parent q_root:\n"
36" $ nl-cls-delete --dev eth0 --parent q_root:\n"
43static void delete_cb(
struct nl_object *obj,
void *arg)
45 struct rtnl_cls *cls = nl_object_priv(obj);
52 if (interactive && !nl_cli_confirm(obj, ¶ms, default_yes))
67static void __delete_link(
int ifindex,
struct rtnl_cls *filter)
69 struct nl_cache *cache;
72 cache = nl_cli_cls_alloc_cache(sock, ifindex, parent);
77static void delete_link(
struct nl_object *obj,
void *arg)
79 struct rtnl_link *link = nl_object_priv(obj);
84int main(
int argc,
char *argv[])
88 struct nl_cache *link_cache;
91 sock = nl_cli_alloc_socket();
92 nl_cli_connect(sock, NETLINK_ROUTE);
93 link_cache = nl_cli_link_alloc_cache(sock);
94 cls = nl_cli_cls_alloc();
95 tc = (
struct rtnl_tc *) cls;
101 ARG_INTERACTIVE = 258,
105 static struct option long_opts[] = {
106 {
"interactive", 0, 0, ARG_INTERACTIVE },
107 {
"yes", 0, 0, ARG_YES },
108 {
"quiet", 0, 0,
'q' },
109 {
"help", 0, 0,
'h' },
110 {
"version", 0, 0,
'v' },
111 {
"dev", 1, 0,
'd' },
112 {
"parent", 1, 0,
'p' },
114 {
"kind", 1, 0,
'k' },
115 {
"proto", 1, 0, ARG_PROTO },
116 {
"prio", 1, 0, ARG_PRIO },
120 c = getopt_long(argc, argv,
"qhvd:p:i:k:", long_opts, &optidx);
126 case ARG_INTERACTIVE: interactive = 1;
break;
127 case ARG_YES: default_yes = 1;
break;
128 case 'q': quiet = 1;
break;
129 case 'h': print_usage();
break;
130 case 'v': nl_cli_print_version();
break;
131 case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg);
break;
132 case 'p': nl_cli_tc_parse_parent(tc, optarg);
break;
133 case 'i': nl_cli_tc_parse_handle(tc, optarg, 0);
break;
134 case 'k': nl_cli_tc_parse_kind(tc, optarg);
break;
135 case ARG_PROTO: nl_cli_cls_parse_proto(cls, optarg);
break;
143 __delete_link(ifindex, cls);
148 printf(
"Deleted %d classs\n", deleted);
void nl_cache_foreach(struct nl_cache *cache, void(*cb)(struct nl_object *, void *), void *arg)
Call a callback on each element of the cache.
void nl_cache_free(struct nl_cache *cache)
Free a cache.
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).
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
uint32_t nl_cli_parse_u32(const char *arg)
Parse a text based 32 bit unsigned integer argument.
int rtnl_cls_delete(struct nl_sock *sk, struct rtnl_cls *cls, int flags)
Delete classifier.
int rtnl_link_get_ifindex(struct rtnl_link *link)
Return interface index of link object.
void nl_object_dump(struct nl_object *obj, struct nl_dump_params *params)
Dump this object according to the specified parameters.
uint32_t rtnl_tc_get_parent(struct rtnl_tc *tc)
Return parent identifier of a traffic control object.
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.