Navigation


Changeset 706:4ffbc9f1e922 in freeDiameter for libfdcore/server.c


Ignore:
Timestamp:
Feb 9, 2011, 3:26:58 PM (13 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Large UNTESTED commit with the following changes:

  • Improved DiameterIdentity? handling (esp. interationalization issues), and improve efficiency of some string operations in peers, sessions, and dictionary modules (closes #7)
  • Cleanup in the session module to free only unreferenced sessions (#16)
  • Removed fd_cpu_flush_cache(), replaced by more robust alternatives.
  • Improved peer state machine algorithm to counter SCTP multistream race condition.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libfdcore/server.c

    r691 r706  
    4141/* We don't need to protect this list, it is only accessed from the main framework thread. */
    4242
     43enum s_state {
     44        NOT_CREATED=0,
     45        RUNNING,
     46        TERMINATED,
     47        ERROR   /* an error occurred, this is not a valid status */
     48};
     49
    4350/* Servers information */
    4451struct server {
     
    5057       
    5158        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 */
    5360       
    5461        struct fd_list  clients;        /* List of clients connected to this server, not yet identified */
    5562        pthread_mutex_t clients_mtx;    /* Mutex to protect the list of clients */
    5663};
     64
    5765
    5866/* Client information (connecting peer for which we don't have the CER yet) */
     
    6573
    6674
     75
     76/* Micro functions to read/change the status thread-safely */
     77static pthread_mutex_t s_lock = PTHREAD_MUTEX_INITIALIZER;
     78static 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}
     86static 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
    6795/* Dump all servers information */
    6896void fd_servers_dump()
     
    73101        for (li = FD_SERVERS.next; li != &FD_SERVERS; li = li->next) {
    74102                struct server * s = (struct server *)li;
    75                 fd_cpu_flush_cache();
     103                enum s_state st = get_status(s);
    76104                fd_log_debug("  Serv %p '%s': %s, %s, %s\n",
    77105                                s, fd_cnx_getid(s->conn),
    78106                                IPPROTO_NAME( s->proto ),
    79107                                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" :
    83111                                                          "Thread status unknown")));
    84112                /* Dump the client list of this server */
     
    192220        CHECK_PARAMS_DO(s, goto error);
    193221        fd_log_threadname ( fd_cnx_getid(s->conn) );
    194         s->status = 1;
    195         fd_cpu_flush_cache();
     222        set_status(s, RUNNING);
    196223       
    197224        /* Accept incoming connections */
     
    225252error: 
    226253        if (s)
    227                 s->status = 2;
     254                set_status(s, TERMINATED);
    228255        /* Send error signal to the daemon */
    229256        TRACE_DEBUG(INFO, "An error occurred in server module! Thread is terminating...");
     
    266293               
    267294                /* 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                }
    272301               
    273302                /* 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                }
    278309               
    279310#endif /* DISABLE_SCTP */
     
    287318                        if (!fd_g_config->cnf_flags.no_ip4) {
    288319                               
    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                                }
    298333                        }
     334                       
    299335                        /* Bind TCP servers on [::] */
    300336                        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                                }
    311351                        }
    312352                } else {
     
    323363                                        continue;
    324364                               
    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                                }
    334378                        }
    335379                }
    336380        }
    337381       
    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) {
    340384                CHECK_FCT(fd_cnx_get_local_eps(&fd_g_config->cnf_endpoints));
    341385                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");
    343389                        return EINVAL;
    344390                }
Note: See TracChangeset for help on using the changeset viewer.