diff mbox series

[PATCHv2,net-next,17/17] sctp: enable udp tunneling socks

Message ID 8ce0fde0d093d62e8969d1788a13921ed1516ad6.1602150362.git.lucien.xin@gmail.com (mailing list archive)
State Not Applicable
Headers show
Series sctp: Implement RFC6951: UDP Encapsulation of SCTP | expand

Commit Message

Xin Long Oct. 8, 2020, 9:48 a.m. UTC
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(+)

Comments

kernel test robot Oct. 8, 2020, 3:46 p.m. UTC | #1
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
Xin Long Oct. 9, 2020, 2:02 a.m. UTC | #2
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
diff mbox series

Patch

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;