/*
- * Copyright (c) 2008-2010 Apple Inc. All rights reserved.
+ * Copyright (c) 2008-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
* 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,
* 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@
*/
/*!
@constant MBUF_EXT Indicates this mbuf has external data.
@constant MBUF_PKTHDR Indicates this mbuf has a packet header.
@constant MBUF_EOR Indicates this mbuf is the end of a record.
+ @constant MBUF_LOOP Indicates this packet is looped back.
@constant MBUF_BCAST Indicates this packet will be sent or was
received as a brodcast.
@constant MBUF_MCAST Indicates this packet will be sent or was
MBUF_EXT = 0x0001, /* has associated external storage */
MBUF_PKTHDR = 0x0002, /* start of record */
MBUF_EOR = 0x0004, /* end of record */
+ MBUF_LOOP = 0x0040, /* packet is looped back */
MBUF_BCAST = 0x0100, /* send/received as link-level broadcast */
MBUF_MCAST = 0x0200, /* send/received as link-level multicast */
MBUF_FRAG = 0x0400, /* packet is a fragment of a larger packet */
MBUF_FIRSTFRAG = 0x0800, /* packet is first fragment */
MBUF_LASTFRAG = 0x1000, /* packet is last fragment */
- MBUF_PROMISC = 0x2000 /* packet is promiscuous */
+ MBUF_PROMISC = 0x2000, /* packet is promiscuous */
+ MBUF_HASFCS = 0x4000 /* packet has FCS */
};
typedef u_int32_t mbuf_flags_t;
calculated yet.
@constant MBUF_CSUM_REQ_UDP Indicates the UDP checksum has not been
calculated yet.
+ @constant MBUF_CSUM_REQ_TCPIPV6 Indicates the TCP checksum for IPv6
+ has not been calculated yet.
+ @constant MBUF_CSUM_REQ_UDPIPV6 Indicates the UDP checksum for IPv6
+ has not been calculated yet.
*/
enum {
MBUF_TSO_IPV4 = 0x100000,
enum {
#ifdef KERNEL_PRIVATE
- MBUF_CSUM_REQ_SUM16 = 0x1000, /* Weird apple hardware checksum */
+ MBUF_CSUM_PARTIAL = 0x1000, /* 16-bit 1's complement sum */
+ MBUF_CSUM_REQ_SUM16 = MBUF_CSUM_PARTIAL,
#endif /* KERNEL_PRIVATE */
MBUF_CSUM_REQ_IP = 0x0001,
MBUF_CSUM_REQ_TCP = 0x0002,
- MBUF_CSUM_REQ_UDP = 0x0004
+ MBUF_CSUM_REQ_UDP = 0x0004,
+ MBUF_CSUM_REQ_TCPIPV6 = 0x0020,
+ MBUF_CSUM_REQ_UDPIPV6 = 0x0040
};
typedef u_int32_t mbuf_csum_request_flags_t;
hardware should be passed as the second parameter of
mbuf_set_csum_performed. The hardware calculated checksum value
can be retrieved using the second parameter passed to
- mbuf_get_csum_performed.
+ mbuf_get_csum_performed. This should be done for IPv4 or IPv6.
@constant MBUF_CSUM_PSEUDO_HDR If set, this indicates that the
checksum value for MBUF_CSUM_DID_DATA includes the pseudo header
value. If this is not set, the stack will calculate the pseudo
*/
enum {
#ifdef KERNEL_PRIVATE
- MBUF_CSUM_TCP_SUM16 = MBUF_CSUM_REQ_SUM16, /* Weird apple hardware checksum */
+ MBUF_CSUM_TCP_SUM16 = MBUF_CSUM_PARTIAL,
#endif /* KERNEL_PRIVATE */
MBUF_CSUM_DID_IP = 0x0100,
MBUF_CSUM_IP_GOOD = 0x0200,
/*!
@enum mbuf_how_t
@abstract Method of allocating an mbuf.
- @discussion Blocking will cause the funnel to be dropped. If the
- funnel is dropped, other threads may make changes to networking
- data structures. This can lead to very bad things happening.
- Blocking on the input our output path can also impact
+ @discussion Blocking on the input or output path can impact
performance. There are some cases where making a blocking call
is acceptable. When in doubt, use MBUF_DONTWAIT.
@constant MBUF_WAITOK Allow a call to allocate an mbuf to block.
@function mbuf_setflags
@discussion Sets the set of set flags.
@param mbuf The mbuf.
- @param flags The flags that should be set, all other flags will be cleared.
+ @param flags The flags that should be set, all other flags will be
+ cleared. Certain flags such as MBUF_EXT cannot be altered.
@result 0 upon success otherwise the errno error.
*/
extern errno_t mbuf_setflags(mbuf_t mbuf, mbuf_flags_t flags);
@discussion Useful for setting or clearing individual flags. Easier
than calling mbuf_setflags(m, mbuf_flags(m) | M_FLAG).
@param mbuf The mbuf.
- @param flags The flags that should be set or cleared.
+ @param flags The flags that should be set or cleared. Certain flags
+ such as MBUF_EXT cannot be altered.
@param mask The mask controlling which flags will be modified.
@result 0 upon success otherwise the errno error.
*/
*/
extern void mbuf_pkthdr_setlen(mbuf_t mbuf, size_t len);
+#ifdef XNU_KERNEL_PRIVATE
+/*!
+ @function mbuf_pkthdr_maxlen
+ @discussion Retrieves the maximum length of data that may be stored
+ in this mbuf packet. This value assumes that the data pointer
+ was set to the start of the possible range for that pointer
+ for each mbuf in the packet chain
+ @param mbuf The mbuf.
+ @result The maximum lenght of data for this mbuf.
+ */
+extern size_t mbuf_pkthdr_maxlen(const mbuf_t mbuf);
+#endif /* XNU_KERNEL_PRIVATE */
+
/*!
@function mbuf_pkthdr_adjustlen
@discussion Adjusts the length of the packet in the packet header.
*/
extern u_int32_t mbuf_get_mhlen(void);
+/*!
+ @function mbuf_get_minclsize
+ @discussion This routine returns the minimum number of data bytes
+ before an external cluster is used. This is equivalent to the
+ legacy MINCLSIZE macro.
+ @result The minimum number of bytes before a cluster will be used.
+ */
+extern u_int32_t mbuf_get_minclsize(void);
+
/*!
@function mbuf_clear_csum_performed
@discussion Clears the hardware checksum flags and values.
extern void mbuf_tag_free(mbuf_t mbuf, mbuf_tag_id_t module_id,
mbuf_tag_type_t type);
+#ifdef KERNEL_PRIVATE
+/*
+ @function mbuf_add_drvaux
+ @discussion Allocate space for driver auxiliary data and attach it
+ to the packet (MBUF_PKTHDR is required.) This space is freed
+ when the mbuf is freed or when mbuf_del_drvaux is called.
+ Only one instance of driver auxiliary data may be attached to
+ a packet. Any attempt to add it to a packet already associated
+ with one will yield an error, and the existing one must first
+ be removed via mbuf_del_drvaux. The format and length of the
+ data depend largely on the family and sub-family. The system
+ makes no attempt to define and/or interpret the contents of
+ the data, and simply acts as a conduit between its producer
+ and consumer.
+ @param mbuf The mbuf to attach the auxiliary data to.
+ @param how Indicate whether you are willing to block and wait for
+ memory, if memory is not immediately available.
+ @param family The interface family as defined in net/kpi_interface.h.
+ @param subfamily The interface sub-family as defined in
+ net/kpi_interface.h.
+ @param length The length of the auxiliary data, must be greater than 0.
+ @param data_p Upon successful return, *data_p will point to the
+ space allocated for the data. Caller may set this to NULL.
+ @result 0 upon success otherwise the errno error.
+ */
+extern errno_t mbuf_add_drvaux(mbuf_t mbuf, mbuf_how_t how,
+ u_int32_t family, u_int32_t subfamily, size_t length, void **data_p);
+
+/*
+ @function mbuf_find_drvaux
+ @discussion Find the driver auxiliary data associated with a packet.
+ @param mbuf The mbuf the auxiliary data is attached to.
+ @param family_p Upon successful return, *family_p will contain
+ the interface family associated with the data, as defined
+ in net/kpi_interface.h. Caller may set this to NULL.
+ @param subfamily_p Upon successful return, *subfamily_p will contain
+ the interface family associated with the data, as defined
+ in net/kpi_interface.h. Caller may set this to NULL.
+ @param length_p Upon successful return, *length_p will contain
+ the length of the driver auxiliary data. Caller may
+ set this to NULL.
+ @param data_p Upon successful return, *data_p will point to the
+ space allocated for the data.
+ @result 0 upon success otherwise the errno error.
+ */
+extern errno_t mbuf_find_drvaux(mbuf_t mbuf, u_int32_t *family_p,
+ u_int32_t *subfamily_p, u_int32_t *length_p, void **data_p);
+
+/*
+ @function mbuf_del_drvaux
+ @discussion Remove and free any driver auxility data associated
+ with the packet.
+ @param mbuf The mbuf the auxiliary data is attached to.
+ */
+extern void mbuf_del_drvaux(mbuf_t mbuf);
+#endif /* KERNEL_PRIVATE */
+
/* mbuf stats */
/*!
*/
extern void mbuf_stats(struct mbuf_stat *stats);
-#ifdef KERNEL_PRIVATE
-/*
- @enum mbuf_priority_t
- @abstract Priority of a packet.
- @discussion Some mbufs represent packets containing application data.
- The priority of the application data is represented by the
- mbuf priority, as determined by the system.
- @constant MBUF_PRIORITY_NORMAL Indicates the packet contains
- normal priority data.
- @constant MBUF_PRIORITY_BACKGROUND Indicates the packet contains
- background priority data.
- */
-typedef enum {
- MBUF_PRIORITY_NORMAL = 0,
- MBUF_PRIORITY_BACKGROUND = 1
-} mbuf_priority_t;
-
-/*
- @function mbuf_get_priority
- @discussion Get the priority value of the packet.
- @param mbuf The mbuf to obtain the priority value from.
- @result The priority value of the packet.
- */
-extern mbuf_priority_t mbuf_get_priority(mbuf_t mbuf);
-/*
+/*!
@enum mbuf_traffic_class_t
@abstract Traffic class of a packet
@discussion Property that represent the category of traffic of a packet.
*/
typedef enum {
#ifdef XNU_KERNEL_PRIVATE
- MBUF_TC_NONE = -1,
+ MBUF_TC_UNSPEC = -1, /* Internal: not specified */
#endif
- MBUF_TC_BE = 0,
+ MBUF_TC_BE = 0,
MBUF_TC_BK = 1,
MBUF_TC_VI = 2,
MBUF_TC_VO = 3
+#ifdef XNU_KERNEL_PRIVATE
+ ,
+ MBUF_TC_MAX = 4 /* Internal: traffic class count */
+#endif
} mbuf_traffic_class_t;
-/*
+/*!
@function mbuf_get_traffic_class
@discussion Get the traffic class of an mbuf packet
@param mbuf The mbuf to get the traffic class of.
*/
extern mbuf_traffic_class_t mbuf_get_traffic_class(mbuf_t mbuf);
-/*
+/*!
@function mbuf_set_traffic_class
@discussion Set the traffic class of an mbuf packet.
@param mbuf The mbuf to set the traffic class on.
- @ac The traffic class
- @result 0 on success, EINVAL if bad paramater is passed
+ @tc The traffic class
+ @result 0 on success, EINVAL if bad parameter is passed
*/
extern errno_t mbuf_set_traffic_class(mbuf_t mbuf, mbuf_traffic_class_t tc);
+
+/*!
+ @function mbuf_is_traffic_class_privileged
+ @discussion Returns the privileged status of the traffic class
+ of the packet specified by the mbuf.
+ @param mbuf The mbuf to retrieve the status from.
+ @result Non-zero if privileged, 0 otherwise.
+ */
+extern int mbuf_is_traffic_class_privileged(mbuf_t mbuf);
+
+#ifdef KERNEL_PRIVATE
+
+/*!
+ @function mbuf_get_traffic_class_max_count
+ @discussion Returns the maximum number of mbuf traffic class types
+ @result The total count of mbuf traffic classes
+ */
+extern u_int32_t mbuf_get_traffic_class_max_count(void);
+
+/*!
+ @function mbuf_get_traffic_class_index
+ @discussion Returns the zero-based index of an mbuf traffic class value
+ @param tc The traffic class
+ @param index Pointer to the index value
+ @result 0 on success, EINVAL if bad parameter is passed
+ */
+extern errno_t mbuf_get_traffic_class_index(mbuf_traffic_class_t tc,
+ u_int32_t *index);
+
+/*!
+ @enum mbuf_svc_class_t
+ @abstract Service class of a packet
+ @discussion Property that represents the category of service
+ of a packet. This information may be used by the driver
+ and at the link level.
+ @constant MBUF_SC_BK_SYS "Background System-Initiated", high delay
+ tolerant, high loss tolerant, elastic flow, variable size &
+ long-lived.
+ @constant MBUF_SC_BK "Background", user-initiated, high delay tolerant,
+ high loss tolerant, elastic flow, variable size. This level
+ corresponds to WMM access class "BG", or MBUF_TC_BK.
+ @constant MBUF_SC_BE "Best Effort", unclassified/standard. This is
+ the default service class; pretty much a mix of everything.
+ This level corresponds to WMM access class "BE" or MBUF_TC_BE.
+ @constant MBUF_SC_RD
+ "Responsive Data", a notch higher than "Best Effort", medium
+ delay tolerant, medium loss tolerant, elastic flow, bursty,
+ long-lived.
+ @constant MBUF_SC_OAM "Operations, Administration, and Management",
+ medium delay tolerant, low-medium loss tolerant, elastic &
+ inelastic flows, variable size.
+ @constant MBUF_SC_AV "Multimedia Audio/Video Streaming", medium delay
+ tolerant, low-medium loss tolerant, elastic flow, constant
+ packet interval, variable rate & size.
+ @constant MBUF_SC_RV "Responsive Multimedia Audio/Video", low delay
+ tolerant, low-medium loss tolerant, elastic flow, variable
+ packet interval, rate and size.
+ @constant MBUF_SC_VI "Interactive Video", low delay tolerant, low-
+ medium loss tolerant, elastic flow, constant packet interval,
+ variable rate & size. This level corresponds to WMM access
+ class "VI" or MBUF_TC_VI.
+ @constant MBUF_SC_VO "Interactive Voice", low delay tolerant, low loss
+ tolerant, inelastic flow, constant packet rate, somewhat fixed
+ size. This level corresponds to WMM access class "VO" or
+ MBUF_TC_VO.
+ @constant MBUF_SC_CTL "Network Control", low delay tolerant, low loss
+ tolerant, inelastic flow, rate is short & burst, variable size.
+*/
+typedef enum {
+#ifdef XNU_KERNEL_PRIVATE
+ MBUF_SC_UNSPEC = -1, /* Internal: not specified */
+#endif
+ MBUF_SC_BK_SYS = 0x00080090, /* lowest class */
+ MBUF_SC_BK = 0x00100080,
+
+ MBUF_SC_BE = 0x00000000,
+ MBUF_SC_RD = 0x00180010,
+ MBUF_SC_OAM = 0x00200020,
+
+ MBUF_SC_AV = 0x00280120,
+ MBUF_SC_RV = 0x00300110,
+ MBUF_SC_VI = 0x00380100,
+
+ MBUF_SC_VO = 0x00400180,
+ MBUF_SC_CTL = 0x00480190, /* highest class */
+} mbuf_svc_class_t;
+
+/*!
+ @function mbuf_get_service_class_max_count
+ @discussion Returns the maximum number of mbuf service class types.
+ @result The total count of mbuf service classes.
+ */
+extern u_int32_t mbuf_get_service_class_max_count(void);
+
+/*!
+ @function mbuf_get_service_class_index
+ @discussion Returns the zero-based index of an mbuf service class value
+ @param sc The service class
+ @param index Pointer to the index value
+ @result 0 on success, EINVAL if bad parameter is passed
+ */
+extern errno_t mbuf_get_service_class_index(mbuf_svc_class_t sc,
+ u_int32_t *index);
+
+/*!
+ @function mbuf_get_service_class
+ @discussion Get the service class of an mbuf packet
+ @param mbuf The mbuf to get the service class of.
+ @result The service class
+*/
+extern mbuf_svc_class_t mbuf_get_service_class(mbuf_t mbuf);
+
+/*!
+ @function mbuf_set_servicec_class
+ @discussion Set the service class of an mbuf packet.
+ @param mbuf The mbuf to set the service class on.
+ @sc The service class
+ @result 0 on success, EINVAL if bad parameter is passed
+*/
+extern errno_t mbuf_set_service_class(mbuf_t mbuf, mbuf_svc_class_t sc);
+
+/*!
+ @function mbuf_is_service_class_privileged
+ @discussion Returns the privileged status of the service class
+ of the packet specified by the mbuf.
+ @param mbuf The mbuf to retrieve the status from.
+ @result Non-zero if privileged, 0 otherwise.
+ */
+extern int mbuf_is_service_class_privileged(mbuf_t mbuf);
+
+/*
+ @enum mbuf_pkthdr_aux_flags_t
+ @abstract Constants defining mbuf auxiliary flags. Only the flags
+ listed below can be retrieved.
+ @constant MBUF_PKTAUXF_INET_RESOLVE_RTR Indicates this is an ARP
+ request packet, whose target is the address of the default
+ IPv4 router.
+ @constant MBUF_PKTAUXF_INET6_RESOLVE_RTR Indicates this is an ICMPv6
+ Neighbor Solicitation packet, whose target is the address of
+ the default IPv6 router.
+ */
+enum {
+ MBUF_PKTAUXF_INET_RESOLVE_RTR = 0x0004,
+ MBUF_PKTAUXF_INET6_RESOLVE_RTR = 0x0008,
+};
+typedef u_int32_t mbuf_pkthdr_aux_flags_t;
+
+/*
+ @function mbuf_pkthdr_aux_flags
+ @discussion Returns the auxiliary flags of a packet.
+ @param mbuf The mbuf containing the packet header.
+ @param paux_flags Pointer to mbuf_pkthdr_aux_flags_t variable.
+ @result 0 upon success otherwise the errno error.
+*/
+extern errno_t mbuf_pkthdr_aux_flags(mbuf_t mbuf,
+ mbuf_pkthdr_aux_flags_t *paux_flags);
+
+/*
+ @function mbuf_get_driver_scratch
+ @discussion Returns a pointer to a driver specific area in the mbuf
+ @param m The mbuf whose driver scratch space is to be returned
+ @param area A pointer to a location to store the address of the
+ driver scratch space. This value is guaranteed to be 32-bit
+ aligned.
+ @param area_ln A pointer to a location to store the total length of
+ the memory location.
+*/
+extern errno_t mbuf_get_driver_scratch(mbuf_t m, u_int8_t **area,
+ size_t *area_ln);
#endif /* KERNEL_PRIVATE */
+#ifdef XNU_KERNEL_PRIVATE
+/*!
+ @function mbuf_pkt_list_len
+ @discussion Retrieves the length of the list of mbuf packets.
+ @param mbuf The mbuf.
+ @result The length of the mbuf packet list.
+ */
+extern size_t mbuf_pkt_list_len(const mbuf_t mbuf);
+
+/*!
+ @function mbuf_pkt_list_maxlen
+ @discussion Retrieves the maximum length of data that may be stored
+ in the list of mbuf packet. This value assumes that the data pointer
+ was set to the start of the possible range for that pointer
+ for each mbuf in the packet chain
+ @param mbuf The mbuf.
+ @result The maximum length of data for this mbuf.
+ */
+extern size_t mbuf_pkt_list_maxlen(const mbuf_t mbuf);
+#endif /* XNU_KERNEL_PRIVATE */
+
/* IF_QUEUE interaction */
#define IF_ENQUEUE_MBUF(ifq, m) { \