summaryrefslogtreecommitdiffstats
path: root/src/expr/numgen.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/expr/numgen.c')
-rw-r--r--src/expr/numgen.c48
1 files changed, 18 insertions, 30 deletions
diff --git a/src/expr/numgen.c b/src/expr/numgen.c
index 4e0d541..5243d9d 100644
--- a/src/expr/numgen.c
+++ b/src/expr/numgen.c
@@ -1,11 +1,6 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* (C) 2016 by Laura Garcia <nevola@gmail.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
*/
#include <stdio.h>
@@ -29,22 +24,22 @@ struct nftnl_expr_ng {
static int
nftnl_expr_ng_set(struct nftnl_expr *e, uint16_t type,
- const void *data, uint32_t data_len)
+ const void *data, uint32_t data_len, uint32_t byteorder)
{
struct nftnl_expr_ng *ng = nftnl_expr_data(e);
switch (type) {
case NFTNL_EXPR_NG_DREG:
- memcpy(&ng->dreg, data, sizeof(ng->dreg));
+ memcpy(&ng->dreg, data, data_len);
break;
case NFTNL_EXPR_NG_MODULUS:
- memcpy(&ng->modulus, data, sizeof(ng->modulus));
+ memcpy(&ng->modulus, data, data_len);
break;
case NFTNL_EXPR_NG_TYPE:
- memcpy(&ng->type, data, sizeof(ng->type));
+ memcpy(&ng->type, data, data_len);
break;
case NFTNL_EXPR_NG_OFFSET:
- memcpy(&ng->offset, data, sizeof(ng->offset));
+ memcpy(&ng->offset, data, data_len);
break;
default:
return -1;
@@ -143,11 +138,11 @@ nftnl_expr_ng_parse(struct nftnl_expr *e, struct nlattr *attr)
}
static int
-nftnl_expr_ng_snprintf_default(char *buf, size_t size,
- const struct nftnl_expr *e)
+nftnl_expr_ng_snprintf(char *buf, size_t remain,
+ uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_ng *ng = nftnl_expr_data(e);
- int remain = size, offset = 0, ret;
+ int offset = 0, ret;
switch (ng->type) {
case NFT_NG_INCREMENTAL:
@@ -172,28 +167,21 @@ nftnl_expr_ng_snprintf_default(char *buf, size_t size,
return offset;
}
-static int
-nftnl_expr_ng_snprintf(char *buf, size_t len, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_ng_snprintf_default(buf, len, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
+static struct attr_policy numgen_attr_policy[__NFTNL_EXPR_NG_MAX] = {
+ [NFTNL_EXPR_NG_DREG] = { .maxlen = sizeof(uint32_t) },
+ [NFTNL_EXPR_NG_MODULUS] = { .maxlen = sizeof(uint32_t) },
+ [NFTNL_EXPR_NG_TYPE] = { .maxlen = sizeof(uint32_t) },
+ [NFTNL_EXPR_NG_OFFSET] = { .maxlen = sizeof(uint32_t) },
+};
struct expr_ops expr_ops_ng = {
.name = "numgen",
.alloc_len = sizeof(struct nftnl_expr_ng),
- .max_attr = NFTA_NG_MAX,
+ .nftnl_max_attr = __NFTNL_EXPR_NG_MAX - 1,
+ .attr_policy = numgen_attr_policy,
.set = nftnl_expr_ng_set,
.get = nftnl_expr_ng_get,
.parse = nftnl_expr_ng_parse,
.build = nftnl_expr_ng_build,
- .snprintf = nftnl_expr_ng_snprintf,
+ .output = nftnl_expr_ng_snprintf,
};