xref: /openbsd/sys/net/rtable.h (revision 0f9e9ec2)
1 /*	$OpenBSD: rtable.h,v 1.30 2024/05/13 01:15:53 jsg Exp $ */
2 
3 /*
4  * Copyright (c) 2014-2016 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_RTABLE_H_
20 #define	_NET_RTABLE_H_
21 
22 /*
23  * Newer routing table implementation based on ART (Allotment Routing
24  * Table).
25  */
26 
27 #define	rt_key(rt)	((rt)->rt_dest)
28 #define	rt_plen(rt)	((rt)->rt_plen)
29 #define	RT_ROOT(rt)	(0)
30 
31 int		 rtable_satoplen(sa_family_t, const struct sockaddr *);
32 
33 void		 rtable_init(void);
34 int		 rtable_exists(unsigned int);
35 int		 rtable_empty(unsigned int);
36 int		 rtable_add(unsigned int);
37 unsigned int	 rtable_l2(unsigned int);
38 unsigned int	 rtable_loindex(unsigned int);
39 void		 rtable_l2set(unsigned int, unsigned int, unsigned int);
40 
41 int		 rtable_setsource(unsigned int, int, struct sockaddr *);
42 struct sockaddr *rtable_getsource(unsigned int, int);
43 void		 rtable_clearsource(unsigned int, struct sockaddr *);
44 struct rtentry	*rtable_lookup(unsigned int, const struct sockaddr *,
45 		     const struct sockaddr *, const struct sockaddr *, uint8_t);
46 struct rtentry	*rtable_match(unsigned int, const struct sockaddr *,
47 		     uint32_t *);
48 struct rtentry	*rtable_iterate(struct rtentry *);
49 int		 rtable_insert(unsigned int, struct sockaddr *,
50 		     const struct sockaddr *, const struct sockaddr *, uint8_t,
51 		     struct rtentry *);
52 int		 rtable_delete(unsigned int, const struct sockaddr *,
53 		     const struct sockaddr *, struct rtentry *);
54 int		 rtable_walk(unsigned int, sa_family_t, struct rtentry **,
55 		     int (*)(struct rtentry *, void *, unsigned int), void *);
56 
57 int		 rtable_mpath_capable(unsigned int, sa_family_t);
58 int		 rtable_mpath_reprio(unsigned int, struct sockaddr *, int,
59 		     uint8_t, struct rtentry *);
60 
61 #endif /* _NET_RTABLE_H_ */
62