summaryrefslogtreecommitdiffstats
path: root/src/expr/target.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/expr/target.c')
-rw-r--r--src/expr/target.c36
1 files changed, 14 insertions, 22 deletions
diff --git a/src/expr/target.c b/src/expr/target.c
index 9100038..6b590f5 100644
--- a/src/expr/target.c
+++ b/src/expr/target.c
@@ -1,11 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* (C) 2012 by Pablo Neira Ayuso <pablo@netfilter.org>
*
- * 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.
- *
* This code has been sponsored by Sophos Astaro <http://www.sophos.com>
*/
@@ -36,7 +32,7 @@ struct nftnl_expr_target {
static int
nftnl_expr_target_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_target *tg = nftnl_expr_data(e);
@@ -46,7 +42,7 @@ nftnl_expr_target_set(struct nftnl_expr *e, uint16_t type,
(const char *) data);
break;
case NFTNL_EXPR_TG_REV:
- memcpy(&tg->rev, data, sizeof(tg->rev));
+ memcpy(&tg->rev, data, data_len);
break;
case NFTNL_EXPR_TG_INFO:
if (e->flags & (1 << NFTNL_EXPR_TG_INFO))
@@ -55,8 +51,6 @@ nftnl_expr_target_set(struct nftnl_expr *e, uint16_t type,
tg->data = data;
tg->data_len = data_len;
break;
- default:
- return -1;
}
return 0;
}
@@ -165,21 +159,12 @@ static int nftnl_expr_target_parse(struct nftnl_expr *e, struct nlattr *attr)
}
static int
-nftnl_expr_target_snprintf(char *buf, size_t len, uint32_t type,
+nftnl_expr_target_snprintf(char *buf, size_t len,
uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_target *target = nftnl_expr_data(e);
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return snprintf(buf, len, "name %s rev %u ",
- target->name, target->rev);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
+ return snprintf(buf, len, "name %s rev %u ", target->name, target->rev);
}
static void nftnl_expr_target_free(const struct nftnl_expr *e)
@@ -189,14 +174,21 @@ static void nftnl_expr_target_free(const struct nftnl_expr *e)
xfree(target->data);
}
+static struct attr_policy target_attr_policy[__NFTNL_EXPR_TG_MAX] = {
+ [NFTNL_EXPR_TG_NAME] = { .maxlen = XT_EXTENSION_MAXNAMELEN },
+ [NFTNL_EXPR_TG_REV] = { .maxlen = sizeof(uint32_t) },
+ [NFTNL_EXPR_TG_INFO] = { .maxlen = 0 },
+};
+
struct expr_ops expr_ops_target = {
.name = "target",
.alloc_len = sizeof(struct nftnl_expr_target),
- .max_attr = NFTA_TARGET_MAX,
+ .nftnl_max_attr = __NFTNL_EXPR_TG_MAX - 1,
+ .attr_policy = target_attr_policy,
.free = nftnl_expr_target_free,
.set = nftnl_expr_target_set,
.get = nftnl_expr_target_get,
.parse = nftnl_expr_target_parse,
.build = nftnl_expr_target_build,
- .snprintf = nftnl_expr_target_snprintf,
+ .output = nftnl_expr_target_snprintf,
};