12 #include <netlink/cli/utils.h>
13 #include <netlink/cli/cls.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-cls-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 classifer 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 classifier (e.g. basic, u32, fw)\n"
35 " --protocol=PROTO Protocol to match (default: all)\n"
36 " --prio=PRIO Priority (default: 0)\n"
39 " # Delete all classifiers on eth0 attached to parent q_root:\n"
40 " $ nl-cls-delete --dev eth0 --parent q_root:\n"
47 static void delete_cb(
struct nl_object *obj,
void *arg)
49 struct rtnl_cls *cls = nl_object_priv(obj);
56 if (interactive && !nl_cli_confirm(obj, ¶ms, default_yes))
71 static void __delete_link(
int ifindex,
struct rtnl_cls *filter)
73 struct nl_cache *cache;
76 cache = nl_cli_cls_alloc_cache(sock, ifindex, parent);
81 static void delete_link(
struct nl_object *obj,
void *arg)
83 struct rtnl_link *link = nl_object_priv(obj);
88 int main(
int argc,
char *argv[])
92 struct nl_cache *link_cache;
95 sock = nl_cli_alloc_socket();
96 nl_cli_connect(sock, NETLINK_ROUTE);
97 link_cache = nl_cli_link_alloc_cache(sock);
98 cls = nl_cli_cls_alloc();
99 tc = (
struct rtnl_tc *) cls;
105 ARG_INTERACTIVE = 258,
109 static struct option long_opts[] = {
110 {
"interactive", 0, 0, ARG_INTERACTIVE },
111 {
"yes", 0, 0, ARG_YES },
112 {
"quiet", 0, 0,
'q' },
113 {
"help", 0, 0,
'h' },
114 {
"version", 0, 0,
'v' },
115 {
"dev", 1, 0,
'd' },
116 {
"parent", 1, 0,
'p' },
118 {
"kind", 1, 0,
'k' },
119 {
"proto", 1, 0, ARG_PROTO },
120 {
"prio", 1, 0, ARG_PRIO },
124 c = getopt_long(argc, argv,
"qhvd:p:i:k:", long_opts, &optidx);
130 case ARG_INTERACTIVE: interactive = 1;
break;
131 case ARG_YES: default_yes = 1;
break;
132 case 'q': quiet = 1;
break;
133 case 'h': print_usage();
break;
134 case 'v': nl_cli_print_version();
break;
135 case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg);
break;
136 case 'p': nl_cli_tc_parse_parent(tc, optarg);
break;
137 case 'i': nl_cli_tc_parse_handle(tc, optarg, 0);
break;
138 case 'k': nl_cli_tc_parse_kind(tc, optarg);
break;
139 case ARG_PROTO: nl_cli_cls_parse_proto(cls, optarg);
break;
147 __delete_link(ifindex, cls);
152 printf(
"Deleted %d classs\n", deleted);