1/*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Copyright (c) 1980, 1986, 1991, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. Neither the name of the University nor the names of its contributors 16 * may be used to endorse or promote products derived from this software 17 * without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31/************************************************************************ 32 * Note: In this file a 'fib' is a "forwarding information base" * 33 * Which is the new name for an in kernel routing (next hop) table. * 34 ***********************************************************************/ 35 36#include "opt_inet.h" 37#include "opt_inet6.h" 38#include "opt_mrouting.h" 39#include "opt_route.h" 40 41#include <sys/param.h> 42#include <sys/systm.h> 43#include <sys/malloc.h> 44#include <sys/mbuf.h> 45#include <sys/socket.h> 46#include <sys/sysctl.h> 47#include <sys/syslog.h> 48#include <sys/sysproto.h> 49#include <sys/proc.h> 50#include <sys/devctl.h> 51#include <sys/domain.h> 52#include <sys/eventhandler.h> 53#include <sys/kernel.h> 54#include <sys/lock.h> 55#include <sys/rmlock.h> 56 57#include <net/if.h> 58#include <net/if_var.h> 59#include <net/if_private.h> 60#include <net/if_dl.h> 61#include <net/route.h> 62#include <net/route/route_ctl.h> 63#include <net/route/route_var.h> 64#include <net/route/nhop.h> 65#include <net/vnet.h> 66 67#include <netinet/in.h> 68#include <netinet/ip_mroute.h> 69#include <netinet6/in6_var.h> 70 71VNET_PCPUSTAT_DEFINE(struct rtstat, rtstat); 72 73VNET_PCPUSTAT_SYSINIT(rtstat); 74#ifdef VIMAGE 75VNET_PCPUSTAT_SYSUNINIT(rtstat); 76#endif 77 78EVENTHANDLER_LIST_DEFINE(rt_addrmsg); 79 80static int rt_ifdelroute(const struct rtentry *rt, const struct nhop_object *, 81 void *arg); 82 83/* 84 * route initialization must occur before ip6_init2(), which happenas at 85 * SI_ORDER_MIDDLE. 86 */ 87static void 88route_init(void) 89{ 90 91 nhops_init(); 92} 93SYSINIT(route_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, route_init, NULL); 94 95struct rib_head * 96rt_table_init(int offset, int family, u_int fibnum) 97{ 98 struct rib_head *rh; 99 100 rh = malloc(sizeof(struct rib_head), M_RTABLE, M_WAITOK | M_ZERO); 101 102 /* TODO: These details should be hidded inside radix.c */ 103 /* Init masks tree */ 104 rn_inithead_internal(&rh->head, rh->rnh_nodes, offset); 105 rn_inithead_internal(&rh->rmhead.head, rh->rmhead.mask_nodes, 0); 106 rh->head.rnh_masks = &rh->rmhead; 107 108 /* Save metadata associated with this routing table. */ 109 rh->rib_family = family; 110 rh->rib_fibnum = fibnum; 111#ifdef VIMAGE 112 rh->rib_vnet = curvnet; 113#endif 114 115 tmproutes_init(rh); 116 117 /* Init locks */ 118 RIB_LOCK_INIT(rh); 119 120 nhops_init_rib(rh); 121 122 /* Init subscription system */ 123 rib_init_subscriptions(rh); 124 125 /* Finally, set base callbacks */ 126 rh->rnh_addaddr = rn_addroute; 127 rh->rnh_deladdr = rn_delete; 128 rh->rnh_matchaddr = rn_match; 129 rh->rnh_lookup = rn_lookup; 130 rh->rnh_walktree = rn_walktree; 131 rh->rnh_walktree_from = rn_walktree_from; 132 133 return (rh); 134} 135 136static int 137rt_freeentry(struct radix_node *rn, void *arg) 138{ 139 struct radix_head * const rnh = arg; 140 struct radix_node *x; 141 142 x = (struct radix_node *)rn_delete(rn + 2, NULL, rnh); 143 if (x != NULL) 144 R_Free(x); 145 return (0); 146} 147 148void 149rt_table_destroy(struct rib_head *rh) 150{ 151 152 RIB_WLOCK(rh); 153 rh->rib_dying = true; 154 RIB_WUNLOCK(rh); 155 156#ifdef FIB_ALGO 157 fib_destroy_rib(rh); 158#endif 159 160 tmproutes_destroy(rh); 161 162 rn_walktree(&rh->rmhead.head, rt_freeentry, &rh->rmhead.head); 163 164 nhops_destroy_rib(rh); 165 166 rib_destroy_subscriptions(rh); 167 168 /* Assume table is already empty */ 169 RIB_LOCK_DESTROY(rh); 170 free(rh, M_RTABLE); 171} 172 173/* 174 * Adds a temporal redirect entry to the routing table. 175 * @fibnum: fib number 176 * @dst: destination to install redirect to 177 * @gateway: gateway to go via 178 * @author: sockaddr of originating router, can be NULL 179 * @ifp: interface to use for the redirected route 180 * @flags: set of flags to add. Allowed: RTF_GATEWAY 181 * @lifetime_sec: time in seconds to expire this redirect. 182 * 183 * Retuns 0 on success, errno otherwise. 184 */ 185int 186rib_add_redirect(u_int fibnum, struct sockaddr *dst, struct sockaddr *gateway, 187 struct sockaddr *author, struct ifnet *ifp, int flags, int lifetime_sec) 188{ 189 struct route_nhop_data rnd = { .rnd_weight = RT_DEFAULT_WEIGHT }; 190 struct rib_cmd_info rc; 191 struct ifaddr *ifa; 192 int error; 193 194 NET_EPOCH_ASSERT(); 195 196 if (rt_tables_get_rnh(fibnum, dst->sa_family) == NULL) 197 return (EAFNOSUPPORT); 198 199 /* Verify the allowed flag mask. */ 200 KASSERT(((flags & ~(RTF_GATEWAY)) == 0), 201 ("invalid redirect flags: %x", flags)); 202 flags |= RTF_HOST | RTF_DYNAMIC; 203 204 /* Get the best ifa for the given interface and gateway. */ 205 if ((ifa = ifaof_ifpforaddr(gateway, ifp)) == NULL) 206 return (ENETUNREACH); 207 208 struct nhop_object *nh = nhop_alloc(fibnum, dst->sa_family); 209 if (nh == NULL) 210 return (ENOMEM); 211 212 nhop_set_gw(nh, gateway, flags & RTF_GATEWAY); 213 nhop_set_transmit_ifp(nh, ifp); 214 nhop_set_src(nh, ifa); 215 nhop_set_pxtype_flag(nh, NHF_HOST); 216 nhop_set_expire(nh, lifetime_sec + time_uptime); 217 nhop_set_redirect(nh, true); 218 nhop_set_origin(nh, NH_ORIGIN_REDIRECT); 219 rnd.rnd_nhop = nhop_get_nhop(nh, &error); 220 if (error == 0) { 221 error = rib_add_route_px(fibnum, dst, -1, 222 &rnd, RTM_F_CREATE, &rc); 223 } 224 225 if (error != 0) { 226 /* TODO: add per-fib redirect stats. */ 227 return (error); 228 } 229 230 RTSTAT_INC(rts_dynamic); 231 232 /* Send notification of a route addition to userland. */ 233 struct rt_addrinfo info = { 234 .rti_info[RTAX_DST] = dst, 235 .rti_info[RTAX_GATEWAY] = gateway, 236 .rti_info[RTAX_AUTHOR] = author, 237 }; 238 rt_missmsg_fib(RTM_REDIRECT, &info, flags | RTF_UP, error, fibnum); 239 240 return (0); 241} 242 243/* 244 * Routing table ioctl interface. 245 */ 246int 247rtioctl_fib(u_long req, caddr_t data, u_int fibnum) 248{ 249 250 /* 251 * If more ioctl commands are added here, make sure the proper 252 * super-user checks are being performed because it is possible for 253 * prison-root to make it this far if raw sockets have been enabled 254 * in jails. 255 */ 256#ifdef INET 257 /* Multicast goop, grrr... */ 258 return mrt_ioctl ? mrt_ioctl(req, data, fibnum) : EOPNOTSUPP; 259#else /* INET */ 260 return ENXIO; 261#endif /* INET */ 262} 263 264struct ifaddr * 265ifa_ifwithroute(int flags, const struct sockaddr *dst, 266 const struct sockaddr *gateway, u_int fibnum) 267{ 268 struct ifaddr *ifa; 269 270 NET_EPOCH_ASSERT(); 271 if ((flags & RTF_GATEWAY) == 0) { 272 /* 273 * If we are adding a route to an interface, 274 * and the interface is a pt to pt link 275 * we should search for the destination 276 * as our clue to the interface. Otherwise 277 * we can use the local address. 278 */ 279 ifa = NULL; 280 if (flags & RTF_HOST) 281 ifa = ifa_ifwithdstaddr(dst, fibnum); 282 if (ifa == NULL) 283 ifa = ifa_ifwithaddr(gateway); 284 } else { 285 /* 286 * If we are adding a route to a remote net 287 * or host, the gateway may still be on the 288 * other end of a pt to pt link. 289 */ 290 ifa = ifa_ifwithdstaddr(gateway, fibnum); 291 } 292 if (ifa == NULL) 293 ifa = ifa_ifwithnet(gateway, 0, fibnum); 294 if (ifa == NULL) { 295 struct nhop_object *nh; 296 297 nh = rib_lookup(fibnum, gateway, NHR_NONE, 0); 298 299 /* 300 * dismiss a gateway that is reachable only 301 * through the default router 302 */ 303 if ((nh == NULL) || (nh->nh_flags & NHF_DEFAULT)) 304 return (NULL); 305 ifa = nh->nh_ifa; 306 } 307 if (ifa->ifa_addr->sa_family != dst->sa_family) { 308 struct ifaddr *oifa = ifa; 309 ifa = ifaof_ifpforaddr(dst, ifa->ifa_ifp); 310 if (ifa == NULL) 311 ifa = oifa; 312 } 313 314 return (ifa); 315} 316 317/* 318 * Delete Routes for a Network Interface 319 * 320 * Called for each routing entry via the rnh->rnh_walktree() call above 321 * to delete all route entries referencing a detaching network interface. 322 * 323 * Arguments: 324 * rt pointer to rtentry 325 * nh pointer to nhop 326 * arg argument passed to rnh->rnh_walktree() - detaching interface 327 * 328 * Returns: 329 * 0 successful 330 * errno failed - reason indicated 331 */ 332static int 333rt_ifdelroute(const struct rtentry *rt, const struct nhop_object *nh, void *arg) 334{ 335 struct ifnet *ifp = arg; 336 337 if (nh->nh_ifp != ifp) 338 return (0); 339 340 /* 341 * Protect (sorta) against walktree recursion problems 342 * with cloned routes 343 */ 344 if ((rt->rte_flags & RTF_UP) == 0) 345 return (0); 346 347 return (1); 348} 349 350void 351rt_flushifroutes(struct ifnet *ifp) 352{ 353 354 rib_foreach_table_walk_del(AF_UNSPEC, rt_ifdelroute, ifp); 355} 356 357/* 358 * Tries to extract interface from RTAX_IFP passed in rt_addrinfo. 359 * Interface can be specified ether as interface index (sdl_index) or 360 * the interface name (sdl_data). 361 * 362 * Returns found ifp or NULL 363 */ 364static struct ifnet * 365info_get_ifp(struct rt_addrinfo *info) 366{ 367 const struct sockaddr_dl *sdl; 368 369 sdl = (const struct sockaddr_dl *)info->rti_info[RTAX_IFP]; 370 if (sdl->sdl_family != AF_LINK) 371 return (NULL); 372 373 if (sdl->sdl_index != 0) 374 return (ifnet_byindex(sdl->sdl_index)); 375 if (sdl->sdl_nlen > 0) { 376 char if_name[IF_NAMESIZE]; 377 if (sdl->sdl_nlen + offsetof(struct sockaddr_dl, sdl_data) > sdl->sdl_len) 378 return (NULL); 379 if (sdl->sdl_nlen >= IF_NAMESIZE) 380 return (NULL); 381 bzero(if_name, sizeof(if_name)); 382 memcpy(if_name, sdl->sdl_data, sdl->sdl_nlen); 383 return (ifunit(if_name)); 384 } 385 386 return (NULL); 387} 388 389/* 390 * Calculates proper ifa/ifp for the cases when gateway AF is different 391 * from dst AF. 392 * 393 * Returns 0 on success. 394 */ 395__noinline static int 396rt_getifa_family(struct rt_addrinfo *info, uint32_t fibnum) 397{ 398 if (info->rti_ifp == NULL) { 399 struct ifaddr *ifa = NULL; 400 /* 401 * No transmit interface specified. Guess it by checking gw sa. 402 */ 403 const struct sockaddr *gw = info->rti_info[RTAX_GATEWAY]; 404 ifa = ifa_ifwithroute(RTF_GATEWAY, gw, gw, fibnum); 405 if (ifa == NULL) 406 return (ENETUNREACH); 407 info->rti_ifp = ifa->ifa_ifp; 408 } 409 410 /* Prefer address from outgoing interface */ 411 info->rti_ifa = ifaof_ifpforaddr(info->rti_info[RTAX_DST], info->rti_ifp); 412#ifdef INET 413 if (info->rti_ifa == NULL) { 414 /* Use first found IPv4 address */ 415 bool loopback_ok = info->rti_ifp->if_flags & IFF_LOOPBACK; 416 info->rti_ifa = (struct ifaddr *)in_findlocal(fibnum, loopback_ok); 417 } 418#endif 419 if (info->rti_ifa == NULL) 420 return (ENETUNREACH); 421 return (0); 422} 423 424/* 425 * Fills in rti_ifp and rti_ifa for the provided fib. 426 * 427 * Assume basic consistency checks are executed by callers: 428 * RTAX_DST exists, if RTF_GATEWAY is set, RTAX_GATEWAY exists as well. 429 */ 430int 431rt_getifa_fib(struct rt_addrinfo *info, u_int fibnum) 432{ 433 const struct sockaddr *dst, *gateway, *ifaaddr; 434 int error, flags; 435 436 dst = info->rti_info[RTAX_DST]; 437 gateway = info->rti_info[RTAX_GATEWAY]; 438 ifaaddr = info->rti_info[RTAX_IFA]; 439 flags = info->rti_flags; 440 441 /* 442 * ifp may be specified by sockaddr_dl 443 * when protocol address is ambiguous. 444 */ 445 error = 0; 446 447 /* If we have interface specified by RTAX_IFP address, try to use it */ 448 if ((info->rti_ifp == NULL) && (info->rti_info[RTAX_IFP] != NULL)) 449 info->rti_ifp = info_get_ifp(info); 450 /* 451 * If we have source address specified, try to find it 452 * TODO: avoid enumerating all ifas on all interfaces. 453 */ 454 if (info->rti_ifa == NULL && ifaaddr != NULL) 455 info->rti_ifa = ifa_ifwithaddr(ifaaddr); 456 if ((info->rti_ifa == NULL) && ((info->rti_flags & RTF_GATEWAY) != 0) && 457 (gateway->sa_family != dst->sa_family)) 458 return (rt_getifa_family(info, fibnum)); 459 if (info->rti_ifa == NULL) { 460 const struct sockaddr *sa; 461 462 /* 463 * Most common use case for the userland-supplied routes. 464 * 465 * Choose sockaddr to select ifa. 466 * -- if ifp is set -- 467 * Order of preference: 468 * 1) IFA address 469 * 2) gateway address 470 * Note: for interface routes link-level gateway address 471 * is specified to indicate the interface index without 472 * specifying RTF_GATEWAY. In this case, ignore gateway 473 * Note: gateway AF may be different from dst AF. In this case, 474 * ignore gateway 475 * 3) final destination. 476 * 4) if all of these fails, try to get at least link-level ifa. 477 * -- else -- 478 * try to lookup gateway or dst in the routing table to get ifa 479 */ 480 if (info->rti_info[RTAX_IFA] != NULL) 481 sa = info->rti_info[RTAX_IFA]; 482 else if ((info->rti_flags & RTF_GATEWAY) != 0 && 483 gateway->sa_family == dst->sa_family) 484 sa = gateway; 485 else 486 sa = dst; 487 if (info->rti_ifp != NULL) { 488 info->rti_ifa = ifaof_ifpforaddr(sa, info->rti_ifp); 489 /* Case 4 */ 490 if (info->rti_ifa == NULL && gateway != NULL) 491 info->rti_ifa = ifaof_ifpforaddr(gateway, info->rti_ifp); 492 } else if (dst != NULL && gateway != NULL) 493 info->rti_ifa = ifa_ifwithroute(flags, dst, gateway, 494 fibnum); 495 else if (sa != NULL) 496 info->rti_ifa = ifa_ifwithroute(flags, sa, sa, 497 fibnum); 498 } 499 if (info->rti_ifa != NULL) { 500 if (info->rti_ifp == NULL) 501 info->rti_ifp = info->rti_ifa->ifa_ifp; 502 } else 503 error = ENETUNREACH; 504 return (error); 505} 506 507void 508rt_updatemtu(struct ifnet *ifp) 509{ 510 struct rib_head *rnh; 511 int mtu; 512 int i, j; 513 514 /* 515 * Try to update rt_mtu for all routes using this interface 516 * Unfortunately the only way to do this is to traverse all 517 * routing tables in all fibs/domains. 518 */ 519 for (i = 1; i <= AF_MAX; i++) { 520 mtu = if_getmtu_family(ifp, i); 521 for (j = 0; j < rt_numfibs; j++) { 522 rnh = rt_tables_get_rnh(j, i); 523 if (rnh == NULL) 524 continue; 525 nhops_update_ifmtu(rnh, ifp, mtu); 526 } 527 } 528} 529 530#if 0 531int p_sockaddr(char *buf, int buflen, struct sockaddr *s); 532int rt_print(char *buf, int buflen, struct rtentry *rt); 533 534int 535p_sockaddr(char *buf, int buflen, struct sockaddr *s) 536{ 537 void *paddr = NULL; 538 539 switch (s->sa_family) { 540 case AF_INET: 541 paddr = &((struct sockaddr_in *)s)->sin_addr; 542 break; 543 case AF_INET6: 544 paddr = &((struct sockaddr_in6 *)s)->sin6_addr; 545 break; 546 } 547 548 if (paddr == NULL) 549 return (0); 550 551 if (inet_ntop(s->sa_family, paddr, buf, buflen) == NULL) 552 return (0); 553 554 return (strlen(buf)); 555} 556 557int 558rt_print(char *buf, int buflen, struct rtentry *rt) 559{ 560 struct sockaddr *addr, *mask; 561 int i = 0; 562 563 addr = rt_key(rt); 564 mask = rt_mask(rt); 565 566 i = p_sockaddr(buf, buflen, addr); 567 if (!(rt->rt_flags & RTF_HOST)) { 568 buf[i++] = '/'; 569 i += p_sockaddr(buf + i, buflen - i, mask); 570 } 571 572 if (rt->rt_flags & RTF_GATEWAY) { 573 buf[i++] = '>'; 574 i += p_sockaddr(buf + i, buflen - i, &rt->rt_nhop->gw_sa); 575 } 576 577 return (i); 578} 579#endif 580 581void 582rt_maskedcopy(const struct sockaddr *src, struct sockaddr *dst, 583 const struct sockaddr *netmask) 584{ 585 const u_char *cp1 = (const u_char *)src; 586 u_char *cp2 = (u_char *)dst; 587 const u_char *cp3 = (const u_char *)netmask; 588 u_char *cplim = cp2 + *cp3; 589 u_char *cplim2 = cp2 + *cp1; 590 591 *cp2++ = *cp1++; *cp2++ = *cp1++; /* copies sa_len & sa_family */ 592 cp3 += 2; 593 if (cplim > cplim2) 594 cplim = cplim2; 595 while (cp2 < cplim) 596 *cp2++ = *cp1++ & *cp3++; 597 if (cp2 < cplim2) 598 bzero((caddr_t)cp2, (unsigned)(cplim2 - cp2)); 599} 600 601/* 602 * Announce interface address arrival/withdraw 603 * Returns 0 on success. 604 */ 605int 606rt_addrmsg(int cmd, struct ifaddr *ifa, int fibnum) 607{ 608#if defined(INET) || defined(INET6) 609 struct sockaddr *sa = ifa->ifa_addr; 610 struct ifnet *ifp = ifa->ifa_ifp; 611#endif 612 613 KASSERT(cmd == RTM_ADD || cmd == RTM_DELETE, 614 ("unexpected cmd %d", cmd)); 615 KASSERT((fibnum >= 0 && fibnum < rt_numfibs), 616 ("%s: fib out of range 0 <=%d<%d", __func__, fibnum, rt_numfibs)); 617 618 EVENTHANDLER_DIRECT_INVOKE(rt_addrmsg, ifa, cmd); 619 620#ifdef INET 621 if (sa->sa_family == AF_INET) { 622 char addrstr[INET_ADDRSTRLEN]; 623 char strbuf[INET_ADDRSTRLEN + 12]; 624 625 inet_ntoa_r(((struct sockaddr_in *)sa)->sin_addr, addrstr); 626 snprintf(strbuf, sizeof(strbuf), "address=%s", addrstr); 627 devctl_notify("IFNET", ifp->if_xname, 628 (cmd == RTM_ADD) ? "ADDR_ADD" : "ADDR_DEL", strbuf); 629 } 630#endif 631#ifdef INET6 632 if (sa->sa_family == AF_INET6) { 633 char addrstr[INET6_ADDRSTRLEN]; 634 char strbuf[INET6_ADDRSTRLEN + 12]; 635 636 ip6_sprintf(addrstr, IFA_IN6(ifa)); 637 snprintf(strbuf, sizeof(strbuf), "address=%s", addrstr); 638 devctl_notify("IFNET", ifp->if_xname, 639 (cmd == RTM_ADD) ? "ADDR_ADD" : "ADDR_DEL", strbuf); 640 } 641#endif 642 643 if (V_rt_add_addr_allfibs) 644 fibnum = RT_ALL_FIBS; 645 return (rtsock_addrmsg(cmd, ifa, fibnum)); 646} 647 648/* 649 * Announce kernel-originated route addition/removal to rtsock based on @rt data. 650 * cmd: RTM_ cmd 651 * @rt: valid rtentry 652 * @nh: nhop object to announce 653 * @fibnum: fib id or RT_ALL_FIBS 654 * 655 * Returns 0 on success. 656 */ 657int 658rt_routemsg(int cmd, struct rtentry *rt, struct nhop_object *nh, 659 int fibnum) 660{ 661 662 KASSERT(cmd == RTM_ADD || cmd == RTM_DELETE || cmd == RTM_CHANGE, 663 ("unexpected cmd %d", cmd)); 664 665 KASSERT(fibnum == RT_ALL_FIBS || (fibnum >= 0 && fibnum < rt_numfibs), 666 ("%s: fib out of range 0 <=%d<%d", __func__, fibnum, rt_numfibs)); 667 668 KASSERT(rt_key(rt) != NULL, (":%s: rt_key must be supplied", __func__)); 669 670 return (rtsock_routemsg(cmd, rt, nh, fibnum)); 671} 672 673/* 674 * Announce kernel-originated route addition/removal to rtsock based on @rt data. 675 * cmd: RTM_ cmd 676 * @info: addrinfo structure with valid data. 677 * @fibnum: fib id or RT_ALL_FIBS 678 * 679 * Returns 0 on success. 680 */ 681int 682rt_routemsg_info(int cmd, struct rt_addrinfo *info, int fibnum) 683{ 684 685 KASSERT(cmd == RTM_ADD || cmd == RTM_DELETE || cmd == RTM_CHANGE, 686 ("unexpected cmd %d", cmd)); 687 688 KASSERT(fibnum == RT_ALL_FIBS || (fibnum >= 0 && fibnum < rt_numfibs), 689 ("%s: fib out of range 0 <=%d<%d", __func__, fibnum, rt_numfibs)); 690 691 KASSERT(info->rti_info[RTAX_DST] != NULL, (":%s: RTAX_DST must be supplied", __func__)); 692 693 return (rtsock_routemsg_info(cmd, info, fibnum)); 694} 695 696void 697rt_ifmsg(struct ifnet *ifp, int if_flags_mask) 698{ 699 rtsock_callback_p->ifmsg_f(ifp, if_flags_mask); 700 netlink_callback_p->ifmsg_f(ifp, if_flags_mask); 701} 702 703