Please wait until the page is fully downloaded and then press the "Expand" button or the blue line numbers.
0023001 /*
0023002 buf.h
0023003
0023004 Copyright 1995 Philip Homburg
0023005 */
0023006
0023007 #ifndef BUF_H
0023008 #define BUF_H
0023009
0023010 /* Note: BUF_S should be defined in const.h */
0023011
0023012 #define MAX_BUFREQ_PRI 10
0023013
0023014 #define ETH_PRI_PORTBUFS 3
0023015 #define ETH_PRI_FDBUFS_EXTRA 5
0023016 #define ETH_PRI_FDBUFS 6
0023017
0023018 #define IP_PRI_PORTBUFS 3
0023019 #define IP_PRI_ASSBUFS 4
0023020 #define IP_PRI_FDBUFS_EXTRA 5
0023021 #define IP_PRI_FDBUFS 6
0023022
0023023 #define ICMP_PRI_QUEUE 1
0023024
0023025 #define TCP_PRI_FRAG2SEND 4
0023026 #define TCP_PRI_CONN_EXTRA 5
0023027 #define TCP_PRI_CONNwoUSER 7
0023028 #define TCP_PRI_CONN_INUSE 9
0023029
0023030 #define UDP_PRI_FDBUFS_EXTRA 5
0023031 #define UDP_PRI_FDBUFS 6
0023032
0023033 #define PSIP_PRI_EXP_PROMISC 2
0023034
0023035 struct acc;
0023036 typedef void (*buffree_t) ARGS(( struct acc *acc ));
0023037 typedef void (*bf_freereq_t) ARGS(( int priority ));
0023038
0023039 #ifdef BUF_CONSISTENCY_CHECK
0023040 typedef void (*bf_checkreq_t) ARGS(( void ));
0023041 #endif
0023042
0023043 typedef struct buf
0023044 {
0023045 int buf_linkC;
0023046 buffree_t buf_free;
0023047 size_t buf_size;
0023048 char *buf_data_p;
0023049
0023050 #ifdef BUF_TRACK_ALLOC_FREE
0023051 char *buf_alloc_file;
0023052 int buf_alloc_line;
0023053 char *buf_free_file;
0023054 int buf_free_line;
0023055 #endif
0023056 #ifdef BUF_CONSISTENCY_CHECK
0023057 unsigned buf_generation;
0023058 int buf_check_linkC;
0023059 #endif
0023060 } buf_t;
0023061
0023062 typedef struct acc
0023063 {
0023064 int acc_linkC;
0023065 int acc_offset, acc_length;
0023066 buf_t *acc_buffer;
0023067 struct acc *acc_next, *acc_ext_link;
0023068
0023069 #ifdef BUF_TRACK_ALLOC_FREE
0023070 char *acc_alloc_file;
0023071 int acc_alloc_line;
0023072 char *acc_free_file;
0023073 int acc_free_line;
0023074 #endif
0023075 #ifdef BUF_CONSISTENCY_CHECK
0023076 unsigned acc_generation;
0023077 int acc_check_linkC;
0023078 #endif
0023079 } acc_t;
0023080
0023081 extern acc_t *bf_temporary_acc;
0023082
0023083 /* For debugging... */
0023084
0023085 #ifdef BUF_TRACK_ALLOC_FREE
0023086
0023087 #ifndef BUF_IMPLEMENTATION
0023088
0023089 #define bf_memreq(a) _bf_memreq(this_file, __LINE__, a)
0023090 #define bf_cut(a,b,c) _bf_cut(this_file, __LINE__, a, b, c)
0023091 #define bf_delhead(a,b) _bf_delhead(this_file, __LINE__, a, b)
0023092 #define bf_packIffLess(a,b) _bf_packIffLess(this_file, __LINE__, \
0023093 a, b)
0023094 #define bf_afree(a) _bf_afree(this_file, __LINE__, a)
0023095 #define bf_pack(a) _bf_pack(this_file, __LINE__, a)
0023096 #define bf_append(a,b) _bf_append(this_file, __LINE__, a, b)
0023097 #define bf_dupacc(a) _bf_dupacc(this_file, __LINE__, a)
0023098 #define bf_mark_acc(a) _bf_mark_acc(this_file, __LINE__, a)
0023099 #define bf_align(a,s,al) _bf_align(this_file, __LINE__, a, s, al)
0023100
0023101 #else /* BUF_IMPLEMENTATION */
0023102
0023103 #define bf_afree(a) _bf_afree(clnt_file, clnt_line, a)
0023104 #define bf_pack(a) _bf_pack(clnt_file, clnt_line, a)
0023105 #define bf_memreq(a) _bf_memreq(clnt_file, clnt_line, a)
0023106 #define bf_dupacc(a) _bf_dupacc(clnt_file, clnt_line, a)
0023107 #define bf_cut(a,b,c) _bf_cut(clnt_file, clnt_line, a, b, c)
0023108 #define bf_delhead(a,b) _bf_delhead(clnt_file, clnt_line, a, b)
0023109 #define bf_align(a,s,al) _bf_align(clnt_file, clnt_line, a, s, al)
0023110
0023111 #endif /* !BUF_IMPLEMENTATION */
0023112
0023113 #else
0023114
0023115 #define bf_mark_acc(acc) ((void)0)
0023116
0023117 #endif /* BUF_TRACK_ALLOC_FREE */
0023118
0023119 /* Prototypes */
0023120
0023121 void bf_init ARGS(( void ));
0023122 #ifndef BUF_CONSISTENCY_CHECK
0023123 void bf_logon ARGS(( bf_freereq_t func ));
0023124 #else
0023125 void bf_logon ARGS(( bf_freereq_t func, bf_checkreq_t checkfunc ));
0023126 #endif
0023127
0023128 #ifndef BUF_TRACK_ALLOC_FREE
0023129 acc_t *bf_memreq ARGS(( unsigned size));
0023130 #else
0023131 acc_t *_bf_memreq ARGS(( char *clnt_file, int clnt_line,
0023132 unsigned size));
0023133 #endif
0023134 /* the result is an acc with linkC == 1 */
0023135
0023136 #ifndef BUF_TRACK_ALLOC_FREE
0023137 acc_t *bf_dupacc ARGS(( acc_t *acc ));
0023138 #else
0023139 acc_t *_bf_dupacc ARGS(( char *clnt_file, int clnt_line,
0023140 acc_t *acc ));
0023141 #endif
0023142 /* the result is an acc with linkC == 1 identical to the given one */
0023143
0023144 #ifndef BUF_TRACK_ALLOC_FREE
0023145 void bf_afree ARGS(( acc_t *acc));
0023146 #else
0023147 void _bf_afree ARGS(( char *clnt_file, int clnt_line,
0023148 acc_t *acc));
0023149 #endif
0023150 /* this reduces the linkC off the given acc with one */
0023151
0023152 #ifndef BUF_TRACK_ALLOC_FREE
0023153 acc_t *bf_pack ARGS(( acc_t *pack));
0023154 #else
0023155 acc_t *_bf_pack ARGS(( char *clnt_file, int clnt_line,
0023156 acc_t *pack));
0023157 #endif
0023158 /* this gives a packed copy of the given acc, the linkC of the given acc is
0023159 reduced by one, the linkC of the result == 1 */
0023160
0023161 #ifndef BUF_TRACK_ALLOC_FREE
0023162 acc_t *bf_packIffLess ARGS(( acc_t *pack, int min_len ));
0023163 #else
0023164 acc_t *_bf_packIffLess ARGS(( char *clnt_file, int clnt_line,
0023165 acc_t *pack, int min_len ));
0023166 #endif
0023167 /* this performs a bf_pack iff pack->acc_length<min_len */
0023168
0023169 size_t bf_bufsize ARGS(( acc_t *pack));
0023170 /* this gives the length of the buffer specified by the given acc. The linkC
0023171 of the given acc remains the same */
0023172
0023173 #ifndef BUF_TRACK_ALLOC_FREE
0023174 acc_t *bf_cut ARGS(( acc_t *data, unsigned offset, unsigned length ));
0023175 #else
0023176 acc_t *_bf_cut ARGS(( char *clnt_file, int clnt_line,
0023177 acc_t *data, unsigned offset, unsigned length ));
0023178 #endif
0023179 /* the result is a cut of the buffer from offset with length length.
0023180 The linkC of the result == 1, the linkC of the given acc remains the
0023181 same. */
0023182
0023183 #ifndef BUF_TRACK_ALLOC_FREE
0023184 acc_t *bf_delhead ARGS(( acc_t *data, unsigned offset ));
0023185 #else
0023186 acc_t *_bf_delhead ARGS(( char *clnt_file, int clnt_line,
0023187 acc_t *data, unsigned offset ));
0023188 #endif
0023189 /* the result is a cut of the buffer from offset until the end.
0023190 The linkC of the result == 1, the linkC of the given acc is
0023191 decremented. */
0023192
0023193 #ifndef BUF_TRACK_ALLOC_FREE
0023194 acc_t *bf_append ARGS(( acc_t *data_first, acc_t *data_second ));
0023195 #else
0023196 acc_t *_bf_append ARGS(( char *clnt_file, int clnt_line,
0023197 acc_t *data_first, acc_t *data_second ));
0023198 #endif
0023199 /* data_second is appended after data_first, a link is returned to the
0023200 result and the linkCs of data_first and data_second are reduced.
0023201 further more, if the contents of the last part of data_first and
0023202 the first part of data_second fit in a buffer, both parts are
0023203 copied into a (possibly fresh) buffer
0023204 */
0023205
0023206 #ifndef BUF_TRACK_ALLOC_FREE
0023207 acc_t *bf_align ARGS(( acc_t *acc, size_t size, size_t alignment ));
0023208 #else
0023209 acc_t *_bf_align ARGS(( char *clnt_file, int clnt_line,
0023210 acc_t *acc, size_t size, size_t alignment ));
0023211 #endif
0023212 /* size bytes of acc (or all bytes of acc if the size buffer is smaller
0023213 than size) are aligned on an address that is multiple of alignment.
0023214 Size must be less than or equal to BUF_S.
0023215 */
0023216
0023217 #define ptr2acc_data(/* acc_t * */ a) (bf_temporary_acc=(a), \
0023218 (&bf_temporary_acc->acc_buffer->buf_data_p[bf_temporary_acc-> \
0023219 acc_offset]))
0023220
0023221 #define bf_chkbuf(buf) ((buf)? (compare((buf)->acc_linkC,>,0), \
0023222 compare((buf)->acc_buffer, !=, 0), \
0023223 compare((buf)->acc_buffer->buf_linkC,>,0)) : 0)
0023224
0023225 #ifdef BUF_CONSISTENCY_CHECK
0023226 int bf_consistency_check ARGS(( void ));
0023227 void bf_check_acc ARGS(( acc_t *acc ));
0023228 void _bf_mark_acc ARGS(( char *clnt_file, int clnt_line, acc_t *acc ));
0023229 #endif
0023230
0023231 #endif /* BUF_H */
0023232
0023233 /*
0023234 * $PchId: buf.h,v 1.8 1995/11/21 06:45:27 philip Exp $
0023235 */
I really wish I understood what these all mean. I do know that these are priorities of sorts and that when buffers are put back on the buf512_freelist, the buffers of lower priority are put on the buf512_freelist first.