21 #include <netlink-private/netlink.h> 22 #include <netlink-private/tc.h> 23 #include <netlink/netlink.h> 24 #include <netlink-private/route/tc-api.h> 25 #include <netlink/route/classifier.h> 26 #include <netlink/route/cls/fw.h> 29 #define FW_ATTR_CLASSID 0x001 30 #define FW_ATTR_ACTION 0x002 31 #define FW_ATTR_POLICE 0x004 32 #define FW_ATTR_INDEV 0x008 33 #define FW_ATTR_MASK 0x010 36 static struct nla_policy fw_policy[TCA_FW_MAX+1] = {
40 [TCA_FW_MASK] = { .type =
NLA_U32 },
43 static int fw_msg_parser(
struct rtnl_tc *tc,
void *data)
45 struct nlattr *tb[TCA_FW_MAX + 1];
46 struct rtnl_fw *f = data;
49 err = tca_parse(tb, TCA_FW_MAX, tc, fw_policy);
53 if (tb[TCA_FW_CLASSID]) {
55 f->cf_mask |= FW_ATTR_CLASSID;
62 f->cf_mask |= FW_ATTR_ACTION;
65 if (tb[TCA_FW_POLICE]) {
69 f->cf_mask |= FW_ATTR_POLICE;
72 if (tb[TCA_FW_INDEV]) {
73 nla_strlcpy(f->cf_indev, tb[TCA_FW_INDEV], IFNAMSIZ);
74 f->cf_mask |= FW_ATTR_INDEV;
77 if (tb[TCA_FW_MASK]) {
79 f->cf_mask |= FW_ATTR_MASK;
85 static void fw_free_data(
struct rtnl_tc *tc,
void *data)
87 struct rtnl_fw *f = data;
93 static int fw_clone(
void *_dst,
void *_src)
95 struct rtnl_fw *dst = _dst, *src = _src;
97 if (src->cf_act && !(dst->cf_act =
nl_data_clone(src->cf_act)))
100 if (src->cf_police && !(dst->cf_police =
nl_data_clone(src->cf_police)))
106 static void fw_dump_line(
struct rtnl_tc *tc,
void *data,
109 struct rtnl_fw *f = data;
114 if (f->cf_mask & FW_ATTR_CLASSID) {
121 if (f->cf_mask & FW_ATTR_MASK)
122 nl_dump(p,
" mask 0x%x", f->cf_fwmask);
125 static void fw_dump_details(
struct rtnl_tc *tc,
void *data,
128 struct rtnl_fw *f = data;
130 if (f && f->cf_mask & FW_ATTR_INDEV)
131 nl_dump(p,
"indev %s ", f->cf_indev);
134 static int fw_msg_fill(
struct rtnl_tc *tc,
void *data,
struct nl_msg *msg)
136 struct rtnl_fw *f = data;
141 if (f->cf_mask & FW_ATTR_CLASSID)
144 if (f->cf_mask & FW_ATTR_ACTION)
147 if (f->cf_mask & FW_ATTR_POLICE)
150 if (f->cf_mask & FW_ATTR_INDEV)
153 if (f->cf_mask & FW_ATTR_MASK)
167 int rtnl_fw_set_classid(
struct rtnl_cls *cls, uint32_t classid)
174 f->cf_classid = classid;
175 f->cf_mask |= FW_ATTR_CLASSID;
180 int rtnl_fw_set_mask(
struct rtnl_cls *cls, uint32_t mask)
188 f->cf_mask |= FW_ATTR_MASK;
195 static struct rtnl_tc_ops fw_ops = {
197 .to_type = RTNL_TC_TYPE_CLS,
198 .to_size =
sizeof(
struct rtnl_fw),
199 .to_msg_parser = fw_msg_parser,
200 .to_msg_fill = fw_msg_fill,
201 .to_free_data = fw_free_data,
202 .to_clone = fw_clone,
209 static void __init fw_init(
void)
214 static void __exit fw_exit(
void)
Dump object briefly on one line.
int rtnl_tc_register(struct rtnl_tc_ops *ops)
Register a traffic control module.
Attribute validation policy.
#define NLA_PUT_DATA(msg, attrtype, data)
Add abstract data attribute to netlink message.
uint32_t nla_get_u32(const struct nlattr *nla)
Return payload of 32 bit integer attribute.
struct nl_data * nl_data_alloc_attr(const struct nlattr *nla)
Allocate abstract data object based on netlink attribute.
NUL terminated character string.
Dump all attributes but no statistics.
void rtnl_tc_unregister(struct rtnl_tc_ops *ops)
Unregister a traffic control module.
#define TC_CAST(ptr)
Macro to cast qdisc/class/classifier to tc object.
#define NLA_PUT_U32(msg, attrtype, value)
Add 32 bit integer attribute to netlink message.
struct nl_data * nl_data_clone(const struct nl_data *src)
Clone an abstract data object.
void * rtnl_tc_data(struct rtnl_tc *tc)
Return pointer to private data of traffic control object.
#define NLA_PUT_STRING(msg, attrtype, value)
Add string attribute to netlink message.
uint16_t type
Type of attribute or NLA_UNSPEC.
char * rtnl_tc_handle2str(uint32_t handle, char *buf, size_t len)
Convert a traffic control handle to a character string (Reentrant).
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
size_t nla_strlcpy(char *dst, const struct nlattr *nla, size_t dstsize)
Copy string attribute payload to a buffer.
void nl_data_free(struct nl_data *data)
Free an abstract data object.