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

Functions to encode RADIUS attributes. More...

#include <freeradius-devel/util/dbuff.h>
#include <freeradius-devel/util/md5.h>
#include <freeradius-devel/util/struct.h>
#include <freeradius-devel/io/test_point.h>
#include <freeradius-devel/protocol/radius/freeradius.internal.h>
#include "attrs.h"
+ Include dependency graph for encode.c:

Go to the source code of this file.

Macros

#define TAG_VALID(x)   ((x) > 0 && (x) < 0x20)
 

Functions

static ssize_t attr_fragment (fr_dbuff_t *data, size_t data_len, fr_dbuff_marker_t *hdr, size_t hdr_len, int flag_offset, int vsa_offset)
 Breaks down large data into pieces, each with a header. More...
 
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)
 Encode an RFC format attribute. More...
 
static ssize_t encode_concat (fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, unsigned int depth, fr_dcursor_t *cursor, UNUSED void *encode_ctx)
 Encode an RFC format attribute, with the "concat" flag set. More...
 
static ssize_t encode_extended (fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, NDEBUG_UNUSED unsigned int depth, fr_dcursor_t *cursor, void *encode_ctx)
 Encode an "extended" attribute. More...
 
static ssize_t encode_extended_nested (fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, unsigned int depth, fr_dcursor_t *cursor, void *encode_ctx)
 
static ssize_t encode_nas_filter_rule (fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, NDEBUG_UNUSED unsigned int depth, fr_dcursor_t *cursor, UNUSED void *encode_ctx)
 Encode NAS-Filter-Rule. More...
 
static ssize_t encode_pairs (fr_dbuff_t *dbuff, fr_pair_list_t const *vps, void *encode_ctx)
 
static ssize_t encode_password (fr_dbuff_t *dbuff, fr_dbuff_marker_t *input, size_t inlen, fr_radius_encode_ctx_t *packet_ctx)
 "encrypt" a password RADIUS style More...
 
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)
 Encode an RFC standard attribute 1..255. 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)
 
static ssize_t encode_tunnel_password (fr_dbuff_t *dbuff, fr_dbuff_marker_t *in, size_t inlen, fr_radius_encode_ctx_t *packet_ctx)
 
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)
 Encodes the data portion of an attribute. More...
 
static ssize_t encode_vendor (fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, unsigned int depth, fr_dcursor_t *cursor, void *encode_ctx)
 
static ssize_t encode_vendor_attr (fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, unsigned int depth, fr_dcursor_t *cursor, void *encode_ctx)
 Encode one full Vendor-Specific + Vendor-ID + Vendor-Attr + Vendor-Length + ... More...
 
static ssize_t encode_vsa (fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, unsigned int depth, fr_dcursor_t *cursor, void *encode_ctx)
 Encode a Vendor-Specific attribute. More...
 
static ssize_t encode_wimax (fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, unsigned int depth, fr_dcursor_t *cursor, void *encode_ctx)
 Encode a WiMAX attribute. More...
 
ssize_t fr_radius_encode_foreign (fr_dbuff_t *dbuff, fr_pair_list_t const *list)
 
ssize_t fr_radius_encode_pair (fr_dbuff_t *dbuff, fr_dcursor_t *cursor, void *encode_ctx)
 Encode a data structure into a RADIUS attribute. More...
 
static ssize_t fr_radius_encode_proto (UNUSED TALLOC_CTX *ctx, fr_pair_list_t *vps, uint8_t *data, size_t data_len, void *proto_ctx)
 
void * fr_radius_next_encodable (fr_dlist_head_t *list, void *to_eval, void *uctx)
 

Variables

fr_test_point_pair_encode_t radius_tp_encode_pair
 
fr_test_point_proto_encode_t radius_tp_encode_proto
 

Detailed Description

Functions to encode RADIUS attributes.

Id
cb75f7569be13742e2a7b31f9c06603f4d516703

Definition in file encode.c.

Macro Definition Documentation

◆ TAG_VALID

#define TAG_VALID (   x)    ((x) > 0 && (x) < 0x20)

Definition at line 34 of file encode.c.

Function Documentation

◆ attr_fragment()

static ssize_t attr_fragment ( fr_dbuff_t data,
size_t  data_len,
fr_dbuff_marker_t hdr,
size_t  hdr_len,
int  flag_offset,
int  vsa_offset 
)
static

Breaks down large data into pieces, each with a header.

Parameters
[out]datawe're fragmenting.
[in]data_lenthe amount of data in the dbuff that makes up the value we're splitting.
[in,out]hdrmarker that points at said header
[in]hdr_lenlength of the headers that will be added
[in]flag_offsetoffset within header of a flag byte whose MSB is set for all but the last piece.
[in]vsa_offsetif non-zero, the offset of a length field in a (sub?)-header of size 3 that also needs to be adjusted to include the number of bytes of data in the piece
Returns
  • <0 the number of bytes we would have needed to create space for another attribute header in the buffer.
  • 0 data was not modified.
  • >0 the number additional bytes we used inserting extra headers.

Definition at line 615 of file encode.c.

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

◆ 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

Encode an RFC format attribute.

This could be a standard attribute, or a TLV data type. If it's a standard attribute, then vp->da->attr == attribute. Otherwise, attribute may be something else.

Definition at line 927 of file encode.c.

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

◆ encode_concat()

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

Encode an RFC format attribute, with the "concat" flag set.

If there isn't enough freespace in the packet, the data is truncated to fit.

The attribute is split on 253 byte boundaries, with a header prepended to each chunk.

Definition at line 877 of file encode.c.

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

◆ encode_extended()

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

Encode an "extended" attribute.

Definition at line 712 of file encode.c.

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

◆ encode_extended_nested()

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

Definition at line 832 of file encode.c.

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

◆ encode_nas_filter_rule()

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

Encode NAS-Filter-Rule.

Concatenating the string attributes together, separated by a 0x00 byte,

Definition at line 1293 of file encode.c.

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

◆ encode_pairs()

static ssize_t encode_pairs ( fr_dbuff_t dbuff,
fr_pair_list_t const *  vps,
void *  encode_ctx 
)
static

Definition at line 287 of file encode.c.

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

◆ encode_password()

static ssize_t encode_password ( fr_dbuff_t dbuff,
fr_dbuff_marker_t input,
size_t  inlen,
fr_radius_encode_ctx_t packet_ctx 
)
static

"encrypt" a password RADIUS style

Input and output buffers can be identical if in-place encryption is needed.

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

Encode an RFC standard attribute 1..255.

This function is not the same as encode_child(), because this one treats some "top level" attributes as special. e.g. Message-Authenticator.

Definition at line 1403 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 1683 of file encode.c.

◆ 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

Definition at line 224 of file encode.c.

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

◆ encode_tunnel_password()

static ssize_t encode_tunnel_password ( fr_dbuff_t dbuff,
fr_dbuff_marker_t in,
size_t  inlen,
fr_radius_encode_ctx_t packet_ctx 
)
static

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

Encodes the data portion of an attribute.

Returns
> 0, Length of the data portion. = 0, we could not encode anything, skip this attribute (and don't encode the header) unless it's one of a list of exceptions. < 0, How many additional bytes we'd need as a negative integer. PAIR_ENCODE_FATAL_ERROR - Abort encoding the packet.

Definition at line 320 of file encode.c.

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

◆ encode_vendor()

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

Definition at line 1165 of file encode.c.

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

◆ encode_vendor_attr()

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

Encode one full Vendor-Specific + Vendor-ID + Vendor-Attr + Vendor-Length + ...

Definition at line 959 of file encode.c.

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

◆ encode_vsa()

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

Encode a Vendor-Specific attribute.

Definition at line 1230 of file encode.c.

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

◆ encode_wimax()

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

Encode a WiMAX attribute.

Definition at line 1092 of file encode.c.

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

◆ fr_radius_encode_foreign()

ssize_t fr_radius_encode_foreign ( fr_dbuff_t dbuff,
fr_pair_list_t const *  list 
)

Definition at line 1663 of file encode.c.

+ Here is the call graph for this function:

◆ fr_radius_encode_pair()

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

Encode a data structure into a RADIUS attribute.

This is the main entry point into the encoder. It sets up the encoder array we use for tracking our TLV/VSA nesting and then calls the appropriate dispatch function.

Parameters
[out]dbuffWhere to write encoded data.
[in]cursorSpecifying attribute to encode.
[in]encode_ctxAdditional data such as the shared secret to use.
Returns
  • >0 The number of bytes written to out.
  • 0 Nothing to encode (or attribute skipped).
  • <0 an error occurred.

Definition at line 1498 of file encode.c.

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

◆ fr_radius_encode_proto()

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

Definition at line 1708 of file encode.c.

+ Here is the call graph for this function:

◆ fr_radius_next_encodable()

void* fr_radius_next_encodable ( fr_dlist_head_t list,
void *  to_eval,
void *  uctx 
)

Definition at line 840 of file base.c.

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

Variable Documentation

◆ radius_tp_encode_pair

fr_test_point_pair_encode_t radius_tp_encode_pair
Initial value:
= {
.test_ctx = encode_test_ctx,
.next_encodable = fr_radius_next_encodable,
}
void * fr_radius_next_encodable(fr_dlist_head_t *list, void *to_eval, void *uctx)
Definition: base.c:840
ssize_t fr_radius_encode_pair(fr_dbuff_t *dbuff, fr_dcursor_t *cursor, void *encode_ctx)
Encode a data structure into a RADIUS attribute.
Definition: encode.c:1498
static int encode_test_ctx(void **out, TALLOC_CTX *ctx)
Definition: encode.c:1683

Definition at line 1755 of file encode.c.

◆ radius_tp_encode_proto

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

Definition at line 1763 of file encode.c.