/*
- * Copyright (c) 2004-2007 Apple Inc. All rights reserved.
+ * Copyright (c) 2004-2010 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
#include <kern/kalloc.h>
#include <string.h>
#include <netinet/in.h>
-#include "kpi_mbuf_internal.h"
+
+#include "net/net_str_id.h"
static const mbuf_flags_t mbuf_flags_mask = MBUF_EXT | MBUF_PKTHDR | MBUF_EOR |
MBUF_BCAST | MBUF_MCAST | MBUF_FRAG | MBUF_FIRSTFRAG |
addr64_t mbuf_data_to_physical(void* ptr)
{
- return (addr64_t)(intptr_t)mcl_to_paddr(ptr);
+ return (addr64_t)(uintptr_t)mcl_to_paddr(ptr);
}
errno_t mbuf_get(mbuf_how_t how, mbuf_type_t type, mbuf_t *mbuf)
return 0;
}
+mbuf_t
+mbuf_concatenate(mbuf_t dst, mbuf_t src)
+{
+ if (dst == NULL)
+ return (NULL);
+
+ m_cat(dst, src);
+
+ /* return dst as is in the current implementation */
+ return (dst);
+}
errno_t mbuf_copydata(const mbuf_t m0, size_t off, size_t len, void* out_data)
{
/* Copied m_copydata, added error handling (don't just panic) */
extern void in_delayed_cksum_offset(struct mbuf *m, int ip_offset);
void
-mbuf_outbound_finalize(mbuf_t mbuf, u_long protocol_family, size_t protocol_offset)
+mbuf_outbound_finalize(mbuf_t mbuf, u_int32_t protocol_family, size_t protocol_offset)
{
if ((mbuf->m_pkthdr.csum_flags &
(CSUM_DELAY_DATA | CSUM_DELAY_IP | CSUM_TCP_SUM16)) == 0)
* Hardware checksum code looked pretty IPv4 specific.
*/
if ((mbuf->m_pkthdr.csum_flags & (CSUM_DELAY_DATA | CSUM_DELAY_IP)) != 0)
- panic("mbuf_outbound_finalize - CSUM flags set for non-IPv4 packet (%lu)!\n", protocol_family);
+ panic("mbuf_outbound_finalize - CSUM flags set for non-IPv4 packet (%u)!\n", protocol_family);
}
}
return 0;
}
+static const mbuf_tso_request_flags_t mbuf_valid_tso_request_flags =
+ MBUF_TSO_IPV4 | MBUF_TSO_IPV6;
+
+errno_t
+mbuf_get_tso_requested(
+ mbuf_t mbuf,
+ mbuf_tso_request_flags_t *request,
+ u_int32_t *value)
+{
+ if (mbuf == NULL || (mbuf->m_flags & M_PKTHDR) == 0 ||
+ request == NULL || value == NULL)
+ return EINVAL;
+
+ *request = mbuf->m_pkthdr.csum_flags;
+ *request &= mbuf_valid_tso_request_flags;
+ if (*request && value != NULL)
+ *value = mbuf->m_pkthdr.tso_segsz;
+
+ return 0;
+}
+
errno_t
mbuf_get_csum_requested(
mbuf_t mbuf,
* Mbuf tag KPIs
*/
-struct mbuf_tag_id_entry {
- SLIST_ENTRY(mbuf_tag_id_entry) next;
- mbuf_tag_id_t id;
- char string[];
-};
-
-#define MBUF_TAG_ID_ENTRY_SIZE(__str) \
- ((size_t)&(((struct mbuf_tag_id_entry*)0)->string[0]) + \
- strlen(__str) + 1)
-
-#define MTAG_FIRST_ID 1000
-static mbuf_tag_id_t mtag_id_next = MTAG_FIRST_ID;
-static SLIST_HEAD(,mbuf_tag_id_entry) mtag_id_list = {NULL};
-static lck_mtx_t *mtag_id_lock = NULL;
-
-__private_extern__ void
-mbuf_tag_id_first_last(
- mbuf_tag_id_t * first,
- mbuf_tag_id_t * last)
-{
- *first = MTAG_FIRST_ID;
- *last = mtag_id_next - 1;
-}
-
-__private_extern__ errno_t
-mbuf_tag_id_find_internal(
- const char *string,
- mbuf_tag_id_t *out_id,
- int create)
-{
- struct mbuf_tag_id_entry *entry = NULL;
-
-
- *out_id = 0;
-
- if (string == NULL || out_id == NULL) {
- return EINVAL;
- }
-
- /* Don't bother allocating the lock if we're only doing a lookup */
- if (create == 0 && mtag_id_lock == NULL)
- return ENOENT;
-
- /* Allocate lock if necessary */
- if (mtag_id_lock == NULL) {
- lck_grp_attr_t *grp_attrib = NULL;
- lck_attr_t *lck_attrb = NULL;
- lck_grp_t *lck_group = NULL;
- lck_mtx_t *new_lock = NULL;
-
- grp_attrib = lck_grp_attr_alloc_init();
- lck_group = lck_grp_alloc_init("mbuf_tag_allocate_id", grp_attrib);
- lck_grp_attr_free(grp_attrib);
- lck_attrb = lck_attr_alloc_init();
-
- new_lock = lck_mtx_alloc_init(lck_group, lck_attrb);
- if (!OSCompareAndSwap((UInt32)0, (UInt32)new_lock, (UInt32*)&mtag_id_lock)) {
- /*
- * If the atomic swap fails, someone else has already
- * done this work. We can free the stuff we allocated.
- */
- lck_mtx_free(new_lock, lck_group);
- lck_grp_free(lck_group);
- }
- lck_attr_free(lck_attrb);
- }
-
- /* Look for an existing entry */
- lck_mtx_lock(mtag_id_lock);
- SLIST_FOREACH(entry, &mtag_id_list, next) {
- if (strncmp(string, entry->string, strlen(string) + 1) == 0) {
- break;
- }
- }
-
- if (entry == NULL) {
- if (create == 0) {
- lck_mtx_unlock(mtag_id_lock);
- return ENOENT;
- }
-
- entry = kalloc(MBUF_TAG_ID_ENTRY_SIZE(string));
- if (entry == NULL) {
- lck_mtx_unlock(mtag_id_lock);
- return ENOMEM;
- }
-
- strlcpy(entry->string, string, strlen(string)+1);
- entry->id = mtag_id_next;
- mtag_id_next++;
- SLIST_INSERT_HEAD(&mtag_id_list, entry, next);
- }
- lck_mtx_unlock(mtag_id_lock);
-
- *out_id = entry->id;
-
- return 0;
-}
+#define MTAG_FIRST_ID FIRST_KPI_STR_ID
errno_t
mbuf_tag_id_find(
const char *string,
mbuf_tag_id_t *out_id)
{
- return mbuf_tag_id_find_internal(string, out_id, 1);
+ return net_str_id_find_internal(string, out_id, NSI_MBUF_TAG, 1);
}
errno_t
void** data_p)
{
struct m_tag *tag;
+ u_int32_t mtag_id_first, mtag_id_last;
if (data_p != NULL)
*data_p = NULL;
/* Sanity check parameters */
- if (mbuf == NULL || (mbuf->m_flags & M_PKTHDR) == 0 || id < MTAG_FIRST_ID ||
- id >= mtag_id_next || length < 1 || (length & 0xffff0000) != 0 ||
+ (void) net_str_id_first_last(&mtag_id_first, &mtag_id_last, NSI_MBUF_TAG);
+ if (mbuf == NULL || (mbuf->m_flags & M_PKTHDR) == 0 || id < mtag_id_first ||
+ id > mtag_id_last || length < 1 || (length & 0xffff0000) != 0 ||
data_p == NULL) {
return EINVAL;
}
void** data_p)
{
struct m_tag *tag;
+ u_int32_t mtag_id_first, mtag_id_last;
if (length != NULL)
*length = 0;
*data_p = NULL;
/* Sanity check parameters */
- if (mbuf == NULL || (mbuf->m_flags & M_PKTHDR) == 0 || id < MTAG_FIRST_ID ||
- id >= mtag_id_next || length == NULL || data_p == NULL) {
+ (void) net_str_id_first_last(&mtag_id_first, &mtag_id_last, NSI_MBUF_TAG);
+ if (mbuf == NULL || (mbuf->m_flags & M_PKTHDR) == 0 || id < mtag_id_first ||
+ id > mtag_id_last || length == NULL || data_p == NULL) {
return EINVAL;
}
mbuf_tag_type_t type)
{
struct m_tag *tag;
+ u_int32_t mtag_id_first, mtag_id_last;
- if (mbuf == NULL || (mbuf->m_flags & M_PKTHDR) == 0 || id < MTAG_FIRST_ID ||
- id >= mtag_id_next)
+ /* Sanity check parameters */
+ (void) net_str_id_first_last(&mtag_id_first, &mtag_id_last, NSI_MBUF_TAG);
+ if (mbuf == NULL || (mbuf->m_flags & M_PKTHDR) == 0 || id < mtag_id_first ||
+ id > mtag_id_last)
return;
tag = m_tag_locate(mbuf, id, type, NULL);
return result;
}
-#if !INET6
-void inet6_unsupported(void);
+u_int32_t
+mbuf_get_mlen(void)
+{
+ return (_MLEN);
+}
+
+u_int32_t
+mbuf_get_mhlen(void)
+{
+ return (_MHLEN);
+}
+
+mbuf_priority_t
+mbuf_get_priority(struct mbuf *m)
+{
+#if !PKT_PRIORITY
+#pragma unused(m)
+ return (MBUF_PRIORITY_NORMAL);
+#else /* PKT_PRIORITY */
+ mbuf_priority_t prio = MBUF_PRIORITY_NORMAL;
+
+ if (m == NULL || !(m->m_flags & M_PKTHDR))
+ return (prio);
+
+ /* Defaults to normal; ignore anything else but background */
+ if (m->m_pkthdr.prio == MBUF_PRIORITY_BACKGROUND)
+ prio = MBUF_PRIORITY_BACKGROUND;
+
+ return (prio);
+#endif /* PKT_PRIORITY */
+}
+
+mbuf_traffic_class_t
+mbuf_get_traffic_class(mbuf_t m)
+{
+#if !PKT_PRIORITY
+#pragma unused(m)
+ return (MBUF_TC_BE);
+#else /* PKT_PRIORITY */
+ mbuf_priority_t prio = MBUF_TC_BE;
+
+ if (m == NULL || !(m->m_flags & M_PKTHDR))
+ return (prio);
+
+ if (m->m_pkthdr.prio <= MBUF_TC_VO)
+ prio = m->m_pkthdr.prio;
+
+ return (prio);
+#endif /* PKT_PRIORITY */
+}
-void inet6_unsupported(void)
+errno_t
+mbuf_set_traffic_class(mbuf_t m, mbuf_traffic_class_t tc)
{
- *((int *)0) = 0x1;
+#if !PKT_PRIORITY
+#pragma unused(m)
+#pragma unused(tc)
+ return 0;
+#else /* PKT_PRIORITY */
+ errno_t error = 0;
+
+ if (m == NULL || !(m->m_flags & M_PKTHDR))
+ return EINVAL;
+
+ switch (tc) {
+ case MBUF_TC_BE:
+ case MBUF_TC_BK:
+ case MBUF_TC_VI:
+ case MBUF_TC_VO:
+ m->m_pkthdr.prio = tc;
+ break;
+ default:
+ error = EINVAL;
+ break;
+ }
+ return error;
+#endif /* PKT_PRIORITY */
}
-#endif /* !INET6 */