Mercurial > hg > freeDiameter
annotate libfdcore/cnxctx.c @ 1200:ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Fri, 14 Jun 2013 10:14:11 +0800 |
parents | 8c4dd4b693c6 |
children | 98478a8aabb1 |
rev | line source |
---|---|
20
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
1 /********************************************************************************************************* |
277ec00d793e
Backup before typhoon... Progress on server side
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:
730
diff
changeset
|
3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * |
20
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
4 * * |
928
5053f1abcf5d
Updated copyright information
Sebastien Decugis <sdecugis@freediameter.net>
parents:
927
diff
changeset
|
5 * Copyright (c) 2013, WIDE Project and NICT * |
20
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
6 * All rights reserved. * |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
7 * * |
277ec00d793e
Backup before typhoon... Progress on server side
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 * |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
9 * permitted provided that the following conditions are met: * |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
10 * * |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
11 * * Redistributions of source code must retain the above * |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
12 * copyright notice, this list of conditions and the * |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
13 * following disclaimer. * |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
14 * * |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
15 * * Redistributions in binary form must reproduce the above * |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
16 * copyright notice, this list of conditions and the * |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
17 * following disclaimer in the documentation and/or other * |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
18 * materials provided with the distribution. * |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
19 * * |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
20 * * Neither the name of the WIDE Project or NICT nor the * |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
21 * names of its contributors may be used to endorse or * |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
22 * promote products derived from this software without * |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
23 * specific prior written permission of WIDE Project and * |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
24 * NICT. * |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
25 * * |
277ec00d793e
Backup before typhoon... Progress on server side
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 * |
277ec00d793e
Backup before typhoon... Progress on server side
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 * |
277ec00d793e
Backup before typhoon... Progress on server side
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 * |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * |
277ec00d793e
Backup before typhoon... Progress on server side
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 * |
277ec00d793e
Backup before typhoon... Progress on server side
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 * |
277ec00d793e
Backup before typhoon... Progress on server side
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 * |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
34 *********************************************************************************************************/ |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
35 |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
591
diff
changeset
|
36 #include "fdcore-internal.h" |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
37 #include "cnxctx.h" |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
38 |
378
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
39 #include <net/if.h> |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
40 #include <ifaddrs.h> /* for getifaddrs */ |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
41 #include <sys/uio.h> /* writev */ |
378
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
42 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
43 /* The maximum size of Diameter message we accept to receive (<= 2^24) to avoid too big mallocs in case of trashed headers */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
44 #ifndef DIAMETER_MSG_SIZE_MAX |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
45 #define DIAMETER_MSG_SIZE_MAX 65535 /* in bytes */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
46 #endif /* DIAMETER_MSG_SIZE_MAX */ |
20
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
47 |
378
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
48 |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
49 /* Connections contexts (cnxctx) in freeDiameter are wrappers around the sockets and TLS operations . |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
50 * They are used to hide the details of the processing to the higher layers of the daemon. |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
51 * They are always oriented on connections (TCP or SCTP), connectionless modes (UDP or SCTP) are not supported. |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
52 */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
53 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
54 /* Lifetime of a cnxctx object: |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
55 * 1) Creation |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
56 * a) a server socket: |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
57 * - create the object with fd_cnx_serv_tcp or fd_cnx_serv_sctp |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
58 * - start listening incoming connections: fd_cnx_serv_listen |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
59 * - accept new clients with fd_cnx_serv_accept. |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
60 * b) a client socket: |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
61 * - connect to a remote server with fd_cnx_cli_connect |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
62 * |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
63 * 2) Initialization |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
64 * - if TLS is started first, call fd_cnx_handshake |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
65 * - otherwise to receive clear messages, call fd_cnx_start_clear. fd_cnx_handshake can be called later. |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
66 * |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
67 * 3) Usage |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
68 * - fd_cnx_receive, fd_cnx_send : exchange messages on this connection (send is synchronous, receive is not, but blocking). |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
69 * - fd_cnx_recv_setaltfifo : when a message is received, the event is sent to an external fifo list. fd_cnx_receive does not work when the alt_fifo is set. |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
70 * - fd_cnx_getid : retrieve a descriptive string for the connection (for debug) |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
71 * - fd_cnx_getremoteid : identification of the remote peer (IP address or fqdn) |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
72 * - fd_cnx_getcred : get the remote peer TLS credentials, after handshake |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
73 * |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
74 * 4) End |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
75 * - fd_cnx_destroy |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
76 */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
77 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
78 /*******************************************/ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
79 /* Creation of a connection object */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
80 /*******************************************/ |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
81 |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
82 /* Initialize a context structure */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
83 static struct cnxctx * fd_cnx_init(int full) |
20
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
84 { |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
85 struct cnxctx * conn = NULL; |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
86 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
87 TRACE_ENTRY("%d", full); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
88 |
20
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
89 CHECK_MALLOC_DO( conn = malloc(sizeof(struct cnxctx)), return NULL ); |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
90 memset(conn, 0, sizeof(struct cnxctx)); |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
91 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
92 if (full) { |
767
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
93 CHECK_FCT_DO( fd_fifo_new ( &conn->cc_incoming, 5 ), return NULL ); |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
94 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
95 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
96 return conn; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
97 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
98 |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
99 #define CC_ID_HDR "{----} " |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
100 |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
101 /* Create and bind a server socket to the given endpoint and port */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
102 struct cnxctx * fd_cnx_serv_tcp(uint16_t port, int family, struct fd_endpoint * ep) |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
103 { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
104 struct cnxctx * cnx = NULL; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
105 sSS dummy; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
106 sSA * sa = (sSA *) &dummy; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
107 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
108 TRACE_ENTRY("%hu %d %p", port, family, ep); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
109 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
110 CHECK_PARAMS_DO( port, return NULL ); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
111 CHECK_PARAMS_DO( ep || family, return NULL ); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
112 CHECK_PARAMS_DO( (! family) || (family == AF_INET) || (family == AF_INET6), return NULL ); |
730 | 113 CHECK_PARAMS_DO( (! ep) || (ep->ss.ss_family == AF_INET) || (ep->ss.ss_family == AF_INET6), return NULL ); |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
114 CHECK_PARAMS_DO( (! ep) || (!family) || (ep->ss.ss_family == family), return NULL ); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
115 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
116 /* The connection object */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
117 CHECK_MALLOC_DO( cnx = fd_cnx_init(0), return NULL ); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
118 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
119 /* Prepare the socket address information */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
120 if (ep) { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
121 memcpy(sa, &ep->ss, sizeof(sSS)); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
122 } else { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
123 memset(&dummy, 0, sizeof(dummy)); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
124 sa->sa_family = family; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
125 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
126 if (sa->sa_family == AF_INET) { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
127 ((sSA4 *)sa)->sin_port = htons(port); |
220
5f2ce627db3c
Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
214
diff
changeset
|
128 cnx->cc_family = AF_INET; |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
129 } else { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
130 ((sSA6 *)sa)->sin6_port = htons(port); |
220
5f2ce627db3c
Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
214
diff
changeset
|
131 cnx->cc_family = AF_INET6; |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
132 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
133 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
134 /* Create the socket */ |
246
6418a188c1b5
getnameinfo is also more sensitive on freeBSD
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
245
diff
changeset
|
135 CHECK_FCT_DO( fd_tcp_create_bind_server( &cnx->cc_socket, sa, sSAlen(sa) ), goto error ); |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
136 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
137 /* Generate the name for the connection object */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
138 { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
139 char addrbuf[INET6_ADDRSTRLEN]; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
140 int rc; |
247
f89b5a12d2af
Forgot a couple of getnameinfo
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
246
diff
changeset
|
141 rc = getnameinfo(sa, sSAlen(sa), addrbuf, sizeof(addrbuf), NULL, 0, NI_NUMERICHOST); |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
142 if (rc) |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
143 snprintf(addrbuf, sizeof(addrbuf), "[err:%s]", gai_strerror(rc)); |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
144 snprintf(cnx->cc_id, sizeof(cnx->cc_id), CC_ID_HDR "TCP srv [%s]:%hu (%d)", addrbuf, port, cnx->cc_socket); |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
145 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
146 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
147 cnx->cc_proto = IPPROTO_TCP; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
148 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
149 return cnx; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
150 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
151 error: |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
152 fd_cnx_destroy(cnx); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
153 return NULL; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
154 } |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
155 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
156 /* Same function for SCTP, with a list of local endpoints to bind to */ |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
157 struct cnxctx * fd_cnx_serv_sctp(uint16_t port, struct fd_list * ep_list) |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
158 { |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
159 #ifdef DISABLE_SCTP |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
160 TRACE_DEBUG(INFO, "This function should never been called when SCTP is disabled..."); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
161 ASSERT(0); |
709
19a9470de77a
Fix a few compilations errors and warnings
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
162 CHECK_FCT_DO( ENOTSUP, ); |
19a9470de77a
Fix a few compilations errors and warnings
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
163 return NULL; |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
164 #else /* DISABLE_SCTP */ |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
165 struct cnxctx * cnx = NULL; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
166 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
167 TRACE_ENTRY("%hu %p", port, ep_list); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
168 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
169 CHECK_PARAMS_DO( port, return NULL ); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
170 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
171 /* The connection object */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
172 CHECK_MALLOC_DO( cnx = fd_cnx_init(0), return NULL ); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
173 |
220
5f2ce627db3c
Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
214
diff
changeset
|
174 if (fd_g_config->cnf_flags.no_ip6) { |
5f2ce627db3c
Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
214
diff
changeset
|
175 cnx->cc_family = AF_INET; |
5f2ce627db3c
Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
214
diff
changeset
|
176 } else { |
5f2ce627db3c
Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
214
diff
changeset
|
177 cnx->cc_family = AF_INET6; /* can create socket for both IP and IPv6 */ |
5f2ce627db3c
Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
214
diff
changeset
|
178 } |
5f2ce627db3c
Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
214
diff
changeset
|
179 |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
180 /* Create the socket */ |
220
5f2ce627db3c
Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
214
diff
changeset
|
181 CHECK_FCT_DO( fd_sctp_create_bind_server( &cnx->cc_socket, cnx->cc_family, ep_list, port ), goto error ); |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
182 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
183 /* Generate the name for the connection object */ |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
184 snprintf(cnx->cc_id, sizeof(cnx->cc_id), CC_ID_HDR "SCTP srv :%hu (%d)", port, cnx->cc_socket); |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
185 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
186 cnx->cc_proto = IPPROTO_SCTP; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
187 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
188 return cnx; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
189 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
190 error: |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
191 fd_cnx_destroy(cnx); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
192 return NULL; |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
193 #endif /* DISABLE_SCTP */ |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
194 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
195 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
196 /* Allow clients to connect on the server socket */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
197 int fd_cnx_serv_listen(struct cnxctx * conn) |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
198 { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
199 CHECK_PARAMS( conn ); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
200 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
201 switch (conn->cc_proto) { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
202 case IPPROTO_TCP: |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
203 CHECK_FCT(fd_tcp_listen(conn->cc_socket)); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
204 break; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
205 |
23
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
206 #ifndef DISABLE_SCTP |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
207 case IPPROTO_SCTP: |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
208 CHECK_FCT(fd_sctp_listen(conn->cc_socket)); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
209 break; |
23
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
210 #endif /* DISABLE_SCTP */ |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
211 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
212 default: |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
213 CHECK_PARAMS(0); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
214 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
215 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
216 return 0; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
217 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
218 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
219 /* Accept a client (blocking until a new client connects) -- cancelable */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
220 struct cnxctx * fd_cnx_serv_accept(struct cnxctx * serv) |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
221 { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
222 struct cnxctx * cli = NULL; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
223 sSS ss; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
224 socklen_t ss_len = sizeof(ss); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
225 int cli_sock = 0; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
226 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
227 TRACE_ENTRY("%p", serv); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
228 CHECK_PARAMS_DO(serv, return NULL); |
20
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
229 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
230 /* Accept the new connection -- this is blocking until new client enters or until cancellation */ |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
231 CHECK_SYS_DO( cli_sock = accept(serv->cc_socket, (sSA *)&ss, &ss_len), return NULL ); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
232 |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
233 CHECK_MALLOC_DO( cli = fd_cnx_init(1), { shutdown(cli_sock, SHUT_RDWR); close(cli_sock); return NULL; } ); |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
234 cli->cc_socket = cli_sock; |
220
5f2ce627db3c
Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
214
diff
changeset
|
235 cli->cc_family = serv->cc_family; |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
236 cli->cc_proto = serv->cc_proto; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
237 |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
238 /* Set the timeout */ |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
239 fd_cnx_s_setto(cli->cc_socket); |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
240 |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
241 /* Generate the name for the connection object */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
242 { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
243 char addrbuf[INET6_ADDRSTRLEN]; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
244 char portbuf[10]; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
245 int rc; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
246 |
711
f7c665948e0c
Use size returned by accept
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
710
diff
changeset
|
247 rc = getnameinfo((sSA *)&ss, ss_len, addrbuf, sizeof(addrbuf), portbuf, sizeof(portbuf), NI_NUMERICHOST | NI_NUMERICSERV); |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
248 if (rc) { |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
249 snprintf(addrbuf, sizeof(addrbuf), "[err:%s]", gai_strerror(rc)); |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
250 portbuf[0] = '\0'; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
251 } |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
252 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
253 /* Numeric values for debug... */ |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
254 snprintf(cli->cc_id, sizeof(cli->cc_id), CC_ID_HDR "%s from [%s]:%s (%d<-%d)", |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
255 IPPROTO_NAME(cli->cc_proto), addrbuf, portbuf, serv->cc_socket, cli->cc_socket); |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
256 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
257 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
258 /* ...Name for log messages */ |
711
f7c665948e0c
Use size returned by accept
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
710
diff
changeset
|
259 rc = getnameinfo((sSA *)&ss, ss_len, cli->cc_remid, sizeof(cli->cc_remid), NULL, 0, 0); |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
260 if (rc) |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
261 snprintf(cli->cc_remid, sizeof(cli->cc_remid), "[err:%s]", gai_strerror(rc)); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
262 } |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1102
diff
changeset
|
263 |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1102
diff
changeset
|
264 LOG_D("Incoming connection: '%s' <- '%s' {%s}", fd_cnx_getid(serv), cli->cc_remid, cli->cc_id); |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
265 |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
266 #ifndef DISABLE_SCTP |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
267 /* SCTP-specific handlings */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
268 if (cli->cc_proto == IPPROTO_SCTP) { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
269 /* Retrieve the number of streams */ |
407 | 270 CHECK_FCT_DO( fd_sctp_get_str_info( cli->cc_socket, &cli->cc_sctp_para.str_in, &cli->cc_sctp_para.str_out, NULL ), {fd_cnx_destroy(cli); return NULL;} ); |
396 | 271 if (cli->cc_sctp_para.str_out < cli->cc_sctp_para.str_in) |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
272 cli->cc_sctp_para.pairs = cli->cc_sctp_para.str_out; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
273 else |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
274 cli->cc_sctp_para.pairs = cli->cc_sctp_para.str_in; |
396 | 275 |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1102
diff
changeset
|
276 LOG_A( "%s : client '%s' (SCTP:%d, %d/%d streams)", fd_cnx_getid(serv), fd_cnx_getid(cli), cli->cc_socket, cli->cc_sctp_para.str_in, cli->cc_sctp_para.str_out); |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
277 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
278 #endif /* DISABLE_SCTP */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
279 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
280 return cli; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
281 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
282 |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
283 /* Client side: connect to a remote server -- cancelable */ |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
284 struct cnxctx * fd_cnx_cli_connect_tcp(sSA * sa /* contains the port already */, socklen_t addrlen) |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
285 { |
227
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
286 int sock = 0; |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
287 struct cnxctx * cnx = NULL; |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1102
diff
changeset
|
288 char sa_buf[sSA_DUMP_STRLEN]; |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
289 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
290 TRACE_ENTRY("%p %d", sa, addrlen); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
291 CHECK_PARAMS_DO( sa && addrlen, return NULL ); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
292 |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1102
diff
changeset
|
293 fd_sa_sdump_numeric(sa_buf, sa); |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1102
diff
changeset
|
294 |
1198
8c4dd4b693c6
Some cleanups in the traces
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1192
diff
changeset
|
295 LOG_D("Connecting to TCP %s...", sa_buf); |
8c4dd4b693c6
Some cleanups in the traces
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1192
diff
changeset
|
296 |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
297 /* Create the socket and connect, which can take some time and/or fail */ |
227
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
298 { |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
299 int ret = fd_tcp_client( &sock, sa, addrlen ); |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
300 if (ret != 0) { |
1198
8c4dd4b693c6
Some cleanups in the traces
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1192
diff
changeset
|
301 LOG_D("TCP connection to %s failed: %s", sa_buf, strerror(ret)); |
227
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
302 return NULL; |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
303 } |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
304 } |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
305 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
306 /* Once the socket is created successfuly, prepare the remaining of the cnx */ |
182
9ed2e3ce4434
Cleaner error handling
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
156
diff
changeset
|
307 CHECK_MALLOC_DO( cnx = fd_cnx_init(1), { shutdown(sock, SHUT_RDWR); close(sock); return NULL; } ); |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
308 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
309 cnx->cc_socket = sock; |
220
5f2ce627db3c
Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
214
diff
changeset
|
310 cnx->cc_family = sa->sa_family; |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
311 cnx->cc_proto = IPPROTO_TCP; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
312 |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
313 /* Set the timeout */ |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
314 fd_cnx_s_setto(cnx->cc_socket); |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
315 |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
316 /* Generate the names for the object */ |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
317 { |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
318 int rc; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
319 |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
320 snprintf(cnx->cc_id, sizeof(cnx->cc_id), CC_ID_HDR "TCP,#%d->%s", cnx->cc_socket, sa_buf); |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
321 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
322 /* ...Name for log messages */ |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
323 rc = getnameinfo(sa, addrlen, cnx->cc_remid, sizeof(cnx->cc_remid), NULL, 0, 0); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
324 if (rc) |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
325 snprintf(cnx->cc_remid, sizeof(cnx->cc_remid), "[err:%s]", gai_strerror(rc)); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
326 } |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
327 |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1102
diff
changeset
|
328 LOG_A("TCP connection to %s succeed (socket:%d).", sa_buf, sock); |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1102
diff
changeset
|
329 |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
330 return cnx; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
331 } |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
332 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
333 /* Same for SCTP, accepts a list of remote addresses to connect to (see sctp_connectx for how they are used) */ |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
334 struct cnxctx * fd_cnx_cli_connect_sctp(int no_ip6, uint16_t port, struct fd_list * list) |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
335 { |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
336 #ifdef DISABLE_SCTP |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
337 TRACE_DEBUG(INFO, "This function should never be called when SCTP is disabled..."); |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
338 ASSERT(0); |
709
19a9470de77a
Fix a few compilations errors and warnings
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
339 CHECK_FCT_DO( ENOTSUP, ); |
19a9470de77a
Fix a few compilations errors and warnings
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
340 return NULL; |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
341 #else /* DISABLE_SCTP */ |
227
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
342 int sock = 0; |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
343 struct cnxctx * cnx = NULL; |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1102
diff
changeset
|
344 char sa_buf[sSA_DUMP_STRLEN]; |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
345 sSS primary; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
346 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
347 TRACE_ENTRY("%p", list); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
348 CHECK_PARAMS_DO( list && !FD_IS_LIST_EMPTY(list), return NULL ); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
349 |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1102
diff
changeset
|
350 fd_sa_sdump_numeric(sa_buf, &((struct fd_endpoint *)(list->next))->sa); |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1102
diff
changeset
|
351 |
1198
8c4dd4b693c6
Some cleanups in the traces
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1192
diff
changeset
|
352 LOG_D("Connecting to SCTP %s:%hu...", sa_buf, port); |
8c4dd4b693c6
Some cleanups in the traces
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1192
diff
changeset
|
353 |
227
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
354 { |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
355 int ret = fd_sctp_client( &sock, no_ip6, port, list ); |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
356 if (ret != 0) { |
1198
8c4dd4b693c6
Some cleanups in the traces
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1192
diff
changeset
|
357 LOG_D("SCTP connection to [%s,...] failed: %s", sa_buf, strerror(ret)); |
227
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
358 return NULL; |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
359 } |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
360 } |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
361 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
362 /* Once the socket is created successfuly, prepare the remaining of the cnx */ |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
363 CHECK_MALLOC_DO( cnx = fd_cnx_init(1), { shutdown(sock, SHUT_RDWR); close(sock); return NULL; } ); |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
364 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
365 cnx->cc_socket = sock; |
220
5f2ce627db3c
Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
214
diff
changeset
|
366 cnx->cc_family = no_ip6 ? AF_INET : AF_INET6; |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
367 cnx->cc_proto = IPPROTO_SCTP; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
368 |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
369 /* Set the timeout */ |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
370 fd_cnx_s_setto(cnx->cc_socket); |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
371 |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
372 /* Retrieve the number of streams and primary address */ |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
373 CHECK_FCT_DO( fd_sctp_get_str_info( sock, &cnx->cc_sctp_para.str_in, &cnx->cc_sctp_para.str_out, &primary ), goto error ); |
402
1e1dc47ef241
Fix remaining problem, closes #6
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
396
diff
changeset
|
374 if (cnx->cc_sctp_para.str_out < cnx->cc_sctp_para.str_in) |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
375 cnx->cc_sctp_para.pairs = cnx->cc_sctp_para.str_out; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
376 else |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
377 cnx->cc_sctp_para.pairs = cnx->cc_sctp_para.str_in; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
378 |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1102
diff
changeset
|
379 fd_sa_sdump_numeric(sa_buf, (sSA *)&primary); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
380 |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
381 /* Generate the names for the object */ |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
382 { |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
383 int rc; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
384 |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
385 snprintf(cnx->cc_id, sizeof(cnx->cc_id), CC_ID_HDR "SCTP,#%d->%s", cnx->cc_socket, sa_buf); |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
386 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
387 /* ...Name for log messages */ |
247
f89b5a12d2af
Forgot a couple of getnameinfo
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
246
diff
changeset
|
388 rc = getnameinfo((sSA *)&primary, sSAlen(&primary), cnx->cc_remid, sizeof(cnx->cc_remid), NULL, 0, 0); |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
389 if (rc) |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
390 snprintf(cnx->cc_remid, sizeof(cnx->cc_remid), "[err:%s]", gai_strerror(rc)); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
391 } |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
392 |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1102
diff
changeset
|
393 LOG_A("SCTP connection to %s succeed (socket:%d, %d/%d streams).", sa_buf, sock, cnx->cc_sctp_para.str_in, cnx->cc_sctp_para.str_out); |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1102
diff
changeset
|
394 |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
395 return cnx; |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
396 |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
397 error: |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
398 fd_cnx_destroy(cnx); |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
399 return NULL; |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
400 #endif /* DISABLE_SCTP */ |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
401 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
402 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
403 /* Return a string describing the connection, for debug */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
404 char * fd_cnx_getid(struct cnxctx * conn) |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
405 { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
406 CHECK_PARAMS_DO( conn, return "" ); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
407 return conn->cc_id; |
20
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
408 } |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
409 |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
410 /* Return the protocol of a connection */ |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
411 int fd_cnx_getproto(struct cnxctx * conn) |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
412 { |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
413 CHECK_PARAMS_DO( conn, return 0 ); |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
414 return conn->cc_proto; |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
415 } |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
416 |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
417 /* Set the hostname to check during handshake */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
418 void fd_cnx_sethostname(struct cnxctx * conn, DiamId_t hn) |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
419 { |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
420 CHECK_PARAMS_DO( conn, return ); |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
421 conn->cc_tls_para.cn = hn; |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
422 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
423 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
424 /* We share a lock with many threads but we hold it only very short time so it is OK */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
425 static pthread_mutex_t state_lock = PTHREAD_MUTEX_INITIALIZER; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
426 uint32_t fd_cnx_getstate(struct cnxctx * conn) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
427 { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
428 uint32_t st; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
429 CHECK_POSIX_DO( pthread_mutex_lock(&state_lock), { ASSERT(0); } ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
430 st = conn->cc_state; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
431 CHECK_POSIX_DO( pthread_mutex_unlock(&state_lock), { ASSERT(0); } ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
432 return st; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
433 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
434 int fd_cnx_teststate(struct cnxctx * conn, uint32_t flag) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
435 { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
436 uint32_t st; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
437 CHECK_POSIX_DO( pthread_mutex_lock(&state_lock), { ASSERT(0); } ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
438 st = conn->cc_state; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
439 CHECK_POSIX_DO( pthread_mutex_unlock(&state_lock), { ASSERT(0); } ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
440 return st & flag; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
441 } |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
442 void fd_cnx_update_id(struct cnxctx * conn) { |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
443 if (conn->cc_state & CC_STATUS_CLOSING) |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
444 conn->cc_id[1] = 'C'; |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
445 else |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
446 conn->cc_id[1] = '-'; |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
447 |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
448 if (conn->cc_state & CC_STATUS_ERROR) |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
449 conn->cc_id[2] = 'E'; |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
450 else |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
451 conn->cc_id[2] = '-'; |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
452 |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
453 if (conn->cc_state & CC_STATUS_SIGNALED) |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
454 conn->cc_id[3] = 'S'; |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
455 else |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
456 conn->cc_id[3] = '-'; |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
457 |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
458 if (conn->cc_state & CC_STATUS_TLS) |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
459 conn->cc_id[4] = 'T'; |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
460 else |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
461 conn->cc_id[4] = '-'; |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
462 } |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
463 void fd_cnx_addstate(struct cnxctx * conn, uint32_t orstate) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
464 { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
465 CHECK_POSIX_DO( pthread_mutex_lock(&state_lock), { ASSERT(0); } ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
466 conn->cc_state |= orstate; |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
467 fd_cnx_update_id(conn); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
468 CHECK_POSIX_DO( pthread_mutex_unlock(&state_lock), { ASSERT(0); } ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
469 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
470 void fd_cnx_setstate(struct cnxctx * conn, uint32_t abstate) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
471 { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
472 CHECK_POSIX_DO( pthread_mutex_lock(&state_lock), { ASSERT(0); } ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
473 conn->cc_state = abstate; |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
474 fd_cnx_update_id(conn); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
475 CHECK_POSIX_DO( pthread_mutex_unlock(&state_lock), { ASSERT(0); } ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
476 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
477 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
478 |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
479 /* Return the TLS state of a connection */ |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
480 int fd_cnx_getTLS(struct cnxctx * conn) |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
481 { |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
482 CHECK_PARAMS_DO( conn, return 0 ); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
483 return fd_cnx_teststate(conn, CC_STATUS_TLS); |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
484 } |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
485 |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
486 /* Mark the connection to tell if OOO delivery is permitted (only for SCTP) */ |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
487 int fd_cnx_unordered_delivery(struct cnxctx * conn, int is_allowed) |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
488 { |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
489 CHECK_PARAMS( conn ); |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
490 conn->cc_sctp_para.unordered = is_allowed; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
491 return 0; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
492 } |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
493 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
494 /* Return true if the connection supports unordered delivery of messages */ |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
495 int fd_cnx_is_unordered_delivery_supported(struct cnxctx * conn) |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
496 { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
497 CHECK_PARAMS_DO( conn, return 0 ); |
709
19a9470de77a
Fix a few compilations errors and warnings
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
498 #ifndef DISABLE_SCTP |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
499 if (conn->cc_proto == IPPROTO_SCTP) |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
500 return (conn->cc_sctp_para.str_out > 1); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
501 #endif /* DISABLE_SCTP */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
502 return 0; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
503 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
504 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
505 |
23
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
506 /* Get the list of endpoints (IP addresses) of the local and remote peers on this connection */ |
378
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
507 int fd_cnx_getremoteeps(struct cnxctx * conn, struct fd_list * eps) |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
508 { |
1027
0117a7746b21
Fix a number of errors and warnings introduced/highlighted by recent commits
Sebastien Decugis <sdecugis@freediameter.net>
parents:
999
diff
changeset
|
509 TRACE_ENTRY("%p %p", conn, eps); |
378
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
510 CHECK_PARAMS(conn && eps); |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
511 |
378
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
512 /* Check we have a full connection object, not a listening socket (with no remote) */ |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
513 CHECK_PARAMS( conn->cc_incoming ); |
23
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
514 |
378
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
515 /* Retrieve the peer endpoint(s) of the connection */ |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
516 switch (conn->cc_proto) { |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
517 case IPPROTO_TCP: { |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
518 sSS ss; |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
519 socklen_t sl; |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
520 CHECK_FCT(fd_tcp_get_remote_ep(conn->cc_socket, &ss, &sl)); |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
521 CHECK_FCT(fd_ep_add_merge( eps, (sSA *)&ss, sl, EP_FL_LL | EP_FL_PRIMARY )); |
23
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
522 } |
378
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
523 break; |
23
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
524 |
378
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
525 #ifndef DISABLE_SCTP |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
526 case IPPROTO_SCTP: { |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
527 CHECK_FCT(fd_sctp_get_remote_ep(conn->cc_socket, eps)); |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
528 } |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
529 break; |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
530 #endif /* DISABLE_SCTP */ |
23
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
531 |
378
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
532 default: |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
533 CHECK_PARAMS(0); |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
534 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
535 |
23
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
536 return 0; |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
537 } |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
538 |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
539 /* Get a string describing the remote peer address (ip address or fqdn) */ |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
540 char * fd_cnx_getremoteid(struct cnxctx * conn) |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
541 { |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
542 CHECK_PARAMS_DO( conn, return "" ); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
543 return conn->cc_remid; |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
544 } |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
545 |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
546 static int fd_cnx_may_dtls(struct cnxctx * conn); |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
547 |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
548 /* Get a short string representing the connection */ |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
549 int fd_cnx_proto_info(struct cnxctx * conn, char * buf, size_t len) |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
550 { |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
551 CHECK_PARAMS( conn ); |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
552 |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
553 if (fd_cnx_teststate(conn, CC_STATUS_TLS)) { |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
554 snprintf(buf, len, "%s,%s,soc#%d", IPPROTO_NAME(conn->cc_proto), fd_cnx_may_dtls(conn) ? "DTLS" : "TLS", conn->cc_socket); |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
555 } else { |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
556 snprintf(buf, len, "%s,soc#%d", IPPROTO_NAME(conn->cc_proto), conn->cc_socket); |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
557 } |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
558 |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
559 return 0; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
560 } |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
561 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
562 /* Retrieve a list of all IP addresses of the local system from the kernel, using getifaddrs */ |
378
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
563 int fd_cnx_get_local_eps(struct fd_list * list) |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
564 { |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
565 struct ifaddrs *iflist, *cur; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
566 |
378
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
567 CHECK_SYS(getifaddrs(&iflist)); |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
568 |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
569 for (cur = iflist; cur != NULL; cur = cur->ifa_next) { |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
570 if (cur->ifa_flags & IFF_LOOPBACK) |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
571 continue; |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
572 |
927
8bb4d749ed37
Fix for ticket #43: PPP interface have no address
Sebastien Decugis <sdecugis@freediameter.net>
parents:
896
diff
changeset
|
573 if (cur->ifa_addr == NULL) /* may happen with ppp interfaces */ |
8bb4d749ed37
Fix for ticket #43: PPP interface have no address
Sebastien Decugis <sdecugis@freediameter.net>
parents:
896
diff
changeset
|
574 continue; |
8bb4d749ed37
Fix for ticket #43: PPP interface have no address
Sebastien Decugis <sdecugis@freediameter.net>
parents:
896
diff
changeset
|
575 |
378
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
576 if (fd_g_config->cnf_flags.no_ip4 && (cur->ifa_addr->sa_family == AF_INET)) |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
577 continue; |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
578 |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
579 if (fd_g_config->cnf_flags.no_ip6 && (cur->ifa_addr->sa_family == AF_INET6)) |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
580 continue; |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
581 |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
582 CHECK_FCT(fd_ep_add_merge( list, cur->ifa_addr, sSAlen(cur->ifa_addr), EP_FL_LL )); |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
583 } |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
584 |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
585 freeifaddrs(iflist); |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
586 |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
587 return 0; |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
588 } |
41e3c2a3721c
Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
258
diff
changeset
|
589 |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
590 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
591 /**************************************/ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
592 /* Use of a connection object */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
593 /**************************************/ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
594 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
595 /* An error occurred on the socket */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
596 void fd_cnx_markerror(struct cnxctx * conn) |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
597 { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
598 TRACE_ENTRY("%p", conn); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
599 CHECK_PARAMS_DO( conn, goto fatal ); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
600 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
601 TRACE_DEBUG(FULL, "Error flag set for socket %d (%s, %s)", conn->cc_socket, conn->cc_id, conn->cc_remid); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
602 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
603 /* Mark the error */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
604 fd_cnx_addstate(conn, CC_STATUS_ERROR); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
605 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
606 /* Report the error if not reported yet, and not closing */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
607 if (!fd_cnx_teststate(conn, CC_STATUS_CLOSING | CC_STATUS_SIGNALED )) { |
223
85dc47afeac7
Cleanup termination
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
220
diff
changeset
|
608 TRACE_DEBUG(FULL, "Sending FDEVP_CNX_ERROR event"); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
609 CHECK_FCT_DO( fd_event_send( fd_cnx_target_queue(conn), FDEVP_CNX_ERROR, 0, NULL), goto fatal); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
610 fd_cnx_addstate(conn, CC_STATUS_SIGNALED); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
611 } |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
612 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
613 return; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
614 fatal: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
615 /* An unrecoverable error occurred, stop the daemon */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
616 ASSERT(0); |
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
|
617 CHECK_FCT_DO(fd_core_shutdown(), ); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
618 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
619 |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
620 /* Set the timeout option on the socket */ |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
621 void fd_cnx_s_setto(int sock) |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
622 { |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
623 struct timeval tv; |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
624 |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
625 /* Set a timeout on the socket so that in any case we are not stuck waiting for something */ |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
626 memset(&tv, 0, sizeof(tv)); |
1200
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
627 tv.tv_usec = 100000L; /* 100ms, to react quickly to head-of-the-line blocking. */ |
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
628 CHECK_SYS_DO( setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)), ); |
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
629 CHECK_SYS_DO( setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)), ); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
630 } |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
631 |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
632 |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
633 #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
|
634 /* The pull_timeout function for gnutls */ |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
635 static int fd_cnx_s_select (struct cnxctx * conn, 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
|
636 { |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
637 fd_set rfds; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
638 struct timeval tv; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
639 |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
640 FD_ZERO (&rfds); |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
641 FD_SET (conn->cc_socket, &rfds); |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
642 |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
643 tv.tv_sec = ms / 1000; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
644 tv.tv_usec = (ms * 1000) % 1000000; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
645 |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
646 return select (conn->cc_socket + 1, &rfds, NULL, NULL, &tv); |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
647 } |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
648 #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
|
649 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
650 /* A recv-like function, taking a cnxctx object instead of socket as entry. We use it to quickly react to timeouts without traversing GNUTLS wrapper each time */ |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
651 ssize_t fd_cnx_s_recv(struct cnxctx * conn, void *buffer, size_t length) |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
652 { |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
653 ssize_t ret = 0; |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
654 int timedout = 0; |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
655 again: |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
656 ret = recv(conn->cc_socket, buffer, length, 0); |
710 | 657 /* Handle special case of timeout / interrupts */ |
658 if ((ret < 0) && ((errno == EAGAIN) || (errno == EINTR))) { | |
659 pthread_testcancel(); | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
660 if (! fd_cnx_teststate(conn, CC_STATUS_CLOSING )) |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
661 goto again; /* don't care, just ignore */ |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
662 if (!timedout) { |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
663 timedout ++; /* allow for one timeout while closing */ |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
664 goto again; |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
665 } |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
666 } |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
667 |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
668 /* Mark the error */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
669 if (ret <= 0) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
670 CHECK_SYS_DO(ret, /* continue, this is only used to log the error here */); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
671 fd_cnx_markerror(conn); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
672 } |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
673 |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
674 return ret; |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
675 } |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
676 |
1200
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
677 /* Send */ |
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
678 static ssize_t fd_cnx_s_sendv(struct cnxctx * conn, const struct iovec * iov, int iovcnt) |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
679 { |
201
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
680 ssize_t ret = 0; |
1200
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
681 struct timespec ts, now; |
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
682 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &ts), return -1 ); |
201
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
683 again: |
1200
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
684 ret = writev(conn->cc_socket, iov, iovcnt); |
201
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
685 /* Handle special case of timeout */ |
710 | 686 if ((ret < 0) && ((errno == EAGAIN) || (errno == EINTR))) { |
1200
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
687 ret = -errno; |
710 | 688 pthread_testcancel(); |
1200
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
689 |
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
690 /* Check how much time we were blocked for this sending. */ |
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
691 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &now), return -1 ); |
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
692 if ( ((now.tv_sec - ts.tv_sec) * 1000 + ((now.tv_nsec - ts.tv_nsec) / 1000000L)) > MAX_HOTL_BLOCKING_TIME) { |
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
693 LOG_D("Unable to send any data for %dms, closing the connection", MAX_HOTL_BLOCKING_TIME); |
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
694 } else if (! fd_cnx_teststate(conn, CC_STATUS_CLOSING )) { |
201
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
695 goto again; /* don't care, just ignore */ |
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
696 } |
1200
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
697 |
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
698 /* propagate the error */ |
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
699 errno = -ret; |
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
700 ret = -1; |
201
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
701 CHECK_SYS_DO(ret, /* continue */); |
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
702 } |
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
703 |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
704 /* Mark the error */ |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
705 if (ret <= 0) |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
706 fd_cnx_markerror(conn); |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
707 |
201
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
708 return ret; |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
709 } |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
710 |
1200
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
711 /* Send, for older GNUTLS */ |
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
712 #ifndef GNUTLS_VERSION_212 |
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
713 static ssize_t fd_cnx_s_send(struct cnxctx * conn, const void *buffer, size_t length) |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
714 { |
1200
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
715 struct iovec iov; |
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
716 iov.iov_base = (void *)buffer; |
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
717 iov.iov_len = length; |
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
718 return fd_cnx_s_sendv(conn, &iov, 1); |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
719 } |
1200
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
720 #endif /* GNUTLS_VERSION_212 */ |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
721 |
1102
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
722 #define ALIGNOF(t) ((char *)(&((struct { char c; t _h; } *)0)->_h) - (char *)0) /* Could use __alignof__(t) on some systems but this is more portable probably */ |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
723 #define PMDL_PADDED(len) ( ((len) + ALIGNOF(struct fd_msg_pmdl) - 1) & ~(ALIGNOF(struct fd_msg_pmdl) - 1) ) |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
724 |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
725 size_t fd_msg_pmdl_sizewithoverhead(size_t datalen) |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
726 { |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1102
diff
changeset
|
727 return PMDL_PADDED(datalen) + sizeof(struct fd_msg_pmdl); |
1102
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
728 } |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
729 |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
730 struct fd_msg_pmdl * fd_msg_pmdl_get_inbuf(uint8_t * buf, size_t datalen) |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
731 { |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
732 return (struct fd_msg_pmdl *)(buf + PMDL_PADDED(datalen)); |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
733 } |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
734 |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
735 static int fd_cnx_init_msg_buffer(uint8_t * buffer, size_t expected_len, struct fd_msg_pmdl ** pmdl) |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
736 { |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
737 *pmdl = fd_msg_pmdl_get_inbuf(buffer, expected_len); |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
738 fd_list_init(&(*pmdl)->sentinel, NULL); |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
739 CHECK_POSIX(pthread_mutex_init(&(*pmdl)->lock, NULL) ); |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
740 return 0; |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
741 } |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
742 |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
743 static uint8_t * fd_cnx_alloc_msg_buffer(size_t expected_len, struct fd_msg_pmdl ** pmdl) |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
744 { |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
745 uint8_t * ret = NULL; |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
746 |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1102
diff
changeset
|
747 CHECK_MALLOC_DO( ret = malloc( fd_msg_pmdl_sizewithoverhead(expected_len) ), return NULL ); |
1102
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
748 CHECK_FCT_DO( fd_cnx_init_msg_buffer(ret, expected_len, pmdl), {free(ret); return NULL;} ); |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
749 return ret; |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
750 } |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
751 |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
752 #ifndef DISABLE_SCTP /* WE use this function only in SCTP code */ |
1102
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
753 static uint8_t * fd_cnx_realloc_msg_buffer(uint8_t * buffer, size_t expected_len, struct fd_msg_pmdl ** pmdl) |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
754 { |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
755 uint8_t * ret = NULL; |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
756 |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1102
diff
changeset
|
757 CHECK_MALLOC_DO( ret = realloc( buffer, fd_msg_pmdl_sizewithoverhead(expected_len) ), return NULL ); |
1102
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
758 CHECK_FCT_DO( fd_cnx_init_msg_buffer(ret, expected_len, pmdl), {free(ret); return NULL;} ); |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
759 return ret; |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
760 } |
1141
3ae22e5dc56c
Fix a few compilation warnings/errors
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1103
diff
changeset
|
761 #endif /* DISABLE_SCTP */ |
1102
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
762 |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
763 static void free_rcvdata(void * arg) |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
764 { |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
765 struct fd_cnx_rcvdata * data = arg; |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
766 struct fd_msg_pmdl * pmdl = fd_msg_pmdl_get_inbuf(data->buffer, data->length); |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
767 (void) pthread_mutex_destroy(&pmdl->lock); |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
768 free(data->buffer); |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
769 } |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
770 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
771 /* Receiver thread (TCP & noTLS) : incoming message is directly saved into the target queue */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
772 static void * rcvthr_notls_tcp(void * arg) |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
773 { |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
774 struct cnxctx * conn = arg; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
775 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
776 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
|
777 CHECK_PARAMS_DO(conn && (conn->cc_socket > 0), goto out); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
778 |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
779 /* 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
|
780 { |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
781 char buf[48]; |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
782 snprintf(buf, sizeof(buf), "Receiver (%d) TCP/noTLS)", conn->cc_socket); |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
783 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
|
784 } |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
785 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
786 ASSERT( conn->cc_proto == IPPROTO_TCP ); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
787 ASSERT( ! fd_cnx_teststate(conn, CC_STATUS_TLS ) ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
788 ASSERT( fd_cnx_target_queue(conn) ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
789 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
790 /* Receive from a TCP connection: we have to rebuild the message boundaries */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
791 do { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
792 uint8_t header[4]; |
1102
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
793 struct fd_cnx_rcvdata rcv_data; |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
794 struct fd_msg_pmdl *pmdl=NULL; |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
795 ssize_t ret = 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
796 size_t received = 0; |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
797 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
798 do { |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
799 ret = fd_cnx_s_recv(conn, &header[received], sizeof(header) - received); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
800 if (ret <= 0) { |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
801 goto out; /* Stop the thread, the event was already sent */ |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
802 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
803 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
804 received += ret; |
1192
48759e3f7611
Reject more quickly invalid messages if possible
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1190
diff
changeset
|
805 |
48759e3f7611
Reject more quickly invalid messages if possible
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1190
diff
changeset
|
806 if (header[0] != DIAMETER_VERSION) |
48759e3f7611
Reject more quickly invalid messages if possible
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1190
diff
changeset
|
807 break; /* No need to wait for 4 bytes in this case */ |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
808 } while (received < sizeof(header)); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
809 |
1102
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
810 rcv_data.length = ((size_t)header[1] << 16) + ((size_t)header[2] << 8) + (size_t)header[3]; |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
811 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
812 /* Check the received word is a valid begining of a Diameter message */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
813 if ((header[0] != DIAMETER_VERSION) /* defined in <libfdproto.h> */ |
1102
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
814 || (rcv_data.length > DIAMETER_MSG_SIZE_MAX)) { /* to avoid too big mallocs */ |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
815 /* The message is suspect */ |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1102
diff
changeset
|
816 LOG_E( "Received suspect header [ver: %d, size: %zd] from '%s', assuming disconnection", (int)header[0], rcv_data.length, conn->cc_remid); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
817 fd_cnx_markerror(conn); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
818 goto out; /* Stop the thread, the recipient of the event will cleanup */ |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
819 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
820 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
821 /* Ok, now we can really receive the data */ |
1102
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
822 CHECK_MALLOC_DO( rcv_data.buffer = fd_cnx_alloc_msg_buffer( rcv_data.length, &pmdl ), goto fatal ); |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
823 memcpy(rcv_data.buffer, header, sizeof(header)); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
824 |
1102
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
825 while (received < rcv_data.length) { |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
826 pthread_cleanup_push(free_rcvdata, &rcv_data); /* In case we are canceled, clean the partialy built buffer */ |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
827 ret = fd_cnx_s_recv(conn, rcv_data.buffer + received, rcv_data.length - received); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
828 pthread_cleanup_pop(0); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
829 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
830 if (ret <= 0) { |
1102
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
831 free_rcvdata(&rcv_data); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
832 goto out; |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
833 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
834 received += ret; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
835 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
836 |
1102
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
837 fd_hook_call(HOOK_DATA_RECEIVED, NULL, NULL, &rcv_data, pmdl); |
1098
f38d77f9cfd3
Initial implementation of the hook mechanism
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1084
diff
changeset
|
838 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
839 /* We have received a complete message, pass it to the daemon */ |
1102
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
840 CHECK_FCT_DO( fd_event_send( fd_cnx_target_queue(conn), FDEVP_CNX_MSG_RECV, rcv_data.length, rcv_data.buffer), |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
841 { |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
842 free_rcvdata(&rcv_data); |
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
|
843 goto fatal; |
1102
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
844 } ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
845 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
846 } while (conn->cc_loop); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
847 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
848 out: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
849 TRACE_DEBUG(FULL, "Thread terminated"); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
850 return NULL; |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
851 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
852 fatal: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
853 /* 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
|
854 CHECK_FCT_DO(fd_core_shutdown(), ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
855 goto out; |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
856 } |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
857 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
858 #ifndef DISABLE_SCTP |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
859 /* Receiver thread (SCTP & noTLS) : incoming message is directly saved into cc_incoming, no need to care for the stream ID */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
860 static void * rcvthr_notls_sctp(void * arg) |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
861 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
862 struct cnxctx * conn = arg; |
1102
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
863 struct fd_cnx_rcvdata rcv_data; |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
864 int event; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
865 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
866 TRACE_ENTRY("%p", arg); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
867 CHECK_PARAMS_DO(conn && (conn->cc_socket > 0), goto fatal); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
868 |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
869 /* 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
|
870 { |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
871 char buf[48]; |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
872 snprintf(buf, sizeof(buf), "Receiver (%d) SCTP/noTLS)", conn->cc_socket); |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
873 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
|
874 } |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
875 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
876 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
|
877 ASSERT( ! fd_cnx_teststate(conn, CC_STATUS_TLS ) ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
878 ASSERT( fd_cnx_target_queue(conn) ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
879 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
880 do { |
1102
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
881 struct fd_msg_pmdl *pmdl=NULL; |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
882 CHECK_FCT_DO( fd_sctp_recvmeta(conn, NULL, &rcv_data.buffer, &rcv_data.length, &event), goto fatal ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
883 if (event == FDEVP_CNX_ERROR) { |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
884 fd_cnx_markerror(conn); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
885 goto out; |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
886 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
887 |
228 | 888 if (event == FDEVP_CNX_SHUTDOWN) { |
889 /* Just ignore the notification for now, we will get another error later anyway */ | |
890 continue; | |
891 } | |
1102
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
892 |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
893 if (event == FDEVP_CNX_MSG_RECV) { |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
894 CHECK_MALLOC_DO( rcv_data.buffer = fd_cnx_realloc_msg_buffer(rcv_data.buffer, rcv_data.length, &pmdl), goto fatal ); |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
895 fd_hook_call(HOOK_DATA_RECEIVED, NULL, NULL, &rcv_data, pmdl); |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
896 } |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
897 CHECK_FCT_DO( fd_event_send( fd_cnx_target_queue(conn), event, rcv_data.length, rcv_data.buffer), goto fatal ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
898 |
250
07624e65c7e0
Loop anyway until we get a real message or an error
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
247
diff
changeset
|
899 } while (conn->cc_loop || (event != FDEVP_CNX_MSG_RECV)); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
900 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
901 out: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
902 TRACE_DEBUG(FULL, "Thread terminated"); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
903 return NULL; |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
904 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
905 fatal: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
906 /* 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
|
907 CHECK_FCT_DO(fd_core_shutdown(), ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
908 goto out; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
909 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
910 #endif /* DISABLE_SCTP */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
911 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
912 /* Start receving messages in clear (no TLS) on the connection */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
913 int fd_cnx_start_clear(struct cnxctx * conn, int loop) |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
914 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
915 TRACE_ENTRY("%p %i", conn, loop); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
916 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
917 CHECK_PARAMS( conn && fd_cnx_target_queue(conn) && (!fd_cnx_teststate(conn, CC_STATUS_TLS)) && (!conn->cc_loop)); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
918 |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
919 /* Release resources in case of a previous call was already made */ |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
920 CHECK_FCT_DO( fd_thr_term(&conn->cc_rcvthr), /* continue */); |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
921 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
922 /* Save the loop request */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
923 conn->cc_loop = loop; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
924 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
925 switch (conn->cc_proto) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
926 case IPPROTO_TCP: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
927 /* Start the tcp_notls thread */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
928 CHECK_POSIX( pthread_create( &conn->cc_rcvthr, NULL, rcvthr_notls_tcp, conn ) ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
929 break; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
930 #ifndef DISABLE_SCTP |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
931 case IPPROTO_SCTP: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
932 /* Start the tcp_notls thread */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
933 CHECK_POSIX( pthread_create( &conn->cc_rcvthr, NULL, rcvthr_notls_sctp, conn ) ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
934 break; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
935 #endif /* DISABLE_SCTP */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
936 default: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
937 TRACE_DEBUG(INFO, "Unknown protocol: %d", conn->cc_proto); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
938 ASSERT(0); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
939 return ENOTSUP; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
940 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
941 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
942 return 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
943 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
944 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
945 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
946 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
947 |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
948 /* Returns 0 on error, received data size otherwise (always >= 0). This is not used for DTLS-protected associations. */ |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
949 static ssize_t fd_tls_recv_handle_error(struct cnxctx * conn, gnutls_session_t session, void * data, size_t sz) |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
950 { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
951 ssize_t ret; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
952 again: |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
953 CHECK_GNUTLS_DO( ret = gnutls_record_recv(session, data, sz), |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
954 { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
955 switch (ret) { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
956 case GNUTLS_E_REHANDSHAKE: |
803
d5a4b5e175c2
Add timeout in gnutls_handshake for version 3.1.x
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
767
diff
changeset
|
957 if (!fd_cnx_teststate(conn, CC_STATUS_CLOSING)) { |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
958 CHECK_GNUTLS_DO( ret = gnutls_handshake(session), |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
959 { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
960 if (TRACE_BOOL(INFO)) { |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
961
diff
changeset
|
961 fd_log_debug("TLS re-handshake failed on socket %d (%s) : %s", conn->cc_socket, conn->cc_id, gnutls_strerror(ret)); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
962 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
963 goto end; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
964 } ); |
803
d5a4b5e175c2
Add timeout in gnutls_handshake for version 3.1.x
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
767
diff
changeset
|
965 } |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
966 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
967 case GNUTLS_E_AGAIN: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
968 case GNUTLS_E_INTERRUPTED: |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
969 if (!fd_cnx_teststate(conn, CC_STATUS_CLOSING)) |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
970 goto again; |
228 | 971 TRACE_DEBUG(FULL, "Connection is closing, so abord gnutls_record_recv now."); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
972 break; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
973 |
228 | 974 case GNUTLS_E_UNEXPECTED_PACKET_LENGTH: |
975 /* The connection is closed */ | |
976 TRACE_DEBUG(FULL, "Got 0 size while reading the socket, probably connection closed..."); | |
977 break; | |
978 | |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
979 default: |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
980 if (gnutls_error_is_fatal (ret) == 0) { |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
981 LOG_N("Ignoring non-fatal GNU TLS error: %s", gnutls_strerror (ret)); |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
982 goto again; |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
983 } |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
984 LOG_E("Fatal GNUTLS error: %s", gnutls_strerror (ret)); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
985 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
986 } ); |
251
52c1547dab42
Call gnutls_bye on closing connection
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
250
diff
changeset
|
987 |
52c1547dab42
Call gnutls_bye on closing connection
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
250
diff
changeset
|
988 if (ret == 0) |
52c1547dab42
Call gnutls_bye on closing connection
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
250
diff
changeset
|
989 CHECK_GNUTLS_DO( gnutls_bye(session, GNUTLS_SHUT_RDWR), ); |
52c1547dab42
Call gnutls_bye on closing connection
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
250
diff
changeset
|
990 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
991 end: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
992 if (ret <= 0) |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
993 fd_cnx_markerror(conn); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
994 return ret; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
995 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
996 |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
997 /* Wrapper around gnutls_record_send to handle some error codes. This is also used for DTLS-protected associations */ |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
998 static ssize_t fd_tls_send_handle_error(struct cnxctx * conn, gnutls_session_t session, void * data, size_t sz) |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
999 { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1000 ssize_t ret; |
1200
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
1001 struct timespec ts, now; |
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
1002 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &ts), return -1 ); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1003 again: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1004 CHECK_GNUTLS_DO( ret = gnutls_record_send(session, data, sz), |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1005 { |
1200
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
1006 pthread_testcancel(); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1007 switch (ret) { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1008 case GNUTLS_E_REHANDSHAKE: |
803
d5a4b5e175c2
Add timeout in gnutls_handshake for version 3.1.x
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
767
diff
changeset
|
1009 if (!fd_cnx_teststate(conn, CC_STATUS_CLOSING)) { |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1010 CHECK_GNUTLS_DO( ret = gnutls_handshake(session), |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1011 { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1012 if (TRACE_BOOL(INFO)) { |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
961
diff
changeset
|
1013 fd_log_debug("TLS re-handshake failed on socket %d (%s) : %s", conn->cc_socket, conn->cc_id, gnutls_strerror(ret)); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1014 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1015 goto end; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1016 } ); |
803
d5a4b5e175c2
Add timeout in gnutls_handshake for version 3.1.x
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
767
diff
changeset
|
1017 } |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1018 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1019 case GNUTLS_E_AGAIN: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1020 case GNUTLS_E_INTERRUPTED: |
1200
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
1021 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &now), return -1 ); |
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
1022 if ( ((now.tv_sec - ts.tv_sec) * 1000 + ((now.tv_nsec - ts.tv_nsec) / 1000000L)) > MAX_HOTL_BLOCKING_TIME) { |
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
1023 LOG_D("Unable to send any data for %dms, closing the connection", MAX_HOTL_BLOCKING_TIME); |
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
1024 } else if (! fd_cnx_teststate(conn, CC_STATUS_CLOSING )) { |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1025 goto again; |
1200
ce2b00dc86c1
React quickly to head-of-the-line blocking in case of network failure. Can be adapted with MAX_HOTL_BLOCKING_TIME constant in cnxctx.h
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1198
diff
changeset
|
1026 } |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1027 break; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1028 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1029 default: |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1030 if (gnutls_error_is_fatal (ret) == 0) { |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1031 LOG_N("Ignoring non-fatal GNU TLS error: %s", gnutls_strerror (ret)); |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1032 goto again; |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1033 } |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1034 LOG_E("Fatal GNUTLS error: %s", gnutls_strerror (ret)); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1035 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1036 } ); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1037 end: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1038 if (ret <= 0) |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1039 fd_cnx_markerror(conn); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1040 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1041 return ret; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1042 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1043 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1044 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1045 /* The function that receives TLS data and re-builds a Diameter message -- it exits only on error or cancelation */ |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1046 /* For the case of DTLS, since we are not using SCTP_UNORDERED, the messages over a single stream are ordered. |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1047 Furthermore, as long as messages are shorter than the MTU [2^14 = 16384 bytes], they are delivered in a single |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1048 record, as far as I understand. |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1049 For larger messages, however, it is possible that pieces of messages coming from different streams can get interleaved. |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1050 As a result, we do not use the following function for DTLS reception, because we use the sequence number to rebuild the |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1051 messages. */ |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1052 int fd_tls_rcvthr_core(struct cnxctx * conn, gnutls_session_t session) |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1053 { |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1054 /* No guarantee that GnuTLS preserves the message boundaries, so we re-build it as in TCP. */ |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1055 do { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1056 uint8_t header[4]; |
1102
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
1057 struct fd_cnx_rcvdata rcv_data; |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
1058 struct fd_msg_pmdl *pmdl=NULL; |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1059 ssize_t ret = 0; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1060 size_t received = 0; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1061 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1062 do { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1063 ret = fd_tls_recv_handle_error(conn, session, &header[received], sizeof(header) - received); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1064 if (ret <= 0) { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1065 /* The connection is closed */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1066 goto out; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1067 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1068 received += ret; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1069 } while (received < sizeof(header)); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1070 |
1102
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
1071 rcv_data.length = ((size_t)header[1] << 16) + ((size_t)header[2] << 8) + (size_t)header[3]; |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1072 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1073 /* Check the received word is a valid beginning of a Diameter message */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1074 if ((header[0] != DIAMETER_VERSION) /* defined in <libfreeDiameter.h> */ |
1102
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
1075 || (rcv_data.length > DIAMETER_MSG_SIZE_MAX)) { /* to avoid too big mallocs */ |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1076 /* The message is suspect */ |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1102
diff
changeset
|
1077 LOG_E( "Received suspect header [ver: %d, size: %zd] from '%s', assume disconnection", (int)header[0], rcv_data.length, conn->cc_remid); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1078 fd_cnx_markerror(conn); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1079 goto out; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1080 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1081 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1082 /* Ok, now we can really receive the data */ |
1102
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
1083 CHECK_MALLOC( rcv_data.buffer = fd_cnx_alloc_msg_buffer( rcv_data.length, &pmdl ) ); |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
1084 memcpy(rcv_data.buffer, header, sizeof(header)); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1085 |
1102
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
1086 while (received < rcv_data.length) { |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
1087 pthread_cleanup_push(free_rcvdata, &rcv_data); /* In case we are canceled, clean the partialy built buffer */ |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
1088 ret = fd_tls_recv_handle_error(conn, session, rcv_data.buffer + received, rcv_data.length - received); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1089 pthread_cleanup_pop(0); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1090 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1091 if (ret <= 0) { |
1102
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
1092 free_rcvdata(&rcv_data); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1093 goto out; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1094 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1095 received += ret; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1096 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1097 |
1102
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
1098 fd_hook_call(HOOK_DATA_RECEIVED, NULL, NULL, &rcv_data, pmdl); |
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
1099 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1100 /* We have received a complete message, pass it to the daemon */ |
1102
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
1101 CHECK_FCT_DO( ret = fd_event_send( fd_cnx_target_queue(conn), FDEVP_CNX_MSG_RECV, rcv_data.length, rcv_data.buffer), |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1102 { |
1102
1d7b3ebda27f
Implemented the calls to HOOK_DATA_RECEIVED hook
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1101
diff
changeset
|
1103 free_rcvdata(&rcv_data); |
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
|
1104 CHECK_FCT_DO(fd_core_shutdown(), ); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1105 return ret; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1106 } ); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1107 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1108 } while (1); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1109 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1110 out: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1111 return ENOTCONN; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1112 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1113 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1114 /* Receiver thread (TLS & 1 stream SCTP or TCP) */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1115 static void * rcvthr_tls_single(void * arg) |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1116 { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1117 struct cnxctx * conn = arg; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1118 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1119 TRACE_ENTRY("%p", arg); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1120 CHECK_PARAMS_DO(conn && (conn->cc_socket > 0), return NULL ); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1121 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1122 /* Set the thread name */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1123 { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1124 char buf[48]; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1125 snprintf(buf, sizeof(buf), "Receiver (%d) TLS/single stream", conn->cc_socket); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1126 fd_log_threadname ( buf ); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1127 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1128 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1129 ASSERT( fd_cnx_teststate(conn, CC_STATUS_TLS) ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1130 ASSERT( fd_cnx_target_queue(conn) ); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1131 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1132 /* The next function only returns when there is an error on the socket */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1133 CHECK_FCT_DO(fd_tls_rcvthr_core(conn, conn->cc_tls_para.session), /* continue */); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1134 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1135 TRACE_DEBUG(FULL, "Thread terminated"); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1136 return NULL; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1137 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1138 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1139 /* Prepare a gnutls session object for handshake */ |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1140 int fd_tls_prepare(gnutls_session_t * session, int mode, int dtls, char * priority, void * alt_creds) |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1141 { |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1142 if (dtls) { |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1143 LOG_E("DTLS sessions not yet supported"); |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1144 return ENOTSUP; |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1145 } |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1146 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1147 /* Create the session context */ |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1148 CHECK_GNUTLS_DO( gnutls_init (session, mode), return ENOMEM ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1149 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1150 /* Set the algorithm suite */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1151 if (priority) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1152 const char * errorpos; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1153 CHECK_GNUTLS_DO( gnutls_priority_set_direct( *session, priority, &errorpos ), |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
961
diff
changeset
|
1154 { TRACE_DEBUG(INFO, "Error in priority string '%s' at position: '%s'", priority, errorpos); return EINVAL; } ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1155 } else { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1156 CHECK_GNUTLS_DO( gnutls_priority_set( *session, fd_g_config->cnf_sec_data.prio_cache ), return EINVAL ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1157 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1158 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1159 /* Set the credentials of this side of the connection */ |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
1160 CHECK_GNUTLS_DO( gnutls_credentials_set (*session, GNUTLS_CRD_CERTIFICATE, alt_creds ?: fd_g_config->cnf_sec_data.credentials), return EINVAL ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1161 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1162 /* Request the remote credentials as well */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1163 if (mode == GNUTLS_SERVER) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1164 gnutls_certificate_server_set_request (*session, GNUTLS_CERT_REQUIRE); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1165 } |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1166 |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1167 return 0; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1168 } |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
1169 |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1170 #ifndef 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
|
1171 |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1172 /* Verify remote credentials after successful handshake (return 0 if OK, EINVAL otherwise) */ |
59
067ab3fc6093
Cleanups in debug messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
57
diff
changeset
|
1173 int fd_tls_verify_credentials(gnutls_session_t session, struct cnxctx * conn, int verbose) |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1174 { |
543
40141acabee7
Fix behavior of TLS/SCTP when only one peer does not accept the remote certificate
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
542
diff
changeset
|
1175 int i, ret = 0; |
403
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
402
diff
changeset
|
1176 unsigned int gtret; |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1177 const gnutls_datum_t *cert_list; |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1178 unsigned int cert_list_size; |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1179 gnutls_x509_crt_t cert; |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1180 time_t now; |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1181 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1182 TRACE_ENTRY("%p %d", conn, verbose); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1183 CHECK_PARAMS(conn); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1184 |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1185 /* Trace the session information -- http://www.gnu.org/software/gnutls/manual/gnutls.html#Obtaining-session-information */ |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1186 #ifdef DEBUG |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1187 if (verbose) { |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1188 const char *tmp; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1189 gnutls_kx_algorithm_t kx; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1190 gnutls_credentials_type_t cred; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1191 |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1192 LOG_A("TLS Session information for connection '%s':", conn->cc_id); |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1193 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1194 /* print the key exchange's algorithm name */ |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1195 GNUTLS_TRACE( kx = gnutls_kx_get (session) ); |
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1196 GNUTLS_TRACE( tmp = gnutls_kx_get_name (kx) ); |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1197 LOG_A("\t - Key Exchange: %s", tmp); |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1198 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1199 /* Check the authentication type used and switch |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1200 * to the appropriate. */ |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1201 GNUTLS_TRACE( cred = gnutls_auth_get_type (session) ); |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1202 switch (cred) |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1203 { |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1204 case GNUTLS_CRD_IA: |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1205 LOG_A("\t - TLS/IA session"); |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1206 break; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1207 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1208 case GNUTLS_CRD_PSK: |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1209 /* This returns NULL in server side. */ |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1210 if (gnutls_psk_client_get_hint (session) != NULL) |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1211 LOG_A("\t - PSK authentication. PSK hint '%s'", |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1212 gnutls_psk_client_get_hint (session)); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1213 /* This returns NULL in client side. */ |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1214 if (gnutls_psk_server_get_username (session) != NULL) |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1215 LOG_A("\t - PSK authentication. Connected as '%s'", |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1216 gnutls_psk_server_get_username (session)); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1217 break; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1218 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1219 case GNUTLS_CRD_ANON: /* anonymous authentication */ |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1220 LOG_A("\t - Anonymous DH using prime of %d bits", |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1221 gnutls_dh_get_prime_bits (session)); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1222 break; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1223 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1224 case GNUTLS_CRD_CERTIFICATE: /* certificate authentication */ |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1225 /* Check if we have been using ephemeral Diffie-Hellman. */ |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1226 if (kx == GNUTLS_KX_DHE_RSA || kx == GNUTLS_KX_DHE_DSS) { |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1227 LOG_A("\t - Ephemeral DH using prime of %d bits", |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1228 gnutls_dh_get_prime_bits (session)); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1229 } |
403
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
402
diff
changeset
|
1230 break; |
591
88a494357a9d
Protect against gnutls_srp_server_get_username which is not provided on some platforms, including Fedora 13
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
543
diff
changeset
|
1231 #ifdef ENABLE_SRP |
403
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
402
diff
changeset
|
1232 case GNUTLS_CRD_SRP: |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1233 LOG_A("\t - SRP session with username %s", |
403
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
402
diff
changeset
|
1234 gnutls_srp_server_get_username (session)); |
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
402
diff
changeset
|
1235 break; |
591
88a494357a9d
Protect against gnutls_srp_server_get_username which is not provided on some platforms, including Fedora 13
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
543
diff
changeset
|
1236 #endif /* ENABLE_SRP */ |
403
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
402
diff
changeset
|
1237 |
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
402
diff
changeset
|
1238 default: |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
961
diff
changeset
|
1239 fd_log_debug("\t - Different type of credentials for the session (%d).", cred); |
403
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
402
diff
changeset
|
1240 break; |
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
402
diff
changeset
|
1241 |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1242 } |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1243 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1244 /* print the protocol's name (ie TLS 1.0) */ |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1245 tmp = gnutls_protocol_get_name (gnutls_protocol_get_version (session)); |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1246 LOG_A("\t - Protocol: %s", tmp); |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1247 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1248 /* print the certificate type of the peer. ie X.509 */ |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1249 tmp = gnutls_certificate_type_get_name (gnutls_certificate_type_get (session)); |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1250 LOG_A("\t - Certificate Type: %s", tmp); |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1251 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1252 /* print the compression algorithm (if any) */ |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1253 tmp = gnutls_compression_get_name (gnutls_compression_get (session)); |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1254 LOG_A("\t - Compression: %s", tmp); |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1255 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1256 /* print the name of the cipher used. ie 3DES. */ |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1257 tmp = gnutls_cipher_get_name (gnutls_cipher_get (session)); |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1258 LOG_A("\t - Cipher: %s", tmp); |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1259 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1260 /* Print the MAC algorithms name. ie SHA1 */ |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1261 tmp = gnutls_mac_get_name (gnutls_mac_get (session)); |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1262 LOG_A("\t - MAC: %s", tmp); |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1263 } |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1264 #endif /* DEBUG */ |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1265 |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1266 /* First, use built-in verification */ |
403
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
402
diff
changeset
|
1267 CHECK_GNUTLS_DO( gnutls_certificate_verify_peers2 (session, >ret), return EINVAL ); |
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
402
diff
changeset
|
1268 if (gtret) { |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1269 if (TRACE_BOOL(INFO)) { |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
961
diff
changeset
|
1270 fd_log_debug("TLS: Remote certificate invalid on socket %d (Remote: '%s')(Connection: '%s') :", conn->cc_socket, conn->cc_remid, conn->cc_id); |
403
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
402
diff
changeset
|
1271 if (gtret & GNUTLS_CERT_INVALID) |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
961
diff
changeset
|
1272 fd_log_debug(" - The certificate is not trusted (unknown CA? expired?)"); |
403
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
402
diff
changeset
|
1273 if (gtret & GNUTLS_CERT_REVOKED) |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
961
diff
changeset
|
1274 fd_log_debug(" - The certificate has been revoked."); |
403
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
402
diff
changeset
|
1275 if (gtret & GNUTLS_CERT_SIGNER_NOT_FOUND) |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
961
diff
changeset
|
1276 fd_log_debug(" - The certificate hasn't got a known issuer."); |
403
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
402
diff
changeset
|
1277 if (gtret & GNUTLS_CERT_SIGNER_NOT_CA) |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
961
diff
changeset
|
1278 fd_log_debug(" - The certificate signer is not a CA, or uses version 1, or 3 without basic constraints."); |
403
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
402
diff
changeset
|
1279 if (gtret & GNUTLS_CERT_INSECURE_ALGORITHM) |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
961
diff
changeset
|
1280 fd_log_debug(" - The certificate signature uses a weak algorithm."); |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1281 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1282 return EINVAL; |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1283 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1284 |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1285 /* Code from http://www.gnu.org/software/gnutls/manual/gnutls.html#Verifying-peer_0027s-certificate */ |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1286 if (gnutls_certificate_type_get (session) != GNUTLS_CRT_X509) |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1287 return EINVAL; |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1288 |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1289 GNUTLS_TRACE( cert_list = gnutls_certificate_get_peers (session, &cert_list_size) ); |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1290 if (cert_list == NULL) |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1291 return EINVAL; |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1292 |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1293 now = time(NULL); |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1294 |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1295 #ifdef DEBUG |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1296 char serial[40]; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1297 char dn[128]; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1298 size_t size; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1299 unsigned int algo, bits; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1300 time_t expiration_time, activation_time; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1301 |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1302 LOG_D("TLS Certificate information for connection '%s' (%d certs provided):", conn->cc_id, cert_list_size); |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1303 for (i = 0; i < cert_list_size; i++) |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1304 { |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1305 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1306 CHECK_GNUTLS_DO( gnutls_x509_crt_init (&cert), return EINVAL); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1307 CHECK_GNUTLS_DO( gnutls_x509_crt_import (cert, &cert_list[i], GNUTLS_X509_FMT_DER), return EINVAL); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1308 |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1309 LOG_A(" Certificate %d info:", i); |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1310 |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1311 GNUTLS_TRACE( expiration_time = gnutls_x509_crt_get_expiration_time (cert) ); |
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1312 GNUTLS_TRACE( activation_time = gnutls_x509_crt_get_activation_time (cert) ); |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1313 |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1314 LOG( i ? FD_LOG_ANNOYING : FD_LOG_DEBUG, "\t - Certificate is valid since: %.24s", ctime (&activation_time)); |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1315 LOG( i ? FD_LOG_ANNOYING : FD_LOG_DEBUG, "\t - Certificate expires: %.24s", ctime (&expiration_time)); |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1316 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1317 /* Print the serial number of the certificate. */ |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1318 size = sizeof (serial); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1319 gnutls_x509_crt_get_serial (cert, serial, &size); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1320 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1321 { |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1322 int j; |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
961
diff
changeset
|
1323 char buf[1024]; |
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
961
diff
changeset
|
1324 snprintf(buf, sizeof(buf), "\t - Certificate serial number: "); |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1325 for (j = 0; j < size; j++) { |
999
0f71fc6c069f
Fix compilation warning
Sebastien Decugis <sdecugis@freediameter.net>
parents:
982
diff
changeset
|
1326 snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), "%02hhx", serial[j]); |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1327 } |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1328 LOG( i ? FD_LOG_ANNOYING : FD_LOG_DEBUG, "%s", buf); |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1329 } |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1330 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1331 /* Extract some of the public key algorithm's parameters */ |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1332 GNUTLS_TRACE( algo = gnutls_x509_crt_get_pk_algorithm (cert, &bits) ); |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1333 LOG( i ? FD_LOG_ANNOYING : FD_LOG_DEBUG, "\t - Certificate public key: %s", |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1334 gnutls_pk_algorithm_get_name (algo)); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1335 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1336 /* Print the version of the X.509 certificate. */ |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1337 LOG( i ? FD_LOG_ANNOYING : FD_LOG_DEBUG, "\t - Certificate version: #%d", |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1338 gnutls_x509_crt_get_version (cert)); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1339 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1340 size = sizeof (dn); |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1341 GNUTLS_TRACE( gnutls_x509_crt_get_dn (cert, dn, &size) ); |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1342 LOG( i ? FD_LOG_ANNOYING : FD_LOG_DEBUG, "\t - DN: %s", dn); |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1343 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1344 size = sizeof (dn); |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1345 GNUTLS_TRACE( gnutls_x509_crt_get_issuer_dn (cert, dn, &size) ); |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1346 LOG( i ? FD_LOG_ANNOYING : FD_LOG_DEBUG, "\t - Issuer's DN: %s", dn); |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1347 |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1348 GNUTLS_TRACE( gnutls_x509_crt_deinit (cert) ); |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1349 } |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1350 #endif /* DEBUG */ |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1351 |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1352 /* Check validity of all the certificates */ |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1353 for (i = 0; i < cert_list_size; i++) |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1354 { |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1355 time_t deadline; |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1356 |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1357 CHECK_GNUTLS_DO( gnutls_x509_crt_init (&cert), return EINVAL); |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1358 CHECK_GNUTLS_DO( gnutls_x509_crt_import (cert, &cert_list[i], GNUTLS_X509_FMT_DER), return EINVAL); |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1359 |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1360 GNUTLS_TRACE( deadline = gnutls_x509_crt_get_expiration_time(cert) ); |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1361 if ((deadline != (time_t)-1) && (deadline < now)) { |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1362 if (TRACE_BOOL(INFO)) { |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
961
diff
changeset
|
1363 fd_log_debug("TLS: Remote certificate invalid on socket %d (Remote: '%s')(Connection: '%s') :", conn->cc_socket, conn->cc_remid, conn->cc_id); |
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
961
diff
changeset
|
1364 fd_log_debug(" - The certificate %d in the chain is expired", i); |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1365 } |
543
40141acabee7
Fix behavior of TLS/SCTP when only one peer does not accept the remote certificate
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
542
diff
changeset
|
1366 ret = EINVAL; |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1367 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1368 |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1369 GNUTLS_TRACE( deadline = gnutls_x509_crt_get_activation_time(cert) ); |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1370 if ((deadline != (time_t)-1) && (deadline > now)) { |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1371 if (TRACE_BOOL(INFO)) { |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
961
diff
changeset
|
1372 fd_log_debug("TLS: Remote certificate invalid on socket %d (Remote: '%s')(Connection: '%s') :", conn->cc_socket, conn->cc_remid, conn->cc_id); |
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
961
diff
changeset
|
1373 fd_log_debug(" - The certificate %d in the chain is not yet activated", i); |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1374 } |
543
40141acabee7
Fix behavior of TLS/SCTP when only one peer does not accept the remote certificate
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
542
diff
changeset
|
1375 ret = EINVAL; |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1376 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1377 |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1378 if ((i == 0) && (conn->cc_tls_para.cn)) { |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1379 if (!gnutls_x509_crt_check_hostname (cert, conn->cc_tls_para.cn)) { |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1380 if (TRACE_BOOL(INFO)) { |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
961
diff
changeset
|
1381 fd_log_debug("TLS: Remote certificate invalid on socket %d (Remote: '%s')(Connection: '%s') :", conn->cc_socket, conn->cc_remid, conn->cc_id); |
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
961
diff
changeset
|
1382 fd_log_debug(" - The certificate hostname does not match '%s'", conn->cc_tls_para.cn); |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1383 } |
543
40141acabee7
Fix behavior of TLS/SCTP when only one peer does not accept the remote certificate
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
542
diff
changeset
|
1384 ret = EINVAL; |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1385 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1386 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1387 |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1388 GNUTLS_TRACE( gnutls_x509_crt_deinit (cert) ); |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1389 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1390 |
543
40141acabee7
Fix behavior of TLS/SCTP when only one peer does not accept the remote certificate
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
542
diff
changeset
|
1391 return ret; |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1392 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1393 |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1394 #else /* 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
|
1395 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1396 /* Verify remote credentials DURING handshake (return gnutls status) */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1397 int fd_tls_verify_credentials_2(gnutls_session_t session) |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1398 { |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1399 /* inspired from gnutls 3.x guidelines */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1400 unsigned int status; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1401 const gnutls_datum_t *cert_list = NULL; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1402 unsigned int cert_list_size; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1403 gnutls_x509_crt_t cert; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1404 struct cnxctx * conn; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1405 int hostname_verified = 0; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1406 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1407 TRACE_ENTRY("%p", session); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1408 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1409 /* get the associated connection */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1410 conn = gnutls_session_get_ptr (session); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1411 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1412 /* Trace the session information -- http://www.gnu.org/software/gnutls/manual/gnutls.html#Obtaining-session-information */ |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1413 #ifdef DEBUG |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1414 const char *tmp; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1415 gnutls_credentials_type_t cred; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1416 gnutls_kx_algorithm_t kx; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1417 int dhe, ecdh; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1418 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1419 dhe = ecdh = 0; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1420 |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1421 LOG_A("TLS Session information for connection '%s':", conn->cc_id); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1422 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1423 /* print the key exchange's algorithm name |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1424 */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1425 GNUTLS_TRACE( kx = gnutls_kx_get (session) ); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1426 GNUTLS_TRACE( tmp = gnutls_kx_get_name (kx) ); |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1427 LOG_A("\t- Key Exchange: %s", tmp); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1428 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1429 /* Check the authentication type used and switch |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1430 * to the appropriate. |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1431 */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1432 GNUTLS_TRACE( cred = gnutls_auth_get_type (session) ); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1433 switch (cred) |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1434 { |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1435 case GNUTLS_CRD_IA: |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1436 LOG_A("\t - TLS/IA session"); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1437 break; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1438 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1439 |
982
018357d4c9bb
Use gnutls_srp_* functions only ifdef ENABLE_SRP
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
1440 #ifdef ENABLE_SRP |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1441 case GNUTLS_CRD_SRP: |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1442 LOG_A("\t - SRP session with username %s", |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1443 gnutls_srp_server_get_username (session)); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1444 break; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1445 #endif |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1446 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1447 case GNUTLS_CRD_PSK: |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1448 /* This returns NULL in server side. |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1449 */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1450 if (gnutls_psk_client_get_hint (session) != NULL) |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1451 LOG_A("\t - PSK authentication. PSK hint '%s'", |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1452 gnutls_psk_client_get_hint (session)); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1453 /* This returns NULL in client side. |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1454 */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1455 if (gnutls_psk_server_get_username (session) != NULL) |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1456 LOG_A("\t - PSK authentication. Connected as '%s'", |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1457 gnutls_psk_server_get_username (session)); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1458 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1459 if (kx == GNUTLS_KX_ECDHE_PSK) |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1460 ecdh = 1; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1461 else if (kx == GNUTLS_KX_DHE_PSK) |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1462 dhe = 1; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1463 break; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1464 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1465 case GNUTLS_CRD_ANON: /* anonymous authentication */ |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1466 LOG_A("\t - Anonymous DH using prime of %d bits", |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1467 gnutls_dh_get_prime_bits (session)); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1468 if (kx == GNUTLS_KX_ANON_ECDH) |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1469 ecdh = 1; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1470 else if (kx == GNUTLS_KX_ANON_DH) |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1471 dhe = 1; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1472 break; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1473 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1474 case GNUTLS_CRD_CERTIFICATE: /* certificate authentication */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1475 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1476 /* Check if we have been using ephemeral Diffie-Hellman. |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1477 */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1478 if (kx == GNUTLS_KX_DHE_RSA || kx == GNUTLS_KX_DHE_DSS) |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1479 dhe = 1; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1480 else if (kx == GNUTLS_KX_ECDHE_RSA || kx == GNUTLS_KX_ECDHE_ECDSA) |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1481 ecdh = 1; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1482 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1483 /* Now print some info on the remote certificate */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1484 if (gnutls_certificate_type_get (session) == GNUTLS_CRT_X509) { |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1485 gnutls_datum_t cinfo; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1486 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1487 cert_list = gnutls_certificate_get_peers (session, &cert_list_size); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1488 |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1489 LOG_A("\t Peer provided %d certificates.", cert_list_size); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1490 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1491 if (cert_list_size > 0) |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1492 { |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1493 int ret; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1494 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1495 /* we only print information about the first certificate. |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1496 */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1497 gnutls_x509_crt_init (&cert); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1498 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1499 gnutls_x509_crt_import (cert, &cert_list[0], GNUTLS_X509_FMT_DER); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1500 |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1501 LOG_A("\t Certificate info:"); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1502 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1503 /* This is the preferred way of printing short information about |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1504 a certificate. */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1505 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1506 ret = gnutls_x509_crt_print (cert, GNUTLS_CRT_PRINT_ONELINE, &cinfo); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1507 if (ret == 0) |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1508 { |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1509 LOG_A("\t\t%s", cinfo.data); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1510 gnutls_free (cinfo.data); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1511 } |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1512 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1513 if (conn->cc_tls_para.cn) { |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1514 if (!gnutls_x509_crt_check_hostname (cert, conn->cc_tls_para.cn)) { |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
961
diff
changeset
|
1515 fd_log_debug("\tTLS: Remote certificate invalid on socket %d (Remote: '%s')(Connection: '%s') :", conn->cc_socket, conn->cc_remid, conn->cc_id); |
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
961
diff
changeset
|
1516 fd_log_debug("\t - The certificate hostname does not match '%s'", conn->cc_tls_para.cn); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1517 gnutls_x509_crt_deinit (cert); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1518 return GNUTLS_E_CERTIFICATE_ERROR; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1519 } |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1520 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1521 } |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1522 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1523 hostname_verified = 1; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1524 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1525 gnutls_x509_crt_deinit (cert); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1526 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1527 } |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1528 } |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1529 break; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1530 |
1145
ea3a653a809e
Fix warning on OpenSUSE
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1141
diff
changeset
|
1531 default: |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1532 LOG_A("\t - unknown session type (%d)", cred); |
1145
ea3a653a809e
Fix warning on OpenSUSE
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1141
diff
changeset
|
1533 |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1534 } /* switch */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1535 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1536 if (ecdh != 0) |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1537 LOG_A("\t - Ephemeral ECDH using curve %s", |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1538 gnutls_ecc_curve_get_name (gnutls_ecc_curve_get (session))); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1539 else if (dhe != 0) |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1540 LOG_A("\t - Ephemeral DH using prime of %d bits", |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1541 gnutls_dh_get_prime_bits (session)); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1542 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1543 /* print the protocol's name (ie TLS 1.0) |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1544 */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1545 tmp = gnutls_protocol_get_name (gnutls_protocol_get_version (session)); |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1546 LOG_A("\t - Protocol: %s", tmp); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1547 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1548 /* print the certificate type of the peer. |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1549 * ie X.509 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1550 */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1551 tmp = gnutls_certificate_type_get_name (gnutls_certificate_type_get (session)); |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1552 LOG_A("\t - Certificate Type: %s", tmp); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1553 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1554 /* print the compression algorithm (if any) |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1555 */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1556 tmp = gnutls_compression_get_name (gnutls_compression_get (session)); |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1557 LOG_A("\t - Compression: %s", tmp); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1558 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1559 /* print the name of the cipher used. |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1560 * ie 3DES. |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1561 */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1562 tmp = gnutls_cipher_get_name (gnutls_cipher_get (session)); |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1563 LOG_A("\t - Cipher: %s", tmp); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1564 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1565 /* Print the MAC algorithms name. |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1566 * ie SHA1 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1567 */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1568 tmp = gnutls_mac_get_name (gnutls_mac_get (session)); |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1569 LOG_A("\t - MAC: %s", tmp); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1570 |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1571 #endif /* DEBUG */ |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1572 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1573 /* This verification function uses the trusted CAs in the credentials |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1574 * structure. So you must have installed one or more CA certificates. |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1575 */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1576 CHECK_GNUTLS_DO( gnutls_certificate_verify_peers2 (session, &status), return GNUTLS_E_CERTIFICATE_ERROR ); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1577 if (TRACE_BOOL(INFO) && (status & GNUTLS_CERT_INVALID)) { |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
961
diff
changeset
|
1578 fd_log_debug("TLS: Remote certificate invalid on socket %d (Remote: '%s')(Connection: '%s') :", conn->cc_socket, conn->cc_remid, conn->cc_id); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1579 if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
961
diff
changeset
|
1580 fd_log_debug(" - The certificate hasn't got a known issuer."); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1581 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1582 if (status & GNUTLS_CERT_REVOKED) |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
961
diff
changeset
|
1583 fd_log_debug(" - The certificate has been revoked."); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1584 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1585 if (status & GNUTLS_CERT_EXPIRED) |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
961
diff
changeset
|
1586 fd_log_debug(" - The certificate has expired."); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1587 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1588 if (status & GNUTLS_CERT_NOT_ACTIVATED) |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
961
diff
changeset
|
1589 fd_log_debug(" - The certificate is not yet activated."); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1590 } |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1591 if (status & GNUTLS_CERT_INVALID) |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1592 { |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1593 return GNUTLS_E_CERTIFICATE_ERROR; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1594 } |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1595 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1596 /* Up to here the process is the same for X.509 certificates and |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1597 * OpenPGP keys. From now on X.509 certificates are assumed. This can |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1598 * be easily extended to work with openpgp keys as well. |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1599 */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1600 if ((!hostname_verified) && (conn->cc_tls_para.cn)) { |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1601 if (gnutls_certificate_type_get (session) != GNUTLS_CRT_X509) { |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
961
diff
changeset
|
1602 TRACE_DEBUG(INFO, "TLS: Remote credentials are not x509, rejected on socket %d (Remote: '%s')(Connection: '%s') :", conn->cc_socket, conn->cc_remid, conn->cc_id); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1603 return GNUTLS_E_CERTIFICATE_ERROR; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1604 } |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1605 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1606 CHECK_GNUTLS_DO( gnutls_x509_crt_init (&cert), return GNUTLS_E_CERTIFICATE_ERROR ); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1607 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1608 cert_list = gnutls_certificate_get_peers (session, &cert_list_size); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1609 CHECK_PARAMS_DO( cert_list, return GNUTLS_E_CERTIFICATE_ERROR ); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1610 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1611 CHECK_GNUTLS_DO( gnutls_x509_crt_import (cert, &cert_list[0], GNUTLS_X509_FMT_DER), return GNUTLS_E_CERTIFICATE_ERROR ); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1612 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1613 if (!gnutls_x509_crt_check_hostname (cert, conn->cc_tls_para.cn)) { |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1614 if (TRACE_BOOL(INFO)) { |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
961
diff
changeset
|
1615 fd_log_debug("TLS: Remote certificate invalid on socket %d (Remote: '%s')(Connection: '%s') :", conn->cc_socket, conn->cc_remid, conn->cc_id); |
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
961
diff
changeset
|
1616 fd_log_debug(" - The certificate hostname does not match '%s'", conn->cc_tls_para.cn); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1617 } |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1618 gnutls_x509_crt_deinit (cert); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1619 return GNUTLS_E_CERTIFICATE_ERROR; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1620 } |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1621 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1622 gnutls_x509_crt_deinit (cert); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1623 } |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1624 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1625 /* notify gnutls to continue handshake normally */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1626 return 0; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1627 } |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1628 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1629 #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
|
1630 |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1631 static int fd_cnx_may_dtls(struct cnxctx * conn) { |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1632 #ifndef DISABLE_SCTP |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1633 if ((conn->cc_proto == IPPROTO_SCTP) && (conn->cc_tls_para.algo == ALGO_HANDSHAKE_DEFAULT)) |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1634 return 1; |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1635 #endif /* DISABLE_SCTP */ |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1636 return 0; |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1637 } |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1638 |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1639 static int fd_cnx_uses_dtls(struct cnxctx * conn) { |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1640 return fd_cnx_may_dtls(conn) && (fd_cnx_teststate(conn, CC_STATUS_TLS)); |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1641 } |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1642 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1643 /* TLS handshake a connection; no need to have called start_clear before. Reception is active if handhsake is successful */ |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1644 int fd_cnx_handshake(struct cnxctx * conn, int mode, int algo, char * priority, void * alt_creds) |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1645 { |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1646 int dtls = 0; |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1647 |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1648 TRACE_ENTRY( "%p %d %d %p %p", conn, mode, algo, priority, alt_creds); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1649 CHECK_PARAMS( conn && (!fd_cnx_teststate(conn, CC_STATUS_TLS)) && ( (mode == GNUTLS_CLIENT) || (mode == GNUTLS_SERVER) ) && (!conn->cc_loop) ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1650 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1651 /* Save the mode */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1652 conn->cc_tls_para.mode = mode; |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1653 conn->cc_tls_para.algo = algo; |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1654 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1655 /* Cancel receiving thread if any -- it should already be terminated anyway, we just release the resources */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1656 CHECK_FCT_DO( fd_thr_term(&conn->cc_rcvthr), /* continue */); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1657 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1658 /* Once TLS handshake is done, we don't stop after the first message */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1659 conn->cc_loop = 1; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1660 |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1661 dtls = fd_cnx_may_dtls(conn); |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1662 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1663 /* Prepare the master session credentials and priority */ |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1664 CHECK_FCT( fd_tls_prepare(&conn->cc_tls_para.session, mode, dtls, priority, alt_creds) ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1665 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1666 /* Special case: multi-stream TLS is not natively managed in GNU TLS, we use a wrapper library */ |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1667 if ((!dtls) && (conn->cc_sctp_para.pairs > 1)) { |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1668 #ifdef DISABLE_SCTP |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1669 ASSERT(0); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1670 CHECK_FCT( ENOTSUP ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1671 #else /* DISABLE_SCTP */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1672 /* Initialize the wrapper, start the demux thread */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1145
diff
changeset
|
1673 CHECK_FCT( fd_sctp3436_init(conn) ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1674 #endif /* DISABLE_SCTP */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1675 } else { |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
1676 /* Set the transport pointer passed to push & pull callbacks */ |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1677 GNUTLS_TRACE( gnutls_transport_set_ptr( conn->cc_tls_para.session, (gnutls_transport_ptr_t) conn ) ); |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
1678 |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
1679 /* Set the push and pull callbacks */ |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1680 if (!dtls) { |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1681 #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
|
1682 GNUTLS_TRACE( gnutls_transport_set_pull_timeout_function( conn->cc_tls_para.session, (void *)fd_cnx_s_select ) ); |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1683 #endif /* GNUTLS_VERSION_300 */ |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1684 GNUTLS_TRACE( gnutls_transport_set_pull_function(conn->cc_tls_para.session, (void *)fd_cnx_s_recv) ); |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1685 #ifndef GNUTLS_VERSION_212 |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1686 GNUTLS_TRACE( gnutls_transport_set_push_function(conn->cc_tls_para.session, (void *)fd_cnx_s_send) ); |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1687 #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
|
1688 GNUTLS_TRACE( gnutls_transport_set_vec_push_function(conn->cc_tls_para.session, (void *)fd_cnx_s_sendv) ); |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1689 #endif /* GNUTLS_VERSION_212 */ |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1690 } else { |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1691 TODO("DTLS push/pull functions"); |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1692 return ENOTSUP; |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1693 } |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1694 } |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1695 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1696 /* 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
|
1697 #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
|
1698 /* 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
|
1699 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1700 /* fd_tls_verify_credentials_2 uses the connection */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1701 gnutls_session_set_ptr (conn->cc_tls_para.session, (void *) conn); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1702 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1703 if ((conn->cc_tls_para.cn != NULL) && (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
|
1704 /* this might allow virtual hosting on the remote peer */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1705 CHECK_GNUTLS_DO( gnutls_server_name_set (conn->cc_tls_para.session, GNUTLS_NAME_DNS, conn->cc_tls_para.cn, strlen(conn->cc_tls_para.cn)), /* ignore failure */); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1706 } |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1707 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1708 #endif /* GNUTLS_VERSION_300 */ |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1709 |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1710 #ifdef 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
|
1711 GNUTLS_TRACE( gnutls_handshake_set_timeout( conn->cc_tls_para.session, GNUTLS_DEFAULT_HANDSHAKE_TIMEOUT)); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1712 #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
|
1713 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1714 /* Mark the connection as protected from here, so that the gnutls credentials will be freed */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1715 fd_cnx_addstate(conn, CC_STATUS_TLS); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1716 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1717 /* Handshake master session */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1718 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1719 int ret; |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1720 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1721 CHECK_GNUTLS_DO( ret = gnutls_handshake(conn->cc_tls_para.session), |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1722 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1723 if (TRACE_BOOL(INFO)) { |
974
2091bf698fb1
Remove newlines from fd_log_debug, TRACE_DEBUG, TRACE_ERROR, and TRACE_DEBUG_ERROR
Thomas Klausner <tk@giga.or.at>
parents:
961
diff
changeset
|
1724 fd_log_debug("TLS Handshake failed on socket %d (%s) : %s", conn->cc_socket, conn->cc_id, gnutls_strerror(ret)); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1725 } |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1726 fd_cnx_markerror(conn); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1727 return EINVAL; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1728 } ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1729 |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1730 #ifndef GNUTLS_VERSION_300 |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1731 /* Now verify the remote credentials are valid -- only simple tests here */ |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1732 CHECK_FCT_DO( fd_tls_verify_credentials(conn->cc_tls_para.session, conn, 1), |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1733 { |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1734 CHECK_GNUTLS_DO( gnutls_bye(conn->cc_tls_para.session, GNUTLS_SHUT_RDWR), ); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1735 fd_cnx_markerror(conn); |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1736 return EINVAL; |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1737 }); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1738 #endif /* GNUTLS_VERSION_300 */ |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1739 } |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1740 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1741 /* Multi-stream TLS: handshake other streams as well */ |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1742 if ((!dtls) && (conn->cc_sctp_para.pairs > 1)) { |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1743 #ifndef DISABLE_SCTP |
543
40141acabee7
Fix behavior of TLS/SCTP when only one peer does not accept the remote certificate
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
542
diff
changeset
|
1744 /* Start reading the messages from the master session. That way, if the remote peer closed, we are not stuck inside handshake */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1145
diff
changeset
|
1745 CHECK_FCT(fd_sctp3436_startthreads(conn, 0)); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1746 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1747 /* Resume all additional sessions from the master one. */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1145
diff
changeset
|
1748 CHECK_FCT(fd_sctp3436_handshake_others(conn, priority, alt_creds)); |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
1749 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1750 /* Start decrypting the messages from all threads and queuing them in target queue */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1145
diff
changeset
|
1751 CHECK_FCT(fd_sctp3436_startthreads(conn, 1)); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1752 #endif /* DISABLE_SCTP */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1753 } else { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1754 /* Start decrypting the data */ |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1755 if (!dtls) { |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1756 CHECK_POSIX( pthread_create( &conn->cc_rcvthr, NULL, rcvthr_tls_single, conn ) ); |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1757 } else { |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1758 TODO("Signal the dtls_push function that multiple streams can be used from this point."); |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1759 TODO("Create DTLS rcvthr (must reassembly based on seq numbers & stream id ?)"); |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1760 return ENOTSUP; |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1761 } |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1762 } |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
1763 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1764 return 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1765 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1766 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1767 /* Retrieve TLS credentials of the remote peer, after handshake */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1768 int fd_cnx_getcred(struct cnxctx * conn, const gnutls_datum_t **cert_list, unsigned int *cert_list_size) |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1769 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1770 TRACE_ENTRY("%p %p %p", conn, cert_list, cert_list_size); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1771 CHECK_PARAMS( conn && fd_cnx_teststate(conn, CC_STATUS_TLS) && cert_list && cert_list_size ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1772 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1773 /* This function only works for X.509 certificates. */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1774 CHECK_PARAMS( gnutls_certificate_type_get (conn->cc_tls_para.session) == GNUTLS_CRT_X509 ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1775 |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1776 GNUTLS_TRACE( *cert_list = gnutls_certificate_get_peers (conn->cc_tls_para.session, cert_list_size) ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1777 if (*cert_list == NULL) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1778 TRACE_DEBUG(INFO, "No certificate was provided by remote peer / an error occurred."); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1779 return EINVAL; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1780 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1781 |
54
889c55527a1d
Fixed additional newline character
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
53
diff
changeset
|
1782 TRACE_DEBUG( FULL, "Saved certificate chain (%d certificates) in peer structure.", *cert_list_size); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1783 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1784 return 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1785 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1786 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1787 /* Receive next message. if timeout is not NULL, wait only until timeout. This function only pulls from a queue, mgr thread is filling that queue aynchrounously. */ |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1788 /* if the altfifo has been set on this conn object, this function must not be called */ |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1789 int fd_cnx_receive(struct cnxctx * conn, struct timespec * timeout, unsigned char **buf, size_t * len) |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1790 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1791 int ev; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1792 size_t ev_sz; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1793 void * ev_data; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1794 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1795 TRACE_ENTRY("%p %p %p %p", conn, timeout, buf, len); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1796 CHECK_PARAMS(conn && (conn->cc_socket > 0) && buf && len); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1797 CHECK_PARAMS(conn->cc_rcvthr != (pthread_t)NULL); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1798 CHECK_PARAMS(conn->cc_alt == NULL); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1799 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1800 /* Now, pull the first event */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1801 get_next: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1802 if (timeout) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1803 CHECK_FCT( fd_event_timedget(conn->cc_incoming, timeout, FDEVP_PSM_TIMEOUT, &ev, &ev_sz, &ev_data) ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1804 } else { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1805 CHECK_FCT( fd_event_get(conn->cc_incoming, &ev, &ev_sz, &ev_data) ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1806 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1807 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1808 switch (ev) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1809 case FDEVP_CNX_MSG_RECV: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1810 /* We got one */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1811 *len = ev_sz; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1812 *buf = ev_data; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1813 return 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1814 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1815 case FDEVP_PSM_TIMEOUT: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1816 TRACE_DEBUG(FULL, "Timeout event received"); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1817 return ETIMEDOUT; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1818 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1819 case FDEVP_CNX_EP_CHANGE: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1820 /* We ignore this event */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1821 goto get_next; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1822 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1823 case FDEVP_CNX_ERROR: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1824 TRACE_DEBUG(FULL, "Received ERROR event on the connection"); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1825 return ENOTCONN; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1826 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1827 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1828 TRACE_DEBUG(INFO, "Received unexpected event %d (%s)", ev, fd_pev_str(ev)); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1829 return EINVAL; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1830 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1831 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1832 /* Where the events are sent */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1833 struct fifo * fd_cnx_target_queue(struct cnxctx * conn) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1834 { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1835 struct fifo *q; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1836 CHECK_POSIX_DO( pthread_mutex_lock(&state_lock), { ASSERT(0); } ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1837 q = conn->cc_alt ?: conn->cc_incoming; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1838 CHECK_POSIX_DO( pthread_mutex_unlock(&state_lock), { ASSERT(0); } ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1839 return q; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1840 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1841 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1842 /* Set an alternate FIFO list to send FDEVP_CNX_* events to */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1843 int fd_cnx_recv_setaltfifo(struct cnxctx * conn, struct fifo * alt_fifo) |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1844 { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1845 int ret; |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1846 TRACE_ENTRY( "%p %p", conn, alt_fifo ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1847 CHECK_PARAMS( conn && alt_fifo && conn->cc_incoming ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1848 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1849 /* The magic function does it all */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1850 CHECK_POSIX_DO( pthread_mutex_lock(&state_lock), { ASSERT(0); } ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1851 CHECK_FCT_DO( ret = fd_fifo_move( conn->cc_incoming, alt_fifo, &conn->cc_alt ), ); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1852 CHECK_POSIX_DO( pthread_mutex_unlock(&state_lock), { ASSERT(0); } ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1853 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1854 return ret; |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1855 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1856 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1857 /* Send function when no multi-stream is involved, or sending on stream #0 (send() always use stream 0)*/ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1858 static int send_simple(struct cnxctx * conn, unsigned char * buf, size_t len) |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1859 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1860 ssize_t ret; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1861 size_t sent = 0; |
27
b3a1773e9f46
again, correct was actually %zd
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
26
diff
changeset
|
1862 TRACE_ENTRY("%p %p %zd", conn, buf, len); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1863 do { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1864 if (fd_cnx_teststate(conn, CC_STATUS_TLS)) { |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1865 CHECK_GNUTLS_DO( ret = fd_tls_send_handle_error(conn, conn->cc_tls_para.session, buf + sent, len - sent), ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1866 } else { |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1867 struct iovec iov; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1868 iov.iov_base = buf + sent; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1869 iov.iov_len = len - sent; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1870 CHECK_SYS_DO( ret = fd_cnx_s_sendv(conn, &iov, 1), ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1871 } |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1872 if (ret <= 0) |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1873 return ENOTCONN; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1874 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1875 sent += ret; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1876 } while ( sent < len ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1877 return 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1878 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1879 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1880 /* Send a message -- this is synchronous -- and we assume it's never called by several threads at the same time (on the same conn), so we don't protect. */ |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1881 int fd_cnx_send(struct cnxctx * conn, unsigned char * buf, size_t len) |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
1882 { |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1883 TRACE_ENTRY("%p %p %zd", conn, buf, len); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1884 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1885 CHECK_PARAMS(conn && (conn->cc_socket > 0) && (! fd_cnx_teststate(conn, CC_STATUS_ERROR)) && buf && len); |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1886 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1887 TRACE_DEBUG(FULL, "Sending %zdb %sdata on connection %s", len, fd_cnx_teststate(conn, CC_STATUS_TLS) ? "TLS-protected ":"", conn->cc_id); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1888 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1889 switch (conn->cc_proto) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1890 case IPPROTO_TCP: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1891 CHECK_FCT( send_simple(conn, buf, len) ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1892 break; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1893 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1894 #ifndef DISABLE_SCTP |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1895 case IPPROTO_SCTP: { |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1896 int dtls = fd_cnx_uses_dtls(conn); |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1897 if (!dtls) { |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1898 int stream = 0; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1899 if (conn->cc_sctp_para.unordered) { |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1900 int limit; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1901 if (fd_cnx_teststate(conn, CC_STATUS_TLS)) |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1902 limit = conn->cc_sctp_para.pairs; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1903 else |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1904 limit = conn->cc_sctp_para.str_out; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1905 |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1906 if (limit > 1) { |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1907 conn->cc_sctp_para.next += 1; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1908 conn->cc_sctp_para.next %= limit; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1909 stream = conn->cc_sctp_para.next; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1910 } |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1911 } |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1912 |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1913 if (stream == 0) { |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1914 /* We can use default function, it sends over stream #0 */ |
229
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1915 CHECK_FCT( send_simple(conn, buf, len) ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1916 } else { |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1917 if (!fd_cnx_teststate(conn, CC_STATUS_TLS)) { |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1918 struct iovec iov; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1919 iov.iov_base = buf; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1920 iov.iov_len = len; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1921 |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1922 CHECK_SYS_DO( fd_sctp_sendstrv(conn, stream, &iov, 1), { fd_cnx_markerror(conn); return ENOTCONN; } ); |
229
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1923 } else { |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1924 /* push the data to the appropriate session */ |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1925 ssize_t ret; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1926 size_t sent = 0; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1927 ASSERT(conn->cc_sctp3436_data.array != NULL); |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1928 do { |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1929 CHECK_GNUTLS_DO( ret = fd_tls_send_handle_error(conn, conn->cc_sctp3436_data.array[stream].session, buf + sent, len - sent), ); |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1930 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
|
1931 return ENOTCONN; |
229
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1932 |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1933 sent += ret; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1934 } while ( sent < len ); |
229
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1935 } |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1936 } |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1937 } else { |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1938 /* DTLS */ |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1939 /* Multistream is handled at lower layer in the push/pull function */ |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1181
diff
changeset
|
1940 CHECK_FCT( send_simple(conn, buf, len) ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1941 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1942 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1943 break; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1944 #endif /* DISABLE_SCTP */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1945 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1946 default: |
1099 | 1947 TRACE_DEBUG(INFO, "Unknown protocol: %d", conn->cc_proto); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1948 ASSERT(0); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1949 return ENOTSUP; /* or EINVAL... */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1950 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1951 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1952 return 0; |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
1953 } |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
1954 |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
1955 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1956 /**************************************/ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1957 /* Destruction of connection */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1958 /**************************************/ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1959 |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
1960 /* Destroy a conn structure, and shutdown the socket */ |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
1961 void fd_cnx_destroy(struct cnxctx * conn) |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
1962 { |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1963 TRACE_ENTRY("%p", conn); |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
1964 |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1965 CHECK_PARAMS_DO(conn, return); |
43
2db15632a63d
Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
1966 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1967 fd_cnx_addstate(conn, CC_STATUS_CLOSING); |
155
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1968 |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1969 /* Initiate shutdown of the TLS session(s): call gnutls_bye(WR), then read until error */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1970 if (fd_cnx_teststate(conn, CC_STATUS_TLS)) { |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1971 #ifndef DISABLE_SCTP |
1181
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1972 int dtls = fd_cnx_uses_dtls(conn); |
22de21feec64
Preparing for DTLS support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1180
diff
changeset
|
1973 if ((!dtls) && (conn->cc_sctp_para.pairs > 1)) { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1974 if (! fd_cnx_teststate(conn, CC_STATUS_ERROR )) { |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1975 /* Bye on master session */ |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1976 CHECK_GNUTLS_DO( gnutls_bye(conn->cc_tls_para.session, GNUTLS_SHUT_WR), fd_cnx_markerror(conn) ); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1977 } |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1978 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1979 if (! fd_cnx_teststate(conn, CC_STATUS_ERROR ) ) { |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1980 /* and other stream pairs */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1145
diff
changeset
|
1981 fd_sctp3436_bye(conn); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1982 } |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1983 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1984 if (! fd_cnx_teststate(conn, CC_STATUS_ERROR ) ) { |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1985 /* Now wait for all decipher threads to terminate */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1145
diff
changeset
|
1986 fd_sctp3436_waitthreadsterm(conn); |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1987 } else { |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1988 /* Abord the threads, the connection is dead already */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1145
diff
changeset
|
1989 fd_sctp3436_stopthreads(conn); |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1990 } |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1991 |
155
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1992 /* Deinit gnutls resources */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1145
diff
changeset
|
1993 fd_sctp3436_gnutls_deinit_others(conn); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1994 if (conn->cc_tls_para.session) { |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1995 GNUTLS_TRACE( gnutls_deinit(conn->cc_tls_para.session) ); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1996 conn->cc_tls_para.session = NULL; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1997 } |
155
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1998 |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1999 /* Destroy the wrapper (also stops the demux thread) */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1145
diff
changeset
|
2000 fd_sctp3436_destroy(conn); |
155
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
2001 |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
2002 } else { |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
2003 #endif /* DISABLE_SCTP */ |
1180
773498f59520
Preparing for future DTLS/SCTP support
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1145
diff
changeset
|
2004 /* We are TLS, but not using the sctp3436 wrapper layer */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
2005 if (! fd_cnx_teststate(conn, CC_STATUS_ERROR ) ) { |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
2006 /* Master session */ |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
2007 CHECK_GNUTLS_DO( gnutls_bye(conn->cc_tls_para.session, GNUTLS_SHUT_WR), fd_cnx_markerror(conn) ); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
2008 } |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
2009 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
2010 if (! fd_cnx_teststate(conn, CC_STATUS_ERROR ) ) { |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
2011 /* In this case, just wait for thread rcvthr_tls_single to terminate */ |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
2012 if (conn->cc_rcvthr != (pthread_t)NULL) { |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
2013 CHECK_POSIX_DO( pthread_join(conn->cc_rcvthr, NULL), /* continue */ ); |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
2014 conn->cc_rcvthr = (pthread_t)NULL; |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
2015 } |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
2016 } else { |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
2017 /* Cancel the receiver thread in case it did not already terminate */ |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
2018 CHECK_FCT_DO( fd_thr_term(&conn->cc_rcvthr), /* continue */ ); |
155
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
2019 } |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
2020 |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
2021 /* Free the resources of the TLS session */ |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
2022 if (conn->cc_tls_para.session) { |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
2023 GNUTLS_TRACE( gnutls_deinit(conn->cc_tls_para.session) ); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
2024 conn->cc_tls_para.session = NULL; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
2025 } |
155
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
2026 #ifndef DISABLE_SCTP |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
2027 } |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
2028 #endif /* DISABLE_SCTP */ |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
2029 } |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
2030 |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
2031 /* Terminate the thread in case it is not done yet -- is there any such case left ?*/ |
155
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
2032 CHECK_FCT_DO( fd_thr_term(&conn->cc_rcvthr), /* continue */ ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
2033 |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
2034 /* Shut the connection down */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
2035 if (conn->cc_socket > 0) { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
2036 shutdown(conn->cc_socket, SHUT_RDWR); |
38
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
31
diff
changeset
|
2037 close(conn->cc_socket); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
31
diff
changeset
|
2038 conn->cc_socket = -1; |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
2039 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
2040 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
2041 /* Empty and destroy FIFO list */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
2042 if (conn->cc_incoming) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
2043 fd_event_destroy( &conn->cc_incoming, free ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
2044 } |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
2045 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
2046 /* Free the object */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
2047 free(conn); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
2048 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
2049 /* Done! */ |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
2050 return; |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
2051 } |