networkclient
packet.c File Reference

Encoding and decoding packets. More...

#include <networkradius-devel/client.h>
Include dependency graph for packet.c:

Macros

#define _allow(_x)   (((uint64_t) 1) << _x)
 
#define append_ma(_x)   (0)
 

Functions

int nr_packet_ok_raw (const uint8_t *data, size_t sizeof_data)
 
int nr_packet_ok (RADIUS_PACKET *packet)
 
int nr_packet_verify (RADIUS_PACKET *packet, const RADIUS_PACKET *original)
 
int nr_packet_decode (RADIUS_PACKET *packet, const RADIUS_PACKET *original)
 
int nr_packet_sign (RADIUS_PACKET *packet, const RADIUS_PACKET *original)
 
int nr_packet_can_encode (RADIUS_PACKET *packet, const RADIUS_PACKET *original)
 
ssize_t nr_packet_encode (RADIUS_PACKET *packet, const RADIUS_PACKET *original)
 
int nr_packet_walk (RADIUS_PACKET *packet, void *ctx, nr_packet_walk_func_t callback)
 
int nr_packet_init (RADIUS_PACKET *packet, const RADIUS_PACKET *original, const char *secret, int code, void *data, size_t sizeof_data)
 
ssize_t nr_packet_attr_append (RADIUS_PACKET *packet, const RADIUS_PACKET *original, const DICT_ATTR *da, const void *data, size_t data_len)
 
ssize_t nr_packet_vps_append (RADIUS_PACKET *packet, const RADIUS_PACKET *original, const VALUE_PAIR *vps)
 
int nr_packet_response_ok (RADIUS_PACKET const *packet, RADIUS_PACKET const *response)
 

Variables

const char * nr_packet_codes [NR_MAX_PACKET_CODE+1]
 

Detailed Description

Encoding and decoding packets.

Macro Definition Documentation

#define _allow (   _x)    (((uint64_t) 1) << _x)
#define append_ma (   _x)    (0)

Referenced by nr_packet_encode().

Function Documentation

ssize_t nr_packet_attr_append ( RADIUS_PACKET packet,
const RADIUS_PACKET original,
const DICT_ATTR da,
const void *  data,
size_t  data_len 
)

Add one attribute to the packet.

This function can be used to add "raw" data to a packet. It allows the caller to extend the RADIUS packet without using a VALUE_PAIR data structure.

Some attributes are handled specially by this function.

EAP-Message. This attribute is automatically split into 253-octet chunks.

User-Password, CHAP-Password, and Message-Authenticator. These attributes are automatically encrypted, as is done by nr_packet_encode().

Parameters
[in]packetThe packet to edit
[in]originalThe original request (if any)
[in]daPointer to the attribute definition
[in]dataData to append to the packet
[in]data_lenLength of data to append to the packet
Returns
<0 for error, >= 0 for "successfully appended data" The function returns the number of octets appended to the packet.

References nr_dict_attr::attr, radius_packet::data, nr_dict_attr::flags, radius_packet::flags, attr_flags::length, radius_packet::length, NR_PACKET_ENCODED, NR_TYPE_STRING, nr_vp2attr(), nr_vp_init(), nr_vp_set_data(), PW_EAP_MESSAGE, return_NR_ERR, radius_packet::sizeof_data, nr_dict_attr::type, and nr_dict_attr::vendor.

Referenced by main().

Here is the call graph for this function:

int nr_packet_init ( RADIUS_PACKET packet,
const RADIUS_PACKET original,
const char *  secret,
int  code,
void *  data,
size_t  sizeof_data 
)

Initialize a packet

If original is specified, the packet is initialized as a response to the original request.

Parameters
[in,out]packetThe packet to initialize
[in]originalThe original request (if any) to use as a template
[in]secretShared secret
[in]codeRADIUS Code field.
[in]dataBuffer where packets will be stored (RADIUS_PACKET::data)
[in]sizeof_dataSize of buffer (RADIUS_PACKET::sizeof_data)
Returns
<0 on error, 0 for success.

References radius_packet::code, radius_packet::data, radius_packet::id, radius_packet::length, NR_MAX_PACKET_CODE, nr_packet_can_encode(), return_NR_ERR, radius_packet::secret, radius_packet::sizeof_data, and radius_packet::sizeof_secret.

Referenced by main(), and nr_track_id_packet_alloc().

Here is the call graph for this function:

ssize_t nr_packet_vps_append ( RADIUS_PACKET packet,
const RADIUS_PACKET original,
const VALUE_PAIR vps 
)

Add many VALUE_PAIR structures to a packet

Some attributes are handled specially by this function.

User-Password, CHAP-Password, and Message-Authenticator. These attributes are automatically encrypted, as is done by nr_packet_encode().

Parameters
[in]packetThe packet to edit
[in]originalThe original request (if any)
[in]vpsThe VALUE_PAIR list to append to the packet
Returns
<0 for error, >= 0 for "successfully appended data" The function returns the number of octets appended to the packet.

References radius_packet::data, radius_packet::flags, radius_packet::length, NR_PACKET_ENCODED, nr_vp2attr(), return_NR_ERR, and radius_packet::sizeof_data.

Referenced by nr_packet_encode().

Here is the call graph for this function: