Skip to content

Commit ba76738

Browse files
committed
netfilter: conntrack: introduce nf_ct_acct_update()
Introduce a helper function to update conntrack counters. __nf_ct_kill_acct() was unnecessarily subtracting skb_network_offset() that is expected to be zero from the ipv4/ipv6 hooks. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 4b4ceb9 commit ba76738

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

net/netfilter/nf_conntrack_core.c

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,21 @@ nf_conntrack_hash_check_insert(struct nf_conn *ct)
602602
}
603603
EXPORT_SYMBOL_GPL(nf_conntrack_hash_check_insert);
604604

605+
static inline void nf_ct_acct_update(struct nf_conn *ct,
606+
enum ip_conntrack_info ctinfo,
607+
unsigned int len)
608+
{
609+
struct nf_conn_acct *acct;
610+
611+
acct = nf_conn_acct_find(ct);
612+
if (acct) {
613+
struct nf_conn_counter *counter = acct->counter;
614+
615+
atomic64_inc(&counter[CTINFO2DIR(ctinfo)].packets);
616+
atomic64_add(len, &counter[CTINFO2DIR(ctinfo)].bytes);
617+
}
618+
}
619+
605620
/* Confirm a connection given skb; places it in hash table */
606621
int
607622
__nf_conntrack_confirm(struct sk_buff *skb)
@@ -1258,17 +1273,8 @@ void __nf_ct_refresh_acct(struct nf_conn *ct,
12581273
}
12591274

12601275
acct:
1261-
if (do_acct) {
1262-
struct nf_conn_acct *acct;
1263-
1264-
acct = nf_conn_acct_find(ct);
1265-
if (acct) {
1266-
struct nf_conn_counter *counter = acct->counter;
1267-
1268-
atomic64_inc(&counter[CTINFO2DIR(ctinfo)].packets);
1269-
atomic64_add(skb->len, &counter[CTINFO2DIR(ctinfo)].bytes);
1270-
}
1271-
}
1276+
if (do_acct)
1277+
nf_ct_acct_update(ct, ctinfo, skb->len);
12721278
}
12731279
EXPORT_SYMBOL_GPL(__nf_ct_refresh_acct);
12741280

@@ -1277,18 +1283,8 @@ bool __nf_ct_kill_acct(struct nf_conn *ct,
12771283
const struct sk_buff *skb,
12781284
int do_acct)
12791285
{
1280-
if (do_acct) {
1281-
struct nf_conn_acct *acct;
1282-
1283-
acct = nf_conn_acct_find(ct);
1284-
if (acct) {
1285-
struct nf_conn_counter *counter = acct->counter;
1286-
1287-
atomic64_inc(&counter[CTINFO2DIR(ctinfo)].packets);
1288-
atomic64_add(skb->len - skb_network_offset(skb),
1289-
&counter[CTINFO2DIR(ctinfo)].bytes);
1290-
}
1291-
}
1286+
if (do_acct)
1287+
nf_ct_acct_update(ct, ctinfo, skb->len);
12921288

12931289
if (del_timer(&ct->timeout)) {
12941290
ct->timeout.function((unsigned long)ct);

0 commit comments

Comments
 (0)