summaryrefslogtreecommitdiffstats
path: root/src/numgen.c
diff options
context:
space:
mode:
authorLaura Garcia Liebana <nevola@gmail.com>2016-10-22 23:36:07 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2016-10-27 21:46:43 +0200
commitd4f9a8fb9e9acc09b0726e19e7c8e5faaa959803 (patch)
tree0277f97784fdda68d2e2acb6c8ba493135466a5f /src/numgen.c
parent8a7f6de536408336770e352cde939f8cb09a644d (diff)
src: add offset attribute for numgen expression
Add support to add an offset to the numgen generated value. Example: ct mark set numgen inc mod 2 offset 100 This will generate marks with serie like 100, 101, 100, ... Signed-off-by: Laura Garcia Liebana <nevola@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/numgen.c')
-rw-r--r--src/numgen.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/numgen.c b/src/numgen.c
index d9a43aa0..5c1d00a0 100644
--- a/src/numgen.c
+++ b/src/numgen.c
@@ -32,18 +32,22 @@ static void numgen_expr_print(const struct expr *expr)
{
printf("numgen %s mod %u", numgen_type_str(expr->numgen.type),
expr->numgen.mod);
+ if (expr->numgen.offset)
+ printf(" offset %u", expr->numgen.offset);
}
static bool numgen_expr_cmp(const struct expr *e1, const struct expr *e2)
{
return e1->numgen.type == e2->numgen.type &&
- e1->numgen.mod == e2->numgen.mod;
+ e1->numgen.mod == e2->numgen.mod &&
+ e1->numgen.offset == e2->numgen.offset;
}
static void numgen_expr_clone(struct expr *new, const struct expr *expr)
{
new->numgen.type = expr->numgen.type;
new->numgen.mod = expr->numgen.mod;
+ new->numgen.offset = expr->numgen.offset;
}
static const struct expr_ops numgen_expr_ops = {
@@ -55,7 +59,8 @@ static const struct expr_ops numgen_expr_ops = {
};
struct expr *numgen_expr_alloc(const struct location *loc,
- enum nft_ng_types type, uint32_t mod)
+ enum nft_ng_types type, uint32_t mod,
+ uint32_t offset)
{
struct expr *expr;
@@ -63,6 +68,7 @@ struct expr *numgen_expr_alloc(const struct location *loc,
BYTEORDER_HOST_ENDIAN, 4 * BITS_PER_BYTE);
expr->numgen.type = type;
expr->numgen.mod = mod;
+ expr->numgen.offset = offset;
return expr;
}