[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <e4a9103e-feaa-7e0d-8597-1fe35b399561@gmail.com>
Date: Thu, 28 Apr 2022 16:27:45 +0100
From: Pavel Begunkov <asml.silence@...il.com>
To: Paolo Abeni <pabeni@...hat.com>, netdev@...r.kernel.org,
"David S . Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>
Cc: David Ahern <dsahern@...nel.org>,
Eric Dumazet <edumazet@...gle.com>,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH net-next 01/11] ipv6: optimise ipcm6 cookie init
On 4/28/22 15:04, Paolo Abeni wrote:
> On Thu, 2022-04-28 at 11:56 +0100, Pavel Begunkov wrote:
>> Users of ipcm6_init() have a somewhat complex post initialisation
>> of ->dontfrag and ->tclass. Not only it adds additional overhead,
>> but also complicates the code.
>>
>> First, replace ipcm6_init() with ipcm6_init_sk(). As it might be not an
>> equivalent change, let's first look at ->dontfrag. The logic was to set
>> it from cmsg if specified and otherwise fallback to np->dontfrag. Now
>> it's initialising to np->dontfrag in the beginning and then potentially
>> overriding with cmsg, which is absolutely the same behaviour.
>>
>> It's a bit more complex with ->tclass as ip6_datagram_send_ctl() might
>> set it to -1, which is a default and not valid value. The solution
>> here is to skip -1's specified in cmsg, so it'll be left with the socket
>> default value getting us to the old behaviour.
>>
>> Signed-off-by: Pavel Begunkov <asml.silence@...il.com>
>> ---
>> include/net/ipv6.h | 9 ---------
>> net/ipv6/datagram.c | 4 ++--
>> net/ipv6/ip6_output.c | 2 --
>> net/ipv6/raw.c | 8 +-------
>> net/ipv6/udp.c | 7 +------
>> net/l2tp/l2tp_ip6.c | 8 +-------
>> 6 files changed, 5 insertions(+), 33 deletions(-)
>>
>> diff --git a/include/net/ipv6.h b/include/net/ipv6.h
>> index 213612f1680c..30a3447e34b4 100644
>> --- a/include/net/ipv6.h
>> +++ b/include/net/ipv6.h
>> @@ -352,15 +352,6 @@ struct ipcm6_cookie {
>> struct ipv6_txoptions *opt;
>> };
>>
>> -static inline void ipcm6_init(struct ipcm6_cookie *ipc6)
>> -{
>> - *ipc6 = (struct ipcm6_cookie) {
>> - .hlimit = -1,
>> - .tclass = -1,
>> - .dontfrag = -1,
>> - };
>> -}
>> -
>> static inline void ipcm6_init_sk(struct ipcm6_cookie *ipc6,
>> const struct ipv6_pinfo *np)
>> {
>> diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
>> index 206f66310a88..1b334bc855ae 100644
>> --- a/net/ipv6/datagram.c
>> +++ b/net/ipv6/datagram.c
>> @@ -1003,9 +1003,9 @@ int ip6_datagram_send_ctl(struct net *net, struct sock *sk,
>> if (tc < -1 || tc > 0xff)
>> goto exit_f;
>>
>> + if (tc != -1)
>> + ipc6->tclass = tc;
>> err = 0;
>> - ipc6->tclass = tc;
>> -
>> break;
>> }
>
> It looks like the above causes a behavioral change: before this patch
> cmsg took precedence on socket status, after this patch looks like it's
> the opposide.
>
> Am I missing something?
before:
ipc6.tclass = -1;
if (cmsg)
ip6_datagram_send_ctl(&ipc6);
if (ipc6.tclass < 0)
ipc6.tclass = np->tclass;
after:
ipc6.tclass = np->tclass; // ipcm6_init_sk()
if (cmsg)
ip6_datagram_send_ctl(&ipc6);
Both should prioritise cmsg. The only catch is when tclass is
specified in cmsg but it's -1. The old version would assign
np->tclass in the end, the new one does the same but with
this added "if" in ip6_datagram_send_ctl() in the chunk
you quoted. Unless I missed something as well.
--
Pavel Begunkov
Powered by blists - more mailing lists