networkclient
ID allocation and freeing

Data Structures

struct  nr_track_id_t
 

Typedefs

typedef struct nr_track_id_t nr_track_id_t
 

Functions

int nr_track_id_init (nr_track_id_t *s, int code, const char *secret)
 
int nr_track_id_close (const nr_track_id_t *s)
 
int nr_track_id_alloc (nr_track_id_t *s, RADIUS_PACKET *packet)
 
int nr_track_id_realloc (nr_track_id_t *s, RADIUS_PACKET *packet)
 
int nr_track_id_release (nr_track_id_t *s, RADIUS_PACKET *packet)
 
int nr_track_id_packet_alloc (nr_track_id_t *s, RADIUS_PACKET **packet_p, RADIUS_PACKET *original, size_t sizeof_data)
 

Detailed Description

These routines manage RADIUS ID allocation.

Typedef Documentation

typedef struct nr_track_id_t nr_track_id_t

Track packets sent to a server.

This data structure tracks Identifiers which are used to communicate with a particular destination server. The application should call nr_track_id_init() to initialize it. If necessary, the application should then call nr_track_id_set_ipv4() to open an IPv4 socket to the server.

If the RADIUS packets are being transported over an encapsulation layer (e.g. RADIUS over TLS), then nr_track_id_set_ipv4() does not need to be called. The nr_track_id_t structure should instead be associated wih the TLS session / socket.

Function Documentation

int nr_track_id_alloc ( nr_track_id_t s,
RADIUS_PACKET packet 
)

Allocate a RADIUS_PACKET::id value for sending a packet to a server.

This function allocates a RADIUS_PACKET::id from the nr_track_id_t structure. It also fills in the RADIUS_PACKET::sockfd, RADIUS_PACKET::code, and RADIUS_PACKET::dst fields.

Parameters
[in]sThe server structure which tracks the ID
[in]packetThe packet which needs an ID
Returns
<0 for error, 0 for success

References radius_packet::code, nr_track_id_t::code, radius_packet::dst, nr_track_id_t::dst, radius_packet::id, nr_track_id_t::ids, return_NR_ERR, radius_packet::sockfd, nr_track_id_t::sockfd, radius_packet::src, nr_track_id_t::src, and nr_track_id_t::used.

Referenced by main(), and nr_track_id_packet_alloc().

int nr_track_id_close ( const nr_track_id_t s)

Closes an nr_track_id_t data structure.

Ensures that all IDs are free, and closes the socket.

Parameters
[in]sThe server structure to close.
Returns
<0 for error, 0 for success

References return_NR_ERR, nr_track_id_t::sockfd, and nr_track_id_t::used.

Referenced by main().

int nr_track_id_init ( nr_track_id_t s,
int  code,
const char *  secret 
)

Initializes an nr_track_id_t.

This function performs some simple initialization. See nr_track_id_socket() for initialization of the nr_track_id_t::src and nr_track_id_t::dst fields, if needed.

Parameters
[in,out]sThe nr_track_id_t to initialize
[in]codeThe packet code used for packets sent to this server
[in]secretThe shared secret used for packet sent to this server
Returns
<0 for error, >= 0 for success

References nr_track_id_t::code, nr_track_id_t::ctx, nr_track_id_t::dst, NR_MAX_PACKET_CODE, nr_track_id_t::packet_send, PW_ACCOUNTING_REQUEST, return_NR_ERR, nr_track_id_t::secret, nr_track_id_t::sizeof_secret, nr_track_id_t::sockfd, nr_track_id_t::src, and nr_track_id_t::timers.

Referenced by main().

int nr_track_id_packet_alloc ( nr_track_id_t s,
RADIUS_PACKET **  packet_p,
RADIUS_PACKET original,
size_t  sizeof_data 
)

Allocates a packet using malloc(), and initializes it.

It also allocates an ID for the packet.

Parameters
[in]sThe server structure
[in,out]packet_pPointer to the RADIUS_PACKET to be allocated
[in]originalPointer to the original packet (if any)
[in]sizeof_dataMaximum expected size of packet. (0 menans NR_MAX_PACKET_LEN)
Returns
<0 for error, 0 for success

References nr_track_id_t::code, NR_MAX_PACKET_LEN, nr_packet_init(), nr_track_id_alloc(), PW_ACCESS_ACCEPT, PW_ACCESS_REQUEST, PW_ACCOUNTING_REQUEST, PW_ACCOUNTING_RESPONSE, PW_COA_ACK, PW_COA_REQUEST, PW_DISCONNECT_ACK, PW_DISCONNECT_REQUEST, return_NR_ERR, and nr_track_id_t::secret.

Referenced by main().

Here is the call graph for this function:

int nr_track_id_realloc ( nr_track_id_t s,
RADIUS_PACKET packet 
)

Re-allocate a RADIUS_PACKET::id value for sending a packet to a server.

It is used when retransmitting an Accounting-Request packet to a server, after updating the Acct-Delay-Time field. The "realloc" name means that the new ID is allocated, and is different from the old one.

Note that after the ID has been allocated, the nr_packet_sign() function MUST be called in order to update the packet signature.

Parameters
[in]sThe server structure which tracks the ID
[in]packetThe packet which needs a new ID
Returns
<0 for error, 0 for success

References radius_packet::id, nr_track_id_t::ids, and return_NR_ERR.

int nr_track_id_release ( nr_track_id_t s,
RADIUS_PACKET packet 
)

Releases a RADIUS_PACKET::id value after sending a packet to a server.

Parameters
[in]sThe server structure which tracks the ID
[in]packetThe packet which has an ID, and wants to free it
Returns
<0 for error, 0 for success

References radius_packet::id, nr_track_id_t::ids, return_NR_ERR, radius_packet::sockfd, and nr_track_id_t::used.

Referenced by nr_track_id_packet_free().