The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
track.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: bcace997932a308b04d495db4f0aa104946a9b84 $
20 *
21 * @file track.h
22 * @brief RADIUS client packet tracking
23 *
24 * @copyright 2017 Alan DeKok (aland@freeradius.org)
25 */
26
27#include "rlm_radius.h"
28#include <freeradius-devel/util/dlist.h>
29#include <freeradius-devel/util/rb.h>
30
33
34/** Track one request to a response
35 *
36 */
38 fr_rb_node_t node; //!< Entry in the tracking tree.
39
41
42 radius_track_entry_t ***binding; //!< Binding chunk we use to release the entry
43 ///< when its parent is freed. We also zero
44 ///< out the tracking entry field in the parent.
45
46 request_t *request; //!< as always...
47
48 void *uctx; //!< Result/resumption context.
49
50 uint8_t code; //!< packet code (sigh)
51 uint8_t id; //!< our ID
52
53 union {
54 struct {
55 uint32_t epoch; //!< only for RADIUS/1.1
56 uint32_t token; //!< Token, only for RADIUS/1.1
57 };
58 fr_dlist_t entry; //!< For free list.
59 uint8_t vector[RADIUS_AUTH_VECTOR_LENGTH]; //!< copy of the request authenticator.
60 };
61
62#ifndef NDEBUG
63 uint64_t operation; //!< Used to give an idea of the alloc/free timeline.
64 char const *file; //!< Where the entry was allocated.
65 int line; //!< Where the entry was freed.
66#endif
67};
68
70 unsigned int num_requests; //!< number of requests in the allocation
71
72 fr_dlist_head_t free_list; //!< so we allocate by least recently used
73
74 bool radius_1_1; //!< are we using RADIUS/1.1
75
76 union {
77 struct {
78 uint32_t epoch; //!< to avoid having a linked list
79 uint32_t current; //!< the current Token we will issue.
80 fr_rb_tree_t tree; //!< Outstanding entries, by Token.
81 };
82 radius_track_entry_t id[UINT8_MAX + 1]; //!< which ID was used
83 };
84
85#ifndef NDEBUG
86 uint64_t operation; //!< Incremented each alloc and de-alloc
87#endif
88};
89
90radius_track_t *radius_track_alloc(TALLOC_CTX *ctx, bool radius_1_1);
91
92/*
93 * Debug functions which track allocations and frees
94 */
95#ifndef NDEBUG
96# define radius_track_entry_reserve(_te_out, _ctx, _tt, _request, _code, _uctx) \
97 _radius_track_entry_reserve( __FILE__, __LINE__, _te_out, _ctx, _tt, _request, _code, _uctx)
98int _radius_track_entry_reserve(char const *file, int line,
99 radius_track_entry_t **te_out,
100 TALLOC_CTX *ctx, radius_track_t *tt, request_t *request,
101 uint8_t code, void *uctx)
102 CC_HINT(nonnull(3,5,6));
103
104# define radius_track_entry_release(_te) \
105 _radius_track_entry_release( __FILE__, __LINE__, _te)
106int _radius_track_entry_release(char const *file, int line, radius_track_entry_t **te)
107 CC_HINT(nonnull);
108
109typedef void (*radius_track_log_extra_t)(fr_log_t const *log, fr_log_type_t log_type, char const *file, int line,
111
112void radius_track_state_log(fr_log_t const *log, fr_log_type_t log_type, char const *file, int line,
114/*
115 * Non-debug functions
116 */
117#else
119 TALLOC_CTX *ctx, radius_track_t *tt, request_t *request,
120 uint8_t code, void *uctx)
121 CC_HINT(nonnull(1,3,4));
122
124#endif
125
127 uint8_t const *vector) CC_HINT(nonnull);
128
130 uint8_t const *vector) CC_HINT(nonnull(1));
int const char * file
Definition acutest.h:855
void int line
Definition acutest.h:810
static uint8_t request[4]
Head of a doubly linked list.
Definition dlist.h:51
Entry in a doubly linked list.
Definition dlist.h:41
fr_log_type_t
Definition log.h:51
unsigned int uint32_t
unsigned char uint8_t
#define UINT8_MAX
#define RADIUS_AUTH_VECTOR_LENGTH
Definition net.h:89
The main red black tree structure.
Definition rb.h:71
Definition log.h:93
char const * file
Where the entry was allocated.
Definition track.h:64
void radius_track_state_log(fr_log_t const *log, fr_log_type_t log_type, char const *file, int line, radius_track_t *tt, radius_track_log_extra_t extra)
Print out the state of every tracking entry.
Definition track.c:381
fr_dlist_head_t free_list
so we allocate by least recently used
Definition track.h:72
int _radius_track_entry_release(char const *file, int line, radius_track_entry_t **te)
Release a tracking entry.
Definition track.c:214
radius_track_t * tt
Definition track.h:40
int radius_track_entry_update(radius_track_entry_t *te, uint8_t const *vector)
Update a tracking entry with the authentication vector.
Definition track.c:271
radius_track_entry_t * radius_track_entry_find(radius_track_t *tt, uint8_t packet_id, uint8_t const *vector))
Find a tracking entry from a request authenticator.
Definition track.c:344
#define radius_track_entry_release(_te)
Definition track.h:104
bool radius_1_1
are we using RADIUS/1.1
Definition track.h:74
void * uctx
Result/resumption context.
Definition track.h:48
int line
Where the entry was freed.
Definition track.h:65
uint8_t id
our ID
Definition track.h:51
radius_track_t * radius_track_alloc(TALLOC_CTX *ctx, bool radius_1_1)
Create an radius_track_t.
Definition track.c:52
uint64_t operation
Incremented each alloc and de-alloc.
Definition track.h:86
unsigned int num_requests
number of requests in the allocation
Definition track.h:70
fr_rb_node_t node
Entry in the tracking tree.
Definition track.h:38
uint8_t code
packet code (sigh)
Definition track.h:50
int _radius_track_entry_reserve(char const *file, int line, radius_track_entry_t **te_out, TALLOC_CTX *ctx, radius_track_t *tt, request_t *request, uint8_t code, void *uctx))
Allocate a tracking entry.
Definition track.c:117
#define radius_track_entry_reserve(_te_out, _ctx, _tt, _request, _code, _uctx)
Definition track.h:96
void(* radius_track_log_extra_t)(fr_log_t const *log, fr_log_type_t log_type, char const *file, int line, radius_track_entry_t *te)
Definition track.h:109
uint64_t operation
Used to give an idea of the alloc/free timeline.
Definition track.h:63
request_t * request
as always...
Definition track.h:46
radius_track_entry_t *** binding
Binding chunk we use to release the entry when its parent is freed.
Definition track.h:42
Track one request to a response.
Definition track.h:37
int nonnull(2, 5))