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