diff options
author | Thomas Graf <tgraf@suug.ch> | 2010-10-26 10:54:33 (GMT) |
---|---|---|
committer | Thomas Graf <tgraf@suug.ch> | 2010-10-26 10:54:33 (GMT) |
commit | 4c6d1c5dfb4f7e4a9392895f3da709b55c970e02 (patch) | |
tree | 9303851dcc87e2e3f9c25805ccf24f4a543fe23d | |
parent | b9d965b01b42103389b2a2c0cc3133293447a64d (diff) | |
download | libnl-4c6d1c5dfb4f7e4a9392895f3da709b55c970e02.zip libnl-4c6d1c5dfb4f7e4a9392895f3da709b55c970e02.tar.gz libnl-4c6d1c5dfb4f7e4a9392895f3da709b55c970e02.tar.bz2 |
Unified TC attributes interface
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, 714 insertions, 643 deletions
diff --git a/include/netlink-local.h b/include/netlink-local.h index b5fad32..e9310ea 100644 --- a/include/netlink-local.h +++ b/include/netlink-local.h @@ -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> diff --git a/include/netlink-tc.h b/include/netlink-tc.h index 71a20ff..9e4bce9 100644 --- a/include/netlink-tc.h +++ b/include/netlink-tc.h @@ -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_ @@ -18,46 +18,49 @@ 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; } diff --git a/include/netlink-types.h b/include/netlink-types.h index 4f9bb16..3abeff4 100644 --- a/include/netlink-types.h +++ b/include/netlink-types.h @@ -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; diff --git a/include/netlink/cli/class.h b/include/netlink/cli/class.h index e73cd46..0141c21 100644 --- a/include/netlink/cli/class.h +++ b/include/netlink/cli/class.h @@ -14,13 +14,11 @@ #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 diff --git a/include/netlink/cli/qdisc.h b/include/netlink/cli/qdisc.h index 537e1a9..00c7083 100644 --- a/include/netlink/cli/qdisc.h +++ b/include/netlink/cli/qdisc.h @@ -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 index 0000000..762cc69 --- /dev/null +++ b/include/netlink/cli/tc.h @@ -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 diff --git a/include/netlink/route/class.h b/include/netlink/route/class.h index 480095e..13a25d6 100644 --- a/include/netlink/route/class.h +++ b/include/netlink/route/class.h @@ -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 *, diff --git a/include/netlink/route/classifier.h b/include/netlink/route/classifier.h index d9c3d21..17c834b 100644 --- a/include/netlink/route/classifier.h +++ b/include/netlink/route/classifier.h @@ -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 *); diff --git a/include/netlink/route/qdisc.h b/include/netlink/route/qdisc.h index 5acd6e1..966eb44 100644 --- a/include/netlink/route/qdisc.h +++ b/include/netlink/route/qdisc.h @@ -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 *), diff --git a/include/netlink/route/sch/htb.h b/include/netlink/route/sch/htb.h index d44f039..c15923e 100644 --- a/include/netlink/route/sch/htb.h +++ b/include/netlink/route/sch/htb.h @@ -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 } diff --git a/include/netlink/route/sch/tbf.h b/include/netlink/route/sch/tbf.h index 8e0ea1e..bb0e3b1 100644 --- a/include/netlink/route/sch/tbf.h +++ b/include/netlink/route/sch/tbf.h @@ -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 *); diff --git a/include/netlink/route/tc.h b/include/netlink/route/tc.h index 1fdaf1c..b4e953e 100644 --- a/include/netlink/route/tc.h +++ b/include/netlink/route/tc.h @@ -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_ @@ -15,44 +15,54 @@ #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 *); diff --git a/lib/cli/qdisc/htb.c b/lib/cli/qdisc/htb.c index 6b913a8..febf429 100644 --- a/lib/cli/qdisc/htb.c +++ b/lib/cli/qdisc/htb.c @@ -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; diff --git a/lib/route/class.c b/lib/route/class.c index ddf2d2e..9717d20 100644 --- a/lib/route/class.c +++ b/lib/route/class.c @@ -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; diff --git a/lib/route/class_obj.c b/lib/route/class_obj.c index 5c2e5be..097db25 100644 --- a/lib/route/class_obj.c +++ b/lib/route/class_obj.c @@ -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 = { diff --git a/lib/route/cls.c b/lib/route/cls.c index cbf0345..6d75e47 100644 --- a/lib/route/cls.c +++ b/lib/route/cls.c @@ -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; diff --git a/lib/route/cls/basic.c b/lib/route/cls/basic.c index 1460b72..f151807 100644 --- a/lib/route/cls/basic.c +++ b/lib/route/cls/basic.c @@ -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; diff --git a/lib/route/cls/cgroup.c b/lib/route/cls/cgroup.c index e5f38b8..36ff4d4 100644 --- a/lib/route/cls/cgroup.c +++ b/lib/route/cls/cgroup.c @@ -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; diff --git a/lib/route/cls/fw.c b/lib/route/cls/fw.c index 8cf25b9..b8055fe 100644 --- a/lib/route/cls/fw.c +++ b/lib/route/cls/fw.c @@ -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; diff --git a/lib/route/cls/u32.c b/lib/route/cls/u32.c index 80b8851..38214c9 100644 --- a/lib/route/cls/u32.c +++ b/lib/route/cls/u32.c @@ -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) diff --git a/lib/route/cls_obj.c b/lib/route/cls_obj.c index c8218c0..dcf97ed 100644 --- a/lib/route/cls_obj.c +++ b/lib/route/cls_obj.c @@ -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); diff --git a/lib/route/qdisc.c b/lib/route/qdisc.c index cfeaf05..2867e63 100644 --- a/lib/route/qdisc.c +++ b/lib/route/qdisc.c @@ -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; diff --git a/lib/route/qdisc_obj.c b/lib/route/qdisc_obj.c index dc52ae8..baa00b2 100644 --- a/lib/route/qdisc_obj.c +++ b/lib/route/qdisc_obj.c @@ -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); -} - /** @} */ /** diff --git a/lib/route/sch/cbq.c b/lib/route/sch/cbq.c index 1aaa58d..0df4aa0 100644 --- a/lib/route/sch/cbq.c +++ b/lib/route/sch/cbq.c @@ -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 = { diff --git a/lib/route/sch/dsmark.c b/lib/route/sch/dsmark.c index 61b0fea..a2e1628 100644 --- a/lib/route/sch/dsmark.c +++ b/lib/route/sch/dsmark.c @@ -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; diff --git a/lib/route/sch/htb.c b/lib/route/sch/htb.c index c1651e7..93ec28a 100644 --- a/lib/route/sch/htb.c +++ b/lib/route/sch/htb.c @@ -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 */ @@ -36,14 +36,11 @@ #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; @@ -374,24 +346,6 @@ void rtnl_htb_set_prio(struct rtnl_class *class, uint32_t 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. * @arg rate New rate in bytes per second. @@ -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 = { diff --git a/lib/route/sch/red.c b/lib/route/sch/red.c index e4cac79..727db17 100644 --- a/lib/route/sch/red.c +++ b/lib/route/sch/red.c @@ -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; diff --git a/lib/route/sch/tbf.c b/lib/route/sch/tbf.c index b749a36..c61810e 100644 --- a/lib/route/sch/tbf.c +++ b/lib/route/sch/tbf.c @@ -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; diff --git a/lib/route/tc.c b/lib/route/tc.c index 1860c6f..6a0233a 100644 --- a/lib/route/tc.c +++ b/lib/route/tc.c @@ -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; } diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 1ed5912..e806633 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -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 diff --git a/src/lib/class.c b/src/lib/class.c index 4f6ba30..c6b5525 100644 --- a/src/lib/class.c +++ b/src/lib/class.c @@ -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); diff --git a/src/lib/qdisc.c b/src/lib/qdisc.c index 8b16f3f..4c64e7b 100644 --- a/src/lib/qdisc.c +++ b/src/lib/qdisc.c @@ -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 index 0000000..5f39498 --- /dev/null +++ b/src/lib/tc.c @@ -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); +} + +/** @} */ diff --git a/src/nl-class-add.c b/src/nl-class-add.c index 6e1c402..553dec1 100644 --- a/src/nl-class-add.c +++ b/src/nl-class-add.c @@ -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++]; diff --git a/src/nl-class-delete.c b/src/nl-class-delete.c index 94b11d0..94a6ab4 100644 --- a/src/nl-class-delete.c +++ b/src/nl-class-delete.c @@ -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); diff --git a/src/nl-class-list.c b/src/nl-class-list.c index 7c0edff..3a38555 100644 --- a/src/nl-class-list.c +++ b/src/nl-class-list.c @@ -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); diff --git a/src/nl-qdisc-add.c b/src/nl-qdisc-add.c index 739a6ed..57603b0 100644 --- a/src/nl-qdisc-add.c +++ b/src/nl-qdisc-add.c @@ -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++]; diff --git a/src/nl-qdisc-delete.c b/src/nl-qdisc-delete.c index 24424a7..e91b054 100644 --- a/src/nl-qdisc-delete.c +++ b/src/nl-qdisc-delete.c @@ -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++; diff --git a/src/nl-qdisc-list.c b/src/nl-qdisc-list.c index daea5d2..1ecb9a4 100644 --- a/src/nl-qdisc-list.c +++ b/src/nl-qdisc-list.c @@ -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; } } diff --git a/src/nl-tctree-list.c b/src/nl-tctree-list.c index a074a51..4cd5035 100644 --- a/src/nl-tctree-list.c +++ b/src/nl-tctree-list.c @@ -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, ¶ms); @@ -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, ¶ms); |