inet: add IP_BIND_ADDRESS_NO_PORT to overcome bind(0) limitations
[cascardo/linux.git] / net / ipv4 / af_inet.c
index 8b47a4d..cc858ef 100644 (file)
@@ -317,7 +317,7 @@ lookup_protocol:
        WARN_ON(!answer_prot->slab);
 
        err = -ENOBUFS;
-       sk = sk_alloc(net, PF_INET, GFP_KERNEL, answer_prot);
+       sk = sk_alloc(net, PF_INET, GFP_KERNEL, answer_prot, kern);
        if (!sk)
                goto out;
 
@@ -488,7 +488,8 @@ int inet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
                inet->inet_saddr = 0;  /* Use device */
 
        /* Make sure we are allowed to bind here. */
-       if (sk->sk_prot->get_port(sk, snum)) {
+       if ((snum || !inet->bind_address_no_port) &&
+           sk->sk_prot->get_port(sk, snum)) {
                inet->inet_saddr = inet->inet_rcv_saddr = 0;
                err = -EADDRINUSE;
                goto out_release_sock;
@@ -1430,7 +1431,7 @@ int inet_ctl_sock_create(struct sock **sk, unsigned short family,
                         struct net *net)
 {
        struct socket *sock;
-       int rc = sock_create_kern(family, type, protocol, &sock);
+       int rc = sock_create_kern(net, family, type, protocol, &sock);
 
        if (rc == 0) {
                *sk = sock->sk;
@@ -1440,8 +1441,6 @@ int inet_ctl_sock_create(struct sock **sk, unsigned short family,
                 * we do not wish this socket to see incoming packets.
                 */
                (*sk)->sk_prot->unhash(*sk);
-
-               sk_change_net(*sk, net);
        }
        return rc;
 }
@@ -1597,7 +1596,7 @@ static __net_init int inet_init_net(struct net *net)
         */
        seqlock_init(&net->ipv4.ip_local_ports.lock);
        net->ipv4.ip_local_ports.range[0] =  32768;
-       net->ipv4.ip_local_ports.range[1] =  61000;
+       net->ipv4.ip_local_ports.range[1] =  60999;
 
        seqlock_init(&net->ipv4.ping_group_range.lock);
        /*