2 * src/nl-cls-list.c List classifiers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation version 2.1
9 * Copyright (c) 2008 Thomas Graf <tgraf@suug.ch>
12 #include "cls/utils.h"
14 static struct nl_sock *sock;
15 static struct rtnl_cls *cls;
16 static struct nl_dump_params params = {
17 .dp_type = NL_DUMP_LINE,
20 static void print_usage(void)
23 "Usage: nl-cls-list [OPTION]... [CLASSIFIER]\n"
26 " -f, --format=TYPE Output format { brief | details | stats }\n"
27 " -h, --help Show this help text.\n"
28 " -v, --version Show versioning information.\n"
30 "Classifier Options\n"
31 " -d, --dev=DEV Device the classifier should be assigned to.\n"
32 " -p, --parent=HANDLE Parent qdisc/class\n"
33 " --proto=PROTO Protocol\n"
34 " --prio=NUM Priority\n"
35 " --id=NUM Identifier\n"
40 static void print_cls(struct nl_object *obj, void *arg)
42 struct nl_cache *cls_cache;
46 ifindex = rtnl_link_get_ifindex((struct rtnl_link *) obj);
48 ifindex = rtnl_cls_get_ifindex(cls);
50 err = rtnl_cls_alloc_cache(sock, ifindex, rtnl_cls_get_parent(cls),
53 fatal(err, "Unable to allocate classifier cache: %s",
56 nl_cache_dump_filter(cls_cache, ¶ms, OBJ_CAST(cls));
57 nl_cache_free(cls_cache);
60 int main(int argc, char *argv[])
62 struct nl_cache *link_cache;
65 params.dp_fd = stdout;
66 sock = nlt_alloc_socket();
67 nlt_connect(sock, NETLINK_ROUTE);
68 link_cache = nlt_alloc_link_cache(sock);
69 cls = nlt_alloc_cls();
78 static struct option long_opts[] = {
79 { "format", 1, 0, 'f' },
80 { "help", 0, 0, 'h' },
81 { "version", 0, 0, 'v' },
83 { "parent", 1, 0, 'p' },
84 { "proto", 1, 0, ARG_PROTO },
85 { "prio", 1, 0, ARG_PRIO },
86 { "id", 1, 0, ARG_ID },
90 c = getopt_long(argc, argv, "+f:qhva:d:", long_opts, &optidx);
95 case '?': exit(NLE_INVAL);
96 case 'f': params.dp_type = nlt_parse_dumptype(optarg); break;
97 case 'h': print_usage(); break;
98 case 'v': nlt_print_version(); break;
99 case 'd': dev = 1; parse_dev(cls, link_cache, optarg); break;
100 case 'p': parse_parent(cls, optarg); break;
101 case ARG_PRIO: parse_prio(cls, optarg); break;
102 case ARG_ID: parse_handle(cls, optarg); break;
103 case ARG_PROTO: parse_proto(cls, optarg); break;
108 nl_cache_foreach(link_cache, print_cls, NULL);
110 print_cls(NULL, NULL);