The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
Data Structures | Macros | Enumerations | Functions | Variables
dhcpv4.h File Reference

Implementation of the DHCPv4 protocol. More...

#include <freeradius-devel/util/pcap.h>
#include <freeradius-devel/util/packet.h>
#include <freeradius-devel/protocol/dhcpv4/rfc2131.h>
+ Include dependency graph for dhcpv4.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  dhcp_packet_t
 
struct  fr_dhcpv4_attr_flags_t
 
struct  fr_dhcpv4_ctx_t
 Used as the decoder ctx. More...
 

Macros

#define DEFAULT_PACKET_SIZE   (300)
 
#define DHCP_CHADDR_LEN   (16)
 
#define DHCP_FILE_FIELD   (1)
 
#define DHCP_FILE_LEN   (128)
 
#define DHCP_OPTION_FIELD   (0)
 
#define DHCP_OPTION_MAGIC_NUMBER   (0x63825363U)
 
#define DHCP_PACK_OPTION1(x, y)   ((x) | ((y) << 8))
 
#define DHCP_SNAME_FIELD   (2)
 
#define DHCP_SNAME_LEN   (64)
 
#define DHCP_UNPACK_OPTION1(x)   (((x) & 0xff00) >> 8)
 
#define DHCP_VEND_LEN   (308)
 
#define DHCPV4_MAX_ATTRIBUTES   255
 
#define ETH_ADDR_LEN   6
 
#define FR_DHCP_PACKET_CODE_VALID(_code)   (((_code) > 0) && ((_code) < FR_DHCP_CODE_MAX))
 
#define INADDR_BROADCAST   INADDR_NONE
 
#define MAX_PACKET_SIZE   (1500 - 40)
 
#define MIN_PACKET_SIZE   (244)
 

Enumerations

enum  fr_dhcpv4_attr_flags_prefix_t : int8_t {
  DHCPV4_FLAG_PREFIX_INVALID = -1 ,
  DHCPV4_FLAG_PREFIX_NONE = 0 ,
  DHCPV4_FLAG_PREFIX_BITS = 1 ,
  DHCPV4_FLAG_PREFIX_SPLIT = 2
}
 
enum  fr_dhcpv4_packet_code_t : uint16_t {
  FR_DHCP_INVALID = 0 ,
  FR_DHCP_DISCOVER = 1 ,
  FR_DHCP_OFFER = 2 ,
  FR_DHCP_REQUEST = 3 ,
  FR_DHCP_DECLINE = 4 ,
  FR_DHCP_ACK = 5 ,
  FR_DHCP_NAK = 6 ,
  FR_DHCP_RELEASE = 7 ,
  FR_DHCP_INFORM = 8 ,
  FR_DHCP_FORCE_RENEW = 9 ,
  FR_DHCP_LEASE_QUERY = 10 ,
  FR_DHCP_LEASE_UNASSIGNED = 11 ,
  FR_DHCP_LEASE_UNKNOWN = 12 ,
  FR_DHCP_LEASE_ACTIVE = 13 ,
  FR_DHCP_BULK_LEASE_QUERY = 14 ,
  FR_DHCP_LEASE_QUERY_DONE = 15 ,
  FR_DHCP_CODE_MAX = 16 ,
  FR_DHCP_DO_NOT_RESPOND = 256
}
 

Functions

fr_cmp_ret_t fr_dhcpv4_attr_cmp (void const *a, void const *b)
 
static fr_dhcpv4_attr_flags_t const * fr_dhcpv4_attr_flags (fr_dict_attr_t const *da)
 Return DHCPv4-specific flags for a given attribute.
 
int fr_dhcpv4_decode (TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, size_t data_len, unsigned int *code)
 
ssize_t fr_dhcpv4_decode_foreign (TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, size_t data_len)
 
ssize_t fr_dhcpv4_decode_option (TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, size_t len, void *decode_ctx)
 Decode DHCP option.
 
ssize_t fr_dhcpv4_encode (uint8_t *buffer, size_t buflen, dhcp_packet_t *original, fr_dhcpv4_packet_code_t code, uint32_t xid, fr_pair_list_t *vps)
 
ssize_t fr_dhcpv4_encode_dbuff (fr_dbuff_t *dbuff, dhcp_packet_t *original, fr_dhcpv4_packet_code_t code, uint32_t xid, fr_pair_list_t *vps)
 
ssize_t fr_dhcpv4_encode_foreign (fr_dbuff_t *dbuff, fr_pair_list_t const *list)
 
ssize_t fr_dhcpv4_encode_option (fr_dbuff_t *dbuff, fr_dcursor_t *cursor, void *encode_ctx)
 Encode a DHCP option and any sub-options.
 
static bool fr_dhcpv4_flag_dns_label (fr_dict_attr_t const *da)
 
static bool fr_dhcpv4_flag_exists (fr_dict_attr_t const *da)
 
static fr_dhcpv4_attr_flags_prefix_t fr_dhcpv4_flag_prefix (fr_dict_attr_t const *da)
 
static bool fr_dhcpv4_flag_prefix_bits (fr_dict_attr_t const *da)
 
static bool fr_dhcpv4_flag_prefix_split (fr_dict_attr_t const *da)
 
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, void const *uctx)
 
void * fr_dhcpv4_next_encodable (fr_dcursor_t *cursor, void *to_eval, void *uctx)
 DHCPV4-specific iterator.
 
bool fr_dhcpv4_ok (uint8_t const *data, size_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.
 
fr_packet_t * fr_dhcpv4_packet_alloc (uint8_t const *data, size_t data_len)
 
int fr_dhcpv4_packet_encode (fr_packet_t *packet, fr_pair_list_t *list)
 
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.
 
void fr_dhcpv4_print_hex (FILE *fp, uint8_t const *packet, size_t packet_len)
 Print a raw DHCP packet as hex.
 
fr_packet_t * fr_dhcpv4_udp_packet_recv (int sockfd)
 Receive DHCP packet using a connectionless UDP socket.
 
int fr_dhcpv4_udp_packet_send (fr_packet_t *packet)
 Send DHCP packet using a connectionless UDP socket.
 

Variables

fr_dict_attr_t const ** dhcp_header_attrs []
 
size_t dhcp_header_attrs_len
 
int dhcp_header_sizes []
 
char const * dhcp_message_types [FR_DHCP_CODE_MAX]
 
uint8_t eth_bcast [ETH_ADDR_LEN]
 
fr_dict_protocol_t libfreeradius_dhcpv4_dict_protocol
 

Detailed Description

Implementation of the DHCPv4 protocol.

Id
e9b71fe622406e0b165b8e1db5a5ae97853e058f

Definition in file dhcpv4.h.


Data Structure Documentation

◆ dhcp_packet_t

struct dhcp_packet_t

Definition at line 66 of file dhcpv4.h.

Data Fields
uint8_t chaddr[DHCP_CHADDR_LEN]
uint32_t ciaddr
uint8_t file[DHCP_FILE_LEN]
uint16_t flags
uint32_t giaddr
uint8_t hlen
uint8_t hops
uint8_t htype
uint8_t opcode
uint32_t option_format
uint8_t options[DHCP_VEND_LEN]
uint16_t secs
uint32_t siaddr
uint8_t sname[DHCP_SNAME_LEN]
uint32_t xid
uint32_t yiaddr

◆ fr_dhcpv4_attr_flags_t

struct fr_dhcpv4_attr_flags_t

Definition at line 146 of file dhcpv4.h.

Data Fields
bool dns_label
bool exists
fr_dhcpv4_attr_flags_prefix_t prefix

◆ fr_dhcpv4_ctx_t

struct fr_dhcpv4_ctx_t

Used as the decoder ctx.

Definition at line 134 of file dhcpv4.h.

+ Collaboration diagram for fr_dhcpv4_ctx_t:
Data Fields
fr_dict_attr_t const * root
TALLOC_CTX * tmp_ctx for temporary things cleaned up during decoding

Macro Definition Documentation

◆ DEFAULT_PACKET_SIZE

#define DEFAULT_PACKET_SIZE   (300)

Definition at line 89 of file dhcpv4.h.

◆ DHCP_CHADDR_LEN

#define DHCP_CHADDR_LEN   (16)

Definition at line 37 of file dhcpv4.h.

◆ DHCP_FILE_FIELD

#define DHCP_FILE_FIELD   (1)

Definition at line 94 of file dhcpv4.h.

◆ DHCP_FILE_LEN

#define DHCP_FILE_LEN   (128)

Definition at line 39 of file dhcpv4.h.

◆ DHCP_OPTION_FIELD

#define DHCP_OPTION_FIELD   (0)

Definition at line 93 of file dhcpv4.h.

◆ DHCP_OPTION_MAGIC_NUMBER

#define DHCP_OPTION_MAGIC_NUMBER   (0x63825363U)

Definition at line 41 of file dhcpv4.h.

◆ DHCP_PACK_OPTION1

#define DHCP_PACK_OPTION1 (   x,
  y 
)    ((x) | ((y) << 8))

Definition at line 97 of file dhcpv4.h.

◆ DHCP_SNAME_FIELD

#define DHCP_SNAME_FIELD   (2)

Definition at line 95 of file dhcpv4.h.

◆ DHCP_SNAME_LEN

#define DHCP_SNAME_LEN   (64)

Definition at line 38 of file dhcpv4.h.

◆ DHCP_UNPACK_OPTION1

#define DHCP_UNPACK_OPTION1 (   x)    (((x) & 0xff00) >> 8)

Definition at line 98 of file dhcpv4.h.

◆ DHCP_VEND_LEN

#define DHCP_VEND_LEN   (308)

Definition at line 40 of file dhcpv4.h.

◆ DHCPV4_MAX_ATTRIBUTES

#define DHCPV4_MAX_ATTRIBUTES   255

Definition at line 91 of file dhcpv4.h.

◆ ETH_ADDR_LEN

#define ETH_ADDR_LEN   6

Definition at line 103 of file dhcpv4.h.

◆ FR_DHCP_PACKET_CODE_VALID

#define FR_DHCP_PACKET_CODE_VALID (   _code)    (((_code) > 0) && ((_code) < FR_DHCP_CODE_MAX))

Definition at line 64 of file dhcpv4.h.

◆ INADDR_BROADCAST

#define INADDR_BROADCAST   INADDR_NONE

Definition at line 101 of file dhcpv4.h.

◆ MAX_PACKET_SIZE

#define MAX_PACKET_SIZE   (1500 - 40)

Definition at line 90 of file dhcpv4.h.

◆ MIN_PACKET_SIZE

#define MIN_PACKET_SIZE   (244)

Definition at line 88 of file dhcpv4.h.

Enumeration Type Documentation

◆ fr_dhcpv4_attr_flags_prefix_t

Enumerator
DHCPV4_FLAG_PREFIX_INVALID 
DHCPV4_FLAG_PREFIX_NONE 
DHCPV4_FLAG_PREFIX_BITS 
DHCPV4_FLAG_PREFIX_SPLIT 

Definition at line 139 of file dhcpv4.h.

◆ fr_dhcpv4_packet_code_t

Enumerator
FR_DHCP_INVALID 
FR_DHCP_DISCOVER 
FR_DHCP_OFFER 
FR_DHCP_REQUEST 
FR_DHCP_DECLINE 
FR_DHCP_ACK 
FR_DHCP_NAK 
FR_DHCP_RELEASE 
FR_DHCP_INFORM 
FR_DHCP_FORCE_RENEW 
FR_DHCP_LEASE_QUERY 
FR_DHCP_LEASE_UNASSIGNED 
FR_DHCP_LEASE_UNKNOWN 
FR_DHCP_LEASE_ACTIVE 
FR_DHCP_BULK_LEASE_QUERY 
FR_DHCP_LEASE_QUERY_DONE 
FR_DHCP_CODE_MAX 
FR_DHCP_DO_NOT_RESPOND 

Definition at line 43 of file dhcpv4.h.

Function Documentation

◆ fr_dhcpv4_attr_cmp()

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

Definition at line 204 of file base.c.

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

◆ fr_dhcpv4_attr_flags()

static fr_dhcpv4_attr_flags_t const * fr_dhcpv4_attr_flags ( fr_dict_attr_t const *  da)
inlinestatic

Return DHCPv4-specific flags for a given attribute.

Assert in debug builds when the attribute belongs to another dictionary, as the flags of one protocol say nothing about an attribute of another.

If the attribute does not carry the protocol-specific extension, then assert. Other builds log the error and return zeroed flags instead of NULL.

Definition at line 162 of file dhcpv4.h.

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

◆ fr_dhcpv4_decode()

int fr_dhcpv4_decode ( TALLOC_CTX *  ctx,
fr_pair_list_t *  out,
uint8_t const *  data,
size_t  data_len,
unsigned int *  code 
)

Definition at line 119 of file packet.c.

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

◆ fr_dhcpv4_decode_foreign()

ssize_t fr_dhcpv4_decode_foreign ( TALLOC_CTX *  ctx,
fr_pair_list_t *  out,
uint8_t const *  data,
size_t  data_len 
)

Definition at line 698 of file decode.c.

+ Here is the call graph for this function:

◆ fr_dhcpv4_decode_option()

ssize_t fr_dhcpv4_decode_option ( TALLOC_CTX *  ctx,
fr_pair_list_t *  out,
uint8_t const *  data,
size_t  data_len,
void *  decode_ctx 
)

Decode DHCP option.

Parameters
[in]ctxcontext to alloc new attributes in.
[out]outWhere to write the decoded options.
[in]datato parse.
[in]data_lenof data to parse.
[in]decode_ctxUnused.

Definition at line 587 of file decode.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,
fr_dhcpv4_packet_code_t  code,
uint32_t  xid,
fr_pair_list_t *  vps 
)

Definition at line 358 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,
fr_dhcpv4_packet_code_t  code,
uint32_t  xid,
fr_pair_list_t *  vps 
)

Definition at line 363 of file base.c.

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

◆ fr_dhcpv4_encode_foreign()

ssize_t fr_dhcpv4_encode_foreign ( fr_dbuff_t *  dbuff,
fr_pair_list_t const *  list 
)

Definition at line 786 of file encode.c.

+ Here is the call graph for this function:

◆ fr_dhcpv4_encode_option()

ssize_t fr_dhcpv4_encode_option ( fr_dbuff_t *  dbuff,
fr_dcursor_t *  cursor,
void *  encode_ctx 
)

Encode a DHCP option and any sub-options.

Parameters
[out]dbuffWhere to write encoded DHCP attributes.
[in]cursorwith current VP set to the option to be encoded. Will be advanced to the next option to encode.
[in]encode_ctxContaining DHCPv4 dictionary.
Returns
  • > 0 length of data written.
  • < 0 error.
  • 0 not valid option for DHCP (skipping).

Definition at line 737 of file encode.c.

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

◆ fr_dhcpv4_flag_dns_label()

static bool fr_dhcpv4_flag_dns_label ( fr_dict_attr_t const *  da)
inlinestatic

Definition at line 178 of file dhcpv4.h.

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

◆ fr_dhcpv4_flag_exists()

static bool fr_dhcpv4_flag_exists ( fr_dict_attr_t const *  da)
inlinestatic

Definition at line 183 of file dhcpv4.h.

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

◆ fr_dhcpv4_flag_prefix()

static fr_dhcpv4_attr_flags_prefix_t fr_dhcpv4_flag_prefix ( fr_dict_attr_t const *  da)
inlinestatic

Definition at line 188 of file dhcpv4.h.

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

◆ fr_dhcpv4_flag_prefix_bits()

static bool fr_dhcpv4_flag_prefix_bits ( fr_dict_attr_t const *  da)
inlinestatic

Definition at line 193 of file dhcpv4.h.

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

◆ fr_dhcpv4_flag_prefix_split()

static bool fr_dhcpv4_flag_prefix_split ( fr_dict_attr_t const *  da)
inlinestatic

Definition at line 198 of file dhcpv4.h.

+ 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 635 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 611 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,
void const *  uctx 
)

◆ fr_dhcpv4_next_encodable()

void * fr_dhcpv4_next_encodable ( fr_dcursor_t *  cursor,
void *  to_eval,
void *  uctx 
)

DHCPV4-specific iterator.

Definition at line 332 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,
size_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 248 of file base.c.

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

◆ fr_dhcpv4_packet_alloc()

fr_packet_t * fr_dhcpv4_packet_alloc ( uint8_t const *  data,
size_t  data_len 
)

Definition at line 418 of file packet.c.

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

◆ fr_dhcpv4_packet_encode()

int fr_dhcpv4_packet_encode ( fr_packet_t *  packet,
fr_pair_list_t *  list 
)

Definition at line 390 of file packet.c.

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

◆ fr_dhcpv4_packet_get_option()

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 at line 37 of file packet.c.

+ 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 682 of file base.c.

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

◆ fr_dhcpv4_udp_packet_recv()

fr_packet_t * fr_dhcpv4_udp_packet_recv ( int  sockfd)

Receive DHCP packet using a connectionless UDP socket.

Parameters
sockfdhandle.
Returns
  • pointer to fr_packet_t if successful.
  • NULL if failed.

Definition at line 74 of file udp.c.

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

◆ fr_dhcpv4_udp_packet_send()

int fr_dhcpv4_udp_packet_send ( fr_packet_t *  packet)

Send DHCP packet using a connectionless UDP socket.

Parameters
packetto send
Returns
  • >= 0 if successful.
  • < 0 if failed.

Definition at line 41 of file udp.c.

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

Variable Documentation

◆ dhcp_header_attrs

fr_dict_attr_t const** dhcp_header_attrs[]
extern

Definition at line 111 of file base.c.

◆ dhcp_header_attrs_len

size_t dhcp_header_attrs_len
extern

Definition at line 127 of file base.c.

◆ dhcp_header_sizes

int dhcp_header_sizes[]
extern

Definition at line 150 of file base.c.

◆ dhcp_message_types

char const* dhcp_message_types[FR_DHCP_CODE_MAX]
extern

Definition at line 129 of file base.c.

◆ eth_bcast

uint8_t eth_bcast[ETH_ADDR_LEN]
extern

Definition at line 167 of file base.c.

◆ libfreeradius_dhcpv4_dict_protocol

fr_dict_protocol_t libfreeradius_dhcpv4_dict_protocol
extern

Definition at line 798 of file base.c.