master
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 2022 Alexander V. Chernikov <melifaro@FreeBSD.org>
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
28/*
29 * This file contains definitions shared among NETLINK_ROUTE family
30 */
31#ifndef _NETLINK_ROUTE_ROUTE_VAR_H_
32#define _NETLINK_ROUTE_ROUTE_VAR_H_
33
34#include <sys/priv.h> /* values for priv_check */
35
36struct nlmsghdr;
37struct nlpcb;
38struct nl_pstate;
39
40typedef int rtnl_msg_cb_f(struct nlmsghdr *hdr, struct nlpcb *nlp,
41 struct nl_pstate *npt);
42
43struct rtnl_cmd_handler {
44 int cmd;
45 const char *name;
46 rtnl_msg_cb_f *cb;
47 int priv;
48 int flags;
49};
50
51#define RTNL_F_NOEPOCH 0x01 /* Do not enter epoch when handling command */
52#define RTNL_F_ALLOW_NONVNET_JAIL 0x02 /* Allow command execution inside non-VNET jail */
53
54bool rtnl_register_messages(const struct rtnl_cmd_handler *handlers, int count);
55
56/* route.c */
57struct rib_cmd_info;
58void rtnl_handle_route_event(uint32_t fibnum, const struct rib_cmd_info *rc);
59void rtnl_routes_init(void);
60
61/* neigh.c */
62void rtnl_neighs_init(void);
63void rtnl_neighs_destroy(void);
64
65/* iface.c */
66struct nl_parsed_link {
67 char *ifla_group;
68 char *ifla_ifname;
69 char *ifla_cloner;
70 char *ifla_ifalias;
71 struct nlattr *ifla_idata;
72 unsigned short ifi_type;
73 int ifi_index;
74 uint32_t ifla_link;
75 uint32_t ifla_mtu;
76 uint32_t ifi_flags;
77 uint32_t ifi_change;
78};
79
80#if defined(NETLINK) || defined(NETLINK_MODULE)
81/* Provide optimized calls to the functions inside the same linking unit */
82
83int _nl_modify_ifp_generic(struct ifnet *ifp, struct nl_parsed_link *lattrs,
84 const struct nlattr_bmask *bm, struct nl_pstate *npt);
85void _nl_store_ifp_cookie(struct nl_pstate *npt, struct ifnet *ifp);
86
87static inline int
88nl_modify_ifp_generic(struct ifnet *ifp, struct nl_parsed_link *lattrs,
89 const struct nlattr_bmask *bm, struct nl_pstate *npt)
90{
91 return (_nl_modify_ifp_generic(ifp, lattrs, bm, npt));
92}
93
94static inline void
95nl_store_ifp_cookie(struct nl_pstate *npt, struct ifnet *ifp)
96{
97 _nl_store_ifp_cookie(npt, ifp);
98}
99#else
100/* Provide access to the functions via netlink_glue.c */
101int nl_modify_ifp_generic(struct ifnet *ifp, struct nl_parsed_link *lattrs,
102 const struct nlattr_bmask *bm, struct nl_pstate *npt);
103void nl_store_ifp_cookie(struct nl_pstate *npt, struct ifnet *ifp);
104#endif /* defined(NETLINK) || defined(NETLINK_MODULE) */
105
106
107typedef int rtnl_iface_create_f(struct nl_parsed_link *lattrs,
108 const struct nlattr_bmask *bm, struct nlpcb *nlp, struct nl_pstate *npt);
109typedef int rtnl_iface_modify_f(struct ifnet *ifp, struct nl_parsed_link *lattrs,
110 const struct nlattr_bmask *bm, struct nlpcb *nlp, struct nl_pstate *npt);
111typedef int rtnl_iface_dump_f(struct ifnet *ifp, struct nl_writer *nw);
112
113struct nl_cloner {
114 const char *name;
115 rtnl_iface_create_f *create_f;
116 rtnl_iface_modify_f *modify_f;
117 rtnl_iface_dump_f *dump_f;
118 SLIST_ENTRY(nl_cloner) next;
119};
120
121extern struct nl_cloner generic_cloner;
122
123void rtnl_ifaces_init(void);
124void rtnl_ifaces_destroy(void);
125void rtnl_iface_add_cloner(struct nl_cloner *cloner);
126void rtnl_iface_del_cloner(struct nl_cloner *cloner);
127void rtnl_handle_ifnet_event(struct ifnet *ifp, int if_change_mask);
128
129/* iface_drivers.c */
130void rtnl_iface_drivers_register(void);
131
132/* nexthop.c */
133void rtnl_nexthops_init(void);
134struct nhop_object *nl_find_nhop(uint32_t fibnum, int family,
135 uint32_t uidx, int nh_flags, int *perror);
136int nl_set_nexthop_gw(struct nhop_object *nh, struct sockaddr *gw,
137 struct ifnet *ifp, struct nl_pstate *npt);
138
139
140#endif