Skip to content

Commit 4d31eef

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: x_tables: pass xt_counters struct instead of packet counter
On SMP we overload the packet counter (unsigned long) to contain percpu offset. Hide this from callers and pass xt_counters address instead. Preparation patch to allocate the percpu counters in page-sized batch chunks. Signed-off-by: Florian Westphal <[email protected]> Acked-by: Eric Dumazet <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 679972f commit 4d31eef

File tree

5 files changed

+16
-12
lines changed

5 files changed

+16
-12
lines changed

include/linux/netfilter/x_tables.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,7 @@ static inline unsigned long xt_percpu_counter_alloc(void)
430430

431431
return 0;
432432
}
433-
static inline void xt_percpu_counter_free(u64 pcnt)
434-
{
435-
if (nr_cpu_ids > 1)
436-
free_percpu((void __percpu *) (unsigned long) pcnt);
437-
}
433+
void xt_percpu_counter_free(struct xt_counters *cnt);
438434

439435
static inline struct xt_counters *
440436
xt_get_this_cpu_counter(struct xt_counters *cnt)

net/ipv4/netfilter/arp_tables.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ find_check_entry(struct arpt_entry *e, const char *name, unsigned int size)
439439
err:
440440
module_put(t->u.kernel.target->me);
441441
out:
442-
xt_percpu_counter_free(e->counters.pcnt);
442+
xt_percpu_counter_free(&e->counters);
443443

444444
return ret;
445445
}
@@ -519,7 +519,7 @@ static inline void cleanup_entry(struct arpt_entry *e)
519519
if (par.target->destroy != NULL)
520520
par.target->destroy(&par);
521521
module_put(par.target->me);
522-
xt_percpu_counter_free(e->counters.pcnt);
522+
xt_percpu_counter_free(&e->counters);
523523
}
524524

525525
/* Checks and translates the user-supplied table segment (held in

net/ipv4/netfilter/ip_tables.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ find_check_entry(struct ipt_entry *e, struct net *net, const char *name,
582582
cleanup_match(ematch, net);
583583
}
584584

585-
xt_percpu_counter_free(e->counters.pcnt);
585+
xt_percpu_counter_free(&e->counters);
586586

587587
return ret;
588588
}
@@ -670,7 +670,7 @@ cleanup_entry(struct ipt_entry *e, struct net *net)
670670
if (par.target->destroy != NULL)
671671
par.target->destroy(&par);
672672
module_put(par.target->me);
673-
xt_percpu_counter_free(e->counters.pcnt);
673+
xt_percpu_counter_free(&e->counters);
674674
}
675675

676676
/* Checks and translates the user-supplied table segment (held in

net/ipv6/netfilter/ip6_tables.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ find_check_entry(struct ip6t_entry *e, struct net *net, const char *name,
612612
cleanup_match(ematch, net);
613613
}
614614

615-
xt_percpu_counter_free(e->counters.pcnt);
615+
xt_percpu_counter_free(&e->counters);
616616

617617
return ret;
618618
}
@@ -699,8 +699,7 @@ static void cleanup_entry(struct ip6t_entry *e, struct net *net)
699699
if (par.target->destroy != NULL)
700700
par.target->destroy(&par);
701701
module_put(par.target->me);
702-
703-
xt_percpu_counter_free(e->counters.pcnt);
702+
xt_percpu_counter_free(&e->counters);
704703
}
705704

706705
/* Checks and translates the user-supplied table segment (held in

net/netfilter/x_tables.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,6 +1615,15 @@ void xt_proto_fini(struct net *net, u_int8_t af)
16151615
}
16161616
EXPORT_SYMBOL_GPL(xt_proto_fini);
16171617

1618+
void xt_percpu_counter_free(struct xt_counters *counters)
1619+
{
1620+
unsigned long pcnt = counters->pcnt;
1621+
1622+
if (nr_cpu_ids > 1)
1623+
free_percpu((void __percpu *)pcnt);
1624+
}
1625+
EXPORT_SYMBOL_GPL(xt_percpu_counter_free);
1626+
16181627
static int __net_init xt_net_init(struct net *net)
16191628
{
16201629
int i;

0 commit comments

Comments
 (0)