20 #include <netlink-private/netlink.h> 21 #include <netlink-private/tc.h> 22 #include <netlink/netlink.h> 23 #include <netlink-private/route/tc-api.h> 24 #include <netlink/route/qdisc.h> 25 #include <netlink/route/qdisc/fq_codel.h> 26 #include <netlink/utils.h> 29 #define SCH_FQ_CODEL_ATTR_TARGET 0x1 30 #define SCH_FQ_CODEL_ATTR_LIMIT 0x2 31 #define SCH_FQ_CODEL_ATTR_INTERVAL 0x4 32 #define SCH_FQ_CODEL_ATTR_FLOWS 0x8 33 #define SCH_FQ_CODEL_ATTR_QUANTUM 0x10 34 #define SCH_FQ_CODEL_ATTR_ECN 0x20 37 static struct nla_policy fq_codel_policy[TCA_FQ_CODEL_MAX + 1] = {
39 [TCA_FQ_CODEL_LIMIT] = { .type =
NLA_U32 },
40 [TCA_FQ_CODEL_INTERVAL] = { .type =
NLA_U32 },
41 [TCA_FQ_CODEL_ECN] = { .type =
NLA_U32 },
42 [TCA_FQ_CODEL_FLOWS] = { .type =
NLA_U32 },
43 [TCA_FQ_CODEL_QUANTUM] = { .type =
NLA_U32 },
46 static int fq_codel_msg_parser(
struct rtnl_tc *tc,
void *data)
48 struct rtnl_fq_codel *fq_codel = data;
49 struct nlattr *tb[TCA_FQ_CODEL_MAX + 1];
52 err = tca_parse(tb, TCA_FQ_CODEL_MAX, tc, fq_codel_policy);
56 if (tb[TCA_FQ_CODEL_TARGET]) {
57 fq_codel->fq_target =
nla_get_u32(tb[TCA_FQ_CODEL_TARGET]);
58 fq_codel->fq_mask |= SCH_FQ_CODEL_ATTR_TARGET;
61 if (tb[TCA_FQ_CODEL_INTERVAL]) {
62 fq_codel->fq_interval =
nla_get_u32(tb[TCA_FQ_CODEL_INTERVAL]);
63 fq_codel->fq_mask |= SCH_FQ_CODEL_ATTR_INTERVAL;
66 if (tb[TCA_FQ_CODEL_LIMIT]) {
67 fq_codel->fq_limit =
nla_get_u32(tb[TCA_FQ_CODEL_LIMIT]);
68 fq_codel->fq_mask |= SCH_FQ_CODEL_ATTR_LIMIT;
71 if (tb[TCA_FQ_CODEL_QUANTUM]) {
72 fq_codel->fq_quantum =
nla_get_u32(tb[TCA_FQ_CODEL_QUANTUM]);
73 fq_codel->fq_mask |= SCH_FQ_CODEL_ATTR_QUANTUM;
76 if (tb[TCA_FQ_CODEL_FLOWS]) {
77 fq_codel->fq_flows =
nla_get_u32(tb[TCA_FQ_CODEL_FLOWS]);
78 fq_codel->fq_mask |= SCH_FQ_CODEL_ATTR_FLOWS;
81 if (tb[TCA_FQ_CODEL_ECN]) {
82 fq_codel->fq_ecn =
nla_get_u32(tb[TCA_FQ_CODEL_ECN]);
83 fq_codel->fq_mask |= SCH_FQ_CODEL_ATTR_ECN;
89 static void fq_codel_dump_line(
struct rtnl_tc *tc,
void *data,
92 struct rtnl_fq_codel *fq_codel = data;
97 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_LIMIT)
98 nl_dump(p,
" limit %u packets", fq_codel->fq_limit);
99 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_TARGET)
100 nl_dump(p,
" target %u", fq_codel->fq_target);
101 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_INTERVAL)
102 nl_dump(p,
" interval %u", fq_codel->fq_interval);
103 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_ECN)
104 nl_dump(p,
" ecn %u", fq_codel->fq_ecn);
105 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_FLOWS)
106 nl_dump(p,
" flows %u", fq_codel->fq_flows);
107 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_QUANTUM)
108 nl_dump(p,
" quantum %u", fq_codel->fq_quantum);
111 static int fq_codel_msg_fill(
struct rtnl_tc *tc,
void *data,
struct nl_msg *msg)
113 struct rtnl_fq_codel *fq_codel = data;
118 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_LIMIT)
119 NLA_PUT_U32(msg, TCA_FQ_CODEL_LIMIT, fq_codel->fq_limit);
120 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_INTERVAL)
121 NLA_PUT_U32(msg, TCA_FQ_CODEL_INTERVAL, fq_codel->fq_interval);
122 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_TARGET)
123 NLA_PUT_U32(msg, TCA_FQ_CODEL_TARGET, fq_codel->fq_target);
124 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_QUANTUM)
125 NLA_PUT_U32(msg, TCA_FQ_CODEL_QUANTUM, fq_codel->fq_quantum);
126 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_FLOWS)
127 NLA_PUT_U32(msg, TCA_FQ_CODEL_FLOWS, fq_codel->fq_flows);
128 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_ECN)
129 NLA_PUT_U32(msg, TCA_FQ_CODEL_ECN, fq_codel->fq_ecn);
150 struct rtnl_fq_codel *fq_codel;
155 fq_codel->fq_limit = limit;
156 fq_codel->fq_mask |= SCH_FQ_CODEL_ATTR_LIMIT;
168 struct rtnl_fq_codel *fq_codel;
173 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_LIMIT)
174 return fq_codel->fq_limit;
187 struct rtnl_fq_codel *fq_codel;
192 fq_codel->fq_target = target;
193 fq_codel->fq_mask |= SCH_FQ_CODEL_ATTR_TARGET;
205 struct rtnl_fq_codel *fq_codel;
208 fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_TARGET)
209 return fq_codel->fq_target;
222 struct rtnl_fq_codel *fq_codel;
227 fq_codel->fq_interval = interval;
228 fq_codel->fq_mask |= SCH_FQ_CODEL_ATTR_INTERVAL;
240 struct rtnl_fq_codel *fq_codel;
243 fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_INTERVAL)
244 return fq_codel->fq_interval;
257 struct rtnl_fq_codel *fq_codel;
262 fq_codel->fq_quantum = quantum;
263 fq_codel->fq_mask |= SCH_FQ_CODEL_ATTR_QUANTUM;
275 struct rtnl_fq_codel *fq_codel;
278 (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_QUANTUM))
279 return fq_codel->fq_quantum;
292 struct rtnl_fq_codel *fq_codel;
297 fq_codel->fq_flows = flows;
298 fq_codel->fq_mask |= SCH_FQ_CODEL_ATTR_FLOWS;
310 struct rtnl_fq_codel *fq_codel;
315 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_FLOWS)
316 return fq_codel->fq_flows;
328 struct rtnl_fq_codel *fq_codel;
333 fq_codel->fq_ecn = ecn;
334 fq_codel->fq_mask |= SCH_FQ_CODEL_ATTR_ECN;
346 struct rtnl_fq_codel *fq_codel;
351 if (fq_codel->fq_mask & SCH_FQ_CODEL_ATTR_ECN)
352 return fq_codel->fq_ecn;
358 static struct rtnl_tc_ops fq_codel_ops = {
359 .to_kind =
"fq_codel",
360 .to_type = RTNL_TC_TYPE_QDISC,
361 .to_size =
sizeof(
struct rtnl_fq_codel),
362 .to_msg_parser = fq_codel_msg_parser,
364 .to_msg_fill = fq_codel_msg_fill,
367 static void __init fq_codel_init(
void)
372 static void __exit fq_codel_exit(
void)
Dump object briefly on one line.
int rtnl_tc_register(struct rtnl_tc_ops *ops)
Register a traffic control module.
Attribute validation policy.
uint32_t rtnl_qdisc_fq_codel_get_interval(struct rtnl_qdisc *qdisc)
Get target of a fq_codel qdisc.
uint32_t nla_get_u32(const struct nlattr *nla)
Return payload of 32 bit integer attribute.
int rtnl_qdisc_fq_codel_set_target(struct rtnl_qdisc *qdisc, uint32_t target)
Set target of fq_codel qdisc.
int rtnl_qdisc_fq_codel_get_limit(struct rtnl_qdisc *qdisc)
Get limit of a fq_codel qdisc.
int rtnl_qdisc_fq_codel_set_flows(struct rtnl_qdisc *qdisc, int flows)
Set flows of fq_codel qdisc.
uint32_t rtnl_qdisc_fq_codel_get_quantum(struct rtnl_qdisc *qdisc)
Get quantum of a fq_codel qdisc.
void rtnl_tc_unregister(struct rtnl_tc_ops *ops)
Unregister a traffic control module.
int rtnl_qdisc_fq_codel_get_flows(struct rtnl_qdisc *qdisc)
Get flows of a fq_codel qdisc.
int rtnl_qdisc_fq_codel_set_quantum(struct rtnl_qdisc *qdisc, uint32_t quantum)
Set quantum of fq_codel qdisc.
#define TC_CAST(ptr)
Macro to cast qdisc/class/classifier to tc object.
#define NLA_PUT_U32(msg, attrtype, value)
Add 32 bit integer attribute to netlink message.
int rtnl_qdisc_fq_codel_set_interval(struct rtnl_qdisc *qdisc, uint32_t interval)
Set interval of fq_codel qdisc.
void * rtnl_tc_data(struct rtnl_tc *tc)
Return pointer to private data of traffic control object.
uint16_t type
Type of attribute or NLA_UNSPEC.
int rtnl_qdisc_fq_codel_set_ecn(struct rtnl_qdisc *qdisc, int ecn)
Set ecn of fq_codel qdisc.
int rtnl_qdisc_fq_codel_get_ecn(struct rtnl_qdisc *qdisc)
Get ecn of a fq_codel qdisc.
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
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_target(struct rtnl_qdisc *qdisc)
Get target of a fq_codel qdisc.