110cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf/* 210cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf * src/nl-qdisc-list.c List Qdiscs 310cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf * 410cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf * This library is free software; you can redistribute it and/or 510cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf * modify it under the terms of the GNU Lesser General Public 610cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf * License as published by the Free Software Foundation version 2.1 710cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf * of the License. 810cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf * 98808743839b0f459394ecd00cb0f7c1896c0ab7aThomas Graf * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch> 1010cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf */ 1110cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf 128808743839b0f459394ecd00cb0f7c1896c0ab7aThomas Graf#include <netlink/cli/utils.h> 138808743839b0f459394ecd00cb0f7c1896c0ab7aThomas Graf#include <netlink/cli/qdisc.h> 148808743839b0f459394ecd00cb0f7c1896c0ab7aThomas Graf#include <netlink/cli/link.h> 1510cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf 1610cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Grafstatic int quiet = 0; 1710cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf 1810cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Grafstatic void print_usage(void) 1910cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf{ 2010cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf printf( 2110cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf "Usage: nl-qdisc-list [OPTION]... [QDISC]\n" 2210cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf "\n" 2310cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf "Options\n" 2410cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf " -f, --format=TYPE Output format { brief | details | stats }\n" 2510cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf " -h, --help Show this help\n" 2610cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf " -v, --version Show versioning information\n" 2710cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf "\n" 2810cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf "QDisc Options\n" 2910cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf " -d, --dev=DEV Device the qdisc is attached to\n" 3010cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf " -p, --parent=HANDLE Identifier of parent qdisc\n" 3110cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf " -H, --handle=HANDLE Identifier\n" 3210cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf " -k, --kind=NAME Kind of qdisc (e.g. pfifo_fast)\n" 3310cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf ); 3410cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf exit(0); 3510cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf} 3610cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf 3710cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Grafint main(int argc, char *argv[]) 3810cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf{ 3910cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf struct nl_sock *sock; 4010cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf struct rtnl_qdisc *qdisc; 4110cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf struct nl_cache *link_cache, *qdisc_cache; 4210cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf struct nl_dump_params params = { 43d84430702496f617c01c5e2d27d0e82e02390bb7Thomas Graf .dp_type = NL_DUMP_LINE, 4410cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf .dp_fd = stdout, 4510cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf }; 4610cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf 478808743839b0f459394ecd00cb0f7c1896c0ab7aThomas Graf sock = nl_cli_alloc_socket(); 488808743839b0f459394ecd00cb0f7c1896c0ab7aThomas Graf nl_cli_connect(sock, NETLINK_ROUTE); 498808743839b0f459394ecd00cb0f7c1896c0ab7aThomas Graf link_cache = nl_cli_link_alloc_cache(sock); 508808743839b0f459394ecd00cb0f7c1896c0ab7aThomas Graf qdisc_cache = nl_cli_qdisc_alloc_cache(sock); 518808743839b0f459394ecd00cb0f7c1896c0ab7aThomas Graf qdisc = nl_cli_qdisc_alloc(); 5210cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf 5310cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf for (;;) { 5410cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf int c, optidx = 0; 5510cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf enum { 5610cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf ARG_YES = 257, 5710cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf }; 5810cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf static struct option long_opts[] = { 5910cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf { "format", 1, 0, 'f' }, 6010cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf { "quiet", 0, 0, 'q' }, 6110cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf { "help", 0, 0, 'h' }, 6210cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf { "version", 0, 0, 'v' }, 6310cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf { "dev", 1, 0, 'd' }, 6410cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf { "parent", 1, 0, 'p' }, 6510cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf { "handle", 1, 0, 'H' }, 6610cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf { "kind", 1, 0, 'k' }, 6710cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf { 0, 0, 0, 0 } 6810cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf }; 6910cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf 7010cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf c = getopt_long(argc, argv, "f:qhvd:p:H:k:", 7110cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf long_opts, &optidx); 7210cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf if (c == -1) 7310cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf break; 7410cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf 7510cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf switch (c) { 768808743839b0f459394ecd00cb0f7c1896c0ab7aThomas Graf case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break; 7710cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf case 'q': quiet = 1; break; 7810cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf case 'h': print_usage(); break; 798808743839b0f459394ecd00cb0f7c1896c0ab7aThomas Graf case 'v': nl_cli_print_version(); break; 808808743839b0f459394ecd00cb0f7c1896c0ab7aThomas Graf case 'd': nl_cli_qdisc_parse_dev(qdisc, link_cache, optarg); break; 818808743839b0f459394ecd00cb0f7c1896c0ab7aThomas Graf case 'p': nl_cli_qdisc_parse_parent(qdisc, optarg); break; 828808743839b0f459394ecd00cb0f7c1896c0ab7aThomas Graf case 'H': nl_cli_qdisc_parse_handle(qdisc, optarg); break; 838808743839b0f459394ecd00cb0f7c1896c0ab7aThomas Graf case 'k': nl_cli_qdisc_parse_kind(qdisc, optarg); break; 8410cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf } 8510cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf } 8610cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf 8710cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf nl_cache_dump_filter(qdisc_cache, ¶ms, OBJ_CAST(qdisc)); 8810cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf 8910cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf return 0; 9010cf5a586c149fdb7e2639000dbfae5e6f8522a5Thomas Graf} 91