The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
dedup.h
Go to the documentation of this file.
1#pragma once
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 */
17
18/**
19 * $Id: 13eeb3d7db27b7606905a51aa9bc4343bd9d9120 $
20 * @file lib/bio/dedup.h
21 * @brief Binary IO abstractions for deduping of raw packets
22 *
23 * Read packets from a dedup bio. Once a packet is read, it is checked
24 * against a dedup tree. Duplicate packets are suppressed.
25 *
26 * The caller has to manage the actual dedup tree and comparisons.
27 * Each protocol has its own requirements for dedup, and it is too
28 * awkward to make a generic method which works everywhere.
29 *
30 * @copyright 2024 Network RADIUS SAS (legal@networkradius.com)
31 */
32RCSIDH(lib_bio_dedup_h, "$Id: 13eeb3d7db27b7606905a51aa9bc4343bd9d9120 $")
33
34#include <freeradius-devel/util/event.h>
35#include <freeradius-devel/util/rb.h>
36
37typedef struct {
38 fr_event_list_t *el; //!< event list
39
40 fr_time_delta_t lifetime; //!< default lifetime of dedup entry
42
44
45#ifndef _BIO_DEDUP_PRIVATE
47 void *uctx; //!< user-writable context
48 void *packet_ctx; //!< packet_ctx for dedup purposes
49 uint8_t *packet; //!< cached packet data.
50 size_t packet_size; //!< size of the cached packet data
51 void *reply_ctx; //!< reply ctx
52 uint8_t *reply; //!< reply cached by the application
53 size_t reply_size; //!< size of the cached reply
54
55 fr_rb_node_t dedup; //!< user managed dedup node
56};
57#endif
58
65
66/** Callback on read to see if we should receive the packet.
67 *
68 * The caller should cache dedup_ctx, unless it's a duplicate request.
69 *
70 * If it's a duplicate request, the caller should call fr_bio_dedup_respond() to write out the reply.
71 *
72 * @param bio the binary IO handler
73 * @param dedup_ctx new dedup_ctx assigned to this potential packet
74 * @param packet_ctx per-packet context for the response
75 * @return
76 * - false - discard the packet
77 * - true - create a new entry for the packet
78 */
80
81/** Callback on release the packet (timeout, or cancelled by the application)
82 *
83 * The callback function should clean up any resources associated with the packet. The resources MUST NOT be
84 * released until the data is either "released" or "cancelled".
85 *
86 * The packet will be cancelled after this call returns. The cancellation callback will NOT be run.
87 *
88 * @param bio the binary IO handler
89 * @param dedup_ctx the dedup ctx to release
90 * @param reason why this packet is being released
91 */
93
94typedef fr_bio_dedup_entry_t *(*fr_bio_dedup_get_item_t)(fr_bio_t *bio, void *packet_ctx);
95
96fr_bio_t *fr_bio_dedup_alloc(TALLOC_CTX *ctx, size_t max_saved,
100 fr_bio_dedup_config_t const *cfg,
101 fr_bio_t *next) CC_HINT(nonnull(1,3,4,6,7));
102
103void fr_bio_dedup_entry_cancel(fr_bio_t *bio, fr_bio_dedup_entry_t *dedup_ctx) CC_HINT(nonnull);
104
106
107int fr_bio_dedup_entry_extend(fr_bio_t *bio, fr_bio_dedup_entry_t *dedup_ctx, fr_time_t expires) CC_HINT(nonnull);
static int packet_ctx
the tests pass only the address of packet_ctx
#define RCSIDH(h, id)
Definition build.h:604
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.
Definition dedup.c:212
void * uctx
user-writable context
Definition dedup.c:95
void(* fr_bio_dedup_release_t)(fr_bio_t *bio, fr_bio_dedup_entry_t *dedup_ctx, fr_bio_dedup_release_reason_t reason)
Callback on release the packet (timeout, or cancelled by the application)
Definition dedup.h:92
fr_event_list_t * el
event list
Definition dedup.h:38
fr_time_delta_t lifetime
default lifetime of dedup entry
Definition dedup.h:40
void fr_bio_dedup_entry_cancel(fr_bio_t *bio, fr_bio_dedup_entry_t *dedup_ctx)
Cancel one item.
Definition dedup.c:1013
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 dedup.c:1117
size_t packet_size
size of the cached packet data
Definition dedup.c:98
int fr_bio_dedup_entry_extend(fr_bio_t *bio, fr_bio_dedup_entry_t *dedup_ctx, fr_time_t expires)
Extend the expiry time for an entry.
Definition dedup.c:1031
void * packet_ctx
packet_ctx for dedup purposes
Definition dedup.c:96
uint8_t * reply
reply cached by the application
Definition dedup.c:100
size_t reply_size
size of the cached reply
Definition dedup.c:101
void * reply_ctx
reply ctx
Definition dedup.c:99
uint8_t * packet
cached packet data for finding duplicates
Definition dedup.c:97
fr_rb_node_t dedup
user managed dedup node
Definition dedup.c:103
bool(* fr_bio_dedup_receive_t)(fr_bio_t *bio, fr_bio_dedup_entry_t *dedup_ctx, void *packet_ctx)
Callback on read to see if we should receive the packet.
Definition dedup.h:79
fr_bio_dedup_entry_t *(* fr_bio_dedup_get_item_t)(fr_bio_t *bio, void *packet_ctx)
Definition dedup.h:94
fr_bio_dedup_release_reason_t
Definition dedup.h:59
@ FR_BIO_DEDUP_WRITE_ERROR
Definition dedup.h:62
@ FR_BIO_DEDUP_INTERNAL_ERROR
Definition dedup.h:63
@ FR_BIO_DEDUP_CANCELLED
Definition dedup.h:61
@ FR_BIO_DEDUP_EXPIRED
Definition dedup.h:60
Definition dedup.c:94
Stores all information relating to an event list.
Definition event.c:375
static void * item(fr_lst_t const *lst, fr_lst_index_t idx)
Definition lst.c:121
long int ssize_t
unsigned char bool
unsigned char uint8_t
A time delta, a difference in time measured in nanoseconds.
Definition time.h:80
"server local" time.
Definition time.h:69
int nonnull(2, 5))