]> 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 e8cef396f8f2201c3d5541770e8c9be633fb2a9e..33255ecb1d76bcb565c7aa5c8575c2001d95a6c5 100644 (file)
@@ -52,6 +52,7 @@
  * SUCH DAMAGE.
  *
  *     @(#)if_loop.c   8.1 (Berkeley) 6/10/93
  * SUCH DAMAGE.
  *
  *     @(#)if_loop.c   8.1 (Berkeley) 6/10/93
+ * $FreeBSD: src/sys/net/if_loop.c,v 1.47.2.5 2001/07/03 11:01:41 ume Exp $
  */
 
 /*
  */
 
 /*
 #include <netinet/ip6.h>
 #endif
 
 #include <netinet/ip6.h>
 #endif
 
-#if NS
-#include <netns/ns.h>
-#include <netns/ns_if.h>
-#endif
-
-#if ISO
-#include <netiso/iso.h>
-#include <netiso/iso_var.h>
-#endif
-
 #include <net/dlil.h>
 
 #if NETAT
 #include <net/dlil.h>
 
 #if NETAT
@@ -280,14 +271,10 @@ lo_output(ifp, m)
        ifp->if_opackets++;
        ifp->if_ipackets++;
 
        ifp->if_opackets++;
        ifp->if_ipackets++;
 
-       /* WARNING
-         * This won't work for loopbacked multicast 
-         */
        m->m_pkthdr.header = mtod(m, char *);
        m->m_pkthdr.header = mtod(m, char *);
-        m->m_pkthdr.aux = ifp; /* HACKERY */
-        m->m_pkthdr.csum_data = 0xffff; /* loopback checksums are always OK */
-        m->m_pkthdr.csum_flags = CSUM_DATA_VALID | CSUM_PSEUDO_HDR | 
-                               CSUM_IP_CHECKED | CSUM_IP_VALID;
+       m->m_pkthdr.csum_data = 0xffff; /* loopback checksums are always OK */
+       m->m_pkthdr.csum_flags = CSUM_DATA_VALID | CSUM_PSEUDO_HDR | 
+                                                        CSUM_IP_CHECKED | CSUM_IP_VALID;
        return dlil_input(ifp, m, m);
 }
 
        return dlil_input(ifp, m, m);
 }
 
@@ -335,6 +322,7 @@ lo_pre_output(ifp, m, dst, route, frame_type, dst_addr, dl_tag)
 #endif
 #if INET6
        case AF_INET6:
 #endif
 #if INET6
        case AF_INET6:
+           (*m)->m_flags |= M_LOOP;
            ifq = &ip6intrq;
            isr = NETISR_IPV6;
            break;
            ifq = &ip6intrq;
            isr = NETISR_IPV6;
            break;
@@ -362,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);
        }
@@ -441,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;
@@ -496,9 +479,17 @@ loioctl(dl_tag, ifp, cmd, data)
 
        default:
                error = EOPNOTSUPP;
 
        default:
                error = EOPNOTSUPP;
+               break;
        }
        return (error);
 }
        }
        return (error);
 }
+
+static int
+loioctl(u_long dl_tag, struct ifnet *ifp, u_long cmd, caddr_t data)
+{
+    return (lo_if_ioctl(ifp, cmd, data));
+}
+
 #endif /* NLOOP > 0 */
 
 
 #endif /* NLOOP > 0 */
 
 
@@ -507,36 +498,62 @@ int lo_shutdown()
     return 0;
 }
 
     return 0;
 }
 
-
-void lo_reg_if_mods()
+int  lo_attach_inet(struct ifnet *ifp, u_long *dl_tag)
 {
 {
-     struct dlil_ifmod_reg_str  lo_ifmod;
+    struct dlil_proto_reg_str   reg;
+    struct dlil_demux_desc      desc;
+    short native=0;
+    int   stat =0 ;
+    int i;
 
 
-     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;
+    for (i=0; i < lo_count; i++) {
+       if ((lo_array[i]) && (lo_array[i]->ifp == ifp)) {
+           if (lo_array[i]->protocol_family == PF_INET) {
+               *dl_tag = lo_array[i]->dl_tag;
+               return (0);
+           }
+       }
+    }
 
 
-    if (dlil_reg_if_modules(APPLE_IF_FAM_LOOPBACK, &lo_ifmod))
-       panic("Couldn't register lo modules\n");
-}
+    TAILQ_INIT(&reg.demux_desc_head);
+    desc.type = DLIL_DESC_RAW;
+    desc.variants.bitmask.proto_id_length = 0;
+    desc.variants.bitmask.proto_id = 0;
+    desc.variants.bitmask.proto_id_mask = 0;
+    desc.native_type = (char *) &native;
+    TAILQ_INSERT_TAIL(&reg.demux_desc_head, &desc, next);
+    reg.interface_family = ifp->if_family;
+    reg.unit_number      = ifp->if_unit;
+    reg.input           = lo_input;
+    reg.pre_output       = lo_pre_output;
+    reg.event            = 0;
+    reg.offer            = 0;
+    reg.ioctl            = loioctl;
+    reg.default_proto    = 0;
+    reg.protocol_family  = PF_INET;
 
 
+    stat = dlil_attach_protocol(&reg, dl_tag);
 
 
-u_long  lo_attach_inet(struct ifnet *ifp)
+    if (stat)
+       printf("lo_attach_inet: dlil_attach_protocol returned=%d\n", stat);
+    
+    return stat;
+}
+
+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_INET)
-               return lo_array[i]->dl_tag;
+           if (lo_array[i]->protocol_family == PF_INET6) {
+               *dl_tag = lo_array[i]->dl_tag;
+               return (0);
+           }
        }
     }
 
        }
     }
 
@@ -555,16 +572,49 @@ u_long  lo_attach_inet(struct ifnet *ifp)
     reg.offer            = 0;
     reg.ioctl            = loioctl;
     reg.default_proto    = 0;
     reg.offer            = 0;
     reg.ioctl            = loioctl;
     reg.default_proto    = 0;
-    reg.protocol_family  = PF_INET;
+    reg.protocol_family  = PF_INET6;
 
 
-    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_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 *))
 {
@@ -604,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 = 0;
+               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;