From a3e1073c74ebcef3446b53ca9d8464dcc86d085c Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Sat, 1 Jun 2013 14:37:12 +0200 Subject: expect: consider all expect attributes when comparing The expect cmp function ignored most of the attributes. Signed-off-by: Florian Westphal --- src/expect/compare.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 78 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/expect/compare.c b/src/expect/compare.c index 484d7b1..89ca0f8 100644 --- a/src/expect/compare.c +++ b/src/expect/compare.c @@ -34,6 +34,38 @@ static int exp_cmp(int attr, return 1; } +static int +cmp_exp_master(const struct nf_expect *exp1, const struct nf_expect *exp2, + unsigned int flags) +{ + return __cmp_orig((struct nf_conntrack *)&exp1->master, + (struct nf_conntrack *)&exp2->master, flags); +} + +static int +cmp_exp_expected(const struct nf_expect *exp1, const struct nf_expect *exp2, + unsigned int flags) +{ + return __cmp_orig((struct nf_conntrack *)&exp1->expected, + (struct nf_conntrack *)&exp2->expected, flags); +} + +static int +cmp_exp_mask(const struct nf_expect *exp1, const struct nf_expect *exp2, + unsigned int flags) +{ + return __cmp_orig((struct nf_conntrack *)&exp1->mask, + (struct nf_conntrack *)&exp2->mask, flags); + +} + +static int +cmp_exp_zone(const struct nf_expect *exp1, const struct nf_expect *exp2, + unsigned int flags) +{ + return exp1->zone == exp2->zone; +} + static int cmp_exp_flags(const struct nf_expect *exp1, const struct nf_expect *exp2, unsigned int flags) @@ -41,6 +73,13 @@ cmp_exp_flags(const struct nf_expect *exp1, const struct nf_expect *exp2, return (exp1->flags == exp2->flags); } +static int +cmp_exp_hname(const struct nf_expect *exp1, const struct nf_expect *exp2, + unsigned int flags) +{ + return strcmp(exp1->helper_name, exp2->helper_name) == 0; +} + static int cmp_exp_class(const struct nf_expect *exp1, const struct nf_expect *exp2, unsigned int flags) @@ -48,26 +87,55 @@ cmp_exp_class(const struct nf_expect *exp1, const struct nf_expect *exp2, return (exp1->class == exp2->class); } +static int +cmp_exp_natt(const struct nf_expect *exp1, const struct nf_expect *exp2, + unsigned int flags) +{ + return __cmp_orig((struct nf_conntrack *)&exp1->nat, + (struct nf_conntrack *)&exp2->nat, flags); + +} + +static int +cmp_exp_natdir(const struct nf_expect *exp1, const struct nf_expect *exp2, + unsigned int flags) +{ + return exp1->nat_dir == exp2->nat_dir; +} + +static int +cmp_exp_expfn(const struct nf_expect *exp1, const struct nf_expect *exp2, + unsigned int flags) +{ + return strcmp(exp1->expectfn, exp2->expectfn) == 0; +} + + 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)) { + if (!exp_cmp(ATTR_EXP_MASTER, exp1, exp2, flags, cmp_exp_master)) return 0; - } - if (!__cmp_orig((struct nf_conntrack *)&exp1->expected, - (struct nf_conntrack *)&exp2->expected, flags)) { + if (!exp_cmp(ATTR_EXP_EXPECTED, exp1, exp2, flags, cmp_exp_expected)) return 0; - } - if (!__cmp_orig((struct nf_conntrack *)&exp1->mask, - (struct nf_conntrack *)&exp2->mask, flags)) { + if (!exp_cmp(ATTR_EXP_MASK, exp1, exp2, flags, cmp_exp_mask)) + return 0; + /* ATTR_EXP_TIMEOUT is intentionally not compared at this time; the expectations should + * be considered equal if only the timeout is different */ + if (!exp_cmp(ATTR_EXP_ZONE, exp1, exp2, flags, cmp_exp_zone)) return 0; - } if (!exp_cmp(ATTR_EXP_FLAGS, exp1, exp2, flags, cmp_exp_flags)) return 0; + if (!exp_cmp(ATTR_EXP_HELPER_NAME, exp1, exp2, flags, cmp_exp_hname)) + return 0; if (!exp_cmp(ATTR_EXP_CLASS, exp1, exp2, flags, cmp_exp_class)) return 0; - + if (!exp_cmp(ATTR_EXP_NAT_TUPLE, exp1, exp2, flags, cmp_exp_natt)) + return 0; + if (!exp_cmp(ATTR_EXP_NAT_DIR, exp1, exp2, flags, cmp_exp_natdir)) + return 0; + if (!exp_cmp(ATTR_EXP_FN, exp1, exp2, flags, cmp_exp_expfn)) + return 0; return 1; } -- cgit v1.2.3