Re: [PATCH 009 of 9] knfsd: Allow sockets to be passed to nfsd via 'portlist'



On Tue, 25 Jul 2006 11:55:08 +1000
NeilBrown <neilb@xxxxxxx> wrote:


Userspace should create and bind a socket (but not connectted)
and write the 'fd' to portlist. This will cause the nfs server
to listen on that socket.

To close a socket, the name of the socket - as read from 'portlist'
can be written to 'portlist' with a preceding '-'.


ick. Is that the best API we can come up with?

It's a privileged operation, but heck. Do we perform validation on the fd
to make sure that it's refers to a socket and not to /dev/fb0?

static ssize_t write_ports(struct file *file, char *buf, size_t size)
{
- /* for now, ignore what was written and just
- * return known ports
- * AF proto address port
+ if (size == 0) {
+ int len = 0;
+ lock_kernel();
+ if (nfsd_serv)
+ len = svc_sock_names(buf, nfsd_serv, NULL);
+ unlock_kernel();
+ return len;
+ }
+ /* Either a single 'fd' number is written, in which
+ * case it must be for a socket of a supported family/protocol,
+ * and we use it as an nfsd socket, or
+ * A '-' followed by the 'name' of a socket in which case
+ * we close the socket.
*/
- int len = 0;
- lock_kernel();
- if (nfsd_serv)
- len = svc_sock_names(buf, nfsd_serv);
- unlock_kernel();
- return len;
+ if (isdigit(buf[0])) {
+ char *mesg = buf;
+ int fd;
+ int err;
+ err = get_int(&mesg, &fd);
+ if (err)
+ return -EINVAL;
+ if (fd < 0)
+ return -EINVAL;
+ err = nfsd_create_serv();
+ if (!err) {
+ int proto = 0;
+ err = svc_addsock(nfsd_serv, fd, buf, &proto);
+ /* Decrease the count, but don't shutdown the
+ * the service
+ */
+ if (err >= 0)
+ lockd_up(proto);
+ nfsd_serv->sv_nrthreads--;
+ }
+ return err;
+ }
+ if (buf[0] == '-') {
+ char *toclose = kstrdup(buf+1, GFP_KERNEL);
+ int len = 0;
+ if (!toclose)
+ return -ENOMEM;
+ lock_kernel();
+ if (nfsd_serv)
+ len = svc_sock_names(buf, nfsd_serv, toclose);
+ unlock_kernel();
+ kfree(toclose);
+ return len;
+ }
+ return -EINVAL;
}

<checks>

OK, simple_transaction_get() guarantees that *buf is null-terminated. It
might be worth a comment to stop code-reviewers from freaking out ;)

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



Relevant Pages

  • BIND 9.5.2rc1 is now available.
    ... BIND 9.5.2rc1 is now available. ... triggering an assertion failure in ... API and glibc hides parts of the IPv6 Advanced Socket ... need to tweak ISC_SOCKET_MAXSOCKETS at compilation time ...
    (comp.protocols.dns.bind)
  • BIND 9.5.2 is now available.
    ... BIND 9.5.2 is now available. ... triggering an assertion failure in ... API and glibc hides parts of the IPv6 Advanced Socket ... need to tweak ISC_SOCKET_MAXSOCKETS at compilation time ...
    (comp.protocols.dns.bind)
  • BIND 9.5.2b1 is now available.
    ... BIND 9.5.2b1 is a maintenance release for BIND 9.5. ... triggering an assertion failure in ... API and glibc hides parts of the IPv6 Advanced Socket ... need to tweak ISC_SOCKET_MAXSOCKETS at compilation time ...
    (comp.protocols.dns.bind)
  • Re: Java Socket Constructor
    ... bind() simply binds a socket to an interface/port locally for both client ... After that you can connectto a server. ...
    (comp.lang.java.programmer)
  • Re: How to listen to more a specific IP and specific ports
    ... I have read this long time ago in the textbook Unix Network Programming ... service and connect our socket to INADDR_ANY and then listen for incoming ... Its clear to me on how to bind with ... port numbers. ...
    (microsoft.public.win32.programmer.networks)