mptcp: preserve const qualifier in mptcp_sk()
authorEric Dumazet <edumazet@google.com>
Fri, 17 Mar 2023 15:55:38 +0000 (15:55 +0000)
committerDavid S. Miller <davem@davemloft.net>
Sat, 18 Mar 2023 12:23:34 +0000 (12:23 +0000)
We can change mptcp_sk() to propagate its argument const qualifier,
thanks to container_of_const().

We need to change few things to avoid build errors:

mptcp_set_datafin_timeout() and mptcp_rtx_head() have to accept
non-const sk pointers.

@msk local variable in mptcp_pending_tail() must be const.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Matthieu Baerts <matthieu.baerts@tessares.net>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Reviewed-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/mptcp/protocol.c
net/mptcp/protocol.h

index 6738181b297715faba7cde7127e370ba9a29879f..2d26b911437334f3fff9aad066871c8afa1eb07c 100644 (file)
@@ -459,7 +459,7 @@ static bool mptcp_pending_data_fin(struct sock *sk, u64 *seq)
        return false;
 }
 
-static void mptcp_set_datafin_timeout(const struct sock *sk)
+static void mptcp_set_datafin_timeout(struct sock *sk)
 {
        struct inet_connection_sock *icsk = inet_csk(sk);
        u32 retransmits;
index 339a6f0729898422cfd7e7ee8c014fd09fecbeeb..e1310bc113bef7e37f708e442b24394b5af78644 100644 (file)
@@ -334,10 +334,7 @@ static inline void msk_owned_by_me(const struct mptcp_sock *msk)
        sock_owned_by_me((const struct sock *)msk);
 }
 
-static inline struct mptcp_sock *mptcp_sk(const struct sock *sk)
-{
-       return (struct mptcp_sock *)sk;
-}
+#define mptcp_sk(ptr) container_of_const(ptr, struct mptcp_sock, sk.icsk_inet.sk)
 
 /* the msk socket don't use the backlog, also account for the bulk
  * free memory
@@ -371,7 +368,7 @@ static inline struct mptcp_data_frag *mptcp_send_next(struct sock *sk)
 
 static inline struct mptcp_data_frag *mptcp_pending_tail(const struct sock *sk)
 {
-       struct mptcp_sock *msk = mptcp_sk(sk);
+       const struct mptcp_sock *msk = mptcp_sk(sk);
 
        if (!msk->first_pending)
                return NULL;
@@ -382,7 +379,7 @@ static inline struct mptcp_data_frag *mptcp_pending_tail(const struct sock *sk)
        return list_last_entry(&msk->rtx_queue, struct mptcp_data_frag, list);
 }
 
-static inline struct mptcp_data_frag *mptcp_rtx_head(const struct sock *sk)
+static inline struct mptcp_data_frag *mptcp_rtx_head(struct sock *sk)
 {
        struct mptcp_sock *msk = mptcp_sk(sk);