Home | History | Annotate | Line # | Download | only in netinet
      1  1.3   darrenr /*	$NetBSD: radix_ipf.h,v 1.3 2012/07/22 14:27:52 darrenr Exp $	*/
      2  1.1  christos 
      3  1.1  christos /*
      4  1.3   darrenr  * Copyright (C) 2012 by Darren Reed.
      5  1.1  christos  *
      6  1.1  christos  * See the IPFILTER.LICENCE file for details on licencing.
      7  1.1  christos  */
      8  1.1  christos #ifndef __RADIX_IPF_H__
      9  1.1  christos #define	__RADIX_IPF_H__
     10  1.1  christos 
     11  1.1  christos #ifndef U_32_T
     12  1.1  christos typedef unsigned int u_32_t;
     13  1.1  christos # define	U_32_T	1
     14  1.1  christos #endif
     15  1.1  christos 
     16  1.1  christos typedef struct ipf_rdx_mask {
     17  1.1  christos 	struct ipf_rdx_mask	*next;
     18  1.1  christos 	struct ipf_rdx_node	*node;
     19  1.1  christos 	u_32_t			*mask;
     20  1.1  christos 	int			maskbitcount;
     21  1.1  christos } ipf_rdx_mask_t;
     22  1.1  christos 
     23  1.1  christos typedef struct ipf_rdx_node {
     24  1.1  christos 	struct ipf_rdx_node	*left;
     25  1.1  christos 	struct ipf_rdx_node	*right;
     26  1.1  christos 	struct ipf_rdx_node	*parent;
     27  1.1  christos 	struct ipf_rdx_node	*dupkey;
     28  1.1  christos 	struct ipf_rdx_mask	*masks;
     29  1.1  christos 	struct ipf_rdx_mask	*mymask;
     30  1.1  christos 	u_32_t			*addrkey;
     31  1.1  christos 	u_32_t			*maskkey;
     32  1.1  christos 	u_32_t			*addroff;
     33  1.1  christos 	u_32_t			*maskoff;
     34  1.1  christos 	u_32_t			lastmask;
     35  1.1  christos 	u_32_t			bitmask;
     36  1.1  christos 	int			offset;
     37  1.1  christos 	int			index;
     38  1.1  christos 	int			maskbitcount;
     39  1.1  christos 	int			root;
     40  1.1  christos #ifdef RDX_DEBUG
     41  1.1  christos 	char			name[40];
     42  1.1  christos #endif
     43  1.1  christos } ipf_rdx_node_t;
     44  1.1  christos 
     45  1.1  christos struct ipf_rdx_head;
     46  1.1  christos 
     47  1.1  christos typedef	void		(* radix_walk_func_t)(ipf_rdx_node_t *, void *);
     48  1.1  christos typedef	ipf_rdx_node_t	*(* idx_hamn_func_t)(struct ipf_rdx_head *,
     49  1.1  christos 					     addrfamily_t *, addrfamily_t *,
     50  1.1  christos 					     ipf_rdx_node_t *);
     51  1.1  christos typedef	ipf_rdx_node_t	*(* idx_ham_func_t)(struct ipf_rdx_head *,
     52  1.1  christos 					    addrfamily_t *, addrfamily_t *);
     53  1.1  christos typedef	ipf_rdx_node_t	*(* idx_ha_func_t)(struct ipf_rdx_head *,
     54  1.1  christos 					   addrfamily_t *);
     55  1.1  christos typedef	void		(* idx_walk_func_t)(struct ipf_rdx_head *,
     56  1.1  christos 					    radix_walk_func_t, void *);
     57  1.1  christos 
     58  1.1  christos typedef struct ipf_rdx_head {
     59  1.1  christos 	ipf_rdx_node_t	*root;
     60  1.1  christos 	ipf_rdx_node_t	nodes[3];
     61  1.1  christos 	ipfmutex_t	lock;
     62  1.1  christos 	idx_hamn_func_t	addaddr;	/* add addr/mask to tree */
     63  1.1  christos 	idx_ham_func_t	deladdr;	/* delete addr/mask from tree */
     64  1.1  christos 	idx_ham_func_t	lookup;		/* look for specific addr/mask */
     65  1.1  christos 	idx_ha_func_t	matchaddr;	/* search tree for address match */
     66  1.1  christos 	idx_walk_func_t	walktree;	/* walk entire tree */
     67  1.1  christos } ipf_rdx_head_t;
     68  1.1  christos 
     69  1.1  christos typedef struct radix_softc {
     70  1.1  christos 	u_char			*zeros;
     71  1.1  christos 	u_char			*ones;
     72  1.1  christos } radix_softc_t;
     73  1.1  christos 
     74  1.1  christos #undef	RADIX_NODE_HEAD_LOCK
     75  1.1  christos #undef	RADIX_NODE_HEAD_UNLOCK
     76  1.1  christos #ifdef	_KERNEL
     77  1.1  christos # define	RADIX_NODE_HEAD_LOCK(x)		MUTEX_ENTER(&(x)->lock)
     78  1.1  christos # define	RADIX_NODE_HEAD_UNLOCK(x)	MUTEX_UNLOCK(&(x)->lock)
     79  1.1  christos #else
     80  1.1  christos # define	RADIX_NODE_HEAD_LOCK(x)
     81  1.1  christos # define	RADIX_NODE_HEAD_UNLOCK(x)
     82  1.1  christos #endif
     83  1.1  christos 
     84  1.2  christos extern	void	*ipf_rx_create(void);
     85  1.2  christos extern	int	ipf_rx_init(void *);
     86  1.2  christos extern	void	ipf_rx_destroy(void *);
     87  1.2  christos extern	int	ipf_rx_inithead(radix_softc_t *, ipf_rdx_head_t **);
     88  1.2  christos extern	void	ipf_rx_freehead(ipf_rdx_head_t *);
     89  1.2  christos extern	ipf_rdx_node_t *ipf_rx_addroute(ipf_rdx_head_t *,
     90  1.1  christos 					     addrfamily_t *, addrfamily_t *,
     91  1.2  christos 					     ipf_rdx_node_t *);
     92  1.2  christos extern	ipf_rdx_node_t *ipf_rx_delete(ipf_rdx_head_t *, addrfamily_t *,
     93  1.2  christos 					   addrfamily_t *);
     94  1.2  christos extern	void	ipf_rx_walktree(ipf_rdx_head_t *, radix_walk_func_t,
     95  1.2  christos 				     void *);
     96  1.1  christos 
     97  1.1  christos #endif /* __RADIX_IPF_H__ */
     98