The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Typedefs
base.h File Reference

Transport-specific functions. More...

#include <freeradius-devel/io/channel.h>
#include <freeradius-devel/server/request.h>
#include <freeradius-devel/util/socket.h>
#include <freeradius-devel/util/time.h>
#include <freeradius-devel/util/talloc.h>
+ Include dependency graph for base.h:

Go to the source code of this file.

Data Structures

struct  fr_io_address_t
 
struct  fr_io_stats_t
 

Typedefs

typedef struct fr_channel_s fr_channel_t
 
typedef struct fr_client_s fr_client_t
 
typedef fr_client_t *(* fr_io_client_find_t) (fr_listen_t *li, fr_ipaddr_t const *ipaddr, int ipproto)
 
typedef int(* fr_io_close_t) (fr_listen_t *li)
 Handle a close on the socket. More...
 
typedef int(* fr_io_connection_set_t) (fr_listen_t *li, fr_io_address_t *connection)
 
typedef int(* fr_io_data_inject_t) (fr_listen_t *li, uint8_t const *buffer, size_t buffer_len, fr_time_t recv_time)
 Inject data into a socket. More...
 
typedef ssize_t(* fr_io_data_read_t) (fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time, uint8_t *buffer, size_t buffer_len, size_t *leftover)
 Read from a socket. More...
 
typedef void(* fr_io_data_vnode_t) (fr_listen_t *li, uint32_t fflags)
 Tell the IO handler that a VNODE has changed. More...
 
typedef ssize_t(* fr_io_data_write_t) (fr_listen_t *li, void *packet_ctx, fr_time_t request_time, uint8_t *buffer, size_t buffer_len, size_t written)
 Write a socket. More...
 
typedef int(* fr_io_decode_t) (void const *instance, request_t *request, uint8_t *const data, size_t data_len)
 Decode a raw packet and convert it into a request. More...
 
typedef ssize_t(* fr_io_encode_t) (void const *instance, request_t *request, uint8_t *buffer, size_t buffer_len)
 Encode data from a request_t into a raw packet. More...
 
typedef int(* fr_io_get_fd_t) (fr_listen_t const *li)
 Return a selectable file descriptor for this I/O path. More...
 
typedef size_t(* fr_io_nak_t) (fr_listen_t *li, void *packet_ctx, uint8_t *const packet, size_t packet_len, uint8_t *reply, size_t reply_len)
 NAK a packet. More...
 
typedef char const *(* fr_io_name_t) (fr_listen_t *li)
 
typedef void(* fr_io_network_get_t) (int *ipproto, bool *dynamic_clients, fr_trie_t const **trie, void *instance)
 Callback to return network properties. More...
 
typedef int(* fr_io_open_t) (fr_listen_t *li)
 Open an I/O path. More...
 
typedef int(* fr_io_set_fd_t) (fr_listen_t *li, int fd)
 Set a selectable file descriptor for this I/O path. More...
 
typedef int(* fr_io_signal_t) (fr_listen_t *li)
 Handle an error on the socket. More...
 
typedef int(* fr_io_track_cmp_t) (void const *instance, void *thread_instance, fr_client_t *client, void const *one, void const *two)
 Compare two tracking structures for storing in a duplicate detection tree. More...
 
typedef void *(* fr_io_track_create_t) (void const *instance, void *thread_instance, fr_client_t *client, fr_io_track_t *track, uint8_t const *packet, size_t packet_len)
 Convert a raw packet to a tracking structure. More...
 
typedef struct fr_io_track_s fr_io_track_t
 
typedef struct fr_listen fr_listen_t
 
typedef struct fr_trie_s fr_trie_t
 

Detailed Description

Transport-specific functions.

Id
3f474654c8765c470f1a7e26ce285ef2033e0472

Definition in file base.h.


Data Structure Documentation

◆ fr_io_address_t

struct fr_io_address_t

Definition at line 335 of file base.h.

+ Collaboration diagram for fr_io_address_t:
Data Fields
fr_client_t const * radclient old-style client definition
fr_socket_t socket src/dst ip and port.

◆ fr_io_stats_t

struct fr_io_stats_t

Definition at line 41 of file base.h.

Data Fields
uint64_t dropped
uint64_t dup
uint64_t in
uint64_t out

Typedef Documentation

◆ fr_channel_t

typedef struct fr_channel_s fr_channel_t

Definition at line 1 of file base.h.

◆ fr_client_t

typedef struct fr_client_s fr_client_t

Definition at line 341 of file base.h.

◆ fr_io_client_find_t

typedef fr_client_t*(* fr_io_client_find_t) (fr_listen_t *li, fr_ipaddr_t const *ipaddr, int ipproto)

Definition at line 345 of file base.h.

◆ fr_io_close_t

typedef int(* fr_io_close_t) (fr_listen_t *li)

Handle a close on the socket.

In general, the only thing to do on errors is to close the transport. But on error, the "error" function will be called before "close". On normal finish, the "close" function will be called.

Parameters
[in]lithe listener for this socket
Returns
  • 0 on success
  • <0 on error

Definition at line 330 of file base.h.

◆ fr_io_connection_set_t

typedef int(* fr_io_connection_set_t) (fr_listen_t *li, fr_io_address_t *connection)

Definition at line 341 of file base.h.

◆ fr_io_data_inject_t

typedef int(* fr_io_data_inject_t) (fr_listen_t *li, uint8_t const *buffer, size_t buffer_len, fr_time_t recv_time)

Inject data into a socket.

This function allows callers to inject data into a socket, just as if the data was read from a socket.

Note that this function is NOT an analog to fr_io_data_read_t. That is, the called function MUST copy the packet pointer into an internal list, so that subsequent calls to read() will return this packet.

The network side ensures that the packet buffer remains available to the called function for the duration of an inject() and read() call. i.e. the packet contents do NOT have to be saved, and the code can instead save the pointer to the buffer.

However, this buffer MUST be immediately returned on a subsequent call to read(). If it is not returned, the memory is still freed, and the pointer becomes invalid. Subsequent access to the buffer will result in crashes.

Parameters
[in]lithe listener for this socket
[in]bufferthe buffer where the raw packet to be injected
[in]buffer_lenthe length of the buffer
[in]recv_timewhen the packet was received
Returns
  • <0 on error
  • 0 on success

Definition at line 249 of file base.h.

◆ fr_io_data_read_t

typedef ssize_t(* fr_io_data_read_t) (fr_listen_t *li, void **packet_ctx, fr_time_t *recv_time, uint8_t *buffer, size_t buffer_len, size_t *leftover)

Read from a socket.

The network side guarantees that the read routine can leave partial data in the buffer. That data will be there on the next call to read. However, the data MAY have moved, so please do not keep a pointer to 'buffer' around.

datagram sockets should always set '*leftover = 0'.

stream sockets can read one packet, and set '*leftover' to how many bytes are left in the buffer. The read routine will be called again, with a (possibly new) buffer, but with 'leftover' bytes left in the buffer. The value in 'leftover'' will be the same as from the previous call, so the reader does not need to track it.

Parameters
[in]lithe listener for this socket
[out]packet_ctxWhere to write a newly allocated packet_ctx struct containing request specific data.
[out]recv_timeA pointer to a time when the packet was received
[in,out]bufferthe buffer where the raw packet will be written to (or read from)
[in]buffer_lenthe length of the buffer
[out]leftoverbytes left in the buffer after reading a full packet.
Returns
  • <0 on error
  • >=0 length of the data read or written.

Definition at line 176 of file base.h.

◆ fr_io_data_vnode_t

typedef void(* fr_io_data_vnode_t) (fr_listen_t *li, uint32_t fflags)

Tell the IO handler that a VNODE has changed.

Parameters
[in]lithe listener for this socket
[in]fflagsfrom kevent. Usually just NOTE_EXEND

Definition at line 256 of file base.h.

◆ fr_io_data_write_t

typedef ssize_t(* fr_io_data_write_t) (fr_listen_t *li, void *packet_ctx, fr_time_t request_time, uint8_t *buffer, size_t buffer_len, size_t written)

Write a socket.

If the socket is a datagram socket, then the function can read or write directly into the buffer. Stream sockets are a bit more complicated.

A stream reader can read data into the buffer, and be guaranteed that the data will not change in between subsequent calls to the read routine.

A stream writer MUST be prepared for the caller to delete the data immediately after calling the write routine. This means that if the socket is not ready, the writer MUST copy the data to an internal buffer, usually in instance. It MUST then have a write callback on the socket, which is called when the socket is ready for writing. That callback can then write the internal buffer to the socket.

i.e. this write() function is a way for the network thread to write packets to the transport context. The data may or may not go out to the network right away.

If the write function does a partial write, it should return a value smaller than buffer_len to indicate this. The network functions will then pass that value to a subsequent write call, in the "written" argument.

The reason for this odd API is that read/write should be writing packets, not raw streams of bytes. This API allows the "buffer" parameter to always contain a full packet.

Parameters
[in]lithe listener for this socket
[in]packet_ctxRequest specific data.
[in]request_timewhen the original request was received
[in]bufferthe buffer where the raw packet will be written from
[in]buffer_lenthe length of the buffer
[in]writtentotal number of bytes written in previous calls for this packet.
Returns
  • <0 on error
  • >=0 length of the data read or written.

Definition at line 218 of file base.h.

◆ fr_io_decode_t

typedef int(* fr_io_decode_t) (void const *instance, request_t *request, uint8_t *const data, size_t data_len)

Decode a raw packet and convert it into a request.

This function is the opposite of fr_io_encode_t.

The "decode" function is ONLY for decoding data. It should be aware of the protocol (e.g. RADIUS), but it MUST NOT know anything about the underlying network transport (e.g. UDP), and it MUST NOT know anything about how the data will be used (e.g. authorize, authenticate, etc. for Access-Request)

Parameters
[in]instanceof the fr_app_t or fr_app_io_t.
[in]datathe raw packet data
[in]data_lenthe length of the raw data
[in]requestwhere the decoded VPs should be placed.
Returns
  • <0 on error
  • 0 on success

Definition at line 103 of file base.h.

◆ fr_io_encode_t

typedef ssize_t(* fr_io_encode_t) (void const *instance, request_t *request, uint8_t *buffer, size_t buffer_len)

Encode data from a request_t into a raw packet.

This function is the opposite of fr_io_decode_t.

The "encode" function is ONLY for encoding data. It should be aware of the protocol (e.g. RADIUS), but it MUST NOT know anything about the underlying network transport (e.g. UDP), and it MUST NOT know anything about how the data will be used (e.g. reject delay on Access-Reject)

Parameters
[in]instanceof the fr_app_t or fr_app_io_t.
[in]requestrequest where the VPs to be encoded are located
[out]bufferthe buffer where the raw packet will be written
[in]buffer_lenthe length of the buffer
Returns
  • <0 on error
  • >=0 length of the encoded data in the buffer, will be <=buffer_len

Definition at line 123 of file base.h.

◆ fr_io_get_fd_t

typedef int(* fr_io_get_fd_t) (fr_listen_t const *li)

Return a selectable file descriptor for this I/O path.

Return the file descriptor associated with this I/O path.

Parameters
[in]lithe listener for this socket

Definition at line 75 of file base.h.

◆ fr_io_nak_t

typedef size_t(* fr_io_nak_t) (fr_listen_t *li, void *packet_ctx, uint8_t *const packet, size_t packet_len, uint8_t *reply, size_t reply_len)

NAK a packet.

When a worker receives a packet, it sometimes is unable to process that request. In order for the channels to work correctly, every request MUST be met with a response. This function allows a worker to NAK a request, but NOT send a response packet on the network.

This function MUST NOT fail. It must always return some data.

When the NAK packet is received by the network side, the transport portion of the network side MUST be able to recognize the NAK and take the appropriate action. e.g. for RADIUS, mark a request as "do not respond", even if duplicates come in.

Parameters
[in]lithe listener for this socket
[out]packet_ctxthe packet_ctx struct containing request specific data.
[in]packetthe packet to NAK
[in]packet_lenlength of the packet to NAK
[in]replythe NAK reply
[in]reply_lenlength of the buffer where the reply should be placed.
Returns
length of the data in the reply buffer.

Definition at line 148 of file base.h.

◆ fr_io_name_t

typedef char const*(* fr_io_name_t) (fr_listen_t *li)

Definition at line 356 of file base.h.

◆ fr_io_network_get_t

typedef void(* fr_io_network_get_t) (int *ipproto, bool *dynamic_clients, fr_trie_t const **trie, void *instance)

Callback to return network properties.

Parameters
[out]ipprotoIP protocol (AF_INET or AF_INET6).
[out]dynamic_clientsWhether clients are dynamic.
[out]trieTrie of clients.
[in]instanceInstance data.

Definition at line 354 of file base.h.

◆ fr_io_open_t

typedef int(* fr_io_open_t) (fr_listen_t *li)

Open an I/O path.

Open a socket, file, or anything else that can be referenced by a file descriptor.

The file descriptor should be made available to the event loop via the selectable_fd callback. It will only be used to determine if the socket is readable/writable/has errored.

No data will be read from or written to the fd, except by the io_data callbacks here.

Parameters
[in]lithe listener for this socket
Returns
  • 0 on success
  • <0 on error

Definition at line 67 of file base.h.

◆ fr_io_set_fd_t

typedef int(* fr_io_set_fd_t) (fr_listen_t *li, int fd)

Set a selectable file descriptor for this I/O path.

Parameters
[in]lithe listener for this socket
[in]fdthe FD to set

Definition at line 83 of file base.h.

◆ fr_io_signal_t

typedef int(* fr_io_signal_t) (fr_listen_t *li)

Handle an error on the socket.

In general, the only thing to do on errors is to close the transport. But on error, the "error" function will be called before "close". On normal finish, the "close" function will be called.

Parameters
[in]lithe listener for this socket
Returns
  • 0 on success
  • <0 on error

Definition at line 316 of file base.h.

◆ fr_io_track_cmp_t

typedef int(* fr_io_track_cmp_t) (void const *instance, void *thread_instance, fr_client_t *client, void const *one, void const *two)

Compare two tracking structures for storing in a duplicate detection tree.

We presume that the packets are well formed.

The comparison should be stable. i.e. compare the packets a field at a time. If the field is different, return the result from that field.

The comparison order of the fields should be "very different" to "much the same". The packets are put into an rbtree, so having a large fanout at the top is useful.

Note that this function should not check if the packets are completely identical. Instead, it checks particular fields in the packet so that we can distinguish packets without checking the entire packet.

Parameters
[in]instancethe context for this function
[in]thread_instancethe thread instance for this function
[in]clientthe client associated with this packet
[in]onepacket tracking structure one
[in]twopacket tracking structure two
Returns
  • <0 on packet one "smaller" than packet two
  • >0 on packet two "larger" than packet one
  • =0 on the two packets being identical

Definition at line 302 of file base.h.

◆ fr_io_track_create_t

typedef void*(* fr_io_track_create_t) (void const *instance, void *thread_instance, fr_client_t *client, fr_io_track_t *track, uint8_t const *packet, size_t packet_len)

Convert a raw packet to a tracking structure.

For passing to fr_io_track_cmp_t

Parameters
[in]instancethe context for this function
[in]thread_instancethe thread instance for this function
[in]clientthe client associated with this packet
[in]trackThe parent tracking structure
[in]packetThe packet being summarized
[in]packet_lenLength of the packet being summarized
Returns
  • NULL on error
  • !NULL the packet tracking structure

Definition at line 274 of file base.h.

◆ fr_io_track_t

typedef struct fr_io_track_s fr_io_track_t

Definition at line 256 of file base.h.

◆ fr_listen_t

typedef struct fr_listen fr_listen_t

Definition at line 1 of file base.h.

◆ fr_trie_t

typedef struct fr_trie_s fr_trie_t

Definition at line 1 of file base.h.