All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Typedefs | Functions | Variables
state.c File Reference

Multi-packet state handling. More...

#include <freeradius-devel/radiusd.h>
#include <freeradius-devel/state.h>
#include <freeradius-devel/rad_assert.h>
+ Include dependency graph for state.c:

Go to the source code of this file.

Data Structures

struct  fr_state_tree_t
 
struct  state_entry
 Holds a state value, and associated VALUE_PAIRs and data. More...
 

Macros

#define PTHREAD_MUTEX_LOCK(_x)
 
#define PTHREAD_MUTEX_UNLOCK(_x)
 

Typedefs

typedef struct state_entry fr_state_entry_t
 Holds a state value, and associated VALUE_PAIRs and data. More...
 

Functions

static int _state_entry_free (fr_state_entry_t *entry)
 Frees any data associated with a state. More...
 
static int _state_tree_free (fr_state_tree_t *state)
 Free the state tree. More...
 
bool fr_request_to_state (fr_state_tree_t *state, REQUEST *request, RADIUS_PACKET *original, RADIUS_PACKET *packet)
 Transfer ownership of the state VALUE_PAIRs and ctx, back to a state entry. More...
 
void fr_state_discard (fr_state_tree_t *state, REQUEST *request, RADIUS_PACKET *original)
 Called when sending an Access-Accept/Access-Reject to discard state information. More...
 
uint64_t fr_state_entries_created (fr_state_tree_t *state)
 Return number of entries created. More...
 
uint64_t fr_state_entries_timeout (fr_state_tree_t *state)
 Return number of entries that timed out. More...
 
uint32_t fr_state_entries_tracked (fr_state_tree_t *state)
 Return number of entries we're currently tracking. More...
 
void fr_state_to_request (fr_state_tree_t *state, REQUEST *request, RADIUS_PACKET *packet)
 Copy a pointer to the head of the list of state VALUE_PAIRs (and their ctx) into the request. More...
 
fr_state_tree_tfr_state_tree_init (TALLOC_CTX *ctx, uint32_t max_sessions, uint32_t timeout)
 Initialise a new state tree. More...
 
static int state_entry_cmp (void const *one, void const *two)
 Compare two fr_state_entry_t based on their state value i.e. More...
 
static fr_state_entry_tstate_entry_create (fr_state_tree_t *state, RADIUS_PACKET *packet, fr_state_entry_t *old)
 Create a new state entry. More...
 
static fr_state_entry_tstate_entry_find (fr_state_tree_t *state, RADIUS_PACKET *packet)
 Find the entry, based on the State attribute. More...
 
static void state_entry_unlink (fr_state_tree_t *state, fr_state_entry_t *entry)
 Unlink an entry and remove if from the tree. More...
 

Variables

fr_state_tree_tglobal_state = NULL
 

Detailed Description

Multi-packet state handling.

Id:
2a000258fd4f4d9b1b374adc3229da85eb355c18

For each round of a multi-round authentication method such as EAP, or a 2FA method such as OTP, a state entry will be created. The state entry holds data that should be available during the complete lifecycle of the authentication attempt.

When a request is complete, fr_request_to_state is called to transfer ownership of the state VALUE_PAIRs and state_ctx (which the VALUE_PAIRs are allocated in) to a fr_state_entry_t. This fr_state_entry_t holds the value of the State attribute, that will be send out in the response.

When the next request is received, fr_state_to_request is called to transfer the VALUE_PAIRs and state ctx to the new request.

The ownership of the state_ctx and state VALUE_PAIRs is transferred as below:

  request -> state_entry -> request -> state_entry -> request -> free()
         \-> reply                 \-> reply                 \-> access-reject/access-accept
* 

Definition in file state.c.


Data Structure Documentation

struct fr_state_tree_t

Definition at line 73 of file state.c.

+ Collaboration diagram for fr_state_tree_t:
Data Fields
fr_state_entry_t * head
uint64_t id Next ID to assign.
uint32_t max_sessions Maximum number of sessions we track.
fr_state_entry_t * tail Entries to expire.
uint64_t timed_out Number of states that were cleaned up due to timeout.
uint32_t timeout How long to wait before cleaning up state entires.
rbtree_t * tree rbtree used to lookup state value.
struct state_entry

Holds a state value, and associated VALUE_PAIRs and data.

Definition at line 56 of file state.c.

+ Collaboration diagram for state_entry:
Data Fields
time_t cleanup When this entry should be cleaned up.
TALLOC_CTX * ctx ctx to parent any data that needs to be tied to the lifetime of the request progression.
request_data_t * data Persistable request data, also parented ctx.
uint64_t id State ID for debugging.
struct state_entry * next Next entry in the cleanup list.
struct state_entry * prev Previous entry in the cleanup list.
uint8_t state[AUTH_VECTOR_LEN] State value in binary.
int tries
VALUE_PAIR * vps session-state VALUE_PAIRs, parented by ctx.

Macro Definition Documentation

#define PTHREAD_MUTEX_LOCK (   _x)

Definition at line 96 of file state.c.

#define PTHREAD_MUTEX_UNLOCK (   _x)

Definition at line 97 of file state.c.

Typedef Documentation

typedef struct state_entry fr_state_entry_t

Holds a state value, and associated VALUE_PAIRs and data.

Function Documentation

static int _state_entry_free ( fr_state_entry_t entry)
static

Frees any data associated with a state.

Definition at line 234 of file state.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int _state_tree_free ( fr_state_tree_t state)
static

Free the state tree.

Definition at line 116 of file state.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool fr_request_to_state ( fr_state_tree_t state,
REQUEST request,
RADIUS_PACKET original,
RADIUS_PACKET packet 
)

Transfer ownership of the state VALUE_PAIRs and ctx, back to a state entry.

Put request->state into the State attribute. Put the State attribute into the vps list. Delete the original entry, if it exists

Also creates a new state entry.

Definition at line 579 of file state.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void fr_state_discard ( fr_state_tree_t state,
REQUEST request,
RADIUS_PACKET original 
)

Called when sending an Access-Accept/Access-Reject to discard state information.

Definition at line 487 of file state.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint64_t fr_state_entries_created ( fr_state_tree_t state)

Return number of entries created.

Definition at line 624 of file state.c.

+ Here is the caller graph for this function:

uint64_t fr_state_entries_timeout ( fr_state_tree_t state)

Return number of entries that timed out.

Definition at line 632 of file state.c.

+ Here is the caller graph for this function:

uint32_t fr_state_entries_tracked ( fr_state_tree_t state)

Return number of entries we're currently tracking.

Definition at line 640 of file state.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void fr_state_to_request ( fr_state_tree_t state,
REQUEST request,
RADIUS_PACKET packet 
)

Copy a pointer to the head of the list of state VALUE_PAIRs (and their ctx) into the request.

Note
Does not copy the actual VALUE_PAIRs. The VALUE_PAIRs and their context are transferred between state entries as the conversation progresses.
Called with the mutex free.

Definition at line 523 of file state.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

fr_state_tree_t* fr_state_tree_init ( TALLOC_CTX *  ctx,
uint32_t  max_sessions,
uint32_t  timeout 
)

Initialise a new state tree.

Parameters
ctxto link the lifecycle of the state tree to.
max_sessionswe track state for.
timeoutHow long to wait before cleaning up entries.
Returns
a new state tree or NULL on failure.

Definition at line 156 of file state.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int state_entry_cmp ( void const *  one,
void const *  two 
)
static

Compare two fr_state_entry_t based on their state value i.e.

the value of the attribute

Definition at line 105 of file state.c.

+ Here is the caller graph for this function:

static fr_state_entry_t* state_entry_create ( fr_state_tree_t state,
RADIUS_PACKET packet,
fr_state_entry_t old 
)
static

Create a new state entry.

Note
Called with the mutex held.

Definition at line 273 of file state.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static fr_state_entry_t* state_entry_find ( fr_state_tree_t state,
RADIUS_PACKET packet 
)
static

Find the entry, based on the State attribute.

Definition at line 463 of file state.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void state_entry_unlink ( fr_state_tree_t state,
fr_state_entry_t entry 
)
static

Unlink an entry and remove if from the tree.

Definition at line 201 of file state.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

fr_state_tree_t* global_state = NULL

Definition at line 87 of file state.c.