]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/net/ether_inet_pr_module.c
xnu-4903.270.47.tar.gz
[apple/xnu.git] / bsd / net / ether_inet_pr_module.c
index b47c9dfba63a042eb4d9b8a5656adb45ecbdafa8..436c8fc7b6584334bfc182a13f831d53b76b0985 100644 (file)
@@ -107,26 +107,27 @@ extern void *kdp_get_interface(void);
 extern void kdp_set_ip_and_mac_addresses(struct in_addr *ipaddr,
     struct ether_addr *macaddr);
 
-#define        _ip_copy(dst, src)      \
+#define _ip_copy(dst, src)      \
        bcopy(src, dst, sizeof (struct in_addr))
 
 static void
 ether_inet_arp_input(struct ifnet *ifp, struct mbuf *m)
 {
        struct ether_arp *ea;
-       struct sockaddr_dl      sender_hw;
-       struct sockaddr_in      sender_ip;
-       struct sockaddr_in      target_ip;
+       struct sockaddr_dl      sender_hw;
+       struct sockaddr_in      sender_ip;
+       struct sockaddr_in      target_ip;
 
-       if (mbuf_len(m) < sizeof (*ea) && mbuf_pullup(&m, sizeof (*ea)) != 0)
+       if (mbuf_len(m) < sizeof(*ea) && mbuf_pullup(&m, sizeof(*ea)) != 0) {
                return;
+       }
 
        ea = mbuf_data(m);
 
        /* Verify this is an ethernet/ip arp and address lengths are correct */
        if (ntohs(ea->arp_hrd) != ARPHRD_ETHER ||
            ntohs(ea->arp_pro) != ETHERTYPE_IP ||
-           ea->arp_pln != sizeof (struct in_addr) ||
+           ea->arp_pln != sizeof(struct in_addr) ||
            ea->arp_hln != ETHER_ADDR_LEN) {
                mbuf_freem(m);
                return;
@@ -138,15 +139,15 @@ ether_inet_arp_input(struct ifnet *ifp, struct mbuf *m)
                return;
        }
 
-       bzero(&sender_ip, sizeof (sender_ip));
-       sender_ip.sin_len = sizeof (sender_ip);
+       bzero(&sender_ip, sizeof(sender_ip));
+       sender_ip.sin_len = sizeof(sender_ip);
        sender_ip.sin_family = AF_INET;
        _ip_copy(&sender_ip.sin_addr, ea->arp_spa);
        target_ip = sender_ip;
        _ip_copy(&target_ip.sin_addr, ea->arp_tpa);
 
-       bzero(&sender_hw, sizeof (sender_hw));
-       sender_hw.sdl_len = sizeof (sender_hw);
+       bzero(&sender_hw, sizeof(sender_hw));
+       sender_hw.sdl_len = sizeof(sender_hw);
        sender_hw.sdl_family = AF_LINK;
        sender_hw.sdl_type = IFT_ETHER;
        sender_hw.sdl_alen = ETHER_ADDR_LEN;
@@ -166,13 +167,13 @@ ether_inet_arp_input(struct ifnet *ifp, struct mbuf *m)
  * the ether header, which is provided separately.
  */
 static errno_t
-ether_inet_input(ifnet_t ifp, protocol_family_t        protocol_family,
+ether_inet_input(ifnet_t ifp, protocol_family_t protocol_family,
     mbuf_t m_list)
 {
 #pragma unused(ifp, protocol_family)
-       mbuf_t  m;
-       mbuf_t  *tailptr = &m_list;
-       mbuf_t  nextpkt;
+       mbuf_t  m;
+       mbuf_t  *tailptr = &m_list;
+       mbuf_t  nextpkt;
 
        /* Strip ARP and non-IP packets out of the list */
        for (m = m_list; m; m = nextpkt) {
@@ -206,10 +207,11 @@ ether_inet_input(ifnet_t ifp, protocol_family_t   protocol_family,
                } else {
                        /* Pass ARP packets to arp input */
                        m->m_nextpkt = NULL;
-                       if (eh->ether_type == htons(ETHERTYPE_ARP))
+                       if (eh->ether_type == htons(ETHERTYPE_ARP)) {
                                ether_inet_arp_input(mifp, m);
-                       else
+                       } else {
                                mbuf_freem(m);
+                       }
                }
        }
 
@@ -220,7 +222,7 @@ ether_inet_input(ifnet_t ifp, protocol_family_t     protocol_family,
                mbuf_freem_list(m_list);
        }
 
-       return (EJUSTRETURN);
+       return EJUSTRETURN;
 }
 
 static errno_t
@@ -233,8 +235,9 @@ ether_inet_pre_output(ifnet_t ifp, protocol_family_t protocol_family,
        const struct ether_header *eh;
        errno_t result = 0;
 
-       if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
-               return (ENETDOWN);
+       if ((ifp->if_flags & (IFF_UP | IFF_RUNNING)) != (IFF_UP | IFF_RUNNING)) {
+               return ENETDOWN;
+       }
 
        /*
         * Tell ether_frameout it's ok to loop packet unless negated below.
@@ -247,12 +250,12 @@ ether_inet_pre_output(ifnet_t ifp, protocol_family_t protocol_family,
 
                result = arp_lookup_ip(ifp,
                    (const struct sockaddr_in *)(uintptr_t)(size_t)dst_netaddr,
-                   &ll_dest, sizeof (ll_dest), (route_t)route, *m0);
+                   &ll_dest, sizeof(ll_dest), (route_t)route, *m0);
                if (result == 0) {
                        u_int16_t ethertype_ip = htons(ETHERTYPE_IP);
 
                        bcopy(LLADDR(&ll_dest), edst, ETHER_ADDR_LEN);
-                       bcopy(&ethertype_ip, type, sizeof (ethertype_ip));
+                       bcopy(&ethertype_ip, type, sizeof(ethertype_ip));
                }
                break;
        }
@@ -263,7 +266,7 @@ ether_inet_pre_output(ifnet_t ifp, protocol_family_t protocol_family,
                eh = (const struct ether_header *)(uintptr_t)(size_t)
                    dst_netaddr->sa_data;
                (void) memcpy(edst, eh->ether_dhost, 6);
-               bcopy(&eh->ether_type, type, sizeof (u_short));
+               bcopy(&eh->ether_type, type, sizeof(u_short));
                break;
 
        default:
@@ -274,7 +277,7 @@ ether_inet_pre_output(ifnet_t ifp, protocol_family_t protocol_family,
                break;
        }
 
-       return (result);
+       return result;
 }
 
 static errno_t
@@ -286,14 +289,17 @@ ether_inet_resolve_multi(ifnet_t ifp, const struct sockaddr *proto_addr,
        const struct sockaddr_in *sin =
            (const struct sockaddr_in *)(uintptr_t)(size_t)proto_addr;
 
-       if (proto_addr->sa_family != AF_INET)
-               return (EAFNOSUPPORT);
+       if (proto_addr->sa_family != AF_INET) {
+               return EAFNOSUPPORT;
+       }
 
-       if (proto_addr->sa_len < sizeof (struct sockaddr_in))
-               return (EINVAL);
+       if (proto_addr->sa_len < sizeof(struct sockaddr_in)) {
+               return EINVAL;
+       }
 
-       if (ll_len < minsize)
-               return (EMSGSIZE);
+       if (ll_len < minsize) {
+               return EMSGSIZE;
+       }
 
        bzero(out_ll, minsize);
        out_ll->sdl_len = minsize;
@@ -305,7 +311,7 @@ ether_inet_resolve_multi(ifnet_t ifp, const struct sockaddr *proto_addr,
        out_ll->sdl_slen = 0;
        ETHER_MAP_IP_MULTICAST(&sin->sin_addr, LLADDR(out_ll));
 
-       return (0);
+       return 0;
 }
 
 static errno_t
@@ -316,8 +322,8 @@ ether_inet_prmod_ioctl(ifnet_t ifp, protocol_family_t protocol_family,
        int error = 0;
 
        switch (command) {
-       case SIOCSIFADDR:               /* struct ifaddr pointer */
-       case SIOCAIFADDR: {             /* struct ifaddr pointer */
+       case SIOCSIFADDR:               /* struct ifaddr pointer */
+       case SIOCAIFADDR: {             /* struct ifaddr pointer */
                /*
                 * Note: caller of ifnet_ioctl() passes in pointer to
                 * struct ifaddr as parameter to SIOC{A,S}IFADDR, for
@@ -330,13 +336,15 @@ ether_inet_prmod_ioctl(ifnet_t ifp, protocol_family_t protocol_family,
                        ifnet_ioctl(ifp, 0, SIOCSIFFLAGS, NULL);
                }
 
-               if (ifaddr_address_family(ifa) != AF_INET)
+               if (ifaddr_address_family(ifa) != AF_INET) {
                        break;
+               }
 
                inet_arp_init_ifaddr(ifp, ifa);
 
-               if (command != SIOCSIFADDR)
+               if (command != SIOCSIFADDR) {
                        break;
+               }
 
                /*
                 * Register new IP and MAC addresses with the kernel
@@ -348,13 +356,14 @@ ether_inet_prmod_ioctl(ifnet_t ifp, protocol_family_t protocol_family,
                 */
                if ((kdp_get_interface() != 0 &&
                    kdp_get_interface() == ifp->if_softc) ||
-                   (kdp_get_interface() == 0 && ifp->if_unit == 0))
+                   (kdp_get_interface() == 0 && ifp->if_unit == 0)) {
                        kdp_set_ip_and_mac_addresses(&(IA_SIN(ifa)->sin_addr),
                            (struct ether_addr *)IF_LLADDR(ifp));
+               }
                break;
        }
 
-       case SIOCGIFADDR: {             /* struct ifreq */
+       case SIOCGIFADDR: {             /* struct ifreq */
                struct ifreq *ifr = data;
                ifnet_guarded_lladdr_copy_bytes(ifp, ifr->ifr_addr.sa_data,
                    ETHER_ADDR_LEN);
@@ -366,7 +375,7 @@ ether_inet_prmod_ioctl(ifnet_t ifp, protocol_family_t protocol_family,
                break;
        }
 
-       return (error);
+       return error;
 }
 
 static void
@@ -376,7 +385,7 @@ ether_inet_event(ifnet_t ifp, protocol_family_t protocol,
 #pragma unused(protocol)
        ifaddr_t *addresses;
 
-       if (event->vendor_code !=  KEV_VENDOR_APPLE ||
+       if (event->vendor_code != KEV_VENDOR_APPLE ||
            event->kev_class != KEV_NETWORK_CLASS ||
            event->kev_subclass != KEV_DL_SUBCLASS ||
            event->event_code != KEV_DL_LINK_ADDRESS_CHANGED) {
@@ -399,8 +408,8 @@ ether_inet_arp(ifnet_t ifp, u_short arpop, const struct sockaddr_dl *sender_hw,
     const struct sockaddr *sender_proto, const struct sockaddr_dl *target_hw,
     const struct sockaddr *target_proto)
 {
-       mbuf_t  m;
-       errno_t result;
+       mbuf_t  m;
+       errno_t result;
        struct ether_header *eh;
        struct ether_arp *ea;
        const struct sockaddr_in *sender_ip =
@@ -409,34 +418,38 @@ ether_inet_arp(ifnet_t ifp, u_short arpop, const struct sockaddr_dl *sender_hw,
            (const struct sockaddr_inarp *)(uintptr_t)(size_t)target_proto;
        char *datap;
 
-       if (target_ip == NULL)
-               return (EINVAL);
+       if (target_ip == NULL) {
+               return EINVAL;
+       }
 
        if ((sender_ip && sender_ip->sin_family != AF_INET) ||
-           target_ip->sin_family != AF_INET)
-               return (EAFNOSUPPORT);
+           target_ip->sin_family != AF_INET) {
+               return EAFNOSUPPORT;
+       }
 
        result = mbuf_gethdr(MBUF_DONTWAIT, MBUF_TYPE_DATA, &m);
-       if (result != 0)
-               return (result);
+       if (result != 0) {
+               return result;
+       }
 
-       mbuf_setlen(m, sizeof (*ea));
-       mbuf_pkthdr_setlen(m, sizeof (*ea));
+       mbuf_setlen(m, sizeof(*ea));
+       mbuf_pkthdr_setlen(m, sizeof(*ea));
 
        /* Move the data pointer in the mbuf to the end, aligned to 4 bytes */
        datap = mbuf_datastart(m);
        datap += mbuf_trailingspace(m);
        datap -= (((uintptr_t)datap) & 0x3);
-       mbuf_setdata(m, datap, sizeof (*ea));
+       mbuf_setdata(m, datap, sizeof(*ea));
        ea = mbuf_data(m);
 
        /*
         * Prepend the ethernet header, we will send the raw frame;
         * callee frees the original mbuf when allocation fails.
         */
-       result = mbuf_prepend(&m, sizeof (*eh), MBUF_DONTWAIT);
-       if (result != 0)
-               return (result);
+       result = mbuf_prepend(&m, sizeof(*eh), MBUF_DONTWAIT);
+       if (result != 0) {
+               return result;
+       }
 
        eh = mbuf_data(m);
        eh->ether_type = htons(ETHERTYPE_ARP);
@@ -447,23 +460,23 @@ ether_inet_arp(ifnet_t ifp, u_short arpop, const struct sockaddr_dl *sender_hw,
 
        /* Fill out the arp header */
        ea->arp_pro = htons(ETHERTYPE_IP);
-       ea->arp_hln = sizeof (ea->arp_sha);
-       ea->arp_pln = sizeof (ea->arp_spa);
+       ea->arp_hln = sizeof(ea->arp_sha);
+       ea->arp_pln = sizeof(ea->arp_spa);
        ea->arp_hrd = htons(ARPHRD_ETHER);
        ea->arp_op = htons(arpop);
 
        /* Sender Hardware */
        if (sender_hw != NULL) {
                bcopy(CONST_LLADDR(sender_hw), ea->arp_sha,
-                   sizeof (ea->arp_sha));
+                   sizeof(ea->arp_sha));
        } else {
                ifnet_lladdr_copy_bytes(ifp, ea->arp_sha, ETHER_ADDR_LEN);
        }
-       ifnet_lladdr_copy_bytes(ifp, eh->ether_shost, sizeof (eh->ether_shost));
+       ifnet_lladdr_copy_bytes(ifp, eh->ether_shost, sizeof(eh->ether_shost));
 
        /* Sender IP */
        if (sender_ip != NULL) {
-               bcopy(&sender_ip->sin_addr, ea->arp_spa, sizeof (ea->arp_spa));
+               bcopy(&sender_ip->sin_addr, ea->arp_spa, sizeof(ea->arp_spa));
        } else {
                struct ifaddr *ifa;
 
@@ -475,7 +488,7 @@ ether_inet_arp(ifnet_t ifp, u_short arpop, const struct sockaddr_dl *sender_hw,
                            ifa->ifa_addr->sa_family == AF_INET) {
                                bcopy(&((struct sockaddr_in *)(void *)
                                    ifa->ifa_addr)->sin_addr, ea->arp_spa,
-                                   sizeof (ea->arp_spa));
+                                   sizeof(ea->arp_spa));
                                IFA_UNLOCK(ifa);
                                break;
                        }
@@ -485,29 +498,30 @@ ether_inet_arp(ifnet_t ifp, u_short arpop, const struct sockaddr_dl *sender_hw,
 
                if (ifa == NULL) {
                        mbuf_freem(m);
-                       return (ENXIO);
+                       return ENXIO;
                }
        }
 
        /* Target Hardware */
        if (target_hw == NULL) {
-               bzero(ea->arp_tha, sizeof (ea->arp_tha));
+               bzero(ea->arp_tha, sizeof(ea->arp_tha));
                bcopy(etherbroadcastaddr, eh->ether_dhost,
-                   sizeof (eh->ether_dhost));
+                   sizeof(eh->ether_dhost));
                m->m_flags |= M_BCAST;
        } else {
                bcopy(CONST_LLADDR(target_hw), ea->arp_tha,
-                   sizeof (ea->arp_tha));
+                   sizeof(ea->arp_tha));
                bcopy(CONST_LLADDR(target_hw), eh->ether_dhost,
-                   sizeof (eh->ether_dhost));
+                   sizeof(eh->ether_dhost));
 
                if (bcmp(eh->ether_dhost, etherbroadcastaddr,
-                   ETHER_ADDR_LEN) == 0)
+                   ETHER_ADDR_LEN) == 0) {
                        m->m_flags |= M_BCAST;
+               }
        }
 
        /* Target IP */
-       bcopy(&target_ip->sin_addr, ea->arp_tpa, sizeof (ea->arp_tpa));
+       bcopy(&target_ip->sin_addr, ea->arp_tpa, sizeof(ea->arp_tpa));
 
        /*
         * PKTF_{INET,INET6}_RESOLVE_RTR are mutually exclusive, so make
@@ -520,8 +534,9 @@ ether_inet_arp(ifnet_t ifp, u_short arpop, const struct sockaddr_dl *sender_hw,
         * the packet accordingly so that the driver can find out,
         * in case it needs to perform driver-specific action(s).
         */
-       if (arpop == ARPOP_REQUEST && (target_ip->sin_other & SIN_ROUTER))
+       if (arpop == ARPOP_REQUEST && (target_ip->sin_other & SIN_ROUTER)) {
                m->m_pkthdr.pkt_flags |= PKTF_RESOLVE_RTR;
+       }
 
        if (ifp->if_eflags & IFEF_TXSTART) {
                /*
@@ -533,7 +548,7 @@ ether_inet_arp(ifnet_t ifp, u_short arpop, const struct sockaddr_dl *sender_hw,
 
        ifnet_output_raw(ifp, PF_INET, m);
 
-       return (0);
+       return 0;
 }
 
 errno_t
@@ -544,19 +559,19 @@ ether_attach_inet(struct ifnet *ifp, protocol_family_t proto_family)
        struct ifnet_demux_desc demux[2];
        u_short en_native = htons(ETHERTYPE_IP);
        u_short arp_native = htons(ETHERTYPE_ARP);
-       errno_t error;
+       errno_t error;
 
-       bzero(&demux[0], sizeof (demux));
+       bzero(&demux[0], sizeof(demux));
        demux[0].type = DLIL_DESC_ETYPE2;
        demux[0].data = &en_native;
-       demux[0].datalen = sizeof (en_native);
+       demux[0].datalen = sizeof(en_native);
        demux[1].type = DLIL_DESC_ETYPE2;
        demux[1].data = &arp_native;
-       demux[1].datalen = sizeof (arp_native);
+       demux[1].datalen = sizeof(arp_native);
 
-       bzero(&proto, sizeof (proto));
+       bzero(&proto, sizeof(proto));
        proto.demux_list = demux;
-       proto.demux_count = sizeof (demux) / sizeof (demux[0]);
+       proto.demux_count = sizeof(demux) / sizeof(demux[0]);
        proto.input = ether_inet_input;
        proto.pre_output = ether_inet_pre_output;
        proto.ioctl = ether_inet_prmod_ioctl;
@@ -569,7 +584,7 @@ ether_attach_inet(struct ifnet *ifp, protocol_family_t proto_family)
                printf("WARNING: %s can't attach ip to %s\n", __func__,
                    if_name(ifp));
        }
-       return (error);
+       return error;
 }
 
 void