Xin Long <lucien....@gmail.com> wrote:

> BTW, I'm also thinking to use udp_sock_create(), the only problem I can
> see is it may not do bind() in rxrpc_open_socket(), is that true? or we
> can actually bind to some address when a local address is not supplied?

If a local address isn't explicitly bound to the AF_RXRPC socket, binding the
UDP socket to a random local port is fine.  In fact, sometimes I want to
explicitly bind an rxrpc server socket to a random port.  See fs/afs/rxrpc.c
function afs_open_socket():

        /* bind the callback manager's address to make this a server socket */
        memset(&srx, 0, sizeof(srx));
        srx.srx_family                  = AF_RXRPC;
        srx.srx_service                 = CM_SERVICE;
        srx.transport_type              = SOCK_DGRAM;
        srx.transport_len               = sizeof(srx.transport.sin6);
        srx.transport.sin6.sin6_family  = AF_INET6;
        srx.transport.sin6.sin6_port    = htons(AFS_CM_PORT);
        ...
        ret = kernel_bind(socket, (struct sockaddr *) &srx, sizeof(srx));
        if (ret == -EADDRINUSE) {
                srx.transport.sin6.sin6_port = 0;

                ^^^ That's hoping to get a random port bound.

                ret = kernel_bind(socket, (struct sockaddr *) &srx, 
sizeof(srx));
        }
        if (ret < 0)
                goto error_2;

The client cache manager server socket here is used to receive notifications
back from the fileserver.  There's a standard port (7001) for the service, but
if that's in use, we can use any other port.  The fileserver grabs the source
port from incoming RPC requests - and then uses that when sending 3rd-party
change notifications back.

If you could arrange for a random port to be assigned in such a case (and
indicated back to the caller), that would be awesome.  Possibly I just don't
need to actually use bind in this case.

David

Reply via email to