xref: /openbsd-src/usr.sbin/npppd/common/radish.h (revision 4c1e55dc91edd6e69ccc60ce855900fbc12cf34f)
1 /*
2  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the project nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  */
30 
31 /*
32  * radish.h
33  *
34  * Version:	0.5
35  * Created:	May     27, 1995
36  * Modified:	January 11, 1997
37  * Author:	Kazu YAMAMOTO
38  * Email: 	kazu@is.aist-nara.ac.jp
39  */
40 
41 #ifndef __P
42 #ifdef __STDC__
43 #define __P(x) x
44 #else
45 #define __P(x) ()
46 #endif /* __STDC__ */
47 #endif /* __P */
48 
49 #ifdef RADISH
50 #ifndef _NET_RADISH_H_
51 #define _NET_RADISH_H_
52 
53 struct radish {
54 	struct sockaddr	*rd_route;	/* destination route */
55 	struct sockaddr	*rd_mask;	/* destination mask */
56 	u_int rd_masklen;		/* length of mask */
57 	u_short rd_masklim;		/* length of mask / 8 : test point */
58 	u_char  rd_bmask;		/* byte mask */
59 	u_char	rd_btest;		/* bit to test */
60 	struct radish *rd_p;		/* parent */
61 	struct radish *rd_l;		/* left child */
62 	struct radish *rd_r;		/* right child */
63 #ifndef GENERIC_USE
64 	struct rtentry *rd_rtent;	/* rtentry */
65 #else /* GENERIC_USE */
66 	void *rd_rtent;	/* rtentry */
67 #endif /* GENERIC_USE */
68 };
69 
70 struct radish_head {
71 	int 	rdh_slen;	/* socket address length */
72 	int 	rdh_offset;	/* address start byte */
73 	int 	rdh_alen;	/* address length */
74 	void 	*rdh_masks;
75 	struct radish *rdh_top;
76 	int	(*rdh_match)(void *, void *);
77 };
78 
79 #ifdef KERNEL
80 #define Bcmp(a, b, n) bcmp(((caddr_t)(a)), ((caddr_t)(b)), (unsigned)(n))
81 #define Bcopy(a, b, n) bcopy(((caddr_t)(a)), ((caddr_t)(b)), (unsigned)(n))
82 #define Bzero(p, n) bzero((caddr_t)(p), (unsigned)(n));
83 #define R_Malloc(p, t, n) (p = (t) malloc((unsigned long)(n), M_RTABLE, M_DONTWAIT))
84 #define Free(p) free((caddr_t)p, M_RTABLE);
85 #else /* KERNEL */
86 #ifndef Bcmp
87 #define Bcmp(a, b, n) memcmp(((char *)(a)), ((char *)(b)), (size_t)(n))
88 #endif
89 #ifndef Bzero
90 #define Bzero(p, n) memset((char *)(p), 0, (size_t)(n))
91 #endif
92 #define R_Malloc(p, t, n) (p = (t) malloc((unsigned int)(n)))
93 #define Free(p) free((char *)p);
94 #endif /* KERNEL */
95 
96 /*
97  * prototype for radish functions
98  */
99 
100 int rd_inithead __P((void **, int, int, int, int, int (*)(void *, void *)));
101 struct sockaddr *rd_mask __P((struct sockaddr *, struct radish_head *, int *));
102 
103 #ifndef GENERIC_USE
104 int rd_insert __P((struct sockaddr *, struct sockaddr *,
105 		   struct radish_head *, struct rtentry *));
106 #else /* GENERIC_USE */
107 int rd_insert __P((struct sockaddr *, struct sockaddr *,
108 		   struct radish_head *, void *));
109 #endif /* GENERIC_USE */
110 int rd_glue __P((struct radish *, struct radish *, int, struct radish_head *));
111 int rd_match __P((struct sockaddr *, struct radish_head *, struct radish **));
112 int rd_match_next __P((struct sockaddr *, struct radish_head *, struct radish **, struct radish *));
113 #ifndef GENERIC_USE
114 struct rtentry *rd_lookup __P((struct sockaddr *,
115 			      struct sockaddr *, struct radish_head *));
116 int rd_delete __P((struct sockaddr *, struct sockaddr *,
117 		   struct radish_head *, struct rtentry **));
118 #else /* GENERIC_USE */
119 void *rd_lookup __P((struct sockaddr *,
120 			      struct sockaddr *, struct radish_head *));
121 int rd_delete __P((struct sockaddr *, struct sockaddr *,
122 		   struct radish_head *, void **));
123 #endif /* GENERIC_USE */
124 void rd_unlink __P((struct radish *, struct radish *));
125 int  rd_walktree __P((struct radish_head *, int (*)(struct radish *, void *), void *));
126 int  rd_refines __P((void *, void *));
127 #endif /* !_NET_RADISH_H_ */
128 #endif /* RADISH */
129