Annotation of cci/sys/h/mbuf.h, revision 1.1.1.1

1.1       root        1: /*     mbuf.h  6.1     83/07/29        */
                      2: 
                      3: /*
                      4:  * Constants related to memory allocator.
                      5:  */
                      6: #define        MSIZE           128                     /* size of an mbuf */
                      7: #define        MMINOFF         12                      /* mbuf header length */
                      8: #define        MTAIL           4
                      9: #define        MMAXOFF         (MSIZE-MTAIL)           /* offset where data ends */
                     10: #define        MLEN            (MSIZE-MMINOFF-MTAIL)   /* mbuf data length */
                     11: #define        NMBCLUSTERS     256
                     12: #define        NMBPCL          (CLBYTES/MSIZE)         /* # mbufs per cluster */
                     13: 
                     14: /*
                     15:  * Macros for type conversion
                     16:  */
                     17: 
                     18: /* network cluster number to virtual address, and back */
                     19: #define        cltom(x) ((struct mbuf *)((int)mbutl + ((x) << CLSHIFT)))
                     20: #define        mtocl(x) (((int)x - (int)mbutl) >> CLSHIFT)
                     21: 
                     22: /* address in mbuf to mbuf head */
                     23: #define        dtom(x)         ((struct mbuf *)((int)x & ~(MSIZE-1)))
                     24: 
                     25: /* mbuf head, to typed data */
                     26: #define        mtod(x,t)       ((t)((int)(x) + (x)->m_off))
                     27: 
                     28: struct mbuf {
                     29:        struct  mbuf *m_next;           /* next buffer in chain */
                     30:        u_long  m_off;                  /* offset of data */
                     31:        short   m_len;                  /* amount of data in this mbuf */
                     32:        short   m_type;                 /* mbuf type (0 == free) */
                     33:        u_char  m_dat[MLEN];            /* data storage */
                     34:        struct  mbuf *m_act;            /* link in higher-level mbuf list */
                     35: };
                     36: 
                     37: /* mbuf types */
                     38: #define        MT_FREE         0       /* should be on free list */
                     39: #define        MT_DATA         1       /* dynamic (data) allocation */
                     40: #define        MT_HEADER       2       /* packet header */
                     41: #define        MT_SOCKET       3       /* socket structure */
                     42: #define        MT_PCB          4       /* protocol control block */
                     43: #define        MT_RTABLE       5       /* routing tables */
                     44: #define        MT_HTABLE       6       /* IMP host tables */
                     45: #define        MT_ATABLE       7       /* address resolution tables */
                     46: #define        MT_SONAME       8       /* socket name */
                     47: #define        MT_ZOMBIE       9       /* zombie proc status */
                     48: #define        MT_SOOPTS       10      /* socket options */
                     49: #define        MT_FTABLE       11      /* fragment reassembly header */
                     50: 
                     51: /* flags to m_get */
                     52: #define        M_DONTWAIT      0
                     53: #define        M_WAIT          1
                     54: 
                     55: /* flags to m_pgalloc */
                     56: #define        MPG_MBUFS       0               /* put new mbufs on free list */
                     57: #define        MPG_CLUSTERS    1               /* put new clusters on free list */
                     58: #define        MPG_SPACE       2               /* don't free; caller wants space */
                     59: 
                     60: /* length to m_copy to copy all */
                     61: #define        M_COPYALL       1000000000
                     62: 
                     63: /*
                     64:  * Changes:    print more info before panicking
                     65:  */
                     66: #define        MGET(m, i, t) \
                     67:        { int ms = splimp(); \
                     68:          if ((m)=mfree) \
                     69:                { if ((m)->m_type != MT_FREE) { \
                     70:                        printf("mget: type %d, next %lx, act %lx\n", \
                     71:                                (m)->m_type, (m)->m_next, (m)->m_act); \
                     72:                        panic("mget");  \
                     73:                  }                     \
                     74:                  (m)->m_type = t; \
                     75:                  mbstat.m_mbfree--; mbstat.m_mtypes[t]++; \
                     76:                  mfree = (m)->m_next; (m)->m_next = 0; \
                     77:                  (m)->m_off = MMINOFF; } \
                     78:          else \
                     79:                (m) = m_more(i, t); \
                     80:          splx(ms); }
                     81: #define        MCLGET(m, i) \
                     82:        { int ms = splimp(); \
                     83:          if ((m)=mclfree) \
                     84:             {++mclrefcnt[mtocl(m)];mbstat.m_clfree--;mclfree = (m)->m_next;} \
                     85:          splx(ms); }
                     86: #define        MFREE(m, n) \
                     87:        { int ms = splimp(); \
                     88:          if ((m)->m_type == MT_FREE) panic("mfree"); \
                     89:          if ((m)->m_type < MT_DATA || (m)->m_type > MT_FTABLE) \
                     90:                         panic("mfree (badtype)"); \
                     91:          mbstat.m_mtypes[(m)->m_type]--; (m)->m_type = MT_FREE; \
                     92:          if ((m)->m_off > MSIZE) { \
                     93:                (n) = (struct mbuf *)(mtod(m, int)&~CLOFSET); \
                     94:                if (--mclrefcnt[mtocl(n)] == 0) \
                     95:                    { (n)->m_next = mclfree;mclfree = (n);mbstat.m_clfree++;} \
                     96:          } \
                     97:          (n) = (m)->m_next; (m)->m_next = mfree; \
                     98:          (m)->m_off = 0; (m)->m_act = 0; mfree = (m); mbstat.m_mbfree++; \
                     99:          splx(ms); }
                    100: 
                    101: /*
                    102:  * Mbuf statistics.
                    103:  */
                    104: struct mbstat {
                    105:        short   m_mbufs;        /* mbufs obtained from page pool */
                    106:        short   m_mbfree;       /* mbufs on our free list */
                    107:        short   m_clusters;     /* clusters obtained from page pool */
                    108:        short   m_clfree;       /* free clusters */
                    109:        short   m_drops;        /* times failed to find space */
                    110:        short   m_mtypes[256];  /* type specific mbuf allocations */
                    111: };
                    112: 
                    113: #ifdef KERNEL
                    114: extern struct mbuf mbutl[];            /* virtual address of net free mem */
                    115: extern struct pte Mbmap[];             /* page tables to map Netutl */
                    116: struct mbstat mbstat;
                    117: int    nmbclusters;
                    118: struct mbuf *mfree, *mclfree;
                    119: char   mclrefcnt[NMBCLUSTERS];
                    120: struct mbuf *m_get(),*m_getclr(),*m_free(),*m_more(),*m_copy(),*m_pullup();
                    121: caddr_t        m_clalloc();
                    122: #ifdef  NETGENERR
                    123: #define MBUFNULL(LEVEL,M)      {                               \
                    124:                                if (mbufnull((LEVEL))) {        \
                    125:                                        m_free(M);              \
                    126:                                        (M) = (struct mbuf *)0; \
                    127:                                }                               \
                    128:                        }
                    129: #else
                    130: #define MBUFNULL(LEVEL,M)
                    131: #endif  NETGENERR
                    132: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.