X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/91447636331957f3d9b5ca5b508f07c526b0074d..b7266188b87f3620ec3f9f717e57194a7dd989fe:/bsd/sys/mbuf.h diff --git a/bsd/sys/mbuf.h b/bsd/sys/mbuf.h index d7a417160..905d4119d 100644 --- a/bsd/sys/mbuf.h +++ b/bsd/sys/mbuf.h @@ -1,23 +1,29 @@ /* - * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2008 Apple Inc. All rights reserved. * - * @APPLE_LICENSE_HEADER_START@ + * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * - * The contents of this file constitute Original Code as defined in and - * are subject to the Apple Public Source License Version 1.1 (the - * "License"). You may not use this file except in compliance with the - * License. Please obtain a copy of the License at - * http://www.apple.com/publicsource and read it before using this file. + * 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 + * compliance with the License. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * 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. * - * This Original Code and all software distributed under the License are - * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * 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, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License. + * 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_LICENSE_HEADER_END@ + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ /* Copyright (c) 1998, 1999 Apple Computer, Inc. All Rights Reserved */ /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ @@ -68,6 +74,12 @@ * New version based on 4.4 * Purged old history */ +/* + * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce + * support for mandatory and extensible security protections. This notice + * is included in support of clause 2.2 (b) of the Apple Public License, + * Version 2.0. + */ #ifndef _SYS_MBUF_H_ #define _SYS_MBUF_H_ @@ -80,6 +92,10 @@ #include #include +#if PF_PKTHDR +#include +#endif /* PF_PKTHDR */ + /* * Mbufs are of a single size, MSIZE (machine/param.h), which * includes overhead. An mbuf may add a single "mbuf cluster" of size @@ -88,8 +104,21 @@ * at least MINCLSIZE of data must be stored. */ -#define MLEN (MSIZE - sizeof(struct m_hdr)) /* normal data len */ -#define MHLEN (MLEN - sizeof(struct pkthdr)) /* data len w/pkthdr */ +/* + * These macros are mapped to the appropriate KPIs, so that private code + * can be simply recompiled in order to be forward-compatible with future + * changes toward the struture sizes. + */ +#define MLEN mbuf_get_mlen() /* normal data len */ +#define MHLEN mbuf_get_mhlen() /* data len w/pkthdr */ + +/* + * The following _MLEN and _MHLEN macros are private to xnu. Private code + * that are outside of xnu must use the mbuf_get_{mlen,mhlen} routines since + * the sizes of the structures are dependent upon specific xnu configs. + */ +#define _MLEN (MSIZE - sizeof(struct m_hdr)) /* normal data len */ +#define _MHLEN (_MLEN - sizeof(struct pkthdr)) /* data len w/pkthdr */ #define MINCLSIZE (MHLEN + MLEN) /* smallest amount to put in cluster */ #define M_MAXCOMPRESS (MHLEN / 2) /* max amount to copy for compression */ @@ -100,22 +129,15 @@ * Macros for type conversion * mtod(m,t) - convert mbuf pointer to data pointer of correct type * dtom(x) - convert data pointer within mbuf to mbuf pointer (XXX) - * mtocl(x) - convert pointer within cluster to cluster index # - * cltom(x) - convert cluster # to ptr to beginning of cluster */ #define mtod(m,t) ((t)m_mtod(m)) #define dtom(x) m_dtom(x) -#define mtocl(x) m_mtocl(x) -#define cltom(x) m_cltom(x) - -#define MCLREF(p) m_mclref(p) -#define MCLUNREF(p) m_mclunref(p) /* header at beginning of each mbuf: */ struct m_hdr { struct mbuf *mh_next; /* next buffer in chain */ struct mbuf *mh_nextpkt; /* next chain in queue/record */ - long mh_len; /* amount of data in this mbuf */ + int32_t mh_len; /* amount of data in this mbuf */ caddr_t mh_data; /* location of data */ short mh_type; /* type of data in this mbuf */ short mh_flags; /* flags; see below */ @@ -139,19 +161,21 @@ struct pkthdr { /* variables for ip and tcp reassembly */ void *header; /* pointer to packet header */ /* variables for hardware checksum */ -#ifdef KERNEL_PRIVATE /* Note: csum_flags is used for hardware checksum and VLAN */ -#endif KERNEL_PRIVATE int csum_flags; /* flags regarding checksum */ int csum_data; /* data field used by csum routines */ - struct mbuf *aux; /* extra data buffer; ipsec/others */ -#ifdef KERNEL_PRIVATE + u_int tso_segsz; /* TSO segment size (actual MSS) */ u_short vlan_tag; /* VLAN tag, host byte order */ u_short socket_id; /* socket id */ -#else KERNEL_PRIVATE - u_int reserved1; /* for future use */ -#endif KERNEL_PRIVATE SLIST_HEAD(packet_tags, m_tag) tags; /* list of packet tags */ +#if PF_PKTHDR + /* + * Be careful; {en,dis}abling PF_PKTHDR will require xnu recompile; + * private code outside of xnu must use mbuf_get_mhlen() instead + * of MHLEN. + */ + struct pf_mtag pf_mtag; +#endif /* PF_PKTHDR */ }; @@ -164,8 +188,15 @@ struct m_ext { struct ext_refsq { /* references held */ struct ext_refsq *forward, *backward; } ext_refs; + struct ext_ref { + u_int32_t refcnt; + u_int32_t flags; + } *ext_refflags; }; +/* define m_ext to a type since it gets redefined below */ +typedef struct m_ext _m_ext_t; + struct mbuf { struct m_hdr m_hdr; union { @@ -173,10 +204,10 @@ struct mbuf { struct pkthdr MH_pkthdr; /* M_PKTHDR set */ union { struct m_ext MH_ext; /* M_EXT set */ - char MH_databuf[MHLEN]; + char MH_databuf[_MHLEN]; } MH_dat; } MH; - char M_databuf[MLEN]; /* !M_PKTHDR, !M_EXT */ + char M_databuf[_MLEN]; /* !M_PKTHDR, !M_EXT */ } M_dat; }; @@ -238,7 +269,11 @@ struct mbuf { /* VLAN tag present */ #define CSUM_VLAN_TAG_VALID 0x10000 /* vlan_tag field is valid */ -#endif KERNEL_PRIVATE + +/* TCP Segment Offloading requested on this mbuf */ +#define CSUM_TSO_IPV4 0x100000 /* This mbuf needs to be segmented by the NIC */ +#define CSUM_TSO_IPV6 0x200000 /* This mbuf needs to be segmented by the NIC */ +#endif /* KERNEL_PRIVATE */ /* mbuf types */ @@ -269,23 +304,6 @@ struct mbuf { #define M_DONTWAIT M_NOWAIT #define M_WAIT M_WAITOK -/* - * mbuf utility macros: - * - * MBUFLOCK(code) - * prevents a section of code from from being interrupted by network - * drivers. - */ - -#ifdef _KERN_LOCKS_H_ -extern lck_mtx_t * mbuf_mlock; -#else -extern void * mbuf_mlock; -#endif - -#define MBUF_LOCK() lck_mtx_lock(mbuf_mlock); -#define MBUF_UNLOCK() lck_mtx_unlock(mbuf_mlock); - /* * mbuf allocation/deallocation macros: * @@ -303,8 +321,6 @@ extern void * mbuf_mlock; #define MCHECK(m) #endif -extern struct mbuf *mfree; /* mbuf free list */ - #define MGET(m, how, type) ((m) = m_get((how), (type))) #define MGETHDR(m, how, type) ((m) = m_gethdr((how), (type))) @@ -341,6 +357,12 @@ union mbigcluster { char mbc_buf[NBPG]; }; +#define M16KCLBYTES (16 * 1024) + +union m16kcluster { + union m16kcluster *m16kcl_next; + char m16kcl_buf[M16KCLBYTES]; +}; #define MCLHASREFERENCE(m) m_mclhasreference(m) @@ -403,75 +425,164 @@ union mbigcluster { /* compatiblity with 4.3 */ #define m_copy(m, o, l) m_copym((m), (o), (l), M_DONTWAIT) +#define MBSHIFT 20 /* 1MB */ +#define GBSHIFT 30 /* 1GB */ + #endif /* KERNEL_PRIVATE */ /* - * Mbuf statistics. + * Mbuf statistics (legacy). */ -/* LP64todo - not 64-bit safe */ struct mbstat { - u_long m_mbufs; /* mbufs obtained from page pool */ - u_long m_clusters; /* clusters obtained from page pool */ - u_long m_spare; /* spare field */ - u_long m_clfree; /* free clusters */ - u_long m_drops; /* times failed to find space */ - u_long m_wait; /* times waited for space */ - u_long m_drain; /* times drained protocols for space */ - u_short m_mtypes[256]; /* type specific mbuf allocations */ - u_long m_mcfail; /* times m_copym failed */ - u_long m_mpfail; /* times m_pullup failed */ - u_long m_msize; /* length of an mbuf */ - u_long m_mclbytes; /* length of an mbuf cluster */ - u_long m_minclsize; /* min length of data to allocate a cluster */ - u_long m_mlen; /* length of data in an mbuf */ - u_long m_mhlen; /* length of data in a header mbuf */ - u_long m_bigclusters; /* clusters obtained from page pool */ - u_long m_bigclfree; /* free clusters */ - u_long m_bigmclbytes; /* length of an mbuf cluster */ + u_int32_t m_mbufs; /* mbufs obtained from page pool */ + u_int32_t m_clusters; /* clusters obtained from page pool */ + u_int32_t m_spare; /* spare field */ + u_int32_t m_clfree; /* free clusters */ + u_int32_t m_drops; /* times failed to find space */ + u_int32_t m_wait; /* times waited for space */ + u_int32_t m_drain; /* times drained protocols for space */ + u_short m_mtypes[256]; /* type specific mbuf allocations */ + u_int32_t m_mcfail; /* times m_copym failed */ + u_int32_t m_mpfail; /* times m_pullup failed */ + u_int32_t m_msize; /* length of an mbuf */ + u_int32_t m_mclbytes; /* length of an mbuf cluster */ + u_int32_t m_minclsize; /* min length of data to allocate a cluster */ + u_int32_t m_mlen; /* length of data in an mbuf */ + u_int32_t m_mhlen; /* length of data in a header mbuf */ + u_int32_t m_bigclusters; /* clusters obtained from page pool */ + u_int32_t m_bigclfree; /* free clusters */ + u_int32_t m_bigmclbytes; /* length of an mbuf cluster */ }; /* Compatibillity with 10.3 */ struct ombstat { - u_long m_mbufs; /* mbufs obtained from page pool */ - u_long m_clusters; /* clusters obtained from page pool */ - u_long m_spare; /* spare field */ - u_long m_clfree; /* free clusters */ - u_long m_drops; /* times failed to find space */ - u_long m_wait; /* times waited for space */ - u_long m_drain; /* times drained protocols for space */ - u_short m_mtypes[256]; /* type specific mbuf allocations */ - u_long m_mcfail; /* times m_copym failed */ - u_long m_mpfail; /* times m_pullup failed */ - u_long m_msize; /* length of an mbuf */ - u_long m_mclbytes; /* length of an mbuf cluster */ - u_long m_minclsize; /* min length of data to allocate a cluster */ - u_long m_mlen; /* length of data in an mbuf */ - u_long m_mhlen; /* length of data in a header mbuf */ + u_int32_t m_mbufs; /* mbufs obtained from page pool */ + u_int32_t m_clusters; /* clusters obtained from page pool */ + u_int32_t m_spare; /* spare field */ + u_int32_t m_clfree; /* free clusters */ + u_int32_t m_drops; /* times failed to find space */ + u_int32_t m_wait; /* times waited for space */ + u_int32_t m_drain; /* times drained protocols for space */ + u_short m_mtypes[256]; /* type specific mbuf allocations */ + u_int32_t m_mcfail; /* times m_copym failed */ + u_int32_t m_mpfail; /* times m_pullup failed */ + u_int32_t m_msize; /* length of an mbuf */ + u_int32_t m_mclbytes; /* length of an mbuf cluster */ + u_int32_t m_minclsize; /* min length of data to allocate a cluster */ + u_int32_t m_mlen; /* length of data in an mbuf */ + u_int32_t m_mhlen; /* length of data in a header mbuf */ }; -#ifdef KERNEL_PRIVATE /* - * pkthdr.aux type tags. + * mbuf class statistics. */ -struct mauxtag { - int af; - int type; -}; +#define MAX_MBUF_CNAME 15 + +#if defined(KERNEL_PRIVATE) +/* For backwards compatibility with 32-bit userland process */ +struct omb_class_stat { + char mbcl_cname[MAX_MBUF_CNAME + 1]; /* class name */ + u_int32_t mbcl_size; /* buffer size */ + u_int32_t mbcl_total; /* # of buffers created */ + u_int32_t mbcl_active; /* # of active buffers */ + u_int32_t mbcl_infree; /* # of available buffers */ + u_int32_t mbcl_slab_cnt; /* # of available slabs */ + u_int64_t mbcl_alloc_cnt; /* # of times alloc is called */ + u_int64_t mbcl_free_cnt; /* # of times free is called */ + u_int64_t mbcl_notified; /* # of notified wakeups */ + u_int64_t mbcl_purge_cnt; /* # of purges so far */ + u_int64_t mbcl_fail_cnt; /* # of allocation failures */ + u_int32_t mbcl_ctotal; /* total only for this class */ + /* + * Cache layer statistics + */ + u_int32_t mbcl_mc_state; /* cache state (see below) */ + u_int32_t mbcl_mc_cached; /* # of cached buffers */ + u_int32_t mbcl_mc_waiter_cnt; /* # waiters on the cache */ + u_int32_t mbcl_mc_wretry_cnt; /* # of wait retries */ + u_int32_t mbcl_mc_nwretry_cnt; /* # of no-wait retry attempts */ + u_int64_t mbcl_reserved[4]; /* for future use */ +} __attribute__((__packed__)); +#endif /* KERNEL_PRIVATE */ + +typedef struct mb_class_stat { + char mbcl_cname[MAX_MBUF_CNAME + 1]; /* class name */ + u_int32_t mbcl_size; /* buffer size */ + u_int32_t mbcl_total; /* # of buffers created */ + u_int32_t mbcl_active; /* # of active buffers */ + u_int32_t mbcl_infree; /* # of available buffers */ + u_int32_t mbcl_slab_cnt; /* # of available slabs */ +#if defined(KERNEL) || defined(__LP64__) + u_int32_t mbcl_pad; /* padding */ +#endif /* KERNEL || __LP64__ */ + u_int64_t mbcl_alloc_cnt; /* # of times alloc is called */ + u_int64_t mbcl_free_cnt; /* # of times free is called */ + u_int64_t mbcl_notified; /* # of notified wakeups */ + u_int64_t mbcl_purge_cnt; /* # of purges so far */ + u_int64_t mbcl_fail_cnt; /* # of allocation failures */ + u_int32_t mbcl_ctotal; /* total only for this class */ + /* + * Cache layer statistics + */ + u_int32_t mbcl_mc_state; /* cache state (see below) */ + u_int32_t mbcl_mc_cached; /* # of cached buffers */ + u_int32_t mbcl_mc_waiter_cnt; /* # waiters on the cache */ + u_int32_t mbcl_mc_wretry_cnt; /* # of wait retries */ + u_int32_t mbcl_mc_nwretry_cnt; /* # of no-wait retry attempts */ + u_int64_t mbcl_reserved[4]; /* for future use */ +} mb_class_stat_t; + +#define MCS_DISABLED 0 /* cache is permanently disabled */ +#define MCS_ONLINE 1 /* cache is online */ +#define MCS_PURGING 2 /* cache is being purged */ +#define MCS_OFFLINE 3 /* cache is offline (resizing) */ + +#if defined(KERNEL_PRIVATE) +/* For backwards compatibility with 32-bit userland process */ +struct omb_stat { + u_int32_t mbs_cnt; /* number of classes */ + struct omb_class_stat mbs_class[1]; /* class array */ +} __attribute__((__packed__)); +#endif /* KERNEL_PRIVATE */ + +typedef struct mb_stat { + u_int32_t mbs_cnt; /* number of classes */ +#if defined(KERNEL) || defined(__LP64__) + u_int32_t mbs_pad; /* padding */ +#endif /* KERNEL || __LP64__ */ + mb_class_stat_t mbs_class[1]; /* class array */ +} mb_stat_t; + +#ifdef KERNEL_PRIVATE #ifdef KERNEL extern union mcluster *mbutl; /* virtual address of mclusters */ extern union mcluster *embutl; /* ending virtual address of mclusters */ -extern short *mclrefcnt; /* cluster reference counts */ -extern int *mcl_paddr; /* physical addresses of clusters */ extern struct mbstat mbstat; /* statistics */ -extern int nmbclusters; /* number of mapped clusters */ -extern union mcluster *mclfree; /* free mapped cluster list */ +extern unsigned int nmbclusters; /* number of mapped clusters */ +extern int njcl; /* # of clusters for jumbo sizes */ +extern int njclbytes; /* size of a jumbo cluster */ extern int max_linkhdr; /* largest link-level header */ extern int max_protohdr; /* largest protocol header */ extern int max_hdr; /* largest link+protocol header */ extern int max_datalen; /* MHLEN - max_hdr */ __BEGIN_DECLS +/* Not exported */ +__private_extern__ unsigned int mbuf_default_ncl(int, uint64_t); +__private_extern__ void mbinit(void); +__private_extern__ struct mbuf *m_clattach(struct mbuf *, int, caddr_t, + void (*)(caddr_t , u_int, caddr_t), u_int, caddr_t, int); +__private_extern__ caddr_t m_bigalloc(int); +__private_extern__ void m_bigfree(caddr_t, u_int, caddr_t); +__private_extern__ struct mbuf *m_mbigget(struct mbuf *, int); +__private_extern__ caddr_t m_16kalloc(int); +__private_extern__ void m_16kfree(caddr_t, u_int, caddr_t); +__private_extern__ struct mbuf *m_m16kget(struct mbuf *, int); +__private_extern__ void mbuf_growth_aggressive(void); +__private_extern__ void mbuf_growth_normal(void); + +/* Exported */ struct mbuf *m_copym(struct mbuf *, int, int, int); struct mbuf *m_split(struct mbuf *, int, int); struct mbuf *m_free(struct mbuf *); @@ -490,10 +601,8 @@ int m_freem_list(struct mbuf *); struct mbuf *m_devget(char *, int, int, struct ifnet *, void (*)(const void *, void *, size_t)); char *mcl_to_paddr(char *); struct mbuf *m_pulldown(struct mbuf*, int, int, int*); -struct mbuf *m_aux_add(struct mbuf *, int, int); -struct mbuf *m_aux_find(struct mbuf *, int, int); -void m_aux_delete(struct mbuf *, struct mbuf *); +extern struct mbuf *m_getcl(int, int, int); struct mbuf *m_mclget(struct mbuf *, int); caddr_t m_mclalloc(int); void m_mclfree(caddr_t p); @@ -511,11 +620,14 @@ union mcluster *m_cltom(int ); int m_trailingspace(struct mbuf *); int m_leadingspace(struct mbuf *); +struct mbuf *m_normalize(struct mbuf *m); void m_mchtype(struct mbuf *m, int t); void m_mcheck(struct mbuf*); -void m_copyback(struct mbuf *, int , int , caddr_t); -void m_copydata(struct mbuf *, int , int , caddr_t); +extern void m_copyback(struct mbuf *, int , int , const void *); +extern struct mbuf *m_copyback_cow(struct mbuf *, int, int, const void *, int); +extern int m_makewritable(struct mbuf **, int, int, int); +void m_copydata(struct mbuf *, int , int , void *); struct mbuf* m_dup(struct mbuf *m, int how); void m_cat(struct mbuf *, struct mbuf *); struct mbuf *m_copym_with_hdrs(struct mbuf*, int, int, int, struct mbuf**, int*); @@ -561,7 +673,13 @@ enum { KERNEL_TAG_TYPE_DUMMYNET = 1, KERNEL_TAG_TYPE_DIVERT = 2, KERNEL_TAG_TYPE_IPFORWARD = 3, - KERNEL_TAG_TYPE_IPFILT = 4 + KERNEL_TAG_TYPE_IPFILT = 4, + KERNEL_TAG_TYPE_MACLABEL = 5, + KERNEL_TAG_TYPE_MAC_POLICY_LABEL = 6, + KERNEL_TAG_TYPE_ENCAP = 8, + KERNEL_TAG_TYPE_INET6 = 9, + KERNEL_TAG_TYPE_IPSEC = 10, + KERNEL_TAG_TYPE_PF = 11 }; /* @@ -602,5 +720,5 @@ __END_DECLS #endif /* KERNEL_PRIVATE */ #ifdef KERNEL #include -#endif +#endif /* KERNEL */ #endif /* !_SYS_MBUF_H_ */