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>
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
31static struct nla_policy red_policy[TCA_RED_MAX+1] = {
32 [TCA_RED_PARMS] = { .
minlen =
sizeof(
struct tc_red_qopt) },
35static int red_msg_parser(
struct rtnl_tc *tc,
void *data)
37 struct nlattr *tb[TCA_RED_MAX+1];
38 struct rtnl_red *red = data;
39 struct tc_red_qopt *opts;
42 if (!(tc->ce_mask & TCA_ATTR_OPTS))
45 err = tca_parse(tb, TCA_RED_MAX, tc, red_policy);
49 if (!tb[TCA_RED_PARMS])
50 return -NLE_MISSING_ATTR;
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;
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 |
69static void red_dump_line(
struct rtnl_tc *tc,
void *data,
72 struct rtnl_red *red = data;
79static void red_dump_details(
struct rtnl_tc *tc,
void *data,
82 struct rtnl_red *red = data;
89static void red_dump_stats(
struct rtnl_tc *tc,
void *data,
92 struct rtnl_red *red = data;
99static int red_msg_fill(
struct rtnl_tc *tc,
void *data,
struct nl_msg *msg)
101 struct rtnl_red *red = data;
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;
112 if (
nlmsg_append(msg, &opts,
sizeof(opts), NL_DONTPAD) < 0)
116 return -NLE_OPNOTSUPP;
132 struct rtnl_red *red;
137 red->qr_limit = limit;
138 red->qr_mask |= RED_ATTR_LIMIT;
148 struct rtnl_red *red;
153 if (red->qr_mask & RED_ATTR_LIMIT)
154 return red->qr_limit;
161static struct rtnl_tc_ops red_ops = {
163 .to_type = RTNL_TC_TYPE_QDISC,
164 .to_size =
sizeof(
struct rtnl_red),
165 .to_msg_parser = red_msg_parser,
171 .to_msg_fill = red_msg_fill,
174static void __init red_init(
void)
179static void __exit red_exit(
void)
void * nla_data(const struct nlattr *nla)
Return pointer to the payload section.
int nlmsg_append(struct nl_msg *n, void *data, size_t len, int pad)
Append data to tail of a netlink message.
void rtnl_red_set_limit(struct rtnl_qdisc *qdisc, int limit)
Set limit of RED qdisc.
int rtnl_red_get_limit(struct rtnl_qdisc *qdisc)
Get limit of RED qdisc.
#define TC_CAST(ptr)
Macro to cast qdisc/class/classifier to tc object.
void * rtnl_tc_data(struct rtnl_tc *tc)
Return pointer to private data of traffic control object.
int rtnl_tc_register(struct rtnl_tc_ops *ops)
Register a traffic control module.
void rtnl_tc_unregister(struct rtnl_tc_ops *ops)
Unregister a traffic control module.
@ NL_DUMP_STATS
Dump all attributes including statistics.
@ NL_DUMP_LINE
Dump object briefly on one line.
@ NL_DUMP_DETAILS
Dump all attributes but no statistics.
Attribute validation policy.
uint16_t minlen
Minimal length of payload required.