#include <freeradius-devel/libradius.h>
#include <freeradius-devel/udpfromto.h>
#include <freeradius-devel/dhcp.h>
#include <freeradius-devel/net.h>
#include <freeradius-devel/pcap.h>
#include <sys/ioctl.h>
#include <net/if_arp.h>
Go to the source code of this file.
Data Structures | |
struct | dhcp_option_t |
struct | dhcp_packet_t |
Macros | |
#define | DEBUG if (fr_debug_lvl && fr_log_fp) fr_printf_log |
#define | DEFAULT_PACKET_SIZE (300) |
#define | DHCP_CHADDR_LEN (16) |
#define | DHCP_FILE_FIELD (1) |
#define | DHCP_FILE_LEN (128) |
#define | DHCP_MAX_MESSAGE_TYPE (sizeof(dhcp_message_types) / sizeof(dhcp_message_types[0])) |
#define | DHCP_OPTION_FIELD (0) |
#define | DHCP_OPTION_MAGIC_NUMBER (0x63825363) |
#define | DHCP_SNAME_FIELD (2) |
#define | DHCP_SNAME_LEN (64) |
#define | DHCP_VEND_LEN (308) |
#define | INADDR_BROADCAST INADDR_NONE |
#define | MAX_PACKET_SIZE (1500 - 40) |
#define | MIN_PACKET_SIZE (244) |
Typedefs | |
typedef struct dhcp_option_t | dhcp_option_t |
typedef struct dhcp_packet_t | dhcp_packet_t |
Functions | |
static ssize_t | decode_tlv (TALLOC_CTX *ctx, vp_cursor_t *cursor, fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len) |
RFC 4243 Vendor Specific Suboptions. More... | |
static ssize_t | decode_value (TALLOC_CTX *ctx, vp_cursor_t *cursor, fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len) |
static ssize_t | decode_value_internal (TALLOC_CTX *ctx, vp_cursor_t *cursor, fr_dict_attr_t const *da, uint8_t const *data, size_t data_len) |
static uint8_t const * | dhcp_get_option (dhcp_packet_t const *packet, size_t packet_size, unsigned int option) |
static ssize_t | encode_rfc_hdr (uint8_t *out, ssize_t outlen, fr_dict_attr_t const **tlv_stack, unsigned int depth, vp_cursor_t *cursor) |
Write out an RFC option header and option data. More... | |
static ssize_t | encode_tlv_hdr (uint8_t *out, ssize_t outlen, fr_dict_attr_t const **tlv_stack, unsigned int depth, vp_cursor_t *cursor) |
Write out a TLV header (and any sub TLVs or values) More... | |
static ssize_t | encode_value (uint8_t *out, size_t outlen, fr_dict_attr_t const **tlv_stack, unsigned int depth, vp_cursor_t *cursor) |
Write DHCP option value into buffer. More... | |
int | fr_dhcp_add_arp_entry (UNUSED int fd, UNUSED char const *interface, UNUSED VALUE_PAIR *macaddr, UNUSED VALUE_PAIR *ip) |
static int | fr_dhcp_array_members (size_t *out, size_t len, fr_dict_attr_t const *da) |
Returns the number of array members for arrays with fixed element sizes. More... | |
int8_t | fr_dhcp_attr_cmp (void const *a, void const *b) |
int | fr_dhcp_decode (RADIUS_PACKET *packet) |
ssize_t | fr_dhcp_decode_option (TALLOC_CTX *ctx, vp_cursor_t *cursor, fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len, UNUSED void *decoder_ctx) |
Decode DHCP option. More... | |
int | fr_dhcp_encode (RADIUS_PACKET *packet) |
ssize_t | fr_dhcp_encode_option (uint8_t *out, size_t outlen, vp_cursor_t *cursor, UNUSED void *encoder_ctx) |
Encode a DHCP option and any sub-options. More... | |
static RADIUS_PACKET * | fr_dhcp_packet_ok (uint8_t const *data, ssize_t data_len, fr_ipaddr_t src_ipaddr, uint16_t src_port, fr_ipaddr_t dst_ipaddr, uint16_t dst_port) |
Check reveived DHCP request is valid and build RADIUS_PACKET structure if it is. More... | |
RADIUS_PACKET * | fr_dhcp_recv_socket (int sockfd) |
Receive DHCP packet using socket. More... | |
int | fr_dhcp_send_socket (RADIUS_PACKET *packet) |
Send DHCP packet using socket. More... | |
Variables | |
char const * | dhcp_header_names [] |
static int | dhcp_header_sizes [] |
char const * | dhcp_message_types [] |
struct dhcp_packet_t |
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 |
#define DEBUG if (fr_debug_lvl && fr_log_fp) fr_printf_log |
#define DHCP_MAX_MESSAGE_TYPE (sizeof(dhcp_message_types) / sizeof(dhcp_message_types[0])) |
typedef struct dhcp_option_t dhcp_option_t |
typedef struct dhcp_packet_t dhcp_packet_t |
|
static |
RFC 4243 Vendor Specific Suboptions.
Vendor specific suboptions are in the format.
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Enterprise Number 0 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Len 0 | / +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ / Suboption Data 0 / +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Enterprise Number n | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Len n | / +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ / Suboption Data n / +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
So although the vendor is identified, the format of the data isn't specified so we can't actually resolve the suboption to an attribute. For now, we just convert it to an attribute of DHCP-Vendor-Specific-Information with raw octets contents. Decode DHCP suboptions
[in] | ctx | context to alloc new attributes in. |
[in,out] | cursor | Where to write the decoded options. |
[in] | parent | of sub TLVs. |
[in] | data | to parse. |
[in] | data_len | of data parsed. |
Definition at line 895 of file dhcp.c.
|
static |
|
static |
|
static |
|
static |
Write out an RFC option header and option data.
[in,out] | out | buffer to write the TLV to. |
[out] | outlen | length of the output buffer. |
[in] | tlv_stack | Describing nesting of options. |
[in] | depth | in the tlv_stack. |
[in,out] | cursor | Current attribute we're encoding. |
Definition at line 1431 of file dhcp.c.
|
static |
Write out a TLV header (and any sub TLVs or values)
[in,out] | out | buffer to write the TLV to. |
[out] | outlen | length of the output buffer. |
[in] | tlv_stack | Describing nesting of options. |
[in] | depth | in the tlv_stack. |
[in,out] | cursor | Current attribute we're encoding. |
Definition at line 1503 of file dhcp.c.
|
static |
Write DHCP option value into buffer.
Does not include DHCP option length or number.
[in,out] | out | buffer to write the option to. |
[out] | outlen | length of the output buffer. |
[in] | tlv_stack | Describing nesting of options. |
[in] | depth | in tlv_stack. |
[in,out] | cursor | Current attribute we're encoding. |
Definition at line 1346 of file dhcp.c.
int fr_dhcp_add_arp_entry | ( | UNUSED int | fd, |
UNUSED char const * | interface, | ||
UNUSED VALUE_PAIR * | macaddr, | ||
UNUSED VALUE_PAIR * | ip | ||
) |
|
static |
int8_t fr_dhcp_attr_cmp | ( | void const * | a, |
void const * | b | ||
) |
int fr_dhcp_decode | ( | RADIUS_PACKET * | packet | ) |
ssize_t fr_dhcp_decode_option | ( | TALLOC_CTX * | ctx, |
vp_cursor_t * | cursor, | ||
fr_dict_attr_t const * | parent, | ||
uint8_t const * | data, | ||
size_t | data_len, | ||
UNUSED void * | decoder_ctx | ||
) |
Decode DHCP option.
[in] | ctx | context to alloc new attributes in. |
[in,out] | cursor | Where to write the decoded options. |
[in] | parent | The root of the protocol dictionary used to decode DHCP attributes. |
[in] | data | to parse. |
[in] | data_len | of data to parse. |
[in] | decoder_ctx | Unused. |
Definition at line 1031 of file dhcp.c.
int fr_dhcp_encode | ( | RADIUS_PACKET * | packet | ) |
ssize_t fr_dhcp_encode_option | ( | uint8_t * | out, |
size_t | outlen, | ||
vp_cursor_t * | cursor, | ||
UNUSED void * | encoder_ctx | ||
) |
Encode a DHCP option and any sub-options.
out | Where to write encoded DHCP attributes. |
outlen | Length of out buffer. |
cursor | with current VP set to the option to be encoded. Will be advanced to the next option to encode. |
encoder_ctx | Unused. |
Definition at line 1578 of file dhcp.c.
|
static |
Check reveived DHCP request is valid and build RADIUS_PACKET structure if it is.
data | pointer to received packet. |
data_len | length of received data. |
src_ipaddr | source ip address. |
src_port | source port address. |
dst_ipaddr | destination ip address. |
dst_port | destination port address. |
Definition at line 338 of file dhcp.c.
RADIUS_PACKET* fr_dhcp_recv_socket | ( | int | sockfd | ) |
int fr_dhcp_send_socket | ( | RADIUS_PACKET * | packet | ) |
char const* dhcp_header_names[] |
|
static |
char const* dhcp_message_types[] |