openblt

a hobby OS from the late 90s
git clone http://frotz.net/git/openblt.git
Log | Files | Refs | LICENSE

mbuf.h (4926B)


      1 /* $Id: //depot/blt/include/blt/network/mbuf.h#1 $
      2 **
      3 ** Copyright 1999 Sidney Cammeresi
      4 ** All rights reserved.
      5 **
      6 ** Redistribution and use in source and binary forms, with or without
      7 ** modification, are permitted provided that the following conditions
      8 ** are met:
      9 ** 1. Redistributions of source code must retain the above copyright
     10 **    notice, this list of conditions, and the following disclaimer.
     11 ** 2. Redistributions in binary form must reproduce the above copyright
     12 **    notice, this list of conditions, and the following disclaimer in the
     13 **    documentation and/or other materials provided with the distribution.
     14 ** 3. The name of the author may not be used to endorse or promote products
     15 **    derived from this software without specific prior written permission.
     16 **
     17 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
     28 
     29 /*
     30  * Copyright (c) 1982, 1986, 1988, 1993
     31  *     The Regents of the University of California.  All rights reserved.
     32  *
     33  * Redistribution and use in source and binary forms, with or without
     34  * modification, are permitted provided that the following conditions
     35  * are met:
     36  * 1. Redistributions of source code must retain the above copyright
     37  *    notice, this list of conditions and the following disclaimer.
     38  * 2. Redistributions in binary form must reproduce the above copyright
     39  *    notice, this list of conditions and the following disclaimer in the
     40  *    documentation and/or other materials provided with the distribution.
     41  * 3. All advertising materials mentioning features or use of this software
     42  *    must display the following acknowledgement:
     43  *        This product includes software developed by the University of
     44  *        California, Berkeley and its contributors.
     45  * 4. Neither the name of the University nor the names of its contributors
     46  *    may be used to endorse or promote products derived from this software
     47  *    without specific prior written permission.
     48  *
     49  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     50  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     51  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     52  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     53  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     54  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     55  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     56  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     57  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     58  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     59  * SUCH DAMAGE.
     60  *
     61  *  @(#)mbuf.h  8.5 (Berkeley) 2/19/95
     62  */
     63 
     64 #ifndef _BLT_NETWORK_MBUF_H_
     65 #define _BLT_NETWORK_MBUF_H_
     66 
     67 #define MSIZE       128
     68 #define MCLBYTES    2048
     69 
     70 #define MLEN        (MSIZE - sizeof(struct m_hdr))    /* normal data len */
     71 #define MHLEN       (MLEN - sizeof(struct m_pkthdr))  /* data len w/pkthdr */
     72 #define MINCLSIZE   (MHLEN+MLEN+1)  /* smallest amount to put in cluster */
     73 #define M_MAXCOMPRESS   (MHLEN / 2) /* max amount to copy for compression */
     74 
     75 struct m_hdr
     76 {
     77 	struct mbuf *mh_next, *mh_nextpkt;
     78 	int mh_len;
     79 	char *mh_data;
     80 	short mh_type, mh_flags;
     81 };
     82 
     83 struct m_pkthdr
     84 {
     85 	void *rcvif;
     86 	int len;
     87 };
     88 
     89 struct m_ext
     90 {
     91 	char *ext_buf;
     92 	void (*ext_free) (char *, int);
     93 	int ext_size;
     94 	volatile int ext_refcnt;
     95 };
     96 
     97 struct mbuf
     98 {
     99 	struct m_hdr m_hdr;
    100 	union
    101 	{
    102 		struct
    103 		{
    104 			struct m_pkthdr mh_pkthdr;
    105 			union
    106 			{
    107 				struct m_ext *mh_ext;
    108 				char mh_ext_databuf[MHLEN];
    109 			} mh_dat;
    110 		} mh;
    111 		char mh_databuf[MLEN];
    112 	} m_dat;
    113 };
    114 
    115 #define m_next         m_hdr.mh_next
    116 #define m_nextpkt      m_hdr.mh_nextpkt
    117 #define m_len          m_hdr.mh_len
    118 #define m_data         m_hdr.mh_data
    119 #define m_type         m_hdr.mh_type
    120 #define m_flags        m_hdr.mh_flags
    121 #define m_databuf      m_dat.mh_databuf
    122 #define m_ext_databuf  m_dat.mh.mh_dat.mh_ext_databuf
    123 
    124 #define MT_FREE        1
    125 #define MT_DATA        2
    126 #define MT_HEADER      3
    127 #define MT_IFADDR      4
    128 
    129 #ifdef _NETWORK
    130 
    131 void mbinit (void);
    132 struct mbuf *mget (void);
    133 char *mgetcl (struct mbuf *mbuf);
    134 void mput (struct mbuf *mbuf);
    135 void mputcl (struct mbuf *mbuf);
    136 
    137 #endif
    138 
    139 #endif
    140