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)
Dump object in a brief one-liner.
char co_kind[32]
Kind/Name of classifier.
int rtnl_cls_unregister(struct rtnl_cls_ops *cops)
Unregister a classifier module.
struct nl_data * nl_data_clone(struct nl_data *src)
Clone an abstract data object.
attribute validation policy
struct nl_msg * nlmsg_alloc(void)
Allocate a new netlink message with the default maximum payload size.
char * rtnl_tc_handle2str(uint32_t handle, char *buf, size_t len)
Convert a traffic control handle to a character string (Reentrant).
int nla_put_data(struct nl_msg *n, int attrtype, struct nl_data *data)
Add an abstract data netlink attribute to a netlink message.
int nla_put_string(struct nl_msg *n, int attrtype, const char *str)
Add a string netlink attribute to a netlink message.
int rtnl_cls_register(struct rtnl_cls_ops *cops)
Register a classifier module.
uint16_t type
Type of attribute or NLA_UNSPEC.
struct nl_data * nla_get_data(struct nlattr *nla)
Return payload of abstract data attribute.
uint32_t nla_get_u32(struct nlattr *nla)
Return payload of u32 attribute.
int nla_put_u32(struct nl_msg *n, int attrtype, uint32_t value)
Add a u32 netlink attribute to a netlink message.
Dump all attributes but no statistics.
Dump all attributes including statistics.
size_t nla_strlcpy(char *dst, const struct nlattr *nla, size_t dstsize)
Copy string attribute payload into a sized buffer.
void nl_data_free(struct nl_data *data)
Free an abstract data object.