BSD 4_3_Net_2 release
[unix-history] / usr / src / sys / netns / ns_pcb.c
index 55b303f..0d3bd8e 100644 (file)
@@ -2,20 +2,47 @@
  * Copyright (c) 1984, 1985, 1986, 1987 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1984, 1985, 1986, 1987 Regents of the University of California.
  * All rights reserved.
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
  *
  *
- *     @(#)ns_pcb.c    7.9 (Berkeley) %G%
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)ns_pcb.c    7.11 (Berkeley) 6/27/91
  */
 
 #include "param.h"
 #include "systm.h"
  */
 
 #include "param.h"
 #include "systm.h"
-#include "user.h"
 #include "mbuf.h"
 #include "mbuf.h"
+#include "errno.h"
 #include "socket.h"
 #include "socketvar.h"
 #include "socket.h"
 #include "socketvar.h"
+#include "protosw.h"
+
 #include "../net/if.h"
 #include "../net/route.h"
 #include "../net/if.h"
 #include "../net/route.h"
-#include "protosw.h"
 
 #include "ns.h"
 #include "ns_if.h"
 
 #include "ns.h"
 #include "ns_if.h"
@@ -66,7 +93,8 @@ ns_pcbbind(nsp, nam)
        if (lport) {
                u_short aport = ntohs(lport);
 
        if (lport) {
                u_short aport = ntohs(lport);
 
-               if (aport < NSPORT_RESERVED && u.u_uid != 0)
+               if (aport < NSPORT_RESERVED &&
+                   (nsp->nsp_socket->so_state & SS_PRIV) == 0)
                        return (EACCES);
                if (ns_pcblookup(&zerons_addr, lport, 0))
                        return (EADDRINUSE);
                        return (EACCES);
                if (ns_pcblookup(&zerons_addr, lport, 0))
                        return (EADDRINUSE);
@@ -119,25 +147,22 @@ ns_pcbconnect(nsp, nam)
         */
        ro = &nsp->nsp_route;
        dst = &satons_addr(ro->ro_dst);
         */
        ro = &nsp->nsp_route;
        dst = &satons_addr(ro->ro_dst);
-       if (ro->ro_rt) {
-               if (nsp->nsp_socket->so_options & SO_DONTROUTE)
-                       goto flush;
-               if (!ns_neteq(nsp->nsp_lastdst, sns->sns_addr))
-                       goto flush;
-               if (!ns_hosteq(nsp->nsp_lastdst, sns->sns_addr)) {
-                       if (((ro->ro_rt->rt_flags & (RTF_GATEWAY|RTF_HOST))
-                            == RTF_GATEWAY)
-                           || ((ifp = ro->ro_rt->rt_ifp) &&
-                                !(ifp->if_flags & IFF_POINTOPOINT))) {
-                               /* can patch route to avoid rtalloc */
-                               *dst = sns->sns_addr;
-                       } else {
-               flush:
+       if (nsp->nsp_socket->so_options & SO_DONTROUTE)
+               goto flush;
+       if (!ns_neteq(nsp->nsp_lastdst, sns->sns_addr))
+               goto flush;
+       if (!ns_hosteq(nsp->nsp_lastdst, sns->sns_addr)) {
+               if (ro->ro_rt && ! (ro->ro_rt->rt_flags & RTF_HOST)) {
+                       /* can patch route to avoid rtalloc */
+                       *dst = sns->sns_addr;
+               } else {
+       flush:
+                       if (ro->ro_rt)
                                RTFREE(ro->ro_rt);
                                RTFREE(ro->ro_rt);
-                               ro->ro_rt = (struct rtentry *)0;
-                       }
-               }/* else cached route is ok; do nothing */
-       }
+                       ro->ro_rt = (struct rtentry *)0;
+                       nsp->nsp_laddr.x_net = ns_zeronet;
+               }
+       }/* else cached route is ok; do nothing */
        nsp->nsp_lastdst = sns->sns_addr;
        if ((nsp->nsp_socket->so_options & SO_DONTROUTE) == 0 && /*XXX*/
            (ro->ro_rt == (struct rtentry *)0 ||
        nsp->nsp_lastdst = sns->sns_addr;
        if ((nsp->nsp_socket->so_options & SO_DONTROUTE) == 0 && /*XXX*/
            (ro->ro_rt == (struct rtentry *)0 ||