2 * All very trivial - the simpler the better I say. We try and keep
3 * quqes of netbufs by squirreling a pointer away below the data area.
4 * This is done by the ppp_nb_alloc function. As long as everyone
5 * uses the ppp shrink and grow functions we should be o.k. This code
6 * has now been modified to keep the mark_t stuff nhere as well since
7 * we probably shafted that good and proper in the last version. oops !
17 #include <sys/types.h>
18 #include <kernserv/prototypes.h>
24 * Netbufs and Netbuf wrappers don't help us because we
25 * have no way of keeping track of information on start
26 * position once nb_grow* or nb_shrink* are called.
31 #warning ...you are compiling with NETBUF_PROXY
33 typedef struct _bpf_encapsulater
36 * Depending on the direction of packet travel, these
37 * values have different meanings.
40 * first -- time first byte of packet received.
41 * second -- time last byte of packet received.
42 * third -- Decompression start time
43 * fourth -- Packet Handoff time
44 * (second-first) -- receive time
45 * (third-second) -- queue time waiting for decompression
46 * (fourth-third) -- decompression time
47 * (fourth - first) -- total receive time.
48 * (fourth - second) -- total system process time.
50 * async_esc -- The number of characters escaped in this packet.
51 * size1 -- The size of the inital packet before decompression.
52 * This value includes the expansion caused by AC and PC compression.
54 * AC implies packet got increased by 2 during receive.
55 * PC implies packet got increased by 1 during receive.
56 * This + "async_esc" - (AC + PC expansion) describe actual bytes over link.
57 * Includes PPP header and trailer.
58 * Doesn't count framing PPP_FLAG character.
60 * size2 -- The size after BSD decompression. PPP trailer was removed
61 * so packet should be at least 2 shorter than original.
62 * size3 -- The size after VJ decompression.
65 * OUTGOING: (very similar to incoming)
66 * first -- time packet arrived to pppwrite() or pppoutput()
67 * second -- time compression started
68 * third -- time compression ended
69 * fourth -- time first byte sent to interface
70 * fifth -- time last byte sent to interface
72 * (second - first) Time waiting in system before compression
73 * (third - second) Time for compression
74 * (fourth - third) Time waiting in system out queue waiting to be
75 * selected for sending to interface
76 * (fourth - first) Total system processing time
77 * (fifth-fourth) Total interface send time.
78 * (fifth-first) Total send time.
80 * size1 -- The size of the intial packet as receved from the stack
81 * size2 -- The size after VJ compression
82 * size3 -- The size after BSD compression
85 struct timeval first, second, third, fourth, fifth;
86 unsigned async_esc, size1, size2, size3;
88 int flags; /* info about packet */
89 #define NBFLAG_INCOMING 0x01 /* else outgoing */
90 #define NBFLAG_AC 0x02 /* Address compressed */
91 #define NBFLAG_PC 0x04 /* Protocol Compressed */
92 #define NBFLAG_VJC 0x08 /* VJ compressed */
93 #define NBFLAG_CCP 0x10 /* BSD compressed */
94 #define NBFLAG_CCPINC 0x20 /* BSD incompressible */
95 #define NBFLAG_VJCINC 0x40 /* VJ incompressible */
99 typedef struct _ppp_netbuf_t
102 netbuf_t orig_buffer; /*
103 * Original outgoing datagram
104 * received. We do compression and
105 * statistics gathering on buffer,
106 * we send buffer, but we return
107 * orig_buffer to BPF so that it doesn't
108 * have to understand all the compression.
112 struct _ppp_netbuf_t *next; /* for linked list */
114 unsigned int size; /* original size requested for netbuf.
115 * We leave it up to caller to
116 * determine extra space they need. We
117 * may also include extra space we need
118 * for bounds checking.
121 unsigned char *wrapper, /* unaligned address returned for this containing
122 * structure. Used for freeing.
125 *init_offset; /* Init_offset is nb_map of the netbuf_t before
126 * user can change it around. Can check bounds
131 bpf_encapsulater pktinfo; /* The size and compression stats that
132 * get passed to user level tcpdump
138 * These prototypes are identical to the corrisponding functions
139 * found in netbuf.h except they use the ppp_netbuf_t type.
142 extern ppp_netbuf_t cb_nb_alloc(unsigned size);
143 extern void cb_nb_free(ppp_netbuf_t nb);
144 extern void cb_nb_duplicate(ppp_netbuf_t from, ppp_netbuf_t to);
145 extern char * cb_nb_map(ppp_netbuf_t nb);
146 extern char * cb_nb_map_orig(ppp_netbuf_t nb);
147 extern unsigned cb_nb_size(ppp_netbuf_t nb);
148 extern unsigned cb_nb_size_orig(ppp_netbuf_t nb);
149 extern int cb_nb_shrink_top(ppp_netbuf_t nb, unsigned size);
150 extern int cb_nb_grow_top(ppp_netbuf_t nb, unsigned size);
151 extern int cb_nb_shrink_bot(ppp_netbuf_t nb, unsigned size);
152 extern int cb_nb_grow_bot(ppp_netbuf_t nb, unsigned size);
153 extern int cb_nb_read(ppp_netbuf_t nb, unsigned offset, unsigned size, void *target);
154 extern int cb_nb_write(ppp_netbuf_t nb, unsigned offset, unsigned size, void *source);
155 extern void cb_nb_get_mark(ppp_netbuf_t nb, mark_t *ptr);
156 extern void cb_nb_set_mark(ppp_netbuf_t nb, mark_t ptr);
157 extern void cb_nb_get_next(ppp_netbuf_t nb, ppp_netbuf_t *ptr);
158 extern void cb_nb_set_next(ppp_netbuf_t nb, ppp_netbuf_t ptr);
159 extern ppp_netbuf_t cb_nb_to_NB(netbuf_t);
160 extern netbuf_t cb_NB_to_nb(ppp_netbuf_t);
162 #define NETBUF_T ppp_netbuf_t
163 #define NB_ALLOC cb_nb_alloc
164 #define NB_FREE cb_nb_free
165 #define NB_DUPLICATE cb_nb_duplicate
166 #define NB_MAP cb_nb_map
167 #define NB_MAP_ORIG cb_nb_map_orig
168 #define NB_SIZE cb_nb_size
169 #define NB_SIZE_ORIG cb_nb_size_orig
170 #define NB_SHRINK_TOP cb_nb_shrink_top
171 #define NB_GROW_TOP cb_nb_grow_top
172 #define NB_SHRINK_BOT cb_nb_shrink_bot
173 #define NB_GROW_BOT cb_nb_grow_bot
174 #define NB_READ cb_nb_read
175 #define NB_WRITE cb_nb_write
176 #define NB_GET_MARK cb_nb_get_mark
177 #define NB_SET_MARK cb_nb_set_mark
178 #define NB_GET_NEXT cb_nb_get_next
179 #define NB_SET_NEXT cb_nb_set_next
180 #define nb_TO_NB cb_nb_to_NB
181 #define NB_TO_nb cb_NB_to_nb
183 #else /* NETBUF_PROXY */
185 #define NETBUF_T netbuf_t
186 #define NB_ALLOC ppp_nb_alloc
187 #define NB_FREE nb_free
188 #define NB_MAP nb_map
189 #define NB_SIZE nb_size
190 #define NB_SHRINK_TOP ppp_nb_shrink_top
191 #define NB_GROW_TOP ppp_nb_grow_top
192 #define NB_SHRINK_BOT nb_shrink_bot
193 #define NB_GROW_BOT nb_grow_bot
194 #define NB_READ nb_read
195 #define NB_WRITE nb_write
196 #define NB_GET_MARK nb_get_mark
197 #define NB_SET_MARK nb_set_mark
198 #define NB_GET_NEXT nb_get_next
199 #define NB_SET_NEXT nb_set_next
200 #define nb_TO_NB(nb) (nb)
201 #define NB_TO_nb(NB) (NB)
203 #endif /* NETBUF_PROXY */
207 u_char q_low, q_high, q_max;
213 int low, high, max, len, dropped;
218 #define NB_EXTRA (sizeof(mark_t)+sizeof(netbuf_t))
221 nb_set_next(netbuf_t nb, netbuf_t ptr)
223 if(nb) bcopy(&ptr,NB_MAP(nb)-sizeof(netbuf_t),sizeof(netbuf_t));
227 nb_get_next(netbuf_t nb, netbuf_t *ptr)
229 if(nb && ptr) bcopy(NB_MAP(nb)-sizeof(netbuf_t),ptr,sizeof(netbuf_t));
233 nb_set_mark(netbuf_t nb, mark_t ptr)
235 if(nb) bcopy(&ptr,NB_MAP(nb)-NB_EXTRA,sizeof(mark_t));
239 nb_get_mark(netbuf_t nb, mark_t *ptr)
241 if(nb && ptr) bcopy(NB_MAP(nb)-NB_EXTRA,ptr,sizeof(mark_t));
245 ppp_nb_shrink_top(netbuf_t nb, unsigned int size)
249 NB_GET_NEXT(nb,&ptr);
250 NB_GET_MARK(nb,&mark);
251 nb_shrink_top(nb,size);
252 NB_SET_MARK(nb,mark);
257 ppp_nb_grow_top(netbuf_t nb, unsigned int size)
261 NB_GET_NEXT(nb,&ptr);
262 NB_GET_MARK(nb,&mark);
263 nb_grow_top(nb,size);
264 NB_SET_MARK(nb,mark);
269 static inline netbuf_t
270 ppp_nb_alloc(unsigned int size)
277 NB_SHRINK_TOP(nb,NB_EXTRA);
278 NB_SET_NEXT(nb,NULL);
283 #endif /* NETBUF_PROXY */
284 #endif /* __NBQ_H__ */