xref: /onnv-gate/usr/src/uts/common/inet/ip/ip6_rts.c (revision 1676:37f4a3e2bd99)
10Sstevel@tonic-gate /*
2*1676Sjpk  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
30Sstevel@tonic-gate  * Use is subject to license terms.
40Sstevel@tonic-gate  */
50Sstevel@tonic-gate 
60Sstevel@tonic-gate /*
70Sstevel@tonic-gate  * Copyright (c) 1988, 1991, 1993
80Sstevel@tonic-gate  *	The Regents of the University of California.  All rights reserved.
90Sstevel@tonic-gate  *
100Sstevel@tonic-gate  * Redistribution and use in source and binary forms, with or without
110Sstevel@tonic-gate  * modification, are permitted provided that the following conditions
120Sstevel@tonic-gate  * are met:
130Sstevel@tonic-gate  * 1. Redistributions of source code must retain the above copyright
140Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer.
150Sstevel@tonic-gate  * 2. Redistributions in binary form must reproduce the above copyright
160Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer in the
170Sstevel@tonic-gate  *    documentation and/or other materials provided with the distribution.
180Sstevel@tonic-gate  * 3. All advertising materials mentioning features or use of this software
190Sstevel@tonic-gate  *    must display the following acknowledgement:
200Sstevel@tonic-gate  *	This product includes software developed by the University of
210Sstevel@tonic-gate  *	California, Berkeley and its contributors.
220Sstevel@tonic-gate  * 4. Neither the name of the University nor the names of its contributors
230Sstevel@tonic-gate  *    may be used to endorse or promote products derived from this software
240Sstevel@tonic-gate  *    without specific prior written permission.
250Sstevel@tonic-gate  *
260Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
270Sstevel@tonic-gate  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
280Sstevel@tonic-gate  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
290Sstevel@tonic-gate  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
300Sstevel@tonic-gate  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
310Sstevel@tonic-gate  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
320Sstevel@tonic-gate  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
330Sstevel@tonic-gate  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
340Sstevel@tonic-gate  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
350Sstevel@tonic-gate  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
360Sstevel@tonic-gate  * SUCH DAMAGE.
370Sstevel@tonic-gate  *
380Sstevel@tonic-gate  *	@(#)rtsock.c	8.6 (Berkeley) 2/11/95
390Sstevel@tonic-gate  */
400Sstevel@tonic-gate 
410Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
420Sstevel@tonic-gate 
430Sstevel@tonic-gate /*
440Sstevel@tonic-gate  * This file contains routines that processes routing socket requests.
450Sstevel@tonic-gate  */
460Sstevel@tonic-gate 
470Sstevel@tonic-gate #include <sys/types.h>
480Sstevel@tonic-gate #include <sys/stream.h>
490Sstevel@tonic-gate #include <sys/stropts.h>
500Sstevel@tonic-gate #include <sys/strlog.h>
510Sstevel@tonic-gate #include <sys/dlpi.h>
520Sstevel@tonic-gate #include <sys/ddi.h>
530Sstevel@tonic-gate #include <sys/cmn_err.h>
540Sstevel@tonic-gate #include <sys/debug.h>
550Sstevel@tonic-gate 
560Sstevel@tonic-gate #include <sys/systm.h>
570Sstevel@tonic-gate #include <sys/param.h>
580Sstevel@tonic-gate #include <sys/socket.h>
590Sstevel@tonic-gate #define	_SUN_TPI_VERSION	2
600Sstevel@tonic-gate #include <sys/tihdr.h>
610Sstevel@tonic-gate #include <net/if.h>
620Sstevel@tonic-gate #include <net/route.h>
630Sstevel@tonic-gate #include <netinet/in.h>
640Sstevel@tonic-gate #include <net/if_dl.h>
650Sstevel@tonic-gate #include <netinet/ip6.h>
660Sstevel@tonic-gate 
670Sstevel@tonic-gate #include <inet/common.h>
680Sstevel@tonic-gate #include <inet/mi.h>
690Sstevel@tonic-gate #include <inet/ip.h>
700Sstevel@tonic-gate #include <inet/ip6.h>
710Sstevel@tonic-gate #include <inet/ip_if.h>
720Sstevel@tonic-gate #include <inet/ip_ire.h>
730Sstevel@tonic-gate #include <inet/ip_rts.h>
740Sstevel@tonic-gate #include <inet/ip_multi.h>
75*1676Sjpk #include <sys/tsol/tndb.h>
76*1676Sjpk #include <sys/tsol/tnet.h>
770Sstevel@tonic-gate 
780Sstevel@tonic-gate /*
790Sstevel@tonic-gate  * Fills the message with the given info.
800Sstevel@tonic-gate  */
810Sstevel@tonic-gate void
820Sstevel@tonic-gate rts_fill_msg_v6(int type, int rtm_addrs, const in6_addr_t *dst,
830Sstevel@tonic-gate     const in6_addr_t *mask, const in6_addr_t *gateway,
840Sstevel@tonic-gate     const in6_addr_t *src_addr, const in6_addr_t *brd_addr,
85*1676Sjpk     const in6_addr_t *author, const ipif_t *ipif, mblk_t *mp,
86*1676Sjpk     uint_t sacnt, const tsol_gc_t *gc)
870Sstevel@tonic-gate {
880Sstevel@tonic-gate 	rt_msghdr_t	*rtm;
890Sstevel@tonic-gate 	sin6_t		*sin6;
900Sstevel@tonic-gate 	size_t		data_size, header_size;
910Sstevel@tonic-gate 	uchar_t		*cp;
920Sstevel@tonic-gate 	int		i;
930Sstevel@tonic-gate 
940Sstevel@tonic-gate 	ASSERT(mp != NULL);
95*1676Sjpk 	ASSERT(sacnt == 0 || gc != NULL);
960Sstevel@tonic-gate 	/*
970Sstevel@tonic-gate 	 * First find the type of the message
980Sstevel@tonic-gate 	 * and its length.
990Sstevel@tonic-gate 	 */
1000Sstevel@tonic-gate 	header_size = rts_header_msg_size(type);
1010Sstevel@tonic-gate 	/*
1020Sstevel@tonic-gate 	 * Now find the size of the data
1030Sstevel@tonic-gate 	 * that follows the message header.
1040Sstevel@tonic-gate 	 */
105*1676Sjpk 	data_size = rts_data_msg_size(rtm_addrs, AF_INET6, sacnt);
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate 	rtm = (rt_msghdr_t *)mp->b_rptr;
1080Sstevel@tonic-gate 	mp->b_wptr = &mp->b_rptr[header_size];
1090Sstevel@tonic-gate 	cp = mp->b_wptr;
1100Sstevel@tonic-gate 	bzero(cp, data_size);
1110Sstevel@tonic-gate 	for (i = 0; i < RTA_NUMBITS; i++) {
1120Sstevel@tonic-gate 		sin6 = (sin6_t *)cp;
1130Sstevel@tonic-gate 		switch (rtm_addrs & (1 << i)) {
1140Sstevel@tonic-gate 		case RTA_DST:
1150Sstevel@tonic-gate 			sin6->sin6_addr = *dst;
1160Sstevel@tonic-gate 			sin6->sin6_family = AF_INET6;
1170Sstevel@tonic-gate 			cp += sizeof (sin6_t);
1180Sstevel@tonic-gate 			break;
1190Sstevel@tonic-gate 		case RTA_GATEWAY:
1200Sstevel@tonic-gate 			sin6->sin6_addr = *gateway;
1210Sstevel@tonic-gate 			sin6->sin6_family = AF_INET6;
1220Sstevel@tonic-gate 			cp += sizeof (sin6_t);
1230Sstevel@tonic-gate 			break;
1240Sstevel@tonic-gate 		case RTA_NETMASK:
1250Sstevel@tonic-gate 			sin6->sin6_addr = *mask;
1260Sstevel@tonic-gate 			sin6->sin6_family = AF_INET6;
1270Sstevel@tonic-gate 			cp += sizeof (sin6_t);
1280Sstevel@tonic-gate 			break;
1290Sstevel@tonic-gate 		case RTA_IFA:
1300Sstevel@tonic-gate 		case RTA_SRC:
1310Sstevel@tonic-gate 			sin6->sin6_addr = *src_addr;
1320Sstevel@tonic-gate 			sin6->sin6_family = AF_INET6;
1330Sstevel@tonic-gate 			cp += sizeof (sin6_t);
1340Sstevel@tonic-gate 			break;
1350Sstevel@tonic-gate 		case RTA_IFP:
1360Sstevel@tonic-gate 			cp += ill_dls_info((struct sockaddr_dl *)cp, ipif);
1370Sstevel@tonic-gate 			break;
1380Sstevel@tonic-gate 		case RTA_AUTHOR:
1390Sstevel@tonic-gate 			sin6->sin6_addr = *author;
1400Sstevel@tonic-gate 			sin6->sin6_family = AF_INET6;
1410Sstevel@tonic-gate 			cp += sizeof (sin6_t);
1420Sstevel@tonic-gate 			break;
1430Sstevel@tonic-gate 		case RTA_BRD:
1440Sstevel@tonic-gate 			/*
1450Sstevel@tonic-gate 			 * RTA_BRD is used typically to specify a point-to-point
1460Sstevel@tonic-gate 			 * destination address.
1470Sstevel@tonic-gate 			 */
1480Sstevel@tonic-gate 			sin6->sin6_addr = *brd_addr;
1490Sstevel@tonic-gate 			sin6->sin6_family = AF_INET6;
1500Sstevel@tonic-gate 			cp += sizeof (sin6_t);
1510Sstevel@tonic-gate 			break;
1520Sstevel@tonic-gate 		}
1530Sstevel@tonic-gate 	}
154*1676Sjpk 
155*1676Sjpk 	if (gc != NULL) {
156*1676Sjpk 		rtm_ext_t *rtm_ext;
157*1676Sjpk 		struct rtsa_s *rp_dst;
158*1676Sjpk 		tsol_rtsecattr_t *rsap;
159*1676Sjpk 		int i;
160*1676Sjpk 
161*1676Sjpk 		ASSERT(gc->gc_grp != NULL);
162*1676Sjpk 		ASSERT(RW_LOCK_HELD(&gc->gc_grp->gcgrp_rwlock));
163*1676Sjpk 		ASSERT(sacnt > 0);
164*1676Sjpk 
165*1676Sjpk 		rtm_ext = (rtm_ext_t *)cp;
166*1676Sjpk 		rtm_ext->rtmex_type = RTMEX_GATEWAY_SECATTR;
167*1676Sjpk 		rtm_ext->rtmex_len = TSOL_RTSECATTR_SIZE(sacnt);
168*1676Sjpk 
169*1676Sjpk 		rsap = (tsol_rtsecattr_t *)(rtm_ext + 1);
170*1676Sjpk 		rsap->rtsa_cnt = sacnt;
171*1676Sjpk 		rp_dst = rsap->rtsa_attr;
172*1676Sjpk 
173*1676Sjpk 		for (i = 0; i < sacnt; i++, gc = gc->gc_next, rp_dst++) {
174*1676Sjpk 			ASSERT(gc->gc_db != NULL);
175*1676Sjpk 			bcopy(&gc->gc_db->gcdb_attr, rp_dst, sizeof (*rp_dst));
176*1676Sjpk 		}
177*1676Sjpk 		cp = (uchar_t *)rp_dst;
178*1676Sjpk 	}
179*1676Sjpk 
1800Sstevel@tonic-gate 	mp->b_wptr = cp;
1810Sstevel@tonic-gate 	mp->b_cont = NULL;
1820Sstevel@tonic-gate 	/*
1830Sstevel@tonic-gate 	 * set the fields that are common to
1840Sstevel@tonic-gate 	 * to different messages.
1850Sstevel@tonic-gate 	 */
1860Sstevel@tonic-gate 	rtm->rtm_msglen = (short)(header_size + data_size);
1870Sstevel@tonic-gate 	rtm->rtm_version = RTM_VERSION;
1880Sstevel@tonic-gate 	rtm->rtm_type = (uchar_t)type;
1890Sstevel@tonic-gate }
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate /*
1920Sstevel@tonic-gate  * This routine is called to generate a message to the routing
1930Sstevel@tonic-gate  * socket indicating that a redirect has occured, a routing lookup
1940Sstevel@tonic-gate  * has failed, or that a protocol has detected timeouts to a particular
1950Sstevel@tonic-gate  * destination. This routine is called for message types RTM_LOSING,
1960Sstevel@tonic-gate  * RTM_REDIRECT, and RTM_MISS.
1970Sstevel@tonic-gate  */
1980Sstevel@tonic-gate void
1990Sstevel@tonic-gate ip_rts_change_v6(int type, const in6_addr_t *dst_addr,
2000Sstevel@tonic-gate     const in6_addr_t *gw_addr, const in6_addr_t *net_mask,
2010Sstevel@tonic-gate     const in6_addr_t *source, const in6_addr_t *author,
2020Sstevel@tonic-gate     int flags, int error, int rtm_addrs)
2030Sstevel@tonic-gate {
2040Sstevel@tonic-gate 	rt_msghdr_t	*rtm;
2050Sstevel@tonic-gate 	mblk_t		*mp;
2060Sstevel@tonic-gate 
2070Sstevel@tonic-gate 	if (rtm_addrs == 0)
2080Sstevel@tonic-gate 		return;
209*1676Sjpk 	mp = rts_alloc_msg(type, rtm_addrs, AF_INET6, 0);
2100Sstevel@tonic-gate 	if (mp == NULL)
2110Sstevel@tonic-gate 		return;
2120Sstevel@tonic-gate 	rts_fill_msg_v6(type, rtm_addrs, dst_addr, net_mask, gw_addr, source,
213*1676Sjpk 	    &ipv6_all_zeros, author, NULL, mp, 0, NULL);
2140Sstevel@tonic-gate 	rtm = (rt_msghdr_t *)mp->b_rptr;
2150Sstevel@tonic-gate 	rtm->rtm_flags = flags;
2160Sstevel@tonic-gate 	rtm->rtm_errno = error;
2170Sstevel@tonic-gate 	rtm->rtm_flags |= RTF_DONE;
2180Sstevel@tonic-gate 	rtm->rtm_addrs = rtm_addrs;
2190Sstevel@tonic-gate 	rts_queue_input(mp, NULL, AF_INET6);
2200Sstevel@tonic-gate }
221