14#include <netlink-private/netlink.h>
15#include <netlink-private/tc.h>
16#include <netlink/netlink.h>
17#include <netlink-private/route/tc-api.h>
18#include <netlink/route/qdisc.h>
19#include <netlink/route/qdisc/fq_codel.h>
20#include <netlink/utils.h>
23#define SCH_FQ_CODEL_ATTR_TARGET 0x1
24#define SCH_FQ_CODEL_ATTR_LIMIT 0x2
25#define SCH_FQ_CODEL_ATTR_INTERVAL 0x4
26#define SCH_FQ_CODEL_ATTR_FLOWS 0x8
27#define SCH_FQ_CODEL_ATTR_QUANTUM 0x10
28#define SCH_FQ_CODEL_ATTR_ECN 0x20
31static struct nla_policy fq_codel_policy[TCA_FQ_CODEL_MAX + 1] = {
33 [TCA_FQ_CODEL_LIMIT] = { .type =
NLA_U32 },
34 [TCA_FQ_CODEL_INTERVAL] = { .type =
NLA_U32 },
35 [TCA_FQ_CODEL_ECN] = { .type =
NLA_U32 },
36 [TCA_FQ_CODEL_FLOWS] = { .type =
NLA_U32 },
37 [TCA_FQ_CODEL_QUANTUM] = { .type =
NLA_U32 },
40static int fq_codel_msg_parser(
struct rtnl_tc *tc,
void *data)
42 struct rtnl_fq_codel *fq_codel = data;
43 struct nlattr *tb[TCA_FQ_CODEL_MAX + 1];
46 err = tca_parse(tb, TCA_FQ_CODEL_MAX, tc, fq_codel_policy);
50 if (tb[TCA_FQ_CODEL_TARGET]) {
51 fq_codel->fq_target =
nla_get_u32(tb[TCA_FQ_CODEL_TARGET]);
52 fq_codel->fq_mask |= SCH_FQ_CODEL_ATTR_TARGET;
55 if (tb[TCA_FQ_CODEL_INTERVAL]) {
56 fq_codel->fq_interval =
nla_get_u32(tb[TCA_FQ_CODEL_INTERVAL]);
57 fq_codel->fq_mask |= SCH_FQ_CODEL_ATTR_INTERVAL;
60 if (tb[TCA_FQ_CODEL_LIMIT]) {
61 fq_codel->fq_limit =
nla_get_u32(tb[TCA_FQ_CODEL_LIMIT]);
62 fq_codel->fq_mask |= SCH_FQ_CODEL_ATTR_LIMIT;
65 if (tb[TCA_FQ_CODEL_QUANTUM]) {
66 fq_codel->fq_quantum =
nla_get_u32(tb[TCA_FQ_CODEL_QUANTUM]);
67 fq_codel->fq_mask |= SCH_FQ_CODEL_ATTR_QUANTUM;
70 if (tb[TCA_FQ_CODEL_FLOWS]) {
71 fq_codel->fq_flows =
nla_get_u32(tb[TCA_FQ_CODEL_FLOWS]);
72 fq_codel->fq_mask |= SCH_FQ_CODEL_ATTR_FLOWS;
75 if (tb[TCA_FQ_CODEL_ECN]) {
76 fq_codel->fq_ecn =
nla_get_u32(tb[TCA_FQ_CODEL_ECN]);
77 fq_codel->fq_mask |= SCH_FQ_CODEL_ATTR_ECN;
83static void fq_codel_dump_line(
struct rtnl_tc *tc,
void *data,
86 struct rtnl_fq_codel *fq_codel = data;
91 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_LIMIT)
92 nl_dump(p,
" limit %u packets", fq_codel->fq_limit);
93 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_TARGET)
94 nl_dump(p,
" target %u", fq_codel->fq_target);
95 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_INTERVAL)
96 nl_dump(p,
" interval %u", fq_codel->fq_interval);
97 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_ECN)
98 nl_dump(p,
" ecn %u", fq_codel->fq_ecn);
99 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_FLOWS)
100 nl_dump(p,
" flows %u", fq_codel->fq_flows);
101 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_QUANTUM)
102 nl_dump(p,
" quantum %u", fq_codel->fq_quantum);
105static int fq_codel_msg_fill(
struct rtnl_tc *tc,
void *data,
struct nl_msg *msg)
107 struct rtnl_fq_codel *fq_codel = data;
112 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_LIMIT)
113 NLA_PUT_U32(msg, TCA_FQ_CODEL_LIMIT, fq_codel->fq_limit);
114 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_INTERVAL)
115 NLA_PUT_U32(msg, TCA_FQ_CODEL_INTERVAL, fq_codel->fq_interval);
116 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_TARGET)
117 NLA_PUT_U32(msg, TCA_FQ_CODEL_TARGET, fq_codel->fq_target);
118 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_QUANTUM)
119 NLA_PUT_U32(msg, TCA_FQ_CODEL_QUANTUM, fq_codel->fq_quantum);
120 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_FLOWS)
121 NLA_PUT_U32(msg, TCA_FQ_CODEL_FLOWS, fq_codel->fq_flows);
122 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_ECN)
123 NLA_PUT_U32(msg, TCA_FQ_CODEL_ECN, fq_codel->fq_ecn);
144 struct rtnl_fq_codel *fq_codel;
149 fq_codel->fq_limit = limit;
150 fq_codel->fq_mask |= SCH_FQ_CODEL_ATTR_LIMIT;
162 struct rtnl_fq_codel *fq_codel;
167 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_LIMIT)
168 return fq_codel->fq_limit;
181 struct rtnl_fq_codel *fq_codel;
186 fq_codel->fq_target = target;
187 fq_codel->fq_mask |= SCH_FQ_CODEL_ATTR_TARGET;
199 struct rtnl_fq_codel *fq_codel;
202 fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_TARGET)
203 return fq_codel->fq_target;
216 struct rtnl_fq_codel *fq_codel;
221 fq_codel->fq_interval = interval;
222 fq_codel->fq_mask |= SCH_FQ_CODEL_ATTR_INTERVAL;
234 struct rtnl_fq_codel *fq_codel;
237 fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_INTERVAL)
238 return fq_codel->fq_interval;
251 struct rtnl_fq_codel *fq_codel;
256 fq_codel->fq_quantum = quantum;
257 fq_codel->fq_mask |= SCH_FQ_CODEL_ATTR_QUANTUM;
269 struct rtnl_fq_codel *fq_codel;
272 (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_QUANTUM))
273 return fq_codel->fq_quantum;
286 struct rtnl_fq_codel *fq_codel;
291 fq_codel->fq_flows = flows;
292 fq_codel->fq_mask |= SCH_FQ_CODEL_ATTR_FLOWS;
304 struct rtnl_fq_codel *fq_codel;
309 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_FLOWS)
310 return fq_codel->fq_flows;
322 struct rtnl_fq_codel *fq_codel;
327 fq_codel->fq_ecn = ecn;
328 fq_codel->fq_mask |= SCH_FQ_CODEL_ATTR_ECN;
340 struct rtnl_fq_codel *fq_codel;
345 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_ECN)
346 return fq_codel->fq_ecn;
352static struct rtnl_tc_ops fq_codel_ops = {
353 .to_kind =
"fq_codel",
354 .to_type = RTNL_TC_TYPE_QDISC,
355 .to_size =
sizeof(
struct rtnl_fq_codel),
356 .to_msg_parser = fq_codel_msg_parser,
358 .to_msg_fill = fq_codel_msg_fill,
361static void __init fq_codel_init(
void)
366static void __exit fq_codel_exit(
void)
uint32_t nla_get_u32(const struct nlattr *nla)
Return payload of 32 bit integer attribute.
#define NLA_PUT_U32(msg, attrtype, value)
Add 32 bit integer attribute to netlink message.
int rtnl_qdisc_fq_codel_get_ecn(struct rtnl_qdisc *qdisc)
Get ecn of a fq_codel qdisc.
int rtnl_qdisc_fq_codel_get_flows(struct rtnl_qdisc *qdisc)
Get flows of a fq_codel qdisc.
int rtnl_qdisc_fq_codel_set_target(struct rtnl_qdisc *qdisc, uint32_t target)
Set target of fq_codel qdisc.
uint32_t rtnl_qdisc_fq_codel_get_target(struct rtnl_qdisc *qdisc)
Get target of a fq_codel qdisc.
int rtnl_qdisc_fq_codel_set_interval(struct rtnl_qdisc *qdisc, uint32_t interval)
Set interval of fq_codel qdisc.
int rtnl_qdisc_fq_codel_set_flows(struct rtnl_qdisc *qdisc, int flows)
Set flows of fq_codel qdisc.
int rtnl_qdisc_fq_codel_set_quantum(struct rtnl_qdisc *qdisc, uint32_t quantum)
Set quantum of fq_codel qdisc.
uint32_t rtnl_qdisc_fq_codel_get_quantum(struct rtnl_qdisc *qdisc)
Get quantum of a fq_codel qdisc.
int rtnl_qdisc_fq_codel_set_ecn(struct rtnl_qdisc *qdisc, int ecn)
Set ecn of fq_codel qdisc.
int rtnl_qdisc_fq_codel_set_limit(struct rtnl_qdisc *qdisc, int limit)
Set limit of fq_codel qdisc.
uint32_t rtnl_qdisc_fq_codel_get_interval(struct rtnl_qdisc *qdisc)
Get target of a fq_codel qdisc.
int rtnl_qdisc_fq_codel_get_limit(struct rtnl_qdisc *qdisc)
Get limit of a fq_codel qdisc.
#define TC_CAST(ptr)
Macro to cast qdisc/class/classifier to tc object.
void * rtnl_tc_data(struct rtnl_tc *tc)
Return pointer to private data of traffic control object.
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.
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
@ NL_DUMP_LINE
Dump object briefly on one line.
Attribute validation policy.
uint16_t type
Type of attribute or NLA_UNSPEC.