xref: /titanic_41/usr/src/uts/common/inet/ip/ip6_rts.c (revision 70025d765b044c6d8594bb965a2247a61e991a99)
1 /*
2  * Copyright 1992-2002 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*
7  * Copyright (c) 1988, 1991, 1993
8  *	The Regents of the University of California.  All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the University of
21  *	California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *	@(#)rtsock.c	8.6 (Berkeley) 2/11/95
39  */
40 
41 #pragma ident	"%Z%%M%	%I%	%E% SMI"
42 
43 /*
44  * This file contains routines that processes routing socket requests.
45  */
46 
47 #include <sys/types.h>
48 #include <sys/stream.h>
49 #include <sys/stropts.h>
50 #include <sys/strlog.h>
51 #include <sys/dlpi.h>
52 #include <sys/ddi.h>
53 #include <sys/cmn_err.h>
54 #include <sys/debug.h>
55 
56 #include <sys/systm.h>
57 #include <sys/param.h>
58 #include <sys/socket.h>
59 #define	_SUN_TPI_VERSION	2
60 #include <sys/tihdr.h>
61 #include <net/if.h>
62 #include <net/route.h>
63 #include <netinet/in.h>
64 #include <net/if_dl.h>
65 #include <netinet/ip6.h>
66 
67 #include <inet/common.h>
68 #include <inet/mi.h>
69 #include <inet/ip.h>
70 #include <inet/ip6.h>
71 #include <inet/ip_if.h>
72 #include <inet/ip_ire.h>
73 #include <inet/ip_rts.h>
74 #include <inet/ip_multi.h>
75 
76 /*
77  * Fills the message with the given info.
78  */
79 void
80 rts_fill_msg_v6(int type, int rtm_addrs, const in6_addr_t *dst,
81     const in6_addr_t *mask, const in6_addr_t *gateway,
82     const in6_addr_t *src_addr, const in6_addr_t *brd_addr,
83     const in6_addr_t *author, ipif_t *ipif, mblk_t *mp)
84 {
85 	rt_msghdr_t	*rtm;
86 	sin6_t		*sin6;
87 	size_t		data_size, header_size;
88 	uchar_t		*cp;
89 	int		i;
90 
91 	ASSERT(mp != NULL);
92 	/*
93 	 * First find the type of the message
94 	 * and its length.
95 	 */
96 	header_size = rts_header_msg_size(type);
97 	/*
98 	 * Now find the size of the data
99 	 * that follows the message header.
100 	 */
101 	data_size = rts_data_msg_size(rtm_addrs, AF_INET6);
102 
103 	rtm = (rt_msghdr_t *)mp->b_rptr;
104 	mp->b_wptr = &mp->b_rptr[header_size];
105 	cp = mp->b_wptr;
106 	bzero(cp, data_size);
107 	for (i = 0; i < RTA_NUMBITS; i++) {
108 		sin6 = (sin6_t *)cp;
109 		switch (rtm_addrs & (1 << i)) {
110 		case RTA_DST:
111 			sin6->sin6_addr = *dst;
112 			sin6->sin6_family = AF_INET6;
113 			cp += sizeof (sin6_t);
114 			break;
115 		case RTA_GATEWAY:
116 			sin6->sin6_addr = *gateway;
117 			sin6->sin6_family = AF_INET6;
118 			cp += sizeof (sin6_t);
119 			break;
120 		case RTA_NETMASK:
121 			sin6->sin6_addr = *mask;
122 			sin6->sin6_family = AF_INET6;
123 			cp += sizeof (sin6_t);
124 			break;
125 		case RTA_IFA:
126 		case RTA_SRC:
127 			sin6->sin6_addr = *src_addr;
128 			sin6->sin6_family = AF_INET6;
129 			cp += sizeof (sin6_t);
130 			break;
131 		case RTA_IFP:
132 			cp += ill_dls_info((struct sockaddr_dl *)cp, ipif);
133 			break;
134 		case RTA_AUTHOR:
135 			sin6->sin6_addr = *author;
136 			sin6->sin6_family = AF_INET6;
137 			cp += sizeof (sin6_t);
138 			break;
139 		case RTA_BRD:
140 			/*
141 			 * RTA_BRD is used typically to specify a point-to-point
142 			 * destination address.
143 			 */
144 			sin6->sin6_addr = *brd_addr;
145 			sin6->sin6_family = AF_INET6;
146 			cp += sizeof (sin6_t);
147 			break;
148 		}
149 	}
150 	mp->b_wptr = cp;
151 	mp->b_cont = NULL;
152 	/*
153 	 * set the fields that are common to
154 	 * to different messages.
155 	 */
156 	rtm->rtm_msglen = (short)(header_size + data_size);
157 	rtm->rtm_version = RTM_VERSION;
158 	rtm->rtm_type = (uchar_t)type;
159 }
160 
161 /*
162  * This routine is called to generate a message to the routing
163  * socket indicating that a redirect has occured, a routing lookup
164  * has failed, or that a protocol has detected timeouts to a particular
165  * destination. This routine is called for message types RTM_LOSING,
166  * RTM_REDIRECT, and RTM_MISS.
167  */
168 void
169 ip_rts_change_v6(int type, const in6_addr_t *dst_addr,
170     const in6_addr_t *gw_addr, const in6_addr_t *net_mask,
171     const in6_addr_t *source, const in6_addr_t *author,
172     int flags, int error, int rtm_addrs)
173 {
174 	rt_msghdr_t	*rtm;
175 	mblk_t		*mp;
176 
177 	if (rtm_addrs == 0)
178 		return;
179 	mp = rts_alloc_msg(type, rtm_addrs, AF_INET6);
180 	if (mp == NULL)
181 		return;
182 	rts_fill_msg_v6(type, rtm_addrs, dst_addr, net_mask, gw_addr, source,
183 	    &ipv6_all_zeros, author, NULL, mp);
184 	rtm = (rt_msghdr_t *)mp->b_rptr;
185 	rtm->rtm_flags = flags;
186 	rtm->rtm_errno = error;
187 	rtm->rtm_flags |= RTF_DONE;
188 	rtm->rtm_addrs = rtm_addrs;
189 	rts_queue_input(mp, NULL, AF_INET6);
190 }
191