Skip to content

Commit bb2db45

Browse files
ebiedermdavem330
authored andcommitted
sctp: Enable sctp in all network namespaces
- Fix the sctp_af operations to work in all namespaces - Enable sctp socket creation in all network namespaces. Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com> Acked-by: Vlad Yasevich <vyasevich@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 13d782f commit bb2db45

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

‎net/sctp/ipv6.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ static int sctp_v6_available(union sctp_addr *addr, struct sctp_sock *sp)
582582
if (!(type & IPV6_ADDR_UNICAST))
583583
return 0;
584584

585-
return ipv6_chk_addr(&init_net, in6, NULL, 0);
585+
return ipv6_chk_addr(sock_net(&sp->inet.sk), in6, NULL, 0);
586586
}
587587

588588
/* This function checks if the address is a valid address to be used for
@@ -859,14 +859,14 @@ static int sctp_inet6_bind_verify(struct sctp_sock *opt, union sctp_addr *addr)
859859
struct net_device *dev;
860860

861861
if (type & IPV6_ADDR_LINKLOCAL) {
862+
struct net *net;
862863
if (!addr->v6.sin6_scope_id)
863864
return 0;
865+
net = sock_net(&opt->inet.sk);
864866
rcu_read_lock();
865-
dev = dev_get_by_index_rcu(&init_net,
866-
addr->v6.sin6_scope_id);
867+
dev = dev_get_by_index_rcu(net, addr->v6.sin6_scope_id);
867868
if (!dev ||
868-
!ipv6_chk_addr(&init_net, &addr->v6.sin6_addr,
869-
dev, 0)) {
869+
!ipv6_chk_addr(net, &addr->v6.sin6_addr, dev, 0)) {
870870
rcu_read_unlock();
871871
return 0;
872872
}
@@ -899,7 +899,7 @@ static int sctp_inet6_send_verify(struct sctp_sock *opt, union sctp_addr *addr)
899899
if (!addr->v6.sin6_scope_id)
900900
return 0;
901901
rcu_read_lock();
902-
dev = dev_get_by_index_rcu(&init_net,
902+
dev = dev_get_by_index_rcu(sock_net(&opt->inet.sk),
903903
addr->v6.sin6_scope_id);
904904
rcu_read_unlock();
905905
if (!dev)

‎net/sctp/protocol.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,8 @@ static int sctp_v4_addr_valid(union sctp_addr *addr,
367367
/* Should this be available for binding? */
368368
static int sctp_v4_available(union sctp_addr *addr, struct sctp_sock *sp)
369369
{
370-
int ret = inet_addr_type(&init_net, addr->v4.sin_addr.s_addr);
370+
struct net *net = sock_net(&sp->inet.sk);
371+
int ret = inet_addr_type(net, addr->v4.sin_addr.s_addr);
371372

372373

373374
if (addr->v4.sin_addr.s_addr != htonl(INADDR_ANY) &&
@@ -454,7 +455,7 @@ static void sctp_v4_get_dst(struct sctp_transport *t, union sctp_addr *saddr,
454455
SCTP_DEBUG_PRINTK("%s: DST:%pI4, SRC:%pI4 - ",
455456
__func__, &fl4->daddr, &fl4->saddr);
456457

457-
rt = ip_route_output_key(&init_net, fl4);
458+
rt = ip_route_output_key(sock_net(sk), fl4);
458459
if (!IS_ERR(rt))
459460
dst = &rt->dst;
460461

@@ -500,7 +501,7 @@ static void sctp_v4_get_dst(struct sctp_transport *t, union sctp_addr *saddr,
500501
(AF_INET == laddr->a.sa.sa_family)) {
501502
fl4->saddr = laddr->a.v4.sin_addr.s_addr;
502503
fl4->fl4_sport = laddr->a.v4.sin_port;
503-
rt = ip_route_output_key(&init_net, fl4);
504+
rt = ip_route_output_key(sock_net(sk), fl4);
504505
if (!IS_ERR(rt)) {
505506
dst = &rt->dst;
506507
goto out_unlock;
@@ -1033,6 +1034,7 @@ static const struct net_protocol sctp_protocol = {
10331034
.handler = sctp_rcv,
10341035
.err_handler = sctp_v4_err,
10351036
.no_policy = 1,
1037+
.netns_ok = 1,
10361038
};
10371039

10381040
/* IPv4 address related functions. */

0 commit comments

Comments
 (0)