2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2020 Alexander V. Chernikov
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * This header file contains private definitions for nexthop routing.
33 * Header is not intended to be included by the code external to the
37 #ifndef _NET_ROUTE_NHOP_VAR_H_
38 #define _NET_ROUTE_NHOP_VAR_H_
40 /* define nhop hash table */
42 CHT_SLIST_DEFINE(nhops, struct nhop_priv);
43 /* produce hash value for an object */
44 #define nhops_hash_obj(_obj) hash_priv(_obj)
45 /* compare two objects */
46 #define nhops_cmp(_one, _two) cmp_priv(_one, _two)
47 /* next object accessor */
48 #define nhops_next(_obj) (_obj)->nh_next
52 struct nhops_head nh_head; /* hash table head */
53 struct bitmask_head nh_idx_head; /* nhop index head */
54 struct rwlock ctl_lock; /* overall ctl lock */
55 struct rib_head *ctl_rh; /* pointer back to rnh */
56 struct epoch_context ctl_epoch_ctx; /* epoch ctl helper */
59 #define NHOPS_WLOCK(ctl) rw_wlock(&(ctl)->ctl_lock)
60 #define NHOPS_RLOCK(ctl) rw_rlock(&(ctl)->ctl_lock)
61 #define NHOPS_WUNLOCK(ctl) rw_wunlock(&(ctl)->ctl_lock)
62 #define NHOPS_RUNLOCK(ctl) rw_runlock(&(ctl)->ctl_lock)
63 #define NHOPS_LOCK_INIT(ctl) rw_init(&(ctl)->ctl_lock, "nhop_ctl")
64 #define NHOPS_LOCK_DESTROY(ctl) rw_destroy(&(ctl)->ctl_lock)
65 #define NHOPS_WLOCK_ASSERT(ctl) rw_assert(&(ctl)->ctl_lock, RA_WLOCKED)
68 /* Control plane-only nhop data */
71 uint32_t nh_idx; /* nexthop index */
72 uint8_t nh_family; /* address family of the lookup */
73 uint16_t nh_type; /* nexthop type */
74 void *cb_func; /* function handling additional rewrite caps */
75 u_int nh_refcnt; /* number of references, refcount(9) */
76 u_int nh_linked; /* refcount(9), == 2 if linked to the list */
77 int rt_flags; /* routing flags for the control plane */
78 struct nhop_object *nh; /* backreference to the dataplane nhop */
79 struct nh_control *nh_control; /* backreference to the rnh */
80 struct nhop_priv *nh_next; /* hash table membership */
81 struct vnet *nh_vnet; /* vnet nhop belongs to */
82 struct epoch_context nh_epoch_ctx; /* epoch data for nhop */
85 #define NH_IS_PINNED(_nh) ((_nh)->nh_priv->rt_flags & RTF_PINNED)
88 struct nhop_priv *find_nhop(struct nh_control *ctl,
89 const struct nhop_priv *nh_priv);
90 int link_nhop(struct nh_control *ctl, struct nhop_priv *nh_priv);
91 struct nhop_priv *unlink_nhop(struct nh_control *ctl, struct nhop_priv *nh_priv);
94 int cmp_priv(const struct nhop_priv *_one, const struct nhop_priv *_two);