The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
channel.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: 7a16a37be93d30cbea40ffa896e9524a815e36da $
20 *
21 * @file io/channel.h
22 * @brief 2-way channels based on kqueue and atomic queues.
23 *
24 * @copyright 2016 Alan DeKok (aland@freeradius.org)
25 */
26RCSIDH(channel_h, "$Id: 7a16a37be93d30cbea40ffa896e9524a815e36da $")
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32#include <freeradius-devel/util/table.h>
33
34/**
35 * A two-way channel (i.e. pipe) for exchanging information
36 *
37 * While the channels are two-way, they are designed to have a
38 * "frontend" writing requests to the channel, and a "worker" reading
39 * requests, and writing replies back to the frontend.
40 */
42
43/*
44 * Forward declaration until such time as we fix the code so that
45 * the network threads can push transports to worker threads.
46 */
47typedef struct fr_listen fr_listen_t;
48
49#ifdef __cplusplus
50}
51#endif
52
53#include <freeradius-devel/io/base.h>
54#include <freeradius-devel/io/control.h>
55#include <freeradius-devel/io/message.h>
56#include <freeradius-devel/util/dlist.h>
57#include <freeradius-devel/util/heap.h>
58#include <freeradius-devel/util/log.h>
59
60#include <sys/types.h>
61#include <sys/event.h>
62
63#ifdef __cplusplus
64extern "C" {
65#endif
66
67#define FR_CONTROL_ID_CHANNEL (1)
68
79
80/** Statistics for the channel
81 *
82 */
83typedef struct {
84 uint64_t outstanding; //!< Number of outstanding requests with no reply.
85 uint64_t signals; //!< Number of kevent signals we've sent.
86 uint64_t resignals; //!< Number of signals resent.
87
88 uint64_t packets; //!< Number of actual data packets.
89
90 uint64_t kevents; //!< Number of times we've looked at kevents.
91
92 fr_time_t last_write; //!< Last write to the channel.
93 fr_time_t last_read_other; //!< Last time we successfully read a message from the other the channel
94 fr_time_delta_t message_interval; //!< Interval between messages.
95
96 fr_time_t last_sent_signal; //!< The last time when we signaled the other end.
98
99
100/**
101 * Channel information which is added to a message.
102 *
103 * The messages are just for exchanging packet data. The channel
104 * data structure is for exchanging requests and replies.
105 */
106typedef struct {
107 fr_message_t m; //!< the message header
108
109 union {
110 /*
111 * Messages have a sequence number / ack while
112 * they're in a channel.
113 */
114 struct {
115 uint64_t sequence; //!< sequence number
116 uint64_t ack; //!< ACK of the sequence number from the other end
117 } live;
118
119 /*
120 * Once messages are pulled out of a channel by
121 * the scheduler, we need to cache the channel
122 * somewhere. So we cache it in fields which are now unused.
123 */
124 struct {
125 fr_channel_t *ch; //!< channel where this messages was received
126 fr_heap_index_t heap_id; //!< for the various queues
127 } channel;
128 };
129
130 union {
131 struct {
132 fr_time_t recv_time; //!< time original request was received (network -> worker)
133 } request;
134
135 struct {
136 fr_time_delta_t cpu_time; //!< Total CPU time, including predicted work, (only worker -> network).
137 fr_time_delta_t processing_time; //!< Actual processing time for this packet (only worker -> network).
138 fr_time_t request_time; //!< Timestamp of the request packet.
139 } reply;
140 };
141
142 uint32_t priority; //!< Priority of this packet.
143
144 void *packet_ctx; //!< Packet specific context for holding client
145 //!< information, and other proto_* specific information
146 //!< that needs to be passed to the request.
147
148 fr_listen_t *listen; //!< for tracking packet transport, etc.
150
151#define PRIORITY_NOW (1 << 16)
152#define PRIORITY_HIGH (1 << 15)
153#define PRIORITY_NORMAL (1 << 14)
154#define PRIORITY_LOW (1 << 13)
155
157extern size_t channel_signals_len;
159extern size_t channel_packet_priority_len;
160
161fr_channel_t *fr_channel_create(TALLOC_CTX *ctx, fr_control_t *frontend, fr_control_t *worker, bool same) CC_HINT(nonnull);
162
165
168
170
171typedef void (*fr_channel_recv_callback_t)(void *ctx, fr_channel_t *ch, fr_channel_data_t *cd);
172int fr_channel_set_recv_reply(fr_channel_t *ch, void *ctx, fr_channel_recv_callback_t recv_reply) CC_HINT(nonnull(1,3));
173int fr_channel_set_recv_request(fr_channel_t *ch, void *ctx, fr_channel_recv_callback_t recv_reply) CC_HINT(nonnull(1,3));
174
176
177int fr_channel_service_kevent(fr_channel_t *ch, fr_control_t *c, struct kevent const *kev) CC_HINT(nonnull);
178fr_channel_event_t fr_channel_service_message(fr_time_t when, fr_channel_t **p_channel, void const *data, size_t data_size) CC_HINT(nonnull);
179
180bool fr_channel_active(fr_channel_t *ch) CC_HINT(nonnull);
181
183
186
187void fr_channel_responder_uctx_add(fr_channel_t *ch, void *ctx) CC_HINT(nonnull);
189void fr_channel_requestor_uctx_add(fr_channel_t *ch, void *ctx) CC_HINT(nonnull);
191
192
193void fr_channel_stats_log(fr_channel_t const *ch, fr_log_t const *log, char const *file, int line);
194
195#ifdef __cplusplus
196}
197#endif
int const char * file
Definition acutest.h:702
int const char int line
Definition acutest.h:702
#define RCSIDH(h, id)
Definition build.h:507
A full channel, which consists of two ends.
Definition channel.c:142
void * fr_channel_requestor_uctx_get(fr_channel_t *ch)
Get network-specific data from a channel.
Definition channel.c:918
fr_message_t m
the message header
Definition channel.h:107
int fr_channel_service_kevent(fr_channel_t *ch, fr_control_t *c, struct kevent const *kev)
void fr_channel_responder_uctx_add(fr_channel_t *ch, void *ctx)
Add responder-specific data to a channel.
Definition channel.c:881
fr_table_num_sorted_t const channel_signals[]
Definition channel.c:151
fr_channel_event_t
Definition channel.h:69
@ FR_CHANNEL_NOOP
Definition channel.h:76
@ FR_CHANNEL_EMPTY
Definition channel.h:77
@ FR_CHANNEL_CLOSE
Definition channel.h:74
@ FR_CHANNEL_ERROR
Definition channel.h:70
@ FR_CHANNEL_DATA_READY_REQUESTOR
Definition channel.h:72
@ FR_CHANNEL_OPEN
Definition channel.h:73
@ FR_CHANNEL_DATA_READY_RESPONDER
Definition channel.h:71
void * packet_ctx
Packet specific context for holding client information, and other proto_* specific information that n...
Definition channel.h:144
bool fr_channel_recv_reply(fr_channel_t *ch)
Receive a reply message from the channel.
Definition channel.c:406
fr_time_delta_t message_interval
Interval between messages.
Definition channel.h:94
int fr_channel_send_request(fr_channel_t *ch, fr_channel_data_t *cm)
Send a request message into the channel.
Definition channel.c:304
size_t channel_signals_len
Definition channel.c:160
fr_listen_t * listen
for tracking packet transport, etc.
Definition channel.h:148
void(* fr_channel_recv_callback_t)(void *ctx, fr_channel_t *ch, fr_channel_data_t *cd)
Definition channel.h:171
size_t channel_packet_priority_len
Definition channel.c:168
uint64_t packets
Number of actual data packets.
Definition channel.h:88
int fr_channel_signal_responder_close(fr_channel_t *ch)
Signal a responder that the channel is closing.
Definition channel.c:822
uint64_t resignals
Number of signals resent.
Definition channel.h:86
fr_table_num_sorted_t const channel_packet_priority[]
Definition channel.c:162
void fr_channel_requestor_uctx_add(fr_channel_t *ch, void *ctx)
Add network-specific data to a channel.
Definition channel.c:906
uint64_t outstanding
Number of outstanding requests with no reply.
Definition channel.h:84
fr_time_t last_sent_signal
The last time when we signaled the other end.
Definition channel.h:96
fr_channel_event_t fr_channel_service_message(fr_time_t when, fr_channel_t **p_channel, void const *data, size_t data_size)
Service a control-plane message.
Definition channel.c:683
fr_time_t last_read_other
Last time we successfully read a message from the other the channel.
Definition channel.h:93
fr_channel_t * fr_channel_create(TALLOC_CTX *ctx, fr_control_t *frontend, fr_control_t *worker, bool same)
Create a new channel.
Definition channel.c:181
int fr_channel_set_recv_request(fr_channel_t *ch, void *ctx, fr_channel_recv_callback_t recv_reply))
Definition channel.c:934
void * fr_channel_responder_uctx_get(fr_channel_t *ch)
Get responder-specific data from a channel.
Definition channel.c:893
bool fr_channel_recv_request(fr_channel_t *ch)
Receive a request message from the channel.
Definition channel.c:470
int fr_channel_null_reply(fr_channel_t *ch)
Don't send a reply message into the channel.
Definition channel.c:622
int fr_channel_set_recv_reply(fr_channel_t *ch, void *ctx, fr_channel_recv_callback_t recv_reply))
Definition channel.c:926
int fr_channel_responder_sleeping(fr_channel_t *ch)
Signal a channel that the responder is sleeping.
Definition channel.c:644
int fr_channel_send_reply(fr_channel_t *ch, fr_channel_data_t *cd)
Send a reply message into the channel.
Definition channel.c:509
void fr_channel_stats_log(fr_channel_t const *ch, fr_log_t const *log, char const *file, int line)
Definition channel.c:959
fr_time_t last_write
Last write to the channel.
Definition channel.h:92
uint32_t priority
Priority of this packet.
Definition channel.h:142
bool fr_channel_active(fr_channel_t *ch)
Check if a channel is active.
Definition channel.c:810
uint64_t kevents
Number of times we've looked at kevents.
Definition channel.h:90
int fr_channel_responder_ack_close(fr_channel_t *ch)
Acknowledge that the channel is closing.
Definition channel.c:852
int fr_channel_signal_open(fr_channel_t *ch)
Send a channel to a responder.
Definition channel.c:948
uint64_t signals
Number of kevent signals we've sent.
Definition channel.h:85
Channel information which is added to a message.
Definition channel.h:106
Statistics for the channel.
Definition channel.h:83
unsigned int fr_heap_index_t
Definition heap.h:80
The control structure.
Definition control.c:76
unsigned int uint32_t
Definition log.h:93
An element in a lexicographically sorted array of name to num mappings.
Definition table.h:49
A time delta, a difference in time measured in nanoseconds.
Definition time.h:80
"server local" time.
Definition time.h:69
static fr_slen_t data
Definition value.h:1340
int nonnull(2, 5))