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: d6e360a7de23fac314f6fa4fc5e936df68e54441 $
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: d6e360a7de23fac314f6fa4fc5e936df68e54441 $")
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  fr_app_t *self; //!< child / parent linking issues
40  char const *type; //!< packet type name
41 
42  module_instance_t *io_submodule; //!< As provided by the transport_parse
43  ///< callback. Broken out into the
44  ///< app_io_* fields below for convenience.
45 
46  fr_app_io_t const *app_io; //!< Easy access to the app_io handle.
47  void *app_io_instance; //!< Easy access to the app_io instance.
48  CONF_SECTION *app_io_conf; //!< Easy access to the app_io's config section.
49 // proto_detail_app_io_t *app_io_private; //!< Internal interface for proto_radius.
50 
52 
53  fr_app_io_t const *work_io; //!< Easy access to the app_io handle.
54  void *work_io_instance; //!< Easy access to the app_io instance.
55  CONF_SECTION *work_io_conf; //!< Easy access to the app_io's config secti
56 
57  fr_dict_t const *dict; //!< root dictionary
59 
60  uint32_t code; //!< packet code to use for incoming packets
61  uint32_t max_packet_size; //!< for message ring buffer
62  uint32_t num_messages; //!< for message ring buffer
63  uint32_t priority; //!< for packet processing, larger == higher
64 
65  /** Hacked in functionality to allow easy testing of the detail reader.
66  */
67  bool exit_when_done; //!< exit when done reading the current file.
68 
69  fr_schedule_t *sc; //!< the scheduler, where we insert new readers
70 
71  fr_listen_t *listen; //!< The listener structure which describes
72  //!< the I/O path.
74 
76 
77 /*
78  * The detail "work" data structure, shared by all of the detail readers.
79  */
81  CONF_SECTION *cs; //!< our configuration section
82 
83  proto_detail_t *parent; //!< The module that spawned us!
84  char const *directory; //!< containing the file below
85  char const *filename; //!< file name, usually with wildcards
86  char const *filename_work; //!< work file name
87 
88  uint32_t poll_interval; //!< interval between polling
89 
90  fr_retry_config_t retry_config; //!< retry config with irt, mrt, etc.
91  uint16_t max_outstanding; //!< number of packets to run in parallel
92 
93  bool track_progress; //!< do we track progress by writing?
94  bool retransmit; //!< are we retransmitting on error?
95  bool immediate; //!< start reading the detail files immediately
96 
97  int mode; //!< O_RDWR or O_RDONLY
98 
99  fr_rb_node_t filename_node; //!< for dedup
100 
101  fr_client_t *client; //!< so the rest of the server doesn't complain
102 };
103 
105 
107  char const *name; //!< debug name for printing
108  proto_detail_work_t const *inst; //!< instance data
109 
110  int fd; //!< file descriptor
111  int vnode_fd; //!< file descriptor for vnode_delete
112 
113  fr_event_list_t *el; //!< for various timers
114  fr_network_t *nr; //!< for Linux-specific callbacks
115  fr_listen_t *listen; //!< talloc_parent() is slow
116  proto_detail_work_thread_t *file_parent; //!< thread instance of the directory reader that spawned us
117 
118  char const *filename_work; //!< work file name
119  fr_dlist_head_t list; //!< for retransmissions
120 
121  uint32_t outstanding; //!< number of currently outstanding records;
122  fr_time_delta_t lock_interval; //!< interval between trying the locks.
123 
124  bool eof; //!< are we at EOF on reading?
125  bool closing; //!< we should be closing the file
126  bool paused; //!< Is reading paused?
127 
128  int count; //!< number of packets we read from this file.
129 
130  size_t leftover;
132 
133  size_t last_search; //!< where we last searched in the buffer
134  //!< MUST be offset, as the buffers can change.
135  unsigned int last_line; //!< line number of the last record read.
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:482
A section grouping multiple CONF_PAIR.
Definition: cf_priv.h:101
Head of a doubly linked list.
Definition: dlist.h:51
Describes a host allowed to send packets to the server.
Definition: client.h:80
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:133
proto_detail_t * parent
The module that spawned us!
Definition: proto_detail.h:83
proto_detail_work_thread_t * file_parent
thread instance of the directory reader that spawned us
Definition: proto_detail.h:116
CONF_SECTION * work_io_conf
Easy access to the app_io's config secti.
Definition: proto_detail.h:55
bool immediate
start reading the detail files immediately
Definition: proto_detail.h:95
fr_rb_node_t filename_node
for dedup
Definition: proto_detail.h:99
fr_dict_attr_t const * attr_packet_type
Definition: proto_detail.h:58
char const * directory
containing the file below
Definition: proto_detail.h:84
char const * filename_work
work file name
Definition: proto_detail.h:86
bool paused
Is reading paused?
Definition: proto_detail.h:126
uint32_t max_packet_size
for message ring buffer
Definition: proto_detail.h:61
fr_time_delta_t lock_interval
interval between trying the locks.
Definition: proto_detail.h:122
int count
number of packets we read from this file.
Definition: proto_detail.h:128
bool track_progress
do we track progress by writing?
Definition: proto_detail.h:93
unsigned int last_line
line number of the last record read.
Definition: proto_detail.h:135
bool eof
are we at EOF on reading?
Definition: proto_detail.h:124
bool exit_when_done
Hacked in functionality to allow easy testing of the detail reader.
Definition: proto_detail.h:67
fr_listen_t * listen
talloc_parent() is slow
Definition: proto_detail.h:115
void * work_io_instance
Easy access to the app_io instance.
Definition: proto_detail.h:54
char const * filename
file name, usually with wildcards
Definition: proto_detail.h:85
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:101
char const * name
debug name for printing
Definition: proto_detail.h:107
bool retransmit
are we retransmitting on error?
Definition: proto_detail.h:94
module_instance_t * io_submodule
As provided by the transport_parse callback.
Definition: proto_detail.h:42
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:48
uint16_t max_outstanding
number of packets to run in parallel
Definition: proto_detail.h:91
fr_event_list_t * el
for various timers
Definition: proto_detail.h:113
fr_app_io_t const * work_io
Easy access to the app_io handle.
Definition: proto_detail.h:53
CONF_SECTION * cs
our configuration section
Definition: proto_detail.h:81
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:57
fr_app_io_t const * app_io
Easy access to the app_io handle.
Definition: proto_detail.h:46
fr_schedule_t * sc
the scheduler, where we insert new readers
Definition: proto_detail.h:69
char const * filename_work
work file name
Definition: proto_detail.h:118
module_instance_t * work_submodule
the worker
Definition: proto_detail.h:51
off_t header_offset
offset of the current header we're reading
Definition: proto_detail.h:138
uint32_t poll_interval
interval between polling
Definition: proto_detail.h:88
proto_detail_work_t const * inst
instance data
Definition: proto_detail.h:108
fr_dlist_head_t list
for retransmissions
Definition: proto_detail.h:119
uint32_t code
packet code to use for incoming packets
Definition: proto_detail.h:60
fr_retry_config_t retry_config
retry config with irt, mrt, etc.
Definition: proto_detail.h:90
uint32_t num_messages
for message ring buffer
Definition: proto_detail.h:62
int mode
O_RDWR or O_RDONLY.
Definition: proto_detail.h:97
int fd
file descriptor
Definition: proto_detail.h:110
char const * type
packet type name
Definition: proto_detail.h:40
bool closing
we should be closing the file
Definition: proto_detail.h:125
void * app_io_instance
Easy access to the app_io instance.
Definition: proto_detail.h:47
uint32_t priority
for packet processing, larger == higher
Definition: proto_detail.h:63
int vnode_fd
file descriptor for vnode_delete
Definition: proto_detail.h:111
fr_listen_t * listen
The listener structure which describes the I/O path.
Definition: proto_detail.h:71
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:121
fr_network_t * nr
for Linux-specific callbacks
Definition: proto_detail.h:114
The scheduler.
Definition: schedule.c:125
Module instance data.
Definition: module.h:265
A time delta, a difference in time measured in nanoseconds.
Definition: time.h:80