/** * @file daemon.h * * @brief Interface of daemon_t. * */ /* * Copyright (C) 2005 Jan Hutter, Martin Willi * Hochschule fuer Technik Rapperswil * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. See . * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. */ #ifndef DAEMON_H_ #define DAEMON_H_ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /** * @mainpage * * @section Threading Architecture * * All IKEv2 stuff is handled in charon. It uses a newer and more flexible * architecture than pluto. Charon uses a thread-pool, which allows parallel * execution SA-management. Beside the thread-pool, there are some special purpose * threads which do their job for the common health of the daemon. @verbatim +------+ | E Q | | v u |---+ +------+ +------+ | e e | | | | | IKE- | | n u | +-----------+ | |--| SA | | t e | | | | I M | +------+ +------------+ | - | | Scheduler | | K a | | receiver | +------+ | | | E n | +------+ +----+-------+ +-----------+ | - a | | IKE- | | | +------+ | | S g |--| SA | +-------+--+ +-----| J Q |---+ +------------+ | A e | +------+ -| socket | | o u | | | | - r | +-------+--+ | b e | | Thread- | | | | | - u | | Pool | | | +----+-------+ | e |------| |---| | | sender | +------+ +------------+ +------+ +----+-------+ | +------+ | | S Q | | | e u | | | n e | +------------| d u | | - e | +--+---+ @endverbatim * The thread-pool is the heart of the architecture. It processes jobs from a * (fully synchronized) job-queue. Mostly, a job is associated with a specific * IKE SA. These IKE SAs are synchronized, only one thread can work one an IKE SA. * This makes it unnecesary to use further synchronisation methods once a IKE SA * is checked out. The (rather complex) synchronization of IKE SAs is completely * done in the IKE SA manager. * The sceduler is responsible for event firing. It waits until a event in the * (fully synchronized) event-queue is ready for processing and pushes the event * down to the job-queue. A thread form the pool will pick it up as quick as * possible. Every thread can queue events or jobs. Furter, an event can place a * packet in the send-queue. The sender thread waits for those packets and sends * them over the wire, via the socket. The receiver does exactly the opposite of * the sender. It waits on the socket, reads in packets an places them on the * job-queue for further processing by a thread from the pool. * There are even more threads, not drawn in the upper scheme. The stroke thread * is responsible for reading and processessing commands from another process. The * kernel interface thread handles communication from and to the kernel via a * netlink socket. It waits for kernel events and processes them appropriately. */ /** * Name of the daemon. */ #define DAEMON_NAME "charon" /** * @brief Number of threads in the thread pool. * * There are several other threads, this defines * only the number of threads in thread_pool_t. */ #define NUMBER_OF_WORKING_THREADS 4 /** * UDP Port on which the daemon will listen for incoming traffic. */ #define IKEV2_UDP_PORT 500 /** * PID file, in which charon stores its process id */ #define PID_FILE "/var/run/charon.pid" /** * Output of log, use NULL for syslog */ #define LOG_OUTPUT NULL /** * @brief Default loglevel for every logger context. * * This is the maximum allowed level for ever context, the definiton * of the context may be less verbose. */ #define DEFAULT_LOGLEVEL CONTROL | ERROR | AUDIT typedef struct daemon_t daemon_t; /** * @brief Main class of daemon, contains some globals. */ struct daemon_t { /** * A socket_t instance. */ socket_t *socket; /** * A send_queue_t instance. */ send_queue_t *send_queue; /** * A job_queue_t instance. */ job_queue_t *job_queue; /** * A event_queue_t instance. */ event_queue_t *event_queue; /** * A logger_manager_t instance. */ logger_manager_t *logger_manager; /** * A ike_sa_manager_t instance. */ ike_sa_manager_t *ike_sa_manager; /** * A configuration_t instance. */ configuration_t *configuration; /** * A connection_store_t instance. */ connection_store_t *connections; /** * A policy_store_t instance. */ policy_store_t *policies; /** * A credential_store_t instance. */ credential_store_t *credentials; /** * The Sender-Thread. */ sender_t *sender; /** * The Receiver-Thread. */ receiver_t *receiver; /** * The Scheduler-Thread. */ scheduler_t *scheduler; /** * The Thread pool managing the worker threads. */ thread_pool_t *thread_pool; /** * Kernel Interface to communicate with kernel */ kernel_interface_t *kernel_interface; /** * IPC interface, as whack in pluto */ stroke_t *stroke; /** * @brief Shut down the daemon. * * @param this the daemon to kill * @param reason describtion why it will be killed */ void (*kill) (daemon_t *this, char *reason); }; /** * The one and only instance of the daemon. */ extern daemon_t *charon; #endif /*DAEMON_H_*/