Config...:Socket(3pm)

πŸ’– Config...:Socket(3pm) πŸ’–

okay bestie, real talk β€” this is the manual for Config::Model::models::Systemd::Section::Socket, aka the Configuration class Systemd::Section::Socket. No cap, it's systemd socket units, but they've been through the Config::Model glow-up. Let's get into it. πŸ’…


✨ NAME ✨

  • Config::Model::models::Systemd::Section::Socket β€” Configuration class Systemd::Section::Socket

🌸 DESCRIPTION 🌸

These are configuration classes used by Config::Model. Full stop, that's the whole vibe.

A unit configuration file whose name ends in .socket encodes info about an IPC or network socket, or a file system FIFO, that systemd controls and supervises β€” for socket-based activation. That's the whole job. She's a socket-enabler. πŸ’–

This man page lists the config options that are specific to this unit type. For the common options that all unit config files share, go read systemd.unit(5). Those common config items live in the generic [Unit] and [Install] sections, bestie. The socket-specific config options live in the [Socket] section. That's the split. πŸŽ€

More options are listed in systemd.exec(5) β€” those define the execution environment that the ExecStartPre, ExecStartPost, ExecStopPre and ExecStopPost commands get run in. Then there's systemd.kill(5), which defines the way processes are terminated, and systemd.resource-control(5), which configures resource control settings for the processes of the socket. Three whole man pages of extra options. She's well-documented. 😭

Okay now the important part: for every socket unit, a matching service unit has to exist. That service unit describes what service to start when incoming traffic shows up on the socket (peep systemd.service(5) for the .service unit lore). The name of the .service unit is, by default, the same as the name of the .socket unit β€” but you can change that with the Service option (described below πŸ‘‡). Depending on how the Accept option (also described below πŸ‘‡) is set, this .service unit has to either:

  • be named like the .socket unit but with the suffix replaced β€” unless it's overridden with Service
  • or be a template unit named the same way

Example, because examples are iconic: a socket file foo.socket needs a matching service foo.service if Accept=no is set. If Accept=yes is set, then a service template foo@.service has to exist, and services get instantiated from it for each incoming connection. Slay. ✨

Heads up: no implicit WantedBy or RequiredBy dependency from the socket to the service is added. Which means the service may be started without the socket β€” and in that case it has to be able to open sockets all by itself. To prevent that, you can add an explicit Requires dependency.

Socket units can be used to implement on-demand starting of services, and parallelized starting of services. For an intro, see the blog stories linked at the end. πŸ”₯

Now β€” note that the daemon software you configured for socket activation with socket units needs to be able to accept sockets from systemd. Either via systemd's native socket passing interface (see sd_listen_fds(3) for the details on the precise protocol used and the order the file descriptors get passed in), or via the traditional inetd(8)-style socket passing β€” i.e. sockets passed in via standard input and output, using StandardInput=socket in the service file.

By default, network sockets allocated through .socket units are allocated in the host's network namespace (see network_namespaces(7)). BUT β€” and this is the plot twist β€” that does not mean the service activated by a configured socket unit has to be part of the host's network namespace too. It is supported, and honestly it's good practice, to run services in their own network namespace (for example through PrivateNetwork, see systemd.exec(5)), receiving only the sockets configured through socket-activation from the host's namespace. In such a set-up, communication within the host's network namespace is only permitted through the activation sockets passed in, while all sockets allocated from the service code itself will be associated with the service's own namespace β€” and thus possibly subject to a restrictive configuration. Lowkey profound. πŸ¦‹

Alternatively, it's possible to run a .socket unit in another network namespace by setting PrivateNetwork=yes in combination with JoinsNamespaceOf β€” see systemd.exec(5) and systemd.unit(5) for details. This configuration class was generated from systemd documentation. by parse-man.pl <https://github.com/dod38fr/config-model-systemd/contrib/parse-man.pl>


πŸ”₯ ELEMENTS πŸ”₯

πŸ’œ ListenStream πŸ’œ

Specifies an address to listen on for a stream (SOCK_STREAM), datagram (SOCK_DGRAM), or sequential packet (SOCK_SEQPACKET) socket, respectively. The address can be written in various formats, and bestie, there are a lot of formats:

  • If the address starts with a slash (/), it is read as a file system socket in the AF_UNIX socket family.
  • If the address starts with an at symbol (@), it is read as an abstract namespace socket in the AF_UNIX family. That @ gets replaced with a NUL character before binding. For details, see unix(7).
  • If the address string is a single number, it is read as a port number to listen on via IPv6. Depending on the value of BindIPv6Only (see below), this might result in the service being available via both IPv6 and IPv4 (that's the default) or just via IPv6.
  • If the address string is in the format v.w.x.y:z, it's interpreted as IPv4 address v.w.x.y and port z.
  • If the address string is in the format [x]:y, it's interpreted as IPv6 address x and port y. An optional interface scope (interface name or number) may be specified after a % symbol: [x]:y%dev. Interface scopes are only useful with link-local addresses, because the kernel ignores them in other cases. Note that if an address is specified as IPv6, it might still make the service available via IPv4 too, depending on the BindIPv6Only setting (see below).
  • If the address string is in the format vsock:x:y, it's read as CID x on a port y address in the AF_VSOCK family. The CID is a unique 32-bit integer identifier in AF_VSOCK, analogous to an IP address. Specifying the CID is optional, and may be set to the empty string. vsock may be replaced with vsock-stream, vsock-dgram or vsock-seqpacket to force usage of the corresponding socket type.

Note that SOCK_SEQPACKET (i.e. ListenSequentialPacket) is only available for AF_UNIX sockets. SOCK_STREAM (i.e. ListenStream), when used for IP sockets, refers to TCP sockets, and SOCK_DGRAM (i.e. ListenDatagram) refers to UDP. 🫢

These options may be specified more than once β€” in which case incoming traffic on any of the sockets will trigger service activation, and all listed sockets will be passed to the service, regardless of whether there's incoming traffic on them or not. If the empty string is assigned to any of these options, the list of addresses to listen on is reset, and all prior uses of any of these options will have no effect.

fr fr: empty string = full reset. Everything you listed before? Gone. Ghosted. πŸ’€

It's also possible to have more than one socket unit for the same service when using Service, and the service will receive all the sockets configured in all the socket units. Sockets configured in one unit are passed in the order of configuration, but no ordering between socket units is specified.

If an IP address is used here, it's often desirable to listen on it before the interface it's configured on is up and running β€” and even regardless of whether it will ever be up and running at any point. To deal with this, it's recommended to set the FreeBind option described below. Optional. Type list of uniline.

πŸ’œ ListenDatagram πŸ’œ

Specifies an address to listen on for a stream (SOCK_STREAM), datagram (SOCK_DGRAM), or sequential packet (SOCK_SEQPACKET) socket, respectively. The address can be written in various formats, and yeah, same list, she's thorough:

  • If the address starts with a slash (/), it is read as a file system socket in the AF_UNIX socket family.
  • If the address starts with an at symbol (@), it is read as an abstract namespace socket in the AF_UNIX family. That @ is replaced with a NUL character before binding. For details, see unix(7).
  • If the address string is a single number, it's read as a port number to listen on via IPv6. Depending on the value of BindIPv6Only (see below), this might result in the service being available via both IPv6 and IPv4 (default) or just via IPv6.
  • If the address string is in the format v.w.x.y:z, it's interpreted as IPv4 address v.w.x.y and port z.
  • If the address string is in the format [x]:y, it's interpreted as IPv6 address x and port y. An optional interface scope (interface name or number) may be specified after a % symbol: [x]:y%dev. Interface scopes are only useful with link-local addresses, because the kernel ignores them in other cases. Note that if an address is specified as IPv6, it might still make the service available via IPv4 too, depending on the BindIPv6Only setting (see below).
  • If the address string is in the format vsock:x:y, it's read as CID x on a port y address in the AF_VSOCK family. The CID is a unique 32-bit integer identifier in AF_VSOCK, analogous to an IP address. Specifying the CID is optional and may be set to the empty string. vsock may be replaced with vsock-stream, vsock-dgram or vsock-seqpacket to force usage of the corresponding socket type.

Note that SOCK_SEQPACKET (i.e. ListenSequentialPacket) is only available for AF_UNIX sockets. SOCK_STREAM (i.e. ListenStream) when used for IP sockets refers to TCP sockets, while SOCK_DGRAM (i.e. ListenDatagram) refers to UDP. 🌈

These options may be specified more than once, in which case incoming traffic on any of the sockets will trigger service activation, and all listed sockets will be passed to the service, regardless of whether there's incoming traffic on them or not. If the empty string is assigned to any of these options, the list of addresses to listen on is reset, and all prior uses of any of these options will have no effect.

It is also possible to have more than one socket unit for the same service when using Service, and the service will receive all the sockets configured in all the socket units. Sockets configured in one unit are passed in the order of configuration, but no ordering between socket units is specified.

If an IP address is used here, it's often desirable to listen on it before the interface it's configured on is up and running, and even regardless of whether it will be up and running at any point. To deal with this, it's recommended to set the FreeBind option described below. Optional. Type list of uniline.

πŸ’œ ListenSequentialPacket πŸ’œ

Specifies an address to listen on for a stream (SOCK_STREAM), datagram (SOCK_DGRAM), or sequential packet (SOCK_SEQPACKET) socket, respectively. The address can be written in various formats:

  • If the address starts with a slash (/), it is read as file system socket in the AF_UNIX socket family.
  • If the address starts with an at symbol (@), it is read as abstract namespace socket in the AF_UNIX family. The @ is replaced with a NUL character before binding. For details, see unix(7).

Okay so if the address string is literally just one single number, bestie, that's read as the port number to listen on via IPv6. And depending on whatever BindIPv6Only is set to (peep below πŸ‘‡) you might end up with the service reachable over both IPv6 and IPv4 (that's the default, periodt) or IPv6 only. No in-between.

If the address string looks like the format v.w.x.y:z? It's read as IPv4 address v.w.x.y and port z. Iconic, classic, we been knew.

If it's in the format [x]:y, that's read as IPv6 address x and port y. And you can optionally tack an interface scope on after a % symbol β€” interface name or number, either one: [x]:y%dev. Here's the tea though πŸ«–: interface scopes are only actually useful with link-local addresses, because the kernel just ignores them in every other case. Also note β€” even if you specified an address as IPv6, it might still make the service available via IPv4 too, depending on the BindIPv6Only setting (again, see below).

If the address string is in the format vsock:x:y, it's read as CID x on a port y address in the AF_VSOCK family. The CID is a unique 32-bit integer identifier in AF_VSOCK, loosely analogous to an IP address. Specifying the CID is optional and you can even set it to the empty string. And FYI, vsock may be replaced with vsock-stream, vsock-dgram or vsock-seqpacket to force usage of the corresponding socket type. Slay πŸ’…

Heads up bestie: SOCK_SEQPACKET (aka ListenSequentialPacket) is only available for AF_UNIX sockets. And SOCK_STREAM (aka ListenStream), when used for IP sockets, refers to TCP sockets β€” while SOCK_DGRAM (aka ListenDatagram) refers to UDP. Write that down, it's on the exam 😭

Now, these options may be specified more than once, and in that case incoming traffic on any of the sockets will trigger service activation, and all listed sockets get passed to the service β€” regardless of whether there's incoming traffic on them or not. Group chat behavior, honestly. And if the empty string is assigned to any of these options, the whole list of addresses to listen on is reset, and all prior uses of any of these options will have no effect. Poof. Gone. πŸ’¨

It's also possible to have more than one socket unit for the same service when you're using Service, and then the service will receive all the sockets configured across all the socket units. Sockets configured within one unit are passed in the order of configuration, but no ordering between socket units is specified. Respectfully, don't count on the order. πŸ™ˆ

If an IP address is used here, it's often desirable to listen on it before the interface it's configured on is even up and running β€” and even regardless of whether it will ever be up and running at any point. To deal with that, the recommendation is to set the FreeBind option described below. πŸ’–

Optional. Type list of uniline.

ListenFIFO

Specifies a file system FIFO (go read fifo(7) for the details, study era ✨) to listen on. This expects an absolute file system path as its argument. Behavior is otherwise very, very similar to the ListenDatagram directive above.

Optional. Type list of uniline.

ListenSpecial

Specifies a special file in the file system to listen on. Also expects an absolute file system path as argument. Behavior is otherwise super similar to the ListenFIFO directive above. Use this one to open character device nodes, plus special files in /proc/ and /sys/.

Optional. Type list of uniline.

Specifies a Netlink family to create a socket for, to listen on. This expects a short string referring to the AF_NETLINK family name (think audit or kobject-uevent) as its argument, optionally suffixed by a whitespace followed by a multicast group integer. Behavior is otherwise very similar to the ListenDatagram directive above.

Optional. Type list of uniline.

ListenMessageQueue

Specifies a POSIX message queue name to listen on (see mq_overview(7) for the deets). This expects a valid message queue name β€” meaning it begins with /, bestie, don't forget. Behavior is otherwise very similar to the ListenFIFO directive above. And fun fact: on Linux, message queue descriptors are actually file descriptors and can be inherited between processes. Sharing is caring 🫢

Optional. Type list of uniline.

ListenUSBFunction

Specifies a USB FunctionFS endpoints location to listen on, for implementing USB gadget functions. The link, since you'll want it: https://docs.kernel.org/usb/functionfs.html. This expects an absolute file system path of a FunctionFS mount point as the argument. Behavior is otherwise very similar to the ListenFIFO directive above. Use this to open the FunctionFS endpoint ep0. And listen β€” when you use this option, the activated service has to have the USBFunctionDescriptors and USBFunctionStrings options set. Non-negotiable, it's giving required βœ‹

Optional. Type list of uniline.

SocketProtocol

Takes one of udplite, sctp or mptcp. The socket will use the UDP-Lite (IPPROTO_UDPLITE), SCTP (IPPROTO_SCTP) or MPTCP (IPPROTO_MPTCP) protocol, respectively. Pick your fighter 🌈

Optional. Type enum. choice: 'mptcp', 'sctp', 'udplite'.

BindIPv6Only

Takes one of default, both or ipv6-only, and it controls the IPV6_V6ONLY socket option (see ipv6(7) for the details).

  • If both β€” IPv6 sockets that get bound will be accessible via both IPv4 and IPv6.
  • If ipv6-only β€” they'll be accessible via IPv6 only.
  • If default (which is the default, surprise! 😭) β€” the system-wide default setting is used, as controlled by /proc/sys/net/ipv6/bindv6only, which itself defaults to the equivalent of both.

Optional. Type enum. choice: 'both', 'default', 'ipv6-only'.

Backlog

Takes an unsigned 32-bit integer argument. Specifies the number of connections to queue that have not been accepted yet. This setting matters only for stream and sequential packet sockets. See listen(2) for details. Defaults to 4294967295.

Ngl though: this value gets silently capped by the net.core.somaxconn sysctl, which typically defaults to 4096 β€” so typically it's the sysctl that's the setting that actually matters. Not her fault πŸ’€

Optional. Type uniline.

BindToDevice

Specifies a network interface name to bind this socket to. If set, traffic will only be accepted from the specified network interfaces. This controls the SO_BINDTODEVICE socket option (see socket(7) for details). And if this option is used, an implicit dependency from this socket unit on the network interface device unit gets created (see systemd.device(5)). Also note that setting this parameter might result in additional dependencies being added to the unit (see above). Okay dependencies, we see you πŸ‘‘

Optional. Type uniline.

SocketUser

Takes a UNIX user/group name. When specified, all AF_UNIX sockets, FIFO nodes, and message queues are owned by the specified user and group. If unset (the default), the nodes are owned by the root user/group (if run in system context) or by the invoking user/group (if run in user context). If only a user is specified but no group, then the group is derived from the user's default group. She doesn't need you to spell it out πŸ’…

Optional. Type uniline.

SocketGroup

Takes a UNIX user/group name. When specified, all AF_UNIX sockets, FIFO nodes, and message queues are owned by the specified user and group. If unset (the default), the nodes are owned by the root user/group (if run in system context) or by the invoking user/group (if run in user context). If only a user is specified but no group, then the group is derived from the user's default group. Yes bestie, it's the same energy as SocketUser, different option name, we move.

Optional. Type uniline.

SocketMode

If you're listening on a file system socket, FIFO, or message queue, this option specifies the file system access mode used when creating the file node. Takes an access mode in octal notation. Defaults to 0666.

Optional. Type uniline.

DirectoryMode

If you're listening on a file system socket or FIFO, the parent directories get automatically created if needed. This option specifies the file system access mode used when creating those directories. Takes an access mode in octal notation. Defaults to 0755.

Optional. Type uniline.

Accept

Takes a boolean argument.

  • If yes, a service instance is spawned for each incoming connection, and only the connection socket is passed to it.
  • If no, all the listening sockets themselves are passed to the started service unit, and only one service unit is spawned for all connections (also see above).

This value is ignored for datagram sockets and FIFOs, where a single service unit unconditionally handles all incoming traffic. Defaults to no.

Typically, for performance-sensitive services, a choice of Accept=no is preferable, because that way only the first connection has to pay the activation resource cost. On the other hand, for sporadically used services, Accept=yes can be preferable β€” it simplifies the implementation (the service program code only has to process a single connection instead of handling multiple) and it enables stronger security (since the various sandboxing options can be used to isolate parallel connections from each other, as each one is serviced by a separate service instance and process). Different vibes, both valid πŸ¦‹

A service listening on an AF_UNIX socket may β€” but does not need to β€” call close(2) on the received socket before exiting. However, it must not unlink the socket from a file system. And it should not invoke shutdown(2) on sockets it got with Accept=no, but it may do so for sockets it got with Accept=yes set. Read that twice, it's important πŸ™

Setting Accept=yes is in particular useful for allowing daemons designed for usage with inetd(8) to work unmodified with systemd socket activation. Legacy support but make it fashion ✨

Note that depending on this setting, the services activated by units of this type are either regular services (in the case of Accept=no) or instances of templated services (in the case of Accept=yes). See the Description section above for a more detailed discussion of the naming rules of triggered services.

For IPv4 and IPv6 connections, the $REMOTE_ADDR environment variable will contain the remote IP address, and $REMOTE_PORT will contain the remote port number. These two variables correspond to those defined by the CGI interface for web services (see RFC 3875 β€” https://datatracker.ietf.org/doc/html/rfc3875).

For AF_UNIX socket connections, the $REMOTE_ADDR environment variable will contain either the remote socket's file system path starting with a slash (/) or its address in the abstract namespace starting with an at symbol (@). If the socket is unnamed, $REMOTE_ADDR will not be set. Rude, but okay. πŸ™ˆ

If Accept=yes is used, the activated service process will have set the $SO_COOKIE environment variable to the Linux socket cookie, formatted as a decimal integer. The socket cookie can otherwise be acquired via getsockopt(7).

It is recommended to set CollectMode=inactive-or-failed for service instances activated via Accept=yes, to make sure that failed connection services are cleaned up and released from memory, and don't just accumulate. Spring cleaning energy 🧹🌸

Optional. Type boolean.

upstream_default value :
    no

Writable

Takes a boolean argument. May only be used in conjunction with ListenSpecial. If true, the specified special file is opened in read-write mode; if false, in read-only mode. Defaults to false. πŸŽ€

Optional. Type boolean.

upstream_default value :
    no

FlushPending

Takes a boolean, bestie πŸ’… and it's only allowed when Accept=no. If you set it to yes, the socket's buffers get cleared once the triggered service exits β€” which means any pending data gets flushed and any pending incoming connections get flat-out rejected. If no, the buffers are left alone, so the service can pick up those pending connections after a restart β€” which is the usually expected behaviour, fr fr. Defaults to no. Optional. Type boolean.

upstream_default value :
    no

MaxConnections

The maximum number of connections to simultaneously run services instances for, when Accept=yes is set. If more concurrent connections come pouring in, they'll be refused until at least one existing connection is terminated 😭. Heads up: this setting has no effect on sockets configured with Accept=no or on datagram sockets. Defaults to 64. Optional. Type uniline.


MaxConnectionsPerSource

The maximum number of connections for a service per source IP address (when we're in IPv4/IPv6 territory), per source CID (for AF_VSOCK), or per source UID (for AF_UNIX). It's like, extremely similar to the MaxConnections directive right above it. Defaults to 0, i.e. disabled. Optional. Type uniline.


KeepAlive

Takes a boolean. If true, the TCP/IP stack will send a keep alive message after 2h (depending on the configuration of /proc/sys/net/ipv4/tcp_keepalive_time) for all TCP streams accepted on this socket. This controls the SO_KEEPALIVE socket option (see socket(7) and the TCP Keepalive HOWTO <http://www.tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/> for details). Defaults to false. Optional. Type boolean.

upstream_default value :
    no

KeepAliveTimeSec

Takes time (in seconds) as its argument. The connection needs to remain idle before TCP starts sending keepalive probes. This controls the TCP_KEEPIDLE socket option (see socket(7) and the TCP Keepalive HOWTO <http://www.tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/> for details). Default value is 7200 seconds (2 hours). Optional. Type integer.

upstream_default value :
    7200

KeepAliveIntervalSec

Takes time (in seconds) as argument β€” it's the gap between individual keepalive probes, but only if the socket option SO_KEEPALIVE has been set on this socket. This controls the TCP_KEEPINTVL socket option (see socket(7) and the TCP Keepalive HOWTO <http://www.tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/> for details). Default value is 75 seconds. Optional. Type integer.

upstream_default value :
    75

KeepAliveProbes

Takes an integer. It's the number of unacknowledged probes to send before considering the connection dead and notifying the application layer πŸ’€. This controls the TCP_KEEPCNT socket option (see socket(7) and the TCP Keepalive HOWTO <http://www.tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/> for details). Default value is 9. Optional. Type integer.

upstream_default value :
    9

NoDelay

Takes a boolean. TCP Nagle's algorithm works by combining a number of small outgoing messages and sending them all at once β€” this option is basically the "actually, no" to that ✨. It controls the TCP_NODELAY socket option (see tcp(7)). Defaults to false. Optional. Type boolean.

upstream_default value :
    no

Priority

Takes an integer argument controlling the priority for all traffic sent from this socket πŸ‘‘. This controls the SO_PRIORITY socket option (see socket(7) for details.). Optional. Type integer.


DeferAcceptSec

Takes time (in seconds) as argument. If set, the listening process will be awakened only when data arrives on the socket, and not immediately when the connection is established 😴. When this option is set, the TCP_DEFER_ACCEPT socket option will be used (see tcp(7)), and the kernel will ignore initial ACK packets that don't carry any data. The argument specifies the approximate amount of time the kernel should wait for incoming data before falling back to the normal behavior of honoring empty ACK packets. This one's a whole vibe for protocols where the client sends the data first (e.g. HTTP, in contrast to SMTP), because the server process won't get woken up unnecessarily before it can actually take any action.

If the client also uses the TCP_DEFER_ACCEPT option, the latency of the initial connection may be reduced, because the kernel will send data in the final packet establishing the connection (the third packet in the three-way handshake). Slay.

Disabled by default. Optional. Type integer.


ReceiveBuffer

Takes an integer argument controlling the receive or send buffer sizes of this socket, respectively. This controls the SO_RCVBUF and SO_SNDBUF socket options (see socket(7) for details.). The usual suffixes K, M, G are supported and are understood to the base of 1024. Optional. Type uniline.


SendBuffer

Takes an integer argument controlling the receive or send buffer sizes of this socket, respectively. This controls the SO_RCVBUF and SO_SNDBUF socket options (see socket(7) for details.). The usual suffixes K, M, G are supported and are understood to the base of 1024. Optional. Type uniline.


IPTOS

Takes an integer argument controlling the IP Type-Of-Service field for packets generated from this socket. This controls the IP_TOS socket option (see ip(7) for details.). Either a numeric string or one of low-delay, throughput, reliability or low-cost may be specified. Optional. Type integer.


IPTTL

Takes an integer argument controlling the IPv4 Time-To-Live/IPv6 Hop-Count field for packets generated from this socket. This sets the IP_TTL/IPV6_UNICAST_HOPS socket options (see ip(7) and ipv6(7) for details.) Optional. Type integer.


Mark

Takes an integer value. Controls the firewall mark of packets generated by this socket. You can use this in the firewall logic to filter packets from this socket πŸŽ€. This sets the SO_MARK socket option. See iptables(8) for details. Optional. Type integer.


ReusePort

Takes a boolean value. If true, it allows multiple bind(2)s to this TCP or UDP port. This controls the SO_REUSEPORT socket option. See socket(7) for details. Optional. Type boolean.


SmackLabel

Takes a string value. Controls the extended attributes security.SMACK64, security.SMACK64IPIN and security.SMACK64IPOUT, respectively, i.e. the security label of the FIFO, or the security label for the incoming or outgoing connections of the socket, respectively. See Smack <https://docs.kernel.org/admin-guide/LSM/Smack.html> for details. Optional. Type uniline.


SmackLabelIPIn

Takes a string value. Controls the extended attributes security.SMACK64, security.SMACK64IPIN and security.SMACK64IPOUT, respectively, i.e. the security label of the FIFO, or the security label for the incoming or outgoing connections of the socket, respectively. See Smack <https://docs.kernel.org/admin-guide/LSM/Smack.html> for details. Optional. Type uniline.


SmackLabelIPOut

Takes a string value. Controls the extended attributes security.SMACK64, security.SMACK64IPIN and security.SMACK64IPOUT, respectively, i.e. the security label of the FIFO, or the security label for the incoming or outgoing connections of the socket, respectively. See Smack <https://docs.kernel.org/admin-guide/LSM/Smack.html> for details. Optional. Type uniline.


SELinuxContextFromNet

Takes a boolean argument. When true, systemd will attempt to figure out the SELinux label used for the instantiated service from the information handed by the peer over the network πŸ•΅οΈβ€β™€οΈ. Note that only the security level is used from the information provided by the peer β€” the other parts of the resulting SELinux context originate from either the target binary that is effectively triggered by the socket unit or from the value of the SELinuxContext option. This configuration option applies only when the activated service is passed in a single socket file descriptor, i.e. service instances that have standard input connected to a socket, or services triggered by exactly one socket unit. Also note that this option is useful only when MLS/MCS SELinux policy is deployed. Defaults to false. Optional. Type boolean.

upstream_default value :
    no

PipeSize

Takes a size in bytes. Controls the pipe buffer size of FIFOs configured in this socket unit 🚰. See fcntl(2) for details. The usual suffixes K, M, G are supported and are understood to the base of 1024. Optional. Type uniline.


MessageQueueMaxMessages

These two settings take integer values and control the mq_maxmsg field or the mq_msgsize field, respectively, when creating the message queue. Note that either none or both of these variables need to be set β€” no in-between, bestie πŸ™ˆ. See mq_setattr(3) for details. Optional. Type uniline.


FreeBind

Takes a boolean value. Controls whether the socket can be bound to non-local IP addresses. This is useful to configure sockets listening on specific IP addresses before those IP addresses are successfully configured on a network interface ✨. This sets the IP_FREEBIND/IPV6_FREEBIND socket option. For robustness reasons it is recommended to use this option whenever you bind a socket to a specific IP address. Defaults to false. Optional. Type boolean.

upstream_default value :
    no

Transparent

Takes a boolean value. Controls the IP_TRANSPARENT/IPV6_TRANSPARENT socket option. Defaults to false. Optional. Type boolean.

upstream_default value :
    no

Broadcast

Takes a boolean value. This controls the SO_BROADCAST socket option, which allows broadcast datagrams to be sent from this socket πŸ“‘. Defaults to false. Optional. Type boolean.

upstream_default value :
    no

PassCredentials

Takes a boolean value. This controls the SO_PASSCRED socket option, which allows AF_UNIX sockets to receive the credentials of the sending process in an ancillary message. Defaults to false. Optional. Type boolean.

upstream_default value :
    no

PassPIDFD

Takes a boolean value. This controls the SO_PASSPIDFD socket option, which allows AF_UNIX sockets to receive the pidfd of the sending process in an ancillary message. Defaults to false. Optional. Type boolean.

upstream_default value :
    no

PassSecurity

Takes a boolean value. This controls the SO_PASSSEC socket option, which allows AF_UNIX sockets to receive the security context of the sending process in an ancillary message πŸ”. Defaults to false. Optional. Type boolean.

upstream_default value :
    no

PassPacketInfo

Takes a boolean value. This controls the IP_PKTINFO, IPV6_RECVPKTINFO, NETLINK_PKTINFO or PACKET_AUXDATA socket options, which enable reception of additional per-packet metadata as ancillary message, on AF_INET, AF_INET6, AF_UNIX and AF_PACKET sockets. Defaults to false. Optional. Type boolean.

upstream_default value :
    no

πŸ¦‹ AcceptFileDescriptors πŸ¦‹

okay so this one takes a boolean, bestie. It's the puppet strings for the SO_PASSRIGHTS socket option πŸ’… β€” and when it's disabled, your peer literally cannot send SCM_RIGHTS ancillary messages (that's file descriptors, in case you were wondering ✨) through AF_UNIX sockets. Defaults to true. Optional. Type boolean.

upstream_default value :
    yes

⏰ Timestamping ⏰

bestie pick ONE, not all of them 😭 β€” it's either off, us (alias: usec, ΞΌs), or ns (alias: nsec). This is the girl behind the SO_TIMESTAMP and SO_TIMESTAMPNS socket options, and it decides whether ingress network traffic carries timestamping metadata. Defaults to off. Optional. Type enum. choice: 'ns', 'nsec', 'off', 'us', 'usec', 'ΞΌs'.

🚦 TCPCongestion 🚦

a string, babes β€” this controls the TCP congestion algorithm your socket uses. Should be one of westwood, reno, cubic, lp or literally any other algorithm your IP stack has lying around. Heads up though: this setting applies only to stream sockets. Optional. Type uniline.

πŸŽ€ ExecStartPre πŸŽ€

takes one or more command lines that get executed before (<- your girl) or after the listening sockets/FIFOs are created and bound, respectively. The first token of the command line has to be an absolute filename, then the arguments for the process follow 🫢. You can drop multiple command lines in, following the same scheme that ExecStartPre uses for service unit files. Optional. Type list of uniline.

🌸 ExecStartPost 🌸

takes one or more command lines that get executed before or after the listening sockets/FIFOs are created and bound, respectively. First token = absolute filename (no exceptions bestie), then the process arguments. Multiple command lines welcome, same scheme as ExecStartPre in service unit files. Optional. Type list of uniline.

πŸ’œ ExecStopPre πŸ’œ

extra commands that run before or after the listening sockets/FIFOs are closed and removed, respectively. Yes, multiple command lines may be specified, and yes, same scheme as ExecStartPre of service unit files. Optional. Type list of uniline.

πŸ’œ ExecStopPost πŸ’œ

more extra commands, executed before or after the listening sockets/FIFOs are closed and removed, respectively. Multiple command lines allowed, following the same scheme as ExecStartPre of service unit files. Optional. Type list of uniline.

⏳ TimeoutSec ⏳

this is the clock, honey πŸ•°οΈ β€” it sets how long we wait for the commands in ExecStartPre, ExecStartPost, ExecStopPre and ExecStopPost to finish. If a command doesn't exit in the configured time, the socket is considered failed and gets shut down again. Every command still running gets terminated forcibly via SIGTERM, and after another delay of this same time, via SIGKILL. (See KillMode in systemd.kill(5).) It takes a unit-less value in seconds, or a time span value like 5min 20s. Pass 0 to disable the timeout logic entirely, wild child πŸ’…. Defaults to DefaultTimeoutStartSec from the manager configuration file (see systemd-system.conf(5)). Optional. Type uniline.

🌟 Service 🌟

tells us which service unit to activate on incoming traffic. This setting is only allowed for sockets with Accept=no. It defaults to the service that bears the same name as the socket (with the suffix replaced). Honestly? In most cases you shouldn't need this option at all. But note that setting this parameter might result in additional dependencies being added to the unit (see above). Optional. Type uniline.

πŸ—‘οΈ RemoveOnStop πŸ—‘οΈ

takes a boolean argument. If enabled, any file nodes created by this socket unit get removed when it's stopped. That applies to AF_UNIX sockets in the file system, POSIX message queues, FIFOs, and any symlinks to them configured with Symlinks. Normally you should not need this option, and it is not recommended β€” because services might keep running after the socket unit has been terminated and you'd still want to be able to communicate with them through their file system node 😭. Defaults to off. Optional. Type boolean.

upstream_default value :
    no

takes a list of file system paths. Each of those paths will be created as a symlink pointing at the AF_UNIX socket path or FIFO path of this socket unit ✨. If you use this setting, then only one AF_UNIX socket in the file system or one FIFO may be configured for the socket unit. Use it to manage one or more symlinked alias names for a socket, binding their lifecycles together 🫢. Note that if creation of a symlink fails, this is not considered fatal for the socket unit, and the socket unit may still start. Assign an empty string and the list of paths is reset. Defaults to an empty list. Optional. Type uniline.

🏷️ FileDescriptorName 🏷️

gives a name to all file descriptors this socket unit encapsulates. Super useful for helping activated services figure out which fd is which when multiple fds get passed πŸ‘‘. Services can use the sd_listen_fds_with_names(3) call to grab the names configured for the received file descriptors. Names may contain any ASCII character, but must exclude control characters and :, and must be at most 255 characters in length. If you don't use this setting, the file descriptor name defaults to the name of the socket unit (including its .socket suffix) when Accept=no, and connection otherwise. Optional. Type uniline.

🚨 TriggerLimitIntervalSec 🚨

this sets a limit on how often this socket unit may be activated within a specific time interval. TriggerLimitIntervalSec configures the length of that interval in the usual time units us, ms, s, min, h, … and defaults to 2s (see systemd.time(7) for the deets on all the time units it understands). TriggerLimitBurst takes a positive integer and specifies how many activations are permitted per interval β€” it defaults to 200 for Accept=yes sockets (so 200 activations per 2s by default), and 20 otherwise (20 activations per 2s). Set either one to 0 to disable trigger rate limiting entirely, go off ✨.

If the limit is hit, the socket unit is placed into a failure mode and will not be connectible anymore until restarted. And psst β€” note that this limit is enforced before the service activation is enqueued.

Compare with PollLimitIntervalSec/PollLimitBurst described below, which implements a temporary slowdown if a socket unit is flooded with incoming traffic, as opposed to the permanent failure state TriggerLimitIntervalSec/TriggerLimitBurst results in. Optional. Type uniline.

🚨 TriggerLimitBurst 🚨

this sets a limit on how often this socket unit may be activated within a specific time interval. TriggerLimitIntervalSec configures the length of that interval in the usual time units us, ms, s, min, h, … and defaults to 2s (see systemd.time(7) for details on the various time units understood). TriggerLimitBurst takes a positive integer value and specifies the number of permitted activations per time interval, and defaults to 200 for Accept=yes sockets (thus by default permitting 200 activations per 2s), and 20 otherwise (20 activations per 2s). Set either to 0 to disable any form of trigger rate limiting.

If the limit is hit, the socket unit is placed into a failure mode, and will not be connectible anymore until restarted. Note that this limit is enforced before the service activation is enqueued.

Compare with PollLimitIntervalSec/PollLimitBurst described below, which implements a temporary slowdown if a socket unit is flooded with incoming traffic, as opposed to the permanent failure state TriggerLimitIntervalSec/TriggerLimitBurst results in. Optional. Type uniline.

🌊 PollLimitIntervalSec 🌊

sets a limit on how often polling events on the file descriptors backing this socket unit will be considered πŸ‘€. This pair of settings is similar to TriggerLimitIntervalSec/TriggerLimitBurst, except instead of putting a (fatal) limit on the activation frequency, it puts a (transient) limit on the polling frequency. The expected parameter syntax and range are identical to those of the aforementioned options, and you can disable it the same way.

If the polling limit is hit, polling on it is temporarily disabled until the specified time window passes. So the polling limit slows down connection attempts if it gets hit, but unlike the trigger limit it will not cause permanent failures. It's the recommended mechanism for dealing with DoS attempts through packet flooding πŸ”₯.

The polling limit is enforced per file descriptor to listen on, as opposed to the trigger limit which is enforced for the entire socket unit. That distinction matters for socket units that listen on multiple file descriptors (i.e. have multiple ListenXYZ stanzas).

These settings default to 150 (in the case of Accept=yes) and 15 (otherwise) polling events per 2s. That's considerably lower than the default values for the trigger limit (see above), which means the polling limit should typically ensure the trigger limit is never hit β€” unless one of them gets reconfigured or disabled, obviously πŸ™ˆ. Optional. Type uniline.

🌊 PollLimitBurst 🌊

sets a limit on how often polling events on the file descriptors backing this socket unit will be considered. This pair of settings is similar to TriggerLimitIntervalSec/TriggerLimitBurst but instead of putting a (fatal) limit on the activation frequency, it puts a (transient) limit on the polling frequency. The expected parameter syntax and range are identical to that of the aforementioned options, and can be disabled the same way.

If the polling limit is hit, polling is temporarily disabled on it until the specified time window passes. The polling limit hence slows down connection attempts if hit, but unlike the trigger limit it will not cause permanent failures. It's the recommended mechanism to deal with DoS attempts through packet flooding.

The polling limit is enforced per file descriptor to listen on, as opposed to the trigger limit which is enforced for the entire socket unit. This distinction matters for socket units that listen on multiple file descriptors (i.e. have multiple ListenXYZ stanzas).

These settings default to 150 (in case of Accept=yes) and 15 (otherwise) polling events per 2s. This is considerably lower than the default values for the trigger limit (see above) and means that the polling limit should typically ensure the trigger limit is never hit, unless one of them is reconfigured or disabled. Optional. Type uniline.

DeferTrigger 🌸

Okay bestie, this one takes a boolean argument, OR the literal word patient β€” yes, patient, she's a whole vibe. You may only use it when Accept=no, no exceptions, don't test her.

If you enable it, the job mode lenient gets used instead of replace when triggering the service. Which means: units that are currently activating or running and conflict with the service will not be disturbed, will not be brought down. Nobody gets evicted mid-glow-up. ✨

And if a conflict does exist? The socket unit will wait for the current job queue to finish and potentially defer the activation by then. There's an upper limit on the total time to wait, and you configure that with DeferTriggerMaxSec.

  • If it's set to yes, the socket unit will fail if all jobs have finished or the timeout has been reached β€” but the conflict is still there. Like, okay, we waited, still beefing, we're out. πŸ’€
  • If it's patient, it always waits until DeferTriggerMaxSec elapses. Iconic. Unbothered. Moisturized.

Defaults to no.

This setting is particularly useful if the socket unit should stay active across switch-root/soft-reboot operations while the triggered service is stopped. So basically: she stays up, he's taking a nap. 🫢

Optional. Type enum. choice: 'no', 'patient', 'yes'.

upstream_default value :

no

DeferTriggerMaxSec ⏳

Configures the maximum time to defer the triggering when DeferTrigger is enabled. If the service cannot be activated within the specified time, the socket will be considered failed and get terminated. Bestie, that's a hard deadline, not a suggestion.

Takes a unit-less value in seconds, or a time span value such as 5min 20s. Pass 0 or "infinity" to disable the timeout logic β€” and that is the default, so by default she waits forever. Patient queen. πŸ‘‘

Optional. Type uniline.


PassFileDescriptorsToExec πŸŽ€

Takes a boolean argument. Defaults to off.

If enabled, file descriptors created by the socket unit are passed to ExecStartPost, ExecStopPre, and ExecStopPost commands from the socket unit. The passed file descriptors can be accessed with sd_listen_fds(3) as if the commands were invoked from the associated service units. So they get the whole backstage pass. πŸ’…

Note that ExecStartPre command cannot access socket file descriptors. Sorry babe, that one's not on the list. πŸ™ˆ

Optional. Type boolean.

upstream_default value :

no

πŸ‘€ SEE ALSO

  • cme

2010-2016 Lennart Poettering and others
2016 Dominique Dumont

πŸ“œ LICENSE

LGPLv2.1+

and that's the whole page bestie, we ate, no crumbs left πŸ“βœ¨

this lil manual page ships as perl v5.40.1, dated 2026-03-22, and it lives under the name Config...:Socket(3pm) β€” go forth and socket responsibly, mwah πŸ’–πŸ¦‹

πŸ“¦ where this page comes from