summaryrefslogtreecommitdiffstats
path: root/lib/route/qdisc/red.c
blob: 0480282a5f2d9e2028d946cde92f1f71072b6183 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
 * lib/route/qdisc/red.c		RED Qdisc
 *
 *	This library is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU Lesser General Public
 *	License as published by the Free Software Foundation version 2.1
 *	of the License.
 *
 * Copyright (c) 2003-2011 Thomas Graf <tgraf@suug.ch>
 */

/**
 * @ingroup qdisc
 * @defgroup qdisc_red Random Early Detection (RED)
 * @brief
 * @{
 */

#include <netlink-local.h>
#include <netlink-tc.h>
#include <netlink/netlink.h>
#include <netlink/utils.h>
#include <netlink/route/tc-api.h>
#include <netlink/route/qdisc.h>
#include <netlink/route/qdisc/red.h>

/** @cond SKIP */
#define RED_ATTR_LIMIT		0x01
#define RED_ATTR_QTH_MIN	0x02
#define RED_ATTR_QTH_MAX	0x04
#define RED_ATTR_FLAGS		0x08
#define RED_ATTR_WLOG		0x10
#define RED_ATTR_PLOG		0x20
#define RED_ATTR_SCELL_LOG	0x40
/** @endcond */

static struct nla_policy red_policy[TCA_RED_MAX+1] = {
	[TCA_RED_PARMS]		= { .minlen = sizeof(struct tc_red_qopt) },
};

static int red_msg_parser(struct rtnl_tc *tc, void *data)
{
	struct nlattr *tb[TCA_RED_MAX+1];
	struct rtnl_red *red = data;
	struct tc_red_qopt *opts;
	int err;

	if (!(tc->ce_mask & TCA_ATTR_OPTS))
		return 0;

	err = tca_parse(tb, TCA_RED_MAX, tc, red_policy);
	if (err < 0)
		return err;

	if (!tb[TCA_RED_PARMS])
		return -NLE_MISSING_ATTR;

	opts = nla_data(tb[TCA_RED_PARMS]);

	red->qr_limit = opts->limit;
	red->qr_qth_min = opts->qth_min;
	red->qr_qth_max = opts->qth_max;
	red->qr_flags = opts->flags;
	red->qr_wlog = opts->Wlog;
	red->qr_plog = opts->Plog;
	red->qr_scell_log = opts->Scell_log;

	red->qr_mask = (RED_ATTR_LIMIT | RED_ATTR_QTH_MIN | RED_ATTR_QTH_MAX |
			RED_ATTR_FLAGS | RED_ATTR_WLOG | RED_ATTR_PLOG |
			RED_ATTR_SCELL_LOG);

	return 0;
}

static void red_dump_line(struct rtnl_tc *tc, void *data,
			  struct nl_dump_params *p)
{
	struct rtnl_red *red = data;

	if (red) {
		/* XXX: limit, min, max, flags */
	}
}

static void red_dump_details(struct rtnl_tc *tc, void *data,
			     struct nl_dump_params *p)
{
	struct rtnl_red *red = data;

	if (red) {
		/* XXX: wlog, plog, scell_log */
	}
}

static void red_dump_stats(struct rtnl_tc *tc, void *data,
			   struct nl_dump_params *p)
{
	struct rtnl_red *red = data;

	if (red) {
		/* XXX: xstats */
	}
}

static int red_msg_fill(struct rtnl_tc *tc, void *data, struct nl_msg *msg)
{
	struct rtnl_red *red = data;

	if (!red)
		BUG();

#if 0
	memset(&opts, 0, sizeof(opts));
	opts.quantum = sfq->qs_quantum;
	opts.perturb_period = sfq->qs_perturb;
	opts.limit = sfq->qs_limit;

	if (nlmsg_append(msg, &opts, sizeof(opts), NL_DONTPAD) < 0)
		goto errout;
#endif

	return -NLE_OPNOTSUPP;
}

/**
 * @name Attribute Access
 * @{
 */

/**
 * Set limit of RED qdisc.
 * @arg qdisc		RED qdisc to be modified.
 * @arg limit		New limit in number of packets.
 * @return 0 on success or a negative error code.
 */
void rtnl_red_set_limit(struct rtnl_qdisc *qdisc, int limit)
{
	struct rtnl_red *red;

	if (!(red = rtnl_tc_data(TC_CAST(qdisc))))
		BUG();

	red->qr_limit = limit;
	red->qr_mask |= RED_ATTR_LIMIT;
}

/**
 * Get limit of RED qdisc.
 * @arg qdisc		RED qdisc.
 * @return Limit or a negative error code.
 */
int rtnl_red_get_limit(struct rtnl_qdisc *qdisc)
{
	struct rtnl_red *red;

	if (!(red = rtnl_tc_data(TC_CAST(qdisc))))
		BUG();

	if (red->qr_mask & RED_ATTR_LIMIT)
		return red->qr_limit;
	else
		return -NLE_NOATTR;
}

/** @} */

static struct rtnl_tc_ops red_ops = {
	.to_kind		= "red",
	.to_type		= RTNL_TC_TYPE_QDISC,
	.to_size		= sizeof(struct rtnl_red),
	.to_msg_parser		= red_msg_parser,
	.to_dump = {
	    [NL_DUMP_LINE]	= red_dump_line,
	    [NL_DUMP_DETAILS]	= red_dump_details,
	    [NL_DUMP_STATS]	= red_dump_stats,
	},
	.to_msg_fill		= red_msg_fill,
};

static void __init red_init(void)
{
	rtnl_tc_register(&red_ops);
}

static void __exit red_exit(void)
{
	rtnl_tc_unregister(&red_ops);
}

/** @} */