This enables plugins called via hooks/notifiers triggered
[mpls-ppp.git] / NeXT / nbq.h
blob0fd632c0b70fb582a66139867c3a5e585ab99f53
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 */
11 #ifndef __NBQ_H__
12 #define __NBQ_H__
14 #define KERNEL 1
16 #include <sys/types.h>
17 #if !(NS_TARGET >= 40)
18 #include <kernserv/prototypes.h>
19 #endif /* NS_TARGET */
21 #include "netbuf.h"
22 typedef u_int mark_t;
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)
43 struct qparms {
44 u_char q_low, q_high, q_max;
45 char *q_name;
48 struct nb_queue {
49 char *name;
50 int low, high, max, len, dropped;
51 NETBUF_T head, tail;
54 #define NB_EXTRA (sizeof(mark_t)+sizeof(netbuf_t))
56 static inline void
57 nb_set_next(netbuf_t nb, netbuf_t ptr)
59 if(nb) bcopy(&ptr,NB_MAP(nb)-sizeof(netbuf_t),sizeof(netbuf_t));
62 static inline void
63 nb_get_next(netbuf_t nb, netbuf_t *ptr)
65 if(nb && ptr) bcopy(NB_MAP(nb)-sizeof(netbuf_t),ptr,sizeof(netbuf_t));
68 static inline void
69 nb_set_mark(netbuf_t nb, mark_t ptr)
71 if(nb) bcopy(&ptr,NB_MAP(nb)-NB_EXTRA,sizeof(mark_t));
74 static inline void
75 nb_get_mark(netbuf_t nb, mark_t *ptr)
77 if(nb && ptr) bcopy(NB_MAP(nb)-NB_EXTRA,ptr,sizeof(mark_t));
80 static inline void
81 ppp_nb_shrink_top(netbuf_t nb, unsigned int size)
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);
92 static inline void
93 ppp_nb_grow_top(netbuf_t nb, unsigned int size)
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);
105 static inline netbuf_t
106 ppp_nb_alloc(unsigned int size)
108 netbuf_t nb;
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);
117 return nb;
119 #endif /* __NBQ_H__ */