The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
client.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16  */
17 
18 /**
19  * $Id: e07ed4bd8df39839b4811b97fef620cc2e3a8b0a $
20  *
21  * @file lib/server/client.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: e07ed4bd8df39839b4811b97fef620cc2e3a8b0a $")
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 typedef struct fr_client_s fr_client_t;
34 typedef struct fr_client_list_s fr_client_list_t;
35 
36 /** Callback for retrieving values when building client sections
37  *
38  * Example:
39  @code{.c}
40  int _client_value_cb(char **out, CONF_PAIR const *cp, void *data)
41  {
42  my_result *result = data;
43  char *value;
44 
45  value = get_attribute_from_result(result, cf_pair_value(cp));
46  if (!value) {
47  *out = NULL;
48  return 0;
49  }
50 
51  *out = talloc_strdup(value);
52  free_attribute(value);
53 
54  if (!*out) return -1;
55  return 0;
56  }
57  @endcode
58  *
59  * @param[out] out Where to write a pointer to the talloced value buffer.
60  * @param[in] cp The value of the CONF_PAIR specifies the attribute name to retrieve from the result.
61  * @param[in] data Pointer to the result struct to copy values from.
62  * @return
63  * - 0 on success.
64  * - -1 on failure.
65  */
66 typedef int (*client_value_cb_t)(char **out, CONF_PAIR const *cp, void *data);
67 
68 #include <freeradius-devel/util/time.h>
69 #include <freeradius-devel/server/request.h>
70 #include <freeradius-devel/server/socket.h>
71 #include <freeradius-devel/server/stats.h>
72 #include <freeradius-devel/util/inet.h>
73 
74 /** Describes a host allowed to send packets to the server
75  *
76  */
77 struct fr_client_s {
78  fr_rb_node_t node; //!< Entry in the client tree.
79 
80  fr_ipaddr_t ipaddr; //!< IPv4/IPv6 address of the host.
81  fr_ipaddr_t src_ipaddr; //!< IPv4/IPv6 address to send responses
82  //!< from (family must match ipaddr).
83 
84  char const *longname; //!< Client identifier.
85  char const *shortname; //!< Client nickname.
86 
87  char const *secret; //!< Secret PSK.
88 
89  bool message_authenticator; //!< Require RADIUS message authenticator in requests.
90  bool dynamic; //!< Whether the client was dynamically defined.
91  bool active; //!< for dynamic clients
92  bool use_connected; //!< do we use connected sockets for this client
93  bool dedup_authenticator; //!< more RADIUS stuff
94 
95 #ifdef WITH_TLS
96  bool tls_required; //!< whether TLS encryption is required.
97 #endif
98 
99  char const *nas_type; //!< Type of client (arbitrary).
100 
101  char const *server; //!< Name of the virtual server client is associated with.
102  CONF_SECTION *server_cs; //!< Virtual server that the client is associated with
103 
104  int number; //!< Unique client number.
105 
106  CONF_SECTION *cs; //!< CONF_SECTION that was parsed to generate the client.
107 
108 #ifdef WITH_STATS
109  fr_stats_t auth; //!< Authentication stats.
110  fr_stats_t acct; //!< Accounting stats.
111 #endif
112 
113  fr_time_delta_t response_window; //!< How long the client has to respond.
114 
115  int proto; //!< Protocol number.
116  fr_socket_limit_t limit; //!< Connections per client (TCP clients only).
117 };
118 
120 
121 void client_list_free(void);
122 
124 
125 void client_free(fr_client_t *client);
126 
127 bool client_add(fr_client_list_t *clients, fr_client_t *client);
128 
129 void client_delete(fr_client_list_t *clients, fr_client_t *client);
130 
131 fr_client_t *client_afrom_request(TALLOC_CTX *ctx, request_t *request);
132 
134 
135 fr_client_t *client_afrom_cs(TALLOC_CTX *ctx, CONF_SECTION *cs, CONF_SECTION *server_cs, size_t extra);
136 
137 fr_client_t *client_find(fr_client_list_t const *clients, fr_ipaddr_t const *ipaddr, int proto);
138 
139 fr_client_t *client_findbynumber(fr_client_list_t const *clients, int number);
140 
141 fr_client_t *client_read(char const *filename, CONF_SECTION *server_cs, bool check_dns);
142 
144 #ifdef __cplusplus
145 }
146 #endif
#define RCSIDH(h, id)
Definition: build.h:445
Configuration AVP similar to a fr_pair_t.
Definition: cf_priv.h:70
A section grouping multiple CONF_PAIR.
Definition: cf_priv.h:89
IPv4/6 prefix.
Definition: merged_model.c:272
fr_time_delta_t response_window
How long the client has to respond.
Definition: client.h:113
char const * server
Name of the virtual server client is associated with.
Definition: client.h:101
fr_client_t * client_find(fr_client_list_t const *clients, fr_ipaddr_t const *ipaddr, int proto)
Definition: client.c:375
fr_ipaddr_t ipaddr
IPv4/IPv6 address of the host.
Definition: client.h:80
fr_client_t * client_findbynumber(fr_client_list_t const *clients, int number)
fr_client_list_t * client_list_init(CONF_SECTION *cs)
Return a new client list.
Definition: client.c:110
fr_stats_t acct
Accounting stats.
Definition: client.h:110
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:615
void client_free(fr_client_t *client)
Free a client.
Definition: client.c:95
char const * secret
Secret PSK.
Definition: client.h:87
fr_client_t * client_read(char const *filename, CONF_SECTION *server_cs, bool check_dns)
Read a single client from a file.
Definition: client.c:1040
bool active
for dynamic clients
Definition: client.h:91
fr_ipaddr_t src_ipaddr
IPv4/IPv6 address to send responses from (family must match ipaddr).
Definition: client.h:81
int(* client_value_cb_t)(char **out, CONF_PAIR const *cp, void *data)
Callback for retrieving values when building client sections.
Definition: client.h:66
bool message_authenticator
Require RADIUS message authenticator in requests.
Definition: client.h:89
fr_stats_t auth
Authentication stats.
Definition: client.h:109
char const * nas_type
Type of client (arbitrary).
Definition: client.h:99
int proto
Protocol number.
Definition: client.h:115
fr_client_t * client_from_request(request_t *request)
Search up a list of requests trying to locate one which has a client.
Definition: client.c:1092
CONF_SECTION * cs
CONF_SECTION that was parsed to generate the client.
Definition: client.h:106
bool dynamic
Whether the client was dynamically defined.
Definition: client.h:90
char const * longname
Client identifier.
Definition: client.h:84
fr_rb_node_t node
Entry in the client tree.
Definition: client.h:78
void client_list_free(void)
Definition: client.c:86
fr_socket_limit_t limit
Connections per client (TCP clients only).
Definition: client.h:116
char const * shortname
Client nickname.
Definition: client.h:85
fr_client_t * client_afrom_cs(TALLOC_CTX *ctx, CONF_SECTION *cs, CONF_SECTION *server_cs, size_t extra)
Allocate a new client from a config section.
Definition: client.c:697
bool use_connected
do we use connected sockets for this client
Definition: client.h:92
void client_delete(fr_client_list_t *clients, fr_client_t *client)
Definition: client.c:339
bool client_add(fr_client_list_t *clients, fr_client_t *client)
Add a client to a fr_client_list_t.
Definition: client.c:184
bool dedup_authenticator
more RADIUS stuff
Definition: client.h:93
fr_client_list_t * client_list_parse_section(CONF_SECTION *section, int proto, bool tls_required)
int number
Unique client number.
Definition: client.h:104
CONF_SECTION * server_cs
Virtual server that the client is associated with.
Definition: client.h:102
fr_client_t * client_afrom_request(TALLOC_CTX *ctx, request_t *request)
Create a new client, consuming all attributes in the control list of the request.
Definition: client.c:915
Describes a host allowed to send packets to the server.
Definition: client.h:77
static char const * proto(int id, int porttype)
Definition: radwho.c:85
Group of clients.
Definition: client.c:52
A time delta, a difference in time measured in nanoseconds.
Definition: time.h:80
static fr_slen_t data
Definition: value.h:1259
static size_t char ** out
Definition: value.h:984