Navigation


Changeset 500:d4fc98a3b79c in freeDiameter for extensions/app_radgw


Ignore:
Timestamp:
Aug 17, 2010, 4:35:19 PM (14 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Handle more nicely the local RADIUS clients in the gateway

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/app_radgw/rgw_clients.c

    r442 r500  
    6666       
    6767        /* The FQDN, realm, and optional aliases */
     68        int                      is_local; /* true if the RADIUS client runs on the same host -- we use Diameter Identity in that case */
    6869        char                    *fqdn;
    6970        size_t                   fqdn_len;
     
    9596        char buf[255];
    9697        int ret;
    97        
    98         /* Search FQDN for the client */
    99         ret = getnameinfo( *ip_port, sizeof(struct sockaddr_storage), &buf[0], sizeof(buf), NULL, 0, 0 );
    100         if (ret) {
    101                 TRACE_DEBUG(INFO, "Unable to resolve peer name: %s", gai_strerror(ret));
    102                 return EINVAL;
     98        int loc = 0;
     99       
     100        /* Check if the IP address is local */
     101        if (   ( ((*ip_port)->sa_family == AF_INET ) && (   IN_IS_ADDR_LOOPBACK( &((struct sockaddr_in  *)(*ip_port))->sin_addr ) ) )
     102             ||( ((*ip_port)->sa_family == AF_INET6) && (  IN6_IS_ADDR_LOOPBACK( &((struct sockaddr_in6 *)(*ip_port))->sin6_addr) ) )) {
     103                /* The client is local */
     104                loc = 1;
     105        } else {
     106       
     107                /* Search FQDN for the client */
     108                ret = getnameinfo( *ip_port, sizeof(struct sockaddr_storage), &buf[0], sizeof(buf), NULL, 0, 0 );
     109                if (ret) {
     110                        TRACE_DEBUG(INFO, "Unable to resolve peer name: %s", gai_strerror(ret));
     111                        return EINVAL;
     112                }
    103113        }
    104114       
     
    108118        fd_list_init(&tmp->chain, NULL);
    109119       
    110         /* Copy the fqdn */
    111         CHECK_MALLOC( tmp->fqdn = strdup(buf) );
    112         tmp->fqdn_len = strlen(tmp->fqdn);
    113         /* Find an appropriate realm */
    114         tmp->realm = strchr(tmp->fqdn, '.');
    115         if (tmp->realm)
    116                 tmp->realm += 1;
    117         if ((!tmp->realm) || (*tmp->realm == '\0')) /* in case the fqdn was "localhost." for example, if it is possible... */
    118                 tmp->realm = fd_g_config->cnf_diamrlm;
     120        if (loc) {
     121                tmp->is_local = 1;
     122        } else {
     123                /* Copy the fqdn */
     124                CHECK_MALLOC( tmp->fqdn = strdup(buf) );
     125                tmp->fqdn_len = strlen(tmp->fqdn);
     126                /* Find an appropriate realm */
     127                tmp->realm = strchr(tmp->fqdn, '.');
     128                if (tmp->realm)
     129                        tmp->realm += 1;
     130                if ((!tmp->realm) || (*tmp->realm == '\0')) /* in case the fqdn was "localhost." for example, if it is possible... */
     131                        tmp->realm = fd_g_config->cnf_diamrlm;
     132        }
    119133       
    120134        /* move the sa info reference */
     
    155169
    156170
    157 /* Macro to avoid duplicting the code in the next function */
     171/* Macro to avoid duplicating the code in the next function */
    158172#define client_search_family( _family_ )                                                                                                \
    159173                case AF_INET##_family_: {                                                                                               \
     
    370384        }
    371385       
    372         /* Now check the nas_id */
    373         if (nas_id) {
     386        /* Now check the nas_id, but only for non-local hosts */
     387        if (nas_id && (! cli->is_local) ) {
    374388                char * str;
    375389                int found, ret;
     
    464478        CHECK_PARAMS(cli && fqdn);
    465479       
    466         *fqdn = cli->fqdn;
    467         if (realm)
    468                 *realm= cli->realm;
     480        if (cli->is_local) {
     481                *fqdn = fd_g_config->cnf_diamid;
     482                if (realm)
     483                        *realm= fd_g_config->cnf_diamrlm;
     484        } else {
     485                *fqdn = cli->fqdn;
     486                if (realm)
     487                        *realm= cli->realm;
     488        }
     489               
    469490        return 0;
    470491}
     
    472493char * rgw_clients_id(struct rgw_client *cli)
    473494{
    474         return cli->fqdn;
     495        return cli->is_local ? "(local)" : cli->fqdn;
    475496}
    476497
Note: See TracChangeset for help on using the changeset viewer.