IP2UNIX(1) | IP2Unix Manual | IP2UNIX(1) |
NAME¶
ip2unix - Turn IP sockets into Unix domain sockets
SYNOPSIS¶
ip2unix [-v...] [-p] -f RULES_FILE PROGRAM [ARGS...] ip2unix [-v...] [-p] -F RULES_DATA PROGRAM [ARGS...] ip2unix [-v...] [-p] -r RULE [-r RULE]... PROGRAM [ARGS...] ip2unix [-v...] [-p] -c -f RULES_FILE ip2unix [-v...] [-p] -c -F RULES_DATA ip2unix [-v...] [-p] -c -r RULE [-r RULE]... ip2unix -h ip2unix --version
DESCRIPTION¶
Executes a program and converts IP to Unix domain sockets at runtime based on a list of rules, either given via short command line options (see RULE SPECIFICATION) or via a file with a list of rules (see RULE FILE FORMAT). The first matching rule causes ip2unix to replace the current IP socket with a Unix domain socket based on the options given. For example if a socketPath is specified, the Unix domain socket will bind or listen to the given path.
OPTIONS¶
-c, --check
-h, --help
--version
-p, --print
-r, --rule=RULE
-f, --rules-file=RULES_FILE
-F, --rules-data=RULES_DATA
-v, --verbose
FATAL (default)
ERROR (-v)
WARNING (-vv)
INFO (-vvv)
DEBUG (-vvvv)
TRACE (-vvvvv)
RULE SPECIFICATION¶
Arguments specified via -r contain a comma-separated list of either flags or options. If a value contains a comma (,), it has to be escaped using a backslash (\) character. If you want to have a verbatim backslash character just use two consecutive backslashes instead.
The following flags are available:
in | out
tcp | udp
systemd[=FD_NAME]
reject[=ERRNO]
blackhole
ignore
These options are available:
addr[ess]=ADDRESS
port=PORT[-PORT_END]
path=SOCKET_PATH
RULE FILE FORMAT¶
The rule file (specified via -f is a YAML file (or JSON, as it is a subset of YAML), consisting of an array of objects.
Each object consists of keys/values which define which IP sockets to match and which Unix domain sockets to assign them to.
Rule file options¶
direction
type
address
port
portEnd
socketPath
Placeholders are allowed here and those are substituted accordingly:
%p | port number |
%a | IP address or unknown |
%t | socket type (tcp, udp or unknown) |
%% | verbatim % |
socketActivation
fdName
reject
rejectError
blackhole
ignore
EXAMPLES¶
Simple HTTP client/server¶
On the server side with the rule file rules-server.yaml:
- direction: incoming
socketPath: /tmp/test.socket
The following command spawns a small test web server listening on /tmp/test.socket:
$ ip2unix -f rules-server.yaml python3 -m http.server 8000
The same can be achieved using -r:
$ ip2unix -r in,path=/tmp/test.socket python3 -m http.server 8000
On the client side with rules-client.yaml:
- direction: outgoing
socketPath: /tmp/test.socket
This connects to the test server listening on /tmp/test.socket and should show the directory listing:
$ ip2unix -f rules-client.yaml curl http://1.2.3.4/
With the -r option:
$ ip2unix -r out,path=/tmp/test.socket curl http://1.2.3.4/
More complicated example¶
- direction: outgoing ## (1)
port: 53
ignore: true - direction: outgoing ## (2)
type: tcp
socketPath: /run/some.socket - direction: incoming ## (3)
address: 1.2.3.4
socketPath: /run/another.socket - direction: incoming ## (4)
port: 80
address: abcd::1
blackhole: true - direction: incoming ## (5)
port: 80
reject: true
rejectError: EADDRINUSE - direction: incoming ## (6)
type: tcp
port: 22
socketActivation: true
fdName: ssh
1. | All outgoing connections to port 53 (no matter if it’s TCP or UDP) will not be converted into Unix domain sockets. |
2. | This rule will redirect all TCP connections except to port 53 (see above) to use the Unix domain socket at /run/some.socket. |
3. | Matches the socket that listens to any port on the IPv4 address 1.2.3.4 and instead binds it to the Unix domain socket at /run/another.socket. |
4. | The application may bind to the IPv6 address abcd::1 on port 80 but it will not receive any connections, because no socket path exists. |
5. | Trying to bind to port 80 on addresses other than abcd::1 will result in an EADDRINUSE error. |
6. | Will prevent the TCP socket that would listen on port 22 to not listen at all and instead use the systemd-provided file descriptor named ssh for operations like accept(2). |
The same can be achieved solely using -r commandline arguments:
$ ip2unix -r out,port=53,ignore \
-r out,tcp,path=/run/some.socket \
-r in,addr=1.2.3.4,path=/run/another.socket \
-r in,port=80,reject=EADDRINUSE \
-r in,tcp,port=22,systemd=ssh
LIMITATIONS¶
However, if this really is an issue to you, the recommended workaround is either to use ip2unix to wrap the client (if it supports IP sockets) or fix the server to natively use Unix domain sockets.
ENVIRONMENT VARIABLES¶
IP2UNIX_RULE_FILE
SEE ALSO¶
accept(2), bind(2), connect(2), listen(2), recvfrom(2), recvmsg(2), sendmsg(2), sendto(2), socket(2), unix(7), systemd.socket(5)
AUTHOR¶
Written by aszlig <aszlig@nix.build>
COPYRIGHT¶
Copyright (C) 2018 aszlig. License LGPLv3: GNU LGPL version 3 only https://www.gnu.org/licenses/lgpl-3.0.html.
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
November 2018 | IP2Unix 2.1.4 |