Navigation


Changeset 1540:407e0a889c7e in freeDiameter for libfdcore/sctp.c


Ignore:
Timestamp:
May 1, 2020, 5:20:33 PM (4 years ago)
Author:
Luke Mewburn <luke@mewburn.net>
Branch:
default
Phase:
public
Message:

SCTP ConnectPeer?: sctp_bindx() to local endpoints

When connecting to an SCTP peer using sctp_connectx() with local
addresses configured with ListenOn?, bind to the ListenOn? addresses
using sctp_bindx() so that the SCTP INIT only contains the
configured local addresses, matching what is advertised in the CER,
and disable SCTP_AUTO_ASCONF.

If no local addresses are configured with ListenOn?, the previous
behaviour of sctp_connectx() and enable SCTP_AUTO_ASCONF is used.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libfdcore/sctp.c

    r1495 r1540  
    870870
    871871/* 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 )
     872int fd_sctp_client( int *sock, int no_ip6, uint16_t port, struct fd_list * list, struct fd_list * src_list )
    873873{
    874874        int family;
     
    880880        int count = 0;
    881881        int ret;
     882        int bind_default = 1;   /* enable ASCONF in postbind */
    882883       
    883884        sar.buf = NULL;
    884885       
    885         TRACE_ENTRY("%p %i %hu %p", sock, no_ip6, port, list);
     886        TRACE_ENTRY("%p %i %hu %p %p", sock, no_ip6, port, list, src_list);
    886887        CHECK_PARAMS( sock && list && (!FD_IS_LIST_EMPTY(list)) );
     888        CHECK_PARAMS( !src_list || (src_list && (!FD_IS_LIST_EMPTY(src_list))) );
    887889       
    888890        if (no_ip6) {
     
    900902        /* Set the socket options */
    901903        CHECK_FCT_DO( ret = fd_setsockopt_prebind(*sock), goto out );
    902        
     904
     905        /* Bind to explicit source addresses if requested */
     906        if (src_list && !FD_IS_LIST_EMPTY(src_list)) {
     907                sSA * bindsar = NULL; /* array of addresses */
     908                size_t sz = 0; /* size of the array */
     909                int sarcount = 0; /* number of sock addr in the array */
     910
     911                /* Create the array of configured addresses */
     912                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 );
     913
     914                if (sarcount) {
     915                        LOG_A("Bind to local SCTP endpoints (%d addresses attempted) ", sarcount);
     916
     917                        CHECK_SYS_DO( ret = sctp_bindx(*sock, bindsar, sarcount, SCTP_BINDX_ADD_ADDR), goto out );
     918                }
     919
     920                /* Disable ASCONF option in postbind */
     921                bind_default = 0;
     922
     923                /* We don't need bindsar anymore */
     924                free(bindsar);
     925        }
     926
    903927        /* Create the array of addresses, add first the configured addresses, then the discovered, then the other ones */
    904928        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 );
     
    945969       
    946970        /* Set the remaining sockopts */
    947         CHECK_FCT_DO( ret = fd_setsockopt_postbind(*sock, 1),
     971        CHECK_FCT_DO( ret = fd_setsockopt_postbind(*sock, bind_default),
    948972                {
    949973                        CHECK_SYS_DO( shutdown(*sock, SHUT_RDWR), /* continue */ );
Note: See TracChangeset for help on using the changeset viewer.