From: Patrick McHardy <kaber@trash.net>
To: pablo@netfilter.org
Cc: netfilter-devel@vger.kernel.org
Subject: [PATCH 1/3] concat: add concat subtype lookup/id helpers
Date: Sun, 11 Jan 2015 08:41:56 +0000 [thread overview]
Message-ID: <1420965718-24339-2-git-send-email-kaber@trash.net> (raw)
In-Reply-To: <1420965718-24339-1-git-send-email-kaber@trash.net>
Signed-off-by: Patrick McHardy <kaber@trash.net>
---
include/datatype.h | 16 ++++++++++++++++
src/datatype.c | 4 ++--
src/evaluate.c | 9 +++------
src/parser_bison.y | 3 +--
4 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/include/datatype.h b/include/datatype.h
index f05f987..3c3f42f 100644
--- a/include/datatype.h
+++ b/include/datatype.h
@@ -215,4 +215,20 @@ extern const struct datatype time_type;
extern const struct datatype *concat_type_alloc(uint32_t type);
extern void concat_type_destroy(const struct datatype *dtype);
+static inline uint32_t concat_subtype_add(uint32_t type, uint32_t subtype)
+{
+ return type << TYPE_BITS | subtype;
+}
+
+static inline uint32_t concat_subtype_id(uint32_t type, unsigned int n)
+{
+ return (type >> TYPE_BITS * n) & TYPE_MASK;
+}
+
+static inline const struct datatype *
+concat_subtype_lookup(uint32_t type, unsigned int n)
+{
+ return datatype_lookup(concat_subtype_id(type, n));
+}
+
#endif /* NFTABLES_DATATYPE_H */
diff --git a/src/datatype.c b/src/datatype.c
index 76f2af1..c93f76a 100644
--- a/src/datatype.c
+++ b/src/datatype.c
@@ -931,8 +931,8 @@ const struct datatype *concat_type_alloc(uint32_t type)
unsigned int size = 0, subtypes = 0, n;
n = div_round_up(fls(type), TYPE_BITS);
- while ((type >> TYPE_BITS * --n) & TYPE_MASK) {
- i = datatype_lookup((type >> TYPE_BITS * n) & TYPE_MASK);
+ while (concat_subtype_id(type, --n)) {
+ i = concat_subtype_lookup(type, n);
if (i == NULL)
return NULL;
diff --git a/src/evaluate.c b/src/evaluate.c
index 00c6d91..53f3cf0 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -612,25 +612,22 @@ static int expr_evaluate_concat(struct eval_ctx *ctx, struct expr **expr)
int off = dtype ? dtype->subtypes : 0;
unsigned int flags = EXPR_F_CONSTANT | EXPR_F_SINGLETON;
struct expr *i, *next;
- unsigned int n;
- n = 1;
list_for_each_entry_safe(i, next, &(*expr)->expressions, list) {
if (dtype && off == 0)
return expr_binary_error(ctx->msgs, i, *expr,
"unexpected concat component, "
"expecting %s",
dtype->desc);
- tmp = datatype_lookup((type >> TYPE_BITS * --off) & TYPE_MASK);
+
+ tmp = concat_subtype_lookup(type, --off);
expr_set_context(&ctx->ectx, tmp, tmp->size);
if (list_member_evaluate(ctx, &i) < 0)
return -1;
flags &= i->flags;
- ntype <<= TYPE_BITS;
- ntype |= i->dtype->type;
- n++;
+ ntype = concat_subtype_add(ntype, i->dtype->type);
}
(*expr)->flags |= flags;
diff --git a/src/parser_bison.y b/src/parser_bison.y
index b20f4de..6c46d09 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -1020,8 +1020,7 @@ type_identifier : identifier
state->msgs);
YYERROR;
}
- $$ <<= TYPE_BITS;
- $$ |= dtype->type;
+ $$ = concat_subtype_add($$, dtype->type);
}
;
--
2.1.0
next prev parent reply other threads:[~2015-01-11 8:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-11 8:41 [PATCH 0/3] nftables: concat preparation Patrick McHardy
2015-01-11 8:41 ` Patrick McHardy [this message]
2015-01-11 8:41 ` [PATCH 2/3] netlink_delinearize: add register parsing helper function Patrick McHardy
2015-01-11 8:41 ` [PATCH 3/3] netlink_linearize: add register dumping " Patrick McHardy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1420965718-24339-2-git-send-email-kaber@trash.net \
--to=kaber@trash.net \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).