21 #include <netlink-local.h>
22 #include <netlink-tc.h>
23 #include <netlink/netlink.h>
24 #include <netlink/route/classifier.h>
25 #include <netlink/route/classifier-modules.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 inline struct rtnl_fw *fw_cls(
struct rtnl_cls *cls)
37 return (
struct rtnl_fw *) cls->c_subdata;
40 static inline struct rtnl_fw *fw_alloc(
struct rtnl_cls *cls)
43 cls->c_subdata = calloc(1,
sizeof(
struct rtnl_fw));
48 static struct nla_policy fw_policy[TCA_FW_MAX+1] = {
54 static int fw_msg_parser(
struct rtnl_cls *cls)
57 struct nlattr *tb[TCA_FW_MAX + 1];
60 err = tca_parse(tb, TCA_FW_MAX, (
struct rtnl_tca *) cls, fw_policy);
68 if (tb[TCA_FW_CLASSID]) {
70 f->cf_mask |= FW_ATTR_CLASSID;
77 f->cf_mask |= FW_ATTR_ACTION;
80 if (tb[TCA_FW_POLICE]) {
84 f->cf_mask |= FW_ATTR_POLICE;
87 if (tb[TCA_FW_INDEV]) {
88 nla_strlcpy(f->cf_indev, tb[TCA_FW_INDEV], IFNAMSIZ);
89 f->cf_mask |= FW_ATTR_INDEV;
95 err = nl_errno(ENOMEM);
100 static void fw_free_data(
struct rtnl_cls *cls)
102 struct rtnl_fw *f = fw_cls(cls);
110 free(cls->c_subdata);
113 static int fw_clone(
struct rtnl_cls *_dst,
struct rtnl_cls *_src)
115 struct rtnl_fw *dst, *src = fw_cls(_src);
120 dst = fw_alloc(_dst);
122 return nl_errno(ENOMEM);
134 return nl_get_errno();
137 static int fw_dump_brief(
struct rtnl_cls *cls,
struct nl_dump_params *p,
140 struct rtnl_fw *f = fw_cls(cls);
146 if (f->cf_mask & FW_ATTR_CLASSID)
147 dp_dump(p,
" target %s",
154 static int fw_dump_full(
struct rtnl_cls *cls,
struct nl_dump_params *p,
157 struct rtnl_fw *f = fw_cls(cls);
162 if (f->cf_mask & FW_ATTR_INDEV)
163 dp_dump(p,
"indev %s ", f->cf_indev);
169 static int fw_dump_stats(
struct rtnl_cls *cls,
struct nl_dump_params *p,
172 struct rtnl_fw *f = fw_cls(cls);
181 static struct nl_msg *fw_get_opts(
struct rtnl_cls *cls)
194 if (f->cf_mask & FW_ATTR_CLASSID)
197 if (f->cf_mask & FW_ATTR_ACTION)
200 if (f->cf_mask & FW_ATTR_POLICE)
203 if (f->cf_mask & FW_ATTR_INDEV)
214 int rtnl_fw_set_classid(
struct rtnl_cls *cls, uint32_t classid)
220 return nl_errno(ENOMEM);
222 f->cf_classid = classid;
223 f->cf_mask |= FW_ATTR_CLASSID;
232 .co_msg_parser = fw_msg_parser,
233 .co_free_data = fw_free_data,
234 .co_clone = fw_clone,
235 .co_get_opts = fw_get_opts,
241 static void __init fw_init(
void)
246 static void __exit fw_exit(
void)