xref: /openbsd/sys/net/art.h (revision fc61954a)
1 /* $OpenBSD: art.h,v 1.15 2016/08/30 07:42:57 jmatthew Exp $ */
2 
3 /*
4  * Copyright (c) 2015 Martin Pieuchot
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef _NET_ART_H_
20 #define _NET_ART_H_
21 
22 #include <sys/rwlock.h>
23 
24 #define ART_MAXLVL	32	/* We currently use 32 levels for IPv6. */
25 
26 /*
27  * Root of the ART tables, equivalent to the radix head.
28  */
29 struct art_root {
30 	struct srp		 ar_root;	/* First table */
31 	struct rwlock		 ar_lock;	/* Serialise modifications */
32 	uint8_t			 ar_bits[ART_MAXLVL];	/* Per level stride */
33 	uint8_t			 ar_nlvl;	/* Number of levels */
34 	uint8_t			 ar_alen;	/* Address length in bits */
35 	uint8_t			 ar_off;	/* Offset of the key in bytes */
36 	unsigned int		 ar_rtableid;	/* ID of this routing table */
37 };
38 
39 /*
40  * Forward declaration needed for the list of mpath routes
41  * attached to a single ART node.
42  */
43 struct rtentry;
44 
45 /*
46  * A node is the internal representation of a route entry.
47  */
48 struct art_node {
49 	SRPL_HEAD(, rtentry)	 an_rtlist;	/* Route related to this node */
50 	union {
51 		struct sockaddr	*an__dst;	/* Destination address (key) */
52 		struct art_node	*an__gc;	/* Entry on GC list */
53 	}			 an_pointer;
54 	uint8_t			 an_plen;	/* Prefix length */
55 };
56 #define an_dst	an_pointer.an__dst
57 #define an_gc	an_pointer.an__gc
58 
59 void		 art_init(void);
60 struct art_root	*art_alloc(unsigned int, unsigned int, unsigned int);
61 struct art_node *art_insert(struct art_root *, struct art_node *, uint8_t *,
62 		     int);
63 struct art_node *art_delete(struct art_root *, struct art_node *, uint8_t *,
64 		     int);
65 struct art_node	*art_match(struct art_root *, uint8_t *, struct srp_ref *);
66 struct art_node *art_lookup(struct art_root *, uint8_t *, int,
67 		     struct srp_ref *);
68 int		 art_walk(struct art_root *,
69 		     int (*)(struct art_node *, void *), void *);
70 
71 struct art_node	*art_get(struct sockaddr *, uint8_t);
72 void		 art_put(struct art_node *);
73 
74 #endif /* _NET_ART_H_ */
75