The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
control.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: 80ca73676a48929faf5e63b11028c0bae052dd6b $
20 *
21 * @file io/control.h
22 * @brief control-plane signaling
23 *
24 * @copyright 2016 Alan DeKok (aland@freeradius.org)
25 */
26RCSIDH(control_h, "$Id: 80ca73676a48929faf5e63b11028c0bae052dd6b $")
27
28#include <freeradius-devel/util/time.h>
29#include <freeradius-devel/util/event.h>
30
31#include <sys/types.h>
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37/**
38 * A one-way control plane.
39 *
40 * Multiple-producer, single consumer. Messages are copied into a
41 * queue the receiver owns, and a byte on a unix socket wakes the
42 * receiver. When the socket is full the reader has wakeups it has
43 * not consumed, so further bytes are not needed.
44 */
46typedef void (*fr_control_callback_t)(void const *data, size_t data_size, fr_time_t now, void *uctx);
47
48/** A callback for a message which carries a socket
49 *
50 * The callback owns the socket and must close it. The descriptor
51 * number is a new one, not the sender's.
52 */
53typedef void (*fr_control_socket_callback_t)(int sock, fr_time_t now, void *uctx);
54
55/** Who defines control plane events
56 *
57 * Each event set has its own dispatch table on every control, and
58 * numbers its own events from zero. A message is addressed by
59 * event set and event, so the code behind one set never needs to
60 * know what any other set registered.
61 */
63 FR_CONTROL_EVENTSET_NETWORK = 0, //!< Events the network defines.
64 FR_CONTROL_EVENTSET_WORKER, //!< Events a worker defines.
65 FR_CONTROL_EVENTSET_CHANNEL, //!< Events channels define.
66 FR_CONTROL_EVENTSET_COORD, //!< Events the coordinator defines.
69
70/*
71 * Defaults for the number of messages a control plane can hold
72 * unread, and the largest message it accepts. A message and its
73 * header fit two to a cache line in the receiver's queue.
74 */
75#define FR_CONTROL_MAX_MESSAGES (1024)
76#define FR_CONTROL_MAX_SIZE (48)
77
79
81
83 void const *data, size_t data_size) CC_HINT(nonnull);
85
87 fr_control_callback_t callback, void *uctx) CC_HINT(nonnull(1,4));
89 fr_control_socket_callback_t callback, void *uctx) CC_HINT(nonnull(1,4));
92
94
96void fr_control_awake(fr_control_t *c) CC_HINT(nonnull);
98
99void fr_control_wait(fr_control_t *c) CC_HINT(nonnull);
100
101#ifdef __cplusplus
102}
103#endif
#define RCSIDH(h, id)
Definition build.h:604
fr_control_eventset_t
Who defines control plane events.
Definition control.h:62
@ FR_CONTROL_EVENTSET_MAX
Definition control.h:67
@ FR_CONTROL_EVENTSET_WORKER
Events a worker defines.
Definition control.h:64
@ FR_CONTROL_EVENTSET_COORD
Events the coordinator defines.
Definition control.h:66
@ FR_CONTROL_EVENTSET_CHANNEL
Events channels define.
Definition control.h:65
@ FR_CONTROL_EVENTSET_NETWORK
Events the network defines.
Definition control.h:63
bool fr_control_sleeping(fr_control_t *c)
Record that the reader of this control plane is about to block.
Definition control.c:843
void fr_control_awake(fr_control_t *c)
Record that the reader of this control plane is running again.
Definition control.c:860
void(* fr_control_socket_callback_t)(int sock, fr_time_t now, void *uctx)
A callback for a message which carries a socket.
Definition control.h:53
bool fr_control_is_sleeping(fr_control_t *c)
Check whether the reader of this control plane is blocked.
Definition control.c:875
int fr_control_open(fr_control_t *c)
Open the control-plane signalling path.
Definition control.c:446
fr_control_t * fr_control_create(TALLOC_CTX *ctx, fr_event_list_t *el, uint16_t slots, uint16_t max_size)
Create a control-plane signaling path.
Definition control.c:427
int fr_control_callback_add(fr_control_t *c, fr_control_eventset_t es, uint16_t ev, fr_control_callback_t callback, void *uctx))
Register a callback for a message.
Definition control.c:659
void(* fr_control_callback_t)(void const *data, size_t data_size, fr_time_t now, void *uctx)
Definition control.h:46
int fr_control_socket_callback_delete(fr_control_t *c, fr_control_eventset_t es, uint16_t ev)
Delete a callback for a message which carries a socket.
Definition control.c:813
int fr_control_socket_send(fr_control_t *c, fr_control_eventset_t es, uint16_t ev, int sock)
Send a control-plane message carrying a socket.
Definition control.c:604
int fr_control_callback_delete(fr_control_t *c, fr_control_eventset_t es, uint16_t ev)
Delete a callback for a message.
Definition control.c:786
int fr_control_message_send(fr_control_t *c, fr_control_eventset_t es, uint16_t ev, void const *data, size_t data_size)
Send a control-plane message.
Definition control.c:544
int fr_control_same_thread(fr_control_t *c)
Definition control.c:881
int fr_control_socket_callback_add(fr_control_t *c, fr_control_eventset_t es, uint16_t ev, fr_control_socket_callback_t callback, void *uctx))
Register a callback for a message which carries a socket.
Definition control.c:727
void fr_control_wait(fr_control_t *c)
Wait for a plane control to become readable.
Definition control.c:903
uint16_t max_size
the largest payload a message may carry.
Definition control.c:215
uint16_t slots
messages the queue holds unread.
Definition control.c:214
The control structure.
Definition control.c:211
Stores all information relating to an event list.
Definition event.c:375
unsigned short uint16_t
"server local" time.
Definition time.h:69
static fr_event_list_t * el
static fr_slen_t data
Definition value.h:1366
int nonnull(2, 5))