15#include "nl-default.h"
17#include <netlink/netlink.h>
18#include <netlink/route/classifier.h>
19#include <netlink/route/cls/fw.h>
26 struct nl_data *cf_act;
27 struct nl_data *cf_police;
28 char cf_indev[IFNAMSIZ];
33#define FW_ATTR_CLASSID 0x001
34#define FW_ATTR_ACTION 0x002
35#define FW_ATTR_POLICE 0x004
36#define FW_ATTR_INDEV 0x008
37#define FW_ATTR_MASK 0x010
40static struct nla_policy fw_policy[TCA_FW_MAX+1] = {
44 [TCA_FW_MASK] = { .type =
NLA_U32 },
47static int fw_msg_parser(
struct rtnl_tc *tc,
void *data)
49 struct nlattr *tb[TCA_FW_MAX + 1];
50 struct rtnl_fw *f = data;
53 err = tca_parse(tb, TCA_FW_MAX, tc, fw_policy);
57 if (tb[TCA_FW_CLASSID]) {
59 f->cf_mask |= FW_ATTR_CLASSID;
66 f->cf_mask |= FW_ATTR_ACTION;
69 if (tb[TCA_FW_POLICE]) {
73 f->cf_mask |= FW_ATTR_POLICE;
76 if (tb[TCA_FW_INDEV]) {
77 nla_strlcpy(f->cf_indev, tb[TCA_FW_INDEV], IFNAMSIZ);
78 f->cf_mask |= FW_ATTR_INDEV;
81 if (tb[TCA_FW_MASK]) {
83 f->cf_mask |= FW_ATTR_MASK;
89static void fw_free_data(
struct rtnl_tc *tc,
void *data)
91 struct rtnl_fw *f = data;
97static int fw_clone(
void *_dst,
void *_src)
99 struct rtnl_fw *dst = _dst, *src = _src;
102 dst->cf_police = NULL;
104 if (src->cf_act && !(dst->cf_act =
nl_data_clone(src->cf_act)))
107 if (src->cf_police && !(dst->cf_police =
nl_data_clone(src->cf_police)))
113static void fw_dump_line(
struct rtnl_tc *tc,
void *data,
116 struct rtnl_fw *f = data;
121 if (f->cf_mask & FW_ATTR_CLASSID) {
128 if (f->cf_mask & FW_ATTR_MASK)
129 nl_dump(p,
" mask 0x%x", f->cf_fwmask);
132static void fw_dump_details(
struct rtnl_tc *tc,
void *data,
135 struct rtnl_fw *f = data;
137 if (f && f->cf_mask & FW_ATTR_INDEV)
138 nl_dump(p,
"indev %s ", f->cf_indev);
141static int fw_msg_fill(
struct rtnl_tc *tc,
void *data,
struct nl_msg *msg)
143 struct rtnl_fw *f = data;
148 if (f->cf_mask & FW_ATTR_CLASSID)
151 if (f->cf_mask & FW_ATTR_ACTION)
154 if (f->cf_mask & FW_ATTR_POLICE)
157 if (f->cf_mask & FW_ATTR_INDEV)
160 if (f->cf_mask & FW_ATTR_MASK)
174int rtnl_fw_set_classid(
struct rtnl_cls *cls, uint32_t classid)
181 f->cf_classid = classid;
182 f->cf_mask |= FW_ATTR_CLASSID;
187int rtnl_fw_set_mask(
struct rtnl_cls *cls, uint32_t mask)
195 f->cf_mask |= FW_ATTR_MASK;
202static struct rtnl_tc_ops fw_ops = {
204 .to_type = RTNL_TC_TYPE_CLS,
205 .to_size =
sizeof(
struct rtnl_fw),
206 .to_msg_parser = fw_msg_parser,
207 .to_msg_fill = fw_msg_fill,
208 .to_free_data = fw_free_data,
209 .to_clone = fw_clone,
216static void _nl_init fw_init(
void)
221static void _nl_exit fw_exit(
void)
uint32_t nla_get_u32(const struct nlattr *nla)
Return payload of 32 bit integer attribute.
#define NLA_PUT_DATA(msg, attrtype, data)
Add abstract data attribute to netlink message.
#define NLA_PUT_U32(msg, attrtype, value)
Add 32 bit integer attribute to netlink message.
size_t nla_strlcpy(char *dst, const struct nlattr *nla, size_t dstsize)
Copy string attribute payload to a buffer.
#define NLA_PUT_STRING(msg, attrtype, value)
Add string attribute to netlink message.
@ NLA_STRING
NUL terminated character string.
char * rtnl_tc_handle2str(uint32_t handle, char *buf, size_t len)
Convert a traffic control handle to a character string (Reentrant).
struct nl_data * nl_data_clone(const struct nl_data *src)
Clone an abstract data object.
void nl_data_free(struct nl_data *data)
Free an abstract data object.
struct nl_data * nl_data_alloc_attr(const struct nlattr *nla)
Allocate abstract data object based on netlink attribute.
#define TC_CAST(ptr)
Macro to cast qdisc/class/classifier to tc object.
void * rtnl_tc_data(struct rtnl_tc *)
Return pointer to private data of traffic control object.
int rtnl_tc_register(struct rtnl_tc_ops *)
Register a traffic control module.
void rtnl_tc_unregister(struct rtnl_tc_ops *)
Unregister a traffic control module.
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
@ NL_DUMP_LINE
Dump object briefly on one line.
@ NL_DUMP_DETAILS
Dump all attributes but no statistics.
Attribute validation policy.
uint16_t type
Type of attribute or NLA_UNSPEC.