libnl
3.2.3
|
00001 /* 00002 * src/lib/bfifo.c bfifo module for CLI lib 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation version 2.1 00007 * of the License. 00008 * 00009 * Copyright (c) 2010-2011 Thomas Graf <tgraf@suug.ch> 00010 */ 00011 00012 #include <netlink/cli/utils.h> 00013 #include <netlink/cli/tc.h> 00014 #include <netlink/route/qdisc/fifo.h> 00015 00016 static void print_usage(void) 00017 { 00018 printf( 00019 "Usage: nl-qdisc-add [...] bfifo [OPTIONS]...\n" 00020 "\n" 00021 "OPTIONS\n" 00022 " --help Show this help text.\n" 00023 " --limit=LIMIT Maximum queue length in number of bytes.\n" 00024 "\n" 00025 "EXAMPLE" 00026 " # Attach bfifo with a 4KB bytes limit to eth1\n" 00027 " nl-qdisc-add --dev=eth1 --parent=root bfifo --limit=4096\n"); 00028 } 00029 00030 static void bfifo_parse_argv(struct rtnl_tc *tc, int argc, char **argv) 00031 { 00032 struct rtnl_qdisc *qdisc = (struct rtnl_qdisc *) tc; 00033 int limit; 00034 00035 for (;;) { 00036 int c, optidx = 0; 00037 enum { 00038 ARG_LIMIT = 257, 00039 }; 00040 static struct option long_opts[] = { 00041 { "help", 0, 0, 'h' }, 00042 { "limit", 1, 0, ARG_LIMIT }, 00043 { 0, 0, 0, 0 } 00044 }; 00045 00046 c = getopt_long(argc, argv, "h", long_opts, &optidx); 00047 if (c == -1) 00048 break; 00049 00050 switch (c) { 00051 case 'h': 00052 print_usage(); 00053 return; 00054 00055 case ARG_LIMIT: 00056 limit = nl_size2int(optarg); 00057 if (limit < 0) { 00058 nl_cli_fatal(limit, "Unable to parse bfifo limit " 00059 "\"%s\": Invalid format.", optarg); 00060 } 00061 00062 rtnl_qdisc_fifo_set_limit(qdisc, limit); 00063 break; 00064 } 00065 } 00066 } 00067 00068 static struct nl_cli_tc_module bfifo_module = 00069 { 00070 .tm_name = "bfifo", 00071 .tm_type = RTNL_TC_TYPE_QDISC, 00072 .tm_parse_argv = bfifo_parse_argv, 00073 }; 00074 00075 static void __init bfifo_init(void) 00076 { 00077 nl_cli_tc_register(&bfifo_module); 00078 } 00079 00080 static void __exit bfifo_exit(void) 00081 { 00082 nl_cli_tc_unregister(&bfifo_module); 00083 }