From patchwork Thu Oct 8 09:47:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 11822537 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.8 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 98F35C43467 for ; Thu, 8 Oct 2020 09:48:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3398F2177B for ; Thu, 8 Oct 2020 09:48:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hzBJBqe4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729234AbgJHJsb (ORCPT ); Thu, 8 Oct 2020 05:48:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725849AbgJHJsb (ORCPT ); Thu, 8 Oct 2020 05:48:31 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DC23C061755; Thu, 8 Oct 2020 02:48:31 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id a200so3531786pfa.10; Thu, 08 Oct 2020 02:48:31 -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=hzBJBqe4rmJX0tiZtVjW9rIjMEM62SW041XFnCMWvj6WSsiU/+L1j0BsSgovh1wRBK D3KN39TjpNcxUfbxcufxdtxrBplBsofLC79dl2QnlJ3DzOCle1cD6jrz53RpOBpYGJMV i5yuoe/6PiouA46+XFgikEu9jC+oO5P+lggG4HKnM9vl15HEc4NPSy+dQB9XkEcbbgrx fcw8zwvO2cYiViV5Lbw/xUWn2wx/ubgNHVwtmVEtKQGbOUeHeAvUFM8dKbH+WaopNy3o nXhsP5Yq9q/tOV09v/IkePR7+qdQLwGQkw4+DVyix8exYaChqrn83UfOIb8zmSRviKvU 8NAQ== 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=kN9L2ZRZVFGIB5RVmblhVWK5YZ7TlQWZvJUzE+UlkXrgapulq/XbAkyAESC0u4cv8E JsBgDYPD0Ci8MPrgTnDkqdhFYgfY+2RrzO1NLjQhOfqr8xIbds3hBPmtmMMCTb52wivw AGvnOPvm7AdX1FScUVSVy58XEDEreoRfcLOwjoNFNfVhik+AuD6IUDle8lt8ysFT2Q7N qtrxH09o7rfYSMO1cdTppBPPzO0CzWlGqSqfoZ62wJyURKZm67W8R5wKDU6F0/Msi7LV sbdhnjzj1irMXu8/wVfR4ure2tQ3BOdyIicnb7CpLjC9xqC4SfX1T2WAQESC2RhSNySm Pemg== X-Gm-Message-State: AOAM5334hEJVSWDXDoZON8ZzbGCYl+AxjDxkvUQ+iY0fhdzsrCKznX2g xWlKa9hvX2X+0gYalZgFaYl9g5FlS9U= X-Google-Smtp-Source: ABdhPJwWJfnr7fXR6dgM6yJwKuBryT6QXeufM70v3RxqBnctun1GnaU/D/JnoYkPBoHfABHrNGnO1A== X-Received: by 2002:a63:f74a:: with SMTP id f10mr6968293pgk.263.1602150510254; Thu, 08 Oct 2020 02:48:30 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id mt2sm6284496pjb.17.2020.10.08.02.48.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Oct 2020 02:48:29 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , davem@davemloft.net Subject: [PATCHv2 net-next 01/17] udp: check udp sock encap_type in __udp_lib_err Date: Thu, 8 Oct 2020 17:47:57 +0800 Message-Id: <052acb63198c44df41c5db17f8397eeb7c8bacfe.1602150362.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 Thu Oct 8 09:47:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 11822539 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.8 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 8588EC433E7 for ; Thu, 8 Oct 2020 09:48:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0B8D52177B for ; Thu, 8 Oct 2020 09:48:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nsIlcWKu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729252AbgJHJsm (ORCPT ); Thu, 8 Oct 2020 05:48:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729206AbgJHJsj (ORCPT ); Thu, 8 Oct 2020 05:48:39 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68CB8C061755; Thu, 8 Oct 2020 02:48:39 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id f19so3526830pfj.11; Thu, 08 Oct 2020 02:48:39 -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=kh+4Akzr9Y2ohk7JE0CkOp4rDs5Jp9+QPNorc2hZCXo=; b=nsIlcWKuCkIqMcdGqOpiNJenY/pLo9RMZQ5bG2Hy+YYTQW1T17+huElkV7qtiI6wrB oe9JS+e5kOYZ2t5y5BqD15uZu89PZdJYxuf1S86rFho9JM2VXcJbdS/sVX/e/XcU5MAl olEqQp50D0qQymnmEOoNhwNiCZNwrrywyxOxhhdmFzz2upik84A9YyTP4Q3LzcOoRbqJ 4A2B/FQyEShDuxnjh/bHiiG5zomcCW1P9eDqlrka1rbPfXb2B64Y1so+rT0ErWZ2ebUZ 5qwqzQsmZFBzwBQh8Je6e3Ci/VJmhHE68VK4BKLBudJ9j4Wqq4W3/LbQ6Squcpn1ETmF kwGg== 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=kh+4Akzr9Y2ohk7JE0CkOp4rDs5Jp9+QPNorc2hZCXo=; b=meJjzrwLgAlRIFFTZZ4uEstPdoa420vc8EqrjTA/2heiHRdxgFbF6GZ93UzWD141oN M0Xw+62yBaRo1c9s3Md9JfS6GpT5FFtP4S+c2wwcQoFDHuTM2M6nBLO1jRq2MQNhlmUr 2VKG8eJKMC0PUzg8bctdyDpoG58orwZuTMJF5JEfa8PYtVhMOVHZ/PFLKLvSQzdshzuC 6mEYQozyCYqDSri2VK1LyntrBeS5rL168Xz5Yim9c56qFHjpjv5WT/yOHqvD7CnteIq3 ONRQUdDAt9ovKnc2v4E0t3PJuHesZG4GsZcZcQra9HEBTwj+5w3Nbm9p97cgm8Yajyuv u/oQ== X-Gm-Message-State: AOAM530BR/4Wk6nTlpFB4O/HtKOobgH0881yHtzu2VbtgaxOWMWytiMk KSJkM0z+cn22pQfq47u+hrlrp40VVTg= X-Google-Smtp-Source: ABdhPJyqHNpeQsVWK/Kmtvr2GSoKEebv6a/D5MloyARZ4agRBF77C8DnlQzNkNPwOqhAmuMq7KQXfw== X-Received: by 2002:a17:90a:e553:: with SMTP id ei19mr3291457pjb.136.1602150518601; Thu, 08 Oct 2020 02:48:38 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id h62sm6689123pjd.18.2020.10.08.02.48.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Oct 2020 02:48:38 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , davem@davemloft.net Subject: [PATCHv2 net-next 02/17] udp6: move the mss check after udp gso tunnel processing Date: Thu, 8 Oct 2020 17:47:58 +0800 Message-Id: X-Mailer: git-send-email 2.1.0 In-Reply-To: <052acb63198c44df41c5db17f8397eeb7c8bacfe.1602150362.git.lucien.xin@gmail.com> References: <052acb63198c44df41c5db17f8397eeb7c8bacfe.1602150362.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. While at it, also tidy the variables up. Signed-off-by: Xin Long --- net/ipv6/udp_offload.c | 154 ++++++++++++++++++++++++------------------------- 1 file changed, 76 insertions(+), 78 deletions(-) diff --git a/net/ipv6/udp_offload.c b/net/ipv6/udp_offload.c index 584157a..3c5ec8e 100644 --- a/net/ipv6/udp_offload.c +++ b/net/ipv6/udp_offload.c @@ -17,96 +17,94 @@ static struct sk_buff *udp6_ufo_fragment(struct sk_buff *skb, netdev_features_t features) { + u8 nexthdr, frag_hdr_sz = sizeof(struct frag_hdr); + unsigned int unfrag_ip6hlen, unfrag_len, mss; struct sk_buff *segs = ERR_PTR(-EINVAL); - unsigned int mss; - unsigned int unfrag_ip6hlen, unfrag_len; - struct frag_hdr *fptr; + const struct ipv6hdr *ipv6h; u8 *packet_start, *prevhdr; - u8 nexthdr; - u8 frag_hdr_sz = sizeof(struct frag_hdr); + struct frag_hdr *fptr; + int tnl_hlen, err; + struct udphdr *uh; __wsum csum; - int tnl_hlen; - int err; - mss = skb_shinfo(skb)->gso_size; - if (unlikely(skb->len <= mss)) + 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); 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); - else { - const struct ipv6hdr *ipv6h; - struct udphdr *uh; + if (!(skb_shinfo(skb)->gso_type & (SKB_GSO_UDP | SKB_GSO_UDP_L4))) + goto out; - if (!(skb_shinfo(skb)->gso_type & (SKB_GSO_UDP | SKB_GSO_UDP_L4))) - goto out; + if (!pskb_may_pull(skb, sizeof(struct udphdr))) + goto out; - if (!pskb_may_pull(skb, sizeof(struct udphdr))) - goto out; + if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4) + return __udp_gso_segment(skb, features); - if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4) - return __udp_gso_segment(skb, features); - - /* Do software UFO. Complete and fill in the UDP checksum as HW cannot - * do checksum of UDP packets sent as multiple IP fragments. - */ - - uh = udp_hdr(skb); - ipv6h = ipv6_hdr(skb); - - uh->check = 0; - csum = skb_checksum(skb, 0, skb->len, 0); - uh->check = udp_v6_check(skb->len, &ipv6h->saddr, - &ipv6h->daddr, csum); - if (uh->check == 0) - uh->check = CSUM_MANGLED_0; - - skb->ip_summed = CHECKSUM_UNNECESSARY; - - /* If there is no outer header we can fake a checksum offload - * due to the fact that we have already done the checksum in - * software prior to segmenting the frame. - */ - if (!skb->encap_hdr_csum) - features |= NETIF_F_HW_CSUM; - - /* Check if there is enough headroom to insert fragment header. */ - tnl_hlen = skb_tnl_header_len(skb); - if (skb->mac_header < (tnl_hlen + frag_hdr_sz)) { - if (gso_pskb_expand_head(skb, tnl_hlen + frag_hdr_sz)) - goto out; - } + mss = skb_shinfo(skb)->gso_size; + if (unlikely(skb->len <= mss)) + goto out; - /* Find the unfragmentable header and shift it left by frag_hdr_sz - * bytes to insert fragment header. - */ - err = ip6_find_1stfragopt(skb, &prevhdr); - if (err < 0) - return ERR_PTR(err); - unfrag_ip6hlen = err; - nexthdr = *prevhdr; - *prevhdr = NEXTHDR_FRAGMENT; - unfrag_len = (skb_network_header(skb) - skb_mac_header(skb)) + - unfrag_ip6hlen + tnl_hlen; - packet_start = (u8 *) skb->head + SKB_GSO_CB(skb)->mac_offset; - memmove(packet_start-frag_hdr_sz, packet_start, unfrag_len); - - SKB_GSO_CB(skb)->mac_offset -= frag_hdr_sz; - skb->mac_header -= frag_hdr_sz; - skb->network_header -= frag_hdr_sz; - - fptr = (struct frag_hdr *)(skb_network_header(skb) + unfrag_ip6hlen); - fptr->nexthdr = nexthdr; - fptr->reserved = 0; - fptr->identification = ipv6_proxy_select_ident(dev_net(skb->dev), skb); - - /* Fragment the skb. ipv6 header and the remaining fields of the - * fragment header are updated in ipv6_gso_segment() - */ - segs = skb_segment(skb, features); + /* Do software UFO. Complete and fill in the UDP checksum as HW cannot + * do checksum of UDP packets sent as multiple IP fragments. + */ + + uh = udp_hdr(skb); + ipv6h = ipv6_hdr(skb); + + uh->check = 0; + csum = skb_checksum(skb, 0, skb->len, 0); + uh->check = udp_v6_check(skb->len, &ipv6h->saddr, + &ipv6h->daddr, csum); + if (uh->check == 0) + uh->check = CSUM_MANGLED_0; + + skb->ip_summed = CHECKSUM_UNNECESSARY; + + /* If there is no outer header we can fake a checksum offload + * due to the fact that we have already done the checksum in + * software prior to segmenting the frame. + */ + if (!skb->encap_hdr_csum) + features |= NETIF_F_HW_CSUM; + + /* Check if there is enough headroom to insert fragment header. */ + tnl_hlen = skb_tnl_header_len(skb); + if (skb->mac_header < (tnl_hlen + frag_hdr_sz)) { + if (gso_pskb_expand_head(skb, tnl_hlen + frag_hdr_sz)) + goto out; } + /* Find the unfragmentable header and shift it left by frag_hdr_sz + * bytes to insert fragment header. + */ + err = ip6_find_1stfragopt(skb, &prevhdr); + if (err < 0) + return ERR_PTR(err); + unfrag_ip6hlen = err; + nexthdr = *prevhdr; + *prevhdr = NEXTHDR_FRAGMENT; + unfrag_len = (skb_network_header(skb) - skb_mac_header(skb)) + + unfrag_ip6hlen + tnl_hlen; + packet_start = (u8 *)skb->head + SKB_GSO_CB(skb)->mac_offset; + memmove(packet_start - frag_hdr_sz, packet_start, unfrag_len); + + SKB_GSO_CB(skb)->mac_offset -= frag_hdr_sz; + skb->mac_header -= frag_hdr_sz; + skb->network_header -= frag_hdr_sz; + + fptr = (struct frag_hdr *)(skb_network_header(skb) + unfrag_ip6hlen); + fptr->nexthdr = nexthdr; + fptr->reserved = 0; + fptr->identification = ipv6_proxy_select_ident(dev_net(skb->dev), skb); + + /* Fragment the skb. ipv6 header and the remaining fields of the + * fragment header are updated in ipv6_gso_segment() + */ + segs = skb_segment(skb, features); + out: return segs; } From patchwork Thu Oct 8 09:47:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 11822541 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.8 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,URIBL_BLOCKED,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 00E98C43467 for ; Thu, 8 Oct 2020 09:48:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9668B2177B for ; Thu, 8 Oct 2020 09:48:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AYyZcJf1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729259AbgJHJss (ORCPT ); Thu, 8 Oct 2020 05:48:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729253AbgJHJsr (ORCPT ); Thu, 8 Oct 2020 05:48:47 -0400 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B802CC061755; Thu, 8 Oct 2020 02:48:47 -0700 (PDT) Received: by mail-pg1-x52a.google.com with SMTP id r21so471320pgj.5; Thu, 08 Oct 2020 02:48:47 -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=BDJ5qrxqVkEtVGtt8cqpeRGleZ89sZlJyVe+mDuXBNQ=; b=AYyZcJf1NDVnQNjulcZ25HYIi9gGmt70b2+h/Iyth+lp4EXmFHKLOTxtiAK30+j6zf UN6ws5x+04NBbp9g/nZ1hhEYBMB7y7Mk7MCm3506pCVHs/PWx+qN0JlyB9lbdUEQ/ejy Vw1VdIgSWR5CMaSlgGxs7Jnr0w4zlgXuWRGTR0lnONpAuM8DOAPfqMzKaCgZl5an/2a2 LVmpvG0jcL39Wa59DJndfp/pbUsfYbrVqdpv2HxcMHQKmMvk+SSlo6x6gUfLU3mvd2Z0 i1i14/73TTYECnbemJV/LfH1/aSZgV4moUMWxfiR6wndu4RZY0cqhQrrr4XWkZIjFylC v6aA== 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=BDJ5qrxqVkEtVGtt8cqpeRGleZ89sZlJyVe+mDuXBNQ=; b=Tt2+HJNVNg2BLeF9jQp4E5MCBvaciH/SoOtaUmGw29hkZAvd9JyaLukM5/hSUh1adg oIDBK0TA0FuCmkLcqeFKs8LR7MwOYIDlz6gC6W1a0Cy70J21U4+hbSx1F0IISbBXdYgB wRs2j8EivD5J9iIqjPxT2XxTQw5YPdkkJKXfKSFSc2d7+wtxOg3mxPaEOtT8kjYw+VDL 4cE122ZND3THN3ecQq9sCOTxwgOX6xihZ5RsWt39l1SoOlJw34ltiiLJsackofrbZTpT hbAjhX8IJpBDV9XJUnV36ljseAfAgUzdGV8Nxdh9ryI91ehPCjDhcz22TrxMENzXXdaK g8lA== X-Gm-Message-State: AOAM530GDwYzgg0NmZEXgK7RA3zm+0ZlPh5BAjWPe7VUv/NfkV5wvYeq cBomuedMGJZHQpRYRRe3n+AF94i8wkE= X-Google-Smtp-Source: ABdhPJyPRVVWQMCY6LSVJPfeVQ2yAj8vaHIwaqp+yY+Ys6OQoM2sxRkofrVT4hwWGFrTFgdcjuYw+A== X-Received: by 2002:a05:6a00:23cc:b029:142:2501:35cf with SMTP id g12-20020a056a0023ccb0290142250135cfmr6950258pfc.47.1602150526918; Thu, 08 Oct 2020 02:48:46 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id v10sm6104307pjf.34.2020.10.08.02.48.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Oct 2020 02:48:46 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , davem@davemloft.net Subject: [PATCHv2 net-next 03/17] udp: do checksum properly in skb_udp_tunnel_segment Date: Thu, 8 Oct 2020 17:47:59 +0800 Message-Id: <483d9eec159b22172fe04dacd58d7f88dfc2f301.1602150362.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: References: <052acb63198c44df41c5db17f8397eeb7c8bacfe.1602150362.git.lucien.xin@gmail.com> In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch fixes two things: When skb->ip_summed == CHECKSUM_PARTIAL, skb_checksum_help() should be called do the checksum, instead of gso_make_checksum(), which is used to do the checksum for current proto after calling skb_segment(), not after the inner proto's gso_segment(). When offload_csum is disabled, the hardware will not do the checksum for the current proto, udp. So instead of calling gso_make_checksum(), it should calculate checksum for udp itself. Cc: Tom Herbert Signed-off-by: Xin Long --- net/ipv4/udp_offload.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c index e67a66f..c0b010b 100644 --- a/net/ipv4/udp_offload.c +++ b/net/ipv4/udp_offload.c @@ -131,14 +131,15 @@ static struct sk_buff *__skb_udp_tunnel_segment(struct sk_buff *skb, uh->check = ~csum_fold(csum_add(partial, (__force __wsum)htonl(len))); - if (skb->encapsulation || !offload_csum) { - uh->check = gso_make_checksum(skb, ~uh->check); - if (uh->check == 0) - uh->check = CSUM_MANGLED_0; - } else { + if (skb->encapsulation) + skb_checksum_help(skb); + + if (offload_csum) { skb->ip_summed = CHECKSUM_PARTIAL; skb->csum_start = skb_transport_header(skb) - skb->head; skb->csum_offset = offsetof(struct udphdr, check); + } else { + uh->check = csum_fold(skb_checksum(skb, udp_offset, len, 0)); } } while ((skb = skb->next)); out: From patchwork Thu Oct 8 09:48:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 11822543 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.8 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,URIBL_BLOCKED,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 27DCAC433E7 for ; Thu, 8 Oct 2020 09:48:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BF3AA20725 for ; Thu, 8 Oct 2020 09:48:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BCn2JiAF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729266AbgJHJsy (ORCPT ); Thu, 8 Oct 2020 05:48:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729206AbgJHJsx (ORCPT ); Thu, 8 Oct 2020 05:48:53 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E788C061755; Thu, 8 Oct 2020 02:48:53 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id a200so3532524pfa.10; Thu, 08 Oct 2020 02:48:53 -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=OIF6t/bkwPTd2fAU92sAxQjFTr7embsKbRfu4pfoVNA=; b=BCn2JiAF7Th8ob+cehe5PeoWn45+qgdfVzWriehIM37Pjw1qIpHmQ77MV3gEx9o9zG DJPClkg8hRekeSRhByjVu4/Olo7kYHf16lgDaZ1s3daBXRecMriAmDS2Wk7p00pYjluL WWAoyKHQwKcrTAxmUbwZ6Xzaq+U+hQvSrCGlq2gPZmJlC+0r4RZVDynShpFnlnaQgLHL 3gHPxjSaCmdFXLIfUYvs253vJhytKbUJNpbK5VlFpB9A7nIbTxXEdEPxVrsSncJ7MmoV Z2ydiPanuMpDx0xtTPLOowCwCfc1knZ4R5fkSMdbExhVFgLCVANuq8XIXDuIqofTMmik +gxA== 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=OIF6t/bkwPTd2fAU92sAxQjFTr7embsKbRfu4pfoVNA=; b=RxyEly7gyFIA0pch8bmTQ6J7Z6T4/twr4qwlhZW8GHkqSSiFwIozLbW18xmht7XN4Y 5OazcNxHdVN4Jtu9LzpVMtz7Tkuu1spvt61ckEiOoTwsukkWk6YO09lsOYsOjWznaxPR Y/M8vBntWk0Q0cCgxwf7x08Im7HBLoKrOqhn2ZgGkjBPhPik8cdmvRkbxl8ov1yLDODK OrbQn7ACETf+BDPKoWyI6csHdWM0Zw5lKOeQgnoWkjqKJ5SKBe1/INMbIdTaQopVO2pB X11LCNGhiS74wxe1qJlHC1epMboyLykSyrmr/T/rGlQuUNBbyONmyZ9DeDwmU+1Y0rBh eGpg== X-Gm-Message-State: AOAM530Uq76b8tMpFrSaIMxd39VdPKlku4H4CzPEAv/Z2t0MR2X2qTGv Esx5FV89goJMHAVpFTF7UBsmwODKm6w= X-Google-Smtp-Source: ABdhPJwt2cXJX1tqOTnQffkOggjjUe+wGndIxTdoz3P7nhTmUKlGXcCN5o+1Hs3LVHtBtwbT25u/vQ== X-Received: by 2002:a17:90b:384c:: with SMTP id nl12mr7384081pjb.166.1602150532943; Thu, 08 Oct 2020 02:48:52 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id h9sm6170652pfh.213.2020.10.08.02.48.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Oct 2020 02:48:52 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , davem@davemloft.net Subject: [PATCHv2 net-next 04/17] udp: support sctp over udp in skb_udp_tunnel_segment Date: Thu, 8 Oct 2020 17:48:00 +0800 Message-Id: <17cab00046ea7fe36c8383925a4fc3fbc028c511.1602150362.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <483d9eec159b22172fe04dacd58d7f88dfc2f301.1602150362.git.lucien.xin@gmail.com> References: <052acb63198c44df41c5db17f8397eeb7c8bacfe.1602150362.git.lucien.xin@gmail.com> <483d9eec159b22172fe04dacd58d7f88dfc2f301.1602150362.git.lucien.xin@gmail.com> In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org To call sctp_gso_segment() properly in skb_udp_tunnel_segment() for sctp over udp packets, we need to set transport_header to sctp header. When skb->ip_summed == CHECKSUM_PARTIAL, skb_crc32c_csum_help() should be called for the inner sctp packet. Cc: Tom Herbert Signed-off-by: Xin Long --- net/ipv4/udp_offload.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c index c0b010b..a484405 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; @@ -131,8 +132,12 @@ static struct sk_buff *__skb_udp_tunnel_segment(struct sk_buff *skb, uh->check = ~csum_fold(csum_add(partial, (__force __wsum)htonl(len))); - if (skb->encapsulation) - skb_checksum_help(skb); + if (skb->encapsulation) { + if (skb->csum_not_inet) + skb_crc32c_csum_help(skb); + else + skb_checksum_help(skb); + } if (offload_csum) { skb->ip_summed = CHECKSUM_PARTIAL; From patchwork Thu Oct 8 09:48:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 11822545 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.8 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 BAB7CC43467 for ; Thu, 8 Oct 2020 09:49:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4C5D921531 for ; Thu, 8 Oct 2020 09:49:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OJKPmxGS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729273AbgJHJtC (ORCPT ); Thu, 8 Oct 2020 05:49:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729206AbgJHJtC (ORCPT ); Thu, 8 Oct 2020 05:49:02 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CDE7C061755; Thu, 8 Oct 2020 02:49:02 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id m15so2497158pls.8; Thu, 08 Oct 2020 02:49:02 -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=/bc9STVKDhynKYEAx64TcAnGKQ43YQycLHOwGW1mz3I=; b=OJKPmxGSJrR3Q0/4HbUrpisiuBR6bcvh7nDqlIACh+Pdet4KNUXNrETkTvtL/YHtaQ tPCsEkZxJQzjRej0p2S19zvXLBhB0U8+ljEoyLFjui6SJgJDbnOa/KT/oTwk45dJA+Vs SJSEW6HwHIJZ9BD9z6PWjakSzfX/F8QOOXzqLWauJw//3ABwiWVvtvmyiexAjZuzZNhj QmDwiMv5SYR9JqShvowlgmxVHpRyiznXABlLhFJFS7QcAdMp+uK0ca4Uk7ktSSt5ccMM G87RveWpkWV/jZ71InAbXVItg2R71SVDrHHtLUofSrH68cs09p2ngWzF+xZWMS2AMNcd wD3A== 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=/bc9STVKDhynKYEAx64TcAnGKQ43YQycLHOwGW1mz3I=; b=EP3rpXtMHVgRhxIC3AiyGtayK8IxUHcNJjZ0tDN2DlNxjMglRIyGunaOQa5hnElNYC qqXHtFlFXORAba3lpOmOj9AS+6BBwIUhxke36exoj1nPvWpEFf0ab38FDtvPYiF1IH9G UpzFX83iODDfy+pX/d0eBsxYQVolgjn2QzS69yt4dZQWgbebIEGrbKxQNn/Q0g/U1L6n YPRoiXC4vHpAbTnkgsuLeY1hyn8XcIVgeizqV3vK/4lfcq/0fk+rsKwop0yBr9VdvRM3 iyEef+hzIApbTbYHmFHf6W13OeGnCxSqMrkomVC/yzx4vOw5/Cd0SNzx2CkjBF2HKgtx sVPg== X-Gm-Message-State: AOAM5327tG/t4zROL7gQ6niDKxVNPHNYh86FBE56kJhBjUZ46fEhbN3G /flq81EizSvBio4rhZbaOeCauA647PM= X-Google-Smtp-Source: ABdhPJzSkLOVJXYVI+QHaLIhz856dmSxd7+jt4jP8qFnReJrC98A9YtAr2AZEx/UGUNiGJkI40qsRQ== X-Received: by 2002:a17:902:7d97:b029:d2:8046:f593 with SMTP id a23-20020a1709027d97b02900d28046f593mr6819456plm.43.1602150541285; Thu, 08 Oct 2020 02:49:01 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id n5sm6654275pfq.46.2020.10.08.02.49.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Oct 2020 02:49:00 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , davem@davemloft.net Subject: [PATCHv2 net-next 05/17] sctp: create udp4 sock and add its encap_rcv Date: Thu, 8 Oct 2020 17:48:01 +0800 Message-Id: <6f5a15bba0e2b5d3da6be90fd222c5ee41691d32.1602150362.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <17cab00046ea7fe36c8383925a4fc3fbc028c511.1602150362.git.lucien.xin@gmail.com> References: <052acb63198c44df41c5db17f8397eeb7c8bacfe.1602150362.git.lucien.xin@gmail.com> <483d9eec159b22172fe04dacd58d7f88dfc2f301.1602150362.git.lucien.xin@gmail.com> <17cab00046ea7fe36c8383925a4fc3fbc028c511.1602150362.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. Signed-off-by: Xin Long Reported-by: kernel test robot --- include/net/netns/sctp.h | 5 +++++ include/net/sctp/constants.h | 2 ++ include/net/sctp/sctp.h | 2 ++ net/sctp/protocol.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+) diff --git a/include/net/netns/sctp.h b/include/net/netns/sctp.h index d8d02e4..3d10bef 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..b583166 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/protocol.c b/net/sctp/protocol.c index 2583323..2b7a3e1 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 Thu Oct 8 09:48:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 11822547 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.8 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 AA56FC433E7 for ; Thu, 8 Oct 2020 09:49:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 521512177B for ; Thu, 8 Oct 2020 09:49:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Mh2n3o6T" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729279AbgJHJtK (ORCPT ); Thu, 8 Oct 2020 05:49:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729206AbgJHJtK (ORCPT ); Thu, 8 Oct 2020 05:49:10 -0400 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D5E6C061755; Thu, 8 Oct 2020 02:49:10 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id u24so3853447pgi.1; Thu, 08 Oct 2020 02:49:10 -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=m/TiQ2lE3m4wHvHFT6+tGQzF2YHGDHHA/t6tWuUFplI=; b=Mh2n3o6TWlMlmqxZvhfoaJ3SUM9HaSq59IXLN3qfTHtUB/SY8TbzX+uriDwYLr7Ryq Q3DJd8XEoAV8nQ3VllTImgs6k305bXg9g4TQWmLz6QHruzLgzOpgg9ocuwH4SLKXPEJ1 usP3pRai+fJ0GtpMecN/7cJS1n5gTTDg3fjsMkrpnpkJA01+3U5FM8TO4lk/CITBjYrW IT7ss+h6xSNnUrj7mrXruMPgy3VTrfq0V9A2lmaFK9MKcgRhfZT5KFMMV/x9HFb26HlQ X6Q3A9Cuwd3mPZd14zjbBy96G7bFM8dHcuKZSK/XkZa7+Mg/++kouPaYZwgqEeVsknRn rl2A== 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=m/TiQ2lE3m4wHvHFT6+tGQzF2YHGDHHA/t6tWuUFplI=; b=U/eAWJNVSP7gg6YZwqlXtB5A8S5k4FsNg7LkTA7WmjHth48uaITT2qbRRCVz+QZVun ODpGpuxoPQNzt/2QTnQ5sR3MKgDbMgPpAm09tgDTB6uZdTYjXInQfK1SUD9BvxEYaqDi JMOTwqZmgyC1nBj8lc2bVoZeUGv2kZgiryck95lROxBjRQTFMLW8Ie0XKsp2OyhNAADX MuZfN+L7eO0ifuVTH+VV7Golau7rp+fZeelRo5p9w5QkfWyz3/VAR0lV/88q8yYD1T5j 9SFjK4VIj9gdx3OQpOHOs2Gq0pqgOdUXpqd2mLCFR3x8PlLaWhFRwJZjWV3slMVhQhMd SMzg== X-Gm-Message-State: AOAM530rIOR76T+7mYS6fqXnu/cM6RqiHUVFX9jEJjuSlP1q80OUm/mJ a/tRvzFGsOEgF6JA2pTyLLRRWZ+zneU= X-Google-Smtp-Source: ABdhPJwJ13I10zdzYVUNMDXLWstsg38SN77/XO3KdzzX+O7oqn8LGzuImkHHhFGvYAevB/yIAgDO7g== X-Received: by 2002:a17:90a:46cd:: with SMTP id x13mr7389958pjg.101.1602150549827; Thu, 08 Oct 2020 02:49:09 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id in6sm5365987pjb.42.2020.10.08.02.49.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Oct 2020 02:49:09 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , davem@davemloft.net Subject: [PATCHv2 net-next 06/17] sctp: create udp6 sock and set its encap_rcv Date: Thu, 8 Oct 2020 17:48:02 +0800 Message-Id: X-Mailer: git-send-email 2.1.0 In-Reply-To: <6f5a15bba0e2b5d3da6be90fd222c5ee41691d32.1602150362.git.lucien.xin@gmail.com> References: <052acb63198c44df41c5db17f8397eeb7c8bacfe.1602150362.git.lucien.xin@gmail.com> <483d9eec159b22172fe04dacd58d7f88dfc2f301.1602150362.git.lucien.xin@gmail.com> <17cab00046ea7fe36c8383925a4fc3fbc028c511.1602150362.git.lucien.xin@gmail.com> <6f5a15bba0e2b5d3da6be90fd222c5ee41691d32.1602150362.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 Reported-by: kernel test robot --- 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 3d10bef..f622945 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 2b7a3e1..49b5d75 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 Thu Oct 8 09:48:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 11822549 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.8 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 314CBC433E7 for ; Thu, 8 Oct 2020 09:49:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C52162177B for ; Thu, 8 Oct 2020 09:49:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="utkY8ial" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729284AbgJHJtT (ORCPT ); Thu, 8 Oct 2020 05:49:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725887AbgJHJtT (ORCPT ); Thu, 8 Oct 2020 05:49:19 -0400 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E86D8C061755; Thu, 8 Oct 2020 02:49:18 -0700 (PDT) Received: by mail-pg1-x529.google.com with SMTP id i2so3827767pgh.7; Thu, 08 Oct 2020 02:49:18 -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=mddk0RPj5RANjKGN0DxBgjaZKh24JdfVj6LOwAP3f/8=; b=utkY8ialYs+Jg+Y4IAjQh1kf4rgs2Qt95jgn9oNj64cnRBIu/YHEJHUSjXBoUuD0v1 WDNvQwrELZ+1v8y8lp5g3ZrIVVwZyAEGnXF4GfebKwGsuVR76OUdnck4AZ55Gw8TQ+uE Z0aj9K1IuQnH0RMIg1W8PsXZkDGiVftSIf8R1aIj2j6pvjf/ZXssxrvJm5e1CxsaKqu/ b0chr3yHf4eVGQxLQEzsFnySqb9hq6JSDdwTJDo6CP/jTVktS+RIREjfnmcZpLaSimpG H01CgMA7gpltencYuGdfnKOba46I4ZK57xNgZDAqqs0//gydH8edcQaRmXhgBOU9FUns 7oiw== 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=mddk0RPj5RANjKGN0DxBgjaZKh24JdfVj6LOwAP3f/8=; b=XUTpwAynxuvfgL8+BJha8FMotHGc4X2tYAeiSvcvlXZ5pYFZzFppkeV0G4XboziSAu xWZT7ttTWzsxE24WqrL3t+UFGnSiZhB3OfGEhpXH0dQ78A/avhh9UPsjV1gtiuBYGULF oZ3D8z1F9WEmEaowF3kPY0zIUewiHKSiYdu9wzGibQwF/97AbfaPm/w9fgwf/pyGSLGB pzMcOoBUyiuoZgWlKaKiayreTvv5qxZr9AO3lP5jOrjN8hPgR9mpX3Irxx4vIgh3/vun mPhfj3ZqxRfq40uSuz4+bIAbbEaEg5DZEpfBISp3cVa0IO2fypu7NwiM5i/TwUrzYE60 tAjg== X-Gm-Message-State: AOAM530YLIRk1u9RuYrjkuZK/QWUZkrLvKZZLDqtwWyfP9ruFjZEMxtg laAsKakHGywoB/bKNAVbcJNWlQoor10= X-Google-Smtp-Source: ABdhPJxeIADFgemI74gkbG0I1tnN8WXSvrSkVVka0KyOiqx03LiVL94gPml1pQGX9QoJzqBvAI5Fsg== X-Received: by 2002:a17:90a:804a:: with SMTP id e10mr7151805pjw.218.1602150558158; Thu, 08 Oct 2020 02:49:18 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id 206sm6480605pgh.26.2020.10.08.02.49.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Oct 2020 02:49:17 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , davem@davemloft.net Subject: [PATCHv2 net-next 07/17] sctp: add encap_err_lookup for udp encap socks Date: Thu, 8 Oct 2020 17:48:03 +0800 Message-Id: X-Mailer: git-send-email 2.1.0 In-Reply-To: References: <052acb63198c44df41c5db17f8397eeb7c8bacfe.1602150362.git.lucien.xin@gmail.com> <483d9eec159b22172fe04dacd58d7f88dfc2f301.1602150362.git.lucien.xin@gmail.com> <17cab00046ea7fe36c8383925a4fc3fbc028c511.1602150362.git.lucien.xin@gmail.com> <6f5a15bba0e2b5d3da6be90fd222c5ee41691d32.1602150362.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 49b5d75..dd2d9c4 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 Thu Oct 8 09:48:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 11822551 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.8 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 EDEF2C433E7 for ; Thu, 8 Oct 2020 09:49:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 90FCB21531 for ; Thu, 8 Oct 2020 09:49:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="q7e+CUI8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729290AbgJHJt1 (ORCPT ); Thu, 8 Oct 2020 05:49:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725887AbgJHJt1 (ORCPT ); Thu, 8 Oct 2020 05:49:27 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40088C061755; Thu, 8 Oct 2020 02:49:27 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id n14so3546589pff.6; Thu, 08 Oct 2020 02:49:27 -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=0NQ6rBAGodZmng5U9FvOVx+JoVKAYom7BvJGxpJCao4=; b=q7e+CUI8PVJmdmYvGjAVPhm7gM4bNZr/oW05qNIp+l6JBzlg6gf70tSR1Yd73vtyL0 FrTNUgd7Jd5z12xBTyYDwYVOFeP1b8KERz0pseA1QrPsvAAm0FV3hnLF2d/hXulU4v3u kZxX2UnetqUH1F+n5WRbFT/o4qdmC6R+igilbbW0FCc6Yb7bDWQxBx38SEsy8xvtUPGS jDneFavvOZNfcV+6YaokafMXXMjGshZ43hjn6nk0bzO0cyBDD1HVX+wgjXvsxGQdN7Q3 VoscsrHIjYkC2FGtEP5WF+oq9MvNun89HyfDfSXMKD/s0bpHgCfGK+8MJC4LKVlTq0eF OgTw== 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=0NQ6rBAGodZmng5U9FvOVx+JoVKAYom7BvJGxpJCao4=; b=MAkMWuudBX1IGq/RpuZkwLO1IYDgg+aHqay+QKNqy3JmRjle5iL1oFAEXD78+s2aYy 3c3irqotNM35Cvp1R16xpmFrJUe8CiVRC1EEveQwBSeKaX2iSgSXJtacHFCaSVQaoFhh SE0EpacgMXmsthhq04LodsMx/hlc2vwfZ3prqTNo8B7cdzrF1pIecBs5zaxWozXHSqDL mksIUt7C5NN30yXLsZ5lV+iPuvz0PnebdZ83VMp1P0JXMR8eNCV9gyHUWxDWBvVeNAZH qiVy9Z1GHWhMnZj/YTu6jx4dWmxirjwK8GduxjwkhJh4mt8GsBfIrZqD9OMQmHHMCJ2k sCdw== X-Gm-Message-State: AOAM531kxIkUM9QiRRgk9MjMxImUuNDyn4LifraD5Xu61TIycOBBDqvO cfOXKEYGFJLozPgb9sNQ1ZMAusSpICM= X-Google-Smtp-Source: ABdhPJxIdUqvHkxJcTC76YlOyMv8SjfdrXmZZRCLV8XMLE4YYw51veNpWhJb2Oc2OMG0IOCZrPsyyQ== X-Received: by 2002:a17:90a:109:: with SMTP id b9mr7510171pjb.35.1602150566514; Thu, 08 Oct 2020 02:49:26 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id i17sm6265574pfa.2.2020.10.08.02.49.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Oct 2020 02:49:25 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , davem@davemloft.net Subject: [PATCHv2 net-next 08/17] sctp: add encap_port for netns sock asoc and transport Date: Thu, 8 Oct 2020 17:48:04 +0800 Message-Id: X-Mailer: git-send-email 2.1.0 In-Reply-To: References: <052acb63198c44df41c5db17f8397eeb7c8bacfe.1602150362.git.lucien.xin@gmail.com> <483d9eec159b22172fe04dacd58d7f88dfc2f301.1602150362.git.lucien.xin@gmail.com> <17cab00046ea7fe36c8383925a4fc3fbc028c511.1602150362.git.lucien.xin@gmail.com> <6f5a15bba0e2b5d3da6be90fd222c5ee41691d32.1602150362.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. Signed-off-by: Xin Long --- 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 ++++++++++ 6 files changed, 26 insertions(+) diff --git a/include/net/netns/sctp.h b/include/net/netns/sctp.h index f622945..6af7a39 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 dd2d9c4..5b74187 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 Thu Oct 8 09:48:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 11822553 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.8 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 DCCD1C43467 for ; Thu, 8 Oct 2020 09:49:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7D2212177B for ; Thu, 8 Oct 2020 09:49:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JGaVGwfY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729296AbgJHJte (ORCPT ); Thu, 8 Oct 2020 05:49:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725887AbgJHJtd (ORCPT ); Thu, 8 Oct 2020 05:49:33 -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 7DDD7C061755; Thu, 8 Oct 2020 02:49:33 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id g10so3542581pfc.8; Thu, 08 Oct 2020 02:49: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=dkOFZBoJM3WZhm8quR7jGzshY08u4kbKxUpCXeWgEjU=; b=JGaVGwfY9ZufjhBI+7CYySsz1p4iTqgzg0+IoUfDos4QrmIfAS+Bj5BNj+jF/oICbW wmRbyzhgmcD3POkwhcnKL6XhDpj104alFWN+NHtzsWghkNcF9s+MytK4UFGb65jdymBB q1V6mycTusgSlOGqC6bEuxso8x9sl+atol11ddiiOl47tZNnBQFjPC6ZcxhfPbRjqlH3 MmdewijkcBWG2WiRzvkJiinHiOQl79nIjDlH3dc/kjBuW/M+ISNwQRhWpXAPqN2mbtQq I/ODEdE+0qQ1yCdrRQNuNjlJokroyb+nS2LNokQgtUkOO5oiywtFuxDJQMoQI2bI6tzZ 8hIg== 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=dkOFZBoJM3WZhm8quR7jGzshY08u4kbKxUpCXeWgEjU=; b=SZf6/TtaqMLAx2b4H5+EU3huHMn59dqwUeGG54uuLEJQ2GEs3261gbrwE7vnBx2WjC /bWvvO6t1yxQn8KPDSDLS7xW37AsAfAPbj/Ofk3GviyKIqlihjiL3aKYdt5OWvwoOqK8 WllMB72lPnbDoekVuhraSCsYgpbHgnmYpGjs4NrUhj4/YLOLw4EJtemJj5bzn9M1ow+c xiyGv4YLMnXNQHJ8T+pXBDazA0cFOYEqSrJYEuZykVLF4t63Lt0r3NHtYMHYNvXRb0/l DzFyx496ANJGBNJUbh7z6+fWiMBn/9w3cB9y6mZkQpbesDiVTFb4mrjkOmHyE0ABEpoM xzKg== X-Gm-Message-State: AOAM533VEGFTaFAySfXt3Ismm34WODCsIohMtPHyDCm5Rd+YESeN2NHb c7Plnm7SFOWS4TJW4EYWABz5dI1AMUM= X-Google-Smtp-Source: ABdhPJzYv8A3CA4crJ0WzBxYgqWuFe1Ye4rvMg794t6hlBz0Zyokb0gtgjKg7EYayE4RUzcBo6WpKA== X-Received: by 2002:a17:90b:3841:: with SMTP id nl1mr6802659pjb.99.1602150572749; Thu, 08 Oct 2020 02:49:32 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id m9sm6671011pgr.23.2020.10.08.02.49.31 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Oct 2020 02:49: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 Subject: [PATCHv2 net-next 09/17] sctp: add SCTP_REMOTE_UDP_ENCAPS_PORT sockopt Date: Thu, 8 Oct 2020 17:48:05 +0800 Message-Id: X-Mailer: git-send-email 2.1.0 In-Reply-To: References: <052acb63198c44df41c5db17f8397eeb7c8bacfe.1602150362.git.lucien.xin@gmail.com> <483d9eec159b22172fe04dacd58d7f88dfc2f301.1602150362.git.lucien.xin@gmail.com> <17cab00046ea7fe36c8383925a4fc3fbc028c511.1602150362.git.lucien.xin@gmail.com> <6f5a15bba0e2b5d3da6be90fd222c5ee41691d32.1602150362.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. Signed-off-by: Xin Long Reported-by: kernel test robot --- include/uapi/linux/sctp.h | 7 +++ net/sctp/socket.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 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..c9e86f5 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -4417,6 +4417,53 @@ 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; + + 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. + */ + 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->sue_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 to each + * transport. + */ + if (asoc) { + list_for_each_entry(t, &asoc->peer.transport_addr_list, + transports) + t->encap_port = encap->sue_port; + + return 0; + } + + sctp_sk(sk)->encap_port = encap->sue_port; + return 0; +} + /* API 6.2 setsockopt(), getsockopt() * * Applications use setsockopt() and getsockopt() to set or retrieve @@ -4636,6 +4683,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 +7841,63 @@ 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; + + 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.sue_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.sue_port = asoc->encap_port; + goto out; + } + + encap.sue_port = sctp_sk(sk)->encap_port; + +out: + 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 +8118,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 Thu Oct 8 09:48:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 11822555 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.8 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 ADECEC43467 for ; Thu, 8 Oct 2020 09:49:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5111F20725 for ; Thu, 8 Oct 2020 09:49:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="f2+h7L6z" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729309AbgJHJtn (ORCPT ); Thu, 8 Oct 2020 05:49:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725887AbgJHJtm (ORCPT ); Thu, 8 Oct 2020 05:49:42 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C3C0C061755; Thu, 8 Oct 2020 02:49:42 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id k8so3556418pfk.2; Thu, 08 Oct 2020 02:49: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=iNzHGEAnbQnBSq+cqEMlnX9SeC26Mbv1uc1rY7stx/g=; b=f2+h7L6z+QD8DwKOSIPaAsmej/MbXdTQM1WhaGQyYNSWT7OBYd542FRYBIjBqO0R1G //I/l4tXM+o/2fXAuqC+jSo1UJay7YRit9ns2Btx+c8XrvDmkDH7UrdY2ahOSngvkC8p lj1/BjHBsJztOstvWZpG+a9Ln/zFJr335CyI6bsuHBnQjkAqBoAC8U95Wo6DVHDx/NVo Fpu6LMPjCX354ze4+iy1pD4mnm5RfWuX8OAdqyL1U+HBVmy6SuCBgmLbSLH+ZeUPQeBE j6/FClmQmusFSCS4UNdTFOrz0KBE/JfebgDZLAnBUplbp+NbYkR77QEVJusc+ZDuMkJM sKEQ== 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=iNzHGEAnbQnBSq+cqEMlnX9SeC26Mbv1uc1rY7stx/g=; b=kBzD4MzUrDfOXaLAZzOmTSNKMpqwccI6cT4AXBrHAjTHyv0oRFA9ceYRVni3JLk9dP V8zKuKdn9QpepUIuHZruF7WaHInNNhoHNZ6QfwZBasE1bgj70MMuOA40dynmCNXO4luK XfhdOjBoaJz68B9wLvKkG9wBYXnfEB11de6nivOCoLm9V4nehVQIzYU2q1/Y+JiyLyvf Hh1Q7whc9jpXLG8CykUS6u9fLgrXNnjwJVYkucYZK05+2kolzGv6r/69glUn90P9Mbis bRCq3TGaqzbFzcc8KI4wfx8fJ7aaXcJyYM/ZyylCtayK5uCHTj/WAqu2tGf99TdHa4N/ vy8A== X-Gm-Message-State: AOAM530jaNmZlCU/fUVLYA0JJpaFKRKmN7blWqH02+bGbHZHtvUgyAE8 siA4sV0XL37/qxaTgfjVt9bywXnSzCk= X-Google-Smtp-Source: ABdhPJyTDOXvLh/vXDU6awwUSXXXJxH+OtylhLhijgToPJbDRJpCjr3/tJ/IYdEsmgeWInHS+Me/fg== X-Received: by 2002:a05:6a00:2bc:b029:155:5945:2eb2 with SMTP id q28-20020a056a0002bcb029015559452eb2mr1562233pfs.55.1602150581212; Thu, 08 Oct 2020 02:49:41 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id p4sm3074853pjk.8.2020.10.08.02.49.40 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Oct 2020 02:49:40 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , davem@davemloft.net Subject: [PATCHv2 net-next 10/17] sctp: allow changing transport encap_port by peer packets Date: Thu, 8 Oct 2020 17:48:06 +0800 Message-Id: <92d28810a72dee9d0d49e7433b65027cb52de191.1602150362.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: References: <052acb63198c44df41c5db17f8397eeb7c8bacfe.1602150362.git.lucien.xin@gmail.com> <483d9eec159b22172fe04dacd58d7f88dfc2f301.1602150362.git.lucien.xin@gmail.com> <17cab00046ea7fe36c8383925a4fc3fbc028c511.1602150362.git.lucien.xin@gmail.com> <6f5a15bba0e2b5d3da6be90fd222c5ee41691d32.1602150362.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 5b74187..0d16e5e 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 Thu Oct 8 09:48:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 11822557 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.8 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 44BE4C43467 for ; Thu, 8 Oct 2020 09:49:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DD89A2177B for ; Thu, 8 Oct 2020 09:49:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FlDv+QEx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729315AbgJHJtv (ORCPT ); Thu, 8 Oct 2020 05:49:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725887AbgJHJtv (ORCPT ); Thu, 8 Oct 2020 05:49:51 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 506FEC061755; Thu, 8 Oct 2020 02:49:50 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id o8so2506609pll.4; Thu, 08 Oct 2020 02:49:50 -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=r065IKyXdFJ5GMOudMqVr03VgbZjGBH5pw37dEIt8yw=; b=FlDv+QExgF/i45sOO63T3sCZjZ8SD5VvUI/DB97k295irQH+pN0HARRIzlr10+2pD4 HXq6ESJc8IgrMRAPadgk6nt7f0VJd8OvkSiHd4jQf9e8/hVT1cq1wd+B+K0ZtbJFxEzu FlpafJpAMUzwRE7rWHBm9SQbbp+5dXaeAWWGTz/9CwgGSbkEP1bkOLue45Z06lM02WW3 kI09OchFishQdRQNQrY7HFHIw5rsZvAnH2vN19enYi/MRW+az9LbFSBLJy3wnxL93W3s Mwg4Z3Kvdh/J0yNdC5Yrrwwa8tz1yt1sI1kVVltT9EOYFvo2Swy3AFuFsk7K9tdIldXK jqdw== 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=r065IKyXdFJ5GMOudMqVr03VgbZjGBH5pw37dEIt8yw=; b=HfL+bWlHmIZKAk1pAWc3V4IaQCsgylSyuvPwS1snjNBSuy0ramZd9NIYEBq94h6HFQ ebb4HZq9KwtUi/MIohagpDYeKa2ZzpL0b8plIZXCvoHm7tPEufkmgpBH4XDDR2ueHodi FJ0n8GpzASQKWcTDY87ztPYhbJbOQEVrcjDp0fJnI7w+Z8i10BA8i+fhinzq9bzi+4CO /RAXmi9z6sAg2GYHzsSyRi6VO5xJzHhjkASJZzu4LXV2pzK+LRvnuG+gfQ2yqXhWbmjj Co+n5z+8o3aXwgG8EVN+UvazroqZo9bura4bFiQtzklgcYgFlg71hFoQizDrCpZq5cpe fN3w== X-Gm-Message-State: AOAM533voGW9mPoZMQjRE/eJUE9m6JiRYNRVLblt1xhDJrGM5gO7/OL2 gvlGlZA6uvklOYYJ4tMRhvvhnQ9jekA= X-Google-Smtp-Source: ABdhPJwnklnf2845eRn/TNO/4TW0SgYIc9M5xfZYMuQ4s4yGMDSRu64/thCQEe4BG76zktXa+7ezHw== X-Received: by 2002:a17:902:aa90:b029:d3:b2d3:44ef with SMTP id d16-20020a170902aa90b02900d3b2d344efmr6790987plr.60.1602150589570; Thu, 08 Oct 2020 02:49:49 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id o17sm6110166pji.30.2020.10.08.02.49.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Oct 2020 02:49: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 Subject: [PATCHv2 net-next 11/17] sctp: add udphdr to overhead when udp_port is set Date: Thu, 8 Oct 2020 17:48:07 +0800 Message-Id: <1128490426bfb52572ba338e7a631658da49f34c.1602150362.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <92d28810a72dee9d0d49e7433b65027cb52de191.1602150362.git.lucien.xin@gmail.com> References: <052acb63198c44df41c5db17f8397eeb7c8bacfe.1602150362.git.lucien.xin@gmail.com> <483d9eec159b22172fe04dacd58d7f88dfc2f301.1602150362.git.lucien.xin@gmail.com> <17cab00046ea7fe36c8383925a4fc3fbc028c511.1602150362.git.lucien.xin@gmail.com> <6f5a15bba0e2b5d3da6be90fd222c5ee41691d32.1602150362.git.lucien.xin@gmail.com> <92d28810a72dee9d0d49e7433b65027cb52de191.1602150362.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 c9e86f5..192ab9a 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -4926,6 +4926,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 Thu Oct 8 09:48:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 11822559 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.8 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 424E2C43467 for ; Thu, 8 Oct 2020 09:50:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D9ACB21531 for ; Thu, 8 Oct 2020 09:49:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CwwMaLDX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729321AbgJHJt7 (ORCPT ); Thu, 8 Oct 2020 05:49:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725887AbgJHJt6 (ORCPT ); Thu, 8 Oct 2020 05:49:58 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99D60C061755; Thu, 8 Oct 2020 02:49:58 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id 7so3810835pgm.11; Thu, 08 Oct 2020 02:49:58 -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=CwwMaLDXlQDIPgkCCSE5DGBmA08149Qmw8ypvNRq+0GVsbzUxVxN38K632z4xEu84X 9AmDjy/14yeotECYm3bSzuwOhBMnOirW46nhHaGieTUxkR72nQhFGM+tP+LgzPfMqzGE CJozn1wKvK8VMJ2mLDWic/JK9Z/FDpjhaopIbPAmg8KgEwd/zNUoY0GjUvVSC1RoaY/n bcuY72bFjfvb8YC1aPhJNVX/kDFJNIWgHyR64Ys1u/VkTxy8j2iVnnxnzFraRwtI75jW eYR83+WGpGp9zXLQnLzclHNk+be2yK/jTwHlHvqilhNWw4LPQMMcp0CnWeWxbQq6NlBv 6Zmw== 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=SSO+IgQyFhgZsC63B/RBiByZIIw+iyfKQw3GkcCJc5v9/yTS34DwblaTG2b0/2cMET 34dLxG9gQWXGspcbphRZiH2/kNHEW4iKYFrtMwF3JO6eA0AhWR8sM2diqUAczBARttFs EYsA/Wvpa/yWa5+etXLrre0S7q7Ji7gPgHBjt5ALMb/zy73x0p/gB6i3RlXnWXucTDy9 Ho8CETbTvL1en7ird2XU0mo3/YwkmpAs4mSjnFR8LKj/WTecO9Uk95YBct4wxzLIQyeE qkgwkZzQ42PWPqrT/ALvF8fAO0FI7DPuqOnZ6E4JUx43ssgfrVtvW7Hig4+NBloALI6G eOdw== X-Gm-Message-State: AOAM530938wj1Vfnma9np2jIIHd+JejM9afZzXXzPRm3I18jeETOtlGi 6KYeQMjbb57va2Dv5OuuCSn/r1ShJ5Y= X-Google-Smtp-Source: ABdhPJxBazcIs7wzMgTLEWikewpcizbM2KE4uXwChCeV6kDT60ppFSGuIpuYhDKcYjacOHOGJyoumw== X-Received: by 2002:a17:90b:50a:: with SMTP id r10mr3010722pjz.231.1602150597916; Thu, 08 Oct 2020 02:49:57 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id fv13sm6407198pjb.50.2020.10.08.02.49.56 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Oct 2020 02:49:57 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , davem@davemloft.net Subject: [PATCHv2 net-next 12/17] sctp: call sk_setup_caps in sctp_packet_transmit instead Date: Thu, 8 Oct 2020 17:48:08 +0800 Message-Id: X-Mailer: git-send-email 2.1.0 In-Reply-To: <1128490426bfb52572ba338e7a631658da49f34c.1602150362.git.lucien.xin@gmail.com> References: <052acb63198c44df41c5db17f8397eeb7c8bacfe.1602150362.git.lucien.xin@gmail.com> <483d9eec159b22172fe04dacd58d7f88dfc2f301.1602150362.git.lucien.xin@gmail.com> <17cab00046ea7fe36c8383925a4fc3fbc028c511.1602150362.git.lucien.xin@gmail.com> <6f5a15bba0e2b5d3da6be90fd222c5ee41691d32.1602150362.git.lucien.xin@gmail.com> <92d28810a72dee9d0d49e7433b65027cb52de191.1602150362.git.lucien.xin@gmail.com> <1128490426bfb52572ba338e7a631658da49f34c.1602150362.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 Thu Oct 8 09:48:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 11822561 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.8 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 858D4C43467 for ; Thu, 8 Oct 2020 09:50:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B3072177B for ; Thu, 8 Oct 2020 09:50:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="i43D+nwO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729324AbgJHJuH (ORCPT ); Thu, 8 Oct 2020 05:50:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725887AbgJHJuH (ORCPT ); Thu, 8 Oct 2020 05:50:07 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F2ADC061755; Thu, 8 Oct 2020 02:50:07 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id n14so3547882pff.6; Thu, 08 Oct 2020 02:50: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=vxgUs2t02Y6T7ju2jCDcB1sbv2HoOE9Ilv7QfTc5UB0=; b=i43D+nwOf4/E9Duyi3d1RQD5bnl09MZTf+ueueKzb7ZQHZzAAoRnth3VVObwikZwmY j92/yX9iwCrBmEnbcvJsXlRAWGqn38+bm73JksifpMIjwvjuQk8/ZvBS6j5yp/MFq3lb LQQv5I6sAODpRJIKoWC2uKIfL77d0Qg1bciU3OTNeuFsRqMMQvJHBDB9j4ocvlBoRBT0 Dkr71ce5c64yRlBuoxmpWUoi8AMOnjzjs4zWkozr3gcmQ6+0yPrUbbkccXhDv1GnYS5m ccOe/TmuRhADaI90cmj3sPBfqrSulhk3KTBDlU1fQ8EReO/MpzgEBtGyFC+PKDjrro+C JF2A== 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=vxgUs2t02Y6T7ju2jCDcB1sbv2HoOE9Ilv7QfTc5UB0=; b=X1wCo/n4gNnC8wl2jvhr2bih2opvz01ssV5y0M2CziPxIQWi4CFwwL2ZYKm1UBJJdt aUlmzb2lsgprBk5YDNaxNN33uk5W5X24reil1Lx4u2JH4dbFEvr9h26XvZgOKkcDOrzS YefzLuMVIbl8v+TfyBzYKmkO2zVYGWbYKv2X/uNyT+O8R4CwkerMsRTEeVQYwpIMoWgd J24QmzeuBI0QjZ0+AWuVxWqpgfX+IPJ2nhq7XvqKovn4po/mMw/5MRXJ3XNOr85shiwc 5Q5/23WGN+pLeRNedj7M9kxpcmDHQ8a1zDtv+jkp+ncuE/KQ/Sf3hVx3jvRajLRopphy UOpQ== X-Gm-Message-State: AOAM533UQ9/f/PaUA/lk/oolBpRtxkcPumUjveZAZ0aYIRBc9iqNNPm4 YwmskywcMTcSyie1CydAE6w/XO8eQ+E= X-Google-Smtp-Source: ABdhPJxnq9ITDMw0XHe8yjxtH1sTTB+hTXXek7+xUuf38AQJWNrdH207G2KIl7yBCejCmhJN4ZvytA== X-Received: by 2002:aa7:9dcd:0:b029:152:421f:23eb with SMTP id g13-20020aa79dcd0000b0290152421f23ebmr6599191pfq.58.1602150606340; Thu, 08 Oct 2020 02:50:06 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id l13sm6543347pgq.33.2020.10.08.02.50.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Oct 2020 02:50:05 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , davem@davemloft.net Subject: [PATCHv2 net-next 13/17] sctp: support for sending packet over udp4 sock Date: Thu, 8 Oct 2020 17:48:09 +0800 Message-Id: <1d1b2e92f958add640d5be1e6eaec1ac5e4581ce.1602150362.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: References: <052acb63198c44df41c5db17f8397eeb7c8bacfe.1602150362.git.lucien.xin@gmail.com> <483d9eec159b22172fe04dacd58d7f88dfc2f301.1602150362.git.lucien.xin@gmail.com> <17cab00046ea7fe36c8383925a4fc3fbc028c511.1602150362.git.lucien.xin@gmail.com> <6f5a15bba0e2b5d3da6be90fd222c5ee41691d32.1602150362.git.lucien.xin@gmail.com> <92d28810a72dee9d0d49e7433b65027cb52de191.1602150362.git.lucien.xin@gmail.com> <1128490426bfb52572ba338e7a631658da49f34c.1602150362.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 0d16e5e..be002b7 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 Thu Oct 8 09:48:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 11822563 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.8 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 2E444C433E7 for ; Thu, 8 Oct 2020 09:50:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B89E120725 for ; Thu, 8 Oct 2020 09:50:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JSJqqg3E" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729330AbgJHJuN (ORCPT ); Thu, 8 Oct 2020 05:50:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725887AbgJHJuN (ORCPT ); Thu, 8 Oct 2020 05:50:13 -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 61BB3C061755; Thu, 8 Oct 2020 02:50:13 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id 144so3549179pfb.4; Thu, 08 Oct 2020 02:50: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=zpcgNpTt1Eopd9QaDKGy8sWqns6Rwfi4+2UKE6Sn+wQ=; b=JSJqqg3E7gXGgbVdJAiyQkDh8yVQCW7EVdbcUpGBbH4WrXgGZhLTWrJmajUTmhPoEi mLuNKfTO5i1ghIgxb+4Ac+q57baqp0G6PBbpB6PV+awHWxltHN+Hvki9twl0pq018nSP AjhtxJyhxvtDFUyp3jfTkoZOE5F0+38Z4XjTOSrbJ5ClrfT9ZcQMJBH7cVjQYh8kp+Ot EfXqHJbEj2DgZ0hC/C5D6KBWmzj0sNGANUN1iA4HfOSqoFIxmqMR1VAAhaHPAwQisfju RY2l+4vf5GM3svUeJyHnIrAxqjFfOBYadHjMKPPx8daOmUvgnjWOboO6F8FK8D+6Ies4 e3WA== 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=KvwSwG522L7JjnfOyUYxtWr8jtUwvijFh8BRkZUGIxc40T+0toVcjAOERbCmw7SnTI 4X3k6RHK6NfAio82bf2JUSAWTFgg/D6zS5DFm0WzzTo5qUG2nxX1WARbBOHdbQr57uaI qIpCCC9ABZHUTWsT2gabLGaCG63lTHpf5bgCC1IjazSiXhdKyWeWIR5OcE/x2hd6xWyw 8Hi1rqPEzuiMV0727zQSMbpwb4BbcqTy9h2dEpj2l8mNafjehPL7Qqrwxnno5q8kCXte uUwv0ZWdA1AxEXezUDjCJnwFig8y8cD4+H4WX90xqiBM3mF/awFjaPK9MFvFpRMbCDE5 E/2w== X-Gm-Message-State: AOAM531WhsrxPvcf2TZKAeB2vCFN85j1bfG9FbyiZEf/ZY91O/ykwNZ6 4OjPMzwK+RCE8903IiunS5sdt/H7eJA= X-Google-Smtp-Source: ABdhPJzhlaX/UapeJvm9Od3aYl3WQ6Up7e3sAJ9GUv2QQvWGlktPYrx8XGJm79YvoReBORwfmO9pzQ== X-Received: by 2002:a17:90a:e697:: with SMTP id s23mr6984491pjy.16.1602150612658; Thu, 08 Oct 2020 02:50:12 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id gk14sm6198727pjb.41.2020.10.08.02.50.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Oct 2020 02:50: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 Subject: [PATCHv2 net-next 14/17] sctp: support for sending packet over udp6 sock Date: Thu, 8 Oct 2020 17:48:10 +0800 Message-Id: <5c0e9cf835f54c11f7e3014cab926bf10a47298d.1602150362.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1d1b2e92f958add640d5be1e6eaec1ac5e4581ce.1602150362.git.lucien.xin@gmail.com> References: <052acb63198c44df41c5db17f8397eeb7c8bacfe.1602150362.git.lucien.xin@gmail.com> <483d9eec159b22172fe04dacd58d7f88dfc2f301.1602150362.git.lucien.xin@gmail.com> <17cab00046ea7fe36c8383925a4fc3fbc028c511.1602150362.git.lucien.xin@gmail.com> <6f5a15bba0e2b5d3da6be90fd222c5ee41691d32.1602150362.git.lucien.xin@gmail.com> <92d28810a72dee9d0d49e7433b65027cb52de191.1602150362.git.lucien.xin@gmail.com> <1128490426bfb52572ba338e7a631658da49f34c.1602150362.git.lucien.xin@gmail.com> <1d1b2e92f958add640d5be1e6eaec1ac5e4581ce.1602150362.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 Thu Oct 8 09:48:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 11822565 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.8 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 18583C04EBE for ; Thu, 8 Oct 2020 09:50:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AE5B720725 for ; Thu, 8 Oct 2020 09:50:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QrPNjt0R" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729334AbgJHJuW (ORCPT ); Thu, 8 Oct 2020 05:50:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725887AbgJHJuV (ORCPT ); Thu, 8 Oct 2020 05:50:21 -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 C3BC9C061755; Thu, 8 Oct 2020 02:50:21 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id e10so3566607pfj.1; Thu, 08 Oct 2020 02:50:21 -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=eHpfgVHKRbBtzp3y6GtZn9feVuuP00yNLAtwJLjoQHM=; b=QrPNjt0RO8DT5b3ueEDCjwQvh4/pPPUm5KptSzNpUva9O9Gz7bXkCdCi6XhqM9HWmY Uyd89mkV6WQabi2OOCXTh8bIuMPnuTVqS/nRHike2RVZbIfztY/BIm4GkzrWnk7WZ9wX zyPva/0GiObrsWdKNwg+/vqLkfDIU837PsiTyjQsaBjc5Nvg4o4vY1erd5XUJ3k0mwpS fqec49mv7PNgC14l+IuYo6grm6B/O1H345qr23+e1Cbc7+U+0SxjfP9Uhe4zOEm3CwqT NAVmoFuhg5j24Yd+ia9esoZlQLo+qyv8+ntz+n3TRr11BogKlBX9h7Dgi1bzlNKxsN/5 bFhA== 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=eHpfgVHKRbBtzp3y6GtZn9feVuuP00yNLAtwJLjoQHM=; b=CnnoMzGeSfdMIg7/nBD8iAAypMy4dh2sMxVFGnVc9MeVt2t2cERnetaqIKHJ8mepNG goeD2HmbhPAhK4bRs8BEddrk869uMUrIdtPso1jnV7C2tVNWwqnfTmGf9faHSA1jZiHJ huCzdGM9h5wB0xDl1lXOOkHUjMHO8i2AC111qyIIlh7W5AD0BZ24FCDAekHP7mRfcuIK ggv/MjtV8262X381pM6K7HcYacc/3Mx4W7h785S9d1WOn1aYMGd/yYMRbZTRn8tMPjmP QTx4jioHhueHa/iqFVY57yZwQN4ArFCmlHShgUPoBAND5SbuxbPIYiSOqKofiN8iuUSD xprw== X-Gm-Message-State: AOAM533s+zJG3iAZqNjB4Riyk2/OWPO/n8PmNUIMy9dAP2MS5yhI4lTq 2xZK8P2TJNNR2hHGtCps9Aa8O6rtGpY= X-Google-Smtp-Source: ABdhPJwjjz3XPgKnnUFvCBYB3q0QoS4/vwzxZYzS87QbKM/0wo23sACHz2wVP9sOEcUi4jP/EICGlw== X-Received: by 2002:a17:90a:d57:: with SMTP id 23mr7201642pju.232.1602150621092; Thu, 08 Oct 2020 02:50:21 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id y7sm6428069pgk.73.2020.10.08.02.50.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Oct 2020 02:50: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 Subject: [PATCHv2 net-next 15/17] sctp: add the error cause for new encapsulation port restart Date: Thu, 8 Oct 2020 17:48:11 +0800 Message-Id: <8815067eea44ffd7274b0038e48c2618c2e77916.1602150362.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <5c0e9cf835f54c11f7e3014cab926bf10a47298d.1602150362.git.lucien.xin@gmail.com> References: <052acb63198c44df41c5db17f8397eeb7c8bacfe.1602150362.git.lucien.xin@gmail.com> <483d9eec159b22172fe04dacd58d7f88dfc2f301.1602150362.git.lucien.xin@gmail.com> <17cab00046ea7fe36c8383925a4fc3fbc028c511.1602150362.git.lucien.xin@gmail.com> <6f5a15bba0e2b5d3da6be90fd222c5ee41691d32.1602150362.git.lucien.xin@gmail.com> <92d28810a72dee9d0d49e7433b65027cb52de191.1602150362.git.lucien.xin@gmail.com> <1128490426bfb52572ba338e7a631658da49f34c.1602150362.git.lucien.xin@gmail.com> <1d1b2e92f958add640d5be1e6eaec1ac5e4581ce.1602150362.git.lucien.xin@gmail.com> <5c0e9cf835f54c11f7e3014cab926bf10a47298d.1602150362.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. Signed-off-by: Xin Long Reported-by: kernel test robot --- 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..3bf1399 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 = htons(SCTP_INPUT_CB(chunk->skb)->encap_port); + nep.new_port = htons(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 Thu Oct 8 09:48:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 11822567 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.8 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 11A8CC433E7 for ; Thu, 8 Oct 2020 09:50:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B167A217BA for ; Thu, 8 Oct 2020 09:50:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DiLr5/kJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729343AbgJHJuc (ORCPT ); Thu, 8 Oct 2020 05:50:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729335AbgJHJub (ORCPT ); Thu, 8 Oct 2020 05:50:31 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46ED6C061755; Thu, 8 Oct 2020 02:50:30 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id o8so2507461pll.4; Thu, 08 Oct 2020 02:50:30 -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=p4SMhWw/GkelBn53iaflgFeeujBM4zh1mzJ+1B9emc0=; b=DiLr5/kJE3FI0vWri/jVH/5jzhPnKJp4tno25ep6IBm25uDkb4eqAxuLpLqyngTo88 cgagiX9LrdBiGVnxLIlhDJ1MG2Y9pTcABQ1EpQhdg7RV9yfEbWXGqkO6hDPHRmchAbmS UILHakP/bughjA7dqFw3o7sKO64q+L4NK5Y4k7A5u4AI08oFNqI4/kvsKfrHREuQ45Fb dkVhZbDtAFZE8ik/N+GCaXhPbld1sawpaZAB/sb0bD/162Q8T1bAaGK2rqQlQ7JKIddt i7QCpe08WxcJno9bFubr3eWt3+PpO4IGotqo35XH5j40bR+Xoz8D5jE2K23Me63ginbL XdLA== 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=p4SMhWw/GkelBn53iaflgFeeujBM4zh1mzJ+1B9emc0=; b=mVD7q5U9XCijVpV+fIsWPqC3G21VRUAMH3rWXRY5ELAD9vxD8qu3O6x80s/rW6LP7n oW0khm5mpfktZVn0ZRwLfD/CD6CsynT2lX59m2DluLJ26hkYKIIwKMR3kRhMqYIqVBqM vIx06JeOGp+mtsJENy489e7JleM8K+ulMp3RN+IOB6dMYDQNfcfj0Cy8y5tuO1ITIbO6 vlvVFOhwS2ZlqaQq2C2xaXsdAdUI4UPOEgsfDFRAgcstyXAPPMRk5mvcrTyKh0L0gGJ7 zeOlkZ0j2P9T6vbmoDyMOlcKWJjdUHaIZLWjmPP9HR7Nx0yPKNvGadrD1REeEt7tcsjw w3Xg== X-Gm-Message-State: AOAM532NczUMzb05VC/3yNqPZ20Q8ZpJe5yD3V2hqSmNashtDmLMiVuy qmLrF3xHpq4IDT/Tmknm+BE81tg6/jA= X-Google-Smtp-Source: ABdhPJz0oqvTVCLYh8Ux0T+YbUD4J/nFJb2LagH4j5GnUiaYx89kXNWOZ15zfgiCTsnpJMs1aGmJFA== X-Received: by 2002:a17:902:8646:b029:d3:b593:2842 with SMTP id y6-20020a1709028646b02900d3b5932842mr7034479plt.46.1602150629488; Thu, 08 Oct 2020 02:50:29 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id t13sm6055173pjo.15.2020.10.08.02.50.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Oct 2020 02:50:28 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , davem@davemloft.net Subject: [PATCHv2 net-next 16/17] sctp: handle the init chunk matching an existing asoc Date: Thu, 8 Oct 2020 17:48:12 +0800 Message-Id: X-Mailer: git-send-email 2.1.0 In-Reply-To: <8815067eea44ffd7274b0038e48c2618c2e77916.1602150362.git.lucien.xin@gmail.com> References: <052acb63198c44df41c5db17f8397eeb7c8bacfe.1602150362.git.lucien.xin@gmail.com> <483d9eec159b22172fe04dacd58d7f88dfc2f301.1602150362.git.lucien.xin@gmail.com> <17cab00046ea7fe36c8383925a4fc3fbc028c511.1602150362.git.lucien.xin@gmail.com> <6f5a15bba0e2b5d3da6be90fd222c5ee41691d32.1602150362.git.lucien.xin@gmail.com> <92d28810a72dee9d0d49e7433b65027cb52de191.1602150362.git.lucien.xin@gmail.com> <1128490426bfb52572ba338e7a631658da49f34c.1602150362.git.lucien.xin@gmail.com> <1d1b2e92f958add640d5be1e6eaec1ac5e4581ce.1602150362.git.lucien.xin@gmail.com> <5c0e9cf835f54c11f7e3014cab926bf10a47298d.1602150362.git.lucien.xin@gmail.com> <8815067eea44ffd7274b0038e48c2618c2e77916.1602150362.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..244a5d8 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 Thu Oct 8 09:48:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 11822569 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.8 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 46E2DC43467 for ; Thu, 8 Oct 2020 09:50:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DFCE021531 for ; Thu, 8 Oct 2020 09:50:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Al3wMu1S" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729350AbgJHJuj (ORCPT ); Thu, 8 Oct 2020 05:50:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729335AbgJHJui (ORCPT ); Thu, 8 Oct 2020 05:50:38 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9840BC061755; Thu, 8 Oct 2020 02:50:38 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id x5so2507840plo.6; Thu, 08 Oct 2020 02:50:38 -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=eHKwsdD2P/4UsoU1p41NzNCp0TnmAEioXR/YlvDUq0g=; b=Al3wMu1SjJLKcT9vC+aZ5/bYLMNPlgrmteGUTK30+HyUq7vxNcSnqMlTZ8T68ZV60+ viakhm0GU93UkNR/VXxLdGTjZgKETxQT/FDaYhOfl8+QF3++IC19H35Zq6E7kenhV4FZ KtiViO9X/RfqLbtS49dZKgvnNO03Lr0N4RS9YapAMM+2ie4VrZAXF9/XhRejgZ8JmXQZ gFQJjvhCnVoFXi9bKh4XVOX669rs1MrDh/Aq2ZX0Mkc/bq1TCgueWTYq7hrpSY1Dfk1c vNflcL99kiq87kzQgChfWXHCtD0bPrKZegCO/5LA4tJUU2shMaJ43TMehmJW4kUadWUW Ejgg== 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=eHKwsdD2P/4UsoU1p41NzNCp0TnmAEioXR/YlvDUq0g=; b=abQ2aJbtYvdaAmsdPXxZmNI01LRUzflPErJ0ALte3WFWIjqWiGF9F2jp/82r3ikTWf 9Q42oyIyuJCCWBfqGUPNAlGVbZ0rs1i6LzqRXQUfecS+8P7KWJcwaebQy5AbtUwHkrbs XX0ycOckxg/wLtRTiAchBBQ5Kb4HiB9TgCDCT805aLDoZqC58w90A4+RwnL+bUdrcPxE 8eAVT26Ptoky3k219TG/P+d4OyLP7mK4ogpmoNsZ64IpRRpWwADwwVerXU/EaQjIHe+g +eVy3UePh9lIBNSYAPfFMAgx2R2oQWDPVuNWyTVKeEUvdc5JnHKZddtuSEGYAB+/Nzft 76/w== X-Gm-Message-State: AOAM532QUDfVizJBGZDUd5cwRehCJfbsFVNG2JOkuZ6GmBwrYoj84r46 /f2Z6AkQw6x2OoVp2IRTiU6NnzQPAw4= X-Google-Smtp-Source: ABdhPJwMVa1K0ZNXOsQ+a1YeCThLJ3vRAy1nKg9x2aX+KLqZifBSUuVEoS+o1Rwk+qRmDEmwiBjpCA== X-Received: by 2002:a17:902:c3c2:b029:d3:df24:1584 with SMTP id j2-20020a170902c3c2b02900d3df241584mr7063024plj.33.1602150637897; Thu, 08 Oct 2020 02:50:37 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id e19sm6940258pfl.135.2020.10.08.02.50.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Oct 2020 02:50:37 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , davem@davemloft.net Subject: [PATCHv2 net-next 17/17] sctp: enable udp tunneling socks Date: Thu, 8 Oct 2020 17:48:13 +0800 Message-Id: <8ce0fde0d093d62e8969d1788a13921ed1516ad6.1602150362.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: References: <052acb63198c44df41c5db17f8397eeb7c8bacfe.1602150362.git.lucien.xin@gmail.com> <483d9eec159b22172fe04dacd58d7f88dfc2f301.1602150362.git.lucien.xin@gmail.com> <17cab00046ea7fe36c8383925a4fc3fbc028c511.1602150362.git.lucien.xin@gmail.com> <6f5a15bba0e2b5d3da6be90fd222c5ee41691d32.1602150362.git.lucien.xin@gmail.com> <92d28810a72dee9d0d49e7433b65027cb52de191.1602150362.git.lucien.xin@gmail.com> <1128490426bfb52572ba338e7a631658da49f34c.1602150362.git.lucien.xin@gmail.com> <1d1b2e92f958add640d5be1e6eaec1ac5e4581ce.1602150362.git.lucien.xin@gmail.com> <5c0e9cf835f54c11f7e3014cab926bf10a47298d.1602150362.git.lucien.xin@gmail.com> <8815067eea44ffd7274b0038e48c2618c2e77916.1602150362.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. Signed-off-by: Xin Long Reported-by: kernel test robot --- net/sctp/protocol.c | 5 +++++ net/sctp/sysctl.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c index be002b7..79fb4b5 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..a723613 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,44 @@ 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); + ret = sctp_udp_sock_start(net); + if (ret) + net->sctp.udp_port = 0; + + lock_sock(sk); + sctp_sk(sk)->udp_port = net->sctp.udp_port; + release_sock(sk); + } + + return ret; +} + int sctp_sysctl_net_register(struct net *net) { struct ctl_table *table;