The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
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: 0180ad7ce5a599c858b58fd40283babbde9a959c $
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 
31 typedef struct radius_track_s radius_track_t;
32 
33 /** Track one request to a response
34  *
35  */
37  fr_rb_node_t node; //!< Entry in the tracking tree.
38 
40 
41  radius_track_entry_t ***binding; //!< Binding chunk we use to release the entry
42  ///< when its parent is freed. We also zero
43  ///< out the tracking entry field in the parent.
44 
45  request_t *request; //!< as always...
46 
47  void *uctx; //!< Result/resumption context.
48 
49  uint8_t code; //!< packet code (sigh)
50  uint8_t id; //!< our ID
51 
52  union {
53  fr_dlist_t entry; //!< For free list.
54  uint8_t vector[RADIUS_AUTH_VECTOR_LENGTH]; //!< copy of the request authenticator.
55  };
56 
57 #ifndef NDEBUG
58  uint64_t operation; //!< Used to give an idea of the alloc/free timeline.
59  char const *file; //!< Where the entry was allocated.
60  int line; //!< Where the entry was freed.
61 #endif
62 };
63 
65  unsigned int num_requests; //!< number of requests in the allocation
66 
67  fr_dlist_head_t free_list; //!< so we allocate by least recently used
68 
69  bool use_authenticator; //!< whether to use the request authenticator as an ID
70  int next_id; //!< next ID to allocate
71 
72  radius_track_entry_t id[UINT8_MAX + 1]; //!< which ID was used
73 
74  fr_rb_tree_t *subtree[UINT8_MAX + 1]; //!< for Original-Request-Authenticator
75 
76 #ifndef NDEBUG
77  uint64_t operation; //!< Incremented each alloc and de-alloc
78 #endif
79 };
80 
81 radius_track_t *radius_track_alloc(TALLOC_CTX *ctx);
82 
83 /*
84  * Debug functions which track allocations and frees
85  */
86 #ifndef NDEBUG
87 # define radius_track_entry_reserve(_te_out, _ctx, _tt, _request, _code, _uctx) \
88  _radius_track_entry_reserve( __FILE__, __LINE__, _te_out, _ctx, _tt, _request, _code, _uctx)
89 int _radius_track_entry_reserve(char const *file, int line,
90  radius_track_entry_t **te_out,
91  TALLOC_CTX *ctx, radius_track_t *tt, request_t *request,
92  uint8_t code, void *uctx)
93  CC_HINT(nonnull(3,5,6));
94 
95 # define radius_track_entry_release(_te) \
96  _radius_track_entry_release( __FILE__, __LINE__, _te)
98  CC_HINT(nonnull);
99 
100 typedef void (*radius_track_log_extra_t)(fr_log_t const *log, fr_log_type_t log_type, char const *file, int line,
102 
103 void radius_track_state_log(fr_log_t const *log, fr_log_type_t log_type, char const *file, int line,
105 /*
106  * Non-debug functions
107  */
108 #else
110  TALLOC_CTX *ctx, radius_track_t *tt, request_t *request,
111  uint8_t code, void *uctx)
112  CC_HINT(nonnull(1,3,4));
113 
115 #endif
116 
118  uint8_t const *vector) CC_HINT(nonnull);
119 
121  uint8_t const *vector) CC_HINT(nonnull(1));
122 
123 void radius_track_use_authenticator(radius_track_t *te, bool flag) CC_HINT(nonnull);
int const char * file
Definition: acutest.h:702
int const char int line
Definition: acutest.h:702
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:54
unsigned char uint8_t
Definition: merged_model.c:30
#define UINT8_MAX
Definition: merged_model.c:32
#define RADIUS_AUTH_VECTOR_LENGTH
Definition: net.h:89
The main red black tree structure.
Definition: rb.h:73
Definition: log.h:96
char const * file
Where the entry was allocated.
Definition: track.h:59
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:425
fr_dlist_head_t free_list
so we allocate by least recently used
Definition: track.h:67
int _radius_track_entry_release(char const *file, int line, radius_track_entry_t **te)
Release a tracking entry.
Definition: track.c:209
radius_track_t * tt
Definition: track.h:39
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:293
#define radius_track_entry_release(_te)
Definition: track.h:95
bool use_authenticator
whether to use the request authenticator as an ID
Definition: track.h:69
void * uctx
Result/resumption context.
Definition: track.h:47
void radius_track_use_authenticator(radius_track_t *te, bool flag)
Use Request Authenticator (or not) as an Identifier.
Definition: track.c:408
fr_rb_tree_t * subtree[UINT8_MAX+1]
for Original-Request-Authenticator
Definition: track.h:74
int line
Where the entry was freed.
Definition: track.h:60
uint8_t id
our ID
Definition: track.h:50
uint64_t operation
Incremented each alloc and de-alloc.
Definition: track.h:77
unsigned int num_requests
number of requests in the allocation
Definition: track.h:65
fr_rb_node_t node
Entry in the tracking tree.
Definition: track.h:37
radius_track_t * radius_track_alloc(TALLOC_CTX *ctx)
Create an radius_track_t.
Definition: track.c:42
uint8_t code
packet code (sigh)
Definition: track.h:49
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:109
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:338
#define radius_track_entry_reserve(_te_out, _ctx, _tt, _request, _code, _uctx)
Definition: track.h:87
int next_id
next ID to allocate
Definition: track.h:70
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:100
uint64_t operation
Used to give an idea of the alloc/free timeline.
Definition: track.h:58
request_t * request
as always...
Definition: track.h:45
radius_track_entry_t *** binding
Binding chunk we use to release the entry when its parent is freed.
Definition: track.h:41
Track one request to a response.
Definition: track.h:36
int nonnull(2, 5))