]> git.ozlabs.org Git - ppp.git/blob - NeXT/nbq.h
update for 2.3.5
[ppp.git] / NeXT / nbq.h
1 /*
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 !
8  * PCF
9  */
10
11 #ifndef __NBQ_H__
12 #define __NBQ_H__
13
14 #define KERNEL 1
15
16 #include <sys/types.h>
17 #if !(NS_TARGET >= 40)
18 #include <kernserv/prototypes.h>
19 #endif /* NS_TARGET */
20
21 #include "netbuf.h"
22 typedef u_int mark_t;
23
24 #define NETBUF_T netbuf_t
25 #define NB_ALLOC ppp_nb_alloc
26 #define NB_FREE nb_free
27 #define NB_MAP nb_map
28 #define NB_SIZE nb_size
29 #define NB_SHRINK_TOP ppp_nb_shrink_top
30 #define NB_GROW_TOP ppp_nb_grow_top
31 #define NB_SHRINK_BOT nb_shrink_bot
32 #define NB_GROW_BOT nb_grow_bot
33 #define NB_READ nb_read
34 #define NB_WRITE nb_write
35 #define NB_GET_MARK nb_get_mark
36 #define NB_SET_MARK nb_set_mark
37 #define NB_GET_NEXT nb_get_next
38 #define NB_SET_NEXT nb_set_next
39 #define nb_TO_NB(nb) (nb)
40 #define NB_TO_nb(NB) (NB)
41
42
43 struct qparms {
44     u_char      q_low, q_high, q_max;
45     char        *q_name;
46 };
47
48 struct nb_queue {
49     char        *name;
50     int         low, high, max, len, dropped;
51     NETBUF_T    head, tail;
52 };
53
54 #define NB_EXTRA (sizeof(mark_t)+sizeof(netbuf_t))
55
56 static inline void
57 nb_set_next(netbuf_t nb, netbuf_t ptr)
58 {
59 if(nb) bcopy(&ptr,NB_MAP(nb)-sizeof(netbuf_t),sizeof(netbuf_t));
60 }
61
62 static inline void
63 nb_get_next(netbuf_t nb, netbuf_t *ptr)
64 {
65 if(nb && ptr) bcopy(NB_MAP(nb)-sizeof(netbuf_t),ptr,sizeof(netbuf_t));
66 }
67
68 static inline void
69 nb_set_mark(netbuf_t nb, mark_t ptr)
70 {
71 if(nb) bcopy(&ptr,NB_MAP(nb)-NB_EXTRA,sizeof(mark_t));
72 }
73
74 static inline void
75 nb_get_mark(netbuf_t nb, mark_t *ptr)
76 {
77 if(nb && ptr) bcopy(NB_MAP(nb)-NB_EXTRA,ptr,sizeof(mark_t));
78 }
79
80 static inline void
81 ppp_nb_shrink_top(netbuf_t nb, unsigned int size)
82 {
83     netbuf_t ptr;
84     mark_t   mark;
85     NB_GET_NEXT(nb,&ptr);
86     NB_GET_MARK(nb,&mark);
87     nb_shrink_top(nb,size);
88     NB_SET_MARK(nb,mark);
89     NB_SET_NEXT(nb,ptr);
90 }
91
92 static inline void
93 ppp_nb_grow_top(netbuf_t nb, unsigned int size)
94 {
95     netbuf_t ptr;
96     mark_t   mark;
97     NB_GET_NEXT(nb,&ptr);
98     NB_GET_MARK(nb,&mark);
99     nb_grow_top(nb,size);
100     NB_SET_MARK(nb,mark);
101     NB_SET_NEXT(nb,ptr);
102 }
103
104
105 static inline netbuf_t
106 ppp_nb_alloc(unsigned int size)
107 {
108     netbuf_t nb;
109
110     size+=NB_EXTRA;
111     nb=nb_alloc(size);
112     if(nb) {
113         nb_shrink_top(nb,NB_EXTRA);
114         NB_SET_NEXT(nb,NULL);
115         NB_SET_MARK(nb,0);
116     }
117     return nb;
118 }
119 #endif /* __NBQ_H__ */
120