xref: /freebsd/sys/netinet6/route6.c (revision 51369649b03ece2aed3eb61b0c8214b9aa5b2fa2)
1caf43b02SWarner Losh /*-
2*51369649SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
3*51369649SPedro F. Giffuni  *
482cd038dSYoshinobu Inoue  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
582cd038dSYoshinobu Inoue  * All rights reserved.
682cd038dSYoshinobu Inoue  *
782cd038dSYoshinobu Inoue  * Redistribution and use in source and binary forms, with or without
882cd038dSYoshinobu Inoue  * modification, are permitted provided that the following conditions
982cd038dSYoshinobu Inoue  * are met:
1082cd038dSYoshinobu Inoue  * 1. Redistributions of source code must retain the above copyright
1182cd038dSYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer.
1282cd038dSYoshinobu Inoue  * 2. Redistributions in binary form must reproduce the above copyright
1382cd038dSYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer in the
1482cd038dSYoshinobu Inoue  *    documentation and/or other materials provided with the distribution.
1582cd038dSYoshinobu Inoue  * 3. Neither the name of the project nor the names of its contributors
1682cd038dSYoshinobu Inoue  *    may be used to endorse or promote products derived from this software
1782cd038dSYoshinobu Inoue  *    without specific prior written permission.
1882cd038dSYoshinobu Inoue  *
1982cd038dSYoshinobu Inoue  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
2082cd038dSYoshinobu Inoue  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2182cd038dSYoshinobu Inoue  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2282cd038dSYoshinobu Inoue  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
2382cd038dSYoshinobu Inoue  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2482cd038dSYoshinobu Inoue  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2582cd038dSYoshinobu Inoue  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2682cd038dSYoshinobu Inoue  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2782cd038dSYoshinobu Inoue  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2882cd038dSYoshinobu Inoue  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2982cd038dSYoshinobu Inoue  * SUCH DAMAGE.
30b48287a3SDavid E. O'Brien  *
31b48287a3SDavid E. O'Brien  *	$KAME: route6.c,v 1.24 2001/03/14 03:07:05 itojun Exp $
3282cd038dSYoshinobu Inoue  */
3382cd038dSYoshinobu Inoue 
34b48287a3SDavid E. O'Brien #include <sys/cdefs.h>
35b48287a3SDavid E. O'Brien __FBSDID("$FreeBSD$");
36b48287a3SDavid E. O'Brien 
37686cdd19SJun-ichiro itojun Hagino #include "opt_inet.h"
38686cdd19SJun-ichiro itojun Hagino #include "opt_inet6.h"
39686cdd19SJun-ichiro itojun Hagino 
4082cd038dSYoshinobu Inoue #include <sys/param.h>
4182cd038dSYoshinobu Inoue #include <sys/mbuf.h>
4282cd038dSYoshinobu Inoue #include <sys/socket.h>
43686cdd19SJun-ichiro itojun Hagino #include <sys/systm.h>
4433841545SHajimu UMEMOTO #include <sys/queue.h>
4582cd038dSYoshinobu Inoue 
4682cd038dSYoshinobu Inoue #include <net/if.h>
4776039bc8SGleb Smirnoff #include <net/if_var.h>
4882cd038dSYoshinobu Inoue 
4982cd038dSYoshinobu Inoue #include <netinet/in.h>
5082cd038dSYoshinobu Inoue #include <netinet6/in6_var.h>
51686cdd19SJun-ichiro itojun Hagino #include <netinet/ip6.h>
5282cd038dSYoshinobu Inoue #include <netinet6/ip6_var.h>
53a1f7e5f8SHajimu UMEMOTO #include <netinet6/scope6_var.h>
5482cd038dSYoshinobu Inoue 
5582cd038dSYoshinobu Inoue #include <netinet/icmp6.h>
5682cd038dSYoshinobu Inoue 
571272577eSXin LI /*
581272577eSXin LI  * proto - is unused
591272577eSXin LI  */
601272577eSXin LI 
6182cd038dSYoshinobu Inoue int
621272577eSXin LI route6_input(struct mbuf **mp, int *offp, int proto)
6382cd038dSYoshinobu Inoue {
6433841545SHajimu UMEMOTO 	struct ip6_hdr *ip6;
6533841545SHajimu UMEMOTO 	struct mbuf *m = *mp;
6633841545SHajimu UMEMOTO 	struct ip6_rthdr *rh;
6782cd038dSYoshinobu Inoue 	int off = *offp, rhlen;
681b53a49aSBjoern A. Zeeb #ifdef __notyet__
691410779aSHajimu UMEMOTO 	struct ip6aux *ip6a;
7033841545SHajimu UMEMOTO 
711410779aSHajimu UMEMOTO 	ip6a = ip6_findaux(m);
721410779aSHajimu UMEMOTO 	if (ip6a) {
7333841545SHajimu UMEMOTO 		/* XXX reject home-address option before rthdr */
7433841545SHajimu UMEMOTO 		if (ip6a->ip6a_flags & IP6A_SWAP) {
759cb8d207SAndrey V. Elsukov 			IP6STAT_INC(ip6s_badoptions);
7633841545SHajimu UMEMOTO 			m_freem(m);
7733841545SHajimu UMEMOTO 			return IPPROTO_DONE;
7833841545SHajimu UMEMOTO 		}
7933841545SHajimu UMEMOTO 	}
801b53a49aSBjoern A. Zeeb #endif
8182cd038dSYoshinobu Inoue 
82686cdd19SJun-ichiro itojun Hagino #ifndef PULLDOWN_TEST
8382cd038dSYoshinobu Inoue 	IP6_EXTHDR_CHECK(m, off, sizeof(*rh), IPPROTO_DONE);
8482cd038dSYoshinobu Inoue 	ip6 = mtod(m, struct ip6_hdr *);
8582cd038dSYoshinobu Inoue 	rh = (struct ip6_rthdr *)((caddr_t)ip6 + off);
86686cdd19SJun-ichiro itojun Hagino #else
87686cdd19SJun-ichiro itojun Hagino 	ip6 = mtod(m, struct ip6_hdr *);
88686cdd19SJun-ichiro itojun Hagino 	IP6_EXTHDR_GET(rh, struct ip6_rthdr *, m, off, sizeof(*rh));
89686cdd19SJun-ichiro itojun Hagino 	if (rh == NULL) {
909cb8d207SAndrey V. Elsukov 		IP6STAT_INC(ip6s_tooshort);
91686cdd19SJun-ichiro itojun Hagino 		return IPPROTO_DONE;
92686cdd19SJun-ichiro itojun Hagino 	}
93686cdd19SJun-ichiro itojun Hagino #endif
9482cd038dSYoshinobu Inoue 
951263305fSBjoern A. Zeeb 	/*
961263305fSBjoern A. Zeeb 	 * While this switch may look gratuitous, leave it in
971263305fSBjoern A. Zeeb 	 * in favour of RH2 implementations, etc.
981263305fSBjoern A. Zeeb 	 */
9982cd038dSYoshinobu Inoue 	switch (rh->ip6r_type) {
10082cd038dSYoshinobu Inoue 	default:
1011263305fSBjoern A. Zeeb 		/* Unknown routing header type. */
10282cd038dSYoshinobu Inoue 		if (rh->ip6r_segleft == 0) {
10382cd038dSYoshinobu Inoue 			rhlen = (rh->ip6r_len + 1) << 3;
10482cd038dSYoshinobu Inoue 			break;	/* Final dst. Just ignore the header. */
10582cd038dSYoshinobu Inoue 		}
1069cb8d207SAndrey V. Elsukov 		IP6STAT_INC(ip6s_badoptions);
10782cd038dSYoshinobu Inoue 		icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER,
10882cd038dSYoshinobu Inoue 			    (caddr_t)&rh->ip6r_type - (caddr_t)ip6);
10982cd038dSYoshinobu Inoue 		return (IPPROTO_DONE);
11082cd038dSYoshinobu Inoue 	}
11182cd038dSYoshinobu Inoue 
11282cd038dSYoshinobu Inoue 	*offp += rhlen;
11382cd038dSYoshinobu Inoue 	return (rh->ip6r_nxt);
11482cd038dSYoshinobu Inoue }
115