13#include <netlink-private/netlink.h> 
   14#include <netlink/netfilter/nfnl.h> 
   15#include <netlink/netfilter/queue.h> 
   18#define QUEUE_ATTR_GROUP                (1UL << 0) 
   19#define QUEUE_ATTR_MAXLEN               (1UL << 1) 
   20#define QUEUE_ATTR_COPY_MODE            (1UL << 2) 
   21#define QUEUE_ATTR_COPY_RANGE           (1UL << 3) 
   25static void nfnl_queue_dump(
struct nl_object *a, 
struct nl_dump_params *p)
 
   27        struct nfnl_queue *queue = (
struct nfnl_queue *) a;
 
   32        if (queue->ce_mask & QUEUE_ATTR_GROUP)
 
   33                nl_dump(p, 
"group=%u ", queue->queue_group);
 
   35        if (queue->ce_mask & QUEUE_ATTR_MAXLEN)
 
   36                nl_dump(p, 
"maxlen=%u ", queue->queue_maxlen);
 
   38        if (queue->ce_mask & QUEUE_ATTR_COPY_MODE)
 
   40                        nfnl_queue_copy_mode2str(queue->queue_copy_mode,
 
   43        if (queue->ce_mask & QUEUE_ATTR_COPY_RANGE)
 
   44                nl_dump(p, 
"copy_range=%u ", queue->queue_copy_range);
 
   49static const struct trans_tbl copy_modes[] = {
 
   50        __ADD(NFNL_QUEUE_COPY_NONE,     none),
 
   51        __ADD(NFNL_QUEUE_COPY_META,     meta),
 
   52        __ADD(NFNL_QUEUE_COPY_PACKET,   packet),
 
   55char *nfnl_queue_copy_mode2str(
enum nfnl_queue_copy_mode copy_mode, 
char *buf,
 
   58        return __type2str(copy_mode, buf, len, copy_modes,
 
   59                           ARRAY_SIZE(copy_modes));
 
   62int nfnl_queue_str2copy_mode(
const char *name)
 
   64        return __str2type(name, copy_modes, ARRAY_SIZE(copy_modes));
 
   72struct nfnl_queue *nfnl_queue_alloc(
void)
 
   77void nfnl_queue_get(
struct nfnl_queue *queue)
 
   82void nfnl_queue_put(
struct nfnl_queue *queue)
 
   94void nfnl_queue_set_group(
struct nfnl_queue *queue, uint16_t group)
 
   96        queue->queue_group = group;
 
   97        queue->ce_mask |= QUEUE_ATTR_GROUP;
 
  100int nfnl_queue_test_group(
const struct nfnl_queue *queue)
 
  102        return !!(queue->ce_mask & QUEUE_ATTR_GROUP);
 
  105uint16_t nfnl_queue_get_group(
const struct nfnl_queue *queue)
 
  107        return queue->queue_group;
 
  110void nfnl_queue_set_maxlen(
struct nfnl_queue *queue, uint32_t maxlen)
 
  112        queue->queue_maxlen = maxlen;
 
  113        queue->ce_mask |= QUEUE_ATTR_MAXLEN;
 
  116int nfnl_queue_test_maxlen(
const struct nfnl_queue *queue)
 
  118        return !!(queue->ce_mask & QUEUE_ATTR_MAXLEN);
 
  121uint32_t nfnl_queue_get_maxlen(
const struct nfnl_queue *queue)
 
  123        return queue->queue_maxlen;
 
  126void nfnl_queue_set_copy_mode(
struct nfnl_queue *queue, 
enum nfnl_queue_copy_mode mode)
 
  128        queue->queue_copy_mode = mode;
 
  129        queue->ce_mask |= QUEUE_ATTR_COPY_MODE;
 
  132int nfnl_queue_test_copy_mode(
const struct nfnl_queue *queue)
 
  134        return !!(queue->ce_mask & QUEUE_ATTR_COPY_MODE);
 
  137enum nfnl_queue_copy_mode nfnl_queue_get_copy_mode(
const struct nfnl_queue *queue)
 
  139        return queue->queue_copy_mode;
 
  142void nfnl_queue_set_copy_range(
struct nfnl_queue *queue, uint32_t copy_range)
 
  144        queue->queue_copy_range = copy_range;
 
  145        queue->ce_mask |= QUEUE_ATTR_COPY_RANGE;
 
  148int nfnl_queue_test_copy_range(
const struct nfnl_queue *queue)
 
  150        return !!(queue->ce_mask & QUEUE_ATTR_COPY_RANGE);
 
  153uint32_t nfnl_queue_get_copy_range(
const struct nfnl_queue *queue)
 
  155        return queue->queue_copy_range;
 
  158static uint64_t nfnl_queue_compare(
struct nl_object *_a, 
struct nl_object *_b,
 
  159                                   uint64_t attrs, 
int flags)
 
  161        struct nfnl_queue *a = (
struct nfnl_queue *) _a;
 
  162        struct nfnl_queue *b = (
struct nfnl_queue *) _b;
 
  165#define NFNL_QUEUE_DIFF(ATTR, EXPR) \ 
  166        ATTR_DIFF(attrs, QUEUE_ATTR_##ATTR, a, b, EXPR) 
  167#define NFNL_QUEUE_DIFF_VAL(ATTR, FIELD) \ 
  168        NFNL_QUEUE_DIFF(ATTR, a->FIELD != b->FIELD) 
  170        diff |= NFNL_QUEUE_DIFF_VAL(GROUP,      queue_group);
 
  171        diff |= NFNL_QUEUE_DIFF_VAL(MAXLEN,     queue_maxlen);
 
  172        diff |= NFNL_QUEUE_DIFF_VAL(COPY_MODE,  queue_copy_mode);
 
  173        diff |= NFNL_QUEUE_DIFF_VAL(COPY_RANGE, queue_copy_range);
 
  175#undef NFNL_QUEUE_DIFF 
  176#undef NFNL_QUEUE_DIFF_VAL 
  181static const struct trans_tbl nfnl_queue_attrs[] = {
 
  182        __ADD(QUEUE_ATTR_GROUP,         group),
 
  183        __ADD(QUEUE_ATTR_MAXLEN,        maxlen),
 
  184        __ADD(QUEUE_ATTR_COPY_MODE,     copy_mode),
 
  185        __ADD(QUEUE_ATTR_COPY_RANGE,    copy_range),
 
  188static char *nfnl_queue_attrs2str(
int attrs, 
char *buf, 
size_t len)
 
  190        return __flags2str(attrs, buf, len, nfnl_queue_attrs,
 
  191                           ARRAY_SIZE(nfnl_queue_attrs));
 
  196struct nl_object_ops queue_obj_ops = {
 
  197        .oo_name                = 
"netfilter/queue",
 
  198        .oo_size                = 
sizeof(
struct nfnl_queue),
 
  204        .oo_compare             = nfnl_queue_compare,
 
  205        .oo_attrs2str           = nfnl_queue_attrs2str,
 
  206        .oo_id_attrs            = QUEUE_ATTR_GROUP,
 
void nl_object_put(struct nl_object *obj)
Release a reference from an object.
 
void nl_object_get(struct nl_object *obj)
Acquire a reference on a object.
 
struct nl_object * nl_object_alloc(struct nl_object_ops *ops)
Allocate a new object of kind specified by the operations handle.
 
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
 
void nl_new_line(struct nl_dump_params *params)
Handle a new line while dumping.
 
@ NL_DUMP_STATS
Dump all attributes including statistics.
 
@ NL_DUMP_LINE
Dump object briefly on one line.
 
@ NL_DUMP_DETAILS
Dump all attributes but no statistics.