*BSD News Article 1978


Return to BSD News archive

Path: sserve!manuel!munnari.oz.au!spool.mu.edu!decwrl!olivea!uunet!dtix!mimsy!jds
From: jds@cs.umd.edu (James da Silva)
Newsgroups: comp.unix.bsd
Subject: Re: 386BSD-0.1 - NFS - do requests originate from privileged ports
Summary: patch enclosed
Message-ID: <59052@mimsy.umd.edu>
Date: 17 Jul 92 15:14:35 GMT
Article-I.D.: mimsy.59052
References: <1992Jul17.041356.4919@sura.net> <l6cj3tINN7s2@neuro.usc.edu> <BrIuyv.DEJ@immd4.informatik.uni-erlangen.de>
Sender: news@mimsy.umd.edu
Organization: University of Maryland, Department of Computer Science
Lines: 72

husemann@immd4.informatik.uni-erlangen.de (Dirk Husemann) writes:
>merlin@neuro.usc.edu (merlin) writes:
>>...
>>SUN NFS as configured on our campus requires this capability.  SCO UNIX
>>does not presently provide this feature.  Does 386BSD provide have this
>>capability as it is presently distributed?
>
>If it doesn't it should be fairly trivial to get it in. I volunteer in case it
>isn't in to put it in. Essentially in nfs_connect() you try to bind to a
>privileged port (looping thru the privileged ports above 600 or so).

No, it's not in 386BSD 0.1 now (based on perusal of the sources), but yes,
it isn't difficult.  It was done here by Rob Fristrom <rrf@cs.umd.edu> so
that he could hook his BSDI system up to a Sun NFS server.  I'm posting it
with his permission.

This patch has only been tested on BSDI's BSD/386 0.3, but the source file
(/sys/nfs/nfs_socket.c) is identical between BSDI, BSD Net 2, and 386BSD
0.1, so it should work on all three.


*** nfs_socket.c-net2	Fri Jul 17 10:49:02 1992
--- nfs_socket.c-rrf	Fri Jul 17 10:55:05 1992
***************
*** 153,163 ****
--- 153,192 ----
  	int s, error, bufsize;
  	struct mbuf *m;
  
+         struct sockaddr_in *sin;
+         u_short port;
+ 
  	nmp->nm_so = (struct socket *)0;
  	if (error = socreate(mtod(nmp->nm_nam, struct sockaddr *)->sa_family,
  		&nmp->nm_so, nmp->nm_sotype, nmp->nm_soproto))
  		goto bad;
  	so = nmp->nm_so;
+ 
+         /*
+          * Bind to an unused reserved port.
+          *
+          */
+ 
+ #       define STARTPORT IPPORT_RESERVED
+ #       define STOPPORT 512
+ 
+         MGET(m, M_WAIT, MT_SONAME);
+         m->m_len = sizeof (struct sockaddr_in);        
+         sin = mtod(m, struct sockaddr_in *);
+         sin->sin_family = AF_INET;
+         sin->sin_addr.s_addr = INADDR_ANY;
+ 
+         error = EADDRINUSE;
+         port = STARTPORT;       
+ 
+         while(port > STOPPORT && error == EADDRINUSE) {
+              sin->sin_port = htons(--port);
+              error = sobind(so, m);
+         }
+ 
+         m_freem(m);
+         if(error) goto bad;
+ 
  	nmp->nm_soflags = so->so_proto->pr_flags;
  
  	if (nmp->nm_sotype == SOCK_DGRAM)

Enjoy,
Jaime & Rob
.............................................................................
: Stand on my shoulders, : jds@cs.umd.edu  :		      James da Silva
: not on my toes.	 : uunet!mimsy!jds : Systems Design & Analysis Group