]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/net/if_loop.c
xnu-517.9.5.tar.gz
[apple/xnu.git] / bsd / net / if_loop.c
index ca5e523854aad2f66f54d048f4a2d7dc6f96f6d8..33255ecb1d76bcb565c7aa5c8575c2001d95a6c5 100644 (file)
@@ -3,22 +3,19 @@
  *
  * @APPLE_LICENSE_HEADER_START@
  * 
  *
  * @APPLE_LICENSE_HEADER_START@
  * 
- * Copyright (c) 1999-2003 Apple Computer, Inc.  All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License").  You may not use this file except in compliance with the
+ * License.  Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
  * 
  * 
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- * 
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
  * 
  * @APPLE_LICENSE_HEADER_END@
  */
  * 
  * @APPLE_LICENSE_HEADER_END@
  */
@@ -353,7 +350,7 @@ lo_pre_output(ifp, m, dst, route, frame_type, dst_addr, dl_tag)
            ifq = &atalkintrq;
            isr = NETISR_APPLETALK;
            break;
            ifq = &atalkintrq;
            isr = NETISR_APPLETALK;
            break;
-#endif NETAT
+#endif /* NETAT */
        default:
            return (EAFNOSUPPORT);
        }
        default:
            return (EAFNOSUPPORT);
        }
@@ -432,13 +429,8 @@ lortrequest(cmd, rt, sa)
 /*
  * Process an ioctl request.
  */
 /*
  * Process an ioctl request.
  */
-/* ARGSUSED */
 static int
 static int
-loioctl(dl_tag, ifp, cmd, data)
-       u_long   dl_tag;
-       register struct ifnet *ifp;
-       u_long cmd;
-       void   *data;
+lo_if_ioctl(struct ifnet *ifp, u_long cmd, void * data)
 {
        register struct ifaddr *ifa;
        register struct ifreq *ifr = (struct ifreq *)data;
 {
        register struct ifaddr *ifa;
        register struct ifreq *ifr = (struct ifreq *)data;
@@ -487,48 +479,39 @@ loioctl(dl_tag, ifp, cmd, data)
 
        default:
                error = EOPNOTSUPP;
 
        default:
                error = EOPNOTSUPP;
+               break;
        }
        return (error);
 }
        }
        return (error);
 }
-#endif /* NLOOP > 0 */
-
 
 
-int lo_shutdown()
+static int
+loioctl(u_long dl_tag, struct ifnet *ifp, u_long cmd, caddr_t data)
 {
 {
-    return 0;
+    return (lo_if_ioctl(ifp, cmd, data));
 }
 
 }
 
+#endif /* NLOOP > 0 */
 
 
-void lo_reg_if_mods()
-{
-     struct dlil_ifmod_reg_str  lo_ifmod;
-
-     bzero(&lo_ifmod, sizeof(lo_ifmod));
-     lo_ifmod.add_if = lo_add_if;
-     lo_ifmod.del_if = lo_del_if;
-     lo_ifmod.add_proto = lo_add_proto;
-     lo_ifmod.del_proto = lo_del_proto;
-     lo_ifmod.ifmod_ioctl = 0;
-     lo_ifmod.shutdown    = lo_shutdown;
 
 
-    if (dlil_reg_if_modules(APPLE_IF_FAM_LOOPBACK, &lo_ifmod))
-       panic("Couldn't register lo modules\n");
+int lo_shutdown()
+{
+    return 0;
 }
 
 }
 
-
-u_long  lo_attach_inet(struct ifnet *ifp)
+int  lo_attach_inet(struct ifnet *ifp, u_long *dl_tag)
 {
     struct dlil_proto_reg_str   reg;
     struct dlil_demux_desc      desc;
 {
     struct dlil_proto_reg_str   reg;
     struct dlil_demux_desc      desc;
-    u_long                     dl_tag=0;
     short native=0;
     short native=0;
-    int   stat;
+    int   stat =0 ;
     int i;
 
     for (i=0; i < lo_count; i++) {
        if ((lo_array[i]) && (lo_array[i]->ifp == ifp)) {
     int i;
 
     for (i=0; i < lo_count; i++) {
        if ((lo_array[i]) && (lo_array[i]->ifp == ifp)) {
-           if (lo_array[i]->protocol_family == PF_INET)
-               return lo_array[i]->dl_tag;
+           if (lo_array[i]->protocol_family == PF_INET) {
+               *dl_tag = lo_array[i]->dl_tag;
+               return (0);
+           }
        }
     }
 
        }
     }
 
@@ -549,27 +532,28 @@ u_long  lo_attach_inet(struct ifnet *ifp)
     reg.default_proto    = 0;
     reg.protocol_family  = PF_INET;
 
     reg.default_proto    = 0;
     reg.protocol_family  = PF_INET;
 
-    stat = dlil_attach_protocol(&reg, &dl_tag);
-    if (stat) {
-       panic("lo_attach_inet can't attach interface\n");
-    }
+    stat = dlil_attach_protocol(&reg, dl_tag);
+
+    if (stat)
+       printf("lo_attach_inet: dlil_attach_protocol returned=%d\n", stat);
     
     
-    return dl_tag;
+    return stat;
 }
 
 }
 
-u_long  lo_attach_inet6(struct ifnet *ifp)
+int  lo_attach_inet6(struct ifnet *ifp, u_long *dl_tag)
 {
     struct dlil_proto_reg_str   reg;
     struct dlil_demux_desc      desc;
 {
     struct dlil_proto_reg_str   reg;
     struct dlil_demux_desc      desc;
-    u_long                     dl_tag=0;
     short native=0;
     int   stat;
     int i;
 
     for (i=0; i < lo_count; i++) {
        if ((lo_array[i]) && (lo_array[i]->ifp == ifp)) {
     short native=0;
     int   stat;
     int i;
 
     for (i=0; i < lo_count; i++) {
        if ((lo_array[i]) && (lo_array[i]->ifp == ifp)) {
-           if (lo_array[i]->protocol_family == PF_INET6)
-               return lo_array[i]->dl_tag;
+           if (lo_array[i]->protocol_family == PF_INET6) {
+               *dl_tag = lo_array[i]->dl_tag;
+               return (0);
+           }
        }
     }
 
        }
     }
 
@@ -590,14 +574,47 @@ u_long  lo_attach_inet6(struct ifnet *ifp)
     reg.default_proto    = 0;
     reg.protocol_family  = PF_INET6;
 
     reg.default_proto    = 0;
     reg.protocol_family  = PF_INET6;
 
-    stat = dlil_attach_protocol(&reg, &dl_tag);
-    if (stat) {
-       panic("lo_attach_inet6 can't attach interface\n");
-    }
+    stat = dlil_attach_protocol(&reg, dl_tag);
+
+    if (stat)
+       printf("lo_attach_inet6: dlil_attach_protocol returned=%d\n", stat);
     
     
-    return dl_tag;
+    return stat;
 }
 
 }
 
+void lo_reg_if_mods()
+{
+     struct dlil_ifmod_reg_str  lo_ifmod;
+     struct dlil_protomod_reg_str lo_protoreg;
+     int error;
+
+     bzero(&lo_ifmod, sizeof(lo_ifmod));
+     lo_ifmod.add_if = lo_add_if;
+     lo_ifmod.del_if = lo_del_if;
+     lo_ifmod.add_proto = lo_add_proto;
+     lo_ifmod.del_proto = lo_del_proto;
+     lo_ifmod.ifmod_ioctl = 0;
+     lo_ifmod.shutdown    = lo_shutdown;
+
+       if (dlil_reg_if_modules(APPLE_IF_FAM_LOOPBACK, &lo_ifmod))
+               panic("Couldn't register lo modules\n");
+
+       /* Register protocol registration functions */
+
+       bzero(&lo_protoreg, sizeof(lo_protoreg));
+       lo_protoreg.attach_proto = lo_attach_inet;
+       lo_protoreg.detach_proto = NULL; /* no detach function for loopback */
+       
+       if ( error = dlil_reg_proto_module(PF_INET, APPLE_IF_FAM_LOOPBACK, &lo_protoreg) != 0)
+               printf("dlil_reg_proto_module failed for AF_INET error=%d\n", error);
+
+       lo_protoreg.attach_proto = lo_attach_inet6;
+       lo_protoreg.detach_proto = NULL;
+       
+       if ( error = dlil_reg_proto_module(PF_INET6, APPLE_IF_FAM_LOOPBACK, &lo_protoreg) != 0)
+               printf("dlil_reg_proto_module failed for AF_INET6 error=%d\n", error);
+
+}
 
 int lo_set_bpf_tap(struct ifnet *ifp, int mode, int (*bpf_callback)(struct ifnet *, struct mbuf *))
 {
 
 int lo_set_bpf_tap(struct ifnet *ifp, int mode, int (*bpf_callback)(struct ifnet *, struct mbuf *))
 {
@@ -637,7 +654,7 @@ loopattach(dummy)
                ifp->if_unit = i++;
                ifp->if_mtu = LOMTU;
                ifp->if_flags = IFF_LOOPBACK | IFF_MULTICAST;
                ifp->if_unit = i++;
                ifp->if_mtu = LOMTU;
                ifp->if_flags = IFF_LOOPBACK | IFF_MULTICAST;
-               ifp->if_ioctl = loioctl;
+               ifp->if_ioctl = lo_if_ioctl;
                ifp->if_set_bpf_tap = lo_set_bpf_tap;
                ifp->if_output = lo_output;
                ifp->if_type = IFT_LOOP;
                ifp->if_set_bpf_tap = lo_set_bpf_tap;
                ifp->if_output = lo_output;
                ifp->if_type = IFT_LOOP;