#include <list.h>
#include <netinet/in.h>
#include <libnftnl/object.h> /* For NFTNL_CTTIMEOUT_ARRAY_MAX. */
+#include <linux/netfilter/nf_tables.h>
/**
* struct handle_spec - handle ID
extern void set_print(const struct set *set, struct output_ctx *octx);
extern void set_print_plain(const struct set *s, struct output_ctx *octx);
+static inline bool set_is_datamap(uint32_t set_flags)
+{
+ return set_flags & NFT_SET_MAP;
+}
+
+static inline bool set_is_objmap(uint32_t set_flags)
+{
+ return set_flags & NFT_SET_OBJECT;
+}
+
+static inline bool set_is_map(uint32_t set_flags)
+{
+ return set_is_datamap(set_flags) || set_is_objmap(set_flags);
+}
+
#include <statement.h>
struct counter {
struct set *set;
struct handle h;
- if (expr->set_flags & NFT_SET_MAP)
+ if (set_is_datamap(expr->set_flags))
key_fix_dtype_byteorder(key);
set = set_alloc(&expr->location);
if (expr_evaluate(ctx, &map->mappings) < 0)
return -1;
if (map->mappings->etype != EXPR_SET_REF ||
- !(map->mappings->set->flags & NFT_SET_MAP))
+ !set_is_datamap(map->mappings->set->flags))
return expr_error(ctx->msgs, map->mappings,
"Expression is not a map");
break;
if (set == NULL)
return expr_error(ctx->msgs, mapping,
"mapping outside of map context");
- if (!(set->flags & (NFT_SET_MAP | NFT_SET_OBJECT)))
+ if (!set_is_map(set->flags))
return set_error(ctx, set, "set is not a map");
expr_set_context(&ctx->ectx, set->key->dtype, set->key->len);
if (map->mappings->etype != EXPR_SET_REF)
return expr_error(ctx->msgs, map->mappings,
"Expression is not a map");
- if (!(map->mappings->set->flags & NFT_SET_OBJECT))
+ if (!set_is_objmap(map->mappings->set->flags))
return expr_error(ctx->msgs, map->mappings,
"Expression is not a map with objects");
break;
set->key->etype == EXPR_CONCAT)
return set_error(ctx, set, "concatenated types not supported in interval sets");
- if (set->flags & NFT_SET_MAP) {
+ if (set_is_datamap(set->flags)) {
if (set->datatype == NULL)
return set_error(ctx, set, "map definition does not "
"specify mapping data type");
if (set->datalen == 0 && set->datatype->type != TYPE_VERDICT)
return set_error(ctx, set, "unqualified mapping data "
"type specified in map definition");
- } else if (set->flags & NFT_SET_OBJECT) {
+ } else if (set_is_objmap(set->flags)) {
set->datatype = &string_type;
set->datalen = NFT_OBJ_MAXNAMELEN * BITS_PER_BYTE;
}
json_t *root, *tmp;
const char *type, *datatype_ext = NULL;
- if (set->flags & NFT_SET_MAP) {
+ if (set_is_datamap(set->flags)) {
type = "map";
datatype_ext = set->datatype->name;
- } else if (set->flags & NFT_SET_OBJECT) {
+ } else if (set_is_objmap(set->flags)) {
type = "map";
datatype_ext = obj_type_name(set->objtype);
} else if (set->flags & NFT_SET_EVAL) {
dtype_map_to_kernel(set->key->dtype));
nftnl_set_set_u32(nls, NFTNL_SET_KEY_LEN,
div_round_up(set->key->len, BITS_PER_BYTE));
- if (set->flags & NFT_SET_MAP) {
+ if (set_is_datamap(set->flags)) {
nftnl_set_set_u32(nls, NFTNL_SET_DATA_TYPE,
dtype_map_to_kernel(set->datatype));
nftnl_set_set_u32(nls, NFTNL_SET_DATA_LEN,
set->datalen / BITS_PER_BYTE);
}
- if (set->flags & NFT_SET_OBJECT)
+ if (set_is_objmap(set->flags))
nftnl_set_set_u32(nls, NFTNL_SET_OBJ_TYPE, set->objtype);
if (set->timeout)
set->key->byteorder))
memory_allocation_error();
- if (set->flags & NFT_SET_MAP &&
+ if (set_is_datamap(set->flags) &&
!nftnl_udata_put_u32(udbuf, NFTNL_UDATA_SET_DATABYTEORDER,
set->datatype->byteorder))
memory_allocation_error();
nftnl_udata_buf_len(udbuf));
nftnl_udata_buf_free(udbuf);
}
- if (set->set_flags & NFT_SET_MAP && data != NULL) {
+ if (set_is_datamap(set->set_flags) && data != NULL) {
netlink_gen_data(data, &nld);
switch (data->etype) {
case EXPR_VERDICT:
break;
}
}
- if (set->set_flags & NFT_SET_OBJECT && data != NULL) {
+ if (set_is_objmap(set->set_flags) && data != NULL) {
netlink_gen_data(data, &nld);
nftnl_set_elem_set(nlse, NFTNL_SET_ELEM_OBJREF,
nld.value, nld.len);
}
flags = nftnl_set_get_u32(nls, NFTNL_SET_FLAGS);
- if (flags & NFT_SET_MAP) {
+ if (set_is_datamap(flags)) {
data = nftnl_set_get_u32(nls, NFTNL_SET_DATA_TYPE);
datatype = dtype_map_from_kernel(data);
if (datatype == NULL) {
} else
datatype = NULL;
- if (flags & NFT_SET_OBJECT) {
+ if (set_is_objmap(flags)) {
objtype = nftnl_set_get_u32(nls, NFTNL_SET_OBJ_TYPE);
datatype = &string_type;
}
if (flags & NFT_SET_ELEM_INTERVAL_END)
expr->flags |= EXPR_F_INTERVAL_END;
- if (set->flags & NFT_SET_MAP) {
+ if (set_is_datamap(set->flags)) {
if (nftnl_set_elem_is_set(nlse, NFTNL_SET_ELEM_DATA)) {
nld.value = nftnl_set_elem_get(nlse, NFTNL_SET_ELEM_DATA,
&nld.len);
expr = mapping_expr_alloc(&netlink_location, expr, data);
}
- if (set->flags & NFT_SET_OBJECT) {
+ if (set_is_objmap(set->flags)) {
if (nftnl_set_elem_is_set(nlse, NFTNL_SET_ELEM_OBJREF)) {
nld.value = nftnl_set_elem_get(nlse,
NFTNL_SET_ELEM_OBJREF,
if ((set->flags & (NFT_SET_EVAL | NFT_SET_ANONYMOUS)) ==
(NFT_SET_EVAL | NFT_SET_ANONYMOUS))
type = "meter";
- else if (set->flags & (NFT_SET_MAP | NFT_SET_OBJECT))
+ else if (set_is_map(set->flags))
type = "map";
else
type = "set";
nft_print(octx, "%s", opts->nl);
nft_print(octx, "%s%stype %s",
opts->tab, opts->tab, set->key->dtype->name);
- if (set->flags & NFT_SET_MAP)
+ if (set_is_datamap(set->flags))
nft_print(octx, " : %s", set->datatype->name);
- else if (set->flags & NFT_SET_OBJECT)
+ else if (set_is_objmap(set->flags))
nft_print(octx, " : %s", obj_type_name(set->objtype));
nft_print(octx, "%s", opts->stmt_separator);