optimize boot program
[unix-history] / usr / src / sys / netns / ns_pcb.c
index bce86d2..d8a859f 100644 (file)
@@ -1,35 +1,26 @@
 /*
 /*
- * Copyright (c) 1984, 1985, 1986, 1987 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1984, 1985, 1986, 1987, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * %sccs.include.redist.c%
  *
  *
- *     @(#)ns_pcb.c    7.8 (Berkeley) %G%
+ *     @(#)ns_pcb.c    8.1 (Berkeley) %G%
  */
 
  */
 
-#include "param.h"
-#include "systm.h"
-#include "user.h"
-#include "mbuf.h"
-#include "socket.h"
-#include "socketvar.h"
-#include "../net/if.h"
-#include "../net/route.h"
-#include "protosw.h"
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/mbuf.h>
+#include <sys/errno.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/protosw.h>
 
 
-#include "ns.h"
-#include "ns_if.h"
-#include "ns_pcb.h"
+#include <net/if.h>
+#include <net/route.h>
+
+#include <netns/ns.h>
+#include <netns/ns_if.h>
+#include <netns/ns_pcb.h>
 
 struct ns_addr zerons_addr;
 
 
 struct ns_addr zerons_addr;
 
@@ -76,7 +67,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);
@@ -129,25 +121,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 ||