Allow building WITHOUT_STATS
[freeradius.git] / src / include / radiusd.h
index 6e4cf5f..0c625b0 100644 (file)
@@ -35,19 +35,10 @@ RCSIDH(radiusd_h, "$Id$")
 
 typedef struct auth_req REQUEST;
 
-#include <freeradius-devel/realms.h>
-
 #ifdef HAVE_PTHREAD_H
 #include       <pthread.h>
-typedef pthread_t child_pid_t;
-#define child_kill pthread_kill
-#else
-typedef pid_t child_pid_t;
-#define child_kill kill
 #endif
 
-#define NO_SUCH_CHILD_PID (child_pid_t) (0)
-
 #ifndef NDEBUG
 #define REQUEST_MAGIC (0xdeadbeef)
 #endif
@@ -76,13 +67,49 @@ typedef pid_t child_pid_t;
 #define WITH_UNLANG (1)
 #endif
 
+#ifndef WITHOUT_ACCOUNTING
+#define WITH_ACCOUNTING (1)
+#else
+#ifdef WITH_SESSION_MGMT
+#error WITH_SESSION_MGMT is defined, but WITH_ACCOUNTING is not.  Session management requires accounting.
+#endif
+#ifdef WITH_DETAIL
+#error WITH_DETAIL is defined, but WITH_ACCOUNTING is not.  Detail file reading requires accounting.
+#endif
+#endif
+
+#ifndef WITHOUT_DYNAMIC_CLIENTS
+#define WITH_DYNAMIC_CLIENTS (1)
+#endif
+
+#ifndef WITHOUT_STATS
+#define WITH_STATS
+#endif
+
+#ifndef WITHOUT_COMMAND_SOCKET
+#ifdef HAVE_SYS_UN_H
+#define WITH_COMMAND_SOCKET (1)
+#else
+#define WITHOUT_COMMAND_SOCKET (1)
+#endif
+#endif
+
+#ifndef WITHOUT_COA
+#define WITH_COA (1)
+#ifndef WITH_PROXY
+#error WITH_COA requires WITH_PROXY
+#endif
+#endif
+
+#include <freeradius-devel/stats.h>
+#include <freeradius-devel/realms.h>
+
+
 /*
  *     See util.c
  */
 typedef struct request_data_t request_data_t;
 
-typedef struct rad_snmp_client_entry_t rad_snmp_client_entry_t;
-
 typedef struct radclient {
        fr_ipaddr_t             ipaddr;
        int                     prefix;
@@ -96,8 +123,32 @@ typedef struct radclient {
        char                    *server;
        int                     number; /* internal use only */
        const CONF_SECTION      *cs;
-#ifdef WITH_SNMP
-       rad_snmp_client_entry_t *auth, *acct;
+#ifdef WITH_STATS
+       fr_stats_t              *auth;
+#ifdef WITH_ACCOUNTING
+       fr_stats_t              *acct;
+#endif
+#endif
+
+       int                     proto;
+#ifdef WITH_TCP
+       int                     max_connections;
+       int                     num_connections;
+#endif
+
+#ifdef WITH_DYNAMIC_CLIENTS
+       int                     lifetime;
+       int                     dynamic; /* was dynamically defined */
+       time_t                  created;
+       time_t                  last_new_client;
+       char                    *client_server;
+       int                     rate_limit;
+#endif
+
+#ifdef WITH_COA
+       char                    *coa_name;
+       home_server             *coa_server;
+       home_pool_t             *coa_pool;
 #endif
 } RADCLIENT;
 
@@ -108,13 +159,28 @@ typedef struct radclient {
  */
 typedef enum RAD_LISTEN_TYPE {
        RAD_LISTEN_NONE = 0,
+#ifdef WITH_PROXY
        RAD_LISTEN_PROXY,
+#endif
        RAD_LISTEN_AUTH,
+#ifdef WITH_ACCOUNTING
        RAD_LISTEN_ACCT,
+#endif
+#ifdef WITH_DETAIL
        RAD_LISTEN_DETAIL,
+#endif
+#ifdef WITH_VMPS
        RAD_LISTEN_VQP,
+#endif
+#ifdef WITH_DHCP
        RAD_LISTEN_DHCP,
-       RAD_LISTEN_SNMP,
+#endif
+#ifdef WITH_COMMAND_SOCKET
+       RAD_LISTEN_COMMAND,
+#endif
+#ifdef WITH_COA
+       RAD_LISTEN_COA,
+#endif
        RAD_LISTEN_MAX
 } RAD_LISTEN_TYPE;
 
@@ -123,6 +189,7 @@ typedef enum RAD_LISTEN_TYPE {
  *     For listening on multiple IP's and ports.
  */
 typedef struct rad_listen_t rad_listen_t;
+typedef                void (*radlog_func_t)(int, int, REQUEST *, const char *, ...);
 
 #define REQUEST_DATA_REGEX (0xadbeef00)
 #define REQUEST_MAX_REGEX (8)
@@ -147,9 +214,11 @@ struct auth_req {
 
        request_data_t          *data;
        RADCLIENT               *client;
-       child_pid_t             child_pid;
+#ifdef HAVE_PTHREAD_H
+       pthread_t               child_pid;
+#endif
        time_t                  timestamp;
-       int                     number; /* internal server number */
+       unsigned int            number; /* internal server number */
 
        rad_listen_t            *listener;
 #ifdef WITH_PROXY
@@ -194,9 +263,18 @@ struct auth_req {
 
        const char              *server;
        REQUEST                 *parent;
+       radlog_func_t           radlog; /* logging function, if set */
+#ifdef WITH_COA
+       REQUEST                 *coa;
+       int                     num_coa_requests;
+#endif
 };                             /* REQUEST typedef */
 
 #define RAD_REQUEST_OPTION_NONE            (0)
+#define RAD_REQUEST_OPTION_DEBUG           (1)
+#define RAD_REQUEST_OPTION_DEBUG2          (2)
+#define RAD_REQUEST_OPTION_DEBUG3          (3)
+#define RAD_REQUEST_OPTION_DEBUG4          (4)
 
 #define REQUEST_ACTIVE                 (1)
 #define REQUEST_STOP_PROCESSING (2)
@@ -229,7 +307,7 @@ typedef struct pair_list {
 
 typedef int (*rad_listen_recv_t)(rad_listen_t *, RAD_REQUEST_FUNP *, REQUEST **);
 typedef int (*rad_listen_send_t)(rad_listen_t *, REQUEST *);
-typedef int (*rad_listen_print_t)(rad_listen_t *, char *, size_t);
+typedef int (*rad_listen_print_t)(const rad_listen_t *, char *, size_t);
 typedef int (*rad_listen_encode_t)(rad_listen_t *, REQUEST *);
 typedef int (*rad_listen_decode_t)(rad_listen_t *, REQUEST *);
 
@@ -242,6 +320,10 @@ struct rad_listen_t {
        RAD_LISTEN_TYPE type;
        int             fd;
        const char      *server;
+       int             status;
+#ifdef WITH_TCP
+       int             count;
+#endif
 
        rad_listen_recv_t recv;
        rad_listen_send_t send;
@@ -250,8 +332,56 @@ struct rad_listen_t {
        rad_listen_print_t print;
 
        void            *data;
+
+#ifdef WITH_STATS
+       fr_stats_t      stats;
+#endif
 };
 
+/*
+ *     This shouldn't really be exposed...
+ */
+typedef struct listen_socket_t {
+       /*
+        *      For normal sockets.
+        */
+       fr_ipaddr_t     my_ipaddr;
+       int             my_port;
+
+       const char      *interface;
+#ifdef SO_BROADCAST
+       int             broadcast;
+#endif
+       
+       /* for outgoing sockets */
+       home_server     *home;
+       fr_ipaddr_t     other_ipaddr;
+       int             other_port;
+
+       int             proto;
+
+#ifdef WITH_TCP
+       /* for a proxy connecting to home servers */
+       time_t          last_packet;
+       time_t          opened;
+       fr_event_t      *ev;
+
+       /* for clients connecting to the server */
+       int             max_connections;
+       int             num_connections;
+       struct listen_socket_t *parent;
+       RADCLIENT       *client;
+
+       RADIUS_PACKET   *packet; /* for reading partial packets */
+#endif
+       RADCLIENT_LIST  *clients;
+} listen_socket_t;
+
+#define RAD_LISTEN_STATUS_INIT   (0)
+#define RAD_LISTEN_STATUS_KNOWN  (1)
+#define RAD_LISTEN_STATUS_REMOVE_FD (2)
+#define RAD_LISTEN_STATUS_CLOSED (3)
+#define RAD_LISTEN_STATUS_FINISH (4)
 
 typedef enum radlog_dest_t {
   RADLOG_STDOUT = 0,
@@ -272,7 +402,9 @@ typedef struct main_config_t {
        int             log_auth_goodpass;
        int             allow_core_dumps;
        int             debug_level;
+#ifdef WITH_PROXY
        int             proxy_requests;
+#endif
        int             reject_delay;
        int             status_server;
        int             max_request_time;
@@ -290,12 +422,26 @@ typedef struct main_config_t {
        radlog_dest_t   radlog_dest;
        CONF_SECTION    *config;
        const char      *name;
-       int             do_snmp;
+       const char      *auth_badpass_msg;
+       const char      *auth_goodpass_msg;
 } MAIN_CONFIG_T;
 
 #define DEBUG  if(debug_flag)log_debug
 #define DEBUG2  if (debug_flag > 1)log_debug
 #define DEBUG3  if (debug_flag > 2)log_debug
+#define DEBUG4  if (debug_flag > 3)log_debug
+
+#if __GNUC__ >= 3
+#define RDEBUG(fmt, ...)   if(request && request->radlog) request->radlog(L_DBG, 1, request, fmt, ## __VA_ARGS__)
+#define RDEBUG2(fmt, ...)  if(request && request->radlog) request->radlog(L_DBG, 2, request, fmt, ## __VA_ARGS__)
+#define RDEBUG3(fmt, ...)  if(request && request->radlog) request->radlog(L_DBG, 3, request, fmt, ## __VA_ARGS__)
+#define RDEBUG4(fmt, ...)  if(request && request->radlog) request->radlog(L_DBG, 4, request, fmt, ## __VA_ARGS__)
+#else
+#define RDEBUG  DEBUG
+#define RDEBUG2 DEBUG2
+#define RDEBUG3 DEBUG3
+#define RDEBUG4 DEBUG4
+#endif
 
 #define SECONDS_PER_DAY                86400
 #define MAX_REQUEST_TIME       30
@@ -398,6 +544,7 @@ int         rad_checkfilename(const char *filename);
 void           *rad_malloc(size_t size); /* calls exit(1) on error! */
 REQUEST                *request_alloc(void);
 REQUEST                *request_alloc_fake(REQUEST *oldreq);
+REQUEST                *request_alloc_coa(REQUEST *request);
 int            request_data_add(REQUEST *request,
                                 void *unique_ptr, int unique_int,
                                 void *opaque, void (*free_opaque)(void *));
@@ -414,11 +561,20 @@ void              clients_free(RADCLIENT_LIST *clients);
 RADCLIENT_LIST *clients_parse_section(CONF_SECTION *section);
 void           client_free(RADCLIENT *client);
 int            client_add(RADCLIENT_LIST *clients, RADCLIENT *client);
+#ifdef WITH_DYNAMIC_CLIENTS
+void           client_delete(RADCLIENT_LIST *clients, RADCLIENT *client);
+RADCLIENT      *client_create(RADCLIENT_LIST *clients, REQUEST *request);
+#endif
 RADCLIENT      *client_find(const RADCLIENT_LIST *clients,
-                            const fr_ipaddr_t *ipaddr);
+                            const fr_ipaddr_t *ipaddr, int proto);
+
 RADCLIENT      *client_findbynumber(const RADCLIENT_LIST *clients,
                                     int number);
 RADCLIENT      *client_find_old(const fr_ipaddr_t *ipaddr);
+int            client_validate(RADCLIENT_LIST *clients, RADCLIENT *master,
+                               RADCLIENT *c);
+RADCLIENT      *client_read(const char *filename, int in_server, int flag);
+
 
 /* files.c */
 int            pairlist_read(const char *file, PAIR_LIST **list, int complain);
@@ -440,6 +596,11 @@ int                log_debug(const char *, ...)
 #endif
 ;
 void           vp_listdebug(VALUE_PAIR *vp);
+void radlog_request(int lvl, int priority, REQUEST *request, const char *msg, ...)
+#ifdef __GNUC__
+               __attribute__ ((format (printf, 4, 5)))
+#endif
+;
 
 /* auth.c */
 char   *auth_name(char *buf, size_t buflen, REQUEST *request, int do_cli);
@@ -470,7 +631,7 @@ int radius_callback_compare(REQUEST *req, VALUE_PAIR *request,
                            VALUE_PAIR **reply_pairs);
 int radius_find_compare(int attribute);
 VALUE_PAIR     *radius_paircreate(REQUEST *request, VALUE_PAIR **vps,
-                                 int attribute, int type);
+                                  int attribute, int vendor, int type);
 VALUE_PAIR *radius_pairmake(REQUEST *request, VALUE_PAIR **vps,
                            const char *attribute, const char *value,
                            int operator);
@@ -487,13 +648,14 @@ void              xlat_unregister(const char *module, RAD_XLAT_FUNC func);
 void           xlat_free(void);
 
 /* threads.c */
-extern         int thread_pool_init(CONF_SECTION *cs, int spawn_flag);
+extern         int thread_pool_init(CONF_SECTION *cs, int *spawn_flag);
 extern         int thread_pool_addrequest(REQUEST *, RAD_REQUEST_FUNP);
 extern         pid_t rad_fork(void);
 extern         pid_t rad_waitpid(pid_t pid, int *status);
 extern          int total_active_threads(void);
 extern          void thread_pool_lock(void);
 extern          void thread_pool_unlock(void);
+extern         void thread_pool_queue_stats(int *array);
 
 #ifndef HAVE_PTHREAD_H
 #define rad_fork(n) fork()
@@ -506,13 +668,23 @@ extern struct main_config_t mainconfig;
 
 int read_mainconfig(int reload);
 int free_mainconfig(void);
+void hup_mainconfig(void);
+void fr_suid_down(void);
+void fr_suid_up(void);
+void fr_suid_down_permanent(void);
 
 /* listen.c */
 void listen_free(rad_listen_t **head);
 int listen_init(CONF_SECTION *cs, rad_listen_t **head);
-rad_listen_t *proxy_new_listener(void);
+int proxy_new_listener(home_server *home, int src_port);
 RADCLIENT *client_listener_find(const rad_listen_t *listener,
-                               const fr_ipaddr_t *ipaddr);
+                               const fr_ipaddr_t *ipaddr, int src_port);
+
+#ifdef WITH_STATS
+RADCLIENT_LIST *listener_find_client_list(const fr_ipaddr_t *ipaddr,
+                                         int port);
+#endif
+rad_listen_t *listener_find_byipaddr(const fr_ipaddr_t *ipaddr, int port);
 
 /* event.c */
 int radius_event_init(CONF_SECTION *cs, int spawn_flag);
@@ -523,6 +695,7 @@ int received_request(rad_listen_t *listener,
                     RADIUS_PACKET *packet, REQUEST **prequest,
                     RADCLIENT *client);
 REQUEST *received_proxy_response(RADIUS_PACKET *packet);
+int event_new_fd(rad_listen_t *listener);
 
 /* evaluate.c */
 int radius_evaluate_condition(REQUEST *request, int modreturn, int depth,