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

Functions to encode DHCP options. More...

#include <freeradius-devel/io/pair.h>
#include <freeradius-devel/protocol/dhcpv6/freeradius.internal.h>
#include <freeradius-devel/protocol/dhcpv6/rfc3315.h>
#include <freeradius-devel/protocol/dhcpv6/rfc5007.h>
#include <freeradius-devel/util/proto.h>
#include <freeradius-devel/util/rand.h>
#include "dhcpv6.h"
#include "attrs.h"
+ Include dependency graph for base.c:

Go to the source code of this file.

Functions

static bool attr_valid (UNUSED fr_dict_t *dict, UNUSED fr_dict_attr_t const *parent, UNUSED char const *name, UNUSED int attr, fr_type_t type, fr_dict_attr_flags_t *flags)
 
static void dhcpv6_print_hex (FILE *fp, uint8_t const *packet, size_t packet_len, int depth)
 
static bool duid_match (uint8_t const *option, fr_dhcpv6_decode_ctx_t const *packet_ctx)
 
ssize_t fr_dhcpv6_decode (TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *packet, size_t packet_len)
 Decode a DHCPv6 packet. More...
 
ssize_t fr_dhcpv6_encode (fr_dbuff_t *dbuff, uint8_t const *original, size_t length, int msg_type, fr_pair_list_t *vps)
 Encode a DHCPv6 packet. More...
 
void fr_dhcpv6_global_free (void)
 
int fr_dhcpv6_global_init (void)
 
void * fr_dhcpv6_next_encodable (fr_dlist_head_t *list, void *current, void *uctx)
 DHCPV6-specific iterator. More...
 
bool fr_dhcpv6_ok (uint8_t const *packet, size_t packet_len, uint32_t max_attributes)
 See if the data pointed to by PTR is a valid DHCPv6 packet. More...
 
static ssize_t fr_dhcpv6_ok_internal (uint8_t const *packet, uint8_t const *end, size_t max_attributes, int depth)
 
uint8_t const * fr_dhcpv6_option_find (uint8_t const *start, uint8_t const *end, unsigned int option)
 
static ssize_t fr_dhcpv6_options_ok (uint8_t const *packet, uint8_t const *end, size_t max_attributes, bool allow_relay, int depth)
 
void fr_dhcpv6_print_hex (FILE *fp, uint8_t const *packet, size_t packet_len)
 Print a raw DHCP packet as hex. More...
 
bool fr_dhcpv6_verify (uint8_t const *packet, size_t packet_len, fr_dhcpv6_decode_ctx_t const *packet_ctx, bool from_server)
 Verify the packet under some various circumstances. More...
 
static void print_hex_data (FILE *fp, uint8_t const *ptr, int attrlen, int depth)
 
static bool verify_from_client (uint8_t const *packet, size_t packet_len, fr_dhcpv6_decode_ctx_t const *packet_ctx)
 Verify a packet from a client to a server. More...
 
static bool verify_to_client (uint8_t const *packet, size_t packet_len, fr_dhcpv6_decode_ctx_t const *packet_ctx)
 Verify a reply packet from a server to a client. More...
 

Variables

fr_dict_attr_t const * attr_hop_count
 
fr_dict_attr_t const * attr_option_request
 
fr_dict_attr_t const * attr_packet_type
 
fr_dict_attr_t const * attr_relay_link_address
 
fr_dict_attr_t const * attr_relay_message
 
fr_dict_attr_t const * attr_relay_peer_address
 
fr_dict_attr_t const * attr_transaction_id
 
fr_dict_t const * dict_dhcpv6
 
char const * fr_dhcpv6_packet_names [FR_DHCPV6_CODE_MAX]
 
static uint32_t instance_count = 0
 
fr_dict_autoload_t libfreeradius_dhcpv6_dict []
 
fr_dict_attr_autoload_t libfreeradius_dhcpv6_dict_attr []
 
fr_dict_protocol_t libfreeradius_dhcpv6_dict_protocol
 
static fr_table_num_ordered_t const subtype_table []
 
static char const tabs [] = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"
 

Detailed Description

Functions to encode DHCP options.

Id
35cc68562350bc12e6c8860fd41b57a61cbeb98d
Author
Arran Cudbard-Bell (a.cud.nosp@m.bard.nosp@m.b@fre.nosp@m.erad.nosp@m.ius.o.nosp@m.rg)

Definition in file base.c.

Function Documentation

◆ attr_valid()

static bool attr_valid ( UNUSED fr_dict_t dict,
UNUSED fr_dict_attr_t const *  parent,
UNUSED char const *  name,
UNUSED int  attr,
fr_type_t  type,
fr_dict_attr_flags_t flags 
)
static

Definition at line 947 of file base.c.

◆ dhcpv6_print_hex()

static void dhcpv6_print_hex ( FILE *  fp,
uint8_t const *  packet,
size_t  packet_len,
int  depth 
)
static

Definition at line 812 of file base.c.

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

◆ duid_match()

static bool duid_match ( uint8_t const *  option,
fr_dhcpv6_decode_ctx_t const *  packet_ctx 
)
static

Definition at line 266 of file base.c.

+ Here is the caller graph for this function:

◆ fr_dhcpv6_decode()

ssize_t fr_dhcpv6_decode ( TALLOC_CTX *  ctx,
fr_pair_list_t out,
uint8_t const *  packet,
size_t  packet_len 
)

Decode a DHCPv6 packet.

Definition at line 578 of file base.c.

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

◆ fr_dhcpv6_encode()

ssize_t fr_dhcpv6_encode ( fr_dbuff_t dbuff,
uint8_t const *  original,
size_t  length,
int  msg_type,
fr_pair_list_t vps 
)

Encode a DHCPv6 packet.

Definition at line 717 of file base.c.

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

◆ fr_dhcpv6_global_free()

void fr_dhcpv6_global_free ( void  )

Definition at line 938 of file base.c.

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

◆ fr_dhcpv6_global_init()

int fr_dhcpv6_global_init ( void  )

Definition at line 896 of file base.c.

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

◆ fr_dhcpv6_next_encodable()

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

DHCPV6-specific iterator.

Definition at line 698 of file base.c.

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

◆ fr_dhcpv6_ok()

bool fr_dhcpv6_ok ( uint8_t const *  packet,
size_t  packet_len,
uint32_t  max_attributes 
)

See if the data pointed to by PTR is a valid DHCPv6 packet.

Parameters
[in]packetto check.
[in]packet_lenThe size of the packet data.
[in]max_attributesto allow in the packet.
Returns
  • True on success.
  • False on failure.

Definition at line 227 of file base.c.

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

◆ fr_dhcpv6_ok_internal()

static ssize_t fr_dhcpv6_ok_internal ( uint8_t const *  packet,
uint8_t const *  end,
size_t  max_attributes,
int  depth 
)
static

Definition at line 168 of file base.c.

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

◆ fr_dhcpv6_option_find()

uint8_t const* fr_dhcpv6_option_find ( uint8_t const *  start,
uint8_t const *  end,
unsigned int  option 
)

Definition at line 243 of file base.c.

+ Here is the caller graph for this function:

◆ fr_dhcpv6_options_ok()

static ssize_t fr_dhcpv6_options_ok ( uint8_t const *  packet,
uint8_t const *  end,
size_t  max_attributes,
bool  allow_relay,
int  depth 
)
static

Definition at line 117 of file base.c.

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

◆ fr_dhcpv6_print_hex()

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

Print a raw DHCP packet as hex.

Definition at line 891 of file base.c.

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

◆ fr_dhcpv6_verify()

bool fr_dhcpv6_verify ( uint8_t const *  packet,
size_t  packet_len,
fr_dhcpv6_decode_ctx_t const *  packet_ctx,
bool  from_server 
)

Verify the packet under some various circumstances.

Parameters
[in]packetto check.
[in]packet_lenThe size of the packet data.
[in]packet_ctxThe expected packet_ctx
[in]from_servertrue for packets from a server, false for packets from a client.
Returns
  • True on success.
  • False on failure.

fr_dhcpv6_ok() SHOULD be called before calling this function.

Definition at line 544 of file base.c.

+ Here is the call 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 799 of file base.c.

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

◆ verify_from_client()

static bool verify_from_client ( uint8_t const *  packet,
size_t  packet_len,
fr_dhcpv6_decode_ctx_t const *  packet_ctx 
)
static

Verify a packet from a client to a server.

Definition at line 420 of file base.c.

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

◆ verify_to_client()

static bool verify_to_client ( uint8_t const *  packet,
size_t  packet_len,
fr_dhcpv6_decode_ctx_t const *  packet_ctx 
)
static

Verify a reply packet from a server to a client.

Definition at line 280 of file base.c.

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

Variable Documentation

◆ attr_hop_count

fr_dict_attr_t const* attr_hop_count

Definition at line 50 of file base.c.

◆ attr_option_request

fr_dict_attr_t const* attr_option_request

Definition at line 54 of file base.c.

◆ attr_packet_type

fr_dict_attr_t const* attr_packet_type

Definition at line 48 of file base.c.

◆ attr_relay_link_address

fr_dict_attr_t const* attr_relay_link_address

Definition at line 51 of file base.c.

◆ attr_relay_message

fr_dict_attr_t const* attr_relay_message

Definition at line 53 of file base.c.

◆ attr_relay_peer_address

fr_dict_attr_t const* attr_relay_peer_address

Definition at line 52 of file base.c.

◆ attr_transaction_id

fr_dict_attr_t const* attr_transaction_id

Definition at line 49 of file base.c.

◆ dict_dhcpv6

fr_dict_t const* dict_dhcpv6

Definition at line 40 of file base.c.

◆ fr_dhcpv6_packet_names

char const* fr_dhcpv6_packet_names[FR_DHCPV6_CODE_MAX]

Definition at line 71 of file base.c.

◆ instance_count

uint32_t instance_count = 0
static

Definition at line 38 of file base.c.

◆ libfreeradius_dhcpv6_dict

fr_dict_autoload_t libfreeradius_dhcpv6_dict
Initial value:
= {
{ .out = &dict_dhcpv6, .proto = "dhcpv6" },
{ NULL }
}
fr_dict_t const * dict_dhcpv6
Definition: base.c:40

Definition at line 43 of file base.c.

◆ libfreeradius_dhcpv6_dict_attr

fr_dict_attr_autoload_t libfreeradius_dhcpv6_dict_attr
Initial value:
= {
{ .out = &attr_packet_type, .name = "Packet-Type", .type = FR_TYPE_UINT32, .dict = &dict_dhcpv6 },
{ .out = &attr_transaction_id, .name = "Transaction-Id", .type = FR_TYPE_OCTETS, .dict = &dict_dhcpv6 },
{ .out = &attr_hop_count, .name = "Hop-Count", .type = FR_TYPE_UINT8, .dict = &dict_dhcpv6 },
{ .out = &attr_relay_link_address, .name = "Relay-Link-Address", .type = FR_TYPE_IPV6_ADDR, .dict = &dict_dhcpv6 },
{ .out = &attr_relay_peer_address, .name = "Relay-Peer-Address", .type = FR_TYPE_IPV6_ADDR, .dict = &dict_dhcpv6 },
{ .out = &attr_relay_message, .name = "Relay-Message", .type = FR_TYPE_GROUP, .dict = &dict_dhcpv6 },
{ .out = &attr_option_request, .name = "Option-Request", .type = FR_TYPE_UINT16, .dict = &dict_dhcpv6 },
{ NULL }
}
@ FR_TYPE_UINT16
16 Bit unsigned integer.
Definition: merged_model.c:98
@ FR_TYPE_UINT8
8 Bit unsigned integer.
Definition: merged_model.c:97
@ FR_TYPE_UINT32
32 Bit unsigned integer.
Definition: merged_model.c:99
@ FR_TYPE_IPV6_ADDR
128 Bit IPv6 Address.
Definition: merged_model.c:88
@ FR_TYPE_OCTETS
Raw octets.
Definition: merged_model.c:84
@ FR_TYPE_GROUP
A grouping of other attributes.
Definition: merged_model.c:124
fr_dict_attr_t const * attr_packet_type
Definition: base.c:50
fr_dict_attr_t const * attr_option_request
Definition: base.c:54
fr_dict_attr_t const * attr_hop_count
Definition: base.c:50
fr_dict_attr_t const * attr_relay_link_address
Definition: base.c:51
fr_dict_attr_t const * attr_relay_message
Definition: base.c:53
fr_dict_attr_t const * attr_transaction_id
Definition: base.c:49
fr_dict_attr_t const * attr_relay_peer_address
Definition: base.c:52

Definition at line 57 of file base.c.

◆ libfreeradius_dhcpv6_dict_protocol

fr_dict_protocol_t libfreeradius_dhcpv6_dict_protocol
Initial value:
= {
.name = "dhcpv6",
.default_type_size = 2,
.default_type_length = 2,
.subtype_table = subtype_table,
.subtype_table_len = NUM_ELEMENTS(subtype_table),
.attr_valid = attr_valid,
}
#define NUM_ELEMENTS(_t)
Definition: build.h:335
ssize_t fr_dhcpv6_encode_foreign(fr_dbuff_t *dbuff, fr_pair_list_t const *list)
Definition: encode.c:721
void fr_dhcpv6_global_free(void)
Definition: base.c:938
int fr_dhcpv6_global_init(void)
Definition: base.c:896
static bool attr_valid(UNUSED fr_dict_t *dict, UNUSED fr_dict_attr_t const *parent, UNUSED char const *name, UNUSED int attr, fr_type_t type, fr_dict_attr_flags_t *flags)
Definition: base.c:947
static fr_table_num_ordered_t const subtype_table[]
Definition: base.c:110
ssize_t fr_dhcpv6_decode_foreign(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, size_t data_len)
Definition: decode.c:436

Definition at line 985 of file base.c.

◆ subtype_table

fr_table_num_ordered_t const subtype_table[]
static
Initial value:
= {
{ L("dns_label"), FLAG_ENCODE_DNS_LABEL },
{ L("partial_dns_label"), FLAG_ENCODE_PARTIAL_DNS_LABEL }
}
#define L(_str)
Helper for initialising arrays of string literals.
Definition: build.h:207
@ FLAG_ENCODE_DNS_LABEL
encode as DNS label
Definition: dhcpv4.h:71
@ FLAG_ENCODE_PARTIAL_DNS_LABEL
encode as a partial DNS label
Definition: dhcpv6.h:117

Definition at line 110 of file base.c.

◆ tabs

char const tabs[] = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"
static

Definition at line 797 of file base.c.