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 5104f75b98SAlexander V. Chernikov #define RTNL_F_NOEPOCH 0x01 /* Do not enter epoch when handling command */ 5204f75b98SAlexander 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; 74089104e0SAlexander V. Chernikov uint32_t ifla_link; 757e5bf684SAlexander V. Chernikov uint32_t ifla_mtu; 7680f03e63SAlexander V. Chernikov uint32_t ifi_flags; 7780f03e63SAlexander V. Chernikov uint32_t ifi_change; 787e5bf684SAlexander V. Chernikov }; 797e5bf684SAlexander V. Chernikov 80*9e79038cSAlexander V. Chernikov #if defined(NETLINK) || defined(NETLINK_MODULE) 81*9e79038cSAlexander V. Chernikov /* Provide optimized calls to the functions inside the same linking unit */ 82*9e79038cSAlexander V. Chernikov 83*9e79038cSAlexander V. Chernikov int _nl_modify_ifp_generic(struct ifnet *ifp, struct nl_parsed_link *lattrs, 84*9e79038cSAlexander V. Chernikov const struct nlattr_bmask *bm, struct nl_pstate *npt); 85*9e79038cSAlexander V. Chernikov void _nl_store_ifp_cookie(struct nl_pstate *npt, struct ifnet *ifp); 86*9e79038cSAlexander V. Chernikov 87*9e79038cSAlexander V. Chernikov static inline int 88*9e79038cSAlexander V. Chernikov nl_modify_ifp_generic(struct ifnet *ifp, struct nl_parsed_link *lattrs, 89*9e79038cSAlexander V. Chernikov const struct nlattr_bmask *bm, struct nl_pstate *npt) 90*9e79038cSAlexander V. Chernikov { 91*9e79038cSAlexander V. Chernikov return (_nl_modify_ifp_generic(ifp, lattrs, bm, npt)); 92*9e79038cSAlexander V. Chernikov } 93*9e79038cSAlexander V. Chernikov 94*9e79038cSAlexander V. Chernikov static inline void 95*9e79038cSAlexander V. Chernikov nl_store_ifp_cookie(struct nl_pstate *npt, struct ifnet *ifp) 96*9e79038cSAlexander V. Chernikov { 97*9e79038cSAlexander V. Chernikov _nl_store_ifp_cookie(npt, ifp); 98*9e79038cSAlexander V. Chernikov } 99*9e79038cSAlexander V. Chernikov #else 100*9e79038cSAlexander V. Chernikov /* Provide access to the functions via netlink_glue.c */ 101089104e0SAlexander V. Chernikov int nl_modify_ifp_generic(struct ifnet *ifp, struct nl_parsed_link *lattrs, 102089104e0SAlexander V. Chernikov const struct nlattr_bmask *bm, struct nl_pstate *npt); 103089104e0SAlexander V. Chernikov void nl_store_ifp_cookie(struct nl_pstate *npt, struct ifnet *ifp); 104*9e79038cSAlexander V. Chernikov #endif /* defined(NETLINK) || defined(NETLINK_MODULE) */ 105089104e0SAlexander V. Chernikov 106089104e0SAlexander V. Chernikov 10780f03e63SAlexander V. Chernikov typedef int rtnl_iface_create_f(struct nl_parsed_link *lattrs, 10880f03e63SAlexander V. Chernikov const struct nlattr_bmask *bm, struct nlpcb *nlp, struct nl_pstate *npt); 10980f03e63SAlexander V. Chernikov typedef int rtnl_iface_modify_f(struct ifnet *ifp, struct nl_parsed_link *lattrs, 11080f03e63SAlexander V. Chernikov const struct nlattr_bmask *bm, struct nlpcb *nlp, struct nl_pstate *npt); 11180f03e63SAlexander V. Chernikov typedef int rtnl_iface_dump_f(struct ifnet *ifp, struct nl_writer *nw); 1127e5bf684SAlexander V. Chernikov 1137e5bf684SAlexander V. Chernikov struct nl_cloner { 1147e5bf684SAlexander V. Chernikov const char *name; 1157e5bf684SAlexander V. Chernikov rtnl_iface_create_f *create_f; 1167e5bf684SAlexander V. Chernikov rtnl_iface_modify_f *modify_f; 11780f03e63SAlexander V. Chernikov rtnl_iface_dump_f *dump_f; 1187e5bf684SAlexander V. Chernikov SLIST_ENTRY(nl_cloner) next; 1197e5bf684SAlexander V. Chernikov }; 1207e5bf684SAlexander V. Chernikov 12180f03e63SAlexander V. Chernikov extern struct nl_cloner generic_cloner; 12280f03e63SAlexander V. Chernikov 1237e5bf684SAlexander V. Chernikov void rtnl_ifaces_init(void); 1247e5bf684SAlexander V. Chernikov void rtnl_ifaces_destroy(void); 1257e5bf684SAlexander V. Chernikov void rtnl_iface_add_cloner(struct nl_cloner *cloner); 1267e5bf684SAlexander V. Chernikov void rtnl_iface_del_cloner(struct nl_cloner *cloner); 1271bcd230fSAlexander V. Chernikov void rtnl_handle_ifnet_event(struct ifnet *ifp, int if_change_mask); 1287e5bf684SAlexander V. Chernikov 1297e5bf684SAlexander V. Chernikov /* iface_drivers.c */ 1307e5bf684SAlexander V. Chernikov void rtnl_iface_drivers_register(void); 1317e5bf684SAlexander V. Chernikov 1327e5bf684SAlexander V. Chernikov /* nexthop.c */ 1337e5bf684SAlexander V. Chernikov void rtnl_nexthops_init(void); 1347e5bf684SAlexander V. Chernikov struct nhop_object *nl_find_nhop(uint32_t fibnum, int family, 1357e5bf684SAlexander V. Chernikov uint32_t uidx, int nh_flags, int *perror); 136c7c34816SAlexander V. Chernikov int nl_set_nexthop_gw(struct nhop_object *nh, struct sockaddr *gw, 137c7c34816SAlexander V. Chernikov struct ifnet *ifp, struct nl_pstate *npt); 1387e5bf684SAlexander V. Chernikov 1397e5bf684SAlexander V. Chernikov 1407e5bf684SAlexander V. Chernikov #endif 141