/*-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 <sys/cdefs.h>34#include "opt_inet.h"35#include "opt_inet6.h"3637#include <sys/param.h>38#include <sys/mbuf.h>39#include <sys/socket.h>40#include <sys/systm.h>41#include <sys/queue.h>4243#include <net/if.h>44#include <net/if_var.h>4546#include <netinet/in.h>47#include <netinet6/in6_var.h>48#include <netinet/ip6.h>49#include <netinet6/ip6_var.h>50#include <netinet6/scope6_var.h>5152#include <netinet/icmp6.h>5354/*55* proto - is unused56*/5758int59route6_input(struct mbuf **mp, int *offp, int proto)60{61struct ip6_hdr *ip6;62struct mbuf *m;63struct ip6_rthdr *rh;64int off = *offp, rhlen;65#ifdef __notyet__66struct ip6aux *ip6a;67#endif6869m = *mp;7071#ifdef __notyet__72ip6a = ip6_findaux(m);73if (ip6a) {74/* XXX reject home-address option before rthdr */75if (ip6a->ip6a_flags & IP6A_SWAP) {76IP6STAT_INC(ip6s_badoptions);77m_freem(m);78return IPPROTO_DONE;79}80}81#endif8283if (m->m_len < off + sizeof(*rh)) {84m = m_pullup(m, off + sizeof(*rh));85if (m == NULL) {86IP6STAT_INC(ip6s_exthdrtoolong);87*mp = NULL;88return (IPPROTO_DONE);89}90}91ip6 = mtod(m, struct ip6_hdr *);92rh = (struct ip6_rthdr *)((caddr_t)ip6 + off);9394/*95* While this switch may look gratuitous, leave it in96* in favour of RH2 implementations, etc.97*/98switch (rh->ip6r_type) {99default:100/* Unknown routing header type. */101if (rh->ip6r_segleft == 0) {102rhlen = (rh->ip6r_len + 1) << 3;103break; /* Final dst. Just ignore the header. */104}105IP6STAT_INC(ip6s_badoptions);106icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER,107(caddr_t)&rh->ip6r_type - (caddr_t)ip6);108*mp = NULL;109return (IPPROTO_DONE);110}111112*offp += rhlen;113*mp = m;114return (rh->ip6r_nxt);115}116117118