Navigation


Changeset 1544:7bad8025e69d in freeDiameter


Ignore:
Timestamp:
May 25, 2020, 5:34:47 PM (4 years ago)
Author:
Thomas Klausner <tk@giga.or.at>
Branch:
default
Parents:
1543:9222d31123b1 (diff), 1542:8d7d4e1dfea8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Phase:
public
Message:

merge

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libfdcore/sctp.c

    r1541 r1544  
    111111                        sz = sizeof(rtoinfo);
    112112                        /* Read socket defaults */
    113                         CHECK_SYS(  getsockopt(sk, IPPROTO_SCTP, SCTP_RTOINFO, &rtoinfo, &sz)  );
     113                        CHECK_SYS(  sctp_opt_info(sk, 0, SCTP_RTOINFO, &rtoinfo, &sz)  );
    114114                        if (sz != sizeof(rtoinfo))
    115115                        {
     
    131131                if (TRACE_BOOL(ANNOYING)) {
    132132                        /* Check new values */
    133                         CHECK_SYS(  getsockopt(sk, IPPROTO_SCTP, SCTP_RTOINFO, &rtoinfo, &sz)  );
     133                        CHECK_SYS(  sctp_opt_info(sk, 0, SCTP_RTOINFO, &rtoinfo, &sz)  );
    134134                        fd_log_debug( "New SCTP_RTOINFO : srto_initial : %u", rtoinfo.srto_initial);
    135135                        fd_log_debug( "                   srto_max     : %u", rtoinfo.srto_max);
     
    150150                        sz = sizeof(assoc);
    151151                        /* Read socket defaults */
    152                         CHECK_SYS(  getsockopt(sk, IPPROTO_SCTP, SCTP_ASSOCINFO, &assoc, &sz)  );
     152                        CHECK_SYS(  sctp_opt_info(sk, 0, SCTP_ASSOCINFO, &assoc, &sz)  );
    153153                        if (sz != sizeof(assoc))
    154154                        {
     
    171171                if (TRACE_BOOL(ANNOYING)) {
    172172                        /* Check new values */
    173                         CHECK_SYS(  getsockopt(sk, IPPROTO_SCTP, SCTP_ASSOCINFO, &assoc, &sz)  );
     173                        CHECK_SYS(  sctp_opt_info(sk, 0, SCTP_ASSOCINFO, &assoc, &sz)  );
    174174                        fd_log_debug( "New SCTP_ASSOCINFO : sasoc_asocmaxrxt               : %hu", assoc.sasoc_asocmaxrxt);
    175175                        fd_log_debug( "                     sasoc_number_peer_destinations : %hu", assoc.sasoc_number_peer_destinations);
     
    347347
    348348                        /* Read socket defaults */
    349                         CHECK_SYS(  getsockopt(sk, IPPROTO_SCTP, SCTP_PEER_ADDR_PARAMS, &parms, &sz)  );
     349                        CHECK_SYS(  sctp_opt_info(sk, 0, SCTP_PEER_ADDR_PARAMS, &parms, &sz)  );
    350350                        if (sz != sizeof(parms))
    351351                        {
     
    376376                if (TRACE_BOOL(ANNOYING)) {
    377377                        /* Check new values */
    378                         CHECK_SYS(  getsockopt(sk, IPPROTO_SCTP, SCTP_PEER_ADDR_PARAMS, &parms, &sz)  );
     378                        CHECK_SYS(  sctp_opt_info(sk, 0, SCTP_PEER_ADDR_PARAMS, &parms, &sz)  );
    379379                        fd_log_debug( "New SCTP_PEER_ADDR_PARAMS : spp_hbinterval    : %u",  parms.spp_hbinterval);
    380380                        fd_log_debug( "                            spp_pathmaxrxt    : %hu", parms.spp_pathmaxrxt);
  • libfdcore/sctp.c

    r1543 r1544  
    5959#endif /* USE_DEFAULT_SCTP_RTX_PARAMS */
    6060
     61
     62DECLARE_FD_DUMP_PROTOTYPE(fd_sa_dump_array, sSA * saddrs, int saddrs_count)
     63{
     64        union {
     65                sSA     *sa;
     66                uint8_t *buf;
     67        } ptr;
     68        int i;
     69        int salen;
     70
     71        FD_DUMP_HANDLE_OFFSET();
     72
     73        ptr.sa = saddrs;
     74        for (i = 0; i < saddrs_count; i++) {
     75                salen = sSAlen(ptr.sa);
     76                if (salen == 0) {
     77                        LOG_E("fd_sa_dump_array: Unknown sockaddr family");
     78                        break;
     79                }
     80                if (i > 0) {
     81                        CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, " "), return NULL);
     82                }
     83                CHECK_MALLOC_DO( fd_sa_dump( FD_DUMP_STD_PARAMS, ptr.sa, NI_NUMERICHOST | NI_NUMERICSERV), return NULL);
     84                ptr.buf += salen;
     85        }
     86        return *buf;
     87}
     88
    6189/* Pre-binding socket options -- # streams read in config */
    6290static int fd_setsockopt_prebind(int sk)
     
    815843                        goto redo;
    816844                }
    817                
    818                 #if 0
    819                         union {
    820                                 sSA     *sa;
    821                                 uint8_t *buf;
    822                         } ptr;
    823                         int i;
    824                         ptr.sa = sar;
    825                         fd_log_debug("Calling sctp_bindx with the following address array:");
    826                         for (i = 0; i < count; i++) {
    827                                 TRACE_sSA(FD_LOG_DEBUG, FULL, "    - ", ptr.sa, NI_NUMERICHOST | NI_NUMERICSERV, "" );
    828                                 ptr.buf += (ptr.sa->sa_family == AF_INET) ? sizeof(sSA4) : sizeof(sSA6) ;
    829                         }
    830                 #endif
    831                
     845
     846                /* Debug: show bound addresses */
     847                {
     848                        char * buf = NULL;
     849                        size_t len = 0;
     850                        CHECK_MALLOC_DO( fd_sa_dump_array( &buf, &len, 0, sar, count), );
     851                        LOG_D("SCTP server binding local addresses: %s", buf);
     852                        free(buf);
     853                }
     854
    832855                /* Bind to this array */
    833856                CHECK_SYS(  sctp_bindx(*sock, sar, count, SCTP_BINDX_ADD_ADDR)  );
     
    841864       
    842865        /* Debug: show all local listening addresses */
    843         #if 0
    844                 sSA *sar;
    845                 union {
    846                         sSA     *sa;
    847                         uint8_t *buf;
    848                 } ptr;
    849                 int sz;
    850                
     866        {
     867                sSA *sar = NULL;
     868                int sz = 0;
     869                char * buf = NULL;
     870                size_t len = 0;
     871
    851872                CHECK_SYS(  sz = sctp_getladdrs(*sock, 0, &sar)  );
    852                
    853                 fd_log_debug("SCTP server bound on :");
    854                 for (ptr.sa = sar; sz-- > 0; ptr.buf += (ptr.sa->sa_family == AF_INET) ? sizeof(sSA4) : sizeof(sSA6)) {
    855                         TRACE_sSA(FD_LOG_DEBUG, FULL, "    - ", ptr.sa, NI_NUMERICHOST | NI_NUMERICSERV, "" );
    856                 }
     873
     874                CHECK_MALLOC_DO( fd_sa_dump_array( &buf, &len, 0, sar, sz), );
     875                LOG_D("SCTP server locally bound addresses: %s", buf);
    857876                sctp_freeladdrs(sar);
    858         #endif
     877                free(buf);
     878        }
    859879
    860880        return 0;
     
    870890
    871891/* Create a client socket and connect to remote server */
    872 int fd_sctp_client( int *sock, int no_ip6, uint16_t port, struct fd_list * list )
     892int fd_sctp_client( int *sock, int no_ip6, uint16_t port, struct fd_list * list, struct fd_list * src_list )
    873893{
    874894        int family;
     
    880900        int count = 0;
    881901        int ret;
     902        int bind_default = 1;   /* enable ASCONF in postbind */
    882903       
    883904        sar.buf = NULL;
    884905       
    885         TRACE_ENTRY("%p %i %hu %p", sock, no_ip6, port, list);
     906        TRACE_ENTRY("%p %i %hu %p %p", sock, no_ip6, port, list, src_list);
    886907        CHECK_PARAMS( sock && list && (!FD_IS_LIST_EMPTY(list)) );
     908        CHECK_PARAMS( !src_list || (src_list && (!FD_IS_LIST_EMPTY(src_list))) );
    887909       
    888910        if (no_ip6) {
     
    900922        /* Set the socket options */
    901923        CHECK_FCT_DO( ret = fd_setsockopt_prebind(*sock), goto out );
    902        
     924
     925        /* Bind to explicit source addresses if requested */
     926        if (src_list && !FD_IS_LIST_EMPTY(src_list)) {
     927                sSA * bindsar = NULL; /* array of addresses */
     928                size_t sz = 0; /* size of the array */
     929                int sarcount = 0; /* number of sock addr in the array */
     930
     931                /* Create the array of configured addresses */
     932                CHECK_FCT_DO( ret = add_addresses_from_list_mask((void *)&bindsar, &sz, &sarcount, family, 0, src_list, EP_FL_CONF, EP_FL_CONF), goto out );
     933
     934                if (sarcount) {
     935                        char * buf = NULL;
     936                        size_t len = 0;
     937                        CHECK_MALLOC_DO( fd_sa_dump_array( &buf, &len, 0, bindsar, sarcount), goto out );
     938                        LOG_A("SCTP client binding local addresses: %s", buf);
     939                        free(buf);
     940
     941                        CHECK_SYS_DO( ret = sctp_bindx(*sock, bindsar, sarcount, SCTP_BINDX_ADD_ADDR), goto out );
     942                }
     943
     944                /* Disable ASCONF option in postbind */
     945                bind_default = 0;
     946
     947                /* We don't need bindsar anymore */
     948                free(bindsar);
     949        }
     950
    903951        /* Create the array of addresses, add first the configured addresses, then the discovered, then the other ones */
    904952        CHECK_FCT_DO( ret = add_addresses_from_list_mask(&sar.buf, &size, &count, family, htons(port), list, EP_FL_CONF,              EP_FL_CONF        ), goto out );
     
    907955       
    908956        /* Try connecting */
    909         LOG_A("Attempting SCTP connection (%d addresses attempted) ", count);
    910                
    911 #if 0
    912                 /* Dump the SAs */
    913                 union {
    914                         uint8_t *buf;
    915                         sSA     *sa;
    916                         sSA4    *sin;
    917                         sSA6    *sin6;
    918                 } ptr;
    919                 int i;
    920                 ptr.buf = sar.buf;
    921                 for (i=0; i< count; i++) {
    922                         TRACE_sSA(FD_LOG_DEBUG, FULL, "  - ", ptr.sa, NI_NUMERICHOST | NI_NUMERICSERV, "" );
    923                         ptr.buf += (ptr.sa->sa_family == AF_INET) ? sizeof(sSA4) : sizeof(sSA6);
    924                 }
    925 #endif
    926        
     957        {
     958                char * buf = NULL;
     959                size_t len = 0;
     960                CHECK_MALLOC_DO( fd_sa_dump_array( &buf, &len, 0, sar.sa, count), goto out );
     961                LOG_A("SCTP client connecting to addresses: %s", buf);
     962                free(buf);
     963        }
     964
    927965        /* Bug in some Linux kernel, the sctp_connectx is not a cancellation point. To avoid blocking freeDiameter, we allow async cancel here */
    928966        pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
     
    945983       
    946984        /* Set the remaining sockopts */
    947         CHECK_FCT_DO( ret = fd_setsockopt_postbind(*sock, 1),
     985        CHECK_FCT_DO( ret = fd_setsockopt_postbind(*sock, bind_default),
    948986                {
    949987                        CHECK_SYS_DO( shutdown(*sock, SHUT_RDWR), /* continue */ );
     
    9831021#if 0
    9841022                char sa_buf[sSA_DUMP_STRLEN];
    985                 fd_sa_sdump_numeric(sa_buf, &status.sstat_primary.spinfo_address);
     1023                fd_sa_sdump_numeric(sa_buf, (sSA *)&status.sstat_primary.spinfo_address);
    9861024                fd_log_debug( "SCTP_STATUS : sstat_state                  : %i" , status.sstat_state);
    9871025                fd_log_debug( "              sstat_rwnd                   : %u" , status.sstat_rwnd);
     
    12191257        if (mhdr.msg_flags & MSG_NOTIFICATION) {
    12201258                union sctp_notification * notif = (union sctp_notification *) data;
     1259                char sa_buf[sSA_DUMP_STRLEN];
    12211260               
    12221261                TRACE_DEBUG(FULL, "Received %zdb data of notification on socket %d", datasize, conn->cc_socket);
     
    12361275                        case SCTP_PEER_ADDR_CHANGE:
    12371276                                TRACE_DEBUG(FULL, "Received SCTP_PEER_ADDR_CHANGE notification");
    1238                                 /* TRACE_sSA(FD_LOG_DEBUG, ANNOYING, "    intf_change : ", &(notif->sn_paddr_change.spc_aaddr), NI_NUMERICHOST | NI_NUMERICSERV, "" ); */
     1277                                fd_sa_sdump_numeric(sa_buf, (sSA *)&(notif->sn_paddr_change.spc_aaddr));
     1278                                TRACE_DEBUG(ANNOYING, "    intf_change : %s", sa_buf);
    12391279                                TRACE_DEBUG(ANNOYING, "          state : %d", notif->sn_paddr_change.spc_state);
    12401280                                TRACE_DEBUG(ANNOYING, "          error : %d", notif->sn_paddr_change.spc_error);
Note: See TracChangeset for help on using the changeset viewer.