6#include <netlink/cli/utils.h> 
    7#include <netlink/cli/tc.h> 
    8#include <netlink/cli/qdisc.h> 
    9#include <netlink/cli/class.h> 
   10#include <netlink/cli/cls.h> 
   11#include <netlink/cli/link.h> 
   13#include <linux/pkt_sched.h> 
   14#include <linux/netlink.h> 
   18static struct nl_sock *sock;
 
   19static int recursive = 0;
 
   24static void print_usage(
void)
 
   27        "Usage: nl-qdisc-list [OPTION]... [QDISC]\n" 
   30        "     --details         Show details\n" 
   31        "     --stats           Show statistics\n" 
   32        " -r, --recursive       Show recursive tree\n" 
   33        " -h, --help            Show this help\n" 
   34        " -v, --version         Show versioning information\n" 
   36        " -d, --dev=DEV         Device the qdisc is attached to. (default: all)\n" 
   37        " -p, --parent=ID       Identifier of parent qdisc.\n" 
   38        " -i, --id=ID           Identifier.\n" 
   39        " -k, --kind=NAME       Kind of qdisc (e.g. pfifo_fast)\n" 
   42        "    # Display statistics of all qdiscs attached to eth0\n" 
   43        "    $ nl-qdisc-list --details --dev=eth0\n" 
   49static void list_classes(
int ifindex, uint32_t parent);
 
   50static void list_qdiscs(
int ifindex, uint32_t parent);
 
   52static void list_class(
struct nl_object *obj, 
void *arg)
 
   54        struct rtnl_tc *tc = nl_object_priv(obj);
 
   61static void list_classes(
int ifindex, uint32_t parent)
 
   63        struct nl_cache *class_cache;
 
   64        struct rtnl_class *filter = nl_cli_class_alloc();
 
   66        class_cache = nl_cli_class_alloc_cache(sock, ifindex);
 
   73        rtnl_class_put(filter);
 
   77static void list_cls(
int ifindex, uint32_t parent)
 
   79        struct nl_cache *cls_cache;
 
   81        cls_cache = nl_cli_cls_alloc_cache(sock, ifindex, parent);
 
   90static void list_qdisc(
struct nl_object *obj, 
void *arg)
 
   92        struct rtnl_qdisc *qdisc = nl_object_priv(obj);
 
   93        struct rtnl_tc *tc = (
struct rtnl_tc *) qdisc;
 
  107static void list_qdiscs(
int ifindex, uint32_t parent)
 
  109        struct nl_cache *qdisc_cache;
 
  110        struct rtnl_qdisc *filter = nl_cli_qdisc_alloc();
 
  112        qdisc_cache = nl_cli_qdisc_alloc_cache(sock);
 
  120        rtnl_qdisc_put(filter);
 
  124int main(
int argc, 
char *argv[])
 
  126        struct rtnl_qdisc *qdisc;
 
  128        struct nl_cache *link_cache, *qdisc_cache;
 
  130        params.
dp_fd = stdout;
 
  131        sock = nl_cli_alloc_socket();
 
  132        nl_cli_connect(sock, NETLINK_ROUTE);
 
  133        link_cache = nl_cli_link_alloc_cache(sock);
 
  134        qdisc_cache = nl_cli_qdisc_alloc_cache(sock);
 
  135        qdisc = nl_cli_qdisc_alloc();
 
  136        tc = (
struct rtnl_tc *) qdisc;
 
  144                static struct option long_opts[] = {
 
  145                        { 
"details", 0, 0, ARG_DETAILS },
 
  146                        { 
"stats", 0, 0, ARG_STATS },
 
  147                        { 
"recursive", 0, 0, 
'r' },
 
  148                        { 
"help", 0, 0, 
'h' },
 
  149                        { 
"version", 0, 0, 
'v' },
 
  150                        { 
"dev", 1, 0, 
'd' },
 
  151                        { 
"parent", 1, 0, 
'p' },
 
  153                        { 
"kind", 1, 0, 
'k' },
 
  157                c = getopt_long(argc, argv, 
"rhvd:p:i:k:", long_opts, &optidx);
 
  164                case 'r': recursive = 1; 
break;
 
  165                case 'h': print_usage(); 
break;
 
  166                case 'v': nl_cli_print_version(); 
break;
 
  167                case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg); 
break;
 
  168                case 'p': nl_cli_tc_parse_parent(tc, optarg); 
break;
 
  169                case 'i': nl_cli_tc_parse_handle(tc, optarg, 0); 
break;
 
  170                case 'k': nl_cli_tc_parse_kind(tc, optarg); 
break;
 
void nl_cache_free(struct nl_cache *cache)
Free a cache.
 
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).
 
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_dump(struct nl_cache *cache, struct nl_dump_params *params)
Dump all elements of a 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.
 
void rtnl_tc_set_ifindex(struct rtnl_tc *tc, int ifindex)
Set interface index of traffic control object.
 
int rtnl_tc_get_ifindex(struct rtnl_tc *tc)
Return interface index of traffic control object.
 
uint32_t rtnl_tc_get_handle(struct rtnl_tc *tc)
Return identifier of a traffic control object.
 
void rtnl_tc_set_parent(struct rtnl_tc *tc, uint32_t parent)
Set the parent identifier of a traffic control object.
 
@ NL_DUMP_STATS
Dump all attributes including statistics.
 
@ NL_DUMP_LINE
Dump object briefly on one line.
 
@ NL_DUMP_DETAILS
Dump all attributes but no statistics.
 
int dp_prefix
Specifies the number of whitespaces to be put in front of every new line (indentation).
 
enum nl_dump_type dp_type
Specifies the type of dump that is requested.
 
FILE * dp_fd
File descriptor the dumping output should go to.