12 #include <netlink/cli/utils.h> 13 #include <netlink/cli/tc.h> 14 #include <netlink/cli/class.h> 15 #include <netlink/cli/link.h> 17 #include <linux/netlink.h> 19 static struct nl_sock *sock;
25 static void print_usage(
void)
28 "Usage: nl-class-list [OPTION]...\n" 31 " --details Show details\n" 32 " --stats Show statistics\n" 33 " -h, --help Show this help\n" 34 " -v, --version Show versioning information\n" 36 " -d, --dev=DEV Device the class is attached to. (default: all)\n" 37 " -p, --parent=ID Identifier of parent class.\n" 38 " -i, --id=ID Identifier.\n" 39 " -k, --kind=NAME Kind of class (e.g. pfifo_fast)\n" 42 " # Display statistics of all classes on eth0\n" 43 " $ nl-class-list --stats --dev=eth0\n" 49 static void __dump_class(
int ifindex,
struct rtnl_class *filter)
51 struct nl_cache *cache;
53 cache = nl_cli_class_alloc_cache(sock, ifindex);
57 static void dump_class(
struct nl_object *obj,
void *arg)
59 struct rtnl_link *link = nl_object_priv(obj);
64 int main(
int argc,
char *argv[])
66 struct rtnl_class *
class;
68 struct nl_cache *link_cache;
71 sock = nl_cli_alloc_socket();
72 nl_cli_connect(sock, NETLINK_ROUTE);
73 link_cache = nl_cli_link_alloc_cache(sock);
74 class = nl_cli_class_alloc();
75 tc = (
struct rtnl_tc *)
class;
77 params.
dp_fd = stdout;
85 static struct option long_opts[] = {
86 {
"details", 0, 0, ARG_DETAILS },
87 {
"stats", 0, 0, ARG_STATS },
88 {
"help", 0, 0,
'h' },
89 {
"version", 0, 0,
'v' },
91 {
"parent", 1, 0,
'p' },
93 {
"kind", 1, 0,
'k' },
97 c = getopt_long(argc, argv,
"hvd:p:i:k:", long_opts, &optidx);
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 __dump_class(ifindex,
class);
Dump object briefly on one line.
FILE * dp_fd
File descriptor the dumping output should go to.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.
void nl_cache_dump_filter(struct nl_cache *cache, struct nl_dump_params *params, struct nl_object *filter)
Dump all elements of a cache (filtered).
Dump all attributes but no statistics.
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.
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.
Dump all attributes including statistics.