Mercurial > hg > freeDiameter
annotate libfdcore/cnxctx.c @ 896:b13359ace625
Condition the use of sctps_ctx with #ifndef DISABLE_SCTP
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Fri, 30 Nov 2012 23:04:16 +0100 |
parents | 43fb27a9037f |
children | 8bb4d749ed37 5d9229144cac |
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 * * |
808
c0a88c1bcc1e
Updated copyright information
Sebastien Decugis <sdecugis@freediameter.net>
parents:
807
diff
changeset
|
5 * Copyright (c) 2012, 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 */ |
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
|
41 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
42 /* 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
|
43 #ifndef DIAMETER_MSG_SIZE_MAX |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
44 #define DIAMETER_MSG_SIZE_MAX 65535 /* in bytes */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
45 #endif /* DIAMETER_MSG_SIZE_MAX */ |
20
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
46 |
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
|
47 |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
48 /* 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
|
49 * 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
|
50 * 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
|
51 */ |
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 /* Lifetime of a cnxctx object: |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
54 * 1) Creation |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
55 * a) a server socket: |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
56 * - 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
|
57 * - start listening incoming connections: fd_cnx_serv_listen |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
58 * - accept new clients with fd_cnx_serv_accept. |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
59 * b) a client socket: |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
60 * - 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
|
61 * |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
62 * 2) Initialization |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
63 * - if TLS is started first, call fd_cnx_handshake |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
64 * - 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
|
65 * |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
66 * 3) Usage |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
67 * - 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
|
68 * - 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
|
69 * - 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
|
70 * - 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
|
71 * - 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
|
72 * |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
73 * 4) End |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
74 * - fd_cnx_destroy |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
75 */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
76 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
77 /*******************************************/ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
78 /* Creation of a connection object */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
79 /*******************************************/ |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
80 |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
81 /* Initialize a context structure */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
82 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
|
83 { |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
84 struct cnxctx * conn = NULL; |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
85 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
86 TRACE_ENTRY("%d", full); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
87 |
20
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
88 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
|
89 memset(conn, 0, sizeof(struct cnxctx)); |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
90 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
91 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
|
92 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
|
93 } |
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 return conn; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
96 } |
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 /* 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
|
99 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
|
100 { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
101 struct cnxctx * cnx = NULL; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
102 sSS dummy; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
103 sSA * sa = (sSA *) &dummy; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
104 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
105 TRACE_ENTRY("%hu %d %p", port, family, ep); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
106 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
107 CHECK_PARAMS_DO( port, return NULL ); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
108 CHECK_PARAMS_DO( ep || family, return NULL ); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
109 CHECK_PARAMS_DO( (! family) || (family == AF_INET) || (family == AF_INET6), return NULL ); |
730 | 110 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
|
111 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
|
112 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
113 /* The connection object */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
114 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
|
115 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
116 /* Prepare the socket address information */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
117 if (ep) { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
118 memcpy(sa, &ep->ss, sizeof(sSS)); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
119 } else { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
120 memset(&dummy, 0, sizeof(dummy)); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
121 sa->sa_family = family; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
122 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
123 if (sa->sa_family == AF_INET) { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
124 ((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
|
125 cnx->cc_family = AF_INET; |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
126 } else { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
127 ((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
|
128 cnx->cc_family = AF_INET6; |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
129 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
130 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
131 /* Create the socket */ |
246
6418a188c1b5
getnameinfo is also more sensitive on freeBSD
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
245
diff
changeset
|
132 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
|
133 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
134 /* Generate the name for the connection object */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
135 { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
136 char addrbuf[INET6_ADDRSTRLEN]; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
137 int rc; |
247
f89b5a12d2af
Forgot a couple of getnameinfo
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
246
diff
changeset
|
138 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
|
139 if (rc) |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
140 snprintf(addrbuf, sizeof(addrbuf), "[err:%s]", gai_strerror(rc)); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
141 snprintf(cnx->cc_id, sizeof(cnx->cc_id), "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
|
142 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
143 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
144 cnx->cc_proto = IPPROTO_TCP; |
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 return cnx; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
147 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
148 error: |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
149 fd_cnx_destroy(cnx); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
150 return NULL; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
151 } |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
152 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
153 /* 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
|
154 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
|
155 { |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
156 #ifdef DISABLE_SCTP |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
157 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
|
158 ASSERT(0); |
709
19a9470de77a
Fix a few compilations errors and warnings
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
159 CHECK_FCT_DO( ENOTSUP, ); |
19a9470de77a
Fix a few compilations errors and warnings
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
160 return NULL; |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
161 #else /* DISABLE_SCTP */ |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
162 struct cnxctx * cnx = NULL; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
163 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
164 TRACE_ENTRY("%hu %p", port, ep_list); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
165 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
166 CHECK_PARAMS_DO( port, return NULL ); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
167 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
168 /* The connection object */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
169 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
|
170 |
220
5f2ce627db3c
Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
214
diff
changeset
|
171 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
|
172 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
|
173 } else { |
5f2ce627db3c
Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
214
diff
changeset
|
174 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
|
175 } |
5f2ce627db3c
Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
214
diff
changeset
|
176 |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
177 /* Create the socket */ |
220
5f2ce627db3c
Try to fix the old bug on sctp_getpaddrs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
214
diff
changeset
|
178 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
|
179 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
180 /* Generate the name for the connection object */ |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
181 snprintf(cnx->cc_id, sizeof(cnx->cc_id), "SCTP srv :%hu (%d)", port, cnx->cc_socket); |
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 cnx->cc_proto = IPPROTO_SCTP; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
184 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
185 return cnx; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
186 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
187 error: |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
188 fd_cnx_destroy(cnx); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
189 return NULL; |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
190 #endif /* DISABLE_SCTP */ |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
191 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
192 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
193 /* Allow clients to connect on the server socket */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
194 int fd_cnx_serv_listen(struct cnxctx * conn) |
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 CHECK_PARAMS( conn ); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
197 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
198 switch (conn->cc_proto) { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
199 case IPPROTO_TCP: |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
200 CHECK_FCT(fd_tcp_listen(conn->cc_socket)); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
201 break; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
202 |
23
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
203 #ifndef DISABLE_SCTP |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
204 case IPPROTO_SCTP: |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
205 CHECK_FCT(fd_sctp_listen(conn->cc_socket)); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
206 break; |
23
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
207 #endif /* DISABLE_SCTP */ |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
208 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
209 default: |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
210 CHECK_PARAMS(0); |
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 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
213 return 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 /* 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
|
217 struct cnxctx * fd_cnx_serv_accept(struct cnxctx * serv) |
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 struct cnxctx * cli = NULL; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
220 sSS ss; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
221 socklen_t ss_len = sizeof(ss); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
222 int cli_sock = 0; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
223 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
224 TRACE_ENTRY("%p", serv); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
225 CHECK_PARAMS_DO(serv, return NULL); |
20
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
226 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
227 /* 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
|
228 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
|
229 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
230 if (TRACE_BOOL(INFO)) { |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
231 fd_log_debug("%s : accepted new client [", fd_cnx_getid(serv)); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
232 sSA_DUMP_NODE( &ss, NI_NUMERICHOST ); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
233 fd_log_debug("].\n"); |
20
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
234 } |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
235 |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
236 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
|
237 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
|
238 cli->cc_family = serv->cc_family; |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
239 cli->cc_proto = serv->cc_proto; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
240 |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
241 /* 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
|
242 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
|
243 |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
244 /* Generate the name for the connection object */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
245 { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
246 char addrbuf[INET6_ADDRSTRLEN]; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
247 char portbuf[10]; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
248 int rc; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
249 |
711
f7c665948e0c
Use size returned by accept
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
710
diff
changeset
|
250 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
|
251 if (rc) { |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
252 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
|
253 portbuf[0] = '\0'; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
254 } |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
255 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
256 /* Numeric values for debug... */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
257 snprintf(cli->cc_id, sizeof(cli->cc_id), "%s from [%s]:%s (%d<-%d)", |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
258 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
|
259 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
260 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
261 /* ...Name for log messages */ |
711
f7c665948e0c
Use size returned by accept
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
710
diff
changeset
|
262 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
|
263 if (rc) |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
264 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
|
265 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
266 |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
267 #ifndef DISABLE_SCTP |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
268 /* SCTP-specific handlings */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
269 if (cli->cc_proto == IPPROTO_SCTP) { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
270 /* Retrieve the number of streams */ |
407 | 271 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 | 272 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
|
273 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
|
274 else |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
275 cli->cc_sctp_para.pairs = cli->cc_sctp_para.str_in; |
396 | 276 |
277 TRACE_DEBUG(FULL,"%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
|
278 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
279 #endif /* DISABLE_SCTP */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
280 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
281 return cli; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
282 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
283 |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
284 /* 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
|
285 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
|
286 { |
227
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
287 int sock = 0; |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
288 struct cnxctx * cnx = NULL; |
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 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
293 /* 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
|
294 { |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
295 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
|
296 if (ret != 0) { |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
297 int lvl; |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
298 switch (ret) { |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
299 case ECONNREFUSED: |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
300 |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
301 /* "Normal" errors */ |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
302 lvl = FULL; |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
303 break; |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
304 default: |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
305 lvl = INFO; |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
306 } |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
307 /* Some errors are expected, we log at different level */ |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
308 TRACE_DEBUG( lvl, "fd_tcp_client returned an error: %s", strerror(ret)); |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
309 return NULL; |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
310 } |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
311 } |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
312 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
313 if (TRACE_BOOL(INFO)) { |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
314 fd_log_debug("Connection established to server '"); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
315 sSA_DUMP_NODE_SERV( sa, NI_NUMERICSERV); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
316 fd_log_debug("' (TCP:%d).\n", sock); |
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 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
319 /* 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
|
320 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
|
321 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
322 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
|
323 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
|
324 cnx->cc_proto = IPPROTO_TCP; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
325 |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
326 /* 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
|
327 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
|
328 |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
329 /* Generate the names for the object */ |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
330 { |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
331 char addrbuf[INET6_ADDRSTRLEN]; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
332 char portbuf[10]; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
333 int rc; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
334 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
335 /* Numeric values for debug... */ |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
336 rc = getnameinfo(sa, addrlen, addrbuf, sizeof(addrbuf), portbuf, sizeof(portbuf), NI_NUMERICHOST | NI_NUMERICSERV); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
337 if (rc) { |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
338 snprintf(addrbuf, sizeof(addrbuf), "[err:%s]", gai_strerror(rc)); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
339 portbuf[0] = '\0'; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
340 } |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
341 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
342 snprintf(cnx->cc_id, sizeof(cnx->cc_id), "TCP to [%s]:%s (%d)", addrbuf, portbuf, cnx->cc_socket); |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
343 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
344 /* ...Name for log messages */ |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
345 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
|
346 if (rc) |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
347 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
|
348 } |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
349 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
350 return cnx; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
351 } |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
352 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
353 /* 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
|
354 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
|
355 { |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
356 #ifdef DISABLE_SCTP |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
357 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
|
358 ASSERT(0); |
709
19a9470de77a
Fix a few compilations errors and warnings
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
359 CHECK_FCT_DO( ENOTSUP, ); |
19a9470de77a
Fix a few compilations errors and warnings
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
706
diff
changeset
|
360 return NULL; |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
361 #else /* DISABLE_SCTP */ |
227
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
362 int sock = 0; |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
363 struct cnxctx * cnx = NULL; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
364 sSS primary; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
365 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
366 TRACE_ENTRY("%p", list); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
367 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
|
368 |
227
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
369 { |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
370 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
|
371 if (ret != 0) { |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
372 int lvl; |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
373 switch (ret) { |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
374 case ECONNREFUSED: |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
375 |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
376 /* "Normal" errors */ |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
377 lvl = FULL; |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
378 break; |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
379 default: |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
380 lvl = INFO; |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
381 } |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
382 /* Some errors are expected, we log at different level */ |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
383 TRACE_DEBUG( lvl, "fd_sctp_client returned an error: %s", strerror(ret)); |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
384 return NULL; |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
385 } |
80a7e65167c4
Cleanup verbosity and fix unintialized variable
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
223
diff
changeset
|
386 } |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
387 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
388 /* 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
|
389 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
|
390 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
391 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
|
392 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
|
393 cnx->cc_proto = IPPROTO_SCTP; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
394 |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
395 /* 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
|
396 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
|
397 |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
398 /* 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
|
399 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
|
400 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
|
401 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
|
402 else |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
403 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
|
404 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
405 if (TRACE_BOOL(INFO)) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
406 fd_log_debug("Connection established to server '"); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
407 sSA_DUMP_NODE_SERV( &primary, NI_NUMERICSERV); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
408 fd_log_debug("' (SCTP:%d, %d/%d streams).\n", sock, cnx->cc_sctp_para.str_in, cnx->cc_sctp_para.str_out); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
409 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
410 |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
411 /* Generate the names for the object */ |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
412 { |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
413 char addrbuf[INET6_ADDRSTRLEN]; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
414 char portbuf[10]; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
415 int rc; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
416 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
417 /* Numeric values for debug... */ |
247
f89b5a12d2af
Forgot a couple of getnameinfo
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
246
diff
changeset
|
418 rc = getnameinfo((sSA *)&primary, sSAlen(&primary), 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
|
419 if (rc) { |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
420 snprintf(addrbuf, sizeof(addrbuf), "[err:%s]", gai_strerror(rc)); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
421 portbuf[0] = '\0'; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
422 } |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
423 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
424 snprintf(cnx->cc_id, sizeof(cnx->cc_id), "SCTP to [%s]:%s (%d)", addrbuf, portbuf, cnx->cc_socket); |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
425 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
426 /* ...Name for log messages */ |
247
f89b5a12d2af
Forgot a couple of getnameinfo
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
246
diff
changeset
|
427 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
|
428 if (rc) |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
429 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
|
430 } |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
431 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
432 return cnx; |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
433 |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
434 error: |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
435 fd_cnx_destroy(cnx); |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
436 return NULL; |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
437 #endif /* DISABLE_SCTP */ |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
438 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
439 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
440 /* Return a string describing the connection, for debug */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
441 char * fd_cnx_getid(struct cnxctx * conn) |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
442 { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
443 CHECK_PARAMS_DO( conn, return "" ); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
444 return conn->cc_id; |
20
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
445 } |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
446 |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
447 /* 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
|
448 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
|
449 { |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
450 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
|
451 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
|
452 } |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
453 |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
454 /* 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
|
455 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
|
456 { |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
457 CHECK_PARAMS_DO( conn, return ); |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
458 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
|
459 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
460 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
461 /* 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
|
462 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
|
463 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
|
464 { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
465 uint32_t st; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
466 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
|
467 st = conn->cc_state; |
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 return st; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
470 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
471 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
|
472 { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
473 uint32_t st; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
474 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
|
475 st = conn->cc_state; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
476 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
|
477 return st & flag; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
478 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
479 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
|
480 { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
481 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
|
482 conn->cc_state |= orstate; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
483 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
|
484 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
485 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
|
486 { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
487 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
|
488 conn->cc_state = abstate; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
489 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
|
490 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
491 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
492 |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
493 /* 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
|
494 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
|
495 { |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
496 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
|
497 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
|
498 } |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
499 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
500 /* Return true if the connection supports unordered delivery of messages */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
501 int fd_cnx_isMultichan(struct cnxctx * conn) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
502 { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
503 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
|
504 #ifndef DISABLE_SCTP |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
505 if (conn->cc_proto == IPPROTO_SCTP) |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
506 return (conn->cc_sctp_para.str_in > 1) || (conn->cc_sctp_para.str_out > 1); |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
507 #endif /* DISABLE_SCTP */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
508 return 0; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
509 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
510 |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
511 |
23
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
512 /* 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
|
513 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
|
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 TRACE_ENTRY("%p %p %p", conn, 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
|
516 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
|
517 |
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
|
518 /* 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
|
519 CHECK_PARAMS( conn->cc_incoming ); |
23
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
520 |
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
|
521 /* 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
|
522 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
|
523 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
|
524 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
|
525 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
|
526 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
|
527 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
|
528 } |
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
|
529 break; |
23
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
530 |
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
|
531 #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
|
532 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
|
533 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
|
534 } |
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
|
535 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
|
536 #endif /* DISABLE_SCTP */ |
23
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
537 |
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
|
538 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
|
539 CHECK_PARAMS(0); |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
540 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
541 |
23
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
542 return 0; |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
543 } |
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 /* 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
|
546 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
|
547 { |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
548 CHECK_PARAMS_DO( conn, return "" ); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
549 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
|
550 } |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
551 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
552 /* 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
|
553 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
|
554 { |
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
|
555 struct ifaddrs *iflist, *cur; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
556 |
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
|
557 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
|
558 |
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
|
559 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
|
560 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
|
561 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
|
562 |
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 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
|
564 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
|
565 |
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
|
566 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
|
567 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
|
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 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
|
570 } |
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 |
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 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
|
573 |
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
|
574 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
|
575 } |
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 |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
577 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
578 /**************************************/ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
579 /* Use of a connection object */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
580 /**************************************/ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
581 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
582 /* An error occurred on the socket */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
583 void fd_cnx_markerror(struct cnxctx * conn) |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
584 { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
585 TRACE_ENTRY("%p", conn); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
586 CHECK_PARAMS_DO( conn, goto fatal ); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
587 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
588 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
|
589 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
590 /* Mark the error */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
591 fd_cnx_addstate(conn, CC_STATUS_ERROR); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
592 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
593 /* 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
|
594 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
|
595 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
|
596 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
|
597 fd_cnx_addstate(conn, CC_STATUS_SIGNALED); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
598 } |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
599 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
600 return; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
601 fatal: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
602 /* 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
|
603 ASSERT(0); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
604 CHECK_FCT_DO(fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, 0, NULL), ); |
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 |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
607 /* 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
|
608 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
|
609 { |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
610 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
|
611 |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
612 /* 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
|
613 memset(&tv, 0, sizeof(tv)); |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
614 tv.tv_sec = 3; /* allow 3 seconds timeout for TLS session cleanup */ |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
615 CHECK_SYS_DO( setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)), /* best effort only */ ); |
201
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
616 CHECK_SYS_DO( setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)), /* Also timeout for sending, to avoid waiting forever */ ); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
617 } |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
618 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
619 /* 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
|
620 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
|
621 { |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
622 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
|
623 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
|
624 again: |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
625 ret = recv(conn->cc_socket, buffer, length, 0); |
710 | 626 /* Handle special case of timeout / interrupts */ |
627 if ((ret < 0) && ((errno == EAGAIN) || (errno == EINTR))) { | |
628 pthread_testcancel(); | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
629 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
|
630 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
|
631 if (!timedout) { |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
632 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
|
633 goto again; |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
634 } |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
635 } |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
636 |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
637 /* Mark the error */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
638 if (ret <= 0) { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
639 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
|
640 fd_cnx_markerror(conn); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
641 } |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
642 |
894
43fb27a9037f
Intrumented socket reception to store the timestamp along the received buffer
Sebastien Decugis <sdecugis@freediameter.net>
parents:
816
diff
changeset
|
643 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &conn->cc_tls_para.recvon), /* continue */ ); |
43fb27a9037f
Intrumented socket reception to store the timestamp along the received buffer
Sebastien Decugis <sdecugis@freediameter.net>
parents:
816
diff
changeset
|
644 |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
645 return ret; |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
646 } |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
647 |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
648 /* Send */ |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
649 static ssize_t fd_cnx_s_send(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
|
650 { |
201
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
651 ssize_t ret = 0; |
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
652 int timedout = 0; |
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
653 again: |
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
654 ret = send(conn->cc_socket, buffer, length, 0); |
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
655 /* Handle special case of timeout */ |
710 | 656 if ((ret < 0) && ((errno == EAGAIN) || (errno == EINTR))) { |
657 pthread_testcancel(); | |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
658 if (! fd_cnx_teststate(conn, CC_STATUS_CLOSING )) |
201
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
659 goto again; /* don't care, just ignore */ |
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
660 if (!timedout) { |
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
661 timedout ++; /* allow for one timeout while closing */ |
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
662 goto again; |
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
663 } |
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
664 CHECK_SYS_DO(ret, /* continue */); |
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
665 } |
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
666 |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
667 /* Mark the error */ |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
668 if (ret <= 0) |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
669 fd_cnx_markerror(conn); |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
670 |
201
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
671 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
|
672 } |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
673 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
674 /* 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
|
675 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
|
676 { |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
677 struct cnxctx * conn = arg; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
678 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
679 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
|
680 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
|
681 |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
682 /* 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
|
683 { |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
684 char buf[48]; |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
685 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
|
686 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
|
687 } |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
688 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
689 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
|
690 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
|
691 ASSERT( fd_cnx_target_queue(conn) ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
692 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
693 /* 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
|
694 do { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
695 uint8_t header[4]; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
696 uint8_t * newmsg; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
697 size_t length; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
698 ssize_t ret = 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
699 size_t received = 0; |
894
43fb27a9037f
Intrumented socket reception to store the timestamp along the received buffer
Sebastien Decugis <sdecugis@freediameter.net>
parents:
816
diff
changeset
|
700 struct timespec recv_on; |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
701 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
702 do { |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
703 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
|
704 if (ret <= 0) { |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
705 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
|
706 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
707 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
708 received += ret; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
709 } while (received < sizeof(header)); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
710 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
711 length = ((size_t)header[1] << 16) + ((size_t)header[2] << 8) + (size_t)header[3]; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
712 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
713 /* 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
|
714 if ((header[0] != DIAMETER_VERSION) /* defined in <libfdproto.h> */ |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
715 || (length > DIAMETER_MSG_SIZE_MAX)) { /* to avoid too big mallocs */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
716 /* The message is suspect */ |
27
b3a1773e9f46
again, correct was actually %zd
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
26
diff
changeset
|
717 TRACE_DEBUG(INFO, "Received suspect header [ver: %d, size: %zd], assume disconnection", (int)header[0], length); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
718 fd_cnx_markerror(conn); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
719 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
|
720 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
721 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
722 /* Ok, now we can really receive the data */ |
894
43fb27a9037f
Intrumented socket reception to store the timestamp along the received buffer
Sebastien Decugis <sdecugis@freediameter.net>
parents:
816
diff
changeset
|
723 CHECK_MALLOC_DO( newmsg = malloc( length + sizeof(struct timespec) ), goto fatal ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
724 memcpy(newmsg, header, sizeof(header)); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
725 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
726 while (received < length) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
727 pthread_cleanup_push(free, newmsg); /* In case we are canceled, clean the partialy built buffer */ |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
728 ret = fd_cnx_s_recv(conn, newmsg + received, length - received); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
729 pthread_cleanup_pop(0); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
730 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
731 if (ret <= 0) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
732 free(newmsg); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
733 goto out; |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
734 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
735 received += ret; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
736 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
737 |
894
43fb27a9037f
Intrumented socket reception to store the timestamp along the received buffer
Sebastien Decugis <sdecugis@freediameter.net>
parents:
816
diff
changeset
|
738 /* Piggy-tail the timestamp of reception */ |
43fb27a9037f
Intrumented socket reception to store the timestamp along the received buffer
Sebastien Decugis <sdecugis@freediameter.net>
parents:
816
diff
changeset
|
739 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &recv_on), /* continue */ ); |
43fb27a9037f
Intrumented socket reception to store the timestamp along the received buffer
Sebastien Decugis <sdecugis@freediameter.net>
parents:
816
diff
changeset
|
740 memcpy(newmsg + length, &recv_on, sizeof(struct timespec)); |
43fb27a9037f
Intrumented socket reception to store the timestamp along the received buffer
Sebastien Decugis <sdecugis@freediameter.net>
parents:
816
diff
changeset
|
741 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
742 /* We have received a complete message, pass it to the daemon */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
743 CHECK_FCT_DO( fd_event_send( fd_cnx_target_queue(conn), FDEVP_CNX_MSG_RECV, length, newmsg), /* continue or destroy everything? */); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
744 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
745 } while (conn->cc_loop); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
746 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
747 out: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
748 TRACE_DEBUG(FULL, "Thread terminated"); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
749 return NULL; |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
750 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
751 fatal: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
752 /* An unrecoverable error occurred, stop the daemon */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
753 CHECK_FCT_DO(fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, 0, NULL), ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
754 goto out; |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
755 } |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
756 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
757 #ifndef DISABLE_SCTP |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
758 /* 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
|
759 static void * rcvthr_notls_sctp(void * arg) |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
760 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
761 struct cnxctx * conn = arg; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
762 uint8_t * buf; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
763 size_t bufsz; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
764 int event; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
765 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
766 TRACE_ENTRY("%p", arg); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
767 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
|
768 |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
769 /* 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
|
770 { |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
771 char buf[48]; |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
772 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
|
773 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
|
774 } |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
775 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
776 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
|
777 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
|
778 ASSERT( fd_cnx_target_queue(conn) ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
779 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
780 do { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
781 CHECK_FCT_DO( fd_sctp_recvmeta(conn, NULL, &buf, &bufsz, &event), goto fatal ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
782 if (event == FDEVP_CNX_ERROR) { |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
783 fd_cnx_markerror(conn); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
784 goto out; |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
785 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
786 |
228 | 787 if (event == FDEVP_CNX_SHUTDOWN) { |
788 /* Just ignore the notification for now, we will get another error later anyway */ | |
789 continue; | |
790 } | |
894
43fb27a9037f
Intrumented socket reception to store the timestamp along the received buffer
Sebastien Decugis <sdecugis@freediameter.net>
parents:
816
diff
changeset
|
791 /* Note: the real size of buf is bufsz + struct timespec */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
792 CHECK_FCT_DO( fd_event_send( fd_cnx_target_queue(conn), event, bufsz, buf), goto fatal ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
793 |
250
07624e65c7e0
Loop anyway until we get a real message or an error
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
247
diff
changeset
|
794 } 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
|
795 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
796 out: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
797 TRACE_DEBUG(FULL, "Thread terminated"); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
798 return NULL; |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
799 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
800 fatal: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
801 /* An unrecoverable error occurred, stop the daemon */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
802 CHECK_FCT_DO(fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, 0, NULL), ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
803 goto out; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
804 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
805 #endif /* DISABLE_SCTP */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
806 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
807 /* 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
|
808 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
|
809 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
810 TRACE_ENTRY("%p %i", conn, loop); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
811 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
812 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
|
813 |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
814 /* 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
|
815 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
|
816 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
817 /* Save the loop request */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
818 conn->cc_loop = loop; |
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 switch (conn->cc_proto) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
821 case IPPROTO_TCP: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
822 /* Start the tcp_notls thread */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
823 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
|
824 break; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
825 #ifndef DISABLE_SCTP |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
826 case IPPROTO_SCTP: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
827 /* Start the tcp_notls thread */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
828 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
|
829 break; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
830 #endif /* DISABLE_SCTP */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
831 default: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
832 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
|
833 ASSERT(0); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
834 return ENOTSUP; |
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 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
837 return 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
838 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
839 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
840 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
841 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
842 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
843 /* Returns 0 on error, received data size otherwise (always >= 0) */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
844 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
|
845 { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
846 ssize_t ret; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
847 again: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
848 CHECK_GNUTLS_DO( ret = gnutls_record_recv(session, data, sz), |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
849 { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
850 switch (ret) { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
851 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
|
852 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
|
853 CHECK_GNUTLS_DO( ret = gnutls_handshake(session), |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
854 { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
855 if (TRACE_BOOL(INFO)) { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
856 fd_log_debug("TLS re-handshake failed on socket %d (%s) : %s\n", conn->cc_socket, conn->cc_id, gnutls_strerror(ret)); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
857 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
858 goto end; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
859 } ); |
803
d5a4b5e175c2
Add timeout in gnutls_handshake for version 3.1.x
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
767
diff
changeset
|
860 } |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
861 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
862 case GNUTLS_E_AGAIN: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
863 case GNUTLS_E_INTERRUPTED: |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
864 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
|
865 goto again; |
228 | 866 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
|
867 break; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
868 |
228 | 869 case GNUTLS_E_UNEXPECTED_PACKET_LENGTH: |
870 /* The connection is closed */ | |
871 TRACE_DEBUG(FULL, "Got 0 size while reading the socket, probably connection closed..."); | |
872 break; | |
873 | |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
874 default: |
228 | 875 TRACE_DEBUG(INFO, "This GNU TLS error is not handled, assume unrecoverable error"); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
876 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
877 } ); |
251
52c1547dab42
Call gnutls_bye on closing connection
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
250
diff
changeset
|
878 |
52c1547dab42
Call gnutls_bye on closing connection
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
250
diff
changeset
|
879 if (ret == 0) |
52c1547dab42
Call gnutls_bye on closing connection
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
250
diff
changeset
|
880 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
|
881 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
882 end: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
883 if (ret <= 0) |
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 return ret; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
886 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
887 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
888 /* Wrapper around gnutls_record_send to handle some error codes */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
889 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
|
890 { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
891 ssize_t ret; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
892 again: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
893 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
|
894 { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
895 switch (ret) { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
896 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
|
897 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
|
898 CHECK_GNUTLS_DO( ret = gnutls_handshake(session), |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
899 { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
900 if (TRACE_BOOL(INFO)) { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
901 fd_log_debug("TLS re-handshake failed on socket %d (%s) : %s\n", conn->cc_socket, conn->cc_id, gnutls_strerror(ret)); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
902 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
903 goto end; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
904 } ); |
803
d5a4b5e175c2
Add timeout in gnutls_handshake for version 3.1.x
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
767
diff
changeset
|
905 } |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
906 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
907 case GNUTLS_E_AGAIN: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
908 case GNUTLS_E_INTERRUPTED: |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
909 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
|
910 goto again; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
911 TRACE_DEBUG(INFO, "Connection is closing, so abord gnutls_record_send now."); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
912 break; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
913 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
914 default: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
915 TRACE_DEBUG(INFO, "This TLS error is not handled, assume unrecoverable error"); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
916 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
917 } ); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
918 end: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
919 if (ret <= 0) |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
920 fd_cnx_markerror(conn); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
921 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
922 return ret; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
923 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
924 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
925 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
926 /* The function that receives TLS data and re-builds a Diameter message -- it exits only on error or cancelation */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
927 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
|
928 { |
896
b13359ace625
Condition the use of sctps_ctx with #ifndef DISABLE_SCTP
Sebastien Decugis <sdecugis@freediameter.net>
parents:
894
diff
changeset
|
929 struct timespec * rcv_on = &conn->cc_tls_para.recvon; |
894
43fb27a9037f
Intrumented socket reception to store the timestamp along the received buffer
Sebastien Decugis <sdecugis@freediameter.net>
parents:
816
diff
changeset
|
930 |
896
b13359ace625
Condition the use of sctps_ctx with #ifndef DISABLE_SCTP
Sebastien Decugis <sdecugis@freediameter.net>
parents:
894
diff
changeset
|
931 #ifndef DISABLE_SCTP |
894
43fb27a9037f
Intrumented socket reception to store the timestamp along the received buffer
Sebastien Decugis <sdecugis@freediameter.net>
parents:
816
diff
changeset
|
932 void * ptr = gnutls_transport_get_ptr(session); |
896
b13359ace625
Condition the use of sctps_ctx with #ifndef DISABLE_SCTP
Sebastien Decugis <sdecugis@freediameter.net>
parents:
894
diff
changeset
|
933 if (ptr != conn) { |
894
43fb27a9037f
Intrumented socket reception to store the timestamp along the received buffer
Sebastien Decugis <sdecugis@freediameter.net>
parents:
816
diff
changeset
|
934 struct sctps_ctx * ctx = (struct sctps_ctx *) ptr; |
43fb27a9037f
Intrumented socket reception to store the timestamp along the received buffer
Sebastien Decugis <sdecugis@freediameter.net>
parents:
816
diff
changeset
|
935 rcv_on = &ctx->recvon; |
43fb27a9037f
Intrumented socket reception to store the timestamp along the received buffer
Sebastien Decugis <sdecugis@freediameter.net>
parents:
816
diff
changeset
|
936 } |
896
b13359ace625
Condition the use of sctps_ctx with #ifndef DISABLE_SCTP
Sebastien Decugis <sdecugis@freediameter.net>
parents:
894
diff
changeset
|
937 #endif /* DISABLE_SCTP */ |
894
43fb27a9037f
Intrumented socket reception to store the timestamp along the received buffer
Sebastien Decugis <sdecugis@freediameter.net>
parents:
816
diff
changeset
|
938 |
43fb27a9037f
Intrumented socket reception to store the timestamp along the received buffer
Sebastien Decugis <sdecugis@freediameter.net>
parents:
816
diff
changeset
|
939 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
940 /* No guarantee that GnuTLS preserves the message boundaries, so we re-build it as in TCP */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
941 do { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
942 uint8_t header[4]; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
943 uint8_t * newmsg; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
944 size_t length; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
945 ssize_t ret = 0; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
946 size_t received = 0; |
894
43fb27a9037f
Intrumented socket reception to store the timestamp along the received buffer
Sebastien Decugis <sdecugis@freediameter.net>
parents:
816
diff
changeset
|
947 struct timespec recv_on; |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
948 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
949 do { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
950 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
|
951 if (ret <= 0) { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
952 /* The connection is closed */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
953 goto out; |
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 received += ret; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
956 } while (received < sizeof(header)); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
957 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
958 length = ((size_t)header[1] << 16) + ((size_t)header[2] << 8) + (size_t)header[3]; |
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 /* 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
|
961 if ((header[0] != DIAMETER_VERSION) /* defined in <libfreeDiameter.h> */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
962 || (length > DIAMETER_MSG_SIZE_MAX)) { /* to avoid too big mallocs */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
963 /* The message is suspect */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
964 TRACE_DEBUG(INFO, "Received suspect header [ver: %d, size: %zd], assume disconnection", (int)header[0], length); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
965 fd_cnx_markerror(conn); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
966 goto out; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
967 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
968 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
969 /* Ok, now we can really receive the data */ |
894
43fb27a9037f
Intrumented socket reception to store the timestamp along the received buffer
Sebastien Decugis <sdecugis@freediameter.net>
parents:
816
diff
changeset
|
970 CHECK_MALLOC( newmsg = malloc( length + sizeof(struct timespec)) ); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
971 memcpy(newmsg, header, sizeof(header)); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
972 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
973 while (received < length) { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
974 pthread_cleanup_push(free, newmsg); /* In case we are canceled, clean the partialy built buffer */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
975 ret = fd_tls_recv_handle_error(conn, session, newmsg + received, length - received); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
976 pthread_cleanup_pop(0); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
977 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
978 if (ret <= 0) { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
979 free(newmsg); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
980 goto out; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
981 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
982 received += ret; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
983 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
984 |
894
43fb27a9037f
Intrumented socket reception to store the timestamp along the received buffer
Sebastien Decugis <sdecugis@freediameter.net>
parents:
816
diff
changeset
|
985 /* The timestamp of the last TLS chunk received for this rebuilt message lives close to the session pointer, we piggyback it */ |
43fb27a9037f
Intrumented socket reception to store the timestamp along the received buffer
Sebastien Decugis <sdecugis@freediameter.net>
parents:
816
diff
changeset
|
986 memcpy(newmsg + length, rcv_on, sizeof(struct timespec)); |
43fb27a9037f
Intrumented socket reception to store the timestamp along the received buffer
Sebastien Decugis <sdecugis@freediameter.net>
parents:
816
diff
changeset
|
987 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
988 /* We have received a complete message, pass it to the daemon */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
989 CHECK_FCT_DO( ret = fd_event_send( fd_cnx_target_queue(conn), FDEVP_CNX_MSG_RECV, length, newmsg), |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
990 { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
991 free(newmsg); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
992 CHECK_FCT_DO(fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, 0, NULL), ); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
993 return ret; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
994 } ); |
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 } while (1); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
997 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
998 out: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
999 return ENOTCONN; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1000 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1001 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1002 /* Receiver thread (TLS & 1 stream SCTP or TCP) */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1003 static void * rcvthr_tls_single(void * arg) |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1004 { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1005 struct cnxctx * conn = arg; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1006 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1007 TRACE_ENTRY("%p", arg); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1008 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
|
1009 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1010 /* Set the thread name */ |
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 char buf[48]; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1013 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
|
1014 fd_log_threadname ( buf ); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1015 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1016 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1017 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
|
1018 ASSERT( fd_cnx_target_queue(conn) ); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1019 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1020 /* 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
|
1021 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
|
1022 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1023 TRACE_DEBUG(FULL, "Thread terminated"); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1024 return NULL; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1025 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1026 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1027 /* Prepare a gnutls session object for handshake */ |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
1028 int fd_tls_prepare(gnutls_session_t * session, int mode, char * priority, void * alt_creds) |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1029 { |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1030 /* Create the session context */ |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1031 CHECK_GNUTLS_DO( gnutls_init (session, mode), return ENOMEM ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1032 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1033 /* Set the algorithm suite */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1034 if (priority) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1035 const char * errorpos; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1036 CHECK_GNUTLS_DO( gnutls_priority_set_direct( *session, priority, &errorpos ), |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1037 { TRACE_DEBUG(INFO, "Error in priority string '%s' at position: '%s'\n", priority, errorpos); return EINVAL; } ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1038 } else { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1039 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
|
1040 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1041 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1042 /* 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
|
1043 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
|
1044 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1045 /* Request the remote credentials as well */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1046 if (mode == GNUTLS_SERVER) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1047 gnutls_certificate_server_set_request (*session, GNUTLS_CERT_REQUIRE); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1048 } |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1049 |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1050 return 0; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1051 } |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
1052 |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1053 #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
|
1054 |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1055 /* 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
|
1056 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
|
1057 { |
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
|
1058 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
|
1059 unsigned int gtret; |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1060 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
|
1061 unsigned int cert_list_size; |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1062 gnutls_x509_crt_t cert; |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1063 time_t now; |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1064 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1065 TRACE_ENTRY("%p %d", conn, verbose); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1066 CHECK_PARAMS(conn); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1067 |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1068 /* Trace the session information -- http://www.gnu.org/software/gnutls/manual/gnutls.html#Obtaining-session-information */ |
59
067ab3fc6093
Cleanups in debug messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
57
diff
changeset
|
1069 if (verbose && TRACE_BOOL(FULL)) { |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1070 const char *tmp; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1071 gnutls_kx_algorithm_t kx; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1072 gnutls_credentials_type_t cred; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1073 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1074 fd_log_debug("TLS Session information for connection '%s':\n", conn->cc_id); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1075 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1076 /* 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
|
1077 GNUTLS_TRACE( kx = gnutls_kx_get (session) ); |
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1078 GNUTLS_TRACE( tmp = gnutls_kx_get_name (kx) ); |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1079 fd_log_debug("\t - Key Exchange: %s\n", tmp); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1080 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1081 /* Check the authentication type used and switch |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1082 * to the appropriate. */ |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1083 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
|
1084 switch (cred) |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1085 { |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1086 case GNUTLS_CRD_IA: |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1087 fd_log_debug("\t - TLS/IA session\n"); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1088 break; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1089 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1090 case GNUTLS_CRD_PSK: |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1091 /* This returns NULL in server side. */ |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1092 if (gnutls_psk_client_get_hint (session) != NULL) |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1093 fd_log_debug("\t - PSK authentication. PSK hint '%s'\n", |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1094 gnutls_psk_client_get_hint (session)); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1095 /* This returns NULL in client side. */ |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1096 if (gnutls_psk_server_get_username (session) != NULL) |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1097 fd_log_debug("\t - PSK authentication. Connected as '%s'\n", |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1098 gnutls_psk_server_get_username (session)); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1099 break; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1100 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1101 case GNUTLS_CRD_ANON: /* anonymous authentication */ |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1102 fd_log_debug("\t - Anonymous DH using prime of %d bits\n", |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1103 gnutls_dh_get_prime_bits (session)); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1104 break; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1105 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1106 case GNUTLS_CRD_CERTIFICATE: /* certificate authentication */ |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1107 /* 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
|
1108 if (kx == GNUTLS_KX_DHE_RSA || kx == GNUTLS_KX_DHE_DSS) { |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1109 fd_log_debug("\t - Ephemeral DH using prime of %d bits\n", |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1110 gnutls_dh_get_prime_bits (session)); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1111 } |
403
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
402
diff
changeset
|
1112 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
|
1113 #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
|
1114 case GNUTLS_CRD_SRP: |
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
402
diff
changeset
|
1115 fd_log_debug("\t - SRP session with username %s\n", |
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
402
diff
changeset
|
1116 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
|
1117 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
|
1118 #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
|
1119 |
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
402
diff
changeset
|
1120 default: |
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
402
diff
changeset
|
1121 fd_log_debug("\t - Different type of credentials for the session (%d).\n", cred); |
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
402
diff
changeset
|
1122 break; |
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
402
diff
changeset
|
1123 |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1124 } |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1125 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1126 /* 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
|
1127 tmp = gnutls_protocol_get_name (gnutls_protocol_get_version (session)); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1128 fd_log_debug("\t - Protocol: %s\n", tmp); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1129 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1130 /* 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
|
1131 tmp = gnutls_certificate_type_get_name (gnutls_certificate_type_get (session)); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1132 fd_log_debug("\t - Certificate Type: %s\n", tmp); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1133 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1134 /* print the compression algorithm (if any) */ |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1135 tmp = gnutls_compression_get_name (gnutls_compression_get (session)); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1136 fd_log_debug("\t - Compression: %s\n", tmp); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1137 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1138 /* 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
|
1139 tmp = gnutls_cipher_get_name (gnutls_cipher_get (session)); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1140 fd_log_debug("\t - Cipher: %s\n", tmp); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1141 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1142 /* Print the MAC algorithms name. ie SHA1 */ |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1143 tmp = gnutls_mac_get_name (gnutls_mac_get (session)); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1144 fd_log_debug("\t - MAC: %s\n", tmp); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1145 } |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1146 |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1147 /* 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
|
1148 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
|
1149 if (gtret) { |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1150 if (TRACE_BOOL(INFO)) { |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1151 fd_log_debug("TLS: Remote certificate invalid on socket %d (Remote: '%s')(Connection: '%s') :\n", 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
|
1152 if (gtret & GNUTLS_CERT_INVALID) |
251
52c1547dab42
Call gnutls_bye on closing connection
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
250
diff
changeset
|
1153 fd_log_debug(" - The certificate is not trusted (unknown CA? expired?)\n"); |
403
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
402
diff
changeset
|
1154 if (gtret & GNUTLS_CERT_REVOKED) |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1155 fd_log_debug(" - The certificate has been revoked.\n"); |
403
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
402
diff
changeset
|
1156 if (gtret & GNUTLS_CERT_SIGNER_NOT_FOUND) |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1157 fd_log_debug(" - The certificate hasn't got a known issuer.\n"); |
403
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
402
diff
changeset
|
1158 if (gtret & GNUTLS_CERT_SIGNER_NOT_CA) |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1159 fd_log_debug(" - The certificate signer is not a CA, or uses version 1, or 3 without basic constraints.\n"); |
403
26aafbbc1640
Cleanup all compilation warnings in base code for 32 bit arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
402
diff
changeset
|
1160 if (gtret & GNUTLS_CERT_INSECURE_ALGORITHM) |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1161 fd_log_debug(" - The certificate signature uses a weak algorithm.\n"); |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1162 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1163 return EINVAL; |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1164 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1165 |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1166 /* 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
|
1167 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
|
1168 return EINVAL; |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1169 |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1170 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
|
1171 if (cert_list == NULL) |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1172 return EINVAL; |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1173 |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1174 now = time(NULL); |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1175 |
59
067ab3fc6093
Cleanups in debug messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
57
diff
changeset
|
1176 if (verbose && TRACE_BOOL(FULL)) { |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1177 char serial[40]; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1178 char dn[128]; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1179 size_t size; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1180 unsigned int algo, bits; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1181 time_t expiration_time, activation_time; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1182 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1183 fd_log_debug("TLS Certificate information for connection '%s' (%d certs provided):\n", conn->cc_id, cert_list_size); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1184 for (i = 0; i < cert_list_size; i++) |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1185 { |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1186 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1187 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
|
1188 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
|
1189 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1190 fd_log_debug(" Certificate %d info:\n", i); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1191 |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1192 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
|
1193 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
|
1194 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1195 fd_log_debug("\t - Certificate is valid since: %s", ctime (&activation_time)); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1196 fd_log_debug("\t - Certificate expires: %s", ctime (&expiration_time)); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1197 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1198 /* Print the serial number of the certificate. */ |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1199 size = sizeof (serial); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1200 gnutls_x509_crt_get_serial (cert, serial, &size); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1201 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1202 fd_log_debug("\t - Certificate serial number: "); |
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 int j; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1205 for (j = 0; j < size; j++) { |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1206 fd_log_debug("%02.2hhx", serial[j]); |
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 } |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1209 fd_log_debug("\n"); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1210 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1211 /* 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
|
1212 GNUTLS_TRACE( algo = gnutls_x509_crt_get_pk_algorithm (cert, &bits) ); |
57 | 1213 fd_log_debug("\t - Certificate public key: %s\n", |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1214 gnutls_pk_algorithm_get_name (algo)); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1215 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1216 /* Print the version of the X.509 certificate. */ |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1217 fd_log_debug("\t - Certificate version: #%d\n", |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1218 gnutls_x509_crt_get_version (cert)); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1219 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1220 size = sizeof (dn); |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1221 GNUTLS_TRACE( gnutls_x509_crt_get_dn (cert, dn, &size) ); |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1222 fd_log_debug("\t - DN: %s\n", dn); |
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 size = sizeof (dn); |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1225 GNUTLS_TRACE( gnutls_x509_crt_get_issuer_dn (cert, dn, &size) ); |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1226 fd_log_debug("\t - Issuer's DN: %s\n", dn); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1227 |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1228 GNUTLS_TRACE( gnutls_x509_crt_deinit (cert) ); |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1229 } |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1230 } |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1231 |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1232 /* 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
|
1233 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
|
1234 { |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1235 time_t deadline; |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1236 |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1237 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
|
1238 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
|
1239 |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1240 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
|
1241 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
|
1242 if (TRACE_BOOL(INFO)) { |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1243 fd_log_debug("TLS: Remote certificate invalid on socket %d (Remote: '%s')(Connection: '%s') :\n", conn->cc_socket, conn->cc_remid, conn->cc_id); |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1244 fd_log_debug(" - The certificate %d in the chain is expired\n", i); |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1245 } |
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
|
1246 ret = EINVAL; |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1247 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1248 |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1249 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
|
1250 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
|
1251 if (TRACE_BOOL(INFO)) { |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1252 fd_log_debug("TLS: Remote certificate invalid on socket %d (Remote: '%s')(Connection: '%s') :\n", conn->cc_socket, conn->cc_remid, conn->cc_id); |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1253 fd_log_debug(" - The certificate %d in the chain is not yet activated\n", i); |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1254 } |
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
|
1255 ret = EINVAL; |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1256 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1257 |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1258 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
|
1259 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
|
1260 if (TRACE_BOOL(INFO)) { |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1261 fd_log_debug("TLS: Remote certificate invalid on socket %d (Remote: '%s')(Connection: '%s') :\n", conn->cc_socket, conn->cc_remid, conn->cc_id); |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1262 fd_log_debug(" - The certificate hostname does not match '%s'\n", conn->cc_tls_para.cn); |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1263 } |
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
|
1264 ret = EINVAL; |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1265 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1266 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1267 |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1268 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
|
1269 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1270 |
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
|
1271 return ret; |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1272 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1273 |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1274 #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
|
1275 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1276 /* 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
|
1277 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
|
1278 { |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1279 /* 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
|
1280 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
|
1281 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
|
1282 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
|
1283 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
|
1284 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
|
1285 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
|
1286 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1287 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
|
1288 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1289 /* 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
|
1290 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
|
1291 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1292 /* Trace the session information -- http://www.gnu.org/software/gnutls/manual/gnutls.html#Obtaining-session-information */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1293 if (TRACE_BOOL(FULL)) { |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1294 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
|
1295 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
|
1296 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
|
1297 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
|
1298 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1299 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
|
1300 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1301 fd_log_debug("TLS Session information for connection '%s':\n", conn->cc_id); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1302 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1303 /* 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
|
1304 */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1305 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
|
1306 GNUTLS_TRACE( tmp = gnutls_kx_get_name (kx) ); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1307 fd_log_debug("\t- Key Exchange: %s\n", tmp); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1308 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1309 /* 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
|
1310 * 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
|
1311 */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1312 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
|
1313 switch (cred) |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1314 { |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1315 case GNUTLS_CRD_IA: |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1316 fd_log_debug("\t - TLS/IA session\n"); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1317 break; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1318 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1319 |
816
af62a5485fa2
Removed a few compilation warnings
Sebastien Decugis <sdecugis@freediameter.net>
parents:
808
diff
changeset
|
1320 #if (defined(ENABLE_SRP) || defined(GNUTLS_VERSION_300)) |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1321 case GNUTLS_CRD_SRP: |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1322 fd_log_debug("\t - SRP session with username %s\n", |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1323 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
|
1324 break; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1325 #endif |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1326 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1327 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
|
1328 /* 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
|
1329 */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1330 if (gnutls_psk_client_get_hint (session) != NULL) |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1331 fd_log_debug("\t - PSK authentication. PSK hint '%s'\n", |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1332 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
|
1333 /* 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
|
1334 */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1335 if (gnutls_psk_server_get_username (session) != NULL) |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1336 fd_log_debug("\t - PSK authentication. Connected as '%s'\n", |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1337 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
|
1338 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1339 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
|
1340 ecdh = 1; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1341 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
|
1342 dhe = 1; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1343 break; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1344 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1345 case GNUTLS_CRD_ANON: /* anonymous authentication */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1346 fd_log_debug("\t - Anonymous DH using prime of %d bits\n", |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1347 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
|
1348 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
|
1349 ecdh = 1; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1350 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
|
1351 dhe = 1; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1352 break; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1353 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1354 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
|
1355 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1356 /* 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
|
1357 */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1358 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
|
1359 dhe = 1; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1360 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
|
1361 ecdh = 1; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1362 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1363 /* 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
|
1364 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
|
1365 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
|
1366 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1367 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
|
1368 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1369 fd_log_debug("\t Peer provided %d certificates.\n", 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
|
1370 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1371 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
|
1372 { |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1373 int ret; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1374 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1375 /* 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
|
1376 */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1377 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
|
1378 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1379 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
|
1380 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1381 fd_log_debug("\t Certificate info:\n"); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1382 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1383 /* 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
|
1384 a certificate. */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1385 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1386 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
|
1387 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
|
1388 { |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1389 fd_log_debug("\t\t%s\n", cinfo.data); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1390 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
|
1391 } |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1392 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1393 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
|
1394 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
|
1395 fd_log_debug("\tTLS: Remote certificate invalid on socket %d (Remote: '%s')(Connection: '%s') :\n", conn->cc_socket, conn->cc_remid, conn->cc_id); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1396 fd_log_debug("\t - The certificate hostname does not match '%s'\n", 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
|
1397 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
|
1398 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
|
1399 } |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1400 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1401 } |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1402 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1403 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
|
1404 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1405 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
|
1406 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1407 } |
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 break; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1410 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1411 } /* switch */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1412 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1413 if (ecdh != 0) |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1414 fd_log_debug("\t - Ephemeral ECDH using curve %s\n", |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1415 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
|
1416 else if (dhe != 0) |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1417 fd_log_debug("\t - Ephemeral DH using prime of %d bits\n", |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1418 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
|
1419 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1420 /* 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
|
1421 */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1422 tmp = gnutls_protocol_get_name (gnutls_protocol_get_version (session)); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1423 fd_log_debug("\t - Protocol: %s\n", tmp); |
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 /* 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
|
1426 * 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
|
1427 */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1428 tmp = gnutls_certificate_type_get_name (gnutls_certificate_type_get (session)); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1429 fd_log_debug("\t - Certificate Type: %s\n", tmp); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1430 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1431 /* 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
|
1432 */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1433 tmp = gnutls_compression_get_name (gnutls_compression_get (session)); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1434 fd_log_debug("\t - Compression: %s\n", tmp); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1435 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1436 /* 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
|
1437 * ie 3DES. |
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 tmp = gnutls_cipher_get_name (gnutls_cipher_get (session)); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1440 fd_log_debug("\t - Cipher: %s\n", tmp); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1441 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1442 /* 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
|
1443 * ie SHA1 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1444 */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1445 tmp = gnutls_mac_get_name (gnutls_mac_get (session)); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1446 fd_log_debug("\t - MAC: %s\n", tmp); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1447 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1448 } |
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 /* 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
|
1451 * 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
|
1452 */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1453 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
|
1454 if (TRACE_BOOL(INFO) && (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
|
1455 fd_log_debug("TLS: Remote certificate invalid on socket %d (Remote: '%s')(Connection: '%s') :\n", conn->cc_socket, conn->cc_remid, conn->cc_id); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1456 if (status & GNUTLS_CERT_SIGNER_NOT_FOUND) |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1457 fd_log_debug(" - The certificate hasn't got a known issuer.\n"); |
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 (status & GNUTLS_CERT_REVOKED) |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1460 fd_log_debug(" - The certificate has been revoked.\n"); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1461 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1462 if (status & GNUTLS_CERT_EXPIRED) |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1463 fd_log_debug(" - The certificate has expired.\n"); |
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 if (status & GNUTLS_CERT_NOT_ACTIVATED) |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1466 fd_log_debug(" - The certificate is not yet activated.\n"); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1467 } |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1468 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
|
1469 { |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1470 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
|
1471 } |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1472 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1473 /* 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
|
1474 * 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
|
1475 * 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
|
1476 */ |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1477 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
|
1478 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
|
1479 TRACE_DEBUG(INFO, "TLS: Remote credentials are not x509, rejected on socket %d (Remote: '%s')(Connection: '%s') :\n", conn->cc_socket, conn->cc_remid, conn->cc_id); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1480 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
|
1481 } |
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 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
|
1484 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1485 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
|
1486 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
|
1487 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1488 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
|
1489 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1490 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
|
1491 if (TRACE_BOOL(INFO)) { |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1492 fd_log_debug("TLS: Remote certificate invalid on socket %d (Remote: '%s')(Connection: '%s') :\n", conn->cc_socket, conn->cc_remid, conn->cc_id); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1493 fd_log_debug(" - The certificate hostname does not match '%s'\n", 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
|
1494 } |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1495 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
|
1496 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
|
1497 } |
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_deinit (cert); |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1500 } |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1501 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1502 /* 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
|
1503 return 0; |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1504 } |
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 #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
|
1507 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1508 /* TLS handshake a connection; no need to have called start_clear before. Reception is active if handhsake is successful */ |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
1509 int fd_cnx_handshake(struct cnxctx * conn, int mode, char * priority, void * alt_creds) |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1510 { |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1511 TRACE_ENTRY( "%p %d %p %p", conn, mode, priority, alt_creds); |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1512 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
|
1513 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1514 /* Save the mode */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1515 conn->cc_tls_para.mode = mode; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1516 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1517 /* 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
|
1518 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
|
1519 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1520 /* 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
|
1521 conn->cc_loop = 1; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1522 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1523 /* Prepare the master session credentials and priority */ |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
1524 CHECK_FCT( fd_tls_prepare(&conn->cc_tls_para.session, mode, priority, alt_creds) ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1525 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1526 /* Special case: multi-stream TLS is not natively managed in GNU TLS, we use a wrapper library */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1527 if (conn->cc_sctp_para.pairs > 1) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1528 #ifdef DISABLE_SCTP |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1529 ASSERT(0); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1530 CHECK_FCT( ENOTSUP ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1531 #else /* DISABLE_SCTP */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1532 /* Initialize the wrapper, start the demux thread */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1533 CHECK_FCT( fd_sctps_init(conn) ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1534 #endif /* DISABLE_SCTP */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1535 } else { |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
1536 /* 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
|
1537 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
|
1538 |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
1539 /* Set the push and pull callbacks */ |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1540 GNUTLS_TRACE( gnutls_transport_set_pull_function(conn->cc_tls_para.session, (void *)fd_cnx_s_recv) ); |
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1541 GNUTLS_TRACE( gnutls_transport_set_push_function(conn->cc_tls_para.session, (void *)fd_cnx_s_send) ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1542 } |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1543 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1544 /* 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
|
1545 #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
|
1546 /* 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
|
1547 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1548 /* 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
|
1549 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
|
1550 |
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1551 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
|
1552 /* 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
|
1553 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
|
1554 } |
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 #endif /* GNUTLS_VERSION_300 */ |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1557 |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1558 #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
|
1559 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
|
1560 #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
|
1561 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1562 /* 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
|
1563 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
|
1564 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1565 /* Handshake master session */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1566 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1567 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
|
1568 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1569 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
|
1570 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1571 if (TRACE_BOOL(INFO)) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1572 fd_log_debug("TLS Handshake failed on socket %d (%s) : %s\n", conn->cc_socket, conn->cc_id, gnutls_strerror(ret)); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1573 } |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1574 fd_cnx_markerror(conn); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1575 return EINVAL; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1576 } ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1577 |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1578 #ifndef GNUTLS_VERSION_300 |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1579 /* 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
|
1580 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
|
1581 { |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1582 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
|
1583 fd_cnx_markerror(conn); |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1584 return EINVAL; |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1585 }); |
807
09f8f0c4f4a4
Several changes to support GnuTLS 3.x in a more efficient way
Sebastien Decugis <sdecugis@freediameter.net>
parents:
803
diff
changeset
|
1586 #endif /* GNUTLS_VERSION_300 */ |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1587 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1588 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1589 /* Multi-stream TLS: handshake other streams as well */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1590 if (conn->cc_sctp_para.pairs > 1) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1591 #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
|
1592 /* Start reading the messages from the master session. That way, if the remote peer closed, we are not stuck inside handshake */ |
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
|
1593 CHECK_FCT(fd_sctps_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
|
1594 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1595 /* Resume all additional sessions from the master one. */ |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
1596 CHECK_FCT(fd_sctps_handshake_others(conn, priority, alt_creds)); |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
1597 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1598 /* Start decrypting the messages from all threads and queuing them in target queue */ |
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
|
1599 CHECK_FCT(fd_sctps_startthreads(conn, 1)); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1600 #endif /* DISABLE_SCTP */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1601 } else { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1602 /* Start decrypting the data */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1603 CHECK_POSIX( pthread_create( &conn->cc_rcvthr, NULL, rcvthr_tls_single, conn ) ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1604 } |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
1605 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1606 return 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1607 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1608 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1609 /* Retrieve TLS credentials of the remote peer, after handshake */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1610 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
|
1611 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1612 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
|
1613 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
|
1614 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1615 /* This function only works for X.509 certificates. */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1616 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
|
1617 |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1618 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
|
1619 if (*cert_list == NULL) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1620 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
|
1621 return EINVAL; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1622 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1623 |
54
889c55527a1d
Fixed additional newline character
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
53
diff
changeset
|
1624 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
|
1625 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1626 return 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1627 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1628 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1629 /* 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
|
1630 /* 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
|
1631 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
|
1632 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1633 int ev; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1634 size_t ev_sz; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1635 void * ev_data; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1636 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1637 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
|
1638 CHECK_PARAMS(conn && (conn->cc_socket > 0) && buf && len); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1639 CHECK_PARAMS(conn->cc_rcvthr != (pthread_t)NULL); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1640 CHECK_PARAMS(conn->cc_alt == NULL); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1641 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1642 /* Now, pull the first event */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1643 get_next: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1644 if (timeout) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1645 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
|
1646 } else { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1647 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
|
1648 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1649 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1650 switch (ev) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1651 case FDEVP_CNX_MSG_RECV: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1652 /* We got one */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1653 *len = ev_sz; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1654 *buf = ev_data; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1655 return 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1656 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1657 case FDEVP_PSM_TIMEOUT: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1658 TRACE_DEBUG(FULL, "Timeout event received"); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1659 return ETIMEDOUT; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1660 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1661 case FDEVP_CNX_EP_CHANGE: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1662 /* We ignore this event */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1663 goto get_next; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1664 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1665 case FDEVP_CNX_ERROR: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1666 TRACE_DEBUG(FULL, "Received ERROR event on the connection"); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1667 return ENOTCONN; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1668 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1669 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1670 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
|
1671 return EINVAL; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1672 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1673 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1674 /* Where the events are sent */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1675 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
|
1676 { |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1677 struct fifo *q; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1678 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
|
1679 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
|
1680 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
|
1681 return q; |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1682 } |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1683 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1684 /* 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
|
1685 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
|
1686 { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1687 int ret; |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1688 TRACE_ENTRY( "%p %p", conn, alt_fifo ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1689 CHECK_PARAMS( conn && alt_fifo && conn->cc_incoming ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1690 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1691 /* 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
|
1692 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
|
1693 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
|
1694 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
|
1695 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1696 return ret; |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1697 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1698 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1699 /* 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
|
1700 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
|
1701 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1702 ssize_t ret; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1703 size_t sent = 0; |
27
b3a1773e9f46
again, correct was actually %zd
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
26
diff
changeset
|
1704 TRACE_ENTRY("%p %p %zd", conn, buf, len); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1705 do { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1706 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
|
1707 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
|
1708 } else { |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1709 /* Maybe better to replace this call with sendmsg for atomic sending? */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1710 CHECK_SYS_DO( ret = fd_cnx_s_send(conn, buf + sent, len - sent), ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1711 } |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1712 if (ret <= 0) |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1713 return ENOTCONN; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1714 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1715 sent += ret; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1716 } while ( sent < len ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1717 return 0; |
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 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1720 /* 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. */ |
229
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1721 int fd_cnx_send(struct cnxctx * conn, unsigned char * buf, size_t len, uint32_t flags) |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
1722 { |
229
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1723 TRACE_ENTRY("%p %p %zd %x", conn, buf, len, flags); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1724 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1725 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
|
1726 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1727 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
|
1728 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1729 switch (conn->cc_proto) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1730 case IPPROTO_TCP: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1731 CHECK_FCT( send_simple(conn, buf, len) ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1732 break; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1733 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1734 #ifndef DISABLE_SCTP |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1735 case IPPROTO_SCTP: { |
229
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1736 if (flags & FD_CNX_ORDERED) { |
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1737 /* We send over stream #0 */ |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1738 CHECK_FCT( send_simple(conn, buf, len) ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1739 } else { |
229
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1740 /* Default case : no flag specified */ |
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1741 |
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1742 int another_str = 0; /* do we send over stream #0 ? */ |
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1743 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1744 if ((conn->cc_sctp_para.str_out > 1) && ((!fd_cnx_teststate(conn, CC_STATUS_TLS)) || (conn->cc_sctp_para.pairs > 1))) { |
229
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1745 /* Update the id of the stream we will send this message over */ |
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1746 conn->cc_sctp_para.next += 1; |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1747 conn->cc_sctp_para.next %= (fd_cnx_teststate(conn, CC_STATUS_TLS) ? conn->cc_sctp_para.pairs : conn->cc_sctp_para.str_out); |
229
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1748 another_str = (conn->cc_sctp_para.next ? 1 : 0); |
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1749 } |
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1750 |
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1751 if ( ! another_str ) { |
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1752 CHECK_FCT( send_simple(conn, buf, len) ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1753 } else { |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1754 if (!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
|
1755 CHECK_FCT_DO( fd_sctp_sendstr(conn, conn->cc_sctp_para.next, buf, len), { 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
|
1756 } else { |
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1757 /* push the record to the appropriate session */ |
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1758 ssize_t ret; |
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1759 size_t sent = 0; |
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1760 ASSERT(conn->cc_sctps_data.array != NULL); |
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1761 do { |
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1762 CHECK_GNUTLS_DO( ret = fd_tls_send_handle_error(conn, conn->cc_sctps_data.array[conn->cc_sctp_para.next].session, buf + sent, len - sent), ); |
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1763 if (ret <= 0) |
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1764 return ENOTCONN; |
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1765 |
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1766 sent += ret; |
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1767 } while ( sent < len ); |
965f5971dc23
Broadcast CEA over all streams to avoid possible race condition
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
228
diff
changeset
|
1768 } |
25
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 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1771 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1772 break; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1773 #endif /* DISABLE_SCTP */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1774 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1775 default: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1776 TRACE_DEBUG(INFO, "Unknwon protocol: %d", conn->cc_proto); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1777 ASSERT(0); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1778 return ENOTSUP; /* or EINVAL... */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1779 } |
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 return 0; |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
1782 } |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
1783 |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
1784 |
25
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 /* Destruction of connection */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1787 /**************************************/ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1788 |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
1789 /* 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
|
1790 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
|
1791 { |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1792 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
|
1793 |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1794 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
|
1795 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1796 fd_cnx_addstate(conn, CC_STATUS_CLOSING); |
155
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1797 |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1798 /* 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
|
1799 if (fd_cnx_teststate(conn, CC_STATUS_TLS)) { |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1800 #ifndef DISABLE_SCTP |
155
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1801 if (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
|
1802 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
|
1803 /* Bye on master session */ |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1804 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
|
1805 } |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1806 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1807 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
|
1808 /* and other stream pairs */ |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1809 fd_sctps_bye(conn); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1810 } |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1811 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1812 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
|
1813 /* Now wait for all decipher threads to terminate */ |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1814 fd_sctps_waitthreadsterm(conn); |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1815 } else { |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1816 /* Abord the threads, the connection is dead already */ |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1817 fd_sctps_stopthreads(conn); |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1818 } |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1819 |
155
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1820 /* Deinit gnutls resources */ |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1821 fd_sctps_gnutls_deinit_others(conn); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1822 if (conn->cc_tls_para.session) { |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1823 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
|
1824 conn->cc_tls_para.session = NULL; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1825 } |
155
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1826 |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1827 /* Destroy the wrapper (also stops the demux thread) */ |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1828 fd_sctps_destroy(conn); |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1829 |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1830 } else { |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1831 #endif /* DISABLE_SCTP */ |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1832 /* We are TLS, but not using the sctps wrapper layer */ |
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1833 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
|
1834 /* Master session */ |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1835 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
|
1836 } |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1837 |
706
4ffbc9f1e922
Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
1838 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
|
1839 /* 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
|
1840 if (conn->cc_rcvthr != (pthread_t)NULL) { |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1841 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
|
1842 conn->cc_rcvthr = (pthread_t)NULL; |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1843 } |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1844 } else { |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1845 /* 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
|
1846 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
|
1847 } |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1848 |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1849 /* Free the resources of the TLS session */ |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1850 if (conn->cc_tls_para.session) { |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1851 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
|
1852 conn->cc_tls_para.session = NULL; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1853 } |
155
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1854 #ifndef DISABLE_SCTP |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1855 } |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1856 #endif /* DISABLE_SCTP */ |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1857 } |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1858 |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1859 /* 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
|
1860 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
|
1861 |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1862 /* Shut the connection down */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1863 if (conn->cc_socket > 0) { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1864 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
|
1865 close(conn->cc_socket); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
31
diff
changeset
|
1866 conn->cc_socket = -1; |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1867 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1868 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1869 /* Empty and destroy FIFO list */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1870 if (conn->cc_incoming) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1871 fd_event_destroy( &conn->cc_incoming, free ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1872 } |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1873 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1874 /* Free the object */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1875 free(conn); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1876 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1877 /* Done! */ |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
1878 return; |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
1879 } |