Home | History | Annotate | Download | only in src
      1 /*
      2  * src/nl-qdisc-list.c     List Qdiscs
      3  *
      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
      7  *	of the License.
      8  *
      9  * Copyright (c) 2003-2009 Thomas Graf <tgraf (at) suug.ch>
     10  */
     11 
     12 #include <netlink/cli/utils.h>
     13 #include <netlink/cli/qdisc.h>
     14 #include <netlink/cli/link.h>
     15 
     16 static int quiet = 0;
     17 
     18 static void print_usage(void)
     19 {
     20 	printf(
     21 	"Usage: nl-qdisc-list [OPTION]... [QDISC]\n"
     22 	"\n"
     23 	"Options\n"
     24 	" -f, --format=TYPE     Output format { brief | details | stats }\n"
     25 	" -h, --help            Show this help\n"
     26 	" -v, --version         Show versioning information\n"
     27 	"\n"
     28 	"QDisc Options\n"
     29 	" -d, --dev=DEV         Device the qdisc is attached to\n"
     30 	" -p, --parent=HANDLE   Identifier of parent qdisc\n"
     31 	" -H, --handle=HANDLE   Identifier\n"
     32 	" -k, --kind=NAME       Kind of qdisc (e.g. pfifo_fast)\n"
     33 	);
     34 	exit(0);
     35 }
     36 
     37 int main(int argc, char *argv[])
     38 {
     39 	struct nl_sock *sock;
     40 	struct rtnl_qdisc *qdisc;
     41 	struct nl_cache *link_cache, *qdisc_cache;
     42 	struct nl_dump_params params = {
     43 		.dp_type = NL_DUMP_LINE,
     44 		.dp_fd = stdout,
     45 	};
     46 
     47 	sock = nl_cli_alloc_socket();
     48 	nl_cli_connect(sock, NETLINK_ROUTE);
     49 	link_cache = nl_cli_link_alloc_cache(sock);
     50 	qdisc_cache = nl_cli_qdisc_alloc_cache(sock);
     51  	qdisc = nl_cli_qdisc_alloc();
     52 
     53 	for (;;) {
     54 		int c, optidx = 0;
     55 		enum {
     56 			ARG_YES = 257,
     57 		};
     58 		static struct option long_opts[] = {
     59 			{ "format", 1, 0, 'f' },
     60 			{ "quiet", 0, 0, 'q' },
     61 			{ "help", 0, 0, 'h' },
     62 			{ "version", 0, 0, 'v' },
     63 			{ "dev", 1, 0, 'd' },
     64 			{ "parent", 1, 0, 'p' },
     65 			{ "handle", 1, 0, 'H' },
     66 			{ "kind", 1, 0, 'k' },
     67 			{ 0, 0, 0, 0 }
     68 		};
     69 
     70 		c = getopt_long(argc, argv, "f:qhvd:p:H:k:",
     71 				long_opts, &optidx);
     72 		if (c == -1)
     73 			break;
     74 
     75 		switch (c) {
     76 		case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break;
     77 		case 'q': quiet = 1; break;
     78 		case 'h': print_usage(); break;
     79 		case 'v': nl_cli_print_version(); break;
     80 		case 'd': nl_cli_qdisc_parse_dev(qdisc, link_cache, optarg); break;
     81 		case 'p': nl_cli_qdisc_parse_parent(qdisc, optarg); break;
     82 		case 'H': nl_cli_qdisc_parse_handle(qdisc, optarg); break;
     83 		case 'k': nl_cli_qdisc_parse_kind(qdisc, optarg); break;
     84 		}
     85  	}
     86 
     87 	nl_cache_dump_filter(qdisc_cache, &params, OBJ_CAST(qdisc));
     88 
     89 	return 0;
     90 }
     91