/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14* 3. Neither the name of the project nor the names of its contributors15* may be used to endorse or promote products derived from this software16* without specific prior written permission.17*18* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND19* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE20* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE21* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE22* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL23* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS24* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)25* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT26* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY27* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF28* SUCH DAMAGE.29*30* $KAME: in6_rmx.c,v 1.11 2001/07/26 06:53:16 jinmei Exp $31*/3233/*-34* Copyright 1994, 1995 Massachusetts Institute of Technology35*36* Permission to use, copy, modify, and distribute this software and37* its documentation for any purpose and without fee is hereby38* granted, provided that both the above copyright notice and this39* permission notice appear in all copies, that both the above40* copyright notice and this permission notice appear in all41* supporting documentation, and that the name of M.I.T. not be used42* in advertising or publicity pertaining to distribution of the43* software without specific, written prior permission. M.I.T. makes44* no representations about the suitability of this software for any45* purpose. It is provided "as is" without express or implied46* warranty.47*48* THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS49* ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,50* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF51* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT52* SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,53* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT54* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF55* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND56* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,57* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT58* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF59* SUCH DAMAGE.60*61*/6263#include <sys/param.h>64#include <sys/systm.h>65#include <sys/kernel.h>66#include <sys/lock.h>67#include <sys/queue.h>68#include <sys/socket.h>69#include <sys/mbuf.h>70#include <sys/rwlock.h>71#include <sys/syslog.h>72#include <sys/callout.h>7374#include <net/if.h>75#include <net/if_var.h>76#include <net/if_private.h>77#include <net/route.h>78#include <net/route/route_ctl.h>79#include <net/route/route_var.h>80#include <net/route/nhop.h>8182#include <netinet/in.h>83#include <netinet/ip_var.h>84#include <netinet/in_var.h>8586#include <netinet/ip6.h>87#include <netinet6/ip6_var.h>8889#include <netinet/icmp6.h>90#include <netinet6/nd6.h>9192static int93rib6_set_nh_pfxflags(u_int fibnum, const struct sockaddr *addr, const struct sockaddr *mask,94struct nhop_object *nh)95{96const struct sockaddr_in6 *mask6 = (const struct sockaddr_in6 *)mask;9798if (mask6 == NULL)99nhop_set_pxtype_flag(nh, NHF_HOST);100else if (IN6_IS_ADDR_UNSPECIFIED(&mask6->sin6_addr))101nhop_set_pxtype_flag(nh, NHF_DEFAULT);102else103nhop_set_pxtype_flag(nh, 0);104105return (0);106}107108static int109rib6_augment_nh(u_int fibnum, struct nhop_object *nh)110{111/*112* Check route MTU:113* inherit interface MTU if not set or114* check if MTU is too large.115*/116if (nh->nh_mtu == 0) {117nh->nh_mtu = IN6_LINKMTU(nh->nh_ifp);118} else if (nh->nh_mtu > IN6_LINKMTU(nh->nh_ifp))119nh->nh_mtu = IN6_LINKMTU(nh->nh_ifp);120121/* Set nexthop type */122if (nhop_get_type(nh) == 0) {123uint16_t nh_type;124if (nh->nh_flags & NHF_GATEWAY)125nh_type = NH_TYPE_IPV6_ETHER_NHOP;126else127nh_type = NH_TYPE_IPV6_ETHER_RSLV;128129nhop_set_type(nh, nh_type);130}131132return (0);133}134135/*136* Initialize our routing tree.137*/138139struct rib_head *140in6_inithead(uint32_t fibnum)141{142struct rib_head *rh;143struct rib_subscription *rs __diagused;144145rh = rt_table_init(offsetof(struct sockaddr_in6, sin6_addr) << 3,146AF_INET6, fibnum);147if (rh == NULL)148return (NULL);149150rh->rnh_set_nh_pfxflags = rib6_set_nh_pfxflags;151rh->rnh_augment_nh = rib6_augment_nh;152153rs = rib_subscribe_internal(rh, nd6_subscription_cb, NULL,154RIB_NOTIFY_IMMEDIATE, true);155KASSERT(rs != NULL, ("Unable to subscribe to fib %u\n", fibnum));156157return (rh);158}159160#ifdef VIMAGE161void162in6_detachhead(struct rib_head *rh)163{164165rt_table_destroy(rh);166}167#endif168169170