10Sstevel@tonic-gate /*
28485SPeter.Memishian@Sun.COM * Copyright 2009 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 /*
420Sstevel@tonic-gate * This file contains routines that processes routing socket requests.
430Sstevel@tonic-gate */
440Sstevel@tonic-gate
450Sstevel@tonic-gate #include <sys/types.h>
460Sstevel@tonic-gate #include <sys/stream.h>
470Sstevel@tonic-gate #include <sys/stropts.h>
480Sstevel@tonic-gate #include <sys/strlog.h>
490Sstevel@tonic-gate #include <sys/dlpi.h>
500Sstevel@tonic-gate #include <sys/ddi.h>
510Sstevel@tonic-gate #include <sys/cmn_err.h>
520Sstevel@tonic-gate #include <sys/debug.h>
530Sstevel@tonic-gate
540Sstevel@tonic-gate #include <sys/systm.h>
550Sstevel@tonic-gate #include <sys/param.h>
560Sstevel@tonic-gate #include <sys/socket.h>
570Sstevel@tonic-gate #define _SUN_TPI_VERSION 2
580Sstevel@tonic-gate #include <sys/tihdr.h>
590Sstevel@tonic-gate #include <net/if.h>
600Sstevel@tonic-gate #include <net/route.h>
610Sstevel@tonic-gate #include <netinet/in.h>
620Sstevel@tonic-gate #include <net/if_dl.h>
630Sstevel@tonic-gate #include <netinet/ip6.h>
640Sstevel@tonic-gate
650Sstevel@tonic-gate #include <inet/common.h>
660Sstevel@tonic-gate #include <inet/mi.h>
670Sstevel@tonic-gate #include <inet/ip.h>
680Sstevel@tonic-gate #include <inet/ip6.h>
690Sstevel@tonic-gate #include <inet/ip_if.h>
700Sstevel@tonic-gate #include <inet/ip_ire.h>
710Sstevel@tonic-gate #include <inet/ip_rts.h>
720Sstevel@tonic-gate #include <inet/ip_multi.h>
731676Sjpk #include <sys/tsol/tndb.h>
741676Sjpk #include <sys/tsol/tnet.h>
750Sstevel@tonic-gate
760Sstevel@tonic-gate /*
770Sstevel@tonic-gate * Fills the message with the given info.
780Sstevel@tonic-gate */
790Sstevel@tonic-gate void
rts_fill_msg_v6(int type,int rtm_addrs,const in6_addr_t * dst,const in6_addr_t * mask,const in6_addr_t * gateway,const in6_addr_t * src_addr,const in6_addr_t * brd_addr,const in6_addr_t * author,const in6_addr_t * ifaddr,const ill_t * ill,mblk_t * mp,const tsol_gc_t * gc)800Sstevel@tonic-gate rts_fill_msg_v6(int type, int rtm_addrs, const in6_addr_t *dst,
810Sstevel@tonic-gate const in6_addr_t *mask, const in6_addr_t *gateway,
820Sstevel@tonic-gate const in6_addr_t *src_addr, const in6_addr_t *brd_addr,
83*11042SErik.Nordmark@Sun.COM const in6_addr_t *author, const in6_addr_t *ifaddr, const ill_t *ill,
84*11042SErik.Nordmark@Sun.COM mblk_t *mp, const tsol_gc_t *gc)
850Sstevel@tonic-gate {
860Sstevel@tonic-gate rt_msghdr_t *rtm;
870Sstevel@tonic-gate sin6_t *sin6;
880Sstevel@tonic-gate size_t data_size, header_size;
890Sstevel@tonic-gate uchar_t *cp;
900Sstevel@tonic-gate int i;
910Sstevel@tonic-gate
920Sstevel@tonic-gate ASSERT(mp != NULL);
930Sstevel@tonic-gate /*
940Sstevel@tonic-gate * First find the type of the message
950Sstevel@tonic-gate * and its length.
960Sstevel@tonic-gate */
970Sstevel@tonic-gate header_size = rts_header_msg_size(type);
980Sstevel@tonic-gate /*
990Sstevel@tonic-gate * Now find the size of the data
1000Sstevel@tonic-gate * that follows the message header.
1010Sstevel@tonic-gate */
102*11042SErik.Nordmark@Sun.COM data_size = rts_data_msg_size(rtm_addrs, AF_INET6, gc != NULL ? 1 : 0);
1030Sstevel@tonic-gate
1040Sstevel@tonic-gate rtm = (rt_msghdr_t *)mp->b_rptr;
1050Sstevel@tonic-gate mp->b_wptr = &mp->b_rptr[header_size];
1060Sstevel@tonic-gate cp = mp->b_wptr;
1070Sstevel@tonic-gate bzero(cp, data_size);
1080Sstevel@tonic-gate for (i = 0; i < RTA_NUMBITS; i++) {
1090Sstevel@tonic-gate sin6 = (sin6_t *)cp;
1100Sstevel@tonic-gate switch (rtm_addrs & (1 << i)) {
1110Sstevel@tonic-gate case RTA_DST:
1120Sstevel@tonic-gate sin6->sin6_addr = *dst;
1130Sstevel@tonic-gate sin6->sin6_family = AF_INET6;
1140Sstevel@tonic-gate cp += sizeof (sin6_t);
1150Sstevel@tonic-gate break;
1160Sstevel@tonic-gate case RTA_GATEWAY:
1170Sstevel@tonic-gate sin6->sin6_addr = *gateway;
1180Sstevel@tonic-gate sin6->sin6_family = AF_INET6;
1190Sstevel@tonic-gate cp += sizeof (sin6_t);
1200Sstevel@tonic-gate break;
1210Sstevel@tonic-gate case RTA_NETMASK:
1220Sstevel@tonic-gate sin6->sin6_addr = *mask;
1230Sstevel@tonic-gate sin6->sin6_family = AF_INET6;
1240Sstevel@tonic-gate cp += sizeof (sin6_t);
1250Sstevel@tonic-gate break;
1260Sstevel@tonic-gate case RTA_IFA:
127*11042SErik.Nordmark@Sun.COM sin6->sin6_addr = *ifaddr;
128*11042SErik.Nordmark@Sun.COM sin6->sin6_family = AF_INET6;
129*11042SErik.Nordmark@Sun.COM cp += sizeof (sin6_t);
130*11042SErik.Nordmark@Sun.COM break;
1310Sstevel@tonic-gate case RTA_SRC:
1320Sstevel@tonic-gate sin6->sin6_addr = *src_addr;
1330Sstevel@tonic-gate sin6->sin6_family = AF_INET6;
1340Sstevel@tonic-gate cp += sizeof (sin6_t);
1350Sstevel@tonic-gate break;
1360Sstevel@tonic-gate case RTA_IFP:
137*11042SErik.Nordmark@Sun.COM cp += ill_dls_info((struct sockaddr_dl *)cp, ill);
1380Sstevel@tonic-gate break;
1390Sstevel@tonic-gate case RTA_AUTHOR:
1400Sstevel@tonic-gate sin6->sin6_addr = *author;
1410Sstevel@tonic-gate sin6->sin6_family = AF_INET6;
1420Sstevel@tonic-gate cp += sizeof (sin6_t);
1430Sstevel@tonic-gate break;
1440Sstevel@tonic-gate case RTA_BRD:
1450Sstevel@tonic-gate /*
1460Sstevel@tonic-gate * RTA_BRD is used typically to specify a point-to-point
1470Sstevel@tonic-gate * destination address.
1480Sstevel@tonic-gate */
1490Sstevel@tonic-gate sin6->sin6_addr = *brd_addr;
1500Sstevel@tonic-gate sin6->sin6_family = AF_INET6;
1510Sstevel@tonic-gate cp += sizeof (sin6_t);
1520Sstevel@tonic-gate break;
1530Sstevel@tonic-gate }
1540Sstevel@tonic-gate }
1551676Sjpk
1561676Sjpk if (gc != NULL) {
1571676Sjpk rtm_ext_t *rtm_ext;
1581676Sjpk struct rtsa_s *rp_dst;
1591676Sjpk tsol_rtsecattr_t *rsap;
1601676Sjpk
1611676Sjpk ASSERT(gc->gc_grp != NULL);
1621676Sjpk ASSERT(RW_LOCK_HELD(&gc->gc_grp->gcgrp_rwlock));
1631676Sjpk
1641676Sjpk rtm_ext = (rtm_ext_t *)cp;
1651676Sjpk rtm_ext->rtmex_type = RTMEX_GATEWAY_SECATTR;
166*11042SErik.Nordmark@Sun.COM rtm_ext->rtmex_len = TSOL_RTSECATTR_SIZE(1);
1671676Sjpk
1681676Sjpk rsap = (tsol_rtsecattr_t *)(rtm_ext + 1);
169*11042SErik.Nordmark@Sun.COM rsap->rtsa_cnt = 1;
1701676Sjpk rp_dst = rsap->rtsa_attr;
1711676Sjpk
172*11042SErik.Nordmark@Sun.COM ASSERT(gc->gc_db != NULL);
173*11042SErik.Nordmark@Sun.COM bcopy(&gc->gc_db->gcdb_attr, rp_dst, sizeof (*rp_dst));
1741676Sjpk cp = (uchar_t *)rp_dst;
1751676Sjpk }
1761676Sjpk
1770Sstevel@tonic-gate mp->b_wptr = cp;
1780Sstevel@tonic-gate mp->b_cont = NULL;
1790Sstevel@tonic-gate /*
1800Sstevel@tonic-gate * set the fields that are common to
1810Sstevel@tonic-gate * to different messages.
1820Sstevel@tonic-gate */
1830Sstevel@tonic-gate rtm->rtm_msglen = (short)(header_size + data_size);
1840Sstevel@tonic-gate rtm->rtm_version = RTM_VERSION;
1850Sstevel@tonic-gate rtm->rtm_type = (uchar_t)type;
1860Sstevel@tonic-gate }
1870Sstevel@tonic-gate
1880Sstevel@tonic-gate /*
1890Sstevel@tonic-gate * This routine is called to generate a message to the routing
1900Sstevel@tonic-gate * socket indicating that a redirect has occured, a routing lookup
1910Sstevel@tonic-gate * has failed, or that a protocol has detected timeouts to a particular
1920Sstevel@tonic-gate * destination. This routine is called for message types RTM_LOSING,
1930Sstevel@tonic-gate * RTM_REDIRECT, and RTM_MISS.
1940Sstevel@tonic-gate */
1950Sstevel@tonic-gate void
ip_rts_change_v6(int type,const in6_addr_t * dst_addr,const in6_addr_t * gw_addr,const in6_addr_t * net_mask,const in6_addr_t * source,const in6_addr_t * author,int flags,int error,int rtm_addrs,ip_stack_t * ipst)1960Sstevel@tonic-gate ip_rts_change_v6(int type, const in6_addr_t *dst_addr,
1970Sstevel@tonic-gate const in6_addr_t *gw_addr, const in6_addr_t *net_mask,
1980Sstevel@tonic-gate const in6_addr_t *source, const in6_addr_t *author,
1993448Sdh155122 int flags, int error, int rtm_addrs, ip_stack_t *ipst)
2000Sstevel@tonic-gate {
2010Sstevel@tonic-gate rt_msghdr_t *rtm;
2020Sstevel@tonic-gate mblk_t *mp;
2030Sstevel@tonic-gate
2040Sstevel@tonic-gate if (rtm_addrs == 0)
2050Sstevel@tonic-gate return;
2061676Sjpk mp = rts_alloc_msg(type, rtm_addrs, AF_INET6, 0);
2070Sstevel@tonic-gate if (mp == NULL)
2080Sstevel@tonic-gate return;
2090Sstevel@tonic-gate rts_fill_msg_v6(type, rtm_addrs, dst_addr, net_mask, gw_addr, source,
210*11042SErik.Nordmark@Sun.COM &ipv6_all_zeros, &ipv6_all_zeros, author, NULL, mp, NULL);
2110Sstevel@tonic-gate rtm = (rt_msghdr_t *)mp->b_rptr;
2120Sstevel@tonic-gate rtm->rtm_flags = flags;
2130Sstevel@tonic-gate rtm->rtm_errno = error;
2140Sstevel@tonic-gate rtm->rtm_flags |= RTF_DONE;
2150Sstevel@tonic-gate rtm->rtm_addrs = rtm_addrs;
2168485SPeter.Memishian@Sun.COM rts_queue_input(mp, NULL, AF_INET6, RTSQ_ALL, ipst);
2170Sstevel@tonic-gate }
218