12 #include <netlink/cli/utils.h>
13 #include <netlink/cli/tc.h>
14 #include <netlink/cli/qdisc.h>
15 #include <netlink/cli/class.h>
16 #include <netlink/cli/link.h>
18 #include <netlink-private/route/tc-api.h>
22 static void print_usage(
void)
25 "Usage: nl-class-add [OPTIONS]... class [CONFIGURATION]...\n"
28 " -q, --quiet Do not print informal notifications.\n"
29 " -h, --help Show this help text.\n"
30 " -v, --version Show versioning information.\n"
31 " --update Update class if it exists.\n"
32 " --update-only Only update class, never create it.\n"
33 " -d, --dev=DEV Network device the class should be attached to.\n"
34 " -i, --id=ID ID of new class (default: auto-generated)\n"
35 " -p, --parent=ID ID of parent { root | ingress | class-ID }\n"
36 " --mtu=SIZE Overwrite MTU (default: MTU of network device)\n"
37 " --mpu=SIZE Minimum packet size on the link (default: 0).\n"
38 " --overhead=SIZE Overhead in bytes per packet (default: 0).\n"
39 " --linktype=TYPE Overwrite linktype (default: type of network device)\n"
42 " -h, --help Show help text of class specific options.\n"
45 " $ nl-class-add --dev=eth1 --parent=root htb --rate=100mbit\n"
51 int main(
int argc,
char *argv[])
54 struct rtnl_class *
class;
56 struct nl_cache *link_cache;
62 struct rtnl_tc_ops *ops;
63 int err, flags = NLM_F_CREATE | NLM_F_EXCL;
64 char *kind, *
id = NULL;
66 sock = nl_cli_alloc_socket();
67 nl_cli_connect(sock, NETLINK_ROUTE);
69 link_cache = nl_cli_link_alloc_cache(sock);
71 class = nl_cli_class_alloc();
72 tc = (
struct rtnl_tc *)
class;
78 ARG_UPDATE_ONLY = 258,
84 static struct option long_opts[] = {
85 {
"quiet", 0, 0,
'q' },
86 {
"help", 0, 0,
'h' },
87 {
"version", 0, 0,
'v' },
89 {
"parent", 1, 0,
'p' },
91 {
"update", 0, 0, ARG_UPDATE },
92 {
"update-only", 0, 0, ARG_UPDATE_ONLY },
93 {
"mtu", 1, 0, ARG_MTU },
94 {
"mpu", 1, 0, ARG_MPU },
95 {
"overhead", 1, 0, ARG_OVERHEAD },
96 {
"linktype", 1, 0, ARG_LINKTYPE },
100 c = getopt_long(argc, argv,
"+qhvd:p:i:",
106 case 'q': quiet = 1;
break;
107 case 'h': print_usage();
break;
108 case 'v': nl_cli_print_version();
break;
109 case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg);
break;
110 case 'p': nl_cli_tc_parse_parent(tc, optarg);
break;
111 case 'i':
id = strdup(optarg);
break;
112 case ARG_UPDATE: flags = NLM_F_CREATE;
break;
113 case ARG_UPDATE_ONLY: flags = 0;
break;
114 case ARG_MTU: nl_cli_tc_parse_mtu(tc, optarg);
break;
115 case ARG_MPU: nl_cli_tc_parse_mpu(tc, optarg);
break;
116 case ARG_OVERHEAD: nl_cli_tc_parse_overhead(tc, optarg);
break;
117 case ARG_LINKTYPE: nl_cli_tc_parse_linktype(tc, optarg);
break;
125 nl_cli_fatal(EINVAL,
"You must specify a network device (--dev=XXX)");
128 nl_cli_fatal(EINVAL,
"You must specify a parent (--parent=XXX)");
131 nl_cli_tc_parse_handle(tc,
id, 1);
135 kind = argv[optind++];
138 if (!(ops = rtnl_tc_get_ops(tc)))
141 if (!(tm = nl_cli_tc_lookup(ops)))
142 nl_cli_fatal(ENOTSUP,
"class type \"%s\" not supported.", kind);
144 tm->tm_parse_argv(tc, argc, argv);
152 nl_cli_fatal(EINVAL,
"Unable to add class: %s", nl_geterror(err));