15#include <netlink-private/netlink.h> 
   16#include <netlink-private/tc.h> 
   17#include <netlink/netlink.h> 
   18#include <netlink-private/route/tc-api.h> 
   19#include <netlink/route/classifier.h> 
   20#include <netlink/route/cls/fw.h> 
   23#define FW_ATTR_CLASSID      0x001 
   24#define FW_ATTR_ACTION       0x002 
   25#define FW_ATTR_POLICE       0x004 
   26#define FW_ATTR_INDEV        0x008 
   27#define FW_ATTR_MASK         0x010 
   30static struct nla_policy fw_policy[TCA_FW_MAX+1] = {
 
   34        [TCA_FW_MASK]           = { .type = 
NLA_U32 },
 
   37static int fw_msg_parser(
struct rtnl_tc *tc, 
void *data)
 
   39        struct nlattr *tb[TCA_FW_MAX + 1];
 
   40        struct rtnl_fw *f = data;
 
   43        err = tca_parse(tb, TCA_FW_MAX, tc, fw_policy);
 
   47        if (tb[TCA_FW_CLASSID]) {
 
   49                f->cf_mask |= FW_ATTR_CLASSID;
 
   56                f->cf_mask |= FW_ATTR_ACTION;
 
   59        if (tb[TCA_FW_POLICE]) {
 
   63                f->cf_mask |= FW_ATTR_POLICE;
 
   66        if (tb[TCA_FW_INDEV]) {
 
   67                nla_strlcpy(f->cf_indev, tb[TCA_FW_INDEV], IFNAMSIZ);
 
   68                f->cf_mask |= FW_ATTR_INDEV;
 
   71        if (tb[TCA_FW_MASK]) {
 
   73                f->cf_mask |= FW_ATTR_MASK;
 
   79static void fw_free_data(
struct rtnl_tc *tc, 
void *data)
 
   81        struct rtnl_fw *f = data;
 
   87static int fw_clone(
void *_dst, 
void *_src)
 
   89        struct rtnl_fw *dst = _dst, *src = _src;
 
   92        dst->cf_police = NULL;
 
   94        if (src->cf_act && !(dst->cf_act = 
nl_data_clone(src->cf_act)))
 
   97        if (src->cf_police && !(dst->cf_police = 
nl_data_clone(src->cf_police)))
 
  103static void fw_dump_line(
struct rtnl_tc *tc, 
void *data,
 
  106        struct rtnl_fw *f = data;
 
  111        if (f->cf_mask & FW_ATTR_CLASSID) {
 
  118        if (f->cf_mask & FW_ATTR_MASK)
 
  119                nl_dump(p, 
" mask 0x%x", f->cf_fwmask);
 
  122static void fw_dump_details(
struct rtnl_tc *tc, 
void *data,
 
  125        struct rtnl_fw *f = data;
 
  127        if (f && f->cf_mask & FW_ATTR_INDEV)
 
  128                nl_dump(p, 
"indev %s ", f->cf_indev);
 
  131static int fw_msg_fill(
struct rtnl_tc *tc, 
void *data, 
struct nl_msg *msg)
 
  133        struct rtnl_fw *f = data;
 
  138        if (f->cf_mask & FW_ATTR_CLASSID)
 
  141        if (f->cf_mask & FW_ATTR_ACTION)
 
  144        if (f->cf_mask & FW_ATTR_POLICE)
 
  147        if (f->cf_mask & FW_ATTR_INDEV)
 
  150        if (f->cf_mask & FW_ATTR_MASK)
 
  164int rtnl_fw_set_classid(
struct rtnl_cls *cls, uint32_t classid)
 
  171        f->cf_classid = classid;
 
  172        f->cf_mask |= FW_ATTR_CLASSID;
 
  177int rtnl_fw_set_mask(
struct rtnl_cls *cls, uint32_t mask)
 
  185        f->cf_mask |= FW_ATTR_MASK;
 
  192static struct rtnl_tc_ops fw_ops = {
 
  194        .to_type                = RTNL_TC_TYPE_CLS,
 
  195        .to_size                = 
sizeof(
struct rtnl_fw),
 
  196        .to_msg_parser          = fw_msg_parser,
 
  197        .to_msg_fill            = fw_msg_fill,
 
  198        .to_free_data           = fw_free_data,
 
  199        .to_clone               = fw_clone,
 
  206static void __init fw_init(
void)
 
  211static void __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 *tc)
Return pointer to private data of traffic control object.
 
int rtnl_tc_register(struct rtnl_tc_ops *ops)
Register a traffic control module.
 
void rtnl_tc_unregister(struct rtnl_tc_ops *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.