]> git.ipfire.org Git - thirdparty/libnl.git/commitdiff
Unified TC attributes interface
authorThomas Graf <tgraf@suug.ch>
Tue, 26 Oct 2010 10:54:33 +0000 (12:54 +0200)
committerThomas Graf <tgraf@suug.ch>
Tue, 26 Oct 2010 10:54:33 +0000 (12:54 +0200)
So far all common tc atttributes were accessed via specific functions, i.e.
rtnl_class_set_parent(), rtnl_qdisc_set_parent(), rtnl_cls_set_parent()
which implied a lot of code duplication. Since all tc objects are derived
from struct rtnl_tc and these common attributes are already stored in there
this patch removes all type specific functions and makes rtnl_tc_* attribute
functions public.

        rtnl_qdisc_set_parent(qdisc, 10);

becomes:

        rtnl_tc_set_parent((struct rtnl_tc *) qdisc, 10);

This patch also adds the following new attributes to tc objects therefore
removing them as tc specific attributes:
 - mtu
 - mpu
 - overhead

This allows for the rate table calculations to be unified as well taking into
account the new kernel behavior to take care of overhead automatically.

40 files changed:
include/netlink-local.h
include/netlink-tc.h
include/netlink-types.h
include/netlink/cli/class.h
include/netlink/cli/qdisc.h
include/netlink/cli/tc.h [new file with mode: 0644]
include/netlink/route/class.h
include/netlink/route/classifier.h
include/netlink/route/qdisc.h
include/netlink/route/sch/htb.h
include/netlink/route/sch/tbf.h
include/netlink/route/tc.h
lib/cli/qdisc/htb.c
lib/route/class.c
lib/route/class_obj.c
lib/route/cls.c
lib/route/cls/basic.c
lib/route/cls/cgroup.c
lib/route/cls/fw.c
lib/route/cls/u32.c
lib/route/cls_obj.c
lib/route/qdisc.c
lib/route/qdisc_obj.c
lib/route/sch/cbq.c
lib/route/sch/dsmark.c
lib/route/sch/htb.c
lib/route/sch/red.c
lib/route/sch/tbf.c
lib/route/tc.c
src/lib/Makefile.am
src/lib/class.c
src/lib/qdisc.c
src/lib/tc.c [new file with mode: 0644]
src/nl-class-add.c
src/nl-class-delete.c
src/nl-class-list.c
src/nl-qdisc-add.c
src/nl-qdisc-delete.c
src/nl-qdisc-list.c
src/nl-tctree-list.c

index b5fad32fa7e1e1b943c462d114d8bbda791cb801..e9310eaaefba39fccd98ae354649fe554a26e3ad 100644 (file)
@@ -47,6 +47,7 @@
 #include <linux/pkt_cls.h>
 #include <linux/gen_stats.h>
 #include <linux/ip_mp_alg.h>
+#include <linux/atm.h>
 
 #include <netlink/netlink.h>
 #include <netlink/handlers.h>
index 71a20ffb18f2fc1ddb738a8dbce8cd45fe8e74cf..9e4bce966e8cd6ce3c8136624aa20263492012d3 100644 (file)
@@ -6,7 +6,7 @@
  *     License as published by the Free Software Foundation version 2.1
  *     of the License.
  *
- * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ * Copyright (c) 2003-2010 Thomas Graf <tgraf@suug.ch>
  */
 
 #ifndef NETLINK_TC_PRIV_H_
 extern "C" {
 #endif
 
-#define TCA_ATTR_HANDLE    0x001
-#define TCA_ATTR_PARENT    0x002
-#define TCA_ATTR_IFINDEX   0x004
-#define TCA_ATTR_KIND      0x008
-#define TCA_ATTR_FAMILY    0x010
-#define TCA_ATTR_INFO      0x020
-#define TCA_ATTR_OPTS      0x040
-#define TCA_ATTR_STATS     0x080
-#define TCA_ATTR_XSTATS    0x100
-#define TCA_ATTR_MAX     TCA_ATTR_XSTATS
+#define TCA_ATTR_HANDLE                0x0001
+#define TCA_ATTR_PARENT                0x0002
+#define TCA_ATTR_IFINDEX       0x0004
+#define TCA_ATTR_KIND          0x0008
+#define TCA_ATTR_FAMILY                0x0010
+#define TCA_ATTR_INFO          0x0020
+#define TCA_ATTR_OPTS          0x0040
+#define TCA_ATTR_STATS         0x0080
+#define TCA_ATTR_XSTATS                0x0100
+#define TCA_ATTR_LINK          0x0200
+#define TCA_ATTR_MTU           0x0400
+#define TCA_ATTR_MPU           0x0800
+#define TCA_ATTR_OVERHEAD      0x1000
+#define TCA_ATTR_LINKTYPE      0x2000
+#define TCA_ATTR_MAX           TCA_ATTR_LINKTYPE
 
-extern int tca_parse(struct nlattr **, int, struct rtnl_tca *,
+extern int tca_parse(struct nlattr **, int, struct rtnl_tc *,
                     struct nla_policy *);
-extern int  tca_msg_parser(struct nlmsghdr *, struct rtnl_tca *);
-extern void tca_free_data(struct rtnl_tca *);
-extern int  tca_clone(struct rtnl_tca *, struct rtnl_tca *);
-extern void tca_dump_line(struct rtnl_tca *, const char *,
+extern int  tca_msg_parser(struct nlmsghdr *, struct rtnl_tc *);
+extern void tca_free_data(struct rtnl_tc *);
+extern int  tca_clone(struct rtnl_tc *, struct rtnl_tc *);
+extern void tca_dump_line(struct rtnl_tc *, const char *,
                          struct nl_dump_params *);
-extern void tca_dump_details(struct rtnl_tca *, struct nl_dump_params *);
-extern void tca_dump_stats(struct rtnl_tca *, struct nl_dump_params *);
+extern void tca_dump_details(struct rtnl_tc *, struct nl_dump_params *);
+extern void tca_dump_stats(struct rtnl_tc *, struct nl_dump_params *);
 extern int  tca_compare(struct nl_object *, struct nl_object *, uint32_t, int);
 
-extern void tca_set_ifindex(struct rtnl_tca *, int);
-extern int  tca_get_ifindex(struct rtnl_tca *);
-extern void tca_set_handle(struct rtnl_tca *, uint32_t);
-extern uint32_t tca_get_handle(struct rtnl_tca *);
-extern void tca_set_parent(struct rtnl_tca *, uint32_t);
-extern uint32_t tca_get_parent(struct rtnl_tca *);
-extern void tca_set_kind(struct rtnl_tca *, const char *);
-extern char *tca_get_kind(struct rtnl_tca *);
-extern uint64_t tca_get_stat(struct rtnl_tca *, int );
+extern void    tca_set_kind(struct rtnl_tc *, const char *);
 
-extern int tca_build_msg(struct rtnl_tca *, int, int, struct nl_msg **);
+extern int tca_build_msg(struct rtnl_tc *, int, int, struct nl_msg **);
 
-static inline void *tca_priv(struct rtnl_tca *tca)
+#define RTNL_TC_RTABLE_SIZE    256
+
+extern int rtnl_tc_build_rate_table(struct rtnl_tc *tc, struct rtnl_ratespec *,
+                                   uint32_t *);
+
+
+static inline void *tca_priv(struct rtnl_tc *tca)
 {
        return tca->tc_subdata;
 }
 
-static inline void *tca_xstats(struct rtnl_tca *tca)
+static inline void *tca_xstats(struct rtnl_tc *tca)
 {
        return tca->tc_xstats->d_data;
 }
index 4f9bb16ec54ca07dc269df18dc8d000ba68d9032..3abeff4d5962c581fde886f78602affb19e5a46f 100644 (file)
@@ -450,14 +450,18 @@ struct rtnl_tstats
        uint32_t                pre ##_handle;          \
        uint32_t                pre ##_parent;          \
        uint32_t                pre ##_info;            \
+       uint32_t                pre ##_mtu;             \
+       uint32_t                pre ##_mpu;             \
+       uint32_t                pre ##_overhead;        \
+       uint32_t                pre ##_linktype;        \
        char                    pre ##_kind[TCKINDSIZ]; \
        struct nl_data *        pre ##_opts;            \
        uint64_t                pre ##_stats[RTNL_TC_STATS_MAX+1]; \
        struct nl_data *        pre ##_xstats;          \
        struct nl_data *        pre ##_subdata;         \
+       struct rtnl_link *      pre ##_link
 
-
-struct rtnl_tca
+struct rtnl_tc
 {
        NL_TCA_GENERIC(tc);
 };
@@ -562,7 +566,6 @@ struct rtnl_prio
 struct rtnl_tbf
 {
        uint32_t                qt_limit;
-       uint32_t                qt_mpu;
        struct rtnl_ratespec    qt_rate;
        uint32_t                qt_rate_bucket;
        uint32_t                qt_rate_txtime;
@@ -632,7 +635,6 @@ struct rtnl_htb_qdisc
 struct rtnl_htb_class
 {
        uint32_t                ch_prio;
-       uint32_t                ch_mtu;
        struct rtnl_ratespec    ch_rate;
        struct rtnl_ratespec    ch_ceil;
        uint32_t                ch_rbuffer;
index e73cd460b75f27100b829a5ad8e2a9eca63b1017..0141c21968d0dee0f53ad2a7b4c8fe584860d6d9 100644 (file)
 
 #include <netlink/route/class.h>
 #include <netlink/route/class-modules.h>
+#include <netlink/cli/tc.h>
 
 extern struct rtnl_class *nl_cli_class_alloc(void);
 extern struct nl_cache *nl_cli_class_alloc_cache(struct nl_sock *, int);
 
-extern void nl_cli_class_parse_dev(struct rtnl_class *, struct nl_cache *, char *);
-extern void nl_cli_class_parse_parent(struct rtnl_class *, char *);
-extern void nl_cli_class_parse_handle(struct rtnl_class *, char *);
 extern void nl_cli_class_parse_kind(struct rtnl_class *, char *);
 
 #endif
index 537e1a9c85d5a1480d8eb8a4c8dc6435b2c89527..00c7083ae79d9afbbcdcfd32e09e0db009116b95 100644 (file)
@@ -36,9 +36,6 @@ extern void nl_cli_qdisc_unregister(struct nl_cli_qdisc_module *);
 
 extern struct rtnl_qdisc *nl_cli_qdisc_alloc(void);
 
-extern void nl_cli_qdisc_parse_dev(struct rtnl_qdisc *, struct nl_cache *, char *);
-extern void nl_cli_qdisc_parse_parent(struct rtnl_qdisc *, char *);
-extern void nl_cli_qdisc_parse_handle(struct rtnl_qdisc *, char *);
 extern void nl_cli_qdisc_parse_kind(struct rtnl_qdisc *, char *);
 
 #endif
diff --git a/include/netlink/cli/tc.h b/include/netlink/cli/tc.h
new file mode 100644 (file)
index 0000000..762cc69
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * netlink/cli/tc.h     CLI Traffic Control Helpers
+ *
+ *     This library is free software; you can redistribute it and/or
+ *     modify it under the terms of the GNU Lesser General Public
+ *     License as published by the Free Software Foundation version 2.1
+ *     of the License.
+ *
+ * Copyright (c) 2010 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef __NETLINK_CLI_TC_H_
+#define __NETLINK_CLI_TC_H_
+
+#include <netlink/route/tc.h>
+
+extern void nl_cli_tc_parse_dev(struct rtnl_tc *, struct nl_cache *, char *);
+extern void nl_cli_tc_parse_parent(struct rtnl_tc *, char *);
+extern void nl_cli_tc_parse_handle(struct rtnl_tc *, char *);
+extern void nl_cli_tc_parse_mtu(struct rtnl_tc *, char *);
+extern void nl_cli_tc_parse_mpu(struct rtnl_tc *, char *);
+extern void nl_cli_tc_parse_overhead(struct rtnl_tc *, char *);
+extern void nl_cli_tc_parse_linktype(struct rtnl_tc *, char *);
+
+#endif
index 480095e1f7bf26de75cdfe19e77e3666d6b20f41..13a25d6d321798adbb51fbd5b34f5909237c388c 100644 (file)
@@ -43,16 +43,7 @@ extern int   rtnl_class_build_delete_request(struct rtnl_class *,
                                                                                        struct nl_msg **);
 extern int     rtnl_class_delete(struct nl_sock *, struct rtnl_class *);
 
-extern void            rtnl_class_set_ifindex(struct rtnl_class *, int);
-extern int             rtnl_class_get_ifindex(struct rtnl_class *);
-extern void            rtnl_class_set_handle(struct rtnl_class *, uint32_t);
-extern uint32_t                rtnl_class_get_handle(struct rtnl_class *);
-extern void            rtnl_class_set_parent(struct rtnl_class *, uint32_t);
-extern uint32_t                rtnl_class_get_parent(struct rtnl_class *);
 extern void            rtnl_class_set_kind(struct rtnl_class *, const char *);
-extern char *          rtnl_class_get_kind(struct rtnl_class *);
-extern uint64_t                rtnl_class_get_stat(struct rtnl_class *,
-                                           enum rtnl_tc_stats_id);
 
 /* iterators */
 extern void            rtnl_class_foreach_child(struct rtnl_class *,
index d9c3d211ab38b885019c31e0829ddc9c73bbaaf5..17c834be86abdd498376976dce16783299ba991d 100644 (file)
@@ -6,7 +6,7 @@
  *     License as published by the Free Software Foundation version 2.1
  *     of the License.
  *
- * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch>
+ * Copyright (c) 2003-2010 Thomas Graf <tgraf@suug.ch>
  */
 
 #ifndef NETLINK_CLASSIFIER_H_
@@ -39,11 +39,6 @@ extern int   rtnl_cls_build_delete_request(struct rtnl_cls *, int,
                                              struct nl_msg **);
 extern int     rtnl_cls_delete(struct nl_sock *, struct rtnl_cls *, int);
 
-extern void rtnl_cls_set_ifindex(struct rtnl_cls *, int);
-extern int rtnl_cls_get_ifindex(struct rtnl_cls *);
-extern void rtnl_cls_set_handle(struct rtnl_cls *, uint32_t);
-extern void rtnl_cls_set_parent(struct rtnl_cls *, uint32_t);
-extern uint32_t rtnl_cls_get_parent(struct rtnl_cls *);
 extern int rtnl_cls_set_kind(struct rtnl_cls *, const char *);
 extern struct rtnl_cls_ops *rtnl_cls_get_ops(struct rtnl_cls *);
 
index 5acd6e1c07eaaced76c985701dc6a8a76e667862..966eb44c27356fe8dc3ea67342c11c3170f4e955 100644 (file)
@@ -46,15 +46,7 @@ extern int   rtnl_qdisc_build_delete_request(struct rtnl_qdisc *,
                                                struct nl_msg **);
 extern int     rtnl_qdisc_delete(struct nl_sock *, struct rtnl_qdisc *);
 
-extern void    rtnl_qdisc_set_ifindex(struct rtnl_qdisc *, int);
-extern int     rtnl_qdisc_get_ifindex(struct rtnl_qdisc *);
-extern void    rtnl_qdisc_set_handle(struct rtnl_qdisc *, uint32_t);
-extern uint32_t        rtnl_qdisc_get_handle(struct rtnl_qdisc *);
-extern void    rtnl_qdisc_set_parent(struct rtnl_qdisc *, uint32_t);
-extern uint32_t        rtnl_qdisc_get_parent(struct rtnl_qdisc *);
 extern void    rtnl_qdisc_set_kind(struct rtnl_qdisc *, const char *);
-extern char *  rtnl_qdisc_get_kind(struct rtnl_qdisc *);
-extern uint64_t        rtnl_qdisc_get_stat(struct rtnl_qdisc *, enum rtnl_tc_stats_id);
 
 extern void    rtnl_qdisc_foreach_child(struct rtnl_qdisc *, struct nl_cache *,
                                         void (*cb)(struct nl_object *, void *),
index d44f039a7014aebbe8f495c0ac2520dc5bcde532..c15923e17db1dd22a8aee9c763491319a40e230b 100644 (file)
@@ -6,7 +6,7 @@
  *     License as published by the Free Software Foundation version 2.1
  *     of the License.
  *
- * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ * Copyright (c) 2003-2010 Thomas Graf <tgraf@suug.ch>
  * Copyright (c) 2005 Petr Gotthard <petr.gotthard@siemens.com>
  * Copyright (c) 2005 Siemens AG Oesterreich
  */
@@ -25,14 +25,11 @@ extern void rtnl_htb_set_rate2quantum(struct rtnl_qdisc *, uint32_t);
 extern void rtnl_htb_set_defcls(struct rtnl_qdisc *, uint32_t);
 
 extern void rtnl_htb_set_prio(struct rtnl_class *, uint32_t);
-extern void rtnl_htb_set_mtu(struct rtnl_class *, uint32_t);
 extern void rtnl_htb_set_rate(struct rtnl_class *, uint32_t);
 extern void rtnl_htb_set_ceil(struct rtnl_class *, uint32_t);
 extern void rtnl_htb_set_rbuffer(struct rtnl_class *, uint32_t);
 extern void rtnl_htb_set_cbuffer(struct rtnl_class *, uint32_t);
 extern void rtnl_htb_set_quantum(struct rtnl_class *, uint32_t quantum);
-extern void rtnl_htb_set_overhead(struct rtnl_class *, uint8_t overhead);
-extern void rtnl_htb_set_mpu(struct rtnl_class *, uint8_t mpu);
 
 #ifdef __cplusplus
 }
index 8e0ea1edf77607dcd55062c3eaf33dca58f09061..bb0e3b1379d760a1a9ea8a63f501fece2457c11c 100644 (file)
@@ -6,7 +6,7 @@
  *     License as published by the Free Software Foundation version 2.1
  *     of the License.
  *
- * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ * Copyright (c) 2003-2010 Thomas Graf <tgraf@suug.ch>
  */
 
 #ifndef NETLINK_TBF_H_
@@ -23,9 +23,6 @@ extern int rtnl_qdisc_tbf_set_limit(struct rtnl_qdisc *, int);
 extern int rtnl_qdisc_tbf_set_limit_by_latency(struct rtnl_qdisc *, int);
 extern int rtnl_qdisc_tbf_get_limit(struct rtnl_qdisc *);
 
-extern int rtnl_qdisc_tbf_set_mpu(struct rtnl_qdisc *, int);
-extern int rtnl_qdisc_tbf_get_mpu(struct rtnl_qdisc *);
-
 extern int rtnl_qdisc_tbf_set_rate(struct rtnl_qdisc *, int, int, int);
 extern int rtnl_qdisc_tbf_get_rate(struct rtnl_qdisc *);
 extern int rtnl_qdisc_tbf_get_rate_bucket(struct rtnl_qdisc *);
index 1fdaf1c1f1bfcbb05327018838d9c2463db12fbb..b4e953ee4e5057b260943a62e3d14de250e56e9b 100644 (file)
@@ -6,7 +6,7 @@
  *     License as published by the Free Software Foundation version 2.1
  *     of the License.
  *
- * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ * Copyright (c) 2003-2010 Thomas Graf <tgraf@suug.ch>
  */
 
 #ifndef NETLINK_TC_H_
 #include <netlink/netlink.h>
 #include <netlink/cache.h>
 #include <netlink/data.h>
+#include <netlink/route/link.h>
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+struct rtnl_tc;
+
 /**
- * TC statistics identifiers
  * @ingroup tc
  */
 enum rtnl_tc_stats_id {
-       RTNL_TC_PACKETS,        /**< Packets seen */
-       RTNL_TC_BYTES,          /**< Bytes seen */
+       RTNL_TC_PACKETS,        /**< Number of packets seen */
+       RTNL_TC_BYTES,          /**< Total bytes seen */
        RTNL_TC_RATE_BPS,       /**< Current bits/s (rate estimator) */
        RTNL_TC_RATE_PPS,       /**< Current packet/s (rate estimator) */
-       RTNL_TC_QLEN,           /**< Queue length */
-       RTNL_TC_BACKLOG,        /**< Backlog length */
-       RTNL_TC_DROPS,          /**< Packets dropped */
-       RTNL_TC_REQUEUES,       /**< Number of requeues */
-       RTNL_TC_OVERLIMITS,     /**< Number of overlimits */
+       RTNL_TC_QLEN,           /**< Current queue length */
+       RTNL_TC_BACKLOG,        /**< Current backlog length */
+       RTNL_TC_DROPS,          /**< Total number of packets dropped */
+       RTNL_TC_REQUEUES,       /**< Total number of requeues */
+       RTNL_TC_OVERLIMITS,     /**< Total number of overlimits */
        __RTNL_TC_STATS_MAX,
 };
 
 #define RTNL_TC_STATS_MAX (__RTNL_TC_STATS_MAX - 1)
 
-extern int rtnl_tc_calc_txtime(int, int);
-extern int rtnl_tc_calc_bufsize(int, int);
-extern int rtnl_tc_calc_cell_log(int);
-
-/**
- * Number of entries in a transmission time lookup table
- * @ingroup tc
- */
-#define RTNL_TC_RTABLE_SIZE    256
-
-extern int rtnl_tc_build_rate_table(uint32_t *, uint8_t, int, int);
+extern void            rtnl_tc_set_ifindex(struct rtnl_tc *, int);
+extern int             rtnl_tc_get_ifindex(struct rtnl_tc *);
+extern void            rtnl_tc_set_link(struct rtnl_tc *, struct rtnl_link *);
+extern void            rtnl_tc_set_mtu(struct rtnl_tc *, uint32_t);
+extern uint32_t                rtnl_tc_get_mtu(struct rtnl_tc *);
+extern void            rtnl_tc_set_mpu(struct rtnl_tc *, uint32_t);
+extern uint32_t                rtnl_tc_get_mpu(struct rtnl_tc *);
+extern void            rtnl_tc_set_overhead(struct rtnl_tc *, uint32_t);
+extern uint32_t                rtnl_tc_get_overhead(struct rtnl_tc *);
+extern void            rtnl_tc_set_linktype(struct rtnl_tc *, uint32_t);
+extern uint32_t                rtnl_tc_get_linktype(struct rtnl_tc *);
+extern void            rtnl_tc_set_handle(struct rtnl_tc *, uint32_t);
+extern uint32_t                rtnl_tc_get_handle(struct rtnl_tc *);
+extern void            rtnl_tc_set_parent(struct rtnl_tc *, uint32_t);
+extern uint32_t                rtnl_tc_get_parent(struct rtnl_tc *);
+extern char *          rtnl_tc_get_kind(struct rtnl_tc *);
+extern uint64_t                rtnl_tc_get_stat(struct rtnl_tc *, int );
 
+extern int             rtnl_tc_calc_txtime(int, int);
+extern int             rtnl_tc_calc_bufsize(int, int);
+extern int             rtnl_tc_calc_cell_log(int);
 
-/* TC Handle Translations */
 extern int             rtnl_tc_read_classid_file(void);
 extern char *          rtnl_tc_handle2str(uint32_t, char *, size_t);
 extern int             rtnl_tc_str2handle(const char *, uint32_t *);
index 6b913a8aeb99822f250b469e56fcbe3ac77f6715..febf429ac36c1f32ff6c3b6aad3c44a69d804a13 100644 (file)
@@ -73,9 +73,6 @@ static void print_class_usage(void)
 "     --rate=RATE           Rate limit.\n"
 "     --ceil=RATE           Rate limit while borrowing (default: equal to --rate).\n"
 "     --prio=PRIO           Priority, lower is served first (default: 0).\n"
-"     --mtu=MTU             Maximum packet size on the link (default: 1600).\n"
-"     --mpu=MPU             Minimum packet size on the link (default: 0).\n"
-"     --overhead=OVERHEAD   Overhead in bytes per packet (default: 0).\n"
 "     --quantum=SIZE        Amount of bytes to serve at once (default: rate/r2q).\n"
 "     --burst=SIZE          Max charge size of rate burst buffer (default: auto).\n"
 "     --cburst=SIZE         Max charge size of ceil rate burst buffer (default: auto)\n"
@@ -96,9 +93,6 @@ static void htb_parse_class_argv(struct rtnl_class *class, int argc, char **argv
                        ARG_QUANTUM = 258,
                        ARG_CEIL,
                        ARG_PRIO,
-                       ARG_MTU,
-                       ARG_MPU,
-                       ARG_OVERHEAD,
                        ARG_BURST,
                        ARG_CBURST,
                };
@@ -108,9 +102,6 @@ static void htb_parse_class_argv(struct rtnl_class *class, int argc, char **argv
                        { "quantum", 1, 0, ARG_QUANTUM },
                        { "ceil", 1, 0, ARG_CEIL },
                        { "prio", 1, 0, ARG_PRIO },
-                       { "mtu", 1, 0, ARG_MTU },
-                       { "mpu", 1, 0, ARG_MPU },
-                       { "overhead", 1, 0, ARG_OVERHEAD },
                        { "burst", 1, 0, ARG_BURST },
                        { "cburst", 1, 0, ARG_CBURST },
                        { 0, 0, 0, 0 }
@@ -145,18 +136,6 @@ static void htb_parse_class_argv(struct rtnl_class *class, int argc, char **argv
                        rtnl_htb_set_ceil(class, rate);
                        break;
 
-               case ARG_MTU:
-                       rtnl_htb_set_mtu(class, nl_cli_parse_u32(optarg));
-                       break;
-
-               case ARG_MPU:
-                       rtnl_htb_set_mpu(class, nl_cli_parse_u32(optarg));
-                       break;
-
-               case ARG_OVERHEAD:
-                       rtnl_htb_set_overhead(class, nl_cli_parse_u32(optarg));
-                       break;
-
                case ARG_PRIO:
                        rtnl_htb_set_prio(class, nl_cli_parse_u32(optarg));
                        break;
index ddf2d2e8506862959a1187419b6263d60c2522cb..9717d208036fba52cc7274364b3b5983410f6759 100644 (file)
@@ -6,7 +6,7 @@
  *     License as published by the Free Software Foundation version 2.1
  *     of the License.
  *
- * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ * Copyright (c) 2003-2010 Thomas Graf <tgraf@suug.ch>
  */
 
 /**
@@ -41,7 +41,7 @@ static int class_msg_parser(struct nl_cache_ops *ops, struct sockaddr_nl *who,
        }
        class->ce_msgtype = n->nlmsg_type;
 
-       err = tca_msg_parser(n, (struct rtnl_tca *) class);
+       err = tca_msg_parser(n, (struct rtnl_tc *) class);
        if (err < 0)
                goto errout_free;
 
@@ -81,7 +81,7 @@ static int class_build(struct rtnl_class *class, int type, int flags,
        struct rtnl_class_ops *cops;
        int err;
 
-       err = tca_build_msg((struct rtnl_tca *) class, type, flags, result);
+       err = tca_build_msg((struct rtnl_tc *) class, type, flags, result);
        if (err < 0)
                return err;
 
index 5c2e5be6a794e044fb0cb21184819498e32c5290..097db254e7afdd1f5291ca3ed71318e8e25d926d 100644 (file)
@@ -6,7 +6,7 @@
  *     License as published by the Free Software Foundation version 2.1
  *     of the License.
  *
- * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ * Copyright (c) 2003-2010 Thomas Graf <tgraf@suug.ch>
  */
 
 /**
@@ -30,7 +30,7 @@ static void class_free_data(struct nl_object *obj)
        struct rtnl_class *class = (struct rtnl_class *) obj;
        struct rtnl_class_ops *cops;
        
-       tca_free_data((struct rtnl_tca *) class);
+       tca_free_data((struct rtnl_tc *) class);
 
        cops = rtnl_class_lookup_ops(class);
        if (cops && cops->co_free_data)
@@ -44,7 +44,7 @@ static int class_clone(struct nl_object *_dst, struct nl_object *_src)
        struct rtnl_class_ops *cops;
        int err;
 
-       err = tca_clone((struct rtnl_tca *) dst, (struct rtnl_tca *) src);
+       err = tca_clone((struct rtnl_tc *) dst, (struct rtnl_tc *) src);
        if (err < 0)
                goto errout;
 
@@ -60,7 +60,7 @@ static void class_dump_line(struct nl_object *obj, struct nl_dump_params *p)
        struct rtnl_class *class = (struct rtnl_class *) obj;
        struct rtnl_class_ops *cops;
 
-       tca_dump_line((struct rtnl_tca *) class, "class", p);
+       tca_dump_line((struct rtnl_tc *) class, "class", p);
 
        cops = rtnl_class_lookup_ops(class);
        if (cops && cops->co_dump[NL_DUMP_LINE])
@@ -74,7 +74,7 @@ static void class_dump_details(struct nl_object *obj, struct nl_dump_params *p)
        struct rtnl_class_ops *cops;
 
        class_dump_line(obj, p);
-       tca_dump_details((struct rtnl_tca *) class, p);
+       tca_dump_details((struct rtnl_tc *) class, p);
        
        if (class->c_info) {
                char buf[32];
@@ -97,7 +97,7 @@ static void class_dump_stats(struct nl_object *obj, struct nl_dump_params *p)
        struct rtnl_class_ops *cops;
 
        class_dump_details(obj, p);
-       tca_dump_stats((struct rtnl_tca *) class, p);
+       tca_dump_stats((struct rtnl_tc *) class, p);
        nl_dump(p, "\n");
 
        cops = rtnl_class_lookup_ops(class);
@@ -175,8 +175,8 @@ void rtnl_class_foreach_child(struct rtnl_class *class, struct nl_cache *cache,
        if (!filter)
                return;
 
-       rtnl_class_set_parent(filter, class->c_handle);
-       rtnl_class_set_ifindex(filter, class->c_ifindex);
+       rtnl_tc_set_parent((struct rtnl_tc *) filter, class->c_handle);
+       rtnl_tc_set_ifindex((struct rtnl_tc *) filter, class->c_ifindex);
        rtnl_class_set_kind(filter, class->c_kind);
 
        nl_cache_foreach_filter(cache, (struct nl_object *) filter, cb, arg);
@@ -200,8 +200,8 @@ void rtnl_class_foreach_cls(struct rtnl_class *class, struct nl_cache *cache,
        if (!filter)
                return;
 
-       rtnl_cls_set_ifindex(filter, class->c_ifindex);
-       rtnl_cls_set_parent(filter, class->c_parent);
+       rtnl_tc_set_ifindex((struct rtnl_tc *) filter, class->c_ifindex);
+       rtnl_tc_set_parent((struct rtnl_tc *) filter, class->c_parent);
 
        nl_cache_foreach_filter(cache, (struct nl_object *) filter, cb, arg);
        rtnl_cls_put(filter);
@@ -215,53 +215,12 @@ void rtnl_class_foreach_cls(struct rtnl_class *class, struct nl_cache *cache,
  * @{
  */
 
-void rtnl_class_set_ifindex(struct rtnl_class *class, int ifindex)
-{
-       tca_set_ifindex((struct rtnl_tca *) class, ifindex);
-}
-
-int rtnl_class_get_ifindex(struct rtnl_class *class)
-{
-       return tca_get_ifindex((struct rtnl_tca *) class);
-}
-
-void rtnl_class_set_handle(struct rtnl_class *class, uint32_t handle)
-{
-       tca_set_handle((struct rtnl_tca *) class, handle);
-}
-
-uint32_t rtnl_class_get_handle(struct rtnl_class *class)
-{
-       return tca_get_handle((struct rtnl_tca *) class);
-}
-
-void rtnl_class_set_parent(struct rtnl_class *class, uint32_t parent)
-{
-       tca_set_parent((struct rtnl_tca *) class, parent);
-}
-
-uint32_t rtnl_class_get_parent(struct rtnl_class *class)
-{
-       return tca_get_parent((struct rtnl_tca *) class);
-}
-
 void rtnl_class_set_kind(struct rtnl_class *class, const char *name)
 {
-       tca_set_kind((struct rtnl_tca *) class, name);
+       tca_set_kind((struct rtnl_tc *) class, name);
        class->c_ops = __rtnl_class_lookup_ops(name);
 }
 
-char *rtnl_class_get_kind(struct rtnl_class *class)
-{
-       return tca_get_kind((struct rtnl_tca *) class);
-}
-
-uint64_t rtnl_class_get_stat(struct rtnl_class *class,
-                            enum rtnl_tc_stats_id id)
-{
-       return tca_get_stat((struct rtnl_tca *) class, id);
-}
-
 /** @} */
 
 struct nl_object_ops class_obj_ops = {
index cbf034563b6034869c304ea9fc5e9b77cc6ad8a7..6d75e47378cd14e0a0845d0d2920685131006017 100644 (file)
@@ -49,7 +49,7 @@ static int cls_msg_parser(struct nl_cache_ops *ops, struct sockaddr_nl *who,
        }
        cls->ce_msgtype = nlh->nlmsg_type;
 
-       err = tca_msg_parser(nlh, (struct rtnl_tca *) cls);
+       err = tca_msg_parser(nlh, (struct rtnl_tc *) cls);
        if (err < 0)
                goto errout_free;
 
@@ -87,7 +87,7 @@ static int cls_build(struct rtnl_cls *cls, int type, int flags,
        int err, prio, proto;
        struct tcmsg *tchdr;
 
-       err = tca_build_msg((struct rtnl_tca *) cls, type, flags, result);
+       err = tca_build_msg((struct rtnl_tc *) cls, type, flags, result);
        if (err < 0)
                return err;
 
index 1460b72c25e651060e1aabd109ae8bc13a3c4229..f15180723ec191bee9eff363bef947dce9259495 100644 (file)
@@ -67,7 +67,7 @@ static int basic_msg_parser(struct rtnl_cls *cls)
        struct rtnl_basic *basic = rtnl_cls_data(cls);
        int err;
 
-       err = tca_parse(tb, TCA_BASIC_MAX, (struct rtnl_tca *) cls, basic_policy);
+       err = tca_parse(tb, TCA_BASIC_MAX, (struct rtnl_tc *) cls, basic_policy);
        if (err < 0)
                return err;
 
index e5f38b82dc6636421d2e2474cb38120cd1f61e8b..36ff4d4ed98562b4879d5f8bd90cfda69368964b 100644 (file)
@@ -47,7 +47,7 @@ static int cgroup_msg_parser(struct rtnl_cls *cls)
        struct nlattr *tb[TCA_CGROUP_MAX + 1];
        int err;
 
-       err = tca_parse(tb, TCA_CGROUP_MAX, (struct rtnl_tca *) cls,
+       err = tca_parse(tb, TCA_CGROUP_MAX, (struct rtnl_tc *) cls,
                        cgroup_policy);
        if (err < 0)
                return err;
index 8cf25b978ca4f24f2b5eb75090592f529950c59f..b8055fe569025de3fc2f292d9b15102d3df92a62 100644 (file)
@@ -44,7 +44,7 @@ static int fw_msg_parser(struct rtnl_cls *cls)
        struct nlattr *tb[TCA_FW_MAX + 1];
        int err;
 
-       err = tca_parse(tb, TCA_FW_MAX, (struct rtnl_tca *) cls, fw_policy);
+       err = tca_parse(tb, TCA_FW_MAX, (struct rtnl_tc *) cls, fw_policy);
        if (err < 0)
                return err;
 
index 80b88513dbb4650cc17e9f040da14dbf5b9abc3e..38214c95da379a2e5662981281a92ff261221cd1 100644 (file)
@@ -70,7 +70,7 @@ static int u32_msg_parser(struct rtnl_cls *cls)
        struct nlattr *tb[TCA_U32_MAX + 1];
        int err;
 
-       err = tca_parse(tb, TCA_U32_MAX, (struct rtnl_tca *) cls, u32_policy);
+       err = tca_parse(tb, TCA_U32_MAX, (struct rtnl_tc *) cls, u32_policy);
        if (err < 0)
                return err;
 
@@ -345,7 +345,7 @@ void rtnl_u32_set_handle(struct rtnl_cls *cls, int htid, int hash,
 {
        uint32_t handle = (htid << 20) | (hash << 12) | nodeid;
 
-       tca_set_handle((struct rtnl_tca *) cls, handle );
+       rtnl_tc_set_handle((struct rtnl_tc *) cls, handle );
 }
  
 int rtnl_u32_set_classid(struct rtnl_cls *cls, uint32_t classid)
index c8218c0708ec4df45f953c20906aa3288f3a6afa..dcf97ed47ef133b49406dcb1dd2eec9bdf5d285a 100644 (file)
@@ -6,7 +6,7 @@
  *     License as published by the Free Software Foundation version 2.1
  *     of the License.
  *
- * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ * Copyright (c) 2003-2010 Thomas Graf <tgraf@suug.ch>
  */
 
 /**
@@ -34,7 +34,7 @@ static void cls_free_data(struct nl_object *obj)
        struct rtnl_cls *cls = (struct rtnl_cls *) obj;
        struct rtnl_cls_ops *cops;
        
-       tca_free_data((struct rtnl_tca *) cls);
+       tca_free_data((struct rtnl_tc *) cls);
 
        cops = rtnl_cls_lookup_ops(cls);
        if (cops && cops->co_free_data)
@@ -50,7 +50,7 @@ static int cls_clone(struct nl_object *_dst, struct nl_object *_src)
        struct rtnl_cls_ops *cops;
        int err;
        
-       err = tca_clone((struct rtnl_tca *) dst, (struct rtnl_tca *) src);
+       err = tca_clone((struct rtnl_tc *) dst, (struct rtnl_tc *) src);
        if (err < 0)
                goto errout;
 
@@ -74,7 +74,7 @@ static void cls_dump_line(struct nl_object *obj, struct nl_dump_params *p)
        struct rtnl_cls *cls = (struct rtnl_cls *) obj;
        struct rtnl_cls_ops *cops;
 
-       tca_dump_line((struct rtnl_tca *) cls, "cls", p);
+       tca_dump_line((struct rtnl_tc *) cls, "cls", p);
 
        nl_dump(p, " prio %u protocol %s", cls->c_prio,
                nl_ether_proto2str(cls->c_protocol, buf, sizeof(buf)));
@@ -91,7 +91,7 @@ static void cls_dump_details(struct nl_object *obj, struct nl_dump_params *p)
        struct rtnl_cls_ops *cops;
 
        cls_dump_line(obj, p);
-       tca_dump_details((struct rtnl_tca *) cls, p);
+       tca_dump_details((struct rtnl_tc *) cls, p);
 
        cops = rtnl_cls_lookup_ops(cls);
        if (cops && cops->co_dump[NL_DUMP_DETAILS])
@@ -106,7 +106,7 @@ static void cls_dump_stats(struct nl_object *obj, struct nl_dump_params *p)
        struct rtnl_cls_ops *cops;
 
        cls_dump_details(obj, p);
-       tca_dump_stats((struct rtnl_tca *) cls, p);
+       tca_dump_stats((struct rtnl_tc *) cls, p);
        nl_dump(p, "\n");
 
        cops = rtnl_cls_lookup_ops(cls);
@@ -137,37 +137,12 @@ void rtnl_cls_put(struct rtnl_cls *cls)
  * @{
  */
 
-void rtnl_cls_set_ifindex(struct rtnl_cls *f, int ifindex)
-{
-       tca_set_ifindex((struct rtnl_tca *) f, ifindex);
-}
-
-int rtnl_cls_get_ifindex(struct rtnl_cls *cls)
-{
-       return cls->c_ifindex;
-}
-
-void rtnl_cls_set_handle(struct rtnl_cls *f, uint32_t handle)
-{
-       tca_set_handle((struct rtnl_tca *) f, handle);
-}
-
-void rtnl_cls_set_parent(struct rtnl_cls *f, uint32_t parent)
-{
-       tca_set_parent((struct rtnl_tca *) f, parent);
-}
-
-uint32_t rtnl_cls_get_parent(struct rtnl_cls *cls)
-{
-       return cls->c_parent;
-}
-
 int rtnl_cls_set_kind(struct rtnl_cls *cls, const char *kind)
 {
        if (cls->ce_mask & TCA_ATTR_KIND)
                return -NLE_EXIST;
 
-       tca_set_kind((struct rtnl_tca *) cls, kind);
+       tca_set_kind((struct rtnl_tc *) cls, kind);
 
        /* Force allocation of data */
        rtnl_cls_data(cls);
index cfeaf050d0b4c50bdc6b1222f2836695c81602c3..2867e63ef54d88c9a0aef74dd850cb5302948945 100644 (file)
@@ -110,7 +110,7 @@ static int qdisc_msg_parser(struct nl_cache_ops *ops, struct sockaddr_nl *who,
 
        qdisc->ce_msgtype = n->nlmsg_type;
 
-       err = tca_msg_parser(n, (struct rtnl_tca *) qdisc);
+       err = tca_msg_parser(n, (struct rtnl_tc *) qdisc);
        if (err < 0)
                goto errout_free;
 
@@ -150,7 +150,7 @@ static int qdisc_build(struct rtnl_qdisc *qdisc, int type, int flags,
        struct rtnl_qdisc_ops *qops;
        int err;
 
-       err = tca_build_msg((struct rtnl_tca *) qdisc, type, flags, result);
+       err = tca_build_msg((struct rtnl_tc *) qdisc, type, flags, result);
        if (err < 0)
                return err;
 
index dc52ae8054117951cac57ae4fc04f74a171653fd..baa00b23d428ea5b6838fe3e215f585e0b572795 100644 (file)
@@ -31,7 +31,7 @@ static void qdisc_free_data(struct nl_object *obj)
        struct rtnl_qdisc *qdisc = (struct rtnl_qdisc *) obj;
        struct rtnl_qdisc_ops *qops;
 
-       tca_free_data((struct rtnl_tca *) qdisc);
+       tca_free_data((struct rtnl_tc *) qdisc);
 
        qops = rtnl_qdisc_lookup_ops(qdisc);
        if (qops && qops->qo_free_data)
@@ -45,7 +45,7 @@ static int qdisc_clone(struct nl_object *_dst, struct nl_object *_src)
        struct rtnl_qdisc_ops *qops;
        int err;
 
-       err = tca_clone((struct rtnl_tca *) dst, (struct rtnl_tca *) src);
+       err = tca_clone((struct rtnl_tc *) dst, (struct rtnl_tc *) src);
        if (err < 0)
                goto errout;
 
@@ -61,7 +61,7 @@ static void qdisc_dump_line(struct nl_object *obj, struct nl_dump_params *p)
        struct rtnl_qdisc *qdisc = (struct rtnl_qdisc *) obj;
        struct rtnl_qdisc_ops *qops;
        
-       tca_dump_line((struct rtnl_tca *) qdisc, "qdisc", p);
+       tca_dump_line((struct rtnl_tc *) qdisc, "qdisc", p);
 
        qops = rtnl_qdisc_lookup_ops(qdisc);
        if (qops && qops->qo_dump[NL_DUMP_LINE])
@@ -77,7 +77,7 @@ static void qdisc_dump_details(struct nl_object *arg, struct nl_dump_params *p)
 
        qdisc_dump_line(arg, p);
 
-       tca_dump_details((struct rtnl_tca *) qdisc, p);
+       tca_dump_details((struct rtnl_tc *) qdisc, p);
        nl_dump(p, "refcnt %u ", qdisc->q_info);
 
        qops = rtnl_qdisc_lookup_ops(qdisc);
@@ -93,7 +93,7 @@ static void qdisc_dump_stats(struct nl_object *arg, struct nl_dump_params *p)
        struct rtnl_qdisc_ops *qops;
 
        qdisc_dump_details(arg, p);
-       tca_dump_stats((struct rtnl_tca *) qdisc, p);
+       tca_dump_stats((struct rtnl_tc *) qdisc, p);
        nl_dump(p, "\n");
 
        qops = rtnl_qdisc_lookup_ops(qdisc);
@@ -140,8 +140,8 @@ void rtnl_qdisc_foreach_child(struct rtnl_qdisc *qdisc, struct nl_cache *cache,
        if (!filter)
                return;
 
-       rtnl_class_set_parent(filter, qdisc->q_handle);
-       rtnl_class_set_ifindex(filter, qdisc->q_ifindex);
+       rtnl_tc_set_parent((struct rtnl_tc *) filter, qdisc->q_handle);
+       rtnl_tc_set_ifindex((struct rtnl_tc *) filter, qdisc->q_ifindex);
        rtnl_class_set_kind(filter, qdisc->q_kind);
 
        nl_cache_foreach_filter(cache, (struct nl_object *) filter, cb, arg);
@@ -166,8 +166,8 @@ void rtnl_qdisc_foreach_cls(struct rtnl_qdisc *qdisc, struct nl_cache *cache,
        if (!filter)
                return;
 
-       rtnl_cls_set_ifindex(filter, qdisc->q_ifindex);
-       rtnl_cls_set_parent(filter, qdisc->q_parent);
+       rtnl_tc_set_ifindex((struct rtnl_tc *) filter, qdisc->q_ifindex);
+       rtnl_tc_set_parent((struct rtnl_tc *) filter, qdisc->q_parent);
 
        nl_cache_foreach_filter(cache, (struct nl_object *) filter, cb, arg);
        rtnl_cls_put(filter);
@@ -180,53 +180,12 @@ void rtnl_qdisc_foreach_cls(struct rtnl_qdisc *qdisc, struct nl_cache *cache,
  * @{
  */
 
-void rtnl_qdisc_set_ifindex(struct rtnl_qdisc *qdisc, int ifindex)
-{
-       tca_set_ifindex((struct rtnl_tca *) qdisc, ifindex);
-}
-
-int rtnl_qdisc_get_ifindex(struct rtnl_qdisc *qdisc)
-{
-       return tca_get_ifindex((struct rtnl_tca *) qdisc);
-}
-
-void rtnl_qdisc_set_handle(struct rtnl_qdisc *qdisc, uint32_t handle)
-{
-       tca_set_handle((struct rtnl_tca *) qdisc, handle);
-}
-
-uint32_t rtnl_qdisc_get_handle(struct rtnl_qdisc *qdisc)
-{
-       return tca_get_handle((struct rtnl_tca *) qdisc);
-}
-
-void rtnl_qdisc_set_parent(struct rtnl_qdisc *qdisc, uint32_t parent)
-{
-       tca_set_parent((struct rtnl_tca *) qdisc, parent);
-}
-
-uint32_t rtnl_qdisc_get_parent(struct rtnl_qdisc *qdisc)
-{
-       return tca_get_parent((struct rtnl_tca *) qdisc);
-}
-
 void rtnl_qdisc_set_kind(struct rtnl_qdisc *qdisc, const char *name)
 {
-       tca_set_kind((struct rtnl_tca *) qdisc, name);
+       tca_set_kind((struct rtnl_tc *) qdisc, name);
        qdisc->q_ops = __rtnl_qdisc_lookup_ops(name);
 }
 
-char *rtnl_qdisc_get_kind(struct rtnl_qdisc *qdisc)
-{
-       return tca_get_kind((struct rtnl_tca *) qdisc);
-}
-
-uint64_t rtnl_qdisc_get_stat(struct rtnl_qdisc *qdisc,
-                            enum rtnl_tc_stats_id id)
-{
-       return tca_get_stat((struct rtnl_tca *) qdisc, id);
-}
-
 /** @} */
 
 /**
index 1aaa58dbd264f2ab515e2f84dcf99a57b098cb80..0df4aa06f3508742167d5f7d12b35ee35ab4a4de 100644 (file)
@@ -73,12 +73,12 @@ static struct nla_policy cbq_policy[TCA_CBQ_MAX+1] = {
        [TCA_CBQ_POLICE]        = { .minlen = sizeof(struct tc_cbq_police) },
 };
 
-static inline struct rtnl_cbq *cbq_qdisc(struct rtnl_tca *tca)
+static inline struct rtnl_cbq *cbq_qdisc(struct rtnl_tc *tca)
 {
        return (struct rtnl_cbq *) tca->tc_subdata;
 }
 
-static inline struct rtnl_cbq *cbq_alloc(struct rtnl_tca *tca)
+static inline struct rtnl_cbq *cbq_alloc(struct rtnl_tc *tca)
 {
        if (!tca->tc_subdata)
                tca->tc_subdata = calloc(1, sizeof(struct rtnl_qdisc));
@@ -87,7 +87,7 @@ static inline struct rtnl_cbq *cbq_alloc(struct rtnl_tca *tca)
 }
 
 
-static int cbq_msg_parser(struct rtnl_tca *tca)
+static int cbq_msg_parser(struct rtnl_tc *tca)
 {
        struct nlattr *tb[TCA_CBQ_MAX + 1];
        struct rtnl_cbq *cbq;
@@ -115,12 +115,12 @@ static int cbq_msg_parser(struct rtnl_tca *tca)
 
 static int cbq_qdisc_msg_parser(struct rtnl_qdisc *qdisc)
 {
-       return cbq_msg_parser((struct rtnl_tca *) qdisc);
+       return cbq_msg_parser((struct rtnl_tc *) qdisc);
 }
 
 static int cbq_class_msg_parser(struct rtnl_class *class)
 {
-       return cbq_msg_parser((struct rtnl_tca *) class);
+       return cbq_msg_parser((struct rtnl_tc *) class);
 }
 
 static void cbq_qdisc_free_data(struct rtnl_qdisc *qdisc)
@@ -128,7 +128,7 @@ static void cbq_qdisc_free_data(struct rtnl_qdisc *qdisc)
        free(qdisc->q_subdata);
 }
 
-static int cbq_clone(struct rtnl_tca *_dst, struct rtnl_tca *_src)
+static int cbq_clone(struct rtnl_tc *_dst, struct rtnl_tc *_src)
 {
        struct rtnl_cbq *src = cbq_qdisc(_src);
 
@@ -140,7 +140,7 @@ static int cbq_clone(struct rtnl_tca *_dst, struct rtnl_tca *_src)
 
 static int cbq_qdisc_clone(struct rtnl_qdisc *dst, struct rtnl_qdisc *src)
 {
-       return cbq_clone((struct rtnl_tca *) dst, (struct rtnl_tca *) src);
+       return cbq_clone((struct rtnl_tc *) dst, (struct rtnl_tc *) src);
 }
 
 static void cbq_class_free_data(struct rtnl_class *class)
@@ -150,10 +150,10 @@ static void cbq_class_free_data(struct rtnl_class *class)
 
 static int cbq_class_clone(struct rtnl_class *dst, struct rtnl_class *src)
 {
-       return cbq_clone((struct rtnl_tca *) dst, (struct rtnl_tca *) src);
+       return cbq_clone((struct rtnl_tc *) dst, (struct rtnl_tc *) src);
 }
 
-static void cbq_dump_line(struct rtnl_tca *tca, struct nl_dump_params *p)
+static void cbq_dump_line(struct rtnl_tc *tca, struct nl_dump_params *p)
 {
        struct rtnl_cbq *cbq;
        double r, rbit;
@@ -173,16 +173,16 @@ static void cbq_dump_line(struct rtnl_tca *tca, struct nl_dump_params *p)
 static void cbq_qdisc_dump_line(struct rtnl_qdisc *qdisc,
                                struct nl_dump_params *p)
 {
-       cbq_dump_line((struct rtnl_tca *) qdisc, p);
+       cbq_dump_line((struct rtnl_tc *) qdisc, p);
 }
 
 static void cbq_class_dump_line(struct rtnl_class *class,
                                struct nl_dump_params *p)
 {
-       cbq_dump_line((struct rtnl_tca *) class, p);
+       cbq_dump_line((struct rtnl_tc *) class, p);
 }
 
-static void cbq_dump_details(struct rtnl_tca *tca, struct nl_dump_params *p)
+static void cbq_dump_details(struct rtnl_tc *tca, struct nl_dump_params *p)
 {
        struct rtnl_cbq *cbq;
        char *unit, buf[32];
@@ -225,16 +225,16 @@ static void cbq_dump_details(struct rtnl_tca *tca, struct nl_dump_params *p)
 static void cbq_qdisc_dump_details(struct rtnl_qdisc *qdisc,
                                   struct nl_dump_params *p)
 {
-       cbq_dump_details((struct rtnl_tca *) qdisc, p);
+       cbq_dump_details((struct rtnl_tc *) qdisc, p);
 }
 
 static void cbq_class_dump_details(struct rtnl_class *class,
                                   struct nl_dump_params *p)
 {
-       cbq_dump_details((struct rtnl_tca *) class, p);
+       cbq_dump_details((struct rtnl_tc *) class, p);
 }
 
-static void cbq_dump_stats(struct rtnl_tca *tca, struct nl_dump_params *p)
+static void cbq_dump_stats(struct rtnl_tc *tca, struct nl_dump_params *p)
 {
        struct tc_cbq_xstats *x = tca_xstats(tca);
 
@@ -250,13 +250,13 @@ static void cbq_dump_stats(struct rtnl_tca *tca, struct nl_dump_params *p)
 static void cbq_qdisc_dump_stats(struct rtnl_qdisc *qdisc,
                                 struct nl_dump_params *p)
 {
-       cbq_dump_stats((struct rtnl_tca *) qdisc, p);
+       cbq_dump_stats((struct rtnl_tc *) qdisc, p);
 }
 
 static void cbq_class_dump_stats(struct rtnl_class *class,
                                 struct nl_dump_params *p)
 {
-       cbq_dump_stats((struct rtnl_tca *) class, p);
+       cbq_dump_stats((struct rtnl_tc *) class, p);
 }
 
 static struct rtnl_qdisc_ops cbq_qdisc_ops = {
index 61b0feaa70a98957bc24713e9c58f1de7b70e229..a2e1628fd1464737ffef2fe8bcfd7e39572ff826 100644 (file)
@@ -63,7 +63,7 @@ static int dsmark_qdisc_msg_parser(struct rtnl_qdisc *qdisc)
        struct nlattr *tb[TCA_DSMARK_MAX + 1];
        struct rtnl_dsmark_qdisc *dsmark;
 
-       err = tca_parse(tb, TCA_DSMARK_MAX, (struct rtnl_tca *) qdisc,
+       err = tca_parse(tb, TCA_DSMARK_MAX, (struct rtnl_tc *) qdisc,
                        dsmark_policy);
        if (err < 0)
                return err;
@@ -111,7 +111,7 @@ static int dsmark_class_msg_parser(struct rtnl_class *class)
        struct nlattr *tb[TCA_DSMARK_MAX + 1];
        struct rtnl_dsmark_class *dsmark;
 
-       err = tca_parse(tb, TCA_DSMARK_MAX, (struct rtnl_tca *) class,
+       err = tca_parse(tb, TCA_DSMARK_MAX, (struct rtnl_tc *) class,
                        dsmark_policy);
        if (err < 0)
                return err;
index c1651e76bc506bcf6f7b7ee3b1d61da5765593e8..93ec28a943c1ccf38e3b35ddf0db0863fa53dc5a 100644 (file)
@@ -6,7 +6,7 @@
  *     License as published by the Free Software Foundation version 2.1
  *     of the License.
  *
- * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ * Copyright (c) 2003-2010 Thomas Graf <tgraf@suug.ch>
  * Copyright (c) 2005-2006 Petr Gotthard <petr.gotthard@siemens.com>
  * Copyright (c) 2005-2006 Siemens AG Oesterreich
  */
 #define SCH_HTB_HAS_DEFCLS             0x02
 
 #define SCH_HTB_HAS_PRIO               0x001
-#define SCH_HTB_HAS_MTU                        0x002
-#define SCH_HTB_HAS_RATE               0x004
-#define SCH_HTB_HAS_CEIL               0x008
-#define SCH_HTB_HAS_RBUFFER            0x010
-#define SCH_HTB_HAS_CBUFFER            0x020
-#define SCH_HTB_HAS_QUANTUM            0x040
-#define SCH_HTB_HAS_OVERHEAD           0x080
-#define SCH_HTB_HAS_MPU                        0x100
+#define SCH_HTB_HAS_RATE               0x002
+#define SCH_HTB_HAS_CEIL               0x004
+#define SCH_HTB_HAS_RBUFFER            0x008
+#define SCH_HTB_HAS_CBUFFER            0x010
+#define SCH_HTB_HAS_QUANTUM            0x020
 /** @endcond */
 
 static inline struct rtnl_htb_qdisc *htb_qdisc(struct rtnl_qdisc *qdisc)
@@ -65,7 +62,7 @@ static int htb_qdisc_msg_parser(struct rtnl_qdisc *qdisc)
        struct nlattr *tb[TCA_HTB_MAX + 1];
        struct rtnl_htb_qdisc *d;
 
-       err = tca_parse(tb, TCA_HTB_MAX, (struct rtnl_tca *) qdisc, htb_policy);
+       err = tca_parse(tb, TCA_HTB_MAX, (struct rtnl_tc *) qdisc, htb_policy);
        if (err < 0)
                return err;
        
@@ -102,8 +99,9 @@ static int htb_class_msg_parser(struct rtnl_class *class)
        int err;
        struct nlattr *tb[TCA_HTB_MAX + 1];
        struct rtnl_htb_class *d;
+       struct rtnl_tc *tc = (struct rtnl_tc *) class;
 
-       err = tca_parse(tb, TCA_HTB_MAX, (struct rtnl_tca *) class, htb_policy);
+       err = tca_parse(tb, TCA_HTB_MAX, (struct rtnl_tc *) class, htb_policy);
        if (err < 0)
                return err;
        
@@ -120,10 +118,12 @@ static int htb_class_msg_parser(struct rtnl_class *class)
                d->ch_cbuffer = rtnl_tc_calc_bufsize(opts.cbuffer, opts.ceil.rate);
                d->ch_quantum = opts.quantum;
 
+               rtnl_tc_set_mpu(tc, d->ch_rate.rs_mpu);
+               rtnl_tc_set_overhead(tc, d->ch_rate.rs_overhead);
+
                d->ch_mask = (SCH_HTB_HAS_PRIO | SCH_HTB_HAS_RATE |
                        SCH_HTB_HAS_CEIL | SCH_HTB_HAS_RBUFFER |
-                       SCH_HTB_HAS_CBUFFER | SCH_HTB_HAS_QUANTUM |
-                       SCH_HTB_HAS_OVERHEAD | SCH_HTB_HAS_MPU);
+                       SCH_HTB_HAS_CBUFFER | SCH_HTB_HAS_QUANTUM);
        }
 
        return 0;
@@ -195,9 +195,6 @@ static void htb_class_dump_details(struct rtnl_class *class,
        if (d->ch_mask & SCH_HTB_HAS_PRIO)
                nl_dump(p, " prio %u", d->ch_prio);
 
-       if (d->ch_mask & SCH_HTB_HAS_MTU)
-               nl_dump(p, " mtu %u", d->ch_mtu);
-
        if (d->ch_mask & SCH_HTB_HAS_RBUFFER) {
                double b;
                char *bu;
@@ -216,12 +213,6 @@ static void htb_class_dump_details(struct rtnl_class *class,
 
        if (d->ch_mask & SCH_HTB_HAS_QUANTUM)
                nl_dump(p, " quantum %u", d->ch_quantum);
-
-       if (d->ch_mask & SCH_HTB_HAS_OVERHEAD)
-               nl_dump(p, " overhead %u", d->ch_rate.rs_overhead);
-
-       if (d->ch_mask & SCH_HTB_HAS_MPU)
-               nl_dump(p, " mpu %u", d->ch_rate.rs_mpu);
 }
 
 static struct nl_msg *htb_qdisc_get_opts(struct rtnl_qdisc *qdisc)
@@ -250,17 +241,6 @@ static struct nl_msg *htb_qdisc_get_opts(struct rtnl_qdisc *qdisc)
        return msg;
 }
 
-static uint8_t compute_cell(uint32_t rate, uint32_t mtu)
-{
-       uint8_t cell_log = 0;
-       while (mtu > 255) {
-               mtu >>= 1;
-               cell_log++;
-       }
-
-       return cell_log;
-}
-
 static struct nl_msg *htb_class_get_opts(struct rtnl_class *class)
 {
        struct rtnl_htb_class *d = (struct rtnl_htb_class *) class->c_subdata;
@@ -272,34 +252,34 @@ static struct nl_msg *htb_class_get_opts(struct rtnl_class *class)
        if (d == NULL)
                return NULL;
 
+       if (!(d->ch_mask & SCH_HTB_HAS_RATE))
+               BUG();
+
        msg = nlmsg_alloc();
+       if (!msg)
+               return NULL;
+
        memset(&opts, 0, sizeof(opts));
 
        /* if not set, zero (0) is used as priority */
        if (d->ch_mask & SCH_HTB_HAS_PRIO)
                opts.prio = d->ch_prio;
 
-       if (d->ch_mask & SCH_HTB_HAS_MTU)
-               mtu = d->ch_mtu;
-       else
-               mtu = 1600; /* eth packet len */
-
-       if (!(d->ch_mask & SCH_HTB_HAS_RATE))
-               BUG();
+       mtu = rtnl_tc_get_mtu((struct rtnl_tc *) class);
 
+       rtnl_tc_build_rate_table((struct rtnl_tc *) class, &d->ch_rate, rtable);
        rtnl_rcopy_ratespec(&opts.rate, &d->ch_rate);
-       /* if cell_log not set, compute default value */
-       if (opts.rate.cell_log == UINT8_MAX)
-               opts.rate.cell_log = compute_cell(opts.rate.rate, mtu);
 
-       /* if not set, configured rate is used as ceil, which implies no borrowing */
-       if (d->ch_mask & SCH_HTB_HAS_CEIL)
+       if (d->ch_mask & SCH_HTB_HAS_CEIL) {
+               rtnl_tc_build_rate_table((struct rtnl_tc *) class, &d->ch_ceil, ctable);
                rtnl_rcopy_ratespec(&opts.ceil, &d->ch_ceil);
-       else
+       } else {
+               /*
+                * If not set, configured rate is used as ceil, which implies
+                * no borrowing.
+                */
                memcpy(&opts.ceil, &opts.rate, sizeof(struct tc_ratespec));
-       /* if cell_log not set, compute default value */
-       if (opts.ceil.cell_log == UINT8_MAX)
-               opts.ceil.cell_log = compute_cell(opts.ceil.rate, mtu);
+       }
 
        if (d->ch_mask & SCH_HTB_HAS_RBUFFER)
                buffer = d->ch_rbuffer;
@@ -319,15 +299,7 @@ static struct nl_msg *htb_class_get_opts(struct rtnl_class *class)
                opts.quantum = d->ch_quantum;
 
        nla_put(msg, TCA_HTB_PARMS, sizeof(opts), &opts);
-
-       rtnl_tc_build_rate_table(rtable, d->ch_rate.rs_mpu,
-                                1 << opts.rate.cell_log,
-                                opts.rate.rate);
        nla_put(msg, TCA_HTB_RTAB, sizeof(rtable), &rtable);
-
-       rtnl_tc_build_rate_table(ctable, d->ch_ceil.rs_mpu,
-                                1 << opts.ceil.cell_log,
-                                opts.ceil.rate);
        nla_put(msg, TCA_HTB_CTAB, sizeof(ctable), &ctable);
 
        return msg;
@@ -373,24 +345,6 @@ void rtnl_htb_set_prio(struct rtnl_class *class, uint32_t prio)
        d->ch_mask |= SCH_HTB_HAS_PRIO;
 }
 
-/**
- * Set MTU of the data link.
- * @arg class          HTB class to be modified.
- * @arg mtu            New MTU in bytes.
- *
- * Sets MTU of the data link controlled by the HTB class.
- * If not set, the Ethernet MTU (1600) is used.
- */
-void rtnl_htb_set_mtu(struct rtnl_class *class, uint32_t mtu)
-{
-       struct rtnl_htb_class *d = htb_class(class);
-       if (d == NULL)
-               return;
-
-       d->ch_mtu = mtu;
-       d->ch_mask |= SCH_HTB_HAS_MTU;
-}
-
 /**
  * Set rate of HTB class.
  * @arg class          HTB class to be modified.
@@ -468,38 +422,6 @@ void rtnl_htb_set_quantum(struct rtnl_class *class, uint32_t quantum)
        d->ch_mask |= SCH_HTB_HAS_QUANTUM;
 }
 
-/**
- * Set per-packet size overhead used in rate computations of HTB class.
- * @arg class          HTB class to be modified.
- * @arg overhead               Size in bytes.
- */
-void rtnl_htb_set_overhead(struct rtnl_class *class, uint8_t overhead)
-{
-       struct rtnl_htb_class *d = htb_class(class);
-       if (d == NULL)
-               return;
-
-       d->ch_rate.rs_overhead = overhead;
-       d->ch_ceil.rs_overhead = overhead;
-       d->ch_mask |= SCH_HTB_HAS_OVERHEAD;
-}
-
-/**
- * Set the minimum packet size used in rate computations of HTB class.
- * @arg class          HTB class to be modified.
- * @arg mpu            Size in bytes.
- */
-void rtnl_htb_set_mpu(struct rtnl_class *class, uint8_t mpu)
-{
-       struct rtnl_htb_class *d = htb_class(class);
-       if (d == NULL)
-               return;
-
-       d->ch_rate.rs_mpu = mpu;
-       d->ch_ceil.rs_mpu = mpu;
-       d->ch_mask |= SCH_HTB_HAS_MPU;
-}
-
 /** @} */
 
 static struct rtnl_qdisc_ops htb_qdisc_ops = {
index e4cac796e4d3ca2ab319cba71d2639451c123696..727db172b7acda3f0ab610e83e180fa4b7200478 100644 (file)
@@ -61,7 +61,7 @@ static int red_msg_parser(struct rtnl_qdisc *qdisc)
        if (!(qdisc->ce_mask & TCA_ATTR_OPTS))
                return 0;
 
-       err = tca_parse(tb, TCA_RED_MAX, (struct rtnl_tca *) qdisc, red_policy);
+       err = tca_parse(tb, TCA_RED_MAX, (struct rtnl_tc *) qdisc, red_policy);
        if (err < 0)
                return err;
 
index b749a36e730a36550e25e222447b38e26788b18e..c61810e4086a73a58de177d5d6d9a2142c659156 100644 (file)
@@ -6,7 +6,7 @@
  *     License as published by the Free Software Foundation version 2.1
  *     of the License.
  *
- * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ * Copyright (c) 2003-2010 Thomas Graf <tgraf@suug.ch>
  */
 
 /**
@@ -32,7 +32,6 @@
 #define TBF_ATTR_LIMIT                 0x01
 #define TBF_ATTR_RATE                  0x02
 #define TBF_ATTR_PEAKRATE              0x10
-#define TBF_ATTR_MPU                   0x80
 /** @endcond */
 
 static inline struct rtnl_tbf *tbf_qdisc(struct rtnl_qdisc *qdisc)
@@ -58,7 +57,7 @@ static int tbf_msg_parser(struct rtnl_qdisc *q)
        struct nlattr *tb[TCA_TBF_MAX + 1];
        struct rtnl_tbf *tbf;
 
-       err = tca_parse(tb, TCA_TBF_MAX, (struct rtnl_tca *) q, tbf_policy);
+       err = tca_parse(tb, TCA_TBF_MAX, (struct rtnl_tc *) q, tbf_policy);
        if (err < 0)
                return err;
        
@@ -72,7 +71,6 @@ static int tbf_msg_parser(struct rtnl_qdisc *q)
 
                nla_memcpy(&opts, tb[TCA_TBF_PARMS], sizeof(opts));
                tbf->qt_limit = opts.limit;
-               tbf->qt_mpu = opts.rate.mpu;
        
                rtnl_copy_ratespec(&tbf->qt_rate, &opts.rate);
                tbf->qt_rate_txtime = opts.buffer;
@@ -86,8 +84,10 @@ static int tbf_msg_parser(struct rtnl_qdisc *q)
                                               opts.peakrate.rate);
                tbf->qt_peakrate_bucket = bufsize;
 
-               tbf->qt_mask = (TBF_ATTR_LIMIT | TBF_ATTR_MPU | TBF_ATTR_RATE |
-                               TBF_ATTR_PEAKRATE);
+               rtnl_tc_set_mpu((struct rtnl_tc *) q, tbf->qt_rate.rs_mpu);
+               rtnl_tc_set_overhead((struct rtnl_tc *) q, tbf->qt_rate.rs_overhead);
+
+               tbf->qt_mask = (TBF_ATTR_LIMIT | TBF_ATTR_RATE | TBF_ATTR_PEAKRATE);
        }
 
        return 0;
@@ -128,9 +128,9 @@ static void tbf_dump_details(struct rtnl_qdisc *qdisc, struct nl_dump_params *p)
                double cl = nl_cancel_down_bytes(1 << tbf->qt_rate.rs_cell_log,
                                                 &cu);
 
-               nl_dump(p, "mpu %u rate-bucket-size %1.f%s "
+               nl_dump(p, "rate-bucket-size %1.f%s "
                           "rate-cell-size %.1f%s\n",
-                       tbf->qt_mpu, bs, bu, cl, cu);
+                       bs, bu, cl, cu);
 
        }
 
@@ -156,8 +156,7 @@ static struct nl_msg *tbf_get_opts(struct rtnl_qdisc *qdisc)
        struct tc_tbf_qopt opts;
        struct rtnl_tbf *tbf;
        struct nl_msg *msg;
-       uint32_t rtab[RTNL_TC_RTABLE_SIZE];
-       uint32_t ptab[RTNL_TC_RTABLE_SIZE];
+       uint32_t rtab[RTNL_TC_RTABLE_SIZE], ptab[RTNL_TC_RTABLE_SIZE];
        int required = TBF_ATTR_RATE | TBF_ATTR_LIMIT;
 
        memset(&opts, 0, sizeof(opts));
@@ -171,21 +170,15 @@ static struct nl_msg *tbf_get_opts(struct rtnl_qdisc *qdisc)
 
        opts.limit = tbf->qt_limit;
        opts.buffer = tbf->qt_rate_txtime;
-       tbf->qt_rate.rs_mpu = tbf->qt_mpu;
-       rtnl_rcopy_ratespec(&opts.rate, &tbf->qt_rate);
 
-       rtnl_tc_build_rate_table(rtab, tbf->qt_mpu & 0xff, 
-                                1 << tbf->qt_rate.rs_cell_log,
-                                tbf->qt_rate.rs_rate);
+       rtnl_tc_build_rate_table((struct rtnl_tc *) qdisc, &tbf->qt_rate, rtab);
+       rtnl_rcopy_ratespec(&opts.rate, &tbf->qt_rate);
 
        if (tbf->qt_mask & TBF_ATTR_PEAKRATE) {
                opts.mtu = tbf->qt_peakrate_txtime;
-               tbf->qt_peakrate.rs_mpu = tbf->qt_mpu;
+               rtnl_tc_build_rate_table((struct rtnl_tc *) qdisc, &tbf->qt_peakrate, ptab);
                rtnl_rcopy_ratespec(&opts.peakrate, &tbf->qt_peakrate);
 
-               rtnl_tc_build_rate_table(ptab, tbf->qt_mpu & 0xff,
-                                        1 << tbf->qt_peakrate.rs_cell_log,
-                                        tbf->qt_peakrate.rs_rate);
        }
 
        msg = nlmsg_alloc();
@@ -300,56 +293,9 @@ int rtnl_qdisc_tbf_get_limit(struct rtnl_qdisc *qdisc)
                return -NLE_NOATTR;
 }
 
-/**
- * Set MPU of TBF qdisc.
- * @arg qdisc          TBF qdisc to be modified.
- * @arg mpu            New MPU in bytes.
- * @return 0 on success or a negative error code.
- */
-int rtnl_qdisc_tbf_set_mpu(struct rtnl_qdisc *qdisc, int mpu)
-{
-       struct rtnl_tbf *tbf;
-       
-       tbf = tbf_alloc(qdisc);
-       if (!tbf)
-               return -NLE_NOMEM;
-
-       tbf->qt_mpu = mpu;
-       tbf->qt_mask |= TBF_ATTR_MPU;
-
-       return 0;
-}
-
-/**
- * Get MPU of TBF qdisc.
- * @arg qdisc          TBF qdisc.
- * @return MPU in bytes or a negative error code.
- */
-int rtnl_qdisc_tbf_get_mpu(struct rtnl_qdisc *qdisc)
-{
-       struct rtnl_tbf *tbf;
-       
-       tbf = tbf_qdisc(qdisc);
-       if (tbf && (tbf->qt_mask & TBF_ATTR_MPU))
-               return tbf->qt_mpu;
-       else
-               return -NLE_NOATTR;
-}
-
 static inline int calc_cell_log(int cell, int bucket)
 {
-       if (cell > 0)
                cell = rtnl_tc_calc_cell_log(cell);
-       else {
-               cell = 0;
-
-               if (!bucket)
-                       bucket = 2047; /* defaults to cell_log=3 */
-
-               while ((bucket >> cell) > 255)
-                       cell++;
-       }
-
        return cell;
 }
 
@@ -371,9 +317,10 @@ int rtnl_qdisc_tbf_set_rate(struct rtnl_qdisc *qdisc, int rate, int bucket,
        if (!tbf)
                return -NLE_NOMEM;
 
-       cell_log = calc_cell_log(cell, bucket);
-       if (cell_log < 0)
-               return cell_log;
+       if (!cell)
+               cell_log = UINT8_MAX;
+       else
+               cell_log = rtnl_tc_calc_cell_log(cell);
 
        tbf->qt_rate.rs_rate = rate;
        tbf->qt_rate_bucket = bucket;
index 1860c6fff82aaee09db1860c9e660279325b9e74..6a0233abdac61a597485eea60021b1426a48c778 100644 (file)
@@ -6,13 +6,12 @@
  *     License as published by the Free Software Foundation version 2.1
  *     of the License.
  *
- * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ * Copyright (c) 2003-2010 Thomas Graf <tgraf@suug.ch>
  */
 
 /**
  * @ingroup rtnl
  * @defgroup tc Traffic Control
- * @brief
  * @{
  */
 
@@ -33,7 +32,7 @@ static struct nla_policy tc_policy[TCA_MAX+1] = {
        [TCA_STATS2]    = { .type = NLA_NESTED },
 };
 
-int tca_parse(struct nlattr **tb, int maxattr, struct rtnl_tca *g,
+int tca_parse(struct nlattr **tb, int maxattr, struct rtnl_tc *g,
              struct nla_policy *policy)
 {
        
@@ -55,7 +54,7 @@ static struct nla_policy tc_stats2_policy[TCA_STATS_MAX+1] = {
        [TCA_STATS_QUEUE]    = { .minlen = sizeof(struct gnet_stats_queue) },
 };
 
-int tca_msg_parser(struct nlmsghdr *n, struct rtnl_tca *g)
+int tca_msg_parser(struct nlmsghdr *n, struct rtnl_tc *g)
 {
        struct nlattr *tb[TCA_MAX + 1];
        struct tcmsg *tm;
@@ -160,14 +159,22 @@ compat_xstats:
        return 0;
 }
 
-void tca_free_data(struct rtnl_tca *tca)
+void tca_free_data(struct rtnl_tc *tca)
 {
+       rtnl_link_put(tca->tc_link);
        nl_data_free(tca->tc_opts);
        nl_data_free(tca->tc_xstats);
 }
 
-int tca_clone(struct rtnl_tca *dst, struct rtnl_tca *src)
+int tca_clone(struct rtnl_tc *dst, struct rtnl_tc *src)
 {
+       if (src->tc_link) {
+               dst->tc_link = (struct rtnl_link *)
+                                       nl_object_clone(OBJ_CAST(src->tc_link));
+               if (!dst->tc_link)
+                       return -NLE_NOMEM;
+       }
+
        if (src->tc_opts) {
                dst->tc_opts = nl_data_clone(src->tc_opts);
                if (!dst->tc_opts)
@@ -183,7 +190,7 @@ int tca_clone(struct rtnl_tca *dst, struct rtnl_tca *src)
        return 0;
 }
 
-void tca_dump_line(struct rtnl_tca *g, const char *type,
+void tca_dump_line(struct rtnl_tc *g, const char *type,
                   struct nl_dump_params *p)
 {
        char handle[32], parent[32];
@@ -206,12 +213,21 @@ void tca_dump_line(struct rtnl_tca *g, const char *type,
                rtnl_tc_handle2str(g->tc_parent, parent, sizeof(parent)));
 }
 
-void tca_dump_details(struct rtnl_tca *g, struct nl_dump_params *p)
+void tca_dump_details(struct rtnl_tc *tc, struct nl_dump_params *p)
 {
        nl_dump_line(p, "  ");
+
+       if (tc->ce_mask & TCA_ATTR_MTU)
+               nl_dump(p, " mtu %u", tc->tc_mtu);
+
+       if (tc->ce_mask & TCA_ATTR_MPU)
+               nl_dump(p, " mput %u", tc->tc_mpu);
+
+       if (tc->ce_mask & TCA_ATTR_OVERHEAD)
+               nl_dump(p, " overhead %u", tc->tc_overhead);
 }
 
-void tca_dump_stats(struct rtnl_tca *g, struct nl_dump_params *p)
+void tca_dump_stats(struct rtnl_tc *g, struct nl_dump_params *p)
 {
        char *unit, fmt[64];
        float res;
@@ -245,8 +261,8 @@ void tca_dump_stats(struct rtnl_tca *g, struct nl_dump_params *p)
 int tca_compare(struct nl_object *_a, struct nl_object *_b,
                uint32_t attrs, int flags)
 {
-       struct rtnl_tca *a = (struct rtnl_tca *) _a;
-       struct rtnl_tca *b = (struct rtnl_tca *) _b;
+       struct rtnl_tc *a = (struct rtnl_tc *) _a;
+       struct rtnl_tc *b = (struct rtnl_tc *) _b;
        int diff = 0;
 
 #define TC_DIFF(ATTR, EXPR) ATTR_DIFF(attrs, TCA_ATTR_##ATTR, a, b, EXPR)
@@ -261,97 +277,305 @@ int tca_compare(struct nl_object *_a, struct nl_object *_b,
        return diff;
 }
 
-void tca_set_ifindex(struct rtnl_tca *t, int ifindex)
+int tca_build_msg(struct rtnl_tc *tca, int type, int flags,
+                 struct nl_msg **result)
+{
+       struct nl_msg *msg;
+       struct tcmsg tchdr = {
+               .tcm_family = AF_UNSPEC,
+               .tcm_ifindex = tca->tc_ifindex,
+               .tcm_handle = tca->tc_handle,
+               .tcm_parent = tca->tc_parent,
+       };
+
+       msg = nlmsg_alloc_simple(type, flags);
+       if (!msg)
+               return -NLE_NOMEM;
+
+       if (nlmsg_append(msg, &tchdr, sizeof(tchdr), NLMSG_ALIGNTO) < 0)
+               goto nla_put_failure;
+
+       if (tca->ce_mask & TCA_ATTR_KIND)
+           NLA_PUT_STRING(msg, TCA_KIND, tca->tc_kind);
+
+       *result = msg;
+       return 0;
+
+nla_put_failure:
+       nlmsg_free(msg);
+       return -NLE_MSGSIZE;
+}
+
+void tca_set_kind(struct rtnl_tc *t, const char *kind)
 {
-       t->tc_ifindex = ifindex;
-       t->ce_mask |= TCA_ATTR_IFINDEX;
+       strncpy(t->tc_kind, kind, sizeof(t->tc_kind) - 1);
+       t->ce_mask |= TCA_ATTR_KIND;
 }
 
-int tca_get_ifindex(struct rtnl_tca *t)
+
+/** @endcond */
+
+/**
+ * @name Attributes
+ * @{
+ */
+
+/**
+ * Set interface index of traffic control object
+ * @arg tc             traffic control object
+ * @arg ifindex                interface index.
+ *
+ * Sets the interface index of a traffic control object. The interface
+ * index defines the network device which this tc object is attached to.
+ * This function will overwrite any network device assigned with previous
+ * calls to rtnl_tc_set_ifindex() or rtnl_tc_set_link().
+ */
+void rtnl_tc_set_ifindex(struct rtnl_tc *tc, int ifindex)
 {
-       return t->tc_ifindex;
+       /* Obsolete possible old link reference */
+       rtnl_link_put(tc->tc_link);
+       tc->tc_link = NULL;
+       tc->ce_mask &= ~TCA_ATTR_LINK;
+
+       tc->tc_ifindex = ifindex;
+       tc->ce_mask |= TCA_ATTR_IFINDEX;
 }
 
-void tca_set_handle(struct rtnl_tca *t, uint32_t handle)
+/**
+ * Return interface index of traffic control object
+ * @arg tc             traffic control object
+ */
+int rtnl_tc_get_ifindex(struct rtnl_tc *tc)
 {
-       t->tc_handle = handle;
-       t->ce_mask |= TCA_ATTR_HANDLE;
+       return tc->tc_ifindex;
 }
 
-uint32_t tca_get_handle(struct rtnl_tca *t)
+/**
+ * Set link of traffic control object
+ * @arg tc             traffic control object
+ * @arg link           link object
+ *
+ * Sets the link of a traffic control object. This function serves
+ * the same purpose as rtnl_tc_set_ifindex() but due to the continued
+ * allowed access to the link object it gives it the possibility to
+ * retrieve sane default values for the the MTU and the linktype.
+ * Always prefer this function over rtnl_tc_set_ifindex() if you can
+ * spare to have an additional link object around.
+ */
+void rtnl_tc_set_link(struct rtnl_tc *tc, struct rtnl_link *link)
 {
-       if (t->ce_mask & TCA_ATTR_HANDLE)
-               return t->tc_handle;
-       else
-               return 0;
+       rtnl_link_put(tc->tc_link);
+
+       if (!link)
+               return;
+
+       nl_object_get(OBJ_CAST(link));
+       tc->tc_link = link;
+       tc->tc_ifindex = link->l_index;
+       tc->ce_mask |= TCA_ATTR_LINK | TCA_ATTR_IFINDEX;
 }
 
-void tca_set_parent(struct rtnl_tca *t, uint32_t parent)
+/**
+ * Set the Maximum Transmission Unit (MTU) of traffic control object
+ * @arg tc             traffic control object
+ * @arg mtu            largest packet size expected
+ *
+ * Sets the MTU of a traffic control object. Not all traffic control
+ * objects will make use of this but it helps while calculating rate
+ * tables. This value is typically derived directly from the link
+ * the tc object is attached to if the link has been assigned via
+ * rtnl_tc_set_link(). It is usually not necessary to set the MTU
+ * manually, this function is provided to allow overwriting the derived
+ * value.
+ */
+void rtnl_tc_set_mtu(struct rtnl_tc *tc, uint32_t mtu)
 {
-       t->tc_parent = parent;
-       t->ce_mask |= TCA_ATTR_PARENT;
+       tc->tc_mtu = mtu;
+       tc->ce_mask |= TCA_ATTR_MTU;
 }
 
-uint32_t tca_get_parent(struct rtnl_tca *t)
+/**
+ * Return the MTU of traffic control object
+ * @arg tc             traffic control object
+ *
+ * Returns the MTU of a traffic control object which has been set via:
+ * -# User specified value set via rtnl_tc_set_mtu()
+ * -# Dervied from link set via rtnl_tc_set_link()
+ * -# Fall back to default: ethernet = 1600
+ */
+uint32_t rtnl_tc_get_mtu(struct rtnl_tc *tc)
 {
-       if (t->ce_mask & TCA_ATTR_PARENT)
-               return t->tc_parent;
+       if (tc->ce_mask & TCA_ATTR_MTU)
+               return tc->tc_mtu;
+       else if (tc->ce_mask & TCA_ATTR_LINK)
+               return tc->tc_link->l_mtu;
        else
-               return 0;
+               return 1600; /* default to ethernet */
 }
 
-void tca_set_kind(struct rtnl_tca *t, const char *kind)
+/**
+ * Set the Minimum Packet Unit (MPU) of a traffic control object
+ * @arg tc             traffic control object
+ * @arg mpu            minimum packet size expected
+ *
+ * Sets the MPU of a traffic contorl object. It specifies the minimum
+ * packet size to ever hit this traffic control object. Not all traffic
+ * control objects will make use of this but it helps while calculating
+ * rate tables.
+ */
+void rtnl_tc_set_mpu(struct rtnl_tc *tc, uint32_t mpu)
 {
-       strncpy(t->tc_kind, kind, sizeof(t->tc_kind) - 1);
-       t->ce_mask |= TCA_ATTR_KIND;
+       tc->tc_mpu = mpu;
+       tc->ce_mask |= TCA_ATTR_MPU;
 }
 
-char *tca_get_kind(struct rtnl_tca *t)
+/**
+ * Return the Minimum Packet Unit (MPU) of a traffic control object
+ * @arg tc             traffic control object
+ *
+ * @return The MPU previously set via rtnl_tc_set_mpu() or 0.
+ */
+uint32_t rtnl_tc_get_mpu(struct rtnl_tc *tc)
 {
-       if (t->ce_mask & TCA_ATTR_KIND)
-               return t->tc_kind;
-       else
-               return NULL;
+       return tc->tc_mpu;
 }
 
-uint64_t tca_get_stat(struct rtnl_tca *t, int id)
+/**
+ * Set per packet overhead of a traffic control object
+ * @arg tc             traffic control object
+ * @arg overhead       overhead per packet in bytes
+ *
+ * Sets the per packet overhead in bytes occuring on the link not seen
+ * by the kernel. This value can be used to correct size calculations
+ * if the packet size on the wire does not match the packet sizes seen
+ * in the network stack. Not all traffic control objects will make use
+ * this but it helps while calculating accurate packet sizes in the
+ * kernel.
+ */
+void rtnl_tc_set_overhead(struct rtnl_tc *tc, uint32_t overhead)
 {
-       if (id < 0 || id > RTNL_TC_STATS_MAX)
-               return 0;
+       tc->tc_overhead = overhead;
+       tc->ce_mask |= TCA_ATTR_OVERHEAD;
+}
 
-       return t->tc_stats[id];
+/**
+ * Return per packet overhead of a traffic control object
+ * @arg tc             traffic control object
+ *
+ * @return The overhead previously set by rtnl_tc_set_overhead() or 0.
+ */
+uint32_t rtnl_tc_get_overhead(struct rtnl_tc *tc)
+{
+       return tc->tc_overhead;
 }
 
-int tca_build_msg(struct rtnl_tca *tca, int type, int flags,
-                 struct nl_msg **result)
+/**
+ * Set the linktype of a traffic control object
+ * @arg tc             traffic control object
+ * @arg type           type of link (e.g. ARPHRD_ATM, ARPHRD_ETHER)
+ *
+ * Overwrites the type of link this traffic control object is attached to.
+ * This value is typically derived from the link this tc object is attached
+ * if the link has been assigned via rtnl_tc_set_link(). It is usually not
+ * necessary to set the linktype manually. This function is provided to
+ * allow overwriting the linktype.
+ */
+void rtnl_tc_set_linktype(struct rtnl_tc *tc, uint32_t type)
 {
-       struct nl_msg *msg;
-       struct tcmsg tchdr = {
-               .tcm_family = AF_UNSPEC,
-               .tcm_ifindex = tca->tc_ifindex,
-               .tcm_handle = tca->tc_handle,
-               .tcm_parent = tca->tc_parent,
-       };
+       tc->tc_linktype = type;
+       tc->ce_mask |= TCA_ATTR_LINKTYPE;
+}
 
-       msg = nlmsg_alloc_simple(type, flags);
-       if (!msg)
-               return -NLE_NOMEM;
+/**
+ * Return the linktype of a traffic control object
+ * @arg tc             traffic control object
+ *
+ * Returns the linktype of the link the traffic control object is attached to:
+ * -# User specified value via rtnl_tc_set_linktype()
+ * -# Value derived from link set via rtnl_tc_set_link()
+ * -# Default fall-back: ARPHRD_ETHER
+ */
+uint32_t rtnl_tc_get_linktype(struct rtnl_tc *tc)
+{
+       if (tc->ce_mask & TCA_ATTR_LINKTYPE)
+               return tc->tc_linktype;
+       else if (tc->ce_mask & TCA_ATTR_LINK)
+               return tc->tc_link->l_arptype;
+       else
+               return ARPHRD_ETHER; /* default to ethernet */
+}
 
-       if (nlmsg_append(msg, &tchdr, sizeof(tchdr), NLMSG_ALIGNTO) < 0)
-               goto nla_put_failure;
+/**
+ * Set identifier of traffic control object
+ * @arg tc             traffic control object
+ * @arg id             unique identifier
+ */
+void rtnl_tc_set_handle(struct rtnl_tc *tc, uint32_t id)
+{
+       tc->tc_handle = id;
+       tc->ce_mask |= TCA_ATTR_HANDLE;
+}
 
-       if (tca->ce_mask & TCA_ATTR_KIND)
-           NLA_PUT_STRING(msg, TCA_KIND, tca->tc_kind);
+/**
+ * Return identifier of a traffic control object
+ * @arg tc             traffic control object
+ */
+uint32_t rtnl_tc_get_handle(struct rtnl_tc *tc)
+{
+       return tc->tc_handle;
+}
 
-       *result = msg;
-       return 0;
+/**
+ * Set the parent identifier of a traffic control object
+ * @arg tc             traffic control object
+ * @arg parent         identifier of parent traffif control object
+ *
+ */
+void rtnl_tc_set_parent(struct rtnl_tc *tc, uint32_t parent)
+{
+       tc->tc_parent = parent;
+       tc->ce_mask |= TCA_ATTR_PARENT;
+}
 
-nla_put_failure:
-       nlmsg_free(msg);
-       return -NLE_MSGSIZE;
+/**
+ * Return parent identifier of a traffic control object
+ * @arg tc             traffic control object
+ */
+uint32_t rtnl_tc_get_parent(struct rtnl_tc *tc)
+{
+       return tc->tc_parent;
 }
 
-/** @endcond */
+/**
+ * Return kind of traffic control object
+ * @arg tc             traffic control object
+ *
+ * @return Kind of traffic control object or NULL if not set.
+ */
+char *rtnl_tc_get_kind(struct rtnl_tc *tc)
+{
+       if (tc->ce_mask & TCA_ATTR_KIND)
+               return tc->tc_kind;
+       else
+               return NULL;
+}
+
+/**
+ * Return value of a statistical counter of a traffic control object
+ * @arg tc             traffic control object
+ * @arg id             identifier of statistical counter
+ *
+ * @return Value of requested statistic counter or 0.
+ */
+uint64_t rtnl_tc_get_stat(struct rtnl_tc *tc, int id)
+{
+       if (id < 0 || id > RTNL_TC_STATS_MAX)
+               return 0;
+
+       return tc->tc_stats[id];
+}
+
+/** @} */
 
 /**
  * @name Utilities
@@ -428,36 +652,94 @@ int rtnl_tc_calc_cell_log(int cell_size)
  * @{
  */
 
+/*
+ * COPYRIGHT NOTE:
+ * align_to_atm() and adjust_size() derived/coped from iproute2 source.
+ */
+
+/*
+ * The align to ATM cells is used for determining the (ATM) SAR
+ * alignment overhead at the ATM layer. (SAR = Segmentation And
+ * Reassembly).  This is for example needed when scheduling packet on
+ * an ADSL connection.  Note that the extra ATM-AAL overhead is _not_
+ * included in this calculation. This overhead is added in the kernel
+ * before doing the rate table lookup, as this gives better precision
+ * (as the table will always be aligned for 48 bytes).
+ *  --Hawk, d.7/11-2004. <hawk@diku.dk>
+ */
+static unsigned int align_to_atm(unsigned int size)
+{
+       int linksize, cells;
+       cells = size / ATM_CELL_PAYLOAD;
+       if ((size % ATM_CELL_PAYLOAD) > 0)
+               cells++;
+
+       linksize = cells * ATM_CELL_SIZE; /* Use full cell size to add ATM tax */
+       return linksize;
+}
+
+static unsigned int adjust_size(unsigned int size, unsigned int mpu,
+                               uint32_t linktype)
+{
+       if (size < mpu)
+               size = mpu;
+
+       switch (linktype) {
+       case ARPHRD_ATM:
+               return align_to_atm(size);
+
+       case ARPHRD_ETHER:
+       default:
+               return size;
+       }
+}
+
 /**
  * Compute a transmission time lookup table
- * @arg dst     Destination buffer of RTNL_TC_RTABLE_SIZE uint32_t[].
- * @arg mpu     Minimal size of a packet at all times.
- * @arg cell    Size of cell, i.e. size of step between entries in bytes.
- * @arg rate    Rate in bytes per second.
+ * @arg tc             traffic control object
+ * @arg spec           Rate specification
+ * @arg dst            Destination buffer of RTNL_TC_RTABLE_SIZE uint32_t[].
  *
  * Computes a table of RTNL_TC_RTABLE_SIZE entries specyfing the
  * transmission times for various packet sizes, e.g. the transmission
  * time for a packet of size \c pktsize could be looked up:
  * @code
- * txtime = table[pktsize >> log2(cell)];
+ * txtime = table[pktsize >> log2(mtu)];
  * @endcode
  */
-int rtnl_tc_build_rate_table(uint32_t *dst, uint8_t mpu, int cell, int rate)
+int rtnl_tc_build_rate_table(struct rtnl_tc *tc, struct rtnl_ratespec *spec,
+                            uint32_t *dst)
 {
-       int i, size, cell_log;
-
-       cell_log = rtnl_tc_calc_cell_log(cell);
-       if (cell_log < 0)
-               return cell_log;
+       uint32_t mtu = rtnl_tc_get_mtu(tc);
+       uint32_t linktype = rtnl_tc_get_linktype(tc);
+       uint8_t cell_log = spec->rs_cell_log;
+       unsigned int size, i;
+
+       spec->rs_mpu = rtnl_tc_get_mpu(tc);
+       spec->rs_overhead = rtnl_tc_get_overhead(tc);
+
+       if (mtu == 0)
+               mtu = 2047;
+
+       if (cell_log == UINT8_MAX) {
+               /*
+                * cell_log not specified, calculate it. It has to specify the
+                * minimum number of rshifts required to break the MTU to below
+                * RTNL_TC_RTABLE_SIZE.
+                */
+               cell_log = 0;
+               while ((mtu >> cell_log) >= RTNL_TC_RTABLE_SIZE)
+                       cell_log++;
+       }
 
        for (i = 0; i < RTNL_TC_RTABLE_SIZE; i++) {
-               size = (i << cell_log);
-               if (size < mpu)
-                       size = mpu;
-
-               dst[i] = rtnl_tc_calc_txtime(size, rate);
+               size = adjust_size((i + 1) << cell_log, spec->rs_mpu, linktype);
+               dst[i] = rtnl_tc_calc_txtime(size, spec->rs_rate);
        }
 
+       spec->rs_cell_align = -1;
+       spec->rs_cell_log = cell_log;
+
        return 0;
 }
 
index 1ed59127f441c00c5fc5fdd4a377bbabe2bb77d9..e806633ea0152ed101109e1c5bd87c9a46070f65 100644 (file)
@@ -34,6 +34,6 @@ libnl_cli_la_LIBADD  = ${top_builddir}/lib/libnl.la \
                       ${top_builddir}/lib/libnl-genl.la
 
 libnl_cli_la_SOURCES = \
-       utils.c addr.c ct.c link.c neigh.c qdisc.c class.c rule.c route.c
+       utils.c addr.c ct.c link.c neigh.c tc.c qdisc.c class.c rule.c route.c
 #      cls/ematch_syntax.c cls/ematch_grammar.c cls/ematch.c
 #      cls/pktloc_syntax.c cls/pktloc_grammar.c cls/utils.c
index 4f6ba30dadfe9e0c5e71d3b936a5d95be49b3027..c6b5525c24dcb065f29dcf35a0aa41b27d7cdbb7 100644 (file)
@@ -43,40 +43,6 @@ struct nl_cache *nl_cli_class_alloc_cache(struct nl_sock *sock, int ifindex)
        return cache;
 }
 
-void nl_cli_class_parse_dev(struct rtnl_class *class, struct nl_cache *link_cache, char *arg)
-{
-       int ival;
-
-       if (!(ival = rtnl_link_name2i(link_cache, arg)))
-               nl_cli_fatal(ENOENT, "Link \"%s\" does not exist", arg);
-
-       rtnl_class_set_ifindex(class, ival);
-}
-
-void nl_cli_class_parse_parent(struct rtnl_class *class, char *arg)
-{
-       uint32_t parent;
-       int err;
-
-       if ((err = rtnl_tc_str2handle(arg, &parent)) < 0)
-               nl_cli_fatal(err, "Unable to parse handle \"%s\": %s",
-                     arg, nl_geterror(err));
-
-       rtnl_class_set_parent(class, parent);
-}
-
-void nl_cli_class_parse_handle(struct rtnl_class *class, char *arg)
-{
-       uint32_t handle;
-       int err;
-
-       if ((err = rtnl_tc_str2handle(arg, &handle)) < 0)
-               nl_cli_fatal(err, "Unable to parse classid \"%s\": %s",
-                     arg, nl_geterror(err));
-
-       rtnl_class_set_handle(class, handle);
-}
-
 void nl_cli_class_parse_kind(struct rtnl_class *class, char *arg)
 {
        rtnl_class_set_kind(class, arg);
index 8b16f3f24f93402e8e168ff618852dac078dcbf1..4c64e7b3b985cdea5415830b5161cad9ebccd62d 100644 (file)
@@ -31,40 +31,6 @@ struct rtnl_qdisc *nl_cli_qdisc_alloc(void)
        return qdisc;
 }
 
-void nl_cli_qdisc_parse_dev(struct rtnl_qdisc *qdisc, struct nl_cache *link_cache, char *arg)
-{
-       int ival;
-
-       if (!(ival = rtnl_link_name2i(link_cache, arg)))
-               nl_cli_fatal(ENOENT, "Link \"%s\" does not exist", arg);
-
-       rtnl_qdisc_set_ifindex(qdisc, ival);
-}
-
-void nl_cli_qdisc_parse_parent(struct rtnl_qdisc *qdisc, char *arg)
-{
-       uint32_t parent;
-       int err;
-
-       if ((err = rtnl_tc_str2handle(arg, &parent)) < 0)
-               nl_cli_fatal(err, "Unable to parse handle \"%s\": %s",
-                     arg, nl_geterror(err));
-
-       rtnl_qdisc_set_parent(qdisc, parent);
-}
-
-void nl_cli_qdisc_parse_handle(struct rtnl_qdisc *qdisc, char *arg)
-{
-       uint32_t handle;
-       int err;
-
-       if ((err = rtnl_tc_str2handle(arg, &handle)) < 0)
-               nl_cli_fatal(err, "Unable to parse handle \"%s\": %s",
-                     arg, nl_geterror(err));
-
-       rtnl_qdisc_set_handle(qdisc, handle);
-}
-
 void nl_cli_qdisc_parse_kind(struct rtnl_qdisc *qdisc, char *arg)
 {
        rtnl_qdisc_set_kind(qdisc, arg);
diff --git a/src/lib/tc.c b/src/lib/tc.c
new file mode 100644 (file)
index 0000000..5f39498
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * src/lib/tc.c     CLI Traffic Control Helpers
+ *
+ *     This library is free software; you can redistribute it and/or
+ *     modify it under the terms of the GNU Lesser General Public
+ *     License as published by the Free Software Foundation version 2.1
+ *     of the License.
+ *
+ * Copyright (c) 2010 Thomas Graf <tgraf@suug.ch>
+ */
+
+#include <netlink/cli/utils.h>
+#include <netlink/cli/tc.h>
+#include <netlink/route/tc.h>
+
+/**
+ * @ingroup cli
+ * @defgroup cli_tc Queueing Disciplines
+ * @{
+ */
+void nl_cli_tc_parse_dev(struct rtnl_tc *tc, struct nl_cache *link_cache, char *name)
+{
+       struct rtnl_link *link;
+       
+       link = rtnl_link_get_by_name(link_cache, name);
+       if (!link)
+               nl_cli_fatal(ENOENT, "Link \"%s\" does not exist.", name);
+
+       rtnl_tc_set_link(tc, link);
+       rtnl_link_put(link);
+}
+
+void nl_cli_tc_parse_parent(struct rtnl_tc *tc, char *arg)
+{
+       uint32_t parent;
+       int err;
+
+       if ((err = rtnl_tc_str2handle(arg, &parent)) < 0)
+               nl_cli_fatal(err, "Unable to parse handle \"%s\": %s",
+                     arg, nl_geterror(err));
+
+       rtnl_tc_set_parent(tc, parent);
+}
+
+void nl_cli_tc_parse_handle(struct rtnl_tc *tc, char *arg)
+{
+       uint32_t handle;
+       int err;
+
+       if ((err = rtnl_tc_str2handle(arg, &handle)) < 0)
+               nl_cli_fatal(err, "Unable to parse handle \"%s\": %s",
+                     arg, nl_geterror(err));
+
+       rtnl_tc_set_handle(tc, handle);
+}
+
+void nl_cli_tc_parse_mtu(struct rtnl_tc *tc, char *arg)
+{
+       rtnl_tc_set_mtu(tc, nl_cli_parse_u32(arg));
+}
+
+void nl_cli_tc_parse_mpu(struct rtnl_tc *tc, char *arg)
+{
+       rtnl_tc_set_mpu(tc, nl_cli_parse_u32(arg));
+}
+
+void nl_cli_tc_parse_overhead(struct rtnl_tc *tc, char *arg)
+{
+       rtnl_tc_set_overhead(tc, nl_cli_parse_u32(arg));
+}
+
+void nl_cli_tc_parse_linktype(struct rtnl_tc *tc, char *arg)
+{
+       int type;
+
+       if ((type = nl_str2llproto(arg)) < 0)
+               nl_cli_fatal(type, "Unable to parse linktype \"%s\": %s",
+                       arg, nl_geterror(type));
+
+       rtnl_tc_set_linktype(tc, type);
+}
+
+/** @} */
index 6e1c4020e2b90c50bd4306e66a2dd9d89213da0f..553dec110816715ec332fd4d89f5a6b028ad69c3 100644 (file)
@@ -10,6 +10,7 @@
  */
 
 #include <netlink/cli/utils.h>
+#include <netlink/cli/tc.h>
 #include <netlink/cli/qdisc.h>
 #include <netlink/cli/class.h>
 #include <netlink/cli/link.h>
@@ -28,8 +29,12 @@ static void print_usage(void)
 "     --update              Update class if it exists.\n"
 "     --update-only         Only update class, never create it.\n"
 " -d, --dev=DEV             Network device the class should be attached to.\n"
-" -i, --id=ID               ID of new class (default: auto-generated)r\n"
+" -i, --id=ID               ID of new class (default: auto-generated)\n"
 " -p, --parent=ID           ID of parent { root | ingress | class-ID }\n"
+"     --mtu=SIZE            Overwrite MTU (default: MTU of network device)\n"
+"     --mpu=SIZE            Minimum packet size on the link (default: 0).\n"
+"     --overhead=SIZE       Overhead in bytes per packet (default: 0).\n"
+"     --linktype=TYPE       Overwrite linktype (default: type of network device)\n"
 "\n"
 "CONFIGURATION\n"
 " -h, --help                Show help text of class specific options.\n"
@@ -45,6 +50,7 @@ int main(int argc, char *argv[])
 {
        struct nl_sock *sock;
        struct rtnl_class *class;
+       struct rtnl_tc *tc;
        struct nl_cache *link_cache;
        struct nl_dump_params dp = {
                .dp_type = NL_DUMP_DETAILS,
@@ -61,12 +67,17 @@ int main(int argc, char *argv[])
        link_cache = nl_cli_link_alloc_cache(sock);
 
        class = nl_cli_class_alloc();
+       tc = (struct rtnl_tc *) class;
  
        for (;;) {
                int c, optidx = 0;
                enum {
                        ARG_UPDATE = 257,
                        ARG_UPDATE_ONLY = 258,
+                       ARG_MTU,
+                       ARG_MPU,
+                       ARG_OVERHEAD,
+                       ARG_LINKTYPE,
                };
                static struct option long_opts[] = {
                        { "quiet", 0, 0, 'q' },
@@ -77,6 +88,10 @@ int main(int argc, char *argv[])
                        { "id", 1, 0, 'i' },
                        { "update", 0, 0, ARG_UPDATE },
                        { "update-only", 0, 0, ARG_UPDATE_ONLY },
+                       { "mtu", 1, 0, ARG_MTU },
+                       { "mpu", 1, 0, ARG_MPU },
+                       { "overhead", 1, 0, ARG_OVERHEAD },
+                       { "linktype", 1, 0, ARG_LINKTYPE },
                        { 0, 0, 0, 0 }
                };
        
@@ -89,21 +104,25 @@ int main(int argc, char *argv[])
                case 'q': quiet = 1; break;
                case 'h': print_usage(); break;
                case 'v': nl_cli_print_version(); break;
-               case 'd': nl_cli_class_parse_dev(class, link_cache, optarg); break;
-               case 'p': nl_cli_class_parse_parent(class, optarg); break;
-               case 'i': nl_cli_class_parse_handle(class, optarg); break;
+               case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg); break;
+               case 'p': nl_cli_tc_parse_parent(tc, optarg); break;
+               case 'i': nl_cli_tc_parse_handle(tc, optarg); break;
                case ARG_UPDATE: flags = NLM_F_CREATE; break;
                case ARG_UPDATE_ONLY: flags = 0; break;
+               case ARG_MTU: nl_cli_tc_parse_mtu(tc, optarg); break;
+               case ARG_MPU: nl_cli_tc_parse_mpu(tc, optarg); break;
+               case ARG_OVERHEAD: nl_cli_tc_parse_overhead(tc, optarg); break;
+               case ARG_LINKTYPE: nl_cli_tc_parse_linktype(tc, optarg); break;
                }
        }
 
        if (optind >= argc)
                print_usage();
 
-       if (!rtnl_class_get_ifindex(class))
+       if (!rtnl_tc_get_ifindex(tc))
                nl_cli_fatal(EINVAL, "You must specify a network device (--dev=XXX)");
 
-       if (!rtnl_class_get_parent(class))
+       if (!rtnl_tc_get_parent(tc))
                nl_cli_fatal(EINVAL, "You must specify a parent (--parent=XXX)");
 
        kind = argv[optind++];
index 94b11d08fff4f140c401080612e845214a104eb9..94a6ab4b7e6d25a262d991cce19549425be3cf2b 100644 (file)
@@ -68,12 +68,14 @@ static void delete_cb(struct nl_object *obj, void *arg)
 int main(int argc, char *argv[])
 {
        struct rtnl_class *class;
+       struct rtnl_tc *tc;
        struct nl_cache *link_cache, *class_cache;
  
        sock = nl_cli_alloc_socket();
        nl_cli_connect(sock, NETLINK_ROUTE);
        link_cache = nl_cli_link_alloc_cache(sock);
        class = nl_cli_class_alloc();
+       tc = (struct rtnl_tc *) class;
  
        for (;;) {
                int c, optidx = 0;
@@ -105,25 +107,17 @@ int main(int argc, char *argv[])
                case 'q': quiet = 1; break;
                case 'h': print_usage(); break;
                case 'v': nl_cli_print_version(); break;
-               case 'd':
-                       nl_cli_class_parse_dev(class, link_cache, optarg);
-                       break;
-               case 'p':
-                       nl_cli_class_parse_parent(class, optarg);
-                       break;
-               case 'i':
-                       nl_cli_class_parse_handle(class, optarg);
-                       break;
-               case 'k':
-                       nl_cli_class_parse_kind(class, optarg);
-                       break;
+               case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg); break;
+               case 'p': nl_cli_tc_parse_parent(tc, optarg); break;
+               case 'i': nl_cli_tc_parse_handle(tc, optarg); break;
+               case 'k': nl_cli_class_parse_kind(class, optarg); break;
                }
        }
 
-       if (!rtnl_class_get_ifindex(class))
+       if (!rtnl_tc_get_ifindex(tc))
                nl_cli_fatal(EINVAL, "You must specify a network device (--dev=XXX)");
 
-       class_cache = nl_cli_class_alloc_cache(sock, rtnl_class_get_ifindex(class));
+       class_cache = nl_cli_class_alloc_cache(sock, rtnl_tc_get_ifindex(tc));
 
        nl_cache_foreach_filter(class_cache, OBJ_CAST(class), delete_cb, NULL);
 
index 7c0edff49a5520a21c4f433aeb3d082534f4ea21..3a3855522e6f3ffcaa3b3ebe09ab8fc8825fd7bd 100644 (file)
@@ -10,6 +10,7 @@
  */
 
 #include <netlink/cli/utils.h>
+#include <netlink/cli/tc.h>
 #include <netlink/cli/class.h>
 #include <netlink/cli/link.h>
 
@@ -61,6 +62,7 @@ static void dump_class(struct nl_object *obj, void *arg)
 int main(int argc, char *argv[])
 {
        struct rtnl_class *class;
+       struct rtnl_tc *tc;
        struct nl_cache *link_cache;
        int ifindex;
  
@@ -68,6 +70,7 @@ int main(int argc, char *argv[])
        nl_cli_connect(sock, NETLINK_ROUTE);
        link_cache = nl_cli_link_alloc_cache(sock);
        class = nl_cli_class_alloc();
+       tc = (struct rtnl_tc *) class;
 
        params.dp_fd = stdout;
  
@@ -98,14 +101,14 @@ int main(int argc, char *argv[])
                case ARG_STATS: params.dp_type = NL_DUMP_STATS; break;
                case 'h': print_usage(); break;
                case 'v': nl_cli_print_version(); break;
-               case 'd': nl_cli_class_parse_dev(class, link_cache, optarg); break;
-               case 'p': nl_cli_class_parse_parent(class, optarg); break;
-               case 'i': nl_cli_class_parse_handle(class, optarg); break;
+               case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg); break;
+               case 'p': nl_cli_tc_parse_parent(tc, optarg); break;
+               case 'i': nl_cli_tc_parse_handle(tc, optarg); break;
                case 'k': nl_cli_class_parse_kind(class, optarg); break;
                }
        }
 
-       if ((ifindex = rtnl_class_get_ifindex(class)))
+       if ((ifindex = rtnl_tc_get_ifindex(tc)))
                __dump_class(ifindex, class);
         else
                nl_cache_foreach(link_cache, dump_class, class);
index 739a6edd3e81cf7db117f3e246417f5a87ee4104..57603b05b275f1f00eba731f726060ae44198c91 100644 (file)
@@ -10,6 +10,7 @@
  */
 
 #include <netlink/cli/utils.h>
+#include <netlink/cli/tc.h>
 #include <netlink/cli/qdisc.h>
 #include <netlink/cli/link.h>
 
@@ -46,6 +47,7 @@ int main(int argc, char *argv[])
 {
        struct nl_sock *sock;
        struct rtnl_qdisc *qdisc;
+       struct rtnl_tc *tc;
        struct nl_cache *link_cache;
        struct nl_dump_params dp = {
                .dp_type = NL_DUMP_DETAILS,
@@ -62,6 +64,7 @@ int main(int argc, char *argv[])
        link_cache = nl_cli_link_alloc_cache(sock);
 
        qdisc = nl_cli_qdisc_alloc();
+       tc = (struct rtnl_tc *) qdisc;
  
        for (;;) {
                int c, optidx = 0;
@@ -94,9 +97,9 @@ int main(int argc, char *argv[])
                case 'q': quiet = 1; break;
                case 'h': print_usage(); break;
                case 'v': nl_cli_print_version(); break;
-               case 'd': nl_cli_qdisc_parse_dev(qdisc, link_cache, optarg); break;
-               case 'p': nl_cli_qdisc_parse_parent(qdisc, optarg); break;
-               case 'i': nl_cli_qdisc_parse_handle(qdisc, optarg); break;
+               case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg); break;
+               case 'p': nl_cli_tc_parse_parent(tc, optarg); break;
+               case 'i': nl_cli_tc_parse_handle(tc, optarg); break;
                case ARG_UPDATE: flags = NLM_F_CREATE; break;
                case ARG_REPLACE: flags = NLM_F_CREATE | NLM_F_REPLACE; break;
                case ARG_UPDATE_ONLY: flags = 0; break;
@@ -107,10 +110,10 @@ int main(int argc, char *argv[])
        if (optind >= argc)
                print_usage();
 
-       if (!rtnl_qdisc_get_ifindex(qdisc))
+       if (!rtnl_tc_get_ifindex(tc))
                nl_cli_fatal(EINVAL, "You must specify a network device (--dev=XXX)");
 
-       if (!rtnl_qdisc_get_parent(qdisc))
+       if (!rtnl_tc_get_parent(tc))
                nl_cli_fatal(EINVAL, "You must specify a parent");
 
        kind = argv[optind++];
index 24424a7013a0b45b76a13d8cdd20f1d603b38dfb..e91b054bb2f1c6e6c68a2168bf87270f5a993889 100644 (file)
@@ -10,6 +10,7 @@
  */
 
 #include <netlink/cli/utils.h>
+#include <netlink/cli/tc.h>
 #include <netlink/cli/qdisc.h>
 #include <netlink/cli/link.h>
 
@@ -63,6 +64,7 @@ static void delete_cb(struct nl_object *obj, void *arg)
 int main(int argc, char *argv[])
 {
        struct rtnl_qdisc *qdisc;
+       struct rtnl_tc *tc;
        struct nl_cache *link_cache, *qdisc_cache;
        int nfilter = 0;
  
@@ -71,6 +73,7 @@ int main(int argc, char *argv[])
        link_cache = nl_cli_link_alloc_cache(sock);
        qdisc_cache = nl_cli_qdisc_alloc_cache(sock);
        qdisc = nl_cli_qdisc_alloc();
+       tc = (struct rtnl_tc *) qdisc;
  
        for (;;) {
                int c, optidx = 0;
@@ -104,15 +107,15 @@ int main(int argc, char *argv[])
                case 'v': nl_cli_print_version(); break;
                case 'd':
                        nfilter++;
-                       nl_cli_qdisc_parse_dev(qdisc, link_cache, optarg);
+                       nl_cli_tc_parse_dev(tc, link_cache, optarg);
                        break;
                case 'p':
                        nfilter++;
-                       nl_cli_qdisc_parse_parent(qdisc, optarg);
+                       nl_cli_tc_parse_parent(tc, optarg);
                        break;
                case 'i':
                        nfilter++;
-                       nl_cli_qdisc_parse_handle(qdisc, optarg);
+                       nl_cli_tc_parse_handle(tc, optarg);
                        break;
                case 'k':
                        nfilter++;
index daea5d2b31f32da13048da7891602febc7c0fa2a..1ecb9a4736184a671310dd5b7c0a90f68d4ffc9b 100644 (file)
@@ -10,6 +10,7 @@
  */
 
 #include <netlink/cli/utils.h>
+#include <netlink/cli/tc.h>
 #include <netlink/cli/qdisc.h>
 #include <netlink/cli/link.h>
 
@@ -41,6 +42,7 @@ int main(int argc, char *argv[])
 {
        struct nl_sock *sock;
        struct rtnl_qdisc *qdisc;
+       struct rtnl_tc *tc;
        struct nl_cache *link_cache, *qdisc_cache;
        struct nl_dump_params params = {
                .dp_type = NL_DUMP_LINE,
@@ -52,6 +54,7 @@ int main(int argc, char *argv[])
        link_cache = nl_cli_link_alloc_cache(sock);
        qdisc_cache = nl_cli_qdisc_alloc_cache(sock);
        qdisc = nl_cli_qdisc_alloc();
+       tc = (struct rtnl_tc *) qdisc;
  
        for (;;) {
                int c, optidx = 0;
@@ -80,9 +83,9 @@ int main(int argc, char *argv[])
                case ARG_STATS: params.dp_type = NL_DUMP_STATS; break;
                case 'h': print_usage(); break;
                case 'v': nl_cli_print_version(); break;
-               case 'd': nl_cli_qdisc_parse_dev(qdisc, link_cache, optarg); break;
-               case 'p': nl_cli_qdisc_parse_parent(qdisc, optarg); break;
-               case 'i': nl_cli_qdisc_parse_handle(qdisc, optarg); break;
+               case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg); break;
+               case 'p': nl_cli_tc_parse_parent(tc, optarg); break;
+               case 'i': nl_cli_tc_parse_handle(tc, optarg); break;
                case 'k': nl_cli_qdisc_parse_kind(qdisc, optarg); break;
                }
        }
index a074a512d6cd8dbbcf34fb6c5226883cd3b04f21..4cd503568c3697a7d9d1f3a8b64d83995bcd19e7 100644 (file)
@@ -41,7 +41,7 @@ static void print_class(struct nl_object *obj, void *arg)
        struct rtnl_qdisc *leaf;
        struct rtnl_class *class = (struct rtnl_class *) obj;
        struct nl_cache *cls_cache;
-       uint32_t parent = rtnl_class_get_handle(class);
+       uint32_t parent = rtnl_tc_get_handle((struct rtnl_tc *) class);
 
        params.dp_prefix = (int)(long) arg;
        nl_object_dump(obj, &params);
@@ -64,7 +64,7 @@ static void print_qdisc(struct nl_object *obj, void *arg)
 {
        struct rtnl_qdisc *qdisc = (struct rtnl_qdisc *) obj;
        struct nl_cache *cls_cache;
-       uint32_t parent = rtnl_qdisc_get_handle(qdisc);
+       uint32_t parent = rtnl_tc_get_handle((struct rtnl_tc *) qdisc);
 
        params.dp_prefix = (int)(long) arg;
        nl_object_dump(obj, &params);