]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/socket.h
Merge pull request #1989 from keszybz/filetriggers-v2
[thirdparty/systemd.git] / src / core / socket.h
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
26 #include "mount.h"
27 #include "service.h"
28 #include "socket-util.h"
29
30 typedef enum SocketExecCommand {
31 SOCKET_EXEC_START_PRE,
32 SOCKET_EXEC_START_CHOWN,
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,
45 SOCKET_USB_FUNCTION,
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 {
63 Socket *socket;
64
65 SocketType type;
66 int fd;
67 int *auxiliary_fds;
68 int n_auxiliary_fds;
69
70 SocketAddress address;
71 char *path;
72 sd_event_source *event_source;
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;
87 unsigned keep_alive_cnt;
88 usec_t timeout_usec;
89 usec_t keep_alive_time;
90 usec_t keep_alive_interval;
91 usec_t defer_accept;
92
93 ExecCommand* exec_command[_SOCKET_EXEC_COMMAND_MAX];
94 ExecContext exec_context;
95 KillContext kill_context;
96 CGroupContext cgroup_context;
97 ExecRuntime *exec_runtime;
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
106 sd_event_source *timer_event_source;
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
117 char **symlinks;
118
119 bool accept;
120 bool remove_on_stop;
121 bool writable;
122
123 int socket_protocol;
124
125 /* Socket options */
126 bool keep_alive;
127 bool no_delay;
128 bool free_bind;
129 bool transparent;
130 bool broadcast;
131 bool pass_cred;
132 bool pass_sec;
133
134 /* Only for INET6 sockets: issue IPV6_V6ONLY sockopt */
135 SocketAddressBindIPv6Only bind_ipv6_only;
136
137 int priority;
138 int mark;
139 size_t receive_buffer;
140 size_t send_buffer;
141 int ip_tos;
142 int ip_ttl;
143 size_t pipe_size;
144 char *bind_to_device;
145 char *tcp_congestion;
146 bool reuse_port;
147 long mq_maxmsg;
148 long mq_msgsize;
149
150 char *smack;
151 char *smack_ip_in;
152 char *smack_ip_out;
153
154 bool selinux_context_from_net;
155
156 char *user, *group;
157
158 bool reset_cpu_usage:1;
159
160 char *fdname;
161 };
162
163 /* Called from the service code when collecting fds */
164 int socket_collect_fds(Socket *s, int **fds);
165
166 /* Called from the service code when a per-connection service ended */
167 void socket_connection_unref(Socket *s);
168
169 void socket_free_ports(Socket *s);
170
171 int socket_instantiate_service(Socket *s);
172
173 char *socket_fdname(Socket *s);
174
175 extern const UnitVTable socket_vtable;
176
177 const char* socket_exec_command_to_string(SocketExecCommand i) _const_;
178 SocketExecCommand socket_exec_command_from_string(const char *s) _pure_;
179
180 const char* socket_result_to_string(SocketResult i) _const_;
181 SocketResult socket_result_from_string(const char *s) _pure_;
182
183 const char* socket_port_type_to_string(SocketPort *p) _pure_;