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)
34static const void *nftnl_expr_flow_get(
const struct nftnl_expr *e,
35 uint16_t type, uint32_t *data_len)
40 case NFTNL_EXPR_FLOW_TABLE_NAME:
41 *data_len = strlen(flow->table_name) + 1;
42 return flow->table_name;
47static int nftnl_expr_flow_cb(
const struct nlattr *attr,
void *data)
49 const struct nlattr **tb = data;
50 int type = mnl_attr_get_type(attr);
52 if (mnl_attr_type_valid(attr, NFTA_FLOW_MAX) < 0)
56 case NFTA_FLOW_TABLE_NAME:
57 if (mnl_attr_validate(attr, MNL_TYPE_STRING) < 0)
66static void nftnl_expr_flow_build(
struct nlmsghdr *nlh,
67 const struct nftnl_expr *e)
71 if (e->flags & (1 << NFTNL_EXPR_FLOW_TABLE_NAME))
72 mnl_attr_put_strz(nlh, NFTA_FLOW_TABLE_NAME, flow->table_name);
75static int nftnl_expr_flow_parse(
struct nftnl_expr *e,
struct nlattr *attr)
78 struct nlattr *tb[NFTA_FLOW_MAX+1] = {};
81 if (mnl_attr_parse_nested(attr, nftnl_expr_flow_cb, tb) < 0)
84 if (tb[NFTA_FLOW_TABLE_NAME]) {
86 strdup(mnl_attr_get_str(tb[NFTA_FLOW_TABLE_NAME]));
87 if (!flow->table_name)
89 e->flags |= (1 << NFTNL_EXPR_FLOW_TABLE_NAME);
95static int nftnl_expr_flow_snprintf(
char *buf,
size_t remain,
96 uint32_t flags,
const struct nftnl_expr *e)
101 ret = snprintf(buf, remain,
"flowtable %s ", l->table_name);
102 SNPRINTF_BUFFER_SIZE(ret, remain, offset);
107static void nftnl_expr_flow_free(
const struct nftnl_expr *e)
111 xfree(flow->table_name);
114struct expr_ops expr_ops_flow = {
115 .name =
"flow_offload",
117 .max_attr = NFTA_FLOW_MAX,
118 .free = nftnl_expr_flow_free,
119 .set = nftnl_expr_flow_set,
120 .get = nftnl_expr_flow_get,
121 .parse = nftnl_expr_flow_parse,
122 .build = nftnl_expr_flow_build,
123 .output = nftnl_expr_flow_snprintf,