]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/kern/kpi_mbuf.c
xnu-7195.101.1.tar.gz
[apple/xnu.git] / bsd / kern / kpi_mbuf.c
index 7fb3d23d1ced8c397dad42bea54254461fd8258d..8e1d821ce3564e9fa5d0ec5a6e057412e1c0f732 100644 (file)
@@ -34,7 +34,6 @@
 #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>
@@ -53,7 +52,7 @@ static const mbuf_flags_t mbuf_cflags_mask = (MBUF_EXT);
 #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)
@@ -528,9 +527,13 @@ 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) */
-       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;
@@ -810,14 +813,12 @@ mbuf_outbound_finalize(struct mbuf *m, u_int32_t pf, size_t o)
                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:
@@ -979,7 +980,6 @@ mbuf_inet_cksum(mbuf_t mbuf, int protocol, u_int32_t offset, u_int32_t length,
        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)
@@ -992,45 +992,6 @@ mbuf_inet6_cksum(mbuf_t mbuf, int protocol, u_int32_t offset, u_int32_t length,
        *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
@@ -1821,11 +1782,11 @@ get_tx_compl_callback_index(mbuf_tx_compl_func callback)
 {
        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;
 }
@@ -1839,9 +1800,9 @@ m_get_tx_compl_callback(u_int32_t idx)
                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;
 }
 
@@ -1855,7 +1816,7 @@ mbuf_register_tx_compl_callback(mbuf_tx_compl_func callback)
                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) {
@@ -1873,7 +1834,7 @@ mbuf_register_tx_compl_callback(mbuf_tx_compl_func callback)
                }
        }
 unlock:
-       lck_rw_unlock_exclusive(mbuf_tx_compl_tbl_lock);
+       lck_rw_unlock_exclusive(&mbuf_tx_compl_tbl_lock);
 
        return error;
 }
@@ -1888,7 +1849,7 @@ mbuf_unregister_tx_compl_callback(mbuf_tx_compl_func callback)
                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;
@@ -1900,7 +1861,7 @@ mbuf_unregister_tx_compl_callback(mbuf_tx_compl_func callback)
                }
        }
 unlock:
-       lck_rw_unlock_exclusive(mbuf_tx_compl_tbl_lock);
+       lck_rw_unlock_exclusive(&mbuf_tx_compl_tbl_lock);
 
        return error;
 }
@@ -1989,9 +1950,9 @@ m_do_tx_compl_callback(struct mbuf *m, struct ifnet *ifp)
                        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,
@@ -2014,3 +1975,31 @@ m_do_tx_compl_callback(struct mbuf *m, struct ifnet *ifp)
        }
 #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;
+}