![]() |
The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
|
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. | |
Binary IO abstractions for deduping of raw packets.
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.
| struct fr_bio_dedup_config_t |
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 |
| 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. |
| struct fr_bio_dedup_entry_s |
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 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
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.
| bio | the binary IO handler |
| item | the entry for the packet |
| packet_ctx | the packet_ctx passed to fr_bio_read() |
| 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.
| bio | the binary IO handler |
| item | the item to release |
| reason | why this packet is being released |
| 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:| 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.
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.
| bio | the binary IO handler |
| item | the older entry, which conflicts with a newer request |
Definition at line 1496 of file dedup.c.
Here is the call graph for this function:
Here is the caller graph for this function:| void fr_bio_dedup_entry_cancel | ( | fr_bio_t * | bio, |
| fr_bio_dedup_entry_t * | 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.
| bio | the binary IO handler |
| item | the dedup context from #fr_bio_dedup_respond_t |
| expires | the new expiry time |
Definition at line 1362 of file dedup.c.
Here is the call graph for this function:
Here is the caller graph for this function:| 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.
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.
| bio | the binary IO handler |
| item | the dedup context from #fr_bio_dedup_sent_t |
Definition at line 368 of file dedup.c.
Here is the call graph for this function:
Here is the caller graph for this function:
1.9.8