]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netinet6/natpt_list.h
10a77de7592a1656fd656d8b699bedefb31c27e6
1 /* $KAME: natpt_list.h,v 1.5 2000/03/25 07:23:55 sumikawa Exp $ */
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #define CELL_FREE_MARKER ((Cell *)0xdeadface)
33 #define CELL_WEIRD_ADDR ((Cell *)0xdeadbeef)
35 Cell
*LST_cons
__P((void *, void *));
36 void LST_free
__P((Cell
*));
37 Cell
*LST_last
__P((Cell
*));
38 int LST_length
__P((Cell
*));
39 Cell
*LST_hookup
__P((Cell
*, void *));
40 Cell
*LST_hookup_list
__P((Cell
**, void *));
41 Cell
*LST_remove_elem
__P((Cell
**, void *));
44 #ifdef INCLUDE_NATPT_LIST_C
47 * Typedefs and Miscellaneous definitions
55 #define CELL_PAGE (CELL_NUMS * sizeof(Cell))
59 * Typedefs and Miscellaneous definitions
62 static int _cell_used
;
63 static int _cell_free
;
64 static Cell
*_cell_freeList
;
65 static Cell
*_cell_mallBlock
;
67 static Cell
*_getCell
__P((void));
68 static Cell
*_getEmptyCell
__P((void));
72 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
73 static MALLOC_DEFINE(M_NATPT
, "NATPT", "Network Address Translation - Protocol Translation");
74 #endif /* defined(__FreeBSD__) && __FreeBSD__ >= 3 */
75 #endif /* defined(_KERNEL) */
83 LST_cons(void *c_car
, void *c_cdr
)
101 if (CAR(cell
) != CELL_FREE_MARKER
)
103 CAR(cell
) = CELL_FREE_MARKER
;
104 CDR(cell
) = _cell_freeList
;
105 _cell_freeList
= cell
;
116 register Cell
*ptr
= NULL
;
121 for (ptr
= list
; CDR(ptr
) != NULL
; ptr
= CDR(ptr
)) ;
128 LST_length(Cell
*list
)
130 register int retval
= 0;
138 for (ptr
= list
; ptr
; retval
++, ptr
= CDR(ptr
)) ;
146 LST_hookup(Cell
*list
, void *elem
)
148 register Cell
*ptr
= NULL
;
151 ptr
= LST_cons(elem
, NULL
);
153 CDR(LST_last(list
)) = LST_cons(elem
, NULL
);
160 LST_hookup_list(Cell
**list
, void *elem
)
162 register Cell
*ptr
= NULL
;
165 *list
= LST_cons(elem
, NULL
);
167 CDR(LST_last(*list
)) = LST_cons(elem
, NULL
);
174 LST_remove_elem(Cell
**list
, void *elem
)
176 register Cell
*p
, *q
;
181 for (p
= *list
, q
= NULL
; p
; q
= p
, p
= CDR(p
))
208 if (_cell_freeList
== NULL
)
209 _cell_freeList
= _getEmptyCell();
211 ptr
= _cell_freeList
;
212 _cell_freeList
= CDR(_cell_freeList
);
222 register Cell
*ptr
= NULL
;
225 #if (defined(KERNEL)) || (defined(_KERNEL))
226 MALLOC(ptr
, Cell
*, CELL_PAGE
, M_NATPT
, M_NOWAIT
);
228 ptr
= (Cell
*)malloc(CELL_PAGE
);
229 #endif /* defined(KERNEL) */
232 printf("ENOBUFS in _getEmptyCell %d\n", __LINE__
);
236 CAR(ptr
) = (Cell
*)ptr
;
239 if (_cell_mallBlock
== NULL
)
240 _cell_mallBlock
= ptr
;
242 CDR(LST_last(_cell_mallBlock
)) = ptr
;
245 for (iter
= CELL_NUMS
- 2 , p
= ptr
; iter
; iter
-- , p
++)
246 CAR(p
) = CELL_WEIRD_ADDR
, CDR(p
) = p
+ 1;
247 CAR(p
) = CELL_WEIRD_ADDR
;
249 _cell_free
+= CELL_NUMS
- 1;
254 #endif /* defined(INCLUDE_NATPT_LIST_C) */