inet: preserve const qualifier in inet_sk()

JIRA: https://issues.redhat.com/browse/RHEL-48648
Upstream Status: linux.git

commit abc17a11ed29b0471e428d86189acca8d1a213c6
Author: Eric Dumazet <edumazet@google.com>
Date:   Thu Mar 16 15:31:55 2023 +0000

    inet: preserve const qualifier in inet_sk()

    We can change inet_sk() to propagate const qualifier of its argument.

    This should avoid some potential errors caused by accidental
    (const -> not_const) promotion.

    Other helpers like tcp_sk(), udp_sk(), raw_sk() will be handled
    in separate patch series.

    v2: use container_of_const() as advised by Jakub and Linus

    Signed-off-by: Eric Dumazet <edumazet@google.com>
    Link: https://lore.kernel.org/netdev/20230315142841.3a2ac99a@kernel.org/
    Link: https://lore.kernel.org/netdev/CAHk-=wiOf12nrYEF2vJMcucKjWPN-Ns_SW9fA7LwST_2Dzp7rw@mail.gmail.com/
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Antoine Tenart <atenart@redhat.com>
This commit is contained in:
Antoine Tenart 2024-07-16 16:09:49 +02:00
parent 8e320d89a7
commit a3c9cc5e4b
8 changed files with 12 additions and 14 deletions

View File

@ -285,10 +285,7 @@ static inline struct sock *skb_to_full_sk(const struct sk_buff *skb)
return sk_to_full_sk(skb->sk);
}
static inline struct inet_sock *inet_sk(const struct sock *sk)
{
return (struct inet_sock *)sk;
}
#define inet_sk(ptr) container_of_const(ptr, struct inet_sock, sk)
static inline void __inet_sk_copy_descendant(struct sock *sk_to,
const struct sock *sk_from,

View File

@ -158,7 +158,7 @@ TRACE_EVENT(inet_sock_set_state,
),
TP_fast_assign(
struct inet_sock *inet = inet_sk(sk);
const struct inet_sock *inet = inet_sk(sk);
struct in6_addr *pin6;
__be32 *p32;
@ -222,7 +222,7 @@ TRACE_EVENT(inet_sk_error_report,
),
TP_fast_assign(
struct inet_sock *inet = inet_sk(sk);
const struct inet_sock *inet = inet_sk(sk);
struct in6_addr *pin6;
__be32 *p32;

View File

@ -67,7 +67,7 @@ DECLARE_EVENT_CLASS(tcp_event_sk_skb,
),
TP_fast_assign(
struct inet_sock *inet = inet_sk(sk);
const struct inet_sock *inet = inet_sk(sk);
__be32 *p32;
__entry->skbaddr = skb;

View File

@ -132,7 +132,8 @@ int ip_local_out(struct net *net, struct sock *sk, struct sk_buff *skb)
}
EXPORT_SYMBOL_GPL(ip_local_out);
static inline int ip_select_ttl(struct inet_sock *inet, struct dst_entry *dst)
static inline int ip_select_ttl(const struct inet_sock *inet,
const struct dst_entry *dst)
{
int ttl = inet->uc_ttl;
@ -149,7 +150,7 @@ int ip_build_and_send_pkt(struct sk_buff *skb, const struct sock *sk,
__be32 saddr, __be32 daddr, struct ip_options_rcu *opt,
u8 tos)
{
struct inet_sock *inet = inet_sk(sk);
const struct inet_sock *inet = inet_sk(sk);
struct rtable *rt = skb_rtable(skb);
struct net *net = sock_net(sk);
struct iphdr *iph;

View File

@ -220,7 +220,7 @@ static int ping_v6_seq_show(struct seq_file *seq, void *v)
seq_puts(seq, IPV6_SEQ_DGRAM_HEADER);
} else {
int bucket = ((struct ping_iter_state *) seq->private)->bucket;
struct inet_sock *inet = inet_sk(v);
struct inet_sock *inet = inet_sk((struct sock *)v);
__u16 srcp = ntohs(inet->inet_sport);
__u16 destp = ntohs(inet->inet_dport);
ip6_dgram_sock_seq_show(seq, v, srcp, destp, bucket);

View File

@ -1713,7 +1713,7 @@ int udp6_seq_show(struct seq_file *seq, void *v)
seq_puts(seq, IPV6_SEQ_DGRAM_HEADER);
} else {
int bucket = ((struct udp_iter_state *)seq->private)->bucket;
struct inet_sock *inet = inet_sk(v);
const struct inet_sock *inet = inet_sk((const struct sock *)v);
__u16 srcp = ntohs(inet->inet_sport);
__u16 destp = ntohs(inet->inet_dport);
__ip6_dgram_sock_seq_show(seq, v, srcp, destp,

View File

@ -1069,7 +1069,7 @@ static int mptcp_getsockopt_tcpinfo(struct mptcp_sock *msk, char __user *optval,
static void mptcp_get_sub_addrs(const struct sock *sk, struct mptcp_subflow_addrs *a)
{
struct inet_sock *inet = inet_sk(sk);
const struct inet_sock *inet = inet_sk(sk);
memset(a, 0, sizeof(*a));

View File

@ -317,7 +317,7 @@ static void dump_common_audit_data(struct audit_buffer *ab,
switch (sk->sk_family) {
case AF_INET: {
struct inet_sock *inet = inet_sk(sk);
const struct inet_sock *inet = inet_sk(sk);
print_ipv4_addr(ab, inet->inet_rcv_saddr,
inet->inet_sport,
@ -329,7 +329,7 @@ static void dump_common_audit_data(struct audit_buffer *ab,
}
#if IS_ENABLED(CONFIG_IPV6)
case AF_INET6: {
struct inet_sock *inet = inet_sk(sk);
const struct inet_sock *inet = inet_sk(sk);
print_ipv6_addr(ab, &sk->sk_v6_rcv_saddr,
inet->inet_sport,