]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/socket.h
core: add support for naming file descriptors passed using socket activation
[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 "socket-util.h"
27 #include "mount.h"
28 #include "service.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 /* Socket options */
124 bool keep_alive;
125 bool no_delay;
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;
144 bool reuse_port;
145 long mq_maxmsg;
146 long mq_msgsize;
147
148 char *smack;
149 char *smack_ip_in;
150 char *smack_ip_out;
151
152 bool selinux_context_from_net;
153
154 char *user, *group;
155
156 bool reset_cpu_usage:1;
157
158 char *fdname;
159 };
160
161 /* Called from the service code when collecting fds */
162 int socket_collect_fds(Socket *s, int **fds);
163
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
169 int socket_instantiate_service(Socket *s);
170
171 char *socket_fdname(Socket *s);
172
173 extern const UnitVTable socket_vtable;
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_;