Changeset 706:4ffbc9f1e922 in freeDiameter for libfdcore/server.c
- Timestamp:
- Feb 9, 2011, 3:26:58 PM (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libfdcore/server.c
r691 r706 41 41 /* We don't need to protect this list, it is only accessed from the main framework thread. */ 42 42 43 enum s_state { 44 NOT_CREATED=0, 45 RUNNING, 46 TERMINATED, 47 ERROR /* an error occurred, this is not a valid status */ 48 }; 49 43 50 /* Servers information */ 44 51 struct server { … … 50 57 51 58 pthread_t thr; /* The thread listening for new connections */ 52 int status; /* 0 : not created; 1 : running; 2 : terminated */59 enum s_state state; /* state of the thread */ 53 60 54 61 struct fd_list clients; /* List of clients connected to this server, not yet identified */ 55 62 pthread_mutex_t clients_mtx; /* Mutex to protect the list of clients */ 56 63 }; 64 57 65 58 66 /* Client information (connecting peer for which we don't have the CER yet) */ … … 65 73 66 74 75 76 /* Micro functions to read/change the status thread-safely */ 77 static pthread_mutex_t s_lock = PTHREAD_MUTEX_INITIALIZER; 78 static enum s_state get_status(struct server * s) 79 { 80 enum s_state r; 81 CHECK_POSIX_DO( pthread_mutex_lock(&s_lock), return ERROR ); 82 r = s->state; 83 CHECK_POSIX_DO( pthread_mutex_unlock(&s_lock), return ERROR ); 84 return r; 85 } 86 static void set_status(struct server * s, enum s_state st) 87 { 88 CHECK_POSIX_DO( pthread_mutex_lock(&s_lock), return ); 89 s->state = st; 90 CHECK_POSIX_DO( pthread_mutex_unlock(&s_lock), return ); 91 } 92 93 94 67 95 /* Dump all servers information */ 68 96 void fd_servers_dump() … … 73 101 for (li = FD_SERVERS.next; li != &FD_SERVERS; li = li->next) { 74 102 struct server * s = (struct server *)li; 75 fd_cpu_flush_cache();103 enum s_state st = get_status(s); 76 104 fd_log_debug(" Serv %p '%s': %s, %s, %s\n", 77 105 s, fd_cnx_getid(s->conn), 78 106 IPPROTO_NAME( s->proto ), 79 107 s->secur ? "Secur" : "NotSecur", 80 (s ->status == 0) ? "Thread not created" :81 ((s ->status == 1) ? "Thread running" :82 ((s ->status == 2) ? "Thread terminated" :108 (st == NOT_CREATED) ? "Thread not created" : 109 ((st == RUNNING) ? "Thread running" : 110 ((st == TERMINATED) ? "Thread terminated" : 83 111 "Thread status unknown"))); 84 112 /* Dump the client list of this server */ … … 192 220 CHECK_PARAMS_DO(s, goto error); 193 221 fd_log_threadname ( fd_cnx_getid(s->conn) ); 194 s->status = 1; 195 fd_cpu_flush_cache(); 222 set_status(s, RUNNING); 196 223 197 224 /* Accept incoming connections */ … … 225 252 error: 226 253 if (s) 227 s ->status = 2;254 set_status(s, TERMINATED); 228 255 /* Send error signal to the daemon */ 229 256 TRACE_DEBUG(INFO, "An error occurred in server module! Thread is terminating..."); … … 266 293 267 294 /* Create the server on unsecure port */ 268 CHECK_MALLOC( s = new_serv(IPPROTO_SCTP, 0) ); 269 CHECK_MALLOC( s->conn = fd_cnx_serv_sctp(fd_g_config->cnf_port, FD_IS_LIST_EMPTY(&fd_g_config->cnf_endpoints) ? NULL : &fd_g_config->cnf_endpoints) ); 270 fd_list_insert_before( &FD_SERVERS, &s->chain ); 271 CHECK_POSIX( pthread_create( &s->thr, NULL, serv_th, s ) ); 295 if (fd_g_config->cnf_port) { 296 CHECK_MALLOC( s = new_serv(IPPROTO_SCTP, 0) ); 297 CHECK_MALLOC( s->conn = fd_cnx_serv_sctp(fd_g_config->cnf_port, empty_conf_ep ? NULL : &fd_g_config->cnf_endpoints) ); 298 fd_list_insert_before( &FD_SERVERS, &s->chain ); 299 CHECK_POSIX( pthread_create( &s->thr, NULL, serv_th, s ) ); 300 } 272 301 273 302 /* Create the server on secure port */ 274 CHECK_MALLOC( s = new_serv(IPPROTO_SCTP, 1) ); 275 CHECK_MALLOC( s->conn = fd_cnx_serv_sctp(fd_g_config->cnf_port_tls, FD_IS_LIST_EMPTY(&fd_g_config->cnf_endpoints) ? NULL : &fd_g_config->cnf_endpoints) ); 276 fd_list_insert_before( &FD_SERVERS, &s->chain ); 277 CHECK_POSIX( pthread_create( &s->thr, NULL, serv_th, s ) ); 303 if (fd_g_config->cnf_port_tls) { 304 CHECK_MALLOC( s = new_serv(IPPROTO_SCTP, 1) ); 305 CHECK_MALLOC( s->conn = fd_cnx_serv_sctp(fd_g_config->cnf_port_tls, empty_conf_ep ? NULL : &fd_g_config->cnf_endpoints) ); 306 fd_list_insert_before( &FD_SERVERS, &s->chain ); 307 CHECK_POSIX( pthread_create( &s->thr, NULL, serv_th, s ) ); 308 } 278 309 279 310 #endif /* DISABLE_SCTP */ … … 287 318 if (!fd_g_config->cnf_flags.no_ip4) { 288 319 289 CHECK_MALLOC( s = new_serv(IPPROTO_TCP, 0) ); 290 CHECK_MALLOC( s->conn = fd_cnx_serv_tcp(fd_g_config->cnf_port, AF_INET, NULL) ); 291 fd_list_insert_before( &FD_SERVERS, &s->chain ); 292 CHECK_POSIX( pthread_create( &s->thr, NULL, serv_th, s ) ); 293 294 CHECK_MALLOC( s = new_serv(IPPROTO_TCP, 1) ); 295 CHECK_MALLOC( s->conn = fd_cnx_serv_tcp(fd_g_config->cnf_port_tls, AF_INET, NULL) ); 296 fd_list_insert_before( &FD_SERVERS, &s->chain ); 297 CHECK_POSIX( pthread_create( &s->thr, NULL, serv_th, s ) ); 320 if (fd_g_config->cnf_port) { 321 CHECK_MALLOC( s = new_serv(IPPROTO_TCP, 0) ); 322 CHECK_MALLOC( s->conn = fd_cnx_serv_tcp(fd_g_config->cnf_port, AF_INET, NULL) ); 323 fd_list_insert_before( &FD_SERVERS, &s->chain ); 324 CHECK_POSIX( pthread_create( &s->thr, NULL, serv_th, s ) ); 325 } 326 327 if (fd_g_config->cnf_port_tls) { 328 CHECK_MALLOC( s = new_serv(IPPROTO_TCP, 1) ); 329 CHECK_MALLOC( s->conn = fd_cnx_serv_tcp(fd_g_config->cnf_port_tls, AF_INET, NULL) ); 330 fd_list_insert_before( &FD_SERVERS, &s->chain ); 331 CHECK_POSIX( pthread_create( &s->thr, NULL, serv_th, s ) ); 332 } 298 333 } 334 299 335 /* Bind TCP servers on [::] */ 300 336 if (!fd_g_config->cnf_flags.no_ip6) { 301 302 CHECK_MALLOC( s = new_serv(IPPROTO_TCP, 0) ); 303 CHECK_MALLOC( s->conn = fd_cnx_serv_tcp(fd_g_config->cnf_port, AF_INET6, NULL) ); 304 fd_list_insert_before( &FD_SERVERS, &s->chain ); 305 CHECK_POSIX( pthread_create( &s->thr, NULL, serv_th, s ) ); 306 307 CHECK_MALLOC( s = new_serv(IPPROTO_TCP, 1) ); 308 CHECK_MALLOC( s->conn = fd_cnx_serv_tcp(fd_g_config->cnf_port_tls, AF_INET6, NULL) ); 309 fd_list_insert_before( &FD_SERVERS, &s->chain ); 310 CHECK_POSIX( pthread_create( &s->thr, NULL, serv_th, s ) ); 337 338 if (fd_g_config->cnf_port) { 339 CHECK_MALLOC( s = new_serv(IPPROTO_TCP, 0) ); 340 CHECK_MALLOC( s->conn = fd_cnx_serv_tcp(fd_g_config->cnf_port, AF_INET6, NULL) ); 341 fd_list_insert_before( &FD_SERVERS, &s->chain ); 342 CHECK_POSIX( pthread_create( &s->thr, NULL, serv_th, s ) ); 343 } 344 345 if (fd_g_config->cnf_port_tls) { 346 CHECK_MALLOC( s = new_serv(IPPROTO_TCP, 1) ); 347 CHECK_MALLOC( s->conn = fd_cnx_serv_tcp(fd_g_config->cnf_port_tls, AF_INET6, NULL) ); 348 fd_list_insert_before( &FD_SERVERS, &s->chain ); 349 CHECK_POSIX( pthread_create( &s->thr, NULL, serv_th, s ) ); 350 } 311 351 } 312 352 } else { … … 323 363 continue; 324 364 325 CHECK_MALLOC( s = new_serv(IPPROTO_TCP, 0) ); 326 CHECK_MALLOC( s->conn = fd_cnx_serv_tcp(fd_g_config->cnf_port, sa->sa_family, ep) ); 327 fd_list_insert_before( &FD_SERVERS, &s->chain ); 328 CHECK_POSIX( pthread_create( &s->thr, NULL, serv_th, s ) ); 329 330 CHECK_MALLOC( s = new_serv(IPPROTO_TCP, 1) ); 331 CHECK_MALLOC( s->conn = fd_cnx_serv_tcp(fd_g_config->cnf_port_tls, sa->sa_family, ep) ); 332 fd_list_insert_before( &FD_SERVERS, &s->chain ); 333 CHECK_POSIX( pthread_create( &s->thr, NULL, serv_th, s ) ); 365 if (fd_g_config->cnf_port) { 366 CHECK_MALLOC( s = new_serv(IPPROTO_TCP, 0) ); 367 CHECK_MALLOC( s->conn = fd_cnx_serv_tcp(fd_g_config->cnf_port, sa->sa_family, ep) ); 368 fd_list_insert_before( &FD_SERVERS, &s->chain ); 369 CHECK_POSIX( pthread_create( &s->thr, NULL, serv_th, s ) ); 370 } 371 372 if (fd_g_config->cnf_port_tls) { 373 CHECK_MALLOC( s = new_serv(IPPROTO_TCP, 1) ); 374 CHECK_MALLOC( s->conn = fd_cnx_serv_tcp(fd_g_config->cnf_port_tls, sa->sa_family, ep) ); 375 fd_list_insert_before( &FD_SERVERS, &s->chain ); 376 CHECK_POSIX( pthread_create( &s->thr, NULL, serv_th, s ) ); 377 } 334 378 } 335 379 } 336 380 } 337 381 338 /* Now, if we still have not got the list of local adresses, try to read it from the kernel directly*/339 if ( FD_IS_LIST_EMPTY(&fd_g_config->cnf_endpoints)) {382 /* Now, if we had an empty list of local adresses (no address configured), try to read the real addresses from the kernel */ 383 if (empty_conf_ep) { 340 384 CHECK_FCT(fd_cnx_get_local_eps(&fd_g_config->cnf_endpoints)); 341 385 if (FD_IS_LIST_EMPTY(&fd_g_config->cnf_endpoints)) { 342 TRACE_DEBUG(INFO, "Unable to find the addresses of the local system. Please use \"ListenOn\" parameter in the configuration."); 386 TRACE_DEBUG(INFO, "Unable to find the address(es) of the local system.\n" 387 "Please use \"ListenOn\" parameter in the configuration.\n" 388 "This information is required to generate the CER/CEA messages.\n"); 343 389 return EINVAL; 344 390 }
Note: See TracChangeset
for help on using the changeset viewer.