1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 This file is part of systemd.
7 Copyright 2010 Lennart Poettering
9 systemd is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
14 systemd is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public License
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
23 typedef struct Socket Socket
;
24 typedef struct SocketPeer SocketPeer
;
28 #include "socket-util.h"
30 typedef enum SocketExecCommand
{
31 SOCKET_EXEC_START_PRE
,
32 SOCKET_EXEC_START_CHOWN
,
33 SOCKET_EXEC_START_POST
,
35 SOCKET_EXEC_STOP_POST
,
36 _SOCKET_EXEC_COMMAND_MAX
,
37 _SOCKET_EXEC_COMMAND_INVALID
= -1
40 typedef enum SocketType
{
47 _SOCKET_FIFO_INVALID
= -1
50 typedef enum SocketResult
{
52 SOCKET_FAILURE_RESOURCES
,
53 SOCKET_FAILURE_TIMEOUT
,
54 SOCKET_FAILURE_EXIT_CODE
,
55 SOCKET_FAILURE_SIGNAL
,
56 SOCKET_FAILURE_CORE_DUMP
,
57 SOCKET_FAILURE_START_LIMIT_HIT
,
58 SOCKET_FAILURE_TRIGGER_LIMIT_HIT
,
59 SOCKET_FAILURE_SERVICE_START_LIMIT_HIT
,
61 _SOCKET_RESULT_INVALID
= -1
64 typedef struct SocketPort
{
72 SocketAddress address
;
74 sd_event_source
*event_source
;
76 LIST_FIELDS(struct SocketPort
, port
);
82 LIST_HEAD(SocketPort
, ports
);
84 Set
*peers_by_address
;
87 unsigned n_connections
;
88 unsigned max_connections
;
89 unsigned max_connections_per_source
;
92 unsigned keep_alive_cnt
;
94 usec_t keep_alive_time
;
95 usec_t keep_alive_interval
;
98 ExecCommand
* exec_command
[_SOCKET_EXEC_COMMAND_MAX
];
99 ExecContext exec_context
;
100 KillContext kill_context
;
101 CGroupContext cgroup_context
;
103 ExecRuntime
*exec_runtime
;
104 DynamicCreds dynamic_creds
;
106 /* For Accept=no sockets refers to the one service we'll
107 activate. For Accept=yes sockets is either NULL, or filled
108 when the next service we spawn. */
111 SocketState state
, deserialized_state
;
113 sd_event_source
*timer_event_source
;
115 ExecCommand
* control_command
;
116 SocketExecCommand control_command_id
;
119 mode_t directory_mode
;
141 /* Only for INET6 sockets: issue IPV6_V6ONLY sockopt */
142 SocketAddressBindIPv6Only bind_ipv6_only
;
146 size_t receive_buffer
;
151 char *bind_to_device
;
152 char *tcp_congestion
;
161 bool selinux_context_from_net
;
165 bool reset_accounting
:1;
169 RateLimit trigger_limit
;
172 SocketPeer
*socket_peer_ref(SocketPeer
*p
);
173 SocketPeer
*socket_peer_unref(SocketPeer
*p
);
174 int socket_acquire_peer(Socket
*s
, int fd
, SocketPeer
**p
);
176 DEFINE_TRIVIAL_CLEANUP_FUNC(SocketPeer
*, socket_peer_unref
);
178 /* Called from the service code when collecting fds */
179 int socket_collect_fds(Socket
*s
, int **fds
);
181 /* Called from the service code when a per-connection service ended */
182 void socket_connection_unref(Socket
*s
);
184 void socket_free_ports(Socket
*s
);
186 int socket_instantiate_service(Socket
*s
);
188 char *socket_fdname(Socket
*s
);
190 extern const UnitVTable socket_vtable
;
192 const char* socket_exec_command_to_string(SocketExecCommand i
) _const_
;
193 SocketExecCommand
socket_exec_command_from_string(const char *s
) _pure_
;
195 const char* socket_result_to_string(SocketResult i
) _const_
;
196 SocketResult
socket_result_from_string(const char *s
) _pure_
;
198 const char* socket_port_type_to_string(SocketPort
*p
) _pure_
;