xref: /freebsd/sys/netlink/route/route_var.h (revision 04f75b980293d517558990a7fda6900445edcac6)
17e5bf684SAlexander V. Chernikov /*-
27e5bf684SAlexander V. Chernikov  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
37e5bf684SAlexander V. Chernikov  *
47e5bf684SAlexander V. Chernikov  * Copyright (c) 2022 Alexander V. Chernikov <melifaro@FreeBSD.org>
57e5bf684SAlexander V. Chernikov  *
67e5bf684SAlexander V. Chernikov  * Redistribution and use in source and binary forms, with or without
77e5bf684SAlexander V. Chernikov  * modification, are permitted provided that the following conditions
87e5bf684SAlexander V. Chernikov  * are met:
97e5bf684SAlexander V. Chernikov  * 1. Redistributions of source code must retain the above copyright
107e5bf684SAlexander V. Chernikov  *    notice, this list of conditions and the following disclaimer.
117e5bf684SAlexander V. Chernikov  * 2. Redistributions in binary form must reproduce the above copyright
127e5bf684SAlexander V. Chernikov  *    notice, this list of conditions and the following disclaimer in the
137e5bf684SAlexander V. Chernikov  *    documentation and/or other materials provided with the distribution.
147e5bf684SAlexander V. Chernikov  *
157e5bf684SAlexander V. Chernikov  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
167e5bf684SAlexander V. Chernikov  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
177e5bf684SAlexander V. Chernikov  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
187e5bf684SAlexander V. Chernikov  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
197e5bf684SAlexander V. Chernikov  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
207e5bf684SAlexander V. Chernikov  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
217e5bf684SAlexander V. Chernikov  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
227e5bf684SAlexander V. Chernikov  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
237e5bf684SAlexander V. Chernikov  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
247e5bf684SAlexander V. Chernikov  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
257e5bf684SAlexander V. Chernikov  * SUCH DAMAGE.
267e5bf684SAlexander V. Chernikov  */
277e5bf684SAlexander V. Chernikov 
287e5bf684SAlexander V. Chernikov /*
297e5bf684SAlexander V. Chernikov  * This file contains definitions shared among NETLINK_ROUTE family
307e5bf684SAlexander V. Chernikov  */
317e5bf684SAlexander V. Chernikov #ifndef _NETLINK_ROUTE_ROUTE_VAR_H_
327e5bf684SAlexander V. Chernikov #define _NETLINK_ROUTE_ROUTE_VAR_H_
337e5bf684SAlexander V. Chernikov 
347e5bf684SAlexander V. Chernikov #include <sys/priv.h> /* values for priv_check */
357e5bf684SAlexander V. Chernikov 
367e5bf684SAlexander V. Chernikov struct nlmsghdr;
377e5bf684SAlexander V. Chernikov struct nlpcb;
387e5bf684SAlexander V. Chernikov struct nl_pstate;
397e5bf684SAlexander V. Chernikov 
407e5bf684SAlexander V. Chernikov typedef int rtnl_msg_cb_f(struct nlmsghdr *hdr, struct nlpcb *nlp,
417e5bf684SAlexander V. Chernikov     struct nl_pstate *npt);
427e5bf684SAlexander V. Chernikov 
437e5bf684SAlexander V. Chernikov struct rtnl_cmd_handler {
447e5bf684SAlexander V. Chernikov 	int		cmd;
457e5bf684SAlexander V. Chernikov 	const char	*name;
467e5bf684SAlexander V. Chernikov 	rtnl_msg_cb_f	*cb;
477e5bf684SAlexander V. Chernikov 	int		priv;
487e5bf684SAlexander V. Chernikov 	int		flags;
497e5bf684SAlexander V. Chernikov };
507e5bf684SAlexander V. Chernikov 
51*04f75b98SAlexander V. Chernikov #define	RTNL_F_NOEPOCH			0x01	/* Do not enter epoch when handling command */
52*04f75b98SAlexander V. Chernikov #define	RTNL_F_ALLOW_NONVNET_JAIL	0x02	/* Allow command execution inside non-VNET jail */
537e5bf684SAlexander V. Chernikov 
547e5bf684SAlexander V. Chernikov bool rtnl_register_messages(const struct rtnl_cmd_handler *handlers, int count);
557e5bf684SAlexander V. Chernikov 
567e5bf684SAlexander V. Chernikov /* route.c */
577e5bf684SAlexander V. Chernikov struct rib_cmd_info;
587e5bf684SAlexander V. Chernikov void rtnl_handle_route_event(uint32_t fibnum, const struct rib_cmd_info *rc);
597e5bf684SAlexander V. Chernikov void rtnl_routes_init(void);
607e5bf684SAlexander V. Chernikov 
617e5bf684SAlexander V. Chernikov /* neigh.c */
627e5bf684SAlexander V. Chernikov void rtnl_neighs_init(void);
637e5bf684SAlexander V. Chernikov void rtnl_neighs_destroy(void);
647e5bf684SAlexander V. Chernikov 
657e5bf684SAlexander V. Chernikov /* iface.c */
667e5bf684SAlexander V. Chernikov struct nl_parsed_link {
677e5bf684SAlexander V. Chernikov 	char		*ifla_group;
687e5bf684SAlexander V. Chernikov 	char		*ifla_ifname;
697e5bf684SAlexander V. Chernikov 	char		*ifla_cloner;
7080f03e63SAlexander V. Chernikov 	char		*ifla_ifalias;
717e5bf684SAlexander V. Chernikov 	struct nlattr	*ifla_idata;
727e5bf684SAlexander V. Chernikov 	unsigned short	ifi_type;
737e5bf684SAlexander V. Chernikov 	int		ifi_index;
747e5bf684SAlexander V. Chernikov 	uint32_t	ifla_mtu;
7580f03e63SAlexander V. Chernikov 	uint32_t	ifi_flags;
7680f03e63SAlexander V. Chernikov 	uint32_t	ifi_change;
777e5bf684SAlexander V. Chernikov };
787e5bf684SAlexander V. Chernikov 
7980f03e63SAlexander V. Chernikov typedef int rtnl_iface_create_f(struct nl_parsed_link *lattrs,
8080f03e63SAlexander V. Chernikov     const struct nlattr_bmask *bm, struct nlpcb *nlp, struct nl_pstate *npt);
8180f03e63SAlexander V. Chernikov typedef int rtnl_iface_modify_f(struct ifnet *ifp, struct nl_parsed_link *lattrs,
8280f03e63SAlexander V. Chernikov     const struct nlattr_bmask *bm, struct nlpcb *nlp, struct nl_pstate *npt);
8380f03e63SAlexander V. Chernikov typedef int rtnl_iface_dump_f(struct ifnet *ifp, struct nl_writer *nw);
847e5bf684SAlexander V. Chernikov 
857e5bf684SAlexander V. Chernikov struct nl_cloner {
867e5bf684SAlexander V. Chernikov 	const char		*name;
877e5bf684SAlexander V. Chernikov 	rtnl_iface_create_f	*create_f;
887e5bf684SAlexander V. Chernikov 	rtnl_iface_modify_f	*modify_f;
8980f03e63SAlexander V. Chernikov 	rtnl_iface_dump_f	*dump_f;
907e5bf684SAlexander V. Chernikov 	SLIST_ENTRY(nl_cloner)	next;
917e5bf684SAlexander V. Chernikov };
927e5bf684SAlexander V. Chernikov 
9380f03e63SAlexander V. Chernikov extern struct nl_cloner	generic_cloner;
9480f03e63SAlexander V. Chernikov 
957e5bf684SAlexander V. Chernikov void rtnl_ifaces_init(void);
967e5bf684SAlexander V. Chernikov void rtnl_ifaces_destroy(void);
977e5bf684SAlexander V. Chernikov void rtnl_iface_add_cloner(struct nl_cloner *cloner);
987e5bf684SAlexander V. Chernikov void rtnl_iface_del_cloner(struct nl_cloner *cloner);
991bcd230fSAlexander V. Chernikov void rtnl_handle_ifnet_event(struct ifnet *ifp, int if_change_mask);
1007e5bf684SAlexander V. Chernikov 
1017e5bf684SAlexander V. Chernikov /* iface_drivers.c */
1027e5bf684SAlexander V. Chernikov void rtnl_iface_drivers_register(void);
1037e5bf684SAlexander V. Chernikov 
1047e5bf684SAlexander V. Chernikov /* nexthop.c */
1057e5bf684SAlexander V. Chernikov void rtnl_nexthops_init(void);
1067e5bf684SAlexander V. Chernikov struct nhop_object *nl_find_nhop(uint32_t fibnum, int family,
1077e5bf684SAlexander V. Chernikov     uint32_t uidx, int nh_flags, int *perror);
108c7c34816SAlexander V. Chernikov int nl_set_nexthop_gw(struct nhop_object *nh, struct sockaddr *gw,
109c7c34816SAlexander V. Chernikov     struct ifnet *ifp, struct nl_pstate *npt);
1107e5bf684SAlexander V. Chernikov 
1117e5bf684SAlexander V. Chernikov 
1127e5bf684SAlexander V. Chernikov #endif
113