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