21 #include <netlink-local.h>
22 #include <netlink-tc.h>
23 #include <netlink/netlink.h>
24 #include <netlink/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
35 static struct nla_policy fw_policy[TCA_FW_MAX+1] = {
41 static int fw_msg_parser(
struct rtnl_tc *tc,
void *data)
43 struct nlattr *tb[TCA_FW_MAX + 1];
44 struct rtnl_fw *f = data;
47 err = tca_parse(tb, TCA_FW_MAX, tc, fw_policy);
51 if (tb[TCA_FW_CLASSID]) {
53 f->cf_mask |= FW_ATTR_CLASSID;
60 f->cf_mask |= FW_ATTR_ACTION;
63 if (tb[TCA_FW_POLICE]) {
67 f->cf_mask |= FW_ATTR_POLICE;
70 if (tb[TCA_FW_INDEV]) {
71 nla_strlcpy(f->cf_indev, tb[TCA_FW_INDEV], IFNAMSIZ);
72 f->cf_mask |= FW_ATTR_INDEV;
78 static void fw_free_data(
struct rtnl_tc *tc,
void *data)
80 struct rtnl_fw *f = data;
86 static int fw_clone(
void *_dst,
void *_src)
88 struct rtnl_fw *dst = _dst, *src = _src;
90 if (src->cf_act && !(dst->cf_act =
nl_data_clone(src->cf_act)))
93 if (src->cf_police && !(dst->cf_police =
nl_data_clone(src->cf_police)))
99 static void fw_dump_line(
struct rtnl_tc *tc,
void *data,
102 struct rtnl_fw *f = data;
104 if (f && f->cf_mask & FW_ATTR_CLASSID) {
112 static void fw_dump_details(
struct rtnl_tc *tc,
void *data,
115 struct rtnl_fw *f = data;
117 if (f && f->cf_mask & FW_ATTR_INDEV)
118 nl_dump(p,
"indev %s ", f->cf_indev);
121 static int fw_msg_fill(
struct rtnl_tc *tc,
void *data,
struct nl_msg *msg)
123 struct rtnl_fw *f = data;
128 if (f->cf_mask & FW_ATTR_CLASSID)
131 if (f->cf_mask & FW_ATTR_ACTION)
134 if (f->cf_mask & FW_ATTR_POLICE)
137 if (f->cf_mask & FW_ATTR_INDEV)
151 int rtnl_fw_set_classid(
struct rtnl_cls *cls, uint32_t classid)
158 f->cf_classid = classid;
159 f->cf_mask |= FW_ATTR_CLASSID;
168 .to_type = RTNL_TC_TYPE_CLS,
169 .to_size =
sizeof(
struct rtnl_fw),
170 .to_msg_parser = fw_msg_parser,
171 .to_msg_fill = fw_msg_fill,
172 .to_free_data = fw_free_data,
173 .to_clone = fw_clone,
180 static void __init fw_init(
void)
185 static void __exit fw_exit(
void)