The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Macros | Functions | Variables
proto_dhcpv4.c File Reference

DHCPV4 master protocol handler. More...

#include <freeradius-devel/io/listen.h>
#include <freeradius-devel/server/module_rlm.h>
#include <freeradius-devel/util/debug.h>
#include "proto_dhcpv4.h"
+ Include dependency graph for proto_dhcpv4.c:

Go to the source code of this file.

Macros

#define COPY(_x)   reply->_x = original->_x
 
#define LOG_PREFIX   "proto_dhcpv4"
 
#define MEMCPY(_x)   memcpy(&reply->_x, &original->_x, sizeof(reply->_x))
 

Functions

static int mod_bootstrap (module_inst_ctx_t const *mctx)
 Bootstrap the application. More...
 
static int mod_decode (UNUSED void const *instance, request_t *request, uint8_t *const data, size_t data_len)
 Decode the packet. More...
 
static ssize_t mod_encode (UNUSED void const *instance, request_t *request, uint8_t *buffer, size_t buffer_len)
 
static int mod_instantiate (module_inst_ctx_t const *mctx)
 Instantiate the application. More...
 
static int mod_load (void)
 
static int mod_open (void *instance, fr_schedule_t *sc, UNUSED CONF_SECTION *conf)
 Open listen sockets/connect to external event source. More...
 
static int mod_priority_set (void const *instance, uint8_t const *buffer, size_t buflen)
 
static void mod_unload (void)
 
static int transport_parse (TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
 
static int transport_parse (TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
 Wrapper around dl_instance. More...
 
static int type_parse (TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
 
static int type_parse (UNUSED TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, UNUSED conf_parser_t const *rule)
 Wrapper around dl_instance which translates the packet-type into a submodule name. More...
 

Variables

static fr_dict_attr_t const * attr_message_type
 
static fr_dict_attr_t const * attr_packet_type
 
static fr_dict_t const * dict_dhcpv4
 
static conf_parser_t const limit_config []
 
static const conf_parser_t priority_config []
 
fr_app_t proto_dhcpv4
 
static conf_parser_t const proto_dhcpv4_config []
 How to parse a DHCPV4 listen section. More...
 
fr_dict_autoload_t proto_dhcpv4_dict []
 
fr_dict_attr_autoload_t proto_dhcpv4_dict_attr []
 

Detailed Description

DHCPV4 master protocol handler.

Id
2190d978b194ad2dbf847e359ee6e5be65b851fe

Definition in file proto_dhcpv4.c.

Macro Definition Documentation

◆ COPY

#define COPY (   _x)    reply->_x = original->_x

◆ LOG_PREFIX

#define LOG_PREFIX   "proto_dhcpv4"

Definition at line 25 of file proto_dhcpv4.c.

◆ MEMCPY

#define MEMCPY (   _x)    memcpy(&reply->_x, &original->_x, sizeof(reply->_x))

Function Documentation

◆ mod_bootstrap()

static int mod_bootstrap ( module_inst_ctx_t const *  mctx)
static

Bootstrap the application.

Bootstrap I/O and type submodules.

Returns
  • 0 on success.
  • -1 on failure.

Definition at line 452 of file proto_dhcpv4.c.

+ Here is the call graph for this function:

◆ mod_decode()

static int mod_decode ( UNUSED void const *  instance,
request_t request,
uint8_t *const  data,
size_t  data_len 
)
static

Decode the packet.

Definition at line 191 of file proto_dhcpv4.c.

+ Here is the call graph for this function:

◆ mod_encode()

static ssize_t mod_encode ( UNUSED void const *  instance,
request_t request,
uint8_t buffer,
size_t  buffer_len 
)
static

Definition at line 248 of file proto_dhcpv4.c.

+ Here is the call graph for this function:

◆ mod_instantiate()

static int mod_instantiate ( module_inst_ctx_t const *  mctx)
static

Instantiate the application.

Instantiate I/O and type submodules.

Returns
  • 0 on success.
  • -1 on failure.

Definition at line 414 of file proto_dhcpv4.c.

◆ mod_load()

static int mod_load ( void  )
static

Definition at line 499 of file proto_dhcpv4.c.

+ Here is the call graph for this function:

◆ mod_open()

static int mod_open ( void *  instance,
fr_schedule_t sc,
UNUSED CONF_SECTION conf 
)
static

Open listen sockets/connect to external event source.

Parameters
[in]instanceCtx data for this application.
[in]scto add our file descriptor to.
[in]confListen section parsed to give us instance.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 395 of file proto_dhcpv4.c.

+ Here is the call graph for this function:

◆ mod_priority_set()

static int mod_priority_set ( void const *  instance,
uint8_t const *  buffer,
size_t  buflen 
)
static

Definition at line 353 of file proto_dhcpv4.c.

+ Here is the call graph for this function:

◆ mod_unload()

static void mod_unload ( void  )
static

Definition at line 509 of file proto_dhcpv4.c.

+ Here is the call graph for this function:

◆ transport_parse() [1/2]

static int transport_parse ( TALLOC_CTX *  ctx,
void *  out,
UNUSED void *  parent,
CONF_ITEM ci,
conf_parser_t const *  rule 
)
static

◆ transport_parse() [2/2]

static int transport_parse ( TALLOC_CTX *  ctx,
void *  out,
UNUSED void *  parent,
CONF_ITEM ci,
UNUSED conf_parser_t const *  rule 
)
static

Wrapper around dl_instance.

Parameters
[in]ctxto allocate data in (instance of proto_dhcpv4).
[out]outWhere to write a dl_module_inst_t containing the module handle and instance.
[in]parentBase structure address.
[in]ciCONF_PAIR specifying the name of the type module.
[in]ruleunused.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 149 of file proto_dhcpv4.c.

+ Here is the call graph for this function:

◆ type_parse() [1/2]

static int type_parse ( TALLOC_CTX *  ctx,
void *  out,
void *  parent,
CONF_ITEM ci,
conf_parser_t const *  rule 
)
static

◆ type_parse() [2/2]

static int type_parse ( UNUSED TALLOC_CTX *  ctx,
void *  out,
void *  parent,
CONF_ITEM ci,
UNUSED conf_parser_t const *  rule 
)
static

Wrapper around dl_instance which translates the packet-type into a submodule name.

Parameters
[in]ctxto allocate data in (instance of proto_dhcpv4).
[out]outWhere to write a dl_module_inst_t containing the module handle and instance.
[in]parentBase structure address.
[in]ciCONF_PAIR specifying the name of the type module.
[in]ruleunused.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 115 of file proto_dhcpv4.c.

+ Here is the call graph for this function:

Variable Documentation

◆ attr_message_type

fr_dict_attr_t const* attr_message_type
static

Definition at line 94 of file proto_dhcpv4.c.

◆ attr_packet_type

fr_dict_attr_t const* attr_packet_type
static

Definition at line 95 of file proto_dhcpv4.c.

◆ dict_dhcpv4

fr_dict_t const* dict_dhcpv4
static

Definition at line 86 of file proto_dhcpv4.c.

◆ limit_config

conf_parser_t const limit_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET("cleanup_delay", proto_dhcpv4_t, io.cleanup_delay), .dflt = "5.0" } ,
{ FR_CONF_OFFSET("idle_timeout", proto_dhcpv4_t, io.idle_timeout), .dflt = "30.0" } ,
{ FR_CONF_OFFSET("nak_lifetime", proto_dhcpv4_t, io.nak_lifetime), .dflt = "30.0" } ,
{ FR_CONF_OFFSET("max_connections", proto_dhcpv4_t, io.max_connections), .dflt = "1024" } ,
{ FR_CONF_OFFSET("max_clients", proto_dhcpv4_t, io.max_clients), .dflt = "256" } ,
{ FR_CONF_OFFSET("max_pending_packets", proto_dhcpv4_t, io.max_pending_packets), .dflt = "256" } ,
{ FR_CONF_OFFSET("max_packet_size", proto_dhcpv4_t, max_packet_size) } ,
{ FR_CONF_OFFSET("num_messages", proto_dhcpv4_t, num_messages) } ,
{ FR_CONF_POINTER("priority", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) priority_config },
}
#define CONF_PARSER_TERMINATOR
Definition: cf_parse.h:626
#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
@ CONF_FLAG_SUBSECTION
Instead of putting the information into a configuration structure, the configuration file routines MA...
Definition: cf_parse.h:400
static const conf_parser_t priority_config[]
Definition: proto_dhcpv4.c:36
An instance of a proto_dhcpv4 listen section.
Definition: proto_dhcpv4.h:32

Definition at line 54 of file proto_dhcpv4.c.

◆ priority_config

const conf_parser_t priority_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET("Discover", proto_dhcpv4_t, priorities[FR_DHCP_DISCOVER]),
.func = cf_table_parse_int, .uctx = &(cf_table_parse_ctx_t){ .table = channel_packet_priority, .len = &channel_packet_priority_len }, .dflt = "normal" },
{ FR_CONF_OFFSET("Request", proto_dhcpv4_t, priorities[FR_DHCP_REQUEST]),
.func = cf_table_parse_int, .uctx = &(cf_table_parse_ctx_t){ .table = channel_packet_priority, .len = &channel_packet_priority_len }, .dflt = "normal" },
{ FR_CONF_OFFSET("Decline", proto_dhcpv4_t, priorities[FR_DHCP_DECLINE]),
.func = cf_table_parse_int, .uctx = &(cf_table_parse_ctx_t){ .table = channel_packet_priority, .len = &channel_packet_priority_len }, .dflt = "normal" },
{ FR_CONF_OFFSET("Release", proto_dhcpv4_t, priorities[FR_DHCP_RELEASE]),
.func = cf_table_parse_int, .uctx = &(cf_table_parse_ctx_t){ .table = channel_packet_priority, .len = &channel_packet_priority_len }, .dflt = "normal" },
{ FR_CONF_OFFSET("Inform", proto_dhcpv4_t, priorities[FR_DHCP_INFORM]),
.func = cf_table_parse_int, .uctx = &(cf_table_parse_ctx_t){ .table = channel_packet_priority, .len = &channel_packet_priority_len }, .dflt = "normal" },
{ FR_CONF_OFFSET("Lease-Query", proto_dhcpv4_t, priorities[FR_DHCP_LEASE_QUERY]),
.func = cf_table_parse_int, .uctx = &(cf_table_parse_ctx_t){ .table = channel_packet_priority, .len = &channel_packet_priority_len }, .dflt = "low" },
{ FR_CONF_OFFSET("Bulk-Lease-Query", proto_dhcpv4_t, priorities[FR_DHCP_BULK_LEASE_QUERY]),
.func = cf_table_parse_int, .uctx = &(cf_table_parse_ctx_t){ .table = channel_packet_priority, .len = &channel_packet_priority_len }, .dflt = "low" },
}
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
size_t channel_packet_priority_len
Definition: channel.c:170
fr_table_num_sorted_t const channel_packet_priority[]
Definition: channel.c:164
@ FR_DHCP_REQUEST
Definition: dhcpv4.h:47
@ FR_DHCP_DECLINE
Definition: dhcpv4.h:48
@ FR_DHCP_DISCOVER
Definition: dhcpv4.h:45
@ 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_INFORM
Definition: dhcpv4.h:52

Definition at line 36 of file proto_dhcpv4.c.

◆ proto_dhcpv4

fr_app_t proto_dhcpv4
Initial value:
= {
.common = {
.name = "dhcpv4",
.inst_size = sizeof(proto_dhcpv4_t),
.onload = mod_load,
.unload = mod_unload,
.bootstrap = mod_bootstrap,
},
.dict = &dict_dhcpv4,
.open = mod_open,
.decode = mod_decode,
.encode = mod_encode,
.priority = mod_priority_set
}
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition: dl_module.h:65
static int mod_load(void)
Definition: proto_dhcpv4.c:499
static ssize_t mod_encode(UNUSED void const *instance, request_t *request, uint8_t *buffer, size_t buffer_len)
Definition: proto_dhcpv4.c:248
static conf_parser_t const proto_dhcpv4_config[]
How to parse a DHCPV4 listen section.
Definition: proto_dhcpv4.c:76
static int mod_bootstrap(module_inst_ctx_t const *mctx)
Bootstrap the application.
Definition: proto_dhcpv4.c:452
static void mod_unload(void)
Definition: proto_dhcpv4.c:509
static fr_dict_t const * dict_dhcpv4
Definition: proto_dhcpv4.c:86
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:191
static int mod_instantiate(module_inst_ctx_t const *mctx)
Instantiate the application.
Definition: proto_dhcpv4.c:414
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:395
static int mod_priority_set(void const *instance, uint8_t const *buffer, size_t buflen)
Definition: proto_dhcpv4.c:353
static int instantiate(module_inst_ctx_t const *mctx)
Definition: rlm_rest.c:1312

Definition at line 514 of file proto_dhcpv4.c.

◆ proto_dhcpv4_config

conf_parser_t const proto_dhcpv4_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET_FLAGS("type", CONF_FLAG_NOT_EMPTY, proto_dhcpv4_t, allowed_types), .func = type_parse },
{ FR_CONF_OFFSET_TYPE_FLAGS("transport", FR_TYPE_VOID, 0, proto_dhcpv4_t, io.submodule), .func = transport_parse },
{ FR_CONF_POINTER("limit", 0, CONF_FLAG_SUBSECTION, NULL), .subcs = (void const *) limit_config },
}
#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
@ CONF_FLAG_NOT_EMPTY
CONF_PAIR is required to have a non zero length value.
Definition: cf_parse.h:421
#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
@ FR_TYPE_VOID
User data.
Definition: merged_model.c:127
static conf_parser_t const limit_config[]
Definition: proto_dhcpv4.c:54
static int type_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
static int transport_parse(TALLOC_CTX *ctx, void *out, UNUSED void *parent, CONF_ITEM *ci, conf_parser_t const *rule)

How to parse a DHCPV4 listen section.

Definition at line 76 of file proto_dhcpv4.c.

◆ proto_dhcpv4_dict

fr_dict_autoload_t proto_dhcpv4_dict
Initial value:
= {
{ .out = &dict_dhcpv4, .proto = "dhcpv4" },
{ NULL }
}

Definition at line 89 of file proto_dhcpv4.c.

◆ proto_dhcpv4_dict_attr

fr_dict_attr_autoload_t proto_dhcpv4_dict_attr
Initial value:
= {
{ .out = &attr_message_type, .name = "Message-Type", .type = FR_TYPE_UINT8, .dict = &dict_dhcpv4},
{ .out = &attr_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_dhcpv4},
{ NULL }
}
@ FR_TYPE_UINT8
8 Bit unsigned integer.
Definition: merged_model.c:97
@ FR_TYPE_UINT32
32 Bit unsigned integer.
Definition: merged_model.c:99
static fr_dict_attr_t const * attr_packet_type
Definition: proto_dhcpv4.c:95
static fr_dict_attr_t const * attr_message_type
Definition: proto_dhcpv4.c:94

Definition at line 98 of file proto_dhcpv4.c.