libnl: /data/src/libnl3/lib/route/qdisc/red.c Source File

libnl 3.10.0

red.c
1/* SPDX-License-Identifier: LGPL-2.1-only */
2/*
3 * Copyright (c) 2003-2011 Thomas Graf <tgraf@suug.ch>
4 */
5
6/**
7 * @ingroup qdisc
8 * @defgroup qdisc_red Random Early Detection (RED)
9 * @brief
10 * @{
11 */
12
13#include "nl-default.h"
14
15#include <netlink/netlink.h>
16#include <netlink/utils.h>
17#include <netlink/route/qdisc.h>
18#include <netlink/route/qdisc/red.h>
19
20#include "tc-api.h"
21
22/** @cond SKIP */
23struct rtnl_red {
24 uint32_t qr_limit;
25 uint32_t qr_qth_min;
26 uint32_t qr_qth_max;
27 uint8_t qr_flags;
28 uint8_t qr_wlog;
29 uint8_t qr_plog;
30 uint8_t qr_scell_log;
31 uint32_t qr_mask;
32};
33
34#define RED_ATTR_LIMIT 0x01
35#define RED_ATTR_QTH_MIN 0x02
36#define RED_ATTR_QTH_MAX 0x04
37#define RED_ATTR_FLAGS 0x08
38#define RED_ATTR_WLOG 0x10
39#define RED_ATTR_PLOG 0x20
40#define RED_ATTR_SCELL_LOG 0x40
41/** @endcond */
42
43static struct nla_policy red_policy[TCA_RED_MAX+1] = {
44 [TCA_RED_PARMS] = { .minlen = sizeof(struct tc_red_qopt) },
45};
46
47static int red_msg_parser(struct rtnl_tc *tc, void *data)
48{
49 struct nlattr *tb[TCA_RED_MAX+1];
50 struct rtnl_red *red = data;
51 struct tc_red_qopt *opts;
52 int err;
53
54 if (!(tc->ce_mask & TCA_ATTR_OPTS))
55 return 0;
56
57 err = tca_parse(tb, TCA_RED_MAX, tc, red_policy);
58 if (err < 0)
59 return err;
60
61 if (!tb[TCA_RED_PARMS])
62 return -NLE_MISSING_ATTR;
63
64 opts = nla_data(tb[TCA_RED_PARMS]);
65
66 red->qr_limit = opts->limit;
67 red->qr_qth_min = opts->qth_min;
68 red->qr_qth_max = opts->qth_max;
69 red->qr_flags = opts->flags;
70 red->qr_wlog = opts->Wlog;
71 red->qr_plog = opts->Plog;
72 red->qr_scell_log = opts->Scell_log;
73
74 red->qr_mask = (RED_ATTR_LIMIT | RED_ATTR_QTH_MIN | RED_ATTR_QTH_MAX |
75 RED_ATTR_FLAGS | RED_ATTR_WLOG | RED_ATTR_PLOG |
76 RED_ATTR_SCELL_LOG);
77
78 return 0;
79}
80
81static void red_dump_line(struct rtnl_tc *tc, void *data,
82 struct nl_dump_params *p)
83{
84 struct rtnl_red *red = data;
85
86 if (red) {
87 /* XXX: limit, min, max, flags */
88 }
89}
90
91static void red_dump_details(struct rtnl_tc *tc, void *data,
92 struct nl_dump_params *p)
93{
94 struct rtnl_red *red = data;
95
96 if (red) {
97 /* XXX: wlog, plog, scell_log */
98 }
99}
100
101static void red_dump_stats(struct rtnl_tc *tc, void *data,
102 struct nl_dump_params *p)
103{
104 struct rtnl_red *red = data;
105
106 if (red) {
107 /* XXX: xstats */
108 }
109}
110
111static int red_msg_fill(struct rtnl_tc *tc, void *data, struct nl_msg *msg)
112{
113 struct rtnl_red *red = data;
114
115 if (!red)
116 BUG();
117
118#if 0
119 memset(&opts, 0, sizeof(opts));
120 opts.quantum = sfq->qs_quantum;
121 opts.perturb_period = sfq->qs_perturb;
122 opts.limit = sfq->qs_limit;
123
124 if (nlmsg_append(msg, &opts, sizeof(opts), NL_DONTPAD) < 0)
125 goto errout;
126#endif
127
128 return -NLE_OPNOTSUPP;
129}
130
131/**
132 * @name Attribute Access
133 * @{
134 */
135
136/**
137 * Set limit of RED qdisc.
138 * @arg qdisc RED qdisc to be modified.
139 * @arg limit New limit in number of packets.
140 * @return 0 on success or a negative error code.
141 */
142 void rtnl_red_set_limit(struct rtnl_qdisc *qdisc, int limit)
143{
144 struct rtnl_red *red;
145
146 if (!(red = rtnl_tc_data(TC_CAST(qdisc))))
147 BUG();
148
149 red->qr_limit = limit;
150 red->qr_mask |= RED_ATTR_LIMIT;
151}
152
153/**
154 * Get limit of RED qdisc.
155 * @arg qdisc RED qdisc.
156 * @return Limit or a negative error code.
157 */
158 int rtnl_red_get_limit(struct rtnl_qdisc *qdisc)
159{
160 struct rtnl_red *red;
161
162 if (!(red = rtnl_tc_data(TC_CAST(qdisc))))
163 BUG();
164
165 if (red->qr_mask & RED_ATTR_LIMIT)
166 return red->qr_limit;
167 else
168 return -NLE_NOATTR;
169}
170
171/** @} */
172
173static struct rtnl_tc_ops red_ops = {
174 .to_kind = "red",
175 .to_type = RTNL_TC_TYPE_QDISC,
176 .to_size = sizeof(struct rtnl_red),
177 .to_msg_parser = red_msg_parser,
178 .to_dump = {
179 [NL_DUMP_LINE] = red_dump_line,
180 [NL_DUMP_DETAILS] = red_dump_details,
181 [NL_DUMP_STATS] = red_dump_stats,
182 },
183 .to_msg_fill = red_msg_fill,
184};
185
186static void _nl_init red_init(void)
187{
188 rtnl_tc_register(&red_ops);
189}
190
191static void _nl_exit red_exit(void)
192{
193 rtnl_tc_unregister(&red_ops);
194}
195
196/** @} */
nla_data
void * nla_data(const struct nlattr *nla)
Return pointer to the payload section.
Definition attr.c:119
nlmsg_append
int nlmsg_append(struct nl_msg *n, void *data, size_t len, int pad)
Append data to tail of a netlink message.
Definition msg.c:456
rtnl_red_set_limit
void rtnl_red_set_limit(struct rtnl_qdisc *qdisc, int limit)
Set limit of RED qdisc.
Definition red.c:142
rtnl_red_get_limit
int rtnl_red_get_limit(struct rtnl_qdisc *qdisc)
Get limit of RED qdisc.
Definition red.c:158
TC_CAST
#define TC_CAST(ptr)
Macro to cast qdisc/class/classifier to tc object.
Definition tc.h:50
rtnl_tc_data
void * rtnl_tc_data(struct rtnl_tc *)
Return pointer to private data of traffic control object.
Definition tc.c:1079
rtnl_tc_register
int rtnl_tc_register(struct rtnl_tc_ops *)
Register a traffic control module.
Definition tc.c:1018
rtnl_tc_unregister
void rtnl_tc_unregister(struct rtnl_tc_ops *)
Unregister a traffic control module.
Definition tc.c:1052
NL_DUMP_STATS
@ NL_DUMP_STATS
Dump all attributes including statistics.
Definition types.h:22
NL_DUMP_LINE
@ NL_DUMP_LINE
Dump object briefly on one line.
Definition types.h:20
NL_DUMP_DETAILS
@ NL_DUMP_DETAILS
Dump all attributes but no statistics.
Definition types.h:21
nl_dump_params
Dumping parameters.
Definition types.h:32
nla_policy
Attribute validation policy.
Definition attr.h:63
nla_policy::minlen
uint16_t minlen
Minimal length of payload required.
Definition attr.h:68
nla_policy::type
uint16_t type
Type of attribute or NLA_UNSPEC.
Definition attr.h:65
rtnl_qdisc
Definition nl-route.h:118
rtnl_tc
Definition nl-route.h:114