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 MALLOC_DECLARE(M_NHOP);
42 /* define nhop hash table */
44 CHT_SLIST_DEFINE(nhops, struct nhop_priv);
45 /* produce hash value for an object */
46 #define nhops_hash_obj(_obj) hash_priv(_obj)
47 /* compare two objects */
48 #define nhops_cmp(_one, _two) cmp_priv(_one, _two)
49 /* next object accessor */
50 #define nhops_next(_obj) (_obj)->nh_next
52 /* define multipath hash table */
54 CHT_SLIST_DEFINE(nhgroups, struct nhgrp_priv);
57 struct nhops_head nh_head; /* hash table head */
58 struct bitmask_head nh_idx_head; /* nhop index head */
59 struct nhgroups_head gr_head; /* nhgrp hash table head */
60 struct rwlock ctl_lock; /* overall ctl lock */
61 struct rib_head *ctl_rh; /* pointer back to rnh */
62 struct epoch_context ctl_epoch_ctx; /* epoch ctl helper */
65 #define NHOPS_WLOCK(ctl) rw_wlock(&(ctl)->ctl_lock)
66 #define NHOPS_RLOCK(ctl) rw_rlock(&(ctl)->ctl_lock)
67 #define NHOPS_WUNLOCK(ctl) rw_wunlock(&(ctl)->ctl_lock)
68 #define NHOPS_RUNLOCK(ctl) rw_runlock(&(ctl)->ctl_lock)
69 #define NHOPS_LOCK_INIT(ctl) rw_init(&(ctl)->ctl_lock, "nhop_ctl")
70 #define NHOPS_LOCK_DESTROY(ctl) rw_destroy(&(ctl)->ctl_lock)
71 #define NHOPS_WLOCK_ASSERT(ctl) rw_assert(&(ctl)->ctl_lock, RA_WLOCKED)
73 /* Control plane-only nhop data */
76 /* nhop lookup comparison start */
77 uint8_t nh_upper_family;/* address family of the lookup */
78 uint8_t nh_neigh_family;/* neighbor address family */
79 uint16_t nh_type; /* nexthop type */
80 uint32_t rt_flags; /* routing flags for the control plane */
81 /* nhop lookup comparison end */
82 uint32_t nh_idx; /* nexthop index */
83 uint32_t nh_fibnum; /* nexthop fib */
84 void *cb_func; /* function handling additional rewrite caps */
85 u_int nh_refcnt; /* number of references, refcount(9) */
86 u_int nh_linked; /* refcount(9), == 2 if linked to the list */
87 struct nhop_object *nh; /* backreference to the dataplane nhop */
88 struct nh_control *nh_control; /* backreference to the rnh */
89 struct nhop_priv *nh_next; /* hash table membership */
90 struct vnet *nh_vnet; /* vnet nhop belongs to */
91 struct epoch_context nh_epoch_ctx; /* epoch data for nhop */
94 #define NH_PRIV_END_CMP (__offsetof(struct nhop_priv, nh_idx))
96 #define NH_IS_PINNED(_nh) ((!NH_IS_NHGRP(_nh)) && \
97 ((_nh)->nh_priv->rt_flags & RTF_PINNED))
100 struct nhop_priv *find_nhop(struct nh_control *ctl,
101 const struct nhop_priv *nh_priv);
102 int link_nhop(struct nh_control *ctl, struct nhop_priv *nh_priv);
103 struct nhop_priv *unlink_nhop(struct nh_control *ctl, struct nhop_priv *nh_priv);
106 int cmp_priv(const struct nhop_priv *_one, const struct nhop_priv *_two);