Navigation


source: freeDiameter/freeDiameter/fD.h @ 29:5ba91682f0bc

Last change on this file since 29:5ba91682f0bc was 29:5ba91682f0bc, checked in by Sebastien Decugis <sdecugis@nict.go.jp>, 11 years ago

Added a test for cnxctx (tbc) and fixed some bugs

File size: 9.5 KB
Line 
1/*********************************************************************************************************
2* Software License Agreement (BSD License)                                                               *
3* Author: Sebastien Decugis <sdecugis@nict.go.jp>                                                        *
4*                                                                                                        *
5* Copyright (c) 2009, WIDE Project and NICT                                                              *
6* All rights reserved.                                                                                   *
7*                                                                                                        *
8* Redistribution and use of this software in source and binary forms, with or without modification, are  *
9* permitted provided that the following conditions are met:                                              *
10*                                                                                                        *
11* * Redistributions of source code must retain the above                                                 *
12*   copyright notice, this list of conditions and the                                                    *
13*   following disclaimer.                                                                                *
14*                                                                                                        *
15* * Redistributions in binary form must reproduce the above                                              *
16*   copyright notice, this list of conditions and the                                                    *
17*   following disclaimer in the documentation and/or other                                               *
18*   materials provided with the distribution.                                                            *
19*                                                                                                        *
20* * Neither the name of the WIDE Project or NICT nor the                                                 *
21*   names of its contributors may be used to endorse or                                                  *
22*   promote products derived from this software without                                                  *
23*   specific prior written permission of WIDE Project and                                                *
24*   NICT.                                                                                                *
25*                                                                                                        *
26* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
27* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
28* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
29* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT     *
30* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS    *
31* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
32* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF   *
33* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                                                             *
34*********************************************************************************************************/
35
36/* This file contains the definitions for internal use in the freeDiameter daemon */
37
38#ifndef _FD_H
39#define _FD_H
40
41#include <freeDiameter/freeDiameter-host.h>
42#include <freeDiameter/freeDiameter.h>
43
44/* Timeout for establishing a connection */
45#ifndef CNX_TIMEOUT
46#define  CNX_TIMEOUT    10      /* in seconds */
47#endif /* CNX_TIMEOUT */
48
49/* Timeout for receiving a CER after incoming connection is established */
50#ifndef INCNX_TIMEOUT
51#define  INCNX_TIMEOUT   20     /* in seconds */
52#endif /* INCNX_TIMEOUT */
53
54/* Timeout for receiving a CEA after CER is sent */
55#ifndef CEA_TIMEOUT
56#define  CEA_TIMEOUT    10      /* in seconds */
57#endif /* CEA_TIMEOUT */
58
59/* The timeout value to wait for answer to a DPR */
60#ifndef DPR_TIMEOUT
61#define DPR_TIMEOUT     15      /* in seconds */
62#endif /* DPR_TIMEOUT */
63
64/* Configuration */
65int fd_conf_init();
66void fd_conf_dump();
67int fd_conf_parse();
68int fddparse(struct fd_config * conf); /* yacc generated */
69
70/* Extensions */
71int fd_ext_add( char * filename, char * conffile );
72int fd_ext_load();
73void fd_ext_dump(void);
74int fd_ext_fini(void);
75
76/* Messages */
77int fd_msg_init(void);
78
79/* Global message queues */
80extern struct fifo * fd_g_incoming; /* all messages received from other peers, except local messages (CER, ...) */
81extern struct fifo * fd_g_outgoing; /* messages to be sent to other peers on the network following routing procedure */
82extern struct fifo * fd_g_local; /* messages to be handled to local extensions */
83/* Message queues */
84int fd_queues_init(void);
85int fd_queues_fini(void);
86
87/* Create all the dictionary objects defined in the Diameter base RFC. */
88int fd_dict_base_protocol(struct dictionary * dict);
89
90/* Peers */
91struct fd_peer { /* The "real" definition of the peer structure */
92       
93        /* The public data */
94        struct peer_hdr  p_hdr;
95       
96        /* Eye catcher, EYEC_PEER */
97        int              p_eyec;
98        #define EYEC_PEER       0x373C9336
99       
100        /* Origin of this peer object, for debug */
101        char            *p_dbgorig;
102       
103        /* Chaining in peers sublists */
104        struct fd_list   p_actives;     /* list of peers in the STATE_OPEN state -- faster routing creation */
105        struct fd_list   p_expiry;      /* list of expiring peers, ordered by their timeout value */
106        struct timespec  p_exp_timer;   /* Timestamp where the peer will expire; updated each time activity is seen on the peer (except DW) */
107       
108        /* Some flags influencing the peer state machine */
109        struct {
110                unsigned pf_responder   : 1;    /* The local peer is responder on the connection */
111               
112                unsigned pf_dw_pending  : 1;    /* A DWR message was sent and not answered yet */
113               
114                unsigned pf_cnx_pb      : 1;    /* The peer was disconnected because of watchdogs; must exchange 3 watchdogs before putting back to normal */
115                unsigned pf_reopen_cnt  : 2;    /* remaining DW to be exchanged after re-established connection */
116               
117                /* to be completed */
118               
119        }                p_flags;
120       
121        /* The events queue, peer state machine thread, timer for states timeouts */
122        struct fifo     *p_events;      /* The mutex of this FIFO list protects also the state and timer information */
123        pthread_t        p_psm;
124        struct timespec  p_psm_timer;
125       
126        /* Received message queue, and thread managing reception of messages */
127        struct fifo     *p_recv;
128        pthread_t        p_inthr;
129       
130        /* Outgoing message queue, and thread managing sending the messages */
131        struct fifo     *p_tosend;
132        pthread_t        p_outthr;
133       
134        /* The next hop-by-hop id value for the link, only read & modified by p_outthr */
135        uint32_t         p_hbh;
136       
137        /* Sent requests (for fallback), list of struct sentreq ordered by hbh */
138        struct fd_list   p_sentreq;
139       
140        /* connection context: socket, callbacks and so on */
141        struct cnxctx   *p_cnxctx;
142       
143        /* Callback on initial connection success / failure */
144        void            (*p_cb)(struct peer_info *, void *);
145        void            *p_cb_data;
146       
147};
148#define CHECK_PEER( _p ) \
149        (((_p) != NULL) && (((struct fd_peer *)(_p))->p_eyec == EYEC_PEER))
150
151/* Events codespace for struct fd_peer->p_events */
152enum {
153        /* Dump all info about this peer in the debug log */
154         FDEVP_DUMP_ALL = 1500
155       
156        /* request to terminate this peer : disconnect, requeue all messages */
157        ,FDEVP_TERMINATE
158       
159        /* A connection object has received a message. (data contains the buffer) */
160        ,FDEVP_CNX_MSG_RECV
161                         
162        /* A connection object has encountered an error (disconnected). */
163        ,FDEVP_CNX_ERROR
164       
165        /* Endpoints of a connection have been changed (multihomed SCTP). */
166        ,FDEVP_CNX_EP_CHANGE
167       
168        /* A new connection has been established (data contains the appropriate info) */
169        ,FDEVP_CNX_INCOMING
170       
171        /* The PSM state is expired */
172        ,FDEVP_PSM_TIMEOUT
173       
174};
175const char * fd_pev_str(int event);
176#define CHECK_EVENT( _e ) \
177        (((int)(_e) >= FDEVP_DUMP_ALL) && ((int)(_e) <= FDEVP_PSM_TIMEOUT))
178
179/* The data structure for FDEVP_CNX_INCOMING events */
180struct cnx_incoming {
181        struct msg      * cer;          /* the CER message received on this connection */
182        struct cnxctx   * cnx;          /* The connection context */
183        int               validate;     /* The peer is new, it must be validated (by an extension) or error CEA to be sent */
184};
185
186/* Structure to store a sent request */
187struct sentreq {
188        struct fd_list  chain;  /* the "o" field points directly to the hop-by-hop of the request (uint32_t *)  */
189        struct msg      *req;   /* A request that was sent and not yet answered. */
190};
191
192
193/* Functions */
194int  fd_peer_fini();
195void fd_peer_dump_list(int details);
196void fd_peer_dump(struct fd_peer * peer, int details);
197int  fd_peer_alloc(struct fd_peer ** ptr);
198int  fd_peer_free(struct fd_peer ** ptr);
199int fd_peer_handle_newCER( struct msg ** cer, struct cnxctx ** cnx );
200/* fd_peer_add declared in freeDiameter.h */
201int fd_peer_validate( struct fd_peer * peer );
202
203/* Peer expiry */
204int fd_p_expi_init(void);
205int fd_p_expi_fini(void);
206int fd_p_expi_update(struct fd_peer * peer );
207
208/* Peer state machine */
209int  fd_psm_start();
210int  fd_psm_begin(struct fd_peer * peer );
211int  fd_psm_terminate(struct fd_peer * peer );
212void fd_psm_abord(struct fd_peer * peer );
213
214/* Server sockets */
215void fd_servers_dump();
216int  fd_servers_start();
217int  fd_servers_stop();
218
219/* Connection contexts -- there are also definitions in cnxctx.h for the relevant files */
220struct cnxctx * fd_cnx_serv_tcp(uint16_t port, int family, struct fd_endpoint * ep);
221struct cnxctx * fd_cnx_serv_sctp(uint16_t port, struct fd_list * ep_list);
222int             fd_cnx_serv_listen(struct cnxctx * conn);
223struct cnxctx * fd_cnx_serv_accept(struct cnxctx * serv);
224struct cnxctx * fd_cnx_cli_connect_tcp(sSA * sa, socklen_t addrlen);
225struct cnxctx * fd_cnx_cli_connect_sctp(int no_ip6, uint16_t port, struct fd_list * list);
226int             fd_cnx_start_clear(struct cnxctx * conn, int loop);
227int             fd_cnx_handshake(struct cnxctx * conn, int mode, char * priority, void * alt_creds);
228char *          fd_cnx_getid(struct cnxctx * conn);
229int             fd_cnx_getproto(struct cnxctx * conn);
230int             fd_cnx_getTLS(struct cnxctx * conn);
231int             fd_cnx_getcred(struct cnxctx * conn, const gnutls_datum_t **cert_list, unsigned int *cert_list_size);
232int             fd_cnx_getendpoints(struct cnxctx * conn, struct fd_list * local, struct fd_list * remote);
233char *          fd_cnx_getremoteid(struct cnxctx * conn);
234int             fd_cnx_receive(struct cnxctx * conn, struct timespec * timeout, unsigned char **buf, size_t * len);
235int             fd_cnx_recv_setaltfifo(struct cnxctx * conn, struct fifo * alt_fifo); /* send FDEVP_CNX_MSG_RECV event to the fifo list */
236int             fd_cnx_send(struct cnxctx * conn, unsigned char * buf, size_t len);
237void            fd_cnx_destroy(struct cnxctx * conn);
238
239
240#endif /* _FD_H */
Note: See TracBrowser for help on using the repository browser.