Navigation


source: freeDiameter/freeDiameter/fD.h @ 20:277ec00d793e

Last change on this file since 20:277ec00d793e was 20:277ec00d793e, checked in by Sebastien Decugis <sdecugis@nict.go.jp>, 12 years ago

Backup before typhoon... Progress on server side

File size: 8.7 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 = 2000
155       
156        /* request to terminate this peer : disconnect, requeue all messages */
157        ,FDEVP_TERMINATE
158       
159        /* A message was received in the peer */
160        ,FDEVP_MSG_INCOMING
161       
162        /* The PSM state is expired */
163        ,FDEVP_PSM_TIMEOUT
164};
165const char * fd_pev_str(int event);
166#define CHECK_EVENT( _e ) \
167        (((int)(_e) >= FDEVP_DUMP_ALL) && ((int)(_e) <= FDEVP_PSM_TIMEOUT))
168
169/* Structure to store a sent request */
170struct sentreq {
171        struct fd_list  chain;  /* the "o" field points directly to the hop-by-hop of the request (uint32_t *)  */
172        struct msg      *req;   /* A request that was sent and not yet answered. */
173};
174
175/* The connection context structure */
176struct cnxctx {
177        int             cc_socket;      /* The socket object of the connection -- <=0 if no socket is created */
178       
179        struct fifo   **cc_events;      /* Location of the events list to send connection events */
180       
181        int             cc_proto;       /* IPPROTO_TCP or IPPROTO_SCTP */
182        int             cc_tls;         /* Is TLS already started ? */
183       
184        uint16_t        cc_port;        /* Remote port of the connection, when we are client */
185        struct fd_list  cc_ep_remote;   /* The remote address(es) of the connection */
186        struct fd_list  cc_ep_local;    /* The local address(es) of the connection */
187       
188        /* If cc_proto == SCTP */
189        struct  {
190                int             str_out;/* Out streams */
191                int             str_in; /* In streams */
192                int             pairs;  /* max number of pairs ( = min(in, out)) */
193                int             next;   /* # of stream the next message will be sent to */
194        }               cc_sctp_para;
195       
196        /* If cc_tls == true */
197        struct {
198                int                              mode;          /* GNUTLS_CLIENT / GNUTLS_SERVER */
199                gnutls_session_t                 session;       /* Session object (stream #0 in case of SCTP) */
200        }               cc_tls_para;
201       
202        /* If both conditions */
203        struct {
204                gnutls_session_t                *res_sessions;  /* Sessions of other pairs of streams, resumed from the first */
205                /* Buffers, threads, ... */
206        }               cc_sctp_tls_para;
207};
208
209/* Functions */
210int fd_peer_fini();
211void fd_peer_dump_list(int details);
212void fd_peer_dump(struct fd_peer * peer, int details);
213int fd_peer_alloc(struct fd_peer ** ptr);
214int fd_peer_free(struct fd_peer ** ptr);
215/* fd_peer_add declared in freeDiameter.h */
216
217/* Peer expiry */
218int fd_p_expi_init(void);
219int fd_p_expi_fini(void);
220int fd_p_expi_update(struct fd_peer * peer );
221
222/* Peer state machine */
223int fd_psm_start();
224int fd_psm_begin(struct fd_peer * peer );
225int fd_psm_terminate(struct fd_peer * peer );
226void fd_psm_abord(struct fd_peer * peer );
227
228/* Server sockets */
229void fd_servers_dump();
230int fd_servers_start();
231void fd_servers_stop();
232
233/* Connection contexts */
234struct cnxctx * fd_cnx_init(int sock, int proto);
235int fd_cnx_handshake(struct cnxctx * conn, int mode);
236
237/* SCTP */
238#ifndef DISABLE_SCTP
239int fd_sctp_create_bind_server( int * socket, uint16_t port );
240int fd_sctp_get_str_info( int socket, int *in, int *out );
241
242#endif /* DISABLE_SCTP */
243
244
245
246#endif /* _FD_H */
Note: See TracBrowser for help on using the repository browser.