The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
proto_dhcpv4.c
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 
17 /**
18  * $Id: aae1fcc755ecaeeda6c00e15a73811379232a45e $
19  * @file proto_dhcpv4.c
20  * @brief DHCPV4 master protocol handler.
21  *
22  * @copyright 2017 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
23  * @copyright 2016 Alan DeKok (aland@freeradius.org)
24  */
25 #define LOG_PREFIX "proto_dhcpv4"
26 
27 #include <freeradius-devel/io/listen.h>
28 #include <freeradius-devel/server/module_rlm.h>
29 #include <freeradius-devel/util/debug.h>
30 #include "proto_dhcpv4.h"
31 
32 extern fr_app_t proto_dhcpv4;
33 static int type_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule);
34 static int transport_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule);
35 
36 static const conf_parser_t priority_config[] = {
37  { FR_CONF_OFFSET("Discover", proto_dhcpv4_t, priorities[FR_DHCP_DISCOVER]),
38  .func = cf_table_parse_int, .uctx = &(cf_table_parse_ctx_t){ .table = channel_packet_priority, .len = &channel_packet_priority_len }, .dflt = "normal" },
39  { FR_CONF_OFFSET("Request", proto_dhcpv4_t, priorities[FR_DHCP_REQUEST]),
40  .func = cf_table_parse_int, .uctx = &(cf_table_parse_ctx_t){ .table = channel_packet_priority, .len = &channel_packet_priority_len }, .dflt = "normal" },
41  { FR_CONF_OFFSET("Decline", proto_dhcpv4_t, priorities[FR_DHCP_DECLINE]),
42  .func = cf_table_parse_int, .uctx = &(cf_table_parse_ctx_t){ .table = channel_packet_priority, .len = &channel_packet_priority_len }, .dflt = "normal" },
43  { FR_CONF_OFFSET("Release", proto_dhcpv4_t, priorities[FR_DHCP_RELEASE]),
44  .func = cf_table_parse_int, .uctx = &(cf_table_parse_ctx_t){ .table = channel_packet_priority, .len = &channel_packet_priority_len }, .dflt = "normal" },
45  { FR_CONF_OFFSET("Inform", proto_dhcpv4_t, priorities[FR_DHCP_INFORM]),
46  .func = cf_table_parse_int, .uctx = &(cf_table_parse_ctx_t){ .table = channel_packet_priority, .len = &channel_packet_priority_len }, .dflt = "normal" },
47  { FR_CONF_OFFSET("Lease-Query", proto_dhcpv4_t, priorities[FR_DHCP_LEASE_QUERY]),
48  .func = cf_table_parse_int, .uctx = &(cf_table_parse_ctx_t){ .table = channel_packet_priority, .len = &channel_packet_priority_len }, .dflt = "low" },
49  { FR_CONF_OFFSET("Bulk-Lease-Query", proto_dhcpv4_t, priorities[FR_DHCP_BULK_LEASE_QUERY]),
50  .func = cf_table_parse_int, .uctx = &(cf_table_parse_ctx_t){ .table = channel_packet_priority, .len = &channel_packet_priority_len }, .dflt = "low" },
52 };
53 
54 static conf_parser_t const limit_config[] = {
55  { FR_CONF_OFFSET("cleanup_delay", proto_dhcpv4_t, io.cleanup_delay), .dflt = "5.0" } ,
56  { FR_CONF_OFFSET("idle_timeout", proto_dhcpv4_t, io.idle_timeout), .dflt = "30.0" } ,
57  { FR_CONF_OFFSET("nak_lifetime", proto_dhcpv4_t, io.nak_lifetime), .dflt = "30.0" } ,
58 
59  { FR_CONF_OFFSET("max_connections", proto_dhcpv4_t, io.max_connections), .dflt = "1024" } ,
60  { FR_CONF_OFFSET("max_clients", proto_dhcpv4_t, io.max_clients), .dflt = "256" } ,
61  { FR_CONF_OFFSET("max_pending_packets", proto_dhcpv4_t, io.max_pending_packets), .dflt = "256" } ,
62 
63  /*
64  * For performance tweaking. NOT for normal humans.
65  */
66  { FR_CONF_OFFSET("max_packet_size", proto_dhcpv4_t, max_packet_size) } ,
67  { FR_CONF_OFFSET("num_messages", proto_dhcpv4_t, num_messages) } ,
68  { FR_CONF_POINTER("priority", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) priority_config },
69 
71 };
72 
73 /** How to parse a DHCPV4 listen section
74  *
75  */
77  { FR_CONF_OFFSET_FLAGS("type", CONF_FLAG_NOT_EMPTY, proto_dhcpv4_t, allowed_types), .func = type_parse },
78  { FR_CONF_OFFSET_TYPE_FLAGS("transport", FR_TYPE_VOID, 0, proto_dhcpv4_t, io.submodule),
79  .func = transport_parse },
80 
81  { FR_CONF_POINTER("limit", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) limit_config },
82 
84 };
85 
86 
87 static fr_dict_t const *dict_dhcpv4;
88 
91  { .out = &dict_dhcpv4, .proto = "dhcpv4" },
92  { NULL }
93 };
94 
97 
100  { .out = &attr_message_type, .name = "Message-Type", .type = FR_TYPE_UINT8, .dict = &dict_dhcpv4},
101  { .out = &attr_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_dhcpv4},
102  { NULL }
103 };
104 
105 /** Translates the packet-type into a submodule name
106  *
107  * @param[in] ctx to allocate data in (instance of proto_dhcpv4).
108  * @param[out] out Where to write a module_instance_t containing the module handle and instance.
109  * @param[in] parent Base structure address.
110  * @param[in] ci #CONF_PAIR specifying the name of the type module.
111  * @param[in] rule unused.
112  * @return
113  * - 0 on success.
114  * - -1 on failure.
115  */
116 static int type_parse(UNUSED TALLOC_CTX *ctx, void *out, void *parent,
117  CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
118 {
119  proto_dhcpv4_t *inst = talloc_get_type_abort(parent, proto_dhcpv4_t);
121  CONF_PAIR *cp;
122  char const *value;
123 
124  cp = cf_item_to_pair(ci);
125  value = cf_pair_value(cp);
126 
128  if (!dv || (dv->value->vb_uint32 >= FR_DHCP_CODE_MAX)) {
129  cf_log_err(ci, "Unknown DHCPv4 packet type '%s'", value);
130  return -1;
131  }
132 
133  inst->allowed[dv->value->vb_uint32] = true;
134  *((char const **) out) = value;
135 
136  return 0;
137 }
138 
139 static int transport_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
140 {
141  proto_dhcpv4_t *inst = talloc_get_type_abort(parent, proto_dhcpv4_t);
142  module_instance_t *mi;
143 
144  if (unlikely(virtual_server_listen_transport_parse(ctx, out, parent, ci, rule) < 0)) {
145  return -1;
146  }
147 
148  mi = talloc_get_type_abort(*(void **)out, module_instance_t);
149  inst->io.app_io = (fr_app_io_t const *)mi->exported;
150  inst->io.app_io_instance = mi->data;
151  inst->io.app_io_conf = mi->conf;
152 
153  return 0;
154 }
155 
156 /** Decode the packet
157  *
158  */
159 static int mod_decode(UNUSED void const *instance, request_t *request, uint8_t *const data, size_t data_len)
160 {
161  fr_io_track_t const *track = talloc_get_type_abort_const(request->async->packet_ctx, fr_io_track_t);
162  fr_io_address_t const *address = track->address;
163  fr_client_t const *client;
164  fr_packet_t *packet = request->packet;
165 
166  /*
167  * Set the request dictionary so that we can do
168  * generic->protocol attribute conversions as
169  * the request runs through the server.
170  */
171  request->dict = dict_dhcpv4;
172 
173  RHEXDUMP3(data, data_len, "proto_dhcpv4 decode packet");
174 
175  client = address->radclient;
176 
177  /*
178  * Hacks for now until we have a lower-level decode routine.
179  */
180  request->packet->id = fr_nbo_to_uint32(data + 4);
181  request->reply->id = request->packet->id;
182 
183  request->packet->data = talloc_memdup(request->packet, data, data_len);
184  request->packet->data_len = data_len;
185 
186  /*
187  * Note that we don't set a limit on max_attributes here.
188  * That MUST be set and checked in the underlying
189  * transport, via a call to fr_dhcpv4_ok().
190  */
191  if (fr_dhcpv4_decode(request->request_ctx, &request->request_pairs,
192  packet->data, packet->data_len, &packet->code) < 0) {
193  RPEDEBUG("Failed decoding packet");
194  return -1;
195  }
196 
197  /*
198  * Set the rest of the fields.
199  */
200  request->client = UNCONST(fr_client_t *, client);
201 
202  request->packet->socket = address->socket;
203  fr_socket_addr_swap(&request->reply->socket, &address->socket);
204 
205  if (fr_packet_pairs_from_packet(request->request_ctx, &request->request_pairs, request->packet) < 0) {
206  RPEDEBUG("Failed decoding 'Net.*' packet");
207  return -1;
208  }
209 
210  REQUEST_VERIFY(request);
211 
212  return 0;
213 }
214 
215 static ssize_t mod_encode(UNUSED void const *instance, request_t *request, uint8_t *buffer, size_t buffer_len)
216 {
217  fr_io_track_t *track = talloc_get_type_abort(request->async->packet_ctx, fr_io_track_t);
218  fr_io_address_t const *address = track->address;
219  dhcp_packet_t *reply = (dhcp_packet_t *) buffer;
220  dhcp_packet_t *original = (dhcp_packet_t *) request->packet->data;
221  ssize_t data_len;
222  fr_client_t const *client;
223 
224  /*
225  * process layer NAK, or "Do not respond". We also never
226  * send replies to a release.
227  */
228  if ((buffer_len == 1) ||
229  (request->reply->code == FR_DHCP_DO_NOT_RESPOND) ||
230  (request->reply->code == 0) || (request->reply->code >= FR_DHCP_CODE_MAX) ||
231  (request->packet->code == FR_DHCP_RELEASE)) {
232  track->do_not_respond = true;
233  return 1;
234  }
235 
236  client = address->radclient;
237  fr_assert(client);
238 
239  /*
240  * Dynamic client stuff
241  */
242  if (client->dynamic && !client->active) {
243  fr_client_t *new_client;
244 
245  fr_assert(buffer_len >= sizeof(client));
246 
247  /*
248  * We don't accept the new client, so don't do
249  * anything.
250  */
251  if (request->reply->code != FR_DHCP_ACK) {
252  *buffer = true;
253  return 1;
254  }
255 
256  /*
257  * Allocate the client. If that fails, send back a NAK.
258  *
259  * @todo - deal with NUMA zones? Or just deal with this
260  * client being in different memory.
261  *
262  * Maybe we should create a CONF_SECTION from the client,
263  * and pass *that* back to mod_write(), which can then
264  * parse it to create the actual client....
265  */
266  new_client = client_afrom_request(NULL, request);
267  if (!new_client) {
268  PERROR("Failed creating new client");
269  buffer[0] = true;
270  return 1;
271  }
272 
273  memcpy(buffer, &new_client, sizeof(new_client));
274  return sizeof(new_client);
275  }
276 
277  if (buffer_len < MIN_PACKET_SIZE) {
278  REDEBUG("Output buffer is too small to hold a DHCPv4 packet.");
279  return -1;
280  }
281 
282  memset(buffer, 0, buffer_len);
283 
284  /*
285  * Initialize the output packet from the input packet.
286  */
287 #define COPY(_x) reply->_x = original->_x
288 #define MEMCPY(_x) memcpy(&reply->_x, &original->_x, sizeof(reply->_x))
289 
290  COPY(htype);
291  COPY(hlen);
292  COPY(xid);
293  MEMCPY(chaddr);
294 
295  data_len = fr_dhcpv4_encode(buffer, buffer_len, original, request->reply->code,
296  ntohl(original->xid), &request->reply_pairs);
297  if (data_len < 0) {
298  RPEDEBUG("Failed encoding DHCPV4 reply");
299  return -1;
300  }
301 
302  RHEXDUMP3(buffer, data_len, "proto_dhcpv4 encode packet");
303 
304  if (RDEBUG_ENABLED) {
305  /*
306  * We can't report the destination IP / port here as it is manipulated in mod_write
307  */
308  RDEBUG("Sending %s XID %08x length %zu via socket %s",
309  dhcp_message_types[request->reply->code],
310  request->reply->id,
311  data_len,
312  request->async->listen->name);
313  log_request_proto_pair_list(L_DBG_LVL_1, request, NULL, &request->reply_pairs, NULL);
314  }
315 
316  request->reply->data_len = data_len;
317  return data_len;
318 }
319 
320 static int mod_priority_set(void const *instance, uint8_t const *buffer, size_t buflen)
321 {
323  uint8_t const *code;
324 
325  if (buflen < MIN_PACKET_SIZE) return -1;
326 
328  fr_assert(code != NULL);
329  fr_assert(code[1] == 1);
330  fr_assert(code[2] != 0);
331  fr_assert(code[2] < FR_DHCP_CODE_MAX);
332 
333  /*
334  * Disallowed packet
335  */
336  if (!inst->priorities[code[2]]) return 0;
337 
338  if (!inst->allowed[code[2]]) return -1;
339 
340  /*
341  * @todo - if we cared, we could also return -1 for "this
342  * is a bad packet". But that's really only for
343  * mod_inject, as we assume that app_io->read() always
344  * returns good packets.
345  */
346 
347  /*
348  * Return the configured priority.
349  */
350  return inst->priorities[code[2]];
351 }
352 
353 /** Open listen sockets/connect to external event source
354  *
355  * @param[in] instance Ctx data for this application.
356  * @param[in] sc to add our file descriptor to.
357  * @param[in] conf Listen section parsed to give us instance.
358  * @return
359  * - 0 on success.
360  * - -1 on failure.
361  */
362 static int mod_open(void *instance, fr_schedule_t *sc, UNUSED CONF_SECTION *conf)
363 {
364  proto_dhcpv4_t *inst = talloc_get_type_abort(instance, proto_dhcpv4_t);
365 
366  inst->io.app = &proto_dhcpv4;
367  inst->io.app_instance = instance;
368 
369  return fr_master_io_listen(&inst->io, sc,
370  inst->max_packet_size, inst->num_messages);
371 }
372 
373 /** Instantiate the application
374  *
375  * Instantiate I/O and type submodules.
376  *
377  * @return
378  * - 0 on success.
379  * - -1 on failure.
380  */
381 static int mod_instantiate(module_inst_ctx_t const *mctx)
382 {
383  proto_dhcpv4_t *inst = talloc_get_type_abort(mctx->mi->data, proto_dhcpv4_t);
384 
385  /*
386  * Ensure that the server CONF_SECTION is always set.
387  */
388  inst->io.server_cs = cf_item_to_section(cf_parent(mctx->mi->conf));
389 
390  fr_assert(dict_dhcpv4 != NULL);
391  fr_assert(attr_message_type != NULL);
392 
393  /*
394  * No IO module, it's an empty listener.
395  */
396  if (!inst->io.submodule) return 0;
397 
398  /*
399  * Tell the master handler about the main protocol instance.
400  */
401  inst->io.app = &proto_dhcpv4;
402  inst->io.app_instance = inst;
403 
404  /*
405  * We will need this for dynamic clients and connected sockets.
406  */
407  inst->io.mi = mctx->mi;
408 
409  /*
410  * These configuration items are not printed by default,
411  * because normal people shouldn't be touching them.
412  */
413  if (!inst->max_packet_size && inst->io.app_io) inst->max_packet_size = inst->io.app_io->default_message_size;
414 
415  if (!inst->num_messages) inst->num_messages = 256;
416 
417  /*
418  * These timers are usually protocol specific.
419  */
420  FR_TIME_DELTA_BOUND_CHECK("idle_timeout", inst->io.idle_timeout, >=, fr_time_delta_from_sec(1));
421  FR_TIME_DELTA_BOUND_CHECK("idle_timeout", inst->io.idle_timeout, <=, fr_time_delta_from_sec(600));
422 
423  FR_TIME_DELTA_BOUND_CHECK("nak_lifetime", inst->io.nak_lifetime, >=, fr_time_delta_from_sec(1));
424  FR_TIME_DELTA_BOUND_CHECK("nak_lifetime", inst->io.nak_lifetime, <=, fr_time_delta_from_sec(600));
425 
426  FR_TIME_DELTA_BOUND_CHECK("cleanup_delay", inst->io.cleanup_delay, <=, fr_time_delta_from_sec(30));
427  FR_TIME_DELTA_BOUND_CHECK("cleanup_delay", inst->io.cleanup_delay, >, fr_time_delta_from_sec(0));
428 
429  FR_INTEGER_BOUND_CHECK("num_messages", inst->num_messages, >=, 32);
430  FR_INTEGER_BOUND_CHECK("num_messages", inst->num_messages, <=, 65535);
431 
432  FR_INTEGER_BOUND_CHECK("max_packet_size", inst->max_packet_size, >=, 1024);
433  FR_INTEGER_BOUND_CHECK("max_packet_size", inst->max_packet_size, <=, 65535);
434 
435  /*
436  * Instantiate the transport module before calling the
437  * common instantiation function.
438  */
439  if (module_instantiate(inst->io.submodule) < 0) return -1;
440 
441  /*
442  * Instantiate the master io submodule
443  */
445 }
446 
447 static int mod_load(void)
448 {
449  if (fr_dhcpv4_global_init() < 0) {
450  PERROR("Failed initialising protocol library");
451  return -1;
452  }
453 
454  return 0;
455 }
456 
457 static void mod_unload(void)
458 {
460 }
461 
463  .common = {
464  .magic = MODULE_MAGIC_INIT,
465  .name = "dhcpv4",
466  .config = proto_dhcpv4_config,
467  .inst_size = sizeof(proto_dhcpv4_t),
468 
469  .onload = mod_load,
470  .unload = mod_unload,
471 
473  },
474  .dict = &dict_dhcpv4,
475  .open = mod_open,
476  .decode = mod_decode,
477  .encode = mod_encode,
478  .priority = mod_priority_set
479 };
static int const char char buffer[256]
Definition: acutest.h:574
module_t common
Common fields to all loadable modules.
Definition: app_io.h:34
Public structure describing an I/O path for a protocol.
Definition: app_io.h:33
module_t common
Common fields provided by all modules.
Definition: application.h:72
Describes a new application (protocol)
Definition: application.h:71
#define UNCONST(_type, _ptr)
Remove const qualification from a pointer.
Definition: build.h:165
#define unlikely(_x)
Definition: build.h:379
#define UNUSED
Definition: build.h:313
int cf_table_parse_int(UNUSED TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
Generic function for parsing conf pair values as int.
Definition: cf_parse.c:1474
#define CONF_PARSER_TERMINATOR
Definition: cf_parse.h:627
#define FR_INTEGER_BOUND_CHECK(_name, _var, _op, _bound)
Definition: cf_parse.h:487
#define FR_CONF_OFFSET(_name, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition: cf_parse.h:268
#define FR_CONF_POINTER(_name, _type, _flags, _res_p)
conf_parser_t which parses a single CONF_PAIR producing a single global result
Definition: cf_parse.h:310
#define FR_CONF_OFFSET_FLAGS(_name, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition: cf_parse.h:256
#define FR_TIME_DELTA_BOUND_CHECK(_name, _var, _op, _bound)
Definition: cf_parse.h:498
@ CONF_FLAG_NOT_EMPTY
CONF_PAIR is required to have a non zero length value.
Definition: cf_parse.h:420
@ CONF_FLAG_SUBSECTION
Instead of putting the information into a configuration structure, the configuration file routines MA...
Definition: cf_parse.h:399
#define FR_CONF_OFFSET_TYPE_FLAGS(_name, _type, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition: cf_parse.h:241
Defines a CONF_PAIR to C data type mapping.
Definition: cf_parse.h:564
Common header for all CONF_* types.
Definition: cf_priv.h:49
Configuration AVP similar to a fr_pair_t.
Definition: cf_priv.h:70
A section grouping multiple CONF_PAIR.
Definition: cf_priv.h:101
CONF_PAIR * cf_item_to_pair(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_PAIR.
Definition: cf_util.c:664
char const * cf_pair_value(CONF_PAIR const *pair)
Return the value of a CONF_PAIR.
Definition: cf_util.c:1594
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
Definition: cf_util.c:684
#define cf_log_err(_cf, _fmt,...)
Definition: cf_util.h:289
#define cf_parent(_cf)
Definition: cf_util.h:101
size_t channel_packet_priority_len
Definition: channel.c:170
fr_table_num_sorted_t const channel_packet_priority[]
Definition: channel.c:164
#define MIN_PACKET_SIZE
Definition: dhcpv4.h:88
@ FR_DHCP_REQUEST
Definition: dhcpv4.h:47
@ FR_DHCP_DECLINE
Definition: dhcpv4.h:48
@ FR_DHCP_DISCOVER
Definition: dhcpv4.h:45
@ FR_DHCP_CODE_MAX
Definition: dhcpv4.h:60
@ FR_DHCP_BULK_LEASE_QUERY
Definition: dhcpv4.h:58
@ FR_DHCP_LEASE_QUERY
Definition: dhcpv4.h:54
@ FR_DHCP_RELEASE
Definition: dhcpv4.h:51
@ FR_DHCP_DO_NOT_RESPOND
Definition: dhcpv4.h:61
@ FR_DHCP_INFORM
Definition: dhcpv4.h:52
@ FR_DHCP_ACK
Definition: dhcpv4.h:49
uint8_t const * fr_dhcpv4_packet_get_option(dhcp_packet_t const *packet, size_t packet_size, fr_dict_attr_t const *da)
Retrieve a DHCP option from a raw packet buffer.
Definition: packet.c:37
uint32_t xid
Definition: dhcpv4.h:71
int fr_dhcpv4_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, size_t data_len, unsigned int *code)
Definition: packet.c:100
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
Definition: dict.h:267
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition: dict.h:280
fr_value_box_t const * value
Enum value (what name maps to).
Definition: dict.h:230
fr_dict_enum_value_t * fr_dict_enum_by_name(fr_dict_attr_t const *da, char const *name, ssize_t len)
Definition: dict_util.c:3395
Specifies an attribute which must be present for the module to function.
Definition: dict.h:266
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition: dict.h:279
Value of an enumerated attribute.
Definition: dict.h:226
Test enumeration values.
Definition: dict_test.h:92
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition: dl_module.h:63
if(rcode > 0)
Definition: fd_read.h:9
fr_socket_t socket
src/dst ip and port.
Definition: base.h:336
fr_client_t const * radclient
old-style client definition
Definition: base.h:338
Describes a host allowed to send packets to the server.
Definition: client.h:80
void log_request_proto_pair_list(fr_log_lvl_t lvl, request_t *request, fr_pair_t const *parent, fr_pair_list_t const *vps, char const *prefix)
Print a list of protocol fr_pair_ts.
Definition: log.c:854
#define PERROR(_fmt,...)
Definition: log.h:228
#define RPEDEBUG(fmt,...)
Definition: log.h:376
#define RHEXDUMP3(_data, _len, _fmt,...)
Definition: log.h:705
int fr_packet_pairs_from_packet(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_packet_t const *packet)
Allocate a "Net." struct with src/dst host and port.
Definition: packet.c:89
@ L_DBG_LVL_1
Highest priority debug messages (-x).
Definition: log.h:70
fr_app_io_t fr_master_app_io
Definition: master.c:3139
int fr_master_io_listen(fr_io_instance_t *inst, fr_schedule_t *sc, size_t default_message_size, size_t num_messages)
Definition: master.c:2931
fr_io_address_t const * address
of this packet.. shared between multiple packets
Definition: master.h:54
bool do_not_respond
don't respond
Definition: master.h:50
@ FR_TYPE_UINT8
8 Bit unsigned integer.
Definition: merged_model.c:97
@ FR_TYPE_UINT32
32 Bit unsigned integer.
Definition: merged_model.c:99
@ FR_TYPE_VOID
User data.
Definition: merged_model.c:127
long int ssize_t
Definition: merged_model.c:24
unsigned char uint8_t
Definition: merged_model.c:30
#define MODULE_INST_CTX(_mi)
Wrapper to create a module_inst_ctx_t as a compound literal.
Definition: module_ctx.h:158
module_instance_t * mi
Instance of the module being instantiated.
Definition: module_ctx.h:51
Temporary structure to hold arguments for instantiation calls.
Definition: module_ctx.h:50
static uint32_t fr_nbo_to_uint32(uint8_t const data[static sizeof(uint32_t)])
Read an unsigned 32bit integer from wire format (big endian)
Definition: nbo.h:165
static int mod_load(void)
Definition: proto_dhcpv4.c:447
static fr_dict_attr_t const * attr_packet_type
Definition: proto_dhcpv4.c:96
static ssize_t mod_encode(UNUSED void const *instance, request_t *request, uint8_t *buffer, size_t buffer_len)
Definition: proto_dhcpv4.c:215
static conf_parser_t const limit_config[]
Definition: proto_dhcpv4.c:54
static conf_parser_t const proto_dhcpv4_config[]
How to parse a DHCPV4 listen section.
Definition: proto_dhcpv4.c:76
static int type_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
#define COPY(_x)
fr_app_t proto_dhcpv4
Definition: proto_dhcpv4.c:462
#define MEMCPY(_x)
static void mod_unload(void)
Definition: proto_dhcpv4.c:457
static fr_dict_t const * dict_dhcpv4
Definition: proto_dhcpv4.c:87
fr_dict_attr_autoload_t proto_dhcpv4_dict_attr[]
Definition: proto_dhcpv4.c:99
static int mod_decode(UNUSED void const *instance, request_t *request, uint8_t *const data, size_t data_len)
Decode the packet.
Definition: proto_dhcpv4.c:159
static const conf_parser_t priority_config[]
Definition: proto_dhcpv4.c:36
static int transport_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
Definition: proto_dhcpv4.c:139
fr_dict_autoload_t proto_dhcpv4_dict[]
Definition: proto_dhcpv4.c:90
static int mod_instantiate(module_inst_ctx_t const *mctx)
Instantiate the application.
Definition: proto_dhcpv4.c:381
static int mod_open(void *instance, fr_schedule_t *sc, UNUSED CONF_SECTION *conf)
Open listen sockets/connect to external event source.
Definition: proto_dhcpv4.c:362
static int mod_priority_set(void const *instance, uint8_t const *buffer, size_t buflen)
Definition: proto_dhcpv4.c:320
static fr_dict_attr_t const * attr_message_type
Definition: proto_dhcpv4.c:95
An instance of a proto_dhcpv4 listen section.
Definition: proto_dhcpv4.h:32
char const * dhcp_message_types[]
Definition: base.c:126
int fr_dhcpv4_global_init(void)
Resolve/cache attributes in the DHCP dictionary.
Definition: base.c:584
void fr_dhcpv4_global_free(void)
Definition: base.c:628
ssize_t fr_dhcpv4_encode(uint8_t *buffer, size_t buflen, dhcp_packet_t *original, int code, uint32_t xid, fr_pair_list_t *vps)
Definition: base.c:336
#define REDEBUG(fmt,...)
Definition: radclient.h:52
#define RDEBUG(fmt,...)
Definition: radclient.h:53
#define RDEBUG_ENABLED()
Definition: radclient.h:49
static rs_t * conf
Definition: radsniff.c:53
#define REQUEST_VERIFY(_x)
Definition: request.h:276
static int instantiate(module_inst_ctx_t const *mctx)
Definition: rlm_rest.c:1302
The scheduler.
Definition: schedule.c:125
CONF_SECTION * conf
Module's instance configuration.
Definition: module.h:329
void * data
Module's instance data.
Definition: module.h:271
module_instantiate_t instantiate
Callback to allow the module to register any per-instance resources like sockets and file handles.
Definition: module.h:218
module_t * exported
Public module structure.
Definition: module.h:276
Module instance data.
Definition: module.h:265
static const uchar sc[16]
Definition: smbdes.c:115
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:930
int module_instantiate(module_instance_t *instance)
Manually complete module setup by calling its instantiate function.
Definition: module.c:1195
fr_assert(0)
eap_aka_sim_process_conf_t * inst
#define talloc_get_type_abort_const
Definition: talloc.h:282
static fr_time_delta_t fr_time_delta_from_sec(int64_t sec)
Definition: time.h:590
unsigned int code
Packet code (type).
Definition: packet.h:61
uint8_t * data
Packet data (body).
Definition: packet.h:63
size_t data_len
Length of packet data.
Definition: packet.h:64
static fr_slen_t parent
Definition: pair.h:851
static void fr_socket_addr_swap(fr_socket_t *dst, fr_socket_t const *src)
Swap src/dst information of a fr_socket_t.
Definition: socket.h:121
static fr_slen_t data
Definition: value.h:1265
static size_t char ** out
Definition: value.h:997
int virtual_server_listen_transport_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
Generic conf_parser_t func for loading drivers.