Mercurial > hg > freeDiameter
annotate libfdcore/sctp3436.c @ 1559:2dbc816d48f4
Fail when a peer with empty Origin-Realm tries to connect.
Empty Origin-Realms cause problems in the routing code later.
Reduce warnings when reporting an empty Failed-AVP;
both avp_source and avp_rawdata are NULL in this case.
author | Thomas Klausner <wiz@gatalith.at> |
---|---|
date | Tue, 27 Oct 2020 10:50:04 +0100 |
parents | 566bb46cc73f |
children |
rev | line source |
---|---|
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
1 /********************************************************************************************************* |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
2 * Software License Agreement (BSD License) * |
740
4a9f08d6b6ba
Updated my mail address
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
4 * * |
1554
566bb46cc73f
Updated copyright information
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1405
diff
changeset
|
5 * Copyright (c) 2020, WIDE Project and NICT * |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
6 * All rights reserved. * |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
7 * * |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
8 * Redistribution and use of this software in source and binary forms, with or without modification, are * |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
9 * permitted provided that the following conditions are met: * |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
10 * * |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
11 * * Redistributions of source code must retain the above * |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
12 * copyright notice, this list of conditions and the * |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
13 * following disclaimer. * |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
14 * * |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
15 * * Redistributions in binary form must reproduce the above * |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
16 * copyright notice, this list of conditions and the * |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
17 * following disclaimer in the documentation and/or other * |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
18 * materials provided with the distribution. * |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
19 * * |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
20 * * Neither the name of the WIDE Project or NICT nor the * |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
21 * names of its contributors may be used to endorse or * |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
22 * promote products derived from this software without * |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
23 * specific prior written permission of WIDE Project and * |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
24 * NICT. * |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
25 * * |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
34 *********************************************************************************************************/ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
35 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
36 /* This file contains code for TLS over multi-stream SCTP wrapper implementation (GnuTLS does not support this) */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
37 /* See http://aaa.koganei.wide.ad.jp/blogs/index.php/waaad/2008/08/18/tls-over-sctp for history */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
38 |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
543
diff
changeset
|
39 #include "fdcore-internal.h" |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
40 #include "cnxctx.h" |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
41 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
42 #include <netinet/sctp.h> |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
43 #include <sys/uio.h> |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
44 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
45 /* |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
46 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
47 Architecture of this wrapper: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
48 - we have several fifo queues (1 per stream pairs). |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
49 GnuTLS is configured to use custom push / pull functions: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
50 - the pull function retrieves the data from the fifo queue corresponding to a stream #. |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
51 - the push function sends the data on a certain stream. |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
52 We also have a demux thread that reads the socket and store received data in the appropriate fifo |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
53 |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
54 We have one gnutls_session per stream pair, and as many threads that read the gnutls records and save incoming data to the target queue. |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
55 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
56 This complexity is required because we cannot read a socket for a given stream only; we can only get the next message and find its stream. |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
57 */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
58 |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
59 /* Note that this mechanism is replaced by DTLS in RFC6733 */ |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
60 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
61 /*************************************************************/ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
62 /* threads */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
63 /*************************************************************/ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
64 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
65 /* Demux received data and store in the appropriate fifo */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
66 static void * demuxer(void * arg) |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
67 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
68 struct cnxctx * conn = arg; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
69 uint8_t * buf; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
70 size_t bufsz; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
71 int event; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
72 uint16_t strid; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
73 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
74 TRACE_ENTRY("%p", arg); |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
75 CHECK_PARAMS_DO(conn && (conn->cc_socket > 0), goto out); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
76 |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
77 /* Set the thread name */ |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
78 { |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
79 char buf[100]; |
228 | 80 snprintf(buf, sizeof(buf), "Demuxer (%d:%s)", conn->cc_socket, conn->cc_remid); |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
81 fd_log_threadname ( buf ); |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
82 } |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
83 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
84 ASSERT( conn->cc_proto == IPPROTO_SCTP ); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
85 ASSERT( fd_cnx_target_queue(conn) ); |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
86 ASSERT( conn->cc_sctp3436_data.array ); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
87 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
88 do { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
89 CHECK_FCT_DO( fd_sctp_recvmeta(conn, &strid, &buf, &bufsz, &event), goto fatal ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
90 switch (event) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
91 case FDEVP_CNX_MSG_RECV: |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
207
diff
changeset
|
92 /* Demux this message to the appropriate fifo, another thread will pull, gnutls process, and send to target queue */ |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
155
diff
changeset
|
93 if (strid < conn->cc_sctp_para.pairs) { |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
94 CHECK_FCT_DO(fd_event_send(conn->cc_sctp3436_data.array[strid].raw_recv, event, bufsz, buf), goto fatal ); |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
155
diff
changeset
|
95 } else { |
1027
0117a7746b21
Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1021
diff
changeset
|
96 TRACE_DEBUG(INFO, "Received packet (%zd bytes) on out-of-range stream #%d from %s, discarded.", bufsz, strid, conn->cc_remid); |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
155
diff
changeset
|
97 free(buf); |
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
155
diff
changeset
|
98 } |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
99 break; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
100 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
101 case FDEVP_CNX_EP_CHANGE: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
102 /* Send this event to the target queue */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
103 CHECK_FCT_DO( fd_event_send( fd_cnx_target_queue(conn), event, bufsz, buf), goto fatal ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
104 break; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
105 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
106 case FDEVP_CNX_ERROR: |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
207
diff
changeset
|
107 goto out; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
108 |
228 | 109 case FDEVP_CNX_SHUTDOWN: |
110 /* Just ignore the notification for now, we will get another error later anyway */ | |
111 continue; | |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
112 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
113 default: |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
207
diff
changeset
|
114 goto fatal; |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
115 } |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
116 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
117 } while (conn->cc_loop); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
118 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
119 out: |
223
85dc47afeac7
Cleanup termination
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
215
diff
changeset
|
120 /* Signal termination of the connection to all decipher threads */ |
85dc47afeac7
Cleanup termination
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
215
diff
changeset
|
121 for (strid = 0; strid < conn->cc_sctp_para.pairs; strid++) { |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
122 if (conn->cc_sctp3436_data.array[strid].raw_recv) { |
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
123 CHECK_FCT_DO(fd_event_send(conn->cc_sctp3436_data.array[strid].raw_recv, FDEVP_CNX_ERROR, 0, NULL), goto fatal ); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
124 } |
223
85dc47afeac7
Cleanup termination
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
215
diff
changeset
|
125 } |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
126 fd_cnx_markerror(conn); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
127 TRACE_DEBUG(FULL, "Thread terminated"); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
128 return NULL; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
129 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
207
diff
changeset
|
130 fatal: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
207
diff
changeset
|
131 /* An unrecoverable error occurred, stop the daemon */ |
1190
6a1042d8075b
Replace FDEV_TERMINATE events with calls to fd_core_shutdown to handle the core state properly
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1186
diff
changeset
|
132 CHECK_FCT_DO(fd_core_shutdown(), ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
133 goto out; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
134 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
135 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
136 /* Decrypt the data received in this stream pair and store it in the target queue */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
137 static void * decipher(void * arg) |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
138 { |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
139 struct sctp3436_ctx * ctx = arg; |
1405 | 140 struct cnxctx *cnx = NULL; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
141 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
142 TRACE_ENTRY("%p", arg); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
143 CHECK_PARAMS_DO(ctx && ctx->raw_recv && ctx->parent, goto error); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
144 cnx = ctx->parent; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
145 ASSERT( fd_cnx_target_queue(cnx) ); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
146 |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
147 /* Set the thread name */ |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
148 { |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
149 char buf[100]; |
228 | 150 snprintf(buf, sizeof(buf), "Decipher (%hu@%d:%s)", ctx->strid, cnx->cc_socket, cnx->cc_remid); |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
151 fd_log_threadname ( buf ); |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
152 } |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
153 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
207
diff
changeset
|
154 /* The next function loops while there is no error */ |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
155 CHECK_FCT_DO(fd_tls_rcvthr_core(cnx, ctx->strid ? ctx->session : cnx->cc_tls_para.session), /* continue */); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
156 error: |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
207
diff
changeset
|
157 fd_cnx_markerror(cnx); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
158 TRACE_DEBUG(FULL, "Thread terminated"); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
159 return NULL; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
160 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
161 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
162 /*************************************************************/ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
163 /* push / pull */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
164 /*************************************************************/ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
165 |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
166 #ifdef GNUTLS_VERSION_300 |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
167 /* Check if data is available for gnutls on a given context */ |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
168 static int sctp3436_pull_timeout(gnutls_transport_ptr_t tr, unsigned int ms) |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
169 { |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
170 struct sctp3436_ctx * ctx = (struct sctp3436_ctx *) tr; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
171 struct timespec tsstore, *ts = NULL; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
172 int ret; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
173 |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
174 TRACE_ENTRY("%p %d", tr, ms); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
175 |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
176 if (ctx->partial.buf) |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
177 return 1; /* data is already available for pull */ |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
178 |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
179 if (ms) { |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
180 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &tsstore), return -1 ); |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
181 tsstore.tv_nsec += (long)ms * 1000000; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
182 tsstore.tv_sec += tsstore.tv_nsec / 1000000000L; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
183 tsstore.tv_nsec %= 1000000000L; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
184 ts = &tsstore; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
185 } |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
186 |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
187 ret = fd_fifo_select ( ctx->raw_recv, ts ); |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
188 if (ret < 0) { |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
189 errno = -ret; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
190 ret = -1; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
191 } |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
192 |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
193 return ret; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
194 } |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
195 #endif /* GNUTLS_VERSION_300 */ |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
196 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
197 /* Send data over the connection, called by gnutls */ |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
198 #ifndef GNUTLS_VERSION_212 |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
199 static ssize_t sctp3436_push(gnutls_transport_ptr_t tr, const void * data, size_t len) |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
200 { |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
201 struct sctp3436_ctx * ctx = (struct sctp3436_ctx *) tr; |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
202 struct iovec iov; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
203 |
27
b3a1773e9f46
again, correct was actually %zd
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
26
diff
changeset
|
204 TRACE_ENTRY("%p %p %zd", tr, data, len); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
205 CHECK_PARAMS_DO( tr && data, { errno = EINVAL; return -1; } ); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
206 |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
207 iov.iov_base = (void *)data; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
208 iov.iov_len = len; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
209 |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
210 return fd_sctp_sendstrv(ctx->parent, ctx->strid, &iov, 1); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
211 } |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
212 #else /* GNUTLS_VERSION_212 */ |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
213 static ssize_t sctp3436_pushv(gnutls_transport_ptr_t tr, const giovec_t * iov, int iovcnt) |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
214 { |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
215 struct sctp3436_ctx * ctx = (struct sctp3436_ctx *) tr; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
216 |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
217 TRACE_ENTRY("%p %p %d", tr, iov, iovcnt); |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
218 CHECK_PARAMS_DO( tr && iov, { errno = EINVAL; return -1; } ); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
219 |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
220 return fd_sctp_sendstrv(ctx->parent, ctx->strid, (const struct iovec *)iov, iovcnt); |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
221 } |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
222 #endif /* GNUTLS_VERSION_212 */ |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
223 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
224 /* Retrieve data received on a stream and already demultiplexed */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
225 static ssize_t sctp3436_pull(gnutls_transport_ptr_t tr, void * buf, size_t len) |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
226 { |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
227 struct sctp3436_ctx * ctx = (struct sctp3436_ctx *) tr; |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
228 size_t pulled = 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
229 int emptied; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
230 |
27
b3a1773e9f46
again, correct was actually %zd
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
26
diff
changeset
|
231 TRACE_ENTRY("%p %p %zd", tr, buf, len); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
232 CHECK_PARAMS_DO( tr && buf, { errno = EINVAL; goto error; } ); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
233 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
207
diff
changeset
|
234 /* If we don't have data available now, pull new message from the fifo -- this is blocking (until the queue is destroyed) */ |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
235 if (!ctx->partial.buf) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
236 int ev; |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
237 CHECK_FCT_DO( errno = fd_event_get(ctx->raw_recv, &ev, &ctx->partial.bufsz, (void *)&ctx->partial.buf), goto error ); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
238 if (ev == FDEVP_CNX_ERROR) { |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
239 /* Documentations says to return 0 on connection closed, but it does hang within gnutls_handshake */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
240 return -1; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
241 } |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
242 } |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
243 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
244 pulled = ctx->partial.bufsz - ctx->partial.offset; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
245 if (pulled <= len) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
246 emptied = 1; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
247 } else { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
248 /* limit to the capacity of destination buffer */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
249 emptied = 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
250 pulled = len; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
251 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
252 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
253 /* Store the data in the destination buffer */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
254 memcpy(buf, ctx->partial.buf + ctx->partial.offset, pulled); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
255 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
256 /* Free the buffer if we read all its content, and reset the partial structure */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
257 if (emptied) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
258 free(ctx->partial.buf); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
259 memset(&ctx->partial, 0, sizeof(ctx->partial)); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
260 } else { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
261 ctx->partial.offset += pulled; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
262 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
263 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
264 /* We are done */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
265 return pulled; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
266 |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
267 error: |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
268 gnutls_transport_set_errno (ctx->session, errno); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
269 return -1; |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
270 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
271 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
272 /* Set the parameters of a session to use the appropriate fifo and stream information */ |
1027
0117a7746b21
Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1021
diff
changeset
|
273 #ifndef GNUTLS_VERSION_300 |
1034
f4a73a991623
Fix warning on old GCC versions
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1033
diff
changeset
|
274 GCC_DIAG_OFF("-Wdeprecated-declarations") |
1027
0117a7746b21
Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1021
diff
changeset
|
275 #endif /* !GNUTLS_VERSION_300 */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
276 static void set_sess_transport(gnutls_session_t session, struct sctp3436_ctx *ctx) |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
277 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
278 /* Set the transport pointer passed to push & pull callbacks */ |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
209
diff
changeset
|
279 GNUTLS_TRACE( gnutls_transport_set_ptr( session, (gnutls_transport_ptr_t) ctx ) ); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
280 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
281 /* Reset the low water value, since we don't use sockets */ |
798
ca8e30a2426d
Remove the warning on gnutls_transport_set_lowat
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
767
diff
changeset
|
282 #ifndef GNUTLS_VERSION_300 |
ca8e30a2426d
Remove the warning on gnutls_transport_set_lowat
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
767
diff
changeset
|
283 /* starting version 2.12, this call is not needed */ |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
209
diff
changeset
|
284 GNUTLS_TRACE( gnutls_transport_set_lowat( session, 0 ) ); |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
285 #else /* GNUTLS_VERSION_300 */ |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
286 /* but in 3.0 we have to provide the pull_timeout callback */ |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
287 GNUTLS_TRACE( gnutls_transport_set_pull_timeout_function( session, sctp3436_pull_timeout ) ); |
798
ca8e30a2426d
Remove the warning on gnutls_transport_set_lowat
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
767
diff
changeset
|
288 #endif /* GNUTLS_VERSION_300 */ |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
289 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
290 /* Set the push and pull callbacks */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
291 GNUTLS_TRACE( gnutls_transport_set_pull_function(session, sctp3436_pull) ); |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
292 #ifndef GNUTLS_VERSION_212 |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
293 GNUTLS_TRACE( gnutls_transport_set_push_function(session, sctp3436_push) ); |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
294 #else /* GNUTLS_VERSION_212 */ |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
295 GNUTLS_TRACE( gnutls_transport_set_vec_push_function(session, sctp3436_pushv) ); |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
296 #endif /* GNUTLS_VERSION_212 */ |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
297 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
298 return; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
299 } |
1027
0117a7746b21
Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1021
diff
changeset
|
300 #ifndef GNUTLS_VERSION_300 |
1034
f4a73a991623
Fix warning on old GCC versions
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1033
diff
changeset
|
301 GCC_DIAG_ON("-Wdeprecated-declarations") |
1027
0117a7746b21
Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1021
diff
changeset
|
302 #endif /* !GNUTLS_VERSION_300 */ |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
303 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
304 /*************************************************************/ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
305 /* Session resuming support */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
306 /*************************************************************/ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
307 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
308 struct sr_store { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
309 struct fd_list list; /* list of sr_data, ordered by key.size then key.data */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
310 pthread_rwlock_t lock; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
311 struct cnxctx *parent; |
227
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
312 /* Add another list to chain in a global list to implement a garbage collector on sessions -- TODO if needed */ |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
313 }; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
314 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
315 /* Saved master session data for resuming sessions */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
316 struct sr_data { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
317 struct fd_list chain; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
318 gnutls_datum_t key; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
319 gnutls_datum_t data; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
320 }; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
321 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
322 /* Initialize the store area for a connection */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
323 static int store_init(struct cnxctx * conn) |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
324 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
325 TRACE_ENTRY("%p", conn); |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
326 CHECK_PARAMS( conn && !conn->cc_sctp3436_data.sess_store ); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
327 |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
328 CHECK_MALLOC( conn->cc_sctp3436_data.sess_store = malloc(sizeof(struct sr_store)) ); |
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
329 memset(conn->cc_sctp3436_data.sess_store, 0, sizeof(struct sr_store)); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
330 |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
331 fd_list_init(&conn->cc_sctp3436_data.sess_store->list, NULL); |
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
332 CHECK_POSIX( pthread_rwlock_init(&conn->cc_sctp3436_data.sess_store->lock, NULL) ); |
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
333 conn->cc_sctp3436_data.sess_store->parent = conn; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
334 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
335 return 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
336 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
337 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
338 /* Destroy the store area for a connection, and all its content */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
339 static void store_destroy(struct cnxctx * conn) |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
340 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
341 /* Del all list entries */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
342 TRACE_ENTRY("%p", conn); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
343 CHECK_PARAMS_DO( conn, return ); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
344 |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
345 if (!conn->cc_sctp3436_data.sess_store) |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
346 return; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
347 |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
348 CHECK_POSIX_DO( pthread_rwlock_destroy(&conn->cc_sctp3436_data.sess_store->lock), /* continue */ ); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
349 |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
350 while (!FD_IS_LIST_EMPTY(&conn->cc_sctp3436_data.sess_store->list)) { |
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
351 struct sr_data * sr = (struct sr_data *) conn->cc_sctp3436_data.sess_store->list.next; |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
352 fd_list_unlink( &sr->chain ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
353 free(sr->key.data); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
354 free(sr->data.data); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
355 free(sr); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
356 } |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
357 |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
358 free(conn->cc_sctp3436_data.sess_store); |
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
359 conn->cc_sctp3436_data.sess_store = NULL; |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
360 return; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
361 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
362 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
363 /* Search the position (or next if not found) of a key in a store */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
364 static struct fd_list * find_or_next(struct sr_store * sto, gnutls_datum_t key, int * match) |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
365 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
366 struct fd_list * ret; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
367 *match = 0; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
368 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
369 for (ret = sto->list.next; ret != &sto->list; ret = ret->next) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
370 int cmp = 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
371 struct sr_data * sr = (struct sr_data *)ret; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
372 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
373 cmp = fd_os_cmp(key.data, key.size, sr->key.data, sr->key.size); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
374 if (cmp > 0) |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
375 continue; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
376 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
377 if (cmp == 0) |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
378 *match = 1; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
379 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
380 break; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
381 } |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
382 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
383 return ret; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
384 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
385 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
386 /* Callbacks for the TLS server side of the connection, called during gnutls_handshake */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
387 static int sr_store (void *dbf, gnutls_datum_t key, gnutls_datum_t data) |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
388 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
389 struct sr_store * sto = (struct sr_store *)dbf; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
390 struct fd_list * li; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
391 struct sr_data * sr; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
392 int match = 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
393 int ret = 0; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
394 |
215 | 395 TRACE_DEBUG( GNUTLS_DBG_LEVEL, "GNUTLS Callback: %s", __PRETTY_FUNCTION__ ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
396 CHECK_PARAMS_DO( sto && key.data && data.data, return -1 ); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
397 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
398 CHECK_POSIX_DO( pthread_rwlock_wrlock(&sto->lock), return -1 ); |
965
9b37f34c1b1f
Some modifications to logging code:
Sebastien Decugis <sdecugis@freediameter.net>
parents:
894
diff
changeset
|
399 TRACE_BUFFER(FD_LOG_DEBUG, GNUTLS_DBG_LEVEL, "Session store [key ", key.data, key.size, "]"); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
400 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
401 li = find_or_next(sto, key, &match); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
402 if (match) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
403 sr = (struct sr_data *)li; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
404 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
405 /* Check the data is the same */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
406 if ((data.size != sr->data.size) || memcmp(data.data, sr->data.data, data.size)) { |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
207
diff
changeset
|
407 TRACE_DEBUG(INFO, "GnuTLS tried to store a session with same key and different data!"); |
965
9b37f34c1b1f
Some modifications to logging code:
Sebastien Decugis <sdecugis@freediameter.net>
parents:
894
diff
changeset
|
408 TRACE_BUFFER(FD_LOG_DEBUG, INFO, "Session store [key ", key.data, key.size, "]"); |
9b37f34c1b1f
Some modifications to logging code:
Sebastien Decugis <sdecugis@freediameter.net>
parents:
894
diff
changeset
|
409 TRACE_BUFFER(FD_LOG_DEBUG, INFO, " -- old data [", sr->data.data, sr->data.size, "]"); |
9b37f34c1b1f
Some modifications to logging code:
Sebastien Decugis <sdecugis@freediameter.net>
parents:
894
diff
changeset
|
410 TRACE_BUFFER(FD_LOG_DEBUG, INFO, " -- new data [", data.data, data.size, "]"); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
411 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
412 ret = -1; |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
413 } else { |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
209
diff
changeset
|
414 TRACE_DEBUG(GNUTLS_DBG_LEVEL, "GnuTLS tried to store a session with same key and same data, skipped."); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
415 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
416 goto out; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
417 } |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
418 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
419 /* Create a new entry */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
420 CHECK_MALLOC_DO( sr = malloc(sizeof(struct sr_data)), { ret = -1; goto out; } ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
421 memset(sr, 0, sizeof(struct sr_data)); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
422 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
423 fd_list_init(&sr->chain, sr); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
424 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
425 CHECK_MALLOC_DO( sr->key.data = malloc(key.size), { ret = -1; goto out; } ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
426 sr->key.size = key.size; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
427 memcpy(sr->key.data, key.data, key.size); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
428 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
429 CHECK_MALLOC_DO( sr->data.data = malloc(data.size), { ret = -1; goto out; } ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
430 sr->data.size = data.size; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
431 memcpy(sr->data.data, data.data, data.size); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
432 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
433 /* Save this new entry in the list, we are done */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
434 fd_list_insert_before(li, &sr->chain); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
435 |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
436 out: |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
437 CHECK_POSIX_DO( pthread_rwlock_unlock(&sto->lock), return -1 ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
438 return ret; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
439 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
440 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
441 static int sr_remove (void *dbf, gnutls_datum_t key) |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
442 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
443 struct sr_store * sto = (struct sr_store *)dbf; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
444 struct fd_list * li; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
445 struct sr_data * sr; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
446 int match = 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
447 int ret = 0; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
448 |
215 | 449 TRACE_DEBUG( GNUTLS_DBG_LEVEL, "GNUTLS Callback: %s", __PRETTY_FUNCTION__ ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
450 CHECK_PARAMS_DO( sto && key.data, return -1 ); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
451 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
452 CHECK_POSIX_DO( pthread_rwlock_wrlock(&sto->lock), return -1 ); |
965
9b37f34c1b1f
Some modifications to logging code:
Sebastien Decugis <sdecugis@freediameter.net>
parents:
894
diff
changeset
|
453 TRACE_BUFFER(FD_LOG_DEBUG, GNUTLS_DBG_LEVEL, "Session delete [key ", key.data, key.size, "]"); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
454 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
455 li = find_or_next(sto, key, &match); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
456 if (match) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
457 sr = (struct sr_data *)li; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
458 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
459 /* Destroy this data */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
460 fd_list_unlink(li); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
461 free(sr->key.data); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
462 free(sr->data.data); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
463 free(sr); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
464 } else { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
465 /* It was not found */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
466 ret = -1; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
467 } |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
468 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
469 CHECK_POSIX_DO( pthread_rwlock_unlock(&sto->lock), return -1 ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
470 return ret; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
471 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
472 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
473 static gnutls_datum_t sr_fetch (void *dbf, gnutls_datum_t key) |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
474 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
475 struct sr_store * sto = (struct sr_store *)dbf; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
476 struct fd_list * li; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
477 struct sr_data * sr; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
478 int match = 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
479 gnutls_datum_t res = { NULL, 0 }; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
480 gnutls_datum_t error = { NULL, 0 }; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
481 |
215 | 482 TRACE_DEBUG( GNUTLS_DBG_LEVEL, "GNUTLS Callback: %s", __PRETTY_FUNCTION__ ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
483 CHECK_PARAMS_DO( sto && key.data, return error ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
484 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
485 CHECK_POSIX_DO( pthread_rwlock_rdlock(&sto->lock), return error ); |
965
9b37f34c1b1f
Some modifications to logging code:
Sebastien Decugis <sdecugis@freediameter.net>
parents:
894
diff
changeset
|
486 TRACE_BUFFER(FD_LOG_DEBUG, GNUTLS_DBG_LEVEL, "Session fetch [key ", key.data, key.size, "]"); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
487 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
488 li = find_or_next(sto, key, &match); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
489 if (match) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
490 sr = (struct sr_data *)li; |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
209
diff
changeset
|
491 GNUTLS_TRACE( CHECK_MALLOC_DO(res.data = gnutls_malloc(sr->data.size), goto out ) ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
492 res.size = sr->data.size; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
493 memcpy(res.data, sr->data.data, res.size); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
494 } |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
495 out: |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
209
diff
changeset
|
496 TRACE_DEBUG(GNUTLS_DBG_LEVEL, "Fetched (%p, %d) from store %p", res.data, res.size, sto); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
497 CHECK_POSIX_DO( pthread_rwlock_unlock(&sto->lock), return error); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
498 return res; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
499 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
500 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
501 /* Set the session pointer in a session object */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
502 static void set_resume_callbacks(gnutls_session_t session, struct cnxctx * conn) |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
503 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
504 TRACE_ENTRY("%p", conn); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
505 |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
209
diff
changeset
|
506 GNUTLS_TRACE( gnutls_db_set_retrieve_function(session, sr_fetch)); |
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
209
diff
changeset
|
507 GNUTLS_TRACE( gnutls_db_set_remove_function (session, sr_remove)); |
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
209
diff
changeset
|
508 GNUTLS_TRACE( gnutls_db_set_store_function (session, sr_store)); |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
509 GNUTLS_TRACE( gnutls_db_set_ptr (session, conn->cc_sctp3436_data.sess_store)); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
510 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
511 return; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
512 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
513 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
514 /* The handshake is made in parallel in several threads to speed up */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
515 static void * handshake_resume_th(void * arg) |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
516 { |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
517 struct sctp3436_ctx * ctx = (struct sctp3436_ctx *) arg; |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
518 int resumed; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
519 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
520 TRACE_ENTRY("%p", arg); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
521 |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
522 /* Set the thread name */ |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
523 { |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
524 char buf[48]; |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
525 snprintf(buf, sizeof(buf), "Handshake resume (%hu@%d)", ctx->strid, ctx->parent->cc_socket); |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
526 fd_log_threadname ( buf ); |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
527 } |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
528 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
529 TRACE_DEBUG(FULL, "Starting TLS resumed handshake on stream %hu", ctx->strid); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
530 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
531 CHECK_GNUTLS_DO( gnutls_handshake( ctx->session ), return NULL); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
532 |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
209
diff
changeset
|
533 GNUTLS_TRACE( resumed = gnutls_session_is_resumed(ctx->session) ); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
534 #ifndef GNUTLS_VERSION_300 |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
535 if (!resumed) { |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
536 /* Check the credentials here also */ |
59
067ab3fc6093
Cleanups in debug messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
31
diff
changeset
|
537 CHECK_FCT_DO( fd_tls_verify_credentials(ctx->session, ctx->parent, 0), return NULL ); |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
538 } |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
539 #endif /* GNUTLS_VERSION_300 */ |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
540 if (TRACE_BOOL(FULL)) { |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
541 if (resumed) { |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
965
diff
changeset
|
542 fd_log_debug("Session was resumed successfully on stream %hu (conn: '%s')", ctx->strid, fd_cnx_getid(ctx->parent)); |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
543 } else { |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
965
diff
changeset
|
544 fd_log_debug("Session was NOT resumed on stream %hu (full handshake) (conn: '%s')", ctx->strid, fd_cnx_getid(ctx->parent)); |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
545 } |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
546 } |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
547 |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
29
diff
changeset
|
548 /* Finished, OK */ |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
549 return arg; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
550 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
551 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
552 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
553 /*************************************************************/ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
554 /* Exported functions */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
555 /*************************************************************/ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
556 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
557 /* Initialize the wrapper for the connection */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
558 int fd_sctp3436_init(struct cnxctx * conn) |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
559 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
560 uint16_t i; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
561 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
562 TRACE_ENTRY("%p", conn); |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
563 CHECK_PARAMS( conn && (conn->cc_sctp_para.pairs > 1) && (!conn->cc_sctp3436_data.array) ); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
564 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
565 /* First, alloc the array and initialize the non-TLS data */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
566 CHECK_MALLOC( conn->cc_sctp3436_data.array = calloc(conn->cc_sctp_para.pairs, sizeof(struct sctp3436_ctx)) ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
567 for (i = 0; i < conn->cc_sctp_para.pairs; i++) { |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
568 conn->cc_sctp3436_data.array[i].parent = conn; |
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
569 conn->cc_sctp3436_data.array[i].strid = i; |
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
570 CHECK_FCT( fd_fifo_new(&conn->cc_sctp3436_data.array[i].raw_recv, 10) ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
571 } |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
572 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
573 /* Set push/pull functions in the master session, using fifo in array[0] */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
574 set_sess_transport(conn->cc_tls_para.session, &conn->cc_sctp3436_data.array[0]); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
575 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
576 /* For server side, we also initialize the resuming capabilities */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
577 if (conn->cc_tls_para.mode == GNUTLS_SERVER) { |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
578 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
579 /* Prepare the store for sessions data */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
580 CHECK_FCT( store_init(conn) ); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
581 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
582 /* Set the callbacks for resuming in the master session */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
583 set_resume_callbacks(conn->cc_tls_para.session, conn); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
584 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
585 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
586 /* Start the demux thread */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
587 CHECK_POSIX( pthread_create( &conn->cc_rcvthr, NULL, demuxer, conn ) ); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
588 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
589 return 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
590 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
591 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
592 /* Handshake other streams, after full handshake on the master session */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
593 int fd_sctp3436_handshake_others(struct cnxctx * conn, char * priority, void * alt_creds) |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
594 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
595 uint16_t i; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
596 int errors = 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
597 gnutls_datum_t master_data; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
598 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
599 TRACE_ENTRY("%p %p", conn, priority); |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
600 CHECK_PARAMS( conn && (conn->cc_sctp_para.pairs > 1) && conn->cc_sctp3436_data.array ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
601 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
602 /* Server side: we set all the parameters, the resume callback will take care of resuming the session */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
603 /* Client side: we duplicate the parameters of the master session, then set the transport pointer */ |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
604 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
605 /* For client side, retrieve the master session parameters */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
606 if (conn->cc_tls_para.mode == GNUTLS_CLIENT) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
607 CHECK_GNUTLS_DO( gnutls_session_get_data2(conn->cc_tls_para.session, &master_data), return ENOMEM ); |
69
a8aa7ea6d629
Added a debug for client resuming
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
59
diff
changeset
|
608 /* For debug: */ |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
209
diff
changeset
|
609 if (TRACE_BOOL(GNUTLS_DBG_LEVEL)) { |
69
a8aa7ea6d629
Added a debug for client resuming
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
59
diff
changeset
|
610 uint8_t id[256]; |
a8aa7ea6d629
Added a debug for client resuming
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
59
diff
changeset
|
611 size_t ids = sizeof(id); |
a8aa7ea6d629
Added a debug for client resuming
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
59
diff
changeset
|
612 CHECK_GNUTLS_DO( gnutls_session_get_id(conn->cc_tls_para.session, id, &ids), /* continue */ ); |
965
9b37f34c1b1f
Some modifications to logging code:
Sebastien Decugis <sdecugis@freediameter.net>
parents:
894
diff
changeset
|
613 TRACE_BUFFER(FD_LOG_DEBUG, GNUTLS_DBG_LEVEL, "Master session id: [", id, ids, "]"); |
69
a8aa7ea6d629
Added a debug for client resuming
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
59
diff
changeset
|
614 } |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
615 } |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
616 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
617 /* Initialize the session objects and start the handshake in a separate thread */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
618 for (i = 1; i < conn->cc_sctp_para.pairs; i++) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
619 /* Set credentials and priority */ |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
620 CHECK_FCT( fd_tls_prepare(&conn->cc_sctp3436_data.array[i].session, conn->cc_tls_para.mode, 0, priority, alt_creds) ); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
621 |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
622 /* additional initialization for gnutls 3.x */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
623 #ifdef GNUTLS_VERSION_300 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
624 /* the verify function has already been set in the global initialization in config.c */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
625 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
626 /* fd_tls_verify_credentials_2 uses the connection */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
627 gnutls_session_set_ptr (conn->cc_sctp3436_data.array[i].session, (void *) conn); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
628 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
629 if ((conn->cc_tls_para.cn != NULL) && (conn->cc_tls_para.mode == GNUTLS_CLIENT)) { |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
630 /* this might allow virtual hosting on the remote peer */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
631 CHECK_GNUTLS_DO( gnutls_server_name_set (conn->cc_sctp3436_data.array[i].session, GNUTLS_NAME_DNS, conn->cc_tls_para.cn, strlen(conn->cc_tls_para.cn)), /* ignore failure */); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
632 } |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
633 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
634 #endif /* GNUTLS_VERSION_300 */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
635 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
636 #ifdef GNUTLS_VERSION_310 |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
637 GNUTLS_TRACE( gnutls_handshake_set_timeout( conn->cc_sctp3436_data.array[i].session, GNUTLS_DEFAULT_HANDSHAKE_TIMEOUT)); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
638 #endif /* GNUTLS_VERSION_310 */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
639 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
640 /* For the client, copy data from master session; for the server, set session resuming pointers */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
641 if (conn->cc_tls_para.mode == GNUTLS_CLIENT) { |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
642 CHECK_GNUTLS_DO( gnutls_session_set_data(conn->cc_sctp3436_data.array[i].session, master_data.data, master_data.size), return ENOMEM ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
643 } else { |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
644 set_resume_callbacks(conn->cc_sctp3436_data.array[i].session, conn); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
645 } |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
646 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
647 /* Set transport parameters */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
648 set_sess_transport(conn->cc_sctp3436_data.array[i].session, &conn->cc_sctp3436_data.array[i]); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
649 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
650 /* Start the handshake thread */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
651 CHECK_POSIX( pthread_create( &conn->cc_sctp3436_data.array[i].thr, NULL, handshake_resume_th, &conn->cc_sctp3436_data.array[i] ) ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
652 } |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
653 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
654 /* We can now release the memory of master session data if any */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
655 if (conn->cc_tls_para.mode == GNUTLS_CLIENT) { |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
209
diff
changeset
|
656 GNUTLS_TRACE( gnutls_free(master_data.data) ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
657 } |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
658 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
659 /* Now wait for all handshakes to finish */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
660 for (i = 1; i < conn->cc_sctp_para.pairs; i++) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
661 void * ret; |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
662 CHECK_POSIX( pthread_join(conn->cc_sctp3436_data.array[i].thr, &ret) ); |
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
663 conn->cc_sctp3436_data.array[i].thr = (pthread_t) NULL; |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
664 if (ret == NULL) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
665 errors++; /* Handshake failed on this stream */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
666 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
667 } |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
668 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
207
diff
changeset
|
669 if (errors) { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
207
diff
changeset
|
670 TRACE_DEBUG(INFO, "Handshake failed on %d/%hd stream pairs", errors, conn->cc_sctp_para.pairs); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
207
diff
changeset
|
671 fd_cnx_markerror(conn); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
207
diff
changeset
|
672 return ENOTCONN; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
207
diff
changeset
|
673 } |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
674 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
207
diff
changeset
|
675 return 0; |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
676 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
677 |
543
40141acabee7
Fix behavior of TLS/SCTP when only one peer does not accept the remote certificate
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
455
diff
changeset
|
678 /* Receive messages from others ? all other stream pairs : the master pair */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
679 int fd_sctp3436_startthreads(struct cnxctx * conn, int others) |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
680 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
681 uint16_t i; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
682 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
683 TRACE_ENTRY("%p", conn); |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
684 CHECK_PARAMS( conn && conn->cc_sctp3436_data.array ); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
685 |
543
40141acabee7
Fix behavior of TLS/SCTP when only one peer does not accept the remote certificate
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
455
diff
changeset
|
686 if (others) { |
40141acabee7
Fix behavior of TLS/SCTP when only one peer does not accept the remote certificate
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
455
diff
changeset
|
687 for (i = 1; i < conn->cc_sctp_para.pairs; i++) { |
40141acabee7
Fix behavior of TLS/SCTP when only one peer does not accept the remote certificate
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
455
diff
changeset
|
688 |
40141acabee7
Fix behavior of TLS/SCTP when only one peer does not accept the remote certificate
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
455
diff
changeset
|
689 /* Start the decipher thread */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
690 CHECK_POSIX( pthread_create( &conn->cc_sctp3436_data.array[i].thr, NULL, decipher, &conn->cc_sctp3436_data.array[i] ) ); |
543
40141acabee7
Fix behavior of TLS/SCTP when only one peer does not accept the remote certificate
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
455
diff
changeset
|
691 } |
40141acabee7
Fix behavior of TLS/SCTP when only one peer does not accept the remote certificate
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
455
diff
changeset
|
692 } else { |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
693 CHECK_POSIX( pthread_create( &conn->cc_sctp3436_data.array[0].thr, NULL, decipher, &conn->cc_sctp3436_data.array[0] ) ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
694 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
695 return 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
696 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
697 |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
155
diff
changeset
|
698 /* Initiate a "bye" on all stream pairs */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
699 void fd_sctp3436_bye(struct cnxctx * conn) |
155
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
69
diff
changeset
|
700 { |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
69
diff
changeset
|
701 uint16_t i; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
702 |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
703 CHECK_PARAMS_DO( conn && conn->cc_sctp3436_data.array, return ); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
704 |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
155
diff
changeset
|
705 /* End all TLS sessions, in series (not as efficient as paralel, but simpler) */ |
155
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
69
diff
changeset
|
706 for (i = 1; i < conn->cc_sctp_para.pairs; i++) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
707 if ( ! fd_cnx_teststate(conn, CC_STATUS_ERROR)) { |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
708 CHECK_GNUTLS_DO( gnutls_bye(conn->cc_sctp3436_data.array[i].session, GNUTLS_SHUT_WR), fd_cnx_markerror(conn) ); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
207
diff
changeset
|
709 } |
155
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
69
diff
changeset
|
710 } |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
69
diff
changeset
|
711 } |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
69
diff
changeset
|
712 |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
69
diff
changeset
|
713 /* After "bye" was sent on all streams, read from sessions until an error is received */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
714 void fd_sctp3436_waitthreadsterm(struct cnxctx * conn) |
155
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
69
diff
changeset
|
715 { |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
69
diff
changeset
|
716 uint16_t i; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
717 |
155
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
69
diff
changeset
|
718 TRACE_ENTRY("%p", conn); |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
719 CHECK_PARAMS_DO( conn && conn->cc_sctp3436_data.array, return ); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
720 |
155
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
69
diff
changeset
|
721 for (i = 0; i < conn->cc_sctp_para.pairs; i++) { |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
722 if (conn->cc_sctp3436_data.array[i].thr != (pthread_t)NULL) { |
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
723 CHECK_POSIX_DO( pthread_join(conn->cc_sctp3436_data.array[i].thr, NULL), /* continue */ ); |
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
724 conn->cc_sctp3436_data.array[i].thr = (pthread_t)NULL; |
155
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
69
diff
changeset
|
725 } |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
69
diff
changeset
|
726 } |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
69
diff
changeset
|
727 return; |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
69
diff
changeset
|
728 } |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
69
diff
changeset
|
729 |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
69
diff
changeset
|
730 /* Free gnutls resources of all sessions */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
731 void fd_sctp3436_gnutls_deinit_others(struct cnxctx * conn) |
155
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
69
diff
changeset
|
732 { |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
69
diff
changeset
|
733 uint16_t i; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
734 |
155
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
69
diff
changeset
|
735 TRACE_ENTRY("%p", conn); |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
736 CHECK_PARAMS_DO( conn && conn->cc_sctp3436_data.array, return ); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
737 |
155
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
69
diff
changeset
|
738 for (i = 1; i < conn->cc_sctp_para.pairs; i++) { |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
739 if (conn->cc_sctp3436_data.array[i].session) { |
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
740 GNUTLS_TRACE( gnutls_deinit(conn->cc_sctp3436_data.array[i].session) ); |
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
741 conn->cc_sctp3436_data.array[i].session = NULL; |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
207
diff
changeset
|
742 } |
155
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
69
diff
changeset
|
743 } |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
69
diff
changeset
|
744 } |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
69
diff
changeset
|
745 |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
69
diff
changeset
|
746 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
747 /* Stop all receiver threads */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
748 void fd_sctp3436_stopthreads(struct cnxctx * conn) |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
749 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
750 uint16_t i; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
751 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
752 TRACE_ENTRY("%p", conn); |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
753 CHECK_PARAMS_DO( conn && conn->cc_sctp3436_data.array, return ); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
754 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
755 for (i = 0; i < conn->cc_sctp_para.pairs; i++) { |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
756 CHECK_FCT_DO( fd_thr_term(&conn->cc_sctp3436_data.array[i].thr), /* continue */ ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
757 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
758 return; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
759 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
760 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
761 /* Destroy a wrapper context */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
762 void fd_sctp3436_destroy(struct cnxctx * conn) |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
763 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
764 uint16_t i; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
765 |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
766 CHECK_PARAMS_DO( conn && conn->cc_sctp3436_data.array, return ); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
767 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
768 /* Terminate all receiving threads in case we did not do it yet */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
769 fd_sctp3436_stopthreads(conn); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
770 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
771 /* Now, stop the demux thread */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
772 CHECK_FCT_DO( fd_thr_term(&conn->cc_rcvthr), /* continue */ ); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
773 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
774 /* Free remaining data in the array */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
775 for (i = 0; i < conn->cc_sctp_para.pairs; i++) { |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
776 if (conn->cc_sctp3436_data.array[i].raw_recv) |
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
777 fd_event_destroy( &conn->cc_sctp3436_data.array[i].raw_recv, free ); |
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
778 free(conn->cc_sctp3436_data.array[i].partial.buf); |
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
779 if (conn->cc_sctp3436_data.array[i].session) { |
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
780 GNUTLS_TRACE( gnutls_deinit(conn->cc_sctp3436_data.array[i].session) ); |
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
781 conn->cc_sctp3436_data.array[i].session = NULL; |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
207
diff
changeset
|
782 } |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
783 } |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
784 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
785 /* Free the array itself now */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
786 free(conn->cc_sctp3436_data.array); |
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
787 conn->cc_sctp3436_data.array = NULL; |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
788 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
789 /* Delete the store of sessions */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
790 store_destroy(conn); |
1344
a5c072798f1a
Increase two buffer sizes to avoid truncation.
Thomas Klausner <tk@giga.or.at>
parents:
1190
diff
changeset
|
791 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
792 return ; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
793 } |