The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Typedefs | Enumerations | Functions
dedup.c File Reference

Binary IO abstractions for deduping packets. More...

#include <freeradius-devel/bio/bio_priv.h>
#include <freeradius-devel/bio/null.h>
#include <freeradius-devel/bio/buf.h>
#include <freeradius-devel/util/rb.h>
#include <freeradius-devel/util/dlist.h>
#include <freeradius-devel/bio/dedup.h>
+ Include dependency graph for dedup.c:

Go to the source code of this file.

Data Structures

struct  fr_bio_dedup_entry_s
 
union  fr_bio_dedup_entry_s.__unnamed5__
 
struct  fr_bio_dedup_entry_s.__unnamed5__.__unnamed7__
 
struct  fr_bio_dedup_s
 

Macros

#define _BIO_DEDUP_PRIVATE
 

Typedefs

typedef struct fr_bio_dedup_list_s fr_bio_dedup_list_t
 
typedef struct fr_bio_dedup_s fr_bio_dedup_t
 

Enumerations

enum  fr_bio_dedup_state_t {
  FR_BIO_DEDUP_STATE_FREE ,
  FR_BIO_DEDUP_STATE_ACTIVE ,
  FR_BIO_DEDUP_STATE_PENDING ,
  FR_BIO_DEDUP_STATE_REPLIED ,
  FR_BIO_DEDUP_STATE_PARTIAL ,
  FR_BIO_DEDUP_STATE_CANCELLED
}
 

Functions

static int8_t _entry_cmp (void const *one, void const *two)
 
fr_bio_tfr_bio_dedup_alloc (TALLOC_CTX *ctx, size_t max_saved, fr_bio_dedup_receive_t receive, fr_bio_dedup_release_t release, fr_bio_dedup_get_item_t get_item, fr_bio_dedup_config_t const *cfg, fr_bio_t *next)
 Allocate a fr_bio_dedup_t. More...
 
static ssize_t fr_bio_dedup_blocked (fr_bio_dedup_t *my, fr_bio_dedup_entry_t *item, ssize_t rcode)
 The write is blocked. More...
 
static ssize_t fr_bio_dedup_blocked_data (fr_bio_dedup_t *my, uint8_t const *buffer, size_t size, ssize_t rcode)
 The write is blocked, but we don't have "item". More...
 
static int fr_bio_dedup_buffer_save (fr_bio_dedup_t *my, uint8_t const *buffer, size_t size, ssize_t rcode)
 Save partially written data to our local buffer. More...
 
static ssize_t fr_bio_dedup_buffer_write (fr_bio_dedup_t *my)
 Write data from our local buffer to the next bio. More...
 
static int fr_bio_dedup_destructor (fr_bio_dedup_t *my)
 Remove the dedup cache. More...
 
void fr_bio_dedup_entry_cancel (fr_bio_t *bio, fr_bio_dedup_entry_t *item)
 Cancel one item. More...
 
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. More...
 
static ssize_t fr_bio_dedup_flush_pending (fr_bio_dedup_t *my)
 Flush any packets in the pending queue. More...
 
static ssize_t fr_bio_dedup_read (fr_bio_t *bio, void *packet_ctx, void *buffer, size_t size)
 
static void fr_bio_dedup_release (fr_bio_dedup_t *my, fr_bio_dedup_entry_t *item, fr_bio_dedup_release_reason_t reason)
 Release an entry back to the free list. More...
 
static void fr_bio_dedup_replied (fr_bio_dedup_t *my, fr_bio_dedup_entry_t *item)
 Move an item from active to replied. More...
 
static int fr_bio_dedup_reset_timer (fr_bio_dedup_t *my)
 Reset the timer after changing the rb tree. More...
 
static void fr_bio_dedup_reset_timer_item (fr_bio_dedup_t *my, 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. More...
 
static void fr_bio_dedup_timer (UNUSED fr_event_list_t *el, fr_time_t now, void *uctx)
 Expire an entry when its timer fires. More...
 
static ssize_t fr_bio_dedup_write (fr_bio_t *bio, void *packet_ctx, void const *buffer, size_t size)
 Write raw data to the bio. More...
 
static ssize_t fr_bio_dedup_write_data (fr_bio_t *bio, void *packet_ctx, const void *buffer, size_t size)
 There's a partial block of data written. More...
 
static ssize_t fr_bio_dedup_write_partial (fr_bio_t *bio, void *packet_ctx, const void *buffer, size_t size)
 There's a partial packet written. More...
 

Detailed Description

Binary IO abstractions for deduping packets.

Id
ab4555a4d2ce7461cc77a460269fd40343d29961

Definition in file dedup.c.


Data Structure Documentation

◆ fr_bio_dedup_entry_s

struct fr_bio_dedup_entry_s

Definition at line 57 of file dedup.c.

+ Collaboration diagram for fr_bio_dedup_entry_s:
Data Fields
union fr_bio_dedup_entry_s __unnamed__
fr_time_t expires when this entry expires
fr_bio_dedup_t * my so we can get to it from the event timer callback
uint8_t * packet cached packet data for finding duplicates

cached packet data.

void * packet_ctx packet_ctx for dedup purposes
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
fr_bio_dedup_state_t state which tree or list this item is in
void * uctx user-writable context

◆ fr_bio_dedup_entry_s.__unnamed5__

union fr_bio_dedup_entry_s.__unnamed5__

Definition at line 66 of file dedup.c.

Data Fields
__unnamed5__ __unnamed__

◆ fr_bio_dedup_entry_s.__unnamed5__.__unnamed7__

struct fr_bio_dedup_entry_s.__unnamed5__.__unnamed7__

Definition at line 67 of file dedup.c.

Data Fields
fr_rb_node_t node for the expiry timers

◆ fr_bio_dedup_s

struct fr_bio_dedup_s

Definition at line 81 of file dedup.c.

+ Collaboration diagram for fr_bio_dedup_s:
Data Fields
fr_bio_buf_t buffer
fr_bio_dedup_config_t config
fr_event_list_t * el
fr_event_timer_t const * ev
fr_bio_dedup_entry_t * first
FR_BIO_COMMON
fr_bio_dedup_get_item_t get_item turn a packet_ctx into a fr_bio_dedup_entry_t
fr_bio_dedup_entry_t * partial
fr_rb_tree_t rb expire list
fr_bio_dedup_receive_t receive called when we receive a potentially new packet
fr_bio_dedup_release_t release called to release a packet

Macro Definition Documentation

◆ _BIO_DEDUP_PRIVATE

#define _BIO_DEDUP_PRIVATE

Definition at line 31 of file dedup.c.

Typedef Documentation

◆ fr_bio_dedup_list_t

typedef struct fr_bio_dedup_list_s fr_bio_dedup_list_t

Definition at line 1 of file dedup.c.

◆ fr_bio_dedup_t

Definition at line 1 of file dedup.c.

Enumeration Type Documentation

◆ fr_bio_dedup_state_t

Enumerator
FR_BIO_DEDUP_STATE_FREE 
FR_BIO_DEDUP_STATE_ACTIVE 

Received, but not replied.

FR_BIO_DEDUP_STATE_PENDING 

Have a reply, but we're trying to write it out.

FR_BIO_DEDUP_STATE_REPLIED 

Replied, and waiting for it to expire.

FR_BIO_DEDUP_STATE_PARTIAL 

Partially written.

FR_BIO_DEDUP_STATE_CANCELLED 

Partially written, and then cancelled.

Definition at line 48 of file dedup.c.

Function Documentation

◆ _entry_cmp()

static int8_t _entry_cmp ( void const *  one,
void const *  two 
)
static

Definition at line 871 of file dedup.c.

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

◆ fr_bio_dedup_alloc()

fr_bio_t* fr_bio_dedup_alloc ( TALLOC_CTX *  ctx,
size_t  max_saved,
fr_bio_dedup_receive_t  receive,
fr_bio_dedup_release_t  release,
fr_bio_dedup_get_item_t  get_item,
fr_bio_dedup_config_t const *  cfg,
fr_bio_t next 
)

Allocate a fr_bio_dedup_t.

Definition at line 987 of file dedup.c.

+ Here is the call graph for this function:

◆ fr_bio_dedup_blocked()

static ssize_t fr_bio_dedup_blocked ( fr_bio_dedup_t my,
fr_bio_dedup_entry_t item,
ssize_t  rcode 
)
static

The write is blocked.

We couldn't write out the entire packet, the bio is blocked. Don't write anything else until we become unblocked!

Do NOT free the timer. We can still expire old entries. This newly written entry usually ends up as the last item in the RB tree.

Definition at line 611 of file dedup.c.

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

◆ fr_bio_dedup_blocked_data()

static ssize_t fr_bio_dedup_blocked_data ( fr_bio_dedup_t my,
uint8_t const *  buffer,
size_t  size,
ssize_t  rcode 
)
static

The write is blocked, but we don't have "item".

We couldn't write out the entire packet, the bio is blocked. Don't write anything else until we become unblocked!

Do NOT free the timer. We can still expire old entries. This newly written entry usually ends up as the last item in the RB tree.

Definition at line 699 of file dedup.c.

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

◆ fr_bio_dedup_buffer_save()

static int fr_bio_dedup_buffer_save ( fr_bio_dedup_t my,
uint8_t const *  buffer,
size_t  size,
ssize_t  rcode 
)
static

Save partially written data to our local buffer.

Definition at line 469 of file dedup.c.

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

◆ fr_bio_dedup_buffer_write()

static ssize_t fr_bio_dedup_buffer_write ( fr_bio_dedup_t my)
static

Write data from our local buffer to the next bio.

Definition at line 490 of file dedup.c.

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

◆ fr_bio_dedup_destructor()

static int fr_bio_dedup_destructor ( fr_bio_dedup_t my)
static

Remove the dedup cache.

Definition at line 961 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 887 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 905 of file dedup.c.

+ Here is the call graph for this function:

◆ fr_bio_dedup_flush_pending()

static ssize_t fr_bio_dedup_flush_pending ( fr_bio_dedup_t my)
static

Flush any packets in the pending queue.

Definition at line 392 of file dedup.c.

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

◆ fr_bio_dedup_read()

static ssize_t fr_bio_dedup_read ( fr_bio_t bio,
void *  packet_ctx,
void *  buffer,
size_t  size 
)
static

Definition at line 812 of file dedup.c.

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

◆ fr_bio_dedup_release()

static void fr_bio_dedup_release ( fr_bio_dedup_t my,
fr_bio_dedup_entry_t item,
fr_bio_dedup_release_reason_t  reason 
)
static

Release an entry back to the free list.

Definition at line 335 of file dedup.c.

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

◆ fr_bio_dedup_replied()

static void fr_bio_dedup_replied ( fr_bio_dedup_t my,
fr_bio_dedup_entry_t item 
)
static

Move an item from active to replied.

Note that we don't update any timers. The caller is responsible for that.

Definition at line 139 of file dedup.c.

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

◆ fr_bio_dedup_reset_timer()

static int fr_bio_dedup_reset_timer ( fr_bio_dedup_t my)
static

Reset the timer after changing the rb tree.

Definition at line 292 of file dedup.c.

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

◆ fr_bio_dedup_reset_timer_item()

static void fr_bio_dedup_reset_timer_item ( fr_bio_dedup_t my,
fr_bio_dedup_entry_t item 
)
inlinestatic

Definition at line 127 of file dedup.c.

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

◆ 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 173 of file dedup.c.

+ Here is the call graph for this function:

◆ fr_bio_dedup_timer()

static void fr_bio_dedup_timer ( UNUSED fr_event_list_t el,
fr_time_t  now,
void *  uctx 
)
static

Expire an entry when its timer fires.

Todo:
  • expire items from the pending list, too

Definition at line 723 of file dedup.c.

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

◆ fr_bio_dedup_write()

static ssize_t fr_bio_dedup_write ( fr_bio_t bio,
void *  packet_ctx,
void const *  buffer,
size_t  size 
)
static

Write raw data to the bio.

This function is largely a duplicate of fr_bio_dedup_respond(). Except due to the BIO API, it can be passed a NULL buffer (for flushing the BIOs), and it can't be passed a fr_bio_dedup_entry_t, and instead has to be passed a "void *packet_ctx".

The caller is free to ignore this function,

Definition at line 759 of file dedup.c.

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

◆ fr_bio_dedup_write_data()

static ssize_t fr_bio_dedup_write_data ( fr_bio_t bio,
void *  packet_ctx,
const void *  buffer,
size_t  size 
)
static

There's a partial block of data written.

Write all of that data first, before writing another packet.

Definition at line 664 of file dedup.c.

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

◆ fr_bio_dedup_write_partial()

static ssize_t fr_bio_dedup_write_partial ( fr_bio_t bio,
void *  packet_ctx,
const void *  buffer,
size_t  size 
)
static

There's a partial packet written.

Write all of that one first, before writing another packet.

The packet can either be cancelled, or IO blocked. In either case, we must write this packet before we can write another one.

Definition at line 530 of file dedup.c.

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