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)