summaryrefslogtreecommitdiffstats
path: root/src/expr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/expr.c')
-rw-r--r--src/expr.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/expr.c b/src/expr.c
index 80c4c36..4e32189 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -42,6 +42,9 @@ struct nftnl_expr *nftnl_expr_alloc(const char *name)
expr->flags |= (1 << NFTNL_EXPR_NAME);
expr->ops = ops;
+ if (ops->init)
+ ops->init(expr);
+
return expr;
}
@@ -68,6 +71,16 @@ int nftnl_expr_set(struct nftnl_expr *expr, uint16_t type,
case NFTNL_EXPR_NAME: /* cannot be modified */
return 0;
default:
+ if (type < NFTNL_EXPR_BASE || type > expr->ops->nftnl_max_attr)
+ return -1;
+
+ if (!expr->ops->attr_policy)
+ return -1;
+
+ if (expr->ops->attr_policy[type].maxlen &&
+ expr->ops->attr_policy[type].maxlen < data_len)
+ return -1;
+
if (expr->ops->set(expr, type, data, data_len) < 0)
return -1;
}
@@ -203,6 +216,7 @@ const char *nftnl_expr_get_str(const struct nftnl_expr *expr, uint16_t type)
return (const char *)nftnl_expr_get(expr, type, &data_len);
}
+EXPORT_SYMBOL(nftnl_expr_build_payload);
void nftnl_expr_build_payload(struct nlmsghdr *nlh, struct nftnl_expr *expr)
{
struct nlattr *nest;
@@ -266,19 +280,19 @@ err1:
}
EXPORT_SYMBOL(nftnl_expr_snprintf);
-int nftnl_expr_snprintf(char *buf, size_t size, const struct nftnl_expr *expr,
+int nftnl_expr_snprintf(char *buf, size_t remain, const struct nftnl_expr *expr,
uint32_t type, uint32_t flags)
{
int ret;
- unsigned int offset = 0, remain = size;
+ unsigned int offset = 0;
- if (size)
+ if (remain)
buf[0] = '\0';
- if (!expr->ops->snprintf)
+ if (!expr->ops->output || type != NFTNL_OUTPUT_DEFAULT)
return 0;
- ret = expr->ops->snprintf(buf + offset, remain, type, flags, expr);
+ ret = expr->ops->output(buf + offset, remain, flags, expr);
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
return offset;