Commit e8a3001c authored by Xin Long's avatar Xin Long Committed by Jakub Kicinski
Browse files

sctp: add encap_port for netns sock asoc and transport



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

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

v1->v2:
  - Change to define encap_port as __be16 for sctp_sock, asoc and
    transport.
v2->v3:
  - No change.
v3->v4:
  - Add 'encap_port' entry in ip-sysctl.rst.
v4->v5:
  - Improve the description of encap_port in ip-sysctl.rst.

Signed-off-by: default avatarXin Long <lucien.xin@gmail.com>
Acked-by: default avatarMarcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 89ba4917
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -2642,6 +2642,22 @@ addr_scope_policy - INTEGER

	Default: 1

encap_port - INTEGER
	The default remote UDP encapsulation port.

	This value is used to set the dest port of the UDP header for the
	outgoing UDP-encapsulated SCTP packets by default. Users can also
	change the value for each sock/asoc/transport by using setsockopt.
	For further information, please refer to RFC6951.

	Note that when connecting to a remote server, the client should set
	this to the port that the UDP tunneling sock on the peer server is
	listening to and the local UDP tunneling sock on the client also
	must be started. On the server, it would get the encap_port from
	the incoming packet's source port.

	Default: 0


``/proc/sys/net/core/*``
========================
+2 −0
Original line number Diff line number Diff line
@@ -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
+6 −0
Original line number Diff line number Diff line
@@ -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.
	 */
+4 −0
Original line number Diff line number Diff line
@@ -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;

+3 −0
Original line number Diff line number Diff line
@@ -1359,6 +1359,9 @@ static int __net_init sctp_defaults_init(struct net *net)
	/* Set UDP tunneling listening port to 0 by default */
	net->sctp.udp_port = 0;

	/* 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;

Loading