Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp106908ybg; Mon, 8 Jun 2020 17:46:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzY0PiITRBxH+SA8FKMu1vEKvUQEDVYSNCYhbRMxK0qS5EGgmCc/HxBeCRsDLjRUzqH7Bna X-Received: by 2002:a05:6402:3044:: with SMTP id bu4mr24536871edb.69.1591663615140; Mon, 08 Jun 2020 17:46:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591663615; cv=none; d=google.com; s=arc-20160816; b=n5FL/7n1MrZtOaKhsMnsShbso6Dk7AVlJdQ31NJ2LDC22Ftj0PrfesCB49f4dytbO6 K4X9AfMxfTVe0itCmhKg3kJ+fa52CVfFD3nulX3wvobudmbj45i087KQdLB8RKC5R7GC OiQyGYl/7KDsjC/F+VPkafvzRKCeYqTQXYSNEsFpcPUPleCuIdoTdoAmu3HWLe2uGbMQ XgjgDl7RncsEFuv1uhqAlElXsjMPFemeKmHIvQ2nBGaAZ+j79lPbjGES8b7Of+r1s52Y SEKeb19rZix8iS+R24gEN8B5RqEH36HqtzNPX7kwdeeYVK/AAle20JlPUWZqowp8Ytmk ApYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YyyCwzaMRA4dGTIoM8yqfQtvX9xOUy/RWDBFfIzr4jk=; b=f1MwYtJ/frOF/Rg714VHZh5X3Vky4r3x1ncEUIiz9UWnrZpd+gM1bH5rPpfgSCwbQp q1He49x2oQFD/mj928T08/33GyfN4RKti8UeJ2HSpwCMXw5zKvtEXBnKtlDL3jzqQSHr KtiTfVjgobKtWar1Hc4VMNe3s1GHMHrimvpy18hOFtdmQm6cewbaIExbrHGcTbph24nT d7ewyyOGk7NkhmzzrYDw8YrotLc/8gqfFCtnOgi+fvH44GBBdvnYo3ME/lmeBEB8OKqB kFB5v7tf3th9HPnaiESohB7ZWY2nJFWpD/d/LBiKwTxLx47wj2NnxNeUN6iqPW9Ny/ai Jw3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="p/5sZVUP"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dd25si10292041edb.134.2020.06.08.17.46.31; Mon, 08 Jun 2020 17:46:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="p/5sZVUP"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733222AbgFIAov (ORCPT + 99 others); Mon, 8 Jun 2020 20:44:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:59066 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728244AbgFHXL5 (ORCPT ); Mon, 8 Jun 2020 19:11:57 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 22139208C3; Mon, 8 Jun 2020 23:11:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591657917; bh=fy02eLuhzPt5qrxj0NR1EGOO8siKTXnQaq5uk9noZPg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p/5sZVUPGvkfzOFh1brwrJKtQIy99vsCT6feJZdBh2aPrLs5182Myyai3NE5i8Rdj gqYO9rpDmDctjewDLjcRpI1d3tCl+Jjzw9esSa4oqSn5cxj0iLHYwvlAVBGJpjyCOG UprvZJclqpMUgbiNKa2bDUJ5oISfA4fgwJa346Yg= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: John Fastabend , Alexei Starovoitov , Jakub Sitnicki , Song Liu , Sasha Levin , netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH AUTOSEL 5.7 267/274] bpf: Refactor sockmap redirect code so its easy to reuse Date: Mon, 8 Jun 2020 19:06:00 -0400 Message-Id: <20200608230607.3361041-267-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200608230607.3361041-1-sashal@kernel.org> References: <20200608230607.3361041-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: John Fastabend [ Upstream commit ca2f5f21dbbd5e3a00cd3e97f728aa2ca0b2e011 ] We will need this block of code called from tls context shortly lets refactor the redirect logic so its easy to use. This also cleans up the switch stmt so we have fewer fallthrough cases. No logic changes are intended. Fixes: d829e9c4112b5 ("tls: convert to generic sk_msg interface") Signed-off-by: John Fastabend Signed-off-by: Alexei Starovoitov Reviewed-by: Jakub Sitnicki Acked-by: Song Liu Link: https://lore.kernel.org/bpf/159079360110.5745.7024009076049029819.stgit@john-Precision-5820-Tower Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- net/core/skmsg.c | 55 ++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/net/core/skmsg.c b/net/core/skmsg.c index c479372f2cd2..9d72f71e9b47 100644 --- a/net/core/skmsg.c +++ b/net/core/skmsg.c @@ -682,13 +682,43 @@ static struct sk_psock *sk_psock_from_strp(struct strparser *strp) return container_of(parser, struct sk_psock, parser); } -static void sk_psock_verdict_apply(struct sk_psock *psock, - struct sk_buff *skb, int verdict) +static void sk_psock_skb_redirect(struct sk_psock *psock, struct sk_buff *skb) { struct sk_psock *psock_other; struct sock *sk_other; bool ingress; + sk_other = tcp_skb_bpf_redirect_fetch(skb); + if (unlikely(!sk_other)) { + kfree_skb(skb); + return; + } + psock_other = sk_psock(sk_other); + if (!psock_other || sock_flag(sk_other, SOCK_DEAD) || + !sk_psock_test_state(psock_other, SK_PSOCK_TX_ENABLED)) { + kfree_skb(skb); + return; + } + + ingress = tcp_skb_bpf_ingress(skb); + if ((!ingress && sock_writeable(sk_other)) || + (ingress && + atomic_read(&sk_other->sk_rmem_alloc) <= + sk_other->sk_rcvbuf)) { + if (!ingress) + skb_set_owner_w(skb, sk_other); + skb_queue_tail(&psock_other->ingress_skb, skb); + schedule_work(&psock_other->work); + } else { + kfree_skb(skb); + } +} + +static void sk_psock_verdict_apply(struct sk_psock *psock, + struct sk_buff *skb, int verdict) +{ + struct sock *sk_other; + switch (verdict) { case __SK_PASS: sk_other = psock->sk; @@ -707,25 +737,8 @@ static void sk_psock_verdict_apply(struct sk_psock *psock, } goto out_free; case __SK_REDIRECT: - sk_other = tcp_skb_bpf_redirect_fetch(skb); - if (unlikely(!sk_other)) - goto out_free; - psock_other = sk_psock(sk_other); - if (!psock_other || sock_flag(sk_other, SOCK_DEAD) || - !sk_psock_test_state(psock_other, SK_PSOCK_TX_ENABLED)) - goto out_free; - ingress = tcp_skb_bpf_ingress(skb); - if ((!ingress && sock_writeable(sk_other)) || - (ingress && - atomic_read(&sk_other->sk_rmem_alloc) <= - sk_other->sk_rcvbuf)) { - if (!ingress) - skb_set_owner_w(skb, sk_other); - skb_queue_tail(&psock_other->ingress_skb, skb); - schedule_work(&psock_other->work); - break; - } - /* fall-through */ + sk_psock_skb_redirect(psock, skb); + break; case __SK_DROP: /* fall-through */ default: -- 2.25.1