Consolidate the two malloc()s that are done when allocating
an mbuf.
This commit is contained in:
parent
3f37462e61
commit
9773f8c0c8
@ -23,7 +23,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: log.c,v 1.33 1998/08/07 18:42:49 brian Exp $
|
||||
* $Id: log.c,v 1.34 1998/08/09 15:34:11 brian Exp $
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -324,12 +324,12 @@ log_Printf(int lev, const char *fmt,...)
|
||||
}
|
||||
|
||||
void
|
||||
log_DumpBp(int lev, const char *hdr, const struct mbuf * bp)
|
||||
log_DumpBp(int lev, const char *hdr, const struct mbuf *bp)
|
||||
{
|
||||
if (log_IsKept(lev)) {
|
||||
char buf[50];
|
||||
char *b;
|
||||
u_char *ptr;
|
||||
const u_char *ptr;
|
||||
int f;
|
||||
|
||||
if (hdr && *hdr)
|
||||
@ -338,7 +338,7 @@ log_DumpBp(int lev, const char *hdr, const struct mbuf * bp)
|
||||
b = buf;
|
||||
do {
|
||||
f = bp->cnt;
|
||||
ptr = MBUF_CTOP(bp);
|
||||
ptr = CONST_MBUF_CTOP(bp);
|
||||
while (f--) {
|
||||
sprintf(b, " %02x", (int) *ptr++);
|
||||
b += 3;
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: mbuf.c,v 1.19 1998/08/07 18:42:50 brian Exp $
|
||||
* $Id: mbuf.c,v 1.20 1998/08/21 18:09:57 brian Exp $
|
||||
*
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
@ -56,27 +56,20 @@ mbuf_Length(struct mbuf * bp)
|
||||
struct mbuf *
|
||||
mbuf_Alloc(int cnt, int type)
|
||||
{
|
||||
u_char *p;
|
||||
struct mbuf *bp;
|
||||
|
||||
if (type > MB_MAX)
|
||||
log_Printf(LogERROR, "Bad mbuf type %d\n", type);
|
||||
bp = (struct mbuf *) malloc(sizeof(struct mbuf));
|
||||
bp = malloc(sizeof(struct mbuf) + cnt);
|
||||
if (bp == NULL) {
|
||||
log_Printf(LogALERT, "failed to allocate memory: %ld\n",
|
||||
(long)sizeof(struct mbuf));
|
||||
AbortProgram(EX_OSERR);
|
||||
}
|
||||
memset(bp, '\0', sizeof(struct mbuf));
|
||||
p = (u_char *) malloc(cnt);
|
||||
if (p == NULL) {
|
||||
log_Printf(LogALERT, "failed to allocate memory: %d\n", cnt);
|
||||
AbortProgram(EX_OSERR);
|
||||
}
|
||||
MemMap[type].fragments++;
|
||||
MemMap[type].octets += cnt;
|
||||
totalalloced += cnt;
|
||||
bp->base = p;
|
||||
bp->size = bp->cnt = cnt;
|
||||
bp->type = type;
|
||||
bp->pnext = NULL;
|
||||
@ -93,7 +86,6 @@ mbuf_FreeSeg(struct mbuf * bp)
|
||||
MemMap[bp->type].fragments--;
|
||||
MemMap[bp->type].octets -= bp->size;
|
||||
totalalloced -= bp->size;
|
||||
free(bp->base);
|
||||
free(bp);
|
||||
return (nbp);
|
||||
}
|
||||
|
@ -15,19 +15,19 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: mbuf.h,v 1.12 1998/05/21 21:46:49 brian Exp $
|
||||
* $Id: mbuf.h,v 1.13 1998/08/07 18:42:50 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
|
||||
struct mbuf {
|
||||
u_char *base; /* pointer to top of buffer space */
|
||||
short size; /* size allocated from base */
|
||||
short offset; /* offset to start position */
|
||||
short size; /* size allocated (excluding header) */
|
||||
short offset; /* offset from header end to start position */
|
||||
short cnt; /* available byte count in buffer */
|
||||
short type;
|
||||
short type; /* MB_* below */
|
||||
struct mbuf *next; /* link to next mbuf */
|
||||
struct mbuf *pnext; /* link to next packet */
|
||||
/* buffer space is malloc()d directly after the header */
|
||||
};
|
||||
|
||||
struct mqueue {
|
||||
@ -36,7 +36,8 @@ struct mqueue {
|
||||
int qlen;
|
||||
};
|
||||
|
||||
#define MBUF_CTOP(bp) (bp->base + bp->offset)
|
||||
#define MBUF_CTOP(bp) ((u_char *)((bp)+1) + (bp)->offset)
|
||||
#define CONST_MBUF_CTOP(bp) ((const u_char *)((bp)+1) + (bp)->offset)
|
||||
|
||||
#define MB_ASYNC 1
|
||||
#define MB_FSM 2
|
||||
|
Loading…
x
Reference in New Issue
Block a user