The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
id.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: badc5703e37123d6b4d96e406194b41add796bea $
20  *
21  * @file protocols/radius/id.h
22  * @brief RADIUS bio handlers for tracking 8-bit IDs
23  *
24  * @copyright 2024 Network RADIUS SAS (legal@networkradius.com)
25  */
26 RCSIDH(radius_id_h, "$Id: badc5703e37123d6b4d96e406194b41add796bea $")
27 
28 #include <freeradius-devel/radius/radius.h>
29 
30 typedef struct fr_radius_id_s fr_radius_id_t;
31 
33 
34 typedef struct {
35  void *request_ctx; //!< for the application to track
36  fr_packet_t *packet; //!< outgoing packet
37  fr_packet_t *response; //!< response to outgoing packet
38  void *retry_ctx; //!< to find the retry information
40 
41 fr_radius_id_t *fr_radius_id_alloc(TALLOC_CTX *ctx);
42 
44 
45 void fr_radius_id_push(fr_radius_id_t *track, fr_packet_t const *packet) CC_HINT(nonnull);
46 
48 
49 int fr_radius_id_force(fr_radius_id_t *track, int id) CC_HINT(nonnull);
50 
51 static inline CC_HINT(nonnull) int fr_radius_code_id_alloc(TALLOC_CTX *ctx, fr_radius_code_id_t codes, int code)
52 {
53  fr_assert(code > 0);
55 
56  fr_assert(!codes[code]);
57 
58  codes[code] = fr_radius_id_alloc(ctx);
59  if (!codes[code]) return -1;
60 
61  return 0;
62 }
63 
65 {
66  fr_assert(packet->code > 0);
68 
69  fr_assert(codes[packet->code]);
70 
71  return fr_radius_id_pop(codes[packet->code], packet);
72 }
73 
74 static inline CC_HINT(nonnull) void fr_radius_code_id_push(fr_radius_code_id_t codes, fr_packet_t const *packet)
75 {
76  fr_assert(packet->code > 0);
78 
79  fr_assert(codes[packet->code]);
80 
81  fr_radius_id_push(codes[packet->code], packet);
82 }
83 
84 static inline CC_HINT(nonnull) fr_radius_id_ctx_t *fr_radius_code_id_find(fr_radius_code_id_t codes, int code, int id)
85 {
86  fr_assert(code > 0);
88 
89  if (!codes[code]) return NULL;
90 
91  return fr_radius_id_find(codes[code], id);
92 }
93 
94 static inline CC_HINT(nonnull) int fr_radius_code_id_force(fr_radius_code_id_t codes, int code, int id)
95 {
96  fr_assert(code > 0);
98 
99  if (!codes[code]) return -1;
100 
101  return fr_radius_id_force(codes[code], id);
102 }
#define RCSIDH(h, id)
Definition: build.h:482
@ FR_RADIUS_CODE_MAX
Maximum possible protocol code.
Definition: defs.h:53
void fr_radius_id_push(fr_radius_id_t *track, fr_packet_t const *packet)
De-allocate an ID for a packet, using LRU.
Definition: id.c:118
static void fr_radius_code_id_push(fr_radius_code_id_t codes, fr_packet_t const *packet)
Definition: id.h:74
static fr_radius_id_ctx_t * fr_radius_code_id_pop(fr_radius_code_id_t codes, fr_packet_t *packet)
Definition: id.h:64
void * retry_ctx
to find the retry information
Definition: id.h:38
void * request_ctx
for the application to track
Definition: id.h:35
fr_packet_t * packet
outgoing packet
Definition: id.h:36
fr_packet_t * response
response to outgoing packet
Definition: id.h:37
int fr_radius_id_force(fr_radius_id_t *track, int id)
Forces the next ID to be the given one.
Definition: id.c:150
static int fr_radius_code_id_alloc(TALLOC_CTX *ctx, fr_radius_code_id_t codes, int code)
Definition: id.h:51
static fr_radius_id_ctx_t * fr_radius_code_id_find(fr_radius_code_id_t codes, int code, int id)
Definition: id.h:84
fr_radius_id_t * fr_radius_code_id_t[FR_RADIUS_CODE_MAX]
Definition: id.h:32
fr_radius_id_t * fr_radius_id_alloc(TALLOC_CTX *ctx)
Allocate a tracking structure for one packet code.
Definition: id.c:45
fr_radius_id_ctx_t * fr_radius_id_find(fr_radius_id_t *track, int id)
Definition: id.c:139
fr_radius_id_ctx_t * fr_radius_id_pop(fr_radius_id_t *track, fr_packet_t *packet)
Allocate an ID for a packet, using LRU.
Definition: id.c:89
static int fr_radius_code_id_force(fr_radius_code_id_t codes, int code, int id)
Definition: id.h:94
fr_assert(0)
unsigned int code
Packet code (type).
Definition: packet.h:61
int nonnull(2, 5))