Skip to content

Commit

Permalink
netfilter: nf_conntrack: add nf_ct_kill()
Browse files Browse the repository at this point in the history
Encapsulate the common

	if (del_timer(&ct->timeout))
		ct->timeout.function((unsigned long)ct)

sequence in a new function.

Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Patrick McHardy authored and David S. Miller committed Jun 9, 2008
1 parent 31d8519 commit 5109176
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 16 deletions.
2 changes: 2 additions & 0 deletions include/net/netfilter/nf_conntrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ static inline void nf_ct_refresh(struct nf_conn *ct,
__nf_ct_refresh_acct(ct, 0, skb, extra_jiffies, 0);
}

extern void nf_ct_kill(struct nf_conn *ct);

/* These are for NAT. Icky. */
/* Update TCP window tracking data when NAT mangles the packet */
extern void nf_conntrack_tcp_update(const struct sk_buff *skb,
Expand Down
5 changes: 2 additions & 3 deletions net/ipv4/netfilter/nf_conntrack_proto_icmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ static int icmp_packet(struct nf_conn *ct,
means this will only run once even if count hits zero twice
(theoretically possible with SMP) */
if (CTINFO2DIR(ctinfo) == IP_CT_DIR_REPLY) {
if (atomic_dec_and_test(&ct->proto.icmp.count)
&& del_timer(&ct->timeout))
ct->timeout.function((unsigned long)ct);
if (atomic_dec_and_test(&ct->proto.icmp.count))
nf_ct_kill(ct);
} else {
atomic_inc(&ct->proto.icmp.count);
nf_conntrack_event_cache(IPCT_PROTOINFO_VOLATILE, skb);
Expand Down
5 changes: 2 additions & 3 deletions net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ static int icmpv6_packet(struct nf_conn *ct,
means this will only run once even if count hits zero twice
(theoretically possible with SMP) */
if (CTINFO2DIR(ctinfo) == IP_CT_DIR_REPLY) {
if (atomic_dec_and_test(&ct->proto.icmp.count)
&& del_timer(&ct->timeout))
ct->timeout.function((unsigned long)ct);
if (atomic_dec_and_test(&ct->proto.icmp.count))
nf_ct_kill(ct);
} else {
atomic_inc(&ct->proto.icmp.count);
nf_conntrack_event_cache(IPCT_PROTOINFO_VOLATILE, skb);
Expand Down
7 changes: 7 additions & 0 deletions net/netfilter/nf_conntrack_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,13 @@ void __nf_ct_refresh_acct(struct nf_conn *ct,
}
EXPORT_SYMBOL_GPL(__nf_ct_refresh_acct);

void nf_ct_kill(struct nf_conn *ct)
{
if (del_timer(&ct->timeout))
ct->timeout.function((unsigned long)ct);
}
EXPORT_SYMBOL_GPL(nf_ct_kill);

#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)

#include <linux/netfilter/nfnetlink.h>
Expand Down
3 changes: 1 addition & 2 deletions net/netfilter/nf_conntrack_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -812,9 +812,8 @@ ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
return -ENOENT;
}
}
if (del_timer(&ct->timeout))
ct->timeout.function((unsigned long)ct);

nf_ct_kill(ct);
nf_ct_put(ct);

return 0;
Expand Down
3 changes: 1 addition & 2 deletions net/netfilter/nf_conntrack_proto_dccp.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,7 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
if (type == DCCP_PKT_RESET &&
!test_bit(IPS_SEEN_REPLY_BIT, &ct->status)) {
/* Tear down connection immediately if only reply is a RESET */
if (del_timer(&ct->timeout))
ct->timeout.function((unsigned long)ct);
nf_ct_kill(ct);
return NF_ACCEPT;
}

Expand Down
9 changes: 3 additions & 6 deletions net/netfilter/nf_conntrack_proto_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -843,8 +843,7 @@ static int tcp_packet(struct nf_conn *ct,
/* Attempt to reopen a closed/aborted connection.
* Delete this connection and look up again. */
write_unlock_bh(&tcp_lock);
if (del_timer(&ct->timeout))
ct->timeout.function((unsigned long)ct);
nf_ct_kill(ct);
return -NF_REPEAT;
}
/* Fall through */
Expand Down Expand Up @@ -877,8 +876,7 @@ static int tcp_packet(struct nf_conn *ct,
if (LOG_INVALID(IPPROTO_TCP))
nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
"nf_ct_tcp: killing out of sync session ");
if (del_timer(&ct->timeout))
ct->timeout.function((unsigned long)ct);
nf_ct_kill(ct);
return -NF_DROP;
}
ct->proto.tcp.last_index = index;
Expand Down Expand Up @@ -961,8 +959,7 @@ static int tcp_packet(struct nf_conn *ct,
problem case, so we can delete the conntrack
immediately. --RR */
if (th->rst) {
if (del_timer(&ct->timeout))
ct->timeout.function((unsigned long)ct);
nf_ct_kill(ct);
return NF_ACCEPT;
}
} else if (!test_bit(IPS_ASSURED_BIT, &ct->status)
Expand Down

0 comments on commit 5109176

Please sign in to comment.