12 #include <netlink/cli/utils.h> 13 #include <netlink/cli/cls.h> 14 #include <netlink/cli/link.h> 16 #include <linux/netlink.h> 18 static int quiet = 0, default_yes = 0, deleted = 0, interactive = 0;
19 static struct nl_sock *sock;
21 static void print_usage(
void)
24 "Usage: nl-cls-delete [OPTION]... [class]\n" 27 " --interactive Run interactively.\n" 28 " --yes Set default answer to yes.\n" 29 " -q, --quiet Do not print informal notifications.\n" 30 " -h, --help Show this help text and exit.\n" 31 " -v, --version Show versioning information and exit.\n" 33 " -d, --dev=DEV Device the classifer is attached to.\n" 34 " -p, --parent=ID Identifier of parent qdisc/class.\n" 35 " -i, --id=ID Identifier\n" 36 " -k, --kind=NAME Kind of classifier (e.g. basic, u32, fw)\n" 37 " --proto=PROTO Protocol to match (default: all)\n" 38 " --prio=PRIO Priority (default: 0)\n" 41 " # Delete all classifiers on eth0 attached to parent q_root:\n" 42 " $ nl-cls-delete --dev eth0 --parent q_root:\n" 49 static void delete_cb(
struct nl_object *obj,
void *arg)
51 struct rtnl_cls *cls = nl_object_priv(obj);
58 if (interactive && !nl_cli_confirm(obj, ¶ms, default_yes))
73 static void __delete_link(
int ifindex,
struct rtnl_cls *filter)
75 struct nl_cache *cache;
78 cache = nl_cli_cls_alloc_cache(sock, ifindex, parent);
83 static void delete_link(
struct nl_object *obj,
void *arg)
85 struct rtnl_link *link = nl_object_priv(obj);
90 int main(
int argc,
char *argv[])
94 struct nl_cache *link_cache;
97 sock = nl_cli_alloc_socket();
98 nl_cli_connect(sock, NETLINK_ROUTE);
99 link_cache = nl_cli_link_alloc_cache(sock);
100 cls = nl_cli_cls_alloc();
101 tc = (
struct rtnl_tc *) cls;
107 ARG_INTERACTIVE = 258,
111 static struct option long_opts[] = {
112 {
"interactive", 0, 0, ARG_INTERACTIVE },
113 {
"yes", 0, 0, ARG_YES },
114 {
"quiet", 0, 0,
'q' },
115 {
"help", 0, 0,
'h' },
116 {
"version", 0, 0,
'v' },
117 {
"dev", 1, 0,
'd' },
118 {
"parent", 1, 0,
'p' },
120 {
"kind", 1, 0,
'k' },
121 {
"proto", 1, 0, ARG_PROTO },
122 {
"prio", 1, 0, ARG_PRIO },
126 c = getopt_long(argc, argv,
"qhvd:p:i:k:", long_opts, &optidx);
132 case ARG_INTERACTIVE: interactive = 1;
break;
133 case ARG_YES: default_yes = 1;
break;
134 case 'q': quiet = 1;
break;
135 case 'h': print_usage();
break;
136 case 'v': nl_cli_print_version();
break;
137 case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg);
break;
138 case 'p': nl_cli_tc_parse_parent(tc, optarg);
break;
139 case 'i': nl_cli_tc_parse_handle(tc, optarg, 0);
break;
140 case 'k': nl_cli_tc_parse_kind(tc, optarg);
break;
141 case ARG_PROTO: nl_cli_cls_parse_proto(cls, optarg);
break;
149 __delete_link(ifindex, cls);
154 printf(
"Deleted %d classs\n", deleted);
Dump object briefly on one line.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.
int rtnl_cls_delete(struct nl_sock *sk, struct rtnl_cls *cls, int flags)
Delete classifier.
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_cache_free(struct nl_cache *cache)
Free a cache.
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_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.
uint32_t nl_cli_parse_u32(const char *arg)
Parse a text based 32 bit unsigned integer argument.
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
int rtnl_link_get_ifindex(struct rtnl_link *link)
Return interface index of link object.
int rtnl_tc_get_ifindex(struct rtnl_tc *tc)
Return interface index of traffic control object.