]> git.ozlabs.org Git - ppp.git/blob - NeXT/nbq.h
mods for optional MS-CHAP support
[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 #include <kernserv/prototypes.h>
18 #include "netbuf.h"
19
20 struct qparms {
21     u_char      q_low, q_high, q_max;
22     char        *q_name;
23 };
24
25 struct nb_queue {
26     char        *name;
27     int         low, high, max, len, dropped;
28     netbuf_t    head, tail;
29 };
30
31 typedef u_int mark_t;
32 #define NB_EXTRA (sizeof(mark_t)+sizeof(netbuf_t))
33
34 static inline void
35 nb_set_next(netbuf_t nb, netbuf_t ptr)
36 {
37 if(nb) bcopy(&ptr,nb_map(nb)-sizeof(netbuf_t),sizeof(netbuf_t));
38 }
39
40 static inline void
41 nb_get_next(netbuf_t nb, netbuf_t *ptr)
42 {
43 if(nb && ptr) bcopy(nb_map(nb)-sizeof(netbuf_t),ptr,sizeof(netbuf_t));
44 }
45
46 static inline void
47 nb_set_mark(netbuf_t nb, mark_t ptr)
48 {
49 if(nb) bcopy(&ptr,nb_map(nb)-NB_EXTRA,sizeof(mark_t));
50 }
51
52 static inline void
53 nb_get_mark(netbuf_t nb, mark_t *ptr)
54 {
55 if(nb && ptr) bcopy(nb_map(nb)-NB_EXTRA,ptr,sizeof(mark_t));
56 }
57
58 static inline void
59 ppp_nb_shrink_top(netbuf_t nb, unsigned int size)
60 {
61     netbuf_t ptr;
62     mark_t   mark;
63     nb_get_next(nb,&ptr);
64     nb_get_mark(nb,&mark);
65     nb_shrink_top(nb,size);
66     nb_set_mark(nb,mark);
67     nb_set_next(nb,ptr);
68 }
69
70 static inline void
71 ppp_nb_grow_top(netbuf_t nb, unsigned int size)
72 {
73     netbuf_t ptr;
74     mark_t   mark;
75     nb_get_next(nb,&ptr);
76     nb_get_mark(nb,&mark);
77     nb_grow_top(nb,size);
78     nb_set_mark(nb,mark);
79     nb_set_next(nb,ptr);
80 }
81
82 static inline netbuf_t
83 ppp_nb_alloc(unsigned int size)
84 {
85     netbuf_t nb;
86
87     size+=NB_EXTRA;
88     nb=nb_alloc(size);
89     if(nb) {
90         nb_shrink_top(nb,NB_EXTRA);
91         nb_set_next(nb,NULL);
92         nb_set_mark(nb,0);
93     }
94     return nb;
95 }
96 #endif /* __NBQ_H__ */
97