net/tcp: refactor tcp_inet6_sk()

JIRA: https://issues.redhat.com/browse/RHEL-30902

commit fe79bd65c819cc520aa66de65caae8e4cea29c5a
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Fri May 19 14:30:36 2023 +0100

    net/tcp: refactor tcp_inet6_sk()
    
    Don't keep hand coded offset caluclations and replace it with
    container_of(). It should be type safer and a bit less confusing.
    
    It also makes it with a macro instead of inline function to preserve
    constness, which was previously casted out like in case of
    tcp_v6_send_synack().
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Reviewed-by: Simon Horman <simon.horman@corigine.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Felix Maurer <fmaurer@redhat.com>
This commit is contained in:
Felix Maurer 2024-06-07 13:45:30 +02:00
parent 41af358717
commit 8fc3cda22c
1 changed files with 3 additions and 7 deletions

View File

@ -93,12 +93,8 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(const struct sock *sk,
* This avoids a dereference and allow compiler optimizations.
* It is a specialized version of inet6_sk_generic().
*/
static struct ipv6_pinfo *tcp_inet6_sk(const struct sock *sk)
{
unsigned int offset = sizeof(struct tcp6_sock) - sizeof(struct ipv6_pinfo);
return (struct ipv6_pinfo *)(((u8 *)sk) + offset);
}
#define tcp_inet6_sk(sk) (&container_of_const(tcp_sk(sk), \
struct tcp6_sock, tcp)->inet6)
static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
{
@ -527,7 +523,7 @@ static int tcp_v6_send_synack(const struct sock *sk, struct dst_entry *dst,
struct sk_buff *syn_skb)
{
struct inet_request_sock *ireq = inet_rsk(req);
struct ipv6_pinfo *np = tcp_inet6_sk(sk);
const struct ipv6_pinfo *np = tcp_inet6_sk(sk);
struct ipv6_txoptions *opt;
struct flowi6 *fl6 = &fl->u.ip6;
struct sk_buff *skb;