Navigation


Changeset 8:3e143f047f78 in freeDiameter for include


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

Backup for the week-end

Location:
include/freeDiameter
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • include/freeDiameter/CMakeLists.txt

    r1 r8  
    7272CHECK_INCLUDE_FILES (malloc.h HAVE_MALLOC_H)
    7373
     74# signalent.h ? -- found in strace distrib; just for nice signal names...
     75CHECK_INCLUDE_FILES (signalent.h HAVE_SIGNALENT_H)
     76
    7477# The default configuration file name
    7578IF (NOT DEFAULT_CONF_FILE)
  • include/freeDiameter/freeDiameter-host.h.in

    r1 r8  
    4040#cmakedefine HAVE_NTOHLL
    4141#cmakedefine HAVE_MALLOC_H
     42#cmakedefine HAVE_SIGNALENT_H
    4243
    4344#cmakedefine HOST_BIG_ENDIAN @HOST_BIG_ENDIAN@
     
    4546#cmakedefine DISABLE_SCTP
    4647
    47 #cmakedefine PROJECT_NAME "@PROJECT_NAME@"
    48 #cmakedefine CMAKE_PROJECT_NAME "@CMAKE_PROJECT_NAME@"
    49 #cmakedefine PROJECT_VERSION "@PROJECT_VERSION@"
    50 #cmakedefine PROJECT_COPYRIGHT "@PROJECT_COPYRIGHT@"
     48#cmakedefine FD_PROJECT_BINARY "@FD_PROJECT_BINARY@"
     49#cmakedefine FD_PROJECT_NAME "@FD_PROJECT_NAME@"
     50#cmakedefine FD_PROJECT_VERSION_MAJOR @FD_PROJECT_VERSION_MAJOR@
     51#ifndef FD_PROJECT_VERSION_MAJOR
     52# define FD_PROJECT_VERSION_MAJOR 0
     53#endif /*FD_PROJECT_VERSION_MAJOR*/
     54#cmakedefine FD_PROJECT_VERSION_MINOR @FD_PROJECT_VERSION_MINOR@
     55#ifndef FD_PROJECT_VERSION_MINOR
     56# define FD_PROJECT_VERSION_MINOR 0
     57#endif /*FD_PROJECT_VERSION_MINOR*/
     58#cmakedefine FD_PROJECT_VERSION_REV   @FD_PROJECT_VERSION_REV@
     59#ifndef FD_PROJECT_VERSION_REV
     60# define FD_PROJECT_VERSION_REV 0
     61#endif /*FD_PROJECT_VERSION_REV*/
     62/* HG_VERSION */
     63/* PACKAGE_HG_REVISION */
     64#cmakedefine FD_PROJECT_COPYRIGHT "@FD_PROJECT_COPYRIGHT@"
    5165
    5266#cmakedefine DEFAULT_CONF_FILE "@DEFAULT_CONF_FILE@"
    5367
     68
    5469#endif /* FD_IS_CONFIG */
  • include/freeDiameter/freeDiameter.h

    r7 r8  
    4141
    4242
    43 /* The global dictionary */
    44 extern struct dictionary * fd_g_dict;
    45 
     43/* Structure to hold the configuration of the freeDiameter daemon */
     44struct fd_config {
     45        int              eyec;          /* Eye catcher: EYEC_CONFIG */
     46        char            *conf_file;     /* Configuration file to parse, default is DEFAULT_CONF_FILE */
     47       
     48        char            *diam_id;       /* Diameter Identity of the local peer (FQDN -- UTF-8) */
     49        size_t           diam_id_len;   /* length of the previous string */
     50        char            *diam_realm;    /* Diameter realm of the local peer, default to realm part of diam_id */
     51        size_t           diam_realm_len;/* length of the previous string */
     52       
     53        uint16_t         loc_port;      /* the local port for legacy Diameter (default: 3868) in host byte order */
     54        uint16_t         loc_port_tls;  /* the local port for Diameter/TLS (default: 3869) in host byte order */
     55        uint16_t         loc_sctp_str;  /* default max number of streams for SCTP associations (def: 30) */
     56        struct fd_list   loc_endpoints; /* the local endpoints to bind the server to. list of struct fd_endpoint. default is empty (bind all) */
     57        struct {
     58                unsigned no_ip4 : 1;    /* disable IP */
     59                unsigned no_ip6 : 1;    /* disable IPv6 */
     60                unsigned no_tcp : 1;    /* disable use of TCP */
     61                unsigned no_sctp: 1;    /* disable the use of SCTP */
     62                unsigned pr_tcp : 1;    /* prefer TCP over SCTP */
     63                unsigned tls_alg: 1;    /* TLS algorithm for initiated cnx. 0: separate port. 1: inband-security (old) */
     64                unsigned no_fwd : 1;    /* the peer does not relay messages (0xffffff app id) */
     65        }                flags;
     66       
     67        unsigned int     timer_tc;      /* The value in seconds of the default Tc timer */
     68        unsigned int     timer_tw;      /* The value in seconds of the default Tw timer */
     69       
     70        uint32_t         or_state_id;   /* The value to use in Origin-State-Id, default to random value */
     71        struct dictionary *g_dict;      /* pointer to the global dictionary */
     72        struct fifo       *g_fifo_main; /* FIFO queue of events in the daemon main (struct fd_event items) */
     73};
     74
     75#define EYEC_CONFIG     0xC011F16
     76
     77/* The pointer to access the global configuration, initalized in main */
     78extern struct fd_config *fd_g_config;
     79
     80/* Endpoints */
     81struct fd_endpoint {
     82        struct fd_list  chain;  /* link in loc_endpoints list */
     83        sSS             ss;     /* the socket information. */
     84};
     85
     86/* Events */
     87struct fd_event {
     88        int      code; /* codespace depends on the queue */
     89        void    *data;
     90};
     91
     92/* send an event */
     93static __inline__ int fd_event_send(struct fifo *queue, int code, void * data)
     94{
     95        struct fd_event * ev;
     96        CHECK_MALLOC( ev = malloc(sizeof(struct fd_event)) );
     97        ev->code = code;
     98        ev->data = data;
     99        CHECK_FCT( fd_fifo_post(queue, &ev) );
     100        return 0;
     101}
     102/* receive an event */
     103static __inline__ int fd_event_get(struct fifo *queue, int *code, void ** data)
     104{
     105        struct fd_event * ev;
     106        CHECK_FCT( fd_fifo_get(queue, &ev) );
     107        if (code)
     108                *code = ev->code;
     109        if (data)
     110                *data = ev->data;
     111        free(ev);
     112        return 0;
     113}
    46114
    47115/***************************************/
  • include/freeDiameter/libfreeDiameter.h

    r7 r8  
    3737 *
    3838 * This library is meant to be used by both the freeDiameter daemon and its extensions.
    39  *
    4039 * It provides the tools to manipulate Diameter messages and related data.
    41  *
    4240 * This file should always be included as #include <freeDiameter/libfreeDiameter.h>
     41 *
     42 * The file contains the following parts:
     43 *      DEBUG
     44 *      MACROS
     45 *      THREADS
     46 *      LISTS
     47 *      DICTIONARY
     48 *      SESSIONS
     49 *      MESSAGES
     50 *      DISPATCH
     51 *      QUEUES
    4352 */
    4453
     
    297306#define sSA6    struct sockaddr_in6
    298307
    299 /* Dump one sockaddr */
    300 #define sSA_DUMP( level, text, sa ) {                           \
     308/* Dump one sockaddr Node information */
     309#define sSA_DUMP_NODE( sa, flag ) {                             \
    301310        sSA * __sa = (sSA *)(sa);                               \
    302         char *__str, __addrbuf[INET6_ADDRSTRLEN];               \
     311        char __addrbuf[INET6_ADDRSTRLEN];                       \
    303312        if (__sa) {                                             \
    304313          int __rc = getnameinfo(__sa,                          \
     
    308317                        NULL,                                   \
    309318                        0,                                      \
    310                         0);                                     \
     319                        flag);                                  \
    311320          if (__rc)                                             \
    312                 __str = (char *)gai_strerror(__rc);             \
     321                fd_log_debug((char *)gai_strerror(__rc));       \
    313322          else                                                  \
    314                 __str = &__addrbuf[0];                          \
     323                fd_log_debug(&__addrbuf[0]);                    \
    315324        } else {                                                \
    316                 __str = "(NULL / ANY)";                         \
     325                fd_log_debug("(NULL / ANY)");                   \
    317326        }                                                       \
    318         TRACE_DEBUG(level, text "%s", __str);                   \
    319327}
     328/* if needed, add sSA_DUMP_SERVICE */
    320329
    321330/* The sockaddr length of a sSS structure */
     
    22752284
    22762285/*============================================================*/
    2277 /*                    MESSAGE QUEUES                          */
     2286/*                     QUEUES                                 */
    22782287/*============================================================*/
    22792288
    2280 /* Management of queues of messages */
    2281 
    2282 /* A message queue is an opaque object */
    2283 struct mqueue;
    2284 
    2285 /*
    2286  * FUNCTION:    fd_mq_new
    2287  *
    2288  * PARAMETERS:
    2289  *  queue       : Upon success, a pointer to the new message queue is saved here.
    2290  *
    2291  * DESCRIPTION:
    2292  *  Create a new empty message queue.
     2289/* Management of FIFO queues of elements */
     2290
     2291/* A queue is an opaque object */
     2292struct fifo;
     2293
     2294/*
     2295 * FUNCTION:    fd_fifo_new
     2296 *
     2297 * PARAMETERS:
     2298 *  queue       : Upon success, a pointer to the new queue is saved here.
     2299 *
     2300 * DESCRIPTION:
     2301 *  Create a new empty queue.
    22932302 *
    22942303 * RETURN VALUE :
    2295  *  0           : The message queue has been initialized successfully.
     2304 *  0           : The queue has been initialized successfully.
    22962305 *  EINVAL      : The parameter is invalid.
    22972306 *  ENOMEM      : Not enough memory to complete the creation. 
    22982307 */
    2299 int fd_mq_new ( struct mqueue ** queue );
    2300 
    2301 /*
    2302  * FUNCTION:    fd_mq_del
    2303  *
    2304  * PARAMETERS:
    2305  *  queue       : Pointer to an empty message queue to delete.
    2306  *
    2307  * DESCRIPTION:
    2308  *  Destroys a message queue. This is only possible if no thread is waiting for a message,
     2308int fd_fifo_new ( struct fifo ** queue );
     2309
     2310/*
     2311 * FUNCTION:    fd_fifo_del
     2312 *
     2313 * PARAMETERS:
     2314 *  queue       : Pointer to an empty queue to delete.
     2315 *
     2316 * DESCRIPTION:
     2317 *  Destroys a queue. This is only possible if no thread is waiting for an element,
    23092318 * and the queue is empty.
    23102319 *
    23112320 * RETURN VALUE:
    2312  *  0           : The message queue has been destroyed successfully.
     2321 *  0           : The queue has been destroyed successfully.
    23132322 *  EINVAL      : The parameter is invalid.
    23142323 */
    2315 int fd_mq_del ( struct mqueue  ** queue );
    2316 
    2317 /*
    2318  * FUNCTION:    fd_mq_length
    2319  *
    2320  * PARAMETERS:
    2321  *  queue       : The queue from which to retrieve the length.
    2322  *  length      : Upon success, the current number of messages in the queue is stored here.
    2323  *
    2324  * DESCRIPTION:
    2325  *  Retrieve the number of messages pending in a queue.
     2324int fd_fifo_del ( struct fifo  ** queue );
     2325
     2326/*
     2327 * FUNCTION:    fd_fifo_length
     2328 *
     2329 * PARAMETERS:
     2330 *  queue       : The queue from which to retrieve the number of elements.
     2331 *  length      : Upon success, the current number of elements in the queue is stored here.
     2332 *
     2333 * DESCRIPTION:
     2334 *  Retrieve the number of elements in a queue.
    23262335 *
    23272336 * RETURN VALUE:
     
    23292338 *  EINVAL      : A parameter is invalid.
    23302339 */
    2331 int fd_mq_length ( struct mqueue * queue, int * length );
    2332 int fd_mq_length_noerr ( struct mqueue * queue ); /* alternate with no error checking */
    2333 
    2334 /*
    2335  * FUNCTION:    fd_mq_setthrhd
     2340int fd_fifo_length ( struct fifo * queue, int * length );
     2341int fd_fifo_length_noerr ( struct fifo * queue ); /* no error checking version */
     2342
     2343/*
     2344 * FUNCTION:    fd_fifo_setthrhd
    23362345 *
    23372346 * PARAMETERS:
     
    23452354 * DESCRIPTION:
    23462355 *  This function allows to adjust the number of producer / consumer threads of a queue.
    2347  * If the consumer are slower than the producers, the number of messages in the queue increase.
     2356 * If the consumer are slower than the producers, the number of elements in the queue increase.
    23482357 * By setting a "high" value, we allow a callback to be called when this number is too high.
    23492358 * The typical use would be to create an additional consumer thread in this callback.
    23502359 * If the queue continues to grow, the callback will be called again when the length is 2 * high, then 3*high, ... N * high
    2351  * (the callback itself may implement a limit on the number of consumers that can be created)
     2360 * (the callback itself should implement a limit on the number of consumers that can be created)
    23522361 * When the queue starts to decrease, and the number of elements go under ((N - 1) * high + low, the l_cb callback is called
    2353  * and would typially stop one of the consumer threads. If the queue continue to reduce, l_cb is again called at (N-2)*high + low,
     2362 * and would typially stop one of the consumer threads. If the queue continues to reduce, l_cb is again called at (N-2)*high + low,
    23542363 * and so on.
    23552364 *
     
    23572366 * l_cb when the length of the queue is becoming < low.
    23582367 *
    2359  * Note that the callbacks are called synchronously, during fd_mq_post or fd_mq_get. Their operation should be quick.
     2368 * Note that the callbacks are called synchronously, during fd_fifo_post or fd_fifo_get. Their operation should be quick.
    23602369 *
    23612370 * RETURN VALUE:
     
    23632372 *  EINVAL      : A parameter is invalid.
    23642373 */
    2365 int fd_mq_setthrhd ( struct mqueue * queue, void * data, uint16_t high, void (*h_cb)(struct mqueue *, void **), uint16_t low, void (*l_cb)(struct mqueue *, void **) );
    2366 
    2367 /*
    2368  * FUNCTION:    fd_mq_post
    2369  *
    2370  * PARAMETERS:
    2371  *  queue       : The queue in which the message must be posted.
    2372  *  msg         : The message that is put in the queue.
    2373  *
    2374  * DESCRIPTION:
    2375  *  A message is added in a queue. Messages are retrieved from the queue (in FIFO order)
    2376  *  with the fd_mq_get, fd_mq_tryget, or fd_mq_timedget functions.
    2377  *
    2378  * RETURN VALUE:
    2379  *  0           : The message is queued.
     2374int fd_fifo_setthrhd ( struct fifo * queue, void * data, uint16_t high, void (*h_cb)(struct fifo *, void **), uint16_t low, void (*l_cb)(struct fifo *, void **) );
     2375
     2376/*
     2377 * FUNCTION:    fd_fifo_post
     2378 *
     2379 * PARAMETERS:
     2380 *  queue       : The queue in which the element must be posted.
     2381 *  item        : The element that is put in the queue.
     2382 *
     2383 * DESCRIPTION:
     2384 *  An element is added in a queue. Elements are retrieved from the queue in FIFO order
     2385 *  with the fd_fifo_get, fd_fifo_tryget, or fd_fifo_timedget functions.
     2386 *
     2387 * RETURN VALUE:
     2388 *  0           : The element is queued.
    23802389 *  EINVAL      : A parameter is invalid.
    23812390 *  ENOMEM      : Not enough memory to complete the operation.
    23822391 */
    2383 int fd_mq_post ( struct mqueue * queue, struct msg ** msg );
    2384 
    2385 /*
    2386  * FUNCTION:    fd_mq_get
    2387  *
    2388  * PARAMETERS:
    2389  *  queue       : The queue from which the message must be retrieved.
    2390  *  msg         : On return, the first message of the queue is stored here.
    2391  *
    2392  * DESCRIPTION:
    2393  *  This function retrieves a message from a queue. If the queue is empty, the function will block the
    2394  * thread until a new message is posted to the queue, or until the thread is canceled (in which case the
     2392int fd_fifo_post_int ( struct fifo * queue, void ** item );
     2393#define fd_fifo_post(queue, item) \
     2394        fd_fifo_post_int((queue), (void *)(item))
     2395
     2396/*
     2397 * FUNCTION:    fd_fifo_get
     2398 *
     2399 * PARAMETERS:
     2400 *  queue       : The queue from which the first element must be retrieved.
     2401 *  item        : On return, the first element of the queue is stored here.
     2402 *
     2403 * DESCRIPTION:
     2404 *  This function retrieves the first element from a queue. If the queue is empty, the function will block the
     2405 * thread until a new element is posted to the queue, or until the thread is canceled (in which case the
    23952406 * function does not return).
    23962407 *
    23972408 * RETURN VALUE:
    2398  *  0           : A new message has been retrieved.
    2399  *  EINVAL      : A parameter is invalid.
    2400  */
    2401 int fd_mq_get ( struct mqueue * queue, struct msg ** msg );
    2402 
    2403 /*
    2404  * FUNCTION:    fd_mq_tryget
    2405  *
    2406  * PARAMETERS:
    2407  *  queue       : The queue from which the message must be retrieved.
     2409 *  0           : A new element has been retrieved.
     2410 *  EINVAL      : A parameter is invalid.
     2411 */
     2412int fd_fifo_get_int ( struct fifo * queue, void ** item );
     2413#define fd_fifo_get(queue, item) \
     2414        fd_fifo_get_int((queue), (void *)(item))
     2415
     2416/*
     2417 * FUNCTION:    fd_fifo_tryget
     2418 *
     2419 * PARAMETERS:
     2420 *  queue       : The queue from which the element must be retrieved.
    24082421 *  msg         : On return, the message is stored here.
    24092422 *
    24102423 * DESCRIPTION:
    2411  *  This function is similar to fd_mq_get, except that it will not block if
     2424 *  This function is similar to fd_fifo_get, except that it will not block if
    24122425 * the queue is empty, but return EWOULDBLOCK instead.
    24132426 *
    24142427 * RETURN VALUE:
    2415  *  0           : A new message has been retrieved.
     2428 *  0           : A new element has been retrieved.
    24162429 *  EINVAL      : A parameter is invalid.
    24172430 *  EWOULDBLOCK : The queue was empty.
    24182431 */
    2419 int fd_mq_tryget ( struct mqueue * queue, struct msg ** msg );
    2420 
    2421 /*
    2422  * FUNCTION:    fd_mq_timedget
    2423  *
    2424  * PARAMETERS:
    2425  *  queue       : The queue from which the message must be retrieved.
    2426  *  msg         : On return, the message is stored here.
    2427  *  abstime     : the absolute time until which we allow waiting for a message.
    2428  *
    2429  * DESCRIPTION:
    2430  *  This function is similar to fd_mq_get, except that it will block if the queue is empty
     2432int fd_fifo_tryget_int ( struct fifo * queue, void ** item );
     2433#define fd_fifo_tryget(queue, item) \
     2434        fd_fifo_tryget_int((queue), (void *)(item))
     2435
     2436/*
     2437 * FUNCTION:    fd_fifo_timedget
     2438 *
     2439 * PARAMETERS:
     2440 *  queue       : The queue from which the element must be retrieved.
     2441 *  item        : On return, the element is stored here.
     2442 *  abstime     : the absolute time until which we allow waiting for an item.
     2443 *
     2444 * DESCRIPTION:
     2445 *  This function is similar to fd_fifo_get, except that it will block if the queue is empty
    24312446 * only until the absolute time abstime (see pthread_cond_timedwait for + info).
    24322447 * If the queue is still empty when the time expires, the function returns ETIMEDOUT
    24332448 *
    24342449 * RETURN VALUE:
    2435  *  0           : A new message has been retrieved.
    2436  *  EINVAL      : A parameter is invalid.
    2437  *  ETIMEDOUT   : The time out has passed and no message has been received.
    2438  */
    2439 int fd_mq_timedget ( struct mqueue * queue, struct msg ** msg, const struct timespec *abstime );
     2450 *  0           : A new item has been retrieved.
     2451 *  EINVAL      : A parameter is invalid.
     2452 *  ETIMEDOUT   : The time out has passed and no item has been received.
     2453 */
     2454int fd_fifo_timedget_int ( struct fifo * queue, void ** item, const struct timespec *abstime );
     2455#define fd_fifo_timedget(queue, item, abstime) \
     2456        fd_fifo_timedget_int((queue), (void *)(item), (abstime))
    24402457
    24412458#endif /* _LIBFREEDIAMETER_H */
Note: See TracChangeset for help on using the changeset viewer.