diff options
Diffstat (limited to 'src/expr/rt.c')
| -rw-r--r-- | src/expr/rt.c | 54 |
1 files changed, 13 insertions, 41 deletions
diff --git a/src/expr/rt.c b/src/expr/rt.c index 0fce72d..c0d4311 100644 --- a/src/expr/rt.c +++ b/src/expr/rt.c @@ -1,10 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (c) 2016 Anders K. Pedersen <akp@cohaesio.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> @@ -26,19 +22,17 @@ struct nftnl_expr_rt { static int nftnl_expr_rt_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_rt *rt = nftnl_expr_data(e); switch (type) { case NFTNL_EXPR_RT_KEY: - memcpy(&rt->key, data, sizeof(rt->key)); + memcpy(&rt->key, data, data_len); break; case NFTNL_EXPR_RT_DREG: - memcpy(&rt->dreg, data, sizeof(rt->dreg)); + memcpy(&rt->dreg, data, data_len); break; - default: - return -1; } return 0; } @@ -128,22 +122,9 @@ static const char *rt_key2str(uint8_t key) return "unknown"; } -static inline int str2rt_key(const char *str) -{ - int i; - - for (i = 0; i < NFT_RT_MAX; i++) { - if (strcmp(str, rt_key2str_array[i]) == 0) - return i; - } - - errno = EINVAL; - return -1; -} - static int -nftnl_expr_rt_snprintf_default(char *buf, size_t len, - const struct nftnl_expr *e) +nftnl_expr_rt_snprintf(char *buf, size_t len, + uint32_t flags, const struct nftnl_expr *e) { struct nftnl_expr_rt *rt = nftnl_expr_data(e); @@ -154,28 +135,19 @@ nftnl_expr_rt_snprintf_default(char *buf, size_t len, return 0; } -static int -nftnl_expr_rt_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_rt_snprintf_default(buf, len, e); - case NFTNL_OUTPUT_XML: - case NFTNL_OUTPUT_JSON: - default: - break; - } - return -1; -} +static struct attr_policy rt_attr_policy[__NFTNL_EXPR_RT_MAX] = { + [NFTNL_EXPR_RT_KEY] = { .maxlen = sizeof(uint32_t) }, + [NFTNL_EXPR_RT_DREG] = { .maxlen = sizeof(uint32_t) }, +}; struct expr_ops expr_ops_rt = { .name = "rt", .alloc_len = sizeof(struct nftnl_expr_rt), - .max_attr = NFTA_RT_MAX, + .nftnl_max_attr = __NFTNL_EXPR_RT_MAX - 1, + .attr_policy = rt_attr_policy, .set = nftnl_expr_rt_set, .get = nftnl_expr_rt_get, .parse = nftnl_expr_rt_parse, .build = nftnl_expr_rt_build, - .snprintf = nftnl_expr_rt_snprintf, + .output = nftnl_expr_rt_snprintf, }; |
