1 /* $OpenBSD: rtable.h,v 1.16 2016/09/07 09:36:49 mpi Exp $ */ 2 3 /* 4 * Copyright (c) 2014-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_RTABLE_H_ 20 #define _NET_RTABLE_H_ 21 22 #ifndef ART 23 24 /* 25 * Traditional BSD routing table implementation based on a radix tree. 26 */ 27 #include <net/radix.h> 28 #ifndef SMALL_KERNEL 29 #include <net/radix_mpath.h> 30 #endif 31 32 #define rt_key(rt) (((struct sockaddr *)(rt)->rt_nodes[0].rn_key)) 33 #define rt_mask(rt) (((struct sockaddr *)(rt)->rt_nodes[0].rn_mask)) 34 #define rt_plen(rt) (rtable_satoplen(rt_key(rt)->sa_family, rt_mask(rt))) 35 #define RT_ROOT(rt) ((rt)->rt_nodes[0].rn_flags & RNF_ROOT) 36 37 #else /* ART */ 38 39 /* 40 * Newer routing table implementation based on ART (Allotment Routing 41 * Table). 42 */ 43 #include <net/art.h> 44 45 #define rt_key(rt) ((rt)->rt_dest) 46 #define rt_plen(rt) ((rt)->rt_plen) 47 #define RT_ROOT(rt) (0) 48 49 #endif /* ART */ 50 51 int rtable_satoplen(sa_family_t, struct sockaddr *); 52 53 void rtable_init(void); 54 int rtable_exists(unsigned int); 55 int rtable_add(unsigned int); 56 unsigned int rtable_l2(unsigned int); 57 void rtable_l2set(unsigned int, unsigned int); 58 59 struct rtentry *rtable_lookup(unsigned int, struct sockaddr *, 60 struct sockaddr *, struct sockaddr *, uint8_t); 61 struct rtentry *rtable_match(unsigned int, struct sockaddr *, uint32_t *); 62 struct rtentry *rtable_iterate(struct rtentry *); 63 int rtable_insert(unsigned int, struct sockaddr *, 64 struct sockaddr *, struct sockaddr *, uint8_t, 65 struct rtentry *); 66 int rtable_delete(unsigned int, struct sockaddr *, 67 struct sockaddr *, struct rtentry *); 68 int rtable_walk(unsigned int, sa_family_t, 69 int (*)(struct rtentry *, void *, unsigned int), void *); 70 71 int rtable_mpath_capable(unsigned int, sa_family_t); 72 struct rtentry *rtable_mpath_match(unsigned int, struct rtentry *, 73 struct sockaddr *, uint8_t); 74 int rtable_mpath_reprio(unsigned int, struct sockaddr *, 75 struct sockaddr *, uint8_t, struct rtentry *); 76 #endif /* _NET_RTABLE_H_ */ 77