/*-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: route6.c,v 1.24 2001/03/14 03:07:05 itojun Exp $31*/3233#include "opt_inet.h"34#include "opt_inet6.h"3536#include <sys/param.h>37#include <sys/mbuf.h>38#include <sys/socket.h>39#include <sys/systm.h>40#include <sys/queue.h>4142#include <net/if.h>43#include <net/if_var.h>4445#include <netinet/in.h>46#include <netinet6/in6_var.h>47#include <netinet/ip6.h>48#include <netinet6/ip6_var.h>49#include <netinet6/scope6_var.h>5051#include <netinet/icmp6.h>5253/*54* proto - is unused55*/5657int58route6_input(struct mbuf **mp, int *offp, int proto)59{60struct ip6_hdr *ip6;61struct mbuf *m;62struct ip6_rthdr *rh;63int off = *offp, rhlen;64#ifdef __notyet__65struct ip6aux *ip6a;66#endif6768m = *mp;6970#ifdef __notyet__71ip6a = ip6_findaux(m);72if (ip6a) {73/* XXX reject home-address option before rthdr */74if (ip6a->ip6a_flags & IP6A_SWAP) {75IP6STAT_INC(ip6s_badoptions);76m_freem(m);77return IPPROTO_DONE;78}79}80#endif8182if (m->m_len < off + sizeof(*rh)) {83m = m_pullup(m, off + sizeof(*rh));84if (m == NULL) {85IP6STAT_INC(ip6s_exthdrtoolong);86*mp = NULL;87return (IPPROTO_DONE);88}89}90ip6 = mtod(m, struct ip6_hdr *);91rh = (struct ip6_rthdr *)((caddr_t)ip6 + off);9293/*94* While this switch may look gratuitous, leave it in95* in favour of RH2 implementations, etc.96*/97switch (rh->ip6r_type) {98default:99/* Unknown routing header type. */100if (rh->ip6r_segleft == 0) {101rhlen = (rh->ip6r_len + 1) << 3;102break; /* Final dst. Just ignore the header. */103}104IP6STAT_INC(ip6s_badoptions);105icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER,106(caddr_t)&rh->ip6r_type - (caddr_t)ip6);107*mp = NULL;108return (IPPROTO_DONE);109}110111*offp += rhlen;112*mp = m;113return (rh->ip6r_nxt);114}115116117