epoc32/include/stdapis/net/radix.h
branchSymbian2
changeset 2 2fe1408b6811
child 4 837f303aceeb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/stdapis/net/radix.h	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,164 @@
     1.4 +/*-
     1.5 + * Copyright (c) 1988, 1989, 1993
     1.6 + *	The Regents of the University of California.  All rights reserved.
     1.7 +* © Portions copyright (c) 2007 Symbian Software Ltd. All rights reserved.
     1.8 + * Redistribution and use in source and binary forms, with or without
     1.9 + * modification, are permitted provided that the following conditions
    1.10 + * are met:
    1.11 + * 1. Redistributions of source code must retain the above copyright
    1.12 + *    notice, this list of conditions and the following disclaimer.
    1.13 + * 2. Redistributions in binary form must reproduce the above copyright
    1.14 + *    notice, this list of conditions and the following disclaimer in the
    1.15 + *    documentation and/or other materials provided with the distribution.
    1.16 + * 4. Neither the name of the University nor the names of its contributors
    1.17 + *    may be used to endorse or promote products derived from this software
    1.18 + *    without specific prior written permission.
    1.19 + *
    1.20 + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    1.21 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1.22 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    1.23 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    1.24 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    1.25 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    1.26 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    1.27 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    1.28 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    1.29 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    1.30 + * SUCH DAMAGE.
    1.31 + *
    1.32 + *	@(#)radix.h	8.2 (Berkeley) 10/31/94
    1.33 + * $FreeBSD: src/sys/net/radix.h,v 1.26 2005/01/07 01:45:35 imp Exp $
    1.34 + */
    1.35 +
    1.36 +#ifndef _RADIX_H_
    1.37 +#define	_RADIX_H_
    1.38 +
    1.39 +#ifdef _KERNEL
    1.40 +#include <sys/_lock.h>
    1.41 +#include <sys/_mutex.h>
    1.42 +#endif
    1.43 +
    1.44 +/*
    1.45 + * Radix search tree node layout.
    1.46 + */
    1.47 +
    1.48 +struct radix_node {
    1.49 +	struct	radix_mask *rn_mklist;	/* list of masks contained in subtree */
    1.50 +	struct	radix_node *rn_parent;	/* parent */
    1.51 +	short	rn_bit;			/* bit offset; -1-index(netmask) */
    1.52 +	char	rn_bmask;		/* node: mask for bit test*/
    1.53 +	u_char	rn_flags;		/* enumerated next */
    1.54 +#define RNF_NORMAL	1		/* leaf contains normal route */
    1.55 +#define RNF_ROOT	2		/* leaf is root leaf for tree */
    1.56 +#define RNF_ACTIVE	4		/* This node is alive (for rtfree) */
    1.57 +	union {
    1.58 +		struct {			/* leaf only data: */
    1.59 +			caddr_t	rn_Key;		/* object of search */
    1.60 +			caddr_t	rn_Mask;	/* netmask, if present */
    1.61 +			struct	radix_node *rn_Dupedkey;
    1.62 +		} rn_leaf;
    1.63 +		struct {			/* node only data: */
    1.64 +			int	rn_Off;		/* where to start compare */
    1.65 +			struct	radix_node *rn_L;/* progeny */
    1.66 +			struct	radix_node *rn_R;/* progeny */
    1.67 +		} rn_node;
    1.68 +	}		rn_u;
    1.69 +#ifdef RN_DEBUG
    1.70 +	int rn_info;
    1.71 +	struct radix_node *rn_twin;
    1.72 +	struct radix_node *rn_ybro;
    1.73 +#endif
    1.74 +};
    1.75 +
    1.76 +#define	rn_dupedkey	rn_u.rn_leaf.rn_Dupedkey
    1.77 +#define	rn_key		rn_u.rn_leaf.rn_Key
    1.78 +#define	rn_mask		rn_u.rn_leaf.rn_Mask
    1.79 +#define	rn_offset	rn_u.rn_node.rn_Off
    1.80 +#define	rn_left		rn_u.rn_node.rn_L
    1.81 +#define	rn_right	rn_u.rn_node.rn_R
    1.82 +
    1.83 +/*
    1.84 + * Annotations to tree concerning potential routes applying to subtrees.
    1.85 + */
    1.86 +
    1.87 +struct radix_mask {
    1.88 +	short	rm_bit;			/* bit offset; -1-index(netmask) */
    1.89 +	char	rm_unused;		/* cf. rn_bmask */
    1.90 +	u_char	rm_flags;		/* cf. rn_flags */
    1.91 +	struct	radix_mask *rm_mklist;	/* more masks to try */
    1.92 +	union	{
    1.93 +		caddr_t	rmu_mask;		/* the mask */
    1.94 +		struct	radix_node *rmu_leaf;	/* for normal routes */
    1.95 +	}	rm_rmu;
    1.96 +	int	rm_refs;		/* # of references to this struct */
    1.97 +};
    1.98 +
    1.99 +#define	rm_mask rm_rmu.rmu_mask
   1.100 +#define	rm_leaf rm_rmu.rmu_leaf		/* extra field would make 32 bytes */
   1.101 +
   1.102 +#ifndef __SYMBIAN32__
   1.103 +typedef int walktree_f_t(struct radix_node *, void *);
   1.104 +
   1.105 +struct radix_node_head {
   1.106 +	struct	radix_node *rnh_treetop;
   1.107 +	int	rnh_addrsize;		/* permit, but not require fixed keys */
   1.108 +	int	rnh_pktsize;		/* permit, but not require fixed keys */
   1.109 +	struct	radix_node *(*rnh_addaddr)	/* add based on sockaddr */
   1.110 +		(void *v, void *mask,
   1.111 +		     struct radix_node_head *head, struct radix_node nodes[]);
   1.112 +	struct	radix_node *(*rnh_addpkt)	/* add based on packet hdr */
   1.113 +		(void *v, void *mask,
   1.114 +		     struct radix_node_head *head, struct radix_node nodes[]);
   1.115 +	struct	radix_node *(*rnh_deladdr)	/* remove based on sockaddr */
   1.116 +		(void *v, void *mask, struct radix_node_head *head);
   1.117 +	struct	radix_node *(*rnh_delpkt)	/* remove based on packet hdr */
   1.118 +		(void *v, void *mask, struct radix_node_head *head);
   1.119 +	struct	radix_node *(*rnh_matchaddr)	/* locate based on sockaddr */
   1.120 +		(void *v, struct radix_node_head *head);
   1.121 +	struct	radix_node *(*rnh_lookup)	/* locate based on sockaddr */
   1.122 +		(void *v, void *mask, struct radix_node_head *head);
   1.123 +	struct	radix_node *(*rnh_matchpkt)	/* locate based on packet hdr */
   1.124 +		(void *v, struct radix_node_head *head);
   1.125 +	int	(*rnh_walktree)			/* traverse tree */
   1.126 +		(struct radix_node_head *head, walktree_f_t *f, void *w);
   1.127 +	int	(*rnh_walktree_from)		/* traverse tree below a */
   1.128 +		(struct radix_node_head *head, void *a, void *m,
   1.129 +		     walktree_f_t *f, void *w);
   1.130 +	void	(*rnh_close)	/* do something when the last ref drops */
   1.131 +		(struct radix_node *rn, struct radix_node_head *head);
   1.132 +	struct	radix_node rnh_nodes[3];	/* empty tree for common case */
   1.133 +#ifdef _KERNEL
   1.134 +	struct	mtx rnh_mtx;			/* locks entire radix tree */
   1.135 +#endif
   1.136 +};
   1.137 +
   1.138 +#ifndef _KERNEL
   1.139 +#define R_Malloc(p, t, n) (p = (t) malloc((unsigned int)(n)))
   1.140 +#define R_Zalloc(p, t, n) (p = (t) calloc(1,(unsigned int)(n)))
   1.141 +#ifndef __SYMBIAN32__
   1.142 +#define Free(p) free((char *)p);
   1.143 +#endif
   1.144 +#else
   1.145 +#define R_Malloc(p, t, n) (p = (t) malloc((unsigned long)(n), M_RTABLE, M_NOWAIT))
   1.146 +#define R_Zalloc(p, t, n) (p = (t) malloc((unsigned long)(n), M_RTABLE, M_NOWAIT | M_ZERO))
   1.147 +#ifndef __SYMBIAN32__
   1.148 +#define Free(p) free((caddr_t)p, M_RTABLE);
   1.149 +#endif
   1.150 +#define	RADIX_NODE_HEAD_LOCK_INIT(rnh)	\
   1.151 +    mtx_init(&(rnh)->rnh_mtx, "radix node head", NULL, MTX_DEF | MTX_RECURSE)
   1.152 +#define	RADIX_NODE_HEAD_LOCK(rnh)	mtx_lock(&(rnh)->rnh_mtx)
   1.153 +#define	RADIX_NODE_HEAD_UNLOCK(rnh)	mtx_unlock(&(rnh)->rnh_mtx)
   1.154 +#define	RADIX_NODE_HEAD_DESTROY(rnh)	mtx_destroy(&(rnh)->rnh_mtx)
   1.155 +#define	RADIX_NODE_HEAD_LOCK_ASSERT(rnh) mtx_assert(&(rnh)->rnh_mtx, MA_OWNED)
   1.156 +#endif /* _KERNEL */
   1.157 +
   1.158 +struct radix_node
   1.159 +	 *rn_addmask(void *, int, int),
   1.160 +	 *rn_addroute (void *, void *, struct radix_node_head *,
   1.161 +			struct radix_node [2]),
   1.162 +	 *rn_delete(void *, void *, struct radix_node_head *),
   1.163 +	 *rn_lookup (void *v_arg, void *m_arg,
   1.164 +		        struct radix_node_head *head),
   1.165 +	 *rn_match(void *, struct radix_node_head *);
   1.166 +#endif //__SYMBIAN32__
   1.167 +#endif /* _RADIX_H_ */