]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
c2f1db8f | 2 | #pragma once |
5cb5a6ff | 3 | |
a7334b09 LP |
4 | /*** |
5 | This file is part of systemd. | |
6 | ||
7 | Copyright 2010 Lennart Poettering | |
8 | ||
9 | systemd is free software; you can redistribute it and/or modify it | |
5430f7f2 LP |
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 | |
a7334b09 LP |
12 | (at your option) any later version. |
13 | ||
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 | |
5430f7f2 | 17 | Lesser General Public License for more details. |
a7334b09 | 18 | |
5430f7f2 | 19 | You should have received a copy of the GNU Lesser General Public License |
a7334b09 LP |
20 | along with systemd; If not, see <http://www.gnu.org/licenses/>. |
21 | ***/ | |
22 | ||
5cb5a6ff | 23 | typedef struct Socket Socket; |
9d565427 | 24 | typedef struct SocketPeer SocketPeer; |
5cb5a6ff | 25 | |
6e2ef85b | 26 | #include "mount.h" |
57020a3a | 27 | #include "service.h" |
71d35b6b | 28 | #include "socket-util.h" |
5cb5a6ff | 29 | |
5cb5a6ff LP |
30 | typedef enum SocketExecCommand { |
31 | SOCKET_EXEC_START_PRE, | |
3900e5fd | 32 | SOCKET_EXEC_START_CHOWN, |
5cb5a6ff LP |
33 | SOCKET_EXEC_START_POST, |
34 | SOCKET_EXEC_STOP_PRE, | |
35 | SOCKET_EXEC_STOP_POST, | |
e537352b LP |
36 | _SOCKET_EXEC_COMMAND_MAX, |
37 | _SOCKET_EXEC_COMMAND_INVALID = -1 | |
5cb5a6ff LP |
38 | } SocketExecCommand; |
39 | ||
542563ba LP |
40 | typedef enum SocketType { |
41 | SOCKET_SOCKET, | |
e537352b | 42 | SOCKET_FIFO, |
b0a3f2bc | 43 | SOCKET_SPECIAL, |
916abb21 | 44 | SOCKET_MQUEUE, |
60252446 | 45 | SOCKET_USB_FUNCTION, |
e537352b LP |
46 | _SOCKET_FIFO_MAX, |
47 | _SOCKET_FIFO_INVALID = -1 | |
542563ba LP |
48 | } SocketType; |
49 | ||
cfc4eb4c LP |
50 | typedef enum SocketResult { |
51 | SOCKET_SUCCESS, | |
52 | SOCKET_FAILURE_RESOURCES, | |
53 | SOCKET_FAILURE_TIMEOUT, | |
54 | SOCKET_FAILURE_EXIT_CODE, | |
55 | SOCKET_FAILURE_SIGNAL, | |
56 | SOCKET_FAILURE_CORE_DUMP, | |
07299350 | 57 | SOCKET_FAILURE_START_LIMIT_HIT, |
8b26cdbd | 58 | SOCKET_FAILURE_TRIGGER_LIMIT_HIT, |
6bf0f408 | 59 | SOCKET_FAILURE_SERVICE_START_LIMIT_HIT, |
cfc4eb4c LP |
60 | _SOCKET_RESULT_MAX, |
61 | _SOCKET_RESULT_INVALID = -1 | |
62 | } SocketResult; | |
63 | ||
01f78473 | 64 | typedef struct SocketPort { |
718db961 LP |
65 | Socket *socket; |
66 | ||
542563ba | 67 | SocketType type; |
9d58f1db | 68 | int fd; |
15087cdb PS |
69 | int *auxiliary_fds; |
70 | int n_auxiliary_fds; | |
542563ba LP |
71 | |
72 | SocketAddress address; | |
73 | char *path; | |
718db961 | 74 | sd_event_source *event_source; |
542563ba | 75 | |
01f78473 LP |
76 | LIST_FIELDS(struct SocketPort, port); |
77 | } SocketPort; | |
542563ba | 78 | |
5cb5a6ff | 79 | struct Socket { |
ac155bb8 | 80 | Unit meta; |
5cb5a6ff | 81 | |
542563ba LP |
82 | LIST_HEAD(SocketPort, ports); |
83 | ||
9a73653c | 84 | Set *peers_by_address; |
9d565427 | 85 | |
7fab9d01 LP |
86 | unsigned n_accepted; |
87 | unsigned n_connections; | |
88 | unsigned max_connections; | |
9d565427 | 89 | unsigned max_connections_per_source; |
7fab9d01 | 90 | |
542563ba | 91 | unsigned backlog; |
209e9dcd | 92 | unsigned keep_alive_cnt; |
034c6ed7 | 93 | usec_t timeout_usec; |
209e9dcd SS |
94 | usec_t keep_alive_time; |
95 | usec_t keep_alive_interval; | |
cc567c9b | 96 | usec_t defer_accept; |
034c6ed7 | 97 | |
e537352b | 98 | ExecCommand* exec_command[_SOCKET_EXEC_COMMAND_MAX]; |
5cb5a6ff | 99 | ExecContext exec_context; |
4819ff03 | 100 | KillContext kill_context; |
4ad49000 | 101 | CGroupContext cgroup_context; |
29206d46 | 102 | |
613b411c | 103 | ExecRuntime *exec_runtime; |
29206d46 | 104 | DynamicCreds dynamic_creds; |
5cb5a6ff | 105 | |
b15bdda8 LP |
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. */ | |
57020a3a | 109 | UnitRef service; |
034c6ed7 | 110 | |
a16e1123 | 111 | SocketState state, deserialized_state; |
034c6ed7 | 112 | |
718db961 | 113 | sd_event_source *timer_event_source; |
7fab9d01 | 114 | |
034c6ed7 | 115 | ExecCommand* control_command; |
a16e1123 | 116 | SocketExecCommand control_command_id; |
5cb5a6ff LP |
117 | pid_t control_pid; |
118 | ||
7fab9d01 LP |
119 | mode_t directory_mode; |
120 | mode_t socket_mode; | |
4f2d528d | 121 | |
cfc4eb4c | 122 | SocketResult result; |
7fab9d01 | 123 | |
811ba7a0 LP |
124 | char **symlinks; |
125 | ||
7fab9d01 | 126 | bool accept; |
bd1fe7c7 | 127 | bool remove_on_stop; |
55301ec0 | 128 | bool writable; |
4fd5948e | 129 | |
74bb646e SS |
130 | int socket_protocol; |
131 | ||
4fd5948e LP |
132 | /* Socket options */ |
133 | bool keep_alive; | |
4427c3f4 | 134 | bool no_delay; |
7fab9d01 | 135 | bool free_bind; |
6b6d2dee | 136 | bool transparent; |
ec6370a2 | 137 | bool broadcast; |
d68af586 | 138 | bool pass_cred; |
54ecda32 | 139 | bool pass_sec; |
68667801 ZJS |
140 | |
141 | /* Only for INET6 sockets: issue IPV6_V6ONLY sockopt */ | |
142 | SocketAddressBindIPv6Only bind_ipv6_only; | |
143 | ||
4fd5948e | 144 | int priority; |
7fab9d01 | 145 | int mark; |
4fd5948e LP |
146 | size_t receive_buffer; |
147 | size_t send_buffer; | |
148 | int ip_tos; | |
149 | int ip_ttl; | |
150 | size_t pipe_size; | |
4fd5948e | 151 | char *bind_to_device; |
cebf8b20 | 152 | char *tcp_congestion; |
718db961 | 153 | bool reuse_port; |
916abb21 LP |
154 | long mq_maxmsg; |
155 | long mq_msgsize; | |
57020a3a | 156 | |
0eb59ccf AK |
157 | char *smack; |
158 | char *smack_ip_in; | |
159 | char *smack_ip_out; | |
3900e5fd | 160 | |
16115b0a MS |
161 | bool selinux_context_from_net; |
162 | ||
3900e5fd | 163 | char *user, *group; |
5ad096b3 | 164 | |
906c06f6 | 165 | bool reset_accounting:1; |
8dd4c05b LP |
166 | |
167 | char *fdname; | |
8b26cdbd LP |
168 | |
169 | RateLimit trigger_limit; | |
5cb5a6ff LP |
170 | }; |
171 | ||
9d565427 SS |
172 | SocketPeer *socket_peer_ref(SocketPeer *p); |
173 | SocketPeer *socket_peer_unref(SocketPeer *p); | |
3ebcd323 | 174 | int socket_acquire_peer(Socket *s, int fd, SocketPeer **p); |
9d565427 SS |
175 | |
176 | DEFINE_TRIVIAL_CLEANUP_FUNC(SocketPeer*, socket_peer_unref); | |
177 | ||
44d8db9e | 178 | /* Called from the service code when collecting fds */ |
79c7626d | 179 | int socket_collect_fds(Socket *s, int **fds); |
44d8db9e | 180 | |
6cf6bbc2 LP |
181 | /* Called from the service code when a per-connection service ended */ |
182 | void socket_connection_unref(Socket *s); | |
183 | ||
74051b9b LP |
184 | void socket_free_ports(Socket *s); |
185 | ||
8dd4c05b LP |
186 | int socket_instantiate_service(Socket *s); |
187 | ||
188 | char *socket_fdname(Socket *s); | |
189 | ||
87f0e418 | 190 | extern const UnitVTable socket_vtable; |
5cb5a6ff | 191 | |
44a6b1b6 ZJS |
192 | const char* socket_exec_command_to_string(SocketExecCommand i) _const_; |
193 | SocketExecCommand socket_exec_command_from_string(const char *s) _pure_; | |
a16e1123 | 194 | |
44a6b1b6 ZJS |
195 | const char* socket_result_to_string(SocketResult i) _const_; |
196 | SocketResult socket_result_from_string(const char *s) _pure_; | |
67419600 | 197 | |
44a6b1b6 | 198 | const char* socket_port_type_to_string(SocketPort *p) _pure_; |