diff --git a/include/net/raw.h b/include/net/raw.h index 5e665934ebc7cb5566bcc5e2ef45e6c911a3f0d8..76b3f842258f4bba37176c7bdab8bb59642cf671 100644 --- a/include/net/raw.h +++ b/include/net/raw.h @@ -15,11 +15,12 @@ #include #include +#include #include extern struct proto raw_prot; -extern struct raw_hashinfo raw_v4_hashinfo; +extern struct raw_hashinfo_new raw_v4_hashinfo; bool raw_v4_match(struct net *net, struct sock *sk, unsigned short num, __be32 raddr, __be32 laddr, int dif, int sdif); @@ -29,22 +30,11 @@ int raw_local_deliver(struct sk_buff *, int); int raw_rcv(struct sock *, struct sk_buff *); -#define RAW_HTABLE_SIZE MAX_INET_PROTOS - struct raw_hashinfo { - spinlock_t lock; - struct hlist_nulls_head ht[RAW_HTABLE_SIZE]; + rwlock_t lock; + struct hlist_head ht[RAW_HTABLE_SIZE]; }; -static inline void raw_hashinfo_init(struct raw_hashinfo *hashinfo) -{ - int i; - - spin_lock_init(&hashinfo->lock); - for (i = 0; i < RAW_HTABLE_SIZE; i++) - INIT_HLIST_NULLS_HEAD(&hashinfo->ht[i], i); -} - #ifdef CONFIG_PROC_FS int raw_proc_init(void); void raw_proc_exit(void); diff --git a/include/net/raw_common.h b/include/net/raw_common.h new file mode 100644 index 0000000000000000000000000000000000000000..77e70135792876e51964057af9392bad57fe0dad --- /dev/null +++ b/include/net/raw_common.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef _RAW_COMMON_H +#define _RAW_COMMON_H + +#define RAW_HTABLE_SIZE MAX_INET_PROTOS + +struct raw_hashinfo_new { + spinlock_t lock; + struct hlist_nulls_head ht[RAW_HTABLE_SIZE]; +}; + +static inline void raw_hashinfo_init(struct raw_hashinfo_new *hashinfo) +{ + int i; + + spin_lock_init(&hashinfo->lock); + for (i = 0; i < RAW_HTABLE_SIZE; i++) + INIT_HLIST_NULLS_HEAD(&hashinfo->ht[i], i); +} + +#endif /* _RAW_COMMON_H */ diff --git a/include/net/rawv6.h b/include/net/rawv6.h index bc70909625f60dcd819f50a258841d20e5ba0c68..700de7d3af684ac10f261017b474f1c3c684f993 100644 --- a/include/net/rawv6.h +++ b/include/net/rawv6.h @@ -3,9 +3,8 @@ #define _NET_RAWV6_H #include -#include -extern struct raw_hashinfo raw_v6_hashinfo; +extern struct raw_hashinfo_new raw_v6_hashinfo; bool raw_v6_match(struct net *net, struct sock *sk, unsigned short num, const struct in6_addr *loc_addr, const struct in6_addr *rmt_addr, int dif, int sdif); diff --git a/include/net/sock.h b/include/net/sock.h index a3e2514c5835895a431891eae63ba8cece73292f..74dbbf0e30c03b0087ce342c067909932a362385 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1155,6 +1155,7 @@ struct request_sock_ops; struct timewait_sock_ops; struct inet_hashinfo; struct raw_hashinfo; +struct raw_hashinfo_new; struct smc_hashinfo; struct module; @@ -1269,7 +1270,8 @@ struct proto { union { struct inet_hashinfo *hashinfo; struct udp_table *udp_table; - struct raw_hashinfo *raw_hash; + KABI_REPLACE(struct raw_hashinfo *raw_hash, + struct raw_hashinfo_new *raw_hash) struct smc_hashinfo *smc_hash; } h; diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c index 7963638f9d156b22ddf4a17a8d26f8234ce64a2b..cc9ee2e5a32b7145f67ed90f80837e788bd05388 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c @@ -85,12 +85,12 @@ struct raw_frag_vec { int hlen; }; -struct raw_hashinfo raw_v4_hashinfo; +struct raw_hashinfo_new raw_v4_hashinfo; EXPORT_SYMBOL_GPL(raw_v4_hashinfo); int raw_hash_sk(struct sock *sk) { - struct raw_hashinfo *h = sk->sk_prot->h.raw_hash; + struct raw_hashinfo_new *h = sk->sk_prot->h.raw_hash; struct hlist_nulls_head *hlist; hlist = &h->ht[inet_sk(sk)->inet_num & (RAW_HTABLE_SIZE - 1)]; @@ -107,7 +107,7 @@ EXPORT_SYMBOL_GPL(raw_hash_sk); void raw_unhash_sk(struct sock *sk) { - struct raw_hashinfo *h = sk->sk_prot->h.raw_hash; + struct raw_hashinfo_new *h = sk->sk_prot->h.raw_hash; spin_lock(&h->lock); if (__sk_nulls_del_node_init_rcu(sk)) @@ -944,7 +944,7 @@ struct proto raw_prot = { #ifdef CONFIG_PROC_FS static struct sock *raw_get_first(struct seq_file *seq, int bucket) { - struct raw_hashinfo *h = PDE_DATA(file_inode(seq->file)); + struct raw_hashinfo_new *h = PDE_DATA(file_inode(seq->file)); struct raw_iter_state *state = raw_seq_private(seq); struct hlist_nulls_head *hlist; struct hlist_nulls_node *hnode; diff --git a/net/ipv4/raw_diag.c b/net/ipv4/raw_diag.c index a5fcca24f9eb85b838c16f3e9ac7decb9fce3e7d..70981c6d67ef9405b1d3ac559bc067fc5f4e4a83 100644 --- a/net/ipv4/raw_diag.c +++ b/net/ipv4/raw_diag.c @@ -14,7 +14,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt -static struct raw_hashinfo * +static struct raw_hashinfo_new * raw_get_hashinfo(const struct inet_diag_req_v2 *r) { if (r->sdiag_family == AF_INET) { @@ -56,7 +56,7 @@ static bool raw_lookup(struct net *net, struct sock *sk, static struct sock *raw_sock_get(struct net *net, const struct inet_diag_req_v2 *r) { - struct raw_hashinfo *hashinfo = raw_get_hashinfo(r); + struct raw_hashinfo_new *hashinfo = raw_get_hashinfo(r); struct hlist_nulls_head *hlist; struct hlist_nulls_node *hnode; struct sock *sk; @@ -142,7 +142,7 @@ static void raw_diag_dump(struct sk_buff *skb, struct netlink_callback *cb, const struct inet_diag_req_v2 *r) { bool net_admin = netlink_net_capable(cb->skb, CAP_NET_ADMIN); - struct raw_hashinfo *hashinfo = raw_get_hashinfo(r); + struct raw_hashinfo_new *hashinfo = raw_get_hashinfo(r); struct net *net = sock_net(skb->sk); struct inet_diag_dump_data *cb_data; struct hlist_nulls_head *hlist; diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c index 58287e772613c8c01e4ca835a8ca541c0afade35..2524825e5157eb2c2f4226e0e7a72df07ea030dd 100644 --- a/net/ipv6/af_inet6.c +++ b/net/ipv6/af_inet6.c @@ -62,6 +62,7 @@ #include #include #include +#include #include #include diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c index 20f2d971f3a5301c296977e9dcbdaa76d55949c8..c9cda334fa12495470a85d01ac0a8c0c0e4c4977 100644 --- a/net/ipv6/raw.c +++ b/net/ipv6/raw.c @@ -61,7 +61,7 @@ #define ICMPV6_HDRLEN 4 /* ICMPv6 header, RFC 4443 Section 2.1 */ -struct raw_hashinfo raw_v6_hashinfo; +struct raw_hashinfo_new raw_v6_hashinfo; EXPORT_SYMBOL_GPL(raw_v6_hashinfo); bool raw_v6_match(struct net *net, struct sock *sk, unsigned short num,