annotate libfdcore/server.c @ 882:ae96ae28f3dd 1.1.5

Limit python version to avoid using python3 (not compatible)
author Sebastien Decugis <sdecugis@freediameter.net>
date Sat, 03 Nov 2012 18:45:41 +0100
parents 4a9f08d6b6ba
children a3eed6420b5b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1 /*********************************************************************************************************
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2 * Software License Agreement (BSD License) *
740
4a9f08d6b6ba Updated my mail address
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 706
diff changeset
3 * Author: Sebastien Decugis <sdecugis@freediameter.net> *
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
4 * *
662
2e94ef0515d7 Updated copyright information
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 658
diff changeset
5 * Copyright (c) 2011, WIDE Project and NICT *
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
6 * All rights reserved. *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
7 * *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
8 * Redistribution and use of this software in source and binary forms, with or without modification, are *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
9 * permitted provided that the following conditions are met: *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
10 * *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
11 * * Redistributions of source code must retain the above *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
12 * copyright notice, this list of conditions and the *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
13 * following disclaimer. *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
14 * *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
15 * * Redistributions in binary form must reproduce the above *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
16 * copyright notice, this list of conditions and the *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
17 * following disclaimer in the documentation and/or other *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
18 * materials provided with the distribution. *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
19 * *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
20 * * Neither the name of the WIDE Project or NICT nor the *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
21 * names of its contributors may be used to endorse or *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
22 * promote products derived from this software without *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
23 * specific prior written permission of WIDE Project and *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
24 * NICT. *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
25 * *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
34 *********************************************************************************************************/
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
35
658
f198d16fa7f4 Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 590
diff changeset
36 #include "fdcore-internal.h"
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
37
686
f83d9878bf66 Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
38 /* Server (listening) part of the framework */
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
39
686
f83d9878bf66 Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
40 static struct fd_list FD_SERVERS = FD_LIST_INITIALIZER(FD_SERVERS); /* The list of all server objects */
f83d9878bf66 Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
41 /* We don't need to protect this list, it is only accessed from the main framework thread. */
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
42
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
43 enum s_state {
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
44 NOT_CREATED=0,
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
45 RUNNING,
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
46 TERMINATED,
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
47 ERROR /* an error occurred, this is not a valid status */
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
48 };
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
49
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
50 /* Servers information */
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
51 struct server {
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
52 struct fd_list chain; /* link in the FD_SERVERS list */
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
53
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
54 struct cnxctx * conn; /* server connection context (listening socket) */
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
55 int proto; /* IPPROTO_TCP or IPPROTO_SCTP */
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
56 int secur; /* TLS is started immediatly after connection ? */
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
57
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
58 pthread_t thr; /* The thread listening for new connections */
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
59 enum s_state state; /* state of the thread */
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
60
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
61 struct fd_list clients; /* List of clients connected to this server, not yet identified */
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
62 pthread_mutex_t clients_mtx; /* Mutex to protect the list of clients */
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
63 };
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
64
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
65
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
66 /* Client information (connecting peer for which we don't have the CER yet) */
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
67 struct client {
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
68 struct fd_list chain; /* link in the server's list of clients */
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
69 struct cnxctx *conn; /* Parameters of the connection */
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
70 struct timespec ts; /* Deadline for receiving CER (after INCNX_TIMEOUT) */
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
71 pthread_t thr; /* connection state machine */
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
72 };
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
73
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
74
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
75
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
76 /* Micro functions to read/change the status thread-safely */
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
77 static pthread_mutex_t s_lock = PTHREAD_MUTEX_INITIALIZER;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
78 static enum s_state get_status(struct server * s)
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
79 {
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
80 enum s_state r;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
81 CHECK_POSIX_DO( pthread_mutex_lock(&s_lock), return ERROR );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
82 r = s->state;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
83 CHECK_POSIX_DO( pthread_mutex_unlock(&s_lock), return ERROR );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
84 return r;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
85 }
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
86 static void set_status(struct server * s, enum s_state st)
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
87 {
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
88 CHECK_POSIX_DO( pthread_mutex_lock(&s_lock), return );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
89 s->state = st;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
90 CHECK_POSIX_DO( pthread_mutex_unlock(&s_lock), return );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
91 }
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
92
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
93
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
94
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
95 /* Dump all servers information */
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
96 void fd_servers_dump()
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 struct fd_list * li, *cli;
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
99
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
100 fd_log_debug("Dumping servers list :\n");
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
101 for (li = FD_SERVERS.next; li != &FD_SERVERS; li = li->next) {
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
102 struct server * s = (struct server *)li;
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
103 enum s_state st = get_status(s);
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
104 fd_log_debug(" Serv %p '%s': %s, %s, %s\n",
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
105 s, fd_cnx_getid(s->conn),
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
106 IPPROTO_NAME( s->proto ),
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
107 s->secur ? "Secur" : "NotSecur",
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
108 (st == NOT_CREATED) ? "Thread not created" :
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
109 ((st == RUNNING) ? "Thread running" :
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
110 ((st == TERMINATED) ? "Thread terminated" :
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
111 "Thread status unknown")));
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
112 /* Dump the client list of this server */
686
f83d9878bf66 Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
113 CHECK_POSIX_DO( pthread_mutex_lock(&s->clients_mtx), );
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
114 for (cli = s->clients.next; cli != &s->clients; cli = cli->next) {
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
115 struct client * c = (struct client *)cli;
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
116 char bufts[128];
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
117 fd_log_debug(" Connected: '%s' (timeout: %s)\n",
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
118 fd_cnx_getid(c->conn),
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
119 fd_log_time(&c->ts, bufts, sizeof(bufts)));
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
120 }
686
f83d9878bf66 Fixed in case of termination of several modules (before initialization completed)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
121 CHECK_POSIX_DO( pthread_mutex_unlock(&s->clients_mtx), );
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
122 }
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
123 }
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
124
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
125
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
126 /* The state machine to handle incoming connection before the remote peer is identified */
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
127 static void * client_sm(void * arg)
21
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
128 {
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
129 struct client * c = arg;
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
130 struct server * s = NULL;
26
b4684b76c6ab Fix erroneous %g specifiers for size_t (correct is %z)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
131 uint8_t * buf = NULL;
b4684b76c6ab Fix erroneous %g specifiers for size_t (correct is %z)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
132 size_t bufsz;
b4684b76c6ab Fix erroneous %g specifiers for size_t (correct is %z)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
133 struct msg * msg = NULL;
b4684b76c6ab Fix erroneous %g specifiers for size_t (correct is %z)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
134 struct msg_hdr *hdr = NULL;
21
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
135
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
136 TRACE_ENTRY("%p", c);
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
137
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
138 CHECK_PARAMS_DO(c && c->conn && c->chain.head, goto fatal_error );
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
139
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
140 s = c->chain.head->o;
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
141
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
142 /* Name the current thread */
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
143 fd_log_threadname ( fd_cnx_getid(c->conn) );
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 /* Handshake if we are a secure server port, or start clear otherwise */
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
146 if (s->secur) {
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
147 int ret = fd_cnx_handshake(c->conn, GNUTLS_SERVER, NULL, NULL);
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
148 if (ret != 0) {
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
149 if (TRACE_BOOL(INFO)) {
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
150 fd_log_debug("TLS handshake failed for client '%s', connection aborted.\n", fd_cnx_getid(c->conn));
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
151 }
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
152 goto cleanup;
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
153 }
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
154 } else {
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
155 CHECK_FCT_DO( fd_cnx_start_clear(c->conn, 0), goto cleanup );
21
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
156 }
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
157
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
158 /* Set the timeout to receive the first message */
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
159 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &c->ts), goto fatal_error );
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
160 c->ts.tv_sec += INCNX_TIMEOUT;
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
161
26
b4684b76c6ab Fix erroneous %g specifiers for size_t (correct is %z)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
162 /* Receive the first Diameter message on the connection -- cleanup in case of timeout */
b4684b76c6ab Fix erroneous %g specifiers for size_t (correct is %z)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
163 CHECK_FCT_DO( fd_cnx_receive(c->conn, &c->ts, &buf, &bufsz), goto cleanup );
b4684b76c6ab Fix erroneous %g specifiers for size_t (correct is %z)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
164
27
b3a1773e9f46 again, correct was actually %zd
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 26
diff changeset
165 TRACE_DEBUG(FULL, "Received %zdb from new client '%s'", bufsz, fd_cnx_getid(c->conn));
26
b4684b76c6ab Fix erroneous %g specifiers for size_t (correct is %z)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
166
b4684b76c6ab Fix erroneous %g specifiers for size_t (correct is %z)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
167 /* Try parsing this message */
b4684b76c6ab Fix erroneous %g specifiers for size_t (correct is %z)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
168 CHECK_FCT_DO( fd_msg_parse_buffer( &buf, bufsz, &msg ), /* Parsing failed */ goto cleanup );
b4684b76c6ab Fix erroneous %g specifiers for size_t (correct is %z)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
169
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
170 /* We expect a CER, it must parse with our dictionary and rules */
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
171 CHECK_FCT_DO( fd_msg_parse_rules( msg, fd_g_config->cnf_dict, NULL ), /* Parsing failed -- trace details ? */ goto cleanup );
21
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
172
26
b4684b76c6ab Fix erroneous %g specifiers for size_t (correct is %z)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
173 /* Now check we received a CER */
b4684b76c6ab Fix erroneous %g specifiers for size_t (correct is %z)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
174 CHECK_FCT_DO( fd_msg_hdr ( msg, &hdr ), goto fatal_error );
b4684b76c6ab Fix erroneous %g specifiers for size_t (correct is %z)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
175 CHECK_PARAMS_DO( (hdr->msg_appl == 0) && (hdr->msg_flags & CMD_FLAG_REQUEST) && (hdr->msg_code == CC_CAPABILITIES_EXCHANGE),
b4684b76c6ab Fix erroneous %g specifiers for size_t (correct is %z)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
176 { fd_log_debug("Connection '%s', expecting CER, received something else, closing...\n", fd_cnx_getid(c->conn)); goto cleanup; } );
b4684b76c6ab Fix erroneous %g specifiers for size_t (correct is %z)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
177
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
178 /* Finally, pass the information to the peers module which will handle it next */
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
179 pthread_cleanup_push((void *)fd_cnx_destroy, c->conn);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
180 pthread_cleanup_push((void *)fd_msg_free, msg);
691
78b665400097 Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 688
diff changeset
181 CHECK_FCT_DO( fd_peer_handle_newCER( &msg, &c->conn ), );
29
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
182 pthread_cleanup_pop(0);
5ba91682f0bc Added a test for cnxctx (tbc) and fixed some bugs
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 28
diff changeset
183 pthread_cleanup_pop(0);
26
b4684b76c6ab Fix erroneous %g specifiers for size_t (correct is %z)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
184
28
3628f7d2ba88 some new functions backbones
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 27
diff changeset
185 /* The end, we cleanup the client structure */
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
186 cleanup:
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
187 /* Unlink the client structure */
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
188 CHECK_POSIX_DO( pthread_mutex_lock(&s->clients_mtx), goto fatal_error );
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
189 fd_list_unlink( &c->chain );
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
190 CHECK_POSIX_DO( pthread_mutex_unlock(&s->clients_mtx), goto fatal_error );
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
191
688
8c3dc8584dab Prepared capability for messages logging to separate files / folders
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 686
diff changeset
192 /* Cleanup the parsed message if any */
8c3dc8584dab Prepared capability for messages logging to separate files / folders
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 686
diff changeset
193 if (msg) {
8c3dc8584dab Prepared capability for messages logging to separate files / folders
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 686
diff changeset
194 fd_msg_log( FD_MSG_LOG_DROPPED, msg, "Received invalid/unexpected message from connecting client '%s'", fd_cnx_getid(c->conn) );
8c3dc8584dab Prepared capability for messages logging to separate files / folders
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 686
diff changeset
195 CHECK_FCT_DO( fd_msg_free(msg), /* continue */);
8c3dc8584dab Prepared capability for messages logging to separate files / folders
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 686
diff changeset
196 }
8c3dc8584dab Prepared capability for messages logging to separate files / folders
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 686
diff changeset
197
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
198 /* Destroy the connection object if present */
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
199 if (c->conn)
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
200 fd_cnx_destroy(c->conn);
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
201
26
b4684b76c6ab Fix erroneous %g specifiers for size_t (correct is %z)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
202 /* Cleanup the received buffer if any */
b4684b76c6ab Fix erroneous %g specifiers for size_t (correct is %z)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
203 free(buf);
b4684b76c6ab Fix erroneous %g specifiers for size_t (correct is %z)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
204
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
205 /* Detach the thread, cleanup the client structure */
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
206 pthread_detach(pthread_self());
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
207 free(c);
21
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
208 return NULL;
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
209
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
210 fatal_error: /* This has effect to terminate the daemon */
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
211 CHECK_FCT_DO(fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, 0, NULL), );
21
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
212 return NULL;
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
213 }
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
214
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
215 /* The thread managing a server */
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
216 static void * serv_th(void * arg)
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
217 {
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
218 struct server *s = (struct server *)arg;
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
219
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
220 CHECK_PARAMS_DO(s, goto error);
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
221 fd_log_threadname ( fd_cnx_getid(s->conn) );
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
222 set_status(s, RUNNING);
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
223
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
224 /* Accept incoming connections */
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
225 CHECK_FCT_DO( fd_cnx_serv_listen(s->conn), goto error );
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
226
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
227 do {
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
228 struct client * c = NULL;
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
229 struct cnxctx * conn = NULL;
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
230
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
231 /* Wait for a new client */
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
232 CHECK_MALLOC_DO( conn = fd_cnx_serv_accept(s->conn), goto error );
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
233
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
234 TRACE_DEBUG(FULL, "New connection accepted");
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
235
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
236 /* Create a client structure */
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
237 CHECK_MALLOC_DO( c = malloc(sizeof(struct client)), goto error );
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
238 memset(c, 0, sizeof(struct client));
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
239 fd_list_init(&c->chain, c);
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
240 c->conn = conn;
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
241
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
242 /* Save the client in the list */
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
243 CHECK_POSIX_DO( pthread_mutex_lock( &s->clients_mtx ), goto error );
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
244 fd_list_insert_before(&s->clients, &c->chain);
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
245 CHECK_POSIX_DO( pthread_mutex_unlock( &s->clients_mtx ), goto error );
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 /* Start the client thread */
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
248 CHECK_POSIX_DO( pthread_create( &c->thr, NULL, client_sm, c ), goto error );
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
249
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
250 } while (1);
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
251
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
252 error:
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
253 if (s)
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
254 set_status(s, TERMINATED);
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
255 /* Send error signal to the daemon */
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
256 TRACE_DEBUG(INFO, "An error occurred in server module! Thread is terminating...");
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 24
diff changeset
257 CHECK_FCT_DO(fd_event_send(fd_g_config->cnf_main_ev, FDEV_TERMINATE, 0, NULL), );
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
258
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
259 return NULL;
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
260 }
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
261
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
262
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
263 /* Create a new server structure */
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
264 static struct server * new_serv( int proto, int secur )
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
265 {
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
266 struct server * new;
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
267
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
268 /* New server structure */
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
269 CHECK_MALLOC_DO( new = malloc(sizeof(struct server)), return NULL );
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
270
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
271 memset(new, 0, sizeof(struct server));
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
272 fd_list_init(&new->chain, new);
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
273 new->proto = proto;
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
274 new->secur = secur;
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
275 CHECK_POSIX_DO( pthread_mutex_init(&new->clients_mtx, NULL), return NULL );
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
276 fd_list_init(&new->clients, new);
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
277
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
278 return new;
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
279 }
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
280
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
281 /* Start all the servers */
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
282 int fd_servers_start()
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
283 {
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
284 struct server * s;
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
285
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
286 int empty_conf_ep = FD_IS_LIST_EMPTY(&fd_g_config->cnf_endpoints);
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
287
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
288 /* SCTP */
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
289 if (!fd_g_config->cnf_flags.no_sctp) {
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
290 #ifdef DISABLE_SCTP
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
291 ASSERT(0);
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
292 #else /* DISABLE_SCTP */
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
293
590
da93c7a5e1d0 Fix SCTP port when ListenOn is set (Patch by Vlada) - closes #20
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 456
diff changeset
294 /* Create the server on unsecure port */
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
295 if (fd_g_config->cnf_port) {
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
296 CHECK_MALLOC( s = new_serv(IPPROTO_SCTP, 0) );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
297 CHECK_MALLOC( s->conn = fd_cnx_serv_sctp(fd_g_config->cnf_port, empty_conf_ep ? NULL : &fd_g_config->cnf_endpoints) );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
298 fd_list_insert_before( &FD_SERVERS, &s->chain );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
299 CHECK_POSIX( pthread_create( &s->thr, NULL, serv_th, s ) );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
300 }
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
301
21
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
302 /* Create the server on secure port */
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
303 if (fd_g_config->cnf_port_tls) {
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
304 CHECK_MALLOC( s = new_serv(IPPROTO_SCTP, 1) );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
305 CHECK_MALLOC( s->conn = fd_cnx_serv_sctp(fd_g_config->cnf_port_tls, empty_conf_ep ? NULL : &fd_g_config->cnf_endpoints) );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
306 fd_list_insert_before( &FD_SERVERS, &s->chain );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
307 CHECK_POSIX( pthread_create( &s->thr, NULL, serv_th, s ) );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
308 }
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
309
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
310 #endif /* DISABLE_SCTP */
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
311 }
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
312
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
313 /* TCP */
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
314 if (!fd_g_config->cnf_flags.no_tcp) {
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
315
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
316 if (empty_conf_ep) {
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
317 /* Bind TCP servers on [0.0.0.0] */
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
318 if (!fd_g_config->cnf_flags.no_ip4) {
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
319
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
320 if (fd_g_config->cnf_port) {
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
321 CHECK_MALLOC( s = new_serv(IPPROTO_TCP, 0) );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
322 CHECK_MALLOC( s->conn = fd_cnx_serv_tcp(fd_g_config->cnf_port, AF_INET, NULL) );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
323 fd_list_insert_before( &FD_SERVERS, &s->chain );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
324 CHECK_POSIX( pthread_create( &s->thr, NULL, serv_th, s ) );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
325 }
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
326
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
327 if (fd_g_config->cnf_port_tls) {
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
328 CHECK_MALLOC( s = new_serv(IPPROTO_TCP, 1) );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
329 CHECK_MALLOC( s->conn = fd_cnx_serv_tcp(fd_g_config->cnf_port_tls, AF_INET, NULL) );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
330 fd_list_insert_before( &FD_SERVERS, &s->chain );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
331 CHECK_POSIX( pthread_create( &s->thr, NULL, serv_th, s ) );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
332 }
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
333 }
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
334
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
335 /* Bind TCP servers on [::] */
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
336 if (!fd_g_config->cnf_flags.no_ip6) {
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
337
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
338 if (fd_g_config->cnf_port) {
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
339 CHECK_MALLOC( s = new_serv(IPPROTO_TCP, 0) );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
340 CHECK_MALLOC( s->conn = fd_cnx_serv_tcp(fd_g_config->cnf_port, AF_INET6, NULL) );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
341 fd_list_insert_before( &FD_SERVERS, &s->chain );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
342 CHECK_POSIX( pthread_create( &s->thr, NULL, serv_th, s ) );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
343 }
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
344
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
345 if (fd_g_config->cnf_port_tls) {
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
346 CHECK_MALLOC( s = new_serv(IPPROTO_TCP, 1) );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
347 CHECK_MALLOC( s->conn = fd_cnx_serv_tcp(fd_g_config->cnf_port_tls, AF_INET6, NULL) );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
348 fd_list_insert_before( &FD_SERVERS, &s->chain );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
349 CHECK_POSIX( pthread_create( &s->thr, NULL, serv_th, s ) );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
350 }
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
351 }
21
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
352 } else {
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
353 /* Create all endpoints -- check flags */
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
354 struct fd_list * li;
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
355 for (li = fd_g_config->cnf_endpoints.next; li != &fd_g_config->cnf_endpoints; li = li->next) {
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
356 struct fd_endpoint * ep = (struct fd_endpoint *)li;
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
357 sSA * sa = (sSA *) &ep->ss;
24
bd83ce9328ed Cleanups and completed sctp code (not finished)
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 22
diff changeset
358 if (! (ep->flags & EP_FL_CONF))
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
359 continue;
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
360 if (fd_g_config->cnf_flags.no_ip4 && (sa->sa_family == AF_INET))
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
361 continue;
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
362 if (fd_g_config->cnf_flags.no_ip6 && (sa->sa_family == AF_INET6))
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
363 continue;
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
364
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
365 if (fd_g_config->cnf_port) {
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
366 CHECK_MALLOC( s = new_serv(IPPROTO_TCP, 0) );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
367 CHECK_MALLOC( s->conn = fd_cnx_serv_tcp(fd_g_config->cnf_port, sa->sa_family, ep) );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
368 fd_list_insert_before( &FD_SERVERS, &s->chain );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
369 CHECK_POSIX( pthread_create( &s->thr, NULL, serv_th, s ) );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
370 }
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
371
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
372 if (fd_g_config->cnf_port_tls) {
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
373 CHECK_MALLOC( s = new_serv(IPPROTO_TCP, 1) );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
374 CHECK_MALLOC( s->conn = fd_cnx_serv_tcp(fd_g_config->cnf_port_tls, sa->sa_family, ep) );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
375 fd_list_insert_before( &FD_SERVERS, &s->chain );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
376 CHECK_POSIX( pthread_create( &s->thr, NULL, serv_th, s ) );
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
377 }
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
378 }
21
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
379 }
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
380 }
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
381
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
382 /* Now, if we had an empty list of local adresses (no address configured), try to read the real addresses from the kernel */
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
383 if (empty_conf_ep) {
378
41e3c2a3721c Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
384 CHECK_FCT(fd_cnx_get_local_eps(&fd_g_config->cnf_endpoints));
41e3c2a3721c Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
385 if (FD_IS_LIST_EMPTY(&fd_g_config->cnf_endpoints)) {
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
386 TRACE_DEBUG(INFO, "Unable to find the address(es) of the local system.\n"
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
387 "Please use \"ListenOn\" parameter in the configuration.\n"
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 691
diff changeset
388 "This information is required to generate the CER/CEA messages.\n");
378
41e3c2a3721c Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
389 return EINVAL;
41e3c2a3721c Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
390 }
41e3c2a3721c Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
391 }
41e3c2a3721c Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
392 if (TRACE_BOOL(FULL)){
41e3c2a3721c Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
393 fd_log_debug(" Local server address(es) :\n");
41e3c2a3721c Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
394 fd_ep_dump( 5, &fd_g_config->cnf_endpoints );
41e3c2a3721c Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 258
diff changeset
395 }
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
396 return 0;
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
397 }
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
398
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
399 /* Terminate all the servers */
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
400 int fd_servers_stop()
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
401 {
123
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
402 TRACE_ENTRY("");
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
403
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
404 TRACE_DEBUG(INFO, "Shutting down server sockets...");
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
405
21
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
406 /* Loop on all servers */
123
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
407 while (!FD_IS_LIST_EMPTY(&FD_SERVERS)) {
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
408 struct server * s = (struct server *)(FD_SERVERS.next);
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
409
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
410 /* Lock client list now */
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
411 CHECK_FCT_DO( pthread_mutex_lock(&s->clients_mtx), /* continue anyway */);
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
412
21
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 20
diff changeset
413 /* cancel thread */
123
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
414 CHECK_FCT_DO( fd_thr_term(&s->thr), /* continue */);
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
415
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
416 /* destroy server connection context */
123
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
417 fd_cnx_destroy(s->conn);
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
418
22
0b3b46da2c12 Progress on server code
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
419 /* cancel and destroy all clients */
123
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
420 while (!FD_IS_LIST_EMPTY(&s->clients)) {
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
421 struct client * c = (struct client *)(s->clients.next);
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
422
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
423 /* Destroy client's thread */
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
424 CHECK_FCT_DO( fd_thr_term(&c->thr), /* continue */);
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
425
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
426 /* Destroy client's connection */
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
427 fd_cnx_destroy(c->conn);
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
428
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
429 /* Unlink and free the client */
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
430 fd_list_unlink(&c->chain);
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
431 free(c);
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
432 }
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
433 /* Unlock & destroy */
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
434 CHECK_FCT_DO( pthread_mutex_unlock(&s->clients_mtx), /* continue anyway */);
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
435 CHECK_FCT_DO( pthread_mutex_destroy(&s->clients_mtx), /* continue */);
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
436
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
437 /* Now destroy the server object */
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
438 fd_list_unlink(&s->chain);
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
439 free(s);
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
440 }
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
441
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
442 /* We're done! */
960fa8048805 Merged routing and dispatch files for similarities
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 74
diff changeset
443 return 0;
20
277ec00d793e Backup before typhoon... Progress on server side
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
444 }
"Welcome to our mercurial repository"