]> git.baikalelectronics.ru Git - kernel.git/commitdiff
sctp: add encap_port for netns sock asoc and transport
authorXin Long <lucien.xin@gmail.com>
Thu, 29 Oct 2020 07:05:01 +0000 (15:05 +0800)
committerJakub Kicinski <kuba@kernel.org>
Fri, 30 Oct 2020 22:24:06 +0000 (15:24 -0700)
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: Xin Long <lucien.xin@gmail.com>
Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Documentation/networking/ip-sysctl.rst
include/net/netns/sctp.h
include/net/sctp/structs.h
net/sctp/associola.c
net/sctp/protocol.c
net/sctp/socket.c
net/sctp/sysctl.c

index 25e6673a085a0f55f1f23bd3974e806ed2706f68..dad3ba9529898fcaa8708e85e956d7b0a1a7aec9 100644 (file)
@@ -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/*``
 ========================
index 247b401a0f5215cd401c6028143e201e9f412b31..a0f315effa94b33d934cff32ae2d612f2520c9c6 100644 (file)
@@ -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
index 0bdff38eb4bb7087239990fb7a084365b140860b..aa98e7e659ac3d00e7c6cf70360b68a79e7ea070 100644 (file)
@@ -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.
         */
index fdb69d46276d64cbfd30348a15e858251c2146f2..336df4b3665544c2e8d25d7b9758a555466c5b42 100644 (file)
@@ -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;
 
index 4d12a0c869b89cdd2a0ee04b018fc17142dd0c6e..89dfd313e1136b5b4876feb46a79da5af2f14655 100644 (file)
@@ -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;
 
index 53d0a4161df3f8174819b33816091b44b757a75f..09b94cd7ca37b5edfd9a52d01b160ee4b5daec0c 100644 (file)
@@ -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;
index c16c80963e555cf3f9de9b20a49baee93e843c12..ecc1b5e4c297458e0caa93b1d1ec23d9fba73e9e 100644 (file)
@@ -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 =
@@ -290,6 +291,15 @@ static struct ctl_table sctp_net_table[] = {
                .mode           = 0644,
                .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,