67 #ifndef OPENSSL_NO_DGRAM
69 #if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VMS)
70 #include <sys/timeb.h>
73 #ifndef OPENSSL_NO_SCTP
74 #include <netinet/sctp.h>
76 #define OPENSSL_SCTP_DATA_CHUNK_TYPE 0x00
77 #define OPENSSL_SCTP_FORWARD_CUM_TSN_CHUNK_TYPE 0xc0
80 #ifdef OPENSSL_SYS_LINUX
85 #define sock_write SockWrite
86 #define sock_read SockRead
87 #define sock_puts SockPuts
90 static int dgram_write(
BIO *
h,
const char *buf,
int num);
91 static int dgram_read(
BIO *
h,
char *buf,
int size);
92 static int dgram_puts(
BIO *
h,
const char *str);
93 static long dgram_ctrl(
BIO *
h,
int cmd,
long arg1,
void *arg2);
94 static int dgram_new(
BIO *
h);
95 static int dgram_free(
BIO *
data);
96 static int dgram_clear(
BIO *bio);
98 #ifndef OPENSSL_NO_SCTP
99 static int dgram_sctp_write(
BIO *
h,
const char *buf,
int num);
100 static int dgram_sctp_read(
BIO *
h,
char *buf,
int size);
101 static int dgram_sctp_puts(
BIO *
h,
const char *str);
102 static long dgram_sctp_ctrl(
BIO *
h,
int cmd,
long arg1,
void *arg2);
103 static int dgram_sctp_new(
BIO *
h);
104 static int dgram_sctp_free(
BIO *
data);
105 #ifdef SCTP_AUTHENTICATION_EVENT
106 static void dgram_sctp_handle_auth_free_key_event(
BIO *
b,
union sctp_notification *snp);
110 static int BIO_dgram_should_retry(
int s);
112 static void get_current_time(
struct timeval *
t);
128 #ifndef OPENSSL_NO_SCTP
132 "datagram sctp socket",
150 struct sockaddr_in6 sa_in6;
160 #ifndef OPENSSL_NO_SCTP
174 struct sockaddr_in6 sa_in6;
196 return(&methods_dgramp);
204 if (ret == NULL)
return(NULL);
209 static int dgram_new(
BIO *bi)
225 static int dgram_free(
BIO *
a)
229 if (a == NULL)
return(0);
230 if ( ! dgram_clear(a))
239 static int dgram_clear(
BIO *a)
241 if (a == NULL)
return(0);
254 static void dgram_adjust_rcv_timeout(
BIO *
b)
256 #if defined(SO_RCVTIMEO)
258 int sz =
sizeof(
int);
263 struct timeval timenow, timeleft;
266 #ifdef OPENSSL_SYS_WINDOWS
268 if (getsockopt(b->
num, SOL_SOCKET, SO_RCVTIMEO,
269 (
void*)&timeout, &sz) < 0)
270 { perror(
"getsockopt"); }
277 if ( getsockopt(b->
num, SOL_SOCKET, SO_RCVTIMEO,
279 { perror(
"getsockopt"); }
283 get_current_time(&timenow);
286 memcpy(&timeleft, &(data->
next_timeout),
sizeof(
struct timeval));
287 timeleft.tv_sec -= timenow.tv_sec;
288 timeleft.tv_usec -= timenow.tv_usec;
289 if (timeleft.tv_usec < 0)
292 timeleft.tv_usec += 1000000;
295 if (timeleft.tv_sec < 0)
298 timeleft.tv_usec = 1;
309 #ifdef OPENSSL_SYS_WINDOWS
310 timeout = timeleft.tv_sec * 1000 + timeleft.tv_usec / 1000;
311 if (setsockopt(b->
num, SOL_SOCKET, SO_RCVTIMEO,
312 (
void*)&timeout,
sizeof(timeout)) < 0)
313 { perror(
"setsockopt"); }
315 if ( setsockopt(b->
num, SOL_SOCKET, SO_RCVTIMEO, &timeleft,
316 sizeof(
struct timeval)) < 0)
317 { perror(
"setsockopt"); }
324 static void dgram_reset_rcv_timeout(
BIO *b)
326 #if defined(SO_RCVTIMEO)
332 #ifdef OPENSSL_SYS_WINDOWS
335 if (setsockopt(b->
num, SOL_SOCKET, SO_RCVTIMEO,
336 (
void*)&timeout,
sizeof(timeout)) < 0)
337 { perror(
"setsockopt"); }
340 sizeof(
struct timeval)) < 0)
341 { perror(
"setsockopt"); }
347 static int dgram_read(
BIO *b,
char *out,
int outl)
356 union {
size_t s;
int i; }
len;
359 struct sockaddr_in sa_in;
361 struct sockaddr_in6 sa_in6;
367 sa.len.i=
sizeof(sa.peer);
372 memset(&sa.peer, 0x00,
sizeof(sa.peer));
373 dgram_adjust_rcv_timeout(b);
374 ret=recvfrom(b->
num,out,outl,0,&sa.peer.sa,(
void *)&sa.len);
375 if (
sizeof(sa.len.i)!=
sizeof(sa.len.s) && sa.len.i==0)
378 sa.len.i = (int)sa.len.s;
387 if (BIO_dgram_should_retry(ret))
394 dgram_reset_rcv_timeout(b);
399 static int dgram_write(
BIO *b,
const char *in,
int inl)
409 int peerlen =
sizeof(data->
peer);
411 if (data->
peer.
sa.sa_family == AF_INET)
414 else if (data->
peer.
sa.sa_family == AF_INET6)
415 peerlen =
sizeof(data->
peer.sa_in6);
417 #if defined(NETWARE_CLIB) && defined(NETWARE_BSDSOCK)
418 ret=sendto(b->
num, (
char *)in, inl, 0, &data->
peer.
sa, peerlen);
420 ret=sendto(b->
num, in, inl, 0, &data->
peer.
sa, peerlen);
427 if (BIO_dgram_should_retry(ret))
433 if ( data->
_errno == EMSGSIZE)
442 static long dgram_ctrl(
BIO *b,
int cmd,
long num,
void *
ptr)
446 struct sockaddr *to = NULL;
448 #if defined(IP_MTU_DISCOVER) || defined(IP_MTU)
449 long sockopt_val = 0;
450 unsigned int sockopt_len = 0;
452 #ifdef OPENSSL_SYS_LINUX
456 struct sockaddr_in s4;
458 struct sockaddr_in6 s6;
478 b->
num= *((
int *)ptr);
486 if (ip != NULL) *ip=b->
num;
507 to = (
struct sockaddr *)ptr;
509 if (connect(b->
num, to,
sizeof(
struct sockaddr)) < 0)
510 { perror(
"connect"); ret = 0; }
514 switch (to->sa_family)
521 memcpy(&data->
peer,to,
sizeof(data->
peer.sa_in6));
534 #ifdef OPENSSL_SYS_LINUX
535 addr_len = (socklen_t)
sizeof(addr);
536 memset((
void *)&addr, 0,
sizeof(addr));
537 if (getsockname(b->
num, &addr.sa, &addr_len) < 0)
542 sockopt_len =
sizeof(sockopt_val);
543 switch (addr.sa.sa_family)
546 sockopt_val = IP_PMTUDISC_DO;
547 if ((ret = setsockopt(b->
num, IPPROTO_IP, IP_MTU_DISCOVER,
548 &sockopt_val,
sizeof(sockopt_val))) < 0)
549 perror(
"setsockopt");
551 #if OPENSSL_USE_IPV6 && defined(IPV6_MTU_DISCOVER)
553 sockopt_val = IPV6_PMTUDISC_DO;
554 if ((ret = setsockopt(b->
num, IPPROTO_IPV6, IPV6_MTU_DISCOVER,
555 &sockopt_val,
sizeof(sockopt_val))) < 0)
556 perror(
"setsockopt");
568 #ifdef OPENSSL_SYS_LINUX
569 addr_len = (socklen_t)
sizeof(addr);
570 memset((
void *)&addr, 0,
sizeof(addr));
571 if (getsockname(b->
num, &addr.sa, &addr_len) < 0)
576 sockopt_len =
sizeof(sockopt_val);
577 switch (addr.sa.sa_family)
580 if ((ret = getsockopt(b->
num, IPPROTO_IP, IP_MTU, (
void *)&sockopt_val,
581 &sockopt_len)) < 0 || sockopt_val < 0)
590 data->
mtu = sockopt_val - 8 - 20;
594 #if OPENSSL_USE_IPV6 && defined(IPV6_MTU)
596 if ((ret = getsockopt(b->
num, IPPROTO_IPV6, IPV6_MTU, (
void *)&sockopt_val,
597 &sockopt_len)) < 0 || sockopt_val < 0)
606 data->
mtu = sockopt_val - 8 - 40;
620 switch (data->
peer.
sa.sa_family)
627 #ifdef IN6_IS_ADDR_V4MAPPED
628 if (IN6_IS_ADDR_V4MAPPED(&data->
peer.sa_in6.sin6_addr))
648 to = (
struct sockaddr *)ptr;
653 switch (to->sa_family)
660 memcpy(&data->
peer,to,
sizeof(data->
peer.sa_in6));
671 memset(&(data->
peer), 0x00,
sizeof(data->
peer));
675 switch (data->
peer.
sa.sa_family)
682 ret=
sizeof(data->
peer.sa_in6);
686 ret=
sizeof(data->
peer.
sa);
689 if (num==0 || num>ret)
691 memcpy(ptr,&data->
peer,(ret=num));
694 to = (
struct sockaddr *) ptr;
695 switch (to->sa_family)
702 memcpy(&data->
peer,to,
sizeof(data->
peer.sa_in6));
711 memcpy(&(data->
next_timeout), ptr,
sizeof(
struct timeval));
713 #if defined(SO_RCVTIMEO)
715 #ifdef OPENSSL_SYS_WINDOWS
717 struct timeval *tv = (
struct timeval *)ptr;
718 int timeout = tv->tv_sec * 1000 + tv->tv_usec/1000;
719 if (setsockopt(b->
num, SOL_SOCKET, SO_RCVTIMEO,
720 (
void*)&timeout,
sizeof(timeout)) < 0)
721 { perror(
"setsockopt"); ret = -1; }
724 if ( setsockopt(b->
num, SOL_SOCKET, SO_RCVTIMEO, ptr,
725 sizeof(
struct timeval)) < 0)
726 { perror(
"setsockopt"); ret = -1; }
730 #ifdef OPENSSL_SYS_WINDOWS
732 int timeout, sz =
sizeof(timeout);
733 struct timeval *tv = (
struct timeval *)ptr;
734 if (getsockopt(b->
num, SOL_SOCKET, SO_RCVTIMEO,
735 (
void*)&timeout, &sz) < 0)
736 { perror(
"getsockopt"); ret = -1; }
739 tv->tv_sec = timeout / 1000;
740 tv->tv_usec = (timeout % 1000) * 1000;
745 if ( getsockopt(b->
num, SOL_SOCKET, SO_RCVTIMEO,
746 ptr, (
void *)&ret) < 0)
747 { perror(
"getsockopt"); ret = -1; }
751 #if defined(SO_SNDTIMEO)
753 #ifdef OPENSSL_SYS_WINDOWS
755 struct timeval *tv = (
struct timeval *)ptr;
756 int timeout = tv->tv_sec * 1000 + tv->tv_usec/1000;
757 if (setsockopt(b->
num, SOL_SOCKET, SO_SNDTIMEO,
758 (
void*)&timeout,
sizeof(timeout)) < 0)
759 { perror(
"setsockopt"); ret = -1; }
762 if ( setsockopt(b->
num, SOL_SOCKET, SO_SNDTIMEO, ptr,
763 sizeof(
struct timeval)) < 0)
764 { perror(
"setsockopt"); ret = -1; }
768 #ifdef OPENSSL_SYS_WINDOWS
770 int timeout, sz =
sizeof(timeout);
771 struct timeval *tv = (
struct timeval *)ptr;
772 if (getsockopt(b->
num, SOL_SOCKET, SO_SNDTIMEO,
773 (
void*)&timeout, &sz) < 0)
774 { perror(
"getsockopt"); ret = -1; }
777 tv->tv_sec = timeout / 1000;
778 tv->tv_usec = (timeout % 1000) * 1000;
783 if ( getsockopt(b->
num, SOL_SOCKET, SO_SNDTIMEO,
784 ptr, (
void *)&ret) < 0)
785 { perror(
"getsockopt"); ret = -1; }
792 #ifdef OPENSSL_SYS_WINDOWS
793 if ( data->
_errno == WSAETIMEDOUT)
795 if ( data->
_errno == EAGAIN)
806 if ( data->
_errno == EMSGSIZE)
822 static int dgram_puts(
BIO *
bp,
const char *str)
827 ret=dgram_write(bp,str,n);
831 #ifndef OPENSSL_NO_SCTP
834 return(&methods_dgramp_sctp);
840 int ret, optval = 20000;
841 int auth_data = 0, auth_forward = 0;
843 struct sctp_authchunk auth;
844 struct sctp_authchunks *authchunks;
845 socklen_t sockopt_len;
846 #ifdef SCTP_AUTHENTICATION_EVENT
848 struct sctp_event event;
850 struct sctp_event_subscribe event;
855 if (bio == NULL)
return(NULL);
860 ret = setsockopt(fd, IPPROTO_SCTP, SCTP_AUTH_CHUNK, &auth,
sizeof(
struct sctp_authchunk));
863 ret = setsockopt(fd, IPPROTO_SCTP, SCTP_AUTH_CHUNK, &auth,
sizeof(
struct sctp_authchunk));
869 sockopt_len = (socklen_t)(
sizeof(sctp_assoc_t) + 256 *
sizeof(uint8_t));
871 memset(authchunks, 0,
sizeof(sockopt_len));
872 ret = getsockopt(fd, IPPROTO_SCTP, SCTP_LOCAL_AUTH_CHUNKS, authchunks, &sockopt_len);
875 for (p = (
unsigned char*) authchunks +
sizeof(sctp_assoc_t);
876 p < (
unsigned char*) authchunks + sockopt_len;
877 p +=
sizeof(uint8_t))
888 #ifdef SCTP_AUTHENTICATION_EVENT
890 memset(&event, 0,
sizeof(
struct sctp_event));
891 event.se_assoc_id = 0;
892 event.se_type = SCTP_AUTHENTICATION_EVENT;
894 ret = setsockopt(fd, IPPROTO_SCTP, SCTP_EVENT, &event,
sizeof(
struct sctp_event));
897 sockopt_len = (socklen_t)
sizeof(
struct sctp_event_subscribe);
898 ret = getsockopt(fd, IPPROTO_SCTP, SCTP_EVENTS, &event, &sockopt_len);
901 event.sctp_authentication_event = 1;
903 ret = setsockopt(fd, IPPROTO_SCTP, SCTP_EVENTS, &event,
sizeof(
struct sctp_event_subscribe));
911 ret = setsockopt(fd, IPPROTO_SCTP, SCTP_PARTIAL_DELIVERY_POINT, &optval,
sizeof(optval));
922 static int dgram_sctp_new(
BIO *bi)
932 #ifdef SCTP_PR_SCTP_NONE
941 static int dgram_sctp_free(
BIO *a)
945 if (a == NULL)
return(0);
946 if ( ! dgram_clear(a))
955 #ifdef SCTP_AUTHENTICATION_EVENT
956 void dgram_sctp_handle_auth_free_key_event(
BIO *b,
union sctp_notification *snp)
958 unsigned int sockopt_len = 0;
960 struct sctp_authkey_event* authkeyevent = &snp->sn_auth_event;
962 if (authkeyevent->auth_indication == SCTP_AUTH_FREE_KEY)
964 struct sctp_authkeyid authkeyid;
967 authkeyid.scact_keynumber = authkeyevent->auth_keynumber;
968 sockopt_len =
sizeof(
struct sctp_authkeyid);
969 ret = setsockopt(b->
num, IPPROTO_SCTP, SCTP_AUTH_DELETE_KEY,
970 &authkeyid, sockopt_len);
975 static int dgram_sctp_read(
BIO *b,
char *out,
int outl)
977 int ret = 0, n = 0, i, optval;
980 union sctp_notification *snp;
983 struct cmsghdr *cmsg;
999 msg.msg_control = cmsgbuf;
1000 msg.msg_controllen = 512;
1002 n = recvmsg(b->
num, &msg, 0);
1004 if (msg.msg_controllen > 0)
1006 for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg))
1008 if (cmsg->cmsg_level != IPPROTO_SCTP)
1011 if (cmsg->cmsg_type == SCTP_RCVINFO)
1013 struct sctp_rcvinfo *rcvinfo;
1015 rcvinfo = (
struct sctp_rcvinfo *)CMSG_DATA(cmsg);
1026 if (cmsg->cmsg_type == SCTP_SNDRCV)
1028 struct sctp_sndrcvinfo *sndrcvinfo;
1030 sndrcvinfo = (
struct sctp_sndrcvinfo *)CMSG_DATA(cmsg);
1050 if (msg.msg_flags & MSG_NOTIFICATION)
1052 snp = (
union sctp_notification*) out;
1053 if (snp->sn_header.sn_type == SCTP_SENDER_DRY_EVENT)
1056 struct sctp_event event;
1058 struct sctp_event_subscribe event;
1059 socklen_t eventsize;
1074 memset(&event, 0,
sizeof(
struct sctp_event));
1075 event.se_assoc_id = 0;
1076 event.se_type = SCTP_SENDER_DRY_EVENT;
1078 i = setsockopt(b->
num, IPPROTO_SCTP, SCTP_EVENT, &event,
sizeof(
struct sctp_event));
1081 eventsize =
sizeof(
struct sctp_event_subscribe);
1082 i = getsockopt(b->
num, IPPROTO_SCTP, SCTP_EVENTS, &event, &eventsize);
1085 event.sctp_sender_dry_event = 0;
1087 i = setsockopt(b->
num, IPPROTO_SCTP, SCTP_EVENTS, &event,
sizeof(
struct sctp_event_subscribe));
1092 #ifdef SCTP_AUTHENTICATION_EVENT
1093 if (snp->sn_header.sn_type == SCTP_AUTHENTICATION_EVENT)
1094 dgram_sctp_handle_auth_free_key_event(b, snp);
1100 memset(out, 0, outl);
1105 while ((msg.msg_flags & MSG_NOTIFICATION) && (msg.msg_flags & MSG_EOR) && (ret < outl));
1107 if (ret > 0 && !(msg.msg_flags & MSG_EOR))
1119 optlen = (socklen_t)
sizeof(
int);
1120 ret = getsockopt(b->
num, SOL_SOCKET, SO_RCVBUF, &optval, &optlen);
1127 optlen = (socklen_t)
sizeof(
int);
1128 ret = getsockopt(b->
num, IPPROTO_SCTP, SCTP_PARTIAL_DELIVERY_POINT,
1139 memset(out, 0, outl);
1147 if (BIO_dgram_should_retry(ret))
1157 int ii, auth_data = 0, auth_forward = 0;
1159 struct sctp_authchunks *authchunks;
1161 optlen = (socklen_t)(
sizeof(sctp_assoc_t) + 256 *
sizeof(uint8_t));
1163 memset(authchunks, 0,
sizeof(optlen));
1164 ii = getsockopt(b->
num, IPPROTO_SCTP, SCTP_PEER_AUTH_CHUNKS, authchunks, &optlen);
1167 for (p = (
unsigned char*) authchunks +
sizeof(sctp_assoc_t);
1168 p < (
unsigned char*) authchunks + optlen;
1169 p +=
sizeof(uint8_t))
1177 if (!auth_data || !auth_forward)
1189 static int dgram_sctp_write(
BIO *b,
const char *in,
int inl)
1196 struct iovec iov[1];
1198 struct cmsghdr *cmsg;
1199 #if defined(SCTP_SNDINFO) && defined(SCTP_PRINFO)
1200 char cmsgbuf[CMSG_SPACE(
sizeof(
struct sctp_sndinfo)) + CMSG_SPACE(
sizeof(
struct sctp_prinfo))];
1201 struct sctp_sndinfo *sndinfo;
1202 struct sctp_prinfo *prinfo;
1204 char cmsgbuf[CMSG_SPACE(
sizeof(
struct sctp_sndrcvinfo))];
1205 struct sctp_sndrcvinfo *sndrcvinfo;
1215 #ifdef SCTP_SACK_IMMEDIATELY
1216 handshake_sinfo.snd_flags = SCTP_SACK_IMMEDIATELY;
1218 sinfo = &handshake_sinfo;
1234 iov[0].iov_base = (
char *)in;
1235 iov[0].iov_len = inl;
1236 msg.msg_name = NULL;
1237 msg.msg_namelen = 0;
1240 msg.msg_control = (caddr_t)cmsgbuf;
1241 msg.msg_controllen = 0;
1243 #if defined(SCTP_SNDINFO) && defined(SCTP_PRINFO)
1244 cmsg = (
struct cmsghdr *)cmsgbuf;
1245 cmsg->cmsg_level = IPPROTO_SCTP;
1246 cmsg->cmsg_type = SCTP_SNDINFO;
1247 cmsg->cmsg_len = CMSG_LEN(
sizeof(
struct sctp_sndinfo));
1248 sndinfo = (
struct sctp_sndinfo *)CMSG_DATA(cmsg);
1249 memset(sndinfo, 0,
sizeof(
struct sctp_sndinfo));
1250 sndinfo->snd_sid = sinfo->snd_sid;
1251 sndinfo->snd_flags = sinfo->snd_flags;
1252 sndinfo->snd_ppid = sinfo->snd_ppid;
1253 sndinfo->snd_context = sinfo->snd_context;
1254 msg.msg_controllen += CMSG_SPACE(
sizeof(
struct sctp_sndinfo));
1256 cmsg = (
struct cmsghdr *)&cmsgbuf[CMSG_SPACE(
sizeof(
struct sctp_sndinfo))];
1257 cmsg->cmsg_level = IPPROTO_SCTP;
1258 cmsg->cmsg_type = SCTP_PRINFO;
1259 cmsg->cmsg_len = CMSG_LEN(
sizeof(
struct sctp_prinfo));
1260 prinfo = (
struct sctp_prinfo *)CMSG_DATA(cmsg);
1261 memset(prinfo, 0,
sizeof(
struct sctp_prinfo));
1263 prinfo->pr_value = pinfo->
pr_value;
1264 msg.msg_controllen += CMSG_SPACE(
sizeof(
struct sctp_prinfo));
1266 cmsg = (
struct cmsghdr *)cmsgbuf;
1267 cmsg->cmsg_level = IPPROTO_SCTP;
1268 cmsg->cmsg_type = SCTP_SNDRCV;
1269 cmsg->cmsg_len = CMSG_LEN(
sizeof(
struct sctp_sndrcvinfo));
1270 sndrcvinfo = (
struct sctp_sndrcvinfo *)CMSG_DATA(cmsg);
1271 memset(sndrcvinfo, 0,
sizeof(
struct sctp_sndrcvinfo));
1272 sndrcvinfo->sinfo_stream = sinfo->snd_sid;
1273 sndrcvinfo->sinfo_flags = sinfo->snd_flags;
1275 sndrcvinfo->sinfo_flags |= pinfo->
pr_policy;
1277 sndrcvinfo->sinfo_ppid = sinfo->snd_ppid;
1278 sndrcvinfo->sinfo_context = sinfo->snd_context;
1279 sndrcvinfo->sinfo_timetolive = pinfo->
pr_value;
1280 msg.msg_controllen += CMSG_SPACE(
sizeof(
struct sctp_sndrcvinfo));
1283 ret = sendmsg(b->
num, &msg, 0);
1288 if (BIO_dgram_should_retry(ret))
1297 static long dgram_sctp_ctrl(
BIO *b,
int cmd,
long num,
void *ptr)
1301 unsigned int sockopt_len = 0;
1302 struct sctp_authkeyid authkeyid;
1303 struct sctp_authkey *authkey;
1343 ret = setsockopt(b->
num, IPPROTO_SCTP, SCTP_NODELAY, &data->
in_handshake,
sizeof(
int));
1351 sockopt_len =
sizeof(
struct sctp_authkeyid);
1352 ret = getsockopt(b->
num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, &authkeyid, &sockopt_len);
1356 sockopt_len =
sizeof(
struct sctp_authkey) + 64 *
sizeof(uint8_t);
1358 memset(authkey, 0x00, sockopt_len);
1359 authkey->sca_keynumber = authkeyid.scact_keynumber + 1;
1364 authkey->sca_keylength = 64;
1366 memcpy(&authkey->sca_key[0], ptr, 64 *
sizeof(uint8_t));
1368 ret = setsockopt(b->
num, IPPROTO_SCTP, SCTP_AUTH_KEY, authkey, sockopt_len);
1372 ret = setsockopt(b->
num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY,
1373 &authkeyid,
sizeof(
struct sctp_authkeyid));
1381 sockopt_len =
sizeof(
struct sctp_authkeyid);
1382 ret = getsockopt(b->
num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, &authkeyid, &sockopt_len);
1386 authkeyid.scact_keynumber = authkeyid.scact_keynumber + 1;
1387 ret = setsockopt(b->
num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY,
1388 &authkeyid,
sizeof(
struct sctp_authkeyid));
1407 sockopt_len =
sizeof(
struct sctp_authkeyid);
1408 ret = getsockopt(b->
num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, &authkeyid, &sockopt_len);
1414 authkeyid.scact_keynumber = authkeyid.scact_keynumber - 1;
1415 #ifdef SCTP_AUTH_DEACTIVATE_KEY
1416 sockopt_len =
sizeof(
struct sctp_authkeyid);
1417 ret = setsockopt(b->
num, IPPROTO_SCTP, SCTP_AUTH_DEACTIVATE_KEY,
1418 &authkeyid, sockopt_len);
1421 #ifndef SCTP_AUTHENTICATION_EVENT
1422 if (authkeyid.scact_keynumber > 0)
1424 authkeyid.scact_keynumber = authkeyid.scact_keynumber - 1;
1425 ret = setsockopt(b->
num, IPPROTO_SCTP, SCTP_AUTH_DELETE_KEY,
1426 &authkeyid,
sizeof(
struct sctp_authkeyid));
1440 memcpy(ptr, &(data->
sndinfo), num);
1448 memcpy(&(data->
sndinfo), ptr, num);
1455 memcpy(ptr, &data->
rcvinfo, num);
1464 memcpy(&(data->
rcvinfo), ptr, num);
1471 memcpy(ptr, &(data->
prinfo), num);
1479 memcpy(&(data->
prinfo), ptr, num);
1493 ret=dgram_ctrl(b, cmd, num, ptr);
1500 void (*handle_notifications)(
BIO *bio,
void *context,
void *buf),
1505 if (handle_notifications != NULL)
1519 int n, sockflags, ret;
1520 union sctp_notification snp;
1524 struct sctp_event event;
1526 struct sctp_event_subscribe event;
1527 socklen_t eventsize;
1533 memset(&event, 0,
sizeof(
struct sctp_event));
1534 event.se_assoc_id = 0;
1535 event.se_type = SCTP_SENDER_DRY_EVENT;
1537 ret = setsockopt(b->
num, IPPROTO_SCTP, SCTP_EVENT, &event,
sizeof(
struct sctp_event));
1539 eventsize =
sizeof(
struct sctp_event_subscribe);
1540 ret = getsockopt(b->
num, IPPROTO_SCTP, SCTP_EVENTS, &event, &eventsize);
1544 event.sctp_sender_dry_event = 1;
1546 ret = setsockopt(b->
num, IPPROTO_SCTP, SCTP_EVENTS, &event,
sizeof(
struct sctp_event_subscribe));
1552 memset(&snp, 0x00,
sizeof(
union sctp_notification));
1553 iov.iov_base = (
char *)&snp;
1554 iov.iov_len =
sizeof(
union sctp_notification);
1555 msg.msg_name = NULL;
1556 msg.msg_namelen = 0;
1559 msg.msg_control = NULL;
1560 msg.msg_controllen = 0;
1563 n = recvmsg(b->
num, &msg, MSG_PEEK);
1573 while (msg.msg_flags & MSG_NOTIFICATION)
1575 memset(&snp, 0x00,
sizeof(
union sctp_notification));
1576 iov.iov_base = (
char *)&snp;
1577 iov.iov_len =
sizeof(
union sctp_notification);
1578 msg.msg_name = NULL;
1579 msg.msg_namelen = 0;
1582 msg.msg_control = NULL;
1583 msg.msg_controllen = 0;
1586 n = recvmsg(b->
num, &msg, 0);
1595 if (snp.sn_header.sn_type == SCTP_SENDER_DRY_EVENT)
1601 memset(&event, 0,
sizeof(
struct sctp_event));
1602 event.se_assoc_id = 0;
1603 event.se_type = SCTP_SENDER_DRY_EVENT;
1605 ret = setsockopt(b->
num, IPPROTO_SCTP, SCTP_EVENT, &event,
sizeof(
struct sctp_event));
1607 eventsize = (socklen_t)
sizeof(
struct sctp_event_subscribe);
1608 ret = getsockopt(b->
num, IPPROTO_SCTP, SCTP_EVENTS, &event, &eventsize);
1612 event.sctp_sender_dry_event = 0;
1614 ret = setsockopt(b->
num, IPPROTO_SCTP, SCTP_EVENTS, &event,
sizeof(
struct sctp_event_subscribe));
1620 #ifdef SCTP_AUTHENTICATION_EVENT
1621 if (snp.sn_header.sn_type == SCTP_AUTHENTICATION_EVENT)
1622 dgram_sctp_handle_auth_free_key_event(b, &snp);
1629 memset(&snp, 0x00,
sizeof(
union sctp_notification));
1630 iov.iov_base = (
char *)&snp;
1631 iov.iov_len =
sizeof(
union sctp_notification);
1632 msg.msg_name = NULL;
1633 msg.msg_namelen = 0;
1636 msg.msg_control = NULL;
1637 msg.msg_controllen = 0;
1643 sockflags = fcntl(b->
num, F_GETFL, 0);
1644 fcntl(b->
num, F_SETFL, O_NONBLOCK);
1647 n = recvmsg(b->
num, &msg, MSG_PEEK);
1651 fcntl(b->
num, F_SETFL, sockflags);
1670 union sctp_notification snp;
1678 memset(&snp, 0x00,
sizeof(
union sctp_notification));
1679 iov.iov_base = (
char *)&snp;
1680 iov.iov_len =
sizeof(
union sctp_notification);
1681 msg.msg_name = NULL;
1682 msg.msg_namelen = 0;
1685 msg.msg_control = NULL;
1686 msg.msg_controllen = 0;
1689 sockflags = fcntl(b->
num, F_GETFL, 0);
1690 fcntl(b->
num, F_SETFL, O_NONBLOCK);
1691 n = recvmsg(b->
num, &msg, MSG_PEEK);
1692 fcntl(b->
num, F_SETFL, sockflags);
1695 if (n > 0 && (msg.msg_flags & MSG_NOTIFICATION))
1697 #ifdef SCTP_AUTHENTICATION_EVENT
1698 if (snp.sn_header.sn_type == SCTP_AUTHENTICATION_EVENT)
1699 dgram_sctp_handle_auth_free_key_event(b, &snp);
1702 memset(&snp, 0x00,
sizeof(
union sctp_notification));
1703 iov.iov_base = (
char *)&snp;
1704 iov.iov_len =
sizeof(
union sctp_notification);
1705 msg.msg_name = NULL;
1706 msg.msg_namelen = 0;
1709 msg.msg_control = NULL;
1710 msg.msg_controllen = 0;
1712 n = recvmsg(b->
num, &msg, 0);
1714 if (data->handle_notifications != NULL)
1715 data->handle_notifications(b, data->notification_context, (
void*) &snp);
1718 }
while (n > 0 && (msg.msg_flags & MSG_NOTIFICATION));
1727 static int dgram_sctp_puts(
BIO *bp,
const char *str)
1732 ret=dgram_sctp_write(bp,str,n);
1737 static int BIO_dgram_should_retry(
int i)
1741 if ((i == 0) || (i == -1))
1745 #if defined(OPENSSL_SYS_WINDOWS)
1763 #if defined(OPENSSL_SYS_WINDOWS)
1764 # if defined(WSAEWOULDBLOCK)
1765 case WSAEWOULDBLOCK:
1769 # if defined(WSAENOTCONN)
1776 # ifdef WSAEWOULDBLOCK
1777 # if WSAEWOULDBLOCK != EWOULDBLOCK
1790 #if EWOULDBLOCK != EAGAIN
1815 static void get_current_time(
struct timeval *
t)
1817 #ifdef OPENSSL_SYS_WIN32
1820 t->tv_sec = (long)tb.time;
1821 t->tv_usec = (
long)tb.millitm * 1000;
1822 #elif defined(OPENSSL_SYS_VMS)
1825 t->tv_sec = (long)tb.time;
1826 t->tv_usec = (
long)tb.millitm * 1000;
1828 gettimeofday(t, NULL);