The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
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_ctx_t
 Used as the decoder ctx. More...
 

Macros

#define da_is_bits_prefix(_da)   (!(_da)->flags.extra && ((_da)->flags.subtype == FLAG_ENCODE_BITS_PREFIX))
 
#define da_is_bool_exists(_da)   (!(_da)->flags.extra && ((_da)->flags.subtype == FLAG_ENCODE_BOOL_EXISTS))
 
#define da_is_dns_label(_da)   (!(_da)->flags.extra && ((_da)->flags.subtype == FLAG_ENCODE_DNS_LABEL))
 
#define da_is_split_prefix(_da)   (!(_da)->flags.extra && ((_da)->flags.subtype == FLAG_ENCODE_SPLIT_PREFIX))
 
#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   (0x63825363)
 
#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_OPTION_82   (82)
 
#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  {
  FLAG_ENCODE_NONE = 0 ,
  FLAG_ENCODE_DNS_LABEL ,
  FLAG_ENCODE_SPLIT_PREFIX ,
  FLAG_ENCODE_BITS_PREFIX ,
  FLAG_ENCODE_BOOL_EXISTS
}
 subtype values for DHCPv4 and DHCPv6 More...
 
enum  fr_dhcpv4_packet_code_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

int8_t fr_dhcpv4_attr_cmp (void const *a, void const *b)
 
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. More...
 
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)
 
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. More...
 
void fr_dhcpv4_global_free (void)
 
int fr_dhcpv4_global_init (void)
 Resolve/cache attributes in the DHCP dictionary. More...
 
bool fr_dhcpv4_is_encodable (void const *item, void const *uctx)
 
void * fr_dhcpv4_next_encodable (fr_dlist_head_t *list, void *to_eval, void *uctx)
 DHCPV4-specific iterator. More...
 
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. More...
 
fr_packet_tfr_dhcpv4_packet_alloc (uint8_t const *data, ssize_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. More...
 
void fr_dhcpv4_print_hex (FILE *fp, uint8_t const *packet, size_t packet_len)
 Print a raw DHCP packet as hex. More...
 
fr_packet_tfr_dhcpv4_udp_packet_recv (int sockfd)
 Receive DHCP packet using a connectionless UDP socket. More...
 
int fr_dhcpv4_udp_packet_send (fr_packet_t *packet)
 Send DHCP packet using a connectionless UDP socket. More...
 

Variables

fr_dict_attr_t const ** dhcp_header_attrs []
 
size_t dhcp_header_attrs_len
 
int dhcp_header_sizes []
 
char const * dhcp_message_types []
 
HIDDEN fr_dict_attr_t const * dhcp_option_82
 
uint8_t eth_bcast [ETH_ADDR_LEN]
 

Detailed Description

Implementation of the DHCPv4 protocol.

Id
24d4195921871fb197d1b759eb818b23c30c6f5a

Definition in file dhcpv4.h.


Data Structure Documentation

◆ dhcp_packet_t

struct dhcp_packet_t

Definition at line 82 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_ctx_t

struct fr_dhcpv4_ctx_t

Used as the decoder ctx.

Definition at line 152 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

◆ da_is_bits_prefix

#define da_is_bits_prefix (   _da)    (!(_da)->flags.extra && ((_da)->flags.subtype == FLAG_ENCODE_BITS_PREFIX))

Definition at line 79 of file dhcpv4.h.

◆ da_is_bool_exists

#define da_is_bool_exists (   _da)    (!(_da)->flags.extra && ((_da)->flags.subtype == FLAG_ENCODE_BOOL_EXISTS))

Definition at line 80 of file dhcpv4.h.

◆ da_is_dns_label

#define da_is_dns_label (   _da)    (!(_da)->flags.extra && ((_da)->flags.subtype == FLAG_ENCODE_DNS_LABEL))

Definition at line 77 of file dhcpv4.h.

◆ da_is_split_prefix

#define da_is_split_prefix (   _da)    (!(_da)->flags.extra && ((_da)->flags.subtype == FLAG_ENCODE_SPLIT_PREFIX))

Definition at line 78 of file dhcpv4.h.

◆ DEFAULT_PACKET_SIZE

#define DEFAULT_PACKET_SIZE   (300)

Definition at line 105 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 110 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 109 of file dhcpv4.h.

◆ DHCP_OPTION_MAGIC_NUMBER

#define DHCP_OPTION_MAGIC_NUMBER   (0x63825363)

Definition at line 41 of file dhcpv4.h.

◆ DHCP_PACK_OPTION1

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

Definition at line 114 of file dhcpv4.h.

◆ DHCP_SNAME_FIELD

#define DHCP_SNAME_FIELD   (2)

Definition at line 111 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 115 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 107 of file dhcpv4.h.

◆ ETH_ADDR_LEN

#define ETH_ADDR_LEN   6

Definition at line 120 of file dhcpv4.h.

◆ FR_DHCP_OPTION_82

#define FR_DHCP_OPTION_82   (82)

Definition at line 113 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 118 of file dhcpv4.h.

◆ MAX_PACKET_SIZE

#define MAX_PACKET_SIZE   (1500 - 40)

Definition at line 106 of file dhcpv4.h.

◆ MIN_PACKET_SIZE

#define MIN_PACKET_SIZE   (244)

Definition at line 104 of file dhcpv4.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

subtype values for DHCPv4 and DHCPv6

Enumerator
FLAG_ENCODE_NONE 

no particular encoding for DHCPv6 strings

FLAG_ENCODE_DNS_LABEL 

encode as DNS label

FLAG_ENCODE_SPLIT_PREFIX 

encode IPv4 prefixes as Policy-Filter, split into IP/mask

FLAG_ENCODE_BITS_PREFIX 

encode IPv4 prefixes as prefix bits, followed by IP.

FLAG_ENCODE_BOOL_EXISTS 

bool as existence checks

Definition at line 69 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()

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

Definition at line 166 of file base.c.

+ 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 100 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 640 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 538 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,
int  code,
uint32_t  xid,
fr_pair_list_t vps 
)

Definition at line 311 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 316 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 759 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 711 of file encode.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 601 of file base.c.

+ Here is the call graph for this function:
+ 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 557 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_dlist_head_t list,
void *  to_eval,
void *  uctx 
)

DHCPV4-specific iterator.

Definition at line 294 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 215 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,
ssize_t  data_len 
)

Definition at line 401 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 373 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 645 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 106 of file base.c.

◆ dhcp_header_attrs_len

size_t dhcp_header_attrs_len
extern

Definition at line 122 of file base.c.

◆ dhcp_header_sizes

int dhcp_header_sizes[]
extern

Definition at line 145 of file base.c.

◆ dhcp_message_types

char const* dhcp_message_types[]
extern

Definition at line 124 of file base.c.

◆ dhcp_option_82

HIDDEN fr_dict_attr_t const* dhcp_option_82
extern

Definition at line 164 of file base.c.

◆ eth_bcast

uint8_t eth_bcast[ETH_ADDR_LEN]
extern

Definition at line 162 of file base.c.