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