4 Copyright 1995 Philip Homburg
10 /* Note: BUF_S should be defined in const.h */
12 #define MAX_BUFREQ_PRI 10
15 #define ARP_PRI_SEND 3
17 #define ETH_PRI_PORTBUFS 3
18 #define ETH_PRI_FDBUFS_EXTRA 5
19 #define ETH_PRI_FDBUFS 6
21 #define IP_PRI_PORTBUFS 3
22 #define IP_PRI_ASSBUFS 4
23 #define IP_PRI_FDBUFS_EXTRA 5
24 #define IP_PRI_FDBUFS 6
26 #define ICMP_PRI_QUEUE 1
28 #define TCP_PRI_FRAG2SEND 4
29 #define TCP_PRI_CONN_EXTRA 5
30 #define TCP_PRI_CONNwoUSER 7
31 #define TCP_PRI_CONN_INUSE 9
33 #define UDP_PRI_FDBUFS_EXTRA 5
34 #define UDP_PRI_FDBUFS 6
36 #define PSIP_PRI_EXP_PROMISC 2
39 typedef void (*buffree_t
) ARGS(( struct acc
*acc
));
40 typedef void (*bf_freereq_t
) ARGS(( int priority
));
42 #ifdef BUF_CONSISTENCY_CHECK
43 typedef void (*bf_checkreq_t
) ARGS(( void ));
53 #ifdef BUF_TRACK_ALLOC_FREE
59 #ifdef BUF_CONSISTENCY_CHECK
60 unsigned buf_generation
;
68 int acc_offset
, acc_length
;
70 struct acc
*acc_next
, *acc_ext_link
;
72 #ifdef BUF_TRACK_ALLOC_FREE
78 #ifdef BUF_CONSISTENCY_CHECK
79 unsigned acc_generation
;
84 extern acc_t
*bf_temporary_acc
;
85 extern acc_t
*bf_linkcheck_acc
;
87 /* For debugging... */
89 #ifdef BUF_TRACK_ALLOC_FREE
91 #ifndef BUF_IMPLEMENTATION
93 #define bf_memreq(a) _bf_memreq(this_file, __LINE__, a)
94 #define bf_cut(a,b,c) _bf_cut(this_file, __LINE__, a, b, c)
95 #define bf_delhead(a,b) _bf_delhead(this_file, __LINE__, a, b)
96 #define bf_packIffLess(a,b) _bf_packIffLess(this_file, __LINE__, \
98 #define bf_afree(a) _bf_afree(this_file, __LINE__, a)
99 #define bf_pack(a) _bf_pack(this_file, __LINE__, a)
100 #define bf_append(a,b) _bf_append(this_file, __LINE__, a, b)
101 #define bf_dupacc(a) _bf_dupacc(this_file, __LINE__, a)
103 #define bf_mark_1acc(a) _bf_mark_1acc(this_file, __LINE__, a)
104 #define bf_mark_acc(a) _bf_mark_acc(this_file, __LINE__, a)
106 #define bf_align(a,s,al) _bf_align(this_file, __LINE__, a, s, al)
108 #else /* BUF_IMPLEMENTATION */
110 #define bf_afree(a) _bf_afree(clnt_file, clnt_line, a)
111 #define bf_pack(a) _bf_pack(clnt_file, clnt_line, a)
112 #define bf_memreq(a) _bf_memreq(clnt_file, clnt_line, a)
113 #define bf_dupacc(a) _bf_dupacc(clnt_file, clnt_line, a)
114 #define bf_cut(a,b,c) _bf_cut(clnt_file, clnt_line, a, b, c)
115 #define bf_delhead(a,b) _bf_delhead(clnt_file, clnt_line, a, b)
116 #define bf_align(a,s,al) _bf_align(clnt_file, clnt_line, a, s, al)
118 #endif /* !BUF_IMPLEMENTATION */
122 #define bf_mark_1acc(acc) ((void)0)
123 #define bf_mark_acc(acc) ((void)0)
125 #endif /* BUF_TRACK_ALLOC_FREE */
129 void bf_init
ARGS(( void ));
130 #ifndef BUF_CONSISTENCY_CHECK
131 void bf_logon
ARGS(( bf_freereq_t func
));
133 void bf_logon
ARGS(( bf_freereq_t func
, bf_checkreq_t checkfunc
));
136 #ifndef BUF_TRACK_ALLOC_FREE
137 acc_t
*bf_memreq
ARGS(( unsigned size
));
139 acc_t
*_bf_memreq
ARGS(( char *clnt_file
, int clnt_line
,
142 /* the result is an acc with linkC == 1 */
144 #ifndef BUF_TRACK_ALLOC_FREE
145 acc_t
*bf_dupacc
ARGS(( acc_t
*acc
));
147 acc_t
*_bf_dupacc
ARGS(( char *clnt_file
, int clnt_line
,
150 /* the result is an acc with linkC == 1 identical to the given one */
152 #ifndef BUF_TRACK_ALLOC_FREE
153 void bf_afree
ARGS(( acc_t
*acc
));
155 void _bf_afree
ARGS(( char *clnt_file
, int clnt_line
,
158 /* this reduces the linkC off the given acc with one */
160 #ifndef BUF_TRACK_ALLOC_FREE
161 acc_t
*bf_pack
ARGS(( acc_t
*pack
));
163 acc_t
*_bf_pack
ARGS(( char *clnt_file
, int clnt_line
,
166 /* this gives a packed copy of the given acc, the linkC of the given acc is
167 reduced by one, the linkC of the result == 1 */
169 #ifndef BUF_TRACK_ALLOC_FREE
170 acc_t
*bf_packIffLess
ARGS(( acc_t
*pack
, int min_len
));
172 acc_t
*_bf_packIffLess
ARGS(( char *clnt_file
, int clnt_line
,
173 acc_t
*pack
, int min_len
));
175 /* this performs a bf_pack iff pack->acc_length<min_len */
177 size_t bf_bufsize
ARGS(( acc_t
*pack
));
178 /* this gives the length of the buffer specified by the given acc. The linkC
179 of the given acc remains the same */
181 #ifndef BUF_TRACK_ALLOC_FREE
182 acc_t
*bf_cut
ARGS(( acc_t
*data
, unsigned offset
, unsigned length
));
184 acc_t
*_bf_cut
ARGS(( char *clnt_file
, int clnt_line
,
185 acc_t
*data
, unsigned offset
, unsigned length
));
187 /* the result is a cut of the buffer from offset with length length.
188 The linkC of the result == 1, the linkC of the given acc remains the
191 #ifndef BUF_TRACK_ALLOC_FREE
192 acc_t
*bf_delhead
ARGS(( acc_t
*data
, unsigned offset
));
194 acc_t
*_bf_delhead
ARGS(( char *clnt_file
, int clnt_line
,
195 acc_t
*data
, unsigned offset
));
197 /* the result is a cut of the buffer from offset until the end.
198 The linkC of the result == 1, the linkC of the given acc is
201 #ifndef BUF_TRACK_ALLOC_FREE
202 acc_t
*bf_append
ARGS(( acc_t
*data_first
, acc_t
*data_second
));
204 acc_t
*_bf_append
ARGS(( char *clnt_file
, int clnt_line
,
205 acc_t
*data_first
, acc_t
*data_second
));
207 /* data_second is appended after data_first, a link is returned to the
208 result and the linkCs of data_first and data_second are reduced.
209 further more, if the contents of the last part of data_first and
210 the first part of data_second fit in a buffer, both parts are
211 copied into a (possibly fresh) buffer
214 #ifndef BUF_TRACK_ALLOC_FREE
215 acc_t
*bf_align
ARGS(( acc_t
*acc
, size_t size
, size_t alignment
));
217 acc_t
*_bf_align
ARGS(( char *clnt_file
, int clnt_line
,
218 acc_t
*acc
, size_t size
, size_t alignment
));
220 /* size bytes of acc (or all bytes of acc if the size buffer is smaller
221 than size) are aligned on an address that is multiple of alignment.
222 Size must be less than or equal to BUF_S.
225 int bf_linkcheck
ARGS(( acc_t
*acc
));
226 /* check if all link count are positive, and offsets and sizes are within
227 * the underlying buffer.
230 #define ptr2acc_data(/* acc_t * */ a) (bf_temporary_acc=(a), \
231 (&bf_temporary_acc->acc_buffer->buf_data_p[bf_temporary_acc-> \
234 #define bf_chkbuf(buf) ((buf)? (compare((buf)->acc_linkC,>,0), \
235 compare((buf)->acc_buffer, !=, 0), \
236 compare((buf)->acc_buffer->buf_linkC,>,0)) : (void)0)
238 #ifdef BUF_CONSISTENCY_CHECK
239 int bf_consistency_check
ARGS(( void ));
240 void bf_check_acc
ARGS(( acc_t
*acc
));
241 void _bf_mark_1acc
ARGS(( char *clnt_file
, int clnt_line
, acc_t
*acc
));
242 void _bf_mark_acc
ARGS(( char *clnt_file
, int clnt_line
, acc_t
*acc
));
248 * $PchId: buf.h,v 1.13 2003/09/10 08:52:09 philip Exp $