Skip to content

Commit 046c052

Browse files
lxinkuba-moo
authored andcommitted
sctp: enable udp tunneling socks
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. v2->v3: - Call htons() when setting sk udp_port from netns udp_port. v3->v4: - Not call sctp_udp_sock_start() when new_value is 0. - Add udp_port entry in ip-sysctl.rst. v4->v5: - Not call sctp_udp_sock_start/stop() in sctp_ctrlsock_init/exit(). - Improve the description of udp_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>
1 parent 1c16a18 commit 046c052

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

Documentation/networking/ip-sysctl.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2642,6 +2642,21 @@ addr_scope_policy - INTEGER
26422642

26432643
Default: 1
26442644

2645+
udp_port - INTEGER
2646+
The listening port for the local UDP tunneling sock. Normally it's
2647+
using the IANA-assigned UDP port number 9899 (sctp-tunneling).
2648+
2649+
This UDP sock is used for processing the incoming UDP-encapsulated
2650+
SCTP packets (from RFC6951), and shared by all applications in the
2651+
same net namespace. This UDP sock will be closed when the value is
2652+
set to 0.
2653+
2654+
The value will also be used to set the src port of the UDP header
2655+
for the outgoing UDP-encapsulated SCTP packets. For the dest port,
2656+
please refer to 'encap_port' below.
2657+
2658+
Default: 0
2659+
26452660
encap_port - INTEGER
26462661
The default remote UDP encapsulation port.
26472662

net/sctp/sysctl.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
4949
void *buffer, size_t *lenp, loff_t *ppos);
5050
static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write, void *buffer,
5151
size_t *lenp, loff_t *ppos);
52+
static int proc_sctp_do_udp_port(struct ctl_table *ctl, int write, void *buffer,
53+
size_t *lenp, loff_t *ppos);
5254
static int proc_sctp_do_alpha_beta(struct ctl_table *ctl, int write,
5355
void *buffer, size_t *lenp, loff_t *ppos);
5456
static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
@@ -291,6 +293,15 @@ static struct ctl_table sctp_net_table[] = {
291293
.mode = 0644,
292294
.proc_handler = proc_dointvec,
293295
},
296+
{
297+
.procname = "udp_port",
298+
.data = &init_net.sctp.udp_port,
299+
.maxlen = sizeof(int),
300+
.mode = 0644,
301+
.proc_handler = proc_sctp_do_udp_port,
302+
.extra1 = SYSCTL_ZERO,
303+
.extra2 = &udp_port_max,
304+
},
294305
{
295306
.procname = "encap_port",
296307
.data = &init_net.sctp.encap_port,
@@ -487,6 +498,47 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
487498
return ret;
488499
}
489500

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+
if (new_value) {
528+
ret = sctp_udp_sock_start(net);
529+
if (ret)
530+
net->sctp.udp_port = 0;
531+
}
532+
533+
/* Update the value in the control socket */
534+
lock_sock(sk);
535+
sctp_sk(sk)->udp_port = htons(net->sctp.udp_port);
536+
release_sock(sk);
537+
}
538+
539+
return ret;
540+
}
541+
490542
int sctp_sysctl_net_register(struct net *net)
491543
{
492544
struct ctl_table *table;

0 commit comments

Comments
 (0)