10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51673Sgt145670 * Common Development and Distribution License (the "License"). 61673Sgt145670 * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 2212643SAnders.Persson@Sun.COM * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 230Sstevel@tonic-gate */ 240Sstevel@tonic-gate 250Sstevel@tonic-gate #ifndef _UDP_IMPL_H 260Sstevel@tonic-gate #define _UDP_IMPL_H 270Sstevel@tonic-gate 28741Smasputra /* 29741Smasputra * UDP implementation private declarations. These interfaces are 30741Smasputra * used to build the IP module and are not meant to be accessed 31741Smasputra * by any modules except IP itself. They are undocumented and are 32741Smasputra * subject to change without notice. 33741Smasputra */ 34741Smasputra 350Sstevel@tonic-gate #ifdef __cplusplus 360Sstevel@tonic-gate extern "C" { 370Sstevel@tonic-gate #endif 380Sstevel@tonic-gate 390Sstevel@tonic-gate #ifdef _KERNEL 400Sstevel@tonic-gate 410Sstevel@tonic-gate #include <sys/int_types.h> 423448Sdh155122 #include <sys/netstack.h> 430Sstevel@tonic-gate 440Sstevel@tonic-gate #include <netinet/in.h> 450Sstevel@tonic-gate #include <netinet/ip6.h> 460Sstevel@tonic-gate 470Sstevel@tonic-gate #include <inet/common.h> 480Sstevel@tonic-gate #include <inet/ip.h> 491676Sjpk #include <inet/optcom.h> 5012016SGirish.Moodalbail@Sun.COM #include <inet/tunables.h> 510Sstevel@tonic-gate 52741Smasputra #define UDP_MOD_ID 5607 53741Smasputra 543448Sdh155122 /* 553448Sdh155122 * Bind hash list size and hash function. It has to be a power of 2 for 563448Sdh155122 * hashing. 573448Sdh155122 */ 583448Sdh155122 #define UDP_BIND_FANOUT_SIZE 512 593448Sdh155122 #define UDP_BIND_HASH(lport, size) \ 603448Sdh155122 ((ntohs((uint16_t)lport)) & (size - 1)) 613448Sdh155122 623448Sdh155122 /* UDP bind fanout hash structure. */ 633448Sdh155122 typedef struct udp_fanout_s { 643448Sdh155122 struct udp_s *uf_udp; 653448Sdh155122 kmutex_t uf_lock; 663448Sdh155122 #if defined(_LP64) || defined(_I32LPx) 673448Sdh155122 char uf_pad[48]; 683448Sdh155122 #else 693448Sdh155122 char uf_pad[56]; 703448Sdh155122 #endif 713448Sdh155122 } udp_fanout_t; 723448Sdh155122 733448Sdh155122 /* Kstats */ 743448Sdh155122 typedef struct udp_stat { /* Class "net" kstats */ 753448Sdh155122 kstat_named_t udp_sock_fallback; 763448Sdh155122 kstat_named_t udp_out_opt; 773448Sdh155122 kstat_named_t udp_out_err_notconn; 783448Sdh155122 kstat_named_t udp_out_err_output; 793448Sdh155122 kstat_named_t udp_out_err_tudr; 803448Sdh155122 #ifdef DEBUG 813448Sdh155122 kstat_named_t udp_data_conn; 823448Sdh155122 kstat_named_t udp_data_notconn; 8311042SErik.Nordmark@Sun.COM kstat_named_t udp_out_lastdst; 8411042SErik.Nordmark@Sun.COM kstat_named_t udp_out_diffdst; 8511042SErik.Nordmark@Sun.COM kstat_named_t udp_out_ipv6; 8611042SErik.Nordmark@Sun.COM kstat_named_t udp_out_mapped; 8711042SErik.Nordmark@Sun.COM kstat_named_t udp_out_ipv4; 883448Sdh155122 #endif 8912869SKacheong.Poon@Sun.COM } udp_stat_t; 903448Sdh155122 9112869SKacheong.Poon@Sun.COM /* 9212869SKacheong.Poon@Sun.COM * This struct contains only the counter part of udp_stat_t. It is used 9312869SKacheong.Poon@Sun.COM * in udp_stats_cpu_t instead of udp_stat_t to save memory space. 9412869SKacheong.Poon@Sun.COM */ 9512869SKacheong.Poon@Sun.COM typedef struct { 9612869SKacheong.Poon@Sun.COM uint64_t udp_sock_fallback; 9712869SKacheong.Poon@Sun.COM uint64_t udp_out_opt; 9812869SKacheong.Poon@Sun.COM uint64_t udp_out_err_notconn; 9912869SKacheong.Poon@Sun.COM uint64_t udp_out_err_output; 10012869SKacheong.Poon@Sun.COM uint64_t udp_out_err_tudr; 10112869SKacheong.Poon@Sun.COM #ifdef DEBUG 10212869SKacheong.Poon@Sun.COM uint64_t udp_data_conn; 10312869SKacheong.Poon@Sun.COM uint64_t udp_data_notconn; 10412869SKacheong.Poon@Sun.COM uint64_t udp_out_lastdst; 10512869SKacheong.Poon@Sun.COM uint64_t udp_out_diffdst; 10612869SKacheong.Poon@Sun.COM uint64_t udp_out_ipv6; 10712869SKacheong.Poon@Sun.COM uint64_t udp_out_mapped; 10812869SKacheong.Poon@Sun.COM uint64_t udp_out_ipv4; 10912869SKacheong.Poon@Sun.COM #endif 11012869SKacheong.Poon@Sun.COM } udp_stat_counter_t; 11112869SKacheong.Poon@Sun.COM 11212869SKacheong.Poon@Sun.COM /* Per CPU stats: UDP MIB2 and UDP kstat. */ 11312869SKacheong.Poon@Sun.COM typedef struct { 11412869SKacheong.Poon@Sun.COM mib2_udp_t udp_sc_mib; 11512869SKacheong.Poon@Sun.COM udp_stat_counter_t udp_sc_stats; 11612869SKacheong.Poon@Sun.COM } udp_stats_cpu_t; 1173448Sdh155122 11812016SGirish.Moodalbail@Sun.COM #define UDP_NUM_EPRIV_PORTS 64 1193448Sdh155122 12012016SGirish.Moodalbail@Sun.COM /* Default buffer size and flow control wake up threshold. */ 12112016SGirish.Moodalbail@Sun.COM #define UDP_RECV_HIWATER (56 * 1024) 12212016SGirish.Moodalbail@Sun.COM #define UDP_RECV_LOWATER 128 12312016SGirish.Moodalbail@Sun.COM #define UDP_XMIT_HIWATER (56 * 1024) 12412016SGirish.Moodalbail@Sun.COM #define UDP_XMIT_LOWATER 1024 1253448Sdh155122 1263448Sdh155122 /* 1273448Sdh155122 * UDP stack instances 1283448Sdh155122 */ 1293448Sdh155122 struct udp_stack { 1303448Sdh155122 netstack_t *us_netstack; /* Common netstack */ 1313448Sdh155122 1323448Sdh155122 uint_t us_bind_fanout_size; 1333448Sdh155122 udp_fanout_t *us_bind_fanout; 1343448Sdh155122 1353448Sdh155122 int us_num_epriv_ports; 1363448Sdh155122 in_port_t us_epriv_ports[UDP_NUM_EPRIV_PORTS]; 13712016SGirish.Moodalbail@Sun.COM kmutex_t us_epriv_port_lock; 1383448Sdh155122 1393448Sdh155122 /* Hint not protected by any lock */ 1403448Sdh155122 in_port_t us_next_port_to_try; 1413448Sdh155122 14212016SGirish.Moodalbail@Sun.COM /* UDP tunables table */ 14312016SGirish.Moodalbail@Sun.COM struct mod_prop_info_s *us_propinfo_tbl; 1443448Sdh155122 1453448Sdh155122 kstat_t *us_mibkp; /* kstats exporting mib data */ 1463448Sdh155122 kstat_t *us_kstat; 1473448Sdh155122 1483448Sdh155122 /* 1493448Sdh155122 * The smallest anonymous port in the priviledged port range which UDP 1503448Sdh155122 * looks for free port. Use in the option UDP_ANONPRIVBIND. 1513448Sdh155122 */ 1523448Sdh155122 in_port_t us_min_anonpriv_port; 1533448Sdh155122 1548348SEric.Yu@Sun.COM ldi_ident_t us_ldi_ident; 15512869SKacheong.Poon@Sun.COM 15612869SKacheong.Poon@Sun.COM udp_stats_cpu_t **us_sc; 15712869SKacheong.Poon@Sun.COM int us_sc_cnt; 1583448Sdh155122 }; 1598348SEric.Yu@Sun.COM 1603448Sdh155122 typedef struct udp_stack udp_stack_t; 1613448Sdh155122 1620Sstevel@tonic-gate /* Internal udp control structure, one per open stream */ 1630Sstevel@tonic-gate typedef struct udp_s { 1645240Snordmark /* 16511042SErik.Nordmark@Sun.COM * The addresses and ports in the conn_t and udp_state are protected by 16611042SErik.Nordmark@Sun.COM * conn_lock and the fanout lock i.e. uf_lock. Need both locks to change 16711042SErik.Nordmark@Sun.COM * the fields, either lock is sufficient for reading the field. 16811042SErik.Nordmark@Sun.COM * conn_lock also protects the content of udp_t. 1695240Snordmark */ 170741Smasputra uint32_t udp_state; /* TPI state */ 1715240Snordmark 17211042SErik.Nordmark@Sun.COM ip_pkt_t udp_recv_ipp; /* Used for IPv4 options received */ 1730Sstevel@tonic-gate 1745240Snordmark /* Written to only once at the time of opening the endpoint */ 1755240Snordmark conn_t *udp_connp; 1760Sstevel@tonic-gate 17711042SErik.Nordmark@Sun.COM uint32_t 17811042SErik.Nordmark@Sun.COM udp_issocket : 1, /* socket mode; sockfs is on top */ 17911042SErik.Nordmark@Sun.COM udp_nat_t_endpoint : 1, /* UDP_NAT_T_ENDPOINT option */ 18011042SErik.Nordmark@Sun.COM udp_rcvhdr : 1, /* UDP_RCVHDR option */ 18111042SErik.Nordmark@Sun.COM 18211042SErik.Nordmark@Sun.COM udp_pad_to_bit_31 : 29; 1835240Snordmark 1845240Snordmark /* Following 2 fields protected by the uf_lock */ 1850Sstevel@tonic-gate struct udp_s *udp_bind_hash; /* Bind hash chain */ 1860Sstevel@tonic-gate struct udp_s **udp_ptpbhn; /* Pointer to previous bind hash next. */ 187741Smasputra 1888348SEric.Yu@Sun.COM kmutex_t udp_recv_lock; /* recv lock */ 1898348SEric.Yu@Sun.COM size_t udp_rcv_disply_hiwat; /* user's view of rcvbuf */ 190741Smasputra size_t udp_rcv_hiwat; /* receive high watermark */ 1913284Sapersson 19211042SErik.Nordmark@Sun.COM /* Set at open time and never changed */ 1933448Sdh155122 udp_stack_t *udp_us; /* Stack instance for zone */ 19411042SErik.Nordmark@Sun.COM 1958348SEric.Yu@Sun.COM int udp_delayed_error; 1968348SEric.Yu@Sun.COM mblk_t *udp_fallback_queue_head; 1978348SEric.Yu@Sun.COM mblk_t *udp_fallback_queue_tail; 1988348SEric.Yu@Sun.COM struct sockaddr_storage udp_delayed_addr; 1990Sstevel@tonic-gate } udp_t; 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate /* UDP Protocol header aligned */ 2020Sstevel@tonic-gate typedef struct udpahdr_s { 2030Sstevel@tonic-gate in_port_t uha_src_port; /* Source port */ 2040Sstevel@tonic-gate in_port_t uha_dst_port; /* Destination port */ 2050Sstevel@tonic-gate uint16_t uha_length; /* UDP length */ 2060Sstevel@tonic-gate uint16_t uha_checksum; /* UDP checksum */ 2070Sstevel@tonic-gate } udpha_t; 2080Sstevel@tonic-gate 20912016SGirish.Moodalbail@Sun.COM #define us_wroff_extra us_propinfo_tbl[0].prop_cur_uval 21012016SGirish.Moodalbail@Sun.COM #define us_ipv4_ttl us_propinfo_tbl[1].prop_cur_uval 21112016SGirish.Moodalbail@Sun.COM #define us_ipv6_hoplimit us_propinfo_tbl[2].prop_cur_uval 21212016SGirish.Moodalbail@Sun.COM #define us_smallest_nonpriv_port us_propinfo_tbl[3].prop_cur_uval 21312016SGirish.Moodalbail@Sun.COM #define us_do_checksum us_propinfo_tbl[4].prop_cur_bval 21412016SGirish.Moodalbail@Sun.COM #define us_smallest_anon_port us_propinfo_tbl[5].prop_cur_uval 21512016SGirish.Moodalbail@Sun.COM #define us_largest_anon_port us_propinfo_tbl[6].prop_cur_uval 21612016SGirish.Moodalbail@Sun.COM #define us_xmit_hiwat us_propinfo_tbl[7].prop_cur_uval 21712016SGirish.Moodalbail@Sun.COM #define us_xmit_lowat us_propinfo_tbl[8].prop_cur_uval 21812016SGirish.Moodalbail@Sun.COM #define us_recv_hiwat us_propinfo_tbl[9].prop_cur_uval 21912016SGirish.Moodalbail@Sun.COM #define us_max_buf us_propinfo_tbl[10].prop_cur_uval 22012016SGirish.Moodalbail@Sun.COM #define us_pmtu_discovery us_propinfo_tbl[11].prop_cur_bval 22112016SGirish.Moodalbail@Sun.COM #define us_sendto_ignerr us_propinfo_tbl[12].prop_cur_bval 2223448Sdh155122 22312869SKacheong.Poon@Sun.COM #define UDPS_BUMP_MIB(us, x) \ 22412869SKacheong.Poon@Sun.COM BUMP_MIB(&(us)->us_sc[CPU->cpu_seqid]->udp_sc_mib, x) 22512869SKacheong.Poon@Sun.COM 22612869SKacheong.Poon@Sun.COM #define UDP_STAT(us, x) ((us)->us_sc[CPU->cpu_seqid]->udp_sc_stats.x++) 2273448Sdh155122 #define UDP_STAT_UPDATE(us, x, n) \ 22812869SKacheong.Poon@Sun.COM ((us)->us->sc[CPU->cpu_seqid]->udp_sc_stats.x.value.ui64 += (n)) 229741Smasputra #ifdef DEBUG 2303448Sdh155122 #define UDP_DBGSTAT(us, x) UDP_STAT(us, x) 231741Smasputra #else 2323448Sdh155122 #define UDP_DBGSTAT(us, x) 233741Smasputra #endif /* DEBUG */ 234741Smasputra 235741Smasputra extern int udp_opt_default(queue_t *, t_scalar_t, t_scalar_t, uchar_t *); 2368348SEric.Yu@Sun.COM extern int udp_tpi_opt_get(queue_t *, t_scalar_t, t_scalar_t, uchar_t *); 2378348SEric.Yu@Sun.COM extern int udp_tpi_opt_set(queue_t *, uint_t, int, int, uint_t, uchar_t *, 23811042SErik.Nordmark@Sun.COM uint_t *, uchar_t *, void *, cred_t *); 239*12897SBaban.Kenkre@Sun.COM extern mblk_t *udp_snmp_get(queue_t *, mblk_t *, boolean_t); 240741Smasputra extern int udp_snmp_set(queue_t *, t_scalar_t, t_scalar_t, uchar_t *, int); 2418348SEric.Yu@Sun.COM extern void udp_ddi_g_init(void); 2428348SEric.Yu@Sun.COM extern void udp_ddi_g_destroy(void); 2438348SEric.Yu@Sun.COM extern void udp_output(conn_t *connp, mblk_t *mp, struct sockaddr *addr, 2448348SEric.Yu@Sun.COM socklen_t addrlen); 2458348SEric.Yu@Sun.COM extern void udp_wput(queue_t *, mblk_t *); 2461676Sjpk 24712869SKacheong.Poon@Sun.COM extern void *udp_kstat_init(netstackid_t stackid); 24812869SKacheong.Poon@Sun.COM extern void udp_kstat_fini(netstackid_t stackid, kstat_t *ksp); 24912869SKacheong.Poon@Sun.COM extern void *udp_kstat2_init(netstackid_t stackid); 25012869SKacheong.Poon@Sun.COM extern void udp_kstat2_fini(netstackid_t, kstat_t *); 25112869SKacheong.Poon@Sun.COM 25212869SKacheong.Poon@Sun.COM extern void udp_stack_cpu_add(udp_stack_t *, processorid_t); 25312869SKacheong.Poon@Sun.COM 2541676Sjpk /* 2551676Sjpk * Object to represent database of options to search passed to 2561676Sjpk * {sock,tpi}optcom_req() interface routine to take care of option 2571676Sjpk * management and associated methods. 2581676Sjpk */ 2591676Sjpk extern optdb_obj_t udp_opt_obj; 2601676Sjpk extern uint_t udp_max_optsize; 2611676Sjpk 2628348SEric.Yu@Sun.COM extern sock_lower_handle_t udp_create(int, int, int, sock_downcalls_t **, 2638348SEric.Yu@Sun.COM uint_t *, int *, int, cred_t *); 2648963SAnders.Persson@Sun.COM extern int udp_fallback(sock_lower_handle_t, queue_t *, boolean_t, 26512643SAnders.Persson@Sun.COM so_proto_quiesced_cb_t, sock_quiesce_arg_t *); 2668348SEric.Yu@Sun.COM 2678348SEric.Yu@Sun.COM extern sock_downcalls_t sock_udp_downcalls; 2688348SEric.Yu@Sun.COM 2690Sstevel@tonic-gate #endif /* _KERNEL */ 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate #ifdef __cplusplus 2720Sstevel@tonic-gate } 2730Sstevel@tonic-gate #endif 2740Sstevel@tonic-gate 2750Sstevel@tonic-gate #endif /* _UDP_IMPL_H */ 276