diff options
Diffstat (limited to 'src/expr/ct.c')
| -rw-r--r-- | src/expr/ct.c | 80 |
1 files changed, 20 insertions, 60 deletions
diff --git a/src/expr/ct.c b/src/expr/ct.c index 124de9d..4117eee 100644 --- a/src/expr/ct.c +++ b/src/expr/ct.c @@ -1,11 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * (C) 2012-2013 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> */ @@ -33,25 +29,23 @@ struct nftnl_expr_ct { static int nftnl_expr_ct_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_ct *ct = nftnl_expr_data(e); switch(type) { case NFTNL_EXPR_CT_KEY: - memcpy(&ct->key, data, sizeof(ct->key)); + memcpy(&ct->key, data, data_len); break; case NFTNL_EXPR_CT_DIR: - memcpy(&ct->dir, data, sizeof(ct->dir)); + memcpy(&ct->dir, data, data_len); break; case NFTNL_EXPR_CT_DREG: - memcpy(&ct->dreg, data, sizeof(ct->dreg)); + memcpy(&ct->dreg, data, data_len); break; case NFTNL_EXPR_CT_SREG: - memcpy(&ct->sreg, data, sizeof(ct->sreg)); + memcpy(&ct->sreg, data, data_len); break; - default: - return -1; } return 0; } @@ -177,24 +171,12 @@ static const char *ctkey2str_array[NFT_CT_MAX + 1] = { static const char *ctkey2str(uint32_t ctkey) { - if (ctkey >= NFT_CT_MAX) + if (ctkey > NFT_CT_MAX) return "unknown"; return ctkey2str_array[ctkey]; } -static inline int str2ctkey(const char *ctkey) -{ - int i; - - for (i = 0; i < NFT_CT_MAX; i++) { - if (strcmp(ctkey2str_array[i], ctkey) == 0) - return i; - } - - return -1; -} - static const char *ctdir2str(uint8_t ctdir) { switch (ctdir) { @@ -207,30 +189,15 @@ static const char *ctdir2str(uint8_t ctdir) } } -static inline int str2ctdir(const char *str, uint8_t *ctdir) -{ - if (strcmp(str, "original") == 0) { - *ctdir = IP_CT_DIR_ORIGINAL; - return 0; - } - - if (strcmp(str, "reply") == 0) { - *ctdir = IP_CT_DIR_REPLY; - return 0; - } - - return -1; -} - static int -nftnl_expr_ct_snprintf_default(char *buf, size_t size, - const struct nftnl_expr *e) +nftnl_expr_ct_snprintf(char *buf, size_t remain, + uint32_t flags, const struct nftnl_expr *e) { - int ret, remain = size, offset = 0; struct nftnl_expr_ct *ct = nftnl_expr_data(e); + int ret, offset = 0; if (e->flags & (1 << NFTNL_EXPR_CT_SREG)) { - ret = snprintf(buf, size, "set %s with reg %u ", + ret = snprintf(buf, remain, "set %s with reg %u ", ctkey2str(ct->key), ct->sreg); SNPRINTF_BUFFER_SIZE(ret, remain, offset); } @@ -250,28 +217,21 @@ nftnl_expr_ct_snprintf_default(char *buf, size_t size, return offset; } -static int -nftnl_expr_ct_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_ct_snprintf_default(buf, len, e); - case NFTNL_OUTPUT_XML: - case NFTNL_OUTPUT_JSON: - default: - break; - } - return -1; -} +static struct attr_policy ct_attr_policy[__NFTNL_EXPR_CT_MAX] = { + [NFTNL_EXPR_CT_DREG] = { .maxlen = sizeof(uint32_t) }, + [NFTNL_EXPR_CT_KEY] = { .maxlen = sizeof(uint32_t) }, + [NFTNL_EXPR_CT_DIR] = { .maxlen = sizeof(uint8_t) }, + [NFTNL_EXPR_CT_SREG] = { .maxlen = sizeof(uint32_t) }, +}; struct expr_ops expr_ops_ct = { .name = "ct", .alloc_len = sizeof(struct nftnl_expr_ct), - .max_attr = NFTA_CT_MAX, + .nftnl_max_attr = __NFTNL_EXPR_CT_MAX - 1, + .attr_policy = ct_attr_policy, .set = nftnl_expr_ct_set, .get = nftnl_expr_ct_get, .parse = nftnl_expr_ct_parse, .build = nftnl_expr_ct_build, - .snprintf = nftnl_expr_ct_snprintf, + .output = nftnl_expr_ct_snprintf, }; |
