The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
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: 56f6a2bcd2b6ffceda8078890a81606720dd37b9 $
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: 56f6a2bcd2b6ffceda8078890a81606720dd37b9 $")
33
34#include <freeradius-devel/util/event.h>
35
36typedef struct {
37 fr_event_list_t *el; //!< event list
38
39 fr_time_delta_t lifetime; //!< default lifetime of dedup entry
41
43
44#ifndef _BIO_DEDUP_PRIVATE
46 void *uctx; //!< user-writable context
47 void *packet_ctx; //!< packet_ctx for dedup purposes
48 uint8_t *packet; //!< cached packet data.
49 size_t packet_size; //!< size of the cached packet data
50 void *reply_ctx; //!< reply ctx
51 uint8_t *reply; //!< reply cached by the application
52 size_t reply_size; //!< size of the cached reply
53
54 fr_rb_node_t dedup; //!< user managed dedup node
55};
56#endif
57
64
65/** Callback on read to see if we should receive the packet.
66 *
67 * The caller should cache dedup_ctx, unless it's a duplicate request.
68 *
69 * If it's a duplicate request, the caller should call fr_bio_dedup_respond() to write out the reply.
70 *
71 * @param bio the binary IO handler
72 * @param dedup_ctx new dedup_ctx assigned to this potential packet
73 * @param packet_ctx per-packet context for the response
74 * @return
75 * - false - discard the packet
76 * - true - create a new entry for the packet
77 */
78typedef bool (*fr_bio_dedup_receive_t)(fr_bio_t *bio, fr_bio_dedup_entry_t *dedup_ctx, void *packet_ctx);
79
80/** Callback on release the packet (timeout, or cancelled by the application)
81 *
82 * The callback function should clean up any resources associated with the packet. The resources MUST NOT be
83 * released until the data is either "released" or "cancelled".
84 *
85 * The packet will be cancelled after this call returns. The cancellation callback will NOT be run.
86 *
87 * @param bio the binary IO handler
88 * @param dedup_ctx the dedup ctx to release
89 * @param reason why this packet is being released
90 */
92
93typedef fr_bio_dedup_entry_t *(*fr_bio_dedup_get_item_t)(fr_bio_t *bio, void *packet_ctx);
94
95fr_bio_t *fr_bio_dedup_alloc(TALLOC_CTX *ctx, size_t max_saved,
99 fr_bio_dedup_config_t const *cfg,
100 fr_bio_t *next) CC_HINT(nonnull(1,3,4,6,7));
101
102void fr_bio_dedup_entry_cancel(fr_bio_t *bio, fr_bio_dedup_entry_t *dedup_ctx) CC_HINT(nonnull);
103
105
106int fr_bio_dedup_entry_extend(fr_bio_t *bio, fr_bio_dedup_entry_t *dedup_ctx, fr_time_t expires) CC_HINT(nonnull);
#define RCSIDH(h, id)
Definition build.h:484
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:214
void * uctx
user-writable context
Definition dedup.c:97
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:91
fr_event_list_t * el
event list
Definition dedup.h:37
fr_time_delta_t lifetime
default lifetime of dedup entry
Definition dedup.h:39
void fr_bio_dedup_entry_cancel(fr_bio_t *bio, fr_bio_dedup_entry_t *dedup_ctx)
Cancel one item.
Definition dedup.c:935
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:1036
size_t packet_size
size of the cached packet data
Definition dedup.c:100
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:953
void * packet_ctx
packet_ctx for dedup purposes
Definition dedup.c:98
uint8_t * reply
reply cached by the application
Definition dedup.c:102
size_t reply_size
size of the cached reply
Definition dedup.c:103
void * reply_ctx
reply ctx
Definition dedup.c:101
uint8_t * packet
cached packet data for finding duplicates
Definition dedup.c:99
fr_rb_node_t dedup
user managed dedup node
Definition dedup.c:105
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:78
fr_bio_dedup_entry_t *(* fr_bio_dedup_get_item_t)(fr_bio_t *bio, void *packet_ctx)
Definition dedup.h:93
fr_bio_dedup_release_reason_t
Definition dedup.h:58
@ FR_BIO_DEDUP_WRITE_ERROR
Definition dedup.h:61
@ FR_BIO_DEDUP_INTERNAL_ERROR
Definition dedup.h:62
@ FR_BIO_DEDUP_CANCELLED
Definition dedup.h:60
@ FR_BIO_DEDUP_EXPIRED
Definition dedup.h:59
Definition dedup.c:96
Stores all information relating to an event list.
Definition event.c:411
static void * item(fr_lst_t const *lst, fr_lst_index_t idx)
Definition lst.c:122
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))