8#include <libmnl/libmnl.h>
9#include <linux/netfilter/nf_tables.h>
10#include <libnftnl/rule.h>
11#include <libnftnl/expr.h>
17static int nftnl_expr_flow_set(
struct nftnl_expr *e, uint16_t type,
18 const void *data, uint32_t data_len)
23 case NFTNL_EXPR_FLOW_TABLE_NAME:
24 flow->table_name = strdup((
const char *)data);
25 if (!flow->table_name)
32static const void *nftnl_expr_flow_get(
const struct nftnl_expr *e,
33 uint16_t type, uint32_t *data_len)
38 case NFTNL_EXPR_FLOW_TABLE_NAME:
39 *data_len = strlen(flow->table_name) + 1;
40 return flow->table_name;
45static int nftnl_expr_flow_cb(
const struct nlattr *attr,
void *data)
47 const struct nlattr **tb = data;
48 int type = mnl_attr_get_type(attr);
50 if (mnl_attr_type_valid(attr, NFTA_FLOW_MAX) < 0)
54 case NFTA_FLOW_TABLE_NAME:
55 if (mnl_attr_validate(attr, MNL_TYPE_STRING) < 0)
64static void nftnl_expr_flow_build(
struct nlmsghdr *nlh,
65 const struct nftnl_expr *e)
69 if (e->flags & (1 << NFTNL_EXPR_FLOW_TABLE_NAME))
70 mnl_attr_put_strz(nlh, NFTA_FLOW_TABLE_NAME, flow->table_name);
73static int nftnl_expr_flow_parse(
struct nftnl_expr *e,
struct nlattr *attr)
76 struct nlattr *tb[NFTA_FLOW_MAX+1] = {};
79 if (mnl_attr_parse_nested(attr, nftnl_expr_flow_cb, tb) < 0)
82 if (tb[NFTA_FLOW_TABLE_NAME]) {
84 strdup(mnl_attr_get_str(tb[NFTA_FLOW_TABLE_NAME]));
85 if (!flow->table_name)
87 e->flags |= (1 << NFTNL_EXPR_FLOW_TABLE_NAME);
93static int nftnl_expr_flow_snprintf(
char *buf,
size_t remain,
94 uint32_t flags,
const struct nftnl_expr *e)
99 ret = snprintf(buf, remain,
"flowtable %s ", l->table_name);
100 SNPRINTF_BUFFER_SIZE(ret, remain, offset);
105static void nftnl_expr_flow_free(
const struct nftnl_expr *e)
109 xfree(flow->table_name);
112static struct attr_policy flow_offload_attr_policy[__NFTNL_EXPR_FLOW_MAX] = {
113 [NFTNL_EXPR_FLOW_TABLE_NAME] = { .maxlen = NFT_NAME_MAXLEN },
116struct expr_ops expr_ops_flow = {
117 .name =
"flow_offload",
119 .nftnl_max_attr = __NFTNL_EXPR_FLOW_MAX - 1,
120 .attr_policy = flow_offload_attr_policy,
121 .free = nftnl_expr_flow_free,
122 .set = nftnl_expr_flow_set,
123 .get = nftnl_expr_flow_get,
124 .parse = nftnl_expr_flow_parse,
125 .build = nftnl_expr_flow_build,
126 .output = nftnl_expr_flow_snprintf,