summaryrefslogtreecommitdiffstats
path: root/src/expect/compare.c
blob: 65ec9c228c2b752b43b0a6b3a721c7f1050be999 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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;
}