diff options
Diffstat (limited to 'src/expr/fib.c')
| -rw-r--r-- | src/expr/fib.c | 46 |
1 files changed, 16 insertions, 30 deletions
diff --git a/src/expr/fib.c b/src/expr/fib.c index 9475af4..31750da 100644 --- a/src/expr/fib.c +++ b/src/expr/fib.c @@ -1,11 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2016 Red Hat GmbH * Author: Florian Westphal <fw@strlen.de> - * - * 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 +25,20 @@ struct nftnl_expr_fib { static int nftnl_expr_fib_set(struct nftnl_expr *e, uint16_t result, - const void *data, uint32_t data_len) + const void *data, uint32_t data_len, uint32_t byteorder) { struct nftnl_expr_fib *fib = nftnl_expr_data(e); switch (result) { case NFTNL_EXPR_FIB_RESULT: - memcpy(&fib->result, data, sizeof(fib->result)); + memcpy(&fib->result, data, data_len); break; case NFTNL_EXPR_FIB_DREG: - memcpy(&fib->dreg, data, sizeof(fib->dreg)); + memcpy(&fib->dreg, data, data_len); break; case NFTNL_EXPR_FIB_FLAGS: - memcpy(&fib->flags, data, sizeof(fib->flags)); + memcpy(&fib->flags, data, data_len); break; - default: - return -1; } return 0; } @@ -143,13 +137,13 @@ static const char *fib_type_str(enum nft_fib_result r) } static int -nftnl_expr_fib_snprintf_default(char *buf, size_t size, - const struct nftnl_expr *e) +nftnl_expr_fib_snprintf(char *buf, size_t remain, + uint32_t printflags, const struct nftnl_expr *e) { struct nftnl_expr_fib *fib = nftnl_expr_data(e); - int remain = size, offset = 0, ret, i; uint32_t flags = fib->flags & ~NFTA_FIB_F_PRESENT; uint32_t present_flag = fib->flags & NFTA_FIB_F_PRESENT; + int offset = 0, ret, i; static const struct { int bit; const char *name; @@ -190,28 +184,20 @@ nftnl_expr_fib_snprintf_default(char *buf, size_t size, return offset; } -static int -nftnl_expr_fib_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_fib_snprintf_default(buf, len, e); - case NFTNL_OUTPUT_XML: - case NFTNL_OUTPUT_JSON: - default: - break; - } - return -1; -} +static struct attr_policy fib_attr_policy[__NFTNL_EXPR_FIB_MAX] = { + [NFTNL_EXPR_FIB_DREG] = { .maxlen = sizeof(uint32_t) }, + [NFTNL_EXPR_FIB_RESULT] = { .maxlen = sizeof(uint32_t) }, + [NFTNL_EXPR_FIB_FLAGS] = { .maxlen = sizeof(uint32_t) }, +}; struct expr_ops expr_ops_fib = { .name = "fib", .alloc_len = sizeof(struct nftnl_expr_fib), - .max_attr = NFTA_FIB_MAX, + .nftnl_max_attr = __NFTNL_EXPR_FIB_MAX - 1, + .attr_policy = fib_attr_policy, .set = nftnl_expr_fib_set, .get = nftnl_expr_fib_get, .parse = nftnl_expr_fib_parse, .build = nftnl_expr_fib_build, - .snprintf = nftnl_expr_fib_snprintf, + .output = nftnl_expr_fib_snprintf, }; |
