Skip to content

Commit f04df57

Browse files
author
Florian Westphal
committed
netfilter: nft_set_pipapo: constify lookup fn args where possible
Those get called from packet path, content must not be modified. No functional changes intended. Reviewed-by: Stefano Brivio <[email protected]> Signed-off-by: Florian Westphal <[email protected]>
1 parent 749d4ef commit f04df57

File tree

3 files changed

+48
-35
lines changed

3 files changed

+48
-35
lines changed

net/netfilter/nft_set_pipapo.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@
360360
* Return: -1 on no match, bit position on 'match_only', 0 otherwise.
361361
*/
362362
int pipapo_refill(unsigned long *map, int len, int rules, unsigned long *dst,
363-
union nft_pipapo_map_bucket *mt, bool match_only)
363+
const union nft_pipapo_map_bucket *mt, bool match_only)
364364
{
365365
unsigned long bitset;
366366
int k, ret = -1;
@@ -412,9 +412,9 @@ bool nft_pipapo_lookup(const struct net *net, const struct nft_set *set,
412412
struct nft_pipapo_scratch *scratch;
413413
unsigned long *res_map, *fill_map;
414414
u8 genmask = nft_genmask_cur(net);
415+
const struct nft_pipapo_match *m;
416+
const struct nft_pipapo_field *f;
415417
const u8 *rp = (const u8 *)key;
416-
struct nft_pipapo_match *m;
417-
struct nft_pipapo_field *f;
418418
bool map_index;
419419
int i;
420420

@@ -519,11 +519,13 @@ static struct nft_pipapo_elem *pipapo_get(const struct net *net,
519519
{
520520
struct nft_pipapo_elem *ret = ERR_PTR(-ENOENT);
521521
struct nft_pipapo *priv = nft_set_priv(set);
522-
struct nft_pipapo_match *m = priv->clone;
523522
unsigned long *res_map, *fill_map = NULL;
524-
struct nft_pipapo_field *f;
523+
const struct nft_pipapo_match *m;
524+
const struct nft_pipapo_field *f;
525525
int i;
526526

527+
m = priv->clone;
528+
527529
res_map = kmalloc_array(m->bsize_max, sizeof(*res_map), GFP_ATOMIC);
528530
if (!res_map) {
529531
ret = ERR_PTR(-ENOMEM);
@@ -1597,7 +1599,7 @@ static void pipapo_gc(struct nft_set *set, struct nft_pipapo_match *m)
15971599

15981600
while ((rules_f0 = pipapo_rules_same_key(m->f, first_rule))) {
15991601
union nft_pipapo_map_bucket rulemap[NFT_PIPAPO_MAX_FIELDS];
1600-
struct nft_pipapo_field *f;
1602+
const struct nft_pipapo_field *f;
16011603
int i, start, rules_fx;
16021604

16031605
start = first_rule;
@@ -2039,8 +2041,8 @@ static void nft_pipapo_walk(const struct nft_ctx *ctx, struct nft_set *set,
20392041
{
20402042
struct nft_pipapo *priv = nft_set_priv(set);
20412043
struct net *net = read_pnet(&set->net);
2042-
struct nft_pipapo_match *m;
2043-
struct nft_pipapo_field *f;
2044+
const struct nft_pipapo_match *m;
2045+
const struct nft_pipapo_field *f;
20442046
int i, r;
20452047

20462048
rcu_read_lock();

net/netfilter/nft_set_pipapo.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,15 @@ struct nft_pipapo_elem {
187187
};
188188

189189
int pipapo_refill(unsigned long *map, int len, int rules, unsigned long *dst,
190-
union nft_pipapo_map_bucket *mt, bool match_only);
190+
const union nft_pipapo_map_bucket *mt, bool match_only);
191191

192192
/**
193193
* pipapo_and_field_buckets_4bit() - Intersect 4-bit buckets
194194
* @f: Field including lookup table
195195
* @dst: Area to store result
196196
* @data: Input data selecting table buckets
197197
*/
198-
static inline void pipapo_and_field_buckets_4bit(struct nft_pipapo_field *f,
198+
static inline void pipapo_and_field_buckets_4bit(const struct nft_pipapo_field *f,
199199
unsigned long *dst,
200200
const u8 *data)
201201
{
@@ -223,7 +223,7 @@ static inline void pipapo_and_field_buckets_4bit(struct nft_pipapo_field *f,
223223
* @dst: Area to store result
224224
* @data: Input data selecting table buckets
225225
*/
226-
static inline void pipapo_and_field_buckets_8bit(struct nft_pipapo_field *f,
226+
static inline void pipapo_and_field_buckets_8bit(const struct nft_pipapo_field *f,
227227
unsigned long *dst,
228228
const u8 *data)
229229
{

net/netfilter/nft_set_pipapo_avx2.c

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,9 @@ static int nft_pipapo_avx2_refill(int offset, unsigned long *map,
212212
* word index to be checked next (i.e. first filled word).
213213
*/
214214
static int nft_pipapo_avx2_lookup_4b_2(unsigned long *map, unsigned long *fill,
215-
struct nft_pipapo_field *f, int offset,
216-
const u8 *pkt, bool first, bool last)
215+
const struct nft_pipapo_field *f,
216+
int offset, const u8 *pkt,
217+
bool first, bool last)
217218
{
218219
int i, ret = -1, m256_size = f->bsize / NFT_PIPAPO_LONGS_PER_M256, b;
219220
u8 pg[2] = { pkt[0] >> 4, pkt[0] & 0xf };
@@ -274,8 +275,9 @@ static int nft_pipapo_avx2_lookup_4b_2(unsigned long *map, unsigned long *fill,
274275
* word index to be checked next (i.e. first filled word).
275276
*/
276277
static int nft_pipapo_avx2_lookup_4b_4(unsigned long *map, unsigned long *fill,
277-
struct nft_pipapo_field *f, int offset,
278-
const u8 *pkt, bool first, bool last)
278+
const struct nft_pipapo_field *f,
279+
int offset, const u8 *pkt,
280+
bool first, bool last)
279281
{
280282
int i, ret = -1, m256_size = f->bsize / NFT_PIPAPO_LONGS_PER_M256, b;
281283
u8 pg[4] = { pkt[0] >> 4, pkt[0] & 0xf, pkt[1] >> 4, pkt[1] & 0xf };
@@ -350,8 +352,9 @@ static int nft_pipapo_avx2_lookup_4b_4(unsigned long *map, unsigned long *fill,
350352
* word index to be checked next (i.e. first filled word).
351353
*/
352354
static int nft_pipapo_avx2_lookup_4b_8(unsigned long *map, unsigned long *fill,
353-
struct nft_pipapo_field *f, int offset,
354-
const u8 *pkt, bool first, bool last)
355+
const struct nft_pipapo_field *f,
356+
int offset, const u8 *pkt,
357+
bool first, bool last)
355358
{
356359
u8 pg[8] = { pkt[0] >> 4, pkt[0] & 0xf, pkt[1] >> 4, pkt[1] & 0xf,
357360
pkt[2] >> 4, pkt[2] & 0xf, pkt[3] >> 4, pkt[3] & 0xf,
@@ -445,8 +448,9 @@ static int nft_pipapo_avx2_lookup_4b_8(unsigned long *map, unsigned long *fill,
445448
* word index to be checked next (i.e. first filled word).
446449
*/
447450
static int nft_pipapo_avx2_lookup_4b_12(unsigned long *map, unsigned long *fill,
448-
struct nft_pipapo_field *f, int offset,
449-
const u8 *pkt, bool first, bool last)
451+
const struct nft_pipapo_field *f,
452+
int offset, const u8 *pkt,
453+
bool first, bool last)
450454
{
451455
u8 pg[12] = { pkt[0] >> 4, pkt[0] & 0xf, pkt[1] >> 4, pkt[1] & 0xf,
452456
pkt[2] >> 4, pkt[2] & 0xf, pkt[3] >> 4, pkt[3] & 0xf,
@@ -534,8 +538,9 @@ static int nft_pipapo_avx2_lookup_4b_12(unsigned long *map, unsigned long *fill,
534538
* word index to be checked next (i.e. first filled word).
535539
*/
536540
static int nft_pipapo_avx2_lookup_4b_32(unsigned long *map, unsigned long *fill,
537-
struct nft_pipapo_field *f, int offset,
538-
const u8 *pkt, bool first, bool last)
541+
const struct nft_pipapo_field *f,
542+
int offset, const u8 *pkt,
543+
bool first, bool last)
539544
{
540545
u8 pg[32] = { pkt[0] >> 4, pkt[0] & 0xf, pkt[1] >> 4, pkt[1] & 0xf,
541546
pkt[2] >> 4, pkt[2] & 0xf, pkt[3] >> 4, pkt[3] & 0xf,
@@ -669,8 +674,9 @@ static int nft_pipapo_avx2_lookup_4b_32(unsigned long *map, unsigned long *fill,
669674
* word index to be checked next (i.e. first filled word).
670675
*/
671676
static int nft_pipapo_avx2_lookup_8b_1(unsigned long *map, unsigned long *fill,
672-
struct nft_pipapo_field *f, int offset,
673-
const u8 *pkt, bool first, bool last)
677+
const struct nft_pipapo_field *f,
678+
int offset, const u8 *pkt,
679+
bool first, bool last)
674680
{
675681
int i, ret = -1, m256_size = f->bsize / NFT_PIPAPO_LONGS_PER_M256, b;
676682
unsigned long *lt = f->lt, bsize = f->bsize;
@@ -726,8 +732,9 @@ static int nft_pipapo_avx2_lookup_8b_1(unsigned long *map, unsigned long *fill,
726732
* word index to be checked next (i.e. first filled word).
727733
*/
728734
static int nft_pipapo_avx2_lookup_8b_2(unsigned long *map, unsigned long *fill,
729-
struct nft_pipapo_field *f, int offset,
730-
const u8 *pkt, bool first, bool last)
735+
const struct nft_pipapo_field *f,
736+
int offset, const u8 *pkt,
737+
bool first, bool last)
731738
{
732739
int i, ret = -1, m256_size = f->bsize / NFT_PIPAPO_LONGS_PER_M256, b;
733740
unsigned long *lt = f->lt, bsize = f->bsize;
@@ -790,8 +797,9 @@ static int nft_pipapo_avx2_lookup_8b_2(unsigned long *map, unsigned long *fill,
790797
* word index to be checked next (i.e. first filled word).
791798
*/
792799
static int nft_pipapo_avx2_lookup_8b_4(unsigned long *map, unsigned long *fill,
793-
struct nft_pipapo_field *f, int offset,
794-
const u8 *pkt, bool first, bool last)
800+
const struct nft_pipapo_field *f,
801+
int offset, const u8 *pkt,
802+
bool first, bool last)
795803
{
796804
int i, ret = -1, m256_size = f->bsize / NFT_PIPAPO_LONGS_PER_M256, b;
797805
unsigned long *lt = f->lt, bsize = f->bsize;
@@ -865,8 +873,9 @@ static int nft_pipapo_avx2_lookup_8b_4(unsigned long *map, unsigned long *fill,
865873
* word index to be checked next (i.e. first filled word).
866874
*/
867875
static int nft_pipapo_avx2_lookup_8b_6(unsigned long *map, unsigned long *fill,
868-
struct nft_pipapo_field *f, int offset,
869-
const u8 *pkt, bool first, bool last)
876+
const struct nft_pipapo_field *f,
877+
int offset, const u8 *pkt,
878+
bool first, bool last)
870879
{
871880
int i, ret = -1, m256_size = f->bsize / NFT_PIPAPO_LONGS_PER_M256, b;
872881
unsigned long *lt = f->lt, bsize = f->bsize;
@@ -950,8 +959,9 @@ static int nft_pipapo_avx2_lookup_8b_6(unsigned long *map, unsigned long *fill,
950959
* word index to be checked next (i.e. first filled word).
951960
*/
952961
static int nft_pipapo_avx2_lookup_8b_16(unsigned long *map, unsigned long *fill,
953-
struct nft_pipapo_field *f, int offset,
954-
const u8 *pkt, bool first, bool last)
962+
const struct nft_pipapo_field *f,
963+
int offset, const u8 *pkt,
964+
bool first, bool last)
955965
{
956966
int i, ret = -1, m256_size = f->bsize / NFT_PIPAPO_LONGS_PER_M256, b;
957967
unsigned long *lt = f->lt, bsize = f->bsize;
@@ -1042,8 +1052,9 @@ static int nft_pipapo_avx2_lookup_8b_16(unsigned long *map, unsigned long *fill,
10421052
* word index to be checked next (i.e. first filled word).
10431053
*/
10441054
static int nft_pipapo_avx2_lookup_slow(unsigned long *map, unsigned long *fill,
1045-
struct nft_pipapo_field *f, int offset,
1046-
const u8 *pkt, bool first, bool last)
1055+
const struct nft_pipapo_field *f,
1056+
int offset, const u8 *pkt,
1057+
bool first, bool last)
10471058
{
10481059
unsigned long bsize = f->bsize;
10491060
int i, ret = -1, b;
@@ -1119,9 +1130,9 @@ bool nft_pipapo_avx2_lookup(const struct net *net, const struct nft_set *set,
11191130
struct nft_pipapo *priv = nft_set_priv(set);
11201131
struct nft_pipapo_scratch *scratch;
11211132
u8 genmask = nft_genmask_cur(net);
1133+
const struct nft_pipapo_match *m;
1134+
const struct nft_pipapo_field *f;
11221135
const u8 *rp = (const u8 *)key;
1123-
struct nft_pipapo_match *m;
1124-
struct nft_pipapo_field *f;
11251136
unsigned long *res, *fill;
11261137
bool map_index;
11271138
int i, ret = 0;

0 commit comments

Comments
 (0)