summaryrefslogtreecommitdiffstats
path: root/src/expr/exthdr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/expr/exthdr.c')
-rw-r--r--src/expr/exthdr.c56
1 files changed, 28 insertions, 28 deletions
diff --git a/src/expr/exthdr.c b/src/expr/exthdr.c
index e5f714b..453902c 100644
--- a/src/expr/exthdr.c
+++ b/src/expr/exthdr.c
@@ -46,28 +46,26 @@ nftnl_expr_exthdr_set(struct nftnl_expr *e, uint16_t type,
switch(type) {
case NFTNL_EXPR_EXTHDR_DREG:
- memcpy(&exthdr->dreg, data, sizeof(exthdr->dreg));
+ memcpy(&exthdr->dreg, data, data_len);
break;
case NFTNL_EXPR_EXTHDR_TYPE:
- memcpy(&exthdr->type, data, sizeof(exthdr->type));
+ memcpy(&exthdr->type, data, data_len);
break;
case NFTNL_EXPR_EXTHDR_OFFSET:
- memcpy(&exthdr->offset, data, sizeof(exthdr->offset));
+ memcpy(&exthdr->offset, data, data_len);
break;
case NFTNL_EXPR_EXTHDR_LEN:
- memcpy(&exthdr->len, data, sizeof(exthdr->len));
+ memcpy(&exthdr->len, data, data_len);
break;
case NFTNL_EXPR_EXTHDR_OP:
- memcpy(&exthdr->op, data, sizeof(exthdr->op));
+ memcpy(&exthdr->op, data, data_len);
break;
case NFTNL_EXPR_EXTHDR_FLAGS:
- memcpy(&exthdr->flags, data, sizeof(exthdr->flags));
+ memcpy(&exthdr->flags, data, data_len);
break;
case NFTNL_EXPR_EXTHDR_SREG:
- memcpy(&exthdr->sreg, data, sizeof(exthdr->sreg));
+ memcpy(&exthdr->sreg, data, data_len);
break;
- default:
- return -1;
}
return 0;
}
@@ -235,8 +233,9 @@ static inline int str2exthdr_type(const char *str)
return -1;
}
-static int nftnl_expr_exthdr_snprintf_default(char *buf, size_t len,
- const struct nftnl_expr *e)
+static int
+nftnl_expr_exthdr_snprintf(char *buf, size_t len,
+ uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_exthdr *exthdr = nftnl_expr_data(e);
@@ -246,35 +245,36 @@ static int nftnl_expr_exthdr_snprintf_default(char *buf, size_t len,
exthdr->offset,
exthdr->flags & NFT_EXTHDR_F_PRESENT ? " present" : "",
exthdr->dreg);
- else
+ else if (e->flags & (1 << NFTNL_EXPR_EXTHDR_SREG))
return snprintf(buf, len, "write%s reg %u => %ub @ %u + %u ",
op2str(exthdr->op), exthdr->sreg, exthdr->len, exthdr->type,
exthdr->offset);
+ else if (exthdr->op == NFT_EXTHDR_OP_TCPOPT && exthdr->len == 0)
+ return snprintf(buf, len, "reset tcpopt %u ", exthdr->type);
+ else
+ return snprintf(buf, len, "op %u len %u type %u offset %u ",
+ exthdr->op, exthdr->len, exthdr->type, exthdr->offset);
}
-static int
-nftnl_expr_exthdr_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_exthdr_snprintf_default(buf, len, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
+static struct attr_policy exthdr_attr_policy[__NFTNL_EXPR_EXTHDR_MAX] = {
+ [NFTNL_EXPR_EXTHDR_DREG] = { .maxlen = sizeof(uint32_t) },
+ [NFTNL_EXPR_EXTHDR_TYPE] = { .maxlen = sizeof(uint8_t) },
+ [NFTNL_EXPR_EXTHDR_OFFSET] = { .maxlen = sizeof(uint32_t) },
+ [NFTNL_EXPR_EXTHDR_LEN] = { .maxlen = sizeof(uint32_t) },
+ [NFTNL_EXPR_EXTHDR_FLAGS] = { .maxlen = sizeof(uint32_t) },
+ [NFTNL_EXPR_EXTHDR_OP] = { .maxlen = sizeof(uint32_t) },
+ [NFTNL_EXPR_EXTHDR_SREG] = { .maxlen = sizeof(uint32_t) },
+};
struct expr_ops expr_ops_exthdr = {
.name = "exthdr",
.alloc_len = sizeof(struct nftnl_expr_exthdr),
- .max_attr = NFTA_EXTHDR_MAX,
+ .nftnl_max_attr = __NFTNL_EXPR_EXTHDR_MAX - 1,
+ .attr_policy = exthdr_attr_policy,
.set = nftnl_expr_exthdr_set,
.get = nftnl_expr_exthdr_get,
.parse = nftnl_expr_exthdr_parse,
.build = nftnl_expr_exthdr_build,
- .snprintf = nftnl_expr_exthdr_snprintf,
+ .output = nftnl_expr_exthdr_snprintf,
};