lint and wnj changes
[unix-history] / usr / src / sys / net / if.c
index 5bb08c0..6b22145 100644 (file)
@@ -1,9 +1,14 @@
-/*     if.c    4.20    82/10/09        */
+/*     if.c    4.28    83/05/27        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 #include "../h/socket.h"
 #include "../h/protosw.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
 #include "../h/socket.h"
 #include "../h/protosw.h"
+#include "../h/time.h"
+#include "../h/kernel.h"
+#include "../h/ioctl.h"
+#include "../h/errno.h"
+
 #include "../net/if.h"
 #include "../net/af.h"
 
 #include "../net/if.h"
 #include "../net/af.h"
 
@@ -40,8 +45,8 @@ ifubareset(uban)
        register struct ifnet *ifp;
 
        for (ifp = ifnet; ifp; ifp = ifp->if_next)
        register struct ifnet *ifp;
 
        for (ifp = ifnet; ifp; ifp = ifp->if_next)
-               if (ifp->if_ubareset)
-                       (*ifp->if_ubareset)(uban);
+               if (ifp->if_reset)
+                       (*ifp->if_reset)(uban);
 }
 #endif
 
 }
 #endif
 
@@ -140,6 +145,7 @@ if_ifwithaf(af)
 /*
  * Mark an interface down and notify protocols of
  * the transition.
 /*
  * Mark an interface down and notify protocols of
  * the transition.
+ * NOTE: must be called at splnet or eqivalent.
  */
 if_down(ifp)
        register struct ifnet *ifp;
  */
 if_down(ifp)
        register struct ifnet *ifp;
@@ -158,14 +164,123 @@ if_slowtimo()
 {
        register struct ifnet *ifp;
 
 {
        register struct ifnet *ifp;
 
-       for (ifp = ifnet; ifp; ifp = ifp->if_next)
-               if (ifp->if_timer && --ifp->if_timer == 0) {
-                       if (ifp->if_watchdog == 0) {
-                               printf("%s%d: no watchdog routine\n", 
-                                       ifp->if_name, ifp->if_unit);
-                               continue;
-                       }
+       for (ifp = ifnet; ifp; ifp = ifp->if_next) {
+               if (ifp->if_timer == 0 || --ifp->if_timer)
+                       continue;
+               if (ifp->if_watchdog)
                        (*ifp->if_watchdog)(ifp->if_unit);
                        (*ifp->if_watchdog)(ifp->if_unit);
+       }
+       timeout(if_slowtimo, (caddr_t)0, hz / IFNET_SLOWHZ);
+}
+
+/*
+ * Service a socket ioctl request directed
+ * to an interface.
+ */
+ifrequest(cmd, data)
+       int cmd;
+       caddr_t data;
+{
+       register struct ifnet *ifp;
+       register struct ifreq *ifr;
+       register char *cp;
+       int unit, s;
+
+       ifr = (struct ifreq *)data;
+       for (cp = ifr->ifr_name; *cp; cp++)
+               if (*cp >= '0' && *cp <= '9')
+                       break;
+       if (*cp == 0)
+               return (ENXIO);         /* couldn't find unit */
+       unit = *cp - '0', *cp = 0;
+       for (ifp = ifnet; ifp; ifp = ifp->if_next) {
+               if (bcmp(ifp->if_name, ifr->ifr_name,
+                   (unsigned)(cp - ifr->ifr_name)))
+                       continue;
+               if (unit == ifp->if_unit)
+                       goto found;
+       }
+       return (ENXIO);
+
+found:
+       switch (cmd) {
+
+       case SIOCGIFADDR:
+               ifr->ifr_addr = ifp->if_addr;
+               break;
+
+       case SIOCSIFADDR:
+               if_rtinit(ifp, -1);     /* delete previous route */
+               s = splimp();
+               ifp->if_addr = ifr->ifr_addr;
+               (*ifp->if_init)(unit);
+               splx(s);
+               break;
+
+       case SIOCGIFDSTADDR:
+               if ((ifp->if_flags & IFF_POINTOPOINT) == 0)
+                       return (EINVAL);
+               ifr->ifr_dstaddr = ifp->if_dstaddr;
+               break;
+
+       case SIOCSIFDSTADDR:
+               if ((ifp->if_flags & IFF_POINTOPOINT) == 0)
+                       return (EINVAL);
+               s = splimp();
+               ifp->if_dstaddr = ifr->ifr_dstaddr;
+               splx(s);
+               break;
+
+       case SIOCGIFFLAGS:
+               ifr->ifr_flags = ifp->if_flags;
+               break;
+
+       case SIOCSIFFLAGS:
+               if ((ifr->ifr_flags & IFF_UP) == 0 &&
+                   (ifp->if_flags & IFF_UP)) {
+                       s = splimp();
+                       if_down(ifp);
+                       splx(s);
                }
                }
-       timeout(if_slowtimo, 0, hz / IFNET_SLOWHZ);
+               ifp->if_flags = ifr->ifr_flags;
+               break;
+
+       default:
+               return (EINVAL);
+       }
+       return (0);
+}
+
+/*
+ * Return interface configuration
+ * of system.  List may be used
+ * in later ioctl's (above) to get
+ * other information.
+ */
+/*ARGSUSED*/
+ifconf(cmd, data)
+       int cmd;
+       caddr_t data;
+{
+       register struct ifconf *ifc = (struct ifconf *)data;
+       register struct ifnet *ifp = ifnet;
+       register char *cp, *ep;
+       struct ifreq ifr, *ifrp;
+       int space = ifc->ifc_len, error = 0;
+
+       ifrp = ifc->ifc_req;
+       ep = ifr.ifr_name + sizeof (ifr.ifr_name) - 2;
+       for (; space > sizeof (ifr) && ifp; ifp = ifp->if_next) {
+               bcopy(ifp->if_name, ifr.ifr_name, sizeof (ifr.ifr_name) - 2);
+               for (cp = ifr.ifr_name; cp < ep && *cp; cp++)
+                       ;
+               *cp++ = '0' + ifp->if_unit; *cp = '\0';
+               ifr.ifr_addr = ifp->if_addr;
+               error = copyout((caddr_t)&ifr, (caddr_t)ifrp, sizeof (ifr));
+               if (error)
+                       break;
+               space -= sizeof (ifr), ifrp++;
+       }
+       ifc->ifc_len -= space;
+       return (error);
 }
 }