xref: /freebsd/sys/net/route/route_ctl.h (revision 5ffd83dbcc34f10e07f6d3e968ae6365869615f4)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2020 Alexander V. Chernikov
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
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.
14  *
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
25  * SUCH DAMAGE.
26  *
27  * $FreeBSD$
28  */
29 
30 /*
31  * This header file contains public functions and structures used for
32  * routing table manipulations.
33  */
34 
35 #ifndef	_NET_ROUTE_ROUTE_CTL_H_
36 #define	_NET_ROUTE_ROUTE_CTL_H_
37 
38 struct rib_cmd_info {
39 	uint8_t			rc_cmd;		/* RTM_ADD|RTM_DEL|RTM_CHANGE */
40 	uint8_t			spare[3];
41 	uint32_t		rc_nh_weight;	/* new nhop weight */
42 	struct rtentry		*rc_rt;		/* Target entry */
43 	struct nhop_object	*rc_nh_old;	/* Target nhop OR mpath */
44 	struct nhop_object	*rc_nh_new;	/* Target nhop OR mpath */
45 };
46 
47 
48 int rib_add_route(uint32_t fibnum, struct rt_addrinfo *info,
49   struct rib_cmd_info *rc);
50 int rib_del_route(uint32_t fibnum, struct rt_addrinfo *info,
51   struct rib_cmd_info *rc);
52 int rib_change_route(uint32_t fibnum, struct rt_addrinfo *info,
53   struct rib_cmd_info *rc);
54 int rib_action(uint32_t fibnum, int action, struct rt_addrinfo *info,
55   struct rib_cmd_info *rc);
56 
57 int rib_add_redirect(u_int fibnum, struct sockaddr *dst,
58   struct sockaddr *gateway, struct sockaddr *author, struct ifnet *ifp,
59   int flags, int expire_sec);
60 
61 typedef int rt_walktree_f_t(struct rtentry *, void *);
62 void rib_walk(int af, u_int fibnum, rt_walktree_f_t *wa_f, void *arg);
63 void rib_walk_del(u_int fibnum, int family, rt_filter_f_t *filter_f,
64   void *arg, bool report);
65 
66 typedef void rt_setwarg_t(struct rib_head *, uint32_t, int, void *);
67 void rt_foreach_fib_walk(int af, rt_setwarg_t *, rt_walktree_f_t *, void *);
68 void rt_foreach_fib_walk_del(int af, rt_filter_f_t *filter_f, void *arg);
69 
70 enum rib_subscription_type {
71 	RIB_NOTIFY_IMMEDIATE,
72 	RIB_NOTIFY_DELAYED
73 };
74 
75 struct rib_subscription;
76 typedef void rib_subscription_cb_t(struct rib_head *rnh, struct rib_cmd_info *rc,
77     void *arg);
78 
79 struct rib_subscription *rib_subscribe(uint32_t fibnum, int family,
80     rib_subscription_cb_t *f, void *arg, enum rib_subscription_type type,
81     int waitok);
82 int rib_unsibscribe(uint32_t fibnum, int family, struct rib_subscription *rs);
83 
84 #endif
85 
86