diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2012-01-04 17:16:39 +0100 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2012-01-04 17:16:39 +0100 |
commit | 8e63e483240687ee4c4325073d84926e39416bc9 (patch) | |
tree | 54848f691373638fc54c84c5f87938e18977f6b1 /src/expect/compare.c | |
parent | 849342adcb7099d23b39192a4369908bb0259eee (diff) |
expect: add nfexp_cmp
This patch adds nfexp_cmp that allows you to compare two expectation
objects.
This includes the extension of test_api for this new function.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/expect/compare.c')
-rw-r--r-- | src/expect/compare.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/expect/compare.c b/src/expect/compare.c new file mode 100644 index 0000000..65ec9c2 --- /dev/null +++ b/src/expect/compare.c @@ -0,0 +1,59 @@ +/* + * (C) 2005-2012 by Pablo Neira Ayuso <pablo@netfilter.org> + * (C) 2012 by Vyatta Inc. <http://www.vyatta.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/internal.h" + +static int exp_cmp(int attr, + const struct nf_expect *exp1, + const struct nf_expect *exp2, + unsigned int flags, + int (*cmp)(const struct nf_expect *exp1, + const struct nf_expect *exp2, + unsigned int flags)) +{ + if (test_bit(attr, exp1->set) && test_bit(attr, exp2->set)) { + return cmp(exp1, exp2, flags); + } else if (flags & NFCT_CMP_MASK && + test_bit(attr, exp1->set)) { + return 0; + } else if (flags & NFCT_CMP_STRICT) { + return 0; + } + return 1; +} + +static int +cmp_exp_flags(const struct nf_expect *exp1, const struct nf_expect *exp, + unsigned int flags) +{ + return (exp->flags == exp->flags); +} + +int __cmp_expect(const struct nf_expect *exp1, + const struct nf_expect *exp2, + unsigned int flags) +{ + if (!__cmp_orig((struct nf_conntrack *)&exp1->master, + (struct nf_conntrack *)&exp2->master, flags)) { + return 0; + } + if (!__cmp_orig((struct nf_conntrack *)&exp1->expected, + (struct nf_conntrack *)&exp2->expected, flags)) { + return 0; + } + if (!__cmp_orig((struct nf_conntrack *)&exp1->mask, + (struct nf_conntrack *)&exp2->mask, flags)) { + return 0; + } + if (!exp_cmp(ATTR_EXP_FLAGS, exp1, exp2, flags, cmp_exp_flags)) + return 0; + + return 1; +} |