10Sstevel@tonic-gate /* 21676Sjpk * 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/ddi.h> 510Sstevel@tonic-gate #include <sys/cmn_err.h> 520Sstevel@tonic-gate #include <sys/debug.h> 530Sstevel@tonic-gate #include <sys/policy.h> 540Sstevel@tonic-gate #include <sys/zone.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 #include <sys/strsun.h> 600Sstevel@tonic-gate #include <net/if.h> 610Sstevel@tonic-gate #include <net/route.h> 620Sstevel@tonic-gate #include <netinet/in.h> 630Sstevel@tonic-gate #include <net/if_dl.h> 640Sstevel@tonic-gate #include <netinet/ip6.h> 650Sstevel@tonic-gate 660Sstevel@tonic-gate #include <inet/common.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> 712535Ssangeeta #include <inet/ip_ftable.h> 720Sstevel@tonic-gate #include <inet/ip_rts.h> 730Sstevel@tonic-gate 740Sstevel@tonic-gate #include <inet/ipclassifier.h> 750Sstevel@tonic-gate 761676Sjpk #include <sys/tsol/tndb.h> 771676Sjpk #include <sys/tsol/tnet.h> 781676Sjpk 791676Sjpk #define RTS_MSG_SIZE(type, rtm_addrs, af, sacnt) \ 801676Sjpk (rts_data_msg_size(rtm_addrs, af, sacnt) + rts_header_msg_size(type)) 810Sstevel@tonic-gate 820Sstevel@tonic-gate static size_t rts_copyfromsockaddr(struct sockaddr *sa, in6_addr_t *addrp); 830Sstevel@tonic-gate static void rts_fill_msg(int type, int rtm_addrs, ipaddr_t dst, 840Sstevel@tonic-gate ipaddr_t mask, ipaddr_t gateway, ipaddr_t src_addr, ipaddr_t brd_addr, 851676Sjpk ipaddr_t author, const ipif_t *ipif, mblk_t *mp, uint_t, const tsol_gc_t *); 860Sstevel@tonic-gate static int rts_getaddrs(rt_msghdr_t *rtm, in6_addr_t *dst_addrp, 870Sstevel@tonic-gate in6_addr_t *gw_addrp, in6_addr_t *net_maskp, in6_addr_t *authorp, 880Sstevel@tonic-gate in6_addr_t *if_addrp, in6_addr_t *src_addrp, ushort_t *indexp, 891676Sjpk ushort_t *src_indexp, sa_family_t *afp, tsol_rtsecattr_t *rtsecattr, 901676Sjpk int *error); 911676Sjpk static void rts_getifdata(if_data_t *if_data, const ipif_t *ipif); 920Sstevel@tonic-gate static int rts_getmetrics(ire_t *ire, rt_metrics_t *metrics); 930Sstevel@tonic-gate static mblk_t *rts_rtmget(mblk_t *mp, ire_t *ire, ire_t *sire, 940Sstevel@tonic-gate sa_family_t af); 950Sstevel@tonic-gate static void rts_setmetrics(ire_t *ire, uint_t which, rt_metrics_t *metrics); 960Sstevel@tonic-gate static void ip_rts_request_retry(ipsq_t *, queue_t *q, mblk_t *mp, void *); 970Sstevel@tonic-gate 980Sstevel@tonic-gate /* 990Sstevel@tonic-gate * Send the ack to all the routing queues. In case of the originating queue, 1000Sstevel@tonic-gate * send it only if the loopback is set. 1010Sstevel@tonic-gate * 1020Sstevel@tonic-gate * Messages are sent upstream only on routing sockets that did not specify an 1030Sstevel@tonic-gate * address family when they were created or when the address family matches the 1040Sstevel@tonic-gate * one specified by the caller. 1050Sstevel@tonic-gate * 1060Sstevel@tonic-gate */ 1070Sstevel@tonic-gate void 1080Sstevel@tonic-gate rts_queue_input(mblk_t *mp, queue_t *q, sa_family_t af) 1090Sstevel@tonic-gate { 1100Sstevel@tonic-gate mblk_t *mp1; 1110Sstevel@tonic-gate int checkqfull; 1120Sstevel@tonic-gate conn_t *connp, *next_connp; 1130Sstevel@tonic-gate 1140Sstevel@tonic-gate mutex_enter(&rts_clients.connf_lock); 1150Sstevel@tonic-gate connp = rts_clients.connf_head; 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate while (connp != NULL) { 1180Sstevel@tonic-gate /* 1190Sstevel@tonic-gate * If there was a family specified when this routing socket was 1200Sstevel@tonic-gate * created and it doesn't match the family of the message to 1210Sstevel@tonic-gate * copy, then continue. 1220Sstevel@tonic-gate */ 1230Sstevel@tonic-gate if ((connp->conn_proto != AF_UNSPEC) && 1240Sstevel@tonic-gate (connp->conn_proto != af)) { 1250Sstevel@tonic-gate connp = connp->conn_next; 1260Sstevel@tonic-gate continue; 1270Sstevel@tonic-gate } 1280Sstevel@tonic-gate /* 1290Sstevel@tonic-gate * For the originating queue, we only copy the message upstream 1300Sstevel@tonic-gate * if loopback is set. For others reading on the routing 1310Sstevel@tonic-gate * socket, we check if there is room upstream for a copy of the 1320Sstevel@tonic-gate * message. 1330Sstevel@tonic-gate */ 1340Sstevel@tonic-gate if ((q != NULL) && (CONNP_TO_RQ(connp) == RD(q))) { 1350Sstevel@tonic-gate if (connp->conn_loopback == 0) { 1360Sstevel@tonic-gate connp = connp->conn_next; 1370Sstevel@tonic-gate continue; 1380Sstevel@tonic-gate } 1390Sstevel@tonic-gate checkqfull = B_FALSE; 1400Sstevel@tonic-gate } else { 1410Sstevel@tonic-gate checkqfull = B_TRUE; 1420Sstevel@tonic-gate } 1430Sstevel@tonic-gate CONN_INC_REF(connp); 1440Sstevel@tonic-gate mutex_exit(&rts_clients.connf_lock); 1450Sstevel@tonic-gate if (!checkqfull || canputnext(CONNP_TO_RQ(connp))) { 1460Sstevel@tonic-gate mp1 = dupmsg(mp); 1470Sstevel@tonic-gate if (mp1 == NULL) 1480Sstevel@tonic-gate mp1 = copymsg(mp); 1490Sstevel@tonic-gate if (mp1 != NULL) 1500Sstevel@tonic-gate putnext(CONNP_TO_RQ(connp), mp1); 1510Sstevel@tonic-gate } 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate mutex_enter(&rts_clients.connf_lock); 1540Sstevel@tonic-gate /* Follow the next pointer before releasing the conn. */ 1550Sstevel@tonic-gate next_connp = connp->conn_next; 1560Sstevel@tonic-gate CONN_DEC_REF(connp); 1570Sstevel@tonic-gate connp = next_connp; 1580Sstevel@tonic-gate } 1590Sstevel@tonic-gate mutex_exit(&rts_clients.connf_lock); 1600Sstevel@tonic-gate freemsg(mp); 1610Sstevel@tonic-gate } 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate /* 1640Sstevel@tonic-gate * Takes an ire and sends an ack to all the routing sockets. This 1650Sstevel@tonic-gate * routine is used 1660Sstevel@tonic-gate * - when a route is created/deleted through the ioctl interface. 1670Sstevel@tonic-gate * - when ire_expire deletes a stale redirect 1680Sstevel@tonic-gate */ 1690Sstevel@tonic-gate void 1700Sstevel@tonic-gate ip_rts_rtmsg(int type, ire_t *ire, int error) 1710Sstevel@tonic-gate { 1720Sstevel@tonic-gate mblk_t *mp; 1730Sstevel@tonic-gate rt_msghdr_t *rtm; 1740Sstevel@tonic-gate int rtm_addrs = (RTA_DST | RTA_NETMASK | RTA_GATEWAY); 1750Sstevel@tonic-gate sa_family_t af; 1760Sstevel@tonic-gate in6_addr_t gw_addr_v6; 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate if (ire == NULL) 1790Sstevel@tonic-gate return; 1800Sstevel@tonic-gate ASSERT(ire->ire_ipversion == IPV4_VERSION || 1810Sstevel@tonic-gate ire->ire_ipversion == IPV6_VERSION); 1820Sstevel@tonic-gate 1830Sstevel@tonic-gate if (ire->ire_flags & RTF_SETSRC) 1840Sstevel@tonic-gate rtm_addrs |= RTA_SRC; 1850Sstevel@tonic-gate 1860Sstevel@tonic-gate switch (ire->ire_ipversion) { 1870Sstevel@tonic-gate case IPV4_VERSION: 1880Sstevel@tonic-gate af = AF_INET; 1891676Sjpk mp = rts_alloc_msg(type, rtm_addrs, af, 0); 1900Sstevel@tonic-gate if (mp == NULL) 1910Sstevel@tonic-gate return; 1920Sstevel@tonic-gate rts_fill_msg(type, rtm_addrs, ire->ire_addr, ire->ire_mask, 1931676Sjpk ire->ire_gateway_addr, ire->ire_src_addr, 0, 0, NULL, mp, 1941676Sjpk 0, NULL); 1950Sstevel@tonic-gate break; 1960Sstevel@tonic-gate case IPV6_VERSION: 1970Sstevel@tonic-gate af = AF_INET6; 1981676Sjpk mp = rts_alloc_msg(type, rtm_addrs, af, 0); 1990Sstevel@tonic-gate if (mp == NULL) 2000Sstevel@tonic-gate return; 2010Sstevel@tonic-gate mutex_enter(&ire->ire_lock); 2020Sstevel@tonic-gate gw_addr_v6 = ire->ire_gateway_addr_v6; 2030Sstevel@tonic-gate mutex_exit(&ire->ire_lock); 2040Sstevel@tonic-gate rts_fill_msg_v6(type, rtm_addrs, &ire->ire_addr_v6, 2050Sstevel@tonic-gate &ire->ire_mask_v6, &gw_addr_v6, 2060Sstevel@tonic-gate &ire->ire_src_addr_v6, &ipv6_all_zeros, &ipv6_all_zeros, 2071676Sjpk NULL, mp, 0, NULL); 2080Sstevel@tonic-gate break; 2090Sstevel@tonic-gate } 2100Sstevel@tonic-gate rtm = (rt_msghdr_t *)mp->b_rptr; 2110Sstevel@tonic-gate mp->b_wptr = (uchar_t *)&mp->b_rptr[rtm->rtm_msglen]; 2120Sstevel@tonic-gate rtm->rtm_addrs = rtm_addrs; 2130Sstevel@tonic-gate rtm->rtm_flags = ire->ire_flags; 2140Sstevel@tonic-gate if (error != 0) 2150Sstevel@tonic-gate rtm->rtm_errno = error; 2160Sstevel@tonic-gate else 2170Sstevel@tonic-gate rtm->rtm_flags |= RTF_DONE; 2180Sstevel@tonic-gate rts_queue_input(mp, NULL, af); 2190Sstevel@tonic-gate } 2200Sstevel@tonic-gate 2210Sstevel@tonic-gate /* ARGSUSED */ 2220Sstevel@tonic-gate static void 2230Sstevel@tonic-gate ip_rts_request_retry(ipsq_t *dummy_sq, queue_t *q, mblk_t *mp, void *dummy) 2240Sstevel@tonic-gate { 2250Sstevel@tonic-gate (void) ip_rts_request(q, mp, DB_CRED(mp)); 2260Sstevel@tonic-gate } 2270Sstevel@tonic-gate 2280Sstevel@tonic-gate /* 2290Sstevel@tonic-gate * Processes requests received on a routing socket. It extracts all the 2300Sstevel@tonic-gate * arguments and calls the appropriate function to process the request. 2310Sstevel@tonic-gate * 2320Sstevel@tonic-gate * RTA_SRC bit flag requests are sent by mipagent and 'route -setsrc'. 2330Sstevel@tonic-gate * RTA_SRCIFP bit flag requests are sent by mipagent only. 2340Sstevel@tonic-gate * 2350Sstevel@tonic-gate * In general, this function does not consume the message supplied but rather 2360Sstevel@tonic-gate * sends the message upstream with an appropriate UNIX errno. 2370Sstevel@tonic-gate * 2380Sstevel@tonic-gate * We may need to restart this operation if the ipif cannot be looked up 2390Sstevel@tonic-gate * due to an exclusive operation that is currently in progress. The restart 2400Sstevel@tonic-gate * entry point is ip_rts_request_retry. While the request is enqueud in the 2410Sstevel@tonic-gate * ipsq the ioctl could be aborted and the conn close. To ensure that we don't 2420Sstevel@tonic-gate * have stale conn pointers, ip_wput_ioctl does a conn refhold. This is 2430Sstevel@tonic-gate * released at the completion of the rts ioctl at the end of this function 2440Sstevel@tonic-gate * by calling CONN_OPER_PENDING_DONE or when the ioctl is aborted and 2450Sstevel@tonic-gate * conn close occurs in conn_ioctl_cleanup. 2460Sstevel@tonic-gate */ 2470Sstevel@tonic-gate int 2480Sstevel@tonic-gate ip_rts_request(queue_t *q, mblk_t *mp, cred_t *ioc_cr) 2490Sstevel@tonic-gate { 2500Sstevel@tonic-gate rt_msghdr_t *rtm = NULL; 2510Sstevel@tonic-gate in6_addr_t dst_addr_v6; 2520Sstevel@tonic-gate in6_addr_t src_addr_v6; 2530Sstevel@tonic-gate in6_addr_t gw_addr_v6; 2540Sstevel@tonic-gate in6_addr_t net_mask_v6; 2550Sstevel@tonic-gate in6_addr_t author_v6; 2560Sstevel@tonic-gate in6_addr_t if_addr_v6; 2570Sstevel@tonic-gate mblk_t *mp1, *ioc_mp = mp; 2580Sstevel@tonic-gate ire_t *ire = NULL; 2590Sstevel@tonic-gate ire_t *sire = NULL; 2600Sstevel@tonic-gate int error = 0; 2610Sstevel@tonic-gate int match_flags = MATCH_IRE_DSTONLY; 2622304Swy83408 int match_flags_local = MATCH_IRE_TYPE | MATCH_IRE_GW; 2630Sstevel@tonic-gate int found_addrs; 2640Sstevel@tonic-gate sa_family_t af; 2650Sstevel@tonic-gate ipaddr_t dst_addr; 2660Sstevel@tonic-gate ipaddr_t gw_addr; 2670Sstevel@tonic-gate ipaddr_t src_addr; 2680Sstevel@tonic-gate ipaddr_t net_mask; 2690Sstevel@tonic-gate ushort_t index; 2700Sstevel@tonic-gate ushort_t src_index; 2710Sstevel@tonic-gate ipif_t *ipif = NULL; 2720Sstevel@tonic-gate ipif_t *src_ipif = NULL; 2730Sstevel@tonic-gate ipif_t *tmp_ipif = NULL; 2740Sstevel@tonic-gate IOCP iocp = (IOCP)mp->b_rptr; 2750Sstevel@tonic-gate conn_t *connp; 2761676Sjpk boolean_t gcgrp_xtraref = B_FALSE; 2771676Sjpk tsol_gcgrp_addr_t ga; 2781676Sjpk tsol_rtsecattr_t rtsecattr; 2791676Sjpk struct rtsa_s *rtsap = NULL; 2801676Sjpk tsol_gcgrp_t *gcgrp = NULL; 2811676Sjpk tsol_gc_t *gc = NULL; 282*2601Swy83408 ts_label_t *tsl = NULL; 2830Sstevel@tonic-gate 2840Sstevel@tonic-gate ip1dbg(("ip_rts_request: mp is %x\n", DB_TYPE(mp))); 2850Sstevel@tonic-gate 2860Sstevel@tonic-gate ASSERT(CONN_Q(q)); 2870Sstevel@tonic-gate connp = Q_TO_CONN(q); 2880Sstevel@tonic-gate 2890Sstevel@tonic-gate ASSERT(mp->b_cont != NULL); 2900Sstevel@tonic-gate /* ioc_mp holds mp */ 2910Sstevel@tonic-gate mp = mp->b_cont; 2920Sstevel@tonic-gate 2930Sstevel@tonic-gate /* 2940Sstevel@tonic-gate * The Routing Socket data starts on 2950Sstevel@tonic-gate * next block. If there is no next block 2960Sstevel@tonic-gate * this is an indication from routing module 2970Sstevel@tonic-gate * that it is a routing socket stream queue. 2980Sstevel@tonic-gate */ 2990Sstevel@tonic-gate if (mp->b_cont != NULL) { 3000Sstevel@tonic-gate mp1 = dupmsg(mp->b_cont); 3010Sstevel@tonic-gate if (mp1 == NULL) { 3020Sstevel@tonic-gate freemsg(mp); 3030Sstevel@tonic-gate error = ENOBUFS; 3040Sstevel@tonic-gate goto done; 3050Sstevel@tonic-gate } 3060Sstevel@tonic-gate mp = mp1; 3070Sstevel@tonic-gate } else { 3080Sstevel@tonic-gate /* 3090Sstevel@tonic-gate * This is a message from RTS module 3100Sstevel@tonic-gate * indicating that this is a Routing Socket 3110Sstevel@tonic-gate * Stream. Insert this conn_t in routing 3120Sstevel@tonic-gate * socket client list. 3130Sstevel@tonic-gate */ 3140Sstevel@tonic-gate 3150Sstevel@tonic-gate connp->conn_loopback = 1; 3160Sstevel@tonic-gate ipcl_hash_insert_wildcard(&rts_clients, connp); 3170Sstevel@tonic-gate 3180Sstevel@tonic-gate goto done; 3190Sstevel@tonic-gate } 3200Sstevel@tonic-gate if (mp->b_cont != NULL && !pullupmsg(mp, -1)) { 3210Sstevel@tonic-gate freemsg(mp); 3220Sstevel@tonic-gate error = EINVAL; 3230Sstevel@tonic-gate goto done; 3240Sstevel@tonic-gate } 3250Sstevel@tonic-gate if ((mp->b_wptr - mp->b_rptr) < sizeof (rt_msghdr_t)) { 3260Sstevel@tonic-gate freemsg(mp); 3270Sstevel@tonic-gate error = EINVAL; 3280Sstevel@tonic-gate goto done; 3290Sstevel@tonic-gate } 3300Sstevel@tonic-gate 3310Sstevel@tonic-gate /* 3320Sstevel@tonic-gate * Check the routing message for basic consistency including the 3330Sstevel@tonic-gate * version number and that the number of octets written is the same 3340Sstevel@tonic-gate * as specified by the rtm_msglen field. 3350Sstevel@tonic-gate * 3360Sstevel@tonic-gate * At this point, an error can be delivered back via rtm_errno. 3370Sstevel@tonic-gate */ 3380Sstevel@tonic-gate rtm = (rt_msghdr_t *)mp->b_rptr; 3390Sstevel@tonic-gate if ((mp->b_wptr - mp->b_rptr) != rtm->rtm_msglen) { 3400Sstevel@tonic-gate error = EINVAL; 3410Sstevel@tonic-gate goto done; 3420Sstevel@tonic-gate } 3430Sstevel@tonic-gate if (rtm->rtm_version != RTM_VERSION) { 3440Sstevel@tonic-gate error = EPROTONOSUPPORT; 3450Sstevel@tonic-gate goto done; 3460Sstevel@tonic-gate } 3470Sstevel@tonic-gate 3480Sstevel@tonic-gate /* Only allow RTM_GET or RTM_RESOLVE for unprivileged process */ 3490Sstevel@tonic-gate if (rtm->rtm_type != RTM_GET && 3500Sstevel@tonic-gate rtm->rtm_type != RTM_RESOLVE && 3510Sstevel@tonic-gate (ioc_cr == NULL || 3520Sstevel@tonic-gate secpolicy_net_config(ioc_cr, B_FALSE) != 0)) { 3530Sstevel@tonic-gate error = EPERM; 3540Sstevel@tonic-gate goto done; 3550Sstevel@tonic-gate } 3560Sstevel@tonic-gate 3570Sstevel@tonic-gate found_addrs = rts_getaddrs(rtm, &dst_addr_v6, &gw_addr_v6, &net_mask_v6, 3581676Sjpk &author_v6, &if_addr_v6, &src_addr_v6, &index, &src_index, &af, 3591676Sjpk &rtsecattr, &error); 3601676Sjpk 3611676Sjpk if (error != 0) 3621676Sjpk goto done; 3631676Sjpk 3640Sstevel@tonic-gate if ((found_addrs & RTA_DST) == 0) { 3650Sstevel@tonic-gate error = EINVAL; 3660Sstevel@tonic-gate goto done; 3670Sstevel@tonic-gate } 3680Sstevel@tonic-gate 3690Sstevel@tonic-gate /* 3700Sstevel@tonic-gate * Based on the address family of the destination address, determine 3710Sstevel@tonic-gate * the destination, gateway and netmask and return the appropriate error 3720Sstevel@tonic-gate * if an unknown address family was specified (following the errno 3730Sstevel@tonic-gate * values that 4.4BSD-Lite2 returns.) 3740Sstevel@tonic-gate */ 3750Sstevel@tonic-gate switch (af) { 3760Sstevel@tonic-gate case AF_INET: 3770Sstevel@tonic-gate /* 3780Sstevel@tonic-gate * RTA_SRCIFP is supported for interface route only. 3790Sstevel@tonic-gate * Thus a gateway route with srcifindex is rejected, 3800Sstevel@tonic-gate * except if it's a request to add reverse tunnel 3810Sstevel@tonic-gate * route. 3820Sstevel@tonic-gate */ 3830Sstevel@tonic-gate if ((rtm->rtm_flags & RTF_GATEWAY) && 3840Sstevel@tonic-gate (found_addrs & RTA_SRCIFP) && 3850Sstevel@tonic-gate !(found_addrs & RTA_SRC)) { 3860Sstevel@tonic-gate error = EINVAL; 3870Sstevel@tonic-gate goto done; 3880Sstevel@tonic-gate } 3890Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&dst_addr_v6, dst_addr); 3900Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&src_addr_v6, src_addr); 3910Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&gw_addr_v6, gw_addr); 3920Sstevel@tonic-gate if (((found_addrs & RTA_NETMASK) == 0) || 3930Sstevel@tonic-gate (rtm->rtm_flags & RTF_HOST)) 3940Sstevel@tonic-gate net_mask = IP_HOST_MASK; 3950Sstevel@tonic-gate else 3960Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&net_mask_v6, net_mask); 3970Sstevel@tonic-gate break; 3980Sstevel@tonic-gate case AF_INET6: 3990Sstevel@tonic-gate /* 4000Sstevel@tonic-gate * RTA_SRCIFP is not a valid flag for IPv6 routes. 4010Sstevel@tonic-gate */ 4020Sstevel@tonic-gate if (found_addrs & RTA_SRCIFP) { 4030Sstevel@tonic-gate error = EINVAL; 4040Sstevel@tonic-gate goto done; 4050Sstevel@tonic-gate } 4060Sstevel@tonic-gate if (((found_addrs & RTA_NETMASK) == 0) || 4070Sstevel@tonic-gate (rtm->rtm_flags & RTF_HOST)) 4080Sstevel@tonic-gate net_mask_v6 = ipv6_all_ones; 4090Sstevel@tonic-gate break; 4100Sstevel@tonic-gate default: 4110Sstevel@tonic-gate /* 4120Sstevel@tonic-gate * These errno values are meant to be compatible with 4130Sstevel@tonic-gate * 4.4BSD-Lite2 for the given message types. 4140Sstevel@tonic-gate */ 4150Sstevel@tonic-gate switch (rtm->rtm_type) { 4160Sstevel@tonic-gate case RTM_ADD: 4170Sstevel@tonic-gate case RTM_DELETE: 4180Sstevel@tonic-gate error = ESRCH; 4190Sstevel@tonic-gate goto done; 4200Sstevel@tonic-gate case RTM_GET: 4210Sstevel@tonic-gate case RTM_CHANGE: 4220Sstevel@tonic-gate error = EAFNOSUPPORT; 4230Sstevel@tonic-gate goto done; 4240Sstevel@tonic-gate default: 4250Sstevel@tonic-gate error = EOPNOTSUPP; 4260Sstevel@tonic-gate goto done; 4270Sstevel@tonic-gate } 4280Sstevel@tonic-gate } 4290Sstevel@tonic-gate 4300Sstevel@tonic-gate /* 4310Sstevel@tonic-gate * At this point, the address family must be something known. 4320Sstevel@tonic-gate */ 4330Sstevel@tonic-gate ASSERT(af == AF_INET || af == AF_INET6); 4340Sstevel@tonic-gate 4350Sstevel@tonic-gate if (index != 0) { 4360Sstevel@tonic-gate ill_t *ill; 4370Sstevel@tonic-gate 4380Sstevel@tonic-gate /* 4390Sstevel@tonic-gate * IPC must be refheld somewhere in ip_wput_nondata or 4400Sstevel@tonic-gate * ip_wput_ioctl etc... and cleaned up if ioctl is killed. 4410Sstevel@tonic-gate * If ILL_CHANGING the request is queued in the ipsq. 4420Sstevel@tonic-gate */ 4430Sstevel@tonic-gate ill = ill_lookup_on_ifindex(index, af == AF_INET6, 4440Sstevel@tonic-gate CONNP_TO_WQ(connp), ioc_mp, ip_rts_request_retry, &error); 4450Sstevel@tonic-gate if (ill == NULL) { 4460Sstevel@tonic-gate if (error != EINPROGRESS) 4470Sstevel@tonic-gate error = EINVAL; 4480Sstevel@tonic-gate goto done; 4490Sstevel@tonic-gate } 4500Sstevel@tonic-gate 4510Sstevel@tonic-gate ipif = ipif_get_next_ipif(NULL, ill); 4520Sstevel@tonic-gate ill_refrele(ill); 4530Sstevel@tonic-gate /* 4540Sstevel@tonic-gate * If this is replacement ipif, prevent a route from 4550Sstevel@tonic-gate * being added. 4560Sstevel@tonic-gate */ 4570Sstevel@tonic-gate if (ipif != NULL && ipif->ipif_replace_zero) { 4580Sstevel@tonic-gate error = ENETDOWN; 4590Sstevel@tonic-gate goto done; 4600Sstevel@tonic-gate } 4610Sstevel@tonic-gate match_flags |= MATCH_IRE_ILL; 4620Sstevel@tonic-gate } 4630Sstevel@tonic-gate 4640Sstevel@tonic-gate /* RTA_SRCIFP is unsupported on AF_INET6. */ 4650Sstevel@tonic-gate if (af == AF_INET && src_index != 0) { 4660Sstevel@tonic-gate ill_t *ill; 4670Sstevel@tonic-gate 4680Sstevel@tonic-gate /* If ILL_CHANGING the request is queued in the ipsq. */ 4690Sstevel@tonic-gate ill = ill_lookup_on_ifindex(src_index, B_FALSE, 4700Sstevel@tonic-gate CONNP_TO_WQ(connp), ioc_mp, ip_rts_request_retry, &error); 4710Sstevel@tonic-gate if (ill == NULL) { 4720Sstevel@tonic-gate if (error != EINPROGRESS) 4730Sstevel@tonic-gate error = EINVAL; 4740Sstevel@tonic-gate goto done; 4750Sstevel@tonic-gate } 4760Sstevel@tonic-gate 4770Sstevel@tonic-gate src_ipif = ipif_get_next_ipif(NULL, ill); 4780Sstevel@tonic-gate ill_refrele(ill); 4790Sstevel@tonic-gate } 4800Sstevel@tonic-gate /* 4810Sstevel@tonic-gate * If a netmask was supplied in the message, then subsequent route 4820Sstevel@tonic-gate * lookups will attempt to match on the netmask as well. 4830Sstevel@tonic-gate */ 4840Sstevel@tonic-gate if ((found_addrs & RTA_NETMASK) != 0) 4850Sstevel@tonic-gate match_flags |= MATCH_IRE_MASK; 4860Sstevel@tonic-gate 4871676Sjpk /* 4881676Sjpk * We only process any passed-in route security attributes for 4892304Swy83408 * either RTM_ADD or RTM_CHANGE message; We overload them 4902304Swy83408 * to do an RTM_GET as a different label; ignore otherwise. 4911676Sjpk */ 4922304Swy83408 if (rtm->rtm_type == RTM_ADD || rtm->rtm_type == RTM_CHANGE || 4932304Swy83408 rtm->rtm_type == RTM_GET) { 4941676Sjpk ASSERT(rtsecattr.rtsa_cnt <= TSOL_RTSA_REQUEST_MAX); 4951676Sjpk if (rtsecattr.rtsa_cnt > 0) 4961676Sjpk rtsap = &rtsecattr.rtsa_attr[0]; 4971676Sjpk } 4981676Sjpk 4990Sstevel@tonic-gate switch (rtm->rtm_type) { 5000Sstevel@tonic-gate case RTM_ADD: 5010Sstevel@tonic-gate /* if we are adding a route, gateway is a must */ 5020Sstevel@tonic-gate if ((found_addrs & RTA_GATEWAY) == 0) { 5030Sstevel@tonic-gate error = EINVAL; 5040Sstevel@tonic-gate goto done; 5050Sstevel@tonic-gate } 5060Sstevel@tonic-gate 5070Sstevel@tonic-gate /* Multirouting does not support net routes. */ 5080Sstevel@tonic-gate if ((rtm->rtm_flags & (RTF_MULTIRT | RTF_HOST)) == 5090Sstevel@tonic-gate RTF_MULTIRT) { 5100Sstevel@tonic-gate error = EADDRNOTAVAIL; 5110Sstevel@tonic-gate goto done; 5120Sstevel@tonic-gate } 5130Sstevel@tonic-gate 5140Sstevel@tonic-gate /* 5150Sstevel@tonic-gate * Multirouting and user-specified source addresses 5160Sstevel@tonic-gate * do not support interface based routing. 5170Sstevel@tonic-gate * Assigning a source address to an interface based 5180Sstevel@tonic-gate * route is achievable by plumbing a new ipif and 5190Sstevel@tonic-gate * setting up the interface route via this ipif, 5200Sstevel@tonic-gate * though. 5210Sstevel@tonic-gate */ 5220Sstevel@tonic-gate if (rtm->rtm_flags & (RTF_MULTIRT | RTF_SETSRC)) { 5230Sstevel@tonic-gate if ((rtm->rtm_flags & RTF_GATEWAY) == 0) { 5240Sstevel@tonic-gate error = EADDRNOTAVAIL; 5250Sstevel@tonic-gate goto done; 5260Sstevel@tonic-gate } 5270Sstevel@tonic-gate } 5280Sstevel@tonic-gate 5290Sstevel@tonic-gate switch (af) { 5300Sstevel@tonic-gate case AF_INET: 5310Sstevel@tonic-gate if (src_addr != INADDR_ANY) { 5320Sstevel@tonic-gate /* 5330Sstevel@tonic-gate * If there is a source address, but 5340Sstevel@tonic-gate * no RTF_SETSRC modifier, setup a MobileIP 5350Sstevel@tonic-gate * reverse tunnel. 5360Sstevel@tonic-gate */ 5370Sstevel@tonic-gate if ((rtm->rtm_flags & RTF_SETSRC) == 0) { 5380Sstevel@tonic-gate error = ip_mrtun_rt_add(src_addr, 5390Sstevel@tonic-gate rtm->rtm_flags, ipif, 5400Sstevel@tonic-gate src_ipif, &ire, CONNP_TO_WQ(connp), 5410Sstevel@tonic-gate ioc_mp, ip_rts_request_retry); 5420Sstevel@tonic-gate break; 5430Sstevel@tonic-gate } 5440Sstevel@tonic-gate /* 5450Sstevel@tonic-gate * The RTF_SETSRC flag is present, check that 5460Sstevel@tonic-gate * the supplied src address is not the loopback 5470Sstevel@tonic-gate * address. This would produce martian packets. 5480Sstevel@tonic-gate */ 5490Sstevel@tonic-gate if (src_addr == htonl(INADDR_LOOPBACK)) { 5500Sstevel@tonic-gate error = EINVAL; 5510Sstevel@tonic-gate goto done; 5520Sstevel@tonic-gate } 5530Sstevel@tonic-gate /* 5540Sstevel@tonic-gate * Also check that the supplied address is a 5550Sstevel@tonic-gate * valid, local one. 5560Sstevel@tonic-gate */ 5570Sstevel@tonic-gate tmp_ipif = ipif_lookup_addr(src_addr, NULL, 5580Sstevel@tonic-gate ALL_ZONES, CONNP_TO_WQ(connp), ioc_mp, 5590Sstevel@tonic-gate ip_rts_request_retry, &error); 5600Sstevel@tonic-gate if (tmp_ipif == NULL) { 5610Sstevel@tonic-gate if (error != EINPROGRESS) 5620Sstevel@tonic-gate error = EADDRNOTAVAIL; 5630Sstevel@tonic-gate goto done; 5640Sstevel@tonic-gate } 5650Sstevel@tonic-gate if (!(tmp_ipif->ipif_flags & IPIF_UP) || 5660Sstevel@tonic-gate (tmp_ipif->ipif_flags & 5670Sstevel@tonic-gate (IPIF_NOLOCAL | IPIF_ANYCAST))) { 5680Sstevel@tonic-gate error = EINVAL; 5690Sstevel@tonic-gate goto done; 5700Sstevel@tonic-gate } 5710Sstevel@tonic-gate } else { 5720Sstevel@tonic-gate /* 5730Sstevel@tonic-gate * The RTF_SETSRC modifier must be associated 5740Sstevel@tonic-gate * to a non-null source address. 5750Sstevel@tonic-gate */ 5760Sstevel@tonic-gate if (rtm->rtm_flags & RTF_SETSRC) { 5770Sstevel@tonic-gate error = EINVAL; 5780Sstevel@tonic-gate goto done; 5790Sstevel@tonic-gate } 5800Sstevel@tonic-gate } 5810Sstevel@tonic-gate 5821676Sjpk error = ip_rt_add(dst_addr, net_mask, gw_addr, src_addr, 5830Sstevel@tonic-gate rtm->rtm_flags, ipif, src_ipif, &ire, B_FALSE, 5841676Sjpk CONNP_TO_WQ(connp), ioc_mp, ip_rts_request_retry, 5851676Sjpk rtsap); 5860Sstevel@tonic-gate if (ipif != NULL) 5870Sstevel@tonic-gate ASSERT(!MUTEX_HELD(&ipif->ipif_ill->ill_lock)); 5880Sstevel@tonic-gate break; 5890Sstevel@tonic-gate case AF_INET6: 5900Sstevel@tonic-gate if (!IN6_IS_ADDR_UNSPECIFIED(&src_addr_v6)) { 5910Sstevel@tonic-gate /* 5920Sstevel@tonic-gate * If there is a source address, but 5930Sstevel@tonic-gate * no RTF_SETSRC modifier, reject, as 5940Sstevel@tonic-gate * MobileIP IPv6 reverse tunnels are 5950Sstevel@tonic-gate * not supported. 5960Sstevel@tonic-gate */ 5970Sstevel@tonic-gate if ((rtm->rtm_flags & RTF_SETSRC) == 0) { 5980Sstevel@tonic-gate error = EINVAL; 5990Sstevel@tonic-gate goto done; 6000Sstevel@tonic-gate } 6010Sstevel@tonic-gate /* 6020Sstevel@tonic-gate * The RTF_SETSRC flag is present, check that 6030Sstevel@tonic-gate * the supplied src address is not the loopback 6040Sstevel@tonic-gate * address. This would produce martian packets. 6050Sstevel@tonic-gate */ 6060Sstevel@tonic-gate if (IN6_IS_ADDR_LOOPBACK(&src_addr_v6)) { 6070Sstevel@tonic-gate error = EINVAL; 6080Sstevel@tonic-gate goto done; 6090Sstevel@tonic-gate } 6100Sstevel@tonic-gate /* 6110Sstevel@tonic-gate * Also check that the supplied address is a 6120Sstevel@tonic-gate * valid, local one. 6130Sstevel@tonic-gate */ 6140Sstevel@tonic-gate tmp_ipif = ipif_lookup_addr_v6(&src_addr_v6, 6150Sstevel@tonic-gate NULL, ALL_ZONES, CONNP_TO_WQ(connp), ioc_mp, 6160Sstevel@tonic-gate ip_rts_request_retry, &error); 6170Sstevel@tonic-gate if (tmp_ipif == NULL) { 6180Sstevel@tonic-gate if (error != EINPROGRESS) 6190Sstevel@tonic-gate error = EADDRNOTAVAIL; 6200Sstevel@tonic-gate goto done; 6210Sstevel@tonic-gate } 6220Sstevel@tonic-gate 6230Sstevel@tonic-gate if (!(tmp_ipif->ipif_flags & IPIF_UP) || 6240Sstevel@tonic-gate (tmp_ipif->ipif_flags & 6250Sstevel@tonic-gate (IPIF_NOLOCAL | IPIF_ANYCAST))) { 6260Sstevel@tonic-gate error = EINVAL; 6270Sstevel@tonic-gate goto done; 6280Sstevel@tonic-gate } 6290Sstevel@tonic-gate 6300Sstevel@tonic-gate error = ip_rt_add_v6(&dst_addr_v6, &net_mask_v6, 6310Sstevel@tonic-gate &gw_addr_v6, &src_addr_v6, rtm->rtm_flags, 6320Sstevel@tonic-gate ipif, &ire, CONNP_TO_WQ(connp), ioc_mp, 6331676Sjpk ip_rts_request_retry, rtsap); 6340Sstevel@tonic-gate break; 6350Sstevel@tonic-gate } 6360Sstevel@tonic-gate /* 6370Sstevel@tonic-gate * The RTF_SETSRC modifier must be associated 6380Sstevel@tonic-gate * to a non-null source address. 6390Sstevel@tonic-gate */ 6400Sstevel@tonic-gate if (rtm->rtm_flags & RTF_SETSRC) { 6410Sstevel@tonic-gate error = EINVAL; 6420Sstevel@tonic-gate goto done; 6430Sstevel@tonic-gate } 6440Sstevel@tonic-gate error = ip_rt_add_v6(&dst_addr_v6, &net_mask_v6, 6450Sstevel@tonic-gate &gw_addr_v6, NULL, rtm->rtm_flags, 6460Sstevel@tonic-gate ipif, &ire, CONNP_TO_WQ(connp), ioc_mp, 6471676Sjpk ip_rts_request_retry, rtsap); 6480Sstevel@tonic-gate if (ipif != NULL) 6490Sstevel@tonic-gate ASSERT(!MUTEX_HELD(&ipif->ipif_ill->ill_lock)); 6500Sstevel@tonic-gate break; 6510Sstevel@tonic-gate } 6520Sstevel@tonic-gate if (error != 0) 6530Sstevel@tonic-gate goto done; 6540Sstevel@tonic-gate ASSERT(ire != NULL); 6550Sstevel@tonic-gate rts_setmetrics(ire, rtm->rtm_inits, &rtm->rtm_rmx); 6560Sstevel@tonic-gate break; 6570Sstevel@tonic-gate case RTM_DELETE: 6580Sstevel@tonic-gate /* if we are deleting a route, gateway is a must */ 6590Sstevel@tonic-gate if ((found_addrs & RTA_GATEWAY) == 0) { 6600Sstevel@tonic-gate error = EINVAL; 6610Sstevel@tonic-gate goto done; 6620Sstevel@tonic-gate } 6630Sstevel@tonic-gate /* 6640Sstevel@tonic-gate * The RTF_SETSRC modifier does not make sense 6650Sstevel@tonic-gate * when deleting a route. 6660Sstevel@tonic-gate */ 6670Sstevel@tonic-gate if (rtm->rtm_flags & RTF_SETSRC) { 6680Sstevel@tonic-gate error = EINVAL; 6690Sstevel@tonic-gate goto done; 6700Sstevel@tonic-gate } 6710Sstevel@tonic-gate 6720Sstevel@tonic-gate switch (af) { 6730Sstevel@tonic-gate case AF_INET: 6740Sstevel@tonic-gate /* 6750Sstevel@tonic-gate * If there is a source address, delete 6760Sstevel@tonic-gate * a MobileIP reverse tunnel. 6770Sstevel@tonic-gate */ 6780Sstevel@tonic-gate if (src_addr != INADDR_ANY) { 6790Sstevel@tonic-gate error = ip_mrtun_rt_delete(src_addr, 6800Sstevel@tonic-gate src_ipif); 6810Sstevel@tonic-gate break; 6820Sstevel@tonic-gate } 6830Sstevel@tonic-gate error = ip_rt_delete(dst_addr, net_mask, gw_addr, 6840Sstevel@tonic-gate found_addrs, rtm->rtm_flags, ipif, src_ipif, 6850Sstevel@tonic-gate B_FALSE, CONNP_TO_WQ(connp), ioc_mp, 6860Sstevel@tonic-gate ip_rts_request_retry); 6870Sstevel@tonic-gate break; 6880Sstevel@tonic-gate case AF_INET6: 6890Sstevel@tonic-gate error = ip_rt_delete_v6(&dst_addr_v6, &net_mask_v6, 6900Sstevel@tonic-gate &gw_addr_v6, found_addrs, rtm->rtm_flags, ipif, 6910Sstevel@tonic-gate CONNP_TO_WQ(connp), ioc_mp, ip_rts_request_retry); 6920Sstevel@tonic-gate break; 6930Sstevel@tonic-gate } 6940Sstevel@tonic-gate break; 6950Sstevel@tonic-gate case RTM_GET: 6960Sstevel@tonic-gate case RTM_CHANGE: 6970Sstevel@tonic-gate /* 6980Sstevel@tonic-gate * In the case of RTM_GET, the forwarding table should be 6990Sstevel@tonic-gate * searched recursively with default being matched if the 7000Sstevel@tonic-gate * specific route doesn't exist. Also, if a gateway was 7010Sstevel@tonic-gate * specified then the gateway address must also be matched. 7020Sstevel@tonic-gate * 7030Sstevel@tonic-gate * In the case of RTM_CHANGE, the gateway address (if supplied) 7040Sstevel@tonic-gate * is the new gateway address so matching on the gateway address 7050Sstevel@tonic-gate * is not done. This can lead to ambiguity when looking up the 7060Sstevel@tonic-gate * route to change as usually only the destination (and netmask, 7070Sstevel@tonic-gate * if supplied) is used for the lookup. However if a RTA_IFP 7080Sstevel@tonic-gate * sockaddr is also supplied, it can disambiguate which route to 7090Sstevel@tonic-gate * change provided the ambigous routes are tied to distinct 7100Sstevel@tonic-gate * ill's (or interface indices). If the routes are not tied to 7110Sstevel@tonic-gate * any particular interfaces (for example, with traditional 7120Sstevel@tonic-gate * gateway routes), then a RTA_IFP sockaddr will be of no use as 7130Sstevel@tonic-gate * it won't match any such routes. 7140Sstevel@tonic-gate * RTA_SRC is not supported for RTM_GET and RTM_CHANGE, 7150Sstevel@tonic-gate * except when RTM_CHANGE is combined to RTF_SETSRC. 7160Sstevel@tonic-gate */ 7170Sstevel@tonic-gate if (((found_addrs & RTA_SRC) != 0) && 7180Sstevel@tonic-gate ((rtm->rtm_type == RTM_GET) || 7190Sstevel@tonic-gate !(rtm->rtm_flags & RTF_SETSRC))) { 7200Sstevel@tonic-gate error = EOPNOTSUPP; 7210Sstevel@tonic-gate goto done; 7220Sstevel@tonic-gate } 7230Sstevel@tonic-gate 7240Sstevel@tonic-gate if (rtm->rtm_type == RTM_GET) { 7250Sstevel@tonic-gate match_flags |= 7262304Swy83408 (MATCH_IRE_DEFAULT | MATCH_IRE_RECURSIVE | 7272304Swy83408 MATCH_IRE_SECATTR); 7282304Swy83408 match_flags_local |= MATCH_IRE_SECATTR; 7290Sstevel@tonic-gate if ((found_addrs & RTA_GATEWAY) != 0) 7300Sstevel@tonic-gate match_flags |= MATCH_IRE_GW; 731*2601Swy83408 if (ioc_cr) 732*2601Swy83408 tsl = crgetlabel(ioc_cr); 7332304Swy83408 if (rtsap != NULL) { 7342304Swy83408 if (rtsa_validate(rtsap) != 0) { 7352304Swy83408 error = EINVAL; 7362304Swy83408 goto done; 7372304Swy83408 } 738*2601Swy83408 if (tsl != NULL && 739*2601Swy83408 crgetzoneid(ioc_cr) != GLOBAL_ZONEID && 7402304Swy83408 (tsl->tsl_doi != rtsap->rtsa_doi || 7412304Swy83408 !bldominates(&tsl->tsl_label, 7422304Swy83408 &rtsap->rtsa_slrange.lower_bound))) { 7432304Swy83408 error = EPERM; 7442304Swy83408 goto done; 7452304Swy83408 } 7462304Swy83408 tsl = labelalloc( 7472304Swy83408 &rtsap->rtsa_slrange.lower_bound, 7482304Swy83408 rtsap->rtsa_doi, KM_NOSLEEP); 7492304Swy83408 } 7500Sstevel@tonic-gate } 7510Sstevel@tonic-gate if (rtm->rtm_type == RTM_CHANGE) { 7520Sstevel@tonic-gate if ((found_addrs & RTA_GATEWAY) && 7530Sstevel@tonic-gate (rtm->rtm_flags & RTF_SETSRC)) { 7540Sstevel@tonic-gate /* 7550Sstevel@tonic-gate * Do not want to change the gateway, 7560Sstevel@tonic-gate * but rather the source address. 7570Sstevel@tonic-gate */ 7580Sstevel@tonic-gate match_flags |= MATCH_IRE_GW; 7590Sstevel@tonic-gate } 7600Sstevel@tonic-gate } 7610Sstevel@tonic-gate 7620Sstevel@tonic-gate /* 7630Sstevel@tonic-gate * If the netmask is all ones (either as supplied or as derived 7640Sstevel@tonic-gate * above), then first check for an IRE_LOOPBACK or 7650Sstevel@tonic-gate * IRE_LOCAL entry. 7660Sstevel@tonic-gate * 7670Sstevel@tonic-gate * If we didn't check for or find an IRE_LOOPBACK or IRE_LOCAL 7680Sstevel@tonic-gate * entry, then look in the forwarding table. 7690Sstevel@tonic-gate */ 7700Sstevel@tonic-gate switch (af) { 7710Sstevel@tonic-gate case AF_INET: 7720Sstevel@tonic-gate if (net_mask == IP_HOST_MASK) { 7730Sstevel@tonic-gate ire = ire_ctable_lookup(dst_addr, gw_addr, 7740Sstevel@tonic-gate IRE_LOCAL | IRE_LOOPBACK, NULL, ALL_ZONES, 7752304Swy83408 tsl, match_flags_local); 7760Sstevel@tonic-gate } 7770Sstevel@tonic-gate if (ire == NULL) { 7780Sstevel@tonic-gate ire = ire_ftable_lookup(dst_addr, net_mask, 7790Sstevel@tonic-gate gw_addr, 0, ipif, &sire, ALL_ZONES, 0, 7802304Swy83408 tsl, match_flags); 7810Sstevel@tonic-gate } 7820Sstevel@tonic-gate break; 7830Sstevel@tonic-gate case AF_INET6: 7840Sstevel@tonic-gate if (IN6_ARE_ADDR_EQUAL(&net_mask_v6, &ipv6_all_ones)) { 7850Sstevel@tonic-gate ire = ire_ctable_lookup_v6(&dst_addr_v6, 7860Sstevel@tonic-gate &gw_addr_v6, IRE_LOCAL | IRE_LOOPBACK, NULL, 7872304Swy83408 ALL_ZONES, tsl, match_flags_local); 7880Sstevel@tonic-gate } 7890Sstevel@tonic-gate if (ire == NULL) { 7900Sstevel@tonic-gate ire = ire_ftable_lookup_v6(&dst_addr_v6, 7910Sstevel@tonic-gate &net_mask_v6, &gw_addr_v6, 0, ipif, &sire, 7922304Swy83408 ALL_ZONES, 0, tsl, match_flags); 7930Sstevel@tonic-gate } 7940Sstevel@tonic-gate break; 7950Sstevel@tonic-gate } 7962304Swy83408 if (tsl != NULL && tsl != crgetlabel(ioc_cr)) 7972304Swy83408 label_rele(tsl); 7980Sstevel@tonic-gate 7990Sstevel@tonic-gate if (ire == NULL) { 8000Sstevel@tonic-gate error = ESRCH; 8010Sstevel@tonic-gate goto done; 8020Sstevel@tonic-gate } 8030Sstevel@tonic-gate /* we know the IRE before we come here */ 8040Sstevel@tonic-gate switch (rtm->rtm_type) { 8050Sstevel@tonic-gate case RTM_GET: 8060Sstevel@tonic-gate mp1 = rts_rtmget(mp, ire, sire, af); 8070Sstevel@tonic-gate if (mp1 == NULL) { 8080Sstevel@tonic-gate error = ENOBUFS; 8090Sstevel@tonic-gate goto done; 8100Sstevel@tonic-gate } 8110Sstevel@tonic-gate freemsg(mp); 8120Sstevel@tonic-gate mp = mp1; 8130Sstevel@tonic-gate rtm = (rt_msghdr_t *)mp->b_rptr; 8140Sstevel@tonic-gate break; 8150Sstevel@tonic-gate case RTM_CHANGE: 8160Sstevel@tonic-gate /* 8170Sstevel@tonic-gate * Do not allow to the multirouting state of a route 8180Sstevel@tonic-gate * to be changed. This aims to prevent undesirable 8190Sstevel@tonic-gate * stages where both multirt and non-multirt routes 8200Sstevel@tonic-gate * for the same destination are declared. 8210Sstevel@tonic-gate */ 8220Sstevel@tonic-gate if ((ire->ire_flags & RTF_MULTIRT) != 8230Sstevel@tonic-gate (rtm->rtm_flags & RTF_MULTIRT)) { 8240Sstevel@tonic-gate error = EINVAL; 8250Sstevel@tonic-gate goto done; 8260Sstevel@tonic-gate } 8270Sstevel@tonic-gate /* 8280Sstevel@tonic-gate * Note that we do not need to do 8290Sstevel@tonic-gate * ire_flush_cache_*(IRE_FLUSH_ADD) as a change 8300Sstevel@tonic-gate * in metrics or gateway will not affect existing 8310Sstevel@tonic-gate * routes since it does not create a more specific 8320Sstevel@tonic-gate * route. 8330Sstevel@tonic-gate */ 8340Sstevel@tonic-gate switch (af) { 8350Sstevel@tonic-gate case AF_INET: 8360Sstevel@tonic-gate ire_flush_cache_v4(ire, IRE_FLUSH_DELETE); 8370Sstevel@tonic-gate if ((found_addrs & RTA_GATEWAY) != 0 && 8380Sstevel@tonic-gate (ire->ire_gateway_addr != gw_addr)) { 8390Sstevel@tonic-gate ire->ire_gateway_addr = gw_addr; 8400Sstevel@tonic-gate } 8411676Sjpk 8421676Sjpk if (rtsap != NULL) { 8431676Sjpk ga.ga_af = AF_INET; 8441676Sjpk IN6_IPADDR_TO_V4MAPPED( 8451676Sjpk ire->ire_gateway_addr, &ga.ga_addr); 8461676Sjpk 8471676Sjpk gcgrp = gcgrp_lookup(&ga, B_TRUE); 8481676Sjpk if (gcgrp == NULL) { 8491676Sjpk error = ENOMEM; 8501676Sjpk goto done; 8511676Sjpk } 8521676Sjpk } 8531676Sjpk 8540Sstevel@tonic-gate if ((found_addrs & RTA_SRC) != 0 && 8550Sstevel@tonic-gate (rtm->rtm_flags & RTF_SETSRC) != 0 && 8560Sstevel@tonic-gate (ire->ire_src_addr != src_addr)) { 8570Sstevel@tonic-gate 8580Sstevel@tonic-gate if (src_addr != INADDR_ANY) { 8590Sstevel@tonic-gate /* 8600Sstevel@tonic-gate * The RTF_SETSRC flag is 8610Sstevel@tonic-gate * present, check that the 8620Sstevel@tonic-gate * supplied src address is not 8630Sstevel@tonic-gate * the loopback address. This 8640Sstevel@tonic-gate * would produce martian 8650Sstevel@tonic-gate * packets. 8660Sstevel@tonic-gate */ 8670Sstevel@tonic-gate if (src_addr == 8680Sstevel@tonic-gate htonl(INADDR_LOOPBACK)) { 8690Sstevel@tonic-gate error = EINVAL; 8700Sstevel@tonic-gate goto done; 8710Sstevel@tonic-gate } 8720Sstevel@tonic-gate /* 8730Sstevel@tonic-gate * Also check that the the 8740Sstevel@tonic-gate * supplied addr is a valid 8750Sstevel@tonic-gate * local address. 8760Sstevel@tonic-gate */ 8770Sstevel@tonic-gate tmp_ipif = ipif_lookup_addr( 8780Sstevel@tonic-gate src_addr, NULL, ALL_ZONES, 8790Sstevel@tonic-gate CONNP_TO_WQ(connp), ioc_mp, 8800Sstevel@tonic-gate ip_rts_request_retry, 8810Sstevel@tonic-gate &error); 8820Sstevel@tonic-gate if (tmp_ipif == NULL) { 8830Sstevel@tonic-gate error = (error == 8840Sstevel@tonic-gate EINPROGRESS) ? 8850Sstevel@tonic-gate error : 8860Sstevel@tonic-gate EADDRNOTAVAIL; 8870Sstevel@tonic-gate goto done; 8880Sstevel@tonic-gate } 8890Sstevel@tonic-gate 8900Sstevel@tonic-gate if (!(tmp_ipif->ipif_flags & 8910Sstevel@tonic-gate IPIF_UP) || 8920Sstevel@tonic-gate (tmp_ipif->ipif_flags & 8930Sstevel@tonic-gate (IPIF_NOLOCAL | 8940Sstevel@tonic-gate IPIF_ANYCAST))) { 8950Sstevel@tonic-gate error = EINVAL; 8960Sstevel@tonic-gate goto done; 8970Sstevel@tonic-gate } 8980Sstevel@tonic-gate ire->ire_flags |= RTF_SETSRC; 8990Sstevel@tonic-gate } else { 9000Sstevel@tonic-gate ire->ire_flags &= ~RTF_SETSRC; 9010Sstevel@tonic-gate } 9020Sstevel@tonic-gate ire->ire_src_addr = src_addr; 9030Sstevel@tonic-gate } 9040Sstevel@tonic-gate break; 9050Sstevel@tonic-gate case AF_INET6: 9060Sstevel@tonic-gate ire_flush_cache_v6(ire, IRE_FLUSH_DELETE); 9070Sstevel@tonic-gate mutex_enter(&ire->ire_lock); 9080Sstevel@tonic-gate if ((found_addrs & RTA_GATEWAY) != 0 && 9090Sstevel@tonic-gate !IN6_ARE_ADDR_EQUAL( 9100Sstevel@tonic-gate &ire->ire_gateway_addr_v6, &gw_addr_v6)) { 9110Sstevel@tonic-gate ire->ire_gateway_addr_v6 = gw_addr_v6; 9120Sstevel@tonic-gate } 9131676Sjpk 9141676Sjpk if (rtsap != NULL) { 9151676Sjpk ga.ga_af = AF_INET6; 9161676Sjpk ga.ga_addr = ire->ire_gateway_addr_v6; 9171676Sjpk 9181676Sjpk gcgrp = gcgrp_lookup(&ga, B_TRUE); 9191676Sjpk if (gcgrp == NULL) { 9201676Sjpk error = ENOMEM; 9211676Sjpk goto done; 9221676Sjpk } 9231676Sjpk } 9241676Sjpk 9250Sstevel@tonic-gate if ((found_addrs & RTA_SRC) != 0 && 9260Sstevel@tonic-gate (rtm->rtm_flags & RTF_SETSRC) != 0 && 9270Sstevel@tonic-gate !IN6_ARE_ADDR_EQUAL( 9280Sstevel@tonic-gate &ire->ire_src_addr_v6, &src_addr_v6)) { 9290Sstevel@tonic-gate 9300Sstevel@tonic-gate if (!IN6_IS_ADDR_UNSPECIFIED( 9310Sstevel@tonic-gate &src_addr_v6)) { 9320Sstevel@tonic-gate /* 9330Sstevel@tonic-gate * The RTF_SETSRC flag is 9340Sstevel@tonic-gate * present, check that the 9350Sstevel@tonic-gate * supplied src address is not 9360Sstevel@tonic-gate * the loopback address. This 9370Sstevel@tonic-gate * would produce martian 9380Sstevel@tonic-gate * packets. 9390Sstevel@tonic-gate */ 9400Sstevel@tonic-gate if (IN6_IS_ADDR_LOOPBACK( 9410Sstevel@tonic-gate &src_addr_v6)) { 9420Sstevel@tonic-gate mutex_exit( 9430Sstevel@tonic-gate &ire->ire_lock); 9440Sstevel@tonic-gate error = EINVAL; 9450Sstevel@tonic-gate goto done; 9460Sstevel@tonic-gate } 9470Sstevel@tonic-gate /* 9480Sstevel@tonic-gate * Also check that the the 9490Sstevel@tonic-gate * supplied addr is a valid 9500Sstevel@tonic-gate * local address. 9510Sstevel@tonic-gate */ 9520Sstevel@tonic-gate tmp_ipif = ipif_lookup_addr_v6( 9530Sstevel@tonic-gate &src_addr_v6, NULL, 9540Sstevel@tonic-gate ALL_ZONES, 9550Sstevel@tonic-gate CONNP_TO_WQ(connp), ioc_mp, 9560Sstevel@tonic-gate ip_rts_request_retry, 9570Sstevel@tonic-gate &error); 9580Sstevel@tonic-gate if (tmp_ipif == NULL) { 9590Sstevel@tonic-gate mutex_exit( 9600Sstevel@tonic-gate &ire->ire_lock); 9610Sstevel@tonic-gate error = (error == 9620Sstevel@tonic-gate EINPROGRESS) ? 9630Sstevel@tonic-gate error : 9640Sstevel@tonic-gate EADDRNOTAVAIL; 9650Sstevel@tonic-gate goto done; 9660Sstevel@tonic-gate } 9670Sstevel@tonic-gate if (!(tmp_ipif->ipif_flags & 9680Sstevel@tonic-gate IPIF_UP) || 9690Sstevel@tonic-gate (tmp_ipif->ipif_flags & 9700Sstevel@tonic-gate (IPIF_NOLOCAL | 9710Sstevel@tonic-gate IPIF_ANYCAST))) { 9720Sstevel@tonic-gate mutex_exit( 9730Sstevel@tonic-gate &ire->ire_lock); 9740Sstevel@tonic-gate error = EINVAL; 9750Sstevel@tonic-gate goto done; 9760Sstevel@tonic-gate } 9770Sstevel@tonic-gate ire->ire_flags |= RTF_SETSRC; 9780Sstevel@tonic-gate } else { 9790Sstevel@tonic-gate ire->ire_flags &= ~RTF_SETSRC; 9800Sstevel@tonic-gate } 9810Sstevel@tonic-gate ire->ire_src_addr_v6 = src_addr_v6; 9820Sstevel@tonic-gate } 9830Sstevel@tonic-gate mutex_exit(&ire->ire_lock); 9840Sstevel@tonic-gate break; 9850Sstevel@tonic-gate } 9861676Sjpk 9871676Sjpk if (rtsap != NULL) { 9881676Sjpk in_addr_t ga_addr4; 9891676Sjpk 9901676Sjpk ASSERT(gcgrp != NULL); 9911676Sjpk 9921676Sjpk /* 9931676Sjpk * Create and add the security attribute to 9941676Sjpk * prefix IRE; it will add a reference to the 9951676Sjpk * group upon allocating a new entry. If it 9961676Sjpk * finds an already-existing entry for the 9971676Sjpk * security attribute, it simply returns it 9981676Sjpk * and no new group reference is made. 9991676Sjpk */ 10001676Sjpk gc = gc_create(rtsap, gcgrp, &gcgrp_xtraref); 10011676Sjpk if (gc == NULL || 10021676Sjpk (error = tsol_ire_init_gwattr(ire, 10031676Sjpk ire->ire_ipversion, gc, NULL)) != 0) { 10041676Sjpk if (gc != NULL) { 10051676Sjpk GC_REFRELE(gc); 10061676Sjpk } else { 10071676Sjpk /* gc_create failed */ 10081676Sjpk error = ENOMEM; 10091676Sjpk } 10101676Sjpk goto done; 10111676Sjpk } 10121676Sjpk 10131676Sjpk /* 10141676Sjpk * Now delete any existing gateway IRE caches 10151676Sjpk * as well as all caches using the gateway, 10161676Sjpk * and allow them to be created on demand 10171676Sjpk * through ip_newroute{_v6}. 10181676Sjpk */ 10191676Sjpk IN6_V4MAPPED_TO_IPADDR(&ga.ga_addr, ga_addr4); 10201676Sjpk if (af == AF_INET) { 10211676Sjpk ire_clookup_delete_cache_gw( 10221676Sjpk ga_addr4, ALL_ZONES); 10231676Sjpk } else { 10241676Sjpk ire_clookup_delete_cache_gw_v6( 10251676Sjpk &ga.ga_addr, ALL_ZONES); 10261676Sjpk } 10271676Sjpk } 10280Sstevel@tonic-gate rts_setmetrics(ire, rtm->rtm_inits, &rtm->rtm_rmx); 10290Sstevel@tonic-gate break; 10300Sstevel@tonic-gate } 10310Sstevel@tonic-gate break; 10320Sstevel@tonic-gate default: 10330Sstevel@tonic-gate error = EOPNOTSUPP; 10340Sstevel@tonic-gate break; 10350Sstevel@tonic-gate } 10360Sstevel@tonic-gate done: 10370Sstevel@tonic-gate if (ire != NULL) 10380Sstevel@tonic-gate ire_refrele(ire); 10390Sstevel@tonic-gate if (sire != NULL) 10400Sstevel@tonic-gate ire_refrele(sire); 10410Sstevel@tonic-gate if (ipif != NULL) 10420Sstevel@tonic-gate ipif_refrele(ipif); 10430Sstevel@tonic-gate if (src_ipif != NULL) 10440Sstevel@tonic-gate ipif_refrele(src_ipif); 10450Sstevel@tonic-gate if (tmp_ipif != NULL) 10460Sstevel@tonic-gate ipif_refrele(tmp_ipif); 10470Sstevel@tonic-gate 10481676Sjpk if (gcgrp_xtraref) 10491676Sjpk GCGRP_REFRELE(gcgrp); 10501676Sjpk 10510Sstevel@tonic-gate if (error == EINPROGRESS) 10520Sstevel@tonic-gate return (error); 10530Sstevel@tonic-gate if (rtm != NULL) { 10540Sstevel@tonic-gate ASSERT(mp->b_wptr <= mp->b_datap->db_lim); 10550Sstevel@tonic-gate if (error != 0) { 10560Sstevel@tonic-gate rtm->rtm_errno = error; 10570Sstevel@tonic-gate /* Send error ACK */ 10580Sstevel@tonic-gate ip1dbg(("ip_rts_request: error %d\n", error)); 10590Sstevel@tonic-gate } else { 10600Sstevel@tonic-gate rtm->rtm_flags |= RTF_DONE; 10610Sstevel@tonic-gate /* OK ACK already set up by caller except this */ 10620Sstevel@tonic-gate ip2dbg(("ip_rts_request: OK ACK\n")); 10630Sstevel@tonic-gate } 10640Sstevel@tonic-gate rts_queue_input(mp, q, af); 10650Sstevel@tonic-gate } 10660Sstevel@tonic-gate iocp->ioc_error = error; 10670Sstevel@tonic-gate ioc_mp->b_datap->db_type = M_IOCACK; 10680Sstevel@tonic-gate if (iocp->ioc_error != 0) 10690Sstevel@tonic-gate iocp->ioc_count = 0; 10700Sstevel@tonic-gate qreply(q, ioc_mp); 10710Sstevel@tonic-gate /* conn was refheld in ip_wput_ioctl. */ 10720Sstevel@tonic-gate CONN_OPER_PENDING_DONE(connp); 10730Sstevel@tonic-gate 10740Sstevel@tonic-gate return (error); 10750Sstevel@tonic-gate } 10760Sstevel@tonic-gate 10770Sstevel@tonic-gate /* 10780Sstevel@tonic-gate * Build a reply to the RTM_GET request contained in the given message block 10790Sstevel@tonic-gate * using the retrieved IRE of the destination address, the parent IRE (if it 10800Sstevel@tonic-gate * exists) and the address family. 10810Sstevel@tonic-gate * 10820Sstevel@tonic-gate * Returns a pointer to a message block containing the reply if successful, 10830Sstevel@tonic-gate * otherwise NULL is returned. 10840Sstevel@tonic-gate */ 10851676Sjpk static mblk_t * 10860Sstevel@tonic-gate rts_rtmget(mblk_t *mp, ire_t *ire, ire_t *sire, sa_family_t af) 10870Sstevel@tonic-gate { 10880Sstevel@tonic-gate rt_msghdr_t *rtm; 10890Sstevel@tonic-gate rt_msghdr_t *new_rtm; 10900Sstevel@tonic-gate mblk_t *new_mp; 10910Sstevel@tonic-gate int rtm_addrs; 10920Sstevel@tonic-gate int rtm_flags; 10930Sstevel@tonic-gate in6_addr_t gw_addr_v6; 10941676Sjpk tsol_ire_gw_secattr_t *attrp = NULL; 10951676Sjpk tsol_gc_t *gc = NULL; 10961676Sjpk tsol_gcgrp_t *gcgrp = NULL; 10971676Sjpk int sacnt = 0; 10980Sstevel@tonic-gate 10990Sstevel@tonic-gate ASSERT(ire->ire_ipif != NULL); 11000Sstevel@tonic-gate rtm = (rt_msghdr_t *)mp->b_rptr; 11010Sstevel@tonic-gate 11021676Sjpk if (sire != NULL && sire->ire_gw_secattr != NULL) 11031676Sjpk attrp = sire->ire_gw_secattr; 11041676Sjpk else if (ire->ire_gw_secattr != NULL) 11051676Sjpk attrp = ire->ire_gw_secattr; 11061676Sjpk 11071676Sjpk if (attrp != NULL) { 11081676Sjpk mutex_enter(&attrp->igsa_lock); 11091676Sjpk if ((gc = attrp->igsa_gc) != NULL) { 11101676Sjpk gcgrp = gc->gc_grp; 11111676Sjpk ASSERT(gcgrp != NULL); 11121676Sjpk rw_enter(&gcgrp->gcgrp_rwlock, RW_READER); 11131676Sjpk sacnt = 1; 11141676Sjpk } else if ((gcgrp = attrp->igsa_gcgrp) != NULL) { 11151676Sjpk rw_enter(&gcgrp->gcgrp_rwlock, RW_READER); 11161676Sjpk gc = gcgrp->gcgrp_head; 11171676Sjpk sacnt = gcgrp->gcgrp_count; 11181676Sjpk } 11191676Sjpk mutex_exit(&attrp->igsa_lock); 11201676Sjpk 11211676Sjpk /* do nothing if there's no gc to report */ 11221676Sjpk if (gc == NULL) { 11231676Sjpk ASSERT(sacnt == 0); 11241676Sjpk if (gcgrp != NULL) { 11251676Sjpk /* we might as well drop the lock now */ 11261676Sjpk rw_exit(&gcgrp->gcgrp_rwlock); 11271676Sjpk gcgrp = NULL; 11281676Sjpk } 11291676Sjpk attrp = NULL; 11301676Sjpk } 11311676Sjpk 11321676Sjpk ASSERT(gc == NULL || (gcgrp != NULL && 11331676Sjpk RW_LOCK_HELD(&gcgrp->gcgrp_rwlock))); 11341676Sjpk } 11351676Sjpk ASSERT(sacnt == 0 || gc != NULL); 11361676Sjpk 11370Sstevel@tonic-gate /* 11380Sstevel@tonic-gate * Always return RTA_DST, RTA_GATEWAY and RTA_NETMASK. 11390Sstevel@tonic-gate * 11400Sstevel@tonic-gate * The 4.4BSD-Lite2 code (net/rtsock.c) returns both 11410Sstevel@tonic-gate * RTA_IFP and RTA_IFA if either is defined, and also 11420Sstevel@tonic-gate * returns RTA_BRD if the appropriate interface is 11430Sstevel@tonic-gate * point-to-point. 11440Sstevel@tonic-gate */ 11450Sstevel@tonic-gate rtm_addrs = (RTA_DST | RTA_GATEWAY | RTA_NETMASK); 11460Sstevel@tonic-gate if (rtm->rtm_addrs & (RTA_IFP | RTA_IFA)) { 11470Sstevel@tonic-gate rtm_addrs |= (RTA_IFP | RTA_IFA); 11480Sstevel@tonic-gate if (ire->ire_ipif->ipif_flags & IPIF_POINTOPOINT) 11490Sstevel@tonic-gate rtm_addrs |= RTA_BRD; 11500Sstevel@tonic-gate } 11510Sstevel@tonic-gate 11521676Sjpk new_mp = rts_alloc_msg(RTM_GET, rtm_addrs, af, sacnt); 11531676Sjpk if (new_mp == NULL) { 11541676Sjpk if (gcgrp != NULL) 11551676Sjpk rw_exit(&gcgrp->gcgrp_rwlock); 11560Sstevel@tonic-gate return (NULL); 11571676Sjpk } 11580Sstevel@tonic-gate 11590Sstevel@tonic-gate /* 11600Sstevel@tonic-gate * We set the destination address, gateway address, 11610Sstevel@tonic-gate * netmask and flags in the RTM_GET response depending 11620Sstevel@tonic-gate * on whether we found a parent IRE or not. 11630Sstevel@tonic-gate * In particular, if we did find a parent IRE during the 11640Sstevel@tonic-gate * recursive search, use that IRE's gateway address. 11650Sstevel@tonic-gate * Otherwise, we use the IRE's source address for the 11660Sstevel@tonic-gate * gateway address. 11670Sstevel@tonic-gate */ 11680Sstevel@tonic-gate ASSERT(af == AF_INET || af == AF_INET6); 11690Sstevel@tonic-gate switch (af) { 11700Sstevel@tonic-gate case AF_INET: 11710Sstevel@tonic-gate if (sire == NULL) { 11720Sstevel@tonic-gate rtm_flags = ire->ire_flags; 11730Sstevel@tonic-gate rts_fill_msg(RTM_GET, rtm_addrs, ire->ire_addr, 11740Sstevel@tonic-gate ire->ire_mask, ire->ire_src_addr, ire->ire_src_addr, 11750Sstevel@tonic-gate ire->ire_ipif->ipif_pp_dst_addr, 0, ire->ire_ipif, 11761676Sjpk new_mp, sacnt, gc); 11770Sstevel@tonic-gate } else { 11780Sstevel@tonic-gate if (sire->ire_flags & RTF_SETSRC) 11790Sstevel@tonic-gate rtm_addrs |= RTA_SRC; 11800Sstevel@tonic-gate 11810Sstevel@tonic-gate rtm_flags = sire->ire_flags; 11820Sstevel@tonic-gate rts_fill_msg(RTM_GET, rtm_addrs, sire->ire_addr, 11830Sstevel@tonic-gate sire->ire_mask, sire->ire_gateway_addr, 11840Sstevel@tonic-gate (sire->ire_flags & RTF_SETSRC) ? 11850Sstevel@tonic-gate sire->ire_src_addr : ire->ire_src_addr, 11860Sstevel@tonic-gate ire->ire_ipif->ipif_pp_dst_addr, 11871676Sjpk 0, ire->ire_ipif, new_mp, sacnt, gc); 11880Sstevel@tonic-gate } 11890Sstevel@tonic-gate break; 11900Sstevel@tonic-gate case AF_INET6: 11910Sstevel@tonic-gate if (sire == NULL) { 11920Sstevel@tonic-gate rtm_flags = ire->ire_flags; 11930Sstevel@tonic-gate rts_fill_msg_v6(RTM_GET, rtm_addrs, &ire->ire_addr_v6, 11940Sstevel@tonic-gate &ire->ire_mask_v6, &ire->ire_src_addr_v6, 11950Sstevel@tonic-gate &ire->ire_src_addr_v6, 11960Sstevel@tonic-gate &ire->ire_ipif->ipif_v6pp_dst_addr, 11971676Sjpk &ipv6_all_zeros, ire->ire_ipif, new_mp, 11981676Sjpk sacnt, gc); 11990Sstevel@tonic-gate } else { 12000Sstevel@tonic-gate if (sire->ire_flags & RTF_SETSRC) 12010Sstevel@tonic-gate rtm_addrs |= RTA_SRC; 12020Sstevel@tonic-gate 12030Sstevel@tonic-gate rtm_flags = sire->ire_flags; 12040Sstevel@tonic-gate mutex_enter(&sire->ire_lock); 12050Sstevel@tonic-gate gw_addr_v6 = sire->ire_gateway_addr_v6; 12060Sstevel@tonic-gate mutex_exit(&sire->ire_lock); 12070Sstevel@tonic-gate rts_fill_msg_v6(RTM_GET, rtm_addrs, &sire->ire_addr_v6, 12080Sstevel@tonic-gate &sire->ire_mask_v6, &gw_addr_v6, 12090Sstevel@tonic-gate (sire->ire_flags & RTF_SETSRC) ? 12100Sstevel@tonic-gate &sire->ire_src_addr_v6 : &ire->ire_src_addr_v6, 12110Sstevel@tonic-gate &ire->ire_ipif->ipif_v6pp_dst_addr, &ipv6_all_zeros, 12121676Sjpk ire->ire_ipif, new_mp, sacnt, gc); 12130Sstevel@tonic-gate } 12140Sstevel@tonic-gate break; 12150Sstevel@tonic-gate } 12161676Sjpk 12171676Sjpk if (gcgrp != NULL) 12181676Sjpk rw_exit(&gcgrp->gcgrp_rwlock); 12191676Sjpk 12200Sstevel@tonic-gate new_rtm = (rt_msghdr_t *)new_mp->b_rptr; 12210Sstevel@tonic-gate 12220Sstevel@tonic-gate /* 12230Sstevel@tonic-gate * The rtm_msglen, rtm_version and rtm_type fields in 12240Sstevel@tonic-gate * RTM_GET response are filled in by rts_fill_msg. 12250Sstevel@tonic-gate * 12260Sstevel@tonic-gate * rtm_addrs and rtm_flags are filled in based on what 12270Sstevel@tonic-gate * was requested and the state of the IREs looked up 12280Sstevel@tonic-gate * above. 12290Sstevel@tonic-gate * 12300Sstevel@tonic-gate * rtm_inits and rtm_rmx are filled in with metrics 12310Sstevel@tonic-gate * based on whether a parent IRE was found or not. 12320Sstevel@tonic-gate * 12330Sstevel@tonic-gate * TODO: rtm_index and rtm_use should probably be 12340Sstevel@tonic-gate * filled in with something resonable here and not just 12350Sstevel@tonic-gate * copied from the request. 12360Sstevel@tonic-gate */ 12370Sstevel@tonic-gate new_rtm->rtm_index = rtm->rtm_index; 12380Sstevel@tonic-gate new_rtm->rtm_pid = rtm->rtm_pid; 12390Sstevel@tonic-gate new_rtm->rtm_seq = rtm->rtm_seq; 12400Sstevel@tonic-gate new_rtm->rtm_use = rtm->rtm_use; 12410Sstevel@tonic-gate new_rtm->rtm_addrs = rtm_addrs; 12420Sstevel@tonic-gate new_rtm->rtm_flags = rtm_flags; 12430Sstevel@tonic-gate if (sire == NULL) 12440Sstevel@tonic-gate new_rtm->rtm_inits = rts_getmetrics(ire, &new_rtm->rtm_rmx); 12450Sstevel@tonic-gate else 12460Sstevel@tonic-gate new_rtm->rtm_inits = rts_getmetrics(sire, &new_rtm->rtm_rmx); 12471676Sjpk 12480Sstevel@tonic-gate return (new_mp); 12490Sstevel@tonic-gate } 12500Sstevel@tonic-gate 12510Sstevel@tonic-gate /* 12520Sstevel@tonic-gate * Fill the given if_data_t with interface statistics. 12530Sstevel@tonic-gate */ 12540Sstevel@tonic-gate static void 12551676Sjpk rts_getifdata(if_data_t *if_data, const ipif_t *ipif) 12560Sstevel@tonic-gate { 12570Sstevel@tonic-gate if_data->ifi_type = ipif->ipif_type; /* ethernet, tokenring, etc */ 12580Sstevel@tonic-gate if_data->ifi_addrlen = 0; /* media address length */ 12590Sstevel@tonic-gate if_data->ifi_hdrlen = 0; /* media header length */ 12600Sstevel@tonic-gate if_data->ifi_mtu = ipif->ipif_mtu; /* maximum transmission unit */ 12610Sstevel@tonic-gate if_data->ifi_metric = ipif->ipif_metric; /* metric (external only) */ 12620Sstevel@tonic-gate if_data->ifi_baudrate = 0; /* linespeed */ 12630Sstevel@tonic-gate 12640Sstevel@tonic-gate if_data->ifi_ipackets = 0; /* packets received on if */ 12650Sstevel@tonic-gate if_data->ifi_ierrors = 0; /* input errors on interface */ 12660Sstevel@tonic-gate if_data->ifi_opackets = 0; /* packets sent on interface */ 12670Sstevel@tonic-gate if_data->ifi_oerrors = 0; /* output errors on if */ 12680Sstevel@tonic-gate if_data->ifi_collisions = 0; /* collisions on csma if */ 12690Sstevel@tonic-gate if_data->ifi_ibytes = 0; /* total number received */ 12700Sstevel@tonic-gate if_data->ifi_obytes = 0; /* total number sent */ 12710Sstevel@tonic-gate if_data->ifi_imcasts = 0; /* multicast packets received */ 12720Sstevel@tonic-gate if_data->ifi_omcasts = 0; /* multicast packets sent */ 12730Sstevel@tonic-gate if_data->ifi_iqdrops = 0; /* dropped on input */ 12740Sstevel@tonic-gate if_data->ifi_noproto = 0; /* destined for unsupported */ 12750Sstevel@tonic-gate /* protocol. */ 12760Sstevel@tonic-gate } 12770Sstevel@tonic-gate 12780Sstevel@tonic-gate /* 12790Sstevel@tonic-gate * Set the metrics on a forwarding table route. 12800Sstevel@tonic-gate */ 12810Sstevel@tonic-gate static void 12820Sstevel@tonic-gate rts_setmetrics(ire_t *ire, uint_t which, rt_metrics_t *metrics) 12830Sstevel@tonic-gate { 12840Sstevel@tonic-gate clock_t rtt; 12850Sstevel@tonic-gate clock_t rtt_sd; 12860Sstevel@tonic-gate ipif_t *ipif; 12870Sstevel@tonic-gate ifrt_t *ifrt; 12880Sstevel@tonic-gate mblk_t *mp; 12890Sstevel@tonic-gate in6_addr_t gw_addr_v6; 12900Sstevel@tonic-gate 12910Sstevel@tonic-gate /* 12920Sstevel@tonic-gate * Bypass obtaining the lock and searching ipif_saved_ire_mp in the 12930Sstevel@tonic-gate * common case of no metrics. 12940Sstevel@tonic-gate */ 12950Sstevel@tonic-gate if (which == 0) 12960Sstevel@tonic-gate return; 12970Sstevel@tonic-gate ire->ire_uinfo.iulp_set = B_TRUE; 12980Sstevel@tonic-gate 12990Sstevel@tonic-gate /* 13000Sstevel@tonic-gate * iulp_rtt and iulp_rtt_sd are in milliseconds, but 4.4BSD-Lite2's 13010Sstevel@tonic-gate * <net/route.h> says: rmx_rtt and rmx_rttvar are stored as 13020Sstevel@tonic-gate * microseconds. 13030Sstevel@tonic-gate */ 13040Sstevel@tonic-gate if (which & RTV_RTT) 13050Sstevel@tonic-gate rtt = metrics->rmx_rtt / 1000; 13060Sstevel@tonic-gate if (which & RTV_RTTVAR) 13070Sstevel@tonic-gate rtt_sd = metrics->rmx_rttvar / 1000; 13080Sstevel@tonic-gate 13090Sstevel@tonic-gate /* 13100Sstevel@tonic-gate * Update the metrics in the IRE itself. 13110Sstevel@tonic-gate */ 13120Sstevel@tonic-gate mutex_enter(&ire->ire_lock); 13130Sstevel@tonic-gate if (which & RTV_MTU) 13140Sstevel@tonic-gate ire->ire_max_frag = metrics->rmx_mtu; 13150Sstevel@tonic-gate if (which & RTV_RTT) 13160Sstevel@tonic-gate ire->ire_uinfo.iulp_rtt = rtt; 13170Sstevel@tonic-gate if (which & RTV_SSTHRESH) 13180Sstevel@tonic-gate ire->ire_uinfo.iulp_ssthresh = metrics->rmx_ssthresh; 13190Sstevel@tonic-gate if (which & RTV_RTTVAR) 13200Sstevel@tonic-gate ire->ire_uinfo.iulp_rtt_sd = rtt_sd; 13210Sstevel@tonic-gate if (which & RTV_SPIPE) 13220Sstevel@tonic-gate ire->ire_uinfo.iulp_spipe = metrics->rmx_sendpipe; 13230Sstevel@tonic-gate if (which & RTV_RPIPE) 13240Sstevel@tonic-gate ire->ire_uinfo.iulp_rpipe = metrics->rmx_recvpipe; 13250Sstevel@tonic-gate mutex_exit(&ire->ire_lock); 13260Sstevel@tonic-gate 13270Sstevel@tonic-gate /* 13280Sstevel@tonic-gate * Search through the ifrt_t chain hanging off the IPIF in order to 13290Sstevel@tonic-gate * reflect the metric change there. 13300Sstevel@tonic-gate */ 13310Sstevel@tonic-gate ipif = ire->ire_ipif; 13320Sstevel@tonic-gate if (ipif == NULL) 13330Sstevel@tonic-gate return; 13340Sstevel@tonic-gate ASSERT((ipif->ipif_isv6 && ire->ire_ipversion == IPV6_VERSION) || 13350Sstevel@tonic-gate ((!ipif->ipif_isv6 && ire->ire_ipversion == IPV4_VERSION))); 13360Sstevel@tonic-gate if (ipif->ipif_isv6) { 13370Sstevel@tonic-gate mutex_enter(&ire->ire_lock); 13380Sstevel@tonic-gate gw_addr_v6 = ire->ire_gateway_addr_v6; 13390Sstevel@tonic-gate mutex_exit(&ire->ire_lock); 13400Sstevel@tonic-gate } 13410Sstevel@tonic-gate mutex_enter(&ipif->ipif_saved_ire_lock); 13420Sstevel@tonic-gate for (mp = ipif->ipif_saved_ire_mp; mp != NULL; mp = mp->b_cont) { 13430Sstevel@tonic-gate /* 13440Sstevel@tonic-gate * On a given ipif, the triple of address, gateway and mask is 13450Sstevel@tonic-gate * unique for each saved IRE (in the case of ordinary interface 13460Sstevel@tonic-gate * routes, the gateway address is all-zeroes). 13470Sstevel@tonic-gate */ 13480Sstevel@tonic-gate ifrt = (ifrt_t *)mp->b_rptr; 13490Sstevel@tonic-gate if (ipif->ipif_isv6) { 13500Sstevel@tonic-gate if (!IN6_ARE_ADDR_EQUAL(&ifrt->ifrt_v6addr, 13510Sstevel@tonic-gate &ire->ire_addr_v6) || 13520Sstevel@tonic-gate !IN6_ARE_ADDR_EQUAL(&ifrt->ifrt_v6gateway_addr, 13530Sstevel@tonic-gate &gw_addr_v6) || 13540Sstevel@tonic-gate !IN6_ARE_ADDR_EQUAL(&ifrt->ifrt_v6mask, 13550Sstevel@tonic-gate &ire->ire_mask_v6)) 13560Sstevel@tonic-gate continue; 13570Sstevel@tonic-gate } else { 13580Sstevel@tonic-gate if (ifrt->ifrt_addr != ire->ire_addr || 13590Sstevel@tonic-gate ifrt->ifrt_gateway_addr != ire->ire_gateway_addr || 13600Sstevel@tonic-gate ifrt->ifrt_mask != ire->ire_mask) 13610Sstevel@tonic-gate continue; 13620Sstevel@tonic-gate } 13630Sstevel@tonic-gate if (which & RTV_MTU) 13640Sstevel@tonic-gate ifrt->ifrt_max_frag = metrics->rmx_mtu; 13650Sstevel@tonic-gate if (which & RTV_RTT) 13660Sstevel@tonic-gate ifrt->ifrt_iulp_info.iulp_rtt = rtt; 13670Sstevel@tonic-gate if (which & RTV_SSTHRESH) { 13680Sstevel@tonic-gate ifrt->ifrt_iulp_info.iulp_ssthresh = 13690Sstevel@tonic-gate metrics->rmx_ssthresh; 13700Sstevel@tonic-gate } 13710Sstevel@tonic-gate if (which & RTV_RTTVAR) 13720Sstevel@tonic-gate ifrt->ifrt_iulp_info.iulp_rtt_sd = metrics->rmx_rttvar; 13730Sstevel@tonic-gate if (which & RTV_SPIPE) 13740Sstevel@tonic-gate ifrt->ifrt_iulp_info.iulp_spipe = metrics->rmx_sendpipe; 13750Sstevel@tonic-gate if (which & RTV_RPIPE) 13760Sstevel@tonic-gate ifrt->ifrt_iulp_info.iulp_rpipe = metrics->rmx_recvpipe; 13770Sstevel@tonic-gate break; 13780Sstevel@tonic-gate } 13790Sstevel@tonic-gate mutex_exit(&ipif->ipif_saved_ire_lock); 13800Sstevel@tonic-gate } 13810Sstevel@tonic-gate 13820Sstevel@tonic-gate /* 13830Sstevel@tonic-gate * Get the metrics from a forwarding table route. 13840Sstevel@tonic-gate */ 13850Sstevel@tonic-gate static int 13860Sstevel@tonic-gate rts_getmetrics(ire_t *ire, rt_metrics_t *metrics) 13870Sstevel@tonic-gate { 13880Sstevel@tonic-gate int metrics_set = 0; 13890Sstevel@tonic-gate 13900Sstevel@tonic-gate bzero(metrics, sizeof (rt_metrics_t)); 13910Sstevel@tonic-gate /* 13920Sstevel@tonic-gate * iulp_rtt and iulp_rtt_sd are in milliseconds, but 4.4BSD-Lite2's 13930Sstevel@tonic-gate * <net/route.h> says: rmx_rtt and rmx_rttvar are stored as 13940Sstevel@tonic-gate * microseconds. 13950Sstevel@tonic-gate */ 13960Sstevel@tonic-gate metrics->rmx_rtt = ire->ire_uinfo.iulp_rtt * 1000; 13970Sstevel@tonic-gate metrics_set |= RTV_RTT; 13980Sstevel@tonic-gate metrics->rmx_mtu = ire->ire_max_frag; 13990Sstevel@tonic-gate metrics_set |= RTV_MTU; 14000Sstevel@tonic-gate metrics->rmx_ssthresh = ire->ire_uinfo.iulp_ssthresh; 14010Sstevel@tonic-gate metrics_set |= RTV_SSTHRESH; 14020Sstevel@tonic-gate metrics->rmx_rttvar = ire->ire_uinfo.iulp_rtt_sd * 1000; 14030Sstevel@tonic-gate metrics_set |= RTV_RTTVAR; 14040Sstevel@tonic-gate metrics->rmx_sendpipe = ire->ire_uinfo.iulp_spipe; 14050Sstevel@tonic-gate metrics_set |= RTV_SPIPE; 14060Sstevel@tonic-gate metrics->rmx_recvpipe = ire->ire_uinfo.iulp_rpipe; 14070Sstevel@tonic-gate metrics_set |= RTV_RPIPE; 14080Sstevel@tonic-gate return (metrics_set); 14090Sstevel@tonic-gate } 14100Sstevel@tonic-gate 14110Sstevel@tonic-gate /* 14120Sstevel@tonic-gate * Takes a pointer to a routing message and extracts necessary info by looking 14130Sstevel@tonic-gate * at the rtm->rtm_addrs bits and store the requested sockaddrs in the pointers 14140Sstevel@tonic-gate * passed (all of which must be valid). 14150Sstevel@tonic-gate * 14160Sstevel@tonic-gate * The bitmask of sockaddrs actually found in the message is returned, or zero 14170Sstevel@tonic-gate * is returned in the case of an error. 14180Sstevel@tonic-gate */ 14190Sstevel@tonic-gate static int 14200Sstevel@tonic-gate rts_getaddrs(rt_msghdr_t *rtm, in6_addr_t *dst_addrp, in6_addr_t *gw_addrp, 14210Sstevel@tonic-gate in6_addr_t *net_maskp, in6_addr_t *authorp, in6_addr_t *if_addrp, 14220Sstevel@tonic-gate in6_addr_t *in_src_addrp, ushort_t *indexp, ushort_t *src_indexp, 14231676Sjpk sa_family_t *afp, tsol_rtsecattr_t *rtsecattr, int *error) 14240Sstevel@tonic-gate { 14250Sstevel@tonic-gate struct sockaddr *sa; 14260Sstevel@tonic-gate int i; 14270Sstevel@tonic-gate int addr_bits; 14280Sstevel@tonic-gate int length; 14290Sstevel@tonic-gate int found_addrs = 0; 14300Sstevel@tonic-gate caddr_t cp; 14310Sstevel@tonic-gate size_t size; 14320Sstevel@tonic-gate struct sockaddr_dl *sdl; 14330Sstevel@tonic-gate 14340Sstevel@tonic-gate *dst_addrp = ipv6_all_zeros; 14350Sstevel@tonic-gate *gw_addrp = ipv6_all_zeros; 14360Sstevel@tonic-gate *net_maskp = ipv6_all_zeros; 14370Sstevel@tonic-gate *authorp = ipv6_all_zeros; 14380Sstevel@tonic-gate *if_addrp = ipv6_all_zeros; 14390Sstevel@tonic-gate *in_src_addrp = ipv6_all_zeros; 14400Sstevel@tonic-gate *indexp = 0; 14410Sstevel@tonic-gate *src_indexp = 0; 14420Sstevel@tonic-gate *afp = AF_UNSPEC; 14431676Sjpk rtsecattr->rtsa_cnt = 0; 14441676Sjpk *error = 0; 14450Sstevel@tonic-gate 14460Sstevel@tonic-gate /* 14470Sstevel@tonic-gate * At present we handle only RTA_DST, RTA_GATEWAY, RTA_NETMASK, RTA_IFP, 14480Sstevel@tonic-gate * RTA_IFA and RTA_AUTHOR. The rest will be added as we need them. 14490Sstevel@tonic-gate */ 14500Sstevel@tonic-gate cp = (caddr_t)&rtm[1]; 14510Sstevel@tonic-gate length = rtm->rtm_msglen; 14520Sstevel@tonic-gate for (i = 0; (i < RTA_NUMBITS) && ((cp - (caddr_t)rtm) < length); i++) { 14530Sstevel@tonic-gate /* 14540Sstevel@tonic-gate * The address family we are working with starts out as 14550Sstevel@tonic-gate * AF_UNSPEC, but is set to the one specified with the 14560Sstevel@tonic-gate * destination address. 14570Sstevel@tonic-gate * 14580Sstevel@tonic-gate * If the "working" address family that has been set to 14590Sstevel@tonic-gate * something other than AF_UNSPEC, then the address family of 14600Sstevel@tonic-gate * subsequent sockaddrs must either be AF_UNSPEC (for 14610Sstevel@tonic-gate * compatibility with older programs) or must be the same as our 14620Sstevel@tonic-gate * "working" one. 14630Sstevel@tonic-gate * 14640Sstevel@tonic-gate * This code assumes that RTA_DST (1) comes first in the loop. 14650Sstevel@tonic-gate */ 14660Sstevel@tonic-gate sa = (struct sockaddr *)cp; 14670Sstevel@tonic-gate addr_bits = (rtm->rtm_addrs & (1 << i)); 14680Sstevel@tonic-gate if (addr_bits == 0) 14690Sstevel@tonic-gate continue; 14700Sstevel@tonic-gate switch (addr_bits) { 14710Sstevel@tonic-gate case RTA_DST: 14720Sstevel@tonic-gate size = rts_copyfromsockaddr(sa, dst_addrp); 14730Sstevel@tonic-gate *afp = sa->sa_family; 14740Sstevel@tonic-gate break; 14750Sstevel@tonic-gate case RTA_GATEWAY: 14760Sstevel@tonic-gate if (sa->sa_family != *afp && sa->sa_family != AF_UNSPEC) 14770Sstevel@tonic-gate return (0); 14780Sstevel@tonic-gate size = rts_copyfromsockaddr(sa, gw_addrp); 14790Sstevel@tonic-gate break; 14800Sstevel@tonic-gate case RTA_NETMASK: 14810Sstevel@tonic-gate if (sa->sa_family != *afp && sa->sa_family != AF_UNSPEC) 14820Sstevel@tonic-gate return (0); 14830Sstevel@tonic-gate size = rts_copyfromsockaddr(sa, net_maskp); 14840Sstevel@tonic-gate break; 14850Sstevel@tonic-gate case RTA_IFP: 14860Sstevel@tonic-gate if (sa->sa_family != AF_LINK && 14870Sstevel@tonic-gate sa->sa_family != AF_UNSPEC) 14880Sstevel@tonic-gate return (0); 14890Sstevel@tonic-gate sdl = (struct sockaddr_dl *)cp; 14900Sstevel@tonic-gate *indexp = sdl->sdl_index; 14910Sstevel@tonic-gate size = sizeof (struct sockaddr_dl); 14920Sstevel@tonic-gate break; 14930Sstevel@tonic-gate case RTA_SRC: 14940Sstevel@tonic-gate /* Source address of the incoming packet */ 14950Sstevel@tonic-gate size = rts_copyfromsockaddr(sa, in_src_addrp); 14960Sstevel@tonic-gate *afp = sa->sa_family; 14970Sstevel@tonic-gate break; 14980Sstevel@tonic-gate case RTA_SRCIFP: 14990Sstevel@tonic-gate /* Return incoming interface index pointer */ 15000Sstevel@tonic-gate if (sa->sa_family != AF_LINK && 15010Sstevel@tonic-gate sa->sa_family != AF_UNSPEC) 15020Sstevel@tonic-gate return (0); 15030Sstevel@tonic-gate sdl = (struct sockaddr_dl *)cp; 15040Sstevel@tonic-gate *src_indexp = sdl->sdl_index; 15050Sstevel@tonic-gate size = sizeof (struct sockaddr_dl); 15060Sstevel@tonic-gate break; 15070Sstevel@tonic-gate case RTA_IFA: 15080Sstevel@tonic-gate if (sa->sa_family != *afp && sa->sa_family != AF_UNSPEC) 15090Sstevel@tonic-gate return (0); 15100Sstevel@tonic-gate size = rts_copyfromsockaddr(sa, if_addrp); 15110Sstevel@tonic-gate break; 15120Sstevel@tonic-gate case RTA_AUTHOR: 15130Sstevel@tonic-gate if (sa->sa_family != *afp && sa->sa_family != AF_UNSPEC) 15140Sstevel@tonic-gate return (0); 15150Sstevel@tonic-gate size = rts_copyfromsockaddr(sa, authorp); 15160Sstevel@tonic-gate break; 15170Sstevel@tonic-gate default: 15180Sstevel@tonic-gate return (0); 15190Sstevel@tonic-gate } 15200Sstevel@tonic-gate if (size == 0) 15210Sstevel@tonic-gate return (0); 15220Sstevel@tonic-gate cp += size; 15230Sstevel@tonic-gate found_addrs |= addr_bits; 15240Sstevel@tonic-gate } 15251676Sjpk 15261676Sjpk /* 15271676Sjpk * Parse the routing message and look for any security- 15281676Sjpk * related attributes for the route. For each valid 15291676Sjpk * attribute, allocate/obtain the corresponding kernel 15301676Sjpk * route security attributes. 15311676Sjpk */ 15321676Sjpk *error = tsol_rtsa_init(rtm, rtsecattr, cp); 15331676Sjpk ASSERT(rtsecattr->rtsa_cnt <= TSOL_RTSA_REQUEST_MAX); 15341676Sjpk 15350Sstevel@tonic-gate return (found_addrs); 15360Sstevel@tonic-gate } 15370Sstevel@tonic-gate 15380Sstevel@tonic-gate /* 15390Sstevel@tonic-gate * Fills the message with the given info. 15400Sstevel@tonic-gate */ 15410Sstevel@tonic-gate static void 15420Sstevel@tonic-gate rts_fill_msg(int type, int rtm_addrs, ipaddr_t dst, ipaddr_t mask, 15430Sstevel@tonic-gate ipaddr_t gateway, ipaddr_t src_addr, ipaddr_t brd_addr, ipaddr_t author, 15441676Sjpk const ipif_t *ipif, mblk_t *mp, uint_t sacnt, const tsol_gc_t *gc) 15450Sstevel@tonic-gate { 15460Sstevel@tonic-gate rt_msghdr_t *rtm; 15470Sstevel@tonic-gate sin_t *sin; 15480Sstevel@tonic-gate size_t data_size, header_size; 15490Sstevel@tonic-gate uchar_t *cp; 15500Sstevel@tonic-gate int i; 15510Sstevel@tonic-gate 15520Sstevel@tonic-gate ASSERT(mp != NULL); 15531676Sjpk ASSERT(sacnt == 0 || gc != NULL); 15540Sstevel@tonic-gate /* 15550Sstevel@tonic-gate * First find the type of the message 15560Sstevel@tonic-gate * and its length. 15570Sstevel@tonic-gate */ 15580Sstevel@tonic-gate header_size = rts_header_msg_size(type); 15590Sstevel@tonic-gate /* 15600Sstevel@tonic-gate * Now find the size of the data 15610Sstevel@tonic-gate * that follows the message header. 15620Sstevel@tonic-gate */ 15631676Sjpk data_size = rts_data_msg_size(rtm_addrs, AF_INET, sacnt); 15640Sstevel@tonic-gate 15650Sstevel@tonic-gate rtm = (rt_msghdr_t *)mp->b_rptr; 15660Sstevel@tonic-gate mp->b_wptr = &mp->b_rptr[header_size]; 15670Sstevel@tonic-gate cp = mp->b_wptr; 15680Sstevel@tonic-gate bzero(cp, data_size); 15690Sstevel@tonic-gate for (i = 0; i < RTA_NUMBITS; i++) { 15700Sstevel@tonic-gate sin = (sin_t *)cp; 15710Sstevel@tonic-gate switch (rtm_addrs & (1 << i)) { 15720Sstevel@tonic-gate case RTA_DST: 15730Sstevel@tonic-gate sin->sin_addr.s_addr = dst; 15740Sstevel@tonic-gate sin->sin_family = AF_INET; 15750Sstevel@tonic-gate cp += sizeof (sin_t); 15760Sstevel@tonic-gate break; 15770Sstevel@tonic-gate case RTA_GATEWAY: 15780Sstevel@tonic-gate sin->sin_addr.s_addr = gateway; 15790Sstevel@tonic-gate sin->sin_family = AF_INET; 15800Sstevel@tonic-gate cp += sizeof (sin_t); 15810Sstevel@tonic-gate break; 15820Sstevel@tonic-gate case RTA_NETMASK: 15830Sstevel@tonic-gate sin->sin_addr.s_addr = mask; 15840Sstevel@tonic-gate sin->sin_family = AF_INET; 15850Sstevel@tonic-gate cp += sizeof (sin_t); 15860Sstevel@tonic-gate break; 15870Sstevel@tonic-gate case RTA_IFP: 15880Sstevel@tonic-gate cp += ill_dls_info((struct sockaddr_dl *)cp, ipif); 15890Sstevel@tonic-gate break; 15900Sstevel@tonic-gate case RTA_SRCIFP: 15910Sstevel@tonic-gate /* 15920Sstevel@tonic-gate * RTA_SRCIFP is not yet supported 15930Sstevel@tonic-gate * for RTM_GET and RTM_CHANGE 15940Sstevel@tonic-gate */ 15950Sstevel@tonic-gate break; 15960Sstevel@tonic-gate case RTA_IFA: 15970Sstevel@tonic-gate case RTA_SRC: 15980Sstevel@tonic-gate sin->sin_addr.s_addr = src_addr; 15990Sstevel@tonic-gate sin->sin_family = AF_INET; 16000Sstevel@tonic-gate cp += sizeof (sin_t); 16010Sstevel@tonic-gate break; 16020Sstevel@tonic-gate case RTA_AUTHOR: 16030Sstevel@tonic-gate sin->sin_addr.s_addr = author; 16040Sstevel@tonic-gate sin->sin_family = AF_INET; 16050Sstevel@tonic-gate cp += sizeof (sin_t); 16060Sstevel@tonic-gate break; 16070Sstevel@tonic-gate case RTA_BRD: 16080Sstevel@tonic-gate /* 16090Sstevel@tonic-gate * RTA_BRD is used typically to specify a point-to-point 16100Sstevel@tonic-gate * destination address. 16110Sstevel@tonic-gate */ 16120Sstevel@tonic-gate sin->sin_addr.s_addr = brd_addr; 16130Sstevel@tonic-gate sin->sin_family = AF_INET; 16140Sstevel@tonic-gate cp += sizeof (sin_t); 16150Sstevel@tonic-gate break; 16160Sstevel@tonic-gate } 16170Sstevel@tonic-gate } 16181676Sjpk 16191676Sjpk if (gc != NULL) { 16201676Sjpk rtm_ext_t *rtm_ext; 16211676Sjpk struct rtsa_s *rp_dst; 16221676Sjpk tsol_rtsecattr_t *rsap; 16231676Sjpk int i; 16241676Sjpk 16251676Sjpk ASSERT(gc->gc_grp != NULL); 16261676Sjpk ASSERT(RW_LOCK_HELD(&gc->gc_grp->gcgrp_rwlock)); 16271676Sjpk ASSERT(sacnt > 0); 16281676Sjpk 16291676Sjpk rtm_ext = (rtm_ext_t *)cp; 16301676Sjpk rtm_ext->rtmex_type = RTMEX_GATEWAY_SECATTR; 16311676Sjpk rtm_ext->rtmex_len = TSOL_RTSECATTR_SIZE(sacnt); 16321676Sjpk 16331676Sjpk rsap = (tsol_rtsecattr_t *)(rtm_ext + 1); 16341676Sjpk rsap->rtsa_cnt = sacnt; 16351676Sjpk rp_dst = rsap->rtsa_attr; 16361676Sjpk 16371676Sjpk for (i = 0; i < sacnt; i++, gc = gc->gc_next, rp_dst++) { 16381676Sjpk ASSERT(gc->gc_db != NULL); 16391676Sjpk bcopy(&gc->gc_db->gcdb_attr, rp_dst, sizeof (*rp_dst)); 16401676Sjpk } 16411676Sjpk cp = (uchar_t *)rp_dst; 16421676Sjpk } 16431676Sjpk 16440Sstevel@tonic-gate mp->b_wptr = cp; 16450Sstevel@tonic-gate mp->b_cont = NULL; 16460Sstevel@tonic-gate /* 16470Sstevel@tonic-gate * set the fields that are common to 16480Sstevel@tonic-gate * to different messages. 16490Sstevel@tonic-gate */ 16500Sstevel@tonic-gate rtm->rtm_msglen = (short)(header_size + data_size); 16510Sstevel@tonic-gate rtm->rtm_version = RTM_VERSION; 16520Sstevel@tonic-gate rtm->rtm_type = (uchar_t)type; 16530Sstevel@tonic-gate } 16540Sstevel@tonic-gate 16550Sstevel@tonic-gate /* 16560Sstevel@tonic-gate * Allocates and initializes a routing socket message. 16570Sstevel@tonic-gate */ 16580Sstevel@tonic-gate mblk_t * 16591676Sjpk rts_alloc_msg(int type, int rtm_addrs, sa_family_t af, uint_t sacnt) 16600Sstevel@tonic-gate { 16610Sstevel@tonic-gate size_t length; 16620Sstevel@tonic-gate mblk_t *mp; 16630Sstevel@tonic-gate 16641676Sjpk length = RTS_MSG_SIZE(type, rtm_addrs, af, sacnt); 16650Sstevel@tonic-gate mp = allocb(length, BPRI_MED); 16660Sstevel@tonic-gate if (mp == NULL) 16670Sstevel@tonic-gate return (mp); 16680Sstevel@tonic-gate bzero(mp->b_rptr, length); 16690Sstevel@tonic-gate return (mp); 16700Sstevel@tonic-gate } 16710Sstevel@tonic-gate 16720Sstevel@tonic-gate /* 16730Sstevel@tonic-gate * Returns the size of the routing 16740Sstevel@tonic-gate * socket message header size. 16750Sstevel@tonic-gate */ 16760Sstevel@tonic-gate size_t 16770Sstevel@tonic-gate rts_header_msg_size(int type) 16780Sstevel@tonic-gate { 16790Sstevel@tonic-gate switch (type) { 16800Sstevel@tonic-gate case RTM_DELADDR: 16810Sstevel@tonic-gate case RTM_NEWADDR: 16820Sstevel@tonic-gate return (sizeof (ifa_msghdr_t)); 16830Sstevel@tonic-gate case RTM_IFINFO: 16840Sstevel@tonic-gate return (sizeof (if_msghdr_t)); 16850Sstevel@tonic-gate default: 16860Sstevel@tonic-gate return (sizeof (rt_msghdr_t)); 16870Sstevel@tonic-gate } 16880Sstevel@tonic-gate } 16890Sstevel@tonic-gate 16900Sstevel@tonic-gate /* 16910Sstevel@tonic-gate * Returns the size of the message needed with the given rtm_addrs and family. 16920Sstevel@tonic-gate * 16930Sstevel@tonic-gate * It is assumed that all of the sockaddrs (with the exception of RTA_IFP) are 16940Sstevel@tonic-gate * of the same family (currently either AF_INET or AF_INET6). 16950Sstevel@tonic-gate */ 16960Sstevel@tonic-gate size_t 16971676Sjpk rts_data_msg_size(int rtm_addrs, sa_family_t af, uint_t sacnt) 16980Sstevel@tonic-gate { 16990Sstevel@tonic-gate int i; 17000Sstevel@tonic-gate size_t length = 0; 17010Sstevel@tonic-gate 17020Sstevel@tonic-gate for (i = 0; i < RTA_NUMBITS; i++) { 17030Sstevel@tonic-gate switch (rtm_addrs & (1 << i)) { 17040Sstevel@tonic-gate case RTA_IFP: 17050Sstevel@tonic-gate length += sizeof (struct sockaddr_dl); 17060Sstevel@tonic-gate break; 17070Sstevel@tonic-gate case RTA_DST: 17080Sstevel@tonic-gate case RTA_GATEWAY: 17090Sstevel@tonic-gate case RTA_NETMASK: 17100Sstevel@tonic-gate case RTA_SRC: 17110Sstevel@tonic-gate case RTA_SRCIFP: 17120Sstevel@tonic-gate case RTA_IFA: 17130Sstevel@tonic-gate case RTA_AUTHOR: 17140Sstevel@tonic-gate case RTA_BRD: 17150Sstevel@tonic-gate ASSERT(af == AF_INET || af == AF_INET6); 17160Sstevel@tonic-gate switch (af) { 17170Sstevel@tonic-gate case AF_INET: 17180Sstevel@tonic-gate length += sizeof (sin_t); 17190Sstevel@tonic-gate break; 17200Sstevel@tonic-gate case AF_INET6: 17210Sstevel@tonic-gate length += sizeof (sin6_t); 17220Sstevel@tonic-gate break; 17230Sstevel@tonic-gate } 17240Sstevel@tonic-gate break; 17250Sstevel@tonic-gate } 17260Sstevel@tonic-gate } 17271676Sjpk if (sacnt > 0) 17281676Sjpk length += sizeof (rtm_ext_t) + TSOL_RTSECATTR_SIZE(sacnt); 17291676Sjpk 17300Sstevel@tonic-gate return (length); 17310Sstevel@tonic-gate } 17320Sstevel@tonic-gate 17330Sstevel@tonic-gate /* 17340Sstevel@tonic-gate * This routine is called to generate a message to the routing 17350Sstevel@tonic-gate * socket indicating that a redirect has occured, a routing lookup 17360Sstevel@tonic-gate * has failed, or that a protocol has detected timeouts to a particular 17370Sstevel@tonic-gate * destination. This routine is called for message types RTM_LOSING, 17380Sstevel@tonic-gate * RTM_REDIRECT, and RTM_MISS. 17390Sstevel@tonic-gate */ 17400Sstevel@tonic-gate void 17410Sstevel@tonic-gate ip_rts_change(int type, ipaddr_t dst_addr, ipaddr_t gw_addr, ipaddr_t net_mask, 17420Sstevel@tonic-gate ipaddr_t source, ipaddr_t author, int flags, int error, int rtm_addrs) 17430Sstevel@tonic-gate { 17440Sstevel@tonic-gate rt_msghdr_t *rtm; 17450Sstevel@tonic-gate mblk_t *mp; 17460Sstevel@tonic-gate 17470Sstevel@tonic-gate if (rtm_addrs == 0) 17480Sstevel@tonic-gate return; 17491676Sjpk mp = rts_alloc_msg(type, rtm_addrs, AF_INET, 0); 17500Sstevel@tonic-gate if (mp == NULL) 17510Sstevel@tonic-gate return; 17520Sstevel@tonic-gate rts_fill_msg(type, rtm_addrs, dst_addr, net_mask, gw_addr, source, 0, 17531676Sjpk author, NULL, mp, 0, NULL); 17540Sstevel@tonic-gate rtm = (rt_msghdr_t *)mp->b_rptr; 17550Sstevel@tonic-gate rtm->rtm_flags = flags; 17560Sstevel@tonic-gate rtm->rtm_errno = error; 17570Sstevel@tonic-gate rtm->rtm_flags |= RTF_DONE; 17580Sstevel@tonic-gate rtm->rtm_addrs = rtm_addrs; 17590Sstevel@tonic-gate rts_queue_input(mp, NULL, AF_INET); 17600Sstevel@tonic-gate } 17610Sstevel@tonic-gate 17620Sstevel@tonic-gate /* 17630Sstevel@tonic-gate * This routine is called to generate a message to the routing 17640Sstevel@tonic-gate * socket indicating that the status of a network interface has changed. 17650Sstevel@tonic-gate * Message type generated RTM_IFINFO. 17660Sstevel@tonic-gate */ 17670Sstevel@tonic-gate void 17681676Sjpk ip_rts_ifmsg(const ipif_t *ipif) 17690Sstevel@tonic-gate { 17700Sstevel@tonic-gate if_msghdr_t *ifm; 17710Sstevel@tonic-gate mblk_t *mp; 17720Sstevel@tonic-gate sa_family_t af; 17730Sstevel@tonic-gate 17740Sstevel@tonic-gate /* 17750Sstevel@tonic-gate * This message should be generated only 17760Sstevel@tonic-gate * when the physical device is changing 17770Sstevel@tonic-gate * state. 17780Sstevel@tonic-gate */ 17790Sstevel@tonic-gate if (ipif->ipif_id != 0) 17800Sstevel@tonic-gate return; 17810Sstevel@tonic-gate if (ipif->ipif_isv6) { 17820Sstevel@tonic-gate af = AF_INET6; 17831676Sjpk mp = rts_alloc_msg(RTM_IFINFO, RTA_IFP, af, 0); 17840Sstevel@tonic-gate if (mp == NULL) 17850Sstevel@tonic-gate return; 17860Sstevel@tonic-gate rts_fill_msg_v6(RTM_IFINFO, RTA_IFP, &ipv6_all_zeros, 17870Sstevel@tonic-gate &ipv6_all_zeros, &ipv6_all_zeros, &ipv6_all_zeros, 17881676Sjpk &ipv6_all_zeros, &ipv6_all_zeros, ipif, mp, 0, NULL); 17890Sstevel@tonic-gate } else { 17900Sstevel@tonic-gate af = AF_INET; 17911676Sjpk mp = rts_alloc_msg(RTM_IFINFO, RTA_IFP, af, 0); 17920Sstevel@tonic-gate if (mp == NULL) 17930Sstevel@tonic-gate return; 17941676Sjpk rts_fill_msg(RTM_IFINFO, RTA_IFP, 0, 0, 0, 0, 0, 0, ipif, mp, 17951676Sjpk 0, NULL); 17960Sstevel@tonic-gate } 17970Sstevel@tonic-gate ifm = (if_msghdr_t *)mp->b_rptr; 17980Sstevel@tonic-gate ifm->ifm_index = ipif->ipif_ill->ill_phyint->phyint_ifindex; 17990Sstevel@tonic-gate ifm->ifm_flags = ipif->ipif_flags | ipif->ipif_ill->ill_flags | 18000Sstevel@tonic-gate ipif->ipif_ill->ill_phyint->phyint_flags; 18010Sstevel@tonic-gate rts_getifdata(&ifm->ifm_data, ipif); 18020Sstevel@tonic-gate ifm->ifm_addrs = RTA_IFP; 18030Sstevel@tonic-gate rts_queue_input(mp, NULL, af); 18040Sstevel@tonic-gate } 18050Sstevel@tonic-gate 18060Sstevel@tonic-gate /* 18070Sstevel@tonic-gate * This is called to generate messages to the routing socket 18080Sstevel@tonic-gate * indicating a network interface has had addresses associated with it. 18090Sstevel@tonic-gate * The structure of the code is based on the 4.4BSD-Lite2 <net/rtsock.c>. 18100Sstevel@tonic-gate */ 18110Sstevel@tonic-gate void 18121676Sjpk ip_rts_newaddrmsg(int cmd, int error, const ipif_t *ipif) 18130Sstevel@tonic-gate { 18140Sstevel@tonic-gate int pass; 18150Sstevel@tonic-gate int ncmd; 18160Sstevel@tonic-gate int rtm_addrs; 18170Sstevel@tonic-gate mblk_t *mp; 18180Sstevel@tonic-gate ifa_msghdr_t *ifam; 18190Sstevel@tonic-gate rt_msghdr_t *rtm; 18200Sstevel@tonic-gate sa_family_t af; 18210Sstevel@tonic-gate 18220Sstevel@tonic-gate if (ipif->ipif_isv6) 18230Sstevel@tonic-gate af = AF_INET6; 18240Sstevel@tonic-gate else 18250Sstevel@tonic-gate af = AF_INET; 18260Sstevel@tonic-gate /* 18270Sstevel@tonic-gate * If the request is DELETE, send RTM_DELETE and RTM_DELADDR. 18280Sstevel@tonic-gate * if the request is ADD, send RTM_NEWADDR and RTM_ADD. 18290Sstevel@tonic-gate */ 18300Sstevel@tonic-gate for (pass = 1; pass < 3; pass++) { 18310Sstevel@tonic-gate if ((cmd == RTM_ADD && pass == 1) || 18320Sstevel@tonic-gate (cmd == RTM_DELETE && pass == 2)) { 18330Sstevel@tonic-gate ncmd = ((cmd == RTM_ADD) ? RTM_NEWADDR : RTM_DELADDR); 18340Sstevel@tonic-gate 18352263Ssommerfe rtm_addrs = (RTA_IFA | RTA_NETMASK | RTA_BRD | RTA_IFP); 18361676Sjpk mp = rts_alloc_msg(ncmd, rtm_addrs, af, 0); 18370Sstevel@tonic-gate if (mp == NULL) 18380Sstevel@tonic-gate continue; 18390Sstevel@tonic-gate switch (af) { 18400Sstevel@tonic-gate case AF_INET: 18410Sstevel@tonic-gate rts_fill_msg(ncmd, rtm_addrs, 0, 18420Sstevel@tonic-gate ipif->ipif_net_mask, 0, ipif->ipif_lcl_addr, 18432263Ssommerfe ipif->ipif_pp_dst_addr, 0, ipif, mp, 18441676Sjpk 0, NULL); 18450Sstevel@tonic-gate break; 18460Sstevel@tonic-gate case AF_INET6: 18470Sstevel@tonic-gate rts_fill_msg_v6(ncmd, rtm_addrs, 18480Sstevel@tonic-gate &ipv6_all_zeros, &ipif->ipif_v6net_mask, 18490Sstevel@tonic-gate &ipv6_all_zeros, &ipif->ipif_v6lcl_addr, 18500Sstevel@tonic-gate &ipif->ipif_v6pp_dst_addr, &ipv6_all_zeros, 18512263Ssommerfe ipif, mp, 0, NULL); 18520Sstevel@tonic-gate break; 18530Sstevel@tonic-gate } 18540Sstevel@tonic-gate ifam = (ifa_msghdr_t *)mp->b_rptr; 18550Sstevel@tonic-gate ifam->ifam_index = 18560Sstevel@tonic-gate ipif->ipif_ill->ill_phyint->phyint_ifindex; 18570Sstevel@tonic-gate ifam->ifam_metric = ipif->ipif_metric; 18580Sstevel@tonic-gate ifam->ifam_flags = ((cmd == RTM_ADD) ? RTF_UP : 0); 18590Sstevel@tonic-gate ifam->ifam_addrs = rtm_addrs; 18600Sstevel@tonic-gate rts_queue_input(mp, NULL, af); 18610Sstevel@tonic-gate } 18620Sstevel@tonic-gate if ((cmd == RTM_ADD && pass == 2) || 18630Sstevel@tonic-gate (cmd == RTM_DELETE && pass == 1)) { 18640Sstevel@tonic-gate rtm_addrs = (RTA_DST | RTA_NETMASK); 18651676Sjpk mp = rts_alloc_msg(cmd, rtm_addrs, af, 0); 18660Sstevel@tonic-gate if (mp == NULL) 18670Sstevel@tonic-gate continue; 18680Sstevel@tonic-gate switch (af) { 18690Sstevel@tonic-gate case AF_INET: 18700Sstevel@tonic-gate rts_fill_msg(cmd, rtm_addrs, 18710Sstevel@tonic-gate ipif->ipif_lcl_addr, ipif->ipif_net_mask, 0, 18721676Sjpk 0, 0, 0, NULL, mp, 0, NULL); 18730Sstevel@tonic-gate break; 18740Sstevel@tonic-gate case AF_INET6: 18750Sstevel@tonic-gate rts_fill_msg_v6(cmd, rtm_addrs, 18760Sstevel@tonic-gate &ipif->ipif_v6lcl_addr, 18770Sstevel@tonic-gate &ipif->ipif_v6net_mask, &ipv6_all_zeros, 18780Sstevel@tonic-gate &ipv6_all_zeros, &ipv6_all_zeros, 18791676Sjpk &ipv6_all_zeros, NULL, mp, 0, NULL); 18800Sstevel@tonic-gate break; 18810Sstevel@tonic-gate } 18820Sstevel@tonic-gate rtm = (rt_msghdr_t *)mp->b_rptr; 18830Sstevel@tonic-gate rtm->rtm_index = 18840Sstevel@tonic-gate ipif->ipif_ill->ill_phyint->phyint_ifindex; 18850Sstevel@tonic-gate rtm->rtm_flags = ((cmd == RTM_ADD) ? RTF_UP : 0); 18860Sstevel@tonic-gate rtm->rtm_errno = error; 18870Sstevel@tonic-gate if (error == 0) 18880Sstevel@tonic-gate rtm->rtm_flags |= RTF_DONE; 18890Sstevel@tonic-gate rtm->rtm_addrs = rtm_addrs; 18900Sstevel@tonic-gate rts_queue_input(mp, NULL, af); 18910Sstevel@tonic-gate } 18920Sstevel@tonic-gate } 18930Sstevel@tonic-gate } 18940Sstevel@tonic-gate 18950Sstevel@tonic-gate /* 18960Sstevel@tonic-gate * Based on the address family specified in a sockaddr, copy the address field 18970Sstevel@tonic-gate * into an in6_addr_t. 18980Sstevel@tonic-gate * 18990Sstevel@tonic-gate * In the case of AF_UNSPEC, we assume the family is actually AF_INET for 19000Sstevel@tonic-gate * compatibility with programs that leave the family cleared in the sockaddr. 19010Sstevel@tonic-gate * Callers of rts_copyfromsockaddr should check the family themselves if they 19020Sstevel@tonic-gate * wish to verify its value. 19030Sstevel@tonic-gate * 19040Sstevel@tonic-gate * In the case of AF_INET6, a check is made to ensure that address is not an 19050Sstevel@tonic-gate * IPv4-mapped address. 19060Sstevel@tonic-gate */ 19070Sstevel@tonic-gate size_t 19080Sstevel@tonic-gate rts_copyfromsockaddr(struct sockaddr *sa, in6_addr_t *addrp) 19090Sstevel@tonic-gate { 19100Sstevel@tonic-gate switch (sa->sa_family) { 19110Sstevel@tonic-gate case AF_INET: 19120Sstevel@tonic-gate case AF_UNSPEC: 19130Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(((sin_t *)sa)->sin_addr.s_addr, addrp); 19140Sstevel@tonic-gate return (sizeof (sin_t)); 19150Sstevel@tonic-gate case AF_INET6: 19160Sstevel@tonic-gate *addrp = ((sin6_t *)sa)->sin6_addr; 19170Sstevel@tonic-gate if (IN6_IS_ADDR_V4MAPPED(addrp)) 19180Sstevel@tonic-gate return (0); 19190Sstevel@tonic-gate return (sizeof (sin6_t)); 19200Sstevel@tonic-gate default: 19210Sstevel@tonic-gate return (0); 19220Sstevel@tonic-gate } 19230Sstevel@tonic-gate } 1924