diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2013-07-13 21:21:27 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2013-07-13 21:35:23 +0200 |
commit | 4dd0772911a2c92a43d4e4aecf305fba498be106 (patch) | |
tree | 0b40bca77b673de3102c8466d6b25ce07711fb99 /src/expr_ops.c | |
parent | 013227cb6f13cbab2fbccbeb750199a051fd7a43 (diff) |
expr: use __attribute__((constructor)) to register expression
Instead of manual array registration.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/expr_ops.c')
-rw-r--r-- | src/expr_ops.c | 49 |
1 files changed, 10 insertions, 39 deletions
diff --git a/src/expr_ops.c b/src/expr_ops.c index da4c194..d0315a3 100644 --- a/src/expr_ops.c +++ b/src/expr_ops.c @@ -1,51 +1,22 @@ #include <string.h> +#include <linux_list.h> #include "expr_ops.h" -extern struct expr_ops expr_ops_bitwise; -extern struct expr_ops expr_ops_byteorder; -extern struct expr_ops expr_ops_cmp; -extern struct expr_ops expr_ops_counter; -extern struct expr_ops expr_ops_ct; -extern struct expr_ops expr_ops_exthdr; -extern struct expr_ops expr_ops_immediate; -extern struct expr_ops expr_ops_limit; -extern struct expr_ops expr_ops_log; -extern struct expr_ops expr_ops_lookup; -extern struct expr_ops expr_ops_match; -extern struct expr_ops expr_ops_meta; -extern struct expr_ops expr_ops_nat; -extern struct expr_ops expr_ops_payload; -extern struct expr_ops expr_ops_target; +static LIST_HEAD(expr_ops_list); -struct expr_ops *expr_ops[] = { - &expr_ops_bitwise, - &expr_ops_byteorder, - &expr_ops_cmp, - &expr_ops_counter, - &expr_ops_ct, - &expr_ops_exthdr, - &expr_ops_immediate, - &expr_ops_match, - &expr_ops_meta, - &expr_ops_nat, - &expr_ops_payload, - &expr_ops_target, - &expr_ops_limit, - &expr_ops_log, - &expr_ops_lookup, - NULL, -}; +void nft_expr_ops_register(struct expr_ops *ops) +{ + list_add_tail(&ops->head, &expr_ops_list); +} struct expr_ops *nft_expr_ops_lookup(const char *name) { - int i = 0; - - while (expr_ops[i] != NULL) { - if (strcmp(expr_ops[i]->name, name) == 0) - return expr_ops[i]; + struct expr_ops *ops; - i++; + list_for_each_entry(ops, &expr_ops_list, head) { + if (strcmp(ops->name, name) == 0) + return ops; } return NULL; |