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