#ifndef _FBSD_COMPAT_SYS_MBUF_H_
#define _FBSD_COMPAT_SYS_MBUF_H_
#include <sys/queue.h>
#include <sys/systm.h>
#include <vm/uma.h>
#define MHSIZE __offsetof(struct mbuf, m_dat)
#define MPKTHSIZE __offsetof(struct mbuf, m_pktdat)
#define MLEN ((int)(MSIZE - MHSIZE))
#define MHLEN ((int)(MSIZE - MPKTHSIZE))
#define MINCLSIZE (MHLEN + 1)
#define MBTOM(how) (how)
#define M_DONTWAIT M_NOWAIT
#define M_TRYWAIT M_WAITOK
#define M_WAIT M_WAITOK
#define MT_DATA 1
#define MT_NOINIT 255
#define M_EXT 0x00000001
#define M_PKTHDR 0x00000002
#define M_EOR 0x00000004
#define M_RDONLY 0x00000008
#define M_BCAST 0x00000010
#define M_MCAST 0x00000020
#define M_PROMISC 0x00000040
#define M_VLANTAG 0x00000080
#define M_UNUSED_8 0x00000100
#define M_NOFREE 0x00000200
#define M_PROTO1 0x00001000
#define M_PROTO2 0x00002000
#define M_PROTO3 0x00004000
#define M_PROTO4 0x00008000
#define M_PROTO5 0x00010000
#define M_PROTO6 0x00020000
#define M_PROTO7 0x00040000
#define M_PROTO8 0x00080000
#define M_PROTO9 0x00100000
#define M_PROTO10 0x00200000
#define M_PROTO11 0x00400000
#define M_PROTO12 0x00800000
#define M_PROTOFLAGS \
(M_PROTO1|M_PROTO2|M_PROTO3|M_PROTO4|M_PROTO5|M_PROTO6|M_PROTO7|M_PROTO8|\
M_PROTO9|M_PROTO10|M_PROTO11|M_PROTO12)
#define M_COPYFLAGS \
(M_PKTHDR|M_EOR|M_RDONLY|M_BCAST|M_MCAST|M_PROMISC|M_VLANTAG| \
M_PROTOFLAGS)
#define M_MOVE_PKTHDR(to, from) m_move_pkthdr((to), (from))
#define MGET(m, how, type) ((m) = m_get((how), (type)))
#define MGETHDR(m, how, type) ((m) = m_gethdr((how), (type)))
#define MCLGET(m, how) m_clget((m), (how))
#define m_getm(m, len, how, type) \
m_getm2((m), (len), (how), (type), M_PKTHDR)
#define mtod(m, type) ((type)((m)->m_data))
#define mtodo(m, o) ((void *)(((m)->m_data) + (o)))
#define M_ASSERTPKTHDR(m) KASSERT(m != NULL && m->m_flags & M_PKTHDR, \
("%s: no mbuf packet header!", __func__))
#define M_HASHTYPE_HASHPROP 0x80
#define M_HASHTYPE_HASH(t) (M_HASHTYPE_HASHPROP | (t))
#define M_HASHTYPE_NONE 0
#define M_HASHTYPE_RSS_IPV4 M_HASHTYPE_HASH(1)
#define M_HASHTYPE_RSS_TCP_IPV4 M_HASHTYPE_HASH(2)
#define M_HASHTYPE_RSS_IPV6 M_HASHTYPE_HASH(3)
#define M_HASHTYPE_RSS_TCP_IPV6 M_HASHTYPE_HASH(4)
#define M_HASHTYPE_RSS_IPV6_EX M_HASHTYPE_HASH(5)
#define M_HASHTYPE_RSS_TCP_IPV6_EX M_HASHTYPE_HASH(6)
#define M_HASHTYPE_RSS_UDP_IPV4 M_HASHTYPE_HASH(7)
#define M_HASHTYPE_RSS_UDP_IPV4_EX M_HASHTYPE_HASH(8)
#define M_HASHTYPE_RSS_UDP_IPV6 M_HASHTYPE_HASH(9)
#define M_HASHTYPE_RSS_UDP_IPV6_EX M_HASHTYPE_HASH(10)
#define M_HASHTYPE_OPAQUE 63
#define M_HASHTYPE_OPAQUE_HASH M_HASHTYPE_HASH(M_HASHTYPE_OPAQUE)
#define M_HASHTYPE_CLEAR(m) ((m)->m_pkthdr.rsstype = 0)
#define M_HASHTYPE_GET(m) ((m)->m_pkthdr.rsstype)
#define M_HASHTYPE_SET(m, v) ((m)->m_pkthdr.rsstype = (v))
#define M_HASHTYPE_TEST(m, v) (M_HASHTYPE_GET(m) == (v))
#define M_HASHTYPE_ISHASH(m) (M_HASHTYPE_GET(m) & M_HASHTYPE_HASHPROP)
#define MBUF_CHECKSLEEP(how) do { } while (0)
#define MTAG_PERSISTENT 0x800
#define M_COPYALL 1000000000
#define EXT_CLUSTER 1
#define EXT_JUMBOP 4
#define EXT_JUMBO9 5
#define EXT_NET_DRV 100
#define EXT_EXTREF 255
#define EXT_FLAG_EMBREF 0x000001
#define EXT_FLAG_EXTREF 0x000002
#define CSUM_IP 0x00000001
#define CSUM_IP_UDP 0x00000002
#define CSUM_IP_TCP 0x00000004
#define CSUM_IP_SCTP 0x00000008
#define CSUM_IP_TSO 0x00000010
#define CSUM_IP_ISCSI 0x00000020
#define CSUM_IP6_UDP 0x00000200
#define CSUM_IP6_TCP 0x00000400
#define CSUM_IP6_SCTP 0x00000800
#define CSUM_IP6_TSO 0x00001000
#define CSUM_IP6_ISCSI 0x00002000
#define CSUM_L3_CALC 0x01000000
#define CSUM_L3_VALID 0x02000000
#define CSUM_L4_CALC 0x04000000
#define CSUM_L4_VALID 0x08000000
#define CSUM_L5_CALC 0x10000000
#define CSUM_L5_VALID 0x20000000
#define CSUM_COALESCED 0x40000000
#define CSUM_IP_CHECKED CSUM_L3_CALC
#define CSUM_IP_VALID CSUM_L3_VALID
#define CSUM_DATA_VALID CSUM_L4_VALID
#define CSUM_PSEUDO_HDR CSUM_L4_CALC
#define CSUM_SCTP_VALID CSUM_L4_VALID
#define CSUM_DELAY_DATA (CSUM_TCP|CSUM_UDP)
#define CSUM_DELAY_IP CSUM_IP
#define CSUM_DELAY_DATA_IPV6 (CSUM_TCP_IPV6|CSUM_UDP_IPV6)
#define CSUM_DATA_VALID_IPV6 CSUM_DATA_VALID
#define CSUM_TCP CSUM_IP_TCP
#define CSUM_UDP CSUM_IP_UDP
#define CSUM_SCTP CSUM_IP_SCTP
#define CSUM_TSO (CSUM_IP_TSO|CSUM_IP6_TSO)
#define CSUM_UDP_IPV6 CSUM_IP6_UDP
#define CSUM_TCP_IPV6 CSUM_IP6_TCP
#define CSUM_SCTP_IPV6 CSUM_IP6_SCTP
#define MEXTADD(m, buf, size, free, arg1, arg2, flags, type) \
m_extadd((m), (caddr_t)(buf), (size), (free),(arg1),(arg2),(flags), (type))
extern int max_linkhdr;
extern int max_protohdr;
extern int max_hdr;
extern int max_datalen;
struct pkthdr {
struct ifnet* rcvif;
SLIST_HEAD(packet_tags, m_tag) tags;
int len;
uint32_t flowid;
uint64_t csum_flags;
int csum_data;
uint8_t rsstype;
uint16_t tso_segsz;
uint16_t ether_vtag;
union {
uintptr_t unintptr[1];
void* ptr;
} PH_loc;
};
struct m_tag {
SLIST_ENTRY(m_tag) m_tag_link;
u_int16_t m_tag_id;
u_int16_t m_tag_len;
u_int32_t m_tag_cookie;
void (*m_tag_free)(struct m_tag*);
};
struct m_ext {
union {
volatile u_int ext_count;
volatile u_int *ext_cnt;
};
caddr_t ext_buf;
uint32_t ext_size;
uint32_t ext_type:8,
ext_flags:24;
};
struct mbuf {
union {
struct mbuf *m_next;
SLIST_ENTRY(mbuf) m_slist;
STAILQ_ENTRY(mbuf) m_stailq;
};
union {
struct mbuf *m_nextpkt;
SLIST_ENTRY(mbuf) m_slistpkt;
STAILQ_ENTRY(mbuf) m_stailqpkt;
};
caddr_t m_data;
int32_t m_len;
uint32_t m_type:8,
m_flags:24;
union {
struct {
struct pkthdr MH_pkthdr;
union {
struct m_ext MH_ext;
char MH_databuf[0] __aligned(8);
} MH_dat;
} MH;
char M_databuf[0] __aligned(8);
} M_dat;
};
#define m_pkthdr M_dat.MH.MH_pkthdr
#define m_ext M_dat.MH.MH_dat.MH_ext
#define m_pktdat M_dat.MH.MH_dat.MH_databuf
#define m_dat M_dat.M_databuf
int m_init(struct mbuf *m, int how, short type, int flags);
int m_pkthdr_init(struct mbuf *m, int how);
void m_catpkt(struct mbuf *m, struct mbuf *n);
void m_adj(struct mbuf*, int);
int m_append(struct mbuf*, int, c_caddr_t);
void m_cat(struct mbuf*, struct mbuf*);
int m_clget(struct mbuf*, int);
void* m_cljget(struct mbuf*, int, int);
struct mbuf* m_collapse(struct mbuf*, int, int);
void m_copyback(struct mbuf *m0, int off, int len, c_caddr_t cp);
void m_copydata(const struct mbuf*, int, int, caddr_t);
struct mbuf* m_copypacket(struct mbuf*, int);
struct mbuf * m_copym(struct mbuf *m, int off0, int len, int wait);
struct mbuf* m_defrag(struct mbuf*, int);
struct mbuf* m_devget(char*, int, int, struct ifnet*,
void(*) (char*, caddr_t, u_int));
struct mbuf* m_dup(const struct mbuf *m, int how);
int m_dup_pkthdr(struct mbuf *to, const struct mbuf *from, int how);
void m_demote_pkthdr(struct mbuf *m);
void m_demote(struct mbuf *m0, int all, int flags);
void m_extadd(struct mbuf *mb, caddr_t buf, u_int size,
void (*freef)(struct mbuf *, void *, void *), void *arg1, void *arg2,
int flags, int type);
u_int m_fixhdr(struct mbuf*);
struct mbuf* m_free(struct mbuf*);
void m_freem(struct mbuf*);
struct mbuf* m_get(int, short);
struct mbuf* m_get2(int size, int how, short type, int flags);
struct mbuf* m_get3(int size, int how, short type, int flags);
struct mbuf * m_getm2(struct mbuf *m, int len, int how, short type, int flags);
struct mbuf* m_gethdr(int, short);
struct mbuf* m_getjcl(int, short, int, int);
u_int m_length(struct mbuf*, struct mbuf**);
struct mbuf* m_getcl(int, short, int);
void m_move_pkthdr(struct mbuf*, struct mbuf*);
struct mbuf* m_prepend(struct mbuf*, int, int);
struct mbuf* m_pulldown(struct mbuf*, int, int, int*);
struct mbuf* m_pullup(struct mbuf*, int);
struct mbuf* m_split(struct mbuf*, int, int);
struct mbuf* m_unshare(struct mbuf*, int);
struct m_tag* m_tag_alloc(u_int32_t, int, int, int);
void m_tag_delete(struct mbuf*, struct m_tag*);
void m_tag_delete_chain(struct mbuf*, struct m_tag*);
void m_tag_free_default(struct m_tag*);
struct m_tag* m_tag_locate(struct mbuf*, u_int32_t, int, struct m_tag*);
struct m_tag* m_tag_copy(struct m_tag*, int);
int m_tag_copy_chain(struct mbuf *to, const struct mbuf *from, int how);
void m_tag_delete_nonpersistent(struct mbuf*);
static inline void
m_tag_setup(struct m_tag* tagPointer, u_int32_t cookie, int type, int length)
{
tagPointer->m_tag_id = type;
tagPointer->m_tag_len = length;
tagPointer->m_tag_cookie = cookie;
}
static inline void
m_tag_free(struct m_tag* tag)
{
(*tag->m_tag_free)(tag);
}
static inline void
m_tag_prepend(struct mbuf* memoryBuffer, struct m_tag* tag)
{
SLIST_INSERT_HEAD(&memoryBuffer->m_pkthdr.tags, tag, m_tag_link);
}
static inline void
m_tag_unlink(struct mbuf* memoryBuffer, struct m_tag* tag)
{
SLIST_REMOVE(&memoryBuffer->m_pkthdr.tags, tag, m_tag, m_tag_link);
}
#include <sys/mbuf-fbsd.h>
#endif