date and time created 88/12/13 13:20:26 by sklower
[unix-history] / usr / src / sys / net / if.c
index 1899dbb..f4f7efe 100644 (file)
@@ -1,6 +1,24 @@
-/*     if.c    6.6     85/04/01        */
+/*
+ * Copyright (c) 1980, 1986 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.
+ *
+ *     @(#)if.c        7.4 (Berkeley) %G%
+ */
 
 #include "param.h"
 
 #include "param.h"
+#include "mbuf.h"
 #include "systm.h"
 #include "socket.h"
 #include "socketvar.h"
 #include "systm.h"
 #include "socket.h"
 #include "socketvar.h"
@@ -30,11 +48,8 @@ ifinit()
        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_init) {
-                       (*ifp->if_init)(ifp->if_unit);
-                       if (ifp->if_snd.ifq_maxlen == 0)
-                               ifp->if_snd.ifq_maxlen = ifqmaxlen;
-               }
+               if (ifp->if_snd.ifq_maxlen == 0)
+                       ifp->if_snd.ifq_maxlen = ifqmaxlen;
        if_slowtimo();
 }
 
        if_slowtimo();
 }
 
@@ -92,6 +107,27 @@ ifa_ifwithaddr(addr)
        }
        return ((struct ifaddr *)0);
 }
        }
        return ((struct ifaddr *)0);
 }
+/*
+ * Locate the point to point interface with a given destination address.
+ */
+/*ARGSUSED*/
+struct ifaddr *
+ifa_ifwithdstaddr(addr)
+       struct sockaddr *addr;
+{
+       register struct ifnet *ifp;
+       register struct ifaddr *ifa;
+
+       for (ifp = ifnet; ifp; ifp = ifp->if_next) 
+           if (ifp->if_flags & IFF_POINTOPOINT)
+               for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next) {
+                       if (ifa->ifa_addr.sa_family != addr->sa_family)
+                               continue;
+                       if (equal(&ifa->ifa_dstaddr, addr))
+                               return (ifa);
+       }
+       return ((struct ifaddr *)0);
+}
 
 /*
  * Find an interface on a specific network.  If many, choice
 
 /*
  * Find an interface on a specific network.  If many, choice
@@ -119,6 +155,7 @@ ifa_ifwithnet(addr)
        return ((struct ifaddr *)0);
 }
 
        return ((struct ifaddr *)0);
 }
 
+#ifdef notdef
 /*
  * Find an interface using a specific address family
  */
 /*
  * Find an interface using a specific address family
  */
@@ -135,6 +172,7 @@ ifa_ifwithaf(af)
                        return (ifa);
        return ((struct ifaddr *)0);
 }
                        return (ifa);
        return ((struct ifaddr *)0);
 }
+#endif
 
 /*
  * Mark an interface down and notify protocols of
 
 /*
  * Mark an interface down and notify protocols of
@@ -148,7 +186,26 @@ if_down(ifp)
 
        ifp->if_flags &= ~IFF_UP;
        for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next)
 
        ifp->if_flags &= ~IFF_UP;
        for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next)
-               pfctlinput(PRC_IFDOWN, (caddr_t)&ifa->ifa_addr);
+               pfctlinput(PRC_IFDOWN, &ifa->ifa_addr);
+       if_qflush(&ifp->if_snd);
+}
+
+/*
+ * Flush an interface queue.
+ */
+if_qflush(ifq)
+       register struct ifqueue *ifq;
+{
+       register struct mbuf *m, *n;
+
+       n = ifq->ifq_head;
+       while (m = n) {
+               n = m->m_act;
+               m_freem(m);
+       }
+       ifq->ifq_head = 0;
+       ifq->ifq_tail = 0;
+       ifq->ifq_len = 0;
 }
 
 /*
 }
 
 /*
@@ -232,7 +289,13 @@ ifioctl(so, cmd, data)
                ifr->ifr_flags = ifp->if_flags;
                break;
 
                ifr->ifr_flags = ifp->if_flags;
                break;
 
+       case SIOCGIFMETRIC:
+               ifr->ifr_metric = ifp->if_metric;
+               break;
+
        case SIOCSIFFLAGS:
        case SIOCSIFFLAGS:
+               if (!suser())
+                       return (u.u_error);
                if (ifp->if_flags & IFF_UP && (ifr->ifr_flags & IFF_UP) == 0) {
                        int s = splimp();
                        if_down(ifp);
                if (ifp->if_flags & IFF_UP && (ifr->ifr_flags & IFF_UP) == 0) {
                        int s = splimp();
                        if_down(ifp);
@@ -240,6 +303,14 @@ ifioctl(so, cmd, data)
                }
                ifp->if_flags = (ifp->if_flags & IFF_CANTCHANGE) |
                        (ifr->ifr_flags &~ IFF_CANTCHANGE);
                }
                ifp->if_flags = (ifp->if_flags & IFF_CANTCHANGE) |
                        (ifr->ifr_flags &~ IFF_CANTCHANGE);
+               if (ifp->if_ioctl)
+                       (void) (*ifp->if_ioctl)(ifp, cmd, data);
+               break;
+
+       case SIOCSIFMETRIC:
+               if (!suser())
+                       return (u.u_error);
+               ifp->if_metric = ifr->ifr_metric;
                break;
 
        default:
                break;
 
        default: