diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1997-07-28 19:54:18 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1997-07-28 19:54:18 +0000 |
commit | 9d8143ad023fcdea14ab10835daa6215a8e81be2 (patch) | |
tree | b5a51d3d50c6c704ba736e243f3d74a22b870c07 | |
parent | abfe20226a7f5136a64868578ef5980075505fba (diff) |
allocate random ports
-rw-r--r-- | sys/nfs/nfs_socket.c | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/sys/nfs/nfs_socket.c b/sys/nfs/nfs_socket.c index 98155666183..8753bf36f15 100644 --- a/sys/nfs/nfs_socket.c +++ b/sys/nfs/nfs_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nfs_socket.c,v 1.11 1997/04/25 09:22:31 deraadt Exp $ */ +/* $OpenBSD: nfs_socket.c,v 1.12 1997/07/28 19:54:17 deraadt Exp $ */ /* $NetBSD: nfs_socket.c,v 1.27 1996/04/15 20:20:00 thorpej Exp $ */ /* @@ -152,7 +152,6 @@ nfs_connect(nmp, rep) struct sockaddr *saddr; struct sockaddr_in *sin; struct mbuf *m; - u_int16_t tport; nmp->nm_so = (struct socket *)0; saddr = mtod(nmp->nm_nam, struct sockaddr *); @@ -169,20 +168,35 @@ nfs_connect(nmp, rep) * disclosure through UDP port capture. */ if (saddr->sa_family == AF_INET) { + struct mbuf *mopt; + int *ip; + + MGET(mopt, M_WAIT, MT_SOOPTS); + mopt->m_len = sizeof(int); + ip = mtod(mopt, int *); + *ip = IP_PORTRANGE_LOW; + error = sosetopt(so, IPPROTO_IP, IP_PORTRANGE, mopt); + if (error) + goto bad; + MGET(m, M_WAIT, MT_SONAME); sin = mtod(m, struct sockaddr_in *); sin->sin_len = m->m_len = sizeof (struct sockaddr_in); sin->sin_family = AF_INET; sin->sin_addr.s_addr = INADDR_ANY; - /* XXX should do random allocation */ - tport = IPPORT_RESERVED - 1; - sin->sin_port = htons(tport); - while ((error = sobind(so, m)) == EADDRINUSE && - --tport > IPPORT_RESERVED / 2) - sin->sin_port = htons(tport); + sin->sin_port = htons(0); + error = sobind(so, m); m_freem(m); if (error) goto bad; + + MGET(mopt, M_WAIT, MT_SOOPTS); + mopt->m_len = sizeof(int); + ip = mtod(mopt, int *); + *ip = IP_PORTRANGE_DEFAULT; + error = sosetopt(so, IPPROTO_IP, IP_PORTRANGE, mopt); + if (error) + goto bad; } /* |