6#include <netlink-private/netlink.h>
7#include <netlink-private/tc.h>
8#include <netlink/netlink.h>
9#include <netlink/utils.h>
10#include <netlink-private/route/tc-api.h>
11#include <netlink/route/qdisc.h>
12#include <netlink/route/class.h>
13#include <netlink/route/link.h>
14#include <netlink/route/qdisc/cbq.h>
15#include <netlink/route/cls/police.h>
24static const struct trans_tbl ovl_strategies[] = {
25 __ADD(TC_CBQ_OVL_CLASSIC,classic),
26 __ADD(TC_CBQ_OVL_DELAY,delay),
27 __ADD(TC_CBQ_OVL_LOWPRIO,lowprio),
28 __ADD(TC_CBQ_OVL_DROP,drop),
29 __ADD(TC_CBQ_OVL_RCLASSIC,rclassic),
44 return __type2str(type, buf, len, ovl_strategies,
45 ARRAY_SIZE(ovl_strategies));
57 return __str2type(name, ovl_strategies, ARRAY_SIZE(ovl_strategies));
60static struct nla_policy cbq_policy[TCA_CBQ_MAX+1] = {
61 [TCA_CBQ_LSSOPT] = { .
minlen =
sizeof(
struct tc_cbq_lssopt) },
62 [TCA_CBQ_RATE] = { .minlen =
sizeof(
struct tc_ratespec) },
63 [TCA_CBQ_WRROPT] = { .minlen =
sizeof(
struct tc_cbq_wrropt) },
64 [TCA_CBQ_OVL_STRATEGY] = { .minlen =
sizeof(
struct tc_cbq_ovl) },
65 [TCA_CBQ_FOPT] = { .minlen =
sizeof(
struct tc_cbq_fopt) },
66 [TCA_CBQ_POLICE] = { .minlen =
sizeof(
struct tc_cbq_police) },
69static int cbq_msg_parser(
struct rtnl_tc *tc,
void *data)
71 struct nlattr *tb[TCA_CBQ_MAX + 1];
72 struct rtnl_cbq *cbq = data;
75 err = tca_parse(tb, TCA_CBQ_MAX, tc, cbq_policy);
79 nla_memcpy(&cbq->cbq_lss, tb[TCA_CBQ_LSSOPT],
sizeof(cbq->cbq_lss));
80 nla_memcpy(&cbq->cbq_rate, tb[TCA_CBQ_RATE],
sizeof(cbq->cbq_rate));
81 nla_memcpy(&cbq->cbq_wrr, tb[TCA_CBQ_WRROPT],
sizeof(cbq->cbq_wrr));
82 nla_memcpy(&cbq->cbq_fopt, tb[TCA_CBQ_FOPT],
sizeof(cbq->cbq_fopt));
83 nla_memcpy(&cbq->cbq_ovl, tb[TCA_CBQ_OVL_STRATEGY],
84 sizeof(cbq->cbq_ovl));
85 nla_memcpy(&cbq->cbq_police, tb[TCA_CBQ_POLICE],
86 sizeof(cbq->cbq_police));
91static void cbq_dump_line(
struct rtnl_tc *tc,
void *data,
94 struct rtnl_cbq *cbq = data;
104 nl_dump(p,
" rate %.2f%s/s (%.0f%s) prio %u",
105 r, ru, rbit, rubit, cbq->cbq_wrr.priority);
108static void cbq_dump_details(
struct rtnl_tc *tc,
void *data,
111 struct rtnl_cbq *cbq = data;
121 nl_dump(p,
"avgpkt %u mpu %u cell %u allot %u weight %.0f%s\n",
124 1 << cbq->cbq_rate.cell_log,
125 cbq->cbq_wrr.allot, w, unit);
127 el = cbq->cbq_lss.ewma_log;
128 nl_dump_line(p,
" minidle %uus maxidle %uus offtime "
129 "%uus level %u ewma_log %u\n",
134 cbq->cbq_lss.ewma_log);
136 nl_dump_line(p,
" penalty %uus strategy %s ",
140 nl_dump(p,
"split %s defmap 0x%08x ",
142 cbq->cbq_fopt.defmap);
145 nl_police2str(cbq->cbq_police.police, buf,
sizeof(buf)));
148static void cbq_dump_stats(
struct rtnl_tc *tc,
void *data,
151 struct tc_cbq_xstats *x;
153 if (!(x = tca_xstats(tc)))
156 nl_dump_line(p,
" borrows overact "
157 " avgidle undertime\n");
158 nl_dump_line(p,
" %10u %10u %10u %10u\n",
159 x->borrows, x->overactions, x->avgidle, x->undertime);
162static struct rtnl_tc_ops cbq_qdisc_ops = {
164 .to_type = RTNL_TC_TYPE_QDISC,
165 .to_size =
sizeof(
struct rtnl_cbq),
166 .to_msg_parser = cbq_msg_parser,
174static struct rtnl_tc_ops cbq_class_ops = {
176 .to_type = RTNL_TC_TYPE_CLASS,
177 .to_size =
sizeof(
struct rtnl_cbq),
178 .to_msg_parser = cbq_msg_parser,
186static void __init cbq_init(
void)
192static void __exit cbq_exit(
void)
int nla_memcpy(void *dest, const struct nlattr *src, int count)
Copy attribute payload to another memory area.
char * rtnl_tc_handle2str(uint32_t handle, char *buf, size_t len)
Convert a traffic control handle to a character string (Reentrant).
int nl_str2ovl_strategy(const char *name)
Convert a string to a CBQ OVL strategy.
char * nl_ovl_strategy2str(int type, char *buf, size_t len)
Convert a CBQ OVL strategy to a character string.
int rtnl_tc_register(struct rtnl_tc_ops *ops)
Register a traffic control module.
void rtnl_tc_unregister(struct rtnl_tc_ops *ops)
Unregister a traffic control module.
double nl_cancel_down_bits(unsigned long long l, char **unit)
Cancel down a bit counter.
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
double nl_cancel_down_bytes(unsigned long long l, char **unit)
Cancel down a byte counter.
uint32_t nl_ticks2us(uint32_t ticks)
Convert ticks to micro seconds.
@ NL_DUMP_STATS
Dump all attributes including statistics.
@ NL_DUMP_LINE
Dump object briefly on one line.
@ NL_DUMP_DETAILS
Dump all attributes but no statistics.
Attribute validation policy.
uint16_t minlen
Minimal length of payload required.