jdk/src/solaris/native/sun/nio/ch/Sctp.h
changeset 2542 d859108aea12
child 3072 a801b122142f
equal deleted inserted replaced
2418:15096652c4d4 2542:d859108aea12
       
     1 /*
       
     2  * Copyright 2009 Sun Microsystems, Inc.  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.  Sun designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    23  * have any questions.
       
    24  */
       
    25 
       
    26 #ifndef SUN_NIO_CH_SCTP_H
       
    27 #define SUN_NIO_CH_SCTP_H
       
    28 
       
    29 #ifdef __solaris__
       
    30 
       
    31 #define _XPG4_2
       
    32 #define __EXTENSIONS__
       
    33 #include <sys/socket.h>
       
    34 #include <netinet/sctp.h>
       
    35 #include "jni.h"
       
    36 
       
    37 /* Current Solaris headers don't comply with draft rfc */
       
    38 #ifndef SCTP_EOF
       
    39 #define SCTP_EOF MSG_EOF
       
    40 #endif
       
    41 
       
    42 #ifndef SCTP_UNORDERED
       
    43 #define SCTP_UNORDERED MSG_UNORDERED
       
    44 #endif
       
    45 
       
    46 /* The current version of the socket API extension shipped with Solaris does
       
    47  * not define the following options that the Java API (optionally) supports */
       
    48 #ifndef SCTP_EXPLICIT_EOR
       
    49 #define SCTP_EXPLICIT_EOR -1
       
    50 #endif
       
    51 #ifndef SCTP_FRAGMENT_INTERLEAVE
       
    52 #define SCTP_FRAGMENT_INTERLEAVE -1
       
    53 #endif
       
    54 #ifndef SCTP_SET_PEER_PRIMARY_ADDR
       
    55 #define SCTP_SET_PEER_PRIMARY_ADDR -1
       
    56 #endif
       
    57 
       
    58 /* Function types to support dynamic linking of socket API extension functions
       
    59  * for SCTP. This is so that there is no linkage depandancy during build or
       
    60  * runtime for libsctp.*/
       
    61 typedef int sctp_getladdrs_func(int sock, sctp_assoc_t id, void **addrs);
       
    62 typedef int sctp_freeladdrs_func(void* addrs);
       
    63 typedef int sctp_getpaddrs_func(int sock, sctp_assoc_t id, void **addrs);
       
    64 typedef int sctp_freepaddrs_func(void *addrs);
       
    65 typedef int sctp_bindx_func(int sock, void *addrs, int addrcnt, int flags);
       
    66 
       
    67 
       
    68 #else /* __linux__ */
       
    69 #include <stdint.h>
       
    70 #include <linux/types.h>
       
    71 #include <sys/socket.h>
       
    72 #include <netinet/in.h>
       
    73 #include "jni.h"
       
    74 
       
    75 //Causes compiler error if not found, should make warning and uncomment
       
    76 /*#include <netinet/sctp.h>*/
       
    77 
       
    78 #ifndef IPPROTO_SCTP
       
    79 #define IPPROTO_SCTP    132
       
    80 #endif
       
    81 
       
    82 /* The current version of lksctp does
       
    83  * not define the following option that the Java API (optionally) supports */
       
    84 #ifndef SCTP_EXPLICIT_EOR
       
    85 #define SCTP_EXPLICIT_EOR -1
       
    86 #endif
       
    87 
       
    88 /* Definitions taken from lksctp-tools-1.0.8/src/include/netinet/sctp.h */
       
    89 #ifndef SCTP_INITMSG
       
    90 
       
    91 enum sctp_optname {
       
    92         SCTP_RTOINFO,
       
    93 #define SCTP_RTOINFO SCTP_RTOINFO
       
    94         SCTP_ASSOCINFO,
       
    95 #define SCTP_ASSOCINFO SCTP_ASSOCINFO
       
    96         SCTP_INITMSG,
       
    97 #define SCTP_INITMSG SCTP_INITMSG
       
    98         SCTP_NODELAY,   /* Get/set nodelay option. */
       
    99 #define SCTP_NODELAY    SCTP_NODELAY
       
   100         SCTP_AUTOCLOSE,
       
   101 #define SCTP_AUTOCLOSE SCTP_AUTOCLOSE
       
   102         SCTP_SET_PEER_PRIMARY_ADDR,
       
   103 #define SCTP_SET_PEER_PRIMARY_ADDR SCTP_SET_PEER_PRIMARY_ADDR
       
   104         SCTP_PRIMARY_ADDR,
       
   105 #define SCTP_PRIMARY_ADDR SCTP_PRIMARY_ADDR
       
   106         SCTP_ADAPTATION_LAYER,
       
   107 #define SCTP_ADAPTATION_LAYER SCTP_ADAPTATION_LAYER
       
   108         SCTP_DISABLE_FRAGMENTS,
       
   109 #define SCTP_DISABLE_FRAGMENTS SCTP_DISABLE_FRAGMENTS
       
   110         SCTP_PEER_ADDR_PARAMS,
       
   111 #define SCTP_PEER_ADDR_PARAMS SCTP_PEER_ADDR_PARAMS
       
   112         SCTP_DEFAULT_SEND_PARAM,
       
   113 #define SCTP_DEFAULT_SEND_PARAM SCTP_DEFAULT_SEND_PARAM
       
   114         SCTP_EVENTS,
       
   115 #define SCTP_EVENTS SCTP_EVENTS
       
   116         SCTP_I_WANT_MAPPED_V4_ADDR,  /* Turn on/off mapped v4 addresses  */
       
   117 #define SCTP_I_WANT_MAPPED_V4_ADDR SCTP_I_WANT_MAPPED_V4_ADDR
       
   118         SCTP_MAXSEG,    /* Get/set maximum fragment. */
       
   119 #define SCTP_MAXSEG     SCTP_MAXSEG
       
   120         SCTP_STATUS,
       
   121 #define SCTP_STATUS SCTP_STATUS
       
   122         SCTP_GET_PEER_ADDR_INFO,
       
   123 #define SCTP_GET_PEER_ADDR_INFO SCTP_GET_PEER_ADDR_INFO
       
   124         SCTP_DELAYED_ACK_TIME,
       
   125 #define SCTP_DELAYED_ACK_TIME SCTP_DELAYED_ACK_TIME
       
   126         SCTP_CONTEXT,   /* Receive Context */
       
   127 #define SCTP_CONTEXT SCTP_CONTEXT
       
   128         SCTP_FRAGMENT_INTERLEAVE,
       
   129 #define SCTP_FRAGMENT_INTERLEAVE SCTP_FRAGMENT_INTERLEAVE
       
   130         SCTP_PARTIAL_DELIVERY_POINT,    /* Set/Get partial delivery point */
       
   131 #define SCTP_PARTIAL_DELIVERY_POINT SCTP_PARTIAL_DELIVERY_POINT
       
   132         SCTP_MAX_BURST,         /* Set/Get max burst */
       
   133 #define SCTP_MAX_BURST SCTP_MAX_BURST
       
   134 };
       
   135 
       
   136 enum sctp_sac_state {
       
   137         SCTP_COMM_UP,
       
   138         SCTP_COMM_LOST,
       
   139         SCTP_RESTART,
       
   140         SCTP_SHUTDOWN_COMP,
       
   141         SCTP_CANT_STR_ASSOC,
       
   142 };
       
   143 
       
   144 enum sctp_spc_state {
       
   145         SCTP_ADDR_AVAILABLE,
       
   146         SCTP_ADDR_UNREACHABLE,
       
   147         SCTP_ADDR_REMOVED,
       
   148         SCTP_ADDR_ADDED,
       
   149         SCTP_ADDR_MADE_PRIM,
       
   150         SCTP_ADDR_CONFIRMED,
       
   151 };
       
   152 
       
   153 enum sctp_sinfo_flags {
       
   154         SCTP_UNORDERED = 1,  /* Send/receive message unordered. */
       
   155         SCTP_ADDR_OVER = 2,  /* Override the primary destination. */
       
   156         SCTP_ABORT=4,        /* Send an ABORT message to the peer. */
       
   157         SCTP_EOF=MSG_FIN,    /* Initiate graceful shutdown process. */
       
   158 };
       
   159 
       
   160 enum sctp_sn_type {
       
   161         SCTP_SN_TYPE_BASE     = (1<<15),
       
   162         SCTP_ASSOC_CHANGE,
       
   163         SCTP_PEER_ADDR_CHANGE,
       
   164         SCTP_SEND_FAILED,
       
   165         SCTP_REMOTE_ERROR,
       
   166         SCTP_SHUTDOWN_EVENT,
       
   167         SCTP_PARTIAL_DELIVERY_EVENT,
       
   168         SCTP_ADAPTATION_INDICATION,
       
   169 };
       
   170 
       
   171 typedef enum sctp_cmsg_type {
       
   172         SCTP_INIT,              /* 5.2.1 SCTP Initiation Structure */
       
   173 #define SCTP_INIT SCTP_INIT
       
   174         SCTP_SNDRCV,            /* 5.2.2 SCTP Header Information Structure */
       
   175 #define SCTP_SNDRCV SCTP_SNDRCV
       
   176 } sctp_cmsg_t;
       
   177 
       
   178 enum sctp_msg_flags {
       
   179         MSG_NOTIFICATION = 0x8000,
       
   180 #define MSG_NOTIFICATION MSG_NOTIFICATION
       
   181 };
       
   182 
       
   183 #define SCTP_BINDX_ADD_ADDR 0x01
       
   184 #define SCTP_BINDX_REM_ADDR 0x02
       
   185 
       
   186 typedef __s32 sctp_assoc_t;
       
   187 
       
   188 struct sctp_initmsg {
       
   189         __u16 sinit_num_ostreams;
       
   190         __u16 sinit_max_instreams;
       
   191         __u16 sinit_max_attempts;
       
   192         __u16 sinit_max_init_timeo;
       
   193 };
       
   194 
       
   195 struct sctp_sndrcvinfo {
       
   196         __u16 sinfo_stream;
       
   197         __u16 sinfo_ssn;
       
   198         __u16 sinfo_flags;
       
   199         __u32 sinfo_ppid;
       
   200         __u32 sinfo_context;
       
   201         __u32 sinfo_timetolive;
       
   202         __u32 sinfo_tsn;
       
   203         __u32 sinfo_cumtsn;
       
   204         sctp_assoc_t sinfo_assoc_id;
       
   205 };
       
   206 
       
   207 struct sctp_event_subscribe {
       
   208         __u8 sctp_data_io_event;
       
   209         __u8 sctp_association_event;
       
   210         __u8 sctp_address_event;
       
   211         __u8 sctp_send_failure_event;
       
   212         __u8 sctp_peer_error_event;
       
   213         __u8 sctp_shutdown_event;
       
   214         __u8 sctp_partial_delivery_event;
       
   215         __u8 sctp_adaptation_layer_event;
       
   216 };
       
   217 
       
   218 struct sctp_send_failed {
       
   219         __u16 ssf_type;
       
   220         __u16 ssf_flags;
       
   221         __u32 ssf_length;
       
   222         __u32 ssf_error;
       
   223         struct sctp_sndrcvinfo ssf_info;
       
   224         sctp_assoc_t ssf_assoc_id;
       
   225         __u8 ssf_data[0];
       
   226 };
       
   227 
       
   228 struct sctp_assoc_change {
       
   229         __u16 sac_type;
       
   230         __u16 sac_flags;
       
   231         __u32 sac_length;
       
   232         __u16 sac_state;
       
   233         __u16 sac_error;
       
   234         __u16 sac_outbound_streams;
       
   235         __u16 sac_inbound_streams;
       
   236         sctp_assoc_t sac_assoc_id;
       
   237         __u8 sac_info[0];
       
   238 };
       
   239 
       
   240 struct sctp_shutdown_event {
       
   241         __u16 sse_type;
       
   242         __u16 sse_flags;
       
   243         __u32 sse_length;
       
   244         sctp_assoc_t sse_assoc_id;
       
   245 };
       
   246 
       
   247 struct sctp_paddr_change {
       
   248         __u16 spc_type;
       
   249         __u16 spc_flags;
       
   250         __u32 spc_length;
       
   251         struct sockaddr_storage spc_aaddr;
       
   252         int spc_state;
       
   253         int spc_error;
       
   254         sctp_assoc_t spc_assoc_id;
       
   255 } __attribute__((packed, aligned(4)));
       
   256 
       
   257 struct sctp_remote_error {
       
   258         __u16 sre_type;
       
   259         __u16 sre_flags;
       
   260         __u32 sre_length;
       
   261         __u16 sre_error;
       
   262         sctp_assoc_t sre_assoc_id;
       
   263         __u8 sre_data[0];
       
   264 };
       
   265 
       
   266 struct sctp_adaptation_event {
       
   267         __u16 sai_type;
       
   268         __u16 sai_flags;
       
   269         __u32 sai_length;
       
   270         __u32 sai_adaptation_ind;
       
   271         sctp_assoc_t sai_assoc_id;
       
   272 };
       
   273 
       
   274 struct sctp_setprim {
       
   275         sctp_assoc_t            ssp_assoc_id;
       
   276         struct sockaddr_storage ssp_addr;
       
   277 } __attribute__((packed, aligned(4)));
       
   278 
       
   279 struct sctp_setpeerprim {
       
   280         sctp_assoc_t            sspp_assoc_id;
       
   281         struct sockaddr_storage sspp_addr;
       
   282 } __attribute__((packed, aligned(4)));
       
   283 
       
   284 
       
   285 struct sctp_pdapi_event {
       
   286         __u16 pdapi_type;
       
   287         __u16 pdapi_flags;
       
   288         __u32 pdapi_length;
       
   289         __u32 pdapi_indication;
       
   290         sctp_assoc_t pdapi_assoc_id;
       
   291 };
       
   292 
       
   293 union sctp_notification {
       
   294         struct {
       
   295                 __u16 sn_type;             /* Notification type. */
       
   296                 __u16 sn_flags;
       
   297                 __u32 sn_length;
       
   298         } sn_header;
       
   299         struct sctp_assoc_change sn_assoc_change;
       
   300         struct sctp_paddr_change sn_paddr_change;
       
   301         struct sctp_remote_error sn_remote_error;
       
   302         struct sctp_send_failed sn_send_failed;
       
   303         struct sctp_shutdown_event sn_shutdown_event;
       
   304         struct sctp_adaptation_event sn_adaptation_event;
       
   305         struct sctp_pdapi_event sn_pdapi_event;
       
   306 };
       
   307 
       
   308 #endif /* SCTP_INITMSG */
       
   309 
       
   310 /* Function types to support dynamic linking of socket API extension functions
       
   311  * for SCTP. This is so that there is no linkage depandancy during build or
       
   312  * runtime for libsctp.*/
       
   313 typedef int sctp_getladdrs_func(int sd, sctp_assoc_t id, struct sockaddr **addrs);
       
   314 typedef int sctp_freeladdrs_func(struct sockaddr *addrs);
       
   315 typedef int sctp_getpaddrs_func(int sd, sctp_assoc_t id, struct sockaddr **addrs);
       
   316 typedef int sctp_freepaddrs_func(struct sockaddr *addrs);
       
   317 typedef int sctp_bindx_func(int sd, struct sockaddr *addrs, int addrcnt, int flags);
       
   318 
       
   319 #endif /* __linux__ */
       
   320 
       
   321 sctp_getladdrs_func* nio_sctp_getladdrs;
       
   322 sctp_freeladdrs_func* nio_sctp_freeladdrs;
       
   323 sctp_getpaddrs_func* nio_sctp_getpaddrs;
       
   324 sctp_freepaddrs_func* nio_sctp_freepaddrs;
       
   325 sctp_bindx_func* nio_sctp_bindx;
       
   326 
       
   327 jboolean loadSocketExtensionFuncs(JNIEnv* env);
       
   328 
       
   329 #endif /* !SUN_NIO_CH_SCTP_H */