10Sstevel@tonic-gate /* 2*8485SPeter.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/ddi.h> 490Sstevel@tonic-gate #include <sys/cmn_err.h> 500Sstevel@tonic-gate #include <sys/debug.h> 510Sstevel@tonic-gate #include <sys/policy.h> 520Sstevel@tonic-gate #include <sys/zone.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 #include <sys/strsun.h> 580Sstevel@tonic-gate #include <net/if.h> 590Sstevel@tonic-gate #include <net/route.h> 600Sstevel@tonic-gate #include <netinet/in.h> 610Sstevel@tonic-gate #include <net/if_dl.h> 620Sstevel@tonic-gate #include <netinet/ip6.h> 630Sstevel@tonic-gate 640Sstevel@tonic-gate #include <inet/common.h> 650Sstevel@tonic-gate #include <inet/ip.h> 660Sstevel@tonic-gate #include <inet/ip6.h> 670Sstevel@tonic-gate #include <inet/ip_if.h> 680Sstevel@tonic-gate #include <inet/ip_ire.h> 692535Ssangeeta #include <inet/ip_ftable.h> 700Sstevel@tonic-gate #include <inet/ip_rts.h> 710Sstevel@tonic-gate 720Sstevel@tonic-gate #include <inet/ipclassifier.h> 730Sstevel@tonic-gate 741676Sjpk #include <sys/tsol/tndb.h> 751676Sjpk #include <sys/tsol/tnet.h> 761676Sjpk 771676Sjpk #define RTS_MSG_SIZE(type, rtm_addrs, af, sacnt) \ 781676Sjpk (rts_data_msg_size(rtm_addrs, af, sacnt) + rts_header_msg_size(type)) 790Sstevel@tonic-gate 800Sstevel@tonic-gate static size_t rts_copyfromsockaddr(struct sockaddr *sa, in6_addr_t *addrp); 810Sstevel@tonic-gate static void rts_fill_msg(int type, int rtm_addrs, ipaddr_t dst, 820Sstevel@tonic-gate ipaddr_t mask, ipaddr_t gateway, ipaddr_t src_addr, ipaddr_t brd_addr, 831676Sjpk ipaddr_t author, const ipif_t *ipif, mblk_t *mp, uint_t, const tsol_gc_t *); 840Sstevel@tonic-gate static int rts_getaddrs(rt_msghdr_t *rtm, in6_addr_t *dst_addrp, 850Sstevel@tonic-gate in6_addr_t *gw_addrp, in6_addr_t *net_maskp, in6_addr_t *authorp, 860Sstevel@tonic-gate in6_addr_t *if_addrp, in6_addr_t *src_addrp, ushort_t *indexp, 874823Sseb sa_family_t *afp, tsol_rtsecattr_t *rtsecattr, int *error); 881676Sjpk static void rts_getifdata(if_data_t *if_data, const ipif_t *ipif); 890Sstevel@tonic-gate static int rts_getmetrics(ire_t *ire, rt_metrics_t *metrics); 900Sstevel@tonic-gate static mblk_t *rts_rtmget(mblk_t *mp, ire_t *ire, ire_t *sire, 910Sstevel@tonic-gate sa_family_t af); 920Sstevel@tonic-gate static void rts_setmetrics(ire_t *ire, uint_t which, rt_metrics_t *metrics); 930Sstevel@tonic-gate static void ip_rts_request_retry(ipsq_t *, queue_t *q, mblk_t *mp, void *); 940Sstevel@tonic-gate 950Sstevel@tonic-gate /* 96*8485SPeter.Memishian@Sun.COM * Send `mp' to all eligible routing queues. A queue is ineligible if: 970Sstevel@tonic-gate * 98*8485SPeter.Memishian@Sun.COM * 1. SO_USELOOPBACK is off and it is not the originating queue. 99*8485SPeter.Memishian@Sun.COM * 2. RTAW_UNDER_IPMP is on and RTSQ_UNDER_IPMP is clear in `flags'. 100*8485SPeter.Memishian@Sun.COM * 3. RTAW_UNDER_IPMP is off and RTSQ_NORMAL is clear in `flags'. 101*8485SPeter.Memishian@Sun.COM * 4. It is not the same address family as `af', and `af' isn't AF_UNSPEC. 1020Sstevel@tonic-gate */ 1030Sstevel@tonic-gate void 104*8485SPeter.Memishian@Sun.COM rts_queue_input(mblk_t *mp, conn_t *o_connp, sa_family_t af, uint_t flags, 105*8485SPeter.Memishian@Sun.COM ip_stack_t *ipst) 1060Sstevel@tonic-gate { 1070Sstevel@tonic-gate mblk_t *mp1; 1080Sstevel@tonic-gate conn_t *connp, *next_connp; 1090Sstevel@tonic-gate 110*8485SPeter.Memishian@Sun.COM /* 111*8485SPeter.Memishian@Sun.COM * Since we don't have an ill_t here, RTSQ_DEFAULT must already be 112*8485SPeter.Memishian@Sun.COM * resolved to one or more of RTSQ_NORMAL|RTSQ_UNDER_IPMP by now. 113*8485SPeter.Memishian@Sun.COM */ 114*8485SPeter.Memishian@Sun.COM ASSERT(!(flags & RTSQ_DEFAULT)); 115*8485SPeter.Memishian@Sun.COM 1163448Sdh155122 mutex_enter(&ipst->ips_rts_clients->connf_lock); 1173448Sdh155122 connp = ipst->ips_rts_clients->connf_head; 1180Sstevel@tonic-gate 119*8485SPeter.Memishian@Sun.COM for (; connp != NULL; connp = next_connp) { 120*8485SPeter.Memishian@Sun.COM next_connp = connp->conn_next; 121*8485SPeter.Memishian@Sun.COM 1220Sstevel@tonic-gate /* 1230Sstevel@tonic-gate * If there was a family specified when this routing socket was 1240Sstevel@tonic-gate * created and it doesn't match the family of the message to 1250Sstevel@tonic-gate * copy, then continue. 1260Sstevel@tonic-gate */ 1270Sstevel@tonic-gate if ((connp->conn_proto != AF_UNSPEC) && 128*8485SPeter.Memishian@Sun.COM (connp->conn_proto != af)) 1290Sstevel@tonic-gate continue; 130*8485SPeter.Memishian@Sun.COM 131*8485SPeter.Memishian@Sun.COM /* 132*8485SPeter.Memishian@Sun.COM * Queue the message only if the conn_t and flags match. 133*8485SPeter.Memishian@Sun.COM */ 134*8485SPeter.Memishian@Sun.COM if (connp->conn_rtaware & RTAW_UNDER_IPMP) { 135*8485SPeter.Memishian@Sun.COM if (!(flags & RTSQ_UNDER_IPMP)) 136*8485SPeter.Memishian@Sun.COM continue; 137*8485SPeter.Memishian@Sun.COM } else { 138*8485SPeter.Memishian@Sun.COM if (!(flags & RTSQ_NORMAL)) 139*8485SPeter.Memishian@Sun.COM continue; 1400Sstevel@tonic-gate } 141*8485SPeter.Memishian@Sun.COM 1420Sstevel@tonic-gate /* 1430Sstevel@tonic-gate * For the originating queue, we only copy the message upstream 1440Sstevel@tonic-gate * if loopback is set. For others reading on the routing 1450Sstevel@tonic-gate * socket, we check if there is room upstream for a copy of the 1460Sstevel@tonic-gate * message. 1470Sstevel@tonic-gate */ 1488348SEric.Yu@Sun.COM if ((o_connp == connp) && connp->conn_loopback == 0) { 149*8485SPeter.Memishian@Sun.COM connp = connp->conn_next; 150*8485SPeter.Memishian@Sun.COM continue; 1510Sstevel@tonic-gate } 1520Sstevel@tonic-gate CONN_INC_REF(connp); 1533448Sdh155122 mutex_exit(&ipst->ips_rts_clients->connf_lock); 1545240Snordmark /* Pass to rts_input */ 1558348SEric.Yu@Sun.COM if ((IPCL_IS_NONSTR(connp) && !PROTO_FLOW_CNTRLD(connp))|| 1568348SEric.Yu@Sun.COM (!IPCL_IS_NONSTR(connp) && 1578348SEric.Yu@Sun.COM canputnext(CONNP_TO_RQ(connp)))) { 1580Sstevel@tonic-gate mp1 = dupmsg(mp); 1590Sstevel@tonic-gate if (mp1 == NULL) 1600Sstevel@tonic-gate mp1 = copymsg(mp); 1610Sstevel@tonic-gate if (mp1 != NULL) 1625240Snordmark (connp->conn_recv)(connp, mp1, NULL); 1630Sstevel@tonic-gate } 1640Sstevel@tonic-gate 1653448Sdh155122 mutex_enter(&ipst->ips_rts_clients->connf_lock); 166*8485SPeter.Memishian@Sun.COM /* reload next_connp since conn_next may have changed */ 1670Sstevel@tonic-gate next_connp = connp->conn_next; 1680Sstevel@tonic-gate CONN_DEC_REF(connp); 1690Sstevel@tonic-gate } 1703448Sdh155122 mutex_exit(&ipst->ips_rts_clients->connf_lock); 1710Sstevel@tonic-gate freemsg(mp); 1720Sstevel@tonic-gate } 1730Sstevel@tonic-gate 1740Sstevel@tonic-gate /* 1750Sstevel@tonic-gate * Takes an ire and sends an ack to all the routing sockets. This 1760Sstevel@tonic-gate * routine is used 1770Sstevel@tonic-gate * - when a route is created/deleted through the ioctl interface. 1780Sstevel@tonic-gate * - when ire_expire deletes a stale redirect 1790Sstevel@tonic-gate */ 1800Sstevel@tonic-gate void 1813448Sdh155122 ip_rts_rtmsg(int type, ire_t *ire, int error, ip_stack_t *ipst) 1820Sstevel@tonic-gate { 1830Sstevel@tonic-gate mblk_t *mp; 1840Sstevel@tonic-gate rt_msghdr_t *rtm; 1850Sstevel@tonic-gate int rtm_addrs = (RTA_DST | RTA_NETMASK | RTA_GATEWAY); 1860Sstevel@tonic-gate sa_family_t af; 1870Sstevel@tonic-gate in6_addr_t gw_addr_v6; 1880Sstevel@tonic-gate 1890Sstevel@tonic-gate if (ire == NULL) 1900Sstevel@tonic-gate return; 1910Sstevel@tonic-gate ASSERT(ire->ire_ipversion == IPV4_VERSION || 1920Sstevel@tonic-gate ire->ire_ipversion == IPV6_VERSION); 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate if (ire->ire_flags & RTF_SETSRC) 1950Sstevel@tonic-gate rtm_addrs |= RTA_SRC; 1960Sstevel@tonic-gate 1970Sstevel@tonic-gate switch (ire->ire_ipversion) { 1980Sstevel@tonic-gate case IPV4_VERSION: 1990Sstevel@tonic-gate af = AF_INET; 2001676Sjpk mp = rts_alloc_msg(type, rtm_addrs, af, 0); 2010Sstevel@tonic-gate if (mp == NULL) 2020Sstevel@tonic-gate return; 2030Sstevel@tonic-gate rts_fill_msg(type, rtm_addrs, ire->ire_addr, ire->ire_mask, 2041676Sjpk ire->ire_gateway_addr, ire->ire_src_addr, 0, 0, NULL, mp, 2051676Sjpk 0, NULL); 2060Sstevel@tonic-gate break; 2070Sstevel@tonic-gate case IPV6_VERSION: 2080Sstevel@tonic-gate af = AF_INET6; 2091676Sjpk mp = rts_alloc_msg(type, rtm_addrs, af, 0); 2100Sstevel@tonic-gate if (mp == NULL) 2110Sstevel@tonic-gate return; 2120Sstevel@tonic-gate mutex_enter(&ire->ire_lock); 2130Sstevel@tonic-gate gw_addr_v6 = ire->ire_gateway_addr_v6; 2140Sstevel@tonic-gate mutex_exit(&ire->ire_lock); 2150Sstevel@tonic-gate rts_fill_msg_v6(type, rtm_addrs, &ire->ire_addr_v6, 2160Sstevel@tonic-gate &ire->ire_mask_v6, &gw_addr_v6, 2170Sstevel@tonic-gate &ire->ire_src_addr_v6, &ipv6_all_zeros, &ipv6_all_zeros, 2181676Sjpk NULL, mp, 0, NULL); 2190Sstevel@tonic-gate break; 2200Sstevel@tonic-gate } 2210Sstevel@tonic-gate rtm = (rt_msghdr_t *)mp->b_rptr; 2220Sstevel@tonic-gate mp->b_wptr = (uchar_t *)&mp->b_rptr[rtm->rtm_msglen]; 2230Sstevel@tonic-gate rtm->rtm_addrs = rtm_addrs; 2240Sstevel@tonic-gate rtm->rtm_flags = ire->ire_flags; 2250Sstevel@tonic-gate if (error != 0) 2260Sstevel@tonic-gate rtm->rtm_errno = error; 2270Sstevel@tonic-gate else 2280Sstevel@tonic-gate rtm->rtm_flags |= RTF_DONE; 229*8485SPeter.Memishian@Sun.COM rts_queue_input(mp, NULL, af, RTSQ_ALL, ipst); 2300Sstevel@tonic-gate } 2310Sstevel@tonic-gate 2320Sstevel@tonic-gate /* ARGSUSED */ 2330Sstevel@tonic-gate static void 2340Sstevel@tonic-gate ip_rts_request_retry(ipsq_t *dummy_sq, queue_t *q, mblk_t *mp, void *dummy) 2350Sstevel@tonic-gate { 2360Sstevel@tonic-gate (void) ip_rts_request(q, mp, DB_CRED(mp)); 2370Sstevel@tonic-gate } 2380Sstevel@tonic-gate 2390Sstevel@tonic-gate /* 2405240Snordmark * This is a call from the RTS module 2415240Snordmark * indicating that this is a Routing Socket 2425240Snordmark * Stream. Insert this conn_t in routing 2435240Snordmark * socket client list. 2445240Snordmark */ 2455240Snordmark void 2465240Snordmark ip_rts_register(conn_t *connp) 2475240Snordmark { 2485240Snordmark ip_stack_t *ipst = connp->conn_netstack->netstack_ip; 2495240Snordmark 2505240Snordmark connp->conn_loopback = 1; 2515240Snordmark ipcl_hash_insert_wildcard(ipst->ips_rts_clients, connp); 2525240Snordmark } 2535240Snordmark 2545240Snordmark /* 2555240Snordmark * This is a call from the RTS module indicating that it is closing. 2565240Snordmark */ 2575240Snordmark void 2585240Snordmark ip_rts_unregister(conn_t *connp) 2595240Snordmark { 2605240Snordmark ipcl_hash_remove(connp); 2615240Snordmark } 2625240Snordmark 2635240Snordmark /* 2640Sstevel@tonic-gate * Processes requests received on a routing socket. It extracts all the 2650Sstevel@tonic-gate * arguments and calls the appropriate function to process the request. 2660Sstevel@tonic-gate * 2674823Sseb * RTA_SRC bit flag requests are sent by 'route -setsrc'. 2680Sstevel@tonic-gate * 2690Sstevel@tonic-gate * In general, this function does not consume the message supplied but rather 2700Sstevel@tonic-gate * sends the message upstream with an appropriate UNIX errno. 2710Sstevel@tonic-gate * 2720Sstevel@tonic-gate * We may need to restart this operation if the ipif cannot be looked up 2730Sstevel@tonic-gate * due to an exclusive operation that is currently in progress. The restart 2740Sstevel@tonic-gate * entry point is ip_rts_request_retry. While the request is enqueud in the 2750Sstevel@tonic-gate * ipsq the ioctl could be aborted and the conn close. To ensure that we don't 2760Sstevel@tonic-gate * have stale conn pointers, ip_wput_ioctl does a conn refhold. This is 2770Sstevel@tonic-gate * released at the completion of the rts ioctl at the end of this function 2780Sstevel@tonic-gate * by calling CONN_OPER_PENDING_DONE or when the ioctl is aborted and 2790Sstevel@tonic-gate * conn close occurs in conn_ioctl_cleanup. 2800Sstevel@tonic-gate */ 2810Sstevel@tonic-gate int 2828348SEric.Yu@Sun.COM ip_rts_request_common(queue_t *q, mblk_t *mp, conn_t *connp, cred_t *ioc_cr) 2830Sstevel@tonic-gate { 2840Sstevel@tonic-gate rt_msghdr_t *rtm = NULL; 2850Sstevel@tonic-gate in6_addr_t dst_addr_v6; 2860Sstevel@tonic-gate in6_addr_t src_addr_v6; 2870Sstevel@tonic-gate in6_addr_t gw_addr_v6; 2880Sstevel@tonic-gate in6_addr_t net_mask_v6; 2890Sstevel@tonic-gate in6_addr_t author_v6; 2900Sstevel@tonic-gate in6_addr_t if_addr_v6; 2910Sstevel@tonic-gate mblk_t *mp1, *ioc_mp = mp; 2920Sstevel@tonic-gate ire_t *ire = NULL; 2930Sstevel@tonic-gate ire_t *sire = NULL; 2940Sstevel@tonic-gate int error = 0; 2950Sstevel@tonic-gate int match_flags = MATCH_IRE_DSTONLY; 2962304Swy83408 int match_flags_local = MATCH_IRE_TYPE | MATCH_IRE_GW; 2970Sstevel@tonic-gate int found_addrs; 2980Sstevel@tonic-gate sa_family_t af; 2990Sstevel@tonic-gate ipaddr_t dst_addr; 3000Sstevel@tonic-gate ipaddr_t gw_addr; 3010Sstevel@tonic-gate ipaddr_t src_addr; 3020Sstevel@tonic-gate ipaddr_t net_mask; 3030Sstevel@tonic-gate ushort_t index; 3040Sstevel@tonic-gate ipif_t *ipif = NULL; 3050Sstevel@tonic-gate ipif_t *tmp_ipif = NULL; 3060Sstevel@tonic-gate IOCP iocp = (IOCP)mp->b_rptr; 3071676Sjpk boolean_t gcgrp_xtraref = B_FALSE; 3081676Sjpk tsol_gcgrp_addr_t ga; 3091676Sjpk tsol_rtsecattr_t rtsecattr; 3101676Sjpk struct rtsa_s *rtsap = NULL; 3111676Sjpk tsol_gcgrp_t *gcgrp = NULL; 3121676Sjpk tsol_gc_t *gc = NULL; 3132601Swy83408 ts_label_t *tsl = NULL; 3142733Snordmark zoneid_t zoneid; 3153448Sdh155122 ip_stack_t *ipst; 3160Sstevel@tonic-gate 3170Sstevel@tonic-gate ip1dbg(("ip_rts_request: mp is %x\n", DB_TYPE(mp))); 3180Sstevel@tonic-gate 3192733Snordmark zoneid = connp->conn_zoneid; 3203448Sdh155122 ipst = connp->conn_netstack->netstack_ip; 3210Sstevel@tonic-gate 3220Sstevel@tonic-gate ASSERT(mp->b_cont != NULL); 3230Sstevel@tonic-gate /* ioc_mp holds mp */ 3240Sstevel@tonic-gate mp = mp->b_cont; 3250Sstevel@tonic-gate 3260Sstevel@tonic-gate /* 3270Sstevel@tonic-gate * The Routing Socket data starts on 3280Sstevel@tonic-gate * next block. If there is no next block 3290Sstevel@tonic-gate * this is an indication from routing module 3300Sstevel@tonic-gate * that it is a routing socket stream queue. 3315315Snordmark * We need to support that for compatibility with SDP since 3325315Snordmark * it has a contract private interface to use IP_IOC_RTS_REQUEST. 3330Sstevel@tonic-gate */ 3345315Snordmark if (mp->b_cont == NULL) { 3355315Snordmark /* 3365315Snordmark * This is a message from SDP 3375315Snordmark * indicating that this is a Routing Socket 3385315Snordmark * Stream. Insert this conn_t in routing 3395315Snordmark * socket client list. 3405315Snordmark */ 3415315Snordmark connp->conn_loopback = 1; 3425315Snordmark ipcl_hash_insert_wildcard(ipst->ips_rts_clients, connp); 3435315Snordmark goto done; 3445315Snordmark } 3455240Snordmark mp1 = dupmsg(mp->b_cont); 3465240Snordmark if (mp1 == NULL) { 3475240Snordmark error = ENOBUFS; 3480Sstevel@tonic-gate goto done; 3490Sstevel@tonic-gate } 3505240Snordmark mp = mp1; 3515240Snordmark 3520Sstevel@tonic-gate if (mp->b_cont != NULL && !pullupmsg(mp, -1)) { 3530Sstevel@tonic-gate freemsg(mp); 3540Sstevel@tonic-gate error = EINVAL; 3550Sstevel@tonic-gate goto done; 3560Sstevel@tonic-gate } 3570Sstevel@tonic-gate if ((mp->b_wptr - mp->b_rptr) < sizeof (rt_msghdr_t)) { 3580Sstevel@tonic-gate freemsg(mp); 3590Sstevel@tonic-gate error = EINVAL; 3600Sstevel@tonic-gate goto done; 3610Sstevel@tonic-gate } 3620Sstevel@tonic-gate 3630Sstevel@tonic-gate /* 3640Sstevel@tonic-gate * Check the routing message for basic consistency including the 3650Sstevel@tonic-gate * version number and that the number of octets written is the same 3660Sstevel@tonic-gate * as specified by the rtm_msglen field. 3670Sstevel@tonic-gate * 3680Sstevel@tonic-gate * At this point, an error can be delivered back via rtm_errno. 3690Sstevel@tonic-gate */ 3700Sstevel@tonic-gate rtm = (rt_msghdr_t *)mp->b_rptr; 3710Sstevel@tonic-gate if ((mp->b_wptr - mp->b_rptr) != rtm->rtm_msglen) { 3720Sstevel@tonic-gate error = EINVAL; 3730Sstevel@tonic-gate goto done; 3740Sstevel@tonic-gate } 3750Sstevel@tonic-gate if (rtm->rtm_version != RTM_VERSION) { 3760Sstevel@tonic-gate error = EPROTONOSUPPORT; 3770Sstevel@tonic-gate goto done; 3780Sstevel@tonic-gate } 3790Sstevel@tonic-gate 3800Sstevel@tonic-gate /* Only allow RTM_GET or RTM_RESOLVE for unprivileged process */ 3810Sstevel@tonic-gate if (rtm->rtm_type != RTM_GET && 3820Sstevel@tonic-gate rtm->rtm_type != RTM_RESOLVE && 3830Sstevel@tonic-gate (ioc_cr == NULL || 3843448Sdh155122 secpolicy_ip_config(ioc_cr, B_FALSE) != 0)) { 3850Sstevel@tonic-gate error = EPERM; 3860Sstevel@tonic-gate goto done; 3870Sstevel@tonic-gate } 3880Sstevel@tonic-gate 3890Sstevel@tonic-gate found_addrs = rts_getaddrs(rtm, &dst_addr_v6, &gw_addr_v6, &net_mask_v6, 3904823Sseb &author_v6, &if_addr_v6, &src_addr_v6, &index, &af, &rtsecattr, 3914823Sseb &error); 3921676Sjpk 3931676Sjpk if (error != 0) 3941676Sjpk goto done; 3951676Sjpk 3960Sstevel@tonic-gate if ((found_addrs & RTA_DST) == 0) { 3970Sstevel@tonic-gate error = EINVAL; 3980Sstevel@tonic-gate goto done; 3990Sstevel@tonic-gate } 4000Sstevel@tonic-gate 4010Sstevel@tonic-gate /* 4020Sstevel@tonic-gate * Based on the address family of the destination address, determine 4030Sstevel@tonic-gate * the destination, gateway and netmask and return the appropriate error 4040Sstevel@tonic-gate * if an unknown address family was specified (following the errno 4050Sstevel@tonic-gate * values that 4.4BSD-Lite2 returns.) 4060Sstevel@tonic-gate */ 4070Sstevel@tonic-gate switch (af) { 4080Sstevel@tonic-gate case AF_INET: 4090Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&dst_addr_v6, dst_addr); 4100Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&src_addr_v6, src_addr); 4110Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&gw_addr_v6, gw_addr); 4120Sstevel@tonic-gate if (((found_addrs & RTA_NETMASK) == 0) || 4130Sstevel@tonic-gate (rtm->rtm_flags & RTF_HOST)) 4140Sstevel@tonic-gate net_mask = IP_HOST_MASK; 4150Sstevel@tonic-gate else 4160Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&net_mask_v6, net_mask); 4170Sstevel@tonic-gate break; 4180Sstevel@tonic-gate case AF_INET6: 4190Sstevel@tonic-gate if (((found_addrs & RTA_NETMASK) == 0) || 4200Sstevel@tonic-gate (rtm->rtm_flags & RTF_HOST)) 4210Sstevel@tonic-gate net_mask_v6 = ipv6_all_ones; 4220Sstevel@tonic-gate break; 4230Sstevel@tonic-gate default: 4240Sstevel@tonic-gate /* 4250Sstevel@tonic-gate * These errno values are meant to be compatible with 4260Sstevel@tonic-gate * 4.4BSD-Lite2 for the given message types. 4270Sstevel@tonic-gate */ 4280Sstevel@tonic-gate switch (rtm->rtm_type) { 4290Sstevel@tonic-gate case RTM_ADD: 4300Sstevel@tonic-gate case RTM_DELETE: 4310Sstevel@tonic-gate error = ESRCH; 4320Sstevel@tonic-gate goto done; 4330Sstevel@tonic-gate case RTM_GET: 4340Sstevel@tonic-gate case RTM_CHANGE: 4350Sstevel@tonic-gate error = EAFNOSUPPORT; 4360Sstevel@tonic-gate goto done; 4370Sstevel@tonic-gate default: 4380Sstevel@tonic-gate error = EOPNOTSUPP; 4390Sstevel@tonic-gate goto done; 4400Sstevel@tonic-gate } 4410Sstevel@tonic-gate } 4420Sstevel@tonic-gate 4430Sstevel@tonic-gate /* 4440Sstevel@tonic-gate * At this point, the address family must be something known. 4450Sstevel@tonic-gate */ 4460Sstevel@tonic-gate ASSERT(af == AF_INET || af == AF_INET6); 4470Sstevel@tonic-gate 4480Sstevel@tonic-gate if (index != 0) { 4490Sstevel@tonic-gate ill_t *ill; 450*8485SPeter.Memishian@Sun.COM lookup: 4510Sstevel@tonic-gate /* 4520Sstevel@tonic-gate * IPC must be refheld somewhere in ip_wput_nondata or 4530Sstevel@tonic-gate * ip_wput_ioctl etc... and cleaned up if ioctl is killed. 4540Sstevel@tonic-gate * If ILL_CHANGING the request is queued in the ipsq. 4550Sstevel@tonic-gate */ 4560Sstevel@tonic-gate ill = ill_lookup_on_ifindex(index, af == AF_INET6, 4573448Sdh155122 CONNP_TO_WQ(connp), ioc_mp, ip_rts_request_retry, &error, 4583448Sdh155122 ipst); 4590Sstevel@tonic-gate if (ill == NULL) { 4600Sstevel@tonic-gate if (error != EINPROGRESS) 4610Sstevel@tonic-gate error = EINVAL; 4620Sstevel@tonic-gate goto done; 4630Sstevel@tonic-gate } 4640Sstevel@tonic-gate 465*8485SPeter.Memishian@Sun.COM /* 466*8485SPeter.Memishian@Sun.COM * Since all interfaces in an IPMP group must be equivalent, 467*8485SPeter.Memishian@Sun.COM * we prevent changes to a specific underlying interface's 468*8485SPeter.Memishian@Sun.COM * routing configuration. However, for backward compatibility, 469*8485SPeter.Memishian@Sun.COM * we intepret a request to add a route on an underlying 470*8485SPeter.Memishian@Sun.COM * interface as a request to add a route on its IPMP interface. 471*8485SPeter.Memishian@Sun.COM */ 472*8485SPeter.Memishian@Sun.COM if (IS_UNDER_IPMP(ill)) { 473*8485SPeter.Memishian@Sun.COM switch (rtm->rtm_type) { 474*8485SPeter.Memishian@Sun.COM case RTM_CHANGE: 475*8485SPeter.Memishian@Sun.COM case RTM_DELETE: 476*8485SPeter.Memishian@Sun.COM ill_refrele(ill); 477*8485SPeter.Memishian@Sun.COM error = EINVAL; 478*8485SPeter.Memishian@Sun.COM goto done; 479*8485SPeter.Memishian@Sun.COM case RTM_ADD: 480*8485SPeter.Memishian@Sun.COM index = ipmp_ill_get_ipmp_ifindex(ill); 481*8485SPeter.Memishian@Sun.COM ill_refrele(ill); 482*8485SPeter.Memishian@Sun.COM if (index == 0) { 483*8485SPeter.Memishian@Sun.COM error = EINVAL; 484*8485SPeter.Memishian@Sun.COM goto done; 485*8485SPeter.Memishian@Sun.COM } 486*8485SPeter.Memishian@Sun.COM goto lookup; 487*8485SPeter.Memishian@Sun.COM } 488*8485SPeter.Memishian@Sun.COM } 489*8485SPeter.Memishian@Sun.COM 4900Sstevel@tonic-gate ipif = ipif_get_next_ipif(NULL, ill); 4910Sstevel@tonic-gate ill_refrele(ill); 4920Sstevel@tonic-gate match_flags |= MATCH_IRE_ILL; 4930Sstevel@tonic-gate } 4940Sstevel@tonic-gate 4950Sstevel@tonic-gate /* 4960Sstevel@tonic-gate * If a netmask was supplied in the message, then subsequent route 4970Sstevel@tonic-gate * lookups will attempt to match on the netmask as well. 4980Sstevel@tonic-gate */ 4990Sstevel@tonic-gate if ((found_addrs & RTA_NETMASK) != 0) 5000Sstevel@tonic-gate match_flags |= MATCH_IRE_MASK; 5010Sstevel@tonic-gate 5021676Sjpk /* 5031676Sjpk * We only process any passed-in route security attributes for 5042304Swy83408 * either RTM_ADD or RTM_CHANGE message; We overload them 5052304Swy83408 * to do an RTM_GET as a different label; ignore otherwise. 5061676Sjpk */ 5072304Swy83408 if (rtm->rtm_type == RTM_ADD || rtm->rtm_type == RTM_CHANGE || 5082304Swy83408 rtm->rtm_type == RTM_GET) { 5091676Sjpk ASSERT(rtsecattr.rtsa_cnt <= TSOL_RTSA_REQUEST_MAX); 5101676Sjpk if (rtsecattr.rtsa_cnt > 0) 5111676Sjpk rtsap = &rtsecattr.rtsa_attr[0]; 5121676Sjpk } 5131676Sjpk 5140Sstevel@tonic-gate switch (rtm->rtm_type) { 5150Sstevel@tonic-gate case RTM_ADD: 5160Sstevel@tonic-gate /* if we are adding a route, gateway is a must */ 5170Sstevel@tonic-gate if ((found_addrs & RTA_GATEWAY) == 0) { 5180Sstevel@tonic-gate error = EINVAL; 5190Sstevel@tonic-gate goto done; 5200Sstevel@tonic-gate } 5210Sstevel@tonic-gate 5220Sstevel@tonic-gate /* Multirouting does not support net routes. */ 5230Sstevel@tonic-gate if ((rtm->rtm_flags & (RTF_MULTIRT | RTF_HOST)) == 5240Sstevel@tonic-gate RTF_MULTIRT) { 5250Sstevel@tonic-gate error = EADDRNOTAVAIL; 5260Sstevel@tonic-gate goto done; 5270Sstevel@tonic-gate } 5280Sstevel@tonic-gate 5290Sstevel@tonic-gate /* 5300Sstevel@tonic-gate * Multirouting and user-specified source addresses 5310Sstevel@tonic-gate * do not support interface based routing. 5320Sstevel@tonic-gate * Assigning a source address to an interface based 5330Sstevel@tonic-gate * route is achievable by plumbing a new ipif and 5340Sstevel@tonic-gate * setting up the interface route via this ipif, 5350Sstevel@tonic-gate * though. 5360Sstevel@tonic-gate */ 5370Sstevel@tonic-gate if (rtm->rtm_flags & (RTF_MULTIRT | RTF_SETSRC)) { 5380Sstevel@tonic-gate if ((rtm->rtm_flags & RTF_GATEWAY) == 0) { 5390Sstevel@tonic-gate error = EADDRNOTAVAIL; 5400Sstevel@tonic-gate goto done; 5410Sstevel@tonic-gate } 5420Sstevel@tonic-gate } 5430Sstevel@tonic-gate 5440Sstevel@tonic-gate switch (af) { 5450Sstevel@tonic-gate case AF_INET: 5460Sstevel@tonic-gate if (src_addr != INADDR_ANY) { 5470Sstevel@tonic-gate /* 5480Sstevel@tonic-gate * The RTF_SETSRC flag is present, check that 5490Sstevel@tonic-gate * the supplied src address is not the loopback 5500Sstevel@tonic-gate * address. This would produce martian packets. 5510Sstevel@tonic-gate */ 5520Sstevel@tonic-gate if (src_addr == htonl(INADDR_LOOPBACK)) { 5530Sstevel@tonic-gate error = EINVAL; 5540Sstevel@tonic-gate goto done; 5550Sstevel@tonic-gate } 5560Sstevel@tonic-gate /* 5570Sstevel@tonic-gate * Also check that the supplied address is a 5580Sstevel@tonic-gate * valid, local one. 5590Sstevel@tonic-gate */ 5600Sstevel@tonic-gate tmp_ipif = ipif_lookup_addr(src_addr, NULL, 5610Sstevel@tonic-gate ALL_ZONES, CONNP_TO_WQ(connp), ioc_mp, 5623448Sdh155122 ip_rts_request_retry, &error, ipst); 5630Sstevel@tonic-gate if (tmp_ipif == NULL) { 5640Sstevel@tonic-gate if (error != EINPROGRESS) 5650Sstevel@tonic-gate error = EADDRNOTAVAIL; 5660Sstevel@tonic-gate goto done; 5670Sstevel@tonic-gate } 5680Sstevel@tonic-gate if (!(tmp_ipif->ipif_flags & IPIF_UP) || 5690Sstevel@tonic-gate (tmp_ipif->ipif_flags & 5700Sstevel@tonic-gate (IPIF_NOLOCAL | IPIF_ANYCAST))) { 5710Sstevel@tonic-gate error = EINVAL; 5720Sstevel@tonic-gate goto done; 5730Sstevel@tonic-gate } 5740Sstevel@tonic-gate } else { 5750Sstevel@tonic-gate /* 5760Sstevel@tonic-gate * The RTF_SETSRC modifier must be associated 5770Sstevel@tonic-gate * to a non-null source address. 5780Sstevel@tonic-gate */ 5790Sstevel@tonic-gate if (rtm->rtm_flags & RTF_SETSRC) { 5800Sstevel@tonic-gate error = EINVAL; 5810Sstevel@tonic-gate goto done; 5820Sstevel@tonic-gate } 5830Sstevel@tonic-gate } 5840Sstevel@tonic-gate 5851676Sjpk error = ip_rt_add(dst_addr, net_mask, gw_addr, src_addr, 5864823Sseb rtm->rtm_flags, ipif, &ire, B_FALSE, 5878348SEric.Yu@Sun.COM WR(q), ioc_mp, ip_rts_request_retry, 5883448Sdh155122 rtsap, ipst); 5890Sstevel@tonic-gate if (ipif != NULL) 5900Sstevel@tonic-gate ASSERT(!MUTEX_HELD(&ipif->ipif_ill->ill_lock)); 5910Sstevel@tonic-gate break; 5920Sstevel@tonic-gate case AF_INET6: 5930Sstevel@tonic-gate if (!IN6_IS_ADDR_UNSPECIFIED(&src_addr_v6)) { 5940Sstevel@tonic-gate /* 5950Sstevel@tonic-gate * The RTF_SETSRC flag is present, check that 5960Sstevel@tonic-gate * the supplied src address is not the loopback 5970Sstevel@tonic-gate * address. This would produce martian packets. 5980Sstevel@tonic-gate */ 5990Sstevel@tonic-gate if (IN6_IS_ADDR_LOOPBACK(&src_addr_v6)) { 6000Sstevel@tonic-gate error = EINVAL; 6010Sstevel@tonic-gate goto done; 6020Sstevel@tonic-gate } 6030Sstevel@tonic-gate /* 6040Sstevel@tonic-gate * Also check that the supplied address is a 6050Sstevel@tonic-gate * valid, local one. 6060Sstevel@tonic-gate */ 6070Sstevel@tonic-gate tmp_ipif = ipif_lookup_addr_v6(&src_addr_v6, 6080Sstevel@tonic-gate NULL, ALL_ZONES, CONNP_TO_WQ(connp), ioc_mp, 6093448Sdh155122 ip_rts_request_retry, &error, ipst); 6100Sstevel@tonic-gate if (tmp_ipif == NULL) { 6110Sstevel@tonic-gate if (error != EINPROGRESS) 6120Sstevel@tonic-gate error = EADDRNOTAVAIL; 6130Sstevel@tonic-gate goto done; 6140Sstevel@tonic-gate } 6150Sstevel@tonic-gate 6160Sstevel@tonic-gate if (!(tmp_ipif->ipif_flags & IPIF_UP) || 6170Sstevel@tonic-gate (tmp_ipif->ipif_flags & 6180Sstevel@tonic-gate (IPIF_NOLOCAL | IPIF_ANYCAST))) { 6190Sstevel@tonic-gate error = EINVAL; 6200Sstevel@tonic-gate goto done; 6210Sstevel@tonic-gate } 6220Sstevel@tonic-gate 6230Sstevel@tonic-gate error = ip_rt_add_v6(&dst_addr_v6, &net_mask_v6, 6240Sstevel@tonic-gate &gw_addr_v6, &src_addr_v6, rtm->rtm_flags, 6258348SEric.Yu@Sun.COM ipif, &ire, WR(q), ioc_mp, 6263448Sdh155122 ip_rts_request_retry, rtsap, ipst); 6270Sstevel@tonic-gate break; 6280Sstevel@tonic-gate } 6290Sstevel@tonic-gate /* 6300Sstevel@tonic-gate * The RTF_SETSRC modifier must be associated 6310Sstevel@tonic-gate * to a non-null source address. 6320Sstevel@tonic-gate */ 6330Sstevel@tonic-gate if (rtm->rtm_flags & RTF_SETSRC) { 6340Sstevel@tonic-gate error = EINVAL; 6350Sstevel@tonic-gate goto done; 6360Sstevel@tonic-gate } 6370Sstevel@tonic-gate error = ip_rt_add_v6(&dst_addr_v6, &net_mask_v6, 6380Sstevel@tonic-gate &gw_addr_v6, NULL, rtm->rtm_flags, 6398348SEric.Yu@Sun.COM ipif, &ire, WR(q), ioc_mp, 6403448Sdh155122 ip_rts_request_retry, rtsap, ipst); 6410Sstevel@tonic-gate if (ipif != NULL) 6420Sstevel@tonic-gate ASSERT(!MUTEX_HELD(&ipif->ipif_ill->ill_lock)); 6430Sstevel@tonic-gate break; 6440Sstevel@tonic-gate } 6450Sstevel@tonic-gate if (error != 0) 6460Sstevel@tonic-gate goto done; 6470Sstevel@tonic-gate ASSERT(ire != NULL); 6480Sstevel@tonic-gate rts_setmetrics(ire, rtm->rtm_inits, &rtm->rtm_rmx); 6490Sstevel@tonic-gate break; 6500Sstevel@tonic-gate case RTM_DELETE: 6510Sstevel@tonic-gate /* if we are deleting a route, gateway is a must */ 6520Sstevel@tonic-gate if ((found_addrs & RTA_GATEWAY) == 0) { 6530Sstevel@tonic-gate error = EINVAL; 6540Sstevel@tonic-gate goto done; 6550Sstevel@tonic-gate } 6560Sstevel@tonic-gate /* 6570Sstevel@tonic-gate * The RTF_SETSRC modifier does not make sense 6580Sstevel@tonic-gate * when deleting a route. 6590Sstevel@tonic-gate */ 6600Sstevel@tonic-gate if (rtm->rtm_flags & RTF_SETSRC) { 6610Sstevel@tonic-gate error = EINVAL; 6620Sstevel@tonic-gate goto done; 6630Sstevel@tonic-gate } 6640Sstevel@tonic-gate 6650Sstevel@tonic-gate switch (af) { 6660Sstevel@tonic-gate case AF_INET: 6670Sstevel@tonic-gate error = ip_rt_delete(dst_addr, net_mask, gw_addr, 6684823Sseb found_addrs, rtm->rtm_flags, ipif, B_FALSE, 6698348SEric.Yu@Sun.COM WR(q), ioc_mp, ip_rts_request_retry, ipst); 6700Sstevel@tonic-gate break; 6710Sstevel@tonic-gate case AF_INET6: 6720Sstevel@tonic-gate error = ip_rt_delete_v6(&dst_addr_v6, &net_mask_v6, 6730Sstevel@tonic-gate &gw_addr_v6, found_addrs, rtm->rtm_flags, ipif, 6748348SEric.Yu@Sun.COM WR(q), ioc_mp, ip_rts_request_retry, ipst); 6750Sstevel@tonic-gate break; 6760Sstevel@tonic-gate } 6770Sstevel@tonic-gate break; 6780Sstevel@tonic-gate case RTM_GET: 6790Sstevel@tonic-gate case RTM_CHANGE: 6800Sstevel@tonic-gate /* 6810Sstevel@tonic-gate * In the case of RTM_GET, the forwarding table should be 6820Sstevel@tonic-gate * searched recursively with default being matched if the 6830Sstevel@tonic-gate * specific route doesn't exist. Also, if a gateway was 6840Sstevel@tonic-gate * specified then the gateway address must also be matched. 6850Sstevel@tonic-gate * 6860Sstevel@tonic-gate * In the case of RTM_CHANGE, the gateway address (if supplied) 6870Sstevel@tonic-gate * is the new gateway address so matching on the gateway address 6880Sstevel@tonic-gate * is not done. This can lead to ambiguity when looking up the 6890Sstevel@tonic-gate * route to change as usually only the destination (and netmask, 6900Sstevel@tonic-gate * if supplied) is used for the lookup. However if a RTA_IFP 6910Sstevel@tonic-gate * sockaddr is also supplied, it can disambiguate which route to 6920Sstevel@tonic-gate * change provided the ambigous routes are tied to distinct 6930Sstevel@tonic-gate * ill's (or interface indices). If the routes are not tied to 6940Sstevel@tonic-gate * any particular interfaces (for example, with traditional 6950Sstevel@tonic-gate * gateway routes), then a RTA_IFP sockaddr will be of no use as 6960Sstevel@tonic-gate * it won't match any such routes. 6970Sstevel@tonic-gate * RTA_SRC is not supported for RTM_GET and RTM_CHANGE, 6980Sstevel@tonic-gate * except when RTM_CHANGE is combined to RTF_SETSRC. 6990Sstevel@tonic-gate */ 7000Sstevel@tonic-gate if (((found_addrs & RTA_SRC) != 0) && 7010Sstevel@tonic-gate ((rtm->rtm_type == RTM_GET) || 7020Sstevel@tonic-gate !(rtm->rtm_flags & RTF_SETSRC))) { 7030Sstevel@tonic-gate error = EOPNOTSUPP; 7040Sstevel@tonic-gate goto done; 7050Sstevel@tonic-gate } 7060Sstevel@tonic-gate 7070Sstevel@tonic-gate if (rtm->rtm_type == RTM_GET) { 7080Sstevel@tonic-gate match_flags |= 7092304Swy83408 (MATCH_IRE_DEFAULT | MATCH_IRE_RECURSIVE | 7102304Swy83408 MATCH_IRE_SECATTR); 7112304Swy83408 match_flags_local |= MATCH_IRE_SECATTR; 7120Sstevel@tonic-gate if ((found_addrs & RTA_GATEWAY) != 0) 7130Sstevel@tonic-gate match_flags |= MATCH_IRE_GW; 7142601Swy83408 if (ioc_cr) 7152601Swy83408 tsl = crgetlabel(ioc_cr); 7162304Swy83408 if (rtsap != NULL) { 7172304Swy83408 if (rtsa_validate(rtsap) != 0) { 7182304Swy83408 error = EINVAL; 7192304Swy83408 goto done; 7202304Swy83408 } 7212601Swy83408 if (tsl != NULL && 7222601Swy83408 crgetzoneid(ioc_cr) != GLOBAL_ZONEID && 7232304Swy83408 (tsl->tsl_doi != rtsap->rtsa_doi || 7242304Swy83408 !bldominates(&tsl->tsl_label, 7252304Swy83408 &rtsap->rtsa_slrange.lower_bound))) { 7262304Swy83408 error = EPERM; 7272304Swy83408 goto done; 7282304Swy83408 } 7292304Swy83408 tsl = labelalloc( 7302304Swy83408 &rtsap->rtsa_slrange.lower_bound, 7312304Swy83408 rtsap->rtsa_doi, KM_NOSLEEP); 7322304Swy83408 } 7330Sstevel@tonic-gate } 7340Sstevel@tonic-gate if (rtm->rtm_type == RTM_CHANGE) { 7350Sstevel@tonic-gate if ((found_addrs & RTA_GATEWAY) && 7360Sstevel@tonic-gate (rtm->rtm_flags & RTF_SETSRC)) { 7370Sstevel@tonic-gate /* 7380Sstevel@tonic-gate * Do not want to change the gateway, 7390Sstevel@tonic-gate * but rather the source address. 7400Sstevel@tonic-gate */ 7410Sstevel@tonic-gate match_flags |= MATCH_IRE_GW; 7420Sstevel@tonic-gate } 7430Sstevel@tonic-gate } 7440Sstevel@tonic-gate 7450Sstevel@tonic-gate /* 7460Sstevel@tonic-gate * If the netmask is all ones (either as supplied or as derived 7470Sstevel@tonic-gate * above), then first check for an IRE_LOOPBACK or 7480Sstevel@tonic-gate * IRE_LOCAL entry. 7490Sstevel@tonic-gate * 7500Sstevel@tonic-gate * If we didn't check for or find an IRE_LOOPBACK or IRE_LOCAL 7510Sstevel@tonic-gate * entry, then look in the forwarding table. 7520Sstevel@tonic-gate */ 7530Sstevel@tonic-gate switch (af) { 7540Sstevel@tonic-gate case AF_INET: 7550Sstevel@tonic-gate if (net_mask == IP_HOST_MASK) { 7560Sstevel@tonic-gate ire = ire_ctable_lookup(dst_addr, gw_addr, 7572733Snordmark IRE_LOCAL | IRE_LOOPBACK, NULL, zoneid, 7583448Sdh155122 tsl, match_flags_local, ipst); 7592733Snordmark /* 7602733Snordmark * If we found an IRE_LOCAL, make sure 7612733Snordmark * it is one that would be used by this 7622733Snordmark * zone to send packets. 7632733Snordmark */ 7642733Snordmark if (ire != NULL && 7652733Snordmark ire->ire_type == IRE_LOCAL && 7663448Sdh155122 ipst->ips_ip_restrict_interzone_loopback && 7672733Snordmark !ire_local_ok_across_zones(ire, 7683448Sdh155122 zoneid, &dst_addr, tsl, ipst)) { 7692733Snordmark ire_refrele(ire); 7702733Snordmark ire = NULL; 7712733Snordmark } 7720Sstevel@tonic-gate } 7730Sstevel@tonic-gate if (ire == NULL) { 7740Sstevel@tonic-gate ire = ire_ftable_lookup(dst_addr, net_mask, 7752733Snordmark gw_addr, 0, ipif, &sire, zoneid, 0, 7763448Sdh155122 tsl, match_flags, ipst); 7770Sstevel@tonic-gate } 7780Sstevel@tonic-gate break; 7790Sstevel@tonic-gate case AF_INET6: 7800Sstevel@tonic-gate if (IN6_ARE_ADDR_EQUAL(&net_mask_v6, &ipv6_all_ones)) { 7810Sstevel@tonic-gate ire = ire_ctable_lookup_v6(&dst_addr_v6, 7820Sstevel@tonic-gate &gw_addr_v6, IRE_LOCAL | IRE_LOOPBACK, NULL, 7833448Sdh155122 zoneid, tsl, match_flags_local, ipst); 7842733Snordmark /* 7852733Snordmark * If we found an IRE_LOCAL, make sure 7862733Snordmark * it is one that would be used by this 7872733Snordmark * zone to send packets. 7882733Snordmark */ 7892733Snordmark if (ire != NULL && 7902733Snordmark ire->ire_type == IRE_LOCAL && 7913448Sdh155122 ipst->ips_ip_restrict_interzone_loopback && 7922733Snordmark !ire_local_ok_across_zones(ire, 7933448Sdh155122 zoneid, (void *)&dst_addr_v6, tsl, ipst)) { 7942733Snordmark ire_refrele(ire); 7952733Snordmark ire = NULL; 7962733Snordmark } 7970Sstevel@tonic-gate } 7980Sstevel@tonic-gate if (ire == NULL) { 7990Sstevel@tonic-gate ire = ire_ftable_lookup_v6(&dst_addr_v6, 8000Sstevel@tonic-gate &net_mask_v6, &gw_addr_v6, 0, ipif, &sire, 8013448Sdh155122 zoneid, 0, tsl, match_flags, ipst); 8020Sstevel@tonic-gate } 8030Sstevel@tonic-gate break; 8040Sstevel@tonic-gate } 8052304Swy83408 if (tsl != NULL && tsl != crgetlabel(ioc_cr)) 8062304Swy83408 label_rele(tsl); 8070Sstevel@tonic-gate 8080Sstevel@tonic-gate if (ire == NULL) { 8090Sstevel@tonic-gate error = ESRCH; 8100Sstevel@tonic-gate goto done; 8110Sstevel@tonic-gate } 8120Sstevel@tonic-gate /* we know the IRE before we come here */ 8130Sstevel@tonic-gate switch (rtm->rtm_type) { 8140Sstevel@tonic-gate case RTM_GET: 8150Sstevel@tonic-gate mp1 = rts_rtmget(mp, ire, sire, af); 8160Sstevel@tonic-gate if (mp1 == NULL) { 8170Sstevel@tonic-gate error = ENOBUFS; 8180Sstevel@tonic-gate goto done; 8190Sstevel@tonic-gate } 8200Sstevel@tonic-gate freemsg(mp); 8210Sstevel@tonic-gate mp = mp1; 8220Sstevel@tonic-gate rtm = (rt_msghdr_t *)mp->b_rptr; 8230Sstevel@tonic-gate break; 8240Sstevel@tonic-gate case RTM_CHANGE: 8250Sstevel@tonic-gate /* 8260Sstevel@tonic-gate * Do not allow to the multirouting state of a route 8270Sstevel@tonic-gate * to be changed. This aims to prevent undesirable 8280Sstevel@tonic-gate * stages where both multirt and non-multirt routes 8290Sstevel@tonic-gate * for the same destination are declared. 8300Sstevel@tonic-gate */ 8310Sstevel@tonic-gate if ((ire->ire_flags & RTF_MULTIRT) != 8320Sstevel@tonic-gate (rtm->rtm_flags & RTF_MULTIRT)) { 8330Sstevel@tonic-gate error = EINVAL; 8340Sstevel@tonic-gate goto done; 8350Sstevel@tonic-gate } 8360Sstevel@tonic-gate /* 8370Sstevel@tonic-gate * Note that we do not need to do 8380Sstevel@tonic-gate * ire_flush_cache_*(IRE_FLUSH_ADD) as a change 8390Sstevel@tonic-gate * in metrics or gateway will not affect existing 8400Sstevel@tonic-gate * routes since it does not create a more specific 8410Sstevel@tonic-gate * route. 8420Sstevel@tonic-gate */ 8430Sstevel@tonic-gate switch (af) { 8440Sstevel@tonic-gate case AF_INET: 8450Sstevel@tonic-gate ire_flush_cache_v4(ire, IRE_FLUSH_DELETE); 8460Sstevel@tonic-gate if ((found_addrs & RTA_GATEWAY) != 0 && 8470Sstevel@tonic-gate (ire->ire_gateway_addr != gw_addr)) { 8480Sstevel@tonic-gate ire->ire_gateway_addr = gw_addr; 8490Sstevel@tonic-gate } 8501676Sjpk 8511676Sjpk if (rtsap != NULL) { 8521676Sjpk ga.ga_af = AF_INET; 8531676Sjpk IN6_IPADDR_TO_V4MAPPED( 8541676Sjpk ire->ire_gateway_addr, &ga.ga_addr); 8551676Sjpk 8561676Sjpk gcgrp = gcgrp_lookup(&ga, B_TRUE); 8571676Sjpk if (gcgrp == NULL) { 8581676Sjpk error = ENOMEM; 8591676Sjpk goto done; 8601676Sjpk } 8611676Sjpk } 8621676Sjpk 8630Sstevel@tonic-gate if ((found_addrs & RTA_SRC) != 0 && 8640Sstevel@tonic-gate (rtm->rtm_flags & RTF_SETSRC) != 0 && 8650Sstevel@tonic-gate (ire->ire_src_addr != src_addr)) { 8660Sstevel@tonic-gate 8670Sstevel@tonic-gate if (src_addr != INADDR_ANY) { 8680Sstevel@tonic-gate /* 8690Sstevel@tonic-gate * The RTF_SETSRC flag is 8700Sstevel@tonic-gate * present, check that the 8710Sstevel@tonic-gate * supplied src address is not 8720Sstevel@tonic-gate * the loopback address. This 8730Sstevel@tonic-gate * would produce martian 8740Sstevel@tonic-gate * packets. 8750Sstevel@tonic-gate */ 8760Sstevel@tonic-gate if (src_addr == 8770Sstevel@tonic-gate htonl(INADDR_LOOPBACK)) { 8780Sstevel@tonic-gate error = EINVAL; 8790Sstevel@tonic-gate goto done; 8800Sstevel@tonic-gate } 8810Sstevel@tonic-gate /* 8820Sstevel@tonic-gate * Also check that the the 8830Sstevel@tonic-gate * supplied addr is a valid 8840Sstevel@tonic-gate * local address. 8850Sstevel@tonic-gate */ 8860Sstevel@tonic-gate tmp_ipif = ipif_lookup_addr( 8870Sstevel@tonic-gate src_addr, NULL, ALL_ZONES, 8888348SEric.Yu@Sun.COM WR(q), ioc_mp, 8890Sstevel@tonic-gate ip_rts_request_retry, 8903448Sdh155122 &error, ipst); 8910Sstevel@tonic-gate if (tmp_ipif == NULL) { 8920Sstevel@tonic-gate error = (error == 8930Sstevel@tonic-gate EINPROGRESS) ? 8940Sstevel@tonic-gate error : 8950Sstevel@tonic-gate EADDRNOTAVAIL; 8960Sstevel@tonic-gate goto done; 8970Sstevel@tonic-gate } 8980Sstevel@tonic-gate 8990Sstevel@tonic-gate if (!(tmp_ipif->ipif_flags & 9000Sstevel@tonic-gate IPIF_UP) || 9010Sstevel@tonic-gate (tmp_ipif->ipif_flags & 9020Sstevel@tonic-gate (IPIF_NOLOCAL | 9030Sstevel@tonic-gate IPIF_ANYCAST))) { 9040Sstevel@tonic-gate error = EINVAL; 9050Sstevel@tonic-gate goto done; 9060Sstevel@tonic-gate } 9070Sstevel@tonic-gate ire->ire_flags |= RTF_SETSRC; 9080Sstevel@tonic-gate } else { 9090Sstevel@tonic-gate ire->ire_flags &= ~RTF_SETSRC; 9100Sstevel@tonic-gate } 9110Sstevel@tonic-gate ire->ire_src_addr = src_addr; 9120Sstevel@tonic-gate } 9130Sstevel@tonic-gate break; 9140Sstevel@tonic-gate case AF_INET6: 9150Sstevel@tonic-gate ire_flush_cache_v6(ire, IRE_FLUSH_DELETE); 9160Sstevel@tonic-gate mutex_enter(&ire->ire_lock); 9170Sstevel@tonic-gate if ((found_addrs & RTA_GATEWAY) != 0 && 9180Sstevel@tonic-gate !IN6_ARE_ADDR_EQUAL( 9190Sstevel@tonic-gate &ire->ire_gateway_addr_v6, &gw_addr_v6)) { 9200Sstevel@tonic-gate ire->ire_gateway_addr_v6 = gw_addr_v6; 9210Sstevel@tonic-gate } 9221676Sjpk 9231676Sjpk if (rtsap != NULL) { 9241676Sjpk ga.ga_af = AF_INET6; 9251676Sjpk ga.ga_addr = ire->ire_gateway_addr_v6; 9261676Sjpk 9271676Sjpk gcgrp = gcgrp_lookup(&ga, B_TRUE); 9281676Sjpk if (gcgrp == NULL) { 9291676Sjpk error = ENOMEM; 9301676Sjpk goto done; 9311676Sjpk } 9321676Sjpk } 9331676Sjpk 9340Sstevel@tonic-gate if ((found_addrs & RTA_SRC) != 0 && 9350Sstevel@tonic-gate (rtm->rtm_flags & RTF_SETSRC) != 0 && 9360Sstevel@tonic-gate !IN6_ARE_ADDR_EQUAL( 9375240Snordmark &ire->ire_src_addr_v6, &src_addr_v6)) { 9380Sstevel@tonic-gate 9390Sstevel@tonic-gate if (!IN6_IS_ADDR_UNSPECIFIED( 9400Sstevel@tonic-gate &src_addr_v6)) { 9410Sstevel@tonic-gate /* 9420Sstevel@tonic-gate * The RTF_SETSRC flag is 9430Sstevel@tonic-gate * present, check that the 9440Sstevel@tonic-gate * supplied src address is not 9450Sstevel@tonic-gate * the loopback address. This 9460Sstevel@tonic-gate * would produce martian 9470Sstevel@tonic-gate * packets. 9480Sstevel@tonic-gate */ 9490Sstevel@tonic-gate if (IN6_IS_ADDR_LOOPBACK( 9500Sstevel@tonic-gate &src_addr_v6)) { 9510Sstevel@tonic-gate mutex_exit( 9520Sstevel@tonic-gate &ire->ire_lock); 9530Sstevel@tonic-gate error = EINVAL; 9540Sstevel@tonic-gate goto done; 9550Sstevel@tonic-gate } 9560Sstevel@tonic-gate /* 9570Sstevel@tonic-gate * Also check that the the 9580Sstevel@tonic-gate * supplied addr is a valid 9590Sstevel@tonic-gate * local address. 9600Sstevel@tonic-gate */ 9610Sstevel@tonic-gate tmp_ipif = ipif_lookup_addr_v6( 9620Sstevel@tonic-gate &src_addr_v6, NULL, 9630Sstevel@tonic-gate ALL_ZONES, 9640Sstevel@tonic-gate CONNP_TO_WQ(connp), ioc_mp, 9650Sstevel@tonic-gate ip_rts_request_retry, 9663448Sdh155122 &error, ipst); 9670Sstevel@tonic-gate if (tmp_ipif == NULL) { 9680Sstevel@tonic-gate mutex_exit( 9690Sstevel@tonic-gate &ire->ire_lock); 9700Sstevel@tonic-gate error = (error == 9710Sstevel@tonic-gate EINPROGRESS) ? 9720Sstevel@tonic-gate error : 9730Sstevel@tonic-gate EADDRNOTAVAIL; 9740Sstevel@tonic-gate goto done; 9750Sstevel@tonic-gate } 9760Sstevel@tonic-gate if (!(tmp_ipif->ipif_flags & 9770Sstevel@tonic-gate IPIF_UP) || 9780Sstevel@tonic-gate (tmp_ipif->ipif_flags & 9790Sstevel@tonic-gate (IPIF_NOLOCAL | 9800Sstevel@tonic-gate IPIF_ANYCAST))) { 9810Sstevel@tonic-gate mutex_exit( 9820Sstevel@tonic-gate &ire->ire_lock); 9830Sstevel@tonic-gate error = EINVAL; 9840Sstevel@tonic-gate goto done; 9850Sstevel@tonic-gate } 9860Sstevel@tonic-gate ire->ire_flags |= RTF_SETSRC; 9870Sstevel@tonic-gate } else { 9880Sstevel@tonic-gate ire->ire_flags &= ~RTF_SETSRC; 9890Sstevel@tonic-gate } 9900Sstevel@tonic-gate ire->ire_src_addr_v6 = src_addr_v6; 9910Sstevel@tonic-gate } 9920Sstevel@tonic-gate mutex_exit(&ire->ire_lock); 9930Sstevel@tonic-gate break; 9940Sstevel@tonic-gate } 9951676Sjpk 9961676Sjpk if (rtsap != NULL) { 9971676Sjpk in_addr_t ga_addr4; 9981676Sjpk 9991676Sjpk ASSERT(gcgrp != NULL); 10001676Sjpk 10011676Sjpk /* 10021676Sjpk * Create and add the security attribute to 10031676Sjpk * prefix IRE; it will add a reference to the 10041676Sjpk * group upon allocating a new entry. If it 10051676Sjpk * finds an already-existing entry for the 10061676Sjpk * security attribute, it simply returns it 10071676Sjpk * and no new group reference is made. 10081676Sjpk */ 10091676Sjpk gc = gc_create(rtsap, gcgrp, &gcgrp_xtraref); 10101676Sjpk if (gc == NULL || 10111676Sjpk (error = tsol_ire_init_gwattr(ire, 10121676Sjpk ire->ire_ipversion, gc, NULL)) != 0) { 10131676Sjpk if (gc != NULL) { 10141676Sjpk GC_REFRELE(gc); 10151676Sjpk } else { 10161676Sjpk /* gc_create failed */ 10171676Sjpk error = ENOMEM; 10181676Sjpk } 10191676Sjpk goto done; 10201676Sjpk } 10211676Sjpk 10221676Sjpk /* 10231676Sjpk * Now delete any existing gateway IRE caches 10241676Sjpk * as well as all caches using the gateway, 10251676Sjpk * and allow them to be created on demand 10261676Sjpk * through ip_newroute{_v6}. 10271676Sjpk */ 10281676Sjpk IN6_V4MAPPED_TO_IPADDR(&ga.ga_addr, ga_addr4); 10291676Sjpk if (af == AF_INET) { 10301676Sjpk ire_clookup_delete_cache_gw( 10313448Sdh155122 ga_addr4, ALL_ZONES, ipst); 10321676Sjpk } else { 10331676Sjpk ire_clookup_delete_cache_gw_v6( 10343448Sdh155122 &ga.ga_addr, ALL_ZONES, ipst); 10351676Sjpk } 10361676Sjpk } 10370Sstevel@tonic-gate rts_setmetrics(ire, rtm->rtm_inits, &rtm->rtm_rmx); 10380Sstevel@tonic-gate break; 10390Sstevel@tonic-gate } 10400Sstevel@tonic-gate break; 10410Sstevel@tonic-gate default: 10420Sstevel@tonic-gate error = EOPNOTSUPP; 10430Sstevel@tonic-gate break; 10440Sstevel@tonic-gate } 10450Sstevel@tonic-gate done: 10460Sstevel@tonic-gate if (ire != NULL) 10470Sstevel@tonic-gate ire_refrele(ire); 10480Sstevel@tonic-gate if (sire != NULL) 10490Sstevel@tonic-gate ire_refrele(sire); 10500Sstevel@tonic-gate if (ipif != NULL) 10510Sstevel@tonic-gate ipif_refrele(ipif); 10520Sstevel@tonic-gate if (tmp_ipif != NULL) 10530Sstevel@tonic-gate ipif_refrele(tmp_ipif); 10540Sstevel@tonic-gate 10551676Sjpk if (gcgrp_xtraref) 10561676Sjpk GCGRP_REFRELE(gcgrp); 10571676Sjpk 10583142Ssangeeta if (error == EINPROGRESS) { 10593142Ssangeeta if (rtm != NULL) 10603142Ssangeeta freemsg(mp); 10610Sstevel@tonic-gate return (error); 10623142Ssangeeta } 10630Sstevel@tonic-gate if (rtm != NULL) { 10640Sstevel@tonic-gate ASSERT(mp->b_wptr <= mp->b_datap->db_lim); 10650Sstevel@tonic-gate if (error != 0) { 10660Sstevel@tonic-gate rtm->rtm_errno = error; 10670Sstevel@tonic-gate /* Send error ACK */ 10680Sstevel@tonic-gate ip1dbg(("ip_rts_request: error %d\n", error)); 10690Sstevel@tonic-gate } else { 10700Sstevel@tonic-gate rtm->rtm_flags |= RTF_DONE; 10710Sstevel@tonic-gate /* OK ACK already set up by caller except this */ 10720Sstevel@tonic-gate ip2dbg(("ip_rts_request: OK ACK\n")); 10730Sstevel@tonic-gate } 1074*8485SPeter.Memishian@Sun.COM rts_queue_input(mp, connp, af, RTSQ_ALL, ipst); 10750Sstevel@tonic-gate } 10768348SEric.Yu@Sun.COM 10770Sstevel@tonic-gate iocp->ioc_error = error; 10780Sstevel@tonic-gate ioc_mp->b_datap->db_type = M_IOCACK; 10790Sstevel@tonic-gate if (iocp->ioc_error != 0) 10800Sstevel@tonic-gate iocp->ioc_count = 0; 10815240Snordmark (connp->conn_recv)(connp, ioc_mp, NULL); 10828348SEric.Yu@Sun.COM 10830Sstevel@tonic-gate /* conn was refheld in ip_wput_ioctl. */ 10840Sstevel@tonic-gate CONN_OPER_PENDING_DONE(connp); 10850Sstevel@tonic-gate 10860Sstevel@tonic-gate return (error); 10870Sstevel@tonic-gate } 10880Sstevel@tonic-gate 10898348SEric.Yu@Sun.COM int 10908348SEric.Yu@Sun.COM ip_rts_request(queue_t *q, mblk_t *mp, cred_t *ioc_cr) 10918348SEric.Yu@Sun.COM { 10928348SEric.Yu@Sun.COM return (ip_rts_request_common(q, mp, Q_TO_CONN(q), ioc_cr)); 10938348SEric.Yu@Sun.COM } 10948348SEric.Yu@Sun.COM 10950Sstevel@tonic-gate /* 10960Sstevel@tonic-gate * Build a reply to the RTM_GET request contained in the given message block 10970Sstevel@tonic-gate * using the retrieved IRE of the destination address, the parent IRE (if it 10980Sstevel@tonic-gate * exists) and the address family. 10990Sstevel@tonic-gate * 11000Sstevel@tonic-gate * Returns a pointer to a message block containing the reply if successful, 11010Sstevel@tonic-gate * otherwise NULL is returned. 11020Sstevel@tonic-gate */ 11031676Sjpk static mblk_t * 11040Sstevel@tonic-gate rts_rtmget(mblk_t *mp, ire_t *ire, ire_t *sire, sa_family_t af) 11050Sstevel@tonic-gate { 11060Sstevel@tonic-gate rt_msghdr_t *rtm; 11070Sstevel@tonic-gate rt_msghdr_t *new_rtm; 11080Sstevel@tonic-gate mblk_t *new_mp; 11090Sstevel@tonic-gate int rtm_addrs; 11100Sstevel@tonic-gate int rtm_flags; 11110Sstevel@tonic-gate in6_addr_t gw_addr_v6; 11121676Sjpk tsol_ire_gw_secattr_t *attrp = NULL; 11131676Sjpk tsol_gc_t *gc = NULL; 11141676Sjpk tsol_gcgrp_t *gcgrp = NULL; 11151676Sjpk int sacnt = 0; 11160Sstevel@tonic-gate 11170Sstevel@tonic-gate ASSERT(ire->ire_ipif != NULL); 11180Sstevel@tonic-gate rtm = (rt_msghdr_t *)mp->b_rptr; 11190Sstevel@tonic-gate 11201676Sjpk if (sire != NULL && sire->ire_gw_secattr != NULL) 11211676Sjpk attrp = sire->ire_gw_secattr; 11221676Sjpk else if (ire->ire_gw_secattr != NULL) 11231676Sjpk attrp = ire->ire_gw_secattr; 11241676Sjpk 11251676Sjpk if (attrp != NULL) { 11261676Sjpk mutex_enter(&attrp->igsa_lock); 11271676Sjpk if ((gc = attrp->igsa_gc) != NULL) { 11281676Sjpk gcgrp = gc->gc_grp; 11291676Sjpk ASSERT(gcgrp != NULL); 11301676Sjpk rw_enter(&gcgrp->gcgrp_rwlock, RW_READER); 11311676Sjpk sacnt = 1; 11321676Sjpk } else if ((gcgrp = attrp->igsa_gcgrp) != NULL) { 11331676Sjpk rw_enter(&gcgrp->gcgrp_rwlock, RW_READER); 11341676Sjpk gc = gcgrp->gcgrp_head; 11351676Sjpk sacnt = gcgrp->gcgrp_count; 11361676Sjpk } 11371676Sjpk mutex_exit(&attrp->igsa_lock); 11381676Sjpk 11391676Sjpk /* do nothing if there's no gc to report */ 11401676Sjpk if (gc == NULL) { 11411676Sjpk ASSERT(sacnt == 0); 11421676Sjpk if (gcgrp != NULL) { 11431676Sjpk /* we might as well drop the lock now */ 11441676Sjpk rw_exit(&gcgrp->gcgrp_rwlock); 11451676Sjpk gcgrp = NULL; 11461676Sjpk } 11471676Sjpk attrp = NULL; 11481676Sjpk } 11491676Sjpk 11501676Sjpk ASSERT(gc == NULL || (gcgrp != NULL && 11511676Sjpk RW_LOCK_HELD(&gcgrp->gcgrp_rwlock))); 11521676Sjpk } 11531676Sjpk ASSERT(sacnt == 0 || gc != NULL); 11541676Sjpk 11550Sstevel@tonic-gate /* 11560Sstevel@tonic-gate * Always return RTA_DST, RTA_GATEWAY and RTA_NETMASK. 11570Sstevel@tonic-gate * 11580Sstevel@tonic-gate * The 4.4BSD-Lite2 code (net/rtsock.c) returns both 11590Sstevel@tonic-gate * RTA_IFP and RTA_IFA if either is defined, and also 11600Sstevel@tonic-gate * returns RTA_BRD if the appropriate interface is 11610Sstevel@tonic-gate * point-to-point. 11620Sstevel@tonic-gate */ 11630Sstevel@tonic-gate rtm_addrs = (RTA_DST | RTA_GATEWAY | RTA_NETMASK); 11640Sstevel@tonic-gate if (rtm->rtm_addrs & (RTA_IFP | RTA_IFA)) { 11650Sstevel@tonic-gate rtm_addrs |= (RTA_IFP | RTA_IFA); 11660Sstevel@tonic-gate if (ire->ire_ipif->ipif_flags & IPIF_POINTOPOINT) 11670Sstevel@tonic-gate rtm_addrs |= RTA_BRD; 11680Sstevel@tonic-gate } 11690Sstevel@tonic-gate 11701676Sjpk new_mp = rts_alloc_msg(RTM_GET, rtm_addrs, af, sacnt); 11711676Sjpk if (new_mp == NULL) { 11721676Sjpk if (gcgrp != NULL) 11731676Sjpk rw_exit(&gcgrp->gcgrp_rwlock); 11740Sstevel@tonic-gate return (NULL); 11751676Sjpk } 11760Sstevel@tonic-gate 11770Sstevel@tonic-gate /* 11780Sstevel@tonic-gate * We set the destination address, gateway address, 11790Sstevel@tonic-gate * netmask and flags in the RTM_GET response depending 11800Sstevel@tonic-gate * on whether we found a parent IRE or not. 11810Sstevel@tonic-gate * In particular, if we did find a parent IRE during the 11820Sstevel@tonic-gate * recursive search, use that IRE's gateway address. 11830Sstevel@tonic-gate * Otherwise, we use the IRE's source address for the 11840Sstevel@tonic-gate * gateway address. 11850Sstevel@tonic-gate */ 11860Sstevel@tonic-gate ASSERT(af == AF_INET || af == AF_INET6); 11870Sstevel@tonic-gate switch (af) { 11880Sstevel@tonic-gate case AF_INET: 11890Sstevel@tonic-gate if (sire == NULL) { 11900Sstevel@tonic-gate rtm_flags = ire->ire_flags; 11910Sstevel@tonic-gate rts_fill_msg(RTM_GET, rtm_addrs, ire->ire_addr, 11920Sstevel@tonic-gate ire->ire_mask, ire->ire_src_addr, ire->ire_src_addr, 11930Sstevel@tonic-gate ire->ire_ipif->ipif_pp_dst_addr, 0, ire->ire_ipif, 11941676Sjpk new_mp, sacnt, gc); 11950Sstevel@tonic-gate } else { 11960Sstevel@tonic-gate if (sire->ire_flags & RTF_SETSRC) 11970Sstevel@tonic-gate rtm_addrs |= RTA_SRC; 11980Sstevel@tonic-gate 11990Sstevel@tonic-gate rtm_flags = sire->ire_flags; 12000Sstevel@tonic-gate rts_fill_msg(RTM_GET, rtm_addrs, sire->ire_addr, 12010Sstevel@tonic-gate sire->ire_mask, sire->ire_gateway_addr, 12020Sstevel@tonic-gate (sire->ire_flags & RTF_SETSRC) ? 12035240Snordmark sire->ire_src_addr : ire->ire_src_addr, 12040Sstevel@tonic-gate ire->ire_ipif->ipif_pp_dst_addr, 12051676Sjpk 0, ire->ire_ipif, new_mp, sacnt, gc); 12060Sstevel@tonic-gate } 12070Sstevel@tonic-gate break; 12080Sstevel@tonic-gate case AF_INET6: 12090Sstevel@tonic-gate if (sire == NULL) { 12100Sstevel@tonic-gate rtm_flags = ire->ire_flags; 12110Sstevel@tonic-gate rts_fill_msg_v6(RTM_GET, rtm_addrs, &ire->ire_addr_v6, 12120Sstevel@tonic-gate &ire->ire_mask_v6, &ire->ire_src_addr_v6, 12130Sstevel@tonic-gate &ire->ire_src_addr_v6, 12140Sstevel@tonic-gate &ire->ire_ipif->ipif_v6pp_dst_addr, 12151676Sjpk &ipv6_all_zeros, ire->ire_ipif, new_mp, 12161676Sjpk sacnt, gc); 12170Sstevel@tonic-gate } else { 12180Sstevel@tonic-gate if (sire->ire_flags & RTF_SETSRC) 12190Sstevel@tonic-gate rtm_addrs |= RTA_SRC; 12200Sstevel@tonic-gate 12210Sstevel@tonic-gate rtm_flags = sire->ire_flags; 12220Sstevel@tonic-gate mutex_enter(&sire->ire_lock); 12230Sstevel@tonic-gate gw_addr_v6 = sire->ire_gateway_addr_v6; 12240Sstevel@tonic-gate mutex_exit(&sire->ire_lock); 12250Sstevel@tonic-gate rts_fill_msg_v6(RTM_GET, rtm_addrs, &sire->ire_addr_v6, 12260Sstevel@tonic-gate &sire->ire_mask_v6, &gw_addr_v6, 12270Sstevel@tonic-gate (sire->ire_flags & RTF_SETSRC) ? 12285240Snordmark &sire->ire_src_addr_v6 : &ire->ire_src_addr_v6, 12290Sstevel@tonic-gate &ire->ire_ipif->ipif_v6pp_dst_addr, &ipv6_all_zeros, 12301676Sjpk ire->ire_ipif, new_mp, sacnt, gc); 12310Sstevel@tonic-gate } 12320Sstevel@tonic-gate break; 12330Sstevel@tonic-gate } 12341676Sjpk 12351676Sjpk if (gcgrp != NULL) 12361676Sjpk rw_exit(&gcgrp->gcgrp_rwlock); 12371676Sjpk 12380Sstevel@tonic-gate new_rtm = (rt_msghdr_t *)new_mp->b_rptr; 12390Sstevel@tonic-gate 12400Sstevel@tonic-gate /* 12410Sstevel@tonic-gate * The rtm_msglen, rtm_version and rtm_type fields in 12420Sstevel@tonic-gate * RTM_GET response are filled in by rts_fill_msg. 12430Sstevel@tonic-gate * 12440Sstevel@tonic-gate * rtm_addrs and rtm_flags are filled in based on what 12450Sstevel@tonic-gate * was requested and the state of the IREs looked up 12460Sstevel@tonic-gate * above. 12470Sstevel@tonic-gate * 12480Sstevel@tonic-gate * rtm_inits and rtm_rmx are filled in with metrics 12490Sstevel@tonic-gate * based on whether a parent IRE was found or not. 12500Sstevel@tonic-gate * 12510Sstevel@tonic-gate * TODO: rtm_index and rtm_use should probably be 12520Sstevel@tonic-gate * filled in with something resonable here and not just 12530Sstevel@tonic-gate * copied from the request. 12540Sstevel@tonic-gate */ 12550Sstevel@tonic-gate new_rtm->rtm_index = rtm->rtm_index; 12560Sstevel@tonic-gate new_rtm->rtm_pid = rtm->rtm_pid; 12570Sstevel@tonic-gate new_rtm->rtm_seq = rtm->rtm_seq; 12580Sstevel@tonic-gate new_rtm->rtm_use = rtm->rtm_use; 12590Sstevel@tonic-gate new_rtm->rtm_addrs = rtm_addrs; 12600Sstevel@tonic-gate new_rtm->rtm_flags = rtm_flags; 12610Sstevel@tonic-gate if (sire == NULL) 12620Sstevel@tonic-gate new_rtm->rtm_inits = rts_getmetrics(ire, &new_rtm->rtm_rmx); 12630Sstevel@tonic-gate else 12640Sstevel@tonic-gate new_rtm->rtm_inits = rts_getmetrics(sire, &new_rtm->rtm_rmx); 12651676Sjpk 12660Sstevel@tonic-gate return (new_mp); 12670Sstevel@tonic-gate } 12680Sstevel@tonic-gate 12690Sstevel@tonic-gate /* 12700Sstevel@tonic-gate * Fill the given if_data_t with interface statistics. 12710Sstevel@tonic-gate */ 12720Sstevel@tonic-gate static void 12731676Sjpk rts_getifdata(if_data_t *if_data, const ipif_t *ipif) 12740Sstevel@tonic-gate { 12750Sstevel@tonic-gate if_data->ifi_type = ipif->ipif_type; /* ethernet, tokenring, etc */ 12760Sstevel@tonic-gate if_data->ifi_addrlen = 0; /* media address length */ 12770Sstevel@tonic-gate if_data->ifi_hdrlen = 0; /* media header length */ 12780Sstevel@tonic-gate if_data->ifi_mtu = ipif->ipif_mtu; /* maximum transmission unit */ 12790Sstevel@tonic-gate if_data->ifi_metric = ipif->ipif_metric; /* metric (external only) */ 12800Sstevel@tonic-gate if_data->ifi_baudrate = 0; /* linespeed */ 12810Sstevel@tonic-gate 12820Sstevel@tonic-gate if_data->ifi_ipackets = 0; /* packets received on if */ 12830Sstevel@tonic-gate if_data->ifi_ierrors = 0; /* input errors on interface */ 12840Sstevel@tonic-gate if_data->ifi_opackets = 0; /* packets sent on interface */ 12850Sstevel@tonic-gate if_data->ifi_oerrors = 0; /* output errors on if */ 12860Sstevel@tonic-gate if_data->ifi_collisions = 0; /* collisions on csma if */ 12870Sstevel@tonic-gate if_data->ifi_ibytes = 0; /* total number received */ 12880Sstevel@tonic-gate if_data->ifi_obytes = 0; /* total number sent */ 12890Sstevel@tonic-gate if_data->ifi_imcasts = 0; /* multicast packets received */ 12900Sstevel@tonic-gate if_data->ifi_omcasts = 0; /* multicast packets sent */ 12910Sstevel@tonic-gate if_data->ifi_iqdrops = 0; /* dropped on input */ 12920Sstevel@tonic-gate if_data->ifi_noproto = 0; /* destined for unsupported */ 12930Sstevel@tonic-gate /* protocol. */ 12940Sstevel@tonic-gate } 12950Sstevel@tonic-gate 12960Sstevel@tonic-gate /* 12970Sstevel@tonic-gate * Set the metrics on a forwarding table route. 12980Sstevel@tonic-gate */ 12990Sstevel@tonic-gate static void 13000Sstevel@tonic-gate rts_setmetrics(ire_t *ire, uint_t which, rt_metrics_t *metrics) 13010Sstevel@tonic-gate { 13020Sstevel@tonic-gate clock_t rtt; 13030Sstevel@tonic-gate clock_t rtt_sd; 13040Sstevel@tonic-gate ipif_t *ipif; 13050Sstevel@tonic-gate ifrt_t *ifrt; 13060Sstevel@tonic-gate mblk_t *mp; 13070Sstevel@tonic-gate in6_addr_t gw_addr_v6; 13080Sstevel@tonic-gate 13090Sstevel@tonic-gate /* 13100Sstevel@tonic-gate * Bypass obtaining the lock and searching ipif_saved_ire_mp in the 13110Sstevel@tonic-gate * common case of no metrics. 13120Sstevel@tonic-gate */ 13130Sstevel@tonic-gate if (which == 0) 13140Sstevel@tonic-gate return; 13150Sstevel@tonic-gate ire->ire_uinfo.iulp_set = B_TRUE; 13160Sstevel@tonic-gate 13170Sstevel@tonic-gate /* 13180Sstevel@tonic-gate * iulp_rtt and iulp_rtt_sd are in milliseconds, but 4.4BSD-Lite2's 13190Sstevel@tonic-gate * <net/route.h> says: rmx_rtt and rmx_rttvar are stored as 13200Sstevel@tonic-gate * microseconds. 13210Sstevel@tonic-gate */ 13220Sstevel@tonic-gate if (which & RTV_RTT) 13230Sstevel@tonic-gate rtt = metrics->rmx_rtt / 1000; 13240Sstevel@tonic-gate if (which & RTV_RTTVAR) 13250Sstevel@tonic-gate rtt_sd = metrics->rmx_rttvar / 1000; 13260Sstevel@tonic-gate 13270Sstevel@tonic-gate /* 13280Sstevel@tonic-gate * Update the metrics in the IRE itself. 13290Sstevel@tonic-gate */ 13300Sstevel@tonic-gate mutex_enter(&ire->ire_lock); 13310Sstevel@tonic-gate if (which & RTV_MTU) 13320Sstevel@tonic-gate ire->ire_max_frag = metrics->rmx_mtu; 13330Sstevel@tonic-gate if (which & RTV_RTT) 13340Sstevel@tonic-gate ire->ire_uinfo.iulp_rtt = rtt; 13350Sstevel@tonic-gate if (which & RTV_SSTHRESH) 13360Sstevel@tonic-gate ire->ire_uinfo.iulp_ssthresh = metrics->rmx_ssthresh; 13370Sstevel@tonic-gate if (which & RTV_RTTVAR) 13380Sstevel@tonic-gate ire->ire_uinfo.iulp_rtt_sd = rtt_sd; 13390Sstevel@tonic-gate if (which & RTV_SPIPE) 13400Sstevel@tonic-gate ire->ire_uinfo.iulp_spipe = metrics->rmx_sendpipe; 13410Sstevel@tonic-gate if (which & RTV_RPIPE) 13420Sstevel@tonic-gate ire->ire_uinfo.iulp_rpipe = metrics->rmx_recvpipe; 13430Sstevel@tonic-gate mutex_exit(&ire->ire_lock); 13440Sstevel@tonic-gate 13450Sstevel@tonic-gate /* 13460Sstevel@tonic-gate * Search through the ifrt_t chain hanging off the IPIF in order to 13470Sstevel@tonic-gate * reflect the metric change there. 13480Sstevel@tonic-gate */ 13490Sstevel@tonic-gate ipif = ire->ire_ipif; 13500Sstevel@tonic-gate if (ipif == NULL) 13510Sstevel@tonic-gate return; 13520Sstevel@tonic-gate ASSERT((ipif->ipif_isv6 && ire->ire_ipversion == IPV6_VERSION) || 13530Sstevel@tonic-gate ((!ipif->ipif_isv6 && ire->ire_ipversion == IPV4_VERSION))); 13540Sstevel@tonic-gate if (ipif->ipif_isv6) { 13550Sstevel@tonic-gate mutex_enter(&ire->ire_lock); 13560Sstevel@tonic-gate gw_addr_v6 = ire->ire_gateway_addr_v6; 13570Sstevel@tonic-gate mutex_exit(&ire->ire_lock); 13580Sstevel@tonic-gate } 13590Sstevel@tonic-gate mutex_enter(&ipif->ipif_saved_ire_lock); 13600Sstevel@tonic-gate for (mp = ipif->ipif_saved_ire_mp; mp != NULL; mp = mp->b_cont) { 13610Sstevel@tonic-gate /* 13620Sstevel@tonic-gate * On a given ipif, the triple of address, gateway and mask is 13630Sstevel@tonic-gate * unique for each saved IRE (in the case of ordinary interface 13640Sstevel@tonic-gate * routes, the gateway address is all-zeroes). 13650Sstevel@tonic-gate */ 13660Sstevel@tonic-gate ifrt = (ifrt_t *)mp->b_rptr; 13670Sstevel@tonic-gate if (ipif->ipif_isv6) { 13680Sstevel@tonic-gate if (!IN6_ARE_ADDR_EQUAL(&ifrt->ifrt_v6addr, 13690Sstevel@tonic-gate &ire->ire_addr_v6) || 13700Sstevel@tonic-gate !IN6_ARE_ADDR_EQUAL(&ifrt->ifrt_v6gateway_addr, 13710Sstevel@tonic-gate &gw_addr_v6) || 13720Sstevel@tonic-gate !IN6_ARE_ADDR_EQUAL(&ifrt->ifrt_v6mask, 13730Sstevel@tonic-gate &ire->ire_mask_v6)) 13740Sstevel@tonic-gate continue; 13750Sstevel@tonic-gate } else { 13760Sstevel@tonic-gate if (ifrt->ifrt_addr != ire->ire_addr || 13770Sstevel@tonic-gate ifrt->ifrt_gateway_addr != ire->ire_gateway_addr || 13780Sstevel@tonic-gate ifrt->ifrt_mask != ire->ire_mask) 13790Sstevel@tonic-gate continue; 13800Sstevel@tonic-gate } 13810Sstevel@tonic-gate if (which & RTV_MTU) 13820Sstevel@tonic-gate ifrt->ifrt_max_frag = metrics->rmx_mtu; 13830Sstevel@tonic-gate if (which & RTV_RTT) 13840Sstevel@tonic-gate ifrt->ifrt_iulp_info.iulp_rtt = rtt; 13850Sstevel@tonic-gate if (which & RTV_SSTHRESH) { 13860Sstevel@tonic-gate ifrt->ifrt_iulp_info.iulp_ssthresh = 13870Sstevel@tonic-gate metrics->rmx_ssthresh; 13880Sstevel@tonic-gate } 13890Sstevel@tonic-gate if (which & RTV_RTTVAR) 13900Sstevel@tonic-gate ifrt->ifrt_iulp_info.iulp_rtt_sd = metrics->rmx_rttvar; 13910Sstevel@tonic-gate if (which & RTV_SPIPE) 13920Sstevel@tonic-gate ifrt->ifrt_iulp_info.iulp_spipe = metrics->rmx_sendpipe; 13930Sstevel@tonic-gate if (which & RTV_RPIPE) 13940Sstevel@tonic-gate ifrt->ifrt_iulp_info.iulp_rpipe = metrics->rmx_recvpipe; 13950Sstevel@tonic-gate break; 13960Sstevel@tonic-gate } 13970Sstevel@tonic-gate mutex_exit(&ipif->ipif_saved_ire_lock); 13980Sstevel@tonic-gate } 13990Sstevel@tonic-gate 14000Sstevel@tonic-gate /* 14010Sstevel@tonic-gate * Get the metrics from a forwarding table route. 14020Sstevel@tonic-gate */ 14030Sstevel@tonic-gate static int 14040Sstevel@tonic-gate rts_getmetrics(ire_t *ire, rt_metrics_t *metrics) 14050Sstevel@tonic-gate { 14060Sstevel@tonic-gate int metrics_set = 0; 14070Sstevel@tonic-gate 14080Sstevel@tonic-gate bzero(metrics, sizeof (rt_metrics_t)); 14090Sstevel@tonic-gate /* 14100Sstevel@tonic-gate * iulp_rtt and iulp_rtt_sd are in milliseconds, but 4.4BSD-Lite2's 14110Sstevel@tonic-gate * <net/route.h> says: rmx_rtt and rmx_rttvar are stored as 14120Sstevel@tonic-gate * microseconds. 14130Sstevel@tonic-gate */ 14140Sstevel@tonic-gate metrics->rmx_rtt = ire->ire_uinfo.iulp_rtt * 1000; 14150Sstevel@tonic-gate metrics_set |= RTV_RTT; 14160Sstevel@tonic-gate metrics->rmx_mtu = ire->ire_max_frag; 14170Sstevel@tonic-gate metrics_set |= RTV_MTU; 14180Sstevel@tonic-gate metrics->rmx_ssthresh = ire->ire_uinfo.iulp_ssthresh; 14190Sstevel@tonic-gate metrics_set |= RTV_SSTHRESH; 14200Sstevel@tonic-gate metrics->rmx_rttvar = ire->ire_uinfo.iulp_rtt_sd * 1000; 14210Sstevel@tonic-gate metrics_set |= RTV_RTTVAR; 14220Sstevel@tonic-gate metrics->rmx_sendpipe = ire->ire_uinfo.iulp_spipe; 14230Sstevel@tonic-gate metrics_set |= RTV_SPIPE; 14240Sstevel@tonic-gate metrics->rmx_recvpipe = ire->ire_uinfo.iulp_rpipe; 14250Sstevel@tonic-gate metrics_set |= RTV_RPIPE; 14260Sstevel@tonic-gate return (metrics_set); 14270Sstevel@tonic-gate } 14280Sstevel@tonic-gate 14290Sstevel@tonic-gate /* 14300Sstevel@tonic-gate * Takes a pointer to a routing message and extracts necessary info by looking 14310Sstevel@tonic-gate * at the rtm->rtm_addrs bits and store the requested sockaddrs in the pointers 14320Sstevel@tonic-gate * passed (all of which must be valid). 14330Sstevel@tonic-gate * 14340Sstevel@tonic-gate * The bitmask of sockaddrs actually found in the message is returned, or zero 14350Sstevel@tonic-gate * is returned in the case of an error. 14360Sstevel@tonic-gate */ 14370Sstevel@tonic-gate static int 14380Sstevel@tonic-gate rts_getaddrs(rt_msghdr_t *rtm, in6_addr_t *dst_addrp, in6_addr_t *gw_addrp, 14390Sstevel@tonic-gate in6_addr_t *net_maskp, in6_addr_t *authorp, in6_addr_t *if_addrp, 14404823Sseb in6_addr_t *in_src_addrp, ushort_t *indexp, sa_family_t *afp, 14414823Sseb tsol_rtsecattr_t *rtsecattr, int *error) 14420Sstevel@tonic-gate { 14430Sstevel@tonic-gate struct sockaddr *sa; 14440Sstevel@tonic-gate int i; 14450Sstevel@tonic-gate int addr_bits; 14460Sstevel@tonic-gate int length; 14470Sstevel@tonic-gate int found_addrs = 0; 14480Sstevel@tonic-gate caddr_t cp; 14490Sstevel@tonic-gate size_t size; 14500Sstevel@tonic-gate struct sockaddr_dl *sdl; 14510Sstevel@tonic-gate 14520Sstevel@tonic-gate *dst_addrp = ipv6_all_zeros; 14530Sstevel@tonic-gate *gw_addrp = ipv6_all_zeros; 14540Sstevel@tonic-gate *net_maskp = ipv6_all_zeros; 14550Sstevel@tonic-gate *authorp = ipv6_all_zeros; 14560Sstevel@tonic-gate *if_addrp = ipv6_all_zeros; 14570Sstevel@tonic-gate *in_src_addrp = ipv6_all_zeros; 14580Sstevel@tonic-gate *indexp = 0; 14590Sstevel@tonic-gate *afp = AF_UNSPEC; 14601676Sjpk rtsecattr->rtsa_cnt = 0; 14611676Sjpk *error = 0; 14620Sstevel@tonic-gate 14630Sstevel@tonic-gate /* 14640Sstevel@tonic-gate * At present we handle only RTA_DST, RTA_GATEWAY, RTA_NETMASK, RTA_IFP, 14650Sstevel@tonic-gate * RTA_IFA and RTA_AUTHOR. The rest will be added as we need them. 14660Sstevel@tonic-gate */ 14670Sstevel@tonic-gate cp = (caddr_t)&rtm[1]; 14680Sstevel@tonic-gate length = rtm->rtm_msglen; 14690Sstevel@tonic-gate for (i = 0; (i < RTA_NUMBITS) && ((cp - (caddr_t)rtm) < length); i++) { 14700Sstevel@tonic-gate /* 14710Sstevel@tonic-gate * The address family we are working with starts out as 14720Sstevel@tonic-gate * AF_UNSPEC, but is set to the one specified with the 14730Sstevel@tonic-gate * destination address. 14740Sstevel@tonic-gate * 14750Sstevel@tonic-gate * If the "working" address family that has been set to 14760Sstevel@tonic-gate * something other than AF_UNSPEC, then the address family of 14770Sstevel@tonic-gate * subsequent sockaddrs must either be AF_UNSPEC (for 14780Sstevel@tonic-gate * compatibility with older programs) or must be the same as our 14790Sstevel@tonic-gate * "working" one. 14800Sstevel@tonic-gate * 14810Sstevel@tonic-gate * This code assumes that RTA_DST (1) comes first in the loop. 14820Sstevel@tonic-gate */ 14830Sstevel@tonic-gate sa = (struct sockaddr *)cp; 14840Sstevel@tonic-gate addr_bits = (rtm->rtm_addrs & (1 << i)); 14850Sstevel@tonic-gate if (addr_bits == 0) 14860Sstevel@tonic-gate continue; 14870Sstevel@tonic-gate switch (addr_bits) { 14880Sstevel@tonic-gate case RTA_DST: 14890Sstevel@tonic-gate size = rts_copyfromsockaddr(sa, dst_addrp); 14900Sstevel@tonic-gate *afp = sa->sa_family; 14910Sstevel@tonic-gate break; 14920Sstevel@tonic-gate case RTA_GATEWAY: 14930Sstevel@tonic-gate if (sa->sa_family != *afp && sa->sa_family != AF_UNSPEC) 14940Sstevel@tonic-gate return (0); 14950Sstevel@tonic-gate size = rts_copyfromsockaddr(sa, gw_addrp); 14960Sstevel@tonic-gate break; 14970Sstevel@tonic-gate case RTA_NETMASK: 14980Sstevel@tonic-gate if (sa->sa_family != *afp && sa->sa_family != AF_UNSPEC) 14990Sstevel@tonic-gate return (0); 15000Sstevel@tonic-gate size = rts_copyfromsockaddr(sa, net_maskp); 15010Sstevel@tonic-gate break; 15020Sstevel@tonic-gate case RTA_IFP: 15030Sstevel@tonic-gate if (sa->sa_family != AF_LINK && 15040Sstevel@tonic-gate sa->sa_family != AF_UNSPEC) 15050Sstevel@tonic-gate return (0); 15060Sstevel@tonic-gate sdl = (struct sockaddr_dl *)cp; 15070Sstevel@tonic-gate *indexp = sdl->sdl_index; 15080Sstevel@tonic-gate size = sizeof (struct sockaddr_dl); 15090Sstevel@tonic-gate break; 15100Sstevel@tonic-gate case RTA_SRC: 15110Sstevel@tonic-gate /* Source address of the incoming packet */ 15120Sstevel@tonic-gate size = rts_copyfromsockaddr(sa, in_src_addrp); 15130Sstevel@tonic-gate *afp = sa->sa_family; 15140Sstevel@tonic-gate break; 15150Sstevel@tonic-gate case RTA_IFA: 15160Sstevel@tonic-gate if (sa->sa_family != *afp && sa->sa_family != AF_UNSPEC) 15170Sstevel@tonic-gate return (0); 15180Sstevel@tonic-gate size = rts_copyfromsockaddr(sa, if_addrp); 15190Sstevel@tonic-gate break; 15200Sstevel@tonic-gate case RTA_AUTHOR: 15210Sstevel@tonic-gate if (sa->sa_family != *afp && sa->sa_family != AF_UNSPEC) 15220Sstevel@tonic-gate return (0); 15230Sstevel@tonic-gate size = rts_copyfromsockaddr(sa, authorp); 15240Sstevel@tonic-gate break; 15250Sstevel@tonic-gate default: 15260Sstevel@tonic-gate return (0); 15270Sstevel@tonic-gate } 15280Sstevel@tonic-gate if (size == 0) 15290Sstevel@tonic-gate return (0); 15300Sstevel@tonic-gate cp += size; 15310Sstevel@tonic-gate found_addrs |= addr_bits; 15320Sstevel@tonic-gate } 15331676Sjpk 15341676Sjpk /* 15351676Sjpk * Parse the routing message and look for any security- 15361676Sjpk * related attributes for the route. For each valid 15371676Sjpk * attribute, allocate/obtain the corresponding kernel 15381676Sjpk * route security attributes. 15391676Sjpk */ 15401676Sjpk *error = tsol_rtsa_init(rtm, rtsecattr, cp); 15411676Sjpk ASSERT(rtsecattr->rtsa_cnt <= TSOL_RTSA_REQUEST_MAX); 15421676Sjpk 15430Sstevel@tonic-gate return (found_addrs); 15440Sstevel@tonic-gate } 15450Sstevel@tonic-gate 15460Sstevel@tonic-gate /* 15470Sstevel@tonic-gate * Fills the message with the given info. 15480Sstevel@tonic-gate */ 15490Sstevel@tonic-gate static void 15500Sstevel@tonic-gate rts_fill_msg(int type, int rtm_addrs, ipaddr_t dst, ipaddr_t mask, 15510Sstevel@tonic-gate ipaddr_t gateway, ipaddr_t src_addr, ipaddr_t brd_addr, ipaddr_t author, 15521676Sjpk const ipif_t *ipif, mblk_t *mp, uint_t sacnt, const tsol_gc_t *gc) 15530Sstevel@tonic-gate { 15540Sstevel@tonic-gate rt_msghdr_t *rtm; 15550Sstevel@tonic-gate sin_t *sin; 15560Sstevel@tonic-gate size_t data_size, header_size; 15570Sstevel@tonic-gate uchar_t *cp; 15580Sstevel@tonic-gate int i; 15590Sstevel@tonic-gate 15600Sstevel@tonic-gate ASSERT(mp != NULL); 15611676Sjpk ASSERT(sacnt == 0 || gc != NULL); 15620Sstevel@tonic-gate /* 15630Sstevel@tonic-gate * First find the type of the message 15640Sstevel@tonic-gate * and its length. 15650Sstevel@tonic-gate */ 15660Sstevel@tonic-gate header_size = rts_header_msg_size(type); 15670Sstevel@tonic-gate /* 15680Sstevel@tonic-gate * Now find the size of the data 15690Sstevel@tonic-gate * that follows the message header. 15700Sstevel@tonic-gate */ 15711676Sjpk data_size = rts_data_msg_size(rtm_addrs, AF_INET, sacnt); 15720Sstevel@tonic-gate 15730Sstevel@tonic-gate rtm = (rt_msghdr_t *)mp->b_rptr; 15740Sstevel@tonic-gate mp->b_wptr = &mp->b_rptr[header_size]; 15750Sstevel@tonic-gate cp = mp->b_wptr; 15760Sstevel@tonic-gate bzero(cp, data_size); 15770Sstevel@tonic-gate for (i = 0; i < RTA_NUMBITS; i++) { 15780Sstevel@tonic-gate sin = (sin_t *)cp; 15790Sstevel@tonic-gate switch (rtm_addrs & (1 << i)) { 15800Sstevel@tonic-gate case RTA_DST: 15810Sstevel@tonic-gate sin->sin_addr.s_addr = dst; 15820Sstevel@tonic-gate sin->sin_family = AF_INET; 15830Sstevel@tonic-gate cp += sizeof (sin_t); 15840Sstevel@tonic-gate break; 15850Sstevel@tonic-gate case RTA_GATEWAY: 15860Sstevel@tonic-gate sin->sin_addr.s_addr = gateway; 15870Sstevel@tonic-gate sin->sin_family = AF_INET; 15880Sstevel@tonic-gate cp += sizeof (sin_t); 15890Sstevel@tonic-gate break; 15900Sstevel@tonic-gate case RTA_NETMASK: 15910Sstevel@tonic-gate sin->sin_addr.s_addr = mask; 15920Sstevel@tonic-gate sin->sin_family = AF_INET; 15930Sstevel@tonic-gate cp += sizeof (sin_t); 15940Sstevel@tonic-gate break; 15950Sstevel@tonic-gate case RTA_IFP: 15960Sstevel@tonic-gate cp += ill_dls_info((struct sockaddr_dl *)cp, ipif); 15970Sstevel@tonic-gate break; 15980Sstevel@tonic-gate case RTA_IFA: 15990Sstevel@tonic-gate case RTA_SRC: 16000Sstevel@tonic-gate sin->sin_addr.s_addr = src_addr; 16010Sstevel@tonic-gate sin->sin_family = AF_INET; 16020Sstevel@tonic-gate cp += sizeof (sin_t); 16030Sstevel@tonic-gate break; 16040Sstevel@tonic-gate case RTA_AUTHOR: 16050Sstevel@tonic-gate sin->sin_addr.s_addr = author; 16060Sstevel@tonic-gate sin->sin_family = AF_INET; 16070Sstevel@tonic-gate cp += sizeof (sin_t); 16080Sstevel@tonic-gate break; 16090Sstevel@tonic-gate case RTA_BRD: 16100Sstevel@tonic-gate /* 16110Sstevel@tonic-gate * RTA_BRD is used typically to specify a point-to-point 16120Sstevel@tonic-gate * destination address. 16130Sstevel@tonic-gate */ 16140Sstevel@tonic-gate sin->sin_addr.s_addr = brd_addr; 16150Sstevel@tonic-gate sin->sin_family = AF_INET; 16160Sstevel@tonic-gate cp += sizeof (sin_t); 16170Sstevel@tonic-gate break; 16180Sstevel@tonic-gate } 16190Sstevel@tonic-gate } 16201676Sjpk 16211676Sjpk if (gc != NULL) { 16221676Sjpk rtm_ext_t *rtm_ext; 16231676Sjpk struct rtsa_s *rp_dst; 16241676Sjpk tsol_rtsecattr_t *rsap; 16251676Sjpk int i; 16261676Sjpk 16271676Sjpk ASSERT(gc->gc_grp != NULL); 16281676Sjpk ASSERT(RW_LOCK_HELD(&gc->gc_grp->gcgrp_rwlock)); 16291676Sjpk ASSERT(sacnt > 0); 16301676Sjpk 16311676Sjpk rtm_ext = (rtm_ext_t *)cp; 16321676Sjpk rtm_ext->rtmex_type = RTMEX_GATEWAY_SECATTR; 16331676Sjpk rtm_ext->rtmex_len = TSOL_RTSECATTR_SIZE(sacnt); 16341676Sjpk 16351676Sjpk rsap = (tsol_rtsecattr_t *)(rtm_ext + 1); 16361676Sjpk rsap->rtsa_cnt = sacnt; 16371676Sjpk rp_dst = rsap->rtsa_attr; 16381676Sjpk 16391676Sjpk for (i = 0; i < sacnt; i++, gc = gc->gc_next, rp_dst++) { 16401676Sjpk ASSERT(gc->gc_db != NULL); 16411676Sjpk bcopy(&gc->gc_db->gcdb_attr, rp_dst, sizeof (*rp_dst)); 16421676Sjpk } 16431676Sjpk cp = (uchar_t *)rp_dst; 16441676Sjpk } 16451676Sjpk 16460Sstevel@tonic-gate mp->b_wptr = cp; 16470Sstevel@tonic-gate mp->b_cont = NULL; 16480Sstevel@tonic-gate /* 16490Sstevel@tonic-gate * set the fields that are common to 16500Sstevel@tonic-gate * to different messages. 16510Sstevel@tonic-gate */ 16520Sstevel@tonic-gate rtm->rtm_msglen = (short)(header_size + data_size); 16530Sstevel@tonic-gate rtm->rtm_version = RTM_VERSION; 16540Sstevel@tonic-gate rtm->rtm_type = (uchar_t)type; 16550Sstevel@tonic-gate } 16560Sstevel@tonic-gate 16570Sstevel@tonic-gate /* 16580Sstevel@tonic-gate * Allocates and initializes a routing socket message. 16590Sstevel@tonic-gate */ 16600Sstevel@tonic-gate mblk_t * 16611676Sjpk rts_alloc_msg(int type, int rtm_addrs, sa_family_t af, uint_t sacnt) 16620Sstevel@tonic-gate { 16630Sstevel@tonic-gate size_t length; 16640Sstevel@tonic-gate mblk_t *mp; 16650Sstevel@tonic-gate 16661676Sjpk length = RTS_MSG_SIZE(type, rtm_addrs, af, sacnt); 16670Sstevel@tonic-gate mp = allocb(length, BPRI_MED); 16680Sstevel@tonic-gate if (mp == NULL) 16690Sstevel@tonic-gate return (mp); 16700Sstevel@tonic-gate bzero(mp->b_rptr, length); 16710Sstevel@tonic-gate return (mp); 16720Sstevel@tonic-gate } 16730Sstevel@tonic-gate 16740Sstevel@tonic-gate /* 16750Sstevel@tonic-gate * Returns the size of the routing 16760Sstevel@tonic-gate * socket message header size. 16770Sstevel@tonic-gate */ 16780Sstevel@tonic-gate size_t 16790Sstevel@tonic-gate rts_header_msg_size(int type) 16800Sstevel@tonic-gate { 16810Sstevel@tonic-gate switch (type) { 16820Sstevel@tonic-gate case RTM_DELADDR: 16830Sstevel@tonic-gate case RTM_NEWADDR: 16840Sstevel@tonic-gate return (sizeof (ifa_msghdr_t)); 16850Sstevel@tonic-gate case RTM_IFINFO: 16860Sstevel@tonic-gate return (sizeof (if_msghdr_t)); 16870Sstevel@tonic-gate default: 16880Sstevel@tonic-gate return (sizeof (rt_msghdr_t)); 16890Sstevel@tonic-gate } 16900Sstevel@tonic-gate } 16910Sstevel@tonic-gate 16920Sstevel@tonic-gate /* 16930Sstevel@tonic-gate * Returns the size of the message needed with the given rtm_addrs and family. 16940Sstevel@tonic-gate * 16950Sstevel@tonic-gate * It is assumed that all of the sockaddrs (with the exception of RTA_IFP) are 16960Sstevel@tonic-gate * of the same family (currently either AF_INET or AF_INET6). 16970Sstevel@tonic-gate */ 16980Sstevel@tonic-gate size_t 16991676Sjpk rts_data_msg_size(int rtm_addrs, sa_family_t af, uint_t sacnt) 17000Sstevel@tonic-gate { 17010Sstevel@tonic-gate int i; 17020Sstevel@tonic-gate size_t length = 0; 17030Sstevel@tonic-gate 17040Sstevel@tonic-gate for (i = 0; i < RTA_NUMBITS; i++) { 17050Sstevel@tonic-gate switch (rtm_addrs & (1 << i)) { 17060Sstevel@tonic-gate case RTA_IFP: 17070Sstevel@tonic-gate length += sizeof (struct sockaddr_dl); 17080Sstevel@tonic-gate break; 17090Sstevel@tonic-gate case RTA_DST: 17100Sstevel@tonic-gate case RTA_GATEWAY: 17110Sstevel@tonic-gate case RTA_NETMASK: 17120Sstevel@tonic-gate case RTA_SRC: 17130Sstevel@tonic-gate case RTA_IFA: 17140Sstevel@tonic-gate case RTA_AUTHOR: 17150Sstevel@tonic-gate case RTA_BRD: 17160Sstevel@tonic-gate ASSERT(af == AF_INET || af == AF_INET6); 17170Sstevel@tonic-gate switch (af) { 17180Sstevel@tonic-gate case AF_INET: 17190Sstevel@tonic-gate length += sizeof (sin_t); 17200Sstevel@tonic-gate break; 17210Sstevel@tonic-gate case AF_INET6: 17220Sstevel@tonic-gate length += sizeof (sin6_t); 17230Sstevel@tonic-gate break; 17240Sstevel@tonic-gate } 17250Sstevel@tonic-gate break; 17260Sstevel@tonic-gate } 17270Sstevel@tonic-gate } 17281676Sjpk if (sacnt > 0) 17291676Sjpk length += sizeof (rtm_ext_t) + TSOL_RTSECATTR_SIZE(sacnt); 17301676Sjpk 17310Sstevel@tonic-gate return (length); 17320Sstevel@tonic-gate } 17330Sstevel@tonic-gate 17340Sstevel@tonic-gate /* 17350Sstevel@tonic-gate * This routine is called to generate a message to the routing 17360Sstevel@tonic-gate * socket indicating that a redirect has occured, a routing lookup 17370Sstevel@tonic-gate * has failed, or that a protocol has detected timeouts to a particular 17380Sstevel@tonic-gate * destination. This routine is called for message types RTM_LOSING, 17390Sstevel@tonic-gate * RTM_REDIRECT, and RTM_MISS. 17400Sstevel@tonic-gate */ 17410Sstevel@tonic-gate void 17420Sstevel@tonic-gate ip_rts_change(int type, ipaddr_t dst_addr, ipaddr_t gw_addr, ipaddr_t net_mask, 17433448Sdh155122 ipaddr_t source, ipaddr_t author, int flags, int error, int rtm_addrs, 17443448Sdh155122 ip_stack_t *ipst) 17450Sstevel@tonic-gate { 17460Sstevel@tonic-gate rt_msghdr_t *rtm; 17470Sstevel@tonic-gate mblk_t *mp; 17480Sstevel@tonic-gate 17490Sstevel@tonic-gate if (rtm_addrs == 0) 17500Sstevel@tonic-gate return; 17511676Sjpk mp = rts_alloc_msg(type, rtm_addrs, AF_INET, 0); 17520Sstevel@tonic-gate if (mp == NULL) 17530Sstevel@tonic-gate return; 17540Sstevel@tonic-gate rts_fill_msg(type, rtm_addrs, dst_addr, net_mask, gw_addr, source, 0, 17551676Sjpk author, NULL, mp, 0, NULL); 17560Sstevel@tonic-gate rtm = (rt_msghdr_t *)mp->b_rptr; 17570Sstevel@tonic-gate rtm->rtm_flags = flags; 17580Sstevel@tonic-gate rtm->rtm_errno = error; 17590Sstevel@tonic-gate rtm->rtm_flags |= RTF_DONE; 17600Sstevel@tonic-gate rtm->rtm_addrs = rtm_addrs; 1761*8485SPeter.Memishian@Sun.COM rts_queue_input(mp, NULL, AF_INET, RTSQ_ALL, ipst); 17620Sstevel@tonic-gate } 17630Sstevel@tonic-gate 17640Sstevel@tonic-gate /* 17650Sstevel@tonic-gate * This routine is called to generate a message to the routing 17660Sstevel@tonic-gate * socket indicating that the status of a network interface has changed. 17670Sstevel@tonic-gate * Message type generated RTM_IFINFO. 17680Sstevel@tonic-gate */ 17690Sstevel@tonic-gate void 1770*8485SPeter.Memishian@Sun.COM ip_rts_ifmsg(const ipif_t *ipif, uint_t flags) 1771*8485SPeter.Memishian@Sun.COM { 1772*8485SPeter.Memishian@Sun.COM ip_rts_xifmsg(ipif, 0, 0, flags); 1773*8485SPeter.Memishian@Sun.COM } 1774*8485SPeter.Memishian@Sun.COM 1775*8485SPeter.Memishian@Sun.COM void 1776*8485SPeter.Memishian@Sun.COM ip_rts_xifmsg(const ipif_t *ipif, uint64_t set, uint64_t clear, uint_t flags) 17770Sstevel@tonic-gate { 17780Sstevel@tonic-gate if_msghdr_t *ifm; 17790Sstevel@tonic-gate mblk_t *mp; 17800Sstevel@tonic-gate sa_family_t af; 17813448Sdh155122 ip_stack_t *ipst = ipif->ipif_ill->ill_ipst; 17820Sstevel@tonic-gate 17830Sstevel@tonic-gate /* 1784*8485SPeter.Memishian@Sun.COM * This message should be generated only when the physical interface 1785*8485SPeter.Memishian@Sun.COM * is changing state. 17860Sstevel@tonic-gate */ 17870Sstevel@tonic-gate if (ipif->ipif_id != 0) 17880Sstevel@tonic-gate return; 1789*8485SPeter.Memishian@Sun.COM 17900Sstevel@tonic-gate if (ipif->ipif_isv6) { 17910Sstevel@tonic-gate af = AF_INET6; 17921676Sjpk mp = rts_alloc_msg(RTM_IFINFO, RTA_IFP, af, 0); 17930Sstevel@tonic-gate if (mp == NULL) 17940Sstevel@tonic-gate return; 17950Sstevel@tonic-gate rts_fill_msg_v6(RTM_IFINFO, RTA_IFP, &ipv6_all_zeros, 17960Sstevel@tonic-gate &ipv6_all_zeros, &ipv6_all_zeros, &ipv6_all_zeros, 17971676Sjpk &ipv6_all_zeros, &ipv6_all_zeros, ipif, mp, 0, NULL); 17980Sstevel@tonic-gate } else { 17990Sstevel@tonic-gate af = AF_INET; 18001676Sjpk mp = rts_alloc_msg(RTM_IFINFO, RTA_IFP, af, 0); 18010Sstevel@tonic-gate if (mp == NULL) 18020Sstevel@tonic-gate return; 18031676Sjpk rts_fill_msg(RTM_IFINFO, RTA_IFP, 0, 0, 0, 0, 0, 0, ipif, mp, 18041676Sjpk 0, NULL); 18050Sstevel@tonic-gate } 18060Sstevel@tonic-gate ifm = (if_msghdr_t *)mp->b_rptr; 18070Sstevel@tonic-gate ifm->ifm_index = ipif->ipif_ill->ill_phyint->phyint_ifindex; 1808*8485SPeter.Memishian@Sun.COM ifm->ifm_flags = (ipif->ipif_flags | ipif->ipif_ill->ill_flags | 1809*8485SPeter.Memishian@Sun.COM ipif->ipif_ill->ill_phyint->phyint_flags | set) & ~clear; 18100Sstevel@tonic-gate rts_getifdata(&ifm->ifm_data, ipif); 18110Sstevel@tonic-gate ifm->ifm_addrs = RTA_IFP; 1812*8485SPeter.Memishian@Sun.COM 1813*8485SPeter.Memishian@Sun.COM if (flags & RTSQ_DEFAULT) { 1814*8485SPeter.Memishian@Sun.COM flags = RTSQ_ALL; 1815*8485SPeter.Memishian@Sun.COM /* 1816*8485SPeter.Memishian@Sun.COM * If this message is for an underlying interface, prevent 1817*8485SPeter.Memishian@Sun.COM * "normal" (IPMP-unaware) routing sockets from seeing it. 1818*8485SPeter.Memishian@Sun.COM */ 1819*8485SPeter.Memishian@Sun.COM if (IS_UNDER_IPMP(ipif->ipif_ill)) 1820*8485SPeter.Memishian@Sun.COM flags &= ~RTSQ_NORMAL; 1821*8485SPeter.Memishian@Sun.COM } 1822*8485SPeter.Memishian@Sun.COM 1823*8485SPeter.Memishian@Sun.COM rts_queue_input(mp, NULL, af, flags, ipst); 18240Sstevel@tonic-gate } 18250Sstevel@tonic-gate 18260Sstevel@tonic-gate /* 18270Sstevel@tonic-gate * This is called to generate messages to the routing socket 18280Sstevel@tonic-gate * indicating a network interface has had addresses associated with it. 18290Sstevel@tonic-gate * The structure of the code is based on the 4.4BSD-Lite2 <net/rtsock.c>. 18300Sstevel@tonic-gate */ 18310Sstevel@tonic-gate void 1832*8485SPeter.Memishian@Sun.COM ip_rts_newaddrmsg(int cmd, int error, const ipif_t *ipif, uint_t flags) 18330Sstevel@tonic-gate { 18340Sstevel@tonic-gate int pass; 18350Sstevel@tonic-gate int ncmd; 18360Sstevel@tonic-gate int rtm_addrs; 18370Sstevel@tonic-gate mblk_t *mp; 18380Sstevel@tonic-gate ifa_msghdr_t *ifam; 18390Sstevel@tonic-gate rt_msghdr_t *rtm; 18400Sstevel@tonic-gate sa_family_t af; 18413448Sdh155122 ip_stack_t *ipst = ipif->ipif_ill->ill_ipst; 18420Sstevel@tonic-gate 18430Sstevel@tonic-gate if (ipif->ipif_isv6) 18440Sstevel@tonic-gate af = AF_INET6; 18450Sstevel@tonic-gate else 18460Sstevel@tonic-gate af = AF_INET; 1847*8485SPeter.Memishian@Sun.COM 1848*8485SPeter.Memishian@Sun.COM if (flags & RTSQ_DEFAULT) { 1849*8485SPeter.Memishian@Sun.COM flags = RTSQ_ALL; 1850*8485SPeter.Memishian@Sun.COM /* 1851*8485SPeter.Memishian@Sun.COM * If this message is for an underlying interface, prevent 1852*8485SPeter.Memishian@Sun.COM * "normal" (IPMP-unaware) routing sockets from seeing it. 1853*8485SPeter.Memishian@Sun.COM */ 1854*8485SPeter.Memishian@Sun.COM if (IS_UNDER_IPMP(ipif->ipif_ill)) 1855*8485SPeter.Memishian@Sun.COM flags &= ~RTSQ_NORMAL; 1856*8485SPeter.Memishian@Sun.COM } 1857*8485SPeter.Memishian@Sun.COM 18580Sstevel@tonic-gate /* 18590Sstevel@tonic-gate * If the request is DELETE, send RTM_DELETE and RTM_DELADDR. 18600Sstevel@tonic-gate * if the request is ADD, send RTM_NEWADDR and RTM_ADD. 18610Sstevel@tonic-gate */ 18620Sstevel@tonic-gate for (pass = 1; pass < 3; pass++) { 18630Sstevel@tonic-gate if ((cmd == RTM_ADD && pass == 1) || 18640Sstevel@tonic-gate (cmd == RTM_DELETE && pass == 2)) { 18650Sstevel@tonic-gate ncmd = ((cmd == RTM_ADD) ? RTM_NEWADDR : RTM_DELADDR); 18660Sstevel@tonic-gate 18672263Ssommerfe rtm_addrs = (RTA_IFA | RTA_NETMASK | RTA_BRD | RTA_IFP); 18681676Sjpk mp = rts_alloc_msg(ncmd, rtm_addrs, af, 0); 18690Sstevel@tonic-gate if (mp == NULL) 18700Sstevel@tonic-gate continue; 18710Sstevel@tonic-gate switch (af) { 18720Sstevel@tonic-gate case AF_INET: 18730Sstevel@tonic-gate rts_fill_msg(ncmd, rtm_addrs, 0, 18740Sstevel@tonic-gate ipif->ipif_net_mask, 0, ipif->ipif_lcl_addr, 18752263Ssommerfe ipif->ipif_pp_dst_addr, 0, ipif, mp, 18761676Sjpk 0, NULL); 18770Sstevel@tonic-gate break; 18780Sstevel@tonic-gate case AF_INET6: 18790Sstevel@tonic-gate rts_fill_msg_v6(ncmd, rtm_addrs, 18800Sstevel@tonic-gate &ipv6_all_zeros, &ipif->ipif_v6net_mask, 18810Sstevel@tonic-gate &ipv6_all_zeros, &ipif->ipif_v6lcl_addr, 18820Sstevel@tonic-gate &ipif->ipif_v6pp_dst_addr, &ipv6_all_zeros, 18832263Ssommerfe ipif, mp, 0, NULL); 18840Sstevel@tonic-gate break; 18850Sstevel@tonic-gate } 18860Sstevel@tonic-gate ifam = (ifa_msghdr_t *)mp->b_rptr; 18870Sstevel@tonic-gate ifam->ifam_index = 18880Sstevel@tonic-gate ipif->ipif_ill->ill_phyint->phyint_ifindex; 18890Sstevel@tonic-gate ifam->ifam_metric = ipif->ipif_metric; 18900Sstevel@tonic-gate ifam->ifam_flags = ((cmd == RTM_ADD) ? RTF_UP : 0); 18910Sstevel@tonic-gate ifam->ifam_addrs = rtm_addrs; 1892*8485SPeter.Memishian@Sun.COM rts_queue_input(mp, NULL, af, flags, ipst); 18930Sstevel@tonic-gate } 18940Sstevel@tonic-gate if ((cmd == RTM_ADD && pass == 2) || 18950Sstevel@tonic-gate (cmd == RTM_DELETE && pass == 1)) { 18960Sstevel@tonic-gate rtm_addrs = (RTA_DST | RTA_NETMASK); 18971676Sjpk mp = rts_alloc_msg(cmd, rtm_addrs, af, 0); 18980Sstevel@tonic-gate if (mp == NULL) 18990Sstevel@tonic-gate continue; 19000Sstevel@tonic-gate switch (af) { 19010Sstevel@tonic-gate case AF_INET: 19020Sstevel@tonic-gate rts_fill_msg(cmd, rtm_addrs, 19030Sstevel@tonic-gate ipif->ipif_lcl_addr, ipif->ipif_net_mask, 0, 19041676Sjpk 0, 0, 0, NULL, mp, 0, NULL); 19050Sstevel@tonic-gate break; 19060Sstevel@tonic-gate case AF_INET6: 19070Sstevel@tonic-gate rts_fill_msg_v6(cmd, rtm_addrs, 19080Sstevel@tonic-gate &ipif->ipif_v6lcl_addr, 19090Sstevel@tonic-gate &ipif->ipif_v6net_mask, &ipv6_all_zeros, 19100Sstevel@tonic-gate &ipv6_all_zeros, &ipv6_all_zeros, 19111676Sjpk &ipv6_all_zeros, NULL, mp, 0, NULL); 19120Sstevel@tonic-gate break; 19130Sstevel@tonic-gate } 19140Sstevel@tonic-gate rtm = (rt_msghdr_t *)mp->b_rptr; 19150Sstevel@tonic-gate rtm->rtm_index = 19160Sstevel@tonic-gate ipif->ipif_ill->ill_phyint->phyint_ifindex; 19170Sstevel@tonic-gate rtm->rtm_flags = ((cmd == RTM_ADD) ? RTF_UP : 0); 19180Sstevel@tonic-gate rtm->rtm_errno = error; 19190Sstevel@tonic-gate if (error == 0) 19200Sstevel@tonic-gate rtm->rtm_flags |= RTF_DONE; 19210Sstevel@tonic-gate rtm->rtm_addrs = rtm_addrs; 1922*8485SPeter.Memishian@Sun.COM rts_queue_input(mp, NULL, af, flags, ipst); 19230Sstevel@tonic-gate } 19240Sstevel@tonic-gate } 19250Sstevel@tonic-gate } 19260Sstevel@tonic-gate 19270Sstevel@tonic-gate /* 19280Sstevel@tonic-gate * Based on the address family specified in a sockaddr, copy the address field 19290Sstevel@tonic-gate * into an in6_addr_t. 19300Sstevel@tonic-gate * 19310Sstevel@tonic-gate * In the case of AF_UNSPEC, we assume the family is actually AF_INET for 19320Sstevel@tonic-gate * compatibility with programs that leave the family cleared in the sockaddr. 19330Sstevel@tonic-gate * Callers of rts_copyfromsockaddr should check the family themselves if they 19340Sstevel@tonic-gate * wish to verify its value. 19350Sstevel@tonic-gate * 19360Sstevel@tonic-gate * In the case of AF_INET6, a check is made to ensure that address is not an 19370Sstevel@tonic-gate * IPv4-mapped address. 19380Sstevel@tonic-gate */ 19390Sstevel@tonic-gate size_t 19400Sstevel@tonic-gate rts_copyfromsockaddr(struct sockaddr *sa, in6_addr_t *addrp) 19410Sstevel@tonic-gate { 19420Sstevel@tonic-gate switch (sa->sa_family) { 19430Sstevel@tonic-gate case AF_INET: 19440Sstevel@tonic-gate case AF_UNSPEC: 19450Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(((sin_t *)sa)->sin_addr.s_addr, addrp); 19460Sstevel@tonic-gate return (sizeof (sin_t)); 19470Sstevel@tonic-gate case AF_INET6: 19480Sstevel@tonic-gate *addrp = ((sin6_t *)sa)->sin6_addr; 19490Sstevel@tonic-gate if (IN6_IS_ADDR_V4MAPPED(addrp)) 19500Sstevel@tonic-gate return (0); 19510Sstevel@tonic-gate return (sizeof (sin6_t)); 19520Sstevel@tonic-gate default: 19530Sstevel@tonic-gate return (0); 19540Sstevel@tonic-gate } 19550Sstevel@tonic-gate } 1956