diff options
Diffstat (limited to 'src/expr/tproxy.c')
| -rw-r--r-- | src/expr/tproxy.c | 44 |
1 files changed, 16 insertions, 28 deletions
diff --git a/src/expr/tproxy.c b/src/expr/tproxy.c index 3827b75..630dffe 100644 --- a/src/expr/tproxy.c +++ b/src/expr/tproxy.c @@ -1,10 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (c) 2018 Máté Eckl <ecklm94@gmail.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 "internal.h" @@ -28,22 +24,20 @@ struct nftnl_expr_tproxy { static int nftnl_expr_tproxy_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_tproxy *tproxy = nftnl_expr_data(e); switch(type) { case NFTNL_EXPR_TPROXY_FAMILY: - memcpy(&tproxy->family, data, sizeof(tproxy->family)); + memcpy(&tproxy->family, data, data_len); break; case NFTNL_EXPR_TPROXY_REG_ADDR: - memcpy(&tproxy->sreg_addr, data, sizeof(tproxy->sreg_addr)); + memcpy(&tproxy->sreg_addr, data, data_len); break; case NFTNL_EXPR_TPROXY_REG_PORT: - memcpy(&tproxy->sreg_port, data, sizeof(tproxy->sreg_port)); + memcpy(&tproxy->sreg_port, data, data_len); break; - default: - return -1; } return 0; @@ -135,11 +129,11 @@ nftnl_expr_tproxy_build(struct nlmsghdr *nlh, const struct nftnl_expr *e) } static int -nftnl_expr_tproxy_snprintf_default(char *buf, size_t size, - const struct nftnl_expr *e) +nftnl_expr_tproxy_snprintf(char *buf, size_t remain, + uint32_t flags, const struct nftnl_expr *e) { struct nftnl_expr_tproxy *tproxy = nftnl_expr_data(e); - int remain = size, offset = 0, ret = 0; + int offset = 0, ret = 0; if (tproxy->family != NFTA_TPROXY_UNSPEC) { ret = snprintf(buf + offset, remain, "%s ", @@ -162,26 +156,20 @@ nftnl_expr_tproxy_snprintf_default(char *buf, size_t size, return offset; } -static int -nftnl_expr_tproxy_snprintf(char *buf, size_t size, uint32_t type, - uint32_t flags, const struct nftnl_expr *e) -{ - switch (type) { - case NFTNL_OUTPUT_DEFAULT: - return nftnl_expr_tproxy_snprintf_default(buf, size, e); - default: - break; - } - return -1; -} +static struct attr_policy tproxy_attr_policy[__NFTNL_EXPR_TPROXY_MAX] = { + [NFTNL_EXPR_TPROXY_FAMILY] = { .maxlen = sizeof(uint32_t) }, + [NFTNL_EXPR_TPROXY_REG_ADDR] = { .maxlen = sizeof(uint32_t) }, + [NFTNL_EXPR_TPROXY_REG_PORT] = { .maxlen = sizeof(uint32_t) }, +}; struct expr_ops expr_ops_tproxy = { .name = "tproxy", .alloc_len = sizeof(struct nftnl_expr_tproxy), - .max_attr = NFTA_TPROXY_MAX, + .nftnl_max_attr = __NFTNL_EXPR_TPROXY_MAX - 1, + .attr_policy = tproxy_attr_policy, .set = nftnl_expr_tproxy_set, .get = nftnl_expr_tproxy_get, .parse = nftnl_expr_tproxy_parse, .build = nftnl_expr_tproxy_build, - .snprintf = nftnl_expr_tproxy_snprintf, + .output = nftnl_expr_tproxy_snprintf, }; |
