All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
clients.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15  */
16 #ifndef _FR_CLIENTS_H
17 #define _FR_CLIENTS_H
18 /**
19  * $Id: 3de383ea58cdc983dcc430dac180f64ad489e527 $
20  *
21  * @file include/clients.h
22  * @brief API to add client definitions to the server, both on startup and at runtime.
23  *
24  * @author Arran Cudbard-Bell <a.cudbardb@freeradius.org>
25  * @copyright 2015 The FreeRADIUS server project
26  */
27 RCSIDH(clients_h, "$Id: 3de383ea58cdc983dcc430dac180f64ad489e527 $")
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 /** Describes a host allowed to send packets to the server
33  *
34  */
35 typedef struct radclient {
36  fr_ipaddr_t ipaddr; //!< IPv4/IPv6 address of the host.
37  fr_ipaddr_t src_ipaddr; //!< IPv4/IPv6 address to send responses
38  //!< from (family must match ipaddr).
39 
40  char const *longname; //!< Client identifier.
41  char const *shortname; //!< Client nickname.
42 
43  char const *secret; //!< Secret PSK.
44 
45  bool message_authenticator; //!< Require RADIUS message authenticator in requests.
46 
47  char const *nas_type; //!< Type of client (arbitrary).
48 
49  char const *login; //!< Username to use for simultaneous use checks.
50  char const *password; //!< Password to use for simultaneous use checks.
51 
52  char const *server; //!< Virtual server client is associated with.
53 
54  int number; //!< Unique client number.
55 
56  CONF_SECTION *cs; //!< CONF_SECTION that was parsed to generate the client.
57 
58 #ifdef WITH_STATS
59  fr_stats_t auth; //!< Authentication stats.
60 # ifdef WITH_ACCOUNTING
61  fr_stats_t acct; //!< Accounting stats.
62 # endif
63 # ifdef WITH_COA
64  fr_stats_t coa; //!< Change of Authorization stats.
65  fr_stats_t dsc; //!< Disconnect-Request stats.
66 # endif
67 #endif
68 
69  struct timeval response_window; //!< How long the client has to respond.
70 
71  int proto; //!< Protocol number.
72 #ifdef WITH_TCP
73  fr_socket_limit_t limit; //!< Connections per client (TCP clients only).
74 #endif
75 #ifdef WITH_TLS
76  bool tls_required; //!< whether TLS encryption is required.
77 #endif
78 
79 #ifdef WITH_DYNAMIC_CLIENTS
80  uint32_t lifetime; //!< How long before the client is removed.
81  uint32_t dynamic; //!< Whether the client was dynamically defined.
82  time_t created; //!< When the client was created.
83 
84  time_t last_new_client; //!< Used for relate limiting addition and deletion of
85  //!< dynamic clients.
86 
87  char const *client_server; //!< Virtual server associated with this dynamic client.
88  //!< Only used where client specifies a network of potential
89  //!< clients.
90 
91  bool rate_limit; //!< Where addition of clients should be rate limited.
92 #endif
93 
94 #ifdef WITH_COA
95  char const *coa_name; //!< Name of the CoA home server or pool.
96  home_server_t *coa_server; //!< The CoA home_server_t the client is associated with.
97  //!< Must be used exclusively from coa_pool.
98  home_pool_t *coa_pool; //!< The CoA home_pool_t the client is associated with.
99  //!< Must be used exclusively from coa_server.
100  bool defines_coa_server; //!< Client also defines a home_server.
101 #endif
102 } RADCLIENT;
103 
105 
106 /** Callback for retrieving values when building client sections
107  *
108  * Example:
109  @code{.c}
110  int _client_value_cb(char **out, CONF_PAIR const *cp, void *data)
111  {
112  my_result *result = data;
113  char *value;
114 
115  value = get_attribute_from_result(result, cf_pair_value(cp));
116  if (!value) {
117  *out = NULL;
118  return 0;
119  }
120 
121  *out = talloc_strdup(value);
122  free_attribute(value);
123 
124  if (!*out) return -1;
125  return 0;
126  }
127  @endcode
128  *
129  * @param[out] out Where to write a pointer to the talloced value buffer.
130  * @param[in] cp The value of the CONF_PAIR specifies the attribute name to retrieve from the result.
131  * @param[in] data Pointer to the result struct to copy values from.
132  * @return
133  * - 0 on success.
134  * - -1 on failure.
135  */
136 typedef int (*client_value_cb_t)(char **out, CONF_PAIR const *cp, void *data);
137 
139 
140 void client_list_free(RADCLIENT_LIST *clients);
141 
142 RADCLIENT_LIST *client_list_parse_section(CONF_SECTION *section, bool tls_required);
143 
144 void client_free(RADCLIENT *client);
145 
146 bool client_add(RADCLIENT_LIST *clients, RADCLIENT *client);
147 
148 #ifdef WITH_DYNAMIC_CLIENTS
149 void client_delete(RADCLIENT_LIST *clients, RADCLIENT *client);
150 
152 #endif
153 
155 
156 RADCLIENT *client_afrom_cs(TALLOC_CTX *ctx, CONF_SECTION *cs, bool in_server, bool with_coa);
157 
158 RADCLIENT *client_afrom_query(TALLOC_CTX *ctx, char const *identifier, char const *secret, char const *shortname,
159  char const *type, char const *server, bool require_ma)
160  CC_HINT(nonnull(2, 3));
161 
162 RADCLIENT *client_find(RADCLIENT_LIST const *clients, fr_ipaddr_t const *ipaddr, int proto);
163 
164 RADCLIENT *client_findbynumber(RADCLIENT_LIST const *clients, int number);
165 
166 RADCLIENT *client_find_old(fr_ipaddr_t const *ipaddr);
167 
168 bool client_add_dynamic(RADCLIENT_LIST *clients, RADCLIENT *master, RADCLIENT *c);
169 
170 RADCLIENT *client_read(char const *filename, int in_server, int flag);
171 #ifdef __cplusplus
172 }
173 #endif
174 #endif /* _FR_CLIENTS_H */
bool rate_limit
Where addition of clients should be rate limited.
Definition: clients.h:91
#define RCSIDH(h, id)
Definition: build.h:136
fr_stats_t coa
Change of Authorization stats.
Definition: clients.h:64
fr_socket_limit_t limit
Connections per client (TCP clients only).
Definition: clients.h:73
RADCLIENT * client_afrom_cs(TALLOC_CTX *ctx, CONF_SECTION *cs, bool in_server, bool with_coa)
Allocate a new client from a config section.
Definition: client.c:858
RADCLIENT_LIST * client_list_parse_section(CONF_SECTION *section, bool tls_required)
char const * nas_type
Type of client (arbitrary).
Definition: clients.h:47
uint32_t lifetime
How long before the client is removed.
Definition: clients.h:80
fr_stats_t dsc
Disconnect-Request stats.
Definition: clients.h:65
home_pool_t * coa_pool
The CoA home_pool_t the client is associated with.
Definition: clients.h:98
#define CC_HINT(_x)
Definition: build.h:71
bool client_add(RADCLIENT_LIST *clients, RADCLIENT *client)
Add a client to a RADCLIENT_LIST.
Definition: client.c:192
char const * secret
Secret PSK.
Definition: clients.h:43
RADCLIENT RADCLIENT * client_find(RADCLIENT_LIST const *clients, fr_ipaddr_t const *ipaddr, int proto)
Definition: client.c:431
fr_stats_t auth
Authentication stats.
Definition: clients.h:59
static expr_map_t map[]
Definition: rlm_expr.c:169
static char const * proto
Definition: radclient.c:63
bool client_add_dynamic(RADCLIENT_LIST *clients, RADCLIENT *master, RADCLIENT *c)
Add a dynamic client.
Definition: client.c:708
bool defines_coa_server
Client also defines a home_server.
Definition: clients.h:100
void client_delete(RADCLIENT_LIST *clients, RADCLIENT *client)
Definition: client.c:378
struct radclient RADCLIENT
Describes a host allowed to send packets to the server.
RADCLIENT * client_read(char const *filename, int in_server, int flag)
Definition: client.c:1449
char const * login
Username to use for simultaneous use checks.
Definition: clients.h:49
RADCLIENT * client_afrom_request(RADCLIENT_LIST *clients, REQUEST *request)
Create a new client, consuming all attributes in the control list of the request. ...
Definition: client.c:1175
fr_ipaddr_t ipaddr
IPv4/IPv6 address of the host.
Definition: clients.h:36
RADCLIENT * client_find_old(fr_ipaddr_t const *ipaddr)
Definition: client.c:472
CONF_SECTION * cs
CONF_SECTION that was parsed to generate the client.
Definition: clients.h:56
Configuration AVP similar to a VALUE_PAIR.
Definition: conffile.c:82
int(* client_value_cb_t)(char **out, CONF_PAIR const *cp, void *data)
Callback for retrieving values when building client sections.
Definition: clients.h:136
Describes a host allowed to send packets to the server.
Definition: clients.h:35
time_t created
When the client was created.
Definition: clients.h:82
uint8_t data[]
Definition: eap_pwd.h:625
uint32_t dynamic
Whether the client was dynamically defined.
Definition: clients.h:81
RADCLIENT * client_findbynumber(RADCLIENT_LIST const *clients, int number)
Definition: client.c:402
fr_ipaddr_t src_ipaddr
IPv4/IPv6 address to send responses from (family must match ipaddr).
Definition: clients.h:37
int proto
Protocol number.
Definition: clients.h:71
static char const * secret
Definition: radclient.c:44
home_server_t * coa_server
The CoA home_server_t the client is associated with.
Definition: clients.h:96
char const * longname
Client identifier.
Definition: clients.h:40
RADCLIENT_LIST * client_list_init(CONF_SECTION *cs)
Definition: client.c:173
struct timeval response_window
How long the client has to respond.
Definition: clients.h:69
void client_list_free(RADCLIENT_LIST *clients)
Definition: client.c:140
fr_stats_t acct
Accounting stats.
Definition: clients.h:61
IPv4/6 prefix.
Definition: inet.h:41
char const * client_server
Virtual server associated with this dynamic client.
Definition: clients.h:87
char const * coa_name
Name of the CoA home server or pool.
Definition: clients.h:95
bool message_authenticator
Require RADIUS message authenticator in requests.
Definition: clients.h:45
time_t last_new_client
Used for relate limiting addition and deletion of dynamic clients.
Definition: clients.h:84
RADCLIENT * client_afrom_query(TALLOC_CTX *ctx, char const *identifier, char const *secret, char const *shortname, char const *type, char const *server, bool require_ma) CC_HINT(nonnull(2
char const * server
Virtual server client is associated with.
Definition: clients.h:52
int number
Unique client number.
Definition: clients.h:54
int client_map_section(CONF_SECTION *out, CONF_SECTION const *map, client_value_cb_t func, void *data)
Create a client CONF_SECTION using a mapping section to map values from a result set to client attrib...
Definition: client.c:775
char const * password
Password to use for simultaneous use checks.
Definition: clients.h:50
char const * shortname
Client nickname.
Definition: clients.h:41
void client_free(RADCLIENT *client)
Definition: client.c:62