16#include <linux/netfilter/nf_tables.h>
19#include <libmnl/libmnl.h>
20#include <libnftnl/object.h>
24static int nftnl_obj_secmark_set(
struct nftnl_obj *e, uint16_t type,
25 const void *data, uint32_t data_len)
27 struct nftnl_obj_secmark *secmark = nftnl_obj_data(e);
30 case NFTNL_OBJ_SECMARK_CTX:
31 snprintf(secmark->ctx,
sizeof(secmark->ctx),
"%s", (
const char *)data);
39static const void *nftnl_obj_secmark_get(
const struct nftnl_obj *e,
40 uint16_t type, uint32_t *data_len)
42 struct nftnl_obj_secmark *secmark = nftnl_obj_data(e);
45 case NFTNL_OBJ_SECMARK_CTX:
46 *data_len = strlen(secmark->ctx);
52static int nftnl_obj_secmark_cb(
const struct nlattr *attr,
void *data)
54 const struct nftnl_obj_secmark *secmark = NULL;
55 int type = mnl_attr_get_type(attr);
56 const struct nlattr **tb = data;
58 if (mnl_attr_type_valid(attr, NFTA_SECMARK_MAX) < 0)
62 case NFTA_SECMARK_CTX:
63 if (mnl_attr_validate(attr, MNL_TYPE_STRING) < 0)
65 if (mnl_attr_get_payload_len(attr) >=
sizeof(secmark->ctx))
75nftnl_obj_secmark_build(
struct nlmsghdr *nlh,
const struct nftnl_obj *e)
77 struct nftnl_obj_secmark *secmark = nftnl_obj_data(e);
79 if (e->flags & (1 << NFTNL_OBJ_SECMARK_CTX))
80 mnl_attr_put_str(nlh, NFTA_SECMARK_CTX, secmark->ctx);
84nftnl_obj_secmark_parse(
struct nftnl_obj *e,
struct nlattr *attr)
86 struct nftnl_obj_secmark *secmark = nftnl_obj_data(e);
87 struct nlattr *tb[NFTA_SECMARK_MAX + 1] = {};
89 if (mnl_attr_parse_nested(attr, nftnl_obj_secmark_cb, tb) < 0)
92 if (tb[NFTA_SECMARK_CTX]) {
93 snprintf(secmark->ctx,
sizeof(secmark->ctx),
"%s",
94 mnl_attr_get_str(tb[NFTA_SECMARK_CTX]));
95 e->flags |= (1 << NFTNL_OBJ_SECMARK_CTX);
101static int nftnl_obj_secmark_snprintf(
char *buf,
size_t len,
103 const struct nftnl_obj *e)
105 struct nftnl_obj_secmark *secmark = nftnl_obj_data(e);
107 return snprintf(buf, len,
"context %s ", secmark->ctx);
110struct obj_ops obj_ops_secmark = {
112 .type = NFT_OBJECT_SECMARK,
113 .alloc_len =
sizeof(
struct nftnl_obj_secmark),
114 .max_attr = NFTA_SECMARK_MAX,
115 .set = nftnl_obj_secmark_set,
116 .get = nftnl_obj_secmark_get,
117 .parse = nftnl_obj_secmark_parse,
118 .build = nftnl_obj_secmark_build,
119 .output = nftnl_obj_secmark_snprintf,