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

Functions to encode DHCP options. More...

#include <freeradius-devel/io/test_point.h>
#include <freeradius-devel/util/dbuff.h>
#include <freeradius-devel/util/proto.h>
#include <freeradius-devel/util/struct.h>
#include <freeradius-devel/util/dns.h>
#include <freeradius-devel/util/encode.h>
#include "dhcpv4.h"
#include "attrs.h"
+ Include dependency graph for encode.c:

Go to the source code of this file.

Macros

#define DHCPV4_OPT_HDR_LEN   (2)
 

Functions

static ssize_t encode_child (fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, unsigned int depth, fr_dcursor_t *cursor, void *encode_ctx)
 
static ssize_t encode_rfc (fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, unsigned int depth, fr_dcursor_t *cursor, void *encode_ctx)
 Write out an RFC option header and option data. More...
 
static int encode_test_ctx (void **out, TALLOC_CTX *ctx)
 
static ssize_t encode_tlv (fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, unsigned int depth, fr_dcursor_t *cursor, void *encode_ctx)
 Write out a TLV header (and any sub TLVs or values) More...
 
static ssize_t encode_value (fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, unsigned int depth, fr_dcursor_t *cursor, void *encode_ctx)
 Write DHCP option value into buffer. More...
 
static ssize_t encode_vsio (fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, unsigned int depth, fr_dcursor_t *cursor, void *encode_ctx)
 
static ssize_t encode_vsio_data (fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, unsigned int depth, fr_dcursor_t *cursor, void *encode_ctx)
 
static ssize_t extend_option (fr_dbuff_t *dbuff, fr_dbuff_marker_t *hdr, size_t len)
 Extend an encoded option in-place. More...
 
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...
 
static ssize_t fr_dhcpv4_encode_proto (UNUSED TALLOC_CTX *ctx, fr_pair_list_t *vps, uint8_t *data, size_t data_len, UNUSED void *proto_ctx)
 

Variables

fr_test_point_pair_encode_t dhcpv4_tp_encode_pair
 
fr_test_point_proto_encode_t dhcpv4_tp_encode_proto
 

Detailed Description

Functions to encode DHCP options.

Id
541edc91f2278b622c5ad1b44db5806b4a42b386

Definition in file encode.c.

Macro Definition Documentation

◆ DHCPV4_OPT_HDR_LEN

#define DHCPV4_OPT_HDR_LEN   (2)

Definition at line 275 of file encode.c.

Function Documentation

◆ encode_child()

static ssize_t encode_child ( fr_dbuff_t dbuff,
fr_da_stack_t da_stack,
unsigned int  depth,
fr_dcursor_t cursor,
void *  encode_ctx 
)
static

Definition at line 358 of file encode.c.

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

◆ encode_rfc()

static ssize_t encode_rfc ( fr_dbuff_t dbuff,
fr_da_stack_t da_stack,
unsigned int  depth,
fr_dcursor_t cursor,
void *  encode_ctx 
)
static

Write out an RFC option header and option data.

Note
May coalesce options with fixed width values
Parameters
[out]dbuffbuffer to write the TLV to.
[in]da_stackDescribing nesting of options.
[in]depthin the da_stack.
[in,out]cursorCurrent attribute we're encoding.
[in]encode_ctxContaining DHCPv4 dictionary.
Returns
  • >0 length of data encoded.
  • 0 if we ran out of space.
  • < 0 on error.

Definition at line 291 of file encode.c.

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

◆ encode_test_ctx()

static int encode_test_ctx ( void **  out,
TALLOC_CTX *  ctx 
)
static

Definition at line 791 of file encode.c.

+ Here is the call graph for this function:

◆ encode_tlv()

static ssize_t encode_tlv ( fr_dbuff_t dbuff,
fr_da_stack_t da_stack,
unsigned int  depth,
fr_dcursor_t cursor,
void *  encode_ctx 
)
static

Write out a TLV header (and any sub TLVs or values)

Parameters
[out]dbuffbuffer to write the TLV to.
[in]da_stackDescribing nesting of options.
[in]depthin the da_stack.
[in,out]cursorCurrent attribute we're encoding.
[in]encode_ctxContaining DHCPv4 dictionary.
Returns
  • >0 length of data encoded.
  • 0 if we ran out of space.
  • < 0 on error.

Definition at line 435 of file encode.c.

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

◆ encode_value()

static ssize_t encode_value ( fr_dbuff_t dbuff,
fr_da_stack_t da_stack,
unsigned int  depth,
fr_dcursor_t cursor,
void *  encode_ctx 
)
static

Write DHCP option value into buffer.

Does not include DHCP option length or number.

Parameters
[out]dbuffbuffer to write the option to.
[in]da_stackDescribing nesting of options.
[in]depthin da_stack.
[in,out]cursorCurrent attribute we're encoding.
[in]encode_ctxContaining DHCPv4 dictionary.
Returns
  • The length of data written, may return 0 for bools < 0 if there's not enough space or option type is unsupported

Definition at line 58 of file encode.c.

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

◆ encode_vsio()

static ssize_t encode_vsio ( fr_dbuff_t dbuff,
fr_da_stack_t da_stack,
unsigned int  depth,
fr_dcursor_t cursor,
void *  encode_ctx 
)
static

Definition at line 603 of file encode.c.

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

◆ encode_vsio_data()

static ssize_t encode_vsio_data ( fr_dbuff_t dbuff,
fr_da_stack_t da_stack,
unsigned int  depth,
fr_dcursor_t cursor,
void *  encode_ctx 
)
static

Definition at line 512 of file encode.c.

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

◆ extend_option()

static ssize_t extend_option ( fr_dbuff_t dbuff,
fr_dbuff_marker_t hdr,
size_t  len 
)
static

Extend an encoded option in-place.

Parameters
[in]dbuffbuffer containing the option
[in]hdrmarker (with dbuff as parent) set to where the option starts
[in]lenlength of the data being written
Returns
  • <0 if we can't extend the option
  • >0 if we can, with hdr set to where the next option should start
Note
The option starts with a two-byte (type, length) header, where the length does not include the two bytes for the header. The starting length may be non-zero, hence its counting towards the header_byte calculation and its inclusion in sublen calculation. (All those following start out empty, hence the initialization of their lengths to zero.)

Definition at line 190 of file encode.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_encode_proto()

static ssize_t fr_dhcpv4_encode_proto ( UNUSED TALLOC_CTX *  ctx,
fr_pair_list_t vps,
uint8_t data,
size_t  data_len,
UNUSED void *  proto_ctx 
)
static

Definition at line 786 of file encode.c.

+ Here is the call graph for this function:

Variable Documentation

◆ dhcpv4_tp_encode_pair

fr_test_point_pair_encode_t dhcpv4_tp_encode_pair
Initial value:
= {
.test_ctx = encode_test_ctx,
.next_encodable = fr_dhcpv4_next_encodable,
}
void * fr_dhcpv4_next_encodable(fr_dlist_head_t *list, void *current, void *uctx)
DHCPV4-specific iterator.
Definition: base.c:294
static int encode_test_ctx(void **out, TALLOC_CTX *ctx)
Definition: encode.c:791
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.
Definition: encode.c:711

Definition at line 808 of file encode.c.

◆ dhcpv4_tp_encode_proto

fr_test_point_proto_encode_t dhcpv4_tp_encode_proto
Initial value:
= {
.test_ctx = encode_test_ctx,
}
static ssize_t fr_dhcpv4_encode_proto(UNUSED TALLOC_CTX *ctx, fr_pair_list_t *vps, uint8_t *data, size_t data_len, UNUSED void *proto_ctx)
Definition: encode.c:786

Definition at line 817 of file encode.c.