| 1 |
/* SPDX-License-Identifier: LGPL-2.1-only */ |
| 2 |
/* |
| 3 |
* Copyright (c) 2003-2011 Thomas Graf <[email protected]> |
| 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 */ |
| 23 |
struct 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 |
|
| 43 |
static struct nla_policy red_policy[TCA_RED_MAX+1] = { |
| 44 |
[TCA_RED_PARMS] = { .minlen = sizeof(struct tc_red_qopt) }, |
| 45 |
}; |
| 46 |
|
| 47 |
static 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 |
|
| 81 |
static 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 |
|
| 91 |
static 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 |
|
| 101 |
static 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 |
|
| 111 |
static 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 |
|
| 173 |
static 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 |
|
| 186 |
static void _nl_init red_init(void) |
| 187 |
{ |
| 188 |
rtnl_tc_register(&red_ops); |
| 189 |
} |
| 190 |
|
| 191 |
static void _nl_exit red_exit(void) |
| 192 |
{ |
| 193 |
rtnl_tc_unregister(&red_ops); |
| 194 |
} |
| 195 |
|
| 196 |
/** @} */ |