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/route/qdisc.h>
18#include <netlink-private/route/tc-api.h>
19#include <netlink/route/class.h>
20#include <netlink/route/qdisc/dsmark.h>
23#define SCH_DSMARK_ATTR_INDICES 0x1
24#define SCH_DSMARK_ATTR_DEFAULT_INDEX 0x2
25#define SCH_DSMARK_ATTR_SET_TC_INDEX 0x4
27#define SCH_DSMARK_ATTR_MASK 0x1
28#define SCH_DSMARK_ATTR_VALUE 0x2
31static struct nla_policy dsmark_policy[TCA_DSMARK_MAX+1] = {
33 [TCA_DSMARK_DEFAULT_INDEX] = { .type =
NLA_U16 },
34 [TCA_DSMARK_SET_TC_INDEX] = { .type =
NLA_FLAG },
35 [TCA_DSMARK_VALUE] = { .type =
NLA_U8 },
36 [TCA_DSMARK_MASK] = { .type =
NLA_U8 },
39static int dsmark_qdisc_msg_parser(
struct rtnl_tc *tc,
void *data)
41 struct rtnl_dsmark_qdisc *dsmark = data;
42 struct nlattr *tb[TCA_DSMARK_MAX + 1];
45 err = tca_parse(tb, TCA_DSMARK_MAX, tc, dsmark_policy);
49 if (tb[TCA_DSMARK_INDICES]) {
50 dsmark->qdm_indices =
nla_get_u16(tb[TCA_DSMARK_INDICES]);
51 dsmark->qdm_mask |= SCH_DSMARK_ATTR_INDICES;
54 if (tb[TCA_DSMARK_DEFAULT_INDEX]) {
55 dsmark->qdm_default_index =
57 dsmark->qdm_mask |= SCH_DSMARK_ATTR_DEFAULT_INDEX;
60 if (tb[TCA_DSMARK_SET_TC_INDEX]) {
61 dsmark->qdm_set_tc_index = 1;
62 dsmark->qdm_mask |= SCH_DSMARK_ATTR_SET_TC_INDEX;
68static int dsmark_class_msg_parser(
struct rtnl_tc *tc,
void *data)
70 struct rtnl_dsmark_class *dsmark = data;
71 struct nlattr *tb[TCA_DSMARK_MAX + 1];
74 err = tca_parse(tb, TCA_DSMARK_MAX, tc, dsmark_policy);
78 if (tb[TCA_DSMARK_MASK]) {
79 dsmark->cdm_bmask =
nla_get_u8(tb[TCA_DSMARK_MASK]);
80 dsmark->cdm_mask |= SCH_DSMARK_ATTR_MASK;
83 if (tb[TCA_DSMARK_VALUE]) {
84 dsmark->cdm_value =
nla_get_u8(tb[TCA_DSMARK_VALUE]);
85 dsmark->cdm_mask |= SCH_DSMARK_ATTR_VALUE;
91static void dsmark_qdisc_dump_line(
struct rtnl_tc *tc,
void *data,
94 struct rtnl_dsmark_qdisc *dsmark = data;
96 if (dsmark && (dsmark->qdm_mask & SCH_DSMARK_ATTR_INDICES))
97 nl_dump(p,
" indices 0x%04x", dsmark->qdm_indices);
100static void dsmark_qdisc_dump_details(
struct rtnl_tc *tc,
void *data,
103 struct rtnl_dsmark_qdisc *dsmark = data;
108 if (dsmark->qdm_mask & SCH_DSMARK_ATTR_DEFAULT_INDEX)
109 nl_dump(p,
" default index 0x%04x", dsmark->qdm_default_index);
111 if (dsmark->qdm_mask & SCH_DSMARK_ATTR_SET_TC_INDEX)
115static void dsmark_class_dump_line(
struct rtnl_tc *tc,
void *data,
118 struct rtnl_dsmark_class *dsmark = data;
123 if (dsmark->cdm_mask & SCH_DSMARK_ATTR_VALUE)
124 nl_dump(p,
" value 0x%02x", dsmark->cdm_value);
126 if (dsmark->cdm_mask & SCH_DSMARK_ATTR_MASK)
127 nl_dump(p,
" mask 0x%02x", dsmark->cdm_bmask);
130static int dsmark_qdisc_msg_fill(
struct rtnl_tc *tc,
void *data,
133 struct rtnl_dsmark_qdisc *dsmark = data;
138 if (dsmark->qdm_mask & SCH_DSMARK_ATTR_INDICES)
139 NLA_PUT_U16(msg, TCA_DSMARK_INDICES, dsmark->qdm_indices);
141 if (dsmark->qdm_mask & SCH_DSMARK_ATTR_DEFAULT_INDEX)
143 dsmark->qdm_default_index);
145 if (dsmark->qdm_mask & SCH_DSMARK_ATTR_SET_TC_INDEX)
154static int dsmark_class_msg_fill(
struct rtnl_tc *tc,
void *data,
157 struct rtnl_dsmark_class *dsmark = data;
162 if (dsmark->cdm_mask & SCH_DSMARK_ATTR_MASK)
163 NLA_PUT_U8(msg, TCA_DSMARK_MASK, dsmark->cdm_bmask);
165 if (dsmark->cdm_mask & SCH_DSMARK_ATTR_VALUE)
166 NLA_PUT_U8(msg, TCA_DSMARK_VALUE, dsmark->cdm_value);
187 struct rtnl_dsmark_class *dsmark;
192 dsmark->cdm_bmask = mask;
193 dsmark->cdm_mask |= SCH_DSMARK_ATTR_MASK;
205 struct rtnl_dsmark_class *dsmark;
210 if (dsmark->cdm_mask & SCH_DSMARK_ATTR_MASK)
211 return dsmark->cdm_bmask;
224 struct rtnl_dsmark_class *dsmark;
229 dsmark->cdm_value = value;
230 dsmark->cdm_mask |= SCH_DSMARK_ATTR_VALUE;
242 struct rtnl_dsmark_class *dsmark;
247 if (dsmark->cdm_mask & SCH_DSMARK_ATTR_VALUE)
248 return dsmark->cdm_value;
267 struct rtnl_dsmark_qdisc *dsmark;
272 dsmark->qdm_indices = indices;
273 dsmark->qdm_mask |= SCH_DSMARK_ATTR_INDICES;
285 struct rtnl_dsmark_qdisc *dsmark;
290 if (dsmark->qdm_mask & SCH_DSMARK_ATTR_INDICES)
291 return dsmark->qdm_indices;
303 uint16_t default_index)
305 struct rtnl_dsmark_qdisc *dsmark;
310 dsmark->qdm_default_index = default_index;
311 dsmark->qdm_mask |= SCH_DSMARK_ATTR_DEFAULT_INDEX;
323 struct rtnl_dsmark_qdisc *dsmark;
328 if (dsmark->qdm_mask & SCH_DSMARK_ATTR_DEFAULT_INDEX)
329 return dsmark->qdm_default_index;
342 struct rtnl_dsmark_qdisc *dsmark;
347 dsmark->qdm_set_tc_index = !!flag;
348 dsmark->qdm_mask |= SCH_DSMARK_ATTR_SET_TC_INDEX;
361 struct rtnl_dsmark_qdisc *dsmark;
366 if (dsmark->qdm_mask & SCH_DSMARK_ATTR_SET_TC_INDEX)
367 return dsmark->qdm_set_tc_index;
374static struct rtnl_tc_ops dsmark_qdisc_ops = {
376 .to_type = RTNL_TC_TYPE_QDISC,
377 .to_size =
sizeof(
struct rtnl_dsmark_qdisc),
378 .to_msg_parser = dsmark_qdisc_msg_parser,
383 .to_msg_fill = dsmark_qdisc_msg_fill,
386static struct rtnl_tc_ops dsmark_class_ops = {
388 .to_type = RTNL_TC_TYPE_CLASS,
389 .to_size =
sizeof(
struct rtnl_dsmark_class),
390 .to_msg_parser = dsmark_class_msg_parser,
392 .to_msg_fill = dsmark_class_msg_fill,
395static void __init dsmark_init(
void)
401static void __exit dsmark_exit(
void)
uint16_t nla_get_u16(const struct nlattr *nla)
Return payload of 16 bit integer attribute.
#define NLA_PUT_FLAG(msg, attrtype)
Add flag attribute to netlink message.
#define NLA_PUT_U16(msg, attrtype, value)
Add 16 bit integer attribute to netlink message.
#define NLA_PUT_U8(msg, attrtype, value)
Add 8 bit integer attribute to netlink message.
uint8_t nla_get_u8(const struct nlattr *nla)
Return value of 8 bit integer attribute.
int rtnl_qdisc_dsmark_set_indices(struct rtnl_qdisc *qdisc, uint16_t indices)
Set indices of DSMARK qdisc.
int rtnl_class_dsmark_set_value(struct rtnl_class *class, uint8_t value)
Set value of DSMARK class.
int rtnl_class_dsmark_set_bitmask(struct rtnl_class *class, uint8_t mask)
Set bitmask of DSMARK class.
int rtnl_qdisc_dsmark_get_default_index(struct rtnl_qdisc *qdisc)
Get default index of DSMARK qdisc.
int rtnl_qdisc_dsmark_set_set_tc_index(struct rtnl_qdisc *qdisc, int flag)
Set set-tc-index flag of DSMARK qdisc.
int rtnl_class_dsmark_get_value(struct rtnl_class *class)
Get value of DSMARK class.
int rtnl_qdisc_dsmark_get_set_tc_index(struct rtnl_qdisc *qdisc)
Get set-tc-index flag of DSMARK qdisc.
int rtnl_qdisc_dsmark_get_indices(struct rtnl_qdisc *qdisc)
Get indices of DSMARK qdisc.
int rtnl_qdisc_dsmark_set_default_index(struct rtnl_qdisc *qdisc, uint16_t default_index)
Set default index of DSMARK qdisc.
int rtnl_class_dsmark_get_bitmask(struct rtnl_class *class)
Get bitmask of DSMARK class.
#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.
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
@ NL_DUMP_LINE
Dump object briefly on one line.
@ NL_DUMP_DETAILS
Dump all attributes but no statistics.
Attribute validation policy.
uint16_t type
Type of attribute or NLA_UNSPEC.