The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
Data Structures | Typedefs | Enumerations | Functions
dedup.h File Reference

Binary IO abstractions for deduping of raw packets. More...

#include <freeradius-devel/util/event.h>
#include <freeradius-devel/util/rb.h>
#include <freeradius-devel/bio/protocol.h>
+ Include dependency graph for dedup.h:

Go to the source code of this file.

Data Structures

struct  fr_bio_dedup_config_t
 
struct  fr_bio_dedup_entry_s
 

Typedefs

typedef struct fr_bio_dedup_entry_s fr_bio_dedup_entry_t
 
typedef fr_bio_dedup_entry_t *(* fr_bio_dedup_get_item_t) (fr_bio_t *bio, void *packet_ctx)
 
typedef void(* fr_bio_dedup_receive_t) (fr_bio_t *bio, fr_bio_dedup_entry_t *item, void *packet_ctx)
 Tell the application that the packet of the current read has the entry item
 
typedef void(* fr_bio_dedup_release_t) (fr_bio_t *bio, fr_bio_dedup_entry_t *item, fr_bio_dedup_release_reason_t reason)
 Callback on release the packet (timeout, or cancelled by the application)
 

Enumerations

enum  fr_bio_dedup_release_reason_t : uint8_t {
  FR_BIO_DEDUP_EXPIRED = 0 ,
  FR_BIO_DEDUP_CANCELLED ,
  FR_BIO_DEDUP_WRITE_ERROR ,
  FR_BIO_DEDUP_INTERNAL_ERROR ,
  FR_BIO_DEDUP_NO_REPLY
}
 

Functions

fr_bio_t * fr_bio_dedup_alloc (TALLOC_CTX *ctx, fr_bio_dedup_config_t const *cfg, fr_bio_t *next)
 Allocate a fr_bio_dedup_t.
 
int fr_bio_dedup_conflict (fr_bio_t *bio, fr_bio_dedup_entry_t *item)
 Mark an entry as conflicting with a newer request.
 
void fr_bio_dedup_entry_cancel (fr_bio_t *bio, fr_bio_dedup_entry_t *item)
 Cancel one item.
 
int fr_bio_dedup_entry_extend (fr_bio_t *bio, fr_bio_dedup_entry_t *item, fr_time_t expires)
 Extend the expiry time for an entry.
 
int fr_bio_dedup_no_reply (fr_bio_t *bio, fr_bio_dedup_entry_t *item)
 
ssize_t fr_bio_dedup_respond (fr_bio_t *bio, fr_bio_dedup_entry_t *item)
 Resend a reply when we receive a duplicate request.
 

Detailed Description

Binary IO abstractions for deduping of raw packets.

Id
7a78269699d3ce70968a517351184de1e6052081

Read packets from a dedup bio. Once a packet is read, it is checked against a dedup tree. Duplicate packets are suppressed.

The dedup bio creates the dedup tree. The application sets the dedup_cmp function, which compares the dedup_ctx of two fr_bio_dedup_entry_t. Each protocol has its own requirements for dedup. For an unconnected socket, the dedup bio compares the addresses of the two entries before calling dedup_cmp.

The dedup bio creates the dedup context of each packet with the dedup_ctx callback, searches the dedup tree, and inserts new entries. Only the dedup bio inserts entries into the dedup tree, or removes entries from the dedup tree.

When max_active entries are in use, the dedup bio pauses reads, and calls the read_blocked callback. While reads are paused, fr_bio_read() on the dedup bio returns IO_WOULD_BLOCK, and any unread packet stays in the next bio. When an entry stops being in use, the dedup bio resumes reads, and calls the read_resume callback. The application sets the callbacks on the dedup bio with fr_bio_cb_set(). Because reads stay paused until the read_resume callback returns, a read from inside the read_resume callback returns IO_WOULD_BLOCK. The read_resume callback should only mark the file descriptor (FD) as readable, and should not read from the dedup bio.

Definition in file dedup.h.


Data Structure Documentation

◆ fr_bio_dedup_config_t

struct fr_bio_dedup_config_t

Definition at line 104 of file dedup.h.

+ Collaboration diagram for fr_bio_dedup_config_t:
Data Fields
bool connected this BIO is for a connected socket, where all packets have the same address.
fr_cmp_t dedup_cmp compare the dedup contexts of two fr_bio_dedup_entry_t.

It MUST be set.

fr_protocol_dedup_ctx_t dedup_ctx create the dedup context of a packet. It MUST be set.
fr_cmp_t duplicate_cmp returns 0 when two entries with the same key hold the same packet, i.e.

the newer packet is a duplicate. Non-zero means that the newer packet conflicts with the older packet. It MUST be set.

fr_event_list_t * el event list
fr_bio_dedup_get_item_t get_item turn a packet_ctx into a fr_bio_dedup_entry_t.

May be NULL.

fr_time_delta_t lifetime default lifetime of dedup entry
uint32_t max_active maximum number of entries in use.

At the limit, the dedup bio pauses reads. Zero means 1024. The maximum is (1 << 18).

uint32_t max_free maximum number of entries in the free list.

The dedup bio frees any entry over the limit. Zero means 1024. The maximum is (1 << 18).

size_t offset where fr_bio_fd_packet_ctx_t is stored in packet_ctx.

MUST be the offset passed to fr_bio_fd_alloc(). Only used when connected is false. Only used for unconnected sockets, and even then, only for AF_INET and AF_INET6.

fr_bio_dedup_receive_t receive tell the application which entry the dedup bio created for a new packet.

It MUST be set.

fr_bio_dedup_release_t release called to release a packet. It MUST be set.

◆ fr_bio_dedup_entry_s

struct fr_bio_dedup_entry_s

Definition at line 130 of file dedup.c.

+ Collaboration diagram for fr_bio_dedup_entry_s:
Data Fields
union fr_bio_dedup_entry_s.__unnamed20__ __unnamed__
fr_socket_t * addr
fr_rb_node_t dedup node in fr_bio_dedup_t.dedup

node in the dedup tree of the dedup bio

void * dedup_ctx context for dedup purposes
uint8_t * packet cached packet data for finding duplicates

cached packet data.

size_t packet_size size of the cached packet data
uint8_t * reply reply cached by the application
void * reply_ctx reply ctx
size_t reply_size size of the cached reply
void * uctx user-writable context

Typedef Documentation

◆ fr_bio_dedup_entry_t

Definition at line 50 of file dedup.h.

◆ fr_bio_dedup_get_item_t

typedef fr_bio_dedup_entry_t *(* fr_bio_dedup_get_item_t) (fr_bio_t *bio, void *packet_ctx)

Definition at line 102 of file dedup.h.

◆ fr_bio_dedup_receive_t

typedef void(* fr_bio_dedup_receive_t) (fr_bio_t *bio, fr_bio_dedup_entry_t *item, void *packet_ctx)

Tell the application that the packet of the current read has the entry item

The dedup bio calls receive for a new packet only, and after the dedup bio has put item into the dedup tree and the active list. The application should store item in a field of packet_ctx, so that it can find the entry later. The callback MUST NOT call any other dedup function.

Parameters
biothe binary IO handler
itemthe entry for the packet
packet_ctxthe packet_ctx passed to fr_bio_read()

Definition at line 84 of file dedup.h.

◆ fr_bio_dedup_release_t

typedef void(* fr_bio_dedup_release_t) (fr_bio_t *bio, fr_bio_dedup_entry_t *item, fr_bio_dedup_release_reason_t reason)

Callback on release the packet (timeout, or cancelled by the application)

The dedup bio has already removed the entry from the dedup tree. The callback must not remove the entry from the dedup tree.

The callback function should clean up any additonal resources associated with the packet. The resources MUST NOT be released until the data is either "released" or "cancelled".

The packet will be cancelled after this call returns. The cancellation callback will NOT be run.

Parameters
biothe binary IO handler
itemthe item to release
reasonwhy this packet is being released

Definition at line 100 of file dedup.h.

Enumeration Type Documentation

◆ fr_bio_dedup_release_reason_t

Enumerator
FR_BIO_DEDUP_EXPIRED 

it's expired, and we have to delete it

FR_BIO_DEDUP_CANCELLED 

it was cancelled

FR_BIO_DEDUP_WRITE_ERROR 

IO error.

FR_BIO_DEDUP_INTERNAL_ERROR 

something something, error.

FR_BIO_DEDUP_NO_REPLY 

We're not replying to this item.

Definition at line 66 of file dedup.h.

Function Documentation

◆ fr_bio_dedup_alloc()

fr_bio_t * fr_bio_dedup_alloc ( TALLOC_CTX *  ctx,
fr_bio_dedup_config_t const *  cfg,
fr_bio_t *  next 
)

Allocate a fr_bio_dedup_t.

Definition at line 1641 of file dedup.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_bio_dedup_conflict()

int fr_bio_dedup_conflict ( fr_bio_t *  bio,
fr_bio_dedup_entry_t *  item 
)

Mark an entry as conflicting with a newer request.

The dedup bio calls this function when a newer request is found to conflict with an older request which the application may still be processing. The old entry stays in the active list, but is marked as FR_BIO_DEDUP_STATE_CLEANUP. The entry is then released when the application finishes processing the older request, and calls fr_bio_dedup_respond().

If the application has already finished processing the older request, the entry is released now, with reason FR_BIO_DEDUP_CANCELLED.

  • Replied, or "no reply" and waiting to expire. The entry is released.
  • Pending reply. The dedup bio removes the entry from the pending list, and releases the entry.
  • Reply partially written. The rest of the reply is still written, as the next bio has already started writing the reply. The entry is marked FR_BIO_DEDUP_STATE_CANCELLED, and goes back to the free list once the write finishes.

Any other state is a programming error. Because the dedup bio has already removed a cancelled, cleanup, or free entry from the dedup tree, neither fr_bio_dedup_check() nor the application can find the entry to pass to this function.

Parameters
biothe binary IO handler
itemthe older entry, which conflicts with a newer request
Returns
  • <0 error, the entry is unchanged
  • 0 success

Definition at line 1496 of file dedup.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_bio_dedup_entry_cancel()

void fr_bio_dedup_entry_cancel ( fr_bio_t *  bio,
fr_bio_dedup_entry_t *  item 
)

Cancel one item.

Parameters
biothe binary IO handler
itemthe dedup context from #fr_bio_dedup_respond_t

Definition at line 1344 of file dedup.c.

+ Here is the call graph for this function:

◆ fr_bio_dedup_entry_extend()

int fr_bio_dedup_entry_extend ( fr_bio_t *  bio,
fr_bio_dedup_entry_t *  item,
fr_time_t  expires 
)

Extend the expiry time for an entry.

Parameters
biothe binary IO handler
itemthe dedup context from #fr_bio_dedup_respond_t
expiresthe new expiry time
Returns
  • <0 error
  • 0 success

Definition at line 1362 of file dedup.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_bio_dedup_no_reply()

int fr_bio_dedup_no_reply ( fr_bio_t *  bio,
fr_bio_dedup_entry_t *  item 
)

◆ fr_bio_dedup_respond()

ssize_t fr_bio_dedup_respond ( fr_bio_t *  bio,
fr_bio_dedup_entry_t *  item 
)

Resend a reply when we receive a duplicate request.

This function should be called by the respond() callback to re-send a duplicate reply.

It can also be called by the application when it first has a response to the request.

Parameters
biothe binary IO handler
itemthe dedup context from #fr_bio_dedup_sent_t
Returns
  • <0 on error
  • 0 for "wrote no data"
  • >0 for "wrote data".

Definition at line 368 of file dedup.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function: