1294706Smelifaro/*- 2294706Smelifaro * Copyright (c) 2015-2016 3294706Smelifaro * Alexander V. Chernikov <melifaro@FreeBSD.org> 4294706Smelifaro * 5294706Smelifaro * Redistribution and use in source and binary forms, with or without 6294706Smelifaro * modification, are permitted provided that the following conditions 7294706Smelifaro * are met: 8294706Smelifaro * 1. Redistributions of source code must retain the above copyright 9294706Smelifaro * notice, this list of conditions and the following disclaimer. 10294706Smelifaro * 2. Redistributions in binary form must reproduce the above copyright 11294706Smelifaro * notice, this list of conditions and the following disclaimer in the 12294706Smelifaro * documentation and/or other materials provided with the distribution. 13294706Smelifaro * 4. Neither the name of the University nor the names of its contributors 14294706Smelifaro * may be used to endorse or promote products derived from this software 15294706Smelifaro * without specific prior written permission. 16294706Smelifaro * 17294706Smelifaro * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18294706Smelifaro * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19294706Smelifaro * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20294706Smelifaro * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21294706Smelifaro * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22294706Smelifaro * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23294706Smelifaro * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24294706Smelifaro * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25294706Smelifaro * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26294706Smelifaro * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27294706Smelifaro * SUCH DAMAGE. 28294706Smelifaro * 29294706Smelifaro * $FreeBSD: releng/11.0/sys/net/route_var.h 297225 2016-03-24 07:54:56Z gnn $ 30294706Smelifaro */ 31294706Smelifaro 32294706Smelifaro#ifndef _NET_ROUTE_VAR_H_ 33294706Smelifaro#define _NET_ROUTE_VAR_H_ 34294706Smelifaro 35294706Smelifarostruct rib_head { 36294706Smelifaro struct radix_head head; 37294706Smelifaro rn_matchaddr_f_t *rnh_matchaddr; /* longest match for sockaddr */ 38294706Smelifaro rn_addaddr_f_t *rnh_addaddr; /* add based on sockaddr*/ 39294706Smelifaro rn_deladdr_f_t *rnh_deladdr; /* remove based on sockaddr */ 40294706Smelifaro rn_lookup_f_t *rnh_lookup; /* exact match for sockaddr */ 41294706Smelifaro rn_walktree_t *rnh_walktree; /* traverse tree */ 42294706Smelifaro rn_walktree_from_t *rnh_walktree_from; /* traverse tree below a */ 43294706Smelifaro rn_close_t *rnh_close; /*do something when the last ref drops*/ 44297225Sgnn rt_gen_t rnh_gen; /* generation counter */ 45294706Smelifaro int rnh_multipath; /* multipath capable ? */ 46294706Smelifaro struct radix_node rnh_nodes[3]; /* empty tree for common case */ 47294706Smelifaro struct rwlock rib_lock; /* config/data path lock */ 48294706Smelifaro struct radix_mask_head rmhead; /* masks radix head */ 49294706Smelifaro}; 50294706Smelifaro 51294706Smelifaro#define RIB_RLOCK(rh) rw_rlock(&(rh)->rib_lock) 52294706Smelifaro#define RIB_RUNLOCK(rh) rw_runlock(&(rh)->rib_lock) 53294706Smelifaro#define RIB_WLOCK(rh) rw_wlock(&(rh)->rib_lock) 54294706Smelifaro#define RIB_WUNLOCK(rh) rw_wunlock(&(rh)->rib_lock) 55294706Smelifaro#define RIB_LOCK_ASSERT(rh) rw_assert(&(rh)->rib_lock, RA_LOCKED) 56294706Smelifaro#define RIB_WLOCK_ASSERT(rh) rw_assert(&(rh)->rib_lock, RA_WLOCKED) 57294706Smelifaro 58294706Smelifarostruct rib_head *rt_tables_get_rnh(int fib, int family); 59294706Smelifaro 60294706Smelifaro/* rte<>nhop translation */ 61294706Smelifarostatic inline uint16_t 62294706Smelifarofib_rte_to_nh_flags(int rt_flags) 63294706Smelifaro{ 64294706Smelifaro uint16_t res; 65294706Smelifaro 66294706Smelifaro res = (rt_flags & RTF_REJECT) ? NHF_REJECT : 0; 67294706Smelifaro res |= (rt_flags & RTF_BLACKHOLE) ? NHF_BLACKHOLE : 0; 68294706Smelifaro res |= (rt_flags & (RTF_DYNAMIC|RTF_MODIFIED)) ? NHF_REDIRECT : 0; 69294706Smelifaro res |= (rt_flags & RTF_BROADCAST) ? NHF_BROADCAST : 0; 70294706Smelifaro res |= (rt_flags & RTF_GATEWAY) ? NHF_GATEWAY : 0; 71294706Smelifaro 72294706Smelifaro return (res); 73294706Smelifaro} 74294706Smelifaro 75294706Smelifaro 76294706Smelifaro#endif 77