rxrpc: Create an address for sendmsg() to bind unbound socket with
authorDavid Howells <dhowells@redhat.com>
Tue, 13 Sep 2016 07:49:05 +0000 (08:49 +0100)
committerDavid Howells <dhowells@redhat.com>
Tue, 13 Sep 2016 22:09:13 +0000 (23:09 +0100)
Create an address for sendmsg() to bind unbound socket with rather than
using a completely blank address otherwise the transport socket creation
will fail because it will try to use address family 0.

We use the address family specified in the protocol argument when the
AF_RXRPC socket was created and SOCK_DGRAM as the default.  For anything
else, bind() must be used.

Signed-off-by: David Howells <dhowells@redhat.com>
net/rxrpc/af_rxrpc.c

index 25d00ded24bc9cb17c9ae9585f26b757dc1aef76..741b0d8d2e8c6e5e045472ff13d4e10865fc50ae 100644 (file)
@@ -401,6 +401,18 @@ static int rxrpc_sendmsg(struct socket *sock, struct msghdr *m, size_t len)
 
        switch (rx->sk.sk_state) {
        case RXRPC_UNBOUND:
+               rx->srx.srx_family = AF_RXRPC;
+               rx->srx.srx_service = 0;
+               rx->srx.transport_type = SOCK_DGRAM;
+               rx->srx.transport.family = rx->family;
+               switch (rx->family) {
+               case AF_INET:
+                       rx->srx.transport_len = sizeof(struct sockaddr_in);
+                       break;
+               default:
+                       ret = -EAFNOSUPPORT;
+                       goto error_unlock;
+               }
                local = rxrpc_lookup_local(&rx->srx);
                if (IS_ERR(local)) {
                        ret = PTR_ERR(local);