From patchwork Sat Jun 1 12:59:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Westphal X-Patchwork-Id: 248080 X-Patchwork-Delegate: pablo@netfilter.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id F02E82C02A4 for ; Sat, 1 Jun 2013 23:01:06 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756367Ab3FANBC (ORCPT ); Sat, 1 Jun 2013 09:01:02 -0400 Received: from Chamillionaire.breakpoint.cc ([80.244.247.6]:55761 "EHLO Chamillionaire.breakpoint.cc" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756231Ab3FANAy (ORCPT ); Sat, 1 Jun 2013 09:00:54 -0400 Received: from fw by Chamillionaire.breakpoint.cc with local (Exim 4.72) (envelope-from ) id 1UilQT-0006il-2G; Sat, 01 Jun 2013 15:00:53 +0200 From: Florian Westphal To: netfilter-devel@vger.kernel.org Cc: Florian Westphal Subject: [PATCH 3/3] expect: consider all expect attributes when comparing Date: Sat, 1 Jun 2013 14:59:31 +0200 Message-Id: <1370091571-23140-3-git-send-email-fw@strlen.de> X-Mailer: git-send-email 1.8.1.5 In-Reply-To: <1370091571-23140-1-git-send-email-fw@strlen.de> References: <1370091571-23140-1-git-send-email-fw@strlen.de> Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org The expect cmp function ignored most of the attributes. Signed-off-by: Florian Westphal --- src/expect/compare.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 85 insertions(+), 10 deletions(-) diff --git a/src/expect/compare.c b/src/expect/compare.c index 484d7b1..6326706 100644 --- a/src/expect/compare.c +++ b/src/expect/compare.c @@ -35,6 +35,45 @@ static int exp_cmp(int attr, } 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_timeout(const struct nf_expect *exp1, const struct nf_expect *exp2, + unsigned int flags) +{ + return exp1->timeout == exp2->timeout; +} + +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) { @@ -42,32 +81,68 @@ cmp_exp_flags(const struct nf_expect *exp1, const struct nf_expect *exp2, } 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) { 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; + if (!exp_cmp(ATTR_EXP_TIMEOUT, exp1, exp2, flags, cmp_exp_timeout)) + return 0; + 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; }