Navigation


Changeset 24:bd83ce9328ed in freeDiameter


Ignore:
Timestamp:
Oct 21, 2009, 6:42:45 PM (15 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Cleanups and completed sctp code (not finished)

Files:
1 added
13 edited

Legend:

Unmodified
Added
Removed
  • doc/freediameter.conf.sample

    r23 r24  
    205205TcTimer = 60;
    206206TwTimer = 6;
    207 ListenOn = "133.243.146.201";
    208 ListenOn = "fe80::21d:9ff:fe89:7d68%eth0";
     207#ListenOn = "133.243.146.201";
     208#ListenOn = "fe80::21d:9ff:fe89:7d68%eth0";
    209209NoRelay;
    210210LoadExtension = "extensions/dbg_monitor.fdx";
  • freeDiameter/CMakeLists.txt

    r22 r24  
    1313        cnxctx.c
    1414        dispatch.c
     15        endpoints.c
    1516        extensions.c
    1617        dict_base_proto.c
  • freeDiameter/cnxctx.c

    r23 r24  
    174174        return NULL;
    175175}
    176 #ifndef DISABLE_SCTP
     176
     177/* Same function for SCTP, with a list of local endpoints to bind to */
    177178struct cnxctx * fd_cnx_serv_sctp(uint16_t port, struct fd_list * ep_list)
    178179{
     180#ifdef DISABLE_SCTP
     181        TRACE_DEBUG(INFO, "This function should never been called when SCTP is disabled...");
     182        ASSERT(0);
     183        CHECK_FCT_DO( ENOTSUP, return NULL);
     184#else /* DISABLE_SCTP */
    179185        struct cnxctx * cnx = NULL;
    180186        sSS dummy;
     
    201207        fd_cnx_destroy(cnx);
    202208        return NULL;
    203 }
    204209#endif /* DISABLE_SCTP */
     210}
    205211
    206212/* Allow clients to connect on the server socket */
     
    239245        CHECK_PARAMS_DO(serv, return NULL);
    240246       
     247        /* Accept the new connection -- this is blocking until new client enters or cancellation */
    241248        CHECK_SYS_DO( cli_sock = accept(serv->cc_socket, (sSA *)&ss, &ss_len), return NULL );
    242249       
    243250        if (TRACE_BOOL(INFO)) {
    244                 fd_log_debug("%s - new client [", fd_cnx_getid(serv));
    245                 sSA_DUMP_NODE( &ss, AI_NUMERICHOST );
    246                 fd_log_debug("] connected.\n");
     251                fd_log_debug("%s : accepted new client [", fd_cnx_getid(serv));
     252                sSA_DUMP_NODE( &ss, NI_NUMERICHOST );
     253                fd_log_debug("].\n");
    247254        }
    248255       
     
    259266                /* Numeric values for debug */
    260267                rc = getnameinfo((sSA *)&ss, sizeof(sSS), addrbuf, sizeof(addrbuf), portbuf, sizeof(portbuf), NI_NUMERICHOST | NI_NUMERICSERV);
    261                 if (rc)
     268                if (rc) {
    262269                        snprintf(addrbuf, sizeof(addrbuf), "[err:%s]", gai_strerror(rc));
    263                
    264                 snprintf(cli->cc_id, sizeof(cli->cc_id), "Client %s [%s]:%s (%d) / serv (%d)",
     270                        portbuf[0] = '\0';
     271                }
     272               
     273                snprintf(cli->cc_id, sizeof(cli->cc_id), "Incoming %s [%s]:%s (%d) @ serv (%d)",
    265274                                IPPROTO_NAME(cli->cc_proto),
    266275                                addrbuf, portbuf,
    267276                                cli->cc_socket, serv->cc_socket);
    268277               
    269                 /* Textual value for log messages */
    270                 rc = getnameinfo((sSA *)&ss, sizeof(sSS), cli->cc_remid, sizeof(cli->cc_remid), NULL, 0, NI_NUMERICHOST);
     278                /* Name for log messages */
     279                rc = getnameinfo((sSA *)&ss, sizeof(sSS), cli->cc_remid, sizeof(cli->cc_remid), NULL, 0, 0);
    271280                if (rc)
    272281                        snprintf(cli->cc_remid, sizeof(cli->cc_remid), "[err:%s]", gai_strerror(rc));
    273282        }
    274283
     284#ifndef DISABLE_SCTP
    275285        /* SCTP-specific handlings */
    276 #ifndef DISABLE_SCTP
    277286        if (cli->cc_proto == IPPROTO_SCTP) {
    278287                /* Retrieve the number of streams */
    279                 CHECK_FCT_DO( fd_sctp_get_str_info( cli->cc_socket, &cli->cc_sctp_para.str_in, &cli->cc_sctp_para.str_out ), goto error );
     288                CHECK_FCT_DO( fd_sctp_get_str_info( cli->cc_socket, &cli->cc_sctp_para.str_in, &cli->cc_sctp_para.str_out, NULL ), goto error );
    280289                if (cli->cc_sctp_para.str_out > cli->cc_sctp_para.str_in)
    281290                        cli->cc_sctp_para.pairs = cli->cc_sctp_para.str_out;
     
    291300}
    292301
    293 /* Client side: connect to a remote server */
    294 struct cnxctx * fd_cnx_cli_connect(int proto, const sSA * sa,  socklen_t addrlen)
    295 {
    296 
    297         TODO("...");
     302/* Client side: connect to a remote server -- cancelable */
     303struct cnxctx * fd_cnx_cli_connect_tcp(sSA * sa /* contains the port already */, socklen_t addrlen)
     304{
     305        int sock;
     306        struct cnxctx * cnx = NULL;
     307       
     308        TRACE_ENTRY("%p %d", sa, addrlen);
     309        CHECK_PARAMS_DO( sa && addrlen, return NULL );
     310       
     311        /* Create the socket and connect, which can take some time and/or fail */
     312        CHECK_FCT_DO( fd_tcp_client( &sock, sa, addrlen ), return NULL );
     313       
     314        if (TRACE_BOOL(INFO)) {
     315                fd_log_debug("Connection established to server '");
     316                sSA_DUMP_NODE_SERV( sa, NI_NUMERICSERV);
     317                fd_log_debug("' (TCP:%d).\n", sock);
     318        }
     319       
     320        /* Once the socket is created successfuly, prepare the remaining of the cnx */
     321        CHECK_MALLOC_DO( cnx = fd_cnx_init(1), { shutdown(sock, SHUT_RDWR); return NULL; } );
     322       
     323        cnx->cc_socket = sock;
     324        cnx->cc_proto  = IPPROTO_TCP;
     325       
     326        /* Generate the names for the object */
     327        {
     328                char addrbuf[INET6_ADDRSTRLEN];
     329                char portbuf[10];
     330                int  rc;
     331               
     332                /* Numeric values for debug */
     333                rc = getnameinfo(sa, addrlen, addrbuf, sizeof(addrbuf), portbuf, sizeof(portbuf), NI_NUMERICHOST | NI_NUMERICSERV);
     334                if (rc) {
     335                        snprintf(addrbuf, sizeof(addrbuf), "[err:%s]", gai_strerror(rc));
     336                        portbuf[0] = '\0';
     337                }
     338               
     339                snprintf(cnx->cc_id, sizeof(cnx->cc_id), "Client of TCP server [%s]:%s (%d)", addrbuf, portbuf, cnx->cc_socket);
     340               
     341                /* Name for log messages */
     342                rc = getnameinfo(sa, addrlen, cnx->cc_remid, sizeof(cnx->cc_remid), NULL, 0, 0);
     343                if (rc)
     344                        snprintf(cnx->cc_remid, sizeof(cnx->cc_remid), "[err:%s]", gai_strerror(rc));
     345        }
     346       
     347        return cnx;
     348
     349error:
     350        fd_cnx_destroy(cnx);
    298351        return NULL;
     352}
     353
     354/* Same for SCTP, accepts a list of remote addresses to connect to (see sctp_connectx) */
     355struct cnxctx * fd_cnx_cli_connect_sctp(int no_ip6, uint16_t port, struct fd_list * list)
     356{
     357#ifdef DISABLE_SCTP
     358        TRACE_DEBUG(INFO, "This function should never been called when SCTP is disabled...");
     359        ASSERT(0);
     360        CHECK_FCT_DO( ENOTSUP, return NULL);
     361#else /* DISABLE_SCTP */
     362        int sock;
     363        struct cnxctx * cnx = NULL;
     364        sSS primary;
     365       
     366        TRACE_ENTRY("%p", list);
     367        CHECK_PARAMS_DO( list && !FD_IS_LIST_EMPTY(list), return NULL );
     368       
     369        CHECK_FCT_DO( fd_sctp_client( &sock, no_ip6, port, list ), return NULL );
     370       
     371        /* Once the socket is created successfuly, prepare the remaining of the cnx */
     372        CHECK_MALLOC_DO( cnx = fd_cnx_init(1), { shutdown(sock, SHUT_RDWR); return NULL; } );
     373       
     374        cnx->cc_socket = sock;
     375        cnx->cc_proto  = IPPROTO_SCTP;
     376       
     377        /* Retrieve the number of streams and primary address */
     378        CHECK_FCT_DO( fd_sctp_get_str_info( sock, &cnx->cc_sctp_para.str_in, &cnx->cc_sctp_para.str_out, &primary ), goto error );
     379        if (cnx->cc_sctp_para.str_out > cnx->cc_sctp_para.str_in)
     380                cnx->cc_sctp_para.pairs = cnx->cc_sctp_para.str_out;
     381        else
     382                cnx->cc_sctp_para.pairs = cnx->cc_sctp_para.str_in;
     383       
     384        /* Generate the names for the object */
     385        {
     386                char addrbuf[INET6_ADDRSTRLEN];
     387                char portbuf[10];
     388                int  rc;
     389               
     390                /* Numeric values for debug */
     391                rc = getnameinfo((sSA *)&primary, sizeof(sSS), addrbuf, sizeof(addrbuf), portbuf, sizeof(portbuf), NI_NUMERICHOST | NI_NUMERICSERV);
     392                if (rc) {
     393                        snprintf(addrbuf, sizeof(addrbuf), "[err:%s]", gai_strerror(rc));
     394                        portbuf[0] = '\0';
     395                }
     396               
     397                snprintf(cnx->cc_id, sizeof(cnx->cc_id), "Client of SCTP server [%s]:%s (%d)", addrbuf, portbuf, cnx->cc_socket);
     398               
     399                /* Name for log messages */
     400                rc = getnameinfo((sSA *)&primary, sizeof(sSS), cnx->cc_remid, sizeof(cnx->cc_remid), NULL, 0, 0);
     401                if (rc)
     402                        snprintf(cnx->cc_remid, sizeof(cnx->cc_remid), "[err:%s]", gai_strerror(rc));
     403        }
     404       
     405        if (TRACE_BOOL(INFO)) {
     406                fd_log_debug("Connection established to server '");
     407                sSA_DUMP_NODE_SERV( &primary, NI_NUMERICSERV);
     408                fd_log_debug("' (SCTP:%d).\n", sock);
     409        }
     410       
     411        return cnx;
     412
     413error:
     414        fd_cnx_destroy(cnx);
     415        return NULL;
     416#endif /* DISABLE_SCTP */
    299417}
    300418
     
    415533                                socklen_t sl;
    416534                                CHECK_FCT(fd_tcp_get_local_ep(conn->cc_socket, &ss, &sl));
    417                                 CHECK_FCT(fd_ep_add_merge( local, (sSA *)&ss, sl, 0, 0, 0, 1 ));
     535                                CHECK_FCT(fd_ep_add_merge( local, (sSA *)&ss, sl, EP_FL_LL | EP_FL_PRIMARY));
    418536                        }
    419537                        break;
     
    441559                                socklen_t sl;
    442560                                CHECK_FCT(fd_tcp_get_remote_ep(conn->cc_socket, &ss, &sl));
    443                                 CHECK_FCT(fd_ep_add_merge( remote, (sSA *)&ss, sl, 0, 0, 0, 1 ));
     561                                CHECK_FCT(fd_ep_add_merge( remote, (sSA *)&ss, sl, EP_FL_LL | EP_FL_PRIMARY ));
    444562                        }
    445563                        break;
     
    528646        return;
    529647}
    530 
    531 
    532 
    533 
  • freeDiameter/config.c

    r23 r24  
    272272        return 0;
    273273}
    274 
    275 /* Add an endpoint information in a list */
    276 int fd_ep_add_merge( struct fd_list * list, sSA * sa, socklen_t sl, int conf, int disc, int adv, int ll )
    277 {
    278         struct fd_endpoint * ep;
    279         struct fd_list * li;
    280         int cmp = -1;
    281        
    282         TRACE_ENTRY("%p %p %u %i %i %i %i", list, sa, sl, conf, disc, adv, ll);
    283         CHECK_PARAMS( list && sa && (sl <= sizeof(sSS)) && (conf || disc || adv || ll) );
    284        
    285         /* Search place in the list */
    286         for (li = list->next; li != list; li = li->next) {
    287                 ep = (struct fd_endpoint *)li;
    288                
    289                 cmp = memcmp(&ep->ss, sa, sl);
    290                 if (cmp >= 0)
    291                         break;
    292         }
    293        
    294         if (cmp) {
    295                 /* new item to be added */
    296                 CHECK_MALLOC( ep = malloc(sizeof(struct fd_endpoint)) );
    297                 memset(ep, 0, sizeof(struct fd_endpoint));
    298                 fd_list_init(&ep->chain, NULL);
    299                 memcpy(&ep->ss, sa, sl);
    300                
    301                 /* Insert in the list */
    302                 fd_list_insert_before(li, &ep->chain);
    303         }
    304        
    305         /* Merge the flags */
    306         ep->meta.conf = conf || ep->meta.conf;
    307         ep->meta.disc = disc || ep->meta.disc;
    308         ep->meta.adv  =  adv || ep->meta.adv;
    309         ep->meta.ll   =   ll || ep->meta.ll;
    310        
    311         return 0;
    312 }
    313 
  • freeDiameter/fD.h

    r23 r24  
    207207int fd_cnx_serv_listen(struct cnxctx * conn);
    208208struct cnxctx * fd_cnx_serv_accept(struct cnxctx * serv);
    209 struct cnxctx * fd_cnx_cli_connect(int proto, const sSA * sa,  socklen_t addrlen);
     209struct cnxctx * fd_cnx_cli_connect_tcp(sSA * sa, socklen_t addrlen);
     210struct cnxctx * fd_cnx_cli_connect_sctp(int no_ip6, uint16_t port, struct fd_list * list);
    210211char * fd_cnx_getid(struct cnxctx * conn);
    211212int fd_cnx_start_clear(struct cnxctx * conn);
     
    222223int fd_tcp_create_bind_server( int * sock, sSA * sa, socklen_t salen );
    223224int fd_tcp_listen( int sock );
     225int fd_tcp_client( int *sock, sSA * sa, socklen_t salen );
    224226int fd_tcp_get_local_ep(int sock, sSS * ss, socklen_t *sl);
    225227int fd_tcp_get_remote_ep(int sock, sSS * ss, socklen_t *sl);
     
    229231int fd_sctp_create_bind_server( int * sock, struct fd_list * list, uint16_t port );
    230232int fd_sctp_listen( int sock );
     233int fd_sctp_client( int *sock, int no_ip6, uint16_t port, struct fd_list * list );
    231234int fd_sctp_get_local_ep(int sock, struct fd_list * list);
    232235int fd_sctp_get_remote_ep(int sock, struct fd_list * list);
    233 int fd_sctp_get_str_info( int socket, int *in, int *out );
     236int fd_sctp_get_str_info( int sock, int *in, int *out, sSS *primary );
    234237
    235238#endif /* DISABLE_SCTP */
  • freeDiameter/fdd.y

    r23 r24  
    219219                                ret = getaddrinfo($3, NULL, &hints, &ai);
    220220                                if (ret) { yyerror (&yylloc, conf, gai_strerror(ret)); YYERROR; }
    221                                 CHECK_FCT_DO( fd_ep_add_merge( &conf->cnf_endpoints, ai->ai_addr, ai->ai_addrlen, 1, 0, 0, 0 ), YYERROR );
     221                                CHECK_FCT_DO( fd_ep_add_merge( &conf->cnf_endpoints, ai->ai_addr, ai->ai_addrlen, EP_FL_CONF ), YYERROR );
    222222                                freeaddrinfo(ai);
    223223                                free($3);
     
    430430                                if (ret == EAI_NONAME) {
    431431                                        /* The name was maybe not numeric, try again */
    432                                         disc = 1;
     432                                        disc = EP_FL_DISC;
    433433                                        hints.ai_flags &= ~ AI_NUMERICHOST;
    434434                                        ret = getaddrinfo($4, NULL, &hints, &ai);
     
    436436                                if (ret) { yyerror (&yylloc, conf, gai_strerror(ret)); YYERROR; }
    437437                               
    438                                 CHECK_FCT_DO( fd_ep_add_merge( &fddpi.pi_endpoints, ai->ai_addr, ai->ai_addrlen, 1, disc, 0, 0 ), YYERROR );
     438                                CHECK_FCT_DO( fd_ep_add_merge( &fddpi.pi_endpoints, ai->ai_addr, ai->ai_addrlen, EP_FL_CONF | disc ), YYERROR );
    439439                                free($4);
    440440                                freeaddrinfo(ai);
  • freeDiameter/sctp.c

    r23 r24  
    7676                }
    7777               
    78                 TRACE_DEBUG(FULL, "SCTP_EVENTS sctp_data_io_event          : %hhu", event.sctp_data_io_event);
    79                 TRACE_DEBUG(FULL, "SCTP_EVENTS sctp_association_event      : %hhu", event.sctp_association_event);
    80                 TRACE_DEBUG(FULL, "SCTP_EVENTS sctp_address_event          : %hhu", event.sctp_address_event);
    81                 TRACE_DEBUG(FULL, "SCTP_EVENTS sctp_send_failure_event     : %hhu", event.sctp_send_failure_event);
    82                 TRACE_DEBUG(FULL, "SCTP_EVENTS sctp_peer_error_event       : %hhu", event.sctp_peer_error_event);
    83                 TRACE_DEBUG(FULL, "SCTP_EVENTS sctp_shutdown_event         : %hhu", event.sctp_shutdown_event);
    84                 TRACE_DEBUG(FULL, "SCTP_EVENTS sctp_partial_delivery_event : %hhu", event.sctp_partial_delivery_event);
    85                 TRACE_DEBUG(FULL, "SCTP_EVENTS sctp_adaptation_layer_event : %hhu", event.sctp_adaptation_layer_event);
    86                 // TRACE_DEBUG(FULL, "SCTP_EVENTS sctp_authentication_event   : %hhu", event.sctp_authentication_event);
     78                TRACE_DEBUG(FULL, "SCTP_EVENTS : sctp_data_io_event          : %hhu", event.sctp_data_io_event);
     79                TRACE_DEBUG(FULL, "              sctp_association_event      : %hhu", event.sctp_association_event);
     80                TRACE_DEBUG(FULL, "              sctp_address_event          : %hhu", event.sctp_address_event);
     81                TRACE_DEBUG(FULL, "              sctp_send_failure_event     : %hhu", event.sctp_send_failure_event);
     82                TRACE_DEBUG(FULL, "              sctp_peer_error_event       : %hhu", event.sctp_peer_error_event);
     83                TRACE_DEBUG(FULL, "              sctp_shutdown_event         : %hhu", event.sctp_shutdown_event);
     84                TRACE_DEBUG(FULL, "              sctp_partial_delivery_event : %hhu", event.sctp_partial_delivery_event);
     85                TRACE_DEBUG(FULL, "              sctp_adaptation_layer_event : %hhu", event.sctp_adaptation_layer_event);
     86                // TRACE_DEBUG(FULL, "             sctp_authentication_event    : %hhu", event.sctp_authentication_event);
    8787                #endif /* DEBUG_SCTP */
    8888               
     
    104104                        return ENOTSUP;
    105105                }
    106                 TRACE_DEBUG(FULL, "Def SCTP_INITMSG sinit_num_ostreams   : %hu", init.sinit_num_ostreams);
    107                 TRACE_DEBUG(FULL, "Def SCTP_INITMSG sinit_max_instreams  : %hu", init.sinit_max_instreams);
    108                 TRACE_DEBUG(FULL, "Def SCTP_INITMSG sinit_max_attempts   : %hu", init.sinit_max_attempts);
    109                 TRACE_DEBUG(FULL, "Def SCTP_INITMSG sinit_max_init_timeo : %hu", init.sinit_max_init_timeo);
     106                TRACE_DEBUG(FULL, "Def SCTP_INITMSG : sinit_num_ostreams   : %hu", init.sinit_num_ostreams);
     107                TRACE_DEBUG(FULL, "                  sinit_max_instreams  : %hu", init.sinit_max_instreams);
     108                TRACE_DEBUG(FULL, "                  sinit_max_attempts   : %hu", init.sinit_max_attempts);
     109                TRACE_DEBUG(FULL, "                  sinit_max_init_timeo : %hu", init.sinit_max_init_timeo);
    110110                #endif /* DEBUG_SCTP */
    111111
     
    120120                /* Check new values */
    121121                CHECK_SYS(  getsockopt(sk, IPPROTO_SCTP, SCTP_INITMSG, &init, &sz)  );
    122                 TRACE_DEBUG(FULL, "New SCTP_INITMSG sinit_num_ostreams   : %hu", init.sinit_num_ostreams);
    123                 TRACE_DEBUG(FULL, "New SCTP_INITMSG sinit_max_instreams  : %hu", init.sinit_max_instreams);
    124                 TRACE_DEBUG(FULL, "New SCTP_INITMSG sinit_max_attempts   : %hu", init.sinit_max_attempts);
    125                 TRACE_DEBUG(FULL, "New SCTP_INITMSG sinit_max_init_timeo : %hu", init.sinit_max_init_timeo);
     122                TRACE_DEBUG(FULL, "New SCTP_INITMSG : sinit_num_ostreams   : %hu", init.sinit_num_ostreams);
     123                TRACE_DEBUG(FULL, "                  sinit_max_instreams  : %hu", init.sinit_max_instreams);
     124                TRACE_DEBUG(FULL, "                  sinit_max_attempts   : %hu", init.sinit_max_attempts);
     125                TRACE_DEBUG(FULL, "                  sinit_max_init_timeo : %hu", init.sinit_max_init_timeo);
    126126                #endif /* DEBUG_SCTP */
    127127        }
     
    175175                        return ENOTSUP;
    176176                }
    177                 TRACE_DEBUG(FULL, "Def SCTP_RTOINFO srto_initial : %u", rtoinfo.srto_initial);
    178                 TRACE_DEBUG(FULL, "Def SCTP_RTOINFO srto_max     : %u", rtoinfo.srto_max);
    179                 TRACE_DEBUG(FULL, "Def SCTP_RTOINFO srto_min     : %u", rtoinfo.srto_min);
     177                TRACE_DEBUG(FULL, "Def SCTP_RTOINFO : srto_initial : %u", rtoinfo.srto_initial);
     178                TRACE_DEBUG(FULL, "                  srto_max     : %u", rtoinfo.srto_max);
     179                TRACE_DEBUG(FULL, "                  srto_min     : %u", rtoinfo.srto_min);
    180180                #endif /* DEBUG_SCTP */
    181181
     
    188188                /* Check new values */
    189189                CHECK_SYS(  getsockopt(sk, IPPROTO_SCTP, SCTP_RTOINFO, &rtoinfo, &sz)  );
    190                 TRACE_DEBUG(FULL, "New SCTP_RTOINFO srto_initial : %u", rtoinfo.srto_initial);
    191                 TRACE_DEBUG(FULL, "New SCTP_RTOINFO srto_max     : %u", rtoinfo.srto_max);
    192                 TRACE_DEBUG(FULL, "New SCTP_RTOINFO srto_min     : %u", rtoinfo.srto_min);
     190                TRACE_DEBUG(FULL, "New SCTP_RTOINFO : srto_initial : %u", rtoinfo.srto_initial);
     191                TRACE_DEBUG(FULL, "                  srto_max     : %u", rtoinfo.srto_max);
     192                TRACE_DEBUG(FULL, "                  srto_min     : %u", rtoinfo.srto_min);
    193193                #endif /* DEBUG_SCTP */
    194194        }
     
    214214                        return ENOTSUP;
    215215                }
    216                 TRACE_DEBUG(FULL, "Def SCTP_ASSOCINFO sasoc_asocmaxrxt               : %hu", assoc.sasoc_asocmaxrxt);
    217                 TRACE_DEBUG(FULL, "Def SCTP_ASSOCINFO sasoc_number_peer_destinations : %hu", assoc.sasoc_number_peer_destinations);
    218                 TRACE_DEBUG(FULL, "Def SCTP_ASSOCINFO sasoc_peer_rwnd                : %u" , assoc.sasoc_peer_rwnd);
    219                 TRACE_DEBUG(FULL, "Def SCTP_ASSOCINFO sasoc_local_rwnd               : %u" , assoc.sasoc_local_rwnd);
    220                 TRACE_DEBUG(FULL, "Def SCTP_ASSOCINFO sasoc_cookie_life              : %u" , assoc.sasoc_cookie_life);
     216                TRACE_DEBUG(FULL, "Def SCTP_ASSOCINFO : sasoc_asocmaxrxt               : %hu", assoc.sasoc_asocmaxrxt);
     217                TRACE_DEBUG(FULL, "                    sasoc_number_peer_destinations : %hu", assoc.sasoc_number_peer_destinations);
     218                TRACE_DEBUG(FULL, "                    sasoc_peer_rwnd                : %u" , assoc.sasoc_peer_rwnd);
     219                TRACE_DEBUG(FULL, "                    sasoc_local_rwnd               : %u" , assoc.sasoc_local_rwnd);
     220                TRACE_DEBUG(FULL, "                    sasoc_cookie_life              : %u" , assoc.sasoc_cookie_life);
    221221                #endif /* DEBUG_SCTP */
    222222
     
    229229                /* Check new values */
    230230                CHECK_SYS(  getsockopt(sk, IPPROTO_SCTP, SCTP_ASSOCINFO, &assoc, &sz)  );
    231                 TRACE_DEBUG(FULL, "New SCTP_ASSOCINFO sasoc_asocmaxrxt               : %hu", assoc.sasoc_asocmaxrxt);
    232                 TRACE_DEBUG(FULL, "New SCTP_ASSOCINFO sasoc_number_peer_destinations : %hu", assoc.sasoc_number_peer_destinations);
    233                 TRACE_DEBUG(FULL, "New SCTP_ASSOCINFO sasoc_peer_rwnd                : %u" , assoc.sasoc_peer_rwnd);
    234                 TRACE_DEBUG(FULL, "New SCTP_ASSOCINFO sasoc_local_rwnd               : %u" , assoc.sasoc_local_rwnd);
    235                 TRACE_DEBUG(FULL, "New SCTP_ASSOCINFO sasoc_cookie_life              : %u" , assoc.sasoc_cookie_life);
     231                TRACE_DEBUG(FULL, "New SCTP_ASSOCINFO : sasoc_asocmaxrxt               : %hu", assoc.sasoc_asocmaxrxt);
     232                TRACE_DEBUG(FULL, "                    sasoc_number_peer_destinations : %hu", assoc.sasoc_number_peer_destinations);
     233                TRACE_DEBUG(FULL, "                    sasoc_peer_rwnd                : %u" , assoc.sasoc_peer_rwnd);
     234                TRACE_DEBUG(FULL, "                    sasoc_local_rwnd               : %u" , assoc.sasoc_local_rwnd);
     235                TRACE_DEBUG(FULL, "                    sasoc_cookie_life              : %u" , assoc.sasoc_cookie_life);
    236236                #endif /* DEBUG_SCTP */
    237237        }
     
    258258                        return ENOTSUP;
    259259                }
    260                 TRACE_DEBUG(FULL, "Def SO_LINGER l_onoff  : %d", linger.l_onoff);
    261                 TRACE_DEBUG(FULL, "Def SO_LINGER l_linger : %d", linger.l_linger);
     260                TRACE_DEBUG(FULL, "Def SO_LINGER : l_onoff  : %d", linger.l_onoff);
     261                TRACE_DEBUG(FULL, "                l_linger : %d", linger.l_linger);
    262262                #endif /* DEBUG_SCTP */
    263263               
     
    271271                /* Check new values */
    272272                CHECK_SYS(  getsockopt(sk, SOL_SOCKET, SO_LINGER, &linger, &sz)  );
    273                 TRACE_DEBUG(FULL, "New SO_LINGER l_onoff  : %d", linger.l_onoff);
    274                 TRACE_DEBUG(FULL, "New SO_LINGER l_linger : %d", linger.l_linger);
     273                TRACE_DEBUG(FULL, "New SO_LINGER : l_onoff  : %d", linger.l_onoff);
     274                TRACE_DEBUG(FULL, "                l_linger : %d", linger.l_linger);
    275275                #endif /* DEBUG_SCTP */
    276276        }
     
    370370                #endif /* DEBUG_SCTP */
    371371
     372#ifndef SCTP_USE_MAPPED_ADDRESSES
    372373                v4mapped = 0;   /* We don't want v4 mapped addresses */
    373                 v4mapped = 1;   /* but we have to, otherwise the bind fails in linux currently ... (Ok, It'd be better with a cmake test, any volunteer?) */
     374#else /* SCTP_USE_MAPPED_ADDRESSES */
     375                v4mapped = 1;   /* but we may have to, otherwise the bind fails in some environments */
     376#endif /* SCTP_USE_MAPPED_ADDRESSES */
    374377               
    375378                /* Set the option to the socket */
     
    422425        */
    423426       
    424         /* In case of no_ip4, force the v6only option */
     427        /* In case of no_ip4, force the v6only option -- is it a valid option for SCTP ? */
    425428        #ifdef IPV6_V6ONLY
    426429        if (fd_g_config->cnf_flags.no_ip4) {
     
    526529        } else {
    527530                /* Explicit endpoints to bind to from config */
     531               
    528532                union {
    529                         sSA     *sa;
    530                         sSA4    *sin;
    531                         sSA6    *sin6;
    532                 } sar; /* build the list of endpoints to bind to */
     533                        sSA     * sa;
     534                        sSA4    *sin;
     535                        sSA6    *sin6;
     536                        uint8_t *buf;
     537                } ptr;
     538                union {
     539                        sSA     * sa;
     540                        uint8_t * buf;
     541                } sar;
    533542                int count = 0; /* number of sock addr in sar array */
     543                size_t offset = 0;
    534544                struct fd_list * li;
    535545               
    536                 sar.sa = NULL;
     546                sar.buf = NULL;
    537547               
    538548                /* Create a flat array from the list of configured addresses */
    539549                for (li = list->next; li != list; li = li->next) {
    540550                        struct fd_endpoint * ep = (struct fd_endpoint *)li;
     551                        size_t sz = 0;
    541552                       
    542                         if ( ! ep->meta.conf )
     553                        if (! (ep->flags & EP_FL_CONF))
    543554                                continue;
    544555                       
    545556                        count++;
    546                         if (fd_g_config->cnf_flags.no_ip6) {
    547                                 ASSERT(ep->sa.sa_family == AF_INET);
    548                                 CHECK_MALLOC( sar.sa = realloc(sar.sa, count * sizeof(sSA4))  );
    549                                 memcpy(&sar.sin[count - 1], &ep->sin, sizeof(sSA4));
    550                                 sar.sin[count - 1].sin_port = htons(port);
     557                       
     558                        /* Size of the new SA we are adding (sar may contain a mix of sockaddr_in and sockaddr_in6) */
     559#ifndef SCTP_USE_MAPPED_ADDRESSES
     560                        if (ep->sa.sa_family == AF_INET6)
     561#else /* SCTP_USE_MAPPED_ADDRESSES */
     562                        if (family == AF_INET6)
     563#endif /* SCTP_USE_MAPPED_ADDRESSES */
     564                                sz = sizeof(sSA6);
     565                        else
     566                                sz = sizeof(sSA4);
     567                       
     568                        /* augment sar to contain the additional info */
     569                        CHECK_MALLOC( sar.buf = realloc(sar.buf, offset + sz)  );
     570                       
     571                        ptr.buf = sar.buf + offset; /* place of the new SA */
     572                        offset += sz; /* update to end of sar */
     573                       
     574                        if (sz == sizeof(sSA4)) {
     575                                memcpy(ptr.buf, &ep->sin, sz);
     576                                ptr.sin->sin_port = htons(port);
    551577                        } else {
    552                                 /* Pass all addresses as IPv6, eventually mapped -- we already filtered out IPv4 addresses if no_ip4 flag is set */
    553                                 CHECK_MALLOC( sar.sa = realloc(sar.sa, count * sizeof(sSA6))  );
    554                                 if (ep->sa.sa_family == AF_INET) {
    555                                         memset(&sar.sin6[count - 1], 0, sizeof(sSA6));
    556                                         sar.sin6[count - 1].sin6_family = AF_INET6;
    557                                         IN6_ADDR_V4MAP( &sar.sin6[count - 1].sin6_addr.s6_addr, ep->sin.sin_addr.s_addr );
     578                                if (ep->sa.sa_family == AF_INET) { /* We must map the address */
     579                                        memset(ptr.buf, 0, sz);
     580                                        ptr.sin6->sin6_family = AF_INET6;
     581                                        IN6_ADDR_V4MAP( &ptr.sin6->sin6_addr.s6_addr, ep->sin.sin_addr.s_addr );
    558582                                } else {
    559                                         memcpy(&sar.sin6[count - 1], &ep->sin6, sizeof(sSA6));
     583                                        memcpy(ptr.sin6, &ep->sin6, sz);
    560584                                }
    561                                 sar.sin6[count - 1].sin6_port = htons(port);
     585                                ptr.sin6->sin6_port = htons(port);
    562586                        }
    563587                }
     
    572596                if (TRACE_BOOL(FULL)) {
    573597                        int i;
    574                         fd_log_debug("Calling sctp_bindx with the following array:\n");
     598                        ptr.buf = sar.buf;
     599                        fd_log_debug("Calling sctp_bindx with the following address array:\n");
    575600                        for (i = 0; i < count; i++) {
    576                                 fd_log_debug("    - ");
    577                                 sSA_DUMP_NODE_SERV( (sar.sa[0].sa_family == AF_INET) ? (sSA *)(&sar.sin[i]) : (sSA *)(&sar.sin6[i]), NI_NUMERICHOST | NI_NUMERICSERV );
    578                                 fd_log_debug("\n");
     601                                TRACE_DEBUG_sSA(FULL, "    - ", ptr.sa, NI_NUMERICHOST | NI_NUMERICSERV, "" );
     602                                ptr.buf += (ptr.sa->sa_family == AF_INET) ? sizeof(sSA4) : sizeof(sSA6) ;
    579603                        }
    580604                }
    581605                #endif /* DEBUG_SCTP */
    582606               
     607                /* Bind to this array */
    583608                CHECK_SYS(  sctp_bindx(*sock, sar.sa, count, SCTP_BINDX_ADD_ADDR)  );
    584609               
     610                /* We don't need sar anymore */
     611                free(sar.buf);
    585612        }
    586613       
     
    591618        /* Debug: show all local listening addresses */
    592619        if (TRACE_BOOL(FULL)) {
    593                 sSA *sa, *sar;
     620                sSA *sar;
     621                union {
     622                        sSA     *sa;
     623                        uint8_t *buf;
     624                } ptr;
    594625                int sz;
    595626               
     
    597628               
    598629                fd_log_debug("SCTP server bound on :\n");
    599                 for (sa = sar; sz-- > 0; sa = (sSA *)(((uint8_t *)sa) + ((sa->sa_family == AF_INET) ? sizeof(sSA4) : sizeof(sSA6)))) {
    600                         fd_log_debug("    - ");
    601                         sSA_DUMP_NODE_SERV( sa, NI_NUMERICHOST | NI_NUMERICSERV );
    602                         fd_log_debug("\n");
     630                for (ptr.sa = sar; sz-- > 0; ptr.buf += (ptr.sa->sa_family == AF_INET) ? sizeof(sSA4) : sizeof(sSA6)) {
     631                        TRACE_DEBUG_sSA(FULL, "    - ", ptr.sa, NI_NUMERICHOST | NI_NUMERICSERV, "" );
    603632                }
    604633                sctp_freeladdrs(sar);
     
    617646}
    618647
    619 /* Retrieve streams information from a connected association */
    620 int fd_sctp_get_str_info( int socket, int *in, int *out )
     648/* Create a client socket and connect to remote server */
     649int fd_sctp_client( int *sock, int no_ip6, uint16_t port, struct fd_list * list )
    621650{
    622         TODO("Retrieve streams info from the socket");
    623        
    624         return ENOTSUP;
     651        int family;
     652        int count = 0;
     653        size_t offset = 0, sz;
     654        union {
     655                uint8_t *buf;
     656                sSA     *sa;
     657        } sar;
     658        union {
     659                uint8_t *buf;
     660                sSA     *sa;
     661                sSA4    *sin;
     662                sSA6    *sin6;
     663        } ptr;
     664        struct fd_list * li;
     665        int ret;
     666       
     667        sar.buf = NULL;
     668       
     669        TRACE_ENTRY("%p %i %hu %p", sock, no_ip6, port, list);
     670        CHECK_PARAMS( sock && list && (!FD_IS_LIST_EMPTY(list)) );
     671       
     672        if (no_ip6) {
     673                family = AF_INET;
     674        } else {
     675                family = AF_INET6;
     676        }
     677       
     678        /* Create the socket */
     679        CHECK_SYS( *sock = socket(family, SOCK_STREAM, IPPROTO_SCTP) );
     680       
     681        /* Cleanup if we are cancelled */
     682        pthread_cleanup_push(fd_cleanup_socket, sock);
     683       
     684        /* Set the socket options */
     685        CHECK_FCT_DO( ret = fd_setsockopt_prebind(*sock), goto fail );
     686       
     687        /* Create the array of addresses for sctp_connectx */
     688        for (li = list->next; li != list; li = li->next) {
     689                struct fd_endpoint * ep = (struct fd_endpoint *) li;
     690               
     691                count++;
     692               
     693                /* Size of the new SA we are adding (sar may contain a mix of sockaddr_in and sockaddr_in6) */
     694#ifndef SCTP_USE_MAPPED_ADDRESSES
     695                if (ep->sa.sa_family == AF_INET6)
     696#else /* SCTP_USE_MAPPED_ADDRESSES */
     697                if (family == AF_INET6)
     698#endif /* SCTP_USE_MAPPED_ADDRESSES */
     699                        sz = sizeof(sSA6);
     700                else
     701                        sz = sizeof(sSA4);
     702               
     703                /* augment sar to contain the additional info */
     704                CHECK_MALLOC_DO( sar.buf = realloc(sar.buf, offset + sz), { ret = ENOMEM; goto fail; }  );
     705
     706                ptr.buf = sar.buf + offset; /* place of the new SA */
     707                offset += sz; /* update to end of sar */
     708                       
     709                if (sz == sizeof(sSA4)) {
     710                        memcpy(ptr.buf, &ep->sin, sz);
     711                        ptr.sin->sin_port = htons(port);
     712                } else {
     713                        if (ep->sa.sa_family == AF_INET) { /* We must map the address */
     714                                memset(ptr.buf, 0, sz);
     715                                ptr.sin6->sin6_family = AF_INET6;
     716                                IN6_ADDR_V4MAP( &ptr.sin6->sin6_addr.s6_addr, ep->sin.sin_addr.s_addr );
     717                        } else {
     718                                memcpy(ptr.sin6, &ep->sin6, sz);
     719                        }
     720                        ptr.sin6->sin6_port = htons(port);
     721                }
     722        }
     723       
     724        /* Try connecting */
     725        TRACE_DEBUG(FULL, "Attempting SCTP connection (%d addresses attempted)...", count);
     726        CHECK_SYS_DO( sctp_connectx(*sock, sar.sa, count), { ret = errno; goto fail; } );
     727        free(sar.buf); sar.buf = NULL;
     728       
     729        /* Set the remaining sockopts */
     730        CHECK_FCT_DO( ret = fd_setsockopt_postbind(*sock, 1), goto fail );
     731       
     732        /* Done! */
     733        pthread_cleanup_pop(0);
     734        return 0;
     735       
     736fail:
     737        if (*sock > 0) {
     738                shutdown(*sock, SHUT_RDWR);
     739                *sock = -1;
     740        }
     741        free(sar.buf);
     742        return ret;
     743}
     744
     745/* Retrieve streams information from a connected association -- optionaly provide the primary address */
     746int fd_sctp_get_str_info( int sock, int *in, int *out, sSS *primary )
     747{
     748        struct sctp_status status;
     749        socklen_t sz = sizeof(status);
     750       
     751        TRACE_ENTRY("%d %p %p %p", sock, in, out, primary);
     752        CHECK_PARAMS( (sock > 0) && in && out );
     753       
     754        /* Read the association parameters */
     755        memset(&status, 0, sizeof(status));
     756        CHECK_SYS(  getsockopt(sock, IPPROTO_SCTP, SCTP_STATUS, &status, &sz) );
     757        if (sz != sizeof(status))
     758        {
     759                TRACE_DEBUG(INFO, "Invalid size of socket option: %d / %g", sz, sizeof(status));
     760                return ENOTSUP;
     761        }
     762        #ifdef DEBUG_SCTP
     763        TRACE_DEBUG(FULL, "SCTP_STATUS : sstat_state                  : %i" , status.sstat_state);
     764        TRACE_DEBUG(FULL, "              sstat_rwnd                   : %u" , status.sstat_rwnd);
     765        TRACE_DEBUG(FULL, "              sstat_unackdata              : %hu", status.sstat_unackdata);
     766        TRACE_DEBUG(FULL, "              sstat_penddata               : %hu", status.sstat_penddata);
     767        TRACE_DEBUG(FULL, "              sstat_instrms                : %hu", status.sstat_instrms);
     768        TRACE_DEBUG(FULL, "              sstat_outstrms               : %hu", status.sstat_outstrms);
     769        TRACE_DEBUG(FULL, "              sstat_fragmentation_point    : %u" , status.sstat_fragmentation_point);
     770        TRACE_DEBUG_sSA(FULL, "          sstat_primary.spinfo_address : ", &status.sstat_primary.spinfo_address, NI_NUMERICHOST | NI_NUMERICSERV, "" );
     771        TRACE_DEBUG(FULL, "              sstat_primary.spinfo_state   : %d" , status.sstat_primary.spinfo_state);
     772        TRACE_DEBUG(FULL, "              sstat_primary.spinfo_cwnd    : %u" , status.sstat_primary.spinfo_cwnd);
     773        TRACE_DEBUG(FULL, "              sstat_primary.spinfo_srtt    : %u" , status.sstat_primary.spinfo_srtt);
     774        TRACE_DEBUG(FULL, "              sstat_primary.spinfo_rto     : %u" , status.sstat_primary.spinfo_rto);
     775        TRACE_DEBUG(FULL, "              sstat_primary.spinfo_mtu     : %u" , status.sstat_primary.spinfo_mtu);
     776        #endif /* DEBUG_SCTP */
     777       
     778        *in = (int)status.sstat_instrms;
     779        *out = (int)status.sstat_outstrms;
     780       
     781        if (primary)
     782                memcpy(primary, &status.sstat_primary.spinfo_address, sizeof(sSS));
     783       
     784        return 0;
    625785}
    626786
     
    630790        union {
    631791                sSA     *sa;
    632                 sSA4    *sin;
    633                 sSA6    *sin6;
    634792                uint8_t *buf;
    635793        } ptr;
     
    646804       
    647805        while (count) {
    648                 TODO("get the data from ptr");
    649                 TODO("Increment ptr to the next sa in data");
    650                
     806                socklen_t sl;
     807                switch (ptr.sa->sa_family) {
     808                        case AF_INET:   sl = sizeof(sSA4); break;
     809                        case AF_INET6:  sl = sizeof(sSA6); break;
     810                        default:
     811                                TRACE_DEBUG(INFO, "Unkown address family returned in sctp_getladdrs: %d", ptr.sa->sa_family);
     812                }
     813                               
     814                CHECK_FCT( fd_ep_add_merge( list, ptr.sa, sl, EP_FL_LL ) );
     815                ptr.buf += sl;
    651816                count --;
    652817        }
    653818       
    654         /* And now, free the list and return */
     819        /* Free the list */
    655820        sctp_freeladdrs(data);
    656821       
    657         return ENOTSUP;
     822        /* Now get the primary address, the add function will take care of merging with existing entry */
     823        {
     824                 
     825                struct sctp_status status;
     826                socklen_t sz = sizeof(status);
     827                int ret;
     828               
     829                memset(&status, 0, sizeof(status));
     830                /* Attempt to use SCTP_STATUS message to retrieve the primary address */
     831                ret = getsockopt(sock, IPPROTO_SCTP, SCTP_STATUS, &status, &sz);
     832                if (sz != sizeof(status))
     833                        ret = -1;
     834                sz = sizeof(sSS);
     835                if (ret < 0)
     836                {
     837                        /* Fallback to getsockname -- not recommended by draft-ietf-tsvwg-sctpsocket-19#section-7.4 */
     838                        CHECK_SYS(getsockname(sock, (sSA *)&status.sstat_primary.spinfo_address, &sz));
     839                }
     840                       
     841                CHECK_FCT( fd_ep_add_merge( list, (sSA *)&status.sstat_primary.spinfo_address, sz, EP_FL_PRIMARY ) );
     842        }
     843       
     844        return 0;
    658845}
    659846
     
    661848int fd_sctp_get_remote_ep(int sock, struct fd_list * list)
    662849{
    663         TODO("SCTP: sctp_getpaddrs");
    664                
    665        
    666         return ENOTSUP;
     850        union {
     851                sSA     *sa;
     852                uint8_t *buf;
     853        } ptr;
     854       
     855        sSA * data;
     856        int count;
     857       
     858        TRACE_ENTRY("%d %p", sock, list);
     859        CHECK_PARAMS(list);
     860       
     861        /* Read the list on the socket */
     862        CHECK_SYS( count = sctp_getpaddrs(sock, 0, &data)  );
     863        ptr.sa = data;
     864       
     865        while (count) {
     866                socklen_t sl;
     867                switch (ptr.sa->sa_family) {
     868                        case AF_INET:   sl = sizeof(sSA4); break;
     869                        case AF_INET6:  sl = sizeof(sSA6); break;
     870                        default:
     871                                TRACE_DEBUG(INFO, "Unkown address family returned in sctp_getpaddrs: %d", ptr.sa->sa_family);
     872                }
     873                               
     874                CHECK_FCT( fd_ep_add_merge( list, ptr.sa, sl, EP_FL_LL ) );
     875                ptr.buf += sl;
     876                count --;
     877        }
     878       
     879        /* Free the list */
     880        sctp_freepaddrs(data);
     881       
     882        /* Now get the primary address, the add function will take care of merging with existing entry */
     883        {
     884                sSS ss;
     885                socklen_t sl = sizeof(sSS);
     886       
     887                CHECK_SYS(getpeername(sock, (sSA *)&ss, &sl));
     888                CHECK_FCT( fd_ep_add_merge( list, (sSA *)&ss, sl, EP_FL_PRIMARY ) );
     889        }
     890       
     891        /* Done! */
     892        return 0;
    667893}
    668894
  • freeDiameter/server.c

    r22 r24  
    291291                                struct fd_endpoint * ep = (struct fd_endpoint *)li;
    292292                                sSA * sa = (sSA *) &ep->ss;
    293                                 if (! ep->meta.conf)
     293                                if (! (ep->flags & EP_FL_CONF))
    294294                                        continue;
    295295                                if (fd_g_config->cnf_flags.no_ip4 && (sa->sa_family == AF_INET))
  • freeDiameter/tcp.c

    r23 r24  
    113113}
    114114
     115/* Create a client socket and connect to remote server */
     116int fd_tcp_client( int *sock, sSA * sa, socklen_t salen )
     117{
     118        TRACE_ENTRY("%p %p %d", sock, sa, salen);
     119        CHECK_PARAMS( sock && sa && salen );
     120       
     121        /* Create the socket */
     122        CHECK_SYS(  *sock = socket(sa->sa_family, SOCK_STREAM, IPPROTO_TCP)  );
     123       
     124        /* Cleanup if we are cancelled */
     125        pthread_cleanup_push(fd_cleanup_socket, sock);
     126       
     127        /* Set the socket options */
     128        CHECK_FCT(  fd_tcp_setsockopt(sa->sa_family, *sock)  );
     129       
     130        TRACE_DEBUG_sSA(FULL, "Attempting TCP connection with peer: ", sa, NI_NUMERICHOST | NI_NUMERICSERV, "..." );
     131       
     132        /* Try connecting to the remote address */
     133        CHECK_SYS( connect(*sock, sa, salen) );
     134       
     135        /* Done! */
     136        pthread_cleanup_pop(0);
     137        return 0;
     138}
     139
     140
    115141/* Get the local name of a TCP socket -- would be nice if it did not return "0.0.0.0"... */
    116142int fd_tcp_get_local_ep(int sock, sSS * ss, socklen_t *sl)
  • include/freeDiameter/CMakeLists.txt

    r23 r24  
    1313IF (NOT DISABLE_SCTP)
    1414        OPTION(DEBUG_SCTP "Verbose SCTP (for debug)?" OFF)
     15        OPTION(SCTP_USE_MAPPED_ADDRESSES "Use v6-mapped v4 addresses in SCTP (workaround some SCTP limitations)?" OFF)
    1516ENDIF (NOT DISABLE_SCTP)
    1617
  • include/freeDiameter/freeDiameter-host.h.in

    r23 r24  
    4646#cmakedefine DISABLE_SCTP
    4747#cmakedefine DEBUG_SCTP
     48#cmakedefine SCTP_USE_MAPPED_ADDRESSES
    4849#cmakedefine ERRORS_ON_TODO
    4950#cmakedefine DEBUG
  • include/freeDiameter/freeDiameter.h

    r23 r24  
    118118struct fd_endpoint {
    119119        struct fd_list  chain;  /* link in cnf_endpoints list */
     120       
    120121        union {
    121                 sSS             ss;     /* the socket information. List is always ordered by ss value (memcmp) */
     122                sSS             ss;     /* the socket information. List is always ordered by ss value (memcmp) -- see fd_ep_add_merge */
    122123                sSA4            sin;
    123124                sSA6            sin6;
    124125                sSA             sa;
    125126        };
    126         struct {
    127                 unsigned conf : 1; /* This endpoint is statically configured in a configuration file */
    128                 unsigned disc : 1; /* This endpoint was resolved from the Diameter Identity or other DNS query */
    129                 unsigned adv  : 1; /* This endpoint was advertized in Diameter CER/CEA exchange */
    130                 unsigned ll   : 1; /* Lower layer mechanism provided this endpoint */
    131                
    132                 /* To add: a validity timestamp for DNS records ? How do we retrieve this lifetime from DNS ? */
    133 
    134         }               meta;   /* Additional information about the endpoint */
    135 };
    136 
    137 /* Add a new entry in a list of endpoints -- merge if the sockaddr was already there */
    138 int fd_ep_add_merge( struct fd_list * list, sSA * sa, socklen_t sl, int conf, int disc, int adv, int ll );
     127       
     128#define EP_FL_CONF      (1 << 0)        /* This endpoint is statically configured in a configuration file */
     129#define EP_FL_DISC      (1 << 1)        /* This endpoint was resolved from the Diameter Identity or other DNS query */
     130#define EP_FL_ADV       (1 << 2)        /* This endpoint was advertized in Diameter CER/CEA exchange */
     131#define EP_FL_LL        (1 << 3)        /* Lower layer mechanism provided this endpoint */
     132#define EP_FL_PRIMARY   (1 << 4)        /* This endpoint is primary in a multihomed SCTP association */
     133        uint32_t        flags;          /* Additional information about the endpoint */
     134               
     135        /* To add: a validity timestamp for DNS records ? How do we retrieve this lifetime from DNS ? */
     136};
    139137
    140138/* Applications */
     
    468466
    469467
     468/***************************************/
     469/*   Endpoints lists helpers           */
     470/***************************************/
     471
     472int fd_ep_add_merge( struct fd_list * list, sSA * sa, socklen_t sl, uint32_t flags );
     473int fd_ep_filter( struct fd_list * list, uint32_t flags );
     474int fd_ep_clearflags( struct fd_list * list, uint32_t flags );
     475
     476
     477
    470478#endif /* _FREEDIAMETER_H */
  • include/freeDiameter/libfreeDiameter.h

    r23 r24  
    336336        }                                                       \
    337337}
    338 /* Same, for a service */
    339 #define sSA_DUMP_SERV( sa, flag ) {                             \
    340         sSA * __sa = (sSA *)(sa);                               \
    341         char __servbuf[32];                                     \
    342         if (__sa) {                                             \
    343           int __rc = getnameinfo(__sa,                          \
    344                         sizeof(sSS),                            \
    345                         NULL,                                   \
    346                         0,                                      \
    347                         __servbuf,                              \
    348                         sizeof(__servbuf),                      \
    349                         flag);                                  \
    350           if (__rc)                                             \
    351                 fd_log_debug("%s", (char *)gai_strerror(__rc)); \
    352           else                                                  \
    353                 fd_log_debug("%s", &__servbuf[0]);              \
    354         } else {                                                \
    355                 fd_log_debug("(unknown)");                      \
    356         }                                                       \
    357 }
    358 /* Combine both */
     338/* Same but with the port (service) also */
    359339#define sSA_DUMP_NODE_SERV( sa, flag ) {                                \
    360340        sSA * __sa = (sSA *)(sa);                                       \
     
    376356                fd_log_debug("(NULL / ANY)");                           \
    377357        }                                                               \
     358}
     359/* Inside a debug trace */
     360#define TRACE_DEBUG_sSA(level, prefix, sa, flags, suffix ) {                                                                            \
     361        if ( TRACE_BOOL(level) ) {                                                                                              \
     362                char __buf[25];                                                                                                 \
     363                char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed");                                       \
     364                fd_log_debug("\t | tid:%-20s\t%s\tin %s@%s:%d\n"                                                                \
     365                          "\t%s|%*s" prefix ,                                                                                   \
     366                                        __thn, fd_log_time(NULL, __buf, sizeof(__buf)), __PRETTY_FUNCTION__, __FILE__, __LINE__,\
     367                                        (level < FULL)?"@":" ",level, "");                                                      \
     368                sSA_DUMP_NODE_SERV( sa, flags );                                                                                \
     369                fd_log_debug(suffix "\n");                                                                                      \
     370        }                                                                                                                       \
    378371}
    379372
     
    481474        free(buffer);
    482475}
     476static __inline__ void fd_cleanup_socket(void * sockptr)
     477{
     478        if (sockptr) {
     479                shutdown(*(int *)sockptr, SHUT_RDWR);
     480                *(int *)sockptr = 0;
     481        }
     482}
     483
    483484
    484485/*============================================================*/
Note: See TracChangeset for help on using the changeset viewer.