Commit 58020f77 authored by Tony Zelenoff's avatar Tony Zelenoff Committed by Pablo Neira Ayuso

netfilter: nf_ct_ecache: refactor nf_ct_deliver_cached_events

* identation lowered
* some CPU cycles saved at delayed item variable initialization
Signed-off-by: default avatarTony Zelenoff <antonz@parallels.com>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent 93326ae3
...@@ -32,9 +32,11 @@ static DEFINE_MUTEX(nf_ct_ecache_mutex); ...@@ -32,9 +32,11 @@ static DEFINE_MUTEX(nf_ct_ecache_mutex);
void nf_ct_deliver_cached_events(struct nf_conn *ct) void nf_ct_deliver_cached_events(struct nf_conn *ct)
{ {
struct net *net = nf_ct_net(ct); struct net *net = nf_ct_net(ct);
unsigned long events; unsigned long events, missed;
struct nf_ct_event_notifier *notify; struct nf_ct_event_notifier *notify;
struct nf_conntrack_ecache *e; struct nf_conntrack_ecache *e;
struct nf_ct_event item;
int ret;
rcu_read_lock(); rcu_read_lock();
notify = rcu_dereference(net->ct.nf_conntrack_event_cb); notify = rcu_dereference(net->ct.nf_conntrack_event_cb);
...@@ -47,31 +49,32 @@ void nf_ct_deliver_cached_events(struct nf_conn *ct) ...@@ -47,31 +49,32 @@ void nf_ct_deliver_cached_events(struct nf_conn *ct)
events = xchg(&e->cache, 0); events = xchg(&e->cache, 0);
if (nf_ct_is_confirmed(ct) && !nf_ct_is_dying(ct) && events) { if (!nf_ct_is_confirmed(ct) || nf_ct_is_dying(ct) || !events)
struct nf_ct_event item = { goto out_unlock;
.ct = ct,
.pid = 0, /* We make a copy of the missed event cache without taking
.report = 0 * the lock, thus we may send missed events twice. However,
}; * this does not harm and it happens very rarely. */
int ret; missed = e->missed;
/* We make a copy of the missed event cache without taking
* the lock, thus we may send missed events twice. However, if (!((events | missed) & e->ctmask))
* this does not harm and it happens very rarely. */ goto out_unlock;
unsigned long missed = e->missed;
item.ct = ct;
if (!((events | missed) & e->ctmask)) item.pid = 0;
goto out_unlock; item.report = 0;
ret = notify->fcn(events | missed, &item); ret = notify->fcn(events | missed, &item);
if (unlikely(ret < 0 || missed)) {
spin_lock_bh(&ct->lock); if (likely(ret >= 0 && !missed))
if (ret < 0) goto out_unlock;
e->missed |= events;
else spin_lock_bh(&ct->lock);
e->missed &= ~missed; if (ret < 0)
spin_unlock_bh(&ct->lock); e->missed |= events;
} else
} e->missed &= ~missed;
spin_unlock_bh(&ct->lock);
out_unlock: out_unlock:
rcu_read_unlock(); rcu_read_unlock();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment