BSD 4_3_Net_2 release
[unix-history] / usr / src / sys / net / if.c
index 372387c..dc395f5 100644 (file)
@@ -2,22 +2,35 @@
  * Copyright (c) 1980, 1986 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1980, 1986 Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution is only permitted until one year after the first shipment
- * of 4.4BSD by the Regents.  Otherwise, redistribution and use in source and
- * binary forms are permitted provided that: (1) source distributions retain
- * this entire copyright notice and comment, and (2) distributions including
- * binaries display the following acknowledgement:  This product includes
- * software developed by the University of California, Berkeley and its
- * contributors'' in the documentation or other materials provided with the
- * distribution and in all advertising materials mentioning features or use
- * of this software.  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.
- * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * 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.
  *
  *
- *     @(#)if.c        7.13 (Berkeley) 6/28/90
+ * 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.
+ *
+ *     @(#)if.c        7.14 (Berkeley) 4/20/91
  */
 
 #include "param.h"
  */
 
 #include "param.h"
 #include "socket.h"
 #include "socketvar.h"
 #include "protosw.h"
 #include "socket.h"
 #include "socketvar.h"
 #include "protosw.h"
-#include "user.h"
+#include "proc.h"
 #include "kernel.h"
 #include "ioctl.h"
 #include "kernel.h"
 #include "ioctl.h"
-#include "errno.h"
 
 #include "if.h"
 #include "af.h"
 
 #include "if.h"
 #include "af.h"
@@ -74,6 +86,8 @@ ifubareset(uban)
 
 int if_index = 0;
 struct ifaddr **ifnet_addrs;
 
 int if_index = 0;
 struct ifaddr **ifnet_addrs;
+static char *sprint_d();
+
 /*
  * Attach an interface to the
  * list of "active" interfaces.
 /*
  * Attach an interface to the
  * list of "active" interfaces.
@@ -83,7 +97,7 @@ if_attach(ifp)
 {
        unsigned socksize, ifasize;
        int namelen, unitlen;
 {
        unsigned socksize, ifasize;
        int namelen, unitlen;
-       char workbuf[16];
+       char workbuf[12], *unitname;
        register struct ifnet **p = &ifnet;
        register struct sockaddr_dl *sdl;
        register struct ifaddr *ifa;
        register struct ifnet **p = &ifnet;
        register struct sockaddr_dl *sdl;
        register struct ifaddr *ifa;
@@ -113,9 +127,9 @@ if_attach(ifp)
        /*
         * create a Link Level name for this device
         */
        /*
         * create a Link Level name for this device
         */
-       sprint_d(workbuf, ifp->if_unit);
+       unitname = sprint_d((u_int)ifp->if_unit, workbuf, sizeof(workbuf));
        namelen = strlen(ifp->if_name);
        namelen = strlen(ifp->if_name);
-       unitlen = strlen(workbuf);
+       unitlen = strlen(unitname);
 #define _offsetof(t, m) ((int)((caddr_t)&((t *)0)->m))
        socksize = _offsetof(struct sockaddr_dl, sdl_data[0]) +
                               unitlen + namelen + ifp->if_addrlen;
 #define _offsetof(t, m) ((int)((caddr_t)&((t *)0)->m))
        socksize = _offsetof(struct sockaddr_dl, sdl_data[0]) +
                               unitlen + namelen + ifp->if_addrlen;
@@ -135,7 +149,7 @@ if_attach(ifp)
        sdl->sdl_len = socksize;
        sdl->sdl_family = AF_LINK;
        bcopy(ifp->if_name, sdl->sdl_data, namelen);
        sdl->sdl_len = socksize;
        sdl->sdl_family = AF_LINK;
        bcopy(ifp->if_name, sdl->sdl_data, namelen);
-       bcopy((caddr_t)workbuf, namelen + (caddr_t)sdl->sdl_data, unitlen);
+       bcopy(unitname, namelen + (caddr_t)sdl->sdl_data, unitlen);
        sdl->sdl_nlen = (namelen += unitlen);
        sdl->sdl_index = ifp->if_index;
        sdl = (struct sockaddr_dl *)(socksize + (caddr_t)sdl);
        sdl->sdl_nlen = (namelen += unitlen);
        sdl->sdl_index = ifp->if_index;
        sdl = (struct sockaddr_dl *)(socksize + (caddr_t)sdl);
@@ -409,10 +423,11 @@ ifunit(name)
 /*
  * Interface ioctls.
  */
 /*
  * Interface ioctls.
  */
-ifioctl(so, cmd, data)
+ifioctl(so, cmd, data, p)
        struct socket *so;
        int cmd;
        caddr_t data;
        struct socket *so;
        int cmd;
        caddr_t data;
+       struct proc *p;
 {
        register struct ifnet *ifp;
        register struct ifreq *ifr;
 {
        register struct ifnet *ifp;
        register struct ifreq *ifr;
@@ -427,7 +442,7 @@ ifioctl(so, cmd, data)
 #if defined(INET) && NETHER > 0
        case SIOCSARP:
        case SIOCDARP:
 #if defined(INET) && NETHER > 0
        case SIOCSARP:
        case SIOCDARP:
-               if (error = suser(u.u_cred, &u.u_acflag))
+               if (error = suser(p->p_ucred, &p->p_acflag))
                        return (error);
                /* FALL THROUGH */
        case SIOCGARP:
                        return (error);
                /* FALL THROUGH */
        case SIOCGARP:
@@ -450,7 +465,7 @@ ifioctl(so, cmd, data)
                break;
 
        case SIOCSIFFLAGS:
                break;
 
        case SIOCSIFFLAGS:
-               if (error = suser(u.u_cred, &u.u_acflag))
+               if (error = suser(p->p_ucred, &p->p_acflag))
                        return (error);
                if (ifp->if_flags & IFF_UP && (ifr->ifr_flags & IFF_UP) == 0) {
                        int s = splimp();
                        return (error);
                if (ifp->if_flags & IFF_UP && (ifr->ifr_flags & IFF_UP) == 0) {
                        int s = splimp();
@@ -464,7 +479,7 @@ ifioctl(so, cmd, data)
                break;
 
        case SIOCSIFMETRIC:
                break;
 
        case SIOCSIFMETRIC:
-               if (error = suser(u.u_cred, &u.u_acflag))
+               if (error = suser(p->p_ucred, &p->p_acflag))
                        return (error);
                ifp->if_metric = ifr->ifr_metric;
                break;
                        return (error);
                ifp->if_metric = ifr->ifr_metric;
                break;
@@ -601,21 +616,19 @@ ifconf(cmd, data)
        return (error);
 }
 
        return (error);
 }
 
-static sprint_d(cp, n)
-register char *cp;
-u_short n;
+static char *
+sprint_d(n, buf, buflen)
+       u_int n;
+       char *buf;
+       int buflen;
 {
 {
-       register int q, m;
+       register char *cp = buf + buflen - 1;
+
+       *cp = 0;
        do {
        do {
-           if (n >= 10000) m = 10000;
-               else if (n >= 1000) m = 1000;
-               else if (n >= 100) m = 100;
-               else if (n >= 10) m = 10;
-               else m = 1;
-           q = n / m;
-           n -= m * q;
-           if (q > 9) q = 10; /* For crays with more than 100K interfaces */
-           *cp++ = "0123456789Z"[q];
-       } while (n > 0);
-       *cp++ = 0;
+               cp--;
+               *cp = "0123456789"[n % 10];
+               n /= 10;
+       } while (n != 0);
+       return (cp);
 }
 }