summaryrefslogtreecommitdiffstats
path: root/src/expr/counter.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/expr/counter.c')
-rw-r--r--src/expr/counter.c42
1 files changed, 14 insertions, 28 deletions
diff --git a/src/expr/counter.c b/src/expr/counter.c
index 89a602e..21e641b 100644
--- a/src/expr/counter.c
+++ b/src/expr/counter.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>
*/
@@ -29,19 +25,17 @@ struct nftnl_expr_counter {
static int
nftnl_expr_counter_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_counter *ctr = nftnl_expr_data(e);
switch(type) {
case NFTNL_EXPR_CTR_BYTES:
- memcpy(&ctr->bytes, data, sizeof(ctr->bytes));
+ memcpy(&ctr->bytes, data, data_len);
break;
case NFTNL_EXPR_CTR_PACKETS:
- memcpy(&ctr->pkts, data, sizeof(ctr->pkts));
+ memcpy(&ctr->pkts, data, data_len);
break;
- default:
- return -1;
}
return 0;
}
@@ -115,8 +109,9 @@ nftnl_expr_counter_parse(struct nftnl_expr *e, struct nlattr *attr)
return 0;
}
-static int nftnl_expr_counter_snprintf_default(char *buf, size_t len,
- const struct nftnl_expr *e)
+static int nftnl_expr_counter_snprintf(char *buf, size_t len,
+ uint32_t flags,
+ const struct nftnl_expr *e)
{
struct nftnl_expr_counter *ctr = nftnl_expr_data(e);
@@ -124,28 +119,19 @@ static int nftnl_expr_counter_snprintf_default(char *buf, size_t len,
ctr->pkts, ctr->bytes);
}
-static int nftnl_expr_counter_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_counter_snprintf_default(buf, len, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
+static struct attr_policy counter_attr_policy[__NFTNL_EXPR_CTR_MAX] = {
+ [NFTNL_EXPR_CTR_PACKETS] = { .maxlen = sizeof(uint64_t) },
+ [NFTNL_EXPR_CTR_BYTES] = { .maxlen = sizeof(uint64_t) },
+};
struct expr_ops expr_ops_counter = {
.name = "counter",
.alloc_len = sizeof(struct nftnl_expr_counter),
- .max_attr = NFTA_COUNTER_MAX,
+ .nftnl_max_attr = __NFTNL_EXPR_CTR_MAX - 1,
+ .attr_policy = counter_attr_policy,
.set = nftnl_expr_counter_set,
.get = nftnl_expr_counter_get,
.parse = nftnl_expr_counter_parse,
.build = nftnl_expr_counter_build,
- .snprintf = nftnl_expr_counter_snprintf,
+ .output = nftnl_expr_counter_snprintf,
};