socket.h revision 8b835fccdad78d89f9cc64f9b02059fb75ffbab1
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek#pragma once
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek/***
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek This file is part of systemd.
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek Copyright 2010 Lennart Poettering
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek systemd is free software; you can redistribute it and/or modify it
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek under the terms of the GNU Lesser General Public License as published by
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek the Free Software Foundation; either version 2.1 of the License, or
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek (at your option) any later version.
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek systemd is distributed in the hope that it will be useful, but
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek WITHOUT ANY WARRANTY; without even the implied warranty of
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek Lesser General Public License for more details.
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek You should have received a copy of the GNU Lesser General Public License
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek along with systemd; If not, see <http://www.gnu.org/licenses/>.
24882e06c135584f16f31ba8a00fecde8b7f6fadLennart Poettering***/
24882e06c135584f16f31ba8a00fecde8b7f6fadLennart Poettering
24882e06c135584f16f31ba8a00fecde8b7f6fadLennart Poetteringtypedef struct Socket Socket;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering#include "manager.h"
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering#include "unit.h"
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering#include "socket-util.h"
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering#include "mount.h"
24882e06c135584f16f31ba8a00fecde8b7f6fadLennart Poettering#include "service.h"
b4bbcaa9c44260e88402cb8f9a5fb8ac7f35e123Thomas Hindoe Paaboel Andersen
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poetteringtypedef enum SocketState {
74df0fca09b3c31ed19e14ba80f996fdff772417Lennart Poettering SOCKET_DEAD,
74df0fca09b3c31ed19e14ba80f996fdff772417Lennart Poettering SOCKET_START_PRE,
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering SOCKET_START_CHOWN,
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering SOCKET_START_POST,
b5efdb8af40ea759a1ea584c1bc44ecc81dd00ceLennart Poettering SOCKET_LISTENING,
430f0182b72373145c839dbfe99d2382855cb8f8Lennart Poettering SOCKET_RUNNING,
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek SOCKET_STOP_PRE,
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek SOCKET_STOP_PRE_SIGTERM,
a09561746f15b84da9471b5c4be74e53d19e4f3fLennart Poettering SOCKET_STOP_PRE_SIGKILL,
0dec689b098cf62b948d43dc78bde859665056ecTom Gundersen SOCKET_STOP_POST,
3ffd4af22052963e7a29431721ee204e634bea75Lennart Poettering SOCKET_FINAL_SIGTERM,
33d52ab92f2f0bfd706e6f343d172618d1e03f3dLennart Poettering SOCKET_FINAL_SIGKILL,
958b66ea16deddd794b3a52643bd44633e165eadLennart Poettering SOCKET_FAILED,
f4f15635ec05293ffcc83a5b39f624bbabbd8fd0Lennart Poettering _SOCKET_STATE_MAX,
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering _SOCKET_STATE_INVALID = -1
958b66ea16deddd794b3a52643bd44633e165eadLennart Poettering} SocketState;
afc5dbf37fd2399d37976388d9dd9ab470ecf446Lennart Poettering
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poetteringtypedef enum SocketExecCommand {
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering SOCKET_EXEC_START_PRE,
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek SOCKET_EXEC_START_CHOWN,
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek SOCKET_EXEC_START_POST,
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering SOCKET_EXEC_STOP_PRE,
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek SOCKET_EXEC_STOP_POST,
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek _SOCKET_EXEC_COMMAND_MAX,
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering _SOCKET_EXEC_COMMAND_INVALID = -1
3ffd4af22052963e7a29431721ee204e634bea75Lennart Poettering} SocketExecCommand;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poetteringtypedef enum SocketType {
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering SOCKET_SOCKET,
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering SOCKET_FIFO,
6bedfcbb2970e06a4d3280c8fb62083d252ede73Lennart Poettering SOCKET_SPECIAL,
4e731273edfe852a3eee2949cd20f49fd5b4f6d7Lennart Poettering SOCKET_MQUEUE,
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering _SOCKET_FIFO_MAX,
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering _SOCKET_FIFO_INVALID = -1
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering} SocketType;
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poetteringtypedef enum SocketResult {
32917e33882778cf2ec6dd54b1e1082266fb072eZbigniew Jędrzejewski-Szmek SOCKET_SUCCESS,
8b43440b7ef4b81c69c31de7ff820dc07a780254Lennart Poettering SOCKET_FAILURE_RESOURCES,
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering SOCKET_FAILURE_TIMEOUT,
4a0b58c4a30ecaa61202f845ed86f75b36370cd0Lennart Poettering SOCKET_FAILURE_EXIT_CODE,
8a03c9ef744e13dc700a7e7ca6cae8afdcf0d71cZbigniew Jędrzejewski-Szmek SOCKET_FAILURE_SIGNAL,
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek SOCKET_FAILURE_CORE_DUMP,
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek SOCKET_FAILURE_SERVICE_FAILED_PERMANENT,
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek _SOCKET_RESULT_MAX,
26687bf8a907009dedcff79346860ed41511405eOleksii Shevchuk _SOCKET_RESULT_INVALID = -1
7f1ad696a273703789b624fe0b209fb63e953016Lennart Poettering} SocketResult;
7f1ad696a273703789b624fe0b209fb63e953016Lennart Poettering
e150e82097211f09b911c7784a89ef9efed713caMichał Bartoszkiewicztypedef struct SocketPort {
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek Socket *socket;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek SocketType type;
e22aa3d3284709234f086ebebc13a905a295b7a7Lennart Poettering int fd;
e22aa3d3284709234f086ebebc13a905a295b7a7Lennart Poettering
7a24f3bf2fb181243a1957a0cdd54cd919396793Vito Caputo SocketAddress address;
7a24f3bf2fb181243a1957a0cdd54cd919396793Vito Caputo char *path;
7a24f3bf2fb181243a1957a0cdd54cd919396793Vito Caputo sd_event_source *event_source;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering LIST_FIELDS(struct SocketPort, port);
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering} SocketPort;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poetteringstruct Socket {
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering Unit meta;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering LIST_HEAD(SocketPort, ports);
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering unsigned n_accepted;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering unsigned n_connections;
7fd1b19bc9e9f5574f2877936b8ac267c7706947Harald Hoyer unsigned max_connections;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering unsigned backlog;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering usec_t timeout_usec;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek ExecCommand* exec_command[_SOCKET_EXEC_COMMAND_MAX];
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering ExecContext exec_context;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering KillContext kill_context;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering CGroupContext cgroup_context;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering ExecRuntime *exec_runtime;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering /* For Accept=no sockets refers to the one service we'll
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek activate. For Accept=yes sockets is either NULL, or filled
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering when the next service we spawn. */
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek UnitRef service;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering SocketState state, deserialized_state;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering sd_event_source *timer_event_source;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek ExecCommand* control_command;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering SocketExecCommand control_command_id;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek pid_t control_pid;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek mode_t directory_mode;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek mode_t socket_mode;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek SocketResult result;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering char **symlinks;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering bool accept;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek bool remove_on_stop;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek /* Socket options */
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek bool keep_alive;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek bool free_bind;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek bool transparent;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering bool broadcast;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering bool pass_cred;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek bool pass_sec;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek /* Only for INET6 sockets: issue IPV6_V6ONLY sockopt */
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek SocketAddressBindIPv6Only bind_ipv6_only;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek int priority;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek int mark;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek size_t receive_buffer;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek size_t send_buffer;
8a03c9ef744e13dc700a7e7ca6cae8afdcf0d71cZbigniew Jędrzejewski-Szmek int ip_tos;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering int ip_ttl;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering size_t pipe_size;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering char *bind_to_device;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering char *tcp_congestion;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering bool reuse_port;
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek long mq_maxmsg;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering long mq_msgsize;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
348ced909724a1331b85d57aede80a102a00e428Zbigniew Jędrzejewski-Szmek char *smack;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering char *smack_ip_in;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering char *smack_ip_out;
348ced909724a1331b85d57aede80a102a00e428Zbigniew Jędrzejewski-Szmek
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering char *user, *group;
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering};
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering
d025f1e4dca8fc1436aff76f9e6185fe3e728daaZbigniew Jędrzejewski-Szmek/* Called from the service code when collecting fds */
670b110c3b59dfa335ac43065b2038400d1d04a9Zbigniew Jędrzejewski-Szmekint socket_collect_fds(Socket *s, int **fds, unsigned *n_fds);
670b110c3b59dfa335ac43065b2038400d1d04a9Zbigniew Jędrzejewski-Szmek
8580d1f73db36e9383e674e388b4fb55828c0c66Lennart Poettering/* Called from the service code when a per-connection service ended */
282c5c4e422cb6e6685c870946d8b9bdf0879ad1Zbigniew Jędrzejewski-Szmekvoid socket_connection_unref(Socket *s);
282c5c4e422cb6e6685c870946d8b9bdf0879ad1Zbigniew Jędrzejewski-Szmek
282c5c4e422cb6e6685c870946d8b9bdf0879ad1Zbigniew Jędrzejewski-Szmekvoid socket_free_ports(Socket *s);
282c5c4e422cb6e6685c870946d8b9bdf0879ad1Zbigniew Jędrzejewski-Szmek
282c5c4e422cb6e6685c870946d8b9bdf0879ad1Zbigniew Jędrzejewski-Szmekextern const UnitVTable socket_vtable;
282c5c4e422cb6e6685c870946d8b9bdf0879ad1Zbigniew Jędrzejewski-Szmek
670b110c3b59dfa335ac43065b2038400d1d04a9Zbigniew Jędrzejewski-Szmekconst char* socket_state_to_string(SocketState i) _const_;
670b110c3b59dfa335ac43065b2038400d1d04a9Zbigniew Jędrzejewski-SzmekSocketState socket_state_from_string(const char *s) _pure_;
282c5c4e422cb6e6685c870946d8b9bdf0879ad1Zbigniew Jędrzejewski-Szmek
282c5c4e422cb6e6685c870946d8b9bdf0879ad1Zbigniew Jędrzejewski-Szmekconst char* socket_exec_command_to_string(SocketExecCommand i) _const_;
282c5c4e422cb6e6685c870946d8b9bdf0879ad1Zbigniew Jędrzejewski-SzmekSocketExecCommand socket_exec_command_from_string(const char *s) _pure_;
282c5c4e422cb6e6685c870946d8b9bdf0879ad1Zbigniew Jędrzejewski-Szmek
282c5c4e422cb6e6685c870946d8b9bdf0879ad1Zbigniew Jędrzejewski-Szmekconst char* socket_result_to_string(SocketResult i) _const_;
282c5c4e422cb6e6685c870946d8b9bdf0879ad1Zbigniew Jędrzejewski-SzmekSocketResult socket_result_from_string(const char *s) _pure_;
282c5c4e422cb6e6685c870946d8b9bdf0879ad1Zbigniew Jędrzejewski-Szmek
282c5c4e422cb6e6685c870946d8b9bdf0879ad1Zbigniew Jędrzejewski-Szmekconst char* socket_port_type_to_string(SocketPort *p) _pure_;
282c5c4e422cb6e6685c870946d8b9bdf0879ad1Zbigniew Jędrzejewski-Szmek
282c5c4e422cb6e6685c870946d8b9bdf0879ad1Zbigniew Jędrzejewski-Szmekint socket_instantiate_service(Socket *s);
282c5c4e422cb6e6685c870946d8b9bdf0879ad1Zbigniew Jędrzejewski-Szmek