]>
Commit | Line | Data |
---|---|---|
663996b3 MS |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
3 | #pragma once | |
4 | ||
5 | /*** | |
6 | This file is part of systemd. | |
7 | ||
8 | Copyright 2010 Lennart Poettering | |
9 | ||
10 | systemd is free software; you can redistribute it and/or modify it | |
11 | under the terms of the GNU Lesser General Public License as published by | |
12 | the Free Software Foundation; either version 2.1 of the License, or | |
13 | (at your option) any later version. | |
14 | ||
15 | systemd is distributed in the hope that it will be useful, but | |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 | Lesser General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU Lesser General Public License | |
21 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
22 | ***/ | |
23 | ||
24 | typedef struct Socket Socket; | |
25 | ||
663996b3 MS |
26 | #include "socket-util.h" |
27 | #include "mount.h" | |
28 | #include "service.h" | |
29 | ||
663996b3 MS |
30 | typedef enum SocketExecCommand { |
31 | SOCKET_EXEC_START_PRE, | |
60f067b4 | 32 | SOCKET_EXEC_START_CHOWN, |
663996b3 MS |
33 | SOCKET_EXEC_START_POST, |
34 | SOCKET_EXEC_STOP_PRE, | |
35 | SOCKET_EXEC_STOP_POST, | |
36 | _SOCKET_EXEC_COMMAND_MAX, | |
37 | _SOCKET_EXEC_COMMAND_INVALID = -1 | |
38 | } SocketExecCommand; | |
39 | ||
40 | typedef enum SocketType { | |
41 | SOCKET_SOCKET, | |
42 | SOCKET_FIFO, | |
43 | SOCKET_SPECIAL, | |
44 | SOCKET_MQUEUE, | |
6300502b | 45 | SOCKET_USB_FUNCTION, |
663996b3 MS |
46 | _SOCKET_FIFO_MAX, |
47 | _SOCKET_FIFO_INVALID = -1 | |
48 | } SocketType; | |
49 | ||
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, | |
57 | SOCKET_FAILURE_SERVICE_FAILED_PERMANENT, | |
58 | _SOCKET_RESULT_MAX, | |
59 | _SOCKET_RESULT_INVALID = -1 | |
60 | } SocketResult; | |
61 | ||
62 | typedef struct SocketPort { | |
60f067b4 JS |
63 | Socket *socket; |
64 | ||
663996b3 MS |
65 | SocketType type; |
66 | int fd; | |
6300502b MP |
67 | int *auxiliary_fds; |
68 | int n_auxiliary_fds; | |
663996b3 MS |
69 | |
70 | SocketAddress address; | |
71 | char *path; | |
60f067b4 | 72 | sd_event_source *event_source; |
663996b3 MS |
73 | |
74 | LIST_FIELDS(struct SocketPort, port); | |
75 | } SocketPort; | |
76 | ||
77 | struct Socket { | |
78 | Unit meta; | |
79 | ||
80 | LIST_HEAD(SocketPort, ports); | |
81 | ||
82 | unsigned n_accepted; | |
83 | unsigned n_connections; | |
84 | unsigned max_connections; | |
85 | ||
86 | unsigned backlog; | |
5eef597e | 87 | unsigned keep_alive_cnt; |
663996b3 | 88 | usec_t timeout_usec; |
5eef597e MP |
89 | usec_t keep_alive_time; |
90 | usec_t keep_alive_interval; | |
91 | usec_t defer_accept; | |
663996b3 MS |
92 | |
93 | ExecCommand* exec_command[_SOCKET_EXEC_COMMAND_MAX]; | |
94 | ExecContext exec_context; | |
95 | KillContext kill_context; | |
14228c0d | 96 | CGroupContext cgroup_context; |
60f067b4 | 97 | ExecRuntime *exec_runtime; |
663996b3 MS |
98 | |
99 | /* For Accept=no sockets refers to the one service we'll | |
100 | activate. For Accept=yes sockets is either NULL, or filled | |
101 | when the next service we spawn. */ | |
102 | UnitRef service; | |
103 | ||
104 | SocketState state, deserialized_state; | |
105 | ||
60f067b4 | 106 | sd_event_source *timer_event_source; |
663996b3 MS |
107 | |
108 | ExecCommand* control_command; | |
109 | SocketExecCommand control_command_id; | |
110 | pid_t control_pid; | |
111 | ||
112 | mode_t directory_mode; | |
113 | mode_t socket_mode; | |
114 | ||
115 | SocketResult result; | |
116 | ||
60f067b4 JS |
117 | char **symlinks; |
118 | ||
663996b3 | 119 | bool accept; |
60f067b4 | 120 | bool remove_on_stop; |
6300502b | 121 | bool writable; |
663996b3 MS |
122 | |
123 | /* Socket options */ | |
124 | bool keep_alive; | |
5eef597e | 125 | bool no_delay; |
663996b3 MS |
126 | bool free_bind; |
127 | bool transparent; | |
128 | bool broadcast; | |
129 | bool pass_cred; | |
130 | bool pass_sec; | |
131 | ||
132 | /* Only for INET6 sockets: issue IPV6_V6ONLY sockopt */ | |
133 | SocketAddressBindIPv6Only bind_ipv6_only; | |
134 | ||
135 | int priority; | |
136 | int mark; | |
137 | size_t receive_buffer; | |
138 | size_t send_buffer; | |
139 | int ip_tos; | |
140 | int ip_ttl; | |
141 | size_t pipe_size; | |
142 | char *bind_to_device; | |
143 | char *tcp_congestion; | |
60f067b4 | 144 | bool reuse_port; |
663996b3 MS |
145 | long mq_maxmsg; |
146 | long mq_msgsize; | |
147 | ||
148 | char *smack; | |
149 | char *smack_ip_in; | |
150 | char *smack_ip_out; | |
60f067b4 | 151 | |
5eef597e MP |
152 | bool selinux_context_from_net; |
153 | ||
60f067b4 | 154 | char *user, *group; |
e3bff60a MP |
155 | |
156 | bool reset_cpu_usage:1; | |
6300502b MP |
157 | |
158 | char *fdname; | |
663996b3 MS |
159 | }; |
160 | ||
161 | /* Called from the service code when collecting fds */ | |
6300502b | 162 | int socket_collect_fds(Socket *s, int **fds); |
663996b3 | 163 | |
663996b3 MS |
164 | /* Called from the service code when a per-connection service ended */ |
165 | void socket_connection_unref(Socket *s); | |
166 | ||
167 | void socket_free_ports(Socket *s); | |
168 | ||
6300502b | 169 | int socket_instantiate_service(Socket *s); |
663996b3 | 170 | |
6300502b MP |
171 | char *socket_fdname(Socket *s); |
172 | ||
173 | extern const UnitVTable socket_vtable; | |
663996b3 MS |
174 | |
175 | const char* socket_exec_command_to_string(SocketExecCommand i) _const_; | |
176 | SocketExecCommand socket_exec_command_from_string(const char *s) _pure_; | |
177 | ||
178 | const char* socket_result_to_string(SocketResult i) _const_; | |
179 | SocketResult socket_result_from_string(const char *s) _pure_; | |
180 | ||
181 | const char* socket_port_type_to_string(SocketPort *p) _pure_; |