1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 24 * Copyright 2012 David Hoeppner. All rights reserved. 25 */ 26 27 /* 28 * This file contains various helper functions. 29 */ 30 31 #include <sys/types.h> 32 #include <sys/strlog.h> 33 #include <sys/policy.h> 34 #include <sys/strsun.h> 35 36 #include <inet/common.h> 37 #include <inet/dccp_impl.h> 38 39 /* 40 * When a CPU is added, we need to allocate the per CPU stats struct. 41 */ 42 void 43 dccp_stack_cpu_add(dccp_stack_t *dccps, processorid_t cpu_seqid) 44 { 45 int i; 46 47 if (cpu_seqid < dccps->dccps_sc_cnt) { 48 return; 49 } 50 51 for (i = dccps->dccps_sc_cnt; i <= cpu_seqid; i++) { 52 ASSERT(dccps->dccps_sc[i] == NULL); 53 dccps->dccps_sc[i] = kmem_zalloc(sizeof (dccp_stats_cpu_t), 54 KM_SLEEP); 55 } 56 57 membar_producer(); 58 dccps->dccps_sc_cnt = cpu_seqid + 1; 59 } 60 61 /* 62 * Diagnostic routine used to return a string associated with the dccp state. 63 */ 64 char * 65 dccp_display(dccp_t *dccp, char *sup_buf, char format) 66 { 67 conn_t *connp; 68 in6_addr_t local; 69 in6_addr_t remote; 70 char local_addrbuf[INET6_ADDRSTRLEN]; 71 char remote_addrbuf[INET6_ADDRSTRLEN]; 72 char priv_buf[INET6_ADDRSTRLEN * 2 + 80]; 73 char buf1[30]; 74 char *buf; 75 char *cp; 76 77 if (sup_buf != NULL) { 78 buf = sup_buf; 79 } else { 80 buf = priv_buf; 81 } 82 83 if (dccp == NULL) { 84 return ("NULL_DCCP"); 85 } 86 87 connp = dccp->dccp_connp; 88 switch (dccp->dccp_state) { 89 case DCCPS_CLOSED: 90 cp = "DCCP_CLOSED"; 91 break; 92 default: 93 (void) mi_sprintf(buf1, "DCCPUnkState(%d)", dccp->dccp_state); 94 cp = buf1; 95 break; 96 } 97 98 switch (format) { 99 case DISP_ADDR_AND_PORT: 100 if (connp->conn_ipversion == IPV4_VERSION) { 101 IN6_IPADDR_TO_V4MAPPED(connp->conn_laddr_v4, &local); 102 IN6_IPADDR_TO_V4MAPPED(connp->conn_faddr_v4, &remote); 103 } else { 104 local = connp->conn_laddr_v6; 105 remote = connp->conn_faddr_v6; 106 } 107 108 (void) inet_ntop(AF_INET6, &local, local_addrbuf, 109 sizeof (local_addrbuf)); 110 (void) inet_ntop(AF_INET6, &remote, remote_addrbuf, 111 sizeof (remote_addrbuf)); 112 (void) mi_sprintf(buf, "[%s.%u, %s.%u] %s", 113 local_addrbuf, ntohs(connp->conn_lport), remote_addrbuf, 114 ntohs(connp->conn_fport), cp); 115 break; 116 case DISP_PORT_ONLY: 117 default: 118 (void) mi_sprintf(buf, "[%u, %u] %s", 119 ntohs(connp->conn_lport), ntohs(connp->conn_fport), cp); 120 break; 121 } 122 123 return (buf); 124 }