xref: /openbsd/usr.sbin/npppd/common/radish.h (revision 67bdad80)
1 /*	$OpenBSD: radish.h,v 1.6 2017/05/30 17:52:05 yasuoka 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 _RADISH_H_
43 #define _RADISH_H_
44 
45 struct radish {
46 	struct sockaddr	*rd_route;	/* destination route */
47 	struct sockaddr	*rd_mask;	/* destination mask */
48 	u_int rd_masklen;		/* length of mask */
49 	u_short rd_masklim;		/* length of mask / 8 : test point */
50 	u_char  rd_bmask;		/* byte mask */
51 	u_char	rd_btest;		/* bit to test */
52 	struct radish *rd_p;		/* parent */
53 	struct radish *rd_l;		/* left child */
54 	struct radish *rd_r;		/* right child */
55 	void *rd_rtent;			/* rtentry */
56 };
57 
58 struct radish_head {
59 	int 	rdh_slen;	/* socket address length */
60 	int 	rdh_offset;	/* address start byte */
61 	int 	rdh_alen;	/* address length */
62 	void 	*rdh_masks;
63 	struct radish *rdh_top;
64 	int	(*rdh_match)(void *, void *);
65 };
66 
67 #ifndef Bcmp
68 #define Bcmp(a, b, n) memcmp(((char *)(a)), ((char *)(b)), (size_t)(n))
69 #endif
70 #ifndef Bzero
71 #define Bzero(p, n) memset((char *)(p), 0, (size_t)(n))
72 #endif
73 #define R_Malloc(p, t, n) (p = (t) malloc((n)))
74 #define Free(p) free((char *)p);
75 
76 /*
77  * prototype for radish functions
78  */
79 
80 int rd_inithead(void **, int, int, int, int, int (*)(void *, void *));
81 struct sockaddr *rd_mask(struct sockaddr *, struct radish_head *, int *);
82 
83 int rd_insert(struct sockaddr *, struct sockaddr *,
84 		   struct radish_head *, void *);
85 int rd_glue(struct radish *, struct radish *, int, struct radish_head *);
86 int rd_match(struct sockaddr *, struct radish_head *, struct radish **);
87 int rd_match_next(struct sockaddr *, struct radish_head *, struct radish **, struct radish *);
88 void *rd_lookup(struct sockaddr *,
89 			      struct sockaddr *, struct radish_head *);
90 int rd_delete(struct sockaddr *, struct sockaddr *,
91 		   struct radish_head *, void **);
92 void rd_unlink(struct radish *, struct radish *);
93 int  rd_walktree(struct radish_head *, int (*)(struct radish *, void *), void *);
94 int  rd_refines(void *, void *);
95 #endif
96