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/link.h> 
   12#include <netlink-private/route/tc-api.h> 
   14#include <linux/netlink.h> 
   18static void print_usage(
void)
 
   21"Usage: nl-class-add [OPTIONS]... class [CONFIGURATION]...\n" 
   24" -q, --quiet               Do not print informal notifications.\n" 
   25" -h, --help                Show this help text.\n" 
   26" -v, --version             Show versioning information.\n" 
   27"     --update              Update class if it exists.\n" 
   28"     --update-only         Only update class, never create it.\n" 
   29" -d, --dev=DEV             Network device the class should be attached to.\n" 
   30" -i, --id=ID               ID of new class (default: auto-generated)\n" 
   31" -p, --parent=ID           ID of parent { root | ingress | class-ID }\n" 
   32"     --mtu=SIZE            Overwrite MTU (default: MTU of network device)\n" 
   33"     --mpu=SIZE            Minimum packet size on the link (default: 0).\n" 
   34"     --overhead=SIZE       Overhead in bytes per packet (default: 0).\n" 
   35"     --linktype=TYPE       Overwrite linktype (default: type of network device)\n" 
   38" -h, --help                Show help text of class specific options.\n" 
   41"   $ nl-class-add --dev=eth1 --parent=root htb --rate=100mbit\n" 
   47int main(
int argc, 
char *argv[])
 
   50        struct rtnl_class *
class;
 
   52        struct nl_cache *link_cache;
 
   58        struct rtnl_tc_ops *ops;
 
   59        int err, flags = NLM_F_CREATE | NLM_F_EXCL;
 
   60        char *kind, *
id = NULL;
 
   62        sock = nl_cli_alloc_socket();
 
   63        nl_cli_connect(sock, NETLINK_ROUTE);
 
   65        link_cache = nl_cli_link_alloc_cache(sock);
 
   67        class = nl_cli_class_alloc();
 
   68        tc = (
struct rtnl_tc *) 
class;
 
   74                        ARG_UPDATE_ONLY = 258,
 
   80                static struct option long_opts[] = {
 
   81                        { 
"quiet", 0, 0, 
'q' },
 
   82                        { 
"help", 0, 0, 
'h' },
 
   83                        { 
"version", 0, 0, 
'v' },
 
   85                        { 
"parent", 1, 0, 
'p' },
 
   87                        { 
"update", 0, 0, ARG_UPDATE },
 
   88                        { 
"update-only", 0, 0, ARG_UPDATE_ONLY },
 
   89                        { 
"mtu", 1, 0, ARG_MTU },
 
   90                        { 
"mpu", 1, 0, ARG_MPU },
 
   91                        { 
"overhead", 1, 0, ARG_OVERHEAD },
 
   92                        { 
"linktype", 1, 0, ARG_LINKTYPE },
 
   96                c = getopt_long(argc, argv, 
"+qhvd:p:i:",
 
  102                case 'q': quiet = 1; 
break;
 
  103                case 'h': print_usage(); 
break;
 
  104                case 'v': nl_cli_print_version(); 
break;
 
  105                case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg); 
break;
 
  106                case 'p': nl_cli_tc_parse_parent(tc, optarg); 
break;
 
  107                case 'i': 
id = strdup(optarg); 
break;
 
  108                case ARG_UPDATE: flags = NLM_F_CREATE; 
break;
 
  109                case ARG_UPDATE_ONLY: flags = 0; 
break;
 
  110                case ARG_MTU: nl_cli_tc_parse_mtu(tc, optarg); 
break;
 
  111                case ARG_MPU: nl_cli_tc_parse_mpu(tc, optarg); 
break;
 
  112                case ARG_OVERHEAD: nl_cli_tc_parse_overhead(tc, optarg); 
break;
 
  113                case ARG_LINKTYPE: nl_cli_tc_parse_linktype(tc, optarg); 
break;
 
  121                nl_cli_fatal(EINVAL, 
"You must specify a network device (--dev=XXX)");
 
  124                nl_cli_fatal(EINVAL, 
"You must specify a parent (--parent=XXX)");
 
  127                nl_cli_tc_parse_handle(tc, 
id, 1);
 
  131        kind = argv[optind++];
 
  134        if (!(ops = rtnl_tc_get_ops(tc)))
 
  137        if (!(tm = nl_cli_tc_lookup(ops)))
 
  138                nl_cli_fatal(ENOTSUP, 
"class type \"%s\" not supported.", kind);
 
  140        tm->tm_parse_argv(tc, argc, argv);
 
  148                nl_cli_fatal(EINVAL, 
"Unable to add class: %s", nl_geterror(err));
 
int rtnl_class_add(struct nl_sock *sk, struct rtnl_class *class, int flags)
Add/Update traffic class.
 
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
 
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.
 
int rtnl_tc_set_kind(struct rtnl_tc *tc, const char *kind)
Define the type of traffic control object.
 
int rtnl_tc_get_ifindex(struct rtnl_tc *tc)
Return interface index of traffic control object.
 
@ NL_DUMP_DETAILS
Dump all attributes but no statistics.
 
enum nl_dump_type dp_type
Specifies the type of dump that is requested.