Navigation


Changeset 28:3628f7d2ba88 in freeDiameter


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

some new functions backbones

Location:
freeDiameter
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • freeDiameter/fD.h

    r25 r28  
    157157        ,FDEVP_TERMINATE
    158158       
    159         /* A connection object has received a message. */
     159        /* A connection object has received a message. (data contains the buffer) */
    160160        ,FDEVP_CNX_MSG_RECV
    161161                         
     
    166166        ,FDEVP_CNX_EP_CHANGE
    167167       
    168         /* A message was received in the peer */
    169         ,FDEVP_MSG_INCOMING
     168        /* A new connection has been established (data contains the appropriate info) */
     169        ,FDEVP_CNX_INCOMING
    170170       
    171171        /* The PSM state is expired */
     
    185185
    186186/* Functions */
    187 int fd_peer_fini();
     187int  fd_peer_fini();
    188188void fd_peer_dump_list(int details);
    189189void fd_peer_dump(struct fd_peer * peer, int details);
    190 int fd_peer_alloc(struct fd_peer ** ptr);
    191 int fd_peer_free(struct fd_peer ** ptr);
     190int  fd_peer_alloc(struct fd_peer ** ptr);
     191int  fd_peer_free(struct fd_peer ** ptr);
     192int fd_peer_handle_newCER( struct msg ** cer, struct cnxctx ** cnx, int tls_done );
    192193/* fd_peer_add declared in freeDiameter.h */
    193194
     
    198199
    199200/* Peer state machine */
    200 int fd_psm_start();
    201 int fd_psm_begin(struct fd_peer * peer );
    202 int fd_psm_terminate(struct fd_peer * peer );
     201int  fd_psm_start();
     202int  fd_psm_begin(struct fd_peer * peer );
     203int  fd_psm_terminate(struct fd_peer * peer );
    203204void fd_psm_abord(struct fd_peer * peer );
    204205
    205206/* Server sockets */
    206207void fd_servers_dump();
    207 int fd_servers_start();
    208 int fd_servers_stop();
    209 
    210 /* Connection contexts */
     208int  fd_servers_start();
     209int  fd_servers_stop();
     210
     211/* Connection contexts -- there are also definitions in cnxctx.h for the relevant files */
    211212struct cnxctx * fd_cnx_serv_tcp(uint16_t port, int family, struct fd_endpoint * ep);
    212213struct cnxctx * fd_cnx_serv_sctp(uint16_t port, struct fd_list * ep_list);
    213 int fd_cnx_serv_listen(struct cnxctx * conn);
     214int             fd_cnx_serv_listen(struct cnxctx * conn);
    214215struct cnxctx * fd_cnx_serv_accept(struct cnxctx * serv);
    215216struct cnxctx * fd_cnx_cli_connect_tcp(sSA * sa, socklen_t addrlen);
    216217struct cnxctx * fd_cnx_cli_connect_sctp(int no_ip6, uint16_t port, struct fd_list * list);
    217 char * fd_cnx_getid(struct cnxctx * conn);
    218 int fd_cnx_start_clear(struct cnxctx * conn, int loop);
    219 int fd_cnx_handshake(struct cnxctx * conn, int mode, char * priority);
    220 int fd_cnx_getcred(struct cnxctx * conn, const gnutls_datum_t **cert_list, unsigned int *cert_list_size);
    221 int fd_cnx_getendpoints(struct cnxctx * conn, struct fd_list * local, struct fd_list * remote);
    222 char * fd_cnx_getremoteid(struct cnxctx * conn);
    223 int fd_cnx_receive(struct cnxctx * conn, struct timespec * timeout, unsigned char **buf, size_t * len);
    224 int fd_cnx_recv_setaltfifo(struct cnxctx * conn, struct fifo * alt_fifo); /* send FDEVP_CNX_MSG_RECV event to the fifo list */
    225 int fd_cnx_send(struct cnxctx * conn, unsigned char * buf, size_t len);
    226 void fd_cnx_destroy(struct cnxctx * conn);
     218char *          fd_cnx_getid(struct cnxctx * conn);
     219int             fd_cnx_start_clear(struct cnxctx * conn, int loop);
     220int             fd_cnx_handshake(struct cnxctx * conn, int mode, char * priority);
     221int             fd_cnx_getcred(struct cnxctx * conn, const gnutls_datum_t **cert_list, unsigned int *cert_list_size);
     222int             fd_cnx_getendpoints(struct cnxctx * conn, struct fd_list * local, struct fd_list * remote);
     223char *          fd_cnx_getremoteid(struct cnxctx * conn);
     224int             fd_cnx_receive(struct cnxctx * conn, struct timespec * timeout, unsigned char **buf, size_t * len);
     225int             fd_cnx_recv_setaltfifo(struct cnxctx * conn, struct fifo * alt_fifo); /* send FDEVP_CNX_MSG_RECV event to the fifo list */
     226int             fd_cnx_send(struct cnxctx * conn, unsigned char * buf, size_t len);
     227void            fd_cnx_destroy(struct cnxctx * conn);
    227228
    228229
  • freeDiameter/p_psm.c

    r27 r28  
    6060                case_str(FDEVP_CNX_ERROR);
    6161                case_str(FDEVP_CNX_EP_CHANGE);
    62                 case_str(FDEVP_MSG_INCOMING);
     62                case_str(FDEVP_CNX_INCOMING);
    6363                case_str(FDEVP_PSM_TIMEOUT);
    6464               
     
    227227        return NULL;
    228228}       
    229        
    230        
    231 
    232229
    233230/* Create the PSM thread of one peer structure */
  • freeDiameter/peers.c

    r22 r28  
    131131       
    132132        for (li = fd_g_peers.next; li != &fd_g_peers; li = li->next) {
    133                 struct fd_peer * prev = (struct fd_peer *)li;
    134                 int cmp = strcasecmp( p->p_hdr.info.pi_diamid, prev->p_hdr.info.pi_diamid );
    135                 if (cmp < 0)
     133                struct fd_peer * next = (struct fd_peer *)li;
     134                int cmp = strcasecmp( p->p_hdr.info.pi_diamid, next->p_hdr.info.pi_diamid );
     135                if (cmp > 0)
    136136                        continue;
    137137                if (cmp == 0)
     
    375375}
    376376
     377/* Handle an incoming CER request on a new connection */
     378int fd_peer_handle_newCER( struct msg ** cer, struct cnxctx ** cnx, int tls_done )
     379{
     380        struct msg * msg;
     381        struct dict_object *avp_oh_model;
     382        avp_code_t code = AC_ORIGIN_HOST;
     383        struct avp *avp_oh;
     384        struct avp_hdr * avp_hdr;
     385        struct fd_list * li;
     386        int found = 0;
     387        struct fd_peer * peer;
     388       
     389        TRACE_ENTRY("%p %p %d", cer, cnx, tls_done);
     390        CHECK_PARAMS(cer && *cer && cnx && *cnx);
     391       
     392        msg = *cer;
     393       
     394        /* Find the Diameter Identity of the remote peer in the message */
     395        CHECK_FCT( fd_dict_search ( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_CODE, &code, &avp_oh_model, ENOENT) );
     396        CHECK_FCT( fd_msg_search_avp ( msg, avp_oh_model, &avp_oh ) );
     397        CHECK_FCT( fd_msg_avp_hdr ( avp_oh, &avp_hdr ) );
     398       
     399        /* Search if we already have this peer id in our list */
     400        CHECK_POSIX( pthread_rwlock_rdlock(&fd_g_peers_rw) );
     401       
     402        for (li = fd_g_peers.next; li != &fd_g_peers; li = li->next) {
     403                peer = (struct fd_peer *)li;
     404                int cmp = strncasecmp( avp_hdr->avp_value->os.data, peer->p_hdr.info.pi_diamid, avp_hdr->avp_value->os.len );
     405                if (cmp > 0)
     406                        continue;
     407                if (cmp == 0)
     408                        found = 1;
     409                break;
     410        }
     411       
     412        if (!found) {
     413               
     414                TODO("Create a new peer entry with this diameter id (pf_responder = 1)");
     415                TODO("Upgrade the lock to wr");
     416                TODO("Add the new peer in the list");
     417                TODO("Release the wr lock");
     418                TODO("Start the peer PSM, which will have to validate if this peer is authorized to connect, and so on");
     419        }
     420               
     421        TODO("Send the new connection event to the peer SM with the appropriate data: msg, conn, tls_done, found");
     422        /* FDEVP_CNX_INCOMING */
     423       
     424        /* Reset the "out" parameters, so that they are not cleanup on function return. */
     425        *cer = NULL;
     426        *cnx = NULL;
     427       
     428        CHECK_POSIX( pthread_rwlock_unlock(&fd_g_peers_rw) );
     429
     430       
     431        TODO("(later if not tls_done) handshake or start_clear(.., 1) ");
     432       
     433        return 0;
     434}
     435
     436/* Save a callback to accept / reject incoming unknown peers */
     437int fd_peer_validate_register ( int (*peer_validate)(struct peer_info * /* info */, int * /* auth */, int (**cb2)(struct peer_info *)) )
     438{
     439       
     440        TODO("...");
     441        return ENOTSUP;
     442}
  • freeDiameter/server.c

    r27 r28  
    139139        CHECK_FCT_DO( fd_msg_parse_buffer( &buf, bufsz, &msg ), /* Parsing failed */ goto cleanup );
    140140       
    141         /* We expect a CER, it must parse with our dictionary */
    142         CHECK_FCT_DO( fd_msg_parse_dict( msg, fd_g_config->cnf_dict ), /* Parsing failed */ goto cleanup );
     141        /* We expect a CER, it must parse with our dictionary and rules */
     142        CHECK_FCT_DO( fd_msg_parse_rules( msg, fd_g_config->cnf_dict, NULL ), /* Parsing failed -- trace details ? */ goto cleanup );
    143143       
    144144        if (TRACE_BOOL(FULL)) {
     
    149149        /* Now check we received a CER */
    150150        CHECK_FCT_DO( fd_msg_hdr ( msg, &hdr ), goto fatal_error );
    151        
    152151        CHECK_PARAMS_DO( (hdr->msg_appl == 0) && (hdr->msg_flags & CMD_FLAG_REQUEST) && (hdr->msg_code == CC_CAPABILITIES_EXCHANGE),
    153152                { fd_log_debug("Connection '%s', expecting CER, received something else, closing...\n", fd_cnx_getid(c->conn)); goto cleanup; } );
    154153       
    155        
    156         TODO("Search matching peer");
    157         TODO("Send event to the peer");
    158        
    159         TODO("(later) handshake or start_clear(.., 1)");
    160         /* The end */
     154        /* Finally, pass the information to the peers module which will handle it next */
     155        CHECK_FCT_DO( fd_peer_handle_newCER( &msg, &c->conn, s->secur ), goto fatal_error );
     156       
     157        /* The end, we cleanup the client structure */
    161158cleanup:
    162159        /* Unlink the client structure */
Note: See TracChangeset for help on using the changeset viewer.