• M
    net: Add sk_setsockopt() to take the sk ptr instead of the sock ptr · 4d748f99
    Martin KaFai Lau 提交于
    A latter patch refactors bpf_setsockopt(SOL_SOCKET) with the
    sock_setsockopt() to avoid code duplication and code
    drift between the two duplicates.
    
    The current sock_setsockopt() takes sock ptr as the argument.
    The very first thing of this function is to get back the sk ptr
    by 'sk = sock->sk'.
    
    bpf_setsockopt() could be called when the sk does not have
    the sock ptr created.  Meaning sk->sk_socket is NULL.  For example,
    when a passive tcp connection has just been established but has yet
    been accept()-ed.  Thus, it cannot use the sock_setsockopt(sk->sk_socket)
    or else it will pass a NULL ptr.
    
    This patch moves all sock_setsockopt implementation to the newly
    added sk_setsockopt().  The new sk_setsockopt() takes a sk ptr
    and immediately gets the sock ptr by 'sock = sk->sk_socket'
    
    The existing sock_setsockopt(sock) is changed to call
    sk_setsockopt(sock->sk).  All existing callers have both sock->sk
    and sk->sk_socket pointer.
    
    The latter patch will make bpf_setsockopt(SOL_SOCKET) call
    sk_setsockopt(sk) directly.  The bpf_setsockopt(SOL_SOCKET) does
    not use the optnames that require sk->sk_socket, so it will
    be safe.
    Reviewed-by: NStanislav Fomichev <sdf@google.com>
    Signed-off-by: NMartin KaFai Lau <kafai@fb.com>
    Link: https://lore.kernel.org/r/20220817061711.4175048-1-kafai@fb.comSigned-off-by: NAlexei Starovoitov <ast@kernel.org>
    4d748f99
sock.c 96.1 KB