linux-sctp.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv2 net-next 00/17] sctp: Implement RFC6951: UDP Encapsulation of SCTP
@ 2020-10-08  9:47 Xin Long
  2020-10-08  9:47 ` Xin Long
  2020-10-08  9:47 ` [PATCHv2 net-next 01/17] udp: check udp sock encap_type in __udp_lib_err Xin Long
  0 siblings, 2 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:47 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

Description From the RFC:

   The Main Reasons:

   o  To allow SCTP traffic to pass through legacy NATs, which do not
      provide native SCTP support as specified in [BEHAVE] and
      [NATSUPP].

   o  To allow SCTP to be implemented on hosts that do not provide
      direct access to the IP layer.  In particular, applications can
      use their own SCTP implementation if the operating system does not
      provide one.

   Implementation Notes:

   UDP-encapsulated SCTP is normally communicated between SCTP stacks
   using the IANA-assigned UDP port number 9899 (sctp-tunneling) on both
   ends.  There are circumstances where other ports may be used on
   either end, and it might be required to use ports other than the
   registered port.

   Each SCTP stack uses a single local UDP encapsulation port number as
   the destination port for all its incoming SCTP packets, this greatly
   simplifies implementation design.

   An SCTP implementation supporting UDP encapsulation MUST maintain a
   remote UDP encapsulation port number per destination address for each
   SCTP association.  Again, because the remote stack may be using ports
   other than the well-known port, each port may be different from each
   stack.  However, because of remapping of ports by NATs, the remote
   ports associated with different remote IP addresses may not be
   identical, even if they are associated with the same stack.

   Because the well-known port might not be used, implementations need
   to allow other port numbers to be specified as a local or remote UDP
   encapsulation port number through APIs.

Patches:

   This patchset is using the udp4/6 tunnel APIs to implement the UDP
   Encapsulation of SCTP with not much change in SCTP protocol stack
   and with all current SCTP features keeped in Linux Kernel.

   1 - 4: Fix some UDP issues that may be triggered by SCTP over UDP.
   5 - 7: Process incoming UDP encapsulated packets and ICMP packets.
   8 -10: Remote encap port's update by sysctl, sockopt and packets.
   11-14: Process outgoing pakects with UDP encapsulated and its GSO.
   15-16: Add the part from draft-tuexen-tsvwg-sctp-udp-encaps-cons-03.
      17: Enable this feature.

Tests:

  - lksctp-tools/src/func_tests with UDP Encapsulation enabled/disabled:

      Both make v4test and v6test passed.

  - sctp-tests with UDP Encapsulation enabled/disabled:

      repeatability/procdumps/sctpdiag/gsomtuchange/extoverflow/
      sctphashtable passed. Others failed as expected due to those
      "iptables -p sctp" rules.

  - netperf on lo/netns/virtio_net, with gso enabled/disabled and
    with ip_checksum enabled/disabled, with UDP Encapsulation
    enabled/disabled:

      No clear performance dropped.

v1->v2:
  - Fix some incorrect code in the patches 5,6,8,10,11,13,14,17, suggested
    by Marcelo.
  - Append two patches 15-16 to add the Additional Considerations for UDP
    Encapsulation of SCTP from draft-tuexen-tsvwg-sctp-udp-encaps-cons-03,
    noticed by Michael.

Xin Long (17):
  udp: check udp sock encap_type in __udp_lib_err
  udp6: move the mss check after udp gso tunnel processing
  udp: do checksum properly in skb_udp_tunnel_segment
  udp: support sctp over udp in skb_udp_tunnel_segment
  sctp: create udp4 sock and add its encap_rcv
  sctp: create udp6 sock and set its encap_rcv
  sctp: add encap_err_lookup for udp encap socks
  sctp: add encap_port for netns sock asoc and transport
  sctp: add SCTP_REMOTE_UDP_ENCAPS_PORT sockopt
  sctp: allow changing transport encap_port by peer packets
  sctp: add udphdr to overhead when udp_port is set
  sctp: call sk_setup_caps in sctp_packet_transmit instead
  sctp: support for sending packet over udp4 sock
  sctp: support for sending packet over udp6 sock
  sctp: add the error cause for new encapsulation port restart
  sctp: handle the init chunk matching an existing asoc
  sctp: enable udp tunneling socks

 include/linux/sctp.h         |  20 ++++++
 include/net/netns/sctp.h     |   8 +++
 include/net/sctp/constants.h |   2 +
 include/net/sctp/sctp.h      |   9 ++-
 include/net/sctp/sm.h        |   4 ++
 include/net/sctp/structs.h   |  14 ++--
 include/uapi/linux/sctp.h    |   7 ++
 net/ipv4/udp.c               |   2 +-
 net/ipv4/udp_offload.c       |  16 +++--
 net/ipv6/udp.c               |   2 +-
 net/ipv6/udp_offload.c       | 154 +++++++++++++++++++++----------------------
 net/sctp/associola.c         |   4 ++
 net/sctp/ipv6.c              |  44 +++++++++----
 net/sctp/output.c            |  22 +++----
 net/sctp/protocol.c          | 148 +++++++++++++++++++++++++++++++++++++----
 net/sctp/sm_make_chunk.c     |  21 ++++++
 net/sctp/sm_statefuns.c      |  52 +++++++++++++++
 net/sctp/socket.c            | 112 +++++++++++++++++++++++++++++++
 net/sctp/sysctl.c            |  59 +++++++++++++++++
 19 files changed, 572 insertions(+), 128 deletions(-)

-- 
2.1.0

^ permalink raw reply	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 00/17] sctp: Implement RFC6951: UDP Encapsulation of SCTP
  2020-10-08  9:47 [PATCHv2 net-next 00/17] sctp: Implement RFC6951: UDP Encapsulation of SCTP Xin Long
@ 2020-10-08  9:47 ` Xin Long
  2020-10-08  9:47 ` [PATCHv2 net-next 01/17] udp: check udp sock encap_type in __udp_lib_err Xin Long
  1 sibling, 0 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:47 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

Description From the RFC:

   The Main Reasons:

   o  To allow SCTP traffic to pass through legacy NATs, which do not
      provide native SCTP support as specified in [BEHAVE] and
      [NATSUPP].

   o  To allow SCTP to be implemented on hosts that do not provide
      direct access to the IP layer.  In particular, applications can
      use their own SCTP implementation if the operating system does not
      provide one.

   Implementation Notes:

   UDP-encapsulated SCTP is normally communicated between SCTP stacks
   using the IANA-assigned UDP port number 9899 (sctp-tunneling) on both
   ends.  There are circumstances where other ports may be used on
   either end, and it might be required to use ports other than the
   registered port.

   Each SCTP stack uses a single local UDP encapsulation port number as
   the destination port for all its incoming SCTP packets, this greatly
   simplifies implementation design.

   An SCTP implementation supporting UDP encapsulation MUST maintain a
   remote UDP encapsulation port number per destination address for each
   SCTP association.  Again, because the remote stack may be using ports
   other than the well-known port, each port may be different from each
   stack.  However, because of remapping of ports by NATs, the remote
   ports associated with different remote IP addresses may not be
   identical, even if they are associated with the same stack.

   Because the well-known port might not be used, implementations need
   to allow other port numbers to be specified as a local or remote UDP
   encapsulation port number through APIs.

Patches:

   This patchset is using the udp4/6 tunnel APIs to implement the UDP
   Encapsulation of SCTP with not much change in SCTP protocol stack
   and with all current SCTP features keeped in Linux Kernel.

   1 - 4: Fix some UDP issues that may be triggered by SCTP over UDP.
   5 - 7: Process incoming UDP encapsulated packets and ICMP packets.
   8 -10: Remote encap port's update by sysctl, sockopt and packets.
   11-14: Process outgoing pakects with UDP encapsulated and its GSO.
   15-16: Add the part from draft-tuexen-tsvwg-sctp-udp-encaps-cons-03.
      17: Enable this feature.

Tests:

  - lksctp-tools/src/func_tests with UDP Encapsulation enabled/disabled:

      Both make v4test and v6test passed.

  - sctp-tests with UDP Encapsulation enabled/disabled:

      repeatability/procdumps/sctpdiag/gsomtuchange/extoverflow/
      sctphashtable passed. Others failed as expected due to those
      "iptables -p sctp" rules.

  - netperf on lo/netns/virtio_net, with gso enabled/disabled and
    with ip_checksum enabled/disabled, with UDP Encapsulation
    enabled/disabled:

      No clear performance dropped.

v1->v2:
  - Fix some incorrect code in the patches 5,6,8,10,11,13,14,17, suggested
    by Marcelo.
  - Append two patches 15-16 to add the Additional Considerations for UDP
    Encapsulation of SCTP from draft-tuexen-tsvwg-sctp-udp-encaps-cons-03,
    noticed by Michael.

Xin Long (17):
  udp: check udp sock encap_type in __udp_lib_err
  udp6: move the mss check after udp gso tunnel processing
  udp: do checksum properly in skb_udp_tunnel_segment
  udp: support sctp over udp in skb_udp_tunnel_segment
  sctp: create udp4 sock and add its encap_rcv
  sctp: create udp6 sock and set its encap_rcv
  sctp: add encap_err_lookup for udp encap socks
  sctp: add encap_port for netns sock asoc and transport
  sctp: add SCTP_REMOTE_UDP_ENCAPS_PORT sockopt
  sctp: allow changing transport encap_port by peer packets
  sctp: add udphdr to overhead when udp_port is set
  sctp: call sk_setup_caps in sctp_packet_transmit instead
  sctp: support for sending packet over udp4 sock
  sctp: support for sending packet over udp6 sock
  sctp: add the error cause for new encapsulation port restart
  sctp: handle the init chunk matching an existing asoc
  sctp: enable udp tunneling socks

 include/linux/sctp.h         |  20 ++++++
 include/net/netns/sctp.h     |   8 +++
 include/net/sctp/constants.h |   2 +
 include/net/sctp/sctp.h      |   9 ++-
 include/net/sctp/sm.h        |   4 ++
 include/net/sctp/structs.h   |  14 ++--
 include/uapi/linux/sctp.h    |   7 ++
 net/ipv4/udp.c               |   2 +-
 net/ipv4/udp_offload.c       |  16 +++--
 net/ipv6/udp.c               |   2 +-
 net/ipv6/udp_offload.c       | 154 +++++++++++++++++++++----------------------
 net/sctp/associola.c         |   4 ++
 net/sctp/ipv6.c              |  44 +++++++++----
 net/sctp/output.c            |  22 +++----
 net/sctp/protocol.c          | 148 +++++++++++++++++++++++++++++++++++++----
 net/sctp/sm_make_chunk.c     |  21 ++++++
 net/sctp/sm_statefuns.c      |  52 +++++++++++++++
 net/sctp/socket.c            | 112 +++++++++++++++++++++++++++++++
 net/sctp/sysctl.c            |  59 +++++++++++++++++
 19 files changed, 572 insertions(+), 128 deletions(-)

-- 
2.1.0


^ permalink raw reply	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 01/17] udp: check udp sock encap_type in __udp_lib_err
  2020-10-08  9:47 [PATCHv2 net-next 00/17] sctp: Implement RFC6951: UDP Encapsulation of SCTP Xin Long
  2020-10-08  9:47 ` Xin Long
@ 2020-10-08  9:47 ` Xin Long
  2020-10-08  9:47   ` Xin Long
  2020-10-08  9:47   ` [PATCHv2 net-next 02/17] udp6: move the mss check after udp gso tunnel processing Xin Long
  1 sibling, 2 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:47 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

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 <lucien.xin@gmail.com>
---
 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)) {
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 01/17] udp: check udp sock encap_type in __udp_lib_err
  2020-10-08  9:47 ` [PATCHv2 net-next 01/17] udp: check udp sock encap_type in __udp_lib_err Xin Long
@ 2020-10-08  9:47   ` Xin Long
  2020-10-08  9:47   ` [PATCHv2 net-next 02/17] udp6: move the mss check after udp gso tunnel processing Xin Long
  1 sibling, 0 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:47 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

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 <lucien.xin@gmail.com>
---
 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)) {
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 02/17] udp6: move the mss check after udp gso tunnel processing
  2020-10-08  9:47 ` [PATCHv2 net-next 01/17] udp: check udp sock encap_type in __udp_lib_err Xin Long
  2020-10-08  9:47   ` Xin Long
@ 2020-10-08  9:47   ` Xin Long
  2020-10-08  9:47     ` Xin Long
                       ` (2 more replies)
  1 sibling, 3 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:47 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

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 <lucien.xin@gmail.com>
---
 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;
 }
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 02/17] udp6: move the mss check after udp gso tunnel processing
  2020-10-08  9:47   ` [PATCHv2 net-next 02/17] udp6: move the mss check after udp gso tunnel processing Xin Long
@ 2020-10-08  9:47     ` Xin Long
  2020-10-08  9:47     ` [PATCHv2 net-next 03/17] udp: do checksum properly in skb_udp_tunnel_segment Xin Long
  2020-10-08 12:44     ` [PATCHv2 net-next 02/17] udp6: move the mss check after udp gso tunnel processing Willem de Bruijn
  2 siblings, 0 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:47 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

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 <lucien.xin@gmail.com>
---
 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;
 }
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 03/17] udp: do checksum properly in skb_udp_tunnel_segment
  2020-10-08  9:47   ` [PATCHv2 net-next 02/17] udp6: move the mss check after udp gso tunnel processing Xin Long
  2020-10-08  9:47     ` Xin Long
@ 2020-10-08  9:47     ` Xin Long
  2020-10-08  9:47       ` Xin Long
                         ` (2 more replies)
  2020-10-08 12:44     ` [PATCHv2 net-next 02/17] udp6: move the mss check after udp gso tunnel processing Willem de Bruijn
  2 siblings, 3 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:47 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

This patch fixes two things:

  When skb->ip_summed = CHECKSUM_PARTIAL, skb_checksum_help() should be
  called do the checksum, instead of gso_make_checksum(), which is used
  to do the checksum for current proto after calling skb_segment(), not
  after the inner proto's gso_segment().

  When offload_csum is disabled, the hardware will not do the checksum
  for the current proto, udp. So instead of calling gso_make_checksum(),
  it should calculate checksum for udp itself.

Cc: Tom Herbert <tom@herbertland.com>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 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:
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 03/17] udp: do checksum properly in skb_udp_tunnel_segment
  2020-10-08  9:47     ` [PATCHv2 net-next 03/17] udp: do checksum properly in skb_udp_tunnel_segment Xin Long
@ 2020-10-08  9:47       ` Xin Long
  2020-10-08  9:48       ` [PATCHv2 net-next 04/17] udp: support sctp over udp " Xin Long
  2020-10-08 10:01       ` [PATCHv2 net-next 03/17] udp: do checksum properly " Xin Long
  2 siblings, 0 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:47 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

This patch fixes two things:

  When skb->ip_summed == CHECKSUM_PARTIAL, skb_checksum_help() should be
  called do the checksum, instead of gso_make_checksum(), which is used
  to do the checksum for current proto after calling skb_segment(), not
  after the inner proto's gso_segment().

  When offload_csum is disabled, the hardware will not do the checksum
  for the current proto, udp. So instead of calling gso_make_checksum(),
  it should calculate checksum for udp itself.

Cc: Tom Herbert <tom@herbertland.com>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 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:
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 04/17] udp: support sctp over udp in skb_udp_tunnel_segment
  2020-10-08  9:47     ` [PATCHv2 net-next 03/17] udp: do checksum properly in skb_udp_tunnel_segment Xin Long
  2020-10-08  9:47       ` Xin Long
@ 2020-10-08  9:48       ` Xin Long
  2020-10-08  9:48         ` Xin Long
                           ` (2 more replies)
  2020-10-08 10:01       ` [PATCHv2 net-next 03/17] udp: do checksum properly " Xin Long
  2 siblings, 3 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:48 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

To call sctp_gso_segment() properly in skb_udp_tunnel_segment() for sctp
over udp packets, we need to set transport_header to sctp header. When
skb->ip_summed = CHECKSUM_PARTIAL, skb_crc32c_csum_help() should be
called for the inner sctp packet.

Cc: Tom Herbert <tom@herbertland.com>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 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;
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 04/17] udp: support sctp over udp in skb_udp_tunnel_segment
  2020-10-08  9:48       ` [PATCHv2 net-next 04/17] udp: support sctp over udp " Xin Long
@ 2020-10-08  9:48         ` Xin Long
  2020-10-08  9:48         ` [PATCHv2 net-next 05/17] sctp: create udp4 sock and add its encap_rcv Xin Long
  2020-10-08 10:01         ` [PATCHv2 net-next 04/17] udp: support sctp over udp in skb_udp_tunnel_segment Xin Long
  2 siblings, 0 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:48 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

To call sctp_gso_segment() properly in skb_udp_tunnel_segment() for sctp
over udp packets, we need to set transport_header to sctp header. When
skb->ip_summed == CHECKSUM_PARTIAL, skb_crc32c_csum_help() should be
called for the inner sctp packet.

Cc: Tom Herbert <tom@herbertland.com>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 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;
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 05/17] sctp: create udp4 sock and add its encap_rcv
  2020-10-08  9:48       ` [PATCHv2 net-next 04/17] udp: support sctp over udp " Xin Long
  2020-10-08  9:48         ` Xin Long
@ 2020-10-08  9:48         ` Xin Long
  2020-10-08  9:48           ` Xin Long
                             ` (2 more replies)
  2020-10-08 10:01         ` [PATCHv2 net-next 04/17] udp: support sctp over udp in skb_udp_tunnel_segment Xin Long
  2 siblings, 3 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:48 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

This patch is to add the functions to create/release udp4 sock,
and set the sock's encap_rcv to process the incoming udp encap
sctp packets. In sctp_udp_rcv(), as we can see, all we need to
do is fix the transport header for sctp_rcv(), then it would
implement the part of rfc6951#section-5.4:

  "When an encapsulated packet is received, the UDP header is removed.
   Then, the generic lookup is performed, as done by an SCTP stack
   whenever a packet is received, to find the association for the
   received SCTP packet"

Note that these functions will be called in the last patch of
this patchset when enabling this feature.

v1->v2:
  - Add pr_err() when fails to create udp v4 sock.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 include/net/netns/sctp.h     |  5 +++++
 include/net/sctp/constants.h |  2 ++
 include/net/sctp/sctp.h      |  2 ++
 net/sctp/protocol.c          | 43 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 52 insertions(+)

diff --git a/include/net/netns/sctp.h b/include/net/netns/sctp.h
index d8d02e4..3d10bef 100644
--- a/include/net/netns/sctp.h
+++ b/include/net/netns/sctp.h
@@ -22,6 +22,11 @@ struct netns_sctp {
 	 */
 	struct sock *ctl_sock;
 
+	/* udp tunneling listening sock. */
+	struct sock *udp4_sock;
+	/* udp tunneling listening port. */
+	int udp_port;
+
 	/* This is the global local address list.
 	 * We actively maintain this complete list of addresses on
 	 * the system by catching address add/delete events.
diff --git a/include/net/sctp/constants.h b/include/net/sctp/constants.h
index 122d9e2..b583166 100644
--- a/include/net/sctp/constants.h
+++ b/include/net/sctp/constants.h
@@ -286,6 +286,8 @@ enum { SCTP_MAX_GABS = 16 };
 				 * functions simpler to write.
 				 */
 
+#define SCTP_DEFAULT_UDP_PORT 9899	/* default udp tunneling port */
+
 /* These are the values for pf exposure, UNUSED is to keep compatible with old
  * applications by default.
  */
diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
index 4fc747b..bfd87a0 100644
--- a/include/net/sctp/sctp.h
+++ b/include/net/sctp/sctp.h
@@ -84,6 +84,8 @@ int sctp_copy_local_addr_list(struct net *net, struct sctp_bind_addr *addr,
 struct sctp_pf *sctp_get_pf_specific(sa_family_t family);
 int sctp_register_pf(struct sctp_pf *, sa_family_t);
 void sctp_addr_wq_mgmt(struct net *, struct sctp_sockaddr_entry *, int);
+int sctp_udp_sock_start(struct net *net);
+void sctp_udp_sock_stop(struct net *net);
 
 /*
  * sctp/socket.c
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index 2583323..2b7a3e1 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -44,6 +44,7 @@
 #include <net/addrconf.h>
 #include <net/inet_common.h>
 #include <net/inet_ecn.h>
+#include <net/udp_tunnel.h>
 
 #define MAX_SCTP_PORT_HASH_ENTRIES (64 * 1024)
 
@@ -840,6 +841,45 @@ static int sctp_ctl_sock_init(struct net *net)
 	return 0;
 }
 
+static int sctp_udp_rcv(struct sock *sk, struct sk_buff *skb)
+{
+	skb_set_transport_header(skb, sizeof(struct udphdr));
+	sctp_rcv(skb);
+	return 0;
+}
+
+int sctp_udp_sock_start(struct net *net)
+{
+	struct udp_tunnel_sock_cfg tuncfg = {NULL};
+	struct udp_port_cfg udp_conf = {0};
+	struct socket *sock;
+	int err;
+
+	udp_conf.family = AF_INET;
+	udp_conf.local_ip.s_addr = htonl(INADDR_ANY);
+	udp_conf.local_udp_port = htons(net->sctp.udp_port);
+	err = udp_sock_create(net, &udp_conf, &sock);
+	if (err) {
+		pr_err("Failed to create the SCTP udp tunneling v4 sock\n");
+		return err;
+	}
+
+	tuncfg.encap_type = 1;
+	tuncfg.encap_rcv = sctp_udp_rcv;
+	setup_udp_tunnel_sock(net, sock, &tuncfg);
+	net->sctp.udp4_sock = sock->sk;
+
+	return 0;
+}
+
+void sctp_udp_sock_stop(struct net *net)
+{
+	if (net->sctp.udp4_sock) {
+		udp_tunnel_sock_release(net->sctp.udp4_sock->sk_socket);
+		net->sctp.udp4_sock = NULL;
+	}
+}
+
 /* Register address family specific functions. */
 int sctp_register_af(struct sctp_af *af)
 {
@@ -1271,6 +1311,9 @@ static int __net_init sctp_defaults_init(struct net *net)
 	/* Enable ECN by default. */
 	net->sctp.ecn_enable = 1;
 
+	/* Set udp tunneling listening port to default value */
+	net->sctp.udp_port = SCTP_DEFAULT_UDP_PORT;
+
 	/* Set SCOPE policy to enabled */
 	net->sctp.scope_policy = SCTP_SCOPE_POLICY_ENABLE;
 
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 05/17] sctp: create udp4 sock and add its encap_rcv
  2020-10-08  9:48         ` [PATCHv2 net-next 05/17] sctp: create udp4 sock and add its encap_rcv Xin Long
@ 2020-10-08  9:48           ` Xin Long
  2020-10-08  9:48           ` [PATCHv2 net-next 06/17] sctp: create udp6 sock and set " Xin Long
  2020-10-08 18:29           ` [PATCHv2 net-next 05/17] sctp: create udp4 sock and add " kernel test robot
  2 siblings, 0 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:48 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

This patch is to add the functions to create/release udp4 sock,
and set the sock's encap_rcv to process the incoming udp encap
sctp packets. In sctp_udp_rcv(), as we can see, all we need to
do is fix the transport header for sctp_rcv(), then it would
implement the part of rfc6951#section-5.4:

  "When an encapsulated packet is received, the UDP header is removed.
   Then, the generic lookup is performed, as done by an SCTP stack
   whenever a packet is received, to find the association for the
   received SCTP packet"

Note that these functions will be called in the last patch of
this patchset when enabling this feature.

v1->v2:
  - Add pr_err() when fails to create udp v4 sock.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 include/net/netns/sctp.h     |  5 +++++
 include/net/sctp/constants.h |  2 ++
 include/net/sctp/sctp.h      |  2 ++
 net/sctp/protocol.c          | 43 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 52 insertions(+)

diff --git a/include/net/netns/sctp.h b/include/net/netns/sctp.h
index d8d02e4..3d10bef 100644
--- a/include/net/netns/sctp.h
+++ b/include/net/netns/sctp.h
@@ -22,6 +22,11 @@ struct netns_sctp {
 	 */
 	struct sock *ctl_sock;
 
+	/* udp tunneling listening sock. */
+	struct sock *udp4_sock;
+	/* udp tunneling listening port. */
+	int udp_port;
+
 	/* This is the global local address list.
 	 * We actively maintain this complete list of addresses on
 	 * the system by catching address add/delete events.
diff --git a/include/net/sctp/constants.h b/include/net/sctp/constants.h
index 122d9e2..b583166 100644
--- a/include/net/sctp/constants.h
+++ b/include/net/sctp/constants.h
@@ -286,6 +286,8 @@ enum { SCTP_MAX_GABS = 16 };
 				 * functions simpler to write.
 				 */
 
+#define SCTP_DEFAULT_UDP_PORT 9899	/* default udp tunneling port */
+
 /* These are the values for pf exposure, UNUSED is to keep compatible with old
  * applications by default.
  */
diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
index 4fc747b..bfd87a0 100644
--- a/include/net/sctp/sctp.h
+++ b/include/net/sctp/sctp.h
@@ -84,6 +84,8 @@ int sctp_copy_local_addr_list(struct net *net, struct sctp_bind_addr *addr,
 struct sctp_pf *sctp_get_pf_specific(sa_family_t family);
 int sctp_register_pf(struct sctp_pf *, sa_family_t);
 void sctp_addr_wq_mgmt(struct net *, struct sctp_sockaddr_entry *, int);
+int sctp_udp_sock_start(struct net *net);
+void sctp_udp_sock_stop(struct net *net);
 
 /*
  * sctp/socket.c
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index 2583323..2b7a3e1 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -44,6 +44,7 @@
 #include <net/addrconf.h>
 #include <net/inet_common.h>
 #include <net/inet_ecn.h>
+#include <net/udp_tunnel.h>
 
 #define MAX_SCTP_PORT_HASH_ENTRIES (64 * 1024)
 
@@ -840,6 +841,45 @@ static int sctp_ctl_sock_init(struct net *net)
 	return 0;
 }
 
+static int sctp_udp_rcv(struct sock *sk, struct sk_buff *skb)
+{
+	skb_set_transport_header(skb, sizeof(struct udphdr));
+	sctp_rcv(skb);
+	return 0;
+}
+
+int sctp_udp_sock_start(struct net *net)
+{
+	struct udp_tunnel_sock_cfg tuncfg = {NULL};
+	struct udp_port_cfg udp_conf = {0};
+	struct socket *sock;
+	int err;
+
+	udp_conf.family = AF_INET;
+	udp_conf.local_ip.s_addr = htonl(INADDR_ANY);
+	udp_conf.local_udp_port = htons(net->sctp.udp_port);
+	err = udp_sock_create(net, &udp_conf, &sock);
+	if (err) {
+		pr_err("Failed to create the SCTP udp tunneling v4 sock\n");
+		return err;
+	}
+
+	tuncfg.encap_type = 1;
+	tuncfg.encap_rcv = sctp_udp_rcv;
+	setup_udp_tunnel_sock(net, sock, &tuncfg);
+	net->sctp.udp4_sock = sock->sk;
+
+	return 0;
+}
+
+void sctp_udp_sock_stop(struct net *net)
+{
+	if (net->sctp.udp4_sock) {
+		udp_tunnel_sock_release(net->sctp.udp4_sock->sk_socket);
+		net->sctp.udp4_sock = NULL;
+	}
+}
+
 /* Register address family specific functions. */
 int sctp_register_af(struct sctp_af *af)
 {
@@ -1271,6 +1311,9 @@ static int __net_init sctp_defaults_init(struct net *net)
 	/* Enable ECN by default. */
 	net->sctp.ecn_enable = 1;
 
+	/* Set udp tunneling listening port to default value */
+	net->sctp.udp_port = SCTP_DEFAULT_UDP_PORT;
+
 	/* Set SCOPE policy to enabled */
 	net->sctp.scope_policy = SCTP_SCOPE_POLICY_ENABLE;
 
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 06/17] sctp: create udp6 sock and set its encap_rcv
  2020-10-08  9:48         ` [PATCHv2 net-next 05/17] sctp: create udp4 sock and add its encap_rcv Xin Long
  2020-10-08  9:48           ` Xin Long
@ 2020-10-08  9:48           ` Xin Long
  2020-10-08  9:48             ` Xin Long
                               ` (2 more replies)
  2020-10-08 18:29           ` [PATCHv2 net-next 05/17] sctp: create udp4 sock and add " kernel test robot
  2 siblings, 3 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:48 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

This patch is to add the udp6 sock part in sctp_udp_sock_start/stop().
udp_conf.use_udp6_rx_checksums is set to true, as:

   "The SCTP checksum MUST be computed for IPv4 and IPv6, and the UDP
    checksum SHOULD be computed for IPv4 and IPv6"

says in rfc6951#section-5.3.

v1->v2:
  - Add pr_err() when fails to create udp v6 sock.
  - Add #if IS_ENABLED(CONFIG_IPV6) not to create v6 sock when ipv6 is
    disabled.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 include/net/netns/sctp.h |  1 +
 net/sctp/protocol.c      | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/include/net/netns/sctp.h b/include/net/netns/sctp.h
index 3d10bef..f622945 100644
--- a/include/net/netns/sctp.h
+++ b/include/net/netns/sctp.h
@@ -24,6 +24,7 @@ struct netns_sctp {
 
 	/* udp tunneling listening sock. */
 	struct sock *udp4_sock;
+	struct sock *udp6_sock;
 	/* udp tunneling listening port. */
 	int udp_port;
 
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index 2b7a3e1..49b5d75 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -869,6 +869,28 @@ int sctp_udp_sock_start(struct net *net)
 	setup_udp_tunnel_sock(net, sock, &tuncfg);
 	net->sctp.udp4_sock = sock->sk;
 
+#if IS_ENABLED(CONFIG_IPV6)
+	memset(&udp_conf, 0, sizeof(udp_conf));
+
+	udp_conf.family = AF_INET6;
+	udp_conf.local_ip6 = in6addr_any;
+	udp_conf.local_udp_port = htons(net->sctp.udp_port);
+	udp_conf.use_udp6_rx_checksums = true;
+	udp_conf.ipv6_v6only = true;
+	err = udp_sock_create(net, &udp_conf, &sock);
+	if (err) {
+		pr_err("Failed to create the SCTP udp tunneling v6 sock\n");
+		udp_tunnel_sock_release(net->sctp.udp4_sock->sk_socket);
+		net->sctp.udp4_sock = NULL;
+		return err;
+	}
+
+	tuncfg.encap_type = 1;
+	tuncfg.encap_rcv = sctp_udp_rcv;
+	setup_udp_tunnel_sock(net, sock, &tuncfg);
+	net->sctp.udp6_sock = sock->sk;
+#endif
+
 	return 0;
 }
 
@@ -878,6 +900,10 @@ void sctp_udp_sock_stop(struct net *net)
 		udp_tunnel_sock_release(net->sctp.udp4_sock->sk_socket);
 		net->sctp.udp4_sock = NULL;
 	}
+	if (net->sctp.udp6_sock) {
+		udp_tunnel_sock_release(net->sctp.udp6_sock->sk_socket);
+		net->sctp.udp6_sock = NULL;
+	}
 }
 
 /* Register address family specific functions. */
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 06/17] sctp: create udp6 sock and set its encap_rcv
  2020-10-08  9:48           ` [PATCHv2 net-next 06/17] sctp: create udp6 sock and set " Xin Long
@ 2020-10-08  9:48             ` Xin Long
  2020-10-08  9:48             ` [PATCHv2 net-next 07/17] sctp: add encap_err_lookup for udp encap socks Xin Long
  2020-10-08 21:18             ` [PATCHv2 net-next 06/17] sctp: create udp6 sock and set its encap_rcv kernel test robot
  2 siblings, 0 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:48 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

This patch is to add the udp6 sock part in sctp_udp_sock_start/stop().
udp_conf.use_udp6_rx_checksums is set to true, as:

   "The SCTP checksum MUST be computed for IPv4 and IPv6, and the UDP
    checksum SHOULD be computed for IPv4 and IPv6"

says in rfc6951#section-5.3.

v1->v2:
  - Add pr_err() when fails to create udp v6 sock.
  - Add #if IS_ENABLED(CONFIG_IPV6) not to create v6 sock when ipv6 is
    disabled.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 include/net/netns/sctp.h |  1 +
 net/sctp/protocol.c      | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/include/net/netns/sctp.h b/include/net/netns/sctp.h
index 3d10bef..f622945 100644
--- a/include/net/netns/sctp.h
+++ b/include/net/netns/sctp.h
@@ -24,6 +24,7 @@ struct netns_sctp {
 
 	/* udp tunneling listening sock. */
 	struct sock *udp4_sock;
+	struct sock *udp6_sock;
 	/* udp tunneling listening port. */
 	int udp_port;
 
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index 2b7a3e1..49b5d75 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -869,6 +869,28 @@ int sctp_udp_sock_start(struct net *net)
 	setup_udp_tunnel_sock(net, sock, &tuncfg);
 	net->sctp.udp4_sock = sock->sk;
 
+#if IS_ENABLED(CONFIG_IPV6)
+	memset(&udp_conf, 0, sizeof(udp_conf));
+
+	udp_conf.family = AF_INET6;
+	udp_conf.local_ip6 = in6addr_any;
+	udp_conf.local_udp_port = htons(net->sctp.udp_port);
+	udp_conf.use_udp6_rx_checksums = true;
+	udp_conf.ipv6_v6only = true;
+	err = udp_sock_create(net, &udp_conf, &sock);
+	if (err) {
+		pr_err("Failed to create the SCTP udp tunneling v6 sock\n");
+		udp_tunnel_sock_release(net->sctp.udp4_sock->sk_socket);
+		net->sctp.udp4_sock = NULL;
+		return err;
+	}
+
+	tuncfg.encap_type = 1;
+	tuncfg.encap_rcv = sctp_udp_rcv;
+	setup_udp_tunnel_sock(net, sock, &tuncfg);
+	net->sctp.udp6_sock = sock->sk;
+#endif
+
 	return 0;
 }
 
@@ -878,6 +900,10 @@ void sctp_udp_sock_stop(struct net *net)
 		udp_tunnel_sock_release(net->sctp.udp4_sock->sk_socket);
 		net->sctp.udp4_sock = NULL;
 	}
+	if (net->sctp.udp6_sock) {
+		udp_tunnel_sock_release(net->sctp.udp6_sock->sk_socket);
+		net->sctp.udp6_sock = NULL;
+	}
 }
 
 /* Register address family specific functions. */
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 07/17] sctp: add encap_err_lookup for udp encap socks
  2020-10-08  9:48           ` [PATCHv2 net-next 06/17] sctp: create udp6 sock and set " Xin Long
  2020-10-08  9:48             ` Xin Long
@ 2020-10-08  9:48             ` Xin Long
  2020-10-08  9:48               ` Xin Long
  2020-10-08  9:48               ` [PATCHv2 net-next 08/17] sctp: add encap_port for netns sock asoc and transport Xin Long
  2020-10-08 21:18             ` [PATCHv2 net-next 06/17] sctp: create udp6 sock and set its encap_rcv kernel test robot
  2 siblings, 2 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:48 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

As it says in rfc6951#section-5.5:

  "When receiving ICMP or ICMPv6 response packets, there might not be
   enough bytes in the payload to identify the SCTP association that the
   SCTP packet triggering the ICMP or ICMPv6 packet belongs to.  If a
   received ICMP or ICMPv6 packet cannot be related to a specific SCTP
   association or the verification tag cannot be verified, it MUST be
   discarded silently.  In particular, this means that the SCTP stack
   MUST NOT rely on receiving ICMP or ICMPv6 messages.  Implementation
   constraints could prevent processing received ICMP or ICMPv6
   messages."

ICMP or ICMPv6 packets need to be handled, and this is implemented by
udp encap sock .encap_err_lookup function.

The .encap_err_lookup function is called in __udp(6)_lib_err_encap()
to confirm this path does need to be updated. For sctp, what we can
do here is check if the corresponding asoc and transport exist.

Note that icmp packet process for sctp over udp is done by udp sock
.encap_err_lookup(), and it means for now we can't do as much as
sctp_v4/6_err() does. Also we can't do the two mappings mentioned
in rfc6951#section-5.5.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 net/sctp/protocol.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index 49b5d75..dd2d9c4 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -848,6 +848,23 @@ static int sctp_udp_rcv(struct sock *sk, struct sk_buff *skb)
 	return 0;
 }
 
+static int sctp_udp_err_lookup(struct sock *sk, struct sk_buff *skb)
+{
+	struct sctp_association *asoc;
+	struct sctp_transport *t;
+	int family;
+
+	skb->transport_header += sizeof(struct udphdr);
+	family = (ip_hdr(skb)->version = 4) ? AF_INET : AF_INET6;
+	sk = sctp_err_lookup(dev_net(skb->dev), family, skb, sctp_hdr(skb),
+			     &asoc, &t);
+	if (!sk)
+		return -ENOENT;
+
+	sctp_err_finish(sk, t);
+	return 0;
+}
+
 int sctp_udp_sock_start(struct net *net)
 {
 	struct udp_tunnel_sock_cfg tuncfg = {NULL};
@@ -866,6 +883,7 @@ int sctp_udp_sock_start(struct net *net)
 
 	tuncfg.encap_type = 1;
 	tuncfg.encap_rcv = sctp_udp_rcv;
+	tuncfg.encap_err_lookup = sctp_udp_err_lookup;
 	setup_udp_tunnel_sock(net, sock, &tuncfg);
 	net->sctp.udp4_sock = sock->sk;
 
@@ -887,6 +905,7 @@ int sctp_udp_sock_start(struct net *net)
 
 	tuncfg.encap_type = 1;
 	tuncfg.encap_rcv = sctp_udp_rcv;
+	tuncfg.encap_err_lookup = sctp_udp_err_lookup;
 	setup_udp_tunnel_sock(net, sock, &tuncfg);
 	net->sctp.udp6_sock = sock->sk;
 #endif
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 07/17] sctp: add encap_err_lookup for udp encap socks
  2020-10-08  9:48             ` [PATCHv2 net-next 07/17] sctp: add encap_err_lookup for udp encap socks Xin Long
@ 2020-10-08  9:48               ` Xin Long
  2020-10-08  9:48               ` [PATCHv2 net-next 08/17] sctp: add encap_port for netns sock asoc and transport Xin Long
  1 sibling, 0 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:48 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

As it says in rfc6951#section-5.5:

  "When receiving ICMP or ICMPv6 response packets, there might not be
   enough bytes in the payload to identify the SCTP association that the
   SCTP packet triggering the ICMP or ICMPv6 packet belongs to.  If a
   received ICMP or ICMPv6 packet cannot be related to a specific SCTP
   association or the verification tag cannot be verified, it MUST be
   discarded silently.  In particular, this means that the SCTP stack
   MUST NOT rely on receiving ICMP or ICMPv6 messages.  Implementation
   constraints could prevent processing received ICMP or ICMPv6
   messages."

ICMP or ICMPv6 packets need to be handled, and this is implemented by
udp encap sock .encap_err_lookup function.

The .encap_err_lookup function is called in __udp(6)_lib_err_encap()
to confirm this path does need to be updated. For sctp, what we can
do here is check if the corresponding asoc and transport exist.

Note that icmp packet process for sctp over udp is done by udp sock
.encap_err_lookup(), and it means for now we can't do as much as
sctp_v4/6_err() does. Also we can't do the two mappings mentioned
in rfc6951#section-5.5.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 net/sctp/protocol.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index 49b5d75..dd2d9c4 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -848,6 +848,23 @@ static int sctp_udp_rcv(struct sock *sk, struct sk_buff *skb)
 	return 0;
 }
 
+static int sctp_udp_err_lookup(struct sock *sk, struct sk_buff *skb)
+{
+	struct sctp_association *asoc;
+	struct sctp_transport *t;
+	int family;
+
+	skb->transport_header += sizeof(struct udphdr);
+	family = (ip_hdr(skb)->version == 4) ? AF_INET : AF_INET6;
+	sk = sctp_err_lookup(dev_net(skb->dev), family, skb, sctp_hdr(skb),
+			     &asoc, &t);
+	if (!sk)
+		return -ENOENT;
+
+	sctp_err_finish(sk, t);
+	return 0;
+}
+
 int sctp_udp_sock_start(struct net *net)
 {
 	struct udp_tunnel_sock_cfg tuncfg = {NULL};
@@ -866,6 +883,7 @@ int sctp_udp_sock_start(struct net *net)
 
 	tuncfg.encap_type = 1;
 	tuncfg.encap_rcv = sctp_udp_rcv;
+	tuncfg.encap_err_lookup = sctp_udp_err_lookup;
 	setup_udp_tunnel_sock(net, sock, &tuncfg);
 	net->sctp.udp4_sock = sock->sk;
 
@@ -887,6 +905,7 @@ int sctp_udp_sock_start(struct net *net)
 
 	tuncfg.encap_type = 1;
 	tuncfg.encap_rcv = sctp_udp_rcv;
+	tuncfg.encap_err_lookup = sctp_udp_err_lookup;
 	setup_udp_tunnel_sock(net, sock, &tuncfg);
 	net->sctp.udp6_sock = sock->sk;
 #endif
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 08/17] sctp: add encap_port for netns sock asoc and transport
  2020-10-08  9:48             ` [PATCHv2 net-next 07/17] sctp: add encap_err_lookup for udp encap socks Xin Long
  2020-10-08  9:48               ` Xin Long
@ 2020-10-08  9:48               ` Xin Long
  2020-10-08  9:48                 ` Xin Long
  2020-10-08  9:48                 ` [PATCHv2 net-next 09/17] sctp: add SCTP_REMOTE_UDP_ENCAPS_PORT sockopt Xin Long
  1 sibling, 2 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:48 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

encap_port is added as per netns/sock/assoc/transport, and the
latter one's encap_port inherits the former one's by default.
The transport's encap_port value would mostly decide if one
packet should go out with udp encapsulated or not.

This patch also allows users to set netns' encap_port by sysctl.

v1->v2:
  - Change to define encap_port as __be16 for sctp_sock, asoc and
    transport.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 include/net/netns/sctp.h   |  2 ++
 include/net/sctp/structs.h |  6 ++++++
 net/sctp/associola.c       |  4 ++++
 net/sctp/protocol.c        |  3 +++
 net/sctp/socket.c          |  1 +
 net/sctp/sysctl.c          | 10 ++++++++++
 6 files changed, 26 insertions(+)

diff --git a/include/net/netns/sctp.h b/include/net/netns/sctp.h
index f622945..6af7a39 100644
--- a/include/net/netns/sctp.h
+++ b/include/net/netns/sctp.h
@@ -27,6 +27,8 @@ struct netns_sctp {
 	struct sock *udp6_sock;
 	/* udp tunneling listening port. */
 	int udp_port;
+	/* udp tunneling remote encap port. */
+	int encap_port;
 
 	/* This is the global local address list.
 	 * We actively maintain this complete list of addresses on
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index 0bdff38..aa98e7e 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -178,6 +178,8 @@ struct sctp_sock {
 	 */
 	__u32 hbinterval;
 
+	__be16 encap_port;
+
 	/* This is the max_retrans value for new associations. */
 	__u16 pathmaxrxt;
 
@@ -877,6 +879,8 @@ struct sctp_transport {
 	 */
 	unsigned long last_time_ecne_reduced;
 
+	__be16 encap_port;
+
 	/* This is the max_retrans value for the transport and will
 	 * be initialized from the assocs value.  This can be changed
 	 * using the SCTP_SET_PEER_ADDR_PARAMS socket option.
@@ -1790,6 +1794,8 @@ struct sctp_association {
 	 */
 	unsigned long hbinterval;
 
+	__be16 encap_port;
+
 	/* This is the max_retrans value for new transports in the
 	 * association.
 	 */
diff --git a/net/sctp/associola.c b/net/sctp/associola.c
index fdb69d4..336df4b 100644
--- a/net/sctp/associola.c
+++ b/net/sctp/associola.c
@@ -99,6 +99,8 @@ static struct sctp_association *sctp_association_init(
 	 */
 	asoc->hbinterval = msecs_to_jiffies(sp->hbinterval);
 
+	asoc->encap_port = sp->encap_port;
+
 	/* Initialize path max retrans value. */
 	asoc->pathmaxrxt = sp->pathmaxrxt;
 
@@ -624,6 +626,8 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc,
 	 */
 	peer->hbinterval = asoc->hbinterval;
 
+	peer->encap_port = asoc->encap_port;
+
 	/* Set the path max_retrans.  */
 	peer->pathmaxrxt = asoc->pathmaxrxt;
 
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index dd2d9c4..5b74187 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -1359,6 +1359,9 @@ static int __net_init sctp_defaults_init(struct net *net)
 	/* Set udp tunneling listening port to default value */
 	net->sctp.udp_port = SCTP_DEFAULT_UDP_PORT;
 
+	/* Set remote encap port to 0 by default */
+	net->sctp.encap_port = 0;
+
 	/* Set SCOPE policy to enabled */
 	net->sctp.scope_policy = SCTP_SCOPE_POLICY_ENABLE;
 
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 53d0a41..09b94cd 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -4876,6 +4876,7 @@ static int sctp_init_sock(struct sock *sk)
 	 * be modified via SCTP_PEER_ADDR_PARAMS
 	 */
 	sp->hbinterval  = net->sctp.hb_interval;
+	sp->encap_port  = htons(net->sctp.encap_port);
 	sp->pathmaxrxt  = net->sctp.max_retrans_path;
 	sp->pf_retrans  = net->sctp.pf_retrans;
 	sp->ps_retrans  = net->sctp.ps_retrans;
diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
index c16c809..ecc1b5e 100644
--- a/net/sctp/sysctl.c
+++ b/net/sctp/sysctl.c
@@ -36,6 +36,7 @@ static int rto_alpha_max = 1000;
 static int rto_beta_max = 1000;
 static int pf_expose_max = SCTP_PF_EXPOSE_MAX;
 static int ps_retrans_max = SCTP_PS_RETRANS_MAX;
+static int udp_port_max = 65535;
 
 static unsigned long max_autoclose_min = 0;
 static unsigned long max_autoclose_max @@ -291,6 +292,15 @@ static struct ctl_table sctp_net_table[] = {
 		.proc_handler	= proc_dointvec,
 	},
 	{
+		.procname	= "encap_port",
+		.data		= &init_net.sctp.encap_port,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= &udp_port_max,
+	},
+	{
 		.procname	= "addr_scope_policy",
 		.data		= &init_net.sctp.scope_policy,
 		.maxlen		= sizeof(int),
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 08/17] sctp: add encap_port for netns sock asoc and transport
  2020-10-08  9:48               ` [PATCHv2 net-next 08/17] sctp: add encap_port for netns sock asoc and transport Xin Long
@ 2020-10-08  9:48                 ` Xin Long
  2020-10-08  9:48                 ` [PATCHv2 net-next 09/17] sctp: add SCTP_REMOTE_UDP_ENCAPS_PORT sockopt Xin Long
  1 sibling, 0 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:48 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

encap_port is added as per netns/sock/assoc/transport, and the
latter one's encap_port inherits the former one's by default.
The transport's encap_port value would mostly decide if one
packet should go out with udp encapsulated or not.

This patch also allows users to set netns' encap_port by sysctl.

v1->v2:
  - Change to define encap_port as __be16 for sctp_sock, asoc and
    transport.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 include/net/netns/sctp.h   |  2 ++
 include/net/sctp/structs.h |  6 ++++++
 net/sctp/associola.c       |  4 ++++
 net/sctp/protocol.c        |  3 +++
 net/sctp/socket.c          |  1 +
 net/sctp/sysctl.c          | 10 ++++++++++
 6 files changed, 26 insertions(+)

diff --git a/include/net/netns/sctp.h b/include/net/netns/sctp.h
index f622945..6af7a39 100644
--- a/include/net/netns/sctp.h
+++ b/include/net/netns/sctp.h
@@ -27,6 +27,8 @@ struct netns_sctp {
 	struct sock *udp6_sock;
 	/* udp tunneling listening port. */
 	int udp_port;
+	/* udp tunneling remote encap port. */
+	int encap_port;
 
 	/* This is the global local address list.
 	 * We actively maintain this complete list of addresses on
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index 0bdff38..aa98e7e 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -178,6 +178,8 @@ struct sctp_sock {
 	 */
 	__u32 hbinterval;
 
+	__be16 encap_port;
+
 	/* This is the max_retrans value for new associations. */
 	__u16 pathmaxrxt;
 
@@ -877,6 +879,8 @@ struct sctp_transport {
 	 */
 	unsigned long last_time_ecne_reduced;
 
+	__be16 encap_port;
+
 	/* This is the max_retrans value for the transport and will
 	 * be initialized from the assocs value.  This can be changed
 	 * using the SCTP_SET_PEER_ADDR_PARAMS socket option.
@@ -1790,6 +1794,8 @@ struct sctp_association {
 	 */
 	unsigned long hbinterval;
 
+	__be16 encap_port;
+
 	/* This is the max_retrans value for new transports in the
 	 * association.
 	 */
diff --git a/net/sctp/associola.c b/net/sctp/associola.c
index fdb69d4..336df4b 100644
--- a/net/sctp/associola.c
+++ b/net/sctp/associola.c
@@ -99,6 +99,8 @@ static struct sctp_association *sctp_association_init(
 	 */
 	asoc->hbinterval = msecs_to_jiffies(sp->hbinterval);
 
+	asoc->encap_port = sp->encap_port;
+
 	/* Initialize path max retrans value. */
 	asoc->pathmaxrxt = sp->pathmaxrxt;
 
@@ -624,6 +626,8 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc,
 	 */
 	peer->hbinterval = asoc->hbinterval;
 
+	peer->encap_port = asoc->encap_port;
+
 	/* Set the path max_retrans.  */
 	peer->pathmaxrxt = asoc->pathmaxrxt;
 
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index dd2d9c4..5b74187 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -1359,6 +1359,9 @@ static int __net_init sctp_defaults_init(struct net *net)
 	/* Set udp tunneling listening port to default value */
 	net->sctp.udp_port = SCTP_DEFAULT_UDP_PORT;
 
+	/* Set remote encap port to 0 by default */
+	net->sctp.encap_port = 0;
+
 	/* Set SCOPE policy to enabled */
 	net->sctp.scope_policy = SCTP_SCOPE_POLICY_ENABLE;
 
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 53d0a41..09b94cd 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -4876,6 +4876,7 @@ static int sctp_init_sock(struct sock *sk)
 	 * be modified via SCTP_PEER_ADDR_PARAMS
 	 */
 	sp->hbinterval  = net->sctp.hb_interval;
+	sp->encap_port  = htons(net->sctp.encap_port);
 	sp->pathmaxrxt  = net->sctp.max_retrans_path;
 	sp->pf_retrans  = net->sctp.pf_retrans;
 	sp->ps_retrans  = net->sctp.ps_retrans;
diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
index c16c809..ecc1b5e 100644
--- a/net/sctp/sysctl.c
+++ b/net/sctp/sysctl.c
@@ -36,6 +36,7 @@ static int rto_alpha_max = 1000;
 static int rto_beta_max = 1000;
 static int pf_expose_max = SCTP_PF_EXPOSE_MAX;
 static int ps_retrans_max = SCTP_PS_RETRANS_MAX;
+static int udp_port_max = 65535;
 
 static unsigned long max_autoclose_min = 0;
 static unsigned long max_autoclose_max =
@@ -291,6 +292,15 @@ static struct ctl_table sctp_net_table[] = {
 		.proc_handler	= proc_dointvec,
 	},
 	{
+		.procname	= "encap_port",
+		.data		= &init_net.sctp.encap_port,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= &udp_port_max,
+	},
+	{
 		.procname	= "addr_scope_policy",
 		.data		= &init_net.sctp.scope_policy,
 		.maxlen		= sizeof(int),
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 09/17] sctp: add SCTP_REMOTE_UDP_ENCAPS_PORT sockopt
  2020-10-08  9:48               ` [PATCHv2 net-next 08/17] sctp: add encap_port for netns sock asoc and transport Xin Long
  2020-10-08  9:48                 ` Xin Long
@ 2020-10-08  9:48                 ` Xin Long
  2020-10-08  9:48                   ` Xin Long
                                     ` (2 more replies)
  1 sibling, 3 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:48 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

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 <lucien.xin@gmail.com>
---
 include/uapi/linux/sctp.h |   7 +++
 net/sctp/socket.c         | 110 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 117 insertions(+)

diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
index 28ad40d..cb78e7a 100644
--- a/include/uapi/linux/sctp.h
+++ b/include/uapi/linux/sctp.h
@@ -140,6 +140,7 @@ typedef __s32 sctp_assoc_t;
 #define SCTP_ECN_SUPPORTED	130
 #define SCTP_EXPOSE_POTENTIALLY_FAILED_STATE	131
 #define SCTP_EXPOSE_PF_STATE	SCTP_EXPOSE_POTENTIALLY_FAILED_STATE
+#define SCTP_REMOTE_UDP_ENCAPS_PORT	132
 
 /* PR-SCTP policies */
 #define SCTP_PR_SCTP_NONE	0x0000
@@ -1197,6 +1198,12 @@ struct sctp_event {
 	uint8_t se_on;
 };
 
+struct sctp_udpencaps {
+	sctp_assoc_t sue_assoc_id;
+	struct sockaddr_storage sue_address;
+	uint16_t sue_port;
+};
+
 /* SCTP Stream schedulers */
 enum sctp_sched_type {
 	SCTP_SS_FCFS,
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 09b94cd..c9e86f5 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -4417,6 +4417,53 @@ static int sctp_setsockopt_pf_expose(struct sock *sk,
 	return retval;
 }
 
+static int sctp_setsockopt_encap_port(struct sock *sk,
+				      struct sctp_udpencaps *encap,
+				      unsigned int optlen)
+{
+	struct sctp_association *asoc;
+	struct sctp_transport *t;
+
+	if (optlen != sizeof(*encap))
+		return -EINVAL;
+
+	/* If an address other than INADDR_ANY is specified, and
+	 * no transport is found, then the request is invalid.
+	 */
+	if (!sctp_is_any(sk, (union sctp_addr *)&encap->sue_address)) {
+		t = sctp_addr_id2transport(sk, &encap->sue_address,
+					   encap->sue_assoc_id);
+		if (!t)
+			return -EINVAL;
+
+		t->encap_port = encap->sue_port;
+		return 0;
+	}
+
+	/* Get association, if assoc_id != SCTP_FUTURE_ASSOC and the
+	 * socket is a one to many style socket, and an association
+	 * was not found, then the id was invalid.
+	 */
+	asoc = sctp_id2assoc(sk, encap->sue_assoc_id);
+	if (!asoc && encap->sue_assoc_id != SCTP_FUTURE_ASSOC &&
+	    sctp_style(sk, UDP))
+		return -EINVAL;
+
+	/* If changes are for association, also apply encap to each
+	 * transport.
+	 */
+	if (asoc) {
+		list_for_each_entry(t, &asoc->peer.transport_addr_list,
+				    transports)
+			t->encap_port = encap->sue_port;
+
+		return 0;
+	}
+
+	sctp_sk(sk)->encap_port = encap->sue_port;
+	return 0;
+}
+
 /* API 6.2 setsockopt(), getsockopt()
  *
  * Applications use setsockopt() and getsockopt() to set or retrieve
@@ -4636,6 +4683,9 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname,
 	case SCTP_EXPOSE_POTENTIALLY_FAILED_STATE:
 		retval = sctp_setsockopt_pf_expose(sk, kopt, optlen);
 		break;
+	case SCTP_REMOTE_UDP_ENCAPS_PORT:
+		retval = sctp_setsockopt_encap_port(sk, kopt, optlen);
+		break;
 	default:
 		retval = -ENOPROTOOPT;
 		break;
@@ -7791,6 +7841,63 @@ static int sctp_getsockopt_pf_expose(struct sock *sk, int len,
 	return retval;
 }
 
+static int sctp_getsockopt_encap_port(struct sock *sk, int len,
+				      char __user *optval, int __user *optlen)
+{
+	struct sctp_association *asoc;
+	struct sctp_udpencaps encap;
+	struct sctp_transport *t;
+
+	if (len < sizeof(encap))
+		return -EINVAL;
+
+	len = sizeof(encap);
+	if (copy_from_user(&encap, optval, len))
+		return -EFAULT;
+
+	/* If an address other than INADDR_ANY is specified, and
+	 * no transport is found, then the request is invalid.
+	 */
+	if (!sctp_is_any(sk, (union sctp_addr *)&encap.sue_address)) {
+		t = sctp_addr_id2transport(sk, &encap.sue_address,
+					   encap.sue_assoc_id);
+		if (!t) {
+			pr_debug("%s: failed no transport\n", __func__);
+			return -EINVAL;
+		}
+
+		encap.sue_port = t->encap_port;
+		goto out;
+	}
+
+	/* Get association, if assoc_id != SCTP_FUTURE_ASSOC and the
+	 * socket is a one to many style socket, and an association
+	 * was not found, then the id was invalid.
+	 */
+	asoc = sctp_id2assoc(sk, encap.sue_assoc_id);
+	if (!asoc && encap.sue_assoc_id != SCTP_FUTURE_ASSOC &&
+	    sctp_style(sk, UDP)) {
+		pr_debug("%s: failed no association\n", __func__);
+		return -EINVAL;
+	}
+
+	if (asoc) {
+		encap.sue_port = asoc->encap_port;
+		goto out;
+	}
+
+	encap.sue_port = sctp_sk(sk)->encap_port;
+
+out:
+	if (copy_to_user(optval, &encap, len))
+		return -EFAULT;
+
+	if (put_user(len, optlen))
+		return -EFAULT;
+
+	return 0;
+}
+
 static int sctp_getsockopt(struct sock *sk, int level, int optname,
 			   char __user *optval, int __user *optlen)
 {
@@ -8011,6 +8118,9 @@ static int sctp_getsockopt(struct sock *sk, int level, int optname,
 	case SCTP_EXPOSE_POTENTIALLY_FAILED_STATE:
 		retval = sctp_getsockopt_pf_expose(sk, len, optval, optlen);
 		break;
+	case SCTP_REMOTE_UDP_ENCAPS_PORT:
+		retval = sctp_getsockopt_encap_port(sk, len, optval, optlen);
+		break;
 	default:
 		retval = -ENOPROTOOPT;
 		break;
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 09/17] sctp: add SCTP_REMOTE_UDP_ENCAPS_PORT sockopt
  2020-10-08  9:48                 ` [PATCHv2 net-next 09/17] sctp: add SCTP_REMOTE_UDP_ENCAPS_PORT sockopt Xin Long
@ 2020-10-08  9:48                   ` Xin Long
  2020-10-08  9:48                   ` [PATCHv2 net-next 10/17] sctp: allow changing transport encap_port by peer packets Xin Long
  2020-10-08 13:10                   ` [PATCHv2 net-next 09/17] sctp: add SCTP_REMOTE_UDP_ENCAPS_PORT sockopt kernel test robot
  2 siblings, 0 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:48 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

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 <lucien.xin@gmail.com>
---
 include/uapi/linux/sctp.h |   7 +++
 net/sctp/socket.c         | 110 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 117 insertions(+)

diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
index 28ad40d..cb78e7a 100644
--- a/include/uapi/linux/sctp.h
+++ b/include/uapi/linux/sctp.h
@@ -140,6 +140,7 @@ typedef __s32 sctp_assoc_t;
 #define SCTP_ECN_SUPPORTED	130
 #define SCTP_EXPOSE_POTENTIALLY_FAILED_STATE	131
 #define SCTP_EXPOSE_PF_STATE	SCTP_EXPOSE_POTENTIALLY_FAILED_STATE
+#define SCTP_REMOTE_UDP_ENCAPS_PORT	132
 
 /* PR-SCTP policies */
 #define SCTP_PR_SCTP_NONE	0x0000
@@ -1197,6 +1198,12 @@ struct sctp_event {
 	uint8_t se_on;
 };
 
+struct sctp_udpencaps {
+	sctp_assoc_t sue_assoc_id;
+	struct sockaddr_storage sue_address;
+	uint16_t sue_port;
+};
+
 /* SCTP Stream schedulers */
 enum sctp_sched_type {
 	SCTP_SS_FCFS,
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 09b94cd..c9e86f5 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -4417,6 +4417,53 @@ static int sctp_setsockopt_pf_expose(struct sock *sk,
 	return retval;
 }
 
+static int sctp_setsockopt_encap_port(struct sock *sk,
+				      struct sctp_udpencaps *encap,
+				      unsigned int optlen)
+{
+	struct sctp_association *asoc;
+	struct sctp_transport *t;
+
+	if (optlen != sizeof(*encap))
+		return -EINVAL;
+
+	/* If an address other than INADDR_ANY is specified, and
+	 * no transport is found, then the request is invalid.
+	 */
+	if (!sctp_is_any(sk, (union sctp_addr *)&encap->sue_address)) {
+		t = sctp_addr_id2transport(sk, &encap->sue_address,
+					   encap->sue_assoc_id);
+		if (!t)
+			return -EINVAL;
+
+		t->encap_port = encap->sue_port;
+		return 0;
+	}
+
+	/* Get association, if assoc_id != SCTP_FUTURE_ASSOC and the
+	 * socket is a one to many style socket, and an association
+	 * was not found, then the id was invalid.
+	 */
+	asoc = sctp_id2assoc(sk, encap->sue_assoc_id);
+	if (!asoc && encap->sue_assoc_id != SCTP_FUTURE_ASSOC &&
+	    sctp_style(sk, UDP))
+		return -EINVAL;
+
+	/* If changes are for association, also apply encap to each
+	 * transport.
+	 */
+	if (asoc) {
+		list_for_each_entry(t, &asoc->peer.transport_addr_list,
+				    transports)
+			t->encap_port = encap->sue_port;
+
+		return 0;
+	}
+
+	sctp_sk(sk)->encap_port = encap->sue_port;
+	return 0;
+}
+
 /* API 6.2 setsockopt(), getsockopt()
  *
  * Applications use setsockopt() and getsockopt() to set or retrieve
@@ -4636,6 +4683,9 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname,
 	case SCTP_EXPOSE_POTENTIALLY_FAILED_STATE:
 		retval = sctp_setsockopt_pf_expose(sk, kopt, optlen);
 		break;
+	case SCTP_REMOTE_UDP_ENCAPS_PORT:
+		retval = sctp_setsockopt_encap_port(sk, kopt, optlen);
+		break;
 	default:
 		retval = -ENOPROTOOPT;
 		break;
@@ -7791,6 +7841,63 @@ static int sctp_getsockopt_pf_expose(struct sock *sk, int len,
 	return retval;
 }
 
+static int sctp_getsockopt_encap_port(struct sock *sk, int len,
+				      char __user *optval, int __user *optlen)
+{
+	struct sctp_association *asoc;
+	struct sctp_udpencaps encap;
+	struct sctp_transport *t;
+
+	if (len < sizeof(encap))
+		return -EINVAL;
+
+	len = sizeof(encap);
+	if (copy_from_user(&encap, optval, len))
+		return -EFAULT;
+
+	/* If an address other than INADDR_ANY is specified, and
+	 * no transport is found, then the request is invalid.
+	 */
+	if (!sctp_is_any(sk, (union sctp_addr *)&encap.sue_address)) {
+		t = sctp_addr_id2transport(sk, &encap.sue_address,
+					   encap.sue_assoc_id);
+		if (!t) {
+			pr_debug("%s: failed no transport\n", __func__);
+			return -EINVAL;
+		}
+
+		encap.sue_port = t->encap_port;
+		goto out;
+	}
+
+	/* Get association, if assoc_id != SCTP_FUTURE_ASSOC and the
+	 * socket is a one to many style socket, and an association
+	 * was not found, then the id was invalid.
+	 */
+	asoc = sctp_id2assoc(sk, encap.sue_assoc_id);
+	if (!asoc && encap.sue_assoc_id != SCTP_FUTURE_ASSOC &&
+	    sctp_style(sk, UDP)) {
+		pr_debug("%s: failed no association\n", __func__);
+		return -EINVAL;
+	}
+
+	if (asoc) {
+		encap.sue_port = asoc->encap_port;
+		goto out;
+	}
+
+	encap.sue_port = sctp_sk(sk)->encap_port;
+
+out:
+	if (copy_to_user(optval, &encap, len))
+		return -EFAULT;
+
+	if (put_user(len, optlen))
+		return -EFAULT;
+
+	return 0;
+}
+
 static int sctp_getsockopt(struct sock *sk, int level, int optname,
 			   char __user *optval, int __user *optlen)
 {
@@ -8011,6 +8118,9 @@ static int sctp_getsockopt(struct sock *sk, int level, int optname,
 	case SCTP_EXPOSE_POTENTIALLY_FAILED_STATE:
 		retval = sctp_getsockopt_pf_expose(sk, len, optval, optlen);
 		break;
+	case SCTP_REMOTE_UDP_ENCAPS_PORT:
+		retval = sctp_getsockopt_encap_port(sk, len, optval, optlen);
+		break;
 	default:
 		retval = -ENOPROTOOPT;
 		break;
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 10/17] sctp: allow changing transport encap_port by peer packets
  2020-10-08  9:48                 ` [PATCHv2 net-next 09/17] sctp: add SCTP_REMOTE_UDP_ENCAPS_PORT sockopt Xin Long
  2020-10-08  9:48                   ` Xin Long
@ 2020-10-08  9:48                   ` Xin Long
  2020-10-08  9:48                     ` Xin Long
  2020-10-08  9:48                     ` [PATCHv2 net-next 11/17] sctp: add udphdr to overhead when udp_port is set Xin Long
  2020-10-08 13:10                   ` [PATCHv2 net-next 09/17] sctp: add SCTP_REMOTE_UDP_ENCAPS_PORT sockopt kernel test robot
  2 siblings, 2 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:48 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

As rfc6951#section-5.4 says:

  "After finding the SCTP association (which
   includes checking the verification tag), the UDP source port MUST be
   stored as the encapsulation port for the destination address the SCTP
   packet is received from (see Section 5.1).

   When a non-encapsulated SCTP packet is received by the SCTP stack,
   the encapsulation of outgoing packets belonging to the same
   association and the corresponding destination address MUST be
   disabled."

transport encap_port should be updated by a validated incoming packet's
udp src port.

We save the udp src port in sctp_input_cb->encap_port, and then update
the transport in two places:

  1. right after vtag is verified, which is required by RFC, and this
     allows the existent transports to be updated by the chunks that
     can only be processed on an asoc.

  2. right before processing the 'init' where the transports are added,
     and this allows building a sctp over udp connection by client with
     the server not knowing the remote encap port.

  3. when processing ootb_pkt and creating the temporary transport for
     the reply pkt.

Note that sctp_input_cb->header is removed, as it's not used any more
in sctp.

v1->v2:
  - Change encap_port as __be16 for sctp_input_cb.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 include/net/sctp/sm.h      |  1 +
 include/net/sctp/structs.h |  7 +------
 net/sctp/ipv6.c            |  1 +
 net/sctp/protocol.c        | 11 ++++++++++-
 net/sctp/sm_make_chunk.c   |  1 +
 net/sctp/sm_statefuns.c    |  2 ++
 6 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
index 5c491a3..a499341 100644
--- a/include/net/sctp/sm.h
+++ b/include/net/sctp/sm.h
@@ -380,6 +380,7 @@ sctp_vtag_verify(const struct sctp_chunk *chunk,
         if (ntohl(chunk->sctp_hdr->vtag) = asoc->c.my_vtag)
                 return 1;
 
+	chunk->transport->encap_port = SCTP_INPUT_CB(chunk->skb)->encap_port;
 	return 0;
 }
 
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index aa98e7e..81464ae 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -1120,14 +1120,9 @@ static inline void sctp_outq_cork(struct sctp_outq *q)
  * sctp_input_cb is currently used on rx and sock rx queue
  */
 struct sctp_input_cb {
-	union {
-		struct inet_skb_parm	h4;
-#if IS_ENABLED(CONFIG_IPV6)
-		struct inet6_skb_parm	h6;
-#endif
-	} header;
 	struct sctp_chunk *chunk;
 	struct sctp_af *af;
+	__be16 encap_port;
 };
 #define SCTP_INPUT_CB(__skb)	((struct sctp_input_cb *)&((__skb)->cb[0]))
 
diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
index 8a58f42..a064bf2 100644
--- a/net/sctp/ipv6.c
+++ b/net/sctp/ipv6.c
@@ -1053,6 +1053,7 @@ static struct inet_protosw sctpv6_stream_protosw = {
 
 static int sctp6_rcv(struct sk_buff *skb)
 {
+	memset(skb->cb, 0, sizeof(skb->cb));
 	return sctp_rcv(skb) ? -1 : 0;
 }
 
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index 5b74187..0d16e5e 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -843,6 +843,9 @@ static int sctp_ctl_sock_init(struct net *net)
 
 static int sctp_udp_rcv(struct sock *sk, struct sk_buff *skb)
 {
+	memset(skb->cb, 0, sizeof(skb->cb));
+	SCTP_INPUT_CB(skb)->encap_port = udp_hdr(skb)->source;
+
 	skb_set_transport_header(skb, sizeof(struct udphdr));
 	sctp_rcv(skb);
 	return 0;
@@ -1139,9 +1142,15 @@ static struct inet_protosw sctp_stream_protosw = {
 	.flags      = SCTP_PROTOSW_FLAG
 };
 
+static int sctp4_rcv(struct sk_buff *skb)
+{
+	memset(skb->cb, 0, sizeof(skb->cb));
+	return sctp_rcv(skb);
+}
+
 /* Register with IP layer.  */
 static const struct net_protocol sctp_protocol = {
-	.handler     = sctp_rcv,
+	.handler     = sctp4_rcv,
 	.err_handler = sctp_v4_err,
 	.no_policy   = 1,
 	.netns_ok    = 1,
diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
index 9a56ae2..21d0ff1 100644
--- a/net/sctp/sm_make_chunk.c
+++ b/net/sctp/sm_make_chunk.c
@@ -2321,6 +2321,7 @@ int sctp_process_init(struct sctp_association *asoc, struct sctp_chunk *chunk,
 	 * added as the primary transport.  The source address seems to
 	 * be a better choice than any of the embedded addresses.
 	 */
+	asoc->encap_port = SCTP_INPUT_CB(chunk->skb)->encap_port;
 	if (!sctp_assoc_add_peer(asoc, peer_addr, gfp, SCTP_ACTIVE))
 		goto nomem;
 
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index c669f8b..8edab15 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -6268,6 +6268,8 @@ static struct sctp_packet *sctp_ootb_pkt_new(
 	if (!transport)
 		goto nomem;
 
+	transport->encap_port = SCTP_INPUT_CB(chunk->skb)->encap_port;
+
 	/* Cache a route for the transport with the chunk's destination as
 	 * the source address.
 	 */
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 10/17] sctp: allow changing transport encap_port by peer packets
  2020-10-08  9:48                   ` [PATCHv2 net-next 10/17] sctp: allow changing transport encap_port by peer packets Xin Long
@ 2020-10-08  9:48                     ` Xin Long
  2020-10-08  9:48                     ` [PATCHv2 net-next 11/17] sctp: add udphdr to overhead when udp_port is set Xin Long
  1 sibling, 0 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:48 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

As rfc6951#section-5.4 says:

  "After finding the SCTP association (which
   includes checking the verification tag), the UDP source port MUST be
   stored as the encapsulation port for the destination address the SCTP
   packet is received from (see Section 5.1).

   When a non-encapsulated SCTP packet is received by the SCTP stack,
   the encapsulation of outgoing packets belonging to the same
   association and the corresponding destination address MUST be
   disabled."

transport encap_port should be updated by a validated incoming packet's
udp src port.

We save the udp src port in sctp_input_cb->encap_port, and then update
the transport in two places:

  1. right after vtag is verified, which is required by RFC, and this
     allows the existent transports to be updated by the chunks that
     can only be processed on an asoc.

  2. right before processing the 'init' where the transports are added,
     and this allows building a sctp over udp connection by client with
     the server not knowing the remote encap port.

  3. when processing ootb_pkt and creating the temporary transport for
     the reply pkt.

Note that sctp_input_cb->header is removed, as it's not used any more
in sctp.

v1->v2:
  - Change encap_port as __be16 for sctp_input_cb.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 include/net/sctp/sm.h      |  1 +
 include/net/sctp/structs.h |  7 +------
 net/sctp/ipv6.c            |  1 +
 net/sctp/protocol.c        | 11 ++++++++++-
 net/sctp/sm_make_chunk.c   |  1 +
 net/sctp/sm_statefuns.c    |  2 ++
 6 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
index 5c491a3..a499341 100644
--- a/include/net/sctp/sm.h
+++ b/include/net/sctp/sm.h
@@ -380,6 +380,7 @@ sctp_vtag_verify(const struct sctp_chunk *chunk,
         if (ntohl(chunk->sctp_hdr->vtag) == asoc->c.my_vtag)
                 return 1;
 
+	chunk->transport->encap_port = SCTP_INPUT_CB(chunk->skb)->encap_port;
 	return 0;
 }
 
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index aa98e7e..81464ae 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -1120,14 +1120,9 @@ static inline void sctp_outq_cork(struct sctp_outq *q)
  * sctp_input_cb is currently used on rx and sock rx queue
  */
 struct sctp_input_cb {
-	union {
-		struct inet_skb_parm	h4;
-#if IS_ENABLED(CONFIG_IPV6)
-		struct inet6_skb_parm	h6;
-#endif
-	} header;
 	struct sctp_chunk *chunk;
 	struct sctp_af *af;
+	__be16 encap_port;
 };
 #define SCTP_INPUT_CB(__skb)	((struct sctp_input_cb *)&((__skb)->cb[0]))
 
diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
index 8a58f42..a064bf2 100644
--- a/net/sctp/ipv6.c
+++ b/net/sctp/ipv6.c
@@ -1053,6 +1053,7 @@ static struct inet_protosw sctpv6_stream_protosw = {
 
 static int sctp6_rcv(struct sk_buff *skb)
 {
+	memset(skb->cb, 0, sizeof(skb->cb));
 	return sctp_rcv(skb) ? -1 : 0;
 }
 
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index 5b74187..0d16e5e 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -843,6 +843,9 @@ static int sctp_ctl_sock_init(struct net *net)
 
 static int sctp_udp_rcv(struct sock *sk, struct sk_buff *skb)
 {
+	memset(skb->cb, 0, sizeof(skb->cb));
+	SCTP_INPUT_CB(skb)->encap_port = udp_hdr(skb)->source;
+
 	skb_set_transport_header(skb, sizeof(struct udphdr));
 	sctp_rcv(skb);
 	return 0;
@@ -1139,9 +1142,15 @@ static struct inet_protosw sctp_stream_protosw = {
 	.flags      = SCTP_PROTOSW_FLAG
 };
 
+static int sctp4_rcv(struct sk_buff *skb)
+{
+	memset(skb->cb, 0, sizeof(skb->cb));
+	return sctp_rcv(skb);
+}
+
 /* Register with IP layer.  */
 static const struct net_protocol sctp_protocol = {
-	.handler     = sctp_rcv,
+	.handler     = sctp4_rcv,
 	.err_handler = sctp_v4_err,
 	.no_policy   = 1,
 	.netns_ok    = 1,
diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
index 9a56ae2..21d0ff1 100644
--- a/net/sctp/sm_make_chunk.c
+++ b/net/sctp/sm_make_chunk.c
@@ -2321,6 +2321,7 @@ int sctp_process_init(struct sctp_association *asoc, struct sctp_chunk *chunk,
 	 * added as the primary transport.  The source address seems to
 	 * be a better choice than any of the embedded addresses.
 	 */
+	asoc->encap_port = SCTP_INPUT_CB(chunk->skb)->encap_port;
 	if (!sctp_assoc_add_peer(asoc, peer_addr, gfp, SCTP_ACTIVE))
 		goto nomem;
 
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index c669f8b..8edab15 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -6268,6 +6268,8 @@ static struct sctp_packet *sctp_ootb_pkt_new(
 	if (!transport)
 		goto nomem;
 
+	transport->encap_port = SCTP_INPUT_CB(chunk->skb)->encap_port;
+
 	/* Cache a route for the transport with the chunk's destination as
 	 * the source address.
 	 */
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 11/17] sctp: add udphdr to overhead when udp_port is set
  2020-10-08  9:48                   ` [PATCHv2 net-next 10/17] sctp: allow changing transport encap_port by peer packets Xin Long
  2020-10-08  9:48                     ` Xin Long
@ 2020-10-08  9:48                     ` Xin Long
  2020-10-08  9:48                       ` Xin Long
  2020-10-08  9:48                       ` [PATCHv2 net-next 12/17] sctp: call sk_setup_caps in sctp_packet_transmit instead Xin Long
  1 sibling, 2 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:48 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

sctp_mtu_payload() is for calculating the frag size before making
chunks from a msg. So we should only add udphdr size to overhead
when udp socks are listening, as only then sctp can handle the
incoming sctp over udp packets and outgoing sctp over udp packets
will be possible.

Note that we can't do this according to transport->encap_port, as
different transports may be set to different values, while the
chunks were made before choosing the transport, we could not be
able to meet all rfc6951#section-5.6 recommends.

v1->v2:
  - Add udp_port for sctp_sock to avoid a potential race issue, it
    will be used in xmit path in the next patch.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 include/net/sctp/sctp.h    | 7 +++++--
 include/net/sctp/structs.h | 1 +
 net/sctp/socket.c          | 1 +
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
index bfd87a0..86f74f2 100644
--- a/include/net/sctp/sctp.h
+++ b/include/net/sctp/sctp.h
@@ -578,10 +578,13 @@ static inline __u32 sctp_mtu_payload(const struct sctp_sock *sp,
 {
 	__u32 overhead = sizeof(struct sctphdr) + extra;
 
-	if (sp)
+	if (sp) {
 		overhead += sp->pf->af->net_header_len;
-	else
+		if (sp->udp_port)
+			overhead += sizeof(struct udphdr);
+	} else {
 		overhead += sizeof(struct ipv6hdr);
+	}
 
 	if (WARN_ON_ONCE(mtu && mtu <= overhead))
 		mtu = overhead;
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index 81464ae..80f7149 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -178,6 +178,7 @@ struct sctp_sock {
 	 */
 	__u32 hbinterval;
 
+	__be16 udp_port;
 	__be16 encap_port;
 
 	/* This is the max_retrans value for new associations. */
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index c9e86f5..192ab9a 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -4926,6 +4926,7 @@ static int sctp_init_sock(struct sock *sk)
 	 * be modified via SCTP_PEER_ADDR_PARAMS
 	 */
 	sp->hbinterval  = net->sctp.hb_interval;
+	sp->udp_port    = htons(net->sctp.udp_port);
 	sp->encap_port  = htons(net->sctp.encap_port);
 	sp->pathmaxrxt  = net->sctp.max_retrans_path;
 	sp->pf_retrans  = net->sctp.pf_retrans;
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 11/17] sctp: add udphdr to overhead when udp_port is set
  2020-10-08  9:48                     ` [PATCHv2 net-next 11/17] sctp: add udphdr to overhead when udp_port is set Xin Long
@ 2020-10-08  9:48                       ` Xin Long
  2020-10-08  9:48                       ` [PATCHv2 net-next 12/17] sctp: call sk_setup_caps in sctp_packet_transmit instead Xin Long
  1 sibling, 0 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:48 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

sctp_mtu_payload() is for calculating the frag size before making
chunks from a msg. So we should only add udphdr size to overhead
when udp socks are listening, as only then sctp can handle the
incoming sctp over udp packets and outgoing sctp over udp packets
will be possible.

Note that we can't do this according to transport->encap_port, as
different transports may be set to different values, while the
chunks were made before choosing the transport, we could not be
able to meet all rfc6951#section-5.6 recommends.

v1->v2:
  - Add udp_port for sctp_sock to avoid a potential race issue, it
    will be used in xmit path in the next patch.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 include/net/sctp/sctp.h    | 7 +++++--
 include/net/sctp/structs.h | 1 +
 net/sctp/socket.c          | 1 +
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
index bfd87a0..86f74f2 100644
--- a/include/net/sctp/sctp.h
+++ b/include/net/sctp/sctp.h
@@ -578,10 +578,13 @@ static inline __u32 sctp_mtu_payload(const struct sctp_sock *sp,
 {
 	__u32 overhead = sizeof(struct sctphdr) + extra;
 
-	if (sp)
+	if (sp) {
 		overhead += sp->pf->af->net_header_len;
-	else
+		if (sp->udp_port)
+			overhead += sizeof(struct udphdr);
+	} else {
 		overhead += sizeof(struct ipv6hdr);
+	}
 
 	if (WARN_ON_ONCE(mtu && mtu <= overhead))
 		mtu = overhead;
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index 81464ae..80f7149 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -178,6 +178,7 @@ struct sctp_sock {
 	 */
 	__u32 hbinterval;
 
+	__be16 udp_port;
 	__be16 encap_port;
 
 	/* This is the max_retrans value for new associations. */
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index c9e86f5..192ab9a 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -4926,6 +4926,7 @@ static int sctp_init_sock(struct sock *sk)
 	 * be modified via SCTP_PEER_ADDR_PARAMS
 	 */
 	sp->hbinterval  = net->sctp.hb_interval;
+	sp->udp_port    = htons(net->sctp.udp_port);
 	sp->encap_port  = htons(net->sctp.encap_port);
 	sp->pathmaxrxt  = net->sctp.max_retrans_path;
 	sp->pf_retrans  = net->sctp.pf_retrans;
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 12/17] sctp: call sk_setup_caps in sctp_packet_transmit instead
  2020-10-08  9:48                     ` [PATCHv2 net-next 11/17] sctp: add udphdr to overhead when udp_port is set Xin Long
  2020-10-08  9:48                       ` Xin Long
@ 2020-10-08  9:48                       ` Xin Long
  2020-10-08  9:48                         ` Xin Long
  2020-10-08  9:48                         ` [PATCHv2 net-next 13/17] sctp: support for sending packet over udp4 sock Xin Long
  1 sibling, 2 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:48 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

sk_setup_caps() was originally called in Commit 90017accff61 ("sctp:
Add GSO support"), as:

  "We have to refresh this in case we are xmiting to more than one
   transport at a time"

This actually happens in the loop of sctp_outq_flush_transports(),
and it shouldn't be tied to gso, so move it out of gso part and
before sctp_packet_pack().

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 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) {
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 12/17] sctp: call sk_setup_caps in sctp_packet_transmit instead
  2020-10-08  9:48                       ` [PATCHv2 net-next 12/17] sctp: call sk_setup_caps in sctp_packet_transmit instead Xin Long
@ 2020-10-08  9:48                         ` Xin Long
  2020-10-08  9:48                         ` [PATCHv2 net-next 13/17] sctp: support for sending packet over udp4 sock Xin Long
  1 sibling, 0 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:48 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

sk_setup_caps() was originally called in Commit 90017accff61 ("sctp:
Add GSO support"), as:

  "We have to refresh this in case we are xmiting to more than one
   transport at a time"

This actually happens in the loop of sctp_outq_flush_transports(),
and it shouldn't be tied to gso, so move it out of gso part and
before sctp_packet_pack().

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 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) {
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 13/17] sctp: support for sending packet over udp4 sock
  2020-10-08  9:48                       ` [PATCHv2 net-next 12/17] sctp: call sk_setup_caps in sctp_packet_transmit instead Xin Long
  2020-10-08  9:48                         ` Xin Long
@ 2020-10-08  9:48                         ` Xin Long
  2020-10-08  9:48                           ` Xin Long
  2020-10-08  9:48                           ` [PATCHv2 net-next 14/17] sctp: support for sending packet over udp6 sock Xin Long
  1 sibling, 2 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:48 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

This patch does what the rfc6951#section-5.3 says for ipv4:

  "Within the UDP header, the source port MUST be the local UDP
   encapsulation port number of the SCTP stack, and the destination port
   MUST be the remote UDP encapsulation port number maintained for the
   association and the destination address to which the packet is sent
   (see Section 5.1).

   Because the SCTP packet is the UDP payload, the length of the UDP
   packet MUST be the length of the SCTP packet plus the size of the UDP
   header.

   The SCTP checksum MUST be computed for IPv4 and IPv6, and the UDP
   checksum SHOULD be computed for IPv4 and IPv6."

Some places need to be adjusted in sctp_packet_transmit():

  1. For non-gso packets, when transport's encap_port is set, sctp
     checksum has to be done in sctp_packet_pack(), as the outer
     udp will use ip_summed = CHECKSUM_PARTIAL to do the offload
     setting for checksum.

  2. Delay calling dst_clone() and skb_dst_set() for non-udp packets
     until sctp_v4_xmit(), as for udp packets, skb_dst_set() is not
     needed before calling udp_tunnel_xmit_skb().

then in sctp_v4_xmit():

  1. Go to udp_tunnel_xmit_skb() only when transport->encap_port and
     net->sctp.udp_port both are set, as these are one for dst port
     and another for src port.

  2. For gso packet, SKB_GSO_UDP_TUNNEL_CSUM is set for gso_type, and
     with this udp checksum can be done in __skb_udp_tunnel_segment()
     for each segments after the sctp gso.

  3. inner_mac_header and inner_transport_header are set, as these
     will be needed in __skb_udp_tunnel_segment() to find the right
     headers.

  4. df and ttl are calculated, as these are the required params by
     udp_tunnel_xmit_skb().

  5. nocheck param has to be false, as "the UDP checksum SHOULD be
     computed for IPv4 and IPv6", says in rfc6951#section-5.3.

v1->v2:
  - Use sp->udp_port instead in sctp_v4_xmit(), which is more safe.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 net/sctp/output.c   |  9 +++------
 net/sctp/protocol.c | 41 ++++++++++++++++++++++++++++++-----------
 2 files changed, 33 insertions(+), 17 deletions(-)

diff --git a/net/sctp/output.c b/net/sctp/output.c
index fb16500..6614c9f 100644
--- a/net/sctp/output.c
+++ b/net/sctp/output.c
@@ -514,8 +514,8 @@ static int sctp_packet_pack(struct sctp_packet *packet,
 	if (sctp_checksum_disable)
 		return 1;
 
-	if (!(skb_dst(head)->dev->features & NETIF_F_SCTP_CRC) ||
-	    dst_xfrm(skb_dst(head)) || packet->ipfragok) {
+	if (!(tp->dst->dev->features & NETIF_F_SCTP_CRC) ||
+	    dst_xfrm(tp->dst) || packet->ipfragok || tp->encap_port) {
 		struct sctphdr *sh  			(struct sctphdr *)skb_transport_header(head);
 
@@ -542,7 +542,6 @@ int sctp_packet_transmit(struct sctp_packet *packet, gfp_t gfp)
 	struct sctp_association *asoc = tp->asoc;
 	struct sctp_chunk *chunk, *tmp;
 	int pkt_count, gso = 0;
-	struct dst_entry *dst;
 	struct sk_buff *head;
 	struct sctphdr *sh;
 	struct sock *sk;
@@ -579,13 +578,11 @@ int sctp_packet_transmit(struct sctp_packet *packet, gfp_t gfp)
 	sh->checksum = 0;
 
 	/* drop packet if no dst */
-	dst = dst_clone(tp->dst);
-	if (!dst) {
+	if (!tp->dst) {
 		IP_INC_STATS(sock_net(sk), IPSTATS_MIB_OUTNOROUTES);
 		kfree_skb(head);
 		goto out;
 	}
-	skb_dst_set(head, dst);
 
 	rcu_read_lock();
 	if (__sk_dst_get(sk) != tp->dst) {
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index 0d16e5e..be002b7 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -1059,25 +1059,44 @@ static int sctp_inet_supported_addrs(const struct sctp_sock *opt,
 }
 
 /* Wrapper routine that calls the ip transmit routine. */
-static inline int sctp_v4_xmit(struct sk_buff *skb,
-			       struct sctp_transport *transport)
+static inline int sctp_v4_xmit(struct sk_buff *skb, struct sctp_transport *t)
 {
-	struct inet_sock *inet = inet_sk(skb->sk);
+	struct dst_entry *dst = dst_clone(t->dst);
+	struct flowi4 *fl4 = &t->fl.u.ip4;
+	struct sock *sk = skb->sk;
+	struct inet_sock *inet = inet_sk(sk);
 	__u8 dscp = inet->tos;
+	__be16 df = 0;
 
 	pr_debug("%s: skb:%p, len:%d, src:%pI4, dst:%pI4\n", __func__, skb,
-		 skb->len, &transport->fl.u.ip4.saddr,
-		 &transport->fl.u.ip4.daddr);
+		 skb->len, &fl4->saddr, &fl4->daddr);
+
+	if (t->dscp & SCTP_DSCP_SET_MASK)
+		dscp = t->dscp & SCTP_DSCP_VAL_MASK;
 
-	if (transport->dscp & SCTP_DSCP_SET_MASK)
-		dscp = transport->dscp & SCTP_DSCP_VAL_MASK;
+	inet->pmtudisc = t->param_flags & SPP_PMTUD_ENABLE ? IP_PMTUDISC_DO
+							   : IP_PMTUDISC_DONT;
+	SCTP_INC_STATS(sock_net(sk), SCTP_MIB_OUTSCTPPACKS);
 
-	inet->pmtudisc = transport->param_flags & SPP_PMTUD_ENABLE ?
-			 IP_PMTUDISC_DO : IP_PMTUDISC_DONT;
+	if (!t->encap_port || !sctp_sk(sk)->udp_port) {
+		skb_dst_set(skb, dst);
+		return __ip_queue_xmit(sk, skb, &t->fl, dscp);
+	}
+
+	if (skb_is_gso(skb))
+		skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL_CSUM;
 
-	SCTP_INC_STATS(sock_net(&inet->sk), SCTP_MIB_OUTSCTPPACKS);
+	if (ip_dont_fragment(sk, dst) && !skb->ignore_df)
+		df = htons(IP_DF);
 
-	return __ip_queue_xmit(&inet->sk, skb, &transport->fl, dscp);
+	skb->encapsulation = 1;
+	skb_reset_inner_mac_header(skb);
+	skb_reset_inner_transport_header(skb);
+	skb_set_inner_ipproto(skb, IPPROTO_SCTP);
+	udp_tunnel_xmit_skb((struct rtable *)dst, sk, skb, fl4->saddr,
+			    fl4->daddr, dscp, ip4_dst_hoplimit(dst), df,
+			    sctp_sk(sk)->udp_port, t->encap_port, false, false);
+	return 0;
 }
 
 static struct sctp_af sctp_af_inet;
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 13/17] sctp: support for sending packet over udp4 sock
  2020-10-08  9:48                         ` [PATCHv2 net-next 13/17] sctp: support for sending packet over udp4 sock Xin Long
@ 2020-10-08  9:48                           ` Xin Long
  2020-10-08  9:48                           ` [PATCHv2 net-next 14/17] sctp: support for sending packet over udp6 sock Xin Long
  1 sibling, 0 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:48 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

This patch does what the rfc6951#section-5.3 says for ipv4:

  "Within the UDP header, the source port MUST be the local UDP
   encapsulation port number of the SCTP stack, and the destination port
   MUST be the remote UDP encapsulation port number maintained for the
   association and the destination address to which the packet is sent
   (see Section 5.1).

   Because the SCTP packet is the UDP payload, the length of the UDP
   packet MUST be the length of the SCTP packet plus the size of the UDP
   header.

   The SCTP checksum MUST be computed for IPv4 and IPv6, and the UDP
   checksum SHOULD be computed for IPv4 and IPv6."

Some places need to be adjusted in sctp_packet_transmit():

  1. For non-gso packets, when transport's encap_port is set, sctp
     checksum has to be done in sctp_packet_pack(), as the outer
     udp will use ip_summed = CHECKSUM_PARTIAL to do the offload
     setting for checksum.

  2. Delay calling dst_clone() and skb_dst_set() for non-udp packets
     until sctp_v4_xmit(), as for udp packets, skb_dst_set() is not
     needed before calling udp_tunnel_xmit_skb().

then in sctp_v4_xmit():

  1. Go to udp_tunnel_xmit_skb() only when transport->encap_port and
     net->sctp.udp_port both are set, as these are one for dst port
     and another for src port.

  2. For gso packet, SKB_GSO_UDP_TUNNEL_CSUM is set for gso_type, and
     with this udp checksum can be done in __skb_udp_tunnel_segment()
     for each segments after the sctp gso.

  3. inner_mac_header and inner_transport_header are set, as these
     will be needed in __skb_udp_tunnel_segment() to find the right
     headers.

  4. df and ttl are calculated, as these are the required params by
     udp_tunnel_xmit_skb().

  5. nocheck param has to be false, as "the UDP checksum SHOULD be
     computed for IPv4 and IPv6", says in rfc6951#section-5.3.

v1->v2:
  - Use sp->udp_port instead in sctp_v4_xmit(), which is more safe.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 net/sctp/output.c   |  9 +++------
 net/sctp/protocol.c | 41 ++++++++++++++++++++++++++++++-----------
 2 files changed, 33 insertions(+), 17 deletions(-)

diff --git a/net/sctp/output.c b/net/sctp/output.c
index fb16500..6614c9f 100644
--- a/net/sctp/output.c
+++ b/net/sctp/output.c
@@ -514,8 +514,8 @@ static int sctp_packet_pack(struct sctp_packet *packet,
 	if (sctp_checksum_disable)
 		return 1;
 
-	if (!(skb_dst(head)->dev->features & NETIF_F_SCTP_CRC) ||
-	    dst_xfrm(skb_dst(head)) || packet->ipfragok) {
+	if (!(tp->dst->dev->features & NETIF_F_SCTP_CRC) ||
+	    dst_xfrm(tp->dst) || packet->ipfragok || tp->encap_port) {
 		struct sctphdr *sh =
 			(struct sctphdr *)skb_transport_header(head);
 
@@ -542,7 +542,6 @@ int sctp_packet_transmit(struct sctp_packet *packet, gfp_t gfp)
 	struct sctp_association *asoc = tp->asoc;
 	struct sctp_chunk *chunk, *tmp;
 	int pkt_count, gso = 0;
-	struct dst_entry *dst;
 	struct sk_buff *head;
 	struct sctphdr *sh;
 	struct sock *sk;
@@ -579,13 +578,11 @@ int sctp_packet_transmit(struct sctp_packet *packet, gfp_t gfp)
 	sh->checksum = 0;
 
 	/* drop packet if no dst */
-	dst = dst_clone(tp->dst);
-	if (!dst) {
+	if (!tp->dst) {
 		IP_INC_STATS(sock_net(sk), IPSTATS_MIB_OUTNOROUTES);
 		kfree_skb(head);
 		goto out;
 	}
-	skb_dst_set(head, dst);
 
 	rcu_read_lock();
 	if (__sk_dst_get(sk) != tp->dst) {
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index 0d16e5e..be002b7 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -1059,25 +1059,44 @@ static int sctp_inet_supported_addrs(const struct sctp_sock *opt,
 }
 
 /* Wrapper routine that calls the ip transmit routine. */
-static inline int sctp_v4_xmit(struct sk_buff *skb,
-			       struct sctp_transport *transport)
+static inline int sctp_v4_xmit(struct sk_buff *skb, struct sctp_transport *t)
 {
-	struct inet_sock *inet = inet_sk(skb->sk);
+	struct dst_entry *dst = dst_clone(t->dst);
+	struct flowi4 *fl4 = &t->fl.u.ip4;
+	struct sock *sk = skb->sk;
+	struct inet_sock *inet = inet_sk(sk);
 	__u8 dscp = inet->tos;
+	__be16 df = 0;
 
 	pr_debug("%s: skb:%p, len:%d, src:%pI4, dst:%pI4\n", __func__, skb,
-		 skb->len, &transport->fl.u.ip4.saddr,
-		 &transport->fl.u.ip4.daddr);
+		 skb->len, &fl4->saddr, &fl4->daddr);
+
+	if (t->dscp & SCTP_DSCP_SET_MASK)
+		dscp = t->dscp & SCTP_DSCP_VAL_MASK;
 
-	if (transport->dscp & SCTP_DSCP_SET_MASK)
-		dscp = transport->dscp & SCTP_DSCP_VAL_MASK;
+	inet->pmtudisc = t->param_flags & SPP_PMTUD_ENABLE ? IP_PMTUDISC_DO
+							   : IP_PMTUDISC_DONT;
+	SCTP_INC_STATS(sock_net(sk), SCTP_MIB_OUTSCTPPACKS);
 
-	inet->pmtudisc = transport->param_flags & SPP_PMTUD_ENABLE ?
-			 IP_PMTUDISC_DO : IP_PMTUDISC_DONT;
+	if (!t->encap_port || !sctp_sk(sk)->udp_port) {
+		skb_dst_set(skb, dst);
+		return __ip_queue_xmit(sk, skb, &t->fl, dscp);
+	}
+
+	if (skb_is_gso(skb))
+		skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL_CSUM;
 
-	SCTP_INC_STATS(sock_net(&inet->sk), SCTP_MIB_OUTSCTPPACKS);
+	if (ip_dont_fragment(sk, dst) && !skb->ignore_df)
+		df = htons(IP_DF);
 
-	return __ip_queue_xmit(&inet->sk, skb, &transport->fl, dscp);
+	skb->encapsulation = 1;
+	skb_reset_inner_mac_header(skb);
+	skb_reset_inner_transport_header(skb);
+	skb_set_inner_ipproto(skb, IPPROTO_SCTP);
+	udp_tunnel_xmit_skb((struct rtable *)dst, sk, skb, fl4->saddr,
+			    fl4->daddr, dscp, ip4_dst_hoplimit(dst), df,
+			    sctp_sk(sk)->udp_port, t->encap_port, false, false);
+	return 0;
 }
 
 static struct sctp_af sctp_af_inet;
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 14/17] sctp: support for sending packet over udp6 sock
  2020-10-08  9:48                         ` [PATCHv2 net-next 13/17] sctp: support for sending packet over udp4 sock Xin Long
  2020-10-08  9:48                           ` Xin Long
@ 2020-10-08  9:48                           ` Xin Long
  2020-10-08  9:48                             ` Xin Long
  2020-10-08  9:48                             ` [PATCHv2 net-next 15/17] sctp: add the error cause for new encapsulation port restart Xin Long
  1 sibling, 2 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:48 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

This one basically does the similar things in sctp_v6_xmit as does for
udp4 sock in the last patch, just note that:

  1. label needs to be calculated, as it's the param of
     udp_tunnel6_xmit_skb().

  2. The 'nocheck' param of udp_tunnel6_xmit_skb() is false, as
     required by RFC.

v1->v2:
  - Use sp->udp_port instead in sctp_v6_xmit(), which is more safe.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 net/sctp/ipv6.c | 43 ++++++++++++++++++++++++++++++++-----------
 1 file changed, 32 insertions(+), 11 deletions(-)

diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
index a064bf2..814754d 100644
--- a/net/sctp/ipv6.c
+++ b/net/sctp/ipv6.c
@@ -55,6 +55,7 @@
 #include <net/inet_common.h>
 #include <net/inet_ecn.h>
 #include <net/sctp/sctp.h>
+#include <net/udp_tunnel.h>
 
 #include <linux/uaccess.h>
 
@@ -191,33 +192,53 @@ static int sctp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
 	return ret;
 }
 
-static int sctp_v6_xmit(struct sk_buff *skb, struct sctp_transport *transport)
+static int sctp_v6_xmit(struct sk_buff *skb, struct sctp_transport *t)
 {
+	struct dst_entry *dst = dst_clone(t->dst);
+	struct flowi6 *fl6 = &t->fl.u.ip6;
 	struct sock *sk = skb->sk;
 	struct ipv6_pinfo *np = inet6_sk(sk);
-	struct flowi6 *fl6 = &transport->fl.u.ip6;
 	__u8 tclass = np->tclass;
-	int res;
+	__be32 label;
 
 	pr_debug("%s: skb:%p, len:%d, src:%pI6 dst:%pI6\n", __func__, skb,
 		 skb->len, &fl6->saddr, &fl6->daddr);
 
-	if (transport->dscp & SCTP_DSCP_SET_MASK)
-		tclass = transport->dscp & SCTP_DSCP_VAL_MASK;
+	if (t->dscp & SCTP_DSCP_SET_MASK)
+		tclass = t->dscp & SCTP_DSCP_VAL_MASK;
 
 	if (INET_ECN_is_capable(tclass))
 		IP6_ECN_flow_xmit(sk, fl6->flowlabel);
 
-	if (!(transport->param_flags & SPP_PMTUD_ENABLE))
+	if (!(t->param_flags & SPP_PMTUD_ENABLE))
 		skb->ignore_df = 1;
 
 	SCTP_INC_STATS(sock_net(sk), SCTP_MIB_OUTSCTPPACKS);
 
-	rcu_read_lock();
-	res = ip6_xmit(sk, skb, fl6, sk->sk_mark, rcu_dereference(np->opt),
-		       tclass, sk->sk_priority);
-	rcu_read_unlock();
-	return res;
+	if (!t->encap_port || !sctp_sk(sk)->udp_port) {
+		int res;
+
+		skb_dst_set(skb, dst);
+		rcu_read_lock();
+		res = ip6_xmit(sk, skb, fl6, sk->sk_mark,
+			       rcu_dereference(np->opt),
+			       tclass, sk->sk_priority);
+		rcu_read_unlock();
+		return res;
+	}
+
+	if (skb_is_gso(skb))
+		skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL_CSUM;
+
+	skb->encapsulation = 1;
+	skb_reset_inner_mac_header(skb);
+	skb_reset_inner_transport_header(skb);
+	skb_set_inner_ipproto(skb, IPPROTO_SCTP);
+	label = ip6_make_flowlabel(sock_net(sk), skb, fl6->flowlabel, true, fl6);
+
+	return udp_tunnel6_xmit_skb(dst, sk, skb, NULL, &fl6->saddr,
+				    &fl6->daddr, tclass, ip6_dst_hoplimit(dst),
+				    label, sctp_sk(sk)->udp_port, t->encap_port, false);
 }
 
 /* Returns the dst cache entry for the given source and destination ip
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 14/17] sctp: support for sending packet over udp6 sock
  2020-10-08  9:48                           ` [PATCHv2 net-next 14/17] sctp: support for sending packet over udp6 sock Xin Long
@ 2020-10-08  9:48                             ` Xin Long
  2020-10-08  9:48                             ` [PATCHv2 net-next 15/17] sctp: add the error cause for new encapsulation port restart Xin Long
  1 sibling, 0 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:48 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

This one basically does the similar things in sctp_v6_xmit as does for
udp4 sock in the last patch, just note that:

  1. label needs to be calculated, as it's the param of
     udp_tunnel6_xmit_skb().

  2. The 'nocheck' param of udp_tunnel6_xmit_skb() is false, as
     required by RFC.

v1->v2:
  - Use sp->udp_port instead in sctp_v6_xmit(), which is more safe.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 net/sctp/ipv6.c | 43 ++++++++++++++++++++++++++++++++-----------
 1 file changed, 32 insertions(+), 11 deletions(-)

diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
index a064bf2..814754d 100644
--- a/net/sctp/ipv6.c
+++ b/net/sctp/ipv6.c
@@ -55,6 +55,7 @@
 #include <net/inet_common.h>
 #include <net/inet_ecn.h>
 #include <net/sctp/sctp.h>
+#include <net/udp_tunnel.h>
 
 #include <linux/uaccess.h>
 
@@ -191,33 +192,53 @@ static int sctp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
 	return ret;
 }
 
-static int sctp_v6_xmit(struct sk_buff *skb, struct sctp_transport *transport)
+static int sctp_v6_xmit(struct sk_buff *skb, struct sctp_transport *t)
 {
+	struct dst_entry *dst = dst_clone(t->dst);
+	struct flowi6 *fl6 = &t->fl.u.ip6;
 	struct sock *sk = skb->sk;
 	struct ipv6_pinfo *np = inet6_sk(sk);
-	struct flowi6 *fl6 = &transport->fl.u.ip6;
 	__u8 tclass = np->tclass;
-	int res;
+	__be32 label;
 
 	pr_debug("%s: skb:%p, len:%d, src:%pI6 dst:%pI6\n", __func__, skb,
 		 skb->len, &fl6->saddr, &fl6->daddr);
 
-	if (transport->dscp & SCTP_DSCP_SET_MASK)
-		tclass = transport->dscp & SCTP_DSCP_VAL_MASK;
+	if (t->dscp & SCTP_DSCP_SET_MASK)
+		tclass = t->dscp & SCTP_DSCP_VAL_MASK;
 
 	if (INET_ECN_is_capable(tclass))
 		IP6_ECN_flow_xmit(sk, fl6->flowlabel);
 
-	if (!(transport->param_flags & SPP_PMTUD_ENABLE))
+	if (!(t->param_flags & SPP_PMTUD_ENABLE))
 		skb->ignore_df = 1;
 
 	SCTP_INC_STATS(sock_net(sk), SCTP_MIB_OUTSCTPPACKS);
 
-	rcu_read_lock();
-	res = ip6_xmit(sk, skb, fl6, sk->sk_mark, rcu_dereference(np->opt),
-		       tclass, sk->sk_priority);
-	rcu_read_unlock();
-	return res;
+	if (!t->encap_port || !sctp_sk(sk)->udp_port) {
+		int res;
+
+		skb_dst_set(skb, dst);
+		rcu_read_lock();
+		res = ip6_xmit(sk, skb, fl6, sk->sk_mark,
+			       rcu_dereference(np->opt),
+			       tclass, sk->sk_priority);
+		rcu_read_unlock();
+		return res;
+	}
+
+	if (skb_is_gso(skb))
+		skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL_CSUM;
+
+	skb->encapsulation = 1;
+	skb_reset_inner_mac_header(skb);
+	skb_reset_inner_transport_header(skb);
+	skb_set_inner_ipproto(skb, IPPROTO_SCTP);
+	label = ip6_make_flowlabel(sock_net(sk), skb, fl6->flowlabel, true, fl6);
+
+	return udp_tunnel6_xmit_skb(dst, sk, skb, NULL, &fl6->saddr,
+				    &fl6->daddr, tclass, ip6_dst_hoplimit(dst),
+				    label, sctp_sk(sk)->udp_port, t->encap_port, false);
 }
 
 /* Returns the dst cache entry for the given source and destination ip
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 15/17] sctp: add the error cause for new encapsulation port restart
  2020-10-08  9:48                           ` [PATCHv2 net-next 14/17] sctp: support for sending packet over udp6 sock Xin Long
  2020-10-08  9:48                             ` Xin Long
@ 2020-10-08  9:48                             ` Xin Long
  2020-10-08  9:48                               ` Xin Long
                                                 ` (2 more replies)
  1 sibling, 3 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:48 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

This patch is to add the function to make the abort chunk with
the error cause for new encapsulation port restart, defined
on Section 4.4 in draft-tuexen-tsvwg-sctp-udp-encaps-cons-03.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 include/linux/sctp.h     | 20 ++++++++++++++++++++
 include/net/sctp/sm.h    |  3 +++
 net/sctp/sm_make_chunk.c | 20 ++++++++++++++++++++
 3 files changed, 43 insertions(+)

diff --git a/include/linux/sctp.h b/include/linux/sctp.h
index 7673123..bb19265 100644
--- a/include/linux/sctp.h
+++ b/include/linux/sctp.h
@@ -482,11 +482,13 @@ enum sctp_error {
 	 *  11  Restart of an association with new addresses
 	 *  12  User Initiated Abort
 	 *  13  Protocol Violation
+	 *  14  Restart of an Association with New Encapsulation Port
 	 */
 
 	SCTP_ERROR_RESTART         = cpu_to_be16(0x0b),
 	SCTP_ERROR_USER_ABORT      = cpu_to_be16(0x0c),
 	SCTP_ERROR_PROTO_VIOLATION = cpu_to_be16(0x0d),
+	SCTP_ERROR_NEW_ENCAP_PORT  = cpu_to_be16(0x0e),
 
 	/* ADDIP Section 3.3  New Error Causes
 	 *
@@ -793,4 +795,22 @@ enum {
 	SCTP_FLOWLABEL_VAL_MASK = 0xfffff
 };
 
+/* UDP Encapsulation
+ * draft-tuexen-tsvwg-sctp-udp-encaps-cons-03.html#section-4-4
+ *
+ *   The error cause indicating an "Restart of an Association with
+ *   New Encapsulation Port"
+ *
+ * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |        Cause Code = 14        |       Cause Length = 8        |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |   Current Encapsulation Port  |     New Encapsulation Port    |
+ * +-------------------------------+-------------------------------+
+ */
+struct sctp_new_encap_port_hdr {
+	__be16 cur_port;
+	__be16 new_port;
+};
+
 #endif /* __LINUX_SCTP_H__ */
diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
index a499341..fd223c9 100644
--- a/include/net/sctp/sm.h
+++ b/include/net/sctp/sm.h
@@ -221,6 +221,9 @@ struct sctp_chunk *sctp_make_violation_paramlen(
 struct sctp_chunk *sctp_make_violation_max_retrans(
 					const struct sctp_association *asoc,
 					const struct sctp_chunk *chunk);
+struct sctp_chunk *sctp_make_new_encap_port(
+					const struct sctp_association *asoc,
+					const struct sctp_chunk *chunk);
 struct sctp_chunk *sctp_make_heartbeat(const struct sctp_association *asoc,
 				       const struct sctp_transport *transport);
 struct sctp_chunk *sctp_make_heartbeat_ack(const struct sctp_association *asoc,
diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
index 21d0ff1..3bf1399 100644
--- a/net/sctp/sm_make_chunk.c
+++ b/net/sctp/sm_make_chunk.c
@@ -1142,6 +1142,26 @@ struct sctp_chunk *sctp_make_violation_max_retrans(
 	return retval;
 }
 
+struct sctp_chunk *sctp_make_new_encap_port(const struct sctp_association *asoc,
+					    const struct sctp_chunk *chunk)
+{
+	struct sctp_new_encap_port_hdr nep;
+	struct sctp_chunk *retval;
+
+	retval = sctp_make_abort(asoc, chunk,
+				 sizeof(struct sctp_errhdr) + sizeof(nep));
+	if (!retval)
+		goto nodata;
+
+	sctp_init_cause(retval, SCTP_ERROR_NEW_ENCAP_PORT, sizeof(nep));
+	nep.cur_port = htons(SCTP_INPUT_CB(chunk->skb)->encap_port);
+	nep.new_port = htons(chunk->transport->encap_port);
+	sctp_addto_chunk(retval, sizeof(nep), &nep);
+
+nodata:
+	return retval;
+}
+
 /* Make a HEARTBEAT chunk.  */
 struct sctp_chunk *sctp_make_heartbeat(const struct sctp_association *asoc,
 				       const struct sctp_transport *transport)
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 15/17] sctp: add the error cause for new encapsulation port restart
  2020-10-08  9:48                             ` [PATCHv2 net-next 15/17] sctp: add the error cause for new encapsulation port restart Xin Long
@ 2020-10-08  9:48                               ` Xin Long
  2020-10-08  9:48                               ` [PATCHv2 net-next 16/17] sctp: handle the init chunk matching an existing asoc Xin Long
  2020-10-08 14:33                               ` [PATCHv2 net-next 15/17] sctp: add the error cause for new encapsulation port restart kernel test robot
  2 siblings, 0 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:48 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

This patch is to add the function to make the abort chunk with
the error cause for new encapsulation port restart, defined
on Section 4.4 in draft-tuexen-tsvwg-sctp-udp-encaps-cons-03.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 include/linux/sctp.h     | 20 ++++++++++++++++++++
 include/net/sctp/sm.h    |  3 +++
 net/sctp/sm_make_chunk.c | 20 ++++++++++++++++++++
 3 files changed, 43 insertions(+)

diff --git a/include/linux/sctp.h b/include/linux/sctp.h
index 7673123..bb19265 100644
--- a/include/linux/sctp.h
+++ b/include/linux/sctp.h
@@ -482,11 +482,13 @@ enum sctp_error {
 	 *  11  Restart of an association with new addresses
 	 *  12  User Initiated Abort
 	 *  13  Protocol Violation
+	 *  14  Restart of an Association with New Encapsulation Port
 	 */
 
 	SCTP_ERROR_RESTART         = cpu_to_be16(0x0b),
 	SCTP_ERROR_USER_ABORT      = cpu_to_be16(0x0c),
 	SCTP_ERROR_PROTO_VIOLATION = cpu_to_be16(0x0d),
+	SCTP_ERROR_NEW_ENCAP_PORT  = cpu_to_be16(0x0e),
 
 	/* ADDIP Section 3.3  New Error Causes
 	 *
@@ -793,4 +795,22 @@ enum {
 	SCTP_FLOWLABEL_VAL_MASK = 0xfffff
 };
 
+/* UDP Encapsulation
+ * draft-tuexen-tsvwg-sctp-udp-encaps-cons-03.html#section-4-4
+ *
+ *   The error cause indicating an "Restart of an Association with
+ *   New Encapsulation Port"
+ *
+ * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |        Cause Code = 14        |       Cause Length = 8        |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |   Current Encapsulation Port  |     New Encapsulation Port    |
+ * +-------------------------------+-------------------------------+
+ */
+struct sctp_new_encap_port_hdr {
+	__be16 cur_port;
+	__be16 new_port;
+};
+
 #endif /* __LINUX_SCTP_H__ */
diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
index a499341..fd223c9 100644
--- a/include/net/sctp/sm.h
+++ b/include/net/sctp/sm.h
@@ -221,6 +221,9 @@ struct sctp_chunk *sctp_make_violation_paramlen(
 struct sctp_chunk *sctp_make_violation_max_retrans(
 					const struct sctp_association *asoc,
 					const struct sctp_chunk *chunk);
+struct sctp_chunk *sctp_make_new_encap_port(
+					const struct sctp_association *asoc,
+					const struct sctp_chunk *chunk);
 struct sctp_chunk *sctp_make_heartbeat(const struct sctp_association *asoc,
 				       const struct sctp_transport *transport);
 struct sctp_chunk *sctp_make_heartbeat_ack(const struct sctp_association *asoc,
diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
index 21d0ff1..3bf1399 100644
--- a/net/sctp/sm_make_chunk.c
+++ b/net/sctp/sm_make_chunk.c
@@ -1142,6 +1142,26 @@ struct sctp_chunk *sctp_make_violation_max_retrans(
 	return retval;
 }
 
+struct sctp_chunk *sctp_make_new_encap_port(const struct sctp_association *asoc,
+					    const struct sctp_chunk *chunk)
+{
+	struct sctp_new_encap_port_hdr nep;
+	struct sctp_chunk *retval;
+
+	retval = sctp_make_abort(asoc, chunk,
+				 sizeof(struct sctp_errhdr) + sizeof(nep));
+	if (!retval)
+		goto nodata;
+
+	sctp_init_cause(retval, SCTP_ERROR_NEW_ENCAP_PORT, sizeof(nep));
+	nep.cur_port = htons(SCTP_INPUT_CB(chunk->skb)->encap_port);
+	nep.new_port = htons(chunk->transport->encap_port);
+	sctp_addto_chunk(retval, sizeof(nep), &nep);
+
+nodata:
+	return retval;
+}
+
 /* Make a HEARTBEAT chunk.  */
 struct sctp_chunk *sctp_make_heartbeat(const struct sctp_association *asoc,
 				       const struct sctp_transport *transport)
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 16/17] sctp: handle the init chunk matching an existing asoc
  2020-10-08  9:48                             ` [PATCHv2 net-next 15/17] sctp: add the error cause for new encapsulation port restart Xin Long
  2020-10-08  9:48                               ` Xin Long
@ 2020-10-08  9:48                               ` Xin Long
  2020-10-08  9:48                                 ` Xin Long
  2020-10-08  9:48                                 ` [PATCHv2 net-next 17/17] sctp: enable udp tunneling socks Xin Long
  2020-10-08 14:33                               ` [PATCHv2 net-next 15/17] sctp: add the error cause for new encapsulation port restart kernel test robot
  2 siblings, 2 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:48 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

This is from Section 4 of draft-tuexen-tsvwg-sctp-udp-encaps-cons-03,
and it requires responding with an abort chunk with an error cause
when the udp source port of the received init chunk doesn't match the
encap port of the transport.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 net/sctp/sm_statefuns.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index 8edab15..244a5d8 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -87,6 +87,13 @@ static enum sctp_disposition sctp_sf_tabort_8_4_8(
 					const union sctp_subtype type,
 					void *arg,
 					struct sctp_cmd_seq *commands);
+static enum sctp_disposition sctp_sf_new_encap_port(
+					struct net *net,
+					const struct sctp_endpoint *ep,
+					const struct sctp_association *asoc,
+					const union sctp_subtype type,
+					void *arg,
+					struct sctp_cmd_seq *commands);
 static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk);
 
 static enum sctp_disposition sctp_stop_t1_and_abort(
@@ -1493,6 +1500,10 @@ static enum sctp_disposition sctp_sf_do_unexpected_init(
 	if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_init_chunk)))
 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
 						  commands);
+
+	if (SCTP_INPUT_CB(chunk->skb)->encap_port != chunk->transport->encap_port)
+		return sctp_sf_new_encap_port(net, ep, asoc, type, arg, commands);
+
 	/* Grab the INIT header.  */
 	chunk->subh.init_hdr = (struct sctp_inithdr *)chunk->skb->data;
 
@@ -3392,6 +3403,45 @@ static enum sctp_disposition sctp_sf_tabort_8_4_8(
 
 	sctp_packet_append_chunk(packet, abort);
 
+	sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(packet));
+
+	SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
+
+	sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
+	return SCTP_DISPOSITION_CONSUME;
+}
+
+/* Handling of SCTP Packets Containing an INIT Chunk Matching an
+ * Existing Associations when the udp encap port is incorrect.
+ *
+ * From Section 4 at draft-tuexen-tsvwg-sctp-udp-encaps-cons-03.
+ */
+static enum sctp_disposition sctp_sf_new_encap_port(
+					struct net *net,
+					const struct sctp_endpoint *ep,
+					const struct sctp_association *asoc,
+					const union sctp_subtype type,
+					void *arg,
+					struct sctp_cmd_seq *commands)
+{
+	struct sctp_packet *packet = NULL;
+	struct sctp_chunk *chunk = arg;
+	struct sctp_chunk *abort;
+
+	packet = sctp_ootb_pkt_new(net, asoc, chunk);
+	if (!packet)
+		return SCTP_DISPOSITION_NOMEM;
+
+	abort = sctp_make_new_encap_port(asoc, chunk);
+	if (!abort) {
+		sctp_ootb_pkt_free(packet);
+		return SCTP_DISPOSITION_NOMEM;
+	}
+
+	abort->skb->sk = ep->base.sk;
+
+	sctp_packet_append_chunk(packet, abort);
+
 	sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
 			SCTP_PACKET(packet));
 
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 16/17] sctp: handle the init chunk matching an existing asoc
  2020-10-08  9:48                               ` [PATCHv2 net-next 16/17] sctp: handle the init chunk matching an existing asoc Xin Long
@ 2020-10-08  9:48                                 ` Xin Long
  2020-10-08  9:48                                 ` [PATCHv2 net-next 17/17] sctp: enable udp tunneling socks Xin Long
  1 sibling, 0 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:48 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

This is from Section 4 of draft-tuexen-tsvwg-sctp-udp-encaps-cons-03,
and it requires responding with an abort chunk with an error cause
when the udp source port of the received init chunk doesn't match the
encap port of the transport.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 net/sctp/sm_statefuns.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index 8edab15..244a5d8 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -87,6 +87,13 @@ static enum sctp_disposition sctp_sf_tabort_8_4_8(
 					const union sctp_subtype type,
 					void *arg,
 					struct sctp_cmd_seq *commands);
+static enum sctp_disposition sctp_sf_new_encap_port(
+					struct net *net,
+					const struct sctp_endpoint *ep,
+					const struct sctp_association *asoc,
+					const union sctp_subtype type,
+					void *arg,
+					struct sctp_cmd_seq *commands);
 static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk);
 
 static enum sctp_disposition sctp_stop_t1_and_abort(
@@ -1493,6 +1500,10 @@ static enum sctp_disposition sctp_sf_do_unexpected_init(
 	if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_init_chunk)))
 		return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
 						  commands);
+
+	if (SCTP_INPUT_CB(chunk->skb)->encap_port != chunk->transport->encap_port)
+		return sctp_sf_new_encap_port(net, ep, asoc, type, arg, commands);
+
 	/* Grab the INIT header.  */
 	chunk->subh.init_hdr = (struct sctp_inithdr *)chunk->skb->data;
 
@@ -3392,6 +3403,45 @@ static enum sctp_disposition sctp_sf_tabort_8_4_8(
 
 	sctp_packet_append_chunk(packet, abort);
 
+	sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(packet));
+
+	SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
+
+	sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
+	return SCTP_DISPOSITION_CONSUME;
+}
+
+/* Handling of SCTP Packets Containing an INIT Chunk Matching an
+ * Existing Associations when the udp encap port is incorrect.
+ *
+ * From Section 4 at draft-tuexen-tsvwg-sctp-udp-encaps-cons-03.
+ */
+static enum sctp_disposition sctp_sf_new_encap_port(
+					struct net *net,
+					const struct sctp_endpoint *ep,
+					const struct sctp_association *asoc,
+					const union sctp_subtype type,
+					void *arg,
+					struct sctp_cmd_seq *commands)
+{
+	struct sctp_packet *packet = NULL;
+	struct sctp_chunk *chunk = arg;
+	struct sctp_chunk *abort;
+
+	packet = sctp_ootb_pkt_new(net, asoc, chunk);
+	if (!packet)
+		return SCTP_DISPOSITION_NOMEM;
+
+	abort = sctp_make_new_encap_port(asoc, chunk);
+	if (!abort) {
+		sctp_ootb_pkt_free(packet);
+		return SCTP_DISPOSITION_NOMEM;
+	}
+
+	abort->skb->sk = ep->base.sk;
+
+	sctp_packet_append_chunk(packet, abort);
+
 	sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
 			SCTP_PACKET(packet));
 
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 17/17] sctp: enable udp tunneling socks
  2020-10-08  9:48                               ` [PATCHv2 net-next 16/17] sctp: handle the init chunk matching an existing asoc Xin Long
  2020-10-08  9:48                                 ` Xin Long
@ 2020-10-08  9:48                                 ` Xin Long
  2020-10-08  9:48                                   ` Xin Long
  2020-10-08 15:46                                   ` kernel test robot
  1 sibling, 2 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:48 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

This patch is to enable udp tunneling socks by calling
sctp_udp_sock_start() in sctp_ctrlsock_init(), and
sctp_udp_sock_stop() in sctp_ctrlsock_exit().

Also add sysctl udp_port to allow changing the listening
sock's port by users.

Wit this patch, the whole sctp over udp feature can be
enabled and used.

v1->v2:
  - Also update ctl_sock udp_port in proc_sctp_do_udp_port()
    where netns udp_port gets changed.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 net/sctp/protocol.c |  5 +++++
 net/sctp/sysctl.c   | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+)

diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index be002b7..79fb4b5 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -1469,6 +1469,10 @@ static int __net_init sctp_ctrlsock_init(struct net *net)
 	if (status)
 		pr_err("Failed to initialize the SCTP control sock\n");
 
+	status = sctp_udp_sock_start(net);
+	if (status)
+		pr_err("Failed to initialize the SCTP udp tunneling sock\n");
+
 	return status;
 }
 
@@ -1476,6 +1480,7 @@ static void __net_exit sctp_ctrlsock_exit(struct net *net)
 {
 	/* Free the control endpoint.  */
 	inet_ctl_sock_destroy(net->sctp.ctl_sock);
+	sctp_udp_sock_stop(net);
 }
 
 static struct pernet_operations sctp_ctrlsock_ops = {
diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
index ecc1b5e..a723613 100644
--- a/net/sctp/sysctl.c
+++ b/net/sctp/sysctl.c
@@ -49,6 +49,8 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
 				void *buffer, size_t *lenp, loff_t *ppos);
 static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write, void *buffer,
 				size_t *lenp, loff_t *ppos);
+static int proc_sctp_do_udp_port(struct ctl_table *ctl, int write, void *buffer,
+				 size_t *lenp, loff_t *ppos);
 static int proc_sctp_do_alpha_beta(struct ctl_table *ctl, int write,
 				   void *buffer, size_t *lenp, loff_t *ppos);
 static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
@@ -292,6 +294,15 @@ static struct ctl_table sctp_net_table[] = {
 		.proc_handler	= proc_dointvec,
 	},
 	{
+		.procname	= "udp_port",
+		.data		= &init_net.sctp.udp_port,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_sctp_do_udp_port,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= &udp_port_max,
+	},
+	{
 		.procname	= "encap_port",
 		.data		= &init_net.sctp.encap_port,
 		.maxlen		= sizeof(int),
@@ -487,6 +498,44 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
 	return ret;
 }
 
+static int proc_sctp_do_udp_port(struct ctl_table *ctl, int write,
+				 void *buffer, size_t *lenp, loff_t *ppos)
+{
+	struct net *net = current->nsproxy->net_ns;
+	unsigned int min = *(unsigned int *)ctl->extra1;
+	unsigned int max = *(unsigned int *)ctl->extra2;
+	struct ctl_table tbl;
+	int ret, new_value;
+
+	memset(&tbl, 0, sizeof(struct ctl_table));
+	tbl.maxlen = sizeof(unsigned int);
+
+	if (write)
+		tbl.data = &new_value;
+	else
+		tbl.data = &net->sctp.udp_port;
+
+	ret = proc_dointvec(&tbl, write, buffer, lenp, ppos);
+	if (write && ret = 0) {
+		struct sock *sk = net->sctp.ctl_sock;
+
+		if (new_value > max || new_value < min)
+			return -EINVAL;
+
+		net->sctp.udp_port = new_value;
+		sctp_udp_sock_stop(net);
+		ret = sctp_udp_sock_start(net);
+		if (ret)
+			net->sctp.udp_port = 0;
+
+		lock_sock(sk);
+		sctp_sk(sk)->udp_port = net->sctp.udp_port;
+		release_sock(sk);
+	}
+
+	return ret;
+}
+
 int sctp_sysctl_net_register(struct net *net)
 {
 	struct ctl_table *table;
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* [PATCHv2 net-next 17/17] sctp: enable udp tunneling socks
  2020-10-08  9:48                                 ` [PATCHv2 net-next 17/17] sctp: enable udp tunneling socks Xin Long
@ 2020-10-08  9:48                                   ` Xin Long
  2020-10-08 15:46                                   ` kernel test robot
  1 sibling, 0 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08  9:48 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

This patch is to enable udp tunneling socks by calling
sctp_udp_sock_start() in sctp_ctrlsock_init(), and
sctp_udp_sock_stop() in sctp_ctrlsock_exit().

Also add sysctl udp_port to allow changing the listening
sock's port by users.

Wit this patch, the whole sctp over udp feature can be
enabled and used.

v1->v2:
  - Also update ctl_sock udp_port in proc_sctp_do_udp_port()
    where netns udp_port gets changed.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 net/sctp/protocol.c |  5 +++++
 net/sctp/sysctl.c   | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+)

diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index be002b7..79fb4b5 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -1469,6 +1469,10 @@ static int __net_init sctp_ctrlsock_init(struct net *net)
 	if (status)
 		pr_err("Failed to initialize the SCTP control sock\n");
 
+	status = sctp_udp_sock_start(net);
+	if (status)
+		pr_err("Failed to initialize the SCTP udp tunneling sock\n");
+
 	return status;
 }
 
@@ -1476,6 +1480,7 @@ static void __net_exit sctp_ctrlsock_exit(struct net *net)
 {
 	/* Free the control endpoint.  */
 	inet_ctl_sock_destroy(net->sctp.ctl_sock);
+	sctp_udp_sock_stop(net);
 }
 
 static struct pernet_operations sctp_ctrlsock_ops = {
diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
index ecc1b5e..a723613 100644
--- a/net/sctp/sysctl.c
+++ b/net/sctp/sysctl.c
@@ -49,6 +49,8 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
 				void *buffer, size_t *lenp, loff_t *ppos);
 static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write, void *buffer,
 				size_t *lenp, loff_t *ppos);
+static int proc_sctp_do_udp_port(struct ctl_table *ctl, int write, void *buffer,
+				 size_t *lenp, loff_t *ppos);
 static int proc_sctp_do_alpha_beta(struct ctl_table *ctl, int write,
 				   void *buffer, size_t *lenp, loff_t *ppos);
 static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
@@ -292,6 +294,15 @@ static struct ctl_table sctp_net_table[] = {
 		.proc_handler	= proc_dointvec,
 	},
 	{
+		.procname	= "udp_port",
+		.data		= &init_net.sctp.udp_port,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_sctp_do_udp_port,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= &udp_port_max,
+	},
+	{
 		.procname	= "encap_port",
 		.data		= &init_net.sctp.encap_port,
 		.maxlen		= sizeof(int),
@@ -487,6 +498,44 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
 	return ret;
 }
 
+static int proc_sctp_do_udp_port(struct ctl_table *ctl, int write,
+				 void *buffer, size_t *lenp, loff_t *ppos)
+{
+	struct net *net = current->nsproxy->net_ns;
+	unsigned int min = *(unsigned int *)ctl->extra1;
+	unsigned int max = *(unsigned int *)ctl->extra2;
+	struct ctl_table tbl;
+	int ret, new_value;
+
+	memset(&tbl, 0, sizeof(struct ctl_table));
+	tbl.maxlen = sizeof(unsigned int);
+
+	if (write)
+		tbl.data = &new_value;
+	else
+		tbl.data = &net->sctp.udp_port;
+
+	ret = proc_dointvec(&tbl, write, buffer, lenp, ppos);
+	if (write && ret == 0) {
+		struct sock *sk = net->sctp.ctl_sock;
+
+		if (new_value > max || new_value < min)
+			return -EINVAL;
+
+		net->sctp.udp_port = new_value;
+		sctp_udp_sock_stop(net);
+		ret = sctp_udp_sock_start(net);
+		if (ret)
+			net->sctp.udp_port = 0;
+
+		lock_sock(sk);
+		sctp_sk(sk)->udp_port = net->sctp.udp_port;
+		release_sock(sk);
+	}
+
+	return ret;
+}
+
 int sctp_sysctl_net_register(struct net *net)
 {
 	struct ctl_table *table;
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 62+ messages in thread

* Re: [PATCHv2 net-next 03/17] udp: do checksum properly in skb_udp_tunnel_segment
  2020-10-08  9:47     ` [PATCHv2 net-next 03/17] udp: do checksum properly in skb_udp_tunnel_segment Xin Long
  2020-10-08  9:47       ` Xin Long
  2020-10-08  9:48       ` [PATCHv2 net-next 04/17] udp: support sctp over udp " Xin Long
@ 2020-10-08 10:01       ` Xin Long
  2020-10-08 10:01         ` Xin Long
  2 siblings, 1 reply; 62+ messages in thread
From: Xin Long @ 2020-10-08 10:01 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem, Tom Herbert

CCing Tom Herbert

On Thu, Oct 8, 2020 at 5:48 PM Xin Long <lucien.xin@gmail.com> wrote:
>
> This patch fixes two things:
>
>   When skb->ip_summed = CHECKSUM_PARTIAL, skb_checksum_help() should be
>   called do the checksum, instead of gso_make_checksum(), which is used
>   to do the checksum for current proto after calling skb_segment(), not
>   after the inner proto's gso_segment().
>
>   When offload_csum is disabled, the hardware will not do the checksum
>   for the current proto, udp. So instead of calling gso_make_checksum(),
>   it should calculate checksum for udp itself.
>
> Cc: Tom Herbert <tom@herbertland.com>
> Signed-off-by: Xin Long <lucien.xin@gmail.com>
> ---
>  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:
> --
> 2.1.0
>

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCHv2 net-next 03/17] udp: do checksum properly in skb_udp_tunnel_segment
  2020-10-08 10:01       ` [PATCHv2 net-next 03/17] udp: do checksum properly " Xin Long
@ 2020-10-08 10:01         ` Xin Long
  0 siblings, 0 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08 10:01 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem, Tom Herbert

CCing Tom Herbert

On Thu, Oct 8, 2020 at 5:48 PM Xin Long <lucien.xin@gmail.com> wrote:
>
> This patch fixes two things:
>
>   When skb->ip_summed == CHECKSUM_PARTIAL, skb_checksum_help() should be
>   called do the checksum, instead of gso_make_checksum(), which is used
>   to do the checksum for current proto after calling skb_segment(), not
>   after the inner proto's gso_segment().
>
>   When offload_csum is disabled, the hardware will not do the checksum
>   for the current proto, udp. So instead of calling gso_make_checksum(),
>   it should calculate checksum for udp itself.
>
> Cc: Tom Herbert <tom@herbertland.com>
> Signed-off-by: Xin Long <lucien.xin@gmail.com>
> ---
>  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:
> --
> 2.1.0
>

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCHv2 net-next 04/17] udp: support sctp over udp in skb_udp_tunnel_segment
  2020-10-08  9:48       ` [PATCHv2 net-next 04/17] udp: support sctp over udp " Xin Long
  2020-10-08  9:48         ` Xin Long
  2020-10-08  9:48         ` [PATCHv2 net-next 05/17] sctp: create udp4 sock and add its encap_rcv Xin Long
@ 2020-10-08 10:01         ` Xin Long
  2020-10-08 10:01           ` Xin Long
  2 siblings, 1 reply; 62+ messages in thread
From: Xin Long @ 2020-10-08 10:01 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem, Tom Herbert

CCing Tom Herbert

On Thu, Oct 8, 2020 at 5:48 PM Xin Long <lucien.xin@gmail.com> wrote:
>
> To call sctp_gso_segment() properly in skb_udp_tunnel_segment() for sctp
> over udp packets, we need to set transport_header to sctp header. When
> skb->ip_summed = CHECKSUM_PARTIAL, skb_crc32c_csum_help() should be
> called for the inner sctp packet.
>
> Cc: Tom Herbert <tom@herbertland.com>
> Signed-off-by: Xin Long <lucien.xin@gmail.com>
> ---
>  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;
> --
> 2.1.0
>

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCHv2 net-next 04/17] udp: support sctp over udp in skb_udp_tunnel_segment
  2020-10-08 10:01         ` [PATCHv2 net-next 04/17] udp: support sctp over udp in skb_udp_tunnel_segment Xin Long
@ 2020-10-08 10:01           ` Xin Long
  0 siblings, 0 replies; 62+ messages in thread
From: Xin Long @ 2020-10-08 10:01 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem, Tom Herbert

CCing Tom Herbert

On Thu, Oct 8, 2020 at 5:48 PM Xin Long <lucien.xin@gmail.com> wrote:
>
> To call sctp_gso_segment() properly in skb_udp_tunnel_segment() for sctp
> over udp packets, we need to set transport_header to sctp header. When
> skb->ip_summed == CHECKSUM_PARTIAL, skb_crc32c_csum_help() should be
> called for the inner sctp packet.
>
> Cc: Tom Herbert <tom@herbertland.com>
> Signed-off-by: Xin Long <lucien.xin@gmail.com>
> ---
>  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;
> --
> 2.1.0
>

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCHv2 net-next 02/17] udp6: move the mss check after udp gso tunnel processing
  2020-10-08  9:47   ` [PATCHv2 net-next 02/17] udp6: move the mss check after udp gso tunnel processing Xin Long
  2020-10-08  9:47     ` Xin Long
  2020-10-08  9:47     ` [PATCHv2 net-next 03/17] udp: do checksum properly in skb_udp_tunnel_segment Xin Long
@ 2020-10-08 12:44     ` Willem de Bruijn
  2020-10-08 12:44       ` Willem de Bruijn
  2020-10-09  1:48       ` Xin Long
  2 siblings, 2 replies; 62+ messages in thread
From: Willem de Bruijn @ 2020-10-08 12:44 UTC (permalink / raw)
  To: Xin Long
  Cc: network dev, linux-sctp, Marcelo Ricardo Leitner, Neil Horman,
	Michael Tuexen, David Miller

On Thu, Oct 8, 2020 at 5:48 AM Xin Long <lucien.xin@gmail.com> wrote:
>
> 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.

Please don't mix a new feature and code cleanup.

This patch changes almost every line of the function due to
indentation changes. But the only relevant part is

"
        mss = skb_shinfo(skb)->gso_size;
        if (unlikely(skb->len <= mss))
                goto out;

        if (skb->encapsulation && skb_shinfo(skb)->gso_type &
            (SKB_GSO_UDP_TUNNEL|SKB_GSO_UDP_TUNNEL_CSUM))
                segs = skb_udp_tunnel_segment(skb, features, true);
        else {
                /* irrelevant here */
        }

out:
        return segs;
}
"

Is it a sufficient change to just skip the mss check if mss = GSO_BY_FRAGS?

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCHv2 net-next 02/17] udp6: move the mss check after udp gso tunnel processing
  2020-10-08 12:44     ` [PATCHv2 net-next 02/17] udp6: move the mss check after udp gso tunnel processing Willem de Bruijn
@ 2020-10-08 12:44       ` Willem de Bruijn
  2020-10-09  1:48       ` Xin Long
  1 sibling, 0 replies; 62+ messages in thread
From: Willem de Bruijn @ 2020-10-08 12:44 UTC (permalink / raw)
  To: Xin Long
  Cc: network dev, linux-sctp, Marcelo Ricardo Leitner, Neil Horman,
	Michael Tuexen, David Miller

On Thu, Oct 8, 2020 at 5:48 AM Xin Long <lucien.xin@gmail.com> wrote:
>
> 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.

Please don't mix a new feature and code cleanup.

This patch changes almost every line of the function due to
indentation changes. But the only relevant part is

"
        mss = skb_shinfo(skb)->gso_size;
        if (unlikely(skb->len <= mss))
                goto out;

        if (skb->encapsulation && skb_shinfo(skb)->gso_type &
            (SKB_GSO_UDP_TUNNEL|SKB_GSO_UDP_TUNNEL_CSUM))
                segs = skb_udp_tunnel_segment(skb, features, true);
        else {
                /* irrelevant here */
        }

out:
        return segs;
}
"

Is it a sufficient change to just skip the mss check if mss == GSO_BY_FRAGS?

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCHv2 net-next 09/17] sctp: add SCTP_REMOTE_UDP_ENCAPS_PORT sockopt
  2020-10-08  9:48                 ` [PATCHv2 net-next 09/17] sctp: add SCTP_REMOTE_UDP_ENCAPS_PORT sockopt Xin Long
  2020-10-08  9:48                   ` Xin Long
  2020-10-08  9:48                   ` [PATCHv2 net-next 10/17] sctp: allow changing transport encap_port by peer packets Xin Long
@ 2020-10-08 13:10                   ` kernel test robot
  2020-10-08 13:10                     ` kernel test robot
  2 siblings, 1 reply; 62+ messages in thread
From: kernel test robot @ 2020-10-08 13:10 UTC (permalink / raw)
  To: Xin Long, network dev, linux-sctp
  Cc: kbuild-all, Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

[-- Attachment #1: Type: text/plain, Size: 5467 bytes --]

Hi Xin,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 9faebeb2d80065926dfbc09cb73b1bb7779a89cd
config: i386-randconfig-s002-20201008 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.2-218-gc0e96d6d-dirty
        # https://github.com/0day-ci/linux/commit/5f37023ae66b1c3df726e16ec30b9443394e1ed3
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
        git checkout 5f37023ae66b1c3df726e16ec30b9443394e1ed3
        # save the attached .config to linux build tree
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

echo
echo "sparse warnings: (new ones prefixed by >>)"
echo
   net/sctp/socket.c: note: in included file (through include/net/sctp/sctp.h):
   include/net/sctp/structs.h:333:41: sparse: sparse: array of flexible structures
>> net/sctp/socket.c:4439:31: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be16 [usertype] encap_port @@     got unsigned short [usertype] sue_port @@
>> net/sctp/socket.c:4439:31: sparse:     expected restricted __be16 [usertype] encap_port
>> net/sctp/socket.c:4439:31: sparse:     got unsigned short [usertype] sue_port
   net/sctp/socket.c:4458:39: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be16 [usertype] encap_port @@     got unsigned short [usertype] sue_port @@
   net/sctp/socket.c:4458:39: sparse:     expected restricted __be16 [usertype] encap_port
   net/sctp/socket.c:4458:39: sparse:     got unsigned short [usertype] sue_port
   net/sctp/socket.c:4463:33: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be16 [usertype] encap_port @@     got unsigned short [usertype] sue_port @@
   net/sctp/socket.c:4463:33: sparse:     expected restricted __be16 [usertype] encap_port
   net/sctp/socket.c:4463:33: sparse:     got unsigned short [usertype] sue_port
>> net/sctp/socket.c:7869:32: sparse: sparse: incorrect type in assignment (different base types) @@     expected unsigned short [addressable] [usertype] sue_port @@     got restricted __be16 [usertype] encap_port @@
>> net/sctp/socket.c:7869:32: sparse:     expected unsigned short [addressable] [usertype] sue_port
>> net/sctp/socket.c:7869:32: sparse:     got restricted __be16 [usertype] encap_port
   net/sctp/socket.c:7885:32: sparse: sparse: incorrect type in assignment (different base types) @@     expected unsigned short [addressable] [usertype] sue_port @@     got restricted __be16 [usertype] encap_port @@
   net/sctp/socket.c:7885:32: sparse:     expected unsigned short [addressable] [usertype] sue_port
   net/sctp/socket.c:7885:32: sparse:     got restricted __be16 [usertype] encap_port
   net/sctp/socket.c:7889:24: sparse: sparse: incorrect type in assignment (different base types) @@     expected unsigned short [addressable] [usertype] sue_port @@     got restricted __be16 [usertype] encap_port @@
   net/sctp/socket.c:7889:24: sparse:     expected unsigned short [addressable] [usertype] sue_port
   net/sctp/socket.c:7889:24: sparse:     got restricted __be16 [usertype] encap_port
   net/sctp/socket.c:8320:23: sparse: sparse: context imbalance in 'sctp_get_port_local' - unexpected unlock

vim +4439 net/sctp/socket.c

  4419	
  4420	static int sctp_setsockopt_encap_port(struct sock *sk,
  4421					      struct sctp_udpencaps *encap,
  4422					      unsigned int optlen)
  4423	{
  4424		struct sctp_association *asoc;
  4425		struct sctp_transport *t;
  4426	
  4427		if (optlen != sizeof(*encap))
  4428			return -EINVAL;
  4429	
  4430		/* If an address other than INADDR_ANY is specified, and
  4431		 * no transport is found, then the request is invalid.
  4432		 */
  4433		if (!sctp_is_any(sk, (union sctp_addr *)&encap->sue_address)) {
  4434			t = sctp_addr_id2transport(sk, &encap->sue_address,
  4435						   encap->sue_assoc_id);
  4436			if (!t)
  4437				return -EINVAL;
  4438	
> 4439			t->encap_port = encap->sue_port;
  4440			return 0;
  4441		}
  4442	
  4443		/* Get association, if assoc_id != SCTP_FUTURE_ASSOC and the
  4444		 * socket is a one to many style socket, and an association
  4445		 * was not found, then the id was invalid.
  4446		 */
  4447		asoc = sctp_id2assoc(sk, encap->sue_assoc_id);
  4448		if (!asoc && encap->sue_assoc_id != SCTP_FUTURE_ASSOC &&
  4449		    sctp_style(sk, UDP))
  4450			return -EINVAL;
  4451	
  4452		/* If changes are for association, also apply encap to each
  4453		 * transport.
  4454		 */
  4455		if (asoc) {
  4456			list_for_each_entry(t, &asoc->peer.transport_addr_list,
  4457					    transports)
  4458				t->encap_port = encap->sue_port;
  4459	
  4460			return 0;
  4461		}
  4462	
  4463		sctp_sk(sk)->encap_port = encap->sue_port;
  4464		return 0;
  4465	}
  4466	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 30577 bytes --]

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCHv2 net-next 09/17] sctp: add SCTP_REMOTE_UDP_ENCAPS_PORT sockopt
  2020-10-08 13:10                   ` [PATCHv2 net-next 09/17] sctp: add SCTP_REMOTE_UDP_ENCAPS_PORT sockopt kernel test robot
@ 2020-10-08 13:10                     ` kernel test robot
  0 siblings, 0 replies; 62+ messages in thread
From: kernel test robot @ 2020-10-08 13:10 UTC (permalink / raw)
  To: Xin Long, network dev, linux-sctp
  Cc: kbuild-all, Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

[-- Attachment #1: Type: text/plain, Size: 5467 bytes --]

Hi Xin,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 9faebeb2d80065926dfbc09cb73b1bb7779a89cd
config: i386-randconfig-s002-20201008 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.2-218-gc0e96d6d-dirty
        # https://github.com/0day-ci/linux/commit/5f37023ae66b1c3df726e16ec30b9443394e1ed3
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
        git checkout 5f37023ae66b1c3df726e16ec30b9443394e1ed3
        # save the attached .config to linux build tree
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

echo
echo "sparse warnings: (new ones prefixed by >>)"
echo
   net/sctp/socket.c: note: in included file (through include/net/sctp/sctp.h):
   include/net/sctp/structs.h:333:41: sparse: sparse: array of flexible structures
>> net/sctp/socket.c:4439:31: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be16 [usertype] encap_port @@     got unsigned short [usertype] sue_port @@
>> net/sctp/socket.c:4439:31: sparse:     expected restricted __be16 [usertype] encap_port
>> net/sctp/socket.c:4439:31: sparse:     got unsigned short [usertype] sue_port
   net/sctp/socket.c:4458:39: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be16 [usertype] encap_port @@     got unsigned short [usertype] sue_port @@
   net/sctp/socket.c:4458:39: sparse:     expected restricted __be16 [usertype] encap_port
   net/sctp/socket.c:4458:39: sparse:     got unsigned short [usertype] sue_port
   net/sctp/socket.c:4463:33: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be16 [usertype] encap_port @@     got unsigned short [usertype] sue_port @@
   net/sctp/socket.c:4463:33: sparse:     expected restricted __be16 [usertype] encap_port
   net/sctp/socket.c:4463:33: sparse:     got unsigned short [usertype] sue_port
>> net/sctp/socket.c:7869:32: sparse: sparse: incorrect type in assignment (different base types) @@     expected unsigned short [addressable] [usertype] sue_port @@     got restricted __be16 [usertype] encap_port @@
>> net/sctp/socket.c:7869:32: sparse:     expected unsigned short [addressable] [usertype] sue_port
>> net/sctp/socket.c:7869:32: sparse:     got restricted __be16 [usertype] encap_port
   net/sctp/socket.c:7885:32: sparse: sparse: incorrect type in assignment (different base types) @@     expected unsigned short [addressable] [usertype] sue_port @@     got restricted __be16 [usertype] encap_port @@
   net/sctp/socket.c:7885:32: sparse:     expected unsigned short [addressable] [usertype] sue_port
   net/sctp/socket.c:7885:32: sparse:     got restricted __be16 [usertype] encap_port
   net/sctp/socket.c:7889:24: sparse: sparse: incorrect type in assignment (different base types) @@     expected unsigned short [addressable] [usertype] sue_port @@     got restricted __be16 [usertype] encap_port @@
   net/sctp/socket.c:7889:24: sparse:     expected unsigned short [addressable] [usertype] sue_port
   net/sctp/socket.c:7889:24: sparse:     got restricted __be16 [usertype] encap_port
   net/sctp/socket.c:8320:23: sparse: sparse: context imbalance in 'sctp_get_port_local' - unexpected unlock

vim +4439 net/sctp/socket.c

  4419	
  4420	static int sctp_setsockopt_encap_port(struct sock *sk,
  4421					      struct sctp_udpencaps *encap,
  4422					      unsigned int optlen)
  4423	{
  4424		struct sctp_association *asoc;
  4425		struct sctp_transport *t;
  4426	
  4427		if (optlen != sizeof(*encap))
  4428			return -EINVAL;
  4429	
  4430		/* If an address other than INADDR_ANY is specified, and
  4431		 * no transport is found, then the request is invalid.
  4432		 */
  4433		if (!sctp_is_any(sk, (union sctp_addr *)&encap->sue_address)) {
  4434			t = sctp_addr_id2transport(sk, &encap->sue_address,
  4435						   encap->sue_assoc_id);
  4436			if (!t)
  4437				return -EINVAL;
  4438	
> 4439			t->encap_port = encap->sue_port;
  4440			return 0;
  4441		}
  4442	
  4443		/* Get association, if assoc_id != SCTP_FUTURE_ASSOC and the
  4444		 * socket is a one to many style socket, and an association
  4445		 * was not found, then the id was invalid.
  4446		 */
  4447		asoc = sctp_id2assoc(sk, encap->sue_assoc_id);
  4448		if (!asoc && encap->sue_assoc_id != SCTP_FUTURE_ASSOC &&
  4449		    sctp_style(sk, UDP))
  4450			return -EINVAL;
  4451	
  4452		/* If changes are for association, also apply encap to each
  4453		 * transport.
  4454		 */
  4455		if (asoc) {
  4456			list_for_each_entry(t, &asoc->peer.transport_addr_list,
  4457					    transports)
  4458				t->encap_port = encap->sue_port;
  4459	
  4460			return 0;
  4461		}
  4462	
  4463		sctp_sk(sk)->encap_port = encap->sue_port;
  4464		return 0;
  4465	}
  4466	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 30577 bytes --]

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCHv2 net-next 15/17] sctp: add the error cause for new encapsulation port restart
  2020-10-08  9:48                             ` [PATCHv2 net-next 15/17] sctp: add the error cause for new encapsulation port restart Xin Long
  2020-10-08  9:48                               ` Xin Long
  2020-10-08  9:48                               ` [PATCHv2 net-next 16/17] sctp: handle the init chunk matching an existing asoc Xin Long
@ 2020-10-08 14:33                               ` kernel test robot
  2020-10-08 14:33                                 ` kernel test robot
  2 siblings, 1 reply; 62+ messages in thread
From: kernel test robot @ 2020-10-08 14:33 UTC (permalink / raw)
  To: Xin Long, network dev, linux-sctp
  Cc: kbuild-all, Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

[-- Attachment #1: Type: text/plain, Size: 4088 bytes --]

Hi Xin,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 9faebeb2d80065926dfbc09cb73b1bb7779a89cd
config: i386-randconfig-s002-20201008 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.2-218-gc0e96d6d-dirty
        # https://github.com/0day-ci/linux/commit/9119d2be86deb6950b26b152a51ddad0a95182a5
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
        git checkout 9119d2be86deb6950b26b152a51ddad0a95182a5
        # save the attached .config to linux build tree
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

echo
echo "sparse warnings: (new ones prefixed by >>)"
echo
   net/sctp/sm_make_chunk.c: note: in included file (through include/net/sctp/sctp.h):
   include/net/sctp/structs.h:334:41: sparse: sparse: array of flexible structures
>> net/sctp/sm_make_chunk.c:1157:24: sparse: sparse: cast from restricted __be16
>> net/sctp/sm_make_chunk.c:1157:24: sparse: sparse: incorrect type in argument 1 (different base types) @@     expected unsigned short [usertype] val @@     got restricted __be16 [usertype] encap_port @@
>> net/sctp/sm_make_chunk.c:1157:24: sparse:     expected unsigned short [usertype] val
>> net/sctp/sm_make_chunk.c:1157:24: sparse:     got restricted __be16 [usertype] encap_port
>> net/sctp/sm_make_chunk.c:1157:24: sparse: sparse: cast from restricted __be16
>> net/sctp/sm_make_chunk.c:1157:24: sparse: sparse: cast from restricted __be16
   net/sctp/sm_make_chunk.c:1158:24: sparse: sparse: cast from restricted __be16
   net/sctp/sm_make_chunk.c:1158:24: sparse: sparse: incorrect type in argument 1 (different base types) @@     expected unsigned short [usertype] val @@     got restricted __be16 [usertype] encap_port @@
   net/sctp/sm_make_chunk.c:1158:24: sparse:     expected unsigned short [usertype] val
   net/sctp/sm_make_chunk.c:1158:24: sparse:     got restricted __be16 [usertype] encap_port
   net/sctp/sm_make_chunk.c:1158:24: sparse: sparse: cast from restricted __be16
   net/sctp/sm_make_chunk.c:1158:24: sparse: sparse: cast from restricted __be16
   net/sctp/sm_make_chunk.c:3081:48: sparse: sparse: incorrect type in argument 2 (different base types) @@     expected int optname @@     got restricted __be16 @@
   net/sctp/sm_make_chunk.c:3081:48: sparse:     expected int optname
   net/sctp/sm_make_chunk.c:3081:48: sparse:     got restricted __be16
   net/sctp/sm_make_chunk.c:3153:48: sparse: sparse: incorrect type in argument 2 (different base types) @@     expected int optname @@     got restricted __be16 @@
   net/sctp/sm_make_chunk.c:3153:48: sparse:     expected int optname
   net/sctp/sm_make_chunk.c:3153:48: sparse:     got restricted __be16

vim +1157 net/sctp/sm_make_chunk.c

  1144	
  1145	struct sctp_chunk *sctp_make_new_encap_port(const struct sctp_association *asoc,
  1146						    const struct sctp_chunk *chunk)
  1147	{
  1148		struct sctp_new_encap_port_hdr nep;
  1149		struct sctp_chunk *retval;
  1150	
  1151		retval = sctp_make_abort(asoc, chunk,
  1152					 sizeof(struct sctp_errhdr) + sizeof(nep));
  1153		if (!retval)
  1154			goto nodata;
  1155	
  1156		sctp_init_cause(retval, SCTP_ERROR_NEW_ENCAP_PORT, sizeof(nep));
> 1157		nep.cur_port = htons(SCTP_INPUT_CB(chunk->skb)->encap_port);
  1158		nep.new_port = htons(chunk->transport->encap_port);
  1159		sctp_addto_chunk(retval, sizeof(nep), &nep);
  1160	
  1161	nodata:
  1162		return retval;
  1163	}
  1164	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 30577 bytes --]

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCHv2 net-next 15/17] sctp: add the error cause for new encapsulation port restart
  2020-10-08 14:33                               ` [PATCHv2 net-next 15/17] sctp: add the error cause for new encapsulation port restart kernel test robot
@ 2020-10-08 14:33                                 ` kernel test robot
  0 siblings, 0 replies; 62+ messages in thread
From: kernel test robot @ 2020-10-08 14:33 UTC (permalink / raw)
  To: Xin Long, network dev, linux-sctp
  Cc: kbuild-all, Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

[-- Attachment #1: Type: text/plain, Size: 4088 bytes --]

Hi Xin,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 9faebeb2d80065926dfbc09cb73b1bb7779a89cd
config: i386-randconfig-s002-20201008 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.2-218-gc0e96d6d-dirty
        # https://github.com/0day-ci/linux/commit/9119d2be86deb6950b26b152a51ddad0a95182a5
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
        git checkout 9119d2be86deb6950b26b152a51ddad0a95182a5
        # save the attached .config to linux build tree
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

echo
echo "sparse warnings: (new ones prefixed by >>)"
echo
   net/sctp/sm_make_chunk.c: note: in included file (through include/net/sctp/sctp.h):
   include/net/sctp/structs.h:334:41: sparse: sparse: array of flexible structures
>> net/sctp/sm_make_chunk.c:1157:24: sparse: sparse: cast from restricted __be16
>> net/sctp/sm_make_chunk.c:1157:24: sparse: sparse: incorrect type in argument 1 (different base types) @@     expected unsigned short [usertype] val @@     got restricted __be16 [usertype] encap_port @@
>> net/sctp/sm_make_chunk.c:1157:24: sparse:     expected unsigned short [usertype] val
>> net/sctp/sm_make_chunk.c:1157:24: sparse:     got restricted __be16 [usertype] encap_port
>> net/sctp/sm_make_chunk.c:1157:24: sparse: sparse: cast from restricted __be16
>> net/sctp/sm_make_chunk.c:1157:24: sparse: sparse: cast from restricted __be16
   net/sctp/sm_make_chunk.c:1158:24: sparse: sparse: cast from restricted __be16
   net/sctp/sm_make_chunk.c:1158:24: sparse: sparse: incorrect type in argument 1 (different base types) @@     expected unsigned short [usertype] val @@     got restricted __be16 [usertype] encap_port @@
   net/sctp/sm_make_chunk.c:1158:24: sparse:     expected unsigned short [usertype] val
   net/sctp/sm_make_chunk.c:1158:24: sparse:     got restricted __be16 [usertype] encap_port
   net/sctp/sm_make_chunk.c:1158:24: sparse: sparse: cast from restricted __be16
   net/sctp/sm_make_chunk.c:1158:24: sparse: sparse: cast from restricted __be16
   net/sctp/sm_make_chunk.c:3081:48: sparse: sparse: incorrect type in argument 2 (different base types) @@     expected int optname @@     got restricted __be16 @@
   net/sctp/sm_make_chunk.c:3081:48: sparse:     expected int optname
   net/sctp/sm_make_chunk.c:3081:48: sparse:     got restricted __be16
   net/sctp/sm_make_chunk.c:3153:48: sparse: sparse: incorrect type in argument 2 (different base types) @@     expected int optname @@     got restricted __be16 @@
   net/sctp/sm_make_chunk.c:3153:48: sparse:     expected int optname
   net/sctp/sm_make_chunk.c:3153:48: sparse:     got restricted __be16

vim +1157 net/sctp/sm_make_chunk.c

  1144	
  1145	struct sctp_chunk *sctp_make_new_encap_port(const struct sctp_association *asoc,
  1146						    const struct sctp_chunk *chunk)
  1147	{
  1148		struct sctp_new_encap_port_hdr nep;
  1149		struct sctp_chunk *retval;
  1150	
  1151		retval = sctp_make_abort(asoc, chunk,
  1152					 sizeof(struct sctp_errhdr) + sizeof(nep));
  1153		if (!retval)
  1154			goto nodata;
  1155	
  1156		sctp_init_cause(retval, SCTP_ERROR_NEW_ENCAP_PORT, sizeof(nep));
> 1157		nep.cur_port = htons(SCTP_INPUT_CB(chunk->skb)->encap_port);
  1158		nep.new_port = htons(chunk->transport->encap_port);
  1159		sctp_addto_chunk(retval, sizeof(nep), &nep);
  1160	
  1161	nodata:
  1162		return retval;
  1163	}
  1164	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 30577 bytes --]

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCHv2 net-next 17/17] sctp: enable udp tunneling socks
  2020-10-08  9:48                                 ` [PATCHv2 net-next 17/17] sctp: enable udp tunneling socks Xin Long
  2020-10-08  9:48                                   ` Xin Long
@ 2020-10-08 15:46                                   ` kernel test robot
  2020-10-08 15:46                                     ` kernel test robot
  2020-10-09  2:02                                     ` Xin Long
  1 sibling, 2 replies; 62+ messages in thread
From: kernel test robot @ 2020-10-08 15:46 UTC (permalink / raw)
  To: Xin Long, network dev, linux-sctp
  Cc: kbuild-all, Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

[-- Attachment #1: Type: text/plain, Size: 2814 bytes --]

Hi Xin,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 9faebeb2d80065926dfbc09cb73b1bb7779a89cd
config: i386-randconfig-s002-20201008 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.2-218-gc0e96d6d-dirty
        # https://github.com/0day-ci/linux/commit/7dab31e8c96fab2089a651d5a6d06bcf92b011ad
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
        git checkout 7dab31e8c96fab2089a651d5a6d06bcf92b011ad
        # save the attached .config to linux build tree
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

echo
echo "sparse warnings: (new ones prefixed by >>)"
echo
>> net/sctp/sysctl.c:532:39: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be16 [usertype] udp_port @@     got int udp_port @@
>> net/sctp/sysctl.c:532:39: sparse:     expected restricted __be16 [usertype] udp_port
>> net/sctp/sysctl.c:532:39: sparse:     got int udp_port

vim +532 net/sctp/sysctl.c

   500	
   501	static int proc_sctp_do_udp_port(struct ctl_table *ctl, int write,
   502					 void *buffer, size_t *lenp, loff_t *ppos)
   503	{
   504		struct net *net = current->nsproxy->net_ns;
   505		unsigned int min = *(unsigned int *)ctl->extra1;
   506		unsigned int max = *(unsigned int *)ctl->extra2;
   507		struct ctl_table tbl;
   508		int ret, new_value;
   509	
   510		memset(&tbl, 0, sizeof(struct ctl_table));
   511		tbl.maxlen = sizeof(unsigned int);
   512	
   513		if (write)
   514			tbl.data = &new_value;
   515		else
   516			tbl.data = &net->sctp.udp_port;
   517	
   518		ret = proc_dointvec(&tbl, write, buffer, lenp, ppos);
   519		if (write && ret == 0) {
   520			struct sock *sk = net->sctp.ctl_sock;
   521	
   522			if (new_value > max || new_value < min)
   523				return -EINVAL;
   524	
   525			net->sctp.udp_port = new_value;
   526			sctp_udp_sock_stop(net);
   527			ret = sctp_udp_sock_start(net);
   528			if (ret)
   529				net->sctp.udp_port = 0;
   530	
   531			lock_sock(sk);
 > 532			sctp_sk(sk)->udp_port = net->sctp.udp_port;
   533			release_sock(sk);
   534		}
   535	
   536		return ret;
   537	}
   538	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 30577 bytes --]

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCHv2 net-next 17/17] sctp: enable udp tunneling socks
  2020-10-08 15:46                                   ` kernel test robot
@ 2020-10-08 15:46                                     ` kernel test robot
  2020-10-09  2:02                                     ` Xin Long
  1 sibling, 0 replies; 62+ messages in thread
From: kernel test robot @ 2020-10-08 15:46 UTC (permalink / raw)
  To: Xin Long, network dev, linux-sctp
  Cc: kbuild-all, Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

[-- Attachment #1: Type: text/plain, Size: 2814 bytes --]

Hi Xin,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 9faebeb2d80065926dfbc09cb73b1bb7779a89cd
config: i386-randconfig-s002-20201008 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.2-218-gc0e96d6d-dirty
        # https://github.com/0day-ci/linux/commit/7dab31e8c96fab2089a651d5a6d06bcf92b011ad
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
        git checkout 7dab31e8c96fab2089a651d5a6d06bcf92b011ad
        # save the attached .config to linux build tree
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

echo
echo "sparse warnings: (new ones prefixed by >>)"
echo
>> net/sctp/sysctl.c:532:39: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be16 [usertype] udp_port @@     got int udp_port @@
>> net/sctp/sysctl.c:532:39: sparse:     expected restricted __be16 [usertype] udp_port
>> net/sctp/sysctl.c:532:39: sparse:     got int udp_port

vim +532 net/sctp/sysctl.c

   500	
   501	static int proc_sctp_do_udp_port(struct ctl_table *ctl, int write,
   502					 void *buffer, size_t *lenp, loff_t *ppos)
   503	{
   504		struct net *net = current->nsproxy->net_ns;
   505		unsigned int min = *(unsigned int *)ctl->extra1;
   506		unsigned int max = *(unsigned int *)ctl->extra2;
   507		struct ctl_table tbl;
   508		int ret, new_value;
   509	
   510		memset(&tbl, 0, sizeof(struct ctl_table));
   511		tbl.maxlen = sizeof(unsigned int);
   512	
   513		if (write)
   514			tbl.data = &new_value;
   515		else
   516			tbl.data = &net->sctp.udp_port;
   517	
   518		ret = proc_dointvec(&tbl, write, buffer, lenp, ppos);
   519		if (write && ret == 0) {
   520			struct sock *sk = net->sctp.ctl_sock;
   521	
   522			if (new_value > max || new_value < min)
   523				return -EINVAL;
   524	
   525			net->sctp.udp_port = new_value;
   526			sctp_udp_sock_stop(net);
   527			ret = sctp_udp_sock_start(net);
   528			if (ret)
   529				net->sctp.udp_port = 0;
   530	
   531			lock_sock(sk);
 > 532			sctp_sk(sk)->udp_port = net->sctp.udp_port;
   533			release_sock(sk);
   534		}
   535	
   536		return ret;
   537	}
   538	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 30577 bytes --]

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCHv2 net-next 05/17] sctp: create udp4 sock and add its encap_rcv
  2020-10-08  9:48         ` [PATCHv2 net-next 05/17] sctp: create udp4 sock and add its encap_rcv Xin Long
  2020-10-08  9:48           ` Xin Long
  2020-10-08  9:48           ` [PATCHv2 net-next 06/17] sctp: create udp6 sock and set " Xin Long
@ 2020-10-08 18:29           ` kernel test robot
  2020-10-08 18:29             ` kernel test robot
  2020-10-09  1:59             ` Xin Long
  2 siblings, 2 replies; 62+ messages in thread
From: kernel test robot @ 2020-10-08 18:29 UTC (permalink / raw)
  To: Xin Long, network dev, linux-sctp
  Cc: kbuild-all, Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

[-- Attachment #1: Type: text/plain, Size: 1763 bytes --]

Hi Xin,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 9faebeb2d80065926dfbc09cb73b1bb7779a89cd
config: arm-keystone_defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/55d6ef371ddfab66c7767da14b490f7576262f1a
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
        git checkout 55d6ef371ddfab66c7767da14b490f7576262f1a
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   arm-linux-gnueabi-ld: net/sctp/protocol.o: in function `sctp_udp_sock_start':
>> protocol.c:(.text+0x1084): undefined reference to `udp_sock_create4'
>> arm-linux-gnueabi-ld: protocol.c:(.text+0x10b0): undefined reference to `setup_udp_tunnel_sock'
   arm-linux-gnueabi-ld: net/sctp/protocol.o: in function `sctp_udp_sock_stop':
>> protocol.c:(.text+0x1108): undefined reference to `udp_tunnel_sock_release'

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 24381 bytes --]

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCHv2 net-next 05/17] sctp: create udp4 sock and add its encap_rcv
  2020-10-08 18:29           ` [PATCHv2 net-next 05/17] sctp: create udp4 sock and add " kernel test robot
@ 2020-10-08 18:29             ` kernel test robot
  2020-10-09  1:59             ` Xin Long
  1 sibling, 0 replies; 62+ messages in thread
From: kernel test robot @ 2020-10-08 18:29 UTC (permalink / raw)
  To: Xin Long, network dev, linux-sctp
  Cc: kbuild-all, Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

[-- Attachment #1: Type: text/plain, Size: 1763 bytes --]

Hi Xin,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 9faebeb2d80065926dfbc09cb73b1bb7779a89cd
config: arm-keystone_defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/55d6ef371ddfab66c7767da14b490f7576262f1a
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
        git checkout 55d6ef371ddfab66c7767da14b490f7576262f1a
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   arm-linux-gnueabi-ld: net/sctp/protocol.o: in function `sctp_udp_sock_start':
>> protocol.c:(.text+0x1084): undefined reference to `udp_sock_create4'
>> arm-linux-gnueabi-ld: protocol.c:(.text+0x10b0): undefined reference to `setup_udp_tunnel_sock'
   arm-linux-gnueabi-ld: net/sctp/protocol.o: in function `sctp_udp_sock_stop':
>> protocol.c:(.text+0x1108): undefined reference to `udp_tunnel_sock_release'

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 24381 bytes --]

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCHv2 net-next 06/17] sctp: create udp6 sock and set its encap_rcv
  2020-10-08  9:48           ` [PATCHv2 net-next 06/17] sctp: create udp6 sock and set " Xin Long
  2020-10-08  9:48             ` Xin Long
  2020-10-08  9:48             ` [PATCHv2 net-next 07/17] sctp: add encap_err_lookup for udp encap socks Xin Long
@ 2020-10-08 21:18             ` kernel test robot
  2020-10-08 21:18               ` kernel test robot
  2020-10-09  1:59               ` Xin Long
  2 siblings, 2 replies; 62+ messages in thread
From: kernel test robot @ 2020-10-08 21:18 UTC (permalink / raw)
  To: Xin Long, network dev, linux-sctp
  Cc: kbuild-all, Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

[-- Attachment #1: Type: text/plain, Size: 2158 bytes --]

Hi Xin,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 9faebeb2d80065926dfbc09cb73b1bb7779a89cd
config: arm-keystone_defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/60851a8f9ae9fd55f1199581dd78f6030bed63c7
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
        git checkout 60851a8f9ae9fd55f1199581dd78f6030bed63c7
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   arm-linux-gnueabi-ld: net/sctp/protocol.o: in function `sctp_udp_sock_start':
   protocol.c:(.text+0x108c): undefined reference to `udp_sock_create4'
   arm-linux-gnueabi-ld: protocol.c:(.text+0x10b8): undefined reference to `setup_udp_tunnel_sock'
>> arm-linux-gnueabi-ld: protocol.c:(.text+0x111c): undefined reference to `udp_sock_create6'
   arm-linux-gnueabi-ld: protocol.c:(.text+0x113c): undefined reference to `setup_udp_tunnel_sock'
>> arm-linux-gnueabi-ld: protocol.c:(.text+0x1180): undefined reference to `udp_tunnel_sock_release'
   arm-linux-gnueabi-ld: net/sctp/protocol.o: in function `sctp_udp_sock_stop':
   protocol.c:(.text+0x11b4): undefined reference to `udp_tunnel_sock_release'
   arm-linux-gnueabi-ld: protocol.c:(.text+0x11d0): undefined reference to `udp_tunnel_sock_release'

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 24381 bytes --]

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCHv2 net-next 06/17] sctp: create udp6 sock and set its encap_rcv
  2020-10-08 21:18             ` [PATCHv2 net-next 06/17] sctp: create udp6 sock and set its encap_rcv kernel test robot
@ 2020-10-08 21:18               ` kernel test robot
  2020-10-09  1:59               ` Xin Long
  1 sibling, 0 replies; 62+ messages in thread
From: kernel test robot @ 2020-10-08 21:18 UTC (permalink / raw)
  To: Xin Long, network dev, linux-sctp
  Cc: kbuild-all, Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen, davem

[-- Attachment #1: Type: text/plain, Size: 2158 bytes --]

Hi Xin,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 9faebeb2d80065926dfbc09cb73b1bb7779a89cd
config: arm-keystone_defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/60851a8f9ae9fd55f1199581dd78f6030bed63c7
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
        git checkout 60851a8f9ae9fd55f1199581dd78f6030bed63c7
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   arm-linux-gnueabi-ld: net/sctp/protocol.o: in function `sctp_udp_sock_start':
   protocol.c:(.text+0x108c): undefined reference to `udp_sock_create4'
   arm-linux-gnueabi-ld: protocol.c:(.text+0x10b8): undefined reference to `setup_udp_tunnel_sock'
>> arm-linux-gnueabi-ld: protocol.c:(.text+0x111c): undefined reference to `udp_sock_create6'
   arm-linux-gnueabi-ld: protocol.c:(.text+0x113c): undefined reference to `setup_udp_tunnel_sock'
>> arm-linux-gnueabi-ld: protocol.c:(.text+0x1180): undefined reference to `udp_tunnel_sock_release'
   arm-linux-gnueabi-ld: net/sctp/protocol.o: in function `sctp_udp_sock_stop':
   protocol.c:(.text+0x11b4): undefined reference to `udp_tunnel_sock_release'
   arm-linux-gnueabi-ld: protocol.c:(.text+0x11d0): undefined reference to `udp_tunnel_sock_release'

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 24381 bytes --]

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCHv2 net-next 02/17] udp6: move the mss check after udp gso tunnel processing
  2020-10-08 12:44     ` [PATCHv2 net-next 02/17] udp6: move the mss check after udp gso tunnel processing Willem de Bruijn
  2020-10-08 12:44       ` Willem de Bruijn
@ 2020-10-09  1:48       ` Xin Long
  2020-10-09  1:48         ` Xin Long
  2020-10-09 13:59         ` Willem de Bruijn
  1 sibling, 2 replies; 62+ messages in thread
From: Xin Long @ 2020-10-09  1:48 UTC (permalink / raw)
  To: Willem de Bruijn
  Cc: network dev, linux-sctp, Marcelo Ricardo Leitner, Neil Horman,
	Michael Tuexen, David Miller

On Thu, Oct 8, 2020 at 8:45 PM Willem de Bruijn
<willemdebruijn.kernel@gmail.com> wrote:
>
> On Thu, Oct 8, 2020 at 5:48 AM Xin Long <lucien.xin@gmail.com> wrote:
> >
> > 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.
>
> Please don't mix a new feature and code cleanup.
Hi, Willem,

Tidying up variables are not worth a single patch, that's what I was
thinking. I can leave the variables as it is if you wish in this patch.

>
> This patch changes almost every line of the function due to
> indentation changes. But the only relevant part is
>
> "
>         mss = skb_shinfo(skb)->gso_size;
>         if (unlikely(skb->len <= mss))
>                 goto out;
>
>         if (skb->encapsulation && skb_shinfo(skb)->gso_type &
>             (SKB_GSO_UDP_TUNNEL|SKB_GSO_UDP_TUNNEL_CSUM))
>                 segs = skb_udp_tunnel_segment(skb, features, true);
>         else {
>                 /* irrelevant here */
>         }
>
> out:
>         return segs;
> }
> "
>
> Is it a sufficient change to just skip the mss check if mss = GSO_BY_FRAGS?
It is sufficient.

But I think we'd better keep the code here consistent with ipv4's if
there's no other reason to do 'skb->len <= mss' check at the first.

We can go with if-else as you showed above now, then do a cleanup in
the future. What do you think?

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCHv2 net-next 02/17] udp6: move the mss check after udp gso tunnel processing
  2020-10-09  1:48       ` Xin Long
@ 2020-10-09  1:48         ` Xin Long
  2020-10-09 13:59         ` Willem de Bruijn
  1 sibling, 0 replies; 62+ messages in thread
From: Xin Long @ 2020-10-09  1:48 UTC (permalink / raw)
  To: Willem de Bruijn
  Cc: network dev, linux-sctp, Marcelo Ricardo Leitner, Neil Horman,
	Michael Tuexen, David Miller

On Thu, Oct 8, 2020 at 8:45 PM Willem de Bruijn
<willemdebruijn.kernel@gmail.com> wrote:
>
> On Thu, Oct 8, 2020 at 5:48 AM Xin Long <lucien.xin@gmail.com> wrote:
> >
> > 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.
>
> Please don't mix a new feature and code cleanup.
Hi, Willem,

Tidying up variables are not worth a single patch, that's what I was
thinking. I can leave the variables as it is if you wish in this patch.

>
> This patch changes almost every line of the function due to
> indentation changes. But the only relevant part is
>
> "
>         mss = skb_shinfo(skb)->gso_size;
>         if (unlikely(skb->len <= mss))
>                 goto out;
>
>         if (skb->encapsulation && skb_shinfo(skb)->gso_type &
>             (SKB_GSO_UDP_TUNNEL|SKB_GSO_UDP_TUNNEL_CSUM))
>                 segs = skb_udp_tunnel_segment(skb, features, true);
>         else {
>                 /* irrelevant here */
>         }
>
> out:
>         return segs;
> }
> "
>
> Is it a sufficient change to just skip the mss check if mss == GSO_BY_FRAGS?
It is sufficient.

But I think we'd better keep the code here consistent with ipv4's if
there's no other reason to do 'skb->len <= mss' check at the first.

We can go with if-else as you showed above now, then do a cleanup in
the future. What do you think?

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCHv2 net-next 05/17] sctp: create udp4 sock and add its encap_rcv
  2020-10-08 18:29           ` [PATCHv2 net-next 05/17] sctp: create udp4 sock and add " kernel test robot
  2020-10-08 18:29             ` kernel test robot
@ 2020-10-09  1:59             ` Xin Long
  2020-10-09  1:59               ` Xin Long
  1 sibling, 1 reply; 62+ messages in thread
From: Xin Long @ 2020-10-09  1:59 UTC (permalink / raw)
  To: kernel test robot
  Cc: network dev, linux-sctp, kbuild-all, Marcelo Ricardo Leitner,
	Neil Horman, Michael Tuexen, davem

On Fri, Oct 9, 2020 at 2:30 AM kernel test robot <lkp@intel.com> wrote:
>
> Hi Xin,
>
> Thank you for the patch! Yet something to improve:
>
> [auto build test ERROR on net-next/master]
>
> url:    https://github.com/0day-ci/linux/commits/Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 9faebeb2d80065926dfbc09cb73b1bb7779a89cd
> config: arm-keystone_defconfig (attached as .config)
> compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0
> reproduce (this is a W=1 build):
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # https://github.com/0day-ci/linux/commit/55d6ef371ddfab66c7767da14b490f7576262f1a
>         git remote add linux-review https://github.com/0day-ci/linux
>         git fetch --no-tags linux-review Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
>         git checkout 55d6ef371ddfab66c7767da14b490f7576262f1a
>         # save the attached .config to linux build tree
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm
>
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
>
> All errors (new ones prefixed by >>):
>
>    arm-linux-gnueabi-ld: net/sctp/protocol.o: in function `sctp_udp_sock_start':
> >> protocol.c:(.text+0x1084): undefined reference to `udp_sock_create4'
> >> arm-linux-gnueabi-ld: protocol.c:(.text+0x10b0): undefined reference to `setup_udp_tunnel_sock'
>    arm-linux-gnueabi-ld: net/sctp/protocol.o: in function `sctp_udp_sock_stop':
> >> protocol.c:(.text+0x1108): undefined reference to `udp_tunnel_sock_release'
diff --git a/net/sctp/Kconfig b/net/sctp/Kconfig
index 39d7fa9569f8..5da599ff84a9 100644
--- a/net/sctp/Kconfig
+++ b/net/sctp/Kconfig
@@ -11,6 +11,7 @@ menuconfig IP_SCTP
        select CRYPTO_HMAC
        select CRYPTO_SHA1
        select LIBCRC32C
+       select NET_UDP_TUNNEL
        help
          Stream Control Transmission Protocol

>
> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
> https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* Re: [PATCHv2 net-next 05/17] sctp: create udp4 sock and add its encap_rcv
  2020-10-09  1:59             ` Xin Long
@ 2020-10-09  1:59               ` Xin Long
  0 siblings, 0 replies; 62+ messages in thread
From: Xin Long @ 2020-10-09  1:59 UTC (permalink / raw)
  To: kernel test robot
  Cc: network dev, linux-sctp, kbuild-all, Marcelo Ricardo Leitner,
	Neil Horman, Michael Tuexen, davem

On Fri, Oct 9, 2020 at 2:30 AM kernel test robot <lkp@intel.com> wrote:
>
> Hi Xin,
>
> Thank you for the patch! Yet something to improve:
>
> [auto build test ERROR on net-next/master]
>
> url:    https://github.com/0day-ci/linux/commits/Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 9faebeb2d80065926dfbc09cb73b1bb7779a89cd
> config: arm-keystone_defconfig (attached as .config)
> compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0
> reproduce (this is a W=1 build):
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # https://github.com/0day-ci/linux/commit/55d6ef371ddfab66c7767da14b490f7576262f1a
>         git remote add linux-review https://github.com/0day-ci/linux
>         git fetch --no-tags linux-review Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
>         git checkout 55d6ef371ddfab66c7767da14b490f7576262f1a
>         # save the attached .config to linux build tree
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm
>
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
>
> All errors (new ones prefixed by >>):
>
>    arm-linux-gnueabi-ld: net/sctp/protocol.o: in function `sctp_udp_sock_start':
> >> protocol.c:(.text+0x1084): undefined reference to `udp_sock_create4'
> >> arm-linux-gnueabi-ld: protocol.c:(.text+0x10b0): undefined reference to `setup_udp_tunnel_sock'
>    arm-linux-gnueabi-ld: net/sctp/protocol.o: in function `sctp_udp_sock_stop':
> >> protocol.c:(.text+0x1108): undefined reference to `udp_tunnel_sock_release'
diff --git a/net/sctp/Kconfig b/net/sctp/Kconfig
index 39d7fa9569f8..5da599ff84a9 100644
--- a/net/sctp/Kconfig
+++ b/net/sctp/Kconfig
@@ -11,6 +11,7 @@ menuconfig IP_SCTP
        select CRYPTO_HMAC
        select CRYPTO_SHA1
        select LIBCRC32C
+       select NET_UDP_TUNNEL
        help
          Stream Control Transmission Protocol

>
> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
> https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* Re: [PATCHv2 net-next 06/17] sctp: create udp6 sock and set its encap_rcv
  2020-10-08 21:18             ` [PATCHv2 net-next 06/17] sctp: create udp6 sock and set its encap_rcv kernel test robot
  2020-10-08 21:18               ` kernel test robot
@ 2020-10-09  1:59               ` Xin Long
  2020-10-09  1:59                 ` Xin Long
  1 sibling, 1 reply; 62+ messages in thread
From: Xin Long @ 2020-10-09  1:59 UTC (permalink / raw)
  To: kernel test robot
  Cc: network dev, linux-sctp, kbuild-all, Marcelo Ricardo Leitner,
	Neil Horman, Michael Tuexen, davem

On Fri, Oct 9, 2020 at 5:20 AM kernel test robot <lkp@intel.com> wrote:
>
> Hi Xin,
>
> Thank you for the patch! Yet something to improve:
>
> [auto build test ERROR on net-next/master]
>
> url:    https://github.com/0day-ci/linux/commits/Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 9faebeb2d80065926dfbc09cb73b1bb7779a89cd
> config: arm-keystone_defconfig (attached as .config)
> compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0
> reproduce (this is a W=1 build):
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # https://github.com/0day-ci/linux/commit/60851a8f9ae9fd55f1199581dd78f6030bed63c7
>         git remote add linux-review https://github.com/0day-ci/linux
>         git fetch --no-tags linux-review Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
>         git checkout 60851a8f9ae9fd55f1199581dd78f6030bed63c7
>         # save the attached .config to linux build tree
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm
>
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
>
> All errors (new ones prefixed by >>):
>
>    arm-linux-gnueabi-ld: net/sctp/protocol.o: in function `sctp_udp_sock_start':
>    protocol.c:(.text+0x108c): undefined reference to `udp_sock_create4'
>    arm-linux-gnueabi-ld: protocol.c:(.text+0x10b8): undefined reference to `setup_udp_tunnel_sock'
> >> arm-linux-gnueabi-ld: protocol.c:(.text+0x111c): undefined reference to `udp_sock_create6'
>    arm-linux-gnueabi-ld: protocol.c:(.text+0x113c): undefined reference to `setup_udp_tunnel_sock'
> >> arm-linux-gnueabi-ld: protocol.c:(.text+0x1180): undefined reference to `udp_tunnel_sock_release'
>    arm-linux-gnueabi-ld: net/sctp/protocol.o: in function `sctp_udp_sock_stop':
>    protocol.c:(.text+0x11b4): undefined reference to `udp_tunnel_sock_release'
>    arm-linux-gnueabi-ld: protocol.c:(.text+0x11d0): undefined reference to `udp_tunnel_sock_release'
>
diff --git a/net/sctp/Kconfig b/net/sctp/Kconfig
index 39d7fa9569f8..5da599ff84a9 100644
--- a/net/sctp/Kconfig
+++ b/net/sctp/Kconfig
@@ -11,6 +11,7 @@ menuconfig IP_SCTP
        select CRYPTO_HMAC
        select CRYPTO_SHA1
        select LIBCRC32C
+       select NET_UDP_TUNNEL
        help
          Stream Control Transmission Protocol

> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
> https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* Re: [PATCHv2 net-next 06/17] sctp: create udp6 sock and set its encap_rcv
  2020-10-09  1:59               ` Xin Long
@ 2020-10-09  1:59                 ` Xin Long
  0 siblings, 0 replies; 62+ messages in thread
From: Xin Long @ 2020-10-09  1:59 UTC (permalink / raw)
  To: kernel test robot
  Cc: network dev, linux-sctp, kbuild-all, Marcelo Ricardo Leitner,
	Neil Horman, Michael Tuexen, davem

On Fri, Oct 9, 2020 at 5:20 AM kernel test robot <lkp@intel.com> wrote:
>
> Hi Xin,
>
> Thank you for the patch! Yet something to improve:
>
> [auto build test ERROR on net-next/master]
>
> url:    https://github.com/0day-ci/linux/commits/Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 9faebeb2d80065926dfbc09cb73b1bb7779a89cd
> config: arm-keystone_defconfig (attached as .config)
> compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0
> reproduce (this is a W=1 build):
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # https://github.com/0day-ci/linux/commit/60851a8f9ae9fd55f1199581dd78f6030bed63c7
>         git remote add linux-review https://github.com/0day-ci/linux
>         git fetch --no-tags linux-review Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
>         git checkout 60851a8f9ae9fd55f1199581dd78f6030bed63c7
>         # save the attached .config to linux build tree
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm
>
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
>
> All errors (new ones prefixed by >>):
>
>    arm-linux-gnueabi-ld: net/sctp/protocol.o: in function `sctp_udp_sock_start':
>    protocol.c:(.text+0x108c): undefined reference to `udp_sock_create4'
>    arm-linux-gnueabi-ld: protocol.c:(.text+0x10b8): undefined reference to `setup_udp_tunnel_sock'
> >> arm-linux-gnueabi-ld: protocol.c:(.text+0x111c): undefined reference to `udp_sock_create6'
>    arm-linux-gnueabi-ld: protocol.c:(.text+0x113c): undefined reference to `setup_udp_tunnel_sock'
> >> arm-linux-gnueabi-ld: protocol.c:(.text+0x1180): undefined reference to `udp_tunnel_sock_release'
>    arm-linux-gnueabi-ld: net/sctp/protocol.o: in function `sctp_udp_sock_stop':
>    protocol.c:(.text+0x11b4): undefined reference to `udp_tunnel_sock_release'
>    arm-linux-gnueabi-ld: protocol.c:(.text+0x11d0): undefined reference to `udp_tunnel_sock_release'
>
diff --git a/net/sctp/Kconfig b/net/sctp/Kconfig
index 39d7fa9569f8..5da599ff84a9 100644
--- a/net/sctp/Kconfig
+++ b/net/sctp/Kconfig
@@ -11,6 +11,7 @@ menuconfig IP_SCTP
        select CRYPTO_HMAC
        select CRYPTO_SHA1
        select LIBCRC32C
+       select NET_UDP_TUNNEL
        help
          Stream Control Transmission Protocol

> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
> https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

^ permalink raw reply related	[flat|nested] 62+ messages in thread

* Re: [PATCHv2 net-next 17/17] sctp: enable udp tunneling socks
  2020-10-08 15:46                                   ` kernel test robot
  2020-10-08 15:46                                     ` kernel test robot
@ 2020-10-09  2:02                                     ` Xin Long
  2020-10-09  2:02                                       ` Xin Long
  1 sibling, 1 reply; 62+ messages in thread
From: Xin Long @ 2020-10-09  2:02 UTC (permalink / raw)
  To: kernel test robot
  Cc: network dev, linux-sctp, kbuild-all, Marcelo Ricardo Leitner,
	Neil Horman, Michael Tuexen, davem

On Thu, Oct 8, 2020 at 11:46 PM kernel test robot <lkp@intel.com> wrote:
>
> Hi Xin,
>
> Thank you for the patch! Perhaps something to improve:
>
> [auto build test WARNING on net-next/master]
>
> url:    https://github.com/0day-ci/linux/commits/Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 9faebeb2d80065926dfbc09cb73b1bb7779a89cd
> config: i386-randconfig-s002-20201008 (attached as .config)
> compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
> reproduce:
>         # apt-get install sparse
>         # sparse version: v0.6.2-218-gc0e96d6d-dirty
>         # https://github.com/0day-ci/linux/commit/7dab31e8c96fab2089a651d5a6d06bcf92b011ad
>         git remote add linux-review https://github.com/0day-ci/linux
>         git fetch --no-tags linux-review Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
>         git checkout 7dab31e8c96fab2089a651d5a6d06bcf92b011ad
>         # save the attached .config to linux build tree
>         make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=i386
>
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
>
> echo
> echo "sparse warnings: (new ones prefixed by >>)"
> echo
> >> net/sctp/sysctl.c:532:39: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be16 [usertype] udp_port @@     got int udp_port @@
> >> net/sctp/sysctl.c:532:39: sparse:     expected restricted __be16 [usertype] udp_port
> >> net/sctp/sysctl.c:532:39: sparse:     got int udp_port
>
> vim +532 net/sctp/sysctl.c
>
>    500
>    501  static int proc_sctp_do_udp_port(struct ctl_table *ctl, int write,
>    502                                   void *buffer, size_t *lenp, loff_t *ppos)
>    503  {
>    504          struct net *net = current->nsproxy->net_ns;
>    505          unsigned int min = *(unsigned int *)ctl->extra1;
>    506          unsigned int max = *(unsigned int *)ctl->extra2;
>    507          struct ctl_table tbl;
>    508          int ret, new_value;
>    509
>    510          memset(&tbl, 0, sizeof(struct ctl_table));
>    511          tbl.maxlen = sizeof(unsigned int);
>    512
>    513          if (write)
>    514                  tbl.data = &new_value;
>    515          else
>    516                  tbl.data = &net->sctp.udp_port;
>    517
>    518          ret = proc_dointvec(&tbl, write, buffer, lenp, ppos);
>    519          if (write && ret = 0) {
>    520                  struct sock *sk = net->sctp.ctl_sock;
>    521
>    522                  if (new_value > max || new_value < min)
>    523                          return -EINVAL;
>    524
>    525                  net->sctp.udp_port = new_value;
>    526                  sctp_udp_sock_stop(net);
>    527                  ret = sctp_udp_sock_start(net);
>    528                  if (ret)
>    529                          net->sctp.udp_port = 0;
>    530
>    531                  lock_sock(sk);
>  > 532                  sctp_sk(sk)->udp_port = net->sctp.udp_port;
>    533                  release_sock(sk);
>    534          }
>    535
>    536          return ret;
>    537  }
>    538
I will add the restricted __be16 in these 3 patches.

Thanks.
>
> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
> https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCHv2 net-next 17/17] sctp: enable udp tunneling socks
  2020-10-09  2:02                                     ` Xin Long
@ 2020-10-09  2:02                                       ` Xin Long
  0 siblings, 0 replies; 62+ messages in thread
From: Xin Long @ 2020-10-09  2:02 UTC (permalink / raw)
  To: kernel test robot
  Cc: network dev, linux-sctp, kbuild-all, Marcelo Ricardo Leitner,
	Neil Horman, Michael Tuexen, davem

On Thu, Oct 8, 2020 at 11:46 PM kernel test robot <lkp@intel.com> wrote:
>
> Hi Xin,
>
> Thank you for the patch! Perhaps something to improve:
>
> [auto build test WARNING on net-next/master]
>
> url:    https://github.com/0day-ci/linux/commits/Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 9faebeb2d80065926dfbc09cb73b1bb7779a89cd
> config: i386-randconfig-s002-20201008 (attached as .config)
> compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
> reproduce:
>         # apt-get install sparse
>         # sparse version: v0.6.2-218-gc0e96d6d-dirty
>         # https://github.com/0day-ci/linux/commit/7dab31e8c96fab2089a651d5a6d06bcf92b011ad
>         git remote add linux-review https://github.com/0day-ci/linux
>         git fetch --no-tags linux-review Xin-Long/sctp-Implement-RFC6951-UDP-Encapsulation-of-SCTP/20201008-175211
>         git checkout 7dab31e8c96fab2089a651d5a6d06bcf92b011ad
>         # save the attached .config to linux build tree
>         make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=i386
>
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
>
> echo
> echo "sparse warnings: (new ones prefixed by >>)"
> echo
> >> net/sctp/sysctl.c:532:39: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be16 [usertype] udp_port @@     got int udp_port @@
> >> net/sctp/sysctl.c:532:39: sparse:     expected restricted __be16 [usertype] udp_port
> >> net/sctp/sysctl.c:532:39: sparse:     got int udp_port
>
> vim +532 net/sctp/sysctl.c
>
>    500
>    501  static int proc_sctp_do_udp_port(struct ctl_table *ctl, int write,
>    502                                   void *buffer, size_t *lenp, loff_t *ppos)
>    503  {
>    504          struct net *net = current->nsproxy->net_ns;
>    505          unsigned int min = *(unsigned int *)ctl->extra1;
>    506          unsigned int max = *(unsigned int *)ctl->extra2;
>    507          struct ctl_table tbl;
>    508          int ret, new_value;
>    509
>    510          memset(&tbl, 0, sizeof(struct ctl_table));
>    511          tbl.maxlen = sizeof(unsigned int);
>    512
>    513          if (write)
>    514                  tbl.data = &new_value;
>    515          else
>    516                  tbl.data = &net->sctp.udp_port;
>    517
>    518          ret = proc_dointvec(&tbl, write, buffer, lenp, ppos);
>    519          if (write && ret == 0) {
>    520                  struct sock *sk = net->sctp.ctl_sock;
>    521
>    522                  if (new_value > max || new_value < min)
>    523                          return -EINVAL;
>    524
>    525                  net->sctp.udp_port = new_value;
>    526                  sctp_udp_sock_stop(net);
>    527                  ret = sctp_udp_sock_start(net);
>    528                  if (ret)
>    529                          net->sctp.udp_port = 0;
>    530
>    531                  lock_sock(sk);
>  > 532                  sctp_sk(sk)->udp_port = net->sctp.udp_port;
>    533                  release_sock(sk);
>    534          }
>    535
>    536          return ret;
>    537  }
>    538
I will add the restricted __be16 in these 3 patches.

Thanks.
>
> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
> https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCHv2 net-next 02/17] udp6: move the mss check after udp gso tunnel processing
  2020-10-09  1:48       ` Xin Long
  2020-10-09  1:48         ` Xin Long
@ 2020-10-09 13:59         ` Willem de Bruijn
  2020-10-09 13:59           ` Willem de Bruijn
  1 sibling, 1 reply; 62+ messages in thread
From: Willem de Bruijn @ 2020-10-09 13:59 UTC (permalink / raw)
  To: Xin Long
  Cc: Willem de Bruijn, network dev, linux-sctp,
	Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen,
	David Miller

On Thu, Oct 8, 2020 at 9:49 PM Xin Long <lucien.xin@gmail.com> wrote:
>
> On Thu, Oct 8, 2020 at 8:45 PM Willem de Bruijn
> <willemdebruijn.kernel@gmail.com> wrote:
> >
> > On Thu, Oct 8, 2020 at 5:48 AM Xin Long <lucien.xin@gmail.com> wrote:
> > >
> > > 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.
> >
> > Please don't mix a new feature and code cleanup.
> Hi, Willem,
>
> Tidying up variables are not worth a single patch, that's what I was
> thinking. I can leave the variables as it is if you wish in this patch.
>
> >
> > This patch changes almost every line of the function due to
> > indentation changes. But the only relevant part is
> >
> > "
> >         mss = skb_shinfo(skb)->gso_size;
> >         if (unlikely(skb->len <= mss))
> >                 goto out;
> >
> >         if (skb->encapsulation && skb_shinfo(skb)->gso_type &
> >             (SKB_GSO_UDP_TUNNEL|SKB_GSO_UDP_TUNNEL_CSUM))
> >                 segs = skb_udp_tunnel_segment(skb, features, true);
> >         else {
> >                 /* irrelevant here */
> >         }
> >
> > out:
> >         return segs;
> > }
> > "
> >
> > Is it a sufficient change to just skip the mss check if mss = GSO_BY_FRAGS?
> It is sufficient.
>
> But I think we'd better keep the code here consistent with ipv4's if
> there's no other reason to do 'skb->len <= mss' check at the first.
>
> We can go with if-else as you showed above now, then do a cleanup in
> the future. What do you think?

I do think that's a better approach, thanks.

Mixing in feature changes with 150+ lines of code refactoring makes it
hard to spot the behavioral change.

Too often the additional purportedly noop refactoring proves to have
subtle behavioral changes after all. It's easier to review for this if
that patch is separate. Not saying it's the case here, of course.

Refactoring also adds a layer of indirection when using git blame to
understand code or for people who have the existing code memorized, so
has a fairly high bar imho.

^ permalink raw reply	[flat|nested] 62+ messages in thread

* Re: [PATCHv2 net-next 02/17] udp6: move the mss check after udp gso tunnel processing
  2020-10-09 13:59         ` Willem de Bruijn
@ 2020-10-09 13:59           ` Willem de Bruijn
  0 siblings, 0 replies; 62+ messages in thread
From: Willem de Bruijn @ 2020-10-09 13:59 UTC (permalink / raw)
  To: Xin Long
  Cc: Willem de Bruijn, network dev, linux-sctp,
	Marcelo Ricardo Leitner, Neil Horman, Michael Tuexen,
	David Miller

On Thu, Oct 8, 2020 at 9:49 PM Xin Long <lucien.xin@gmail.com> wrote:
>
> On Thu, Oct 8, 2020 at 8:45 PM Willem de Bruijn
> <willemdebruijn.kernel@gmail.com> wrote:
> >
> > On Thu, Oct 8, 2020 at 5:48 AM Xin Long <lucien.xin@gmail.com> wrote:
> > >
> > > 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.
> >
> > Please don't mix a new feature and code cleanup.
> Hi, Willem,
>
> Tidying up variables are not worth a single patch, that's what I was
> thinking. I can leave the variables as it is if you wish in this patch.
>
> >
> > This patch changes almost every line of the function due to
> > indentation changes. But the only relevant part is
> >
> > "
> >         mss = skb_shinfo(skb)->gso_size;
> >         if (unlikely(skb->len <= mss))
> >                 goto out;
> >
> >         if (skb->encapsulation && skb_shinfo(skb)->gso_type &
> >             (SKB_GSO_UDP_TUNNEL|SKB_GSO_UDP_TUNNEL_CSUM))
> >                 segs = skb_udp_tunnel_segment(skb, features, true);
> >         else {
> >                 /* irrelevant here */
> >         }
> >
> > out:
> >         return segs;
> > }
> > "
> >
> > Is it a sufficient change to just skip the mss check if mss == GSO_BY_FRAGS?
> It is sufficient.
>
> But I think we'd better keep the code here consistent with ipv4's if
> there's no other reason to do 'skb->len <= mss' check at the first.
>
> We can go with if-else as you showed above now, then do a cleanup in
> the future. What do you think?

I do think that's a better approach, thanks.

Mixing in feature changes with 150+ lines of code refactoring makes it
hard to spot the behavioral change.

Too often the additional purportedly noop refactoring proves to have
subtle behavioral changes after all. It's easier to review for this if
that patch is separate. Not saying it's the case here, of course.

Refactoring also adds a layer of indirection when using git blame to
understand code or for people who have the existing code memorized, so
has a fairly high bar imho.

^ permalink raw reply	[flat|nested] 62+ messages in thread

end of thread, other threads:[~2020-10-09 14:00 UTC | newest]

Thread overview: 62+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-08  9:47 [PATCHv2 net-next 00/17] sctp: Implement RFC6951: UDP Encapsulation of SCTP Xin Long
2020-10-08  9:47 ` Xin Long
2020-10-08  9:47 ` [PATCHv2 net-next 01/17] udp: check udp sock encap_type in __udp_lib_err Xin Long
2020-10-08  9:47   ` Xin Long
2020-10-08  9:47   ` [PATCHv2 net-next 02/17] udp6: move the mss check after udp gso tunnel processing Xin Long
2020-10-08  9:47     ` Xin Long
2020-10-08  9:47     ` [PATCHv2 net-next 03/17] udp: do checksum properly in skb_udp_tunnel_segment Xin Long
2020-10-08  9:47       ` Xin Long
2020-10-08  9:48       ` [PATCHv2 net-next 04/17] udp: support sctp over udp " Xin Long
2020-10-08  9:48         ` Xin Long
2020-10-08  9:48         ` [PATCHv2 net-next 05/17] sctp: create udp4 sock and add its encap_rcv Xin Long
2020-10-08  9:48           ` Xin Long
2020-10-08  9:48           ` [PATCHv2 net-next 06/17] sctp: create udp6 sock and set " Xin Long
2020-10-08  9:48             ` Xin Long
2020-10-08  9:48             ` [PATCHv2 net-next 07/17] sctp: add encap_err_lookup for udp encap socks Xin Long
2020-10-08  9:48               ` Xin Long
2020-10-08  9:48               ` [PATCHv2 net-next 08/17] sctp: add encap_port for netns sock asoc and transport Xin Long
2020-10-08  9:48                 ` Xin Long
2020-10-08  9:48                 ` [PATCHv2 net-next 09/17] sctp: add SCTP_REMOTE_UDP_ENCAPS_PORT sockopt Xin Long
2020-10-08  9:48                   ` Xin Long
2020-10-08  9:48                   ` [PATCHv2 net-next 10/17] sctp: allow changing transport encap_port by peer packets Xin Long
2020-10-08  9:48                     ` Xin Long
2020-10-08  9:48                     ` [PATCHv2 net-next 11/17] sctp: add udphdr to overhead when udp_port is set Xin Long
2020-10-08  9:48                       ` Xin Long
2020-10-08  9:48                       ` [PATCHv2 net-next 12/17] sctp: call sk_setup_caps in sctp_packet_transmit instead Xin Long
2020-10-08  9:48                         ` Xin Long
2020-10-08  9:48                         ` [PATCHv2 net-next 13/17] sctp: support for sending packet over udp4 sock Xin Long
2020-10-08  9:48                           ` Xin Long
2020-10-08  9:48                           ` [PATCHv2 net-next 14/17] sctp: support for sending packet over udp6 sock Xin Long
2020-10-08  9:48                             ` Xin Long
2020-10-08  9:48                             ` [PATCHv2 net-next 15/17] sctp: add the error cause for new encapsulation port restart Xin Long
2020-10-08  9:48                               ` Xin Long
2020-10-08  9:48                               ` [PATCHv2 net-next 16/17] sctp: handle the init chunk matching an existing asoc Xin Long
2020-10-08  9:48                                 ` Xin Long
2020-10-08  9:48                                 ` [PATCHv2 net-next 17/17] sctp: enable udp tunneling socks Xin Long
2020-10-08  9:48                                   ` Xin Long
2020-10-08 15:46                                   ` kernel test robot
2020-10-08 15:46                                     ` kernel test robot
2020-10-09  2:02                                     ` Xin Long
2020-10-09  2:02                                       ` Xin Long
2020-10-08 14:33                               ` [PATCHv2 net-next 15/17] sctp: add the error cause for new encapsulation port restart kernel test robot
2020-10-08 14:33                                 ` kernel test robot
2020-10-08 13:10                   ` [PATCHv2 net-next 09/17] sctp: add SCTP_REMOTE_UDP_ENCAPS_PORT sockopt kernel test robot
2020-10-08 13:10                     ` kernel test robot
2020-10-08 21:18             ` [PATCHv2 net-next 06/17] sctp: create udp6 sock and set its encap_rcv kernel test robot
2020-10-08 21:18               ` kernel test robot
2020-10-09  1:59               ` Xin Long
2020-10-09  1:59                 ` Xin Long
2020-10-08 18:29           ` [PATCHv2 net-next 05/17] sctp: create udp4 sock and add " kernel test robot
2020-10-08 18:29             ` kernel test robot
2020-10-09  1:59             ` Xin Long
2020-10-09  1:59               ` Xin Long
2020-10-08 10:01         ` [PATCHv2 net-next 04/17] udp: support sctp over udp in skb_udp_tunnel_segment Xin Long
2020-10-08 10:01           ` Xin Long
2020-10-08 10:01       ` [PATCHv2 net-next 03/17] udp: do checksum properly " Xin Long
2020-10-08 10:01         ` Xin Long
2020-10-08 12:44     ` [PATCHv2 net-next 02/17] udp6: move the mss check after udp gso tunnel processing Willem de Bruijn
2020-10-08 12:44       ` Willem de Bruijn
2020-10-09  1:48       ` Xin Long
2020-10-09  1:48         ` Xin Long
2020-10-09 13:59         ` Willem de Bruijn
2020-10-09 13:59           ` Willem de Bruijn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).