#include <sys/socket.h>
#include <kern/debug.h>
#include <libkern/OSAtomic.h>
-#include <kern/kalloc.h>
#include <string.h>
#include <net/dlil.h>
#include <netinet/in.h>
#define MAX_MBUF_TX_COMPL_FUNC 32
mbuf_tx_compl_func
mbuf_tx_compl_table[MAX_MBUF_TX_COMPL_FUNC];
-extern lck_rw_t *mbuf_tx_compl_tbl_lock;
+extern lck_rw_t mbuf_tx_compl_tbl_lock;
u_int32_t mbuf_tx_compl_index = 0;
#if (DEVELOPMENT || DEBUG)
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) */
- int count;
+ size_t count;
mbuf_t m = m0;
+ if (off >= INT_MAX || len >= INT_MAX) {
+ return EINVAL;
+ }
+
while (off > 0) {
if (m == 0) {
return EINVAL;
break;
case PF_INET6:
-#if INET6
/*
* Checksum offload should not have been enabled when
* extension headers exist; indicate that the callee
* should skip such case by setting optlen to -1.
*/
(void) in6_finalize_cksum(m, o, -1, -1, m->m_pkthdr.csum_flags);
-#endif /* INET6 */
break;
default:
return 0;
}
-#if INET6
errno_t
mbuf_inet6_cksum(mbuf_t mbuf, int protocol, u_int32_t offset, u_int32_t length,
u_int16_t *csum)
*csum = inet6_cksum(mbuf, protocol, offset, length);
return 0;
}
-#else /* INET6 */
-errno_t
-mbuf_inet6_cksum(__unused mbuf_t mbuf, __unused int protocol,
- __unused u_int32_t offset, __unused u_int32_t length,
- __unused u_int16_t *csum)
-{
- panic("mbuf_inet6_cksum() doesn't exist on this platform\n");
- return 0;
-}
-
-u_int16_t
-inet6_cksum(__unused struct mbuf *m, __unused unsigned int nxt,
- __unused unsigned int off, __unused unsigned int len)
-{
- panic("inet6_cksum() doesn't exist on this platform\n");
- return 0;
-}
-
-void nd6_lookup_ipv6(void);
-void
-nd6_lookup_ipv6(void)
-{
- panic("nd6_lookup_ipv6() doesn't exist on this platform\n");
-}
-
-int
-in6addr_local(__unused struct in6_addr *a)
-{
- panic("in6addr_local() doesn't exist on this platform\n");
- return 0;
-}
-
-void nd6_storelladdr(void);
-void
-nd6_storelladdr(void)
-{
- panic("nd6_storelladdr() doesn't exist on this platform\n");
-}
-#endif /* INET6 */
/*
* Mbuf tag KPIs
{
u_int32_t i;
- lck_rw_lock_shared(mbuf_tx_compl_tbl_lock);
+ lck_rw_lock_shared(&mbuf_tx_compl_tbl_lock);
i = get_tx_compl_callback_index_locked(callback);
- lck_rw_unlock_shared(mbuf_tx_compl_tbl_lock);
+ lck_rw_unlock_shared(&mbuf_tx_compl_tbl_lock);
return i;
}
ASSERT(0);
return NULL;
}
- lck_rw_lock_shared(mbuf_tx_compl_tbl_lock);
+ lck_rw_lock_shared(&mbuf_tx_compl_tbl_lock);
cb = mbuf_tx_compl_table[idx];
- lck_rw_unlock_shared(mbuf_tx_compl_tbl_lock);
+ lck_rw_unlock_shared(&mbuf_tx_compl_tbl_lock);
return cb;
}
return EINVAL;
}
- lck_rw_lock_exclusive(mbuf_tx_compl_tbl_lock);
+ lck_rw_lock_exclusive(&mbuf_tx_compl_tbl_lock);
i = get_tx_compl_callback_index_locked(callback);
if (i != -1) {
}
}
unlock:
- lck_rw_unlock_exclusive(mbuf_tx_compl_tbl_lock);
+ lck_rw_unlock_exclusive(&mbuf_tx_compl_tbl_lock);
return error;
}
return EINVAL;
}
- lck_rw_lock_exclusive(mbuf_tx_compl_tbl_lock);
+ lck_rw_lock_exclusive(&mbuf_tx_compl_tbl_lock);
/* assume the worst */
error = ENOENT;
}
}
unlock:
- lck_rw_unlock_exclusive(mbuf_tx_compl_tbl_lock);
+ lck_rw_unlock_exclusive(&mbuf_tx_compl_tbl_lock);
return error;
}
continue;
}
- lck_rw_lock_shared(mbuf_tx_compl_tbl_lock);
+ lck_rw_lock_shared(&mbuf_tx_compl_tbl_lock);
callback = mbuf_tx_compl_table[i];
- lck_rw_unlock_shared(mbuf_tx_compl_tbl_lock);
+ lck_rw_unlock_shared(&mbuf_tx_compl_tbl_lock);
if (callback != NULL) {
callback(m->m_pkthdr.pkt_compl_context,
}
#endif /* (DEBUG || DEVELOPMENT) */
}
+
+errno_t
+mbuf_get_keepalive_flag(mbuf_t m, boolean_t *is_keepalive)
+{
+ if (m == NULL || is_keepalive == NULL || !(m->m_flags & M_PKTHDR)) {
+ return EINVAL;
+ }
+
+ *is_keepalive = (m->m_pkthdr.pkt_flags & PKTF_KEEPALIVE);
+
+ return 0;
+}
+
+errno_t
+mbuf_set_keepalive_flag(mbuf_t m, boolean_t is_keepalive)
+{
+ if (m == NULL || !(m->m_flags & M_PKTHDR)) {
+ return EINVAL;
+ }
+
+ if (is_keepalive) {
+ m->m_pkthdr.pkt_flags |= PKTF_KEEPALIVE;
+ } else {
+ m->m_pkthdr.pkt_flags &= ~PKTF_KEEPALIVE;
+ }
+
+ return 0;
+}