From patchwork Tue Sep 29 13:48:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 259933 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.7 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 CA243C4727C for ; Tue, 29 Sep 2020 13:49:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 618EB208FE for ; Tue, 29 Sep 2020 13:49:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZkkNgOj7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730323AbgI2Nt2 (ORCPT ); Tue, 29 Sep 2020 09:49:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728487AbgI2Nt1 (ORCPT ); Tue, 29 Sep 2020 09:49:27 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D45DEC061755; Tue, 29 Sep 2020 06:49:27 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id k8so4613441pfk.2; Tue, 29 Sep 2020 06: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=jGFHohiLMKmOcbBELvAHtKl6/eKf2Rs4EotDZ5VjkE0=; b=ZkkNgOj71CzBiqwUx2PHMXjo+A7b+XwnHK/P0XlALa0bzJUKaqJ98/zbXF9OPFtgiJ ozAXkcmyHmyyJUF7CWb+3+Axpl6wze+7Vo9WOx7WEX8iTmzTnhvtioMkALMgR8nsGzsC uZ3u4iNJ975QRy2MlKhWCd6a5u9dEdZnx5R/Ow3RedlXm7BtMdpLbrIubrEe2nbzjz9a G14kdFiIZ/d3iWTtNUjQoHloUCXiYG9CZ2l6QJXqocBKU/zcm63uBB5jmN+mYWeJWOuj cGvgk2f4p4uhvGb/QkkbTnyIw+UV3HwmUafdnJKM+g9tT84qcQXNjS8tDfdND7iwN8es EpAA== 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=lOiKS8AIUmJaDsTwUPZSaELO7Z6nGj+ELBOmW5Ht1EFL7eKB+uKrYP+pxl5HGQMhOi X30VB4xn75Cru9HgdC96ZwpjzgPiWTuojMcoLchO5E2AYJTDO1YifRF34KGCn6H/2Ut6 UUou6KuO8L+LQzu3sU2MsFoXvHwClWhRLnVIqswU0a50ndRMe1tSU0cOr31QkYVH5pim SaT9q7HMYdG3/7VY/l7S5O4DLsDc5NCAl2FksLaN5OVp2U7vbZMICg+IEWBeWpJiQd9I 3QwImCZWUS964Fr81uforaiWs4bfv2ob3430NAo0W68nFVAE2qGBYuY0uv52tFxmVboW 3UpQ== X-Gm-Message-State: AOAM530pqM0rOCtTskt41+X9lgWdPVcDHS8/ZcXAQ4zynVkUPMuJzdqY /QzskAlWP3MnAnfz3t/fGFrmDoDVfkk= X-Google-Smtp-Source: ABdhPJzC4hQYvDoZWetKVnRMIS2puis0AMvfyEcfImrXwhQXsPUPSYYB2RTuvwtBUSd6quLanPqKCQ== X-Received: by 2002:a17:902:9041:b029:d0:cc02:8540 with SMTP id w1-20020a1709029041b02900d0cc028540mr4425386plz.41.1601387366744; Tue, 29 Sep 2020 06:49:26 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id p4sm4849238pju.29.2020.09.29.06.49.24 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Sep 2020 06:49:24 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , Tom Herbert , davem@davemloft.net Subject: [PATCH net-next 01/15] udp: check udp sock encap_type in __udp_lib_err Date: Tue, 29 Sep 2020 21:48:53 +0800 Message-Id: <51c1fdad515076f3014476711aec1c0a81c18d36.1601387231.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 Tue Sep 29 13:48:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 289388 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.7 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 A006BC4727D for ; Tue, 29 Sep 2020 13:49:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 38F0821531 for ; Tue, 29 Sep 2020 13:49:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mrjFwkTl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730499AbgI2Ntm (ORCPT ); Tue, 29 Sep 2020 09:49:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730283AbgI2Nti (ORCPT ); Tue, 29 Sep 2020 09:49:38 -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 B835BC061755; Tue, 29 Sep 2020 06:49:37 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id w7so4604916pfi.4; Tue, 29 Sep 2020 06:49:37 -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=mrjFwkTl2E2VeXUMo5tIFObiJYgdyLpW2x1AnOsdFoUZAGX6DXUGdw+iShr2++QNKa X8Q+DfW2bUyNYAc7IhMCUpRCwADJNuV64sf+nB7OK+YatajXoqd+RxYGbCr+ToWHKP12 EEN9xAEeKz7ph1GVPMB62pPMh8F5g3f7arV2gAADZyXakk93nQk/8wh+aQrdbngzfRFN o47gRYPppYNByyZDHCjlmGAnoArF91wDyTikS+7eXW95sSVX2mFhYJ9y9rO6fvzDigTK mORMlt+xzac1PjG2U+JFV5qJYgZFc4J9JNMJk3ZEBHLE9qjCN3cXAyOQiGXYOesmzgrA bUmQ== 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=LZSlyjM1hqoQL6SePfFUmThWz02ZB9IHaLDjlLDjdvjdgSUCuV/QFWMUV2C8mjP4lY CGqwvOScZBBwdXqssW0uC++g022JxgGzDLWjIwNX9ryTryqSYgRvFrJf1/Z3ZnSKjncL kxohtsNSXquJMxCTbDE3VFHlr8qi9OISrlXyZpq0TKBIGFdo5i0KNTW0++bQFV/3kcW2 k8PHfeIiAgxskDWPsjhTirMLuHwSlnqx1mwPTpkd+PXQ+md2p5npDWOdURKx5SqoEnha dWo3AZyW7BWQGvXs7QFkHVwAKeQSp+2L/cN19AoxYktvTUKa+TiI385BW2+7p7cJmwQz dotg== X-Gm-Message-State: AOAM530F2BPWVBbFClz05bI8WsX6qDmgEvfeyKSH6bQg1RfLr8hPwwcz cW1JbU4+OrQXwotV9+TRkl6+LIMYVqU= X-Google-Smtp-Source: ABdhPJzv7+P/ErpnFXgPsUr1GQZzuXGFXri8KKVMJtT7Ht9SW4hLRz0sDuDa5Y3K2p0NUHKT9stSgg== X-Received: by 2002:a63:df02:: with SMTP id u2mr3300018pgg.270.1601387376745; Tue, 29 Sep 2020 06:49:36 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id g24sm5703049pfk.65.2020.09.29.06.49.34 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Sep 2020 06:49:34 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , Tom Herbert , davem@davemloft.net Subject: [PATCH net-next 02/15] udp6: move the mss check after udp gso tunnel processing Date: Tue, 29 Sep 2020 21:48:54 +0800 Message-Id: <65f713004ab546e0b6ec793572c72c1d0399f0fe.1601387231.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <51c1fdad515076f3014476711aec1c0a81c18d36.1601387231.git.lucien.xin@gmail.com> References: <51c1fdad515076f3014476711aec1c0a81c18d36.1601387231.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 Tue Sep 29 13:48:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 259932 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.7 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 73FBFC47423 for ; Tue, 29 Sep 2020 13:49:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 177AA207C4 for ; Tue, 29 Sep 2020 13:49:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TKKUR2ow" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730541AbgI2Ntr (ORCPT ); Tue, 29 Sep 2020 09:49:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730501AbgI2Ntp (ORCPT ); Tue, 29 Sep 2020 09:49:45 -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 527CAC061755; Tue, 29 Sep 2020 06:49:45 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id n14so4596807pff.6; Tue, 29 Sep 2020 06:49:45 -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=F9gzu4ux1/gIDa9kBXORz7PWDK9PRGfbQUFqQq4SV/k=; b=TKKUR2owYbVnPKq6L/2bqdFncahUX2SllZzrr+291d644txwI6k5PJcACFDEuJChyP bgQHIPv1epPp+Coc5axdDjeXhsVvgEhB7mZuJjrUkRcqBYsDsV1BVF8HwQtkw9rgw40E MPyLZs/NE9NQePSC8g0I8siYQGBjoO7NAGAQcMen9V4cwk+oewNG1MHmWlLRNsWyFB2f VDUyMfZFfQzU/5y5GD3GKOAKYBVZ9PrTRTU8nbMN/yLH3i5ZZBjdO1SdUZugl2TPKdCh BGpyQ028YVkg86mefK+6nFaI5uC0RQEy20bqk8Ulxxdbmu4BLtNrQOzYJZQO6JDSQKf5 s67Q== 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=F9gzu4ux1/gIDa9kBXORz7PWDK9PRGfbQUFqQq4SV/k=; b=Q9yMafJ/RkqT4MoXWhJ6aZ4LXHpnF4Skw6fSv8aN+2D7DoclFtLbPji6D4nnnNDehe at9nnIeWuKwBm9CH0tmwKreSwPCQT1pRWk3wN48tWzY7VNyybOmdauK4+Tq/dBYuNpne EH4raToUjriMcczWUwXgK6Z2GuRnD5O/wyMjqo3XYTBBYQi18+n569Xsf5YGUgcDE3Mm yQyM3WssO8gp9uSrkTow8EVhi4aSIWJQqZwlZ5PbI3eFlBc6urAKB6Ry7F3PTE3oFirE C/ghdHOU/AESqwFALCE1+iWgSBiXqWsoiER9BA1VXiEhLnVvX5CxXrzDZ8J8vqOB//sJ FMbA== X-Gm-Message-State: AOAM5328DCvQokSYUtfcRx1DpPginGWXQPCPibFFl4YKbnG3w1a+8Bub YsMQ27CEBjRylPpDWeHPZRIyRPEkjko= X-Google-Smtp-Source: ABdhPJxPP4YAHkG6xMFycUU8aMW8/TXDPNMrEtXWDIzd5xgH5MWAHr3LfzHxBNbEcwji7bt08YHozA== X-Received: by 2002:a63:1d5c:: with SMTP id d28mr3217268pgm.82.1601387384298; Tue, 29 Sep 2020 06:49:44 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id h12sm5393320pfo.68.2020.09.29.06.49.42 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Sep 2020 06:49:43 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , Tom Herbert , davem@davemloft.net Subject: [PATCH net-next 03/15] udp: do checksum properly in skb_udp_tunnel_segment Date: Tue, 29 Sep 2020 21:48:55 +0800 Message-Id: <49a1cbb99341f50304b514aeaace078d0b065248.1601387231.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <65f713004ab546e0b6ec793572c72c1d0399f0fe.1601387231.git.lucien.xin@gmail.com> References: <51c1fdad515076f3014476711aec1c0a81c18d36.1601387231.git.lucien.xin@gmail.com> <65f713004ab546e0b6ec793572c72c1d0399f0fe.1601387231.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. 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 Tue Sep 29 13:48:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 289387 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.7 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 8A4F6C4727D for ; Tue, 29 Sep 2020 13:49:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3086E207C4 for ; Tue, 29 Sep 2020 13:49:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Od+22kLy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730563AbgI2Nty (ORCPT ); Tue, 29 Sep 2020 09:49:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730546AbgI2Ntx (ORCPT ); Tue, 29 Sep 2020 09:49:53 -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 B4579C061755; Tue, 29 Sep 2020 06:49:53 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id d6so4587824pfn.9; Tue, 29 Sep 2020 06:49: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=DEGAv+/TL4OwKmD7pxgq0o5h8o/m1hgKFquGraoWa10=; b=Od+22kLyLfZGF1lUP20MY0VPBN51cMfn9C2QJiJBRbjnHnyOfDceh8eZvVzrDEPxxg AeCDj+MJ0YGbI7c/jBa9V2cjUUMgU8YP4ydnffWoQGhjBL3Oku2Y0zL3BGqudhdUugS3 OAnng6Ushsx6cBWFAtCmWdgQ0DvLRNo0KLwPpvSkMhGdQRBn+w3q3dkjfTT5P6u7qfys UHogQsR4qq84QJ6wMnG4fD/MFKIEi/U4N0+0Om7izRLfxkNXYx+sUPJwW6a0omVyP/BW TPvzEwFRwawHCW3a15WctmN93LJtxhtxqrA+iMZAS+2s4GB31CCMKsBBIT75ozjbsR68 /MVQ== 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=DEGAv+/TL4OwKmD7pxgq0o5h8o/m1hgKFquGraoWa10=; b=muLz4iDmulW4VlMo+32ajPaq5zv0X+uUyiu4xO35Esyvgo0vcu/0KJnVM9EZVDdCIC AtnTbOEasTInCoOSYM+zOx2FqPOro5PslBbOsda8hx0bk997RQHP3Znpa+7dXcdbboEC 95ZLCGnXS0N95c/pj0YXxw8XBh9B01fJDah8g8ZiyRmlr/+Jy0N9x9BIWrijPKe8ee9m qIhzOiPuBcB+Je8UIrYmZsw0xDnCUp/SHQq2haKFC2qz8JMUvWGjNYPz9QVQP2PCPyr+ FlHbpySMFpVgGAe6OuhibC+mxEDpcTGRnDqhhB9OtDi0cZR7vUdTX8SXbX7IllDfgY93 ls3Q== X-Gm-Message-State: AOAM531E+y3TTXdBsQ/HQdpt4NbyA1p7Co5BM7SRPJtM5aZErcy/hMfT qdbaYDtOtM06kjeEQLJCCiTFjkscWu0= X-Google-Smtp-Source: ABdhPJxHR7k0IzIpzEzM2dHN/rE7gpjlXoELLo37dLXPL5/Wi9D6ymrLEjlZq2RgKt2Sqbrfhx/ZTQ== X-Received: by 2002:a63:e252:: with SMTP id y18mr3334454pgj.93.1601387392947; Tue, 29 Sep 2020 06:49:52 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id gm17sm4672531pjb.46.2020.09.29.06.49.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Sep 2020 06:49:52 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , Tom Herbert , davem@davemloft.net Subject: [PATCH net-next 04/15] udp: support sctp over udp in skb_udp_tunnel_segment Date: Tue, 29 Sep 2020 21:48:56 +0800 Message-Id: <97963ca7171b92486f46477b55928182abe44806.1601387231.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <49a1cbb99341f50304b514aeaace078d0b065248.1601387231.git.lucien.xin@gmail.com> References: <51c1fdad515076f3014476711aec1c0a81c18d36.1601387231.git.lucien.xin@gmail.com> <65f713004ab546e0b6ec793572c72c1d0399f0fe.1601387231.git.lucien.xin@gmail.com> <49a1cbb99341f50304b514aeaace078d0b065248.1601387231.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. 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 Tue Sep 29 13:48: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: 259931 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.7 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 DC741C4727D for ; Tue, 29 Sep 2020 13:50:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 81D3F207C4 for ; Tue, 29 Sep 2020 13:50:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mtwbM2Qy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730582AbgI2NuD (ORCPT ); Tue, 29 Sep 2020 09:50:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728487AbgI2NuD (ORCPT ); Tue, 29 Sep 2020 09:50:03 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29D3DC061755; Tue, 29 Sep 2020 06:50:03 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id kk9so2691846pjb.2; Tue, 29 Sep 2020 06:50:03 -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=0Iq5oxOzbbhd0aVMKoNrZJRhXFpOs9f+FQV8zzjXj1c=; b=mtwbM2QyyqVFjgnYmlijTjzNGYlifmogjjjDGaZs7+H0ycFgDOVLqQptsy7kO6oQUn c1h0/oNZMgKMTn9tiAcdPoI+HxjRLov2kvWRjVdGOzzDmv3laSrcB89+lof3RbQjPdWs VXzprzrzucmVdpaCCxhiR7k4XSjMXuCZ1Mug6jWkTu41CdnPKTHknRcbwobfeVqICh+J I4VyoRFeeW2vkfieo/QH8zGHO7vwfZl03X9C9SHGtC5y0KVNM5rwKq4+CRejIMsP0nGp /2++hAust0AEoKzLGr2rSaF1yncJW6s/FAQNNrpuAv/sSmqCdkzEeZFp4DriglOYHJhE 3loQ== 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=0Iq5oxOzbbhd0aVMKoNrZJRhXFpOs9f+FQV8zzjXj1c=; b=IJxfyfaqyLFuw/HYPnQZ5aBxSU4kr93VUf4BYTtpSyPWIojfaGYzvtbHmRxijNZRef hKXr+Pl8zqlgn9mhfubVQzBns/3yUOzIxCGaadRIOl5G/trZvgZ66548w7EZi0gP79vB VqwubtE5keyJ57V7nmAKn0tZbsqtQ+gRmtHMF9pSd/eHg8olnyr4PlxfNya79sQAyHa2 9GgTB3Oh61qIxsMO8w0rRoocRt3scEZoFmx+UCql0E2Bmd0tXDPi4kMrsncX2r6c5UXu qyzAR6YLYejIQgAAPpCWjXzTMMikTZ6gq6uaIsfiuU/QKf76xUjo+B+DwCNqG6ZZu9I4 XYAA== X-Gm-Message-State: AOAM532BkVX3LzbVoCE5T58cptpc4yZ8O3y2PeN3iqMTOcds1KcxPek5 1EEYLhq/cTpUKJY+T8fC8RYqyzAM/4c= X-Google-Smtp-Source: ABdhPJzgDP1k9Kkwp+JQ+HUbQTEHVVkrFT/3bfbCI8Y+ZNT9MwiBhxAqf0eGhqNYoLUzseXEEEg8kQ== X-Received: by 2002:a17:90a:f411:: with SMTP id ch17mr3861881pjb.38.1601387402072; Tue, 29 Sep 2020 06:50:02 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id n28sm4891973pgb.51.2020.09.29.06.50.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Sep 2020 06:50:01 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , Tom Herbert , davem@davemloft.net Subject: [PATCH net-next 05/15] sctp: create udp4 sock and add its encap_rcv Date: Tue, 29 Sep 2020 21:48:57 +0800 Message-Id: X-Mailer: git-send-email 2.1.0 In-Reply-To: <97963ca7171b92486f46477b55928182abe44806.1601387231.git.lucien.xin@gmail.com> References: <51c1fdad515076f3014476711aec1c0a81c18d36.1601387231.git.lucien.xin@gmail.com> <65f713004ab546e0b6ec793572c72c1d0399f0fe.1601387231.git.lucien.xin@gmail.com> <49a1cbb99341f50304b514aeaace078d0b065248.1601387231.git.lucien.xin@gmail.com> <97963ca7171b92486f46477b55928182abe44806.1601387231.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. Signed-off-by: Xin Long --- include/net/netns/sctp.h | 5 +++++ include/net/sctp/constants.h | 2 ++ include/net/sctp/sctp.h | 2 ++ net/sctp/protocol.c | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 49 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..f194b60 100644 --- a/net/sctp/protocol.c +++ b/net/sctp/protocol.c @@ -840,6 +840,43 @@ 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) + 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 +1308,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 Tue Sep 29 13:48: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: 289386 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.7 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 DE6BBC4727C for ; Tue, 29 Sep 2020 13:50:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 81DEA208FE for ; Tue, 29 Sep 2020 13:50:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="L7WY8hO5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730595AbgI2NuN (ORCPT ); Tue, 29 Sep 2020 09:50:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727328AbgI2NuL (ORCPT ); Tue, 29 Sep 2020 09:50:11 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B416C061755; Tue, 29 Sep 2020 06:50:11 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id k8so4615591pfk.2; Tue, 29 Sep 2020 06:50:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=Mcp71Li2jeDCKDUTmLEX1lM2xlcdhbiRa5IPyXEKtXY=; b=L7WY8hO52hXp6TSMCnleWTUSPYEJcELKK/Lnkf54hDv50ZdsnWGwgbUZ7HD4SagO/o alnknLO7exXwYVtaadMIUt4rmL+rlYkXWoWX+7rWUh3/SHbmXLycG+q6TFzxJLvdgHEb oRT/gBMqWDz5J8Iv9GTJgyXLhUk+d2S00JNLPI3ADed2f4jGJlM0kOvASzFwk3PfXpNL AldYz41kZW1ZZhLOQPy6aU3kP3omgqxiskKFoBnwvWPBTQ2qU2yHu1wVK2J2LSxlcoob j1A7cVwPWbbKp5sj7jvmbDa72aA1p2OXMuee8a/TUNoEAdZi3z8W/NpWKE8nDdT2SE2s qsiw== 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=Mcp71Li2jeDCKDUTmLEX1lM2xlcdhbiRa5IPyXEKtXY=; b=RTpCsvbAQ3b4irVxWq/JBEPjGGit9nOOXKyDxWspVUxXfecrGBJ+qjnQmHhIem7nAn LkWvBhweG9nTgasR7modY54VWbEcJKbewetwxMI2qFgS2U+C+lWJFY5dv3XyJjUY+Vtk gmHNzVcacYfkplRJ4DVoeOO9xrwHhTsRK5D9J4XVsBdotAEZ6ek1Yh2ZDJaxc6WMgSDd 570uVozWfNXJidykeFsm0uRmsNDbyykiXqo3Hj7/i7nbIK7laDYrKEV93/Gr827HS8h4 cTaWFnGlIW47YpZlQ96YqCfSCVV2+vT9kiiwPRvSqv7pW2+ZZybZ1NU9lYKW4SNlBxLq RuXg== X-Gm-Message-State: AOAM532ox4/Rttzuk7HEWIFQJhlO2KoBuGqZNlJOOiFZyeQuHk9exiei jqijL6QRugMfhv8OcDHFlZtcYUJMy+E= X-Google-Smtp-Source: ABdhPJx2ASqprsHqBolZoU6KcZ8VDKmXbpTWm/7SrdEvPvMixhsJ+8LXQgMAYuy4a7wu66BVcvz1Wg== X-Received: by 2002:a62:242:0:b029:14f:8e68:e7c6 with SMTP id 63-20020a6202420000b029014f8e68e7c6mr4266930pfc.54.1601387410574; Tue, 29 Sep 2020 06:50:10 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id s16sm4858175pgl.78.2020.09.29.06.50.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Sep 2020 06:50:09 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , Tom Herbert , davem@davemloft.net Subject: [PATCH net-next 06/15] sctp: create udp6 sock and set its encap_rcv Date: Tue, 29 Sep 2020 21:48:58 +0800 Message-Id: X-Mailer: git-send-email 2.1.0 In-Reply-To: References: <51c1fdad515076f3014476711aec1c0a81c18d36.1601387231.git.lucien.xin@gmail.com> <65f713004ab546e0b6ec793572c72c1d0399f0fe.1601387231.git.lucien.xin@gmail.com> <49a1cbb99341f50304b514aeaace078d0b065248.1601387231.git.lucien.xin@gmail.com> <97963ca7171b92486f46477b55928182abe44806.1601387231.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. Signed-off-by: Xin Long --- include/net/netns/sctp.h | 1 + net/sctp/protocol.c | 23 +++++++++++++++++++++++ 2 files changed, 24 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 f194b60..0aaa24d 100644 --- a/net/sctp/protocol.c +++ b/net/sctp/protocol.c @@ -866,6 +866,25 @@ int sctp_udp_sock_start(struct net *net) setup_udp_tunnel_sock(net, sock, &tuncfg); net->sctp.udp4_sock = sock->sk; + 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) { + 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; + return 0; } @@ -875,6 +894,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 Tue Sep 29 13:48: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: 259930 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.7 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 008E6C4727C for ; Tue, 29 Sep 2020 13:50:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 93B062145D for ; Tue, 29 Sep 2020 13:50:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CzZoL9k2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730615AbgI2NuV (ORCPT ); Tue, 29 Sep 2020 09:50:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727328AbgI2NuU (ORCPT ); Tue, 29 Sep 2020 09:50:20 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C92F8C061755; Tue, 29 Sep 2020 06:50:20 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id d6so4589141pfn.9; Tue, 29 Sep 2020 06:50:20 -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=uHR6RpGEci8H9pvKA0+VLzTG3pu14wk/3lPhWqq+6lU=; b=CzZoL9k2GKbCZn1o+6xKhGbOgzumuSAWyF+xiN3HK3bjrmVmM8zcmG4LsFtp37YZqi absJMp6WU10nBc+k7pJddk7/fjTsx/8yg2OH/dRiygqXVwFlMi39yJI2sud6ELS46hUa eJ1vBHi1XJ5zizY/RVZC2a90LpbZTLIY7p/wQbsP2BVl5GcjnhkkIiyx48VjGW2wk16m iOMx/f9St5dEf7sUIIOsgGwlWKnJgHs4I9YhdYe9lsZjTU2/V42QNp9FeHGzH7m1X/V0 1PF7ibTGsBNEbxq1XBxvyST7Qh39OK1U9lCIhPAAJrTmmSd2y5vM5kz/t7K3MWg2Iivs Tc9g== 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=uHR6RpGEci8H9pvKA0+VLzTG3pu14wk/3lPhWqq+6lU=; b=l+j19ShJR5oazYKLEakV+SradI4ZeeHCBvs20oEXhMBngkJlR1aL/jhBCa8J2q5RFj M9pcvN4+MBmiruTZaKPsd7iKuafbwXl4nCMB/BOqn3k65TJcZqkyKUGrzsmH+VxrkyWQ rVL76iXhtYQhEeWotATFXW1JUbJNmMcZNoOj4QrZyXxRhk8zj0xtX+W8lDca4S0mPiuT 7qp5uz9Lj0sYZDGHPWBcdDu1wxXZVTyZ561YAYL62gs+b9wVzfwXtiekBPEe4KB8rwLF Pu1b3PAXtm5kt8tt8MqAaMGPY3ixc64Le2DQVn9SSgjboDKAYaEsJCJxM7s06fstllkC LO/A== X-Gm-Message-State: AOAM533LYtpFhOzPOw5/D3ecXlym+Jgi91hh7bYqqFstzJP5XUyY8YmB /rbBQNs5rQomKqs5UsB83Zab7V0NM2c= X-Google-Smtp-Source: ABdhPJyJiB5M+osJ5R/yh3m2UIuWG9HDou9vasZlGbJG7j2O1udgqenwLgqqiVmqmo2o45VuxdmRrg== X-Received: by 2002:a17:902:aa95:b029:d2:19f4:ff56 with SMTP id d21-20020a170902aa95b02900d219f4ff56mr4811599plr.78.1601387419548; Tue, 29 Sep 2020 06:50:19 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id v8sm5395306pgg.58.2020.09.29.06.50.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Sep 2020 06:50:18 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , Tom Herbert , davem@davemloft.net Subject: [PATCH net-next 07/15] sctp: add encap_err_lookup for udp encap socks Date: Tue, 29 Sep 2020 21:48:59 +0800 Message-Id: X-Mailer: git-send-email 2.1.0 In-Reply-To: References: <51c1fdad515076f3014476711aec1c0a81c18d36.1601387231.git.lucien.xin@gmail.com> <65f713004ab546e0b6ec793572c72c1d0399f0fe.1601387231.git.lucien.xin@gmail.com> <49a1cbb99341f50304b514aeaace078d0b065248.1601387231.git.lucien.xin@gmail.com> <97963ca7171b92486f46477b55928182abe44806.1601387231.git.lucien.xin@gmail.com> In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org As 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 exists. 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 0aaa24d..953891b 100644 --- a/net/sctp/protocol.c +++ b/net/sctp/protocol.c @@ -847,6 +847,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}; @@ -863,6 +880,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; @@ -882,6 +900,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; From patchwork Tue Sep 29 13:49: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: 289385 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.7 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 7F785C4727D for ; Tue, 29 Sep 2020 13:50:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2B81F2075F for ; Tue, 29 Sep 2020 13:50:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lUrUCZ2+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730660AbgI2Nua (ORCPT ); Tue, 29 Sep 2020 09:50:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730617AbgI2Nua (ORCPT ); Tue, 29 Sep 2020 09:50:30 -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 B54B1C061755; Tue, 29 Sep 2020 06:50:29 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id f18so4586072pfa.10; Tue, 29 Sep 2020 06:50:29 -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=QbnzsGp5pnURiuLTAjTdwEtqIkPvBJMdIPJb7oM9S30=; b=lUrUCZ2+JUK+A1wEbeLWE2X/13Fcuskb6PnJZbH1gUZloWi1J3fHeAsrp8rl2BthSR UNWGFGPTATq+AXUsxpRff6SB1UbUmafRLZs+8bOVQw6I5OHIU4DByWtKzHbtj0hZeAPh 9LQv+e8+IjjrUr38MrypTujSDvj54bkoqJZEMCXyEgHVwV7ntlQNqUVjz+2UxOG9UO8W 2hKRoyxfk6E6rCotsytgcCUzZX8KFntt35U0P/iwa5RJ+TfBI5QPOUfQQhhPS9r2Al82 uTwAkr0alU/7rkiTrC5h1lZzwLU0Jo8tHoLoBpYOhHZzuYXAZ6Mv+Lfb6vBbSk9ou8dQ W0ig== 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=QbnzsGp5pnURiuLTAjTdwEtqIkPvBJMdIPJb7oM9S30=; b=CD+g+gHdK2LoSGEavXmMF6IExgdFd5V8GmVPpdVry6NqGcbUggf1hRps6qGgTFRq6X HRO2EDm23KdOqnmNOUK4UN1hgTvjrMjAcNSOkiYSTdPSKzDy402gopDa1o7B0C6UwEud Q7yk6BR2jQ2zHEHd9kiO3dx8Tcat/DCNw5tXUO/1qi2pwEnuo5Vmm9xLp0SnjlXi31FM BbAm6aqWBJrgY797JTtYEvc9JodPVGPApGhN610zcVHoL9FbSYZDeruOtJ9SI0PMtHtM oOG3pC53hhKhfkSGQ61euqZqYoXzzdYPQuqmHblVHe7p/unLQ94YLvP8DWvOEuwDcQU9 RS5w== X-Gm-Message-State: AOAM532Kx+S/FQbnqblN8tjuff6Y5HWkUgaJqL7W/guuKmz75TTwSVOs NaKGnllm0Pstrv9o+VAuj2CIrWRqt54= X-Google-Smtp-Source: ABdhPJxkkOrGFThDdpayhEqloiia6Qa6SpWmDK58ihyH/Mz6yEcw7dpDWiMlwW41fy7Y5zlubzkxkQ== X-Received: by 2002:a17:902:8689:b029:d1:9bf7:230a with SMTP id g9-20020a1709028689b02900d19bf7230amr4836326plo.22.1601387428636; Tue, 29 Sep 2020 06:50:28 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id g9sm5796741pfo.144.2020.09.29.06.50.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Sep 2020 06:50:27 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , Tom Herbert , davem@davemloft.net Subject: [PATCH net-next 08/15] sctp: add encap_port for netns sock asoc and transport Date: Tue, 29 Sep 2020 21:49:00 +0800 Message-Id: X-Mailer: git-send-email 2.1.0 In-Reply-To: References: <51c1fdad515076f3014476711aec1c0a81c18d36.1601387231.git.lucien.xin@gmail.com> <65f713004ab546e0b6ec793572c72c1d0399f0fe.1601387231.git.lucien.xin@gmail.com> <49a1cbb99341f50304b514aeaace078d0b065248.1601387231.git.lucien.xin@gmail.com> <97963ca7171b92486f46477b55928182abe44806.1601387231.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 encaped or not. This patch also allows users to set netns's encap_port by sysctl. 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..b6d0e58 100644 --- a/include/net/sctp/structs.h +++ b/include/net/sctp/structs.h @@ -178,6 +178,8 @@ struct sctp_sock { */ __u32 hbinterval; + __u16 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; + __u16 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; + __u16 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 953891b..8b788bd 100644 --- a/net/sctp/protocol.c +++ b/net/sctp/protocol.c @@ -1353,6 +1353,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..9aa0c3d 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 = 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 Tue Sep 29 13:49: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: 259929 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.7 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 84130C4727C for ; Tue, 29 Sep 2020 13:50:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2482F2145D for ; Tue, 29 Sep 2020 13:50:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lDgzB7lN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730684AbgI2Nuk (ORCPT ); Tue, 29 Sep 2020 09:50:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730305AbgI2Nuk (ORCPT ); Tue, 29 Sep 2020 09:50:40 -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 D3C15C061755; Tue, 29 Sep 2020 06:50:38 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id g29so3947424pgl.2; Tue, 29 Sep 2020 06: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=MlXAP9DOdM5rboXZDAHZkt5aNPDNKAGxxdDFS71/fS4=; b=lDgzB7lNyI+d0xcdSiluNMrHmP4y2oKIV2MFbs7Ii4iYESscfh22b7yHwa10pjx8ni 32lw5yGD1+kRryAi6ncuDprEd8XWj0Uuks8NRlXL+rrYzyHS9bYeVjjKbSn0QPY3sdGP JRSQPPC3QOfPQJ+RU1CISPY1ZCI3sneL4csq7g4OdC55vB15VXW55szme0jN1H2N53cf 92biVcIUa9KK0r0jfoMrAuqREvVog/Zbejts/LpxyJmqrEMPJysX2H9cN5doS4aKxe0S QXaEuOIPhoSK3umO2J5tAXJHNZInQB8MWuR+jPpJLj15KxLOT6k/kU3hlQdRRCW7uXTd bZ2w== 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=MlXAP9DOdM5rboXZDAHZkt5aNPDNKAGxxdDFS71/fS4=; b=k1MjdJnAgziUp1AJUX7xUUjYVr/r5aIbgBHUmXnt2c50pmk/E6HXQ4xloQGQ0rSZPD C78qV8EOPMl0/4sLoR7bQSAORRIpE295hfAVt1vvHv2O/TMY5fpY2g1vGVgBlt+LGDh2 Qq/4KXxH+YB7rAGJIjYkzoIKaquL7dBKwtiKCE9cXh6ubcvTnZqieR1uUiuNGi/MJ9Lh qpavQSQp5iq8Snh5e2lFM7xYueVy1vYN3Im2T5Hv5JII70ME5mdH7I8YVyK+j1Mb99+p 62s5DzRFLuAGZf+8WH80jt/7MwNRhoTagBz1vbKqHvhqNwCc3kH83PfowV+ZtljtUjDD wrcQ== X-Gm-Message-State: AOAM533qtzOtsfc9yU41wDh+OMd7AS4ODwjXJ+zPTu3w0D8pFsGgSI6Z y/96tsdXbGvwidn1tjeu/8C7nJycdSA= X-Google-Smtp-Source: ABdhPJyEI0Y3i0yTdvBz17yE7tgfwYfJkXiXi0xwK5FhDMdAIDCSIh+vVHFcb/BpGC4O34EZO43qSg== X-Received: by 2002:a63:482:: with SMTP id 124mr3287061pge.430.1601387437507; Tue, 29 Sep 2020 06:50:37 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id z7sm5931804pfj.75.2020.09.29.06.50.35 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Sep 2020 06:50:36 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , Tom Herbert , davem@davemloft.net Subject: [PATCH net-next 09/15] sctp: add SCTP_REMOTE_UDP_ENCAPS_PORT sockopt Date: Tue, 29 Sep 2020 21:49:01 +0800 Message-Id: X-Mailer: git-send-email 2.1.0 In-Reply-To: References: <51c1fdad515076f3014476711aec1c0a81c18d36.1601387231.git.lucien.xin@gmail.com> <65f713004ab546e0b6ec793572c72c1d0399f0fe.1601387231.git.lucien.xin@gmail.com> <49a1cbb99341f50304b514aeaace078d0b065248.1601387231.git.lucien.xin@gmail.com> <97963ca7171b92486f46477b55928182abe44806.1601387231.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 --- 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 9aa0c3d..d793dfa9 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 Tue Sep 29 13:49: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: 289384 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.7 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 395D7C4727C for ; Tue, 29 Sep 2020 13:50:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CE8652145D for ; Tue, 29 Sep 2020 13:50:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="oAUrpyvY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730687AbgI2Nus (ORCPT ); Tue, 29 Sep 2020 09:50:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729569AbgI2Nus (ORCPT ); Tue, 29 Sep 2020 09:50:48 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAF2EC061755; Tue, 29 Sep 2020 06:50:47 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id k8so4617336pfk.2; Tue, 29 Sep 2020 06:50: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=cgvlbVs7epFjvUB5WJ5L7B/v2IhQIlRIfyZ0mqeKKyg=; b=oAUrpyvYXeiZKm31WZUqeDG7yERUhPuHVXomoAPw29wGT+nTfdK6/s7iU/e6XE8Ox9 hDt0/TmBM09VjK5q2GM3StlkwgkLaMlBJUQ476Cag9riX3ebikcG/OsRNtPsbu6TflWV EdXCtg/sNCAEXesG9cj0NDRI3H8y+4fwIxgsdiIQJmG6/0T+P62d4pdbFpiuhlFiC1pd NQPsTdy+T1NCip8LQzHEjBi+aCFp8McK69N0YYuSVA1So/Smyo6amYeoAdtXPZO2ekox 6AZ7QvpdJLmiTLUGBCwyk9j8M6fK/BcmQctfqiLdGgqY4Vk0qJxnY1Q2CUK7HMTpg4Y7 z6mg== 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=cgvlbVs7epFjvUB5WJ5L7B/v2IhQIlRIfyZ0mqeKKyg=; b=S8L4EQUa9dP36g8VsUPSzJ7F5UgFKrFlzF0yOY2pkjlhLZcEdfAJmQlojU0TCM4+gE JVcK6bwFtIQCrzxB8rpenUHSFhhoAx0I0MHS9qhxUUffS3phXfKzW2wH0Bizlk5OEGTT 893F9i2s2/+zMsBvqsFihHYgqjR9NPzdbO4DMHdRZNPSNvjrVOZg0/l0mI9Lck7qzNCv Ts5fdYn8ybFaoVFhWBoxgOLHYmCkD8rl3u4CbJkPe7O+YsD6Z31ycD4Tu38MSXcradew 949Ilkh7c9YkIv2Z0TK69Wt4PLa+OHF9nRV6egNEWPAx2BV1Rrg+D/3EkZAZigVx7DX7 /JqA== X-Gm-Message-State: AOAM531Lhxq4X2DgPK+jf0uGEsdjmrUZirmOscKyry4g5VG4KxBHebcC ztHr/14JWNp/6DNxBius+RS3O3laQRE= X-Google-Smtp-Source: ABdhPJwqvKD/1UgOIsZc4WviCnIe7LoZuSlxs6EjsmSl/Kq9Wopw0Ehtr5oVfEvBK1UPk39b0OP3Lg== X-Received: by 2002:a65:6685:: with SMTP id b5mr3338537pgw.385.1601387446404; Tue, 29 Sep 2020 06:50:46 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id m12sm4742921pjs.34.2020.09.29.06.50.44 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Sep 2020 06:50:45 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , Tom Herbert , davem@davemloft.net Subject: [PATCH net-next 10/15] sctp: allow changing transport encap_port by peer packets Date: Tue, 29 Sep 2020 21:49:02 +0800 Message-Id: <3f1b88ab88b5cc5321ffe094bcfeff68a3a5ef2c.1601387231.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: References: <51c1fdad515076f3014476711aec1c0a81c18d36.1601387231.git.lucien.xin@gmail.com> <65f713004ab546e0b6ec793572c72c1d0399f0fe.1601387231.git.lucien.xin@gmail.com> <49a1cbb99341f50304b514aeaace078d0b065248.1601387231.git.lucien.xin@gmail.com> <97963ca7171b92486f46477b55928182abe44806.1601387231.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 temparory transport for the reply pkt. Note that sctp_input_cb->header is removed, as it's not used any more in sctp. 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 b6d0e58..8819214 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; + __u16 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 8b788bd..c73fd5f 100644 --- a/net/sctp/protocol.c +++ b/net/sctp/protocol.c @@ -842,6 +842,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 = ntohs(udp_hdr(skb)->source); + skb_set_transport_header(skb, sizeof(struct udphdr)); sctp_rcv(skb); return 0; @@ -1133,9 +1136,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 Tue Sep 29 13:49: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: 259928 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.7 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 BF0DCC4727D for ; Tue, 29 Sep 2020 13:50:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6311620848 for ; Tue, 29 Sep 2020 13:50:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="S9mj+8ve" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730711AbgI2Nu4 (ORCPT ); Tue, 29 Sep 2020 09:50:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729351AbgI2Nu4 (ORCPT ); Tue, 29 Sep 2020 09:50:56 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22346C061755; Tue, 29 Sep 2020 06:50:56 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id 7so3918392pgm.11; Tue, 29 Sep 2020 06:50:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=+wk7LoqYbQetQmR+hUJz4dTqK7qk9HGpsFOcpBKxn78=; b=S9mj+8ve0KZHeSRdDA4NmfnitNx12B6I2bf5xAelUSUVnZEcbbryncmGxAcMXelZmM K0ESMhAb+m05Yg71qQ9mWI/IGr3YQ2+wTvBAqvyK2BumgzXJyM/iexEKtsXVTqwOupJX uw6GJqpOrMwZwBzTli7u3vn7gUyyUNIigVqB0B27S61oL87iPCxDvOdBjkJdWXLFtzMh weXc38YF3eZah/KqIormfppwsyygnC+ZpAB4L8JyIy0Jq30lgkki/Vrruukg0bmUmr6M wuhr+vpHzrPP/v6QoHT59srfUkshZuSRLpEkELKgf1se9L0TlNlOZrBVbgDMTnp5X3wf PX7w== 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=+wk7LoqYbQetQmR+hUJz4dTqK7qk9HGpsFOcpBKxn78=; b=ojJt2mGt37OTKhBE1QKKphy4+WgijwHJlAoscsmmqJRVZ/aW7WjiwSMdUYI4SFajwN UurMrePvPlxC5qLknNPhHTbC3WOKe5N7b3dJxzFmqcZQ/je2q/rSusnlE0vq+R3fNIQL V5B0jX88npFdc1DRPj1DwDWM75gfrvmcjreJ62xUuVYiqWtoPN3yFvnIBx8iq++FWvUa KFQIWLdNbvIaacm2zoxwK5VWWjWaNry5BO/iwjNqtcGLFD2Lbv6tBdokUrXqrYQD47H9 tMNoErFFZr2zqmZCbIaHPT31QwAtwFVy9EMWtbzRMJlSn+UpniY5MQnH69Lsw8nn2wMO AAoQ== X-Gm-Message-State: AOAM533R/GJNjHoN2xvL2oklEyACNAC68fNGkEsZn787XDCnXlj3PBbT bnUvPClVZmFxWlOecwb6/X0eK9P/Kb8= X-Google-Smtp-Source: ABdhPJxs7ybb4B1o5EMBKQvlHqrX8y2UYiCCZtFM/TeDqGWhMTydajK+pClFXZwOhV6xXW2HaPrSiQ== X-Received: by 2002:a17:902:c40d:b029:d2:93e8:1f4b with SMTP id k13-20020a170902c40db02900d293e81f4bmr3529034plk.29.1601387455211; Tue, 29 Sep 2020 06:50:55 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id gm17sm4674915pjb.46.2020.09.29.06.50.53 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Sep 2020 06:50:54 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , Tom Herbert , davem@davemloft.net Subject: [PATCH net-next 11/15] sctp: add udphdr to overhead when udp_port is set Date: Tue, 29 Sep 2020 21:49:03 +0800 Message-Id: <7ff312f910ada8893fa4db57d341c628d1122640.1601387231.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <3f1b88ab88b5cc5321ffe094bcfeff68a3a5ef2c.1601387231.git.lucien.xin@gmail.com> References: <51c1fdad515076f3014476711aec1c0a81c18d36.1601387231.git.lucien.xin@gmail.com> <65f713004ab546e0b6ec793572c72c1d0399f0fe.1601387231.git.lucien.xin@gmail.com> <49a1cbb99341f50304b514aeaace078d0b065248.1601387231.git.lucien.xin@gmail.com> <97963ca7171b92486f46477b55928182abe44806.1601387231.git.lucien.xin@gmail.com> <3f1b88ab88b5cc5321ffe094bcfeff68a3a5ef2c.1601387231.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 handling 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 requires. Signed-off-by: Xin Long Reported-by: kernel test robot --- include/net/sctp/sctp.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h index bfd87a0..6408bbb 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 (sock_net(&sp->inet.sk)->sctp.udp_port) + overhead += sizeof(struct udphdr); + } else { overhead += sizeof(struct ipv6hdr); + } if (WARN_ON_ONCE(mtu && mtu <= overhead)) mtu = overhead; From patchwork Tue Sep 29 13:49: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: 289383 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.7 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 CFC6EC4727C for ; Tue, 29 Sep 2020 13:51:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 767F42145D for ; Tue, 29 Sep 2020 13:51:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XorZi2p5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730716AbgI2NvH (ORCPT ); Tue, 29 Sep 2020 09:51:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729351AbgI2NvG (ORCPT ); Tue, 29 Sep 2020 09:51:06 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22DFAC061755; Tue, 29 Sep 2020 06:51:05 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id o25so3954911pgm.0; Tue, 29 Sep 2020 06:51:05 -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=g1NOLKpd2hSWg3tMRG0Q+HZFXyCwBYbuga7haroPsDs=; b=XorZi2p5oIwFQmiJxYwTHsuPrZY4roo1m23TLllF0H+IQwrgPU2uh8A0+BoyNFCCf8 gfwAKsgW2ALMP8/ie5f/9IeyWqotvnMPH95S7YPZRciuHi5aKQ2iuh8KLkfWsQFHdPsv YTq+sVCYUwqwajEPJbKR3WGtTg7MbnfzFsxZffpWFJ3nWHxYZC9jjlYZNBrIu6h3IC4t MiLKjdVQcLSm90RjOesxss28YBOE7q0JseB4tGb9keObWXbiMHDCQN8j2uXrM263kz8n CCtbE957keP9O/isoGv/SSIOnGprlVoC1GVKcm7DIwwR63rxD314hUTIHWrEWBadthhZ dttw== 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=g1NOLKpd2hSWg3tMRG0Q+HZFXyCwBYbuga7haroPsDs=; b=r9lSkaITtbkSIOpN+r6ziYBM8hFXtO+Kxtk0djbVT/M3HuYFwOrcRvCoqSAXW8gIRa sWaldT7KQ7ABEhb697Ro+eopCmjGXU8KkTRcEnOP2Vp5cYxKJAYqzP1fXjJHDOfeNDyq kH03ElP08UVomvDPKrA9GZHhMNgZuZLnY0NnM7dosTDGKk2JRH8bT4IMxt+uWkwCAjij Z1QjcM3so1o4q0Q57SMzUxIIuMQeGOpRSDJpoiI/T4nbAixX9kBMeTp4Gv5A3YVKjtzM HoIlLI0Ox7C/amT6W1SUe6UdEWbk8mz5/5KNVmCGBWr4ohHjzuGBsO4Dvno2V8qXKGEp 3wOA== X-Gm-Message-State: AOAM530yXlFqs9aejoYA/rMRNlndE99fyDSQsNVeZTgM+1dmrmn79GbT sU5VnejSh9FOaBuvCeTD+NBhnfVt9Ow= X-Google-Smtp-Source: ABdhPJxRK1bUg9FsFhuQdYcDUmMsf0epxcYJZnhAWuTh7MZ+zKLmPzB69SrRIrXt9UmloWqVss9bAQ== X-Received: by 2002:a63:5916:: with SMTP id n22mr3227723pgb.375.1601387464002; Tue, 29 Sep 2020 06:51:04 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id q10sm4946233pja.48.2020.09.29.06.51.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Sep 2020 06:51:03 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , Tom Herbert , davem@davemloft.net Subject: [PATCH net-next 12/15] sctp: call sk_setup_caps in sctp_packet_transmit instead Date: Tue, 29 Sep 2020 21:49:04 +0800 Message-Id: <3716fc0699dc1d5557574b5227524e80b7fd76b8.1601387231.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <7ff312f910ada8893fa4db57d341c628d1122640.1601387231.git.lucien.xin@gmail.com> References: <51c1fdad515076f3014476711aec1c0a81c18d36.1601387231.git.lucien.xin@gmail.com> <65f713004ab546e0b6ec793572c72c1d0399f0fe.1601387231.git.lucien.xin@gmail.com> <49a1cbb99341f50304b514aeaace078d0b065248.1601387231.git.lucien.xin@gmail.com> <97963ca7171b92486f46477b55928182abe44806.1601387231.git.lucien.xin@gmail.com> <3f1b88ab88b5cc5321ffe094bcfeff68a3a5ef2c.1601387231.git.lucien.xin@gmail.com> <7ff312f910ada8893fa4db57d341c628d1122640.1601387231.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 gso related, 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 Tue Sep 29 13:49: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: 259927 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.7 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 CA141C4727C for ; Tue, 29 Sep 2020 13:51:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6BAF620848 for ; Tue, 29 Sep 2020 13:51:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RZpXdv70" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730737AbgI2NvP (ORCPT ); Tue, 29 Sep 2020 09:51:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728367AbgI2NvO (ORCPT ); Tue, 29 Sep 2020 09:51:14 -0400 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65D50C061755; Tue, 29 Sep 2020 06:51:14 -0700 (PDT) Received: by mail-pg1-x52d.google.com with SMTP id m34so3923537pgl.9; Tue, 29 Sep 2020 06:51:14 -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=LWCnKF/kWpp/dptz5TkNnN2Y7xpvkvQgK3bz/gbHONU=; b=RZpXdv70OdevhnZIg65FmoEr6pmi0oNt8Khu/oMjTdz3ZbHztPAxgE8Oc+GfboE1V1 fFjhjtBSoHEKkQu0wHALC0W3X6GSsv8gdAcexju8uyxWj3hVPhsWc1vYJtRfnTB3Tzhx uc+WEn+fe+MdJUiFaa7trOQE1n/nwNtkPCy/24ZcXclBRCVL+av/EZCQfK+aEa8j7ykI 34e3N5vN8032yn4NX5jlFL6lz9yE2zrIuJ6fWESH6j80aYyrDpIFxsH9TQGa04zXZgf4 WTa1s2sEyohunXSCmdVggK8X0ujkv87T5SUDNJXpwbS0PAPKBHvazGSZ0nHLBNy4ltV1 KEbQ== 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=LWCnKF/kWpp/dptz5TkNnN2Y7xpvkvQgK3bz/gbHONU=; b=WHnCqs7DI4mO3Hn6Gyek5rH/qP40y4UvO+q8WTvNGN8qR3Ud3mRH+SEoDIa9jLWh/x p3y+TYR25rZ/YfvLBmjq+BMB1MZT01eKSV1oV/T1k3pRNSARpqwXNhJ/TGNNSvzXdPY8 6J4ai6QWktc3eiMlrrN59Ko+HU+FP59BsyaXkblTKHPsWmOupOFWJKcsaJ3Nx90VdZMI JNxp4LQFyK4yCOiX8EDWx62Y4CiiveePxbuGWiizOEZbZIfvIm/5PrwKpMaET5ay1pIN Dy6K7RnJyEj9KHsH+1BeAF0MnrHufGpz9FNTs3ot3eoLLrLkK3gvjUAmv0XQo/ml2PKA 1eCg== X-Gm-Message-State: AOAM532Qx1xRhFSKX7FHQcZmNmaE+2wYEG1h+wrfHSuKC0ez/M9UdNi4 6Kzihye0XIu1wNDGsX2nLC85vJJjRq0= X-Google-Smtp-Source: ABdhPJzNRN4v98sXKwBQOXXSprZmPsID3kxRLkiQkVclNe3YSAKxJ6/kCoaAv2qvRXHPy9NNtYxLCw== X-Received: by 2002:a62:b40c:0:b029:142:6a8f:c2f8 with SMTP id h12-20020a62b40c0000b02901426a8fc2f8mr4274873pfn.32.1601387473158; Tue, 29 Sep 2020 06:51:13 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id 137sm5726474pfb.183.2020.09.29.06.51.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Sep 2020 06:51:12 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , Tom Herbert , davem@davemloft.net Subject: [PATCH net-next 13/15] sctp: support for sending packet over udp4 sock Date: Tue, 29 Sep 2020 21:49:05 +0800 Message-Id: <82b358f40c81cfdecbfc394113be40fd1f682043.1601387231.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <3716fc0699dc1d5557574b5227524e80b7fd76b8.1601387231.git.lucien.xin@gmail.com> References: <51c1fdad515076f3014476711aec1c0a81c18d36.1601387231.git.lucien.xin@gmail.com> <65f713004ab546e0b6ec793572c72c1d0399f0fe.1601387231.git.lucien.xin@gmail.com> <49a1cbb99341f50304b514aeaace078d0b065248.1601387231.git.lucien.xin@gmail.com> <97963ca7171b92486f46477b55928182abe44806.1601387231.git.lucien.xin@gmail.com> <3f1b88ab88b5cc5321ffe094bcfeff68a3a5ef2c.1601387231.git.lucien.xin@gmail.com> <7ff312f910ada8893fa4db57d341c628d1122640.1601387231.git.lucien.xin@gmail.com> <3716fc0699dc1d5557574b5227524e80b7fd76b8.1601387231.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. Signed-off-by: Xin Long Reported-by: kernel test robot Reported-by: kernel test robot --- net/sctp/output.c | 9 +++------ net/sctp/protocol.c | 44 +++++++++++++++++++++++++++++++++----------- 2 files changed, 36 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 c73fd5f..6606a63 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) @@ -1053,25 +1054,46 @@ 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); + struct net *net = sock_net(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(net, SCTP_MIB_OUTSCTPPACKS); - inet->pmtudisc = transport->param_flags & SPP_PMTUD_ENABLE ? - IP_PMTUDISC_DO : IP_PMTUDISC_DONT; + if (!t->encap_port || !net->sctp.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, + htons(net->sctp.udp_port), htons(t->encap_port), + false, false); + return 0; } static struct sctp_af sctp_af_inet; From patchwork Tue Sep 29 13:49: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: 289382 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.7 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 043EAC4727C for ; Tue, 29 Sep 2020 13:51:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 98FD520848 for ; Tue, 29 Sep 2020 13:51:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fFucPKxS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730763AbgI2NvY (ORCPT ); Tue, 29 Sep 2020 09:51:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728367AbgI2NvY (ORCPT ); Tue, 29 Sep 2020 09:51:24 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1741C061755; Tue, 29 Sep 2020 06:51:23 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id a9so2711321pjg.1; Tue, 29 Sep 2020 06:51:23 -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=OHJXMkcYNxQ8jVivOpoiy0ndt2mH0O/0WP8+Tt4Q51o=; b=fFucPKxSCAwk2Uh0M/DsQImF07xfmlUNmbZ67rTyRZ6Mcex/afmC9AftphuwLc5cBX KNTYTTCuFtWRK0gZeJxXG+DZIw/wSYmBySO/TtLrt+nGjsWSQMKojfrGWJH132Ndf70L Ml+KiNcq2EW87DNxMHu+WmKjU2NTy/t1xPeZJ1XDb3r9sClWRG7cnn8ItZ9onuYNB3Lz /l31i9A9Sw7O7MLfFZ2VxqaEr5Z+LN/A6MFUc3lfjwTrWpbrOM8beLNel0fTfLM2cRT9 8TwZ9WyQyo3JKSwVuRFD3g8wzWTMBmwPyK0XVzXap3GZq5tlOAcSB2hE0mV/kHDnPbAe 0g0Q== 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=OHJXMkcYNxQ8jVivOpoiy0ndt2mH0O/0WP8+Tt4Q51o=; b=ZiXrDNkC+1ERHnVl2im8rSyWVjz+jtCaVB2WsxsMWKEOaDr64uhG55RnG8LYQCxdxk xIZSnZPnCFGNkMWXytlX6eWeoceXtKJ3Szmumk45sYuFRCeU5DkN/zinIKQ+0q0poPaU 8Id46iOrUqIq6WWzbi6CXu3ln81bU0qWY5yhUt2mtJ1Q95U44D7Qt4fg/63aalaoiyr8 yUfqDc+n1KRhdfLr2dBMcfPsFKg7ZiMRiipVgARbrgdQcnnfGo9QjjG7dhQbc+FrqIQr CwTVjjM+RCf5qaitm5B/CH+XM+2PPjUaIiPes41bn+Y6ksd4GnRZE13IaokbboJC1pi4 /x3Q== X-Gm-Message-State: AOAM533rNRk0UGKEPTyc15fNUmk1NVef7CIRaikUZYMY7YpwvbdL85p2 OtgqfZhss/7bJ62JgAOGAK9A5B9m/eI= X-Google-Smtp-Source: ABdhPJzFW1MLgb5nfCYumfjnRi2q5qd2wBH+sAHBcD5BRJOFiMkrsjQoIUoTTVfXJ7Y2wHbwD1eqAg== X-Received: by 2002:a17:90a:8588:: with SMTP id m8mr3828792pjn.91.1601387482534; Tue, 29 Sep 2020 06:51:22 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id u2sm4905725pji.50.2020.09.29.06.51.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Sep 2020 06:51:21 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , Tom Herbert , davem@davemloft.net Subject: [PATCH net-next 14/15] sctp: support for sending packet over udp6 sock Date: Tue, 29 Sep 2020 21:49:06 +0800 Message-Id: <6388faf30ca428c5026e5a62fdf484dcad7e0da2.1601387231.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <82b358f40c81cfdecbfc394113be40fd1f682043.1601387231.git.lucien.xin@gmail.com> References: <51c1fdad515076f3014476711aec1c0a81c18d36.1601387231.git.lucien.xin@gmail.com> <65f713004ab546e0b6ec793572c72c1d0399f0fe.1601387231.git.lucien.xin@gmail.com> <49a1cbb99341f50304b514aeaace078d0b065248.1601387231.git.lucien.xin@gmail.com> <97963ca7171b92486f46477b55928182abe44806.1601387231.git.lucien.xin@gmail.com> <3f1b88ab88b5cc5321ffe094bcfeff68a3a5ef2c.1601387231.git.lucien.xin@gmail.com> <7ff312f910ada8893fa4db57d341c628d1122640.1601387231.git.lucien.xin@gmail.com> <3716fc0699dc1d5557574b5227524e80b7fd76b8.1601387231.git.lucien.xin@gmail.com> <82b358f40c81cfdecbfc394113be40fd1f682043.1601387231.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. Signed-off-by: Xin Long --- net/sctp/ipv6.c | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c index a064bf2..5c831f3 100644 --- a/net/sctp/ipv6.c +++ b/net/sctp/ipv6.c @@ -55,6 +55,7 @@ #include #include #include +#include #include @@ -191,33 +192,55 @@ 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; + struct net *net = sock_net(sk); __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); + SCTP_INC_STATS(net, 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 || !net->sctp.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(net, skb, fl6->flowlabel, true, fl6); + + return udp_tunnel6_xmit_skb(dst, sk, skb, NULL, &fl6->saddr, + &fl6->daddr, tclass, ip6_dst_hoplimit(dst), + label, htons(net->sctp.udp_port), + htons(t->encap_port), false); } /* Returns the dst cache entry for the given source and destination ip From patchwork Tue Sep 29 13:49: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: 259926 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.7 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 8D0D5C4741F for ; Tue, 29 Sep 2020 13:51:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2819B207C4 for ; Tue, 29 Sep 2020 13:51:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AJI/5BMB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730775AbgI2Nvd (ORCPT ); Tue, 29 Sep 2020 09:51:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728367AbgI2Nvc (ORCPT ); Tue, 29 Sep 2020 09:51:32 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1115C061755; Tue, 29 Sep 2020 06:51:32 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id l126so4611395pfd.5; Tue, 29 Sep 2020 06:51:32 -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=nNboYdcjgXYzO6CmiDQoSlJrRKhaen2l7njFPVpXSdw=; b=AJI/5BMBLKoLLOvEbIGCw3Eom/0PjNKR2j2HM4TZHNlrMi6fRBCeyc7kjJIIT1eB8S r5SPndHtiADwGn2nK69FZ8mBmZ0rQpNke+lznOLn+YkZV2ZHj3XdLdLqAIeAWqaHh3l2 nF45FmLyklGo8i31F3n1Kc4Ens5ARmSVm8lN0xuIn5KCxvF4h7aleBD8UjFKCNKZqyOo T50OBYGIp2jYVXPg6hlEzOL4U5ZehbwEboG2dgOu6C680bTs/nzBExunxG261u7DiRNZ KOO5DZJEL+V/b/ymOAWe1HEozl3wpzrclOU4NFJuLzhG9opqiFcJ9nJh06xoPrOWRhtm 1w6g== 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=nNboYdcjgXYzO6CmiDQoSlJrRKhaen2l7njFPVpXSdw=; b=QCIWg+S4MNugohTYdFdLYgT+g1IaKD2uJftoSzYqXoZVro0WDFMS2MwU+Hu/Bjj0b3 7JLsgZ3DcQTB7U7aVWiOFRV1A+Co7QEqbKKkOJrTy7BlvA0Cg7QTk47ehblsHyBCVdae qe/cEwMHUOWPERhsDsCucHiF4FOgr5zIncc9aPle3VpCEu59bYgflF1r4Um8XpmMEqzI bPko/kAaQvsePeNir2bmFdY3B3ZVXf2WAwzeP6dFGy1o/0KHnePR090EjEZj6GU/T+/k 0UaKKhDVPRJu5qTw8HQslrawaGaFPg82C4JUdyTe0B5rH3dNzbDIKcemhXtv4Dg9qT75 Pp/w== X-Gm-Message-State: AOAM531kPZyJ0zlUxv4CrTn9PWJlenxx1Wwb9jvDfHEKqLZQejX8V3mR 2QXB3neoOHV3nsaUbPnQ1VGqJcFqXpk= X-Google-Smtp-Source: ABdhPJxwDwVVlTaIr9qDocdrRgAs5OKZpJ+sgIUWMaASSyJjoYxXWoBsAh+jSlVpLy81pE4/HSsEBg== X-Received: by 2002:a63:4404:: with SMTP id r4mr3090099pga.29.1601387491523; Tue, 29 Sep 2020 06:51:31 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id j11sm2138991pji.31.2020.09.29.06.51.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Sep 2020 06:51:30 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Neil Horman , Michael Tuexen , Tom Herbert , davem@davemloft.net Subject: [PATCH net-next 15/15] sctp: enable udp tunneling socks Date: Tue, 29 Sep 2020 21:49:07 +0800 Message-Id: <780b235b6b4446f77cfcf167ba797ce1ae507cf1.1601387231.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <6388faf30ca428c5026e5a62fdf484dcad7e0da2.1601387231.git.lucien.xin@gmail.com> References: <51c1fdad515076f3014476711aec1c0a81c18d36.1601387231.git.lucien.xin@gmail.com> <65f713004ab546e0b6ec793572c72c1d0399f0fe.1601387231.git.lucien.xin@gmail.com> <49a1cbb99341f50304b514aeaace078d0b065248.1601387231.git.lucien.xin@gmail.com> <97963ca7171b92486f46477b55928182abe44806.1601387231.git.lucien.xin@gmail.com> <3f1b88ab88b5cc5321ffe094bcfeff68a3a5ef2c.1601387231.git.lucien.xin@gmail.com> <7ff312f910ada8893fa4db57d341c628d1122640.1601387231.git.lucien.xin@gmail.com> <3716fc0699dc1d5557574b5227524e80b7fd76b8.1601387231.git.lucien.xin@gmail.com> <82b358f40c81cfdecbfc394113be40fd1f682043.1601387231.git.lucien.xin@gmail.com> <6388faf30ca428c5026e5a62fdf484dcad7e0da2.1601387231.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. Signed-off-by: Xin Long --- net/sctp/protocol.c | 5 +++++ net/sctp/sysctl.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c index 6606a63..4b63883 100644 --- a/net/sctp/protocol.c +++ b/net/sctp/protocol.c @@ -1466,6 +1466,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; } @@ -1473,6 +1477,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..7afe904 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,38 @@ 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) { + 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; + } + + return ret; +} + int sctp_sysctl_net_register(struct net *net) { struct ctl_table *table;