summaryrefslogtreecommitdiffstats
path: root/src/ctnl.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2013-07-11 00:43:20 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2013-07-11 02:42:55 +0200
commit586382d9a8389ee553db019fd9be14a8a7c0b8ec (patch)
tree5f00a12a32920319c95c5b0acafff0c9957131f5 /src/ctnl.c
parent479a37a549abf197ce59a4ae1666d8cba80fe977 (diff)
conntrackd: simplify expectation filtering
This patch simplifies the expectation filtering by looking up for the master conntrack. If it does not exists, then we assume that we don't want this expectation either. This simplification also fixes the current broken expectation filtering, since the master conntrack from expectations has neither reply tuple nor state, however, the filtering code assumes the opposite. This partially reverts (479a37a conntrackd: fix crash with IPv6 expectation in the filtering code) since it was incorrectly setting the reply tuple of the master conntrack. Thanks to Bill Fink for providing feedback to resolve this issue. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/ctnl.c')
-rw-r--r--src/ctnl.c37
1 files changed, 9 insertions, 28 deletions
diff --git a/src/ctnl.c b/src/ctnl.c
index 9e1cfa1..10b5f4c 100644
--- a/src/ctnl.c
+++ b/src/ctnl.c
@@ -211,35 +211,14 @@ out:
return NFCT_CB_CONTINUE;
}
-static const struct nf_conntrack *exp_get_master_ct(struct nf_expect *exp)
-{
- struct nf_conntrack *master =
- (struct nf_conntrack *)nfexp_get_attr(exp, ATTR_EXP_MASTER);
-
- /* The function ct_filter_conntrack needs the source address of the
- * reply tuple, emulate it.
- */
- switch (nfct_get_attr_u8(master, ATTR_L3PROTO)) {
- case AF_INET:
- nfct_set_attr_u32(master, ATTR_REPL_IPV4_SRC,
- nfct_get_attr_u32(master, ATTR_IPV4_DST));
- break;
- case AF_INET6:
- nfct_set_attr(master, ATTR_REPL_IPV6_SRC,
- nfct_get_attr(master, ATTR_IPV6_DST));
- break;
- }
-
- return master;
-}
-
static int exp_event_handler(const struct nlmsghdr *nlh,
enum nf_conntrack_msg_type type,
struct nf_expect *exp,
void *data)
{
int origin_type;
- const struct nf_conntrack *master = exp_get_master_ct(exp);
+ const struct nf_conntrack *master =
+ nfexp_get_attr(exp, ATTR_EXP_MASTER);
STATE(stats).nl_events_received++;
@@ -247,7 +226,7 @@ static int exp_event_handler(const struct nlmsghdr *nlh,
STATE(stats).nl_events_filtered++;
goto out;
}
- if (ct_filter_conntrack(master, 1))
+ if (ct_filter_master(master))
return NFCT_CB_CONTINUE;
origin_type = origin_find(nlh);
@@ -296,12 +275,13 @@ static int dump_handler(enum nf_conntrack_msg_type type,
static int exp_dump_handler(enum nf_conntrack_msg_type type,
struct nf_expect *exp, void *data)
{
- const struct nf_conntrack *master = exp_get_master_ct(exp);
+ const struct nf_conntrack *master =
+ nfexp_get_attr(exp, ATTR_EXP_MASTER);
if (!exp_filter_find(STATE(exp_filter), exp))
return NFCT_CB_CONTINUE;
- if (ct_filter_conntrack(master, 1))
+ if (ct_filter_master(master))
return NFCT_CB_CONTINUE;
switch(type) {
@@ -329,12 +309,13 @@ static int get_handler(enum nf_conntrack_msg_type type,
static int exp_get_handler(enum nf_conntrack_msg_type type,
struct nf_expect *exp, void *data)
{
- const struct nf_conntrack *master = exp_get_master_ct(exp);
+ const struct nf_conntrack *master =
+ nfexp_get_attr(exp, ATTR_EXP_MASTER);
if (!exp_filter_find(STATE(exp_filter), exp))
return NFCT_CB_CONTINUE;
- if (ct_filter_conntrack(master, 1))
+ if (ct_filter_master(master))
return NFCT_CB_CONTINUE;
STATE(get_retval) = 1;