1 /* 2 * Copyright (c) 2009, 2020, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 #ifndef SUN_NIO_CH_SCTP_H 27 #define SUN_NIO_CH_SCTP_H 28 29 #include <stdint.h> 30 #include <linux/types.h> 31 #include <sys/socket.h> 32 #include <netinet/in.h> 33 #include "jni.h" 34 35 //Causes compiler error if not found, should make warning and uncomment 36 /*#include <netinet/sctp.h>*/ 37 38 #ifndef IPPROTO_SCTP 39 #define IPPROTO_SCTP 132 40 #endif 41 42 /* The current version of lksctp does 43 * not define the following option that the Java API (optionally) supports */ 44 #ifndef SCTP_EXPLICIT_EOR 45 #define SCTP_EXPLICIT_EOR -1 46 #endif 47 48 /* Definitions taken from lksctp-tools-1.0.8/src/include/netinet/sctp.h */ 49 #ifndef SCTP_INITMSG 50 51 enum sctp_optname { 52 SCTP_RTOINFO, 53 #define SCTP_RTOINFO SCTP_RTOINFO 54 SCTP_ASSOCINFO, 55 #define SCTP_ASSOCINFO SCTP_ASSOCINFO 56 SCTP_INITMSG, 57 #define SCTP_INITMSG SCTP_INITMSG 58 SCTP_NODELAY, /* Get/set nodelay option. */ 59 #define SCTP_NODELAY SCTP_NODELAY 60 SCTP_AUTOCLOSE, 61 #define SCTP_AUTOCLOSE SCTP_AUTOCLOSE 62 SCTP_SET_PEER_PRIMARY_ADDR, 63 #define SCTP_SET_PEER_PRIMARY_ADDR SCTP_SET_PEER_PRIMARY_ADDR 64 SCTP_PRIMARY_ADDR, 65 #define SCTP_PRIMARY_ADDR SCTP_PRIMARY_ADDR 66 SCTP_ADAPTATION_LAYER, 67 #define SCTP_ADAPTATION_LAYER SCTP_ADAPTATION_LAYER 68 SCTP_DISABLE_FRAGMENTS, 69 #define SCTP_DISABLE_FRAGMENTS SCTP_DISABLE_FRAGMENTS 70 SCTP_PEER_ADDR_PARAMS, 71 #define SCTP_PEER_ADDR_PARAMS SCTP_PEER_ADDR_PARAMS 72 SCTP_DEFAULT_SEND_PARAM, 73 #define SCTP_DEFAULT_SEND_PARAM SCTP_DEFAULT_SEND_PARAM 74 SCTP_EVENTS, 75 #define SCTP_EVENTS SCTP_EVENTS 76 SCTP_I_WANT_MAPPED_V4_ADDR, /* Turn on/off mapped v4 addresses */ 77 #define SCTP_I_WANT_MAPPED_V4_ADDR SCTP_I_WANT_MAPPED_V4_ADDR 78 SCTP_MAXSEG, /* Get/set maximum fragment. */ 79 #define SCTP_MAXSEG SCTP_MAXSEG 80 SCTP_STATUS, 81 #define SCTP_STATUS SCTP_STATUS 82 SCTP_GET_PEER_ADDR_INFO, 83 #define SCTP_GET_PEER_ADDR_INFO SCTP_GET_PEER_ADDR_INFO 84 SCTP_DELAYED_ACK_TIME, 85 #define SCTP_DELAYED_ACK_TIME SCTP_DELAYED_ACK_TIME 86 SCTP_CONTEXT, /* Receive Context */ 87 #define SCTP_CONTEXT SCTP_CONTEXT 88 SCTP_FRAGMENT_INTERLEAVE, 89 #define SCTP_FRAGMENT_INTERLEAVE SCTP_FRAGMENT_INTERLEAVE 90 SCTP_PARTIAL_DELIVERY_POINT, /* Set/Get partial delivery point */ 91 #define SCTP_PARTIAL_DELIVERY_POINT SCTP_PARTIAL_DELIVERY_POINT 92 SCTP_MAX_BURST, /* Set/Get max burst */ 93 #define SCTP_MAX_BURST SCTP_MAX_BURST 94 }; 95 96 enum sctp_sac_state { 97 SCTP_COMM_UP, 98 SCTP_COMM_LOST, 99 SCTP_RESTART, 100 SCTP_SHUTDOWN_COMP, 101 SCTP_CANT_STR_ASSOC, 102 }; 103 104 enum sctp_spc_state { 105 SCTP_ADDR_AVAILABLE, 106 SCTP_ADDR_UNREACHABLE, 107 SCTP_ADDR_REMOVED, 108 SCTP_ADDR_ADDED, 109 SCTP_ADDR_MADE_PRIM, 110 SCTP_ADDR_CONFIRMED, 111 }; 112 113 enum sctp_sinfo_flags { 114 SCTP_UNORDERED = 1, /* Send/receive message unordered. */ 115 SCTP_ADDR_OVER = 2, /* Override the primary destination. */ 116 SCTP_ABORT=4, /* Send an ABORT message to the peer. */ 117 SCTP_EOF=MSG_FIN, /* Initiate graceful shutdown process. */ 118 }; 119 120 enum sctp_sn_type { 121 SCTP_SN_TYPE_BASE = (1<<15), 122 SCTP_ASSOC_CHANGE, 123 SCTP_PEER_ADDR_CHANGE, 124 SCTP_SEND_FAILED, 125 SCTP_REMOTE_ERROR, 126 SCTP_SHUTDOWN_EVENT, 127 SCTP_PARTIAL_DELIVERY_EVENT, 128 SCTP_ADAPTATION_INDICATION, 129 }; 130 131 typedef enum sctp_cmsg_type { 132 SCTP_INIT, /* 5.2.1 SCTP Initiation Structure */ 133 #define SCTP_INIT SCTP_INIT 134 SCTP_SNDRCV, /* 5.2.2 SCTP Header Information Structure */ 135 #define SCTP_SNDRCV SCTP_SNDRCV 136 } sctp_cmsg_t; 137 138 enum sctp_msg_flags { 139 MSG_NOTIFICATION = 0x8000, 140 #define MSG_NOTIFICATION MSG_NOTIFICATION 141 }; 142 143 #define SCTP_BINDX_ADD_ADDR 0x01 144 #define SCTP_BINDX_REM_ADDR 0x02 145 146 typedef __s32 sctp_assoc_t; 147 148 struct sctp_initmsg { 149 __u16 sinit_num_ostreams; 150 __u16 sinit_max_instreams; 151 __u16 sinit_max_attempts; 152 __u16 sinit_max_init_timeo; 153 }; 154 155 struct sctp_sndrcvinfo { 156 __u16 sinfo_stream; 157 __u16 sinfo_ssn; 158 __u16 sinfo_flags; 159 __u32 sinfo_ppid; 160 __u32 sinfo_context; 161 __u32 sinfo_timetolive; 162 __u32 sinfo_tsn; 163 __u32 sinfo_cumtsn; 164 sctp_assoc_t sinfo_assoc_id; 165 }; 166 167 struct sctp_event_subscribe { 168 __u8 sctp_data_io_event; 169 __u8 sctp_association_event; 170 __u8 sctp_address_event; 171 __u8 sctp_send_failure_event; 172 __u8 sctp_peer_error_event; 173 __u8 sctp_shutdown_event; 174 __u8 sctp_partial_delivery_event; 175 __u8 sctp_adaptation_layer_event; 176 }; 177 178 struct sctp_send_failed { 179 __u16 ssf_type; 180 __u16 ssf_flags; 181 __u32 ssf_length; 182 __u32 ssf_error; 183 struct sctp_sndrcvinfo ssf_info; 184 sctp_assoc_t ssf_assoc_id; 185 __u8 ssf_data[0]; 186 }; 187 188 struct sctp_assoc_change { 189 __u16 sac_type; 190 __u16 sac_flags; 191 __u32 sac_length; 192 __u16 sac_state; 193 __u16 sac_error; 194 __u16 sac_outbound_streams; 195 __u16 sac_inbound_streams; 196 sctp_assoc_t sac_assoc_id; 197 __u8 sac_info[0]; 198 }; 199 200 struct sctp_shutdown_event { 201 __u16 sse_type; 202 __u16 sse_flags; 203 __u32 sse_length; 204 sctp_assoc_t sse_assoc_id; 205 }; 206 207 struct sctp_paddr_change { 208 __u16 spc_type; 209 __u16 spc_flags; 210 __u32 spc_length; 211 struct sockaddr_storage spc_aaddr; 212 int spc_state; 213 int spc_error; 214 sctp_assoc_t spc_assoc_id; 215 } __attribute__((packed, aligned(4))); 216 217 struct sctp_remote_error { 218 __u16 sre_type; 219 __u16 sre_flags; 220 __u32 sre_length; 221 __u16 sre_error; 222 sctp_assoc_t sre_assoc_id; 223 __u8 sre_data[0]; 224 }; 225 226 struct sctp_adaptation_event { 227 __u16 sai_type; 228 __u16 sai_flags; 229 __u32 sai_length; 230 __u32 sai_adaptation_ind; 231 sctp_assoc_t sai_assoc_id; 232 }; 233 234 struct sctp_setprim { 235 sctp_assoc_t ssp_assoc_id; 236 struct sockaddr_storage ssp_addr; 237 } __attribute__((packed, aligned(4))); 238 239 struct sctp_setpeerprim { 240 sctp_assoc_t sspp_assoc_id; 241 struct sockaddr_storage sspp_addr; 242 } __attribute__((packed, aligned(4))); 243 244 245 struct sctp_pdapi_event { 246 __u16 pdapi_type; 247 __u16 pdapi_flags; 248 __u32 pdapi_length; 249 __u32 pdapi_indication; 250 sctp_assoc_t pdapi_assoc_id; 251 }; 252 253 union sctp_notification { 254 struct { 255 __u16 sn_type; /* Notification type. */ 256 __u16 sn_flags; 257 __u32 sn_length; 258 } sn_header; 259 struct sctp_assoc_change sn_assoc_change; 260 struct sctp_paddr_change sn_paddr_change; 261 struct sctp_remote_error sn_remote_error; 262 struct sctp_send_failed sn_send_failed; 263 struct sctp_shutdown_event sn_shutdown_event; 264 struct sctp_adaptation_event sn_adaptation_event; 265 struct sctp_pdapi_event sn_pdapi_event; 266 }; 267 268 #endif /* SCTP_INITMSG */ 269 270 /* Function types to support dynamic linking of socket API extension functions 271 * for SCTP. This is so that there is no linkage depandancy during build or 272 * runtime for libsctp.*/ 273 typedef int sctp_getladdrs_func(int sd, sctp_assoc_t id, struct sockaddr **addrs); 274 typedef int sctp_freeladdrs_func(struct sockaddr *addrs); 275 typedef int sctp_getpaddrs_func(int sd, sctp_assoc_t id, struct sockaddr **addrs); 276 typedef int sctp_freepaddrs_func(struct sockaddr *addrs); 277 typedef int sctp_bindx_func(int sd, struct sockaddr *addrs, int addrcnt, int flags); 278 typedef int sctp_peeloff_func(int sock, sctp_assoc_t id); 279 280 281 extern sctp_getladdrs_func* nio_sctp_getladdrs; 282 extern sctp_freeladdrs_func* nio_sctp_freeladdrs; 283 extern sctp_getpaddrs_func* nio_sctp_getpaddrs; 284 extern sctp_freepaddrs_func* nio_sctp_freepaddrs; 285 extern sctp_bindx_func* nio_sctp_bindx; 286 extern sctp_peeloff_func* nio_sctp_peeloff; 287 288 jboolean loadSocketExtensionFuncs(JNIEnv* env); 289 290 #endif /* !SUN_NIO_CH_SCTP_H */