X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/3e170ce000f1506b7b5d2c5c7faec85ceabb573d..d9a64523371fa019c4575bb400cbbc3a50ac9903:/bsd/net/if_bond.c diff --git a/bsd/net/if_bond.c b/bsd/net/if_bond.c index 34f6e03d4..8682a9fe5 100644 --- a/bsd/net/if_bond.c +++ b/bsd/net/if_bond.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2014 Apple Inc. All rights reserved. + * Copyright (c) 2004-2018 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * @@ -49,7 +49,6 @@ #include #include #include - #include #include #include @@ -68,6 +67,7 @@ #include #include +#include #include #include @@ -83,9 +83,14 @@ static struct ether_addr slow_proto_multicast = { IEEE8023AD_SLOW_PROTO_MULTICAST }; +typedef struct ifbond_s ifbond, * ifbond_ref; +typedef struct bondport_s bondport, * bondport_ref; + #define BOND_MAXUNIT 128 -#define BONDNAME "bond" -#define M_BOND M_DEVBUF +#define BOND_ZONE_MAX_ELEM MIN(IFNETS_MAX, BOND_MAXUNIT) +#define BONDNAME "bond" + +#define M_BOND M_DEVBUF #define EA_FORMAT "%x:%x:%x:%x:%x:%x" #define EA_CH(e, i) ((u_char)((u_char *)(e))[(i)]) @@ -134,14 +139,14 @@ bond_lock_init(void) static __inline__ void bond_assert_lock_held(void) { - lck_mtx_assert(bond_lck_mtx, LCK_MTX_ASSERT_OWNED); + LCK_MTX_ASSERT(bond_lck_mtx, LCK_MTX_ASSERT_OWNED); return; } static __inline__ void bond_assert_lock_not_held(void) { - lck_mtx_assert(bond_lck_mtx, LCK_MTX_ASSERT_NOTOWNED); + LCK_MTX_ASSERT(bond_lck_mtx, LCK_MTX_ASSERT_NOTOWNED); return; } @@ -617,24 +622,26 @@ bondport_collecting(bondport_ref p) static int bond_clone_create(struct if_clone *, u_int32_t, void *); static int bond_clone_destroy(struct ifnet *); static int bond_input(ifnet_t ifp, protocol_family_t protocol, mbuf_t m, - char *frame_header); + char *frame_header); static int bond_output(struct ifnet *ifp, struct mbuf *m); static int bond_ioctl(struct ifnet *ifp, u_long cmd, void * addr); static int bond_set_bpf_tap(struct ifnet * ifp, bpf_tap_mode mode, - bpf_packet_func func); + bpf_packet_func func); static int bond_attach_protocol(struct ifnet *ifp); static int bond_detach_protocol(struct ifnet *ifp); static int bond_setmulti(struct ifnet *ifp); static int bond_add_interface(struct ifnet * ifp, struct ifnet * port_ifp); static int bond_remove_interface(ifbond_ref ifb, struct ifnet * port_ifp); static void bond_if_free(struct ifnet * ifp); +static void interface_link_event(struct ifnet * ifp, u_int32_t event_code); static struct if_clone bond_cloner = IF_CLONE_INITIALIZER(BONDNAME, - bond_clone_create, - bond_clone_destroy, - 0, - BOND_MAXUNIT); -static void interface_link_event(struct ifnet * ifp, u_int32_t event_code); + bond_clone_create, + bond_clone_destroy, + 0, + BOND_MAXUNIT, + BOND_ZONE_MAX_ELEM, + sizeof(ifbond)); static int siocsifmtu(struct ifnet * ifp, int mtu) @@ -699,7 +706,7 @@ ifbond_release(ifbond_ref ifb) if (ifb->ifb_distributing_array != NULL) { FREE(ifb->ifb_distributing_array, M_BOND); } - FREE(ifb, M_BOND); + if_clone_softc_deallocate(&bond_cloner, ifb); break; default: break; @@ -1092,7 +1099,7 @@ bond_clone_create(struct if_clone * ifc, u_int32_t unit, __unused void *params) return (error); } - ifb = _MALLOC(sizeof(ifbond), M_BOND, M_WAITOK | M_ZERO); + ifb = if_clone_softc_allocate(&bond_cloner); if (ifb == NULL) { return (ENOMEM); } @@ -1957,6 +1964,10 @@ bond_add_interface(struct ifnet * ifp, struct ifnet * port_ifp) bondport_ref p; int progress = 0; + if (IFNET_IS_INTCOPROC(port_ifp)) { + return (EINVAL); + } + /* pre-allocate space for new port */ p = bondport_create(port_ifp, 0x8000, 1, 0, &error); if (p == NULL) {