]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/core/socket.h
Merge pull request #2561 from msekletar/virtio-blk-by-path
[thirdparty/systemd.git] / src / core / socket.h
CommitLineData
03467c88 1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
5cb5a6ff 2
c2f1db8f 3#pragma once
5cb5a6ff 4
a7334b09
LP
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
5430f7f2
LP
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
a7334b09
LP
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
5430f7f2 18 Lesser General Public License for more details.
a7334b09 19
5430f7f2 20 You should have received a copy of the GNU Lesser General Public License
a7334b09
LP
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22***/
23
5cb5a6ff
LP
24typedef struct Socket Socket;
25
6e2ef85b 26#include "mount.h"
57020a3a 27#include "service.h"
71d35b6b 28#include "socket-util.h"
5cb5a6ff 29
5cb5a6ff
LP
30typedef 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
40typedef 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
50typedef 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,
6bda96a0 57 SOCKET_FAILURE_SERVICE_FAILED_PERMANENT,
cfc4eb4c
LP
58 _SOCKET_RESULT_MAX,
59 _SOCKET_RESULT_INVALID = -1
60} SocketResult;
61
01f78473 62typedef struct SocketPort {
718db961
LP
63 Socket *socket;
64
542563ba 65 SocketType type;
9d58f1db 66 int fd;
15087cdb
PS
67 int *auxiliary_fds;
68 int n_auxiliary_fds;
542563ba
LP
69
70 SocketAddress address;
71 char *path;
718db961 72 sd_event_source *event_source;
542563ba 73
01f78473
LP
74 LIST_FIELDS(struct SocketPort, port);
75} SocketPort;
542563ba 76
5cb5a6ff 77struct Socket {
ac155bb8 78 Unit meta;
5cb5a6ff 79
542563ba
LP
80 LIST_HEAD(SocketPort, ports);
81
7fab9d01
LP
82 unsigned n_accepted;
83 unsigned n_connections;
84 unsigned max_connections;
85
542563ba 86 unsigned backlog;
209e9dcd 87 unsigned keep_alive_cnt;
034c6ed7 88 usec_t timeout_usec;
209e9dcd
SS
89 usec_t keep_alive_time;
90 usec_t keep_alive_interval;
cc567c9b 91 usec_t defer_accept;
034c6ed7 92
e537352b 93 ExecCommand* exec_command[_SOCKET_EXEC_COMMAND_MAX];
5cb5a6ff 94 ExecContext exec_context;
4819ff03 95 KillContext kill_context;
4ad49000 96 CGroupContext cgroup_context;
613b411c 97 ExecRuntime *exec_runtime;
5cb5a6ff 98
b15bdda8
LP
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. */
57020a3a 102 UnitRef service;
034c6ed7 103
a16e1123 104 SocketState state, deserialized_state;
034c6ed7 105
718db961 106 sd_event_source *timer_event_source;
7fab9d01 107
034c6ed7 108 ExecCommand* control_command;
a16e1123 109 SocketExecCommand control_command_id;
5cb5a6ff
LP
110 pid_t control_pid;
111
7fab9d01
LP
112 mode_t directory_mode;
113 mode_t socket_mode;
4f2d528d 114
cfc4eb4c 115 SocketResult result;
7fab9d01 116
811ba7a0
LP
117 char **symlinks;
118
7fab9d01 119 bool accept;
bd1fe7c7 120 bool remove_on_stop;
55301ec0 121 bool writable;
4fd5948e 122
74bb646e
SS
123 int socket_protocol;
124
4fd5948e
LP
125 /* Socket options */
126 bool keep_alive;
4427c3f4 127 bool no_delay;
7fab9d01 128 bool free_bind;
6b6d2dee 129 bool transparent;
ec6370a2 130 bool broadcast;
d68af586 131 bool pass_cred;
54ecda32 132 bool pass_sec;
68667801
ZJS
133
134 /* Only for INET6 sockets: issue IPV6_V6ONLY sockopt */
135 SocketAddressBindIPv6Only bind_ipv6_only;
136
4fd5948e 137 int priority;
7fab9d01 138 int mark;
4fd5948e
LP
139 size_t receive_buffer;
140 size_t send_buffer;
141 int ip_tos;
142 int ip_ttl;
143 size_t pipe_size;
4fd5948e 144 char *bind_to_device;
cebf8b20 145 char *tcp_congestion;
718db961 146 bool reuse_port;
916abb21
LP
147 long mq_maxmsg;
148 long mq_msgsize;
57020a3a 149
0eb59ccf
AK
150 char *smack;
151 char *smack_ip_in;
152 char *smack_ip_out;
3900e5fd 153
16115b0a
MS
154 bool selinux_context_from_net;
155
3900e5fd 156 char *user, *group;
5ad096b3
LP
157
158 bool reset_cpu_usage:1;
8dd4c05b
LP
159
160 char *fdname;
5cb5a6ff
LP
161};
162
44d8db9e 163/* Called from the service code when collecting fds */
79c7626d 164int socket_collect_fds(Socket *s, int **fds);
44d8db9e 165
6cf6bbc2
LP
166/* Called from the service code when a per-connection service ended */
167void socket_connection_unref(Socket *s);
168
74051b9b
LP
169void socket_free_ports(Socket *s);
170
8dd4c05b
LP
171int socket_instantiate_service(Socket *s);
172
173char *socket_fdname(Socket *s);
174
87f0e418 175extern const UnitVTable socket_vtable;
5cb5a6ff 176
44a6b1b6
ZJS
177const char* socket_exec_command_to_string(SocketExecCommand i) _const_;
178SocketExecCommand socket_exec_command_from_string(const char *s) _pure_;
a16e1123 179
44a6b1b6
ZJS
180const char* socket_result_to_string(SocketResult i) _const_;
181SocketResult socket_result_from_string(const char *s) _pure_;
67419600 182
44a6b1b6 183const char* socket_port_type_to_string(SocketPort *p) _pure_;