Navigation


Changeset 378:41e3c2a3721c in freeDiameter for freeDiameter/cnxctx.c


Ignore:
Timestamp:
Jul 5, 2010, 4:21:22 PM (14 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Replaced old mechanism to discover local addresses by a call to getifaddrs, lot cleaner!
Should close #4

File:
1 edited

Legend:

Unmodified
Added
Removed
  • freeDiameter/cnxctx.c

    r258 r378  
    3737#include "cnxctx.h"
    3838
     39#include <net/if.h>
     40#include <ifaddrs.h> /* for getifaddrs */
     41
    3942/* The maximum size of Diameter message we accept to receive (<= 2^24) to avoid too big mallocs in case of trashed headers */
    4043#ifndef DIAMETER_MSG_SIZE_MAX
    4144#define DIAMETER_MSG_SIZE_MAX   65535   /* in bytes */
    4245#endif /* DIAMETER_MSG_SIZE_MAX */
     46
    4347
    4448/* Connections contexts (cnxctx) in freeDiameter are wrappers around the sockets and TLS operations .
     
    7478 */
    7579
    76 
    7780/*******************************************/
    7881/*     Creation of a connection object     */
     
    468471
    469472/* Get the list of endpoints (IP addresses) of the local and remote peers on this connection */
    470 int fd_cnx_getendpoints(struct cnxctx * conn, struct fd_list * local, struct fd_list * remote)
    471 {
    472         TRACE_ENTRY("%p %p %p", conn, local, remote);
    473         CHECK_PARAMS(conn);
    474        
    475         if (local) {
    476                 /* Retrieve the local endpoint(s) of the connection */
    477                 switch (conn->cc_proto) {
    478                         case IPPROTO_TCP: {
    479                                 sSS ss;
    480                                 socklen_t sl;
    481                                 CHECK_FCT(fd_tcp_get_local_ep(conn->cc_socket, &ss, &sl));
    482                                 CHECK_FCT(fd_ep_add_merge( local, (sSA *)&ss, sl, EP_FL_LL | EP_FL_PRIMARY));
    483                         }
    484                         break;
    485 
    486                         #ifndef DISABLE_SCTP
    487                         case IPPROTO_SCTP: {
    488                                 CHECK_FCT(fd_sctp_get_local_ep(conn->cc_socket, local));
    489                         }
    490                         break;
    491                         #endif /* DISABLE_SCTP */
    492 
    493                         default:
    494                                 CHECK_PARAMS(0);
    495                 }
    496         }
    497        
    498         if (remote) {
    499                 /* Check we have a full connection object, not a listening socket (with no remote) */
    500                 CHECK_PARAMS( conn->cc_incoming );
    501                
    502                 /* Retrieve the peer endpoint(s) of the connection */
    503                 switch (conn->cc_proto) {
    504                         case IPPROTO_TCP: {
    505                                 sSS ss;
    506                                 socklen_t sl;
    507                                 CHECK_FCT(fd_tcp_get_remote_ep(conn->cc_socket, &ss, &sl));
    508                                 CHECK_FCT(fd_ep_add_merge( remote, (sSA *)&ss, sl, EP_FL_LL | EP_FL_PRIMARY ));
    509                         }
    510                         break;
    511 
    512                         #ifndef DISABLE_SCTP
    513                         case IPPROTO_SCTP: {
    514                                 CHECK_FCT(fd_sctp_get_remote_ep(conn->cc_socket, remote));
    515                         }
    516                         break;
    517                         #endif /* DISABLE_SCTP */
    518 
    519                         default:
    520                                 CHECK_PARAMS(0);
    521                 }
     473int fd_cnx_getremoteeps(struct cnxctx * conn, struct fd_list * eps)
     474{
     475        TRACE_ENTRY("%p %p %p", conn, eps);
     476        CHECK_PARAMS(conn && eps);
     477       
     478        /* Check we have a full connection object, not a listening socket (with no remote) */
     479        CHECK_PARAMS( conn->cc_incoming );
     480
     481        /* Retrieve the peer endpoint(s) of the connection */
     482        switch (conn->cc_proto) {
     483                case IPPROTO_TCP: {
     484                        sSS ss;
     485                        socklen_t sl;
     486                        CHECK_FCT(fd_tcp_get_remote_ep(conn->cc_socket, &ss, &sl));
     487                        CHECK_FCT(fd_ep_add_merge( eps, (sSA *)&ss, sl, EP_FL_LL | EP_FL_PRIMARY ));
     488                }
     489                break;
     490
     491                #ifndef DISABLE_SCTP
     492                case IPPROTO_SCTP: {
     493                        CHECK_FCT(fd_sctp_get_remote_ep(conn->cc_socket, eps));
     494                }
     495                break;
     496                #endif /* DISABLE_SCTP */
     497
     498                default:
     499                        CHECK_PARAMS(0);
    522500        }
    523501
    524502        return 0;
    525503}
    526 
    527504
    528505/* Get a string describing the remote peer address (ip address or fqdn) */
     
    531508        CHECK_PARAMS_DO( conn, return "" );
    532509        return conn->cc_remid;
     510}
     511
     512/* Retrieve a list of all IP addresses of the local system from the kernel, using  */
     513int fd_cnx_get_local_eps(struct fd_list * list)
     514{
     515        struct ifaddrs *iflist, *cur;
     516        CHECK_SYS(getifaddrs(&iflist));
     517       
     518        for (cur = iflist; cur != NULL; cur = cur->ifa_next) {
     519                if (cur->ifa_flags & IFF_LOOPBACK)
     520                        continue;
     521               
     522                if (fd_g_config->cnf_flags.no_ip4 && (cur->ifa_addr->sa_family == AF_INET))
     523                        continue;
     524               
     525                if (fd_g_config->cnf_flags.no_ip6 && (cur->ifa_addr->sa_family == AF_INET6))
     526                        continue;
     527               
     528                CHECK_FCT(fd_ep_add_merge( list, cur->ifa_addr, sSAlen(cur->ifa_addr), EP_FL_LL ));
     529        }
     530       
     531        freeifaddrs(iflist);
     532       
     533        return 0;
    533534}
    534535
Note: See TracChangeset for help on using the changeset viewer.