Lines Matching defs:ifp
149 struct ifnet *ifp;
324 static int dlil_event_internal(struct ifnet *ifp, struct kev_msg *msg);
551 #define DLIL_INPUT_CHECK(m, ifp) { \
553 if (_rcvif == NULL || (ifp != lo_ifp && _rcvif != ifp) || \
620 find_attached_proto(struct ifnet *ifp, u_int32_t protocol_family)
625 ifnet_lock_assert(ifp, IFNET_LCK_ASSERT_OWNED);
627 if (ifp->if_proto_hash != NULL)
628 proto = SLIST_FIRST(&ifp->if_proto_hash[i]);
645 extern void if_rtproto_del(struct ifnet *ifp, int protocol);
651 struct ifnet *ifp = proto->ifp;
664 proto->kpi.v1.detached(ifp, proto->protocol_family);
668 proto->kpi.v2.detached(ifp, proto->protocol_family);
675 if_rtproto_del(ifp, proto_family);
681 ifnet_lock_shared(ifp);
683 ev_pr_data.proto_remaining_count = dlil_ifp_proto_count(ifp);
684 ifnet_lock_done(ifp);
686 dlil_post_msg(ifp, KEV_DL_SUBCLASS, KEV_DL_PROTO_DETACHED,
694 ifnet_lock_assert(struct ifnet *ifp, ifnet_lock_assert_t what)
722 lck_rw_assert(&ifp->if_lock, type);
726 ifnet_lock_shared(struct ifnet *ifp)
728 lck_rw_lock_shared(&ifp->if_lock);
732 ifnet_lock_exclusive(struct ifnet *ifp)
734 lck_rw_lock_exclusive(&ifp->if_lock);
738 ifnet_lock_done(struct ifnet *ifp)
740 lck_rw_done(&ifp->if_lock);
765 dlil_ifp_proto_count(struct ifnet * ifp)
769 ifnet_lock_assert(ifp, IFNET_LCK_ASSERT_OWNED);
771 if (ifp->if_proto_hash == NULL)
776 SLIST_FOREACH(proto, &ifp->if_proto_hash[i], next_hash) {
785 dlil_post_msg(struct ifnet *ifp, u_int32_t event_subclass,
809 strncpy(&event_data->if_name[0], ifp->if_name, IFNAMSIZ);
810 event_data->if_family = ifp->if_family;
811 event_data->if_unit = (u_int32_t) ifp->if_unit;
817 dlil_event_internal(ifp, &ev_msg);
821 dlil_alloc_local_stats(struct ifnet *ifp)
826 if (ifp == NULL)
829 if (ifp->if_tcp_stat == NULL && ifp->if_udp_stat == NULL) {
850 ifp->if_tcp_stat = base;
872 ifp->if_udp_stat = base;
874 VERIFY(IS_P2ALIGNED(ifp->if_tcp_stat, sizeof (u_int64_t)) &&
875 IS_P2ALIGNED(ifp->if_udp_stat, sizeof (u_int64_t)));
882 if (ifp->if_tcp_stat != NULL) {
884 ((intptr_t)ifp->if_tcp_stat - sizeof (void *));
886 ifp->if_tcp_stat = NULL;
888 if (ifp->if_udp_stat != NULL) {
890 ((intptr_t)ifp->if_udp_stat - sizeof (void *));
892 ifp->if_udp_stat = NULL;
900 dlil_create_input_thread(ifnet_t ifp, struct dlil_threading_info *inp)
906 /* NULL ifp indicates the main input thread, called at dlil_init time */
907 if (ifp == NULL) {
912 } else if (net_rxpoll && (ifp->if_eflags & IFEF_RXPOLL)) {
916 "%s%d_input_poll", ifp->if_name, ifp->if_unit);
921 "%s%d_input", ifp->if_name, ifp->if_unit);
929 inp->ifp = ifp; /* NULL for main input thread */
943 if (ifp != NULL && net_rxpoll && (ifp->if_eflags & IFEF_RXPOLL)) {
985 ifp->if_name, ifp->if_unit);
996 struct ifnet *ifp;
1009 ifp = inp->ifp;
1010 inp->ifp = NULL;
1038 ifp->if_name, ifp->if_unit);
1266 if_flt_monitor_busy(struct ifnet *ifp)
1268 lck_mtx_assert(&ifp->if_flt_lock, LCK_MTX_ASSERT_OWNED);
1270 ++ifp->if_flt_busy;
1271 VERIFY(ifp->if_flt_busy != 0);
1275 if_flt_monitor_unbusy(struct ifnet *ifp)
1277 if_flt_monitor_leave(ifp);
1281 if_flt_monitor_enter(struct ifnet *ifp)
1283 lck_mtx_assert(&ifp->if_flt_lock, LCK_MTX_ASSERT_OWNED);
1285 while (ifp->if_flt_busy) {
1286 ++ifp->if_flt_waiters;
1287 (void) msleep(&ifp->if_flt_head, &ifp->if_flt_lock,
1290 if_flt_monitor_busy(ifp);
1294 if_flt_monitor_leave(struct ifnet *ifp)
1296 lck_mtx_assert(&ifp->if_flt_lock, LCK_MTX_ASSERT_OWNED);
1298 VERIFY(ifp->if_flt_busy != 0);
1299 --ifp->if_flt_busy;
1301 if (ifp->if_flt_busy == 0 && ifp->if_flt_waiters > 0) {
1302 ifp->if_flt_waiters = 0;
1303 wakeup(&ifp->if_flt_head);
1308 dlil_attach_filter(struct ifnet *ifp, const struct iff_filter *if_filter,
1316 if (!ifnet_lookup(ifp)) {
1329 filter->filt_ifp = ifp;
1339 lck_mtx_lock(&ifp->if_flt_lock);
1340 if_flt_monitor_enter(ifp);
1342 lck_mtx_assert(&ifp->if_flt_lock, LCK_MTX_ASSERT_OWNED);
1343 TAILQ_INSERT_TAIL(&ifp->if_flt_head, filter, filt_next);
1345 if_flt_monitor_leave(ifp);
1346 lck_mtx_unlock(&ifp->if_flt_lock);
1359 printf("%s%d: %s filter attached\n", ifp->if_name,
1360 ifp->if_unit, if_filter->iff_name);
1364 if (retval != 0 && ifp != NULL) {
1366 ifp->if_name, ifp->if_unit, if_filter->iff_name, retval);
1380 ifnet_t ifp = NULL;
1383 TAILQ_FOREACH(ifp, &ifnet_head, if_link) {
1386 lck_mtx_lock(&ifp->if_flt_lock);
1387 TAILQ_FOREACH(entry, &ifp->if_flt_head, filt_next) {
1398 lck_mtx_unlock(&ifp->if_flt_lock);
1401 lck_mtx_lock(&ifp->if_flt_lock);
1402 if_flt_monitor_enter(ifp);
1403 lck_mtx_assert(&ifp->if_flt_lock,
1407 TAILQ_REMOVE(&ifp->if_flt_head, filter,
1410 if_flt_monitor_leave(ifp);
1411 lck_mtx_unlock(&ifp->if_flt_lock);
1414 ifp->if_name, ifp->if_unit,
1419 lck_mtx_unlock(&ifp->if_flt_lock);
1482 VERIFY(inp->ifp == NULL);
1549 struct ifnet *ifp = inp->ifp;
1552 VERIFY(ifp != NULL);
1553 VERIFY(!(ifp->if_eflags & IFEF_RXPOLL) || !net_rxpoll);
1600 dlil_input_stats_sync(ifp, inp);
1626 struct ifnet *ifp = inp->ifp;
1630 VERIFY(ifp != NULL && (ifp->if_eflags & IFEF_RXPOLL));
1641 if (ifp->if_poll_update != 0) {
1642 ifp->if_poll_update = 0;
1742 "limits [%d/%d]\n", ifp->if_name,
1743 ifp->if_unit, (inp->mode ==
1785 dlil_input_stats_sync(ifp, inp);
1795 if (poll_req != 0 && ifnet_is_attached(ifp, 1)) {
1804 ifp->if_name, ifp->if_unit,
1814 if ((err = ((*ifp->if_input_ctl)(ifp,
1817 "to %s (%d)\n", ifp->if_name, ifp->if_unit,
1824 ifnet_set_poll_cycle(ifp, NULL);
1832 ifnet_set_poll_cycle(ifp, &ts);
1833 ifnet_poll(ifp);
1845 ifnet_decr_iorefcnt(ifp);
1864 struct ifnet *ifp = inp->ifp;
1868 VERIFY(ifp != NULL && (ifp->if_eflags & IFEF_RXPOLL));
1870 if ((inbw = ifnet_input_linkrate(ifp)) == 0) {
1900 "bytes limits [%d/%d]\n", ifp->if_name, ifp->if_unit,
1908 ifnet_input(struct ifnet *ifp, struct mbuf *m_head,
1911 return (ifnet_input_common(ifp, m_head, NULL, s, FALSE, FALSE));
1915 ifnet_input_extended(struct ifnet *ifp, struct mbuf *m_head,
1918 return (ifnet_input_common(ifp, m_head, m_tail, s, TRUE, FALSE));
1922 ifnet_input_common(struct ifnet *ifp, struct mbuf *m_head, struct mbuf *m_tail,
1935 if (ifp == NULL || m_head == NULL || (s == NULL && ext) ||
1936 (ifp != lo_ifp && !ifnet_is_attached(ifp, 1))) {
1950 DLIL_INPUT_CHECK(last, ifp);
1964 DLIL_INPUT_CHECK(last, ifp);
1985 "tail mbuf %p instead of %p\n", __func__, ifp->if_name,
1986 ifp->if_unit, m_tail, last);
1998 "%d instead of %d\n", __func__, ifp->if_name,
1999 ifp->if_unit, s->packets_in, m_cnt);
2002 if ((inp = ifp->if_inp) == NULL)
2038 * Because of loopbacked multicast we cannot stuff the ifp in
2044 if (inp == dlil_main_input_thread && ifp == lo_ifp) {
2062 "(expected %d)\n", ifp->if_name, ifp->if_unit,
2080 dlil_input_stats_sync(ifp, inp);
2090 if (ifp != lo_ifp) {
2092 ifnet_decr_iorefcnt(ifp);
2099 ifnet_start(struct ifnet *ifp)
2104 lck_mtx_lock_spin(&ifp->if_start_lock);
2105 ifp->if_start_req++;
2106 if (!ifp->if_start_active && ifp->if_start_thread != THREAD_NULL) {
2107 wakeup_one((caddr_t)&ifp->if_start_thread);
2109 lck_mtx_unlock(&ifp->if_start_lock);
2116 struct ifnet *ifp = v;
2119 struct ifclassq *ifq = &ifp->if_snd;
2128 if (ifp == lo_ifp) {
2149 ifp->if_name, ifp->if_unit);
2151 lck_mtx_lock_spin(&ifp->if_start_lock);
2154 (void) msleep(&ifp->if_start_thread, &ifp->if_start_lock,
2158 if (ifp->if_start_thread == THREAD_NULL) {
2159 ifnet_set_start_cycle(ifp, NULL);
2160 lck_mtx_unlock(&ifp->if_start_lock);
2161 ifnet_purge(ifp);
2165 ifp->if_name, ifp->if_unit);
2176 ifp->if_start_active = 1;
2178 u_int32_t req = ifp->if_start_req;
2180 lck_mtx_unlock(&ifp->if_start_lock);
2182 ((*ifp->if_start)(ifp));
2183 lck_mtx_lock_spin(&ifp->if_start_lock);
2186 if (req == ifp->if_start_req)
2189 ifp->if_start_req = 0;
2190 ifp->if_start_active = 0;
2198 &ifp->if_start_cycle : NULL);
2205 lck_mtx_unlock(&ifp->if_start_lock);
2210 ifnet_set_start_cycle(struct ifnet *ifp, struct timespec *ts)
2213 bzero(&ifp->if_start_cycle, sizeof (ifp->if_start_cycle));
2215 *(&ifp->if_start_cycle) = *ts;
2219 ifp->if_name, ifp->if_unit, ts->tv_nsec);
2223 ifnet_poll(struct ifnet *ifp)
2228 lck_mtx_lock_spin(&ifp->if_poll_lock);
2229 ifp->if_poll_req++;
2230 if (!ifp->if_poll_active && ifp->if_poll_thread != THREAD_NULL) {
2231 wakeup_one((caddr_t)&ifp->if_poll_thread);
2233 lck_mtx_unlock(&ifp->if_poll_lock);
2241 struct ifnet *ifp = v;
2247 ifp->if_name, ifp->if_unit);
2250 lck_mtx_lock_spin(&ifp->if_poll_lock);
2252 inp = ifp->if_inp;
2256 if (ifp->if_poll_thread != THREAD_NULL) {
2257 (void) msleep(&ifp->if_poll_thread, &ifp->if_poll_lock,
2262 if (ifp->if_poll_thread == THREAD_NULL) {
2263 ifnet_set_poll_cycle(ifp, NULL);
2264 lck_mtx_unlock(&ifp->if_poll_lock);
2268 ifp->if_name, ifp->if_unit);
2279 ifp->if_poll_active = 1;
2283 u_int16_t req = ifp->if_poll_req;
2285 lck_mtx_unlock(&ifp->if_poll_lock);
2292 if (!ifnet_is_attached(ifp, 1)) {
2293 lck_mtx_lock_spin(&ifp->if_poll_lock);
2305 ifp->if_name, ifp->if_unit, m_lim,
2311 ((*ifp->if_input_poll)(ifp, 0, m_lim, &m_head, &m_tail,
2321 ifp->if_name, ifp->if_unit, m_cnt,
2330 (void) ifnet_input_common(ifp, m_head, m_tail,
2334 "wreq avg %d, bytes avg %d\n", ifp->if_name,
2335 ifp->if_unit, inp->rxpoll_pavg,
2341 ifnet_decr_iorefcnt(ifp);
2343 lck_mtx_lock_spin(&ifp->if_poll_lock);
2346 if (req == ifp->if_poll_req)
2349 ifp->if_poll_req = 0;
2350 ifp->if_poll_active = 0;
2356 ts = &ifp->if_poll_cycle;
2362 lck_mtx_unlock(&ifp->if_poll_lock);
2367 ifnet_set_poll_cycle(struct ifnet *ifp, struct timespec *ts)
2370 bzero(&ifp->if_poll_cycle, sizeof (ifp->if_poll_cycle));
2372 *(&ifp->if_poll_cycle) = *ts;
2376 ifp->if_name, ifp->if_unit, ts->tv_nsec);
2380 ifnet_purge(struct ifnet *ifp)
2382 if (ifp != NULL && (ifp->if_eflags & IFEF_TXSTART))
2383 if_qflush(ifp, 0);
2404 ifnet_update_rcv(struct ifnet *ifp, cqev_t ev)
2408 if (net_rxpoll && (ifp->if_eflags & IFEF_RXPOLL))
2409 ifp->if_poll_update++;
2418 ifnet_set_output_sched_model(struct ifnet *ifp, u_int32_t model)
2424 if (ifp == NULL || (model != IFNET_SCHED_MODEL_DRIVER_MANAGED &&
2427 else if (!(ifp->if_eflags & IFEF_TXSTART))
2430 ifq = &ifp->if_snd;
2432 omodel = ifp->if_output_sched_model;
2433 ifp->if_output_sched_model = model;
2435 ifp->if_output_sched_model = omodel;
2442 ifnet_set_sndq_maxlen(struct ifnet *ifp, u_int32_t maxqlen)
2444 if (ifp == NULL)
2446 else if (!(ifp->if_eflags & IFEF_TXSTART))
2449 ifclassq_set_maxlen(&ifp->if_snd, maxqlen);
2455 ifnet_get_sndq_maxlen(struct ifnet *ifp, u_int32_t *maxqlen)
2457 if (ifp == NULL || maxqlen == NULL)
2459 else if (!(ifp->if_eflags & IFEF_TXSTART))
2462 *maxqlen = ifclassq_get_maxlen(&ifp->if_snd);
2468 ifnet_get_sndq_len(struct ifnet *ifp, u_int32_t *qlen)
2470 if (ifp == NULL || qlen == NULL)
2472 else if (!(ifp->if_eflags & IFEF_TXSTART))
2475 *qlen = ifclassq_get_len(&ifp->if_snd);
2481 ifnet_set_rcvq_maxlen(struct ifnet *ifp, u_int32_t maxqlen)
2485 if (ifp == NULL)
2487 else if (!(ifp->if_eflags & IFEF_RXPOLL) || ifp->if_inp == NULL)
2495 inp = ifp->if_inp;
2504 ifnet_get_rcvq_maxlen(struct ifnet *ifp, u_int32_t *maxqlen)
2508 if (ifp == NULL || maxqlen == NULL)
2510 else if (!(ifp->if_eflags & IFEF_RXPOLL) || ifp->if_inp == NULL)
2513 inp = ifp->if_inp;
2521 ifnet_enqueue(struct ifnet *ifp, struct mbuf *m)
2525 if (ifp == NULL || m == NULL || !(m->m_flags & M_PKTHDR) ||
2530 } else if (!(ifp->if_eflags & IFEF_TXSTART) ||
2531 !(ifp->if_refflags & IFRF_ATTACHED)) {
2535 } else if (!(ifp->if_flags & IFF_UP)) {
2542 error = ifclassq_enqueue(&ifp->if_snd, m);
2550 ifnet_start(ifp);
2556 ifnet_dequeue(struct ifnet *ifp, struct mbuf **mp)
2558 if (ifp == NULL || mp == NULL)
2560 else if (!(ifp->if_eflags & IFEF_TXSTART) ||
2561 (ifp->if_output_sched_model != IFNET_SCHED_MODEL_NORMAL))
2564 return (ifclassq_dequeue(&ifp->if_snd, 1, mp, NULL, NULL, NULL));
2568 ifnet_dequeue_service_class(struct ifnet *ifp, mbuf_svc_class_t sc,
2571 if (ifp == NULL || mp == NULL || !MBUF_VALID_SC(sc))
2573 else if (!(ifp->if_eflags & IFEF_TXSTART) ||
2574 (ifp->if_output_sched_model != IFNET_SCHED_MODEL_DRIVER_MANAGED))
2577 return (ifclassq_dequeue_sc(&ifp->if_snd, sc, 1, mp, NULL, NULL, NULL));
2581 ifnet_dequeue_multi(struct ifnet *ifp, u_int32_t limit, struct mbuf **head,
2584 if (ifp == NULL || head == NULL || limit < 1)
2586 else if (!(ifp->if_eflags & IFEF_TXSTART) ||
2587 (ifp->if_output_sched_model != IFNET_SCHED_MODEL_NORMAL))
2590 return (ifclassq_dequeue(&ifp->if_snd, limit, head, tail, cnt, len));
2594 ifnet_dequeue_service_class_multi(struct ifnet *ifp, mbuf_svc_class_t sc,
2599 if (ifp == NULL || head == NULL || limit < 1 || !MBUF_VALID_SC(sc))
2601 else if (!(ifp->if_eflags & IFEF_TXSTART) ||
2602 (ifp->if_output_sched_model != IFNET_SCHED_MODEL_DRIVER_MANAGED))
2605 return (ifclassq_dequeue_sc(&ifp->if_snd, sc, limit, head,
2610 dlil_interface_filters_input(struct ifnet *ifp, struct mbuf **m_p,
2618 lck_mtx_lock_spin(&ifp->if_flt_lock);
2620 if_flt_monitor_busy(ifp);
2621 TAILQ_FOREACH(filter, &ifp->if_flt_head, filt_next) {
2627 lck_mtx_unlock(&ifp->if_flt_lock);
2630 ifp, protocol_family, m_p, frame_header_p);
2632 lck_mtx_lock_spin(&ifp->if_flt_lock);
2635 if_flt_monitor_unbusy(ifp);
2636 lck_mtx_unlock(&ifp->if_flt_lock);
2642 if_flt_monitor_unbusy(ifp);
2643 lck_mtx_unlock(&ifp->if_flt_lock);
2656 dlil_interface_filters_output(struct ifnet *ifp, struct mbuf **m_p,
2664 lck_mtx_lock_spin(&ifp->if_flt_lock);
2666 if_flt_monitor_busy(ifp);
2667 TAILQ_FOREACH(filter, &ifp->if_flt_head, filt_next) {
2673 lck_mtx_unlock(&ifp->if_flt_lock);
2675 result = filter->filt_output(filter->filt_cookie, ifp,
2678 lck_mtx_lock_spin(&ifp->if_flt_lock);
2681 if_flt_monitor_unbusy(ifp);
2682 lck_mtx_unlock(&ifp->if_flt_lock);
2688 if_flt_monitor_unbusy(ifp);
2689 lck_mtx_unlock(&ifp->if_flt_lock);
2709 error = (*ifproto->kpi.v1.input)(ifproto->ifp,
2717 error = (*ifproto->kpi.v2.input)(ifproto->ifp,
2755 dlil_input_stats_sync(struct ifnet *ifp, struct dlil_threading_info *inp)
2764 atomic_add_64(&ifp->if_data.ifi_ipackets, s->packets_in);
2768 atomic_add_64(&ifp->if_data.ifi_ibytes, s->bytes_in);
2772 atomic_add_64(&ifp->if_data.ifi_ierrors, s->errors_in);
2777 atomic_add_64(&ifp->if_data.ifi_opackets, s->packets_out);
2781 atomic_add_64(&ifp->if_data.ifi_obytes, s->bytes_out);
2785 atomic_add_64(&ifp->if_data.ifi_oerrors, s->errors_out);
2790 atomic_add_64(&ifp->if_data.ifi_collisions, s->collisions);
2794 atomic_add_64(&ifp->if_data.ifi_iqdrops, s->dropped);
2813 dlil_input_packet_list(struct ifnet *ifp, struct mbuf *m)
2815 return (dlil_input_packet_list_common(ifp, m, 0,
2820 dlil_input_packet_list_extended(struct ifnet *ifp, struct mbuf *m,
2823 return (dlil_input_packet_list_common(ifp, m, cnt, mode, TRUE));
2833 ifnet_t ifp = ifp_param;
2851 ifp = m->m_pkthdr.rcvif;
2853 if ((ifp->if_eflags & IFEF_RXPOLL) && poll_thresh != 0 &&
2855 ifnet_poll(ifp);
2858 MBUF_INPUT_CHECK(m, ifp);
2870 if (ifp != lo_ifp) {
2871 if (!ifnet_is_attached(ifp, 1)) {
2878 ifp_inc_traffic_class_in(ifp, m);
2881 ifnet_lock_shared(ifp);
2882 error = (*ifp->if_demux)(ifp, m, frame_header,
2884 ifnet_lock_done(ifp);
2892 iptap_ipf_input(ifp, protocol_family, m, frame_header);
2896 atomic_add_64(&ifp->if_imcasts, 1);
2900 error = dlil_interface_filters_input(ifp, &m,
2916 } else if (last_ifproto != NULL && last_ifproto->ifp == ifp &&
2923 ifnet_lock_shared(ifp);
2925 ifproto = find_attached_proto(ifp, protocol_family);
2926 ifnet_lock_done(ifp);
2967 if (ifp->if_updatemcasts > 0 && if_mcasts_update(ifp) == 0)
2968 ifp->if_updatemcasts = 0;
2970 ifnet_decr_iorefcnt(ifp);
2977 if_mcasts_update(struct ifnet *ifp)
2981 err = ifnet_ioctl(ifp, 0, SIOCADDMULTI, NULL);
2985 "(err=%d)\n", ifp->if_name, ifp->if_unit,
2987 ifp->if_updatemcasts, err);
2994 dlil_event_internal(struct ifnet *ifp, struct kev_msg *event)
2999 if (!ifnet_is_attached(ifp, 1))
3005 lck_mtx_lock_spin(&ifp->if_flt_lock);
3007 if_flt_monitor_busy(ifp);
3008 TAILQ_FOREACH(filter, &ifp->if_flt_head, filt_next) {
3010 lck_mtx_unlock(&ifp->if_flt_lock);
3012 filter->filt_event(filter->filt_cookie, ifp,
3015 lck_mtx_lock_spin(&ifp->if_flt_lock);
3019 if_flt_monitor_unbusy(ifp);
3020 lck_mtx_unlock(&ifp->if_flt_lock);
3022 ifnet_lock_shared(ifp);
3023 if (ifp->if_proto_hash != NULL) {
3029 SLIST_FOREACH(proto, &ifp->if_proto_hash[i],
3038 ifnet_lock_done(ifp);
3040 eventp(ifp, proto->protocol_family,
3043 ifnet_lock_shared(ifp);
3049 ifnet_lock_done(ifp);
3052 if (ifp->if_event != NULL)
3053 ifp->if_event(ifp, event);
3056 ifnet_decr_iorefcnt(ifp);
3063 ifnet_event(ifnet_t ifp, struct kern_event_msg *event)
3068 if (ifp == NULL || event == NULL)
3080 result = dlil_event_internal(ifp, &kev_msg);
3132 ifp_inc_traffic_class_in(struct ifnet *ifp, struct mbuf *m)
3139 ifp->if_tc.ifi_ibepackets++;
3140 ifp->if_tc.ifi_ibebytes += m->m_pkthdr.len;
3143 ifp->if_tc.ifi_ibkpackets++;
3144 ifp->if_tc.ifi_ibkbytes += m->m_pkthdr.len;
3147 ifp->if_tc.ifi_ivipackets++;
3148 ifp->if_tc.ifi_ivibytes += m->m_pkthdr.len;
3151 ifp->if_tc.ifi_ivopackets++;
3152 ifp->if_tc.ifi_ivobytes += m->m_pkthdr.len;
3159 ifp->if_tc.ifi_ipvpackets++;
3160 ifp->if_tc.ifi_ipvbytes += m->m_pkthdr.len;
3170 ifp_inc_traffic_class_out(struct ifnet *ifp, struct mbuf *m)
3177 ifp->if_tc.ifi_obepackets++;
3178 ifp->if_tc.ifi_obebytes += m->m_pkthdr.len;
3181 ifp->if_tc.ifi_obkpackets++;
3182 ifp->if_tc.ifi_obkbytes += m->m_pkthdr.len;
3185 ifp->if_tc.ifi_ovipackets++;
3186 ifp->if_tc.ifi_ovibytes += m->m_pkthdr.len;
3189 ifp->if_tc.ifi_ovopackets++;
3190 ifp->if_tc.ifi_ovobytes += m->m_pkthdr.len;
3197 ifp->if_tc.ifi_opvpackets++;
3198 ifp->if_tc.ifi_opvbytes += m->m_pkthdr.len;
3212 * because a protocol is likely to interact with an ifp while it
3220 dlil_output(ifnet_t ifp, protocol_family_t proto_family, mbuf_t packetlist,
3241 if (!ifnet_is_attached(ifp, 1)) {
3248 if (ifp->if_updatemcasts > 0 && if_mcasts_update(ifp) == 0)
3249 ifp->if_updatemcasts = 0;
3255 ifnet_lock_shared(ifp);
3257 proto = find_attached_proto(ifp, proto_family);
3259 ifnet_lock_done(ifp);
3263 ifnet_lock_done(ifp);
3279 retval = preoutp(ifp, proto_family, &m, dest, route,
3292 retval = mac_ifnet_check_transmit(ifp, m, proto_family,
3305 struct ip *, ip, struct ifnet *, ifp,
3311 struct ip6_hdr *, ip6, struct ifnet*, ifp,
3316 if (raw == 0 && ifp->if_framer) {
3321 * looped back into the system, set the inbound ifp
3322 * to that of the outbound ifp. This will allow
3324 * for the system. Only set the ifp if it's not
3329 m->m_pkthdr.rcvif = ifp;
3333 retval = ifp->if_framer(ifp, &m, dest, dst_linkaddr,
3347 * Clear the ifp if it was set above, and to be
3349 * outbound ifp we have in context. If it was
3355 if (rcvif_set && m->m_pkthdr.rcvif == ifp)
3364 retval = dlil_interface_filters_output(ifp,
3386 if (!(ifp->if_hwassist & IFNET_MULTIPAGES)) {
3397 !(ifp->if_hwassist & IFNET_TSO_IPV4)) {
3404 !(ifp->if_hwassist & IFNET_TSO_IPV6)) {
3413 if ((ifp->if_eflags & IFEF_SENDLIST) != 0) {
3418 iptap_ipf_output(ifp, proto_family, (struct mbuf *)m,
3421 ifp_inc_traffic_class_out(ifp, m);
3424 retval = (*ifp->if_output)(ifp, m);
3435 __func__, ifp->if_name, ifp->if_unit,
3453 iptap_ipf_output(ifp, proto_family, (struct mbuf *)send_head,
3456 ifp_inc_traffic_class_out(ifp, send_head);
3459 retval = (*ifp->if_output)(ifp, send_head);
3469 __func__, ifp->if_name, ifp->if_unit, retval);
3484 ifnet_decr_iorefcnt(ifp);
3490 ifnet_ioctl(ifnet_t ifp, protocol_family_t proto_fam, u_long ioctl_code,
3497 if (ifp == NULL || ioctl_code == 0)
3501 if (!ifnet_is_attached(ifp, 1))
3508 lck_mtx_lock_spin(&ifp->if_flt_lock);
3510 if_flt_monitor_busy(ifp);
3511 TAILQ_FOREACH(filter, &ifp->if_flt_head, filt_next) {
3514 lck_mtx_unlock(&ifp->if_flt_lock);
3516 result = filter->filt_ioctl(filter->filt_cookie, ifp,
3519 lck_mtx_lock_spin(&ifp->if_flt_lock);
3528 if_flt_monitor_unbusy(ifp);
3529 lck_mtx_unlock(&ifp->if_flt_lock);
3536 if_flt_monitor_unbusy(ifp);
3537 lck_mtx_unlock(&ifp->if_flt_lock);
3544 ifnet_lock_shared(ifp);
3545 proto = find_attached_proto(ifp, proto_fam);
3546 ifnet_lock_done(ifp);
3553 result = ioctlp(ifp, proto_fam, ioctl_code,
3575 if (ifp->if_ioctl)
3576 result = (*ifp->if_ioctl)(ifp, ioctl_code, ioctl_arg);
3592 ifnet_decr_iorefcnt(ifp);
3598 dlil_set_bpf_tap(ifnet_t ifp, bpf_tap_mode mode, bpf_packet_func callback)
3603 if (ifp->if_set_bpf_tap) {
3605 if (!ifnet_is_attached(ifp, 1))
3607 error = ifp->if_set_bpf_tap(ifp, mode, callback);
3608 ifnet_decr_iorefcnt(ifp);
3614 dlil_resolve_multi(struct ifnet *ifp, const struct sockaddr *proto_addr,
3622 if (!ifnet_is_attached(ifp, 1))
3628 ifnet_lock_shared(ifp);
3629 proto = find_attached_proto(ifp, proto_addr->sa_family);
3630 ifnet_lock_done(ifp);
3635 result = resolvep(ifp, proto_addr,
3641 if ((result == EOPNOTSUPP || result == 0) && ifp->if_check_multi) {
3646 result = ifp->if_check_multi(ifp, verify);
3649 ifnet_decr_iorefcnt(ifp);
3654 dlil_send_arp_internal(ifnet_t ifp, u_short arpop,
3662 ifnet_lock_shared(ifp);
3663 proto = find_attached_proto(ifp, target_proto->sa_family);
3664 ifnet_lock_done(ifp);
3674 result = arpp(ifp, arpop, sender_hw, sender_proto,
3718 dlil_send_arp(ifnet_t ifp, u_short arpop, const struct sockaddr_dl* sender_hw,
3820 result = dlil_send_arp_internal(ifp, arpop, sender_hw,
3831 ifnet_lookup(struct ifnet *ifp)
3837 if (_ifp == ifp)
3848 ifnet_is_attached(struct ifnet *ifp, int refio)
3852 lck_mtx_lock_spin(&ifp->if_ref_lock);
3853 if ((ret = ((ifp->if_refflags & (IFRF_ATTACHED | IFRF_DETACHING)) ==
3856 ifp->if_refio++;
3858 lck_mtx_unlock(&ifp->if_ref_lock);
3864 ifnet_decr_iorefcnt(struct ifnet *ifp)
3866 lck_mtx_lock_spin(&ifp->if_ref_lock);
3867 VERIFY(ifp->if_refio > 0);
3868 VERIFY((ifp->if_refflags & (IFRF_ATTACHED | IFRF_DETACHING)) != 0);
3869 ifp->if_refio--;
3874 if (ifp->if_refio == 0 &&
3875 (ifp->if_refflags & IFRF_DETACHING) != 0) {
3876 wakeup(&(ifp->if_refio));
3878 lck_mtx_unlock(&ifp->if_ref_lock);
3907 dlil_if_ref(struct ifnet *ifp)
3909 struct dlil_ifnet *dl_if = (struct dlil_ifnet *)ifp;
3917 panic("%s: wraparound refcnt for ifp=%p", __func__, ifp);
3928 dlil_if_free(struct ifnet *ifp)
3930 struct dlil_ifnet *dl_if = (struct dlil_ifnet *)ifp;
3937 panic("%s: negative refcnt for ifp=%p", __func__, ifp);
3953 struct ifnet *ifp = proto->ifp;
3960 ifnet_lock_exclusive(ifp);
3961 _proto = find_attached_proto(ifp, proto->protocol_family);
3963 ifnet_lock_done(ifp);
3972 retval = ifp->if_add_proto(ifp, proto->protocol_family, demux_list,
3975 ifnet_lock_done(ifp);
3982 prev_proto = SLIST_FIRST(&ifp->if_proto_hash[hash_value]);
3988 SLIST_INSERT_HEAD(&ifp->if_proto_hash[hash_value],
3999 ev_pr_data.proto_remaining_count = dlil_ifp_proto_count(ifp);
4000 ifnet_lock_done(ifp);
4002 dlil_post_msg(ifp, KEV_DL_SUBCLASS, KEV_DL_PROTO_ATTACHED,
4009 ifnet_attach_protocol(ifnet_t ifp, protocol_family_t protocol,
4016 if (ifp == NULL || protocol == 0 || proto_details == NULL) {
4021 if (!ifnet_lookup(ifp)) {
4034 ifproto->ifp = ifp;
4049 printf("%s%d: attached v1 protocol %d\n", ifp->if_name,
4050 ifp->if_unit, protocol);
4054 if (retval != 0 && retval != EEXIST && ifp != NULL) {
4056 ifp->if_name, ifp->if_unit, protocol, retval);
4065 ifnet_attach_protocol_v2(ifnet_t ifp, protocol_family_t protocol,
4072 if (ifp == NULL || protocol == 0 || proto_details == NULL) {
4077 if (!ifnet_lookup(ifp)) {
4090 ifproto->ifp = ifp;
4105 printf("%s%d: attached v2 protocol %d\n", ifp->if_name,
4106 ifp->if_unit, protocol);
4110 if (retval != 0 && retval != EEXIST && ifp != NULL) {
4112 ifp->if_name, ifp->if_unit, protocol, retval);
4121 ifnet_detach_protocol(ifnet_t ifp, protocol_family_t proto_family)
4126 if (ifp == NULL || proto_family == 0) {
4131 ifnet_lock_exclusive(ifp);
4133 proto = find_attached_proto(ifp, proto_family);
4136 ifnet_lock_done(ifp);
4141 if (ifp->if_del_proto)
4142 ifp->if_del_proto(ifp, proto->protocol_family);
4144 SLIST_REMOVE(&ifp->if_proto_hash[proto_hash_value(proto_family)],
4163 ifnet_lock_done(ifp);
4166 printf("%s%d: detached %s protocol %d\n", ifp->if_name,
4167 ifp->if_unit, (proto->proto_kpi == kProtoKPI_v1) ?
4187 ifproto_media_input_v1(struct ifnet *ifp, protocol_family_t protocol,
4190 #pragma unused(ifp, protocol, packet, header)
4195 ifproto_media_input_v2(struct ifnet *ifp, protocol_family_t protocol,
4198 #pragma unused(ifp, protocol, packet)
4204 ifproto_media_preout(struct ifnet *ifp, protocol_family_t protocol,
4208 #pragma unused(ifp, protocol, packet, dest, route, frame_type, link_layer_dest)
4214 ifproto_media_event(struct ifnet *ifp, protocol_family_t protocol,
4217 #pragma unused(ifp, protocol, event)
4221 ifproto_media_ioctl(struct ifnet *ifp, protocol_family_t protocol,
4224 #pragma unused(ifp, protocol, command, argument)
4229 ifproto_media_resolve_multi(ifnet_t ifp, const struct sockaddr *proto_addr,
4232 #pragma unused(ifp, proto_addr, out_ll, ll_len)
4237 ifproto_media_send_arp(struct ifnet *ifp, u_short arpop,
4241 #pragma unused(ifp, arpop, sender_hw, sender_proto, target_hw, target_proto)
4248 ifnet_attach(ifnet_t ifp, const struct sockaddr_dl *ll_addr)
4253 struct dlil_ifnet *dl_if = (struct dlil_ifnet *)ifp;
4258 if (ifp == NULL)
4271 if (tmp_if == ifp) {
4278 lck_mtx_lock_spin(&ifp->if_ref_lock);
4279 if (ifp->if_refflags & IFRF_ATTACHED) {
4280 panic_plain("%s: flags mismatch (attached set) ifp=%p",
4281 __func__, ifp);
4284 lck_mtx_unlock(&ifp->if_ref_lock);
4286 ifnet_lock_exclusive(ifp);
4289 VERIFY(ifp->if_detaching_link.tqe_next == NULL);
4290 VERIFY(ifp->if_detaching_link.tqe_prev == NULL);
4293 if (ifp->if_addrlen == 0) {
4294 ifp->if_addrlen = ll_addr->sdl_alen;
4295 } else if (ll_addr->sdl_alen != ifp->if_addrlen) {
4296 ifnet_lock_done(ifp);
4307 if (ifp->if_add_proto == NULL || ifp->if_del_proto == NULL) {
4309 "family module - %d\n", __func__, ifp->if_family);
4310 ifnet_lock_done(ifp);
4317 VERIFY(ifp->if_proto_hash == NULL);
4318 ifp->if_proto_hash = zalloc(dlif_phash_zone);
4319 if (ifp->if_proto_hash == NULL) {
4320 ifnet_lock_done(ifp);
4325 bzero(ifp->if_proto_hash, dlif_phash_size);
4327 lck_mtx_lock_spin(&ifp->if_flt_lock);
4328 VERIFY(TAILQ_EMPTY(&ifp->if_flt_head));
4329 TAILQ_INIT(&ifp->if_flt_head);
4330 VERIFY(ifp->if_flt_busy == 0);
4331 VERIFY(ifp->if_flt_waiters == 0);
4332 lck_mtx_unlock(&ifp->if_flt_lock);
4334 VERIFY(TAILQ_EMPTY(&ifp->if_prefixhead));
4335 TAILQ_INIT(&ifp->if_prefixhead);
4338 VERIFY(LIST_EMPTY(&ifp->if_multiaddrs));
4339 LIST_INIT(&ifp->if_multiaddrs);
4342 VERIFY(ifp->if_allhostsinm == NULL);
4343 VERIFY(TAILQ_EMPTY(&ifp->if_addrhead));
4344 TAILQ_INIT(&ifp->if_addrhead);
4346 if (ifp->if_index == 0) {
4350 ifp->if_index = 0;
4351 ifnet_lock_done(ifp);
4356 ifp->if_index = idx;
4359 VERIFY(ifindex2ifnet[ifp->if_index] == NULL);
4362 VERIFY(!(dl_if->dl_if_flags & DLIF_REUSE) || ifp->if_lladdr != NULL);
4363 ifa = dlil_alloc_lladdr(ifp, ll_addr);
4365 ifnet_lock_done(ifp);
4371 VERIFY(ifnet_addrs[ifp->if_index - 1] == NULL);
4372 ifnet_addrs[ifp->if_index - 1] = ifa;
4379 if_attach_link_ifa(ifp, ifa);
4383 mac_ifnet_label_associate(ifp);
4386 TAILQ_INSERT_TAIL(&ifnet_head, ifp, if_link);
4387 ifindex2ifnet[ifp->if_index] = ifp;
4390 ifnet_reference(ifp);
4393 if_data_saved = ifp->if_data;
4394 bzero(&ifp->if_data, sizeof (ifp->if_data));
4395 ifp->if_data.ifi_type = if_data_saved.ifi_type;
4396 ifp->if_data.ifi_typelen = if_data_saved.ifi_typelen;
4397 ifp->if_data.ifi_physical = if_data_saved.ifi_physical;
4398 ifp->if_data.ifi_addrlen = if_data_saved.ifi_addrlen;
4399 ifp->if_data.ifi_hdrlen = if_data_saved.ifi_hdrlen;
4400 ifp->if_data.ifi_mtu = if_data_saved.ifi_mtu;
4401 ifp->if_data.ifi_baudrate = if_data_saved.ifi_baudrate;
4402 ifp->if_data.ifi_hwassist = if_data_saved.ifi_hwassist;
4403 ifp->if_data.ifi_tso_v4_mtu = if_data_saved.ifi_tso_v4_mtu;
4404 ifp->if_data.ifi_tso_v6_mtu = if_data_saved.ifi_tso_v6_mtu;
4405 ifnet_touch_lastchange(ifp);
4407 VERIFY(ifp->if_output_sched_model == IFNET_SCHED_MODEL_NORMAL ||
4408 ifp->if_output_sched_model == IFNET_SCHED_MODEL_DRIVER_MANAGED);
4416 err = ifclassq_setup(ifp, sflags, (dl_if->dl_if_flags & DLIF_REUSE));
4418 panic_plain("%s: ifp=%p couldn't initialize transmit queue; "
4419 "err=%d", __func__, ifp, err);
4428 VERIFY(dl_inp->ifp == NULL);
4432 VERIFY(ifp->if_inp == NULL);
4451 if ((net_rxpoll && (ifp->if_eflags & IFEF_RXPOLL)) ||
4452 ifp->if_type == IFT_ETHER || ifp->if_type == IFT_CELLULAR) {
4453 ifp->if_inp = dl_inp;
4454 err = dlil_create_input_thread(ifp, ifp->if_inp);
4456 panic_plain("%s: ifp=%p couldn't get an input thread; "
4457 "err=%d", __func__, ifp, err);
4467 if (ifp->if_eflags & IFEF_TXSTART) {
4468 VERIFY(ifp->if_start != NULL);
4469 VERIFY(ifp->if_start_thread == THREAD_NULL);
4471 ifnet_set_start_cycle(ifp, NULL);
4472 ifp->if_start_active = 0;
4473 ifp->if_start_req = 0;
4474 if ((err = kernel_thread_start(ifnet_start_thread_fn, ifp,
4475 &ifp->if_start_thread)) != KERN_SUCCESS) {
4476 panic_plain("%s: ifp=%p couldn't get a start thread; "
4477 "err=%d", __func__, ifp, err);
4480 ml_thread_policy(ifp->if_start_thread, MACHINE_GROUP,
4489 if (ifp->if_eflags & IFEF_RXPOLL) {
4490 VERIFY(ifp->if_input_poll != NULL);
4491 VERIFY(ifp->if_input_ctl != NULL);
4492 VERIFY(ifp->if_poll_thread == THREAD_NULL);
4494 ifnet_set_poll_cycle(ifp, NULL);
4495 ifp->if_poll_update = 0;
4496 ifp->if_poll_active = 0;
4497 ifp->if_poll_req = 0;
4498 if ((err = kernel_thread_start(ifnet_poll_thread_fn, ifp,
4499 &ifp->if_poll_thread)) != KERN_SUCCESS) {
4500 panic_plain("%s: ifp=%p couldn't get a poll thread; "
4501 "err=%d", __func__, ifp, err);
4504 ml_thread_policy(ifp->if_poll_thread, MACHINE_GROUP,
4508 VERIFY(ifp->if_desc.ifd_maxlen == IF_DESCSIZE);
4509 VERIFY(ifp->if_desc.ifd_len == 0);
4510 VERIFY(ifp->if_desc.ifd_desc != NULL);
4513 ctrace_record(&((struct dlil_ifnet *)ifp)->dl_if_attach);
4515 ifp->if_updatemcasts = 0;
4516 if (!LIST_EMPTY(&ifp->if_multiaddrs)) {
4518 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
4522 ifp->if_updatemcasts++;
4527 "membership(s)\n", ifp->if_name, ifp->if_unit,
4528 ifp->if_updatemcasts);
4531 ifnet_lock_done(ifp);
4534 lck_mtx_lock(&ifp->if_cached_route_lock);
4536 ifp->if_fwd_cacheok = 1;
4538 if (ifp->if_fwd_route.ro_rt != NULL)
4539 rtfree(ifp->if_fwd_route.ro_rt);
4540 bzero(&ifp->if_fwd_route, sizeof (ifp->if_fwd_route));
4541 if (ifp->if_src_route.ro_rt != NULL)
4542 rtfree(ifp->if_src_route.ro_rt);
4543 bzero(&ifp->if_src_route, sizeof (ifp->if_src_route));
4544 if (ifp->if_src_route6.ro_rt != NULL)
4545 rtfree(ifp->if_src_route6.ro_rt);
4546 bzero(&ifp->if_src_route6, sizeof (ifp->if_src_route6));
4547 lck_mtx_unlock(&ifp->if_cached_route_lock);
4549 ifnet_llreach_ifattach(ifp, (dl_if->dl_if_flags & DLIF_REUSE));
4561 if (IGMP_IFINFO(ifp) == NULL) {
4562 IGMP_IFINFO(ifp) = igmp_domifattach(ifp, M_WAITOK);
4563 VERIFY(IGMP_IFINFO(ifp) != NULL);
4565 VERIFY(IGMP_IFINFO(ifp)->igi_ifp == ifp);
4566 igmp_domifreattach(IGMP_IFINFO(ifp));
4570 if (MLD_IFINFO(ifp) == NULL) {
4571 MLD_IFINFO(ifp) = mld_domifattach(ifp, M_WAITOK);
4572 VERIFY(MLD_IFINFO(ifp) != NULL);
4574 VERIFY(MLD_IFINFO(ifp)->mli_ifp == ifp);
4575 mld_domifreattach(MLD_IFINFO(ifp));
4583 ifnet_lock_exclusive(ifp);
4585 ifp->if_lqm = (ifp == lo_ifp) ? IFNET_LQM_THRESH_GOOD :
4587 lck_mtx_lock_spin(&ifp->if_ref_lock);
4588 ifp->if_refflags = IFRF_ATTACHED;
4589 lck_mtx_unlock(&ifp->if_ref_lock);
4592 (void) ifnet_set_idle_flags_locked(ifp, IFRF_IDLE_NOTIFY,
4596 (void) ifnet_set_idle_flags_locked(ifp, ifp->if_idle_new_flags,
4597 ifp->if_idle_new_flags_mask);
4600 ifnet_lock_done(ifp);
4608 pf_ifnet_hook(ifp, 1);
4611 dlil_post_msg(ifp, KEV_DL_SUBCLASS, KEV_DL_IF_ATTACHED, NULL, 0);
4614 printf("%s%d: attached%s\n", ifp->if_name, ifp->if_unit,
4632 dlil_alloc_lladdr(struct ifnet *ifp, const struct sockaddr_dl *ll_addr)
4638 struct dlil_ifnet *dl_if = (struct dlil_ifnet *)ifp;
4640 ifnet_lock_assert(ifp, IFNET_LCK_ASSERT_EXCLUSIVE);
4641 VERIFY(ll_addr == NULL || ll_addr->sdl_alen == ifp->if_addrlen);
4644 ifp->if_name, ifp->if_unit);
4646 socksize = masklen + ifp->if_addrlen;
4653 ifa = ifp->if_lladdr;
4701 oifa = ifp->if_lladdr;
4702 ifp->if_lladdr = ifa;
4705 ifa->ifa_ifp = ifp;
4712 asdl->sdl_index = ifp->if_index;
4713 asdl->sdl_type = ifp->if_type;
4733 if_purgeaddrs(struct ifnet *ifp)
4736 in_purgeaddrs(ifp);
4739 in6_purgeaddrs(ifp);
4742 at_purgeaddrs(ifp);
4747 ifnet_detach(ifnet_t ifp)
4749 if (ifp == NULL)
4754 ifnet_lock_exclusive(ifp);
4762 (void) ifnet_set_idle_flags_locked(ifp, 0, ~0);
4764 lck_mtx_lock_spin(&ifp->if_ref_lock);
4765 if (!(ifp->if_refflags & IFRF_ATTACHED)) {
4766 lck_mtx_unlock(&ifp->if_ref_lock);
4767 ifnet_lock_done(ifp);
4771 } else if (ifp->if_refflags & IFRF_DETACHING) {
4773 lck_mtx_unlock(&ifp->if_ref_lock);
4774 ifnet_lock_done(ifp);
4780 ifp->if_refflags &= ~IFRF_ATTACHED;
4781 ifp->if_refflags |= IFRF_DETACHING;
4782 lck_mtx_unlock(&ifp->if_ref_lock);
4785 printf("%s%d: detaching\n", ifp->if_name, ifp->if_unit);
4791 VERIFY(ifindex2ifnet[ifp->if_index] == ifp);
4792 TAILQ_REMOVE(&ifnet_head, ifp, if_link);
4793 ifp->if_link.tqe_next = NULL;
4794 ifp->if_link.tqe_prev = NULL;
4795 ifindex2ifnet[ifp->if_index] = NULL;
4798 ctrace_record(&((struct dlil_ifnet *)ifp)->dl_if_detach);
4800 ifnet_lock_done(ifp);
4805 if (ifp != lo_ifp)
4806 if_lqm_update(ifp, IFNET_LQM_THRESH_OFF);
4809 if (ifp->if_tcp_stat != NULL)
4810 bzero(ifp->if_tcp_stat, sizeof(*ifp->if_tcp_stat));
4813 if (ifp->if_udp_stat != NULL)
4814 bzero(ifp->if_udp_stat, sizeof(*ifp->if_udp_stat));
4817 bpfdetach(ifp);
4820 if_down(ifp);
4823 ifclassq_teardown(ifp);
4826 lck_mtx_lock(&ifp->if_cached_route_lock);
4827 ifp->if_fwd_cacheok = 0;
4828 lck_mtx_unlock(&ifp->if_cached_route_lock);
4836 igmp_domifdetach(ifp);
4839 mld_domifdetach(ifp);
4842 dlil_post_msg(ifp, KEV_DL_SUBCLASS, KEV_DL_IF_DETACHING, NULL, 0);
4846 ifnet_detaching_enqueue(ifp);
4853 ifnet_detaching_enqueue(struct ifnet *ifp)
4859 TAILQ_INSERT_TAIL(&ifnet_detaching_head, ifp, if_detaching_link);
4866 struct ifnet *ifp;
4870 ifp = TAILQ_FIRST(&ifnet_detaching_head);
4871 VERIFY(ifnet_detaching_cnt != 0 || ifp == NULL);
4872 if (ifp != NULL) {
4875 TAILQ_REMOVE(&ifnet_detaching_head, ifp, if_detaching_link);
4876 ifp->if_detaching_link.tqe_next = NULL;
4877 ifp->if_detaching_link.tqe_prev = NULL;
4879 return (ifp);
4886 struct ifnet *ifp;
4900 ifp = ifnet_detaching_dequeue();
4901 if (ifp != NULL) {
4903 ifnet_detach_final(ifp);
4927 ifnet_detach_final(struct ifnet *ifp)
4936 lck_mtx_lock(&ifp->if_ref_lock);
4937 if (!(ifp->if_refflags & IFRF_DETACHING)) {
4938 panic("%s: flags mismatch (detaching not set) ifp=%p",
4939 __func__, ifp);
4948 while (ifp->if_refio > 0) {
4950 "to be released\n", __func__, ifp->if_name, ifp->if_unit);
4951 (void) msleep(&(ifp->if_refio), &ifp->if_ref_lock,
4954 lck_mtx_unlock(&ifp->if_ref_lock);
4957 lck_mtx_lock(&ifp->if_flt_lock);
4958 if_flt_monitor_enter(ifp);
4960 lck_mtx_assert(&ifp->if_flt_lock, LCK_MTX_ASSERT_OWNED);
4961 fhead = ifp->if_flt_head;
4962 TAILQ_INIT(&ifp->if_flt_head);
4966 lck_mtx_unlock(&ifp->if_flt_lock);
4969 lck_mtx_lock(&ifp->if_flt_lock);
4971 if_flt_monitor_leave(ifp);
4972 lck_mtx_unlock(&ifp->if_flt_lock);
4975 if_purgeaddrs(ifp);
4977 ifnet_lock_exclusive(ifp);
4983 proto = SLIST_FIRST(&ifp->if_proto_hash[i]);
4986 ifnet_lock_done(ifp);
4987 proto_unplumb(family, ifp);
4988 ifnet_lock_exclusive(ifp);
4989 proto = SLIST_FIRST(&ifp->if_proto_hash[i]);
4992 VERIFY(SLIST_EMPTY(&ifp->if_proto_hash[i]));
4994 zfree(dlif_phash_zone, ifp->if_proto_hash);
4995 ifp->if_proto_hash = NULL;
4998 ifa = TAILQ_FIRST(&ifp->if_addrhead);
4999 VERIFY(ifnet_addrs[ifp->if_index - 1] == ifa);
5001 if_detach_link_ifa(ifp, ifa);
5006 ifnet_addrs[ifp->if_index - 1] = NULL;
5009 VERIFY(ifp->if_link.tqe_next == NULL);
5010 VERIFY(ifp->if_link.tqe_prev == NULL);
5011 VERIFY(ifp->if_detaching_link.tqe_next == NULL);
5012 VERIFY(ifp->if_detaching_link.tqe_prev == NULL);
5015 VERIFY(TAILQ_EMPTY(&ifp->if_prefixhead));
5018 VERIFY(ifindex2ifnet[ifp->if_index] == NULL);
5021 VERIFY(TAILQ_EMPTY(&ifp->if_addrhead));
5026 if (ifp->if_start_thread != THREAD_NULL) {
5027 lck_mtx_lock_spin(&ifp->if_start_lock);
5028 ifp->if_start_thread = THREAD_NULL;
5029 wakeup_one((caddr_t)&ifp->if_start_thread);
5030 lck_mtx_unlock(&ifp->if_start_lock);
5036 if (ifp->if_poll_thread != THREAD_NULL) {
5037 lck_mtx_lock_spin(&ifp->if_poll_lock);
5038 ifp->if_poll_thread = THREAD_NULL;
5039 wakeup_one((caddr_t)&ifp->if_poll_thread);
5040 lck_mtx_unlock(&ifp->if_poll_lock);
5049 if ((inp = ifp->if_inp) != NULL) {
5067 VERIFY(ifp->if_eflags & IFEF_RXPOLL);
5085 /* disassociate ifp DLIL input thread */
5086 ifp->if_inp = NULL;
5097 if_free = ifp->if_free;
5098 ifp->if_output = ifp_if_output;
5099 ifp->if_pre_enqueue = ifp_if_output;
5100 ifp->if_start = ifp_if_start;
5101 ifp->if_output_ctl = ifp_if_ctl;
5102 ifp->if_input_poll = ifp_if_input_poll;
5103 ifp->if_input_ctl = ifp_if_ctl;
5104 ifp->if_ioctl = ifp_if_ioctl;
5105 ifp->if_set_bpf_tap = ifp_if_set_bpf_tap;
5106 ifp->if_free = ifp_if_free;
5107 ifp->if_demux = ifp_if_demux;
5108 ifp->if_event = ifp_if_event;
5109 ifp->if_framer = ifp_if_framer;
5110 ifp->if_add_proto = ifp_if_add_proto;
5111 ifp->if_del_proto = ifp_if_del_proto;
5112 ifp->if_check_multi = ifp_if_check_multi;
5115 VERIFY(ifp->if_desc.ifd_maxlen == IF_DESCSIZE);
5116 ifp->if_desc.ifd_len = 0;
5117 VERIFY(ifp->if_desc.ifd_desc != NULL);
5118 bzero(ifp->if_desc.ifd_desc, IF_DESCSIZE);
5120 ifnet_lock_done(ifp);
5126 pf_ifnet_hook(ifp, 0);
5130 lck_mtx_lock_spin(&ifp->if_flt_lock);
5131 VERIFY(TAILQ_EMPTY(&ifp->if_flt_head));
5132 VERIFY(ifp->if_flt_busy == 0);
5133 VERIFY(ifp->if_flt_waiters == 0);
5134 lck_mtx_unlock(&ifp->if_flt_lock);
5137 if_qflush(ifp, 0);
5140 lck_mtx_lock(&ifp->if_cached_route_lock);
5141 VERIFY(!ifp->if_fwd_cacheok);
5142 if (ifp->if_fwd_route.ro_rt != NULL)
5143 rtfree(ifp->if_fwd_route.ro_rt);
5144 bzero(&ifp->if_fwd_route, sizeof (ifp->if_fwd_route));
5145 if (ifp->if_src_route.ro_rt != NULL)
5146 rtfree(ifp->if_src_route.ro_rt);
5147 bzero(&ifp->if_src_route, sizeof (ifp->if_src_route));
5148 if (ifp->if_src_route6.ro_rt != NULL)
5149 rtfree(ifp->if_src_route6.ro_rt);
5150 bzero(&ifp->if_src_route6, sizeof (ifp->if_src_route6));
5151 lck_mtx_unlock(&ifp->if_cached_route_lock);
5153 ifnet_llreach_ifdetach(ifp);
5155 dlil_post_msg(ifp, KEV_DL_SUBCLASS, KEV_DL_IF_DETACHED, NULL, 0);
5158 if_free(ifp);
5163 lck_mtx_lock_spin(&ifp->if_ref_lock);
5164 if (!(ifp->if_refflags & IFRF_DETACHING)) {
5165 panic("%s: flags mismatch (detaching not set) ifp=%p",
5166 __func__, ifp);
5169 ifp->if_refflags &= ~IFRF_DETACHING;
5170 lck_mtx_unlock(&ifp->if_ref_lock);
5173 printf("%s%d: detached\n", ifp->if_name, ifp->if_unit);
5176 ifnet_release(ifp);
5180 ifp_if_output(struct ifnet *ifp, struct mbuf *m)
5182 #pragma unused(ifp)
5188 ifp_if_start(struct ifnet *ifp)
5190 ifnet_purge(ifp);
5194 ifp_if_input_poll(struct ifnet *ifp, u_int32_t flags, u_int32_t max_cnt,
5197 #pragma unused(ifp, flags, max_cnt)
5209 ifp_if_ctl(struct ifnet *ifp, ifnet_ctl_cmd_t cmd, u_int32_t arglen, void *arg)
5211 #pragma unused(ifp, cmd, arglen, arg)
5216 ifp_if_demux(struct ifnet *ifp, struct mbuf *m, char *fh, protocol_family_t *pf)
5218 #pragma unused(ifp, fh, pf)
5224 ifp_if_add_proto(struct ifnet *ifp, protocol_family_t pf,
5227 #pragma unused(ifp, pf, da, dc)
5232 ifp_if_del_proto(struct ifnet *ifp, protocol_family_t pf)
5234 #pragma unused(ifp, pf)
5239 ifp_if_check_multi(struct ifnet *ifp, const struct sockaddr *sa)
5241 #pragma unused(ifp, sa)
5245 static errno_t ifp_if_framer(struct ifnet *ifp, struct mbuf **m,
5253 #pragma unused(ifp, m, sa, ll, t)
5264 ifp_if_ioctl(struct ifnet *ifp, unsigned long cmd, void *arg)
5266 #pragma unused(ifp, cmd, arg)
5271 ifp_if_set_bpf_tap(struct ifnet *ifp, bpf_tap_mode tm, bpf_packet_func f)
5273 #pragma unused(ifp, tm, f)
5279 ifp_if_free(struct ifnet *ifp)
5281 #pragma unused(ifp)
5285 ifp_if_event(struct ifnet *ifp, const struct kev_msg *e)
5287 #pragma unused(ifp, e)
5292 size_t uniqueid_len, struct ifnet **ifp)
5320 *ifp = ifp1;
5406 *ifp = ifp1;
5418 dlil_if_release(ifnet_t ifp)
5420 struct dlil_ifnet *dlifp = (struct dlil_ifnet *)ifp;
5422 ifnet_lock_exclusive(ifp);
5425 strncpy(dlifp->dl_if_namestorage, ifp->if_name, IFNAMSIZ);
5426 ifp->if_name = dlifp->dl_if_namestorage;
5432 * still has a handle on ifp will now see it as unlabeled.
5435 mac_ifnet_label_recycle(ifp);
5437 ifnet_lock_done(ifp);
5459 dlil_proto_unplumb_all(struct ifnet *ifp)
5470 (void) proto_unplumb(PF_INET, ifp);
5472 (void) proto_unplumb(PF_INET6, ifp);
5475 (void) proto_unplumb(PF_APPLETALK, ifp);
5480 ifp_src_route_copyout(struct ifnet *ifp, struct route *dst)
5482 lck_mtx_lock_spin(&ifp->if_cached_route_lock);
5483 lck_mtx_convert_spin(&ifp->if_cached_route_lock);
5485 route_copyout(dst, &ifp->if_src_route, sizeof (*dst));
5487 lck_mtx_unlock(&ifp->if_cached_route_lock);
5491 ifp_src_route_copyin(struct ifnet *ifp, struct route *src)
5493 lck_mtx_lock_spin(&ifp->if_cached_route_lock);
5494 lck_mtx_convert_spin(&ifp->if_cached_route_lock);
5496 if (ifp->if_fwd_cacheok) {
5497 route_copyin(src, &ifp->if_src_route, sizeof (*src));
5502 lck_mtx_unlock(&ifp->if_cached_route_lock);
5507 ifp_src_route6_copyout(struct ifnet *ifp, struct route_in6 *dst)
5509 lck_mtx_lock_spin(&ifp->if_cached_route_lock);
5510 lck_mtx_convert_spin(&ifp->if_cached_route_lock);
5512 route_copyout((struct route *)dst, (struct route *)&ifp->if_src_route6,
5515 lck_mtx_unlock(&ifp->if_cached_route_lock);
5519 ifp_src_route6_copyin(struct ifnet *ifp, struct route_in6 *src)
5521 lck_mtx_lock_spin(&ifp->if_cached_route_lock);
5522 lck_mtx_convert_spin(&ifp->if_cached_route_lock);
5524 if (ifp->if_fwd_cacheok) {
5526 (struct route *)&ifp->if_src_route6, sizeof (*src));
5531 lck_mtx_unlock(&ifp->if_cached_route_lock);
5536 ifnet_cached_rtlookup_inet(struct ifnet *ifp, struct in_addr src_ip)
5543 ifp_src_route_copyout(ifp, &src_rt);
5560 0, 0, ifp->if_index);
5566 ifp_src_route_copyin(ifp, &src_rt);
5577 ifnet_cached_rtlookup_inet6(struct ifnet *ifp, struct in6_addr *src_ip6)
5581 ifp_src_route6_copyout(ifp, &src_rt);
5594 src_rt.ro_dst.sin6_scope_id = in6_addr2scopeid(ifp, src_ip6);
5601 ifp->if_index);
5607 ifp_src_route6_copyin(ifp, &src_rt);
5618 if_lqm_update(struct ifnet *ifp, int lqm)
5630 ifnet_lock_exclusive(ifp);
5631 if (lqm == ifp->if_lqm) {
5632 ifnet_lock_done(ifp);
5635 ifp->if_lqm = lqm;
5636 ifnet_lock_done(ifp);
5641 dlil_post_msg(ifp, KEV_DL_SUBCLASS, KEV_DL_LINK_QUALITY_METRIC_CHANGED,
5649 struct ifnet *ifp;
5653 TAILQ_FOREACH(ifp, &ifnet_head, if_link) {
5654 ifnet_lock_shared(ifp);
5655 IFA_LOCK_SPIN(ifp->if_lladdr);
5656 sdl = (struct sockaddr_dl *)(void *)ifp->if_lladdr->ifa_addr;
5659 IFA_UNLOCK(ifp->if_lladdr);
5660 ifnet_lock_done(ifp);
5664 IFA_UNLOCK(ifp->if_lladdr);
5665 ifnet_lock_done(ifp);
5848 dlil_node_present(struct ifnet *ifp, struct sockaddr *sa,
5855 VERIFY(ifp);
5862 nd6_alt_node_addr_decompose(ifp, sa, sdl, sin6);
5868 nd6_alt_node_present(ifp, sin6, sdl, rssi, lqm, npm);
5869 dlil_post_msg(ifp, KEV_DL_SUBCLASS, KEV_DL_NODE_PRESENCE,
5874 dlil_node_absent(struct ifnet *ifp, struct sockaddr *sa)
5880 VERIFY(ifp);
5887 nd6_alt_node_addr_decompose(ifp, sa, sdl, sin6);
5889 nd6_alt_node_absent(ifp, sin6);
5890 dlil_post_msg(ifp, KEV_DL_SUBCLASS, KEV_DL_NODE_ABSENCE,
5895 ifnet_getset_opportunistic(ifnet_t ifp, u_long cmd, struct ifreq *ifr,
5919 result = ifnet_set_throttle(ifp, level);
5920 } else if ((result = ifnet_get_throttle(ifp, &level)) == 0) {
5939 udp_count_opportunistic(ifp->if_index, flags) +
5940 tcp_count_opportunistic(ifp->if_index, flags);
5950 ifnet_get_throttle(struct ifnet *ifp, u_int32_t *level)
5955 if (!(ifp->if_eflags & IFEF_TXSTART))
5960 ifq = &ifp->if_snd;
5971 ifnet_set_throttle(struct ifnet *ifp, u_int32_t level)
5976 if (!(ifp->if_eflags & IFEF_TXSTART))
5992 ifq = &ifp->if_snd;
5999 printf("%s%d: throttling level set to %d\n", ifp->if_name,
6000 ifp->if_unit, level);
6002 ifnet_start(ifp);