Mercurial > hg > freeDiameter
annotate freeDiameter/cnxctx.c @ 220:5f2ce627db3c
Try to fix the old bug on sctp_getpaddrs
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Fri, 19 Feb 2010 18:09:43 +0900 |
parents | 5a1b93f59f8f |
children | 85dc47afeac7 |
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) * |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
3 * Author: Sebastien Decugis <sdecugis@nict.go.jp> * |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
4 * * |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
5 * Copyright (c) 2009, WIDE Project and NICT * |
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 |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
36 #include "fD.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 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
39 /* 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
|
40 #ifndef DIAMETER_MSG_SIZE_MAX |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
41 #define DIAMETER_MSG_SIZE_MAX 65535 /* in bytes */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
42 #endif /* DIAMETER_MSG_SIZE_MAX */ |
20
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
43 |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
44 /* 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
|
45 * 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
|
46 * 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
|
47 */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
48 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
49 /* Note: this file could be moved to libfreeDiameter instead, but since it uses gnuTLS we prefer to keep it in the daemon */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
50 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
51 /* Lifetime of a cnxctx object: |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
52 * 1) Creation |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
53 * a) a server socket: |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
54 * - 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
|
55 * - start listening incoming connections: fd_cnx_serv_listen |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
56 * - accept new clients with fd_cnx_serv_accept. |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
57 * b) a client socket: |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
58 * - 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
|
59 * |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
60 * 2) Initialization |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
61 * - if TLS is started first, call fd_cnx_handshake |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
62 * - 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
|
63 * |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
64 * 3) Usage |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
65 * - 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
|
66 * - 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
|
67 * - 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
|
68 * - 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
|
69 * - 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
|
70 * - fd_cnx_getendpoints : get the endpoints (IP) of the connection |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
71 * |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
72 * 4) End |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
73 * - fd_cnx_destroy |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
74 */ |
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) { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
92 CHECK_FCT_DO( fd_fifo_new ( &conn->cc_incoming ), return NULL ); |
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 ); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
110 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
|
111 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
112 /* The connection object */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
113 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
|
114 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
115 /* Prepare the socket address information */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
116 if (ep) { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
117 memcpy(sa, &ep->ss, sizeof(sSS)); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
118 } else { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
119 memset(&dummy, 0, sizeof(dummy)); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
120 sa->sa_family = family; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
121 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
122 if (sa->sa_family == AF_INET) { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
123 ((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
|
124 cnx->cc_family = AF_INET; |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
125 } else { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
126 ((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
|
127 cnx->cc_family = AF_INET6; |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
128 } |
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 /* Create the socket */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
131 CHECK_FCT_DO( fd_tcp_create_bind_server( &cnx->cc_socket, sa, sizeof(sSS) ), goto error ); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
132 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
133 /* Generate the name for the connection object */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
134 { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
135 char addrbuf[INET6_ADDRSTRLEN]; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
136 int rc; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
137 rc = getnameinfo(sa, sizeof(sSS), addrbuf, sizeof(addrbuf), NULL, 0, NI_NUMERICHOST); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
138 if (rc) |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
139 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
|
140 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
|
141 } |
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 cnx->cc_proto = IPPROTO_TCP; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
144 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
145 return cnx; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
146 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
147 error: |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
148 fd_cnx_destroy(cnx); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
149 return NULL; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
150 } |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
151 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
152 /* 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
|
153 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
|
154 { |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
155 #ifdef DISABLE_SCTP |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
156 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
|
157 ASSERT(0); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
158 CHECK_FCT_DO( ENOTSUP, return NULL); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
159 #else /* DISABLE_SCTP */ |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
160 struct cnxctx * cnx = NULL; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
161 sSS dummy; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
162 sSA * sa = (sSA *) &dummy; |
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 struct fd_endpoint * ep; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
224 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
225 TRACE_ENTRY("%p", serv); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
226 CHECK_PARAMS_DO(serv, return NULL); |
20
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
227 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
228 /* 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
|
229 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
|
230 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
231 if (TRACE_BOOL(INFO)) { |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
232 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
|
233 sSA_DUMP_NODE( &ss, NI_NUMERICHOST ); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
234 fd_log_debug("].\n"); |
20
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
235 } |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
236 |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
237 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
|
238 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
|
239 cli->cc_family = serv->cc_family; |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
240 cli->cc_proto = serv->cc_proto; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
241 |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
242 /* 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
|
243 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
|
244 |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
245 /* Generate the name for the connection object */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
246 { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
247 char addrbuf[INET6_ADDRSTRLEN]; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
248 char portbuf[10]; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
249 int rc; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
250 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
251 /* Numeric values for debug */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
252 rc = getnameinfo((sSA *)&ss, sizeof(sSS), 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
|
253 if (rc) { |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
254 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
|
255 portbuf[0] = '\0'; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
256 } |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
257 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
258 snprintf(cli->cc_id, sizeof(cli->cc_id), "{%s} (%d) <- [%s]:%s (%d)", |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
259 IPPROTO_NAME(cli->cc_proto), serv->cc_socket, |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
260 addrbuf, portbuf, cli->cc_socket); |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
261 |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
262 /* Name for log messages */ |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
263 rc = getnameinfo((sSA *)&ss, sizeof(sSS), 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
|
264 if (rc) |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
265 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
|
266 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
267 |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
268 #ifndef DISABLE_SCTP |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
269 /* SCTP-specific handlings */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
270 if (cli->cc_proto == IPPROTO_SCTP) { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
271 /* Retrieve the number of streams */ |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
272 CHECK_FCT_DO( fd_sctp_get_str_info( cli->cc_socket, &cli->cc_sctp_para.str_in, &cli->cc_sctp_para.str_out, NULL ), goto error ); |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
273 if (cli->cc_sctp_para.str_out > cli->cc_sctp_para.str_in) |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
274 cli->cc_sctp_para.pairs = cli->cc_sctp_para.str_out; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
275 else |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
276 cli->cc_sctp_para.pairs = cli->cc_sctp_para.str_in; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
277 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
278 #endif /* DISABLE_SCTP */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
279 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
280 return cli; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
281 error: |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
282 fd_cnx_destroy(cli); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
283 return NULL; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
284 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
285 |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
286 /* 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
|
287 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
|
288 { |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
289 int sock; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
290 struct cnxctx * cnx = NULL; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
291 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
292 TRACE_ENTRY("%p %d", sa, addrlen); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
293 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
|
294 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
295 /* Create the socket and connect, which can take some time and/or fail */ |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
296 CHECK_FCT_DO( fd_tcp_client( &sock, sa, addrlen ), return NULL ); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
297 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
298 if (TRACE_BOOL(INFO)) { |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
299 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
|
300 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
|
301 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
|
302 } |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
303 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
304 /* 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
|
305 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
|
306 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
307 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
|
308 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
|
309 cnx->cc_proto = IPPROTO_TCP; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
310 |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
311 /* 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
|
312 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
|
313 |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
314 /* Generate the names for the object */ |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
315 { |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
316 char addrbuf[INET6_ADDRSTRLEN]; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
317 char portbuf[10]; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
318 int rc; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
319 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
320 /* Numeric values for debug */ |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
321 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
|
322 if (rc) { |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
323 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
|
324 portbuf[0] = '\0'; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
325 } |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
326 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
327 snprintf(cnx->cc_id, sizeof(cnx->cc_id), "{TCP} -> [%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
|
328 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
329 /* Name for log messages */ |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
330 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
|
331 if (rc) |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
332 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
|
333 } |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
334 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
335 return cnx; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
336 } |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
337 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
338 /* 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
|
339 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
|
340 { |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
341 #ifdef DISABLE_SCTP |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
342 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
|
343 ASSERT(0); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
344 CHECK_FCT_DO( ENOTSUP, return NULL); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
345 #else /* DISABLE_SCTP */ |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
346 int sock; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
347 struct cnxctx * cnx = NULL; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
348 sSS primary; |
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 TRACE_ENTRY("%p", list); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
351 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
|
352 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
353 CHECK_FCT_DO( fd_sctp_client( &sock, no_ip6, port, list ), return NULL ); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
354 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
355 /* 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
|
356 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
|
357 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
358 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
|
359 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
|
360 cnx->cc_proto = IPPROTO_SCTP; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
361 |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
362 /* 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
|
363 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
|
364 |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
365 /* 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
|
366 CHECK_FCT_DO( fd_sctp_get_str_info( sock, &cnx->cc_sctp_para.str_in, &cnx->cc_sctp_para.str_out, &primary ), goto error ); |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
367 if (cnx->cc_sctp_para.str_out > cnx->cc_sctp_para.str_in) |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
368 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
|
369 else |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
370 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
|
371 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
372 if (TRACE_BOOL(INFO)) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
373 fd_log_debug("Connection established to server '"); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
374 sSA_DUMP_NODE_SERV( &primary, NI_NUMERICSERV); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
375 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
|
376 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
377 |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
378 /* Generate the names for the object */ |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
379 { |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
380 char addrbuf[INET6_ADDRSTRLEN]; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
381 char portbuf[10]; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
382 int rc; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
383 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
384 /* Numeric values for debug */ |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
385 rc = getnameinfo((sSA *)&primary, sizeof(sSS), 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
|
386 if (rc) { |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
387 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
|
388 portbuf[0] = '\0'; |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
389 } |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
390 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
391 snprintf(cnx->cc_id, sizeof(cnx->cc_id), "{SCTP} -> [%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
|
392 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
393 /* Name for log messages */ |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
394 rc = getnameinfo((sSA *)&primary, sizeof(sSS), 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
|
395 if (rc) |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
396 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
|
397 } |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
398 |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
399 return cnx; |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
400 |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
401 error: |
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
402 fd_cnx_destroy(cnx); |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
403 return NULL; |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
404 #endif /* DISABLE_SCTP */ |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
405 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
406 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
407 /* Return a string describing the connection, for debug */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
408 char * fd_cnx_getid(struct cnxctx * conn) |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
409 { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
410 CHECK_PARAMS_DO( conn, return "" ); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
411 return conn->cc_id; |
20
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
412 } |
277ec00d793e
Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
413 |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
414 /* 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
|
415 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
|
416 { |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
417 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
|
418 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
|
419 } |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
420 |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
421 /* Set the hostname to check during handshake */ |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
422 void fd_cnx_sethostname(struct cnxctx * conn, char * hn) |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
423 { |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
424 CHECK_PARAMS_DO( conn, return ); |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
425 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
|
426 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
427 |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
428 /* 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
|
429 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
|
430 { |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
431 CHECK_PARAMS_DO( conn, return 0 ); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
432 return conn->cc_status & 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
|
433 } |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
434 |
23
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
435 /* Get the list of endpoints (IP addresses) of the local and remote peers on this connection */ |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
436 int fd_cnx_getendpoints(struct cnxctx * conn, struct fd_list * local, struct fd_list * remote) |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
437 { |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
438 TRACE_ENTRY("%p %p %p", conn, local, remote); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
439 CHECK_PARAMS(conn); |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
440 |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
441 if (local) { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
442 /* Retrieve the local endpoint(s) of the connection */ |
23
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
443 switch (conn->cc_proto) { |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
444 case IPPROTO_TCP: { |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
445 sSS ss; |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
446 socklen_t sl; |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
447 CHECK_FCT(fd_tcp_get_local_ep(conn->cc_socket, &ss, &sl)); |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
448 CHECK_FCT(fd_ep_add_merge( local, (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
|
449 } |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
450 break; |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
451 |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
452 #ifndef DISABLE_SCTP |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
453 case IPPROTO_SCTP: { |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
454 CHECK_FCT(fd_sctp_get_local_ep(conn->cc_socket, local)); |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
455 } |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
456 break; |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
457 #endif /* DISABLE_SCTP */ |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
458 |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
459 default: |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
460 CHECK_PARAMS(0); |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
461 } |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
462 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
463 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
464 if (remote) { |
23
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
465 /* Check we have a full connection object, not a listening socket (with no remote) */ |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
466 CHECK_PARAMS( conn->cc_incoming ); |
23
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
467 |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
468 /* Retrieve the peer endpoint(s) of the connection */ |
23
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
469 switch (conn->cc_proto) { |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
470 case IPPROTO_TCP: { |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
471 sSS ss; |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
472 socklen_t sl; |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
473 CHECK_FCT(fd_tcp_get_remote_ep(conn->cc_socket, &ss, &sl)); |
24
bd83ce9328ed
Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
23
diff
changeset
|
474 CHECK_FCT(fd_ep_add_merge( remote, (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
|
475 } |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
476 break; |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
477 |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
478 #ifndef DISABLE_SCTP |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
479 case IPPROTO_SCTP: { |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
480 CHECK_FCT(fd_sctp_get_remote_ep(conn->cc_socket, remote)); |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
481 } |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
482 break; |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
483 #endif /* DISABLE_SCTP */ |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
484 |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
485 default: |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
486 CHECK_PARAMS(0); |
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
487 } |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
488 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
489 |
23
db6c40b8b307
Added some code in cnxctx.c mainly
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
22
diff
changeset
|
490 return 0; |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
491 } |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
492 |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
493 |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
494 /* 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
|
495 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
|
496 { |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
497 CHECK_PARAMS_DO( conn, return "" ); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
498 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
|
499 } |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
500 |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
501 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
502 /**************************************/ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
503 /* Use of a connection object */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
504 /**************************************/ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
505 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
506 /* An error occurred on the socket */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
507 void fd_cnx_markerror(struct cnxctx * conn) |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
508 { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
509 TRACE_ENTRY("%p", conn); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
510 CHECK_PARAMS_DO( conn, goto fatal ); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
511 |
211
929513df9024
Add a debug message
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
209
diff
changeset
|
512 TRACE_DEBUG(FULL, "Connection (%d) CC_STATUS_ERROR set", conn->cc_socket); |
929513df9024
Add a debug message
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
209
diff
changeset
|
513 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
514 /* Mark the error */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
515 conn->cc_status |= CC_STATUS_ERROR; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
516 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
517 /* Report the error if not reported yet, and not closing */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
518 if ((!(conn->cc_status & CC_STATUS_CLOSING )) && (!(conn->cc_status & CC_STATUS_SIGNALED ))) { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
519 CHECK_FCT_DO( fd_event_send( Target_Queue(conn), FDEVP_CNX_ERROR, 0, NULL), goto fatal); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
520 conn->cc_status |= CC_STATUS_SIGNALED; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
521 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
522 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
523 return; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
524 fatal: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
525 /* An unrecoverable error occurred, stop the daemon */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
526 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
|
527 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
528 |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
529 /* 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
|
530 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
|
531 { |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
532 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
|
533 |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
534 /* 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
|
535 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
|
536 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
|
537 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
|
538 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
|
539 } |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
540 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
541 /* 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
|
542 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
|
543 { |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
544 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
|
545 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
|
546 again: |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
547 ret = recv(conn->cc_socket, buffer, length, 0); |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
548 /* Handle special case of timeout */ |
196
bc530e9dae04
Fix error code returned in case of SO_RCVTIMEO timer reached
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
194
diff
changeset
|
549 if ((ret < 0) && (errno == EAGAIN)) { |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
550 if (! (conn->cc_status & 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
|
551 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
|
552 if (!timedout) { |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
553 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
|
554 goto again; |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
555 } |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
556 } |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
557 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
558 CHECK_SYS_DO(ret, /* continue */); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
559 |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
560 /* Mark the error */ |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
561 if (ret <= 0) |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
562 fd_cnx_markerror(conn); |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
563 |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
564 return ret; |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
565 } |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
566 |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
567 /* Send */ |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
568 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
|
569 { |
201
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
570 ssize_t ret = 0; |
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
571 int timedout = 0; |
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
572 again: |
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
573 ret = send(conn->cc_socket, buffer, length, 0); |
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
574 /* Handle special case of timeout */ |
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
575 if ((ret < 0) && (errno == EAGAIN)) { |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
576 if (! (conn->cc_status & CC_STATUS_CLOSING)) |
201
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
577 goto again; /* don't care, just ignore */ |
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
578 if (!timedout) { |
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
579 timedout ++; /* allow for one timeout while closing */ |
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
580 goto again; |
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
581 } |
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
582 CHECK_SYS_DO(ret, /* continue */); |
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
583 } |
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
584 |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
585 /* Mark the error */ |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
586 if (ret <= 0) |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
587 fd_cnx_markerror(conn); |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
588 |
201
1b47afa59358
Also timeout on sends
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
199
diff
changeset
|
589 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
|
590 } |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
591 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
592 /* 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
|
593 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
|
594 { |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
595 struct cnxctx * conn = arg; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
596 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
597 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
|
598 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
|
599 |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
600 /* 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
|
601 { |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
602 char buf[48]; |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
603 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
|
604 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
|
605 } |
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
606 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
607 ASSERT( conn->cc_proto == IPPROTO_TCP ); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
608 ASSERT( ! (conn->cc_status & CC_STATUS_TLS) ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
609 ASSERT( Target_Queue(conn) ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
610 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
611 /* 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
|
612 do { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
613 uint8_t header[4]; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
614 uint8_t * newmsg; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
615 size_t length; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
616 ssize_t ret = 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
617 size_t received = 0; |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
618 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
619 do { |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
620 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
|
621 if (ret <= 0) { |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
622 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
|
623 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
624 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
625 received += ret; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
626 } while (received < sizeof(header)); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
627 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
628 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
|
629 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
630 /* Check the received word is a valid begining of a Diameter message */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
631 if ((header[0] != DIAMETER_VERSION) /* defined in <libfreeDiameter.h> */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
632 || (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
|
633 /* The message is suspect */ |
27
b3a1773e9f46
again, correct was actually %zd
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
26
diff
changeset
|
634 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
|
635 fd_cnx_markerror(conn); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
636 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
|
637 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
638 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
639 /* Ok, now we can really receive the data */ |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
640 CHECK_MALLOC_DO( newmsg = malloc( length ), goto fatal ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
641 memcpy(newmsg, header, sizeof(header)); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
642 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
643 while (received < length) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
644 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
|
645 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
|
646 pthread_cleanup_pop(0); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
647 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
648 if (ret <= 0) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
649 free(newmsg); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
650 goto out; |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
651 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
652 received += ret; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
653 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
654 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
655 /* We have received a complete message, pass it to the daemon */ |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
656 CHECK_FCT_DO( fd_event_send( Target_Queue(conn), FDEVP_CNX_MSG_RECV, length, newmsg), /* continue or destroy everything? */); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
657 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
658 } while (conn->cc_loop); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
659 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
660 out: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
661 TRACE_DEBUG(FULL, "Thread terminated"); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
662 return NULL; |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
663 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
664 fatal: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
665 /* An unrecoverable error occurred, stop the daemon */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
666 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
|
667 goto out; |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
668 } |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
669 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
670 #ifndef DISABLE_SCTP |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
671 /* 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
|
672 static void * rcvthr_notls_sctp(void * arg) |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
673 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
674 struct cnxctx * conn = arg; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
675 uint8_t * buf; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
676 size_t bufsz; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
677 int event; |
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); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
680 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
|
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) 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
|
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_SCTP ); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
690 ASSERT( ! (conn->cc_status & CC_STATUS_TLS) ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
691 ASSERT( Target_Queue(conn) ); |
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 do { |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
694 CHECK_FCT_DO( fd_sctp_recvmeta(conn->cc_socket, NULL, &buf, &bufsz, &event, &conn->cc_status), goto fatal ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
695 if (event == FDEVP_CNX_ERROR) { |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
696 fd_cnx_markerror(conn); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
697 goto out; |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
698 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
699 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
700 CHECK_FCT_DO( fd_event_send( Target_Queue(conn), event, bufsz, buf), goto fatal ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
701 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
702 } while (conn->cc_loop); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
703 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
704 out: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
705 TRACE_DEBUG(FULL, "Thread terminated"); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
706 return NULL; |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
707 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
708 fatal: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
709 /* An unrecoverable error occurred, stop the daemon */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
710 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
|
711 goto out; |
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 #endif /* DISABLE_SCTP */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
714 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
715 /* 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
|
716 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
|
717 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
718 TRACE_ENTRY("%p %i", conn, loop); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
719 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
720 CHECK_PARAMS( conn && Target_Queue(conn) && (!(conn->cc_status & CC_STATUS_TLS)) && (!conn->cc_loop)); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
721 |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
722 /* 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
|
723 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
|
724 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
725 /* Save the loop request */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
726 conn->cc_loop = loop; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
727 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
728 switch (conn->cc_proto) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
729 case IPPROTO_TCP: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
730 /* Start the tcp_notls thread */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
731 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
|
732 break; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
733 #ifndef DISABLE_SCTP |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
734 case IPPROTO_SCTP: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
735 /* Start the tcp_notls thread */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
736 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
|
737 break; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
738 #endif /* DISABLE_SCTP */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
739 default: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
740 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
|
741 ASSERT(0); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
742 return ENOTSUP; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
743 } |
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 return 0; |
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 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
748 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
749 |
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 /* 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
|
752 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
|
753 { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
754 ssize_t ret; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
755 again: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
756 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
|
757 { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
758 switch (ret) { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
759 case GNUTLS_E_REHANDSHAKE: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
760 if (!(conn->cc_status & CC_STATUS_CLOSING)) |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
761 CHECK_GNUTLS_DO( ret = gnutls_handshake(session), |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
762 { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
763 if (TRACE_BOOL(INFO)) { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
764 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
|
765 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
766 goto end; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
767 } ); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
768 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
769 case GNUTLS_E_AGAIN: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
770 case GNUTLS_E_INTERRUPTED: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
771 if (!(conn->cc_status & CC_STATUS_CLOSING)) |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
772 goto again; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
773 TRACE_DEBUG(INFO, "Connection is closing, so abord gnutls_record_recv now."); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
774 break; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
775 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
776 default: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
777 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
|
778 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
779 } ); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
780 end: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
781 if (ret <= 0) |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
782 fd_cnx_markerror(conn); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
783 return ret; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
784 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
785 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
786 /* 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
|
787 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
|
788 { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
789 ssize_t ret; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
790 again: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
791 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
|
792 { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
793 switch (ret) { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
794 case GNUTLS_E_REHANDSHAKE: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
795 if (!(conn->cc_status & CC_STATUS_CLOSING)) |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
796 CHECK_GNUTLS_DO( ret = gnutls_handshake(session), |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
797 { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
798 if (TRACE_BOOL(INFO)) { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
799 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
|
800 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
801 goto end; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
802 } ); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
803 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
804 case GNUTLS_E_AGAIN: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
805 case GNUTLS_E_INTERRUPTED: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
806 if (!(conn->cc_status & CC_STATUS_CLOSING)) |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
807 goto again; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
808 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
|
809 break; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
810 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
811 default: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
812 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
|
813 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
814 } ); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
815 end: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
816 if (ret <= 0) |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
817 fd_cnx_markerror(conn); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
818 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
819 return ret; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
820 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
821 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
822 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
823 /* 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
|
824 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
|
825 { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
826 /* 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
|
827 do { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
828 uint8_t header[4]; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
829 uint8_t * newmsg; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
830 size_t length; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
831 ssize_t ret = 0; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
832 size_t received = 0; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
833 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
834 do { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
835 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
|
836 if (ret <= 0) { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
837 /* The connection is closed */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
838 goto out; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
839 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
840 received += ret; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
841 } while (received < sizeof(header)); |
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 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
|
844 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
845 /* 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
|
846 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
|
847 || (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
|
848 /* The message is suspect */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
849 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
|
850 fd_cnx_markerror(conn); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
851 goto out; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
852 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
853 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
854 /* Ok, now we can really receive the data */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
855 CHECK_MALLOC( newmsg = malloc( length ) ); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
856 memcpy(newmsg, header, sizeof(header)); |
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 while (received < length) { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
859 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
|
860 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
|
861 pthread_cleanup_pop(0); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
862 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
863 if (ret <= 0) { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
864 free(newmsg); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
865 goto out; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
866 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
867 received += ret; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
868 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
869 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
870 /* We have received a complete message, pass it to the daemon */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
871 CHECK_FCT_DO( ret = fd_event_send( Target_Queue(conn), FDEVP_CNX_MSG_RECV, length, newmsg), |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
872 { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
873 free(newmsg); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
874 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
|
875 return ret; |
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 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
878 } while (1); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
879 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
880 out: |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
881 return ENOTCONN; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
882 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
883 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
884 /* Receiver thread (TLS & 1 stream SCTP or TCP) */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
885 static void * rcvthr_tls_single(void * arg) |
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 struct cnxctx * conn = arg; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
888 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
889 TRACE_ENTRY("%p", arg); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
890 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
|
891 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
892 /* Set the thread name */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
893 { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
894 char buf[48]; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
895 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
|
896 fd_log_threadname ( buf ); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
897 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
898 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
899 ASSERT( conn->cc_status & CC_STATUS_TLS ); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
900 ASSERT( Target_Queue(conn) ); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
901 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
902 /* 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
|
903 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
|
904 |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
905 TRACE_DEBUG(FULL, "Thread terminated"); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
906 return NULL; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
907 } |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
908 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
909 /* 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
|
910 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
|
911 { |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
912 /* Create the session context */ |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
913 CHECK_GNUTLS_DO( gnutls_init (session, mode), return ENOMEM ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
914 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
915 /* Set the algorithm suite */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
916 if (priority) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
917 const char * errorpos; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
918 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
|
919 { 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
|
920 } else { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
921 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
|
922 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
923 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
924 /* 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
|
925 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
|
926 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
927 /* Request the remote credentials as well */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
928 if (mode == GNUTLS_SERVER) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
929 gnutls_certificate_server_set_request (*session, GNUTLS_CERT_REQUIRE); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
930 } |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
931 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
932 return 0; |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
933 } |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
934 |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
935 /* 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
|
936 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
|
937 { |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
938 int ret, i; |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
939 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
|
940 unsigned int cert_list_size; |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
941 gnutls_x509_crt_t cert; |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
942 time_t now; |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
943 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
944 TRACE_ENTRY("%p %d", conn, verbose); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
945 CHECK_PARAMS(conn); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
946 |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
947 /* 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
|
948 if (verbose && TRACE_BOOL(FULL)) { |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
949 const char *tmp; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
950 gnutls_kx_algorithm_t kx; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
951 gnutls_credentials_type_t cred; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
952 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
953 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
|
954 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
955 /* 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
|
956 GNUTLS_TRACE( kx = gnutls_kx_get (session) ); |
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
957 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
|
958 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
|
959 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
960 /* Check the authentication type used and switch |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
961 * to the appropriate. */ |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
962 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
|
963 switch (cred) |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
964 { |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
965 case GNUTLS_CRD_IA: |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
966 fd_log_debug("\t - TLS/IA session\n"); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
967 break; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
968 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
969 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
970 #ifdef ENABLE_SRP |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
971 case GNUTLS_CRD_SRP: |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
972 fd_log_debug("\t - SRP session with username %s\n", |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
973 gnutls_srp_server_get_username (session)); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
974 break; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
975 #endif |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
976 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
977 case GNUTLS_CRD_PSK: |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
978 /* This returns NULL in server side. */ |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
979 if (gnutls_psk_client_get_hint (session) != NULL) |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
980 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
|
981 gnutls_psk_client_get_hint (session)); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
982 /* This returns NULL in client side. */ |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
983 if (gnutls_psk_server_get_username (session) != NULL) |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
984 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
|
985 gnutls_psk_server_get_username (session)); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
986 break; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
987 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
988 case GNUTLS_CRD_ANON: /* anonymous authentication */ |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
989 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
|
990 gnutls_dh_get_prime_bits (session)); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
991 break; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
992 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
993 case GNUTLS_CRD_CERTIFICATE: /* certificate authentication */ |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
994 /* 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
|
995 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
|
996 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
|
997 gnutls_dh_get_prime_bits (session)); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
998 } |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
999 } |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1000 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1001 /* 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
|
1002 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
|
1003 fd_log_debug("\t - Protocol: %s\n", tmp); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1004 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1005 /* 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
|
1006 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
|
1007 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
|
1008 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1009 /* print the compression algorithm (if any) */ |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1010 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
|
1011 fd_log_debug("\t - Compression: %s\n", tmp); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1012 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1013 /* 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
|
1014 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
|
1015 fd_log_debug("\t - Cipher: %s\n", tmp); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1016 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1017 /* Print the MAC algorithms name. ie SHA1 */ |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1018 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
|
1019 fd_log_debug("\t - MAC: %s\n", tmp); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1020 } |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1021 |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1022 /* First, use built-in verification */ |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1023 CHECK_GNUTLS_DO( gnutls_certificate_verify_peers2 (session, &ret), return EINVAL ); |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1024 if (ret) { |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1025 if (TRACE_BOOL(INFO)) { |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1026 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
|
1027 if (ret & GNUTLS_CERT_INVALID) |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1028 fd_log_debug(" - The certificate is not trusted (unknown CA?)\n"); |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1029 if (ret & GNUTLS_CERT_REVOKED) |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1030 fd_log_debug(" - The certificate has been revoked.\n"); |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1031 if (ret & GNUTLS_CERT_SIGNER_NOT_FOUND) |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1032 fd_log_debug(" - The certificate hasn't got a known issuer.\n"); |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1033 if (ret & GNUTLS_CERT_SIGNER_NOT_CA) |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1034 fd_log_debug(" - The certificate signer is not a CA, or uses version 1, or 3 without basic constraints.\n"); |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1035 if (ret & GNUTLS_CERT_INSECURE_ALGORITHM) |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1036 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
|
1037 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1038 return EINVAL; |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1039 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1040 |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1041 /* 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
|
1042 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
|
1043 return EINVAL; |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1044 |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1045 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
|
1046 if (cert_list == NULL) |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1047 return EINVAL; |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1048 |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1049 now = time(NULL); |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1050 |
59
067ab3fc6093
Cleanups in debug messages
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
57
diff
changeset
|
1051 if (verbose && TRACE_BOOL(FULL)) { |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1052 char serial[40]; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1053 char dn[128]; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1054 size_t size; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1055 unsigned int algo, bits; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1056 time_t expiration_time, activation_time; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1057 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1058 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
|
1059 for (i = 0; i < cert_list_size; i++) |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1060 { |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1061 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1062 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
|
1063 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
|
1064 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1065 fd_log_debug(" Certificate %d info:\n", i); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1066 |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1067 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
|
1068 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
|
1069 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1070 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
|
1071 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
|
1072 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1073 /* Print the serial number of the certificate. */ |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1074 size = sizeof (serial); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1075 gnutls_x509_crt_get_serial (cert, serial, &size); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1076 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1077 fd_log_debug("\t - Certificate serial number: "); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1078 { |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1079 int j; |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1080 for (j = 0; j < size; j++) { |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1081 fd_log_debug("%02.2hhx", serial[j]); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1082 } |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1083 } |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1084 fd_log_debug("\n"); |
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 /* 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
|
1087 GNUTLS_TRACE( algo = gnutls_x509_crt_get_pk_algorithm (cert, &bits) ); |
57 | 1088 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
|
1089 gnutls_pk_algorithm_get_name (algo)); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1090 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1091 /* Print the version of the X.509 certificate. */ |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1092 fd_log_debug("\t - Certificate version: #%d\n", |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1093 gnutls_x509_crt_get_version (cert)); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1094 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1095 size = sizeof (dn); |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1096 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
|
1097 fd_log_debug("\t - DN: %s\n", dn); |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1098 |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1099 size = sizeof (dn); |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1100 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
|
1101 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
|
1102 |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1103 GNUTLS_TRACE( gnutls_x509_crt_deinit (cert) ); |
53
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1104 } |
cd5620362909
Add debug information for TLS
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
43
diff
changeset
|
1105 } |
31
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1106 |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1107 /* 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
|
1108 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
|
1109 { |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1110 time_t deadline; |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1111 |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1112 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
|
1113 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
|
1114 |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1115 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
|
1116 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
|
1117 if (TRACE_BOOL(INFO)) { |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1118 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
|
1119 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
|
1120 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1121 return EINVAL; |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1122 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1123 |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1124 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
|
1125 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
|
1126 if (TRACE_BOOL(INFO)) { |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1127 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
|
1128 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
|
1129 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1130 return EINVAL; |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1131 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1132 |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1133 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
|
1134 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
|
1135 if (TRACE_BOOL(INFO)) { |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1136 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
|
1137 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
|
1138 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1139 return EINVAL; |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1140 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1141 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1142 |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1143 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
|
1144 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1145 |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1146 return 0; |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1147 } |
26685c67d387
Completed the test and fixed a couple issues
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
30
diff
changeset
|
1148 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1149 /* 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
|
1150 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
|
1151 { |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1152 TRACE_ENTRY( "%p %d %p %p", conn, mode, priority, alt_creds); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1153 CHECK_PARAMS( conn && (!(conn->cc_status & 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
|
1154 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1155 /* Save the mode */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1156 conn->cc_tls_para.mode = mode; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1157 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1158 /* 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
|
1159 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
|
1160 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1161 /* 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
|
1162 conn->cc_loop = 1; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1163 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1164 /* 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
|
1165 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
|
1166 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1167 /* 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
|
1168 if (conn->cc_sctp_para.pairs > 1) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1169 #ifdef DISABLE_SCTP |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1170 ASSERT(0); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1171 CHECK_FCT( ENOTSUP ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1172 #else /* DISABLE_SCTP */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1173 /* Initialize the wrapper, start the demux thread */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1174 CHECK_FCT( fd_sctps_init(conn) ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1175 #endif /* DISABLE_SCTP */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1176 } else { |
194
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
1177 /* 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
|
1178 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
|
1179 |
d1af490d6e85
Change in sockets options to avoid waiting forever on closing connections
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
188
diff
changeset
|
1180 /* Set the push and pull callbacks */ |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1181 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
|
1182 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
|
1183 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1184 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1185 /* Mark the connection as protected from here, so that the gnutls credentials will be freed */ |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1186 conn->cc_status |= CC_STATUS_TLS; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1187 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1188 /* Handshake master session */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1189 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1190 int ret; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1191 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
|
1192 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1193 if (TRACE_BOOL(INFO)) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1194 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
|
1195 } |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1196 fd_cnx_markerror(conn); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1197 return EINVAL; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1198 } ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1199 |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1200 /* 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
|
1201 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
|
1202 { |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1203 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
|
1204 fd_cnx_markerror(conn); |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1205 return EINVAL; |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1206 }); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1207 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1208 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1209 /* Multi-stream TLS: handshake other streams as well */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1210 if (conn->cc_sctp_para.pairs > 1) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1211 #ifndef DISABLE_SCTP |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1212 /* 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
|
1213 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
|
1214 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1215 /* Start decrypting the messages from all threads and queuing them in target queue */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1216 CHECK_FCT(fd_sctps_startthreads(conn)); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1217 #endif /* DISABLE_SCTP */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1218 } else { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1219 /* Start decrypting the data */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1220 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
|
1221 } |
29
5ba91682f0bc
Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
27
diff
changeset
|
1222 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1223 return 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1224 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1225 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1226 /* Retrieve TLS credentials of the remote peer, after handshake */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1227 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
|
1228 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1229 TRACE_ENTRY("%p %p %p", conn, cert_list, cert_list_size); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1230 CHECK_PARAMS( conn && (conn->cc_status & CC_STATUS_TLS) && cert_list && cert_list_size ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1231 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1232 /* This function only works for X.509 certificates. */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1233 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
|
1234 |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1235 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
|
1236 if (*cert_list == NULL) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1237 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
|
1238 return EINVAL; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1239 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1240 |
54
889c55527a1d
Fixed additional newline character
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
53
diff
changeset
|
1241 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
|
1242 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1243 return 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1244 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1245 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1246 /* 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
|
1247 /* 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
|
1248 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
|
1249 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1250 int ev; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1251 size_t ev_sz; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1252 void * ev_data; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1253 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1254 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
|
1255 CHECK_PARAMS(conn && (conn->cc_socket > 0) && buf && len); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1256 CHECK_PARAMS(conn->cc_rcvthr != (pthread_t)NULL); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1257 CHECK_PARAMS(conn->cc_alt == NULL); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1258 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1259 /* Now, pull the first event */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1260 get_next: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1261 if (timeout) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1262 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
|
1263 } else { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1264 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
|
1265 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1266 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1267 switch (ev) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1268 case FDEVP_CNX_MSG_RECV: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1269 /* We got one */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1270 *len = ev_sz; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1271 *buf = ev_data; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1272 return 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1273 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1274 case FDEVP_PSM_TIMEOUT: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1275 TRACE_DEBUG(FULL, "Timeout event received"); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1276 return ETIMEDOUT; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1277 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1278 case FDEVP_CNX_EP_CHANGE: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1279 /* We ignore this event */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1280 goto get_next; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1281 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1282 case FDEVP_CNX_ERROR: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1283 TRACE_DEBUG(FULL, "Received ERROR event on the connection"); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1284 return ENOTCONN; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1285 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1286 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1287 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
|
1288 return EINVAL; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1289 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1290 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1291 /* 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
|
1292 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
|
1293 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1294 TRACE_ENTRY( "%p %p", conn, alt_fifo ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1295 CHECK_PARAMS( conn && alt_fifo && conn->cc_incoming ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1296 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1297 /* The magic function does it all */ |
43
2db15632a63d
Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
38
diff
changeset
|
1298 CHECK_FCT( fd_fifo_move( conn->cc_incoming, alt_fifo, &conn->cc_alt ) ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1299 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1300 return 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1301 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1302 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1303 /* 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
|
1304 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
|
1305 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1306 ssize_t ret; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1307 size_t sent = 0; |
27
b3a1773e9f46
again, correct was actually %zd
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
26
diff
changeset
|
1308 TRACE_ENTRY("%p %p %zd", conn, buf, len); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1309 do { |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1310 if (conn->cc_status & CC_STATUS_TLS) { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1311 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
|
1312 } else { |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1313 /* 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
|
1314 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
|
1315 } |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1316 if (ret <= 0) |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1317 return ENOTCONN; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1318 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1319 sent += ret; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1320 } while ( sent < len ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1321 return 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1322 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1323 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1324 /* Send a message -- this is synchronous -- and we assume it's never called by several threads at the same time, so we don't protect. */ |
208
e1da03ba112f
Force ordering of messages by using only stream 0 for link-local messages -- avoids issue of DWR arriving before CEA.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
203
diff
changeset
|
1325 int fd_cnx_send(struct cnxctx * conn, unsigned char * buf, size_t len, int ordered) |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
1326 { |
208
e1da03ba112f
Force ordering of messages by using only stream 0 for link-local messages -- avoids issue of DWR arriving before CEA.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
203
diff
changeset
|
1327 TRACE_ENTRY("%p %p %zd %i", conn, buf, len, ordered); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1328 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1329 CHECK_PARAMS(conn && (conn->cc_socket > 0) && (! (conn->cc_status & CC_STATUS_ERROR)) && buf && len); |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1330 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1331 TRACE_DEBUG(FULL, "Sending %zdb %sdata on connection %s", len, (conn->cc_status & CC_STATUS_TLS) ? "TLS-protected ":"", conn->cc_id); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1332 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1333 switch (conn->cc_proto) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1334 case IPPROTO_TCP: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1335 CHECK_FCT( send_simple(conn, buf, len) ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1336 break; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1337 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1338 #ifndef DISABLE_SCTP |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1339 case IPPROTO_SCTP: { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1340 int multistr = 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1341 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1342 if ((!ordered) && (conn->cc_sctp_para.str_out > 1) && ((! (conn->cc_status & CC_STATUS_TLS)) || (conn->cc_sctp_para.pairs > 1))) { |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1343 /* Update the id of the stream we will send this message on */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1344 conn->cc_sctp_para.next += 1; |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1345 conn->cc_sctp_para.next %= ((conn->cc_status & CC_STATUS_TLS) ? conn->cc_sctp_para.pairs : conn->cc_sctp_para.str_out); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1346 multistr = 1; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1347 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1348 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1349 if ((!multistr) || (conn->cc_sctp_para.next == 0)) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1350 CHECK_FCT( send_simple(conn, buf, len) ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1351 } else { |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1352 if (!(conn->cc_status & CC_STATUS_TLS)) { |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1353 CHECK_FCT_DO( fd_sctp_sendstr(conn->cc_socket, conn->cc_sctp_para.next, buf, len, &conn->cc_status), { fd_cnx_markerror(conn); return ENOTCONN; } ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1354 } else { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1355 /* push the record to the appropriate session */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1356 ssize_t ret; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1357 size_t sent = 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1358 ASSERT(conn->cc_sctps_data.array != NULL); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1359 do { |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1360 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), ); |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1361 if (ret <= 0) |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1362 return ENOTCONN; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1363 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1364 sent += ret; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1365 } while ( sent < len ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1366 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1367 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1368 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1369 break; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1370 #endif /* DISABLE_SCTP */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1371 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1372 default: |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1373 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
|
1374 ASSERT(0); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1375 return ENOTSUP; /* or EINVAL... */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1376 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1377 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1378 return 0; |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
1379 } |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
1380 |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
1381 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1382 /**************************************/ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1383 /* Destruction of connection */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1384 /**************************************/ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1385 |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
1386 /* 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
|
1387 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
|
1388 { |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1389 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
|
1390 |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1391 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
|
1392 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1393 conn->cc_status |= CC_STATUS_CLOSING; |
155
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1394 |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1395 /* Initiate shutdown of the TLS session(s): call gnutls_bye(WR), then read until error */ |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1396 if (conn->cc_status & CC_STATUS_TLS) { |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1397 #ifndef DISABLE_SCTP |
155
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1398 if (conn->cc_sctp_para.pairs > 1) { |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1399 if (! (conn->cc_status & CC_STATUS_ERROR )) { |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1400 /* Bye on master session */ |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1401 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
|
1402 } |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1403 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1404 if (! (conn->cc_status & CC_STATUS_ERROR ) ) { |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1405 /* and other stream pairs */ |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1406 fd_sctps_bye(conn); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1407 } |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1408 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1409 if (! (conn->cc_status & CC_STATUS_ERROR ) ) { |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1410 /* 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
|
1411 fd_sctps_waitthreadsterm(conn); |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1412 } else { |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1413 /* 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
|
1414 fd_sctps_stopthreads(conn); |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1415 } |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1416 |
155
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1417 /* Deinit gnutls resources */ |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1418 fd_sctps_gnutls_deinit_others(conn); |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1419 if (conn->cc_tls_para.session) { |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1420 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
|
1421 conn->cc_tls_para.session = NULL; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1422 } |
155
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1423 |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1424 /* Destroy the wrapper (also stops the demux thread) */ |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1425 fd_sctps_destroy(conn); |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1426 |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1427 } else { |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1428 #endif /* DISABLE_SCTP */ |
155
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1429 /* We are not using the sctps wrapper layer */ |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1430 if (! (conn->cc_status & CC_STATUS_ERROR ) ) { |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1431 /* Master session */ |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1432 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
|
1433 } |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1434 |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1435 if (! (conn->cc_status & CC_STATUS_ERROR ) ) { |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1436 /* 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
|
1437 if (conn->cc_rcvthr != (pthread_t)NULL) { |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1438 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
|
1439 conn->cc_rcvthr = (pthread_t)NULL; |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1440 } |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1441 } else { |
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1442 /* 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
|
1443 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
|
1444 } |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1445 |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1446 /* Free the resources of the TLS session */ |
209
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1447 if (conn->cc_tls_para.session) { |
214
5a1b93f59f8f
Added trace facility for GNUTLS calls
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
211
diff
changeset
|
1448 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
|
1449 conn->cc_tls_para.session = NULL; |
b9f48f2f2a22
Some cleanups in the code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
208
diff
changeset
|
1450 } |
155
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1451 |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1452 #ifndef DISABLE_SCTP |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1453 } |
30a7252cbb55
Cleanup connection cleanup sequence
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
136
diff
changeset
|
1454 #endif /* DISABLE_SCTP */ |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1455 } |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1456 |
203
536b1dde8761
Some cleanups in the cnxctx module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
201
diff
changeset
|
1457 /* 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
|
1458 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
|
1459 |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1460 /* Shut the connection down */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1461 if (conn->cc_socket > 0) { |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1462 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
|
1463 close(conn->cc_socket); |
68c1890f7049
Fixed a small bug in SCTP close
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
31
diff
changeset
|
1464 conn->cc_socket = -1; |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1465 } |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1466 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1467 /* Empty and destroy FIFO list */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1468 if (conn->cc_incoming) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1469 fd_event_destroy( &conn->cc_incoming, free ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
24
diff
changeset
|
1470 } |
22
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1471 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1472 /* Free the object */ |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1473 free(conn); |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1474 |
0b3b46da2c12
Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
1475 /* Done! */ |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
1476 return; |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
20
diff
changeset
|
1477 } |