diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2008-10-21 07:00:00 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2008-10-21 07:00:00 -0700 |
commit | 55f4e4a5ec657a017e3bf75299ad71fd1c968dd3 (patch) | |
tree | 550ce922ea0e125ac6a9738210ce2939bf2fe901 /slirp/mbuf.h | |
parent | 413f05aaf54fa08c0ae7e997327a4f4a473c0a8d (diff) | |
download | external_qemu-55f4e4a5ec657a017e3bf75299ad71fd1c968dd3.zip external_qemu-55f4e4a5ec657a017e3bf75299ad71fd1c968dd3.tar.gz external_qemu-55f4e4a5ec657a017e3bf75299ad71fd1c968dd3.tar.bz2 |
Initial Contribution
Diffstat (limited to 'slirp/mbuf.h')
-rw-r--r-- | slirp/mbuf.h | 130 |
1 files changed, 52 insertions, 78 deletions
diff --git a/slirp/mbuf.h b/slirp/mbuf.h index 8cc292b..ed83372 100644 --- a/slirp/mbuf.h +++ b/slirp/mbuf.h @@ -37,111 +37,85 @@ #ifndef _MBUF_H_ #define _MBUF_H_ -#define m_freem m_free - - #define MINCSIZE 4096 /* Amount to increase mbuf if too small */ -/* - * 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) - */ -#define mtod(m,t) ((t)(m)->m_data) -/* #define dtom(x) ((struct mbuf *)((int)(x) & ~(M_SIZE-1))) */ +/* flags for the mh_flags field */ +#define M_EXT 0x01 /* m_ext points to more (malloced) data */ +#define M_FREELIST 0x02 /* mbuf is on free list */ +#define M_USEDLIST 0x04 /* XXX mbuf is on used list (for dtom()) */ +#define M_DOFREE 0x08 /* when mbuf_free is called on the mbuf, free() + * it rather than putting it on the free list */ + /* XXX About mbufs for slirp: * Only one mbuf is ever used in a chain, for each "cell" of data. * m_nextpkt points to the next packet, if fragmented. * If the data is too large, the M_EXT is used, and a larger block - * is alloced. Therefore, m_free[m] must check for M_EXT and if set + * is alloced. Therefore, mbuf_free[m] must check for M_EXT and if set * free the m_ext. This is inefficient memory-wise, but who cares. */ /* XXX should union some of these! */ /* header at beginning of each mbuf: */ -struct m_hdr { - struct mbuf *mh_next; /* Linked list of mbufs */ - struct mbuf *mh_prev; - struct mbuf *mh_nextpkt; /* Next packet in queue/record */ - struct mbuf *mh_prevpkt; /* Flags aren't used in the output queue */ - int mh_flags; /* Misc flags */ - - int mh_size; /* Size of data */ - struct socket *mh_so; - - caddr_t mh_data; /* Location of data */ - int mh_len; /* Amount of data in this mbuf */ -}; -/* - * How much room is in the mbuf, from m_data to the end of the mbuf +/** + * m_next, m_prev :: used to place the MBuf in free/used linked lists + * m_next2, m_prev2 :: used to place the same MBuf in other linked lists + * m_flags :: bit flags describing this MBuf + * m_size :: total size of MBuf buffer + * m_so :: socket this MBuf is attached to + * m_data :: pointer to current cursor in MBuf buffer + * m_len :: amount of data recorded in this MBuf */ -#define M_ROOM(m) ((m->m_flags & M_EXT)? \ - (((m)->m_ext + (m)->m_size) - (m)->m_data) \ - : \ - (((m)->m_dat + (m)->m_size) - (m)->m_data)) +#define MBUF_HEADER \ + struct mbuf* m_next; \ + struct mbuf* m_prev; \ + struct mbuf* m_next2; \ + struct mbuf* m_prev2; \ + int m_flags; \ + int m_size; \ + struct socket* m_so; \ + caddr_t m_data; \ + int m_len; -/* - * How much free room there is - */ -#define M_FREEROOM(m) (M_ROOM(m) - (m)->m_len) -#define M_TRAILINGSPACE M_FREEROOM +struct m_hdr { + MBUF_HEADER +}; -struct mbuf { - struct m_hdr m_hdr; +typedef struct mbuf { + MBUF_HEADER union M_dat { - char m_dat_[1]; /* ANSI don't like 0 sized arrays */ - char *m_ext_; + char m_dat_[1]; /* ANSI doesn't like 0 sized arrays */ + char* m_ext_; } M_dat; -}; +} MBufRec, *MBuf; -#define m_next m_hdr.mh_next -#define m_prev m_hdr.mh_prev -#define m_nextpkt m_hdr.mh_nextpkt -#define m_prevpkt m_hdr.mh_prevpkt -#define m_flags m_hdr.mh_flags -#define m_len m_hdr.mh_len -#define m_data m_hdr.mh_data -#define m_size m_hdr.mh_size +#define m_nextpkt m_next2 +#define m_prevpkt m_prev2 #define m_dat M_dat.m_dat_ #define m_ext M_dat.m_ext_ -#define m_so m_hdr.mh_so #define ifq_prev m_prev #define ifq_next m_next -#define ifs_prev m_prevpkt -#define ifs_next m_nextpkt -#define ifq_so m_so -#define M_EXT 0x01 /* m_ext points to more (malloced) data */ -#define M_FREELIST 0x02 /* mbuf is on free list */ -#define M_USEDLIST 0x04 /* XXX mbuf is on used list (for dtom()) */ -#define M_DOFREE 0x08 /* when m_free is called on the mbuf, free() - * it rather than putting it on the free list */ +#define ifs_prev m_prev2 +#define ifs_next m_next2 -/* - * Mbuf statistics. XXX - */ +#define ifq_so m_so -struct mbstat { - int mbs_alloced; /* Number of mbufs allocated */ - -}; +void mbuf_init (void); +void msize_init (void); +MBuf mbuf_alloc (void); +void mbuf_free (MBuf m); +void mbuf_append(MBuf m1, MBuf m2); +void mbuf_ensure(MBuf m, int size); +void mbuf_trim (MBuf m, int len); +int mbuf_copy (MBuf m, MBuf n, int n_offset, int n_length); + +#define MBUF_TO(m,t) ((t)(m)->m_data) +#define MBUF_FROM(d) mbuf_from(d) +MBuf mbuf_from (void *); -extern struct mbstat mbstat; -extern int mbuf_alloced; -extern struct mbuf m_freelist, m_usedlist; -extern int mbuf_max; - -void m_init _P((void)); -void msize_init _P((void)); -struct mbuf * m_get _P((void)); -void m_free _P((struct mbuf *)); -void m_cat _P((register struct mbuf *, register struct mbuf *)); -void m_inc _P((struct mbuf *, int)); -void m_adj _P((struct mbuf *, int)); -int m_copy _P((struct mbuf *, struct mbuf *, int, int)); -struct mbuf * dtom _P((void *)); +int mbuf_freeroom( MBuf m ); #endif |