The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
Data Structures | Macros | Functions | Variables
base.c File Reference

Functions to send/receive dhcp packets. More...

#include <freeradius-devel/dhcpv4/dhcpv4.h>
#include <freeradius-devel/util/net.h>
#include <freeradius-devel/util/proto.h>
#include "attrs.h"
+ Include dependency graph for base.c:

Go to the source code of this file.

Data Structures

struct  dhcp_option_t
 

Macros

#define DHCP_MAX_MESSAGE_TYPE   (NUM_ELEMENTS(dhcp_message_types))
 

Functions

static bool attr_valid (fr_dict_attr_t *da)
 
static int dict_flag_prefix (fr_dict_attr_t **da_p, char const *value, UNUSED fr_dict_flag_parser_rule_t const *rules)
 
int8_t fr_dhcpv4_attr_cmp (void const *a, void const *b)
 
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)
 
ssize_t fr_dhcpv4_encode_dbuff (fr_dbuff_t *dbuff, dhcp_packet_t *original, int code, uint32_t xid, fr_pair_list_t *vps)
 
void fr_dhcpv4_global_free (void)
 
int fr_dhcpv4_global_init (void)
 Resolve/cache attributes in the DHCP dictionary.
 
bool fr_dhcpv4_is_encodable (void const *item, UNUSED void const *uctx)
 Evaluation function for DCHPV4-encodability.
 
void * fr_dhcpv4_next_encodable (fr_dlist_head_t *list, void *current, void *uctx)
 DHCPV4-specific iterator.
 
bool fr_dhcpv4_ok (uint8_t const *data, ssize_t data_len, uint8_t *message_type, uint32_t *xid)
 Check received DHCP request is valid and build fr_packet_t structure if it is.
 
void fr_dhcpv4_print_hex (FILE *fp, uint8_t const *packet, size_t packet_len)
 Print a raw DHCP packet as hex.
 
static void print_hex_data (FILE *fp, uint8_t const *ptr, int attrlen, int depth)
 

Variables

fr_dict_attr_t const * attr_dhcp_boot_filename
 
fr_dict_attr_t const * attr_dhcp_client_hardware_address
 
fr_dict_attr_t const * attr_dhcp_client_ip_address
 
fr_dict_attr_t const * attr_dhcp_dhcp_maximum_msg_size
 
fr_dict_attr_t const * attr_dhcp_flags
 
fr_dict_attr_t const * attr_dhcp_gateway_ip_address
 
fr_dict_attr_t const * attr_dhcp_hardware_address_length
 
fr_dict_attr_t const * attr_dhcp_hardware_type
 
fr_dict_attr_t const * attr_dhcp_hop_count
 
fr_dict_attr_t const * attr_dhcp_interface_mtu_size
 
fr_dict_attr_t const * attr_dhcp_message_type
 
fr_dict_attr_t const * attr_dhcp_network_subnet
 
fr_dict_attr_t const * attr_dhcp_number_of_seconds
 
fr_dict_attr_t const * attr_dhcp_opcode
 
fr_dict_attr_t const * attr_dhcp_option_82
 
fr_dict_attr_t const * attr_dhcp_overload
 
fr_dict_attr_t const * attr_dhcp_parameter_request_list
 
fr_dict_attr_t const * attr_dhcp_relay_link_selection
 
fr_dict_attr_t const * attr_dhcp_server_host_name
 
fr_dict_attr_t const * attr_dhcp_server_ip_address
 
fr_dict_attr_t const * attr_dhcp_subnet_selection_option
 
fr_dict_attr_t const * attr_dhcp_transaction_id
 
fr_dict_attr_t const * attr_dhcp_vendor_class_identifier
 
fr_dict_attr_t const * attr_dhcp_your_ip_address
 
fr_dict_attr_t const ** dhcp_header_attrs []
 
size_t dhcp_header_attrs_len = NUM_ELEMENTS(dhcp_header_attrs)
 
int dhcp_header_sizes []
 
char const * dhcp_message_types []
 
fr_dict_autoload_t dhcpv4_dict []
 
fr_dict_attr_autoload_t dhcpv4_dict_attr []
 
static fr_dict_flag_parser_t const dhcpv4_flags []
 
fr_dict_t const * dict_dhcpv4
 
uint8_t eth_bcast [ETH_ADDR_LEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }
 
static uint32_t instance_count = 0
 
fr_dict_protocol_t libfreeradius_dhcpv4_dict_protocol
 
static char const * short_header_names []
 

Detailed Description

Functions to send/receive dhcp packets.

Id
a20686cb62483681bc3055353d4544b2d073b541

Definition in file base.c.


Data Structure Documentation

◆ dhcp_option_t

struct dhcp_option_t

Definition at line 35 of file base.c.

Data Fields
uint8_t code
uint8_t length

Macro Definition Documentation

◆ DHCP_MAX_MESSAGE_TYPE

#define DHCP_MAX_MESSAGE_TYPE   (NUM_ELEMENTS(dhcp_message_types))

Definition at line 145 of file base.c.

Function Documentation

◆ attr_valid()

static bool attr_valid ( fr_dict_attr_t da)
static

Definition at line 708 of file base.c.

◆ dict_flag_prefix()

static int dict_flag_prefix ( fr_dict_attr_t **  da_p,
char const *  value,
UNUSED fr_dict_flag_parser_rule_t const *  rules 
)
static

Definition at line 169 of file base.c.

+ Here is the call graph for this function:

◆ fr_dhcpv4_attr_cmp()

int8_t fr_dhcpv4_attr_cmp ( void const *  a,
void const *  b 
)

Definition at line 196 of file base.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_dhcpv4_encode()

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 at line 336 of file base.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_dhcpv4_encode_dbuff()

ssize_t fr_dhcpv4_encode_dbuff ( fr_dbuff_t dbuff,
dhcp_packet_t original,
int  code,
uint32_t  xid,
fr_pair_list_t vps 
)

Definition at line 341 of file base.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_dhcpv4_global_free()

void fr_dhcpv4_global_free ( void  )

Definition at line 628 of file base.c.

+ Here is the caller graph for this function:

◆ fr_dhcpv4_global_init()

int fr_dhcpv4_global_init ( void  )

Resolve/cache attributes in the DHCP dictionary.

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

Definition at line 584 of file base.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_dhcpv4_is_encodable()

bool fr_dhcpv4_is_encodable ( void const *  item,
UNUSED void const *  uctx 
)

Evaluation function for DCHPV4-encodability.

Parameters
itempointer to a fr_pair_t
uctxcontext
Returns
true if the underlying fr_pair_t is DHCPv4 encodable, false otherwise

Definition at line 308 of file base.c.

+ Here is the call graph for this function:

◆ fr_dhcpv4_next_encodable()

void * fr_dhcpv4_next_encodable ( fr_dlist_head_t list,
void *  current,
void *  uctx 
)

DHCPV4-specific iterator.

Definition at line 319 of file base.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_dhcpv4_ok()

bool fr_dhcpv4_ok ( uint8_t const *  data,
ssize_t  data_len,
uint8_t message_type,
uint32_t xid 
)

Check received DHCP request is valid and build fr_packet_t structure if it is.

Parameters
datapointer to received packet.
data_lenlength of received data, and then length of the actual DHCP data.
[out]message_typewhere the message type will be stored (if used)
[out]xidwhere the xid will be stored (if used)
Returns
  • true if the packet is well-formed
  • false if it's a bad packet

Definition at line 240 of file base.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_dhcpv4_print_hex()

void fr_dhcpv4_print_hex ( FILE *  fp,
uint8_t const *  packet,
size_t  packet_len 
)

Print a raw DHCP packet as hex.

Definition at line 672 of file base.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ print_hex_data()

static void print_hex_data ( FILE *  fp,
uint8_t const *  ptr,
int  attrlen,
int  depth 
)
static

Definition at line 655 of file base.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ attr_dhcp_boot_filename

fr_dict_attr_t const* attr_dhcp_boot_filename

Definition at line 48 of file base.c.

◆ attr_dhcp_client_hardware_address

fr_dict_attr_t const* attr_dhcp_client_hardware_address

Definition at line 49 of file base.c.

◆ attr_dhcp_client_ip_address

fr_dict_attr_t const* attr_dhcp_client_ip_address

Definition at line 50 of file base.c.

◆ attr_dhcp_dhcp_maximum_msg_size

fr_dict_attr_t const* attr_dhcp_dhcp_maximum_msg_size

Definition at line 62 of file base.c.

◆ attr_dhcp_flags

fr_dict_attr_t const* attr_dhcp_flags

Definition at line 51 of file base.c.

◆ attr_dhcp_gateway_ip_address

fr_dict_attr_t const* attr_dhcp_gateway_ip_address

Definition at line 52 of file base.c.

◆ attr_dhcp_hardware_address_length

fr_dict_attr_t const* attr_dhcp_hardware_address_length

Definition at line 53 of file base.c.

◆ attr_dhcp_hardware_type

fr_dict_attr_t const* attr_dhcp_hardware_type

Definition at line 54 of file base.c.

◆ attr_dhcp_hop_count

fr_dict_attr_t const* attr_dhcp_hop_count

Definition at line 55 of file base.c.

◆ attr_dhcp_interface_mtu_size

fr_dict_attr_t const* attr_dhcp_interface_mtu_size

Definition at line 63 of file base.c.

◆ attr_dhcp_message_type

fr_dict_attr_t const* attr_dhcp_message_type

Definition at line 64 of file base.c.

◆ attr_dhcp_network_subnet

fr_dict_attr_t const* attr_dhcp_network_subnet

Definition at line 70 of file base.c.

◆ attr_dhcp_number_of_seconds

fr_dict_attr_t const* attr_dhcp_number_of_seconds

Definition at line 56 of file base.c.

◆ attr_dhcp_opcode

fr_dict_attr_t const* attr_dhcp_opcode

Definition at line 57 of file base.c.

◆ attr_dhcp_option_82

fr_dict_attr_t const* attr_dhcp_option_82

Definition at line 71 of file base.c.

◆ attr_dhcp_overload

fr_dict_attr_t const* attr_dhcp_overload

Definition at line 66 of file base.c.

◆ attr_dhcp_parameter_request_list

fr_dict_attr_t const* attr_dhcp_parameter_request_list

Definition at line 65 of file base.c.

◆ attr_dhcp_relay_link_selection

fr_dict_attr_t const* attr_dhcp_relay_link_selection

Definition at line 68 of file base.c.

◆ attr_dhcp_server_host_name

fr_dict_attr_t const* attr_dhcp_server_host_name

Definition at line 58 of file base.c.

◆ attr_dhcp_server_ip_address

fr_dict_attr_t const* attr_dhcp_server_ip_address

Definition at line 59 of file base.c.

◆ attr_dhcp_subnet_selection_option

fr_dict_attr_t const* attr_dhcp_subnet_selection_option

Definition at line 69 of file base.c.

◆ attr_dhcp_transaction_id

fr_dict_attr_t const* attr_dhcp_transaction_id

Definition at line 60 of file base.c.

◆ attr_dhcp_vendor_class_identifier

fr_dict_attr_t const* attr_dhcp_vendor_class_identifier

Definition at line 67 of file base.c.

◆ attr_dhcp_your_ip_address

fr_dict_attr_t const* attr_dhcp_your_ip_address

Definition at line 61 of file base.c.

◆ dhcp_header_attrs

fr_dict_attr_t const** dhcp_header_attrs[]
Initial value:
= {
}
fr_dict_attr_t const * attr_dhcp_opcode
Definition base.c:57
fr_dict_attr_t const * attr_dhcp_gateway_ip_address
Definition base.c:52
fr_dict_attr_t const * attr_dhcp_server_ip_address
Definition base.c:59
fr_dict_attr_t const * attr_dhcp_hop_count
Definition base.c:55
fr_dict_attr_t const * attr_dhcp_server_host_name
Definition base.c:58
fr_dict_attr_t const * attr_dhcp_hardware_address_length
Definition base.c:53
fr_dict_attr_t const * attr_dhcp_transaction_id
Definition base.c:60
fr_dict_attr_t const * attr_dhcp_boot_filename
Definition base.c:48
fr_dict_attr_t const * attr_dhcp_flags
Definition base.c:51
fr_dict_attr_t const * attr_dhcp_hardware_type
Definition base.c:54
fr_dict_attr_t const * attr_dhcp_your_ip_address
Definition base.c:61
fr_dict_attr_t const * attr_dhcp_client_ip_address
Definition base.c:50
fr_dict_attr_t const * attr_dhcp_client_hardware_address
Definition base.c:49
fr_dict_attr_t const * attr_dhcp_number_of_seconds
Definition base.c:56

Definition at line 108 of file base.c.

◆ dhcp_header_attrs_len

size_t dhcp_header_attrs_len = NUM_ELEMENTS(dhcp_header_attrs)

Definition at line 124 of file base.c.

◆ dhcp_header_sizes

int dhcp_header_sizes[]
Initial value:
= {
1,
1,
1,
1,
4,
2,
2,
4,
4,
4,
4,
}
#define DHCP_CHADDR_LEN
Definition dhcpv4.h:37
#define DHCP_SNAME_LEN
Definition dhcpv4.h:38
#define DHCP_FILE_LEN
Definition dhcpv4.h:39

Definition at line 147 of file base.c.

◆ dhcp_message_types

char const* dhcp_message_types[]
Initial value:
= {
"invalid",
"Discover",
"Offer",
"Request",
"Decline",
"Ack",
"NAK",
"Release",
"Inform",
"Force-Renew",
"Lease-Query",
"Lease-Unassigned",
"Lease-Unknown",
"Lease-Active",
"Bulk-Lease-Query",
"Lease-Query-Done"
}

Definition at line 126 of file base.c.

◆ dhcpv4_dict

fr_dict_autoload_t dhcpv4_dict
Initial value:
= {
{ .out = &dict_dhcpv4, .proto = "dhcpv4" },
{ NULL }
}
static fr_dict_t const * dict_dhcpv4
Definition base.c:34

Definition at line 43 of file base.c.

◆ dhcpv4_dict_attr

fr_dict_attr_autoload_t dhcpv4_dict_attr
Initial value:
= {
{ .out = &attr_dhcp_boot_filename, .name = "Boot-Filename", .type = FR_TYPE_STRING, .dict = &dict_dhcpv4 },
{ .out = &attr_dhcp_client_hardware_address, .name = "Client-Hardware-Address", .type = FR_TYPE_ETHERNET, .dict = &dict_dhcpv4 },
{ .out = &attr_dhcp_client_ip_address, .name = "Client-IP-Address", .type = FR_TYPE_IPV4_ADDR, .dict = &dict_dhcpv4 },
{ .out = &attr_dhcp_flags, .name = "Flags", .type = FR_TYPE_UINT16, .dict = &dict_dhcpv4 },
{ .out = &attr_dhcp_gateway_ip_address, .name = "Gateway-IP-Address", .type = FR_TYPE_IPV4_ADDR, .dict = &dict_dhcpv4 },
{ .out = &attr_dhcp_hardware_address_length, .name = "Hardware-Address-Length", .type = FR_TYPE_UINT8, .dict = &dict_dhcpv4 },
{ .out = &attr_dhcp_hardware_type, .name = "Hardware-Type", .type = FR_TYPE_UINT8, .dict = &dict_dhcpv4 },
{ .out = &attr_dhcp_hop_count, .name = "Hop-Count", .type = FR_TYPE_UINT8, .dict = &dict_dhcpv4 },
{ .out = &attr_dhcp_number_of_seconds, .name = "Number-of-Seconds", .type = FR_TYPE_UINT16, .dict = &dict_dhcpv4 },
{ .out = &attr_dhcp_opcode, .name = "Opcode", .type = FR_TYPE_UINT8, .dict = &dict_dhcpv4 },
{ .out = &attr_dhcp_server_host_name, .name = "Server-Host-Name", .type = FR_TYPE_STRING, .dict = &dict_dhcpv4 },
{ .out = &attr_dhcp_server_ip_address, .name = "Server-IP-Address", .type = FR_TYPE_IPV4_ADDR, .dict = &dict_dhcpv4 },
{ .out = &attr_dhcp_transaction_id, .name = "Transaction-Id", .type = FR_TYPE_UINT32, .dict = &dict_dhcpv4 },
{ .out = &attr_dhcp_your_ip_address, .name = "Your-IP-Address", .type = FR_TYPE_IPV4_ADDR, .dict = &dict_dhcpv4 },
{ .out = &attr_dhcp_dhcp_maximum_msg_size, .name = "Maximum-Msg-Size", .type = FR_TYPE_UINT16, .dict = &dict_dhcpv4 },
{ .out = &attr_dhcp_interface_mtu_size, .name = "Interface-MTU-Size", .type = FR_TYPE_UINT16, .dict = &dict_dhcpv4 },
{ .out = &attr_dhcp_message_type, .name = "Message-Type", .type = FR_TYPE_UINT8, .dict = &dict_dhcpv4 },
{ .out = &attr_dhcp_parameter_request_list, .name = "Parameter-Request-List", .type = FR_TYPE_UINT8, .dict = &dict_dhcpv4 },
{ .out = &attr_dhcp_overload, .name = "Overload", .type = FR_TYPE_UINT8, .dict = &dict_dhcpv4 },
{ .out = &attr_dhcp_vendor_class_identifier, .name = "Vendor-Class-Identifier", .type = FR_TYPE_OCTETS, .dict = &dict_dhcpv4 },
{ .out = &attr_dhcp_relay_link_selection, .name = "Relay-Agent-Information.Relay-Link-Selection", .type = FR_TYPE_IPV4_ADDR, .dict = &dict_dhcpv4 },
{ .out = &attr_dhcp_subnet_selection_option, .name = "Subnet-Selection-Option", .type = FR_TYPE_IPV4_ADDR, .dict = &dict_dhcpv4 },
{ .out = &attr_dhcp_network_subnet, .name = "Network-Subnet", .type = FR_TYPE_IPV4_PREFIX, .dict = &dict_dhcpv4 },
{ .out = &attr_dhcp_option_82, .name = "Relay-Agent-Information", .type = FR_TYPE_TLV, .dict = &dict_dhcpv4 },
{ NULL }
}
@ FR_TYPE_IPV4_ADDR
32 Bit IPv4 Address.
@ FR_TYPE_TLV
Contains nested attributes.
@ FR_TYPE_ETHERNET
48 Bit Mac-Address.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_UINT16
16 Bit unsigned integer.
@ FR_TYPE_UINT8
8 Bit unsigned integer.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_IPV4_PREFIX
IPv4 Prefix.
@ FR_TYPE_OCTETS
Raw octets.
fr_dict_attr_t const * attr_dhcp_dhcp_maximum_msg_size
Definition base.c:62
fr_dict_attr_t const * attr_dhcp_relay_link_selection
Definition base.c:68
fr_dict_attr_t const * attr_dhcp_vendor_class_identifier
Definition base.c:67
fr_dict_attr_t const * attr_dhcp_parameter_request_list
Definition base.c:65
fr_dict_attr_t const * attr_dhcp_message_type
Definition base.c:64
fr_dict_attr_t const * attr_dhcp_overload
Definition base.c:66
fr_dict_attr_t const * attr_dhcp_subnet_selection_option
Definition base.c:69
fr_dict_attr_t const * attr_dhcp_network_subnet
Definition base.c:70
fr_dict_attr_t const * attr_dhcp_option_82
Definition base.c:71
fr_dict_attr_t const * attr_dhcp_interface_mtu_size
Definition base.c:63

Definition at line 74 of file base.c.

◆ dhcpv4_flags

fr_dict_flag_parser_t const dhcpv4_flags[]
static
Initial value:
= {
{ L("dns_label"), { .func = dict_flag_dns_label } },
{ L("exists"), { .func = dict_flag_exists } },
{ L("prefix"), { .func = dict_flag_prefix } }
}
#define L(_str)
Helper for initialising arrays of string literals.
Definition build.h:209
static int dict_flag_prefix(fr_dict_attr_t **da_p, char const *value, UNUSED fr_dict_flag_parser_rule_t const *rules)
Definition base.c:169

Definition at line 190 of file base.c.

◆ dict_dhcpv4

fr_dict_t const* dict_dhcpv4

Definition at line 40 of file base.c.

◆ eth_bcast

uint8_t eth_bcast[ETH_ADDR_LEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }

Definition at line 164 of file base.c.

◆ instance_count

uint32_t instance_count = 0
static

Definition at line 33 of file base.c.

◆ libfreeradius_dhcpv4_dict_protocol

fr_dict_protocol_t libfreeradius_dhcpv4_dict_protocol
Initial value:
= {
.name = "dhcpv4",
.default_type_size = 1,
.default_type_length = 1,
.attr = {
.flags = {
.table = dhcpv4_flags,
.table_len = NUM_ELEMENTS(dhcpv4_flags),
.len = sizeof(fr_dhcpv4_attr_flags_t)
},
.valid = attr_valid
},
}
#define NUM_ELEMENTS(_t)
Definition build.h:337
ssize_t fr_dhcpv4_encode_foreign(fr_dbuff_t *dbuff, fr_pair_list_t const *list)
Definition encode.c:774
int fr_dhcpv4_global_init(void)
Resolve/cache attributes in the DHCP dictionary.
Definition base.c:584
static fr_dict_flag_parser_t const dhcpv4_flags[]
Definition base.c:190
void fr_dhcpv4_global_free(void)
Definition base.c:628
ssize_t fr_dhcpv4_decode_foreign(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, size_t data_len)
Definition decode.c:648
static bool attr_valid(fr_dict_attr_t *da)
Definition base.c:443

Definition at line 754 of file base.c.

◆ short_header_names

char const* short_header_names[]
static
Initial value:
= {
"opcode",
"hwtype",
"hwaddrlen",
"hop_count",
"xid",
"seconds",
"flags",
"ciaddr",
"yiaddr",
"siaddr",
"giaddr",
"chaddr",
"server_hostname",
"boot_filename",
}

Definition at line 638 of file base.c.