xref: /dflybsd-src/sys/netinet6/route6.c (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
186d7f5d3SJohn Marino /*	$FreeBSD: src/sys/netinet6/route6.c,v 1.1.2.5 2003/01/23 21:06:47 sam Exp $	*/
286d7f5d3SJohn Marino /*	$DragonFly: src/sys/netinet6/route6.c,v 1.10 2008/09/04 09:08:22 hasso Exp $	*/
386d7f5d3SJohn Marino /*	$KAME: route6.c,v 1.24 2001/03/14 03:07:05 itojun Exp $	*/
486d7f5d3SJohn Marino 
586d7f5d3SJohn Marino /*
686d7f5d3SJohn Marino  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
786d7f5d3SJohn Marino  * All rights reserved.
886d7f5d3SJohn Marino  *
986d7f5d3SJohn Marino  * Redistribution and use in source and binary forms, with or without
1086d7f5d3SJohn Marino  * modification, are permitted provided that the following conditions
1186d7f5d3SJohn Marino  * are met:
1286d7f5d3SJohn Marino  * 1. Redistributions of source code must retain the above copyright
1386d7f5d3SJohn Marino  *    notice, this list of conditions and the following disclaimer.
1486d7f5d3SJohn Marino  * 2. Redistributions in binary form must reproduce the above copyright
1586d7f5d3SJohn Marino  *    notice, this list of conditions and the following disclaimer in the
1686d7f5d3SJohn Marino  *    documentation and/or other materials provided with the distribution.
1786d7f5d3SJohn Marino  * 3. Neither the name of the project nor the names of its contributors
1886d7f5d3SJohn Marino  *    may be used to endorse or promote products derived from this software
1986d7f5d3SJohn Marino  *    without specific prior written permission.
2086d7f5d3SJohn Marino  *
2186d7f5d3SJohn Marino  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
2286d7f5d3SJohn Marino  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2386d7f5d3SJohn Marino  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2486d7f5d3SJohn Marino  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
2586d7f5d3SJohn Marino  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2686d7f5d3SJohn Marino  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2786d7f5d3SJohn Marino  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2886d7f5d3SJohn Marino  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2986d7f5d3SJohn Marino  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3086d7f5d3SJohn Marino  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3186d7f5d3SJohn Marino  * SUCH DAMAGE.
3286d7f5d3SJohn Marino  */
3386d7f5d3SJohn Marino 
3486d7f5d3SJohn Marino #include "opt_inet.h"
3586d7f5d3SJohn Marino #include "opt_inet6.h"
3686d7f5d3SJohn Marino 
3786d7f5d3SJohn Marino #include <sys/param.h>
3886d7f5d3SJohn Marino #include <sys/mbuf.h>
3986d7f5d3SJohn Marino #include <sys/socket.h>
4086d7f5d3SJohn Marino #include <sys/systm.h>
4186d7f5d3SJohn Marino #include <sys/queue.h>
4286d7f5d3SJohn Marino 
4386d7f5d3SJohn Marino #include <net/if.h>
4486d7f5d3SJohn Marino 
4586d7f5d3SJohn Marino #include <netinet/in.h>
4686d7f5d3SJohn Marino #include <netinet6/in6_var.h>
4786d7f5d3SJohn Marino #include <netinet/ip6.h>
4886d7f5d3SJohn Marino #include <netinet6/ip6_var.h>
4986d7f5d3SJohn Marino 
5086d7f5d3SJohn Marino #include <netinet/icmp6.h>
5186d7f5d3SJohn Marino 
5286d7f5d3SJohn Marino int
route6_input(struct mbuf ** mp,int * offp,int proto)5386d7f5d3SJohn Marino route6_input(struct mbuf **mp, int *offp, int proto) /* proto is unused */
5486d7f5d3SJohn Marino {
5586d7f5d3SJohn Marino 	struct ip6_hdr *ip6;
5686d7f5d3SJohn Marino 	struct mbuf *m = *mp;
5786d7f5d3SJohn Marino 	struct ip6_rthdr *rh;
5886d7f5d3SJohn Marino 	int off = *offp, rhlen;
5986d7f5d3SJohn Marino 
6086d7f5d3SJohn Marino #ifndef PULLDOWN_TEST
6186d7f5d3SJohn Marino 	IP6_EXTHDR_CHECK(m, off, sizeof(*rh), IPPROTO_DONE);
6286d7f5d3SJohn Marino 	ip6 = mtod(m, struct ip6_hdr *);
6386d7f5d3SJohn Marino 	rh = (struct ip6_rthdr *)((caddr_t)ip6 + off);
6486d7f5d3SJohn Marino #else
6586d7f5d3SJohn Marino 	ip6 = mtod(m, struct ip6_hdr *);
6686d7f5d3SJohn Marino 	IP6_EXTHDR_GET(rh, struct ip6_rthdr *, m, off, sizeof(*rh));
6786d7f5d3SJohn Marino 	if (rh == NULL) {
6886d7f5d3SJohn Marino 		ip6stat.ip6s_tooshort++;
6986d7f5d3SJohn Marino 		return IPPROTO_DONE;
7086d7f5d3SJohn Marino 	}
7186d7f5d3SJohn Marino #endif
7286d7f5d3SJohn Marino 
7386d7f5d3SJohn Marino 	switch (rh->ip6r_type) {
7486d7f5d3SJohn Marino 	default:
7586d7f5d3SJohn Marino 		/* unknown routing type */
7686d7f5d3SJohn Marino 		if (rh->ip6r_segleft == 0) {
7786d7f5d3SJohn Marino 			rhlen = (rh->ip6r_len + 1) << 3;
7886d7f5d3SJohn Marino 			break;	/* Final dst. Just ignore the header. */
7986d7f5d3SJohn Marino 		}
8086d7f5d3SJohn Marino 		ip6stat.ip6s_badoptions++;
8186d7f5d3SJohn Marino 		icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER,
8286d7f5d3SJohn Marino 			    (caddr_t)&rh->ip6r_type - (caddr_t)ip6);
8386d7f5d3SJohn Marino 		return (IPPROTO_DONE);
8486d7f5d3SJohn Marino 	}
8586d7f5d3SJohn Marino 
8686d7f5d3SJohn Marino 	*offp += rhlen;
8786d7f5d3SJohn Marino 	return (rh->ip6r_nxt);
8886d7f5d3SJohn Marino }
89