X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/316670eb35587141e969394ae8537d66b9211e80..fe8ab488e9161c46dd9885d58fc52996dc0249ff:/bsd/net/if_var.h diff --git a/bsd/net/if_var.h b/bsd/net/if_var.h index 426a78bb5..efa21e8b8 100644 --- a/bsd/net/if_var.h +++ b/bsd/net/if_var.h @@ -1,8 +1,8 @@ /* - * Copyright (c) 2000-2012 Apple Inc. All rights reserved. + * Copyright (c) 2000-2014 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ - * + * * 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 @@ -11,10 +11,10 @@ * unlawful or unlicensed copies of an Apple operating system, or to * circumvent, violate, or enable the circumvention or violation of, any * terms of an Apple operating system software license agreement. - * + * * 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 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, @@ -22,7 +22,7 @@ * 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. - * + * * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ /* @@ -142,8 +142,7 @@ struct net_event_data { }; #if defined(__LP64__) -#define __need_struct_timeval32 -#include +#include #define IF_DATA_TIMEVAL timeval32 #else #define IF_DATA_TIMEVAL timeval @@ -249,6 +248,10 @@ struct if_traffic_class { struct if_data_extended { u_int64_t ifi_alignerrs; /* unaligned (32-bit) input pkts */ + u_int64_t ifi_dt_bytes; /* Data threshold counter */ + u_int64_t ifi_fpackets; /* forwarded packets on interface */ + u_int64_t ifi_fbytes; /* forwarded bytes on interface */ + u_int64_t reserved[12]; /* for future */ }; struct if_packet_stats { @@ -267,6 +270,7 @@ struct if_packet_stats { u_int64_t ifi_tcp_dospacket; u_int64_t ifi_tcp_cleanup; u_int64_t ifi_tcp_synwindow; + u_int64_t reserved[6]; /* UDP */ u_int64_t ifi_udp_port_unreach; u_int64_t ifi_udp_faithprefix; @@ -276,6 +280,7 @@ struct if_packet_stats { u_int64_t ifi_udp_badmcast; u_int64_t ifi_udp_cleanup; u_int64_t ifi_udp_badipsec; + u_int64_t _reserved[4]; }; struct if_description { @@ -289,6 +294,11 @@ struct if_bandwidths { u_int64_t max_bw; /* maximum theoretical bandwidth */ }; +struct if_latencies { + u_int64_t eff_lt; /* effective latency */ + u_int64_t max_lt; /* maximum theoretical latency */ +}; + struct if_rxpoll_stats { u_int32_t ifi_poll_off_req; /* total # of POLL_OFF reqs */ u_int32_t ifi_poll_off_err; /* total # of POLL_OFF errors */ @@ -312,6 +322,9 @@ struct if_rxpoll_stats { u_int32_t ifi_poll_bytes_max; /* largest polled bytes */ u_int32_t ifi_poll_bytes_lowat; /* bytes low watermark */ u_int32_t ifi_poll_bytes_hiwat; /* bytes high watermark */ + + u_int32_t ifi_poll_packets_limit; /* max packets per poll call */ + u_int64_t ifi_poll_interval_time; /* poll interval (nsec) */ }; #endif /* PRIVATE */ @@ -365,17 +378,19 @@ struct if_data_internal { u_int32_t ifi_recvtiming; /* usec spent receiving when timing */ u_int32_t ifi_xmittiming; /* usec spent xmitting when timing */ u_int64_t ifi_alignerrs; /* unaligned (32-bit) input pkts */ -#define IF_LASTCHANGEUPTIME 1 /* lastchange: 1-uptime 0-calendar time */ + u_int64_t ifi_dt_bytes; /* Data threshold counter */ + u_int64_t ifi_fpackets; /* forwarded packets on interface */ + u_int64_t ifi_fbytes; /* forwarded bytes on interface */ struct timeval ifi_lastchange; /* time of last administrative change */ u_int32_t ifi_hwassist; /* HW offload capabilities */ u_int32_t ifi_tso_v4_mtu; /* TCP Segment Offload IPv4 maximum segment size */ u_int32_t ifi_tso_v6_mtu; /* TCP Segment Offload IPv6 maximum segment size */ }; +#if MEASURE_BW /* * Fields per interface to measure perceived bandwidth. */ - struct if_measured_bw { u_int64_t bw; /* measured bandwidth in bytes per ms */ u_int64_t bytes; /* XXX not needed */ @@ -389,7 +404,7 @@ struct if_measured_bw { #define IF_MEASURED_BW_INPROGRESS 0x1 #define IF_MEASURED_BW_CALCULATION 0x2 }; - +#endif /* MEASURE_BW */ #endif /* BSD_KERNEL_PRIVATE */ #ifdef PRIVATE @@ -421,6 +436,9 @@ struct if_measured_bw { #define if_tso_v4_mtu if_data.ifi_tso_v4_mtu #define if_tso_v6_mtu if_data.ifi_tso_v6_mtu #define if_alignerrs if_data.ifi_alignerrs +#define if_dt_bytes if_data.ifi_dt_bytes +#define if_fpackets if_data.ifi_fpackets +#define if_fbytes if_data.ifi_fbytes #endif /* BSD_KERNEL_PRIVATE */ #ifdef BSD_KERNEL_PRIVATE @@ -470,7 +488,7 @@ TAILQ_HEAD(ddesc_head_name, dlil_demux_desc); #define IF_HWASSIST_CSUM_TCPIPV6 0x0020 /* will csum TCPv6, IFNET_CSUM_TCPIPV6 */ #define IF_HWASSIST_CSUM_UDPIPV6 0x0040 /* will csum UDPv6, IFNET_CSUM_UDP */ #define IF_HWASSIST_CSUM_FRAGMENT_IPV6 0x0080 /* will do IPv6 fragmentation, IFNET_IPV6_FRAGMENT */ -#define IF_HWASSIST_CSUM_TCP_SUM16 0x1000 /* simple TCP Sum16 computation, IFNET_CSUM_SUM16 */ +#define IF_HWASSIST_CSUM_PARTIAL 0x1000 /* simple Sum16 computation, IFNET_CSUM_PARTIAL */ #define IF_HWASSIST_CSUM_MASK 0xffff #define IF_HWASSIST_CSUM_FLAGS(hwassist) ((hwassist) & IF_HWASSIST_CSUM_MASK) @@ -484,16 +502,24 @@ TAILQ_HEAD(ddesc_head_name, dlil_demux_desc); #define IF_HWASSIST_TSO_V6 0x00400000 /* will do TCP Segment offload for IPv6, IFNET_TSO_IPV6 */ #endif /* PRIVATE */ +#ifdef PRIVATE +#define IFXNAMSIZ (IFNAMSIZ + 8) /* external name (name + unit) */ +#endif + #ifdef BSD_KERNEL_PRIVATE /* * ifnet is private to BSD portion of kernel */ +#include #include #include +#include #include +#include RB_HEAD(ll_reach_tree, if_llreach); /* define struct ll_reach_tree */ +#define if_name(ifp) ifp->if_xname /* * Structure defining a network interface. * @@ -506,12 +532,13 @@ struct ifnet { decl_lck_rw_data(, if_lock); void *if_softc; /* pointer to driver state */ const char *if_name; /* name, e.g. ``en'' or ``lo'' */ + const char *if_xname; /* external name (name + unit) */ struct if_description if_desc; /* extended description */ TAILQ_ENTRY(ifnet) if_link; /* all struct ifnets are chained */ TAILQ_ENTRY(ifnet) if_detaching_link; /* list of detaching ifnets */ decl_lck_mtx_data(, if_ref_lock) - u_int32_t if_refflags; + u_int32_t if_refflags; /* see IFRF flags below */ u_int32_t if_refio; /* number of io ops to the underlying driver */ #define if_list if_link @@ -536,6 +563,7 @@ struct ifnet { struct if_data_internal if_data __attribute__((aligned(8))); ifnet_family_t if_family; /* value assigned by Apple */ + ifnet_subfamily_t if_subfamily; /* value assigned by Apple */ uintptr_t if_family_cookie; ifnet_output_func if_output; ifnet_pre_enqueue_func if_pre_enqueue; @@ -548,14 +576,18 @@ struct ifnet { ifnet_detached_func if_free; ifnet_demux_func if_demux; ifnet_event_func if_event; - ifnet_framer_func if_framer; + ifnet_framer_func if_framer_legacy; + ifnet_framer_extended_func if_framer; ifnet_add_proto_func if_add_proto; ifnet_del_proto_func if_del_proto; ifnet_check_multi if_check_multi; struct proto_hash_entry *if_proto_hash; void *if_kpi_storage; + u_int32_t if_flowhash; /* interface flow control ID */ + decl_lck_mtx_data(, if_start_lock); + u_int32_t if_start_flags; /* see IFSF flags below */ u_int32_t if_start_req; u_int32_t if_start_active; /* output is active */ struct timespec if_start_cycle; /* restart interval */ @@ -567,6 +599,9 @@ struct ifnet { struct if_bandwidths if_output_bw; struct if_bandwidths if_input_bw; + struct if_latencies if_output_lt; + struct if_latencies if_input_lt; + decl_lck_mtx_data(, if_flt_lock) u_int32_t if_flt_busy; u_int32_t if_flt_waiters; @@ -630,17 +665,57 @@ struct ifnet { #endif /* INET6 */ int if_lqm; /* link quality metric */ +#if MEASURE_BW struct if_measured_bw if_bw; +#endif /* MEASURE_BW */ struct tcpstat_local *if_tcp_stat; /* TCP specific stats */ struct udpstat_local *if_udp_stat; /* UDP specific stats */ + + struct { + int32_t level; /* cached logging level */ + u_int32_t flags; /* cached logging flags */ + int32_t category; /* cached category */ + int32_t subcategory; /* cached subcategory */ + } if_log; + + struct { + struct ifnet *ifp; /* delegated ifp */ + u_int32_t type; /* delegated i/f type */ + u_int32_t family; /* delegated i/f family */ + u_int32_t subfamily; /* delegated i/f sub-family */ + uint32_t expensive:1; /* delegated i/f expensive? */ + } if_delegated; + + u_int64_t if_data_threshold; + u_int32_t if_fg_sendts; /* last send on a fg socket in seconds */ + +#if INET6 + decl_lck_rw_data(, if_inet6data_lock); + void *if_inet6data; +#endif }; +#define IF_TCP_STATINC(_ifp, _s) do { \ + if ((_ifp)->if_tcp_stat != NULL) \ + atomic_add_64(&(_ifp)->if_tcp_stat->_s, 1); \ +} while (0); + +#define IF_UDP_STATINC(_ifp, _s) do { \ + if ((_ifp)->if_udp_stat != NULL) \ + atomic_add_64(&(_ifp)->if_udp_stat->_s, 1); \ +} while (0); + /* - * Valid values for if_useflags + * Valid values for if_refflags */ #define IFRF_ATTACHED 0x1 /* ifnet attach is completely done */ #define IFRF_DETACHING 0x2 /* detach has been requested */ +/* + * Valid values for if_start_flags + */ +#define IFSF_FLOW_CONTROLLED 0x1 /* flow controlled */ + /* * Structure describing a `cloning' interface. */ @@ -881,16 +956,86 @@ struct ifmultiaddr { #define IFMA_REMREF(_ifma) \ ifma_remref(_ifma) -__private_extern__ struct ifnethead ifnet_head; -__private_extern__ struct ifnet **ifindex2ifnet; -__private_extern__ u_int32_t if_sndq_maxlen; -__private_extern__ u_int32_t if_rcvq_maxlen; -__private_extern__ int if_index; -__private_extern__ struct ifaddr **ifnet_addrs; -__private_extern__ lck_attr_t *ifa_mtx_attr; -__private_extern__ lck_grp_t *ifa_mtx_grp; -__private_extern__ lck_grp_t *ifnet_lock_group; -__private_extern__ lck_attr_t *ifnet_lock_attr; +/* + * Indicate whether or not the immediate interface, or the interface delegated + * by it, is a cellular interface (IFT_CELLULAR). Delegated interface type is + * set/cleared along with the delegated ifp; we cache the type for performance + * to avoid dereferencing delegated ifp each time. + * + * Note that this is meant to be used only for accounting and policy purposes; + * certain places need to explicitly know the immediate interface type, and + * this macro should not be used there. + * + * The test is done against IFT_CELLULAR instead of IFNET_FAMILY_CELLULAR to + * handle certain cases where the family isn't set to the latter. + */ +#define IFNET_IS_CELLULAR(_ifp) \ + ((_ifp)->if_type == IFT_CELLULAR || \ + (_ifp)->if_delegated.type == IFT_CELLULAR) + +/* + * Indicate whether or not the immediate interface, or the interface delegated + * by it, is a Wi-Fi interface (IFNET_SUBFAMILY_WIFI). Delegated interface + * subfamily is set/cleared along with the delegated ifp; we cache the subfamily + * for performance to avoid dereferencing delegated ifp each time. + * + * Note that this is meant to be used only for accounting and policy purposes; + * certain places need to explicitly know the immediate interface type, and + * this macro should not be used there. + * + * The test is done against IFNET_SUBFAMILY_WIFI as the family may be set to + * IFNET_FAMILY_ETHERNET (as well as type to IFT_ETHER) which is too generic. + */ +#define IFNET_IS_WIFI(_ifp) \ + ((_ifp)->if_subfamily == IFNET_SUBFAMILY_WIFI || \ + (_ifp)->if_delegated.subfamily == IFNET_SUBFAMILY_WIFI) + +/* + * Indicate whether or not the immediate interface, or the interface delegated + * by it, is a Wired interface (several families). Delegated interface + * family is set/cleared along with the delegated ifp; we cache the family + * for performance to avoid dereferencing delegated ifp each time. + * + * Note that this is meant to be used only for accounting and policy purposes; + * certain places need to explicitly know the immediate interface type, and + * this macro should not be used there. + */ +#define IFNET_IS_WIRED(_ifp) \ + ((_ifp)->if_family == IFNET_FAMILY_ETHERNET || \ + (_ifp)->if_delegated.family == IFNET_FAMILY_ETHERNET || \ + (_ifp)->if_family == IFNET_FAMILY_FIREWIRE || \ + (_ifp)->if_delegated.family == IFNET_FAMILY_FIREWIRE) + +/* + * Indicate whether or not the immediate interface, or the interface delegated + * by it, is marked as expensive. The delegated interface is set/cleared + * along with the delegated ifp; we cache the flag for performance to avoid + * dereferencing delegated ifp each time. + * + * Note that this is meant to be used only for policy purposes. + */ +#define IFNET_IS_EXPENSIVE(_ifp) \ + ((_ifp)->if_eflags & IFEF_EXPENSIVE || \ + (_ifp)->if_delegated.expensive) + +/* + * We don't support AWDL interface delegation. + */ +#define IFNET_IS_AWDL_RESTRICTED(_ifp) \ + (((_ifp)->if_eflags & (IFEF_AWDL|IFEF_AWDL_RESTRICTED)) == \ + (IFEF_AWDL|IFEF_AWDL_RESTRICTED)) + + +extern struct ifnethead ifnet_head; +extern struct ifnet **ifindex2ifnet; +extern u_int32_t if_sndq_maxlen; +extern u_int32_t if_rcvq_maxlen; +extern int if_index; +extern struct ifaddr **ifnet_addrs; +extern lck_attr_t *ifa_mtx_attr; +extern lck_grp_t *ifa_mtx_grp; +extern lck_grp_t *ifnet_lock_group; +extern lck_attr_t *ifnet_lock_attr; extern ifnet_t lo_ifp; extern uint32_t if_bw_measure_size; extern u_int32_t if_bw_smoothing_val; @@ -928,11 +1073,20 @@ typedef enum { IFNET_LCK_ASSERT_NOTOWNED /* not held */ } ifnet_lock_assert_t; +#define IF_LLADDR(_ifp) \ + (LLADDR(SDL(((_ifp)->if_lladdr)->ifa_addr))) + __private_extern__ void ifnet_lock_assert(struct ifnet *, ifnet_lock_assert_t); __private_extern__ void ifnet_lock_shared(struct ifnet *ifp); __private_extern__ void ifnet_lock_exclusive(struct ifnet *ifp); __private_extern__ void ifnet_lock_done(struct ifnet *ifp); +#if INET6 +__private_extern__ void if_inet6data_lock_shared(struct ifnet *ifp); +__private_extern__ void if_inet6data_lock_exclusive(struct ifnet *ifp); +__private_extern__ void if_inet6data_lock_done(struct ifnet *ifp); +#endif + __private_extern__ void ifnet_head_lock_shared(void); __private_extern__ void ifnet_head_lock_exclusive(void); __private_extern__ void ifnet_head_done(void); @@ -983,15 +1137,17 @@ __private_extern__ struct in_ifaddr *ifa_foraddr(unsigned int); __private_extern__ struct in_ifaddr *ifa_foraddr_scoped(unsigned int, unsigned int); -extern void ifnet_fclist_append(struct sfb *sp, struct sfb_fc_list *fcl); -extern struct sfb_bin_fcentry* ifnet_fce_alloc(int how); -extern void ifnet_fce_free(struct sfb_bin_fcentry *); - struct ifreq; extern errno_t ifnet_getset_opportunistic(struct ifnet *, u_long, struct ifreq *, struct proc *); extern int ifnet_get_throttle(struct ifnet *, u_int32_t *); extern int ifnet_set_throttle(struct ifnet *, u_int32_t); +extern errno_t ifnet_getset_log(struct ifnet *, u_long, + struct ifreq *, struct proc *); +extern int ifnet_set_log(struct ifnet *, int32_t, uint32_t, int32_t, int32_t); +extern int ifnet_get_log(struct ifnet *, int32_t *, uint32_t *, int32_t *, + int32_t *); +extern int ifnet_notify_address(struct ifnet *, int); #if INET6 struct in6_addr; @@ -1024,12 +1180,23 @@ __private_extern__ void if_lqm_update(struct ifnet *, int32_t); __private_extern__ void ifnet_update_sndq(struct ifclassq *, cqev_t); __private_extern__ void ifnet_update_rcv(struct ifnet *, cqev_t); +__private_extern__ void ifnet_flowadv(uint32_t); + __private_extern__ errno_t ifnet_set_input_bandwidths(struct ifnet *, struct if_bandwidths *); __private_extern__ errno_t ifnet_set_output_bandwidths(struct ifnet *, struct if_bandwidths *, boolean_t); __private_extern__ u_int64_t ifnet_output_linkrate(struct ifnet *); __private_extern__ u_int64_t ifnet_input_linkrate(struct ifnet *); + +__private_extern__ errno_t ifnet_set_input_latencies(struct ifnet *, + struct if_latencies *); +__private_extern__ errno_t ifnet_set_output_latencies(struct ifnet *, + struct if_latencies *, boolean_t); + +__private_extern__ errno_t ifnet_framer_stub(struct ifnet *, struct mbuf **, + const struct sockaddr *, const char *, const char *, u_int32_t *, + u_int32_t *); #endif /* BSD_KERNEL_PRIVATE */ #ifdef XNU_KERNEL_PRIVATE /* for uuid.c */