[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a9a3e00db4764ffcaf3324046d736b76@AcuMS.aculab.com>
Date: Wed, 27 Jul 2022 08:11:26 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Martin KaFai Lau' <kafai@...com>,
"bpf@...r.kernel.org" <bpf@...r.kernel.org>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>
CC: Alexei Starovoitov <ast@...nel.org>,
Andrii Nakryiko <andrii@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
David Miller <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
"kernel-team@...com" <kernel-team@...com>,
Paolo Abeni <pabeni@...hat.com>
Subject: RE: [PATCH bpf-next 01/14] net: Change sock_setsockopt from taking
sock ptr to sk ptr
From: Martin KaFai Lau
> Sent: 27 July 2022 07:09
>
> 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
> a userspace owner. Meaning sk->sk_socket is NULL. For example,
> when a passive tcp connection has just been established. Thus,
> it cannot use the sock_setsockopt(sk->sk_socket) or else it will
> pass a NULL sock ptr.
I'm intrigued, I've some code that uses sock_create_kern() to create
sockets without a userspace owner - I'd have though bpf is doing
much the same.
I end up doing:
if (level == SOL_SOCKET)
err = sock_setsockopt(sock, level, optname, koptval, optlen);
else
err = sock->ops->setsockopt(sock, level, optname, koptval,
optlen);
to set options.
(This code used to use kern_setsockopt() - but that got removed.)
I'd have though bpf would need similar code??
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists