0e1441750258410d6ad66c86bc8554859e078547
[freeradius.git] / src / include / realms.h
1 #ifndef REALMS_H
2 #define REALMS_H
3
4 /*
5  * realms.h     Structures, prototypes and global variables
6  *              for realms
7  *
8  * Version:     $Id$
9  *
10  */
11
12 #include <freeradius-devel/ident.h>
13 RCSIDH(realms_h, "$Id$")
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 #define HOME_TYPE_INVALID (0)
20 #define HOME_TYPE_AUTH    (1)
21 #define HOME_TYPE_ACCT    (2)
22 #ifdef WITH_COA
23 #define HOME_TYPE_COA     (3)
24 #endif
25
26 #define HOME_PING_CHECK_NONE            (0)
27 #define HOME_PING_CHECK_STATUS_SERVER   (1)
28 #define HOME_PING_CHECK_REQUEST         (2)
29
30 #define HOME_STATE_ALIVE                (0)
31 #define HOME_STATE_ZOMBIE               (1)
32 #define HOME_STATE_IS_DEAD              (2)
33 #define HOME_STATE_UNKNOWN              (3)
34
35 typedef struct fr_socket_limit_t {
36         int             max_connections;
37         int             num_connections;
38         int             max_requests;
39         int             num_requests;
40         int             lifetime;
41         int             idle_timeout;
42 } fr_socket_limit_t;
43
44 typedef struct home_server {
45         const char      *name;
46
47         const char      *hostname;
48         const char      *server; /* for internal proxying */
49         const char      *parent_server;
50
51         fr_ipaddr_t     ipaddr;
52
53         int             port;
54         int             type;           /* auth/acct */
55
56         int             proto;
57         fr_socket_limit_t limit;
58
59         fr_ipaddr_t     src_ipaddr; /* preferred source IP address */
60
61         const char      *secret;
62
63         fr_event_t      *ev;
64         struct timeval  when;
65
66         int             response_window;
67         int             max_outstanding; /* don't overload it */
68         int             currently_outstanding;
69
70         time_t          last_packet_sent;
71         time_t          last_packet_recv;
72         struct timeval  revive_time;
73         struct timeval  zombie_period_start;
74         int             zombie_period; /* unresponsive for T, mark it dead */
75
76         int             state;
77
78         int             ping_check;
79         const char      *ping_user_name;
80         const char      *ping_user_password;
81
82         int             ping_interval;
83         int             num_pings_to_alive;
84         int             num_sent_pings;
85         int             num_received_pings;
86         int             ping_timeout;
87
88         int             revive_interval; /* if it doesn't support pings */
89         CONF_SECTION    *cs;
90 #ifdef WITH_COA
91         int                     coa_irt;
92         int                     coa_mrc;
93         int                     coa_mrt;
94         int                     coa_mrd;
95 #endif
96 #ifdef WITH_TLS
97         fr_tls_server_conf_t    *tls;
98 #endif
99
100 #ifdef WITH_STATS
101         int             number;
102
103         fr_stats_t      stats;
104
105         fr_stats_ema_t  ema;
106 #endif
107 } home_server;
108
109
110 typedef enum home_pool_type_t {
111         HOME_POOL_INVALID = 0,
112         HOME_POOL_LOAD_BALANCE,
113         HOME_POOL_FAIL_OVER,
114         HOME_POOL_CLIENT_BALANCE,
115         HOME_POOL_CLIENT_PORT_BALANCE,
116         HOME_POOL_KEYED_BALANCE
117 } home_pool_type_t;
118
119
120 typedef struct home_pool_t {
121         const char              *name;
122         home_pool_type_t        type;
123
124         int                     server_type;
125         CONF_SECTION            *cs;
126
127         const char              *virtual_server; /* for pre/post-proxy */
128         
129         home_server             *fallback;
130         int                     in_fallback;
131         time_t                  time_all_dead;
132
133         int                     num_home_servers;
134         home_server             *servers[1];
135 } home_pool_t;
136
137
138 typedef struct _realm {
139         const char              *name;
140
141         int                     striprealm;
142
143         home_pool_t             *auth_pool;
144         home_pool_t             *acct_pool;
145 #ifdef WITH_COA
146         home_pool_t             *coa_pool;
147 #endif
148 } REALM;
149
150 int realms_init(CONF_SECTION *config);
151 void realms_free(void);
152 REALM *realm_find(const char *name); /* name is from a packet */
153 REALM *realm_find2(const char *name); /* ... with name taken from realm_find */
154   int realms_home_server_add(home_server *home, CONF_SECTION *cs, int dual);
155   int realms_pool_add(home_pool_t *pool, CONF_SECTION *cs);
156   int realms_realm_add( REALM *r, CONF_SECTION *cs);
157
158
159 void home_server_update_request(home_server *home, REQUEST *request);
160 home_server *home_server_ldb(const char *realmname, home_pool_t *pool, REQUEST *request);
161 home_server *home_server_find(fr_ipaddr_t *ipaddr, int port, int proto);
162 #ifdef WITH_COA
163 home_server *home_server_byname(const char *name, int type);
164 #endif
165 #ifdef WITH_STATS
166 home_server *home_server_bynumber(int number);
167 #endif
168 home_pool_t *home_pool_byname(const char *name, int type);
169
170 #ifdef __cplusplus
171 }
172 #endif
173
174 #endif /* REALMS_H */