The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
proto_detail.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: 0c7a57519b220f434bc502fcc107524509a1bffd $
20  *
21  * @file proto_detail.h
22  * @brief Detail master protocol handler.
23  *
24  * @copyright 2017 Alan DeKok (alan@freeradius.org)
25  */
26 RCSIDH(detail_h, "$Id: 0c7a57519b220f434bc502fcc107524509a1bffd $")
27 
28 #include <freeradius-devel/io/application.h>
29 #include <freeradius-devel/server/module_rlm.h>
30 #include <freeradius-devel/util/retry.h>
31 #include <freeradius-devel/util/dlist.h>
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 typedef struct {
38  CONF_SECTION *server_cs; //!< server CS for this listener
39  CONF_SECTION *cs; //!< my configuration
40  fr_app_t *self; //!< child / parent linking issues
41  char const *type; //!< packet type name
42 
43  dl_module_inst_t *io_submodule; //!< As provided by the transport_parse
44  ///< callback. Broken out into the
45  ///< app_io_* fields below for convenience.
46 
47  fr_app_io_t const *app_io; //!< Easy access to the app_io handle.
48  void *app_io_instance; //!< Easy access to the app_io instance.
49  CONF_SECTION *app_io_conf; //!< Easy access to the app_io's config section.
50 // proto_detail_app_io_t *app_io_private; //!< Internal interface for proto_radius.
51 
52  dl_module_inst_t *work_submodule; //!< the worker
53 
54  fr_app_io_t const *work_io; //!< Easy access to the app_io handle.
55  void *work_io_instance; //!< Easy access to the app_io instance.
56  CONF_SECTION *work_io_conf; //!< Easy access to the app_io's config secti
57 
58  fr_dict_t const *dict; //!< root dictionary
60 
61  uint32_t code; //!< packet code to use for incoming packets
62  uint32_t max_packet_size; //!< for message ring buffer
63  uint32_t num_messages; //!< for message ring buffer
64  uint32_t priority; //!< for packet processing, larger == higher
65 
66  /** Hacked in functionality to allow easy testing of the detail reader.
67  */
68  bool exit_when_done; //!< exit when done reading the current file.
69 
70  fr_schedule_t *sc; //!< the scheduler, where we insert new readers
71 
72  fr_listen_t *listen; //!< The listener structure which describes
73  //!< the I/O path.
75 
77 
78 /*
79  * The detail "work" data structure, shared by all of the detail readers.
80  */
82  CONF_SECTION *cs; //!< our configuration section
83 
84  proto_detail_t *parent; //!< The module that spawned us!
85  char const *directory; //!< containing the file below
86  char const *filename; //!< file name, usually with wildcards
87  char const *filename_work; //!< work file name
88 
89  uint32_t poll_interval; //!< interval between polling
90 
91  fr_retry_config_t retry_config; //!< retry config with irt, mrt, etc.
92  uint16_t max_outstanding; //!< number of packets to run in parallel
93 
94  bool track_progress; //!< do we track progress by writing?
95  bool retransmit; //!< are we retransmitting on error?
96  bool immediate; //!< start reading the detail files immediately
97 
98  int mode; //!< O_RDWR or O_RDONLY
99 
100  fr_rb_node_t filename_node; //!< for dedup
101 
102  fr_client_t *client; //!< so the rest of the server doesn't complain
103 };
104 
106 
108  char const *name; //!< debug name for printing
109  proto_detail_work_t const *inst; //!< instance data
110 
111  int fd; //!< file descriptor
112  int vnode_fd; //!< file descriptor for vnode_delete
113 
114  fr_event_list_t *el; //!< for various timers
115  fr_network_t *nr; //!< for Linux-specific callbacks
116  fr_listen_t *listen; //!< talloc_parent() is slow
117  proto_detail_work_thread_t *file_parent; //!< thread instance of the directory reader that spawned us
118 
119  char const *filename_work; //!< work file name
120  fr_dlist_head_t list; //!< for retransmissions
121 
122  uint32_t outstanding; //!< number of currently outstanding records;
123  fr_time_delta_t lock_interval; //!< interval between trying the locks.
124 
125  bool eof; //!< are we at EOF on reading?
126  bool closing; //!< we should be closing the file
127  bool paused; //!< Is reading paused?
128 
129  int count; //!< number of packets we read from this file.
130 
131  size_t leftover;
133 
134  size_t last_search; //!< where we last searched in the buffer
135  //!< MUST be offset, as the buffers can change.
136 
137  off_t file_size; //!< size of the file
138  off_t header_offset; //!< offset of the current header we're reading
139  off_t read_offset; //!< where we're reading from in filename_work
140 
141  fr_event_timer_t const *ev; //!< for detail file timers.
142 
143  pthread_mutex_t worker_mutex; //!< for the workers
144  int num_workers; //!< number of workers
145 };
146 
147 #include <pthread.h>
148 
149 #ifdef __cplusplus
150 }
151 #endif
Public structure describing an I/O path for a protocol.
Definition: app_io.h:33
Describes a new application (protocol)
Definition: application.h:71
#define RCSIDH(h, id)
Definition: build.h:445
A section grouping multiple CONF_PAIR.
Definition: cf_priv.h:89
A module/inst tuple.
Definition: dl_module.h:162
Head of a doubly linked list.
Definition: dlist.h:51
Describes a host allowed to send packets to the server.
Definition: client.h:77
Stores all information relating to an event list.
Definition: event.c:411
A timer event.
Definition: event.c:102
unsigned short uint16_t
Definition: merged_model.c:31
unsigned int uint32_t
Definition: merged_model.c:33
unsigned char uint8_t
Definition: merged_model.c:30
long long int off_t
Definition: merged_model.c:22
size_t last_search
where we last searched in the buffer MUST be offset, as the buffers can change.
Definition: proto_detail.h:134
proto_detail_t * parent
The module that spawned us!
Definition: proto_detail.h:84
proto_detail_work_thread_t * file_parent
thread instance of the directory reader that spawned us
Definition: proto_detail.h:117
CONF_SECTION * work_io_conf
Easy access to the app_io's config secti.
Definition: proto_detail.h:56
bool immediate
start reading the detail files immediately
Definition: proto_detail.h:96
fr_rb_node_t filename_node
for dedup
Definition: proto_detail.h:100
fr_dict_attr_t const * attr_packet_type
Definition: proto_detail.h:59
char const * directory
containing the file below
Definition: proto_detail.h:85
char const * filename_work
work file name
Definition: proto_detail.h:87
bool paused
Is reading paused?
Definition: proto_detail.h:127
uint32_t max_packet_size
for message ring buffer
Definition: proto_detail.h:62
fr_time_delta_t lock_interval
interval between trying the locks.
Definition: proto_detail.h:123
int count
number of packets we read from this file.
Definition: proto_detail.h:129
bool track_progress
do we track progress by writing?
Definition: proto_detail.h:94
bool eof
are we at EOF on reading?
Definition: proto_detail.h:125
bool exit_when_done
Hacked in functionality to allow easy testing of the detail reader.
Definition: proto_detail.h:68
fr_listen_t * listen
talloc_parent() is slow
Definition: proto_detail.h:116
void * work_io_instance
Easy access to the app_io instance.
Definition: proto_detail.h:55
char const * filename
file name, usually with wildcards
Definition: proto_detail.h:86
CONF_SECTION * server_cs
server CS for this listener
Definition: proto_detail.h:38
fr_client_t * client
so the rest of the server doesn't complain
Definition: proto_detail.h:102
char const * name
debug name for printing
Definition: proto_detail.h:108
bool retransmit
are we retransmitting on error?
Definition: proto_detail.h:95
fr_event_timer_t const * ev
for detail file timers.
Definition: proto_detail.h:141
int num_workers
number of workers
Definition: proto_detail.h:144
CONF_SECTION * app_io_conf
Easy access to the app_io's config section.
Definition: proto_detail.h:49
uint16_t max_outstanding
number of packets to run in parallel
Definition: proto_detail.h:92
fr_event_list_t * el
for various timers
Definition: proto_detail.h:114
fr_app_io_t const * work_io
Easy access to the app_io handle.
Definition: proto_detail.h:54
CONF_SECTION * cs
our configuration section
Definition: proto_detail.h:82
off_t file_size
size of the file
Definition: proto_detail.h:137
pthread_mutex_t worker_mutex
for the workers
Definition: proto_detail.h:143
fr_dict_t const * dict
root dictionary
Definition: proto_detail.h:58
fr_app_io_t const * app_io
Easy access to the app_io handle.
Definition: proto_detail.h:47
fr_schedule_t * sc
the scheduler, where we insert new readers
Definition: proto_detail.h:70
char const * filename_work
work file name
Definition: proto_detail.h:119
off_t header_offset
offset of the current header we're reading
Definition: proto_detail.h:138
dl_module_inst_t * io_submodule
As provided by the transport_parse callback.
Definition: proto_detail.h:43
uint32_t poll_interval
interval between polling
Definition: proto_detail.h:89
proto_detail_work_t const * inst
instance data
Definition: proto_detail.h:109
dl_module_inst_t * work_submodule
the worker
Definition: proto_detail.h:52
fr_dlist_head_t list
for retransmissions
Definition: proto_detail.h:120
uint32_t code
packet code to use for incoming packets
Definition: proto_detail.h:61
fr_retry_config_t retry_config
retry config with irt, mrt, etc.
Definition: proto_detail.h:91
uint32_t num_messages
for message ring buffer
Definition: proto_detail.h:63
int mode
O_RDWR or O_RDONLY.
Definition: proto_detail.h:98
int fd
file descriptor
Definition: proto_detail.h:111
char const * type
packet type name
Definition: proto_detail.h:41
bool closing
we should be closing the file
Definition: proto_detail.h:126
void * app_io_instance
Easy access to the app_io instance.
Definition: proto_detail.h:48
CONF_SECTION * cs
my configuration
Definition: proto_detail.h:39
uint32_t priority
for packet processing, larger == higher
Definition: proto_detail.h:64
int vnode_fd
file descriptor for vnode_delete
Definition: proto_detail.h:112
fr_listen_t * listen
The listener structure which describes the I/O path.
Definition: proto_detail.h:72
off_t read_offset
where we're reading from in filename_work
Definition: proto_detail.h:139
uint32_t outstanding
number of currently outstanding records;
Definition: proto_detail.h:122
fr_network_t * nr
for Linux-specific callbacks
Definition: proto_detail.h:115
The scheduler.
Definition: schedule.c:125
A time delta, a difference in time measured in nanoseconds.
Definition: time.h:80