From patchwork Mon Oct 19 12:25:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 288335 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DC57C433E7 for ; Mon, 19 Oct 2020 12:25:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3842C22276 for ; Mon, 19 Oct 2020 12:25:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sWpwlHAU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727117AbgJSMZx (ORCPT ); Mon, 19 Oct 2020 08:25:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727199AbgJSMZv (ORCPT ); Mon, 19 Oct 2020 08:25:51 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A991C0613CE; Mon, 19 Oct 2020 05:25:51 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id j8so5620504pjy.5; Mon, 19 Oct 2020 05:25:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=jGFHohiLMKmOcbBELvAHtKl6/eKf2Rs4EotDZ5VjkE0=; b=sWpwlHAU56NfFriE3E2sIUTxcft80+7U4FjmNnOj/UKHRvVW0KANSazqWybWpeAuN7 QTS+Vlo9zTfxgVRuV6aTMCw4YVQTWhZlZTxxyFpfVVS7xLhRoO6RHSftr84qgKWhjXVf Ebg4LEQ3fs5Su3sjty0vhfBnTTjx4cQUkX/PS8UaO7XMrvkqIePoLGqa+PvBZI9Syzo2 rkEL5pK0ARJAHGId+Jhsqy0K/XGHwNmhseS+6VWcWEcunAW/NuM2E0Lj4NF/9fFptFgW Z9q55e55aoz4yAGj3NvywnyxPV9xnr8FcGrxsyYwVEqBcd/hEi5j3UBqrmiQrsjJ+s39 wGsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=jGFHohiLMKmOcbBELvAHtKl6/eKf2Rs4EotDZ5VjkE0=; b=WUhQzQPrE7YP+7S9GfCfVXazASVI1wgVlmfeuB7ic/iMtDqVLXMJJJfP4UjH0P/fjK GHxIhkBRnLOh8TMhB/YlX5W5Bszn9XGeYZNSernMSOCO1eeXh8dPgldzxgVPzwt3vofE CLTNw2FHQK0SAg6jcZTQUj4tUb5LEM5qePgy1tbKJjbt0Z8Y0tAC2f0mY0ioeQEMYCaF viMuRO7Qb1Z3TxvKxeWdIr2nLeI/0nqPcncJIdyHSwvRgpGtTMG9sKLWSAJr3GvwWq6Z q0zgLdnt43WDAot1Hj2yNVOMQqDbAGDUTKSA3eRFxR2SSE8Kp9y1ZOz6O9VEB/HybGem QqjA== X-Gm-Message-State: AOAM532ItEAHIZ/PlrcHWTPLsVypxgqvkEJhL7W5ePnpoUoKo/iOFboz 0cfBJhcpCSKJTNnndZgh50FQv8sJxX0= X-Google-Smtp-Source: ABdhPJywoHkGOh1UZ4H+46xwoc824w3L1ii9tB/MCA8M5yIc/mSvLVnXmEqotHHRyGBk4W7DuLqwbw== X-Received: by 2002:a17:902:708a:b029:d4:cf7c:6c59 with SMTP id z10-20020a170902708ab02900d4cf7c6c59mr16795320plk.52.1603110350282; Mon, 19 Oct 2020 05:25:50 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id ga19sm11721302pjb.3.2020.10.19.05.25.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Oct 2020 05:25:49 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , davem@davemloft.net, gnault@redhat.com, pabeni@redhat.com, willemdebruijn.kernel@gmail.com Subject: [PATCHv4 net-next 01/16] udp: check udp sock encap_type in __udp_lib_err Date: Mon, 19 Oct 2020 20:25:18 +0800 Message-Id: <71b3af0fb347f27b5c3bf846dbd34485d9f80af0.1603110316.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: References: In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org There is a chance that __udp4/6_lib_lookup() returns a udp encap sock in __udp_lib_err(), like the udp encap listening sock may use the same port as remote encap port, in which case it should go to __udp4/6_lib_err_encap() for more validation before processing the icmp packet. This patch is to check encap_type in __udp_lib_err() for the further validation for a encap sock. Signed-off-by: Xin Long --- net/ipv4/udp.c | 2 +- net/ipv6/udp.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 09f0a23..ca04a8a 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -702,7 +702,7 @@ int __udp4_lib_err(struct sk_buff *skb, u32 info, struct udp_table *udptable) sk = __udp4_lib_lookup(net, iph->daddr, uh->dest, iph->saddr, uh->source, skb->dev->ifindex, inet_sdif(skb), udptable, NULL); - if (!sk) { + if (!sk || udp_sk(sk)->encap_type) { /* No socket for error: try tunnels before discarding */ sk = ERR_PTR(-ENOENT); if (static_branch_unlikely(&udp_encap_needed_key)) { diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index 29d9691..cde9b88 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -560,7 +560,7 @@ int __udp6_lib_err(struct sk_buff *skb, struct inet6_skb_parm *opt, sk = __udp6_lib_lookup(net, daddr, uh->dest, saddr, uh->source, inet6_iif(skb), inet6_sdif(skb), udptable, NULL); - if (!sk) { + if (!sk || udp_sk(sk)->encap_type) { /* No socket for error: try tunnels before discarding */ sk = ERR_PTR(-ENOENT); if (static_branch_unlikely(&udpv6_encap_needed_key)) { From patchwork Mon Oct 19 12:25:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 298815 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9AFC4C433E7 for ; Mon, 19 Oct 2020 12:26:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 378E322268 for ; Mon, 19 Oct 2020 12:26:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="J9Q9jqCM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727260AbgJSM0A (ORCPT ); Mon, 19 Oct 2020 08:26:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726249AbgJSMZ7 (ORCPT ); Mon, 19 Oct 2020 08:25:59 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84FD7C0613D0; Mon, 19 Oct 2020 05:25:59 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id b26so5929841pff.3; Mon, 19 Oct 2020 05:25:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=IdTDU779pNNOm5wxZz9V3KNfPGoQtUmsqw2exJTyJ+c=; b=J9Q9jqCMhovbCCI1aDAnpO3Ogj5p+DdkNb1buBK2uGHFoOmMzSPQUiEk2/vFve3XjP HVGPn+0b0e8w/OREV26T43oAwE8/xwm0GE8l8OWal513asEnt8oKOAIMnpnmf6obt9oo fmq0N41BMG3VqYzkHEwUq7iguVMoEC3qxlTkQ/J9kb/WobSbeSpYVST/rQ04znyuUnTJ EJueRWcD+AGyvbiD0qz8JaL7ubSvbUQKWXO0T+BHiDMjbQXXK6FFzf+AaOiZbr15Cfk2 mNNAa1XFVVyGebrkCX6O0NEKsSDW1MnzTuB0fQ51XOzXA66gRrK8yM85qGayWddv5+fA MFGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=IdTDU779pNNOm5wxZz9V3KNfPGoQtUmsqw2exJTyJ+c=; b=kZGkha2uVZpq+fja/bax8NNhab6M3gQsTEf1UibEZ7gqD8I3J/Szt7y0frR/7REm9O aCJEhuf4n0TD+9KShSsy/D3vdaUAD5CON8VEnzQs2K5IV9bzIfSf6OYrXBoMsICh9KJ/ F0kPQpsUe7kLZTGUByGScwZygHTKYFDnWihX6kdoR6Z4KE090TOSYzUtokRsFLz9dCh5 E+9A4+kEmcpnSNeIENS0qocwc1V6vHBX+dpbnImW+Qzf0SwWhXLraXdqy0fqPFlzfdMy pGie7/Gj/PPXPgzTKy2dRvEn5qJ1cg00SeoQ6nBaPg4Et1xdKkGRUQVHA0gyamemL7Tl EZJg== X-Gm-Message-State: AOAM532DvIg61bKGL8sNRjc0+732akjZcNW3o9Vz7bAjrQ+Nay9SeqVh xM0t4AkJZF+Q1CdZLthyjZeD3NCikH0= X-Google-Smtp-Source: ABdhPJyx6G1DMspy4Pec4rHEzyBVN4VkT0vTUHKqwqFkHdlSRcXQl0hc/YTDUknZ8xBkhoSXix+klQ== X-Received: by 2002:a65:5a0f:: with SMTP id y15mr13658326pgs.395.1603110358702; Mon, 19 Oct 2020 05:25:58 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id y1sm4979468pjl.12.2020.10.19.05.25.57 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Oct 2020 05:25:58 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , davem@davemloft.net, gnault@redhat.com, pabeni@redhat.com, willemdebruijn.kernel@gmail.com Subject: [PATCHv4 net-next 02/16] udp6: move the mss check after udp gso tunnel processing Date: Mon, 19 Oct 2020 20:25:19 +0800 Message-Id: X-Mailer: git-send-email 2.1.0 In-Reply-To: <71b3af0fb347f27b5c3bf846dbd34485d9f80af0.1603110316.git.lucien.xin@gmail.com> References: <71b3af0fb347f27b5c3bf846dbd34485d9f80af0.1603110316.git.lucien.xin@gmail.com> In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org For some protocol's gso, like SCTP, it's using GSO_BY_FRAGS for gso_size. When using UDP to encapsulate its packet, it will return error in udp6_ufo_fragment() as skb->len < gso_size, and it will never go to the gso tunnel processing. So we should move this check after udp gso tunnel processing, the same as udp4_ufo_fragment() does. v1->v2: - no change. v2->v3: - not do any cleanup. Signed-off-by: Xin Long Acked-by: Willem de Bruijn --- net/ipv6/udp_offload.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/ipv6/udp_offload.c b/net/ipv6/udp_offload.c index 584157a..aa602af 100644 --- a/net/ipv6/udp_offload.c +++ b/net/ipv6/udp_offload.c @@ -28,10 +28,6 @@ static struct sk_buff *udp6_ufo_fragment(struct sk_buff *skb, int tnl_hlen; int err; - mss = skb_shinfo(skb)->gso_size; - if (unlikely(skb->len <= mss)) - goto out; - if (skb->encapsulation && skb_shinfo(skb)->gso_type & (SKB_GSO_UDP_TUNNEL|SKB_GSO_UDP_TUNNEL_CSUM)) segs = skb_udp_tunnel_segment(skb, features, true); @@ -48,6 +44,10 @@ static struct sk_buff *udp6_ufo_fragment(struct sk_buff *skb, if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4) return __udp_gso_segment(skb, features); + mss = skb_shinfo(skb)->gso_size; + if (unlikely(skb->len <= mss)) + goto out; + /* Do software UFO. Complete and fill in the UDP checksum as HW cannot * do checksum of UDP packets sent as multiple IP fragments. */ From patchwork Mon Oct 19 12:25:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 288334 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7BDB7C433E7 for ; Mon, 19 Oct 2020 12:26:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 22AD622268 for ; Mon, 19 Oct 2020 12:26:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="e6ziUfIm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727271AbgJSM0I (ORCPT ); Mon, 19 Oct 2020 08:26:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726249AbgJSM0I (ORCPT ); Mon, 19 Oct 2020 08:26:08 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0BDFC0613CE; Mon, 19 Oct 2020 05:26:07 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id j8so5621057pjy.5; Mon, 19 Oct 2020 05:26:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=HzhHczRtL69delBJzpCl1jQSUECAnKmwpTvFJI3PgEA=; b=e6ziUfIm/yomxmVAsxpRYjdZ19zKQ+CLYxg8Us2gdyRRLUBvQA+PSpcBLay2C41qKO gOEJ3x3ir1sujXNc/NRhOlcjOkMIOL1LI3KeBq5AR79OKS79BtAIBCk+EAkuxR3wTYHc TWFewjy+ySg7J6Ja43GsErYCpsriwxo1aF1ghfI7lnS7lwBYIlhms45IEoyWRyVB/P86 cOzBqR8gTFVqBGB2glLUsuwtruhAsaIWSAgeRwoSuBpKWwiuuU6RmWicfqh2Ip0Y3Qaj FyBXXyOHVzj+6u5SgbKk9oikySps381dUzef5Y/PQe85PscpiS74HcvPRLLkftISVenF k32w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=HzhHczRtL69delBJzpCl1jQSUECAnKmwpTvFJI3PgEA=; b=IHZDzGIgzwe7BTtbrZ3o/fGlrAE1blT1djZU7xBDnx3477UYO4vF2iBqakmGdHzckx u+ku+cjo+ae1qfxrTWb+k0VqymJn+pkV88wzpy1TpltA4FwfaxGxGMHaJhHHwA2Xvtl5 +DHVWisli+WHfHCJ/8vp9xmkhh9zV+8SttU+Xcs4nSZs12zKB/ppBRryWljwsPrYQvxw mPGL4stwwuh7XAXL3Q5/q4MVAcxB1Ko9L8zUhtBRmxdr0UP21xTofUYTZPMqEAGmcU+I wXcfAPNqjvOZmZO7wWhfJn0WZox4oxDpHLxGAM1BoiQjI99sYWvSmjAO28AvBEI4Egcr kWKA== X-Gm-Message-State: AOAM530scCcsXrinXFSrS4kixAL6rT29U0ZSYbx2Nc/Y2fneQ2qGFwb8 nMirUtEAazOSt06SxdVVjGIhGGWUYQg= X-Google-Smtp-Source: ABdhPJwWcxr1s1orKJlC4mu+PfxMIHUse6md0oJlVwBhwpcKTGHS8Hx+vkg5J5NdiEQLoMtaBw4Apw== X-Received: by 2002:a17:90a:a10e:: with SMTP id s14mr16338001pjp.62.1603110367143; Mon, 19 Oct 2020 05:26:07 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id z73sm12142034pfc.75.2020.10.19.05.26.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Oct 2020 05:26:06 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , davem@davemloft.net, gnault@redhat.com, pabeni@redhat.com, willemdebruijn.kernel@gmail.com Subject: [PATCHv4 net-next 03/16] udp: support sctp over udp in skb_udp_tunnel_segment Date: Mon, 19 Oct 2020 20:25:20 +0800 Message-Id: <5f06ac649f4b63fc5a254812a963cada3183f136.1603110316.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: References: <71b3af0fb347f27b5c3bf846dbd34485d9f80af0.1603110316.git.lucien.xin@gmail.com> In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org For the gso of sctp over udp packets, sctp_gso_segment() will be called in skb_udp_tunnel_segment(), we need to set transport_header to sctp header. As all the current HWs can't handle both crc checksum and udp checksum at the same time, the crc checksum has to be done in sctp_gso_segment() by removing the NETIF_F_SCTP_CRC flag from the features. Meanwhile, if the HW can't do udp checksum, csum and csum_start has to be set correctly, and udp checksum will be done in __skb_udp_tunnel_segment() by calling gso_make_checksum(). Thanks to Paolo, Marcelo and Guillaume for helping with this one. v1->v2: - no change. v2->v3: - remove the he NETIF_F_SCTP_CRC flag from the features. - set csum and csum_start in sctp_gso_make_checksum(). Signed-off-by: Xin Long --- net/ipv4/udp_offload.c | 3 +++ net/sctp/offload.c | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c index e67a66f..b8b1fde 100644 --- a/net/ipv4/udp_offload.c +++ b/net/ipv4/udp_offload.c @@ -49,6 +49,7 @@ static struct sk_buff *__skb_udp_tunnel_segment(struct sk_buff *skb, __skb_pull(skb, tnl_hlen); skb_reset_mac_header(skb); skb_set_network_header(skb, skb_inner_network_offset(skb)); + skb_set_transport_header(skb, skb_inner_transport_offset(skb)); skb->mac_len = skb_inner_network_offset(skb); skb->protocol = new_protocol; @@ -67,6 +68,8 @@ static struct sk_buff *__skb_udp_tunnel_segment(struct sk_buff *skb, (NETIF_F_HW_CSUM | NETIF_F_IP_CSUM)))); features &= skb->dev->hw_enc_features; + /* CRC checksum can't be handled by HW when it's a UDP tunneling packet. */ + features &= ~NETIF_F_SCTP_CRC; /* The only checksum offload we care about from here on out is the * outer one so strip the existing checksum feature flags and diff --git a/net/sctp/offload.c b/net/sctp/offload.c index 74847d6..ce281a9 100644 --- a/net/sctp/offload.c +++ b/net/sctp/offload.c @@ -27,7 +27,11 @@ static __le32 sctp_gso_make_checksum(struct sk_buff *skb) { skb->ip_summed = CHECKSUM_NONE; skb->csum_not_inet = 0; - gso_reset_checksum(skb, ~0); + /* csum and csum_start in GSO CB may be needed to do the UDP + * checksum when it's a UDP tunneling packet. + */ + SKB_GSO_CB(skb)->csum = (__force __wsum)~0; + SKB_GSO_CB(skb)->csum_start = skb_headroom(skb) + skb->len; return sctp_compute_cksum(skb, skb_transport_offset(skb)); } From patchwork Mon Oct 19 12:25:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 298814 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED46CC433DF for ; Mon, 19 Oct 2020 12:26:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8DE3C22276 for ; Mon, 19 Oct 2020 12:26:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VevDRD/9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727301AbgJSM0M (ORCPT ); Mon, 19 Oct 2020 08:26:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726249AbgJSM0L (ORCPT ); Mon, 19 Oct 2020 08:26:11 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 583D8C0613CE; Mon, 19 Oct 2020 05:26:11 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id d23so4895884pll.7; Mon, 19 Oct 2020 05:26:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=225QBlNOQv1I2VE0xISPJH7qhCAG1god2efxpwkOjzc=; b=VevDRD/9uGfLa4oNfbM25r6zXD9DgQ7i05pO1kYI4LKIzEUvlk1r36U4WtLA1bbfFI M0C1xC0Wb3SNXthWhIybofBlNDJQHxYHg1OArbw0Dl2Cb38d8TwDsQEVXXyO/l7TiS7M e4jy0thgrxwrVEWIVV4Pl4rwA/4IqtJLSD/mTaJRZhpRUobu5fDyrrmd6uvm10NRQf4l V2g31tm9MR4oxq2+BCE/d7qN8Bidk63HPxqfpUGYz9Qkzf0fjmqFh/g8P2TvpnxAZLUa QPmvd5hTmxkeV+GLk9jf6Em1Hzr2SX3hWuszOrkXUsNp3OE/S2ugExYwG8dOoXTlq1bO 6Yfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=225QBlNOQv1I2VE0xISPJH7qhCAG1god2efxpwkOjzc=; b=oSMmjbZcfHZKm25p3Qkyqoc4k01tt8jgAjU4hfLtctOoMhfu1P1qdMItKSLfRI8KeQ lVLMOD9n8BgrSnmAYW9hrAP2cJrED1NMjo/hdK5LMHUNV83oBlkUSDofGAPgBOa7uYHq 8ZM9YJa148i2F26TfuIGcVKH+3eJESovCaih3sjvDlvGTdCWF0Q72t71CQG3yTut4S2O NJ/mwBfCm7uEfSCscFRrAeDG7v4EtOs6yw2f9fHq/sJnza2uPP88+dbjTPEFbeGlE8oJ PwFyiKXfcckwUzrjydTb4Fm9aCv6P5/Vs39CljsExh0GeFHhpAELP0k7G7ERkq6VfeXF N8ig== X-Gm-Message-State: AOAM5306jAQXycHN7kyuo0iooZUJ0g5dhd42mmf6n0TZtQgC2IzypmVg p6crlTZBPsAMJJMX9A905SJHy0f2GqI= X-Google-Smtp-Source: ABdhPJyT27MG6t8vjwoq4OkQYC/6Uu8fC+GfRUX+C7bSf98oo3/AslnMXguL9VdSVGz1100p+LndPw== X-Received: by 2002:a17:902:9347:b029:d3:7c08:86c6 with SMTP id g7-20020a1709029347b02900d37c0886c6mr16090772plp.84.1603110370557; Mon, 19 Oct 2020 05:26:10 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id q24sm13667142pfn.72.2020.10.19.05.26.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Oct 2020 05:26:10 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , davem@davemloft.net, gnault@redhat.com, pabeni@redhat.com, willemdebruijn.kernel@gmail.com Subject: [PATCHv4 net-next 04/16] sctp: create udp4 sock and add its encap_rcv Date: Mon, 19 Oct 2020 20:25:21 +0800 Message-Id: X-Mailer: git-send-email 2.1.0 In-Reply-To: <5f06ac649f4b63fc5a254812a963cada3183f136.1603110316.git.lucien.xin@gmail.com> References: <71b3af0fb347f27b5c3bf846dbd34485d9f80af0.1603110316.git.lucien.xin@gmail.com> <5f06ac649f4b63fc5a254812a963cada3183f136.1603110316.git.lucien.xin@gmail.com> In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch is to add the functions to create/release udp4 sock, and set the sock's encap_rcv to process the incoming udp encap sctp packets. In sctp_udp_rcv(), as we can see, all we need to do is fix the transport header for sctp_rcv(), then it would implement the part of rfc6951#section-5.4: "When an encapsulated packet is received, the UDP header is removed. Then, the generic lookup is performed, as done by an SCTP stack whenever a packet is received, to find the association for the received SCTP packet" Note that these functions will be called in the last patch of this patchset when enabling this feature. v1->v2: - Add pr_err() when fails to create udp v4 sock. v2->v3: - Add 'select NET_UDP_TUNNEL' in sctp Kconfig. Signed-off-by: Xin Long --- include/net/netns/sctp.h | 5 +++++ include/net/sctp/constants.h | 2 ++ include/net/sctp/sctp.h | 2 ++ net/sctp/Kconfig | 1 + net/sctp/protocol.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 53 insertions(+) diff --git a/include/net/netns/sctp.h b/include/net/netns/sctp.h index d8d02e4..8cc9aff 100644 --- a/include/net/netns/sctp.h +++ b/include/net/netns/sctp.h @@ -22,6 +22,11 @@ struct netns_sctp { */ struct sock *ctl_sock; + /* UDP tunneling listening sock. */ + struct sock *udp4_sock; + /* UDP tunneling listening port. */ + int udp_port; + /* This is the global local address list. * We actively maintain this complete list of addresses on * the system by catching address add/delete events. diff --git a/include/net/sctp/constants.h b/include/net/sctp/constants.h index 122d9e2..14a0d22 100644 --- a/include/net/sctp/constants.h +++ b/include/net/sctp/constants.h @@ -286,6 +286,8 @@ enum { SCTP_MAX_GABS = 16 }; * functions simpler to write. */ +#define SCTP_DEFAULT_UDP_PORT 9899 /* default UDP tunneling port */ + /* These are the values for pf exposure, UNUSED is to keep compatible with old * applications by default. */ diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h index 4fc747b..bfd87a0 100644 --- a/include/net/sctp/sctp.h +++ b/include/net/sctp/sctp.h @@ -84,6 +84,8 @@ int sctp_copy_local_addr_list(struct net *net, struct sctp_bind_addr *addr, struct sctp_pf *sctp_get_pf_specific(sa_family_t family); int sctp_register_pf(struct sctp_pf *, sa_family_t); void sctp_addr_wq_mgmt(struct net *, struct sctp_sockaddr_entry *, int); +int sctp_udp_sock_start(struct net *net); +void sctp_udp_sock_stop(struct net *net); /* * sctp/socket.c diff --git a/net/sctp/Kconfig b/net/sctp/Kconfig index 39d7fa9..5da599f 100644 --- a/net/sctp/Kconfig +++ b/net/sctp/Kconfig @@ -11,6 +11,7 @@ menuconfig IP_SCTP select CRYPTO_HMAC select CRYPTO_SHA1 select LIBCRC32C + select NET_UDP_TUNNEL help Stream Control Transmission Protocol diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c index 2583323..6fb03fc 100644 --- a/net/sctp/protocol.c +++ b/net/sctp/protocol.c @@ -44,6 +44,7 @@ #include #include #include +#include #define MAX_SCTP_PORT_HASH_ENTRIES (64 * 1024) @@ -840,6 +841,45 @@ static int sctp_ctl_sock_init(struct net *net) return 0; } +static int sctp_udp_rcv(struct sock *sk, struct sk_buff *skb) +{ + skb_set_transport_header(skb, sizeof(struct udphdr)); + sctp_rcv(skb); + return 0; +} + +int sctp_udp_sock_start(struct net *net) +{ + struct udp_tunnel_sock_cfg tuncfg = {NULL}; + struct udp_port_cfg udp_conf = {0}; + struct socket *sock; + int err; + + udp_conf.family = AF_INET; + udp_conf.local_ip.s_addr = htonl(INADDR_ANY); + udp_conf.local_udp_port = htons(net->sctp.udp_port); + err = udp_sock_create(net, &udp_conf, &sock); + if (err) { + pr_err("Failed to create the SCTP UDP tunneling v4 sock\n"); + return err; + } + + tuncfg.encap_type = 1; + tuncfg.encap_rcv = sctp_udp_rcv; + setup_udp_tunnel_sock(net, sock, &tuncfg); + net->sctp.udp4_sock = sock->sk; + + return 0; +} + +void sctp_udp_sock_stop(struct net *net) +{ + if (net->sctp.udp4_sock) { + udp_tunnel_sock_release(net->sctp.udp4_sock->sk_socket); + net->sctp.udp4_sock = NULL; + } +} + /* Register address family specific functions. */ int sctp_register_af(struct sctp_af *af) { @@ -1271,6 +1311,9 @@ static int __net_init sctp_defaults_init(struct net *net) /* Enable ECN by default. */ net->sctp.ecn_enable = 1; + /* Set UDP tunneling listening port to default value */ + net->sctp.udp_port = SCTP_DEFAULT_UDP_PORT; + /* Set SCOPE policy to enabled */ net->sctp.scope_policy = SCTP_SCOPE_POLICY_ENABLE; From patchwork Mon Oct 19 12:25:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 288333 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77504C433E7 for ; Mon, 19 Oct 2020 12:26:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1AF8722283 for ; Mon, 19 Oct 2020 12:26:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sQ68S+s5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727353AbgJSM0U (ORCPT ); Mon, 19 Oct 2020 08:26:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727322AbgJSM0T (ORCPT ); Mon, 19 Oct 2020 08:26:19 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B32E6C0613D0; Mon, 19 Oct 2020 05:26:19 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id j8so5621404pjy.5; Mon, 19 Oct 2020 05:26:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=DR4Juetdp2wmKQu69ZewqLs9ujt7Fs4Ku72FITIp7pc=; b=sQ68S+s5JeuUWOaOqD3Thoieb5YO/+Wgsna9R9w7akoYcd0vteyTKPzrKEtWKX2Zo7 ejJeuU7iHl8mvKa96rlamJom7nNOfSWAQT3eSUF4f5vdWStYMSxAMPgFwyoyIqcNxm2O y6HbiDB4vszXWcdKUDYgCV74+oHVEM0bfdPaK7D2vfM+SW9zqKvxADhLiBCJodOP8l/8 O/D0w6pSy9aaRJKiTvJn9JcFptZpHmrwKaOSAJDerqxM3J+JKLSJ8RN0H1gQnYU89dBw eHFJWMD8XsqY6bbqvN3dtc1eC92MWHVwPJ+SOAIl/JxWTCaEVnyL+0tzbkoDhF79tieU 5R+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=DR4Juetdp2wmKQu69ZewqLs9ujt7Fs4Ku72FITIp7pc=; b=L5j4euNiZ8JL8wjYj+rpv5qKGlgfNjh3iL7I7eiC98JFbO68Nj82/0ZdtKsC8ohPrj 12qAK7SxHnvZchiFIUsKE9yooUiH6nSgECwiZ9Q+qeynNm58tA9ty8wVQgniixbs9uMd cEJHVdfeg+QhuXQyRcQDk87FhmYSsiS7wtFBhaK36OklCXQLVccQ4mT7lpk6jKMwdNWK Lr7U2KNIHl6IpJh+hAYGIUQifz9FWvaVBhJNjnJ8p2rtPOnyQCgeSE50IZFLYXO1p4Wq ur5PgaviuUaDJV6P+IocUhBRufzuIkDDy716MjuBHpuDqcvk5GMxfrvBsFQtA+3rPG5+ UlhA== X-Gm-Message-State: AOAM532UkKKQl8gQT1MhesLXiR6D0QNt5effHdzZ5PpDYa+dG/wYCdZE EwEMFmFZciK1SI0q20O93GQJMrJmUlo= X-Google-Smtp-Source: ABdhPJxkiyCWRCSHdP+Um6xrTovnnR0BtNN/orNGDQwVJRsEyLpci/I9BHisQzG64cbqEwEW1QxCiA== X-Received: by 2002:a17:902:7795:b029:d5:cc4a:f970 with SMTP id o21-20020a1709027795b02900d5cc4af970mr13620014pll.63.1603110378931; Mon, 19 Oct 2020 05:26:18 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id x1sm12232212pjj.25.2020.10.19.05.26.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Oct 2020 05:26:18 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , davem@davemloft.net, gnault@redhat.com, pabeni@redhat.com, willemdebruijn.kernel@gmail.com Subject: [PATCHv4 net-next 05/16] sctp: create udp6 sock and set its encap_rcv Date: Mon, 19 Oct 2020 20:25:22 +0800 Message-Id: <7a2f5792c1a428c16962fff08b7bcfedc21bd5e2.1603110316.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: References: <71b3af0fb347f27b5c3bf846dbd34485d9f80af0.1603110316.git.lucien.xin@gmail.com> <5f06ac649f4b63fc5a254812a963cada3183f136.1603110316.git.lucien.xin@gmail.com> In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch is to add the udp6 sock part in sctp_udp_sock_start/stop(). udp_conf.use_udp6_rx_checksums is set to true, as: "The SCTP checksum MUST be computed for IPv4 and IPv6, and the UDP checksum SHOULD be computed for IPv4 and IPv6" says in rfc6951#section-5.3. v1->v2: - Add pr_err() when fails to create udp v6 sock. - Add #if IS_ENABLED(CONFIG_IPV6) not to create v6 sock when ipv6 is disabled. Signed-off-by: Xin Long --- include/net/netns/sctp.h | 1 + net/sctp/protocol.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/net/netns/sctp.h b/include/net/netns/sctp.h index 8cc9aff..247b401 100644 --- a/include/net/netns/sctp.h +++ b/include/net/netns/sctp.h @@ -24,6 +24,7 @@ struct netns_sctp { /* UDP tunneling listening sock. */ struct sock *udp4_sock; + struct sock *udp6_sock; /* UDP tunneling listening port. */ int udp_port; diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c index 6fb03fc..e1501e7 100644 --- a/net/sctp/protocol.c +++ b/net/sctp/protocol.c @@ -869,6 +869,28 @@ int sctp_udp_sock_start(struct net *net) setup_udp_tunnel_sock(net, sock, &tuncfg); net->sctp.udp4_sock = sock->sk; +#if IS_ENABLED(CONFIG_IPV6) + memset(&udp_conf, 0, sizeof(udp_conf)); + + udp_conf.family = AF_INET6; + udp_conf.local_ip6 = in6addr_any; + udp_conf.local_udp_port = htons(net->sctp.udp_port); + udp_conf.use_udp6_rx_checksums = true; + udp_conf.ipv6_v6only = true; + err = udp_sock_create(net, &udp_conf, &sock); + if (err) { + pr_err("Failed to create the SCTP UDP tunneling v6 sock\n"); + udp_tunnel_sock_release(net->sctp.udp4_sock->sk_socket); + net->sctp.udp4_sock = NULL; + return err; + } + + tuncfg.encap_type = 1; + tuncfg.encap_rcv = sctp_udp_rcv; + setup_udp_tunnel_sock(net, sock, &tuncfg); + net->sctp.udp6_sock = sock->sk; +#endif + return 0; } @@ -878,6 +900,10 @@ void sctp_udp_sock_stop(struct net *net) udp_tunnel_sock_release(net->sctp.udp4_sock->sk_socket); net->sctp.udp4_sock = NULL; } + if (net->sctp.udp6_sock) { + udp_tunnel_sock_release(net->sctp.udp6_sock->sk_socket); + net->sctp.udp6_sock = NULL; + } } /* Register address family specific functions. */ From patchwork Mon Oct 19 12:25:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 298813 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA985C433DF for ; Mon, 19 Oct 2020 12:26:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 77A9C22268 for ; Mon, 19 Oct 2020 12:26:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IhKo//bg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727424AbgJSM03 (ORCPT ); Mon, 19 Oct 2020 08:26:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726669AbgJSM03 (ORCPT ); Mon, 19 Oct 2020 08:26:29 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 091DCC0613D0; Mon, 19 Oct 2020 05:26:28 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id p21so5246145pju.0; Mon, 19 Oct 2020 05:26:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=ROdQSoNdZKqCAMjkxoMjfcJGDYgA7Iqly+Pb0MS2b4E=; b=IhKo//bg5gvtTrxhVc79Pchgx6vkEB6G6whzHAvTpoyVa9XQkKRMDyqXHsTOKEi4vs yHa1jPIav1RZWPC//QaprKCyA4SJoDc9e21ITrRzYcGW+0JxMjLNyYXc6N015XHVpShc yysmf3YyPzeDknAgj/kui+HSomO97ysDxS2wm1m4YMGW5QaKPeTDYMzCMgTTAfNbu6w8 3CXht99/zKBSICIee/fB40KSrT+8xH8a8pRDi1XwM3iPB30hYZvtzQPHqVznmGd7DfWR sn2J9mV3NJbo/T355Awu2n1OTx4qfX1WpTKM/62MuADLj5G1eC0fNMHx6so8M7P5eafA jDng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=ROdQSoNdZKqCAMjkxoMjfcJGDYgA7Iqly+Pb0MS2b4E=; b=tLnqFpK1ic7vmqxpNeSeabQERUOYo0Ot0I5EDMfLp3okxesD7kOuAC/Uo5OAAtJBzv PD+zTukPHGFbRkWnnviDjx1FQcABY1Rn1581buf0DJN7W17udXs090o9IIc5NhHXywKK kUDC9VW03Rw7ikj9bhaNAM3rodVslF8tIeGs6NSUl8NhCCIA3xs3f0Cq2M5JhbxcEqua D9eWsSuC0ZCmPy7+3hoLEgt9ULxzTfXZ230SSPeXjnk7/uhmU4kqZl0gC3HBu4y/vv4b 73LfwG3WK7S/97DDo8wtB807ntl8WdnZyNDn2IuMNO4g4MIR5TBu/ca8IYjhM1Y9dTJP Ibdg== X-Gm-Message-State: AOAM531V1ydBD1vu/cdC2Sntt1VEXscfj+H50FQ2WkC2VlOGJe4WSBxO bT85PQfcMZZrFhCMht5+tziP9W8Vzwg= X-Google-Smtp-Source: ABdhPJyBmgmjc9iEDLoNAh5naY+mu8McSk5dKSWwoqmSqqfDc/92ZpCCoAq0nDoJblExg7G2yP1YEA== X-Received: by 2002:a17:90a:1c4:: with SMTP id 4mr1351830pjd.86.1603110387328; Mon, 19 Oct 2020 05:26:27 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id j12sm11798653pjs.21.2020.10.19.05.26.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Oct 2020 05:26:26 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , davem@davemloft.net, gnault@redhat.com, pabeni@redhat.com, willemdebruijn.kernel@gmail.com Subject: [PATCHv4 net-next 06/16] sctp: add encap_err_lookup for udp encap socks Date: Mon, 19 Oct 2020 20:25:23 +0800 Message-Id: <7cfd72e42b8b1cde268ad4062c96c08a56c4b14f.1603110316.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <7a2f5792c1a428c16962fff08b7bcfedc21bd5e2.1603110316.git.lucien.xin@gmail.com> References: <71b3af0fb347f27b5c3bf846dbd34485d9f80af0.1603110316.git.lucien.xin@gmail.com> <5f06ac649f4b63fc5a254812a963cada3183f136.1603110316.git.lucien.xin@gmail.com> <7a2f5792c1a428c16962fff08b7bcfedc21bd5e2.1603110316.git.lucien.xin@gmail.com> In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org As it says in rfc6951#section-5.5: "When receiving ICMP or ICMPv6 response packets, there might not be enough bytes in the payload to identify the SCTP association that the SCTP packet triggering the ICMP or ICMPv6 packet belongs to. If a received ICMP or ICMPv6 packet cannot be related to a specific SCTP association or the verification tag cannot be verified, it MUST be discarded silently. In particular, this means that the SCTP stack MUST NOT rely on receiving ICMP or ICMPv6 messages. Implementation constraints could prevent processing received ICMP or ICMPv6 messages." ICMP or ICMPv6 packets need to be handled, and this is implemented by udp encap sock .encap_err_lookup function. The .encap_err_lookup function is called in __udp(6)_lib_err_encap() to confirm this path does need to be updated. For sctp, what we can do here is check if the corresponding asoc and transport exist. Note that icmp packet process for sctp over udp is done by udp sock .encap_err_lookup(), and it means for now we can't do as much as sctp_v4/6_err() does. Also we can't do the two mappings mentioned in rfc6951#section-5.5. Signed-off-by: Xin Long --- net/sctp/protocol.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c index e1501e7..aa8e5b2 100644 --- a/net/sctp/protocol.c +++ b/net/sctp/protocol.c @@ -848,6 +848,23 @@ static int sctp_udp_rcv(struct sock *sk, struct sk_buff *skb) return 0; } +static int sctp_udp_err_lookup(struct sock *sk, struct sk_buff *skb) +{ + struct sctp_association *asoc; + struct sctp_transport *t; + int family; + + skb->transport_header += sizeof(struct udphdr); + family = (ip_hdr(skb)->version == 4) ? AF_INET : AF_INET6; + sk = sctp_err_lookup(dev_net(skb->dev), family, skb, sctp_hdr(skb), + &asoc, &t); + if (!sk) + return -ENOENT; + + sctp_err_finish(sk, t); + return 0; +} + int sctp_udp_sock_start(struct net *net) { struct udp_tunnel_sock_cfg tuncfg = {NULL}; @@ -866,6 +883,7 @@ int sctp_udp_sock_start(struct net *net) tuncfg.encap_type = 1; tuncfg.encap_rcv = sctp_udp_rcv; + tuncfg.encap_err_lookup = sctp_udp_err_lookup; setup_udp_tunnel_sock(net, sock, &tuncfg); net->sctp.udp4_sock = sock->sk; @@ -887,6 +905,7 @@ int sctp_udp_sock_start(struct net *net) tuncfg.encap_type = 1; tuncfg.encap_rcv = sctp_udp_rcv; + tuncfg.encap_err_lookup = sctp_udp_err_lookup; setup_udp_tunnel_sock(net, sock, &tuncfg); net->sctp.udp6_sock = sock->sk; #endif From patchwork Mon Oct 19 12:25:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 288332 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F25BC43457 for ; Mon, 19 Oct 2020 12:26:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0037422268 for ; Mon, 19 Oct 2020 12:26:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gQF9Kits" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727464AbgJSM0h (ORCPT ); Mon, 19 Oct 2020 08:26:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727425AbgJSM0g (ORCPT ); Mon, 19 Oct 2020 08:26:36 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F2BCC0613D0; Mon, 19 Oct 2020 05:26:36 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id e7so5906368pfn.12; Mon, 19 Oct 2020 05:26:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=Wqdx6TvNLjNAKe3Cl+m74emPKACgsPJgGCH97yUVs7Y=; b=gQF9KitsX99l3hukGrcrx4whAQJfjjoFIbY6kmduMaVnGBEylEzCihjzgwh+bKNBP2 BfUwwgm55v5I7VmT+LzmZ83KTQBlogLK5wu4gRt1U4zONn0Nw0SM8H1JdY+bfVH+1Imo S3f+uNiwaGlvw/nuwGHCviVsfhOS1E9XcUXF/TuB9j7KOhkYPLcqWET0SPkl5bum0nF/ jSeetDMy6SepggQkcRb/U7aacyrC9M9YO2VIkyI/zfUErcKjv1lISvedrtB6Fy2MT6fK 6VVEA6gLJOGYKRbPOtw0Ef6l5RHLXJVkWD/IFGDznlB9EYcOipediAMWQEruJ5de6JxU ga/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=Wqdx6TvNLjNAKe3Cl+m74emPKACgsPJgGCH97yUVs7Y=; b=MLvmzL+TPI+d1992UqMba2ICer+3D7utz9K0lGmpYZd6U/sKZ9y96V/MCD96AS1hPi zo4Ctp6rFRCwdtOZ3of+/UpGaEUwq6B80j7Oiaxk5i8cCFvtxDLr9qWwkvznFDmK7Yhi 4gmPDxEYobE8YCtm3CKyAvYZZMTbdC0t0+XwVA39ItclRdOatATnzdwRbT908SycCC/K kTv5ObKCWILS/U/1inVReJWBzcvpdbszdVfmabrFB1G+dHV1r79DU7juaS+3571HmTp+ LOU2AH1OvLumgRqGCeZVL8GYpS3ieBaEQn0JT65ZgU1LmBPWfkPqeYf4NtVikfEw6fk2 r6pA== X-Gm-Message-State: AOAM533XW518bvubUVIh0uxuJK8ss58XfaYLy3C9rmstrESEBTeFbU0p tx6wc+nlGCMUsdSHnQPFHdu3Ug9I0xk= X-Google-Smtp-Source: ABdhPJziFE52laDgyWOBlRFx7u+HqP3U+iump7wsGNkYOTF3MrIH2WKkuWcwvEXRibOJNXJ0yTXGvA== X-Received: by 2002:a63:e502:: with SMTP id r2mr4726962pgh.362.1603110395825; Mon, 19 Oct 2020 05:26:35 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id s126sm11983457pgc.27.2020.10.19.05.26.34 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Oct 2020 05:26:35 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , davem@davemloft.net, gnault@redhat.com, pabeni@redhat.com, willemdebruijn.kernel@gmail.com Subject: [PATCHv4 net-next 07/16] sctp: add encap_port for netns sock asoc and transport Date: Mon, 19 Oct 2020 20:25:24 +0800 Message-Id: X-Mailer: git-send-email 2.1.0 In-Reply-To: <7cfd72e42b8b1cde268ad4062c96c08a56c4b14f.1603110316.git.lucien.xin@gmail.com> References: <71b3af0fb347f27b5c3bf846dbd34485d9f80af0.1603110316.git.lucien.xin@gmail.com> <5f06ac649f4b63fc5a254812a963cada3183f136.1603110316.git.lucien.xin@gmail.com> <7a2f5792c1a428c16962fff08b7bcfedc21bd5e2.1603110316.git.lucien.xin@gmail.com> <7cfd72e42b8b1cde268ad4062c96c08a56c4b14f.1603110316.git.lucien.xin@gmail.com> In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org encap_port is added as per netns/sock/assoc/transport, and the latter one's encap_port inherits the former one's by default. The transport's encap_port value would mostly decide if one packet should go out with udp encapsulated or not. This patch also allows users to set netns' encap_port by sysctl. v1->v2: - Change to define encap_port as __be16 for sctp_sock, asoc and transport. v2->v3: - No change. v3->v4: - Add 'encap_port' entry in ip-sysctl.rst. Signed-off-by: Xin Long --- Documentation/networking/ip-sysctl.rst | 9 +++++++++ include/net/netns/sctp.h | 2 ++ include/net/sctp/structs.h | 6 ++++++ net/sctp/associola.c | 4 ++++ net/sctp/protocol.c | 3 +++ net/sctp/socket.c | 1 + net/sctp/sysctl.c | 10 ++++++++++ 7 files changed, 35 insertions(+) diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst index 837d51f..3909305 100644 --- a/Documentation/networking/ip-sysctl.rst +++ b/Documentation/networking/ip-sysctl.rst @@ -2640,6 +2640,15 @@ addr_scope_policy - INTEGER Default: 1 +encap_port - INTEGER + The default remote UDP encapsalution port. + When UDP tunneling is enabled, this global value is used to set + the dest port for the udp header of outgoing packets by default. + Users can also change the value for each sock/asoc/transport by + using setsockopt. + + Default: 0 + ``/proc/sys/net/core/*`` ======================== diff --git a/include/net/netns/sctp.h b/include/net/netns/sctp.h index 247b401..a0f315e 100644 --- a/include/net/netns/sctp.h +++ b/include/net/netns/sctp.h @@ -27,6 +27,8 @@ struct netns_sctp { struct sock *udp6_sock; /* UDP tunneling listening port. */ int udp_port; + /* UDP tunneling remote encap port. */ + int encap_port; /* This is the global local address list. * We actively maintain this complete list of addresses on diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h index 0bdff38..aa98e7e 100644 --- a/include/net/sctp/structs.h +++ b/include/net/sctp/structs.h @@ -178,6 +178,8 @@ struct sctp_sock { */ __u32 hbinterval; + __be16 encap_port; + /* This is the max_retrans value for new associations. */ __u16 pathmaxrxt; @@ -877,6 +879,8 @@ struct sctp_transport { */ unsigned long last_time_ecne_reduced; + __be16 encap_port; + /* This is the max_retrans value for the transport and will * be initialized from the assocs value. This can be changed * using the SCTP_SET_PEER_ADDR_PARAMS socket option. @@ -1790,6 +1794,8 @@ struct sctp_association { */ unsigned long hbinterval; + __be16 encap_port; + /* This is the max_retrans value for new transports in the * association. */ diff --git a/net/sctp/associola.c b/net/sctp/associola.c index fdb69d4..336df4b 100644 --- a/net/sctp/associola.c +++ b/net/sctp/associola.c @@ -99,6 +99,8 @@ static struct sctp_association *sctp_association_init( */ asoc->hbinterval = msecs_to_jiffies(sp->hbinterval); + asoc->encap_port = sp->encap_port; + /* Initialize path max retrans value. */ asoc->pathmaxrxt = sp->pathmaxrxt; @@ -624,6 +626,8 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc, */ peer->hbinterval = asoc->hbinterval; + peer->encap_port = asoc->encap_port; + /* Set the path max_retrans. */ peer->pathmaxrxt = asoc->pathmaxrxt; diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c index aa8e5b2..7c729d7 100644 --- a/net/sctp/protocol.c +++ b/net/sctp/protocol.c @@ -1359,6 +1359,9 @@ static int __net_init sctp_defaults_init(struct net *net) /* Set UDP tunneling listening port to default value */ net->sctp.udp_port = SCTP_DEFAULT_UDP_PORT; + /* Set remote encap port to 0 by default */ + net->sctp.encap_port = 0; + /* Set SCOPE policy to enabled */ net->sctp.scope_policy = SCTP_SCOPE_POLICY_ENABLE; diff --git a/net/sctp/socket.c b/net/sctp/socket.c index 53d0a41..09b94cd 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -4876,6 +4876,7 @@ static int sctp_init_sock(struct sock *sk) * be modified via SCTP_PEER_ADDR_PARAMS */ sp->hbinterval = net->sctp.hb_interval; + sp->encap_port = htons(net->sctp.encap_port); sp->pathmaxrxt = net->sctp.max_retrans_path; sp->pf_retrans = net->sctp.pf_retrans; sp->ps_retrans = net->sctp.ps_retrans; diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c index c16c809..ecc1b5e 100644 --- a/net/sctp/sysctl.c +++ b/net/sctp/sysctl.c @@ -36,6 +36,7 @@ static int rto_alpha_max = 1000; static int rto_beta_max = 1000; static int pf_expose_max = SCTP_PF_EXPOSE_MAX; static int ps_retrans_max = SCTP_PS_RETRANS_MAX; +static int udp_port_max = 65535; static unsigned long max_autoclose_min = 0; static unsigned long max_autoclose_max = @@ -291,6 +292,15 @@ static struct ctl_table sctp_net_table[] = { .proc_handler = proc_dointvec, }, { + .procname = "encap_port", + .data = &init_net.sctp.encap_port, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec, + .extra1 = SYSCTL_ZERO, + .extra2 = &udp_port_max, + }, + { .procname = "addr_scope_policy", .data = &init_net.sctp.scope_policy, .maxlen = sizeof(int), From patchwork Mon Oct 19 12:25:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 298812 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 902C8C43457 for ; Mon, 19 Oct 2020 12:26:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2D248222B8 for ; Mon, 19 Oct 2020 12:26:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nj8W4Rsp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727483AbgJSM0q (ORCPT ); Mon, 19 Oct 2020 08:26:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726669AbgJSM0q (ORCPT ); Mon, 19 Oct 2020 08:26:46 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F27BAC0613CE; Mon, 19 Oct 2020 05:26:44 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id gv6so5618475pjb.4; Mon, 19 Oct 2020 05:26:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=chT+1o8Xi621C2FvgvkILiU4uVhJ0TT4r54HGt7i2kM=; b=nj8W4RspfBpzQ1vCEEUOo4/d2zwdyms1ncUaR6YDjdQqFjucyPubIO8MVddEhmiDXi 9RvBXgiep+i9woRc1DDi4H6m3uCcqPYiiSmMa/sH8Gn+Nc0U5vB95ZFA7fSMiKE8zxvD 3qDSyAphFOpva6XznRwqvSGXfmHg5yiCSbZ6EhWIihFZcqw++Hnmp/PbK6fxgycBjvA/ PBuoi+FBChYbUMX9jEb9sPDvcbXhFiQpyqHpXQ1YWR/m1M3b8HeHdOuy6FgocqmKDX2Y bIHIdSVsslqUWp0/WywUpIMGKor/IZCZP1XxzeUiQwbWU+IpjYbWCchmItKo4+38RMwn PN6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=chT+1o8Xi621C2FvgvkILiU4uVhJ0TT4r54HGt7i2kM=; b=RxiX1Bdbo9sXqV1HzYntf+IfYjWUHlFFDb5gJbeUsAjbCXwABlD7gOZDsL0a/B5mZ+ FnkzEPNYL4pILB7V+QYv/L1QZD+mQJwFIeTSsjDD/1uS4gvb+bzTm701ZAW8xHDN2T63 4yHEIwvr8VH+GPfiCxkibynXsmbQHbJCiptbQCSOeEvVdSNW3sGTNYm4/IT+uI+Wa2y4 u1t2LBRio1tq8/p6Bz6LgtrvdsgC7ttI+OOIXV1vV/6qGjnDH1s9MZ2IqTcfD9PSJgJS KDcDUCKAxVN68peLl6G2KfKVexuYky4JBHFxfbJJzUiJRh2FKqSmBOPOzRKvKOqENd2w RgBA== X-Gm-Message-State: AOAM531wZ2Wfm15JhjQMdv4QQAtEUsY6/fAvHJK8a3l0rKkDBgVshpRS 8ohYHBnmaXiAUN/b9Fx5yLIxRgIVHgc= X-Google-Smtp-Source: ABdhPJyzZm3DeEhOSaCeOCP67WT4GPhPbL+aa624VrwRaBwNOnhVf/R0UYhoEz0jyPAm3LILfuHfdQ== X-Received: by 2002:a17:90a:5b05:: with SMTP id o5mr16908779pji.139.1603110404245; Mon, 19 Oct 2020 05:26:44 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id n3sm11011432pgf.11.2020.10.19.05.26.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Oct 2020 05:26:43 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , davem@davemloft.net, gnault@redhat.com, pabeni@redhat.com, willemdebruijn.kernel@gmail.com Subject: [PATCHv4 net-next 08/16] sctp: add SCTP_REMOTE_UDP_ENCAPS_PORT sockopt Date: Mon, 19 Oct 2020 20:25:25 +0800 Message-Id: <25013493737f5b488ce48c38667a077ca6573dd5.1603110316.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: References: <71b3af0fb347f27b5c3bf846dbd34485d9f80af0.1603110316.git.lucien.xin@gmail.com> <5f06ac649f4b63fc5a254812a963cada3183f136.1603110316.git.lucien.xin@gmail.com> <7a2f5792c1a428c16962fff08b7bcfedc21bd5e2.1603110316.git.lucien.xin@gmail.com> <7cfd72e42b8b1cde268ad4062c96c08a56c4b14f.1603110316.git.lucien.xin@gmail.com> In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch is to implement: rfc6951#section-6.1: Get or Set the Remote UDP Encapsulation Port Number with the param of the struct: struct sctp_udpencaps { sctp_assoc_t sue_assoc_id; struct sockaddr_storage sue_address; uint16_t sue_port; }; the encap_port of sock, assoc or transport can be changed by users, which also means it allows the different transports of the same asoc to have different encap_port value. v1->v2: - no change. v2->v3: - fix the endian warning when setting values between encap_port and sue_port. Signed-off-by: Xin Long --- include/uapi/linux/sctp.h | 7 +++ net/sctp/socket.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+) diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h index 28ad40d..cb78e7a 100644 --- a/include/uapi/linux/sctp.h +++ b/include/uapi/linux/sctp.h @@ -140,6 +140,7 @@ typedef __s32 sctp_assoc_t; #define SCTP_ECN_SUPPORTED 130 #define SCTP_EXPOSE_POTENTIALLY_FAILED_STATE 131 #define SCTP_EXPOSE_PF_STATE SCTP_EXPOSE_POTENTIALLY_FAILED_STATE +#define SCTP_REMOTE_UDP_ENCAPS_PORT 132 /* PR-SCTP policies */ #define SCTP_PR_SCTP_NONE 0x0000 @@ -1197,6 +1198,12 @@ struct sctp_event { uint8_t se_on; }; +struct sctp_udpencaps { + sctp_assoc_t sue_assoc_id; + struct sockaddr_storage sue_address; + uint16_t sue_port; +}; + /* SCTP Stream schedulers */ enum sctp_sched_type { SCTP_SS_FCFS, diff --git a/net/sctp/socket.c b/net/sctp/socket.c index 09b94cd..2a9ee9b 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -4417,6 +4417,55 @@ static int sctp_setsockopt_pf_expose(struct sock *sk, return retval; } +static int sctp_setsockopt_encap_port(struct sock *sk, + struct sctp_udpencaps *encap, + unsigned int optlen) +{ + struct sctp_association *asoc; + struct sctp_transport *t; + __be16 encap_port; + + if (optlen != sizeof(*encap)) + return -EINVAL; + + /* If an address other than INADDR_ANY is specified, and + * no transport is found, then the request is invalid. + */ + encap_port = (__force __be16)encap->sue_port; + if (!sctp_is_any(sk, (union sctp_addr *)&encap->sue_address)) { + t = sctp_addr_id2transport(sk, &encap->sue_address, + encap->sue_assoc_id); + if (!t) + return -EINVAL; + + t->encap_port = encap_port; + return 0; + } + + /* Get association, if assoc_id != SCTP_FUTURE_ASSOC and the + * socket is a one to many style socket, and an association + * was not found, then the id was invalid. + */ + asoc = sctp_id2assoc(sk, encap->sue_assoc_id); + if (!asoc && encap->sue_assoc_id != SCTP_FUTURE_ASSOC && + sctp_style(sk, UDP)) + return -EINVAL; + + /* If changes are for association, also apply encap_port to + * each transport. + */ + if (asoc) { + list_for_each_entry(t, &asoc->peer.transport_addr_list, + transports) + t->encap_port = encap_port; + + return 0; + } + + sctp_sk(sk)->encap_port = encap_port; + return 0; +} + /* API 6.2 setsockopt(), getsockopt() * * Applications use setsockopt() and getsockopt() to set or retrieve @@ -4636,6 +4685,9 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname, case SCTP_EXPOSE_POTENTIALLY_FAILED_STATE: retval = sctp_setsockopt_pf_expose(sk, kopt, optlen); break; + case SCTP_REMOTE_UDP_ENCAPS_PORT: + retval = sctp_setsockopt_encap_port(sk, kopt, optlen); + break; default: retval = -ENOPROTOOPT; break; @@ -7791,6 +7843,65 @@ static int sctp_getsockopt_pf_expose(struct sock *sk, int len, return retval; } +static int sctp_getsockopt_encap_port(struct sock *sk, int len, + char __user *optval, int __user *optlen) +{ + struct sctp_association *asoc; + struct sctp_udpencaps encap; + struct sctp_transport *t; + __be16 encap_port; + + if (len < sizeof(encap)) + return -EINVAL; + + len = sizeof(encap); + if (copy_from_user(&encap, optval, len)) + return -EFAULT; + + /* If an address other than INADDR_ANY is specified, and + * no transport is found, then the request is invalid. + */ + if (!sctp_is_any(sk, (union sctp_addr *)&encap.sue_address)) { + t = sctp_addr_id2transport(sk, &encap.sue_address, + encap.sue_assoc_id); + if (!t) { + pr_debug("%s: failed no transport\n", __func__); + return -EINVAL; + } + + encap_port = t->encap_port; + goto out; + } + + /* Get association, if assoc_id != SCTP_FUTURE_ASSOC and the + * socket is a one to many style socket, and an association + * was not found, then the id was invalid. + */ + asoc = sctp_id2assoc(sk, encap.sue_assoc_id); + if (!asoc && encap.sue_assoc_id != SCTP_FUTURE_ASSOC && + sctp_style(sk, UDP)) { + pr_debug("%s: failed no association\n", __func__); + return -EINVAL; + } + + if (asoc) { + encap_port = asoc->encap_port; + goto out; + } + + encap_port = sctp_sk(sk)->encap_port; + +out: + encap.sue_port = (__force uint16_t)encap_port; + if (copy_to_user(optval, &encap, len)) + return -EFAULT; + + if (put_user(len, optlen)) + return -EFAULT; + + return 0; +} + static int sctp_getsockopt(struct sock *sk, int level, int optname, char __user *optval, int __user *optlen) { @@ -8011,6 +8122,9 @@ static int sctp_getsockopt(struct sock *sk, int level, int optname, case SCTP_EXPOSE_POTENTIALLY_FAILED_STATE: retval = sctp_getsockopt_pf_expose(sk, len, optval, optlen); break; + case SCTP_REMOTE_UDP_ENCAPS_PORT: + retval = sctp_getsockopt_encap_port(sk, len, optval, optlen); + break; default: retval = -ENOPROTOOPT; break; From patchwork Mon Oct 19 12:25:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 298811 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2637CC43457 for ; Mon, 19 Oct 2020 12:26:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CBFAB22276 for ; Mon, 19 Oct 2020 12:26:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="n1yXf54s" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727562AbgJSM0u (ORCPT ); Mon, 19 Oct 2020 08:26:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727496AbgJSM0s (ORCPT ); Mon, 19 Oct 2020 08:26:48 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A73BC0613CE; Mon, 19 Oct 2020 05:26:48 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id bf6so2881581plb.4; Mon, 19 Oct 2020 05:26:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=74nhfpPDT8w8i9g8WZ68a54psTdsS36MCxiNdbY0yzI=; b=n1yXf54sBp2PdAYVgRvsR72KS2TsqKD6lCua9j6XAakUZaZOH2Bs5NXjMNZQyDWGq1 uyznU+kBwJoaiDwaD2BzOElUrY9fQEn2O3WNz8fLrrA7So39HUq+y0ESZa8zco6ckoUy nH5z1BsQPn40ZGGhECEdnwXNV5gSPpYn/QRMQrdUbB3Mt3zggvDPHgotGdm0DclZ6Izx PHdZz4m3dZyY76B6ud11TmF8k+P7ojxSl5AjZQYdErI59yubmzIrPqc3dQzy8YAXymoQ uvKq/K99/mrJ0A8NxXqGo6ANdmE+17P/PSsssiy522VkPoBBAjcmKz/0pM2R/2B4rjUd 5J7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=74nhfpPDT8w8i9g8WZ68a54psTdsS36MCxiNdbY0yzI=; b=Ij3+ZobtXGFqHsqNCkrVh33K6NyUhlcjKXB6O2i2O4WPEi2Uie+Y7IOEqOJwC+Avp8 x18rMNQpMQ3LzivzqU3fItS7oNIDmZUpQtoTigoWx6so6RkAfrJ9akMQF9xzX4/JfQxS ueyxxi0BzHRjRLOBn52a01MX3muUBUHNVYSOjf0sACB+vzSFnhfztgVHx6UR5CvTh1DE V8Sk/HOZcjCPaaBoNlsld7CvaaBf+yFMYr862ArFoR9s1jzQx0kde1NPQd6jN/1ROCVD 65CGtj5R3gEW+Ak5d2D0aX2RJcrizCo5IDZxx2gVuUgfw3QFjz2YUb14+m5aOtLFDcmK UVRw== X-Gm-Message-State: AOAM532UAFPe9qM+riwbqoX4bhypr1blfEPNH/nbaRmgORChWmsPGS2R TEsWZUf09dirc3cSGmxkb8oz+jM1qV0= X-Google-Smtp-Source: ABdhPJxV9D7+MEZ9jLJgLIgYy4MhZAOCgVTy5UOTEBXDIgDmDfStfM4Z/48xtWerAuO+q7xOAnejiA== X-Received: by 2002:a17:902:7fcd:b029:d3:f037:d9dc with SMTP id t13-20020a1709027fcdb02900d3f037d9dcmr16549470plb.79.1603110407577; Mon, 19 Oct 2020 05:26:47 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id z5sm11585813pfn.20.2020.10.19.05.26.46 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Oct 2020 05:26:47 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , davem@davemloft.net, gnault@redhat.com, pabeni@redhat.com, willemdebruijn.kernel@gmail.com Subject: [PATCHv4 net-next 09/16] sctp: allow changing transport encap_port by peer packets Date: Mon, 19 Oct 2020 20:25:26 +0800 Message-Id: X-Mailer: git-send-email 2.1.0 In-Reply-To: <25013493737f5b488ce48c38667a077ca6573dd5.1603110316.git.lucien.xin@gmail.com> References: <71b3af0fb347f27b5c3bf846dbd34485d9f80af0.1603110316.git.lucien.xin@gmail.com> <5f06ac649f4b63fc5a254812a963cada3183f136.1603110316.git.lucien.xin@gmail.com> <7a2f5792c1a428c16962fff08b7bcfedc21bd5e2.1603110316.git.lucien.xin@gmail.com> <7cfd72e42b8b1cde268ad4062c96c08a56c4b14f.1603110316.git.lucien.xin@gmail.com> <25013493737f5b488ce48c38667a077ca6573dd5.1603110316.git.lucien.xin@gmail.com> In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org As rfc6951#section-5.4 says: "After finding the SCTP association (which includes checking the verification tag), the UDP source port MUST be stored as the encapsulation port for the destination address the SCTP packet is received from (see Section 5.1). When a non-encapsulated SCTP packet is received by the SCTP stack, the encapsulation of outgoing packets belonging to the same association and the corresponding destination address MUST be disabled." transport encap_port should be updated by a validated incoming packet's udp src port. We save the udp src port in sctp_input_cb->encap_port, and then update the transport in two places: 1. right after vtag is verified, which is required by RFC, and this allows the existent transports to be updated by the chunks that can only be processed on an asoc. 2. right before processing the 'init' where the transports are added, and this allows building a sctp over udp connection by client with the server not knowing the remote encap port. 3. when processing ootb_pkt and creating the temporary transport for the reply pkt. Note that sctp_input_cb->header is removed, as it's not used any more in sctp. v1->v2: - Change encap_port as __be16 for sctp_input_cb. Signed-off-by: Xin Long --- include/net/sctp/sm.h | 1 + include/net/sctp/structs.h | 7 +------ net/sctp/ipv6.c | 1 + net/sctp/protocol.c | 11 ++++++++++- net/sctp/sm_make_chunk.c | 1 + net/sctp/sm_statefuns.c | 2 ++ 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h index 5c491a3..a499341 100644 --- a/include/net/sctp/sm.h +++ b/include/net/sctp/sm.h @@ -380,6 +380,7 @@ sctp_vtag_verify(const struct sctp_chunk *chunk, if (ntohl(chunk->sctp_hdr->vtag) == asoc->c.my_vtag) return 1; + chunk->transport->encap_port = SCTP_INPUT_CB(chunk->skb)->encap_port; return 0; } diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h index aa98e7e..81464ae 100644 --- a/include/net/sctp/structs.h +++ b/include/net/sctp/structs.h @@ -1120,14 +1120,9 @@ static inline void sctp_outq_cork(struct sctp_outq *q) * sctp_input_cb is currently used on rx and sock rx queue */ struct sctp_input_cb { - union { - struct inet_skb_parm h4; -#if IS_ENABLED(CONFIG_IPV6) - struct inet6_skb_parm h6; -#endif - } header; struct sctp_chunk *chunk; struct sctp_af *af; + __be16 encap_port; }; #define SCTP_INPUT_CB(__skb) ((struct sctp_input_cb *)&((__skb)->cb[0])) diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c index 8a58f42..a064bf2 100644 --- a/net/sctp/ipv6.c +++ b/net/sctp/ipv6.c @@ -1053,6 +1053,7 @@ static struct inet_protosw sctpv6_stream_protosw = { static int sctp6_rcv(struct sk_buff *skb) { + memset(skb->cb, 0, sizeof(skb->cb)); return sctp_rcv(skb) ? -1 : 0; } diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c index 7c729d7..36f471d 100644 --- a/net/sctp/protocol.c +++ b/net/sctp/protocol.c @@ -843,6 +843,9 @@ static int sctp_ctl_sock_init(struct net *net) static int sctp_udp_rcv(struct sock *sk, struct sk_buff *skb) { + memset(skb->cb, 0, sizeof(skb->cb)); + SCTP_INPUT_CB(skb)->encap_port = udp_hdr(skb)->source; + skb_set_transport_header(skb, sizeof(struct udphdr)); sctp_rcv(skb); return 0; @@ -1139,9 +1142,15 @@ static struct inet_protosw sctp_stream_protosw = { .flags = SCTP_PROTOSW_FLAG }; +static int sctp4_rcv(struct sk_buff *skb) +{ + memset(skb->cb, 0, sizeof(skb->cb)); + return sctp_rcv(skb); +} + /* Register with IP layer. */ static const struct net_protocol sctp_protocol = { - .handler = sctp_rcv, + .handler = sctp4_rcv, .err_handler = sctp_v4_err, .no_policy = 1, .netns_ok = 1, diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c index 9a56ae2..21d0ff1 100644 --- a/net/sctp/sm_make_chunk.c +++ b/net/sctp/sm_make_chunk.c @@ -2321,6 +2321,7 @@ int sctp_process_init(struct sctp_association *asoc, struct sctp_chunk *chunk, * added as the primary transport. The source address seems to * be a better choice than any of the embedded addresses. */ + asoc->encap_port = SCTP_INPUT_CB(chunk->skb)->encap_port; if (!sctp_assoc_add_peer(asoc, peer_addr, gfp, SCTP_ACTIVE)) goto nomem; diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c index c669f8b..8edab15 100644 --- a/net/sctp/sm_statefuns.c +++ b/net/sctp/sm_statefuns.c @@ -6268,6 +6268,8 @@ static struct sctp_packet *sctp_ootb_pkt_new( if (!transport) goto nomem; + transport->encap_port = SCTP_INPUT_CB(chunk->skb)->encap_port; + /* Cache a route for the transport with the chunk's destination as * the source address. */ From patchwork Mon Oct 19 12:25:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 288331 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99DA2C433DF for ; Mon, 19 Oct 2020 12:26:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D35522283 for ; Mon, 19 Oct 2020 12:26:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UPLEcZpY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727652AbgJSM06 (ORCPT ); Mon, 19 Oct 2020 08:26:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727626AbgJSM05 (ORCPT ); Mon, 19 Oct 2020 08:26:57 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8491C0613CE; Mon, 19 Oct 2020 05:26:56 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id h2so4882938pll.11; Mon, 19 Oct 2020 05:26:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=6TmT0zpWssi6omB7JYKtqocDaBeiltFJDNS384mLiKE=; b=UPLEcZpYHug+vKz040o8b3sGylzOz6BIqJRqC//idSvYfut3DYRLu7wnHyTOcJTCjp wAL/kpiZj8g8WcCAeDcuJIqB3jSmNC/GCkdgZnEsmYZkX+WRQ+eyo6cNw4x28a/f7MNr s3XEC9bx588oYjxvHSTl24QrBmUHiD9YwqQ+qnzs4At1PKweQ+rMNeTUo7O3yN6n7H1E owpvLSTt8RUrkxQQURbvHCUGANwaq9Vp++kKwMRwMLiNjHA2v18SRutwywTUKfQqHPni eBt7LM95zeaWm8PZSvZu8ZoNy40Ca6U/UiCFTN0P4nRH2NJiLvr5cG1XpwZskz7x3xA/ OHcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=6TmT0zpWssi6omB7JYKtqocDaBeiltFJDNS384mLiKE=; b=phXVANgCg1Evpv168ovcAJXdhCrRM2Iklfc1bK4LMXKlFMMQCQ/fZHW1uwOERdYL7+ 1mf2aqvdFSQzOkFGssofvPvmDE+4v/mlkkSmv7QGg0UoWIXg4OKeUjVWd0oBPFZJtrwO G0lF8UFgh8pKxw5xDBgKViNLM9pPUi2LM6aPolpwsvGCSS/JtLKVIXqODNkasAu4HX62 nGzQOhCffcSpnzV6dWfjGZi3sAozFgnLJ+AzqOaxyRkn9w0zMDYds+eGp5QuIByjCMlU S+XixVtRHvLDq7yjPOk4NF5yNAdtwkC18YiUIzdhWUj8UCV4rs6Ra/JPDncqnw7TWsv/ +yZg== X-Gm-Message-State: AOAM532tp5KKtlTTZW1IRvWllYuQVkN84Ho8PiRAOz3IRfFy/AMAK8wM 1c8gVZuCvwhrKPNp2BdD2axL7KquBUk= X-Google-Smtp-Source: ABdhPJzhO8rMhINNt7L+oMr2gmm2X0TlvD0mGKlct8qL1+v5fizRlNSSIqWJ0gXE9nlOk6N0+HnG1w== X-Received: by 2002:a17:90b:312:: with SMTP id ay18mr16987873pjb.17.1603110415974; Mon, 19 Oct 2020 05:26:55 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id k14sm10968111pfu.163.2020.10.19.05.26.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Oct 2020 05:26:55 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , davem@davemloft.net, gnault@redhat.com, pabeni@redhat.com, willemdebruijn.kernel@gmail.com Subject: [PATCHv4 net-next 10/16] sctp: add udphdr to overhead when udp_port is set Date: Mon, 19 Oct 2020 20:25:27 +0800 Message-Id: <8547ef8c7056072bdeca8f5e9eb0d7fec5cdb210.1603110316.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: References: <71b3af0fb347f27b5c3bf846dbd34485d9f80af0.1603110316.git.lucien.xin@gmail.com> <5f06ac649f4b63fc5a254812a963cada3183f136.1603110316.git.lucien.xin@gmail.com> <7a2f5792c1a428c16962fff08b7bcfedc21bd5e2.1603110316.git.lucien.xin@gmail.com> <7cfd72e42b8b1cde268ad4062c96c08a56c4b14f.1603110316.git.lucien.xin@gmail.com> <25013493737f5b488ce48c38667a077ca6573dd5.1603110316.git.lucien.xin@gmail.com> In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org sctp_mtu_payload() is for calculating the frag size before making chunks from a msg. So we should only add udphdr size to overhead when udp socks are listening, as only then sctp can handle the incoming sctp over udp packets and outgoing sctp over udp packets will be possible. Note that we can't do this according to transport->encap_port, as different transports may be set to different values, while the chunks were made before choosing the transport, we could not be able to meet all rfc6951#section-5.6 recommends. v1->v2: - Add udp_port for sctp_sock to avoid a potential race issue, it will be used in xmit path in the next patch. Signed-off-by: Xin Long --- include/net/sctp/sctp.h | 7 +++++-- include/net/sctp/structs.h | 1 + net/sctp/socket.c | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h index bfd87a0..86f74f2 100644 --- a/include/net/sctp/sctp.h +++ b/include/net/sctp/sctp.h @@ -578,10 +578,13 @@ static inline __u32 sctp_mtu_payload(const struct sctp_sock *sp, { __u32 overhead = sizeof(struct sctphdr) + extra; - if (sp) + if (sp) { overhead += sp->pf->af->net_header_len; - else + if (sp->udp_port) + overhead += sizeof(struct udphdr); + } else { overhead += sizeof(struct ipv6hdr); + } if (WARN_ON_ONCE(mtu && mtu <= overhead)) mtu = overhead; diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h index 81464ae..80f7149 100644 --- a/include/net/sctp/structs.h +++ b/include/net/sctp/structs.h @@ -178,6 +178,7 @@ struct sctp_sock { */ __u32 hbinterval; + __be16 udp_port; __be16 encap_port; /* This is the max_retrans value for new associations. */ diff --git a/net/sctp/socket.c b/net/sctp/socket.c index 2a9ee9b..a710917 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -4928,6 +4928,7 @@ static int sctp_init_sock(struct sock *sk) * be modified via SCTP_PEER_ADDR_PARAMS */ sp->hbinterval = net->sctp.hb_interval; + sp->udp_port = htons(net->sctp.udp_port); sp->encap_port = htons(net->sctp.encap_port); sp->pathmaxrxt = net->sctp.max_retrans_path; sp->pf_retrans = net->sctp.pf_retrans; From patchwork Mon Oct 19 12:25:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 298810 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31F18C433DF for ; Mon, 19 Oct 2020 12:27:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CFE3D22283 for ; Mon, 19 Oct 2020 12:27:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DyVHhRoz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727701AbgJSM1F (ORCPT ); Mon, 19 Oct 2020 08:27:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727666AbgJSM1F (ORCPT ); Mon, 19 Oct 2020 08:27:05 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC108C0613D0; Mon, 19 Oct 2020 05:27:04 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id r10so1126729plx.3; Mon, 19 Oct 2020 05:27:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=ccnTdRi301/TdXAApcTfL39DiVa+OmKFQ/8+9UDuAeU=; b=DyVHhRozNAWDkboXTLRB1V5z+YPNnvIQX9/lfIncYO/7jqcMxIynJyVq9ZDW6TdIqK H4ql7DJSLAmL009kw4dEQD7QnOZDCDMk6zBk3YhVE3m0jsohziveJx8oRyjaXylLD9J3 VDIuo8EDtoVsS1qfYIWG/TpO8NgrCqdPXUcGpyYwV6otq6U1GmoVRY/WVFKVVBBH3/h6 jDGL7kNOTxvgaLsiDgAjWMP6XvvGc6FpuyKzsPqSt6doVNX94rb0uEFTJ19Dy3kbmjR3 yu1mrwDu+C+aoCvDc1OQRY3IYgwEEeaUcmRtevHMOR1PfzSG2zVBzzkhqL2l5YRZPmr9 m1tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=ccnTdRi301/TdXAApcTfL39DiVa+OmKFQ/8+9UDuAeU=; b=scv8xFvxzrDY91HWidSjNcMjK4lDXxpxYcTu2TOH7NM3NR7TEwsYd24U7wvHeSc8fw 35fSKP1j6Va6P939yploCRzstUD0j1Tvqc8xXt1n2UAhRO1cvpTqMXEDjgjDKvfwCN2k QsLhNc18GdbW2Id3gC7pCwc+GSON7rQZEOduJ5LX8gEkbCnA0T3IMLW8UtxRlZZHD/UW KKULi0XO7RraqefGHbD63XamM2Zj2+u3Wbo/fvZIEmPAJ8cNjFgZK0RXGlLTithhuqTI VCTCU+n5W60/+u9NLejUtADGR4pTmG6aaWBwhxIXRe23ob2QtpjW45QpaJrpE7OUcOZP hgHQ== X-Gm-Message-State: AOAM533Dp2SD/TCGUshOx8aqM5TjFRub8ebnmwJUkKnkTwIFqYxwPO8L roemBsGCmNqBCx6gVo8eES1oArXoTMo= X-Google-Smtp-Source: ABdhPJzNsD/WOhx8G4t2hEN7WtPnBYt3rvcSktR0B3JWE7UXIf6Ww0HJzR6kxlFcWofw1euRG/80Mg== X-Received: by 2002:a17:90a:ff12:: with SMTP id ce18mr15992572pjb.223.1603110424313; Mon, 19 Oct 2020 05:27:04 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id f5sm11106349pgi.86.2020.10.19.05.27.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Oct 2020 05:27:03 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , davem@davemloft.net, gnault@redhat.com, pabeni@redhat.com, willemdebruijn.kernel@gmail.com Subject: [PATCHv4 net-next 11/16] sctp: call sk_setup_caps in sctp_packet_transmit instead Date: Mon, 19 Oct 2020 20:25:28 +0800 Message-Id: X-Mailer: git-send-email 2.1.0 In-Reply-To: <8547ef8c7056072bdeca8f5e9eb0d7fec5cdb210.1603110316.git.lucien.xin@gmail.com> References: <71b3af0fb347f27b5c3bf846dbd34485d9f80af0.1603110316.git.lucien.xin@gmail.com> <5f06ac649f4b63fc5a254812a963cada3183f136.1603110316.git.lucien.xin@gmail.com> <7a2f5792c1a428c16962fff08b7bcfedc21bd5e2.1603110316.git.lucien.xin@gmail.com> <7cfd72e42b8b1cde268ad4062c96c08a56c4b14f.1603110316.git.lucien.xin@gmail.com> <25013493737f5b488ce48c38667a077ca6573dd5.1603110316.git.lucien.xin@gmail.com> <8547ef8c7056072bdeca8f5e9eb0d7fec5cdb210.1603110316.git.lucien.xin@gmail.com> In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org sk_setup_caps() was originally called in Commit 90017accff61 ("sctp: Add GSO support"), as: "We have to refresh this in case we are xmiting to more than one transport at a time" This actually happens in the loop of sctp_outq_flush_transports(), and it shouldn't be tied to gso, so move it out of gso part and before sctp_packet_pack(). Signed-off-by: Xin Long --- net/sctp/output.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/net/sctp/output.c b/net/sctp/output.c index 1441eaf..fb16500 100644 --- a/net/sctp/output.c +++ b/net/sctp/output.c @@ -508,12 +508,6 @@ static int sctp_packet_pack(struct sctp_packet *packet, sizeof(struct inet6_skb_parm))); skb_shinfo(head)->gso_segs = pkt_count; skb_shinfo(head)->gso_size = GSO_BY_FRAGS; - rcu_read_lock(); - if (skb_dst(head) != tp->dst) { - dst_hold(tp->dst); - sk_setup_caps(sk, tp->dst); - } - rcu_read_unlock(); goto chksum; } @@ -593,6 +587,13 @@ int sctp_packet_transmit(struct sctp_packet *packet, gfp_t gfp) } skb_dst_set(head, dst); + rcu_read_lock(); + if (__sk_dst_get(sk) != tp->dst) { + dst_hold(tp->dst); + sk_setup_caps(sk, tp->dst); + } + rcu_read_unlock(); + /* pack up chunks */ pkt_count = sctp_packet_pack(packet, head, gso, gfp); if (!pkt_count) { From patchwork Mon Oct 19 12:25:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 288330 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E934DC433DF for ; Mon, 19 Oct 2020 12:27:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8B82122283 for ; Mon, 19 Oct 2020 12:27:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gVxTGHOF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727754AbgJSM1O (ORCPT ); Mon, 19 Oct 2020 08:27:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727666AbgJSM1N (ORCPT ); Mon, 19 Oct 2020 08:27:13 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75B8FC0613CE; Mon, 19 Oct 2020 05:27:13 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id y1so4894928plp.6; Mon, 19 Oct 2020 05:27:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=Cwqe1kdLF1BpI/Lbtq3e9NcGf1oL7Z7RjOQGe3mliTg=; b=gVxTGHOFsOU2ls+0582qM5I6qKd0g/0I8qTS5fcOfm3iJ5DImKz6WNt9lpj+78/V7G dwlifgnoMjAOTdOqZZSc6yiJjkoGUDz1sFpskM9ojGIhFkR03Z40L7GxdoLN/Z+yj6Kt pmZ7SpSHUqtNIN2lDXm7g5XmfrRmyv6lvKKf2DFu0JE7ksAOjCx/nBkCRUoXRryf1e8z 6A/7LXkrfvA6WesE83MobUmgdShM0Q2nkciy2dpjmcu1XQWnG6N/jUxjvS8Wxe8vSWtj V+ZPldp27/xn2rk4yUru9YNJZRDc6na/ZFJSKB89IbHLgjBg0We2s0ZbXyh1bqN3v2wp 8ynQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=Cwqe1kdLF1BpI/Lbtq3e9NcGf1oL7Z7RjOQGe3mliTg=; b=avmtX5nRbAoHSUALBsuZhQVIIH9Wk5uV9xJTIPjssQfaouTxzHJbE32cwyw/2AFJ4z IeC/8UQtvh+fXj3zW1j+wppVaO08EQ7JSGOM+TuOdsBHl4tbYKY1doz0rVLTxKDPUUwO le8QeIcAngoTd/pvU9xsDoqgoPdf41qYL5+4BZyDpRvEetbtegvPgL8435m7C0lNSw5k Ey3ESWIqYoCVhsVnVpr26tPwYNUbjYAYH6CctHZEl6TGJJxCNX1Boskmy3XKyJ1nAE1W L0LevfWy9hyS8rarDsDuj+QyJjbYCJQASzSpZLqUJtVHLAiOlKX0BU7TosU0tFYSnPU7 ZUsg== X-Gm-Message-State: AOAM5311H5AXNIrkhJxCeMR/G15acGs3R/R4+o8YmlJ0+RSFZHUJBu8Z EhY6pcgb9t7C0cjvOsO9t85Sa/TQTZg= X-Google-Smtp-Source: ABdhPJwaI6WzNVqztOkdCGWO78/at1kdHl9TYC189kmboEhvRCa30Ycr0XjNEmLUPG8KLsQwcidSWA== X-Received: by 2002:a17:90a:474b:: with SMTP id y11mr16955981pjg.114.1603110432679; Mon, 19 Oct 2020 05:27:12 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id 17sm10936040pgv.58.2020.10.19.05.27.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Oct 2020 05:27:12 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , davem@davemloft.net, gnault@redhat.com, pabeni@redhat.com, willemdebruijn.kernel@gmail.com Subject: [PATCHv4 net-next 12/16] sctp: support for sending packet over udp4 sock Date: Mon, 19 Oct 2020 20:25:29 +0800 Message-Id: <2cac0eaff47574dbc07a4a074500f5e0300cff3e.1603110316.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: References: <71b3af0fb347f27b5c3bf846dbd34485d9f80af0.1603110316.git.lucien.xin@gmail.com> <5f06ac649f4b63fc5a254812a963cada3183f136.1603110316.git.lucien.xin@gmail.com> <7a2f5792c1a428c16962fff08b7bcfedc21bd5e2.1603110316.git.lucien.xin@gmail.com> <7cfd72e42b8b1cde268ad4062c96c08a56c4b14f.1603110316.git.lucien.xin@gmail.com> <25013493737f5b488ce48c38667a077ca6573dd5.1603110316.git.lucien.xin@gmail.com> <8547ef8c7056072bdeca8f5e9eb0d7fec5cdb210.1603110316.git.lucien.xin@gmail.com> In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch does what the rfc6951#section-5.3 says for ipv4: "Within the UDP header, the source port MUST be the local UDP encapsulation port number of the SCTP stack, and the destination port MUST be the remote UDP encapsulation port number maintained for the association and the destination address to which the packet is sent (see Section 5.1). Because the SCTP packet is the UDP payload, the length of the UDP packet MUST be the length of the SCTP packet plus the size of the UDP header. The SCTP checksum MUST be computed for IPv4 and IPv6, and the UDP checksum SHOULD be computed for IPv4 and IPv6." Some places need to be adjusted in sctp_packet_transmit(): 1. For non-gso packets, when transport's encap_port is set, sctp checksum has to be done in sctp_packet_pack(), as the outer udp will use ip_summed = CHECKSUM_PARTIAL to do the offload setting for checksum. 2. Delay calling dst_clone() and skb_dst_set() for non-udp packets until sctp_v4_xmit(), as for udp packets, skb_dst_set() is not needed before calling udp_tunnel_xmit_skb(). then in sctp_v4_xmit(): 1. Go to udp_tunnel_xmit_skb() only when transport->encap_port and net->sctp.udp_port both are set, as these are one for dst port and another for src port. 2. For gso packet, SKB_GSO_UDP_TUNNEL_CSUM is set for gso_type, and with this udp checksum can be done in __skb_udp_tunnel_segment() for each segments after the sctp gso. 3. inner_mac_header and inner_transport_header are set, as these will be needed in __skb_udp_tunnel_segment() to find the right headers. 4. df and ttl are calculated, as these are the required params by udp_tunnel_xmit_skb(). 5. nocheck param has to be false, as "the UDP checksum SHOULD be computed for IPv4 and IPv6", says in rfc6951#section-5.3. v1->v2: - Use sp->udp_port instead in sctp_v4_xmit(), which is more safe. Signed-off-by: Xin Long --- net/sctp/output.c | 9 +++------ net/sctp/protocol.c | 41 ++++++++++++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/net/sctp/output.c b/net/sctp/output.c index fb16500..6614c9f 100644 --- a/net/sctp/output.c +++ b/net/sctp/output.c @@ -514,8 +514,8 @@ static int sctp_packet_pack(struct sctp_packet *packet, if (sctp_checksum_disable) return 1; - if (!(skb_dst(head)->dev->features & NETIF_F_SCTP_CRC) || - dst_xfrm(skb_dst(head)) || packet->ipfragok) { + if (!(tp->dst->dev->features & NETIF_F_SCTP_CRC) || + dst_xfrm(tp->dst) || packet->ipfragok || tp->encap_port) { struct sctphdr *sh = (struct sctphdr *)skb_transport_header(head); @@ -542,7 +542,6 @@ int sctp_packet_transmit(struct sctp_packet *packet, gfp_t gfp) struct sctp_association *asoc = tp->asoc; struct sctp_chunk *chunk, *tmp; int pkt_count, gso = 0; - struct dst_entry *dst; struct sk_buff *head; struct sctphdr *sh; struct sock *sk; @@ -579,13 +578,11 @@ int sctp_packet_transmit(struct sctp_packet *packet, gfp_t gfp) sh->checksum = 0; /* drop packet if no dst */ - dst = dst_clone(tp->dst); - if (!dst) { + if (!tp->dst) { IP_INC_STATS(sock_net(sk), IPSTATS_MIB_OUTNOROUTES); kfree_skb(head); goto out; } - skb_dst_set(head, dst); rcu_read_lock(); if (__sk_dst_get(sk) != tp->dst) { diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c index 36f471d..c8de327 100644 --- a/net/sctp/protocol.c +++ b/net/sctp/protocol.c @@ -1059,25 +1059,44 @@ static int sctp_inet_supported_addrs(const struct sctp_sock *opt, } /* Wrapper routine that calls the ip transmit routine. */ -static inline int sctp_v4_xmit(struct sk_buff *skb, - struct sctp_transport *transport) +static inline int sctp_v4_xmit(struct sk_buff *skb, struct sctp_transport *t) { - struct inet_sock *inet = inet_sk(skb->sk); + struct dst_entry *dst = dst_clone(t->dst); + struct flowi4 *fl4 = &t->fl.u.ip4; + struct sock *sk = skb->sk; + struct inet_sock *inet = inet_sk(sk); __u8 dscp = inet->tos; + __be16 df = 0; pr_debug("%s: skb:%p, len:%d, src:%pI4, dst:%pI4\n", __func__, skb, - skb->len, &transport->fl.u.ip4.saddr, - &transport->fl.u.ip4.daddr); + skb->len, &fl4->saddr, &fl4->daddr); + + if (t->dscp & SCTP_DSCP_SET_MASK) + dscp = t->dscp & SCTP_DSCP_VAL_MASK; - if (transport->dscp & SCTP_DSCP_SET_MASK) - dscp = transport->dscp & SCTP_DSCP_VAL_MASK; + inet->pmtudisc = t->param_flags & SPP_PMTUD_ENABLE ? IP_PMTUDISC_DO + : IP_PMTUDISC_DONT; + SCTP_INC_STATS(sock_net(sk), SCTP_MIB_OUTSCTPPACKS); - inet->pmtudisc = transport->param_flags & SPP_PMTUD_ENABLE ? - IP_PMTUDISC_DO : IP_PMTUDISC_DONT; + if (!t->encap_port || !sctp_sk(sk)->udp_port) { + skb_dst_set(skb, dst); + return __ip_queue_xmit(sk, skb, &t->fl, dscp); + } + + if (skb_is_gso(skb)) + skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL_CSUM; - SCTP_INC_STATS(sock_net(&inet->sk), SCTP_MIB_OUTSCTPPACKS); + if (ip_dont_fragment(sk, dst) && !skb->ignore_df) + df = htons(IP_DF); - return __ip_queue_xmit(&inet->sk, skb, &transport->fl, dscp); + skb->encapsulation = 1; + skb_reset_inner_mac_header(skb); + skb_reset_inner_transport_header(skb); + skb_set_inner_ipproto(skb, IPPROTO_SCTP); + udp_tunnel_xmit_skb((struct rtable *)dst, sk, skb, fl4->saddr, + fl4->daddr, dscp, ip4_dst_hoplimit(dst), df, + sctp_sk(sk)->udp_port, t->encap_port, false, false); + return 0; } static struct sctp_af sctp_af_inet; From patchwork Mon Oct 19 12:25:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 298809 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5A81C433DF for ; Mon, 19 Oct 2020 12:27:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 70BCA2223C for ; Mon, 19 Oct 2020 12:27:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EnR/t6Ye" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727796AbgJSM1W (ORCPT ); Mon, 19 Oct 2020 08:27:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727666AbgJSM1W (ORCPT ); Mon, 19 Oct 2020 08:27:22 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1825FC0613CE; Mon, 19 Oct 2020 05:27:22 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id y14so5904950pfp.13; Mon, 19 Oct 2020 05:27:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=zpcgNpTt1Eopd9QaDKGy8sWqns6Rwfi4+2UKE6Sn+wQ=; b=EnR/t6Yefl4ynppM/Pt6u5FR1UyrGnGg/6sh/Cdzd5DBzocLVy1Nc7oEUyTxa4Z7QG LpyrkAaGEUC0pJzIvQAMP6qfzESXbD/EBORKE/QytC+ZT9M2GKEIimiRefjqCXUnm9Gs nDS4QgHyOg2hXmGCRNvzBBDmiYIttvliDkzMghiwr+F7GZnfhcu5b6LHaiS0E3tHhhyD 1YGMKGVfrgaMrA9lMJob4osVoN7ClLLpm2WC2fhwf6F62s5rc6drMbP9avClI+Oc8BUw 64Av6xPyO7zcOd2ZXF0AdCuxqk26AOZEipQkgpmDHGU6mExTPLkx0cGFtN+QYfQUHrM3 ECWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=zpcgNpTt1Eopd9QaDKGy8sWqns6Rwfi4+2UKE6Sn+wQ=; b=W3+Mdvce1au+VoZYHjMF+Luruc8ms5PWNc4LqYYzmAnzWtYQjJXLoDT/+jXbd7n2GE lUKYvbFd4AOVRx8qebsixKbjwG1LtTr5AVVDnkh+TFHm111TZ8PUnBZXvRRShFf67wp6 mFEc83HQBhV1MBd21snkO2gtkjRh/NFZeSaM+aDm6yBzjRknComw6Sn19i5oT7iybzmj A8VjSHwMHi/SIuNPa4oPvmCxSCdXvfkltT5r0oH+uOLCuJhARyIiq6gJb6Pj1yE8EoCf IsBnLQUGIxEMq6nVP/H7qchaZDU66XouGZsRfbB3v3EDe9brXyJC7xaSyM9yLi3WbHcT LStg== X-Gm-Message-State: AOAM532vKdK9Ch/PyC2DibjYZxhODc5LRPwiVZ7sDQKkaMGMIMN2EOEB yHOMoztDu9GcLUXvjAC5yeZN2FpiQ6g= X-Google-Smtp-Source: ABdhPJyPocIw1l8i+r2wkfmTucmipKkjcna1qVo0575izXjVJ1EokZ5RtjzmqCGk6JJhL5udCmqxsQ== X-Received: by 2002:a62:6202:0:b029:15c:dac8:866 with SMTP id w2-20020a6262020000b029015cdac80866mr7896296pfb.72.1603110441368; Mon, 19 Oct 2020 05:27:21 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id s126sm11985641pgc.27.2020.10.19.05.27.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Oct 2020 05:27:20 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , davem@davemloft.net, gnault@redhat.com, pabeni@redhat.com, willemdebruijn.kernel@gmail.com Subject: [PATCHv4 net-next 13/16] sctp: support for sending packet over udp6 sock Date: Mon, 19 Oct 2020 20:25:30 +0800 Message-Id: <15f6150aa59acd248129723df647d55ea1169d85.1603110316.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <2cac0eaff47574dbc07a4a074500f5e0300cff3e.1603110316.git.lucien.xin@gmail.com> References: <71b3af0fb347f27b5c3bf846dbd34485d9f80af0.1603110316.git.lucien.xin@gmail.com> <5f06ac649f4b63fc5a254812a963cada3183f136.1603110316.git.lucien.xin@gmail.com> <7a2f5792c1a428c16962fff08b7bcfedc21bd5e2.1603110316.git.lucien.xin@gmail.com> <7cfd72e42b8b1cde268ad4062c96c08a56c4b14f.1603110316.git.lucien.xin@gmail.com> <25013493737f5b488ce48c38667a077ca6573dd5.1603110316.git.lucien.xin@gmail.com> <8547ef8c7056072bdeca8f5e9eb0d7fec5cdb210.1603110316.git.lucien.xin@gmail.com> <2cac0eaff47574dbc07a4a074500f5e0300cff3e.1603110316.git.lucien.xin@gmail.com> In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This one basically does the similar things in sctp_v6_xmit as does for udp4 sock in the last patch, just note that: 1. label needs to be calculated, as it's the param of udp_tunnel6_xmit_skb(). 2. The 'nocheck' param of udp_tunnel6_xmit_skb() is false, as required by RFC. v1->v2: - Use sp->udp_port instead in sctp_v6_xmit(), which is more safe. Signed-off-by: Xin Long --- net/sctp/ipv6.c | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c index a064bf2..814754d 100644 --- a/net/sctp/ipv6.c +++ b/net/sctp/ipv6.c @@ -55,6 +55,7 @@ #include #include #include +#include #include @@ -191,33 +192,53 @@ static int sctp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, return ret; } -static int sctp_v6_xmit(struct sk_buff *skb, struct sctp_transport *transport) +static int sctp_v6_xmit(struct sk_buff *skb, struct sctp_transport *t) { + struct dst_entry *dst = dst_clone(t->dst); + struct flowi6 *fl6 = &t->fl.u.ip6; struct sock *sk = skb->sk; struct ipv6_pinfo *np = inet6_sk(sk); - struct flowi6 *fl6 = &transport->fl.u.ip6; __u8 tclass = np->tclass; - int res; + __be32 label; pr_debug("%s: skb:%p, len:%d, src:%pI6 dst:%pI6\n", __func__, skb, skb->len, &fl6->saddr, &fl6->daddr); - if (transport->dscp & SCTP_DSCP_SET_MASK) - tclass = transport->dscp & SCTP_DSCP_VAL_MASK; + if (t->dscp & SCTP_DSCP_SET_MASK) + tclass = t->dscp & SCTP_DSCP_VAL_MASK; if (INET_ECN_is_capable(tclass)) IP6_ECN_flow_xmit(sk, fl6->flowlabel); - if (!(transport->param_flags & SPP_PMTUD_ENABLE)) + if (!(t->param_flags & SPP_PMTUD_ENABLE)) skb->ignore_df = 1; SCTP_INC_STATS(sock_net(sk), SCTP_MIB_OUTSCTPPACKS); - rcu_read_lock(); - res = ip6_xmit(sk, skb, fl6, sk->sk_mark, rcu_dereference(np->opt), - tclass, sk->sk_priority); - rcu_read_unlock(); - return res; + if (!t->encap_port || !sctp_sk(sk)->udp_port) { + int res; + + skb_dst_set(skb, dst); + rcu_read_lock(); + res = ip6_xmit(sk, skb, fl6, sk->sk_mark, + rcu_dereference(np->opt), + tclass, sk->sk_priority); + rcu_read_unlock(); + return res; + } + + if (skb_is_gso(skb)) + skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL_CSUM; + + skb->encapsulation = 1; + skb_reset_inner_mac_header(skb); + skb_reset_inner_transport_header(skb); + skb_set_inner_ipproto(skb, IPPROTO_SCTP); + label = ip6_make_flowlabel(sock_net(sk), skb, fl6->flowlabel, true, fl6); + + return udp_tunnel6_xmit_skb(dst, sk, skb, NULL, &fl6->saddr, + &fl6->daddr, tclass, ip6_dst_hoplimit(dst), + label, sctp_sk(sk)->udp_port, t->encap_port, false); } /* Returns the dst cache entry for the given source and destination ip From patchwork Mon Oct 19 12:25:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 288329 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0CBBC433E7 for ; Mon, 19 Oct 2020 12:27:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 492CE2224D for ; Mon, 19 Oct 2020 12:27:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JeWGO7Id" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727811AbgJSM10 (ORCPT ); Mon, 19 Oct 2020 08:27:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726356AbgJSM10 (ORCPT ); Mon, 19 Oct 2020 08:27:26 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 888E9C0613CE; Mon, 19 Oct 2020 05:27:25 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id c20so5919389pfr.8; Mon, 19 Oct 2020 05:27:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=wT/TsOhKuL5HL67D4xz7aT44ptac/zTxHCX64c9ov/Y=; b=JeWGO7IdSQyHt3ifgiJyIjhZ/BEE9PeB59hozeF8xmMkgITVsDeFXj7VhqkfpQD1FR k2Od6nIU32a83IQQJQnBWI5/gh3zTUTnpBE2otDgm7/sMbRBJgFnMpuudzu9oB7GaxLe O8Yv2lPkk/u7AxH7KqImNIPNBmTg/t5DFAJoRzH24SjlNdPcW5qMH8a6b/goTdZwi5Tz Pz61Mqc+8eObLxXQxFRny69H4rvQb5ERfV1hjirLo481a6zrx+8f5CjDnCMqbbtBv4IK 9phhnF+4wGs2zVmflrBLRIFMABG84sPU64OBZOoj8Je7q53mWyqWvjYkQU33AbzDiKF5 H4Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=wT/TsOhKuL5HL67D4xz7aT44ptac/zTxHCX64c9ov/Y=; b=tR0dmQSnPtsqt2xN3KAIsUsLLEsq9cGheL5rw50I2pUd0iOuMCu8foQmbfCkbFq6DI H2YcB+1xYrU7as3uH8QXkGmyPxFKt718Nfagb3w19IyUR/cKf/bnt66P3uy4a+Q91Jp+ UX6x0jQ9ko4nQKYkK7JJyAyRm2r8NYhN9lEbxjCymz1IEAvdoix4C1RsGY1VFkUUPrIw NfcSFQWgru1Uu22Q3q+uO+4VnmVqG8hSlUYSxiRmqcKX3ZCbPUeOvJNs5tqqfRx1YuDm w9N2CKa2j1xLBWNJxa7IduTsXKmIDp+TGaAmTqP5spV3e3K7A0sx51xQf6IWTANMN3hE ePug== X-Gm-Message-State: AOAM531O1LJdnnlX86CyiXYkWZxRlQXeXvPJlN0zfIWu62zYcWS2LN8V RxLP5GOBPTdC4CxpRIGQ4KY6+FNnJps= X-Google-Smtp-Source: ABdhPJzQagKRhuIt1tEEq2qxlhb/fNFxitM7uMN787n4Ya3mGodXQwnI9aqJ36qo86FMAHq9s9ib9w== X-Received: by 2002:a63:c70c:: with SMTP id n12mr13719923pgg.102.1603110444798; Mon, 19 Oct 2020 05:27:24 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id w187sm11609954pfb.93.2020.10.19.05.27.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Oct 2020 05:27:24 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , davem@davemloft.net, gnault@redhat.com, pabeni@redhat.com, willemdebruijn.kernel@gmail.com Subject: [PATCHv4 net-next 14/16] sctp: add the error cause for new encapsulation port restart Date: Mon, 19 Oct 2020 20:25:31 +0800 Message-Id: <37b49f3c6eb568d25d7e46fa3f55a1c580867bb2.1603110316.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <15f6150aa59acd248129723df647d55ea1169d85.1603110316.git.lucien.xin@gmail.com> References: <71b3af0fb347f27b5c3bf846dbd34485d9f80af0.1603110316.git.lucien.xin@gmail.com> <5f06ac649f4b63fc5a254812a963cada3183f136.1603110316.git.lucien.xin@gmail.com> <7a2f5792c1a428c16962fff08b7bcfedc21bd5e2.1603110316.git.lucien.xin@gmail.com> <7cfd72e42b8b1cde268ad4062c96c08a56c4b14f.1603110316.git.lucien.xin@gmail.com> <25013493737f5b488ce48c38667a077ca6573dd5.1603110316.git.lucien.xin@gmail.com> <8547ef8c7056072bdeca8f5e9eb0d7fec5cdb210.1603110316.git.lucien.xin@gmail.com> <2cac0eaff47574dbc07a4a074500f5e0300cff3e.1603110316.git.lucien.xin@gmail.com> <15f6150aa59acd248129723df647d55ea1169d85.1603110316.git.lucien.xin@gmail.com> In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch is to add the function to make the abort chunk with the error cause for new encapsulation port restart, defined on Section 4.4 in draft-tuexen-tsvwg-sctp-udp-encaps-cons-03. v1->v2: - no change. v2->v3: - no need to call htons() when setting nep.cur_port/new_port. Signed-off-by: Xin Long --- include/linux/sctp.h | 20 ++++++++++++++++++++ include/net/sctp/sm.h | 3 +++ net/sctp/sm_make_chunk.c | 20 ++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/include/linux/sctp.h b/include/linux/sctp.h index 7673123..bb19265 100644 --- a/include/linux/sctp.h +++ b/include/linux/sctp.h @@ -482,11 +482,13 @@ enum sctp_error { * 11 Restart of an association with new addresses * 12 User Initiated Abort * 13 Protocol Violation + * 14 Restart of an Association with New Encapsulation Port */ SCTP_ERROR_RESTART = cpu_to_be16(0x0b), SCTP_ERROR_USER_ABORT = cpu_to_be16(0x0c), SCTP_ERROR_PROTO_VIOLATION = cpu_to_be16(0x0d), + SCTP_ERROR_NEW_ENCAP_PORT = cpu_to_be16(0x0e), /* ADDIP Section 3.3 New Error Causes * @@ -793,4 +795,22 @@ enum { SCTP_FLOWLABEL_VAL_MASK = 0xfffff }; +/* UDP Encapsulation + * draft-tuexen-tsvwg-sctp-udp-encaps-cons-03.html#section-4-4 + * + * The error cause indicating an "Restart of an Association with + * New Encapsulation Port" + * + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Cause Code = 14 | Cause Length = 8 | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Current Encapsulation Port | New Encapsulation Port | + * +-------------------------------+-------------------------------+ + */ +struct sctp_new_encap_port_hdr { + __be16 cur_port; + __be16 new_port; +}; + #endif /* __LINUX_SCTP_H__ */ diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h index a499341..fd223c9 100644 --- a/include/net/sctp/sm.h +++ b/include/net/sctp/sm.h @@ -221,6 +221,9 @@ struct sctp_chunk *sctp_make_violation_paramlen( struct sctp_chunk *sctp_make_violation_max_retrans( const struct sctp_association *asoc, const struct sctp_chunk *chunk); +struct sctp_chunk *sctp_make_new_encap_port( + const struct sctp_association *asoc, + const struct sctp_chunk *chunk); struct sctp_chunk *sctp_make_heartbeat(const struct sctp_association *asoc, const struct sctp_transport *transport); struct sctp_chunk *sctp_make_heartbeat_ack(const struct sctp_association *asoc, diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c index 21d0ff1..f77484d 100644 --- a/net/sctp/sm_make_chunk.c +++ b/net/sctp/sm_make_chunk.c @@ -1142,6 +1142,26 @@ struct sctp_chunk *sctp_make_violation_max_retrans( return retval; } +struct sctp_chunk *sctp_make_new_encap_port(const struct sctp_association *asoc, + const struct sctp_chunk *chunk) +{ + struct sctp_new_encap_port_hdr nep; + struct sctp_chunk *retval; + + retval = sctp_make_abort(asoc, chunk, + sizeof(struct sctp_errhdr) + sizeof(nep)); + if (!retval) + goto nodata; + + sctp_init_cause(retval, SCTP_ERROR_NEW_ENCAP_PORT, sizeof(nep)); + nep.cur_port = SCTP_INPUT_CB(chunk->skb)->encap_port; + nep.new_port = chunk->transport->encap_port; + sctp_addto_chunk(retval, sizeof(nep), &nep); + +nodata: + return retval; +} + /* Make a HEARTBEAT chunk. */ struct sctp_chunk *sctp_make_heartbeat(const struct sctp_association *asoc, const struct sctp_transport *transport) From patchwork Mon Oct 19 12:25:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 298808 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DDD0C433DF for ; Mon, 19 Oct 2020 12:27:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 37DDF2223C for ; Mon, 19 Oct 2020 12:27:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="u8vTYeNQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727843AbgJSM1e (ORCPT ); Mon, 19 Oct 2020 08:27:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726356AbgJSM1e (ORCPT ); Mon, 19 Oct 2020 08:27:34 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2CC2C0613CE; Mon, 19 Oct 2020 05:27:33 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id a17so5244074pju.1; Mon, 19 Oct 2020 05:27:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=TLeEEWtJD5FOcaVlaaBDT3ZenGwCI3iSD6tAYB5q5Yw=; b=u8vTYeNQBzp6MEjI7LCrdEIfVm8/nLVH7xPSFobsHDcdIIblJzz/YlntYyHIv79UYg 4fa2MdZgVfNT4jN6af4cFZDgdpMNRkl0pTIwwRmouORUMKPuSry9scGMUU3WU4QUxPeG IxOBk+dGxC46wG6/9vOrK9C/L7lGNJp2A+YGZxCVnAh6j2cTJR90I68VaHtNLrWZ3bTD 3ftfLZKxyURxxP5clrmUbtvEdtImeyAavHnkdz3ZLHwWW4j0XWEN0LodnqrjNRbujYXQ 0KjAb/g5hTCYjWMkqzg5JqxWcp3Ws0YCwazWV5GW1FXpmjKD9FNyxy0Toq8SWjOPk+c+ 4Skg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=TLeEEWtJD5FOcaVlaaBDT3ZenGwCI3iSD6tAYB5q5Yw=; b=e5vMuc7HmhdVQVq8EQBuKWI5Hnvy9OL+ltm/tXaaXouqGwxhmCgD2BAu1aqNdyB/66 6OaLo7lsIrQ15weOdBoeyy5TdZmDlcr14mV7K+EudQGa1N68Kvo+QJFvx0ZU4ECmyx/n FLTMDtZ+jQ+3pZWUPgQhh9OAP9RU+CJhCZOWxAojh/hp28zGi+5N0agaE+kF7mUvcd6H Hj9+ZOiV2ejemoQ8tqkChsiaa1g1y8xExn6IAOn1u4DH13Gwn+RUCwiRBC7lSPLeRJNO zbm0PWXQMDTmXRgswuQDOVUthkepNDBLhkNVqhNruZtzuJxki6gDzCsXYcR3G+soJMB0 3vKw== X-Gm-Message-State: AOAM5326t9gBZYhiJFA+p5vpf9CeafkzTDciswhERqSknSJkUtLsfdzw jMsKiirSzn91xusn/hIDD3L8umj4i98= X-Google-Smtp-Source: ABdhPJy00OzhMj5POAloB2gUMBjk4dePdPjzC2x+emXVo9vu2aR6ZUlTrJsP2EqRv4ZI/Pza46I8YQ== X-Received: by 2002:a17:90a:cb91:: with SMTP id a17mr16514606pju.220.1603110453180; Mon, 19 Oct 2020 05:27:33 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id u65sm12013776pfc.11.2020.10.19.05.27.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Oct 2020 05:27:32 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , davem@davemloft.net, gnault@redhat.com, pabeni@redhat.com, willemdebruijn.kernel@gmail.com Subject: [PATCHv4 net-next 15/16] sctp: handle the init chunk matching an existing asoc Date: Mon, 19 Oct 2020 20:25:32 +0800 Message-Id: <81779bb5f9dbe452d91904f617d8083f1ba91a34.1603110316.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <37b49f3c6eb568d25d7e46fa3f55a1c580867bb2.1603110316.git.lucien.xin@gmail.com> References: <71b3af0fb347f27b5c3bf846dbd34485d9f80af0.1603110316.git.lucien.xin@gmail.com> <5f06ac649f4b63fc5a254812a963cada3183f136.1603110316.git.lucien.xin@gmail.com> <7a2f5792c1a428c16962fff08b7bcfedc21bd5e2.1603110316.git.lucien.xin@gmail.com> <7cfd72e42b8b1cde268ad4062c96c08a56c4b14f.1603110316.git.lucien.xin@gmail.com> <25013493737f5b488ce48c38667a077ca6573dd5.1603110316.git.lucien.xin@gmail.com> <8547ef8c7056072bdeca8f5e9eb0d7fec5cdb210.1603110316.git.lucien.xin@gmail.com> <2cac0eaff47574dbc07a4a074500f5e0300cff3e.1603110316.git.lucien.xin@gmail.com> <15f6150aa59acd248129723df647d55ea1169d85.1603110316.git.lucien.xin@gmail.com> <37b49f3c6eb568d25d7e46fa3f55a1c580867bb2.1603110316.git.lucien.xin@gmail.com> In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This is from Section 4 of draft-tuexen-tsvwg-sctp-udp-encaps-cons-03, and it requires responding with an abort chunk with an error cause when the udp source port of the received init chunk doesn't match the encap port of the transport. Signed-off-by: Xin Long --- net/sctp/sm_statefuns.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c index 8edab15..af2b704 100644 --- a/net/sctp/sm_statefuns.c +++ b/net/sctp/sm_statefuns.c @@ -87,6 +87,13 @@ static enum sctp_disposition sctp_sf_tabort_8_4_8( const union sctp_subtype type, void *arg, struct sctp_cmd_seq *commands); +static enum sctp_disposition sctp_sf_new_encap_port( + struct net *net, + const struct sctp_endpoint *ep, + const struct sctp_association *asoc, + const union sctp_subtype type, + void *arg, + struct sctp_cmd_seq *commands); static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk); static enum sctp_disposition sctp_stop_t1_and_abort( @@ -1493,6 +1500,10 @@ static enum sctp_disposition sctp_sf_do_unexpected_init( if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_init_chunk))) return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, commands); + + if (SCTP_INPUT_CB(chunk->skb)->encap_port != chunk->transport->encap_port) + return sctp_sf_new_encap_port(net, ep, asoc, type, arg, commands); + /* Grab the INIT header. */ chunk->subh.init_hdr = (struct sctp_inithdr *)chunk->skb->data; @@ -3392,6 +3403,45 @@ static enum sctp_disposition sctp_sf_tabort_8_4_8( sctp_packet_append_chunk(packet, abort); + sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(packet)); + + SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS); + + sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); + return SCTP_DISPOSITION_CONSUME; +} + +/* Handling of SCTP Packets Containing an INIT Chunk Matching an + * Existing Associations when the UDP encap port is incorrect. + * + * From Section 4 at draft-tuexen-tsvwg-sctp-udp-encaps-cons-03. + */ +static enum sctp_disposition sctp_sf_new_encap_port( + struct net *net, + const struct sctp_endpoint *ep, + const struct sctp_association *asoc, + const union sctp_subtype type, + void *arg, + struct sctp_cmd_seq *commands) +{ + struct sctp_packet *packet = NULL; + struct sctp_chunk *chunk = arg; + struct sctp_chunk *abort; + + packet = sctp_ootb_pkt_new(net, asoc, chunk); + if (!packet) + return SCTP_DISPOSITION_NOMEM; + + abort = sctp_make_new_encap_port(asoc, chunk); + if (!abort) { + sctp_ootb_pkt_free(packet); + return SCTP_DISPOSITION_NOMEM; + } + + abort->skb->sk = ep->base.sk; + + sctp_packet_append_chunk(packet, abort); + sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(packet)); From patchwork Mon Oct 19 12:25:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 288328 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08EFDC433DF for ; Mon, 19 Oct 2020 12:27:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A6F572224D for ; Mon, 19 Oct 2020 12:27:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MsOZbKiQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727260AbgJSM1n (ORCPT ); Mon, 19 Oct 2020 08:27:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726356AbgJSM1m (ORCPT ); Mon, 19 Oct 2020 08:27:42 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A61DC0613CE; Mon, 19 Oct 2020 05:27:42 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id j18so5942280pfa.0; Mon, 19 Oct 2020 05:27:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=f6xe1mBGtorQSFf7VDg7oxNiLvTJ4QXITfE6mPgILsM=; b=MsOZbKiQY72G3LtSfI8TKZ+pnzFnOYBik8I+AhTww3T97P1CVoTclASDIsBETbVSyN 7oMgaGeggIMJSru5EAWdh+DHJgmofHMvhiA3ShYTyXKN5MFG1A/kw1t5eVOE+WlmlI3h 5bOxXtlt7Uk2riiRGzARvUEzA7CA79QitVKjJjgnpAWdualCyvZBTIgIjxENyTodN3aa /h3pu7ypuGf2UpV2tdyllrwisD6OerKMEl5t1Y42bbVL4uOdlYK8SwzUN4hLL/iqrQhx l91k9MKbmNpd2CaJucQEwxg7Rju0DteiGgtgXOVPhvZsLkCrYT/GrBC41/KkpbgeHEVa pNmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=f6xe1mBGtorQSFf7VDg7oxNiLvTJ4QXITfE6mPgILsM=; b=cU5c0hv3g6AAHL2Ov7xO1qsyGIKNPzIQlllaGIHGif5fHERZujkGjkufUCNU1bhOMH iim0LaHkQBDVbbrmgxGBHoU47Vsu2P2FFkrW96gtltFZ12AQjKsPGjlpOugPjDFzk+OY quJwnef1lttAVQPVwY+qGS+o8gd65mFwx9Fgn2RPphRKhR+QUME/jW3+xWKhvzeJOdOL 4deLSicxU0hPIuEBbbw9Dljcl1rzAYMk7iaDdsuV1F5L20JrZPHgndKCYmrB0oKr8n+A iXV/RL+SwcYR4LJ4ixvyRcd25pL29XVxduAulIaSH6aVJdnf3dpbgCrF/kqByDwT6i/0 JSqw== X-Gm-Message-State: AOAM533gGBf7crbMHxcmozpR1eqQQpeg9G4O2reIZVMf2x8BittZX4Bq x+ng9r9olLuTVsHA8VDxwJhN0dF4yf8= X-Google-Smtp-Source: ABdhPJxT196bJV3BiKE8uyEiVJPwy2G/+cKFVBhSmDKd3NBMAfTmZHTxtC29PT4o3MbuAVqE98VkPw== X-Received: by 2002:a63:fb4a:: with SMTP id w10mr13682445pgj.285.1603110461616; Mon, 19 Oct 2020 05:27:41 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id b10sm10820986pgm.64.2020.10.19.05.27.40 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Oct 2020 05:27:41 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , davem@davemloft.net, gnault@redhat.com, pabeni@redhat.com, willemdebruijn.kernel@gmail.com Subject: [PATCHv4 net-next 16/16] sctp: enable udp tunneling socks Date: Mon, 19 Oct 2020 20:25:33 +0800 Message-Id: X-Mailer: git-send-email 2.1.0 In-Reply-To: <81779bb5f9dbe452d91904f617d8083f1ba91a34.1603110316.git.lucien.xin@gmail.com> References: <71b3af0fb347f27b5c3bf846dbd34485d9f80af0.1603110316.git.lucien.xin@gmail.com> <5f06ac649f4b63fc5a254812a963cada3183f136.1603110316.git.lucien.xin@gmail.com> <7a2f5792c1a428c16962fff08b7bcfedc21bd5e2.1603110316.git.lucien.xin@gmail.com> <7cfd72e42b8b1cde268ad4062c96c08a56c4b14f.1603110316.git.lucien.xin@gmail.com> <25013493737f5b488ce48c38667a077ca6573dd5.1603110316.git.lucien.xin@gmail.com> <8547ef8c7056072bdeca8f5e9eb0d7fec5cdb210.1603110316.git.lucien.xin@gmail.com> <2cac0eaff47574dbc07a4a074500f5e0300cff3e.1603110316.git.lucien.xin@gmail.com> <15f6150aa59acd248129723df647d55ea1169d85.1603110316.git.lucien.xin@gmail.com> <37b49f3c6eb568d25d7e46fa3f55a1c580867bb2.1603110316.git.lucien.xin@gmail.com> <81779bb5f9dbe452d91904f617d8083f1ba91a34.1603110316.git.lucien.xin@gmail.com> In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch is to enable udp tunneling socks by calling sctp_udp_sock_start() in sctp_ctrlsock_init(), and sctp_udp_sock_stop() in sctp_ctrlsock_exit(). Also add sysctl udp_port to allow changing the listening sock's port by users. Wit this patch, the whole sctp over udp feature can be enabled and used. v1->v2: - Also update ctl_sock udp_port in proc_sctp_do_udp_port() where netns udp_port gets changed. v2->v3: - Call htons() when setting sk udp_port from netns udp_port. v3->v4: - Not call sctp_udp_sock_start() when new_value is 0. - Add udp_port entry in ip-sysctl.rst. Signed-off-by: Xin Long --- Documentation/networking/ip-sysctl.rst | 6 ++++ net/sctp/protocol.c | 5 ++++ net/sctp/sysctl.c | 52 ++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst index 3909305..9effc45 100644 --- a/Documentation/networking/ip-sysctl.rst +++ b/Documentation/networking/ip-sysctl.rst @@ -2640,6 +2640,12 @@ addr_scope_policy - INTEGER Default: 1 +udp_port - INTEGER + The listening port for the local UDP tunneling sock. + UDP encapsulation will be disabled when it's set to 0. + + Default: 9899 + encap_port - INTEGER The default remote UDP encapsalution port. When UDP tunneling is enabled, this global value is used to set diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c index c8de327..894ab12 100644 --- a/net/sctp/protocol.c +++ b/net/sctp/protocol.c @@ -1469,6 +1469,10 @@ static int __net_init sctp_ctrlsock_init(struct net *net) if (status) pr_err("Failed to initialize the SCTP control sock\n"); + status = sctp_udp_sock_start(net); + if (status) + pr_err("Failed to initialize the SCTP UDP tunneling sock\n"); + return status; } @@ -1476,6 +1480,7 @@ static void __net_exit sctp_ctrlsock_exit(struct net *net) { /* Free the control endpoint. */ inet_ctl_sock_destroy(net->sctp.ctl_sock); + sctp_udp_sock_stop(net); } static struct pernet_operations sctp_ctrlsock_ops = { diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c index ecc1b5e..e92df77 100644 --- a/net/sctp/sysctl.c +++ b/net/sctp/sysctl.c @@ -49,6 +49,8 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write, void *buffer, size_t *lenp, loff_t *ppos); static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write, void *buffer, size_t *lenp, loff_t *ppos); +static int proc_sctp_do_udp_port(struct ctl_table *ctl, int write, void *buffer, + size_t *lenp, loff_t *ppos); static int proc_sctp_do_alpha_beta(struct ctl_table *ctl, int write, void *buffer, size_t *lenp, loff_t *ppos); static int proc_sctp_do_auth(struct ctl_table *ctl, int write, @@ -292,6 +294,15 @@ static struct ctl_table sctp_net_table[] = { .proc_handler = proc_dointvec, }, { + .procname = "udp_port", + .data = &init_net.sctp.udp_port, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_sctp_do_udp_port, + .extra1 = SYSCTL_ZERO, + .extra2 = &udp_port_max, + }, + { .procname = "encap_port", .data = &init_net.sctp.encap_port, .maxlen = sizeof(int), @@ -487,6 +498,47 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write, return ret; } +static int proc_sctp_do_udp_port(struct ctl_table *ctl, int write, + void *buffer, size_t *lenp, loff_t *ppos) +{ + struct net *net = current->nsproxy->net_ns; + unsigned int min = *(unsigned int *)ctl->extra1; + unsigned int max = *(unsigned int *)ctl->extra2; + struct ctl_table tbl; + int ret, new_value; + + memset(&tbl, 0, sizeof(struct ctl_table)); + tbl.maxlen = sizeof(unsigned int); + + if (write) + tbl.data = &new_value; + else + tbl.data = &net->sctp.udp_port; + + ret = proc_dointvec(&tbl, write, buffer, lenp, ppos); + if (write && ret == 0) { + struct sock *sk = net->sctp.ctl_sock; + + if (new_value > max || new_value < min) + return -EINVAL; + + net->sctp.udp_port = new_value; + sctp_udp_sock_stop(net); + if (new_value) { + ret = sctp_udp_sock_start(net); + if (ret) + net->sctp.udp_port = 0; + } + + /* Update the value in the control socket */ + lock_sock(sk); + sctp_sk(sk)->udp_port = htons(net->sctp.udp_port); + release_sock(sk); + } + + return ret; +} + int sctp_sysctl_net_register(struct net *net) { struct ctl_table *table;