Ver Fonte

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>
Eric W. Biederman há 13 anos atrás
pai
commit
bb2db45b54
2 ficheiros alterados com 11 adições e 9 exclusões
  1. 6 6
      net/sctp/ipv6.c
  2. 5 3
      net/sctp/protocol.c

+ 6 - 6
net/sctp/ipv6.c

@@ -582,7 +582,7 @@ static int sctp_v6_available(union sctp_addr *addr, struct sctp_sock *sp)
 	if (!(type & IPV6_ADDR_UNICAST))
 	if (!(type & IPV6_ADDR_UNICAST))
 		return 0;
 		return 0;
 
 
-	return ipv6_chk_addr(&init_net, in6, NULL, 0);
+	return ipv6_chk_addr(sock_net(&sp->inet.sk), in6, NULL, 0);
 }
 }
 
 
 /* This function checks if the address is a valid address to be used for
 /* 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)
 		struct net_device *dev;
 		struct net_device *dev;
 
 
 		if (type & IPV6_ADDR_LINKLOCAL) {
 		if (type & IPV6_ADDR_LINKLOCAL) {
+			struct net *net;
 			if (!addr->v6.sin6_scope_id)
 			if (!addr->v6.sin6_scope_id)
 				return 0;
 				return 0;
+			net = sock_net(&opt->inet.sk);
 			rcu_read_lock();
 			rcu_read_lock();
-			dev = dev_get_by_index_rcu(&init_net,
-						   addr->v6.sin6_scope_id);
+			dev = dev_get_by_index_rcu(net, addr->v6.sin6_scope_id);
 			if (!dev ||
 			if (!dev ||
-			    !ipv6_chk_addr(&init_net, &addr->v6.sin6_addr,
-					   dev, 0)) {
+			    !ipv6_chk_addr(net, &addr->v6.sin6_addr, dev, 0)) {
 				rcu_read_unlock();
 				rcu_read_unlock();
 				return 0;
 				return 0;
 			}
 			}
@@ -899,7 +899,7 @@ static int sctp_inet6_send_verify(struct sctp_sock *opt, union sctp_addr *addr)
 			if (!addr->v6.sin6_scope_id)
 			if (!addr->v6.sin6_scope_id)
 				return 0;
 				return 0;
 			rcu_read_lock();
 			rcu_read_lock();
-			dev = dev_get_by_index_rcu(&init_net,
+			dev = dev_get_by_index_rcu(sock_net(&opt->inet.sk),
 						   addr->v6.sin6_scope_id);
 						   addr->v6.sin6_scope_id);
 			rcu_read_unlock();
 			rcu_read_unlock();
 			if (!dev)
 			if (!dev)

+ 5 - 3
net/sctp/protocol.c

@@ -367,7 +367,8 @@ static int sctp_v4_addr_valid(union sctp_addr *addr,
 /* Should this be available for binding?   */
 /* Should this be available for binding?   */
 static int sctp_v4_available(union sctp_addr *addr, struct sctp_sock *sp)
 static int sctp_v4_available(union sctp_addr *addr, struct sctp_sock *sp)
 {
 {
-	int ret = inet_addr_type(&init_net, addr->v4.sin_addr.s_addr);
+	struct net *net = sock_net(&sp->inet.sk);
+	int ret = inet_addr_type(net, addr->v4.sin_addr.s_addr);
 
 
 
 
 	if (addr->v4.sin_addr.s_addr != htonl(INADDR_ANY) &&
 	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,
 	SCTP_DEBUG_PRINTK("%s: DST:%pI4, SRC:%pI4 - ",
 	SCTP_DEBUG_PRINTK("%s: DST:%pI4, SRC:%pI4 - ",
 			  __func__, &fl4->daddr, &fl4->saddr);
 			  __func__, &fl4->daddr, &fl4->saddr);
 
 
-	rt = ip_route_output_key(&init_net, fl4);
+	rt = ip_route_output_key(sock_net(sk), fl4);
 	if (!IS_ERR(rt))
 	if (!IS_ERR(rt))
 		dst = &rt->dst;
 		dst = &rt->dst;
 
 
@@ -500,7 +501,7 @@ static void sctp_v4_get_dst(struct sctp_transport *t, union sctp_addr *saddr,
 		    (AF_INET == laddr->a.sa.sa_family)) {
 		    (AF_INET == laddr->a.sa.sa_family)) {
 			fl4->saddr = laddr->a.v4.sin_addr.s_addr;
 			fl4->saddr = laddr->a.v4.sin_addr.s_addr;
 			fl4->fl4_sport = laddr->a.v4.sin_port;
 			fl4->fl4_sport = laddr->a.v4.sin_port;
-			rt = ip_route_output_key(&init_net, fl4);
+			rt = ip_route_output_key(sock_net(sk), fl4);
 			if (!IS_ERR(rt)) {
 			if (!IS_ERR(rt)) {
 				dst = &rt->dst;
 				dst = &rt->dst;
 				goto out_unlock;
 				goto out_unlock;
@@ -1033,6 +1034,7 @@ static const struct net_protocol sctp_protocol = {
 	.handler     = sctp_rcv,
 	.handler     = sctp_rcv,
 	.err_handler = sctp_v4_err,
 	.err_handler = sctp_v4_err,
 	.no_policy   = 1,
 	.no_policy   = 1,
+	.netns_ok    = 1,
 };
 };
 
 
 /* IPv4 address related functions.  */
 /* IPv4 address related functions.  */