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

Functions to encode RADIUS attributes. More...

#include "protocols/radius/radius.h"
#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.
 
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.
 
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.
 
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.
 
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.
 
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
 
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.
 
static int encode_test_ctx (void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict)
 
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.
 
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 + ...
 
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.
 
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.
 
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.
 
static ssize_t fr_radius_encode_proto (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
e4b0151a1d66f63084bea97bed382f1bdf6d275e

Definition in file encode.c.

Macro Definition Documentation

◆ TAG_VALID

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

Definition at line 35 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 627 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 939 of file encode.c.

+ Here is the call 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 889 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 724 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 844 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 1305 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 288 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 49 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 1415 of file encode.c.

+ Here is the call graph for this function:

◆ encode_test_ctx()

static int encode_test_ctx ( void **  out,
TALLOC_CTX *  ctx,
UNUSED fr_dict_t const *  dict 
)
static

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

+ Here is the call 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 101 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 321 of file encode.c.

+ Here is the call 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 1177 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 971 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 1242 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 1104 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 1680 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 1515 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 ( TALLOC_CTX *  ctx,
fr_pair_list_t vps,
uint8_t data,
size_t  data_len,
void *  proto_ctx 
)
static

Definition at line 1731 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 
)
extern

Definition at line 915 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,
}
static int encode_test_ctx(void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict)
Definition encode.c:165
void * fr_radius_next_encodable(fr_dlist_head_t *list, void *to_eval, void *uctx)
Definition base.c:915
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:1515

Definition at line 1783 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(TALLOC_CTX *ctx, fr_pair_list_t *vps, uint8_t *data, size_t data_len, void *proto_ctx)
Definition encode.c:1731

Definition at line 1791 of file encode.c.