From patchwork Fri May 13 15:26:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12849007 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7CE5DC433EF for ; Fri, 13 May 2022 15:26:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234661AbiEMP0w (ORCPT ); Fri, 13 May 2022 11:26:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381968AbiEMP0u (ORCPT ); Fri, 13 May 2022 11:26:50 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08D5D15803; Fri, 13 May 2022 08:26:48 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id g6so16976073ejw.1; Fri, 13 May 2022 08:26:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NS0EJAZp+0rPTLWVYJ93d+JB/ZGcAv8pGti3LVvcpjY=; b=pBrFe8nLsA/7V80wRN+351c6WWybUimGleeUAf24RlV0LTGjjhm5ab+MjuQjcQBJul CJN35ITxka9b/l/H6KtWmIjsB7v5tmb93kkJn8DbsjfpXjFWOPQiq/Z1chOB5TQ6Cgbt /0IgcrmPo3E0lk5/CiUl9O1+4RaXOLi7C7ZAKVEhzI8tOufEaKxJSwuBSFHSBYtu0Eqd kWnLFb9+GXbND653p6XQthJGOozx3t5VHlFiB52ohYZMpFDr7KVwIhpL7lSoOQh5o+t3 xmH76BovwszxHdXAv/UsKXgei1uhB1JhjRfDJuICkMHxwDpd69vkjKKF7UtCwh+PugL8 4weQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NS0EJAZp+0rPTLWVYJ93d+JB/ZGcAv8pGti3LVvcpjY=; b=8JrsZt+EDakugFeS0nK9Y5v36IsymSuuoluBCyvlK7WEC4CXJ9SWTW0YpnJMnbg2BV 7K6bDOs1ylWtQjYZJjKu61FCuLJgCFdNSrSgLvzty8eVQdKSCT7C5LwfmAafbQR7ZHX7 5FQVJTsvz5Gj7IfAXqu1fVzdYXjmV3Z/7cntoNDeC2KOfJQHpbtY+kczNGtJ9hz5bmEA UFSAPetj+voHCKYZZNtbYocpcr86cp38NQMb2USNqR780wbGY3al7SvBn/vRywnG3MMq dQsNdGRQw7glId2Pbhar7A2s0jwSRL/YWJ4+Fum2rTK6CFK6OW0wqXKtBmIHg79lA8KG pX8w== X-Gm-Message-State: AOAM533vtl2PthyCxHDunGfpTKTFglz2etAdX4EHeQ3f7Db3l7EkDE6X A/Kshk8u41PSpalPm9mrXG+4AEPqiJ8= X-Google-Smtp-Source: ABdhPJy/NcF7De6kBQUtNOI9zYRPteMz9Wi4814U2MisoOVBIQf6suFXIg5/EspUMXmxmhEWk3fXew== X-Received: by 2002:a17:906:c14d:b0:6fd:dd02:7f81 with SMTP id dp13-20020a170906c14d00b006fddd027f81mr4943845ejc.722.1652455607267; Fri, 13 May 2022 08:26:47 -0700 (PDT) Received: from 127.0.0.1localhost ([185.69.144.161]) by smtp.gmail.com with ESMTPSA id j13-20020a508a8d000000b0042617ba63cbsm1015351edj.85.2022.05.13.08.26.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 08:26:46 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH net-next v3 01/10] ipv6: optimise ipcm6 cookie init Date: Fri, 13 May 2022 16:26:06 +0100 Message-Id: <79c491627ca937a6528dd27a1ba6cecd822e1d8d.1652368648.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The common pattern for setting up ipcm6 cookies is to call ipcm6_init() initialising ->dontfrag and tclass fields to -1, which is a special value, and then if the fields haven't changed set it to some default value. For instance ipcm6_init(&ipc6); // ipc6.tclass = -1; if (cmsg) ip6_datagram_send_ctl(&ipc6); if (ipc6.tclass < 0) ipc6.tclass = np->tclass; This prioritieses cmsg over the socket status. This patches changes it to ipcm6_init_sk(), which initially sets those fields to the socket default values, and then lets cmsg to override it: ipcm6_init_sk(&ipc6); // ipc6.tclass = np->tclass; if (cmsg) ip6_datagram_send_ctl(&ipc6); It sets it to the cmsg value if specified and leaves the socket default if not. One difference with this approach is when cmsg sets ->tclass to the special value, i.e. -1, and the old version would catch it and initialise. Thus, this patch also modifies ip6_datagram_send_ctl() to ignore cmsg trying to assign -1 to the ->tclass field. Signed-off-by: Pavel Begunkov --- 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 39b2327edc4e..3a2ae188d08b 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; } diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index afa5bd4ad167..53c0e33e3899 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -2002,8 +2002,6 @@ struct sk_buff *ip6_make_skb(struct sock *sk, ip6_cork_release(cork, &v6_cork); return ERR_PTR(err); } - if (ipc6->dontfrag < 0) - ipc6->dontfrag = inet6_sk(sk)->dontfrag; err = __ip6_append_data(sk, &queue, cork, &v6_cork, ¤t->task_frag, getfrag, from, diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c index 3b7cbd522b54..402e4d9e3f82 100644 --- a/net/ipv6/raw.c +++ b/net/ipv6/raw.c @@ -808,7 +808,7 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) fl6.flowi6_mark = sk->sk_mark; fl6.flowi6_uid = sk->sk_uid; - ipcm6_init(&ipc6); + ipcm6_init_sk(&ipc6, np); ipc6.sockc.tsflags = sk->sk_tsflags; ipc6.sockc.mark = sk->sk_mark; @@ -920,9 +920,6 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) if (hdrincl) fl6.flowi6_flags |= FLOWI_FLAG_KNOWN_NH; - if (ipc6.tclass < 0) - ipc6.tclass = np->tclass; - fl6.flowlabel = ip6_make_flowinfo(ipc6.tclass, fl6.flowlabel); dst = ip6_dst_lookup_flow(sock_net(sk), sk, &fl6, final_p); @@ -933,9 +930,6 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) if (ipc6.hlimit < 0) ipc6.hlimit = ip6_sk_dst_hoplimit(np, &fl6, dst); - if (ipc6.dontfrag < 0) - ipc6.dontfrag = np->dontfrag; - if (msg->msg_flags&MSG_CONFIRM) goto do_confirm; diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index 3fc97d4621ac..11d44ed46953 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -1313,7 +1313,7 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) int is_udplite = IS_UDPLITE(sk); int (*getfrag)(void *, char *, int, int, int, struct sk_buff *); - ipcm6_init(&ipc6); + ipcm6_init_sk(&ipc6, np); ipc6.gso_size = READ_ONCE(up->gso_size); ipc6.sockc.tsflags = sk->sk_tsflags; ipc6.sockc.mark = sk->sk_mark; @@ -1518,9 +1518,6 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) security_sk_classify_flow(sk, flowi6_to_flowi_common(fl6)); - if (ipc6.tclass < 0) - ipc6.tclass = np->tclass; - fl6->flowlabel = ip6_make_flowinfo(ipc6.tclass, fl6->flowlabel); dst = ip6_sk_dst_lookup_flow(sk, fl6, final_p, connected); @@ -1566,8 +1563,6 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) up->pending = AF_INET6; do_append_data: - if (ipc6.dontfrag < 0) - ipc6.dontfrag = np->dontfrag; up->len += ulen; err = ip6_append_data(sk, getfrag, msg, ulen, sizeof(struct udphdr), &ipc6, fl6, (struct rt6_info *)dst, diff --git a/net/l2tp/l2tp_ip6.c b/net/l2tp/l2tp_ip6.c index 217c7192691e..12406789bb28 100644 --- a/net/l2tp/l2tp_ip6.c +++ b/net/l2tp/l2tp_ip6.c @@ -521,7 +521,7 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) fl6.flowi6_mark = sk->sk_mark; fl6.flowi6_uid = sk->sk_uid; - ipcm6_init(&ipc6); + ipcm6_init_sk(&ipc6, np); if (lsa) { if (addr_len < SIN6_LEN_RFC2133) @@ -608,9 +608,6 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) security_sk_classify_flow(sk, flowi6_to_flowi_common(&fl6)); - if (ipc6.tclass < 0) - ipc6.tclass = np->tclass; - fl6.flowlabel = ip6_make_flowinfo(ipc6.tclass, fl6.flowlabel); dst = ip6_dst_lookup_flow(sock_net(sk), sk, &fl6, final_p); @@ -622,9 +619,6 @@ static int l2tp_ip6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) if (ipc6.hlimit < 0) ipc6.hlimit = ip6_sk_dst_hoplimit(np, &fl6, dst); - if (ipc6.dontfrag < 0) - ipc6.dontfrag = np->dontfrag; - if (msg->msg_flags & MSG_CONFIRM) goto do_confirm; From patchwork Fri May 13 15:26:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12849008 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B4CCC433EF for ; Fri, 13 May 2022 15:27:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381996AbiEMP1F (ORCPT ); Fri, 13 May 2022 11:27:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381973AbiEMP0v (ORCPT ); Fri, 13 May 2022 11:26:51 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 799AA1EAC6; Fri, 13 May 2022 08:26:50 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id ks9so16963943ejb.2; Fri, 13 May 2022 08:26:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DZu1vGyRJvfMSB/s4tV6H7jpwGcGvBtFQ856IXndPcQ=; b=ivSAc5Ss+bwVCXF2o/taX96YkXq4gte9BeFc7Rg2VFgcIsWH0dGBSYhGIygnmoPm4i XBFXk7J3W6zhPuPpUWYCL8lwFoA4nfiUY30cKBtVylzK1kkhMv18WLHqE82jA1e6fzkD ONRqucgLp/mzwCtmbW9+dby4B2iget/2OY4gm/m2QTysSpMNG0Qt+yVYbfqS06tATnW5 rA4a9hT2t4ff73cnRLegbL0FrxjSpwkYJDhahPtQ3mp6IlD31fS6vrrRbY6spahqUQPp wAEGmI72MBVrYd0A/KrQQ+GyQgMXqd8NLJZkkyXu9Yq+8R4RkwtXaT6GOrLhyL7q/JBo UTwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DZu1vGyRJvfMSB/s4tV6H7jpwGcGvBtFQ856IXndPcQ=; b=BlwXdJ4n3zVlgvEgdw37d26MVuVoLBCVI8ZuSQIp4wb85Mew3ECjMHC46MPnXP8On+ us6gSh8D2wX80b05XG9q+VNgbmQM9+K+oVctnke94S3vaLZuPElNEwjPQwLYwjwhaVkK V9jw9pfc1alMzcRBBO71QKiTShDESgvEWoVBrB/IW71mlsylvimgV30wF26gjArynPoe w6RPW4LvAkaNnYo/Uk07FMwK46apcZT9FOM21nR6r6u6sE+5GLfwbhhrcyZIWxIiYa/y WgBCYwguSdEaosnfL+fCPAuqmqCX6aSE1wx7Jj3McevXNh+rE7MmDKcCnPwqIJ+jRDft SvUg== X-Gm-Message-State: AOAM533NcA2Y5B6DJiRdG7McIC8RzOqz7Z076VaoN5Sbq9t8ZVRnjhLM eVXPk78KfVMkW3otPbjze7bbtT5kUH8= X-Google-Smtp-Source: ABdhPJwlCuJ5+0i7mNICVTNVdzBucflX4ovUlHMkVIj9lonecTBKgYbn0Id03159P+EQdmMkaogrbQ== X-Received: by 2002:a17:907:960d:b0:6f4:3b68:8d55 with SMTP id gb13-20020a170907960d00b006f43b688d55mr4671925ejc.105.1652455608549; Fri, 13 May 2022 08:26:48 -0700 (PDT) Received: from 127.0.0.1localhost ([185.69.144.161]) by smtp.gmail.com with ESMTPSA id j13-20020a508a8d000000b0042617ba63cbsm1015351edj.85.2022.05.13.08.26.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 08:26:48 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH net-next v3 02/10] udp/ipv6: move pending section of udpv6_sendmsg Date: Fri, 13 May 2022 16:26:07 +0100 Message-Id: X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Move up->pending section of udpv6_sendmsg() to the beginning of the function. Even though it require some code duplication for sin6 parsing, it clearly localises the pending handling in one place, removes an extra if and more importantly will prepare the code for further patches. Signed-off-by: Pavel Begunkov --- net/ipv6/udp.c | 70 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 28 deletions(-) diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index 11d44ed46953..85bff1252f5c 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -1318,6 +1318,46 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) ipc6.sockc.tsflags = sk->sk_tsflags; ipc6.sockc.mark = sk->sk_mark; + /* Rough check on arithmetic overflow, + better check is made in ip6_append_data(). + */ + if (unlikely(len > INT_MAX - sizeof(struct udphdr))) + return -EMSGSIZE; + + getfrag = is_udplite ? udplite_getfrag : ip_generic_getfrag; + + /* There are pending frames. */ + if (up->pending) { + if (up->pending == AF_INET) + return udp_sendmsg(sk, msg, len); + + /* Do a quick destination sanity check before corking. */ + if (sin6) { + if (msg->msg_namelen < offsetof(struct sockaddr, sa_data)) + return -EINVAL; + if (sin6->sin6_family == AF_INET6) { + if (msg->msg_namelen < SIN6_LEN_RFC2133) + return -EINVAL; + if (ipv6_addr_any(&sin6->sin6_addr) && + ipv6_addr_v4mapped(&np->saddr)) + return -EINVAL; + } else if (sin6->sin6_family != AF_UNSPEC) { + return -EINVAL; + } + } + + /* The socket lock must be held while it's corked. */ + lock_sock(sk); + if (unlikely(up->pending != AF_INET6)) { + /* Just now it was seen corked, userspace is buggy */ + err = up->pending ? -EAFNOSUPPORT : -EINVAL; + release_sock(sk); + return err; + } + dst = NULL; + goto do_append_data; + } + /* destination address check */ if (sin6) { if (addr_len < offsetof(struct sockaddr, sa_data)) @@ -1343,12 +1383,11 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) default: return -EINVAL; } - } else if (!up->pending) { + } else { if (sk->sk_state != TCP_ESTABLISHED) return -EDESTADDRREQ; daddr = &sk->sk_v6_daddr; - } else - daddr = NULL; + } if (daddr) { if (ipv6_addr_v4mapped(daddr)) { @@ -1365,31 +1404,6 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) } } - /* Rough check on arithmetic overflow, - better check is made in ip6_append_data(). - */ - if (len > INT_MAX - sizeof(struct udphdr)) - return -EMSGSIZE; - - getfrag = is_udplite ? udplite_getfrag : ip_generic_getfrag; - if (up->pending) { - if (up->pending == AF_INET) - return udp_sendmsg(sk, msg, len); - /* - * There are pending frames. - * The socket lock must be held while it's corked. - */ - lock_sock(sk); - if (likely(up->pending)) { - if (unlikely(up->pending != AF_INET6)) { - release_sock(sk); - return -EAFNOSUPPORT; - } - dst = NULL; - goto do_append_data; - } - release_sock(sk); - } ulen += sizeof(struct udphdr); memset(fl6, 0, sizeof(*fl6)); From patchwork Fri May 13 15:26:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12849009 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 441FDC433EF for ; Fri, 13 May 2022 15:27:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382022AbiEMP1M (ORCPT ); Fri, 13 May 2022 11:27:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381980AbiEMP0w (ORCPT ); Fri, 13 May 2022 11:26:52 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAA241C930; Fri, 13 May 2022 08:26:51 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id a21so10412972edb.1; Fri, 13 May 2022 08:26:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fJZZgrjkTi2qnW8nR0govA2RNr4bkeylxJH5h6SSPcI=; b=itkRUtaB+7FjBPttdl0q8s0A4s4kv4P0zhXHnCuqdVsRxaeDYz3rPP9k7hy6icPm/4 tSc7YmJ4nW+nlYxa2ptt14VEjpSmAA66L49IF4mKyB0uPaGRt/4zEFBT31GjztTtpKnL oVcZ4lHBh7tmqGbOx0W/PyoQl+C2UX4lfOK8I07tTFprYXYLaZ1HUpW+P/6N9qePUa9V RSm0H2iNyDn5mnPJyz0QsJ4EgyDEWjFYFUPac1fUY50MwnXTLXUewxHTbjAkpJAjIvv2 yoHJYEm9s0e3gvjV0oa5shrPMBoiQcYryax4FSg3FKNssv2VK4R+f8ALd6q2Xgh+dKOX 3cng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fJZZgrjkTi2qnW8nR0govA2RNr4bkeylxJH5h6SSPcI=; b=IeUP+N7XZ9BgoaoEnUuWyo9baUKmoiqXcgysig1O7wZ1QWsufWY6eaRG0Al6S49ktV 4e+F3Fu+NQ5WHl9+0inSbEDUNpl9l0dibGw54NvAXTl6AsCsPQQAoKr9x9rSheoi8s00 kzvvxVnvtTcvkUJ+TyyWsmhy+iGPSLG3dc8lelJ5vQC/F3cxBNqqYHQdmr0C1u19jv5+ NQUxgHRtiP4WDbXxsgDlvalN0R5VWz9s552OgKPELbK90DKedx6LavLFPVQgtlEYkNzP K3YHnGcH8tmbgSmzRj1L6NNAOlDN6NWfU8u3jAWaEFg56OQ1tU9VebKcB6D9FxePf3db 79yQ== X-Gm-Message-State: AOAM5328MADDziXG2SkI1tO31p5+E+39xPOalP2mo3Nlpq3hUIby5raZ 8Qc42FhiacROiAKTXJTO6zzbVjLRCt4= X-Google-Smtp-Source: ABdhPJwmO9sZAnEMkpE4QPhtI+gyLA3gKGVloOSQ5aZeKl8rdXstyfkRpHodqot7vd/FsYBjVzfMWw== X-Received: by 2002:a05:6402:4304:b0:427:cb08:b085 with SMTP id m4-20020a056402430400b00427cb08b085mr41024752edc.194.1652455610076; Fri, 13 May 2022 08:26:50 -0700 (PDT) Received: from 127.0.0.1localhost ([185.69.144.161]) by smtp.gmail.com with ESMTPSA id j13-20020a508a8d000000b0042617ba63cbsm1015351edj.85.2022.05.13.08.26.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 08:26:49 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH net-next v3 03/10] udp/ipv6: prioritise the ip6 path over ip4 checks Date: Fri, 13 May 2022 16:26:08 +0100 Message-Id: <50cca375d8730b5bf74b975d0fede64b1a3744c4.1652368648.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org For AF_INET6 sockets we care the most about ipv6 but not ip4 mappings as it's requires some extra hops anyway. Take AF_INET6 case from the address parsing switch and add an explicit path for it. It removes some extra ifs from the path and removes the switch overhead. Signed-off-by: Pavel Begunkov --- net/ipv6/udp.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index 85bff1252f5c..e0b1bea998ce 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -1360,30 +1360,27 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) /* destination address check */ if (sin6) { - if (addr_len < offsetof(struct sockaddr, sa_data)) - return -EINVAL; + if (addr_len < SIN6_LEN_RFC2133 || sin6->sin6_family != AF_INET6) { + if (addr_len < offsetof(struct sockaddr, sa_data)) + return -EINVAL; - switch (sin6->sin6_family) { - case AF_INET6: - if (addr_len < SIN6_LEN_RFC2133) + switch (sin6->sin6_family) { + case AF_INET: + goto do_udp_sendmsg; + case AF_UNSPEC: + msg->msg_name = sin6 = NULL; + msg->msg_namelen = addr_len = 0; + goto no_daddr; + default: return -EINVAL; - daddr = &sin6->sin6_addr; - if (ipv6_addr_any(daddr) && - ipv6_addr_v4mapped(&np->saddr)) - ipv6_addr_set_v4mapped(htonl(INADDR_LOOPBACK), - daddr); - break; - case AF_INET: - goto do_udp_sendmsg; - case AF_UNSPEC: - msg->msg_name = sin6 = NULL; - msg->msg_namelen = addr_len = 0; - daddr = NULL; - break; - default: - return -EINVAL; + } } + + daddr = &sin6->sin6_addr; + if (ipv6_addr_any(daddr) && ipv6_addr_v4mapped(&np->saddr)) + ipv6_addr_set_v4mapped(htonl(INADDR_LOOPBACK), daddr); } else { +no_daddr: if (sk->sk_state != TCP_ESTABLISHED) return -EDESTADDRREQ; daddr = &sk->sk_v6_daddr; From patchwork Fri May 13 15:26:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12849010 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7EB0AC433EF for ; Fri, 13 May 2022 15:27:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381979AbiEMP1P (ORCPT ); Fri, 13 May 2022 11:27:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381990AbiEMP05 (ORCPT ); Fri, 13 May 2022 11:26:57 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E70D41EEDA; Fri, 13 May 2022 08:26:52 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id ch13so16868291ejb.12; Fri, 13 May 2022 08:26:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SqsVpBZTO69SaS86arPCUwx/Sngb5RJIeJy9Pl3nXJs=; b=G5FEGo5NPJnEqtpihWcRp0nfTfjkKyXFvmIiujeTGb4FF2OFWtjC7fm+hBOsYjKHhw EkvQ8n3yG+1VJwRreW/Lp7ZTnhrSBD3/VIIdRFNLgToUnwwhHaqjLPL4bCEGcWVUx9EF pVmLxtFTCidRjum4NlfGZNl1jD0OcRYH+D3HOmZOuKuLeDaTYIc9gT+5mqufVpbutplB g9EHzP6tM6SQgAPpI50MaiwFkNMkYPCGrvw2+xMiGnAqabUm+snhV/rugQvaAN1nXSdw hUGm+d97CHt1Zul+sTIz6OdiiIogQqJ41oy9i7gILbsRO2Fh+Pufsyp13Bj/weBQ7kJs eT9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SqsVpBZTO69SaS86arPCUwx/Sngb5RJIeJy9Pl3nXJs=; b=l40htkN1GbiDLRnSp+5hEBBI+PizdEPBlGPttgDRD2pdPDP6F4EYzHsQlk8EcawryU TRLmwvhHPTsa6nAvkv2SU4aE3iyBMQfHBKx+lFO91wdrNBGjbez+8B41AK9gevuspmUV IwR6xHrzQSxeJIy5GYHxOEgRA+nmJvL5Ho+C8rrVpCJx34XNgw1c8KHCPu1mqHnCy9xF UoxNAyhHY2VDueMYMxmR70SsUHji+s5kWNtu7vsSjFHo6bQFH+3mDWvn8NWAduMhVDGu En+tnN2aSJMiFUgCQvdDgD2N1tu9gpVx+/7jHnSEBoNVHTm8c8ax3JuedgN0+kJr2j1z DK5w== X-Gm-Message-State: AOAM533Eq+KIoMOqVkVTJ4zWgIc7F3SrcefagK4bz9jERWgfC9JOrO+w vI1bjMO/2LTzdoREcWAoA3oIy/Z2dhY= X-Google-Smtp-Source: ABdhPJwK2weACZdaXKWumhZ3sBVozkEGfZk957OqVTilvxG1PCyvh+KEaQJ/3jXh7nDuHIMine7v9Q== X-Received: by 2002:a17:906:7944:b0:6da:b834:2f3e with SMTP id l4-20020a170906794400b006dab8342f3emr4879809ejo.353.1652455611166; Fri, 13 May 2022 08:26:51 -0700 (PDT) Received: from 127.0.0.1localhost ([185.69.144.161]) by smtp.gmail.com with ESMTPSA id j13-20020a508a8d000000b0042617ba63cbsm1015351edj.85.2022.05.13.08.26.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 08:26:50 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH net-next v3 04/10] udp/ipv6: optimise udpv6_sendmsg() daddr checks Date: Fri, 13 May 2022 16:26:09 +0100 Message-Id: <96848ef2c22f73cd819c719fec0ce7a608d1c93e.1652368648.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org All paths taking udpv6_sendmsg() to the ipv6_addr_v4mapped() check set a non zero daddr, we can safely kill the NULL check just before it. Signed-off-by: Pavel Begunkov --- net/ipv6/udp.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index e0b1bea998ce..8a37e2d7b14b 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -1386,19 +1386,18 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) daddr = &sk->sk_v6_daddr; } - if (daddr) { - if (ipv6_addr_v4mapped(daddr)) { - struct sockaddr_in sin; - sin.sin_family = AF_INET; - sin.sin_port = sin6 ? sin6->sin6_port : inet->inet_dport; - sin.sin_addr.s_addr = daddr->s6_addr32[3]; - msg->msg_name = &sin; - msg->msg_namelen = sizeof(sin); + if (ipv6_addr_v4mapped(daddr)) { + struct sockaddr_in sin; + + sin.sin_family = AF_INET; + sin.sin_port = sin6 ? sin6->sin6_port : inet->inet_dport; + sin.sin_addr.s_addr = daddr->s6_addr32[3]; + msg->msg_name = &sin; + msg->msg_namelen = sizeof(sin); do_udp_sendmsg: - if (ipv6_only_sock(sk)) - return -ENETUNREACH; - return udp_sendmsg(sk, msg, len); - } + if (ipv6_only_sock(sk)) + return -ENETUNREACH; + return udp_sendmsg(sk, msg, len); } ulen += sizeof(struct udphdr); From patchwork Fri May 13 15:26:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12849012 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 401CEC433EF for ; Fri, 13 May 2022 15:27:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382040AbiEMP1T (ORCPT ); Fri, 13 May 2022 11:27:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381968AbiEMP1D (ORCPT ); Fri, 13 May 2022 11:27:03 -0400 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05B981EAE2; Fri, 13 May 2022 08:26:54 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id p4so10458088edx.0; Fri, 13 May 2022 08:26:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2f0ybbz8E7mN3j4Tb5d9P3U+4UfBTwfy+rp+to+TOMc=; b=SnN97loAqd01nKEevEa8om4+j+zhtJvbfcYe6gAc4dnVt78jwBv30d9Lj1VwOdRT7j JbdvjHayTNwhnb2Tzihh6iil++p9o51C7jSzJjyk+YLkdwYoj7/9GYL8KtzaBFc5iV/M Ny9+760xuw06BLik3fooaGQHiUkg2QqO/NEx22Dp98VsLHG27j3c6/3MI/QAYwF34D6Q QsrexPPyR45vkMmILm7MZsiu+K53fYaKzje4Ce5c2eCpZg9CnJthPG8aAmdB8grfMBch hH8rzJw6lj2vrbMMMAoVXDxtijDbfUksZ2HaiT7BQLkIj50L3v1+Fr0l+64WoD9aNnso 4iKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2f0ybbz8E7mN3j4Tb5d9P3U+4UfBTwfy+rp+to+TOMc=; b=Sn/jPa1J7OqtT/yiZt5ZcBU/7On8Rg4PULVBmSVgciKUcaUx4Oc8XfehZhyUEUYury umqW43QeHcuBv0UIUnFxWdQ1n8NMgXAhv7ehaVegjBIBU7Pr4OK82dRUE0NYkzQXeKdP BAwewWApKfNIUmnjK9WD09zpqE94v5UnkKbXezF7Sn/MmFWkULFBVH4HaLr2VZDM/Px0 JZt3eAZ8DLQGDYVHAENmvWYnwTUHGSnckBov4+H2BDUQbO7QfwP4l4Y7kTeB3DEdr1Sq oQhEi3D5MN05YA7sBdpZQCyNCW+CcU9KlwIwIM9ti2iWcthaX+a27C3HmZBAh/Tcz68d HDeg== X-Gm-Message-State: AOAM531TVnWq+oQgkptMyBJ78dFpmcgh7h2w71SV8wJ4tghPc8WJF0d5 y/Jf+uFbv4NMuzncPN8doHD8K93tBq8= X-Google-Smtp-Source: ABdhPJxwCDx4BAdWGWk3w9oCniYQ4oGFoyalXpn8i9svkQlZBZXkKzyD7pTLXTt0mdL93QP9y9G1mQ== X-Received: by 2002:a05:6402:278f:b0:428:3c79:4eb8 with SMTP id b15-20020a056402278f00b004283c794eb8mr40872954ede.81.1652455612180; Fri, 13 May 2022 08:26:52 -0700 (PDT) Received: from 127.0.0.1localhost ([185.69.144.161]) by smtp.gmail.com with ESMTPSA id j13-20020a508a8d000000b0042617ba63cbsm1015351edj.85.2022.05.13.08.26.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 08:26:51 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH net-next v3 05/10] udp/ipv6: optimise out daddr reassignment Date: Fri, 13 May 2022 16:26:10 +0100 Message-Id: X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org There is nothing that checks daddr placement in udpv6_sendmsg(), so the check reassigning it to ->sk_v6_daddr looks like a not needed anymore artifact from the past. Remove it. Signed-off-by: Pavel Begunkov --- net/ipv6/udp.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index 8a37e2d7b14b..61dbe2f04675 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -1420,14 +1420,6 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) } } - /* - * Otherwise it will be difficult to maintain - * sk->sk_dst_cache. - */ - if (sk->sk_state == TCP_ESTABLISHED && - ipv6_addr_equal(daddr, &sk->sk_v6_daddr)) - daddr = &sk->sk_v6_daddr; - if (addr_len >= sizeof(struct sockaddr_in6) && sin6->sin6_scope_id && __ipv6_addr_needs_scope_id(__ipv6_addr_type(daddr))) From patchwork Fri May 13 15:26:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12849014 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2B38C4332F for ; Fri, 13 May 2022 15:27:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382055AbiEMP1W (ORCPT ); Fri, 13 May 2022 11:27:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382008AbiEMP1K (ORCPT ); Fri, 13 May 2022 11:27:10 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD41D205F8; Fri, 13 May 2022 08:26:54 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id m20so16892035ejj.10; Fri, 13 May 2022 08:26:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MdffPT0YM78EitIudyoFbqjCIcS1NHxhBv6aczYla1Q=; b=IWf5fvyqwI7ymlG6Mvh6Uai+D7DbXCSJlMEODdUs83qoW1qJFQHPBk2dER5lq2ec9Y 96SCA1zyQ1289Or2jJ78YV5ALyxGM/7jPbYAgqmaJgv9GL5XDRDamptB9fixG/eXdCVz V/K1akmkHRsfKeHLIyXyis+y3MaM73zSMd6EHuJUNSrDZIGylgev1aZOqe3+3vPi4e1H 6WbFuy29+854tqzrMPlkOYRkXSGbWuvKXctuulP+PBXvKeda3TX/ivOKQSuk68FD0pp5 P+rCLZ5u8BcTfnEmOmbrS8Oy6o+hIS1SGtSJCXdDUS3W6e1aDVqQ6taHMCVk9EwMjw0+ 6Lqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MdffPT0YM78EitIudyoFbqjCIcS1NHxhBv6aczYla1Q=; b=0Eh8W30WsIt+FFeXCNLGPTJyGLiSmpf78HfDNECrFaJ5aoq60+CiMAgD87WMA3PGp+ GnL9zoAWTUCoYB6aXCO0SfqS7w0cdBhM8jYSxxcHBdrX909O/mTtMx7vFvjyryn+ARRd oxAq+ZyEaAt7vqJ1XpMI/sALOV37cwslsES4C/5uUkpies8avSy96RQmj2s5AWatPF85 Vc3YrSmnIxwpvnP5A2eVonmIRalA9VHFilMPD7dIMnr3egBGbh/FQFD2HRzYhwXFEHOg ZiW0rSVxWSjAUFUiRlJ15kpebKx3Oefj1qyMR050LYcAjKGImEe0pIWVywZIsxK7tvEN BCdw== X-Gm-Message-State: AOAM530PPZHc3tEFDi43r/jOqUQzN2+epvlowW1fPQ3bewZR3nEZHa9O MEeffANLuDutuYzKEz9WZXjrohAg9s4= X-Google-Smtp-Source: ABdhPJw9jBhhp+PMj+9mJMyRz2PcqazYPwajbKaFd+y4ODIv0RhFDwpfytllQNC23xspaWUCbENPNQ== X-Received: by 2002:a17:907:d1d:b0:6fa:1f27:b39 with SMTP id gn29-20020a1709070d1d00b006fa1f270b39mr4554972ejc.146.1652455613343; Fri, 13 May 2022 08:26:53 -0700 (PDT) Received: from 127.0.0.1localhost ([185.69.144.161]) by smtp.gmail.com with ESMTPSA id j13-20020a508a8d000000b0042617ba63cbsm1015351edj.85.2022.05.13.08.26.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 08:26:52 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH net-next v3 06/10] udp/ipv6: clean up udpv6_sendmsg's saddr init Date: Fri, 13 May 2022 16:26:11 +0100 Message-Id: <2a0bd67940ed265cb9f4734f602792da37292968.1652368648.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org We initialise fl6 in udpv6_sendmsg() to zeroes, that sets saddr to any addr, then it might be changed in by cmsg but only to a non-any addr. After we check again for it left set to "any", which is likely to be so, and try to initialise it from socket saddr. The result of it is that fl6->saddr is set to cmsg's saddr if specified and inet6_sk(sk)->saddr otherwise. We can achieve the same by pre-setting it to the sockets saddr and potentially overriding by cmsg after. This looks a bit cleaner comparing to conditional init and also removes extra checks from the way. Signed-off-by: Pavel Begunkov --- net/ipv6/udp.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index 61dbe2f04675..9bd317c2b67f 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -1434,14 +1434,15 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) connected = true; } + fl6->flowi6_uid = sk->sk_uid; + fl6->saddr = np->saddr; + fl6->daddr = *daddr; + if (!fl6->flowi6_oif) fl6->flowi6_oif = sk->sk_bound_dev_if; - if (!fl6->flowi6_oif) fl6->flowi6_oif = np->sticky_pktinfo.ipi6_ifindex; - fl6->flowi6_uid = sk->sk_uid; - if (msg->msg_controllen) { opt = &opt_space; memset(opt, 0, sizeof(struct ipv6_txoptions)); @@ -1476,9 +1477,6 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) fl6->flowi6_proto = sk->sk_protocol; fl6->flowi6_mark = ipc6.sockc.mark; - fl6->daddr = *daddr; - if (ipv6_addr_any(&fl6->saddr) && !ipv6_addr_any(&np->saddr)) - fl6->saddr = np->saddr; fl6->fl6_sport = inet->inet_sport; if (cgroup_bpf_enabled(CGROUP_UDP6_SENDMSG) && !connected) { From patchwork Fri May 13 15:26:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12849015 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07BE1C433F5 for ; Fri, 13 May 2022 15:27:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382058AbiEMP1X (ORCPT ); Fri, 13 May 2022 11:27:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382009AbiEMP1K (ORCPT ); Fri, 13 May 2022 11:27:10 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD8E020BE8; Fri, 13 May 2022 08:26:56 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id m20so16892158ejj.10; Fri, 13 May 2022 08:26:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jDy/baqCrS7ciidt4u0hxQhcY5iVuejvnMqLkeL0Gp4=; b=LshU9/1jjUekd5qQFD1YNEmSfgMX1tJfwK7Tg8HB9IDHIC/4Cqy4riAvjUXzsdNyqQ Ted+HL9KvDDc2CZRpgZkYBGna+48T5y7uakRkzQzZ6Fwx8imlTaLLrC+oOFJsHNTP9sd EHxg/1j9u90pci2DBZDbWcHtK58qAiUaTf8kU7MqW840m01gOR6kDGANYyDFhTR4uzvT fi4RP7fr7NiasnAhAtFxpC1C7EbMpUuFF1MHh+CSrccv4tsGPGsZxo27yoA13nlV+UGa i68rs3I7mNlDeOYYbJ6Ukk7C01n+sc3cmGGYXH1Wz39XN27BrSU8yA5XZJzjTLTbMxHA hY1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jDy/baqCrS7ciidt4u0hxQhcY5iVuejvnMqLkeL0Gp4=; b=n8b9Vrk5ugN1UbqMnm0p4V6JSqFO0kGOx0BIzlBDO/aplSB04x+i6JWqH9rgnju75o tOMLWYX6cQzrgvNdpb7OF3hBkpw3Zk+n5ORJ3sBIBKKPV3ePldU09Kuqr3bnK9KJuw0R YyfSkWgsKemmRZpwckCMChQd0cjNs61P5R+sCuw1ndakeuCdhy1n9CrlYnOD+cwNLF82 ijdXidgGztgnAuizUJuw/gW3poYvuCtRFOsq3ksnKLXUwgZ9+8lQG/l1hFoZYpNaK1hq LpnSqkCpYsw/gGaVhDPbsWH86JbouiTqn7QcdpvQvjVgb5witBJiyOp7WquTDsWuslT6 OFiQ== X-Gm-Message-State: AOAM532OGAWahX44fKoEI7+35AM3kt5jYWgK5PpKwGapejPYJmNSwEkL uXa3fkiJdhkN/iPlnzjmvzItaFZ8tSE= X-Google-Smtp-Source: ABdhPJz5350Z2tA4TxG8Yw5oq2blWgH73d4InzjH5+r8bz9pmoG2c1KIe8Vb5YI1WKtAFpZzeGlKIQ== X-Received: by 2002:a17:907:90cf:b0:6f4:346f:f771 with SMTP id gk15-20020a17090790cf00b006f4346ff771mr4699837ejb.574.1652455614559; Fri, 13 May 2022 08:26:54 -0700 (PDT) Received: from 127.0.0.1localhost ([185.69.144.161]) by smtp.gmail.com with ESMTPSA id j13-20020a508a8d000000b0042617ba63cbsm1015351edj.85.2022.05.13.08.26.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 08:26:54 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH net-next v3 07/10] ipv6: partially inline fl6_update_dst() Date: Fri, 13 May 2022 16:26:12 +0100 Message-Id: <149e1cc1fea227e687ab63c2f33a7b314ecb91f0.1652368648.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org fl6_update_dst() doesn't do anything when there are no opts passed. Inline the null checking part. Signed-off-by: Pavel Begunkov --- include/net/ipv6.h | 15 ++++++++++++--- net/ipv6/exthdrs.c | 15 ++++++--------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/include/net/ipv6.h b/include/net/ipv6.h index 30a3447e34b4..b9848fcd6954 100644 --- a/include/net/ipv6.h +++ b/include/net/ipv6.h @@ -1094,9 +1094,18 @@ int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset, int target, int ipv6_find_tlv(const struct sk_buff *skb, int offset, int type); -struct in6_addr *fl6_update_dst(struct flowi6 *fl6, - const struct ipv6_txoptions *opt, - struct in6_addr *orig); +struct in6_addr *__fl6_update_dst(struct flowi6 *fl6, + const struct ipv6_txoptions *opt, + struct in6_addr *orig); + +static inline struct in6_addr *fl6_update_dst(struct flowi6 *fl6, + const struct ipv6_txoptions *opt, + struct in6_addr *orig) +{ + if (!opt || !opt->srcrt) + return NULL; + return __fl6_update_dst(fl6, opt, orig); +} /* * socket options (ipv6_sockglue.c) diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c index a8d961d3a477..d02c27d4f2c2 100644 --- a/net/ipv6/exthdrs.c +++ b/net/ipv6/exthdrs.c @@ -1367,8 +1367,8 @@ struct ipv6_txoptions *__ipv6_fixup_options(struct ipv6_txoptions *opt_space, EXPORT_SYMBOL_GPL(__ipv6_fixup_options); /** - * fl6_update_dst - update flowi destination address with info given - * by srcrt option, if any. + * __fl6_update_dst - update flowi destination address with info given + * by srcrt option. * * @fl6: flowi6 for which daddr is to be updated * @opt: struct ipv6_txoptions in which to look for srcrt opt @@ -1377,13 +1377,10 @@ EXPORT_SYMBOL_GPL(__ipv6_fixup_options); * Returns NULL if no txoptions or no srcrt, otherwise returns orig * and initial value of fl6->daddr set in orig */ -struct in6_addr *fl6_update_dst(struct flowi6 *fl6, - const struct ipv6_txoptions *opt, - struct in6_addr *orig) +struct in6_addr *__fl6_update_dst(struct flowi6 *fl6, + const struct ipv6_txoptions *opt, + struct in6_addr *orig) { - if (!opt || !opt->srcrt) - return NULL; - *orig = fl6->daddr; switch (opt->srcrt->type) { @@ -1405,4 +1402,4 @@ struct in6_addr *fl6_update_dst(struct flowi6 *fl6, return orig; } -EXPORT_SYMBOL_GPL(fl6_update_dst); +EXPORT_SYMBOL_GPL(__fl6_update_dst); From patchwork Fri May 13 15:26:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12849011 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A6EAC4332F for ; Fri, 13 May 2022 15:27:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382033AbiEMP1Q (ORCPT ); Fri, 13 May 2022 11:27:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381994AbiEMP1D (ORCPT ); Fri, 13 May 2022 11:27:03 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C803D20F59; Fri, 13 May 2022 08:26:57 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id n10so16958500ejk.5; Fri, 13 May 2022 08:26:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BE2B7uKhNXQyg8J2kv6NnIFx4l6JsKDKmGAV5Q3AWIU=; b=cSQzIJFGbs6YjIOnMw/vwXKddJ7ZQRnMY3HOlTGeyOgYwaeP8PlznsbOtrgI8dloJq QvLoZ8TgMyZPXZt9QeGR1c/q5OTkR5O5XLH0hBXDeLNj37xzjNRhA3H7uQCAp5DJIBxf SwGJHOtiI/ZcffHh16aOc9y9UMFqMM19FH6fmFimBntm7CImnBckGAQYDV2puE6m1iOQ 5oAAEWwT7FLn9jPjrUunHslgHt1TgVk9QnHaSDhd+tWC3xdkNdFmg5huaSyd9aaHaiul 4CINtSms8YWv4IAyQXN2EhcL73PC8xw51OpBZftwvltgHkME0Wh+bGnV9nWXRi98X7LI tmwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BE2B7uKhNXQyg8J2kv6NnIFx4l6JsKDKmGAV5Q3AWIU=; b=TDWmjvBdAC8shZlTzoktj3j5GD+YZHGXH11d76MhTzUkoS92TWq0Ku7r5DnpeYBrdu DaR5BRTOhSeQlRLx4ISJIYbQGLX/aUahaKiunv434fmduz1C+cwKGSO+88gjhfqDnT2P wMVEQ9o90phh7UxAlfeeF+Esxz37V7FH4OihABjfbqXqje/FaoJpDEDcit9pQru8KaKX o3D7QP2kG0Ivrjx3FTC/HWLy+KdXe0Gm1JP5goOHHeaKOzlnZpAMMD4SnK9Q5DeEC+/G 7LA0n/6bGZSqFegReI/yrMSht6YZARuC/fjdDUP0zyuTs8YHFUo+zu7r0DIZfkJm7+n2 jtDA== X-Gm-Message-State: AOAM530IszcohDu2ECavduJKyFynbA69DtJ+V9O8OTXgG91K1kpWCscf vAZ6SbQRMXRce2MvbysqrTgSkBtqXrY= X-Google-Smtp-Source: ABdhPJzeHzP56uLb9ZBQ+E5L/mcOfpQjQ0kh9CSyHC+1ERuzQLdRpzCN+rVBNGUeFgJVudUNWHKu8w== X-Received: by 2002:a17:906:fca:b0:6f3:e2d8:7c57 with SMTP id c10-20020a1709060fca00b006f3e2d87c57mr4802766ejk.320.1652455615584; Fri, 13 May 2022 08:26:55 -0700 (PDT) Received: from 127.0.0.1localhost ([185.69.144.161]) by smtp.gmail.com with ESMTPSA id j13-20020a508a8d000000b0042617ba63cbsm1015351edj.85.2022.05.13.08.26.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 08:26:55 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH net-next v3 08/10] ipv6: refactor opts push in __ip6_make_skb() Date: Fri, 13 May 2022 16:26:13 +0100 Message-Id: <27c44aad28badebcaef184bd993b8f6c719ce1f8.1652368648.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Don't preload v6_cork->opt before we actually need it, it likely to be saved on the stack and read again for no good reason. Signed-off-by: Pavel Begunkov --- net/ipv6/ip6_output.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 53c0e33e3899..e2a6b9bdf79c 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -1856,7 +1856,6 @@ struct sk_buff *__ip6_make_skb(struct sock *sk, struct ipv6_pinfo *np = inet6_sk(sk); struct net *net = sock_net(sk); struct ipv6hdr *hdr; - struct ipv6_txoptions *opt = v6_cork->opt; struct rt6_info *rt = (struct rt6_info *)cork->base.dst; struct flowi6 *fl6 = &cork->fl.u.ip6; unsigned char proto = fl6->flowi6_proto; @@ -1885,10 +1884,14 @@ struct sk_buff *__ip6_make_skb(struct sock *sk, __skb_pull(skb, skb_network_header_len(skb)); final_dst = &fl6->daddr; - if (opt && opt->opt_flen) - ipv6_push_frag_opts(skb, opt, &proto); - if (opt && opt->opt_nflen) - ipv6_push_nfrag_opts(skb, opt, &proto, &final_dst, &fl6->saddr); + if (v6_cork->opt) { + struct ipv6_txoptions *opt = v6_cork->opt; + + if (opt->opt_flen) + ipv6_push_frag_opts(skb, opt, &proto); + if (opt->opt_nflen) + ipv6_push_nfrag_opts(skb, opt, &proto, &final_dst, &fl6->saddr); + } skb_push(skb, sizeof(struct ipv6hdr)); skb_reset_network_header(skb); From patchwork Fri May 13 15:26:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12849013 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C568C433FE for ; Fri, 13 May 2022 15:27:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382013AbiEMP1U (ORCPT ); Fri, 13 May 2022 11:27:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382002AbiEMP1K (ORCPT ); Fri, 13 May 2022 11:27:10 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53D81248E1; Fri, 13 May 2022 08:26:58 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id dk23so16912568ejb.8; Fri, 13 May 2022 08:26:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=D3zbuxrZpd+reD5tDBCOEJ+DWKYB665DXVybKfumiKM=; b=a2aR40sJG6BWUFVttOS4UgRwO+TWZAJbA06M13tI3yoNRxU2vLx43aOBEvbwt7hwGR pu6EI2wDTGdXYyxKEXXMJufvEQx/4gWk7dUikNKsdETYDlE40QUmPugKPCuCU1JHCe9U iNQPf35K0W9S46ty3/utcnzrJDAdyTC4QSwlKSupe0KMxQqE55JbaTiz5cVS3MNgB4fH kKPx1Iu/Ar6U40MGrbO3KSE358F6E6gaKXBiY/Q646g1GV2g4Q11vgodj885RS+JxkQF GroY6Mto11rjK0gZS7RBbsCJjNAb5IpfUaRLxczWazGwEqtFjaTkPv3EpnVjHLANV4QD U/cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=D3zbuxrZpd+reD5tDBCOEJ+DWKYB665DXVybKfumiKM=; b=ULTG4cE1Rb5diP37CLUe5XeOAlmpl+SSmdkVz3Ukj//9/o2B7dO3yJgtLojojNvT3y 6hTjUMktx379O0DN6ANx6zCkpHEjKVnVZ0hQ43vTraYYD8Ycwyv08PTZbr6pahv5VvZ/ bB4apWSMKvBfzgrjK50kTkftXWIkljAoqTfiv5DTQoplbmjcj+TjBRc/xKmCrgyPZ/h9 d9+h9Ngegx5WIe2uDa8kP9IkPLgNPnsvVc4Ix3iomUqlT6VDvkRXcxFIRnulriOHTd3p yH2qWQav8pcLNK3LYLLRCtml29CDWyMBWWP+og0RbF9OdkyPtQzfOWg+5lxT2qbV9FPH GPgQ== X-Gm-Message-State: AOAM5329jW1YVR+doD3xdDwOHDxKzkc60+3/dFPvrPX3QRgAOYwhyaGa 7FyjkZ0EbWf/SH8FhO1o8PZiMU7BZOA= X-Google-Smtp-Source: ABdhPJznqoQK/z/eWLpGyAc6/miENx/pfikUFEFO5W0CiflFf/EkNvJETpsr8MqzRt5M/XtGrJMA6w== X-Received: by 2002:a17:907:6e88:b0:6fa:888d:74a7 with SMTP id sh8-20020a1709076e8800b006fa888d74a7mr4774036ejc.335.1652455616628; Fri, 13 May 2022 08:26:56 -0700 (PDT) Received: from 127.0.0.1localhost ([185.69.144.161]) by smtp.gmail.com with ESMTPSA id j13-20020a508a8d000000b0042617ba63cbsm1015351edj.85.2022.05.13.08.26.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 08:26:56 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH net-next v3 09/10] ipv6: improve opt-less __ip6_make_skb() Date: Fri, 13 May 2022 16:26:14 +0100 Message-Id: <84e2968f7783e478e60f74fa712485d83c904de8.1652368648.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org We do a bit of a network header pointer shuffling in __ip6_make_skb() expecting that ipv6_push_*frag_opts() might change the layout. Avoid it with associated overhead when there are no opts. Signed-off-by: Pavel Begunkov --- net/ipv6/ip6_output.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index e2a6b9bdf79c..6ee44c509485 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -1881,22 +1881,20 @@ struct sk_buff *__ip6_make_skb(struct sock *sk, /* Allow local fragmentation. */ skb->ignore_df = ip6_sk_ignore_df(sk); - __skb_pull(skb, skb_network_header_len(skb)); - final_dst = &fl6->daddr; if (v6_cork->opt) { struct ipv6_txoptions *opt = v6_cork->opt; + __skb_pull(skb, skb_network_header_len(skb)); if (opt->opt_flen) ipv6_push_frag_opts(skb, opt, &proto); if (opt->opt_nflen) ipv6_push_nfrag_opts(skb, opt, &proto, &final_dst, &fl6->saddr); + skb_push(skb, sizeof(struct ipv6hdr)); + skb_reset_network_header(skb); } - skb_push(skb, sizeof(struct ipv6hdr)); - skb_reset_network_header(skb); hdr = ipv6_hdr(skb); - ip6_flow_hdr(hdr, v6_cork->tclass, ip6_make_flowlabel(net, skb, fl6->flowlabel, ip6_autoflowlabel(net, np), fl6)); From patchwork Fri May 13 15:26:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12849016 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7293C4332F for ; Fri, 13 May 2022 15:27:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382064AbiEMP1Z (ORCPT ); Fri, 13 May 2022 11:27:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382012AbiEMP1K (ORCPT ); Fri, 13 May 2022 11:27:10 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44666248DD; Fri, 13 May 2022 08:26:58 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id z2so16958770ejj.3; Fri, 13 May 2022 08:26:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ojlGOBCpkisLhdBLZc5xu5fbD3iLbV6lB886LLnQg1w=; b=FxnvipMwHXfyVVeiBLqbMdLNV5U4F0yr5igQCC7dsfDdEcL35Nh+CKGbHkSA2RRujI qRtj6fP0onfppiUtnZFstFQyer4u9ERWj8xeNVoyiRQr4kOhm8FRiv2uo4rxrBv/eT3W WyrDkp5sddZ+j4YnzAWpV7Yoo9XgnO+vIHqAik5b03AtuSM36WxAnnalkp+W2Uot+61/ gh+cqGZoYUFujdSW4ZN3DzbNUK4BLV7hOVZRStVIe9MkXNtnUhAcIPeEIYeshloz5bwu IANF26vuHPdCB+o/XARjfVwKTAHTvrvmcH41BfbW7ZdV68InWVMq68x5z3mls5qKHjaa YlLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ojlGOBCpkisLhdBLZc5xu5fbD3iLbV6lB886LLnQg1w=; b=Tj/v412+JPjDGboqsIb0odOZzmi07O8F+WKSNVQe3v1UcCKN3/Gi2rP6NW2IL0FUJ7 59oMRoiWUCX1dTGdlXjjn18wsnVDuSJgm+RZsbjPWXaiSAjETDasfazIfICiT2u6nCMP qavYfFPYs7VzdyJDIbXxpEwhorGqBD2uVrGXUO0hn0sGaW5LEmX53mjJHkAwEAlV+BHt lWqsgsFHs1otjHDnstSXnykxz6Z+nRPZf0bdu/k0nifDv0Ro95yStAWRSybiOVkk8PKA C+ZJq743X4bcfOe0Tu7ZHFax5dmC5nj2MuzxSrbC2hCH29CxPXJ0LP6WajmY705449CW 58BA== X-Gm-Message-State: AOAM532Fc6PJtldvPIXkeexZMCPnUFsNo8ijToyO57Wrlmp5C/5WEQOU BbYa2FqdqS3R5asX5H746B/EHwh5hSs= X-Google-Smtp-Source: ABdhPJwwrP/iB1n7B9SUctoDqawFOEMzLHfDXlG7K8RA7Xk3mMBBmsfD0iJsfYwuW2CGYhvrNWG+xA== X-Received: by 2002:a17:906:24db:b0:6f3:a29f:95dc with SMTP id f27-20020a17090624db00b006f3a29f95dcmr4979024ejb.520.1652455617555; Fri, 13 May 2022 08:26:57 -0700 (PDT) Received: from 127.0.0.1localhost ([185.69.144.161]) by smtp.gmail.com with ESMTPSA id j13-20020a508a8d000000b0042617ba63cbsm1015351edj.85.2022.05.13.08.26.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 08:26:57 -0700 (PDT) From: Pavel Begunkov To: netdev@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: David Ahern , Eric Dumazet , linux-kernel@vger.kernel.org, Pavel Begunkov Subject: [PATCH net-next v3 10/10] ipv6: clean up ip6_setup_cork Date: Fri, 13 May 2022 16:26:15 +0100 Message-Id: X-Mailer: git-send-email 2.36.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Do a bit of refactoring for ip6_setup_cork(). Cache a xfrm_dst_path() result to not call it twice, reshuffle ifs to not repeat some parts twice and so. Signed-off-by: Pavel Begunkov --- net/ipv6/ip6_output.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 6ee44c509485..61dfe3eca773 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -1359,15 +1359,13 @@ static int ip6_setup_cork(struct sock *sk, struct inet_cork_full *cork, struct ipv6_pinfo *np = inet6_sk(sk); unsigned int mtu; struct ipv6_txoptions *nopt, *opt = ipc6->opt; + struct dst_entry *xrfm_dst; /* callers pass dst together with a reference, set it first so * ip6_cork_release() can put it down even in case of an error. */ cork->base.dst = &rt->dst; - /* - * setup for corking - */ if (opt) { if (WARN_ON(v6_cork->opt)) return -EINVAL; @@ -1400,28 +1398,26 @@ static int ip6_setup_cork(struct sock *sk, struct inet_cork_full *cork, } v6_cork->hop_limit = ipc6->hlimit; v6_cork->tclass = ipc6->tclass; - if (rt->dst.flags & DST_XFRM_TUNNEL) - mtu = np->pmtudisc >= IPV6_PMTUDISC_PROBE ? - READ_ONCE(rt->dst.dev->mtu) : dst_mtu(&rt->dst); + + xrfm_dst = xfrm_dst_path(&rt->dst); + if (dst_allfrag(xrfm_dst)) + cork->base.flags |= IPCORK_ALLFRAG; + + if (np->pmtudisc < IPV6_PMTUDISC_PROBE) + mtu = dst_mtu(rt->dst.flags & DST_XFRM_TUNNEL ? &rt->dst : xrfm_dst); else - mtu = np->pmtudisc >= IPV6_PMTUDISC_PROBE ? - READ_ONCE(rt->dst.dev->mtu) : dst_mtu(xfrm_dst_path(&rt->dst)); - if (np->frag_size < mtu) { - if (np->frag_size) - mtu = np->frag_size; - } + mtu = READ_ONCE(rt->dst.dev->mtu); + + if (np->frag_size < mtu && np->frag_size) + mtu = np->frag_size; + cork->base.fragsize = mtu; cork->base.gso_size = ipc6->gso_size; cork->base.tx_flags = 0; cork->base.mark = ipc6->sockc.mark; sock_tx_timestamp(sk, ipc6->sockc.tsflags, &cork->base.tx_flags); - - if (dst_allfrag(xfrm_dst_path(&rt->dst))) - cork->base.flags |= IPCORK_ALLFRAG; cork->base.length = 0; - cork->base.transmit_time = ipc6->sockc.transmit_time; - return 0; }