Skip to content

Commit 0143ed3

Browse files
committed
Merge branch 'net-constify-struct-net-parameter-of-socket-lookups'
Eric Dumazet says: ==================== net: constify 'struct net' parameter of socket lookups We should keep const qualifiers whenever possible. This series should remove the need for Tom patch in : Link: https://lore.kernel.org/netdev/[email protected]/ ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 10a6545 + 87d973e commit 0143ed3

File tree

10 files changed

+47
-43
lines changed

10 files changed

+47
-43
lines changed

include/linux/filter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,7 @@ extern struct static_key_false bpf_sk_lookup_enabled;
16161616
_all_pass || _selected_sk ? SK_PASS : SK_DROP; \
16171617
})
16181618

1619-
static inline bool bpf_sk_lookup_run_v4(struct net *net, int protocol,
1619+
static inline bool bpf_sk_lookup_run_v4(const struct net *net, int protocol,
16201620
const __be32 saddr, const __be16 sport,
16211621
const __be32 daddr, const u16 dport,
16221622
const int ifindex, struct sock **psk)
@@ -1653,7 +1653,7 @@ static inline bool bpf_sk_lookup_run_v4(struct net *net, int protocol,
16531653
}
16541654

16551655
#if IS_ENABLED(CONFIG_IPV6)
1656-
static inline bool bpf_sk_lookup_run_v6(struct net *net, int protocol,
1656+
static inline bool bpf_sk_lookup_run_v6(const struct net *net, int protocol,
16571657
const struct in6_addr *saddr,
16581658
const __be16 sport,
16591659
const struct in6_addr *daddr,

include/net/inet6_hashtables.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static inline unsigned int __inet6_ehashfn(const u32 lhash,
4040
*
4141
* The sockhash lock must be held as a reader here.
4242
*/
43-
struct sock *__inet6_lookup_established(struct net *net,
43+
struct sock *__inet6_lookup_established(const struct net *net,
4444
struct inet_hashinfo *hashinfo,
4545
const struct in6_addr *saddr,
4646
const __be16 sport,
@@ -56,15 +56,15 @@ inet6_ehashfn_t inet6_ehashfn;
5656

5757
INDIRECT_CALLABLE_DECLARE(inet6_ehashfn_t udp6_ehashfn);
5858

59-
struct sock *inet6_lookup_reuseport(struct net *net, struct sock *sk,
59+
struct sock *inet6_lookup_reuseport(const struct net *net, struct sock *sk,
6060
struct sk_buff *skb, int doff,
6161
const struct in6_addr *saddr,
6262
__be16 sport,
6363
const struct in6_addr *daddr,
6464
unsigned short hnum,
6565
inet6_ehashfn_t *ehashfn);
6666

67-
struct sock *inet6_lookup_listener(struct net *net,
67+
struct sock *inet6_lookup_listener(const struct net *net,
6868
struct inet_hashinfo *hashinfo,
6969
struct sk_buff *skb, int doff,
7070
const struct in6_addr *saddr,
@@ -73,7 +73,7 @@ struct sock *inet6_lookup_listener(struct net *net,
7373
const unsigned short hnum,
7474
const int dif, const int sdif);
7575

76-
struct sock *inet6_lookup_run_sk_lookup(struct net *net,
76+
struct sock *inet6_lookup_run_sk_lookup(const struct net *net,
7777
int protocol,
7878
struct sk_buff *skb, int doff,
7979
const struct in6_addr *saddr,
@@ -82,7 +82,7 @@ struct sock *inet6_lookup_run_sk_lookup(struct net *net,
8282
const u16 hnum, const int dif,
8383
inet6_ehashfn_t *ehashfn);
8484

85-
static inline struct sock *__inet6_lookup(struct net *net,
85+
static inline struct sock *__inet6_lookup(const struct net *net,
8686
struct inet_hashinfo *hashinfo,
8787
struct sk_buff *skb, int doff,
8888
const struct in6_addr *saddr,
@@ -167,15 +167,15 @@ static inline struct sock *__inet6_lookup_skb(struct inet_hashinfo *hashinfo,
167167
iif, sdif, refcounted);
168168
}
169169

170-
struct sock *inet6_lookup(struct net *net, struct inet_hashinfo *hashinfo,
170+
struct sock *inet6_lookup(const struct net *net, struct inet_hashinfo *hashinfo,
171171
struct sk_buff *skb, int doff,
172172
const struct in6_addr *saddr, const __be16 sport,
173173
const struct in6_addr *daddr, const __be16 dport,
174174
const int dif);
175175

176176
int inet6_hash(struct sock *sk);
177177

178-
static inline bool inet6_match(struct net *net, const struct sock *sk,
178+
static inline bool inet6_match(const struct net *net, const struct sock *sk,
179179
const struct in6_addr *saddr,
180180
const struct in6_addr *daddr,
181181
const __portpair ports,

include/net/inet_hashtables.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ int __inet_hash(struct sock *sk, struct sock *osk);
304304
int inet_hash(struct sock *sk);
305305
void inet_unhash(struct sock *sk);
306306

307-
struct sock *__inet_lookup_listener(struct net *net,
307+
struct sock *__inet_lookup_listener(const struct net *net,
308308
struct inet_hashinfo *hashinfo,
309309
struct sk_buff *skb, int doff,
310310
const __be32 saddr, const __be16 sport,
@@ -351,7 +351,7 @@ static inline struct sock *inet_lookup_listener(struct net *net,
351351
((__force __u64)(__be32)(__saddr)))
352352
#endif /* __BIG_ENDIAN */
353353

354-
static inline bool inet_match(struct net *net, const struct sock *sk,
354+
static inline bool inet_match(const struct net *net, const struct sock *sk,
355355
const __addrpair cookie, const __portpair ports,
356356
int dif, int sdif)
357357
{
@@ -368,7 +368,7 @@ static inline bool inet_match(struct net *net, const struct sock *sk,
368368
/* Sockets in TCP_CLOSE state are _always_ taken out of the hash, so we need
369369
* not check it for lookups anymore, thanks Alexey. -DaveM
370370
*/
371-
struct sock *__inet_lookup_established(struct net *net,
371+
struct sock *__inet_lookup_established(const struct net *net,
372372
struct inet_hashinfo *hashinfo,
373373
const __be32 saddr, const __be16 sport,
374374
const __be32 daddr, const u16 hnum,
@@ -382,13 +382,13 @@ inet_ehashfn_t inet_ehashfn;
382382

383383
INDIRECT_CALLABLE_DECLARE(inet_ehashfn_t udp_ehashfn);
384384

385-
struct sock *inet_lookup_reuseport(struct net *net, struct sock *sk,
385+
struct sock *inet_lookup_reuseport(const struct net *net, struct sock *sk,
386386
struct sk_buff *skb, int doff,
387387
__be32 saddr, __be16 sport,
388388
__be32 daddr, unsigned short hnum,
389389
inet_ehashfn_t *ehashfn);
390390

391-
struct sock *inet_lookup_run_sk_lookup(struct net *net,
391+
struct sock *inet_lookup_run_sk_lookup(const struct net *net,
392392
int protocol,
393393
struct sk_buff *skb, int doff,
394394
__be32 saddr, __be16 sport,

include/net/inet_sock.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ static inline bool inet_bound_dev_eq(bool l3mdev_accept, int bound_dev_if,
150150
return bound_dev_if == dif || bound_dev_if == sdif;
151151
}
152152

153-
static inline bool inet_sk_bound_dev_eq(struct net *net, int bound_dev_if,
153+
static inline bool inet_sk_bound_dev_eq(const struct net *net,
154+
int bound_dev_if,
154155
int dif, int sdif)
155156
{
156157
#if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV)

include/net/ipv6_stubs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ extern const struct ipv6_stub *ipv6_stub __read_mostly;
8282
struct ipv6_bpf_stub {
8383
int (*inet6_bind)(struct sock *sk, struct sockaddr *uaddr, int addr_len,
8484
u32 flags);
85-
struct sock *(*udp6_lib_lookup)(struct net *net,
85+
struct sock *(*udp6_lib_lookup)(const struct net *net,
8686
const struct in6_addr *saddr, __be16 sport,
8787
const struct in6_addr *daddr, __be16 dport,
8888
int dif, int sdif, struct udp_table *tbl,

include/net/udp.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ struct udp_table {
7979
extern struct udp_table udp_table;
8080
void udp_table_init(struct udp_table *, const char *);
8181
static inline struct udp_hslot *udp_hashslot(struct udp_table *table,
82-
struct net *net, unsigned int num)
82+
const struct net *net,
83+
unsigned int num)
8384
{
8485
return &table->hash[udp_hashfn(net, num, table->mask)];
8586
}
@@ -245,7 +246,7 @@ static inline int udp_rqueue_get(struct sock *sk)
245246
return sk_rmem_alloc_get(sk) - READ_ONCE(udp_sk(sk)->forward_deficit);
246247
}
247248

248-
static inline bool udp_sk_bound_dev_eq(struct net *net, int bound_dev_if,
249+
static inline bool udp_sk_bound_dev_eq(const struct net *net, int bound_dev_if,
249250
int dif, int sdif)
250251
{
251252
#if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV)
@@ -296,18 +297,19 @@ int udp_lib_getsockopt(struct sock *sk, int level, int optname,
296297
int udp_lib_setsockopt(struct sock *sk, int level, int optname,
297298
sockptr_t optval, unsigned int optlen,
298299
int (*push_pending_frames)(struct sock *));
299-
struct sock *udp4_lib_lookup(struct net *net, __be32 saddr, __be16 sport,
300+
struct sock *udp4_lib_lookup(const struct net *net, __be32 saddr, __be16 sport,
300301
__be32 daddr, __be16 dport, int dif);
301-
struct sock *__udp4_lib_lookup(struct net *net, __be32 saddr, __be16 sport,
302+
struct sock *__udp4_lib_lookup(const struct net *net, __be32 saddr,
303+
__be16 sport,
302304
__be32 daddr, __be16 dport, int dif, int sdif,
303305
struct udp_table *tbl, struct sk_buff *skb);
304306
struct sock *udp4_lib_lookup_skb(const struct sk_buff *skb,
305307
__be16 sport, __be16 dport);
306-
struct sock *udp6_lib_lookup(struct net *net,
308+
struct sock *udp6_lib_lookup(const struct net *net,
307309
const struct in6_addr *saddr, __be16 sport,
308310
const struct in6_addr *daddr, __be16 dport,
309311
int dif);
310-
struct sock *__udp6_lib_lookup(struct net *net,
312+
struct sock *__udp6_lib_lookup(const struct net *net,
311313
const struct in6_addr *saddr, __be16 sport,
312314
const struct in6_addr *daddr, __be16 dport,
313315
int dif, int sdif, struct udp_table *tbl,

net/ipv4/inet_hashtables.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ inet_lhash2_bucket_sk(struct inet_hashinfo *h, struct sock *sk)
310310
return inet_lhash2_bucket(h, hash);
311311
}
312312

313-
static inline int compute_score(struct sock *sk, struct net *net,
313+
static inline int compute_score(struct sock *sk, const struct net *net,
314314
const unsigned short hnum, const __be32 daddr,
315315
const int dif, const int sdif)
316316
{
@@ -348,7 +348,7 @@ static inline int compute_score(struct sock *sk, struct net *net,
348348
* Return: NULL if sk doesn't have SO_REUSEPORT set, otherwise a pointer to
349349
* the selected sock or an error.
350350
*/
351-
struct sock *inet_lookup_reuseport(struct net *net, struct sock *sk,
351+
struct sock *inet_lookup_reuseport(const struct net *net, struct sock *sk,
352352
struct sk_buff *skb, int doff,
353353
__be32 saddr, __be16 sport,
354354
__be32 daddr, unsigned short hnum,
@@ -374,7 +374,7 @@ EXPORT_SYMBOL_GPL(inet_lookup_reuseport);
374374
*/
375375

376376
/* called with rcu_read_lock() : No refcount taken on the socket */
377-
static struct sock *inet_lhash2_lookup(struct net *net,
377+
static struct sock *inet_lhash2_lookup(const struct net *net,
378378
struct inet_listen_hashbucket *ilb2,
379379
struct sk_buff *skb, int doff,
380380
const __be32 saddr, __be16 sport,
@@ -401,7 +401,7 @@ static struct sock *inet_lhash2_lookup(struct net *net,
401401
return result;
402402
}
403403

404-
struct sock *inet_lookup_run_sk_lookup(struct net *net,
404+
struct sock *inet_lookup_run_sk_lookup(const struct net *net,
405405
int protocol,
406406
struct sk_buff *skb, int doff,
407407
__be32 saddr, __be16 sport,
@@ -423,7 +423,7 @@ struct sock *inet_lookup_run_sk_lookup(struct net *net,
423423
return sk;
424424
}
425425

426-
struct sock *__inet_lookup_listener(struct net *net,
426+
struct sock *__inet_lookup_listener(const struct net *net,
427427
struct inet_hashinfo *hashinfo,
428428
struct sk_buff *skb, int doff,
429429
const __be32 saddr, __be16 sport,
@@ -488,7 +488,7 @@ void sock_edemux(struct sk_buff *skb)
488488
}
489489
EXPORT_SYMBOL(sock_edemux);
490490

491-
struct sock *__inet_lookup_established(struct net *net,
491+
struct sock *__inet_lookup_established(const struct net *net,
492492
struct inet_hashinfo *hashinfo,
493493
const __be32 saddr, const __be16 sport,
494494
const __be32 daddr, const u16 hnum,

net/ipv4/udp.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ int udp_v4_get_port(struct sock *sk, unsigned short snum)
365365
return udp_lib_get_port(sk, snum, hash2_nulladdr);
366366
}
367367

368-
static int compute_score(struct sock *sk, struct net *net,
368+
static int compute_score(struct sock *sk, const struct net *net,
369369
__be32 saddr, __be16 sport,
370370
__be32 daddr, unsigned short hnum,
371371
int dif, int sdif)
@@ -420,7 +420,7 @@ u32 udp_ehashfn(const struct net *net, const __be32 laddr, const __u16 lport,
420420
}
421421

422422
/* called with rcu_read_lock() */
423-
static struct sock *udp4_lib_lookup2(struct net *net,
423+
static struct sock *udp4_lib_lookup2(const struct net *net,
424424
__be32 saddr, __be16 sport,
425425
__be32 daddr, unsigned int hnum,
426426
int dif, int sdif,
@@ -480,7 +480,7 @@ static struct sock *udp4_lib_lookup2(struct net *net,
480480
/* UDP is nearly always wildcards out the wazoo, it makes no sense to try
481481
* harder than this. -DaveM
482482
*/
483-
struct sock *__udp4_lib_lookup(struct net *net, __be32 saddr,
483+
struct sock *__udp4_lib_lookup(const struct net *net, __be32 saddr,
484484
__be16 sport, __be32 daddr, __be16 dport, int dif,
485485
int sdif, struct udp_table *udptable, struct sk_buff *skb)
486486
{
@@ -561,7 +561,7 @@ struct sock *udp4_lib_lookup_skb(const struct sk_buff *skb,
561561
* Does increment socket refcount.
562562
*/
563563
#if IS_ENABLED(CONFIG_NF_TPROXY_IPV4) || IS_ENABLED(CONFIG_NF_SOCKET_IPV4)
564-
struct sock *udp4_lib_lookup(struct net *net, __be32 saddr, __be16 sport,
564+
struct sock *udp4_lib_lookup(const struct net *net, __be32 saddr, __be16 sport,
565565
__be32 daddr, __be16 dport, int dif)
566566
{
567567
struct sock *sk;

net/ipv6/inet6_hashtables.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ EXPORT_SYMBOL_GPL(inet6_ehashfn);
4646
*
4747
* The sockhash lock must be held as a reader here.
4848
*/
49-
struct sock *__inet6_lookup_established(struct net *net,
49+
struct sock *__inet6_lookup_established(const struct net *net,
5050
struct inet_hashinfo *hashinfo,
5151
const struct in6_addr *saddr,
5252
const __be16 sport,
@@ -89,7 +89,7 @@ struct sock *__inet6_lookup_established(struct net *net,
8989
}
9090
EXPORT_SYMBOL(__inet6_lookup_established);
9191

92-
static inline int compute_score(struct sock *sk, struct net *net,
92+
static inline int compute_score(struct sock *sk, const struct net *net,
9393
const unsigned short hnum,
9494
const struct in6_addr *daddr,
9595
const int dif, const int sdif)
@@ -126,7 +126,7 @@ static inline int compute_score(struct sock *sk, struct net *net,
126126
* Return: NULL if sk doesn't have SO_REUSEPORT set, otherwise a pointer to
127127
* the selected sock or an error.
128128
*/
129-
struct sock *inet6_lookup_reuseport(struct net *net, struct sock *sk,
129+
struct sock *inet6_lookup_reuseport(const struct net *net, struct sock *sk,
130130
struct sk_buff *skb, int doff,
131131
const struct in6_addr *saddr,
132132
__be16 sport,
@@ -147,7 +147,7 @@ struct sock *inet6_lookup_reuseport(struct net *net, struct sock *sk,
147147
EXPORT_SYMBOL_GPL(inet6_lookup_reuseport);
148148

149149
/* called with rcu_read_lock() */
150-
static struct sock *inet6_lhash2_lookup(struct net *net,
150+
static struct sock *inet6_lhash2_lookup(const struct net *net,
151151
struct inet_listen_hashbucket *ilb2,
152152
struct sk_buff *skb, int doff,
153153
const struct in6_addr *saddr,
@@ -174,7 +174,7 @@ static struct sock *inet6_lhash2_lookup(struct net *net,
174174
return result;
175175
}
176176

177-
struct sock *inet6_lookup_run_sk_lookup(struct net *net,
177+
struct sock *inet6_lookup_run_sk_lookup(const struct net *net,
178178
int protocol,
179179
struct sk_buff *skb, int doff,
180180
const struct in6_addr *saddr,
@@ -199,7 +199,7 @@ struct sock *inet6_lookup_run_sk_lookup(struct net *net,
199199
}
200200
EXPORT_SYMBOL_GPL(inet6_lookup_run_sk_lookup);
201201

202-
struct sock *inet6_lookup_listener(struct net *net,
202+
struct sock *inet6_lookup_listener(const struct net *net,
203203
struct inet_hashinfo *hashinfo,
204204
struct sk_buff *skb, int doff,
205205
const struct in6_addr *saddr,
@@ -243,7 +243,8 @@ struct sock *inet6_lookup_listener(struct net *net,
243243
}
244244
EXPORT_SYMBOL_GPL(inet6_lookup_listener);
245245

246-
struct sock *inet6_lookup(struct net *net, struct inet_hashinfo *hashinfo,
246+
struct sock *inet6_lookup(const struct net *net,
247+
struct inet_hashinfo *hashinfo,
247248
struct sk_buff *skb, int doff,
248249
const struct in6_addr *saddr, const __be16 sport,
249250
const struct in6_addr *daddr, const __be16 dport,

net/ipv6/udp.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void udp_v6_rehash(struct sock *sk)
114114
udp_lib_rehash(sk, new_hash);
115115
}
116116

117-
static int compute_score(struct sock *sk, struct net *net,
117+
static int compute_score(struct sock *sk, const struct net *net,
118118
const struct in6_addr *saddr, __be16 sport,
119119
const struct in6_addr *daddr, unsigned short hnum,
120120
int dif, int sdif)
@@ -160,7 +160,7 @@ static int compute_score(struct sock *sk, struct net *net,
160160
}
161161

162162
/* called with rcu_read_lock() */
163-
static struct sock *udp6_lib_lookup2(struct net *net,
163+
static struct sock *udp6_lib_lookup2(const struct net *net,
164164
const struct in6_addr *saddr, __be16 sport,
165165
const struct in6_addr *daddr, unsigned int hnum,
166166
int dif, int sdif, struct udp_hslot *hslot2,
@@ -217,7 +217,7 @@ static struct sock *udp6_lib_lookup2(struct net *net,
217217
}
218218

219219
/* rcu_read_lock() must be held */
220-
struct sock *__udp6_lib_lookup(struct net *net,
220+
struct sock *__udp6_lib_lookup(const struct net *net,
221221
const struct in6_addr *saddr, __be16 sport,
222222
const struct in6_addr *daddr, __be16 dport,
223223
int dif, int sdif, struct udp_table *udptable,
@@ -300,7 +300,7 @@ struct sock *udp6_lib_lookup_skb(const struct sk_buff *skb,
300300
* Does increment socket refcount.
301301
*/
302302
#if IS_ENABLED(CONFIG_NF_TPROXY_IPV6) || IS_ENABLED(CONFIG_NF_SOCKET_IPV6)
303-
struct sock *udp6_lib_lookup(struct net *net, const struct in6_addr *saddr, __be16 sport,
303+
struct sock *udp6_lib_lookup(const struct net *net, const struct in6_addr *saddr, __be16 sport,
304304
const struct in6_addr *daddr, __be16 dport, int dif)
305305
{
306306
struct sock *sk;

0 commit comments

Comments
 (0)