Elektra
0.8.26
|
This plugin is a check plugin that checks if a key contains a valid ip address. It uses the POSIX.1-2001
interface getaddrinfo()
in order to check if an ip address is valid.
Furthermore getaddrinfo()
is used in check/port
to resolve a port by its service name which is defined under /etc/services
. The portname is translated to the respective portnumber. The plugin can be used to check for valid port numbers and if the set port is free to use.
While, in theory, a regular expression can express if a string is a network address, in practice, such an attempt does not work well. The reason is that an unmanageable number of valid shortenings for IPv6 addresses makes the regular expression hard to write and understand.
So the idea of building such a complicated regular expression was discarded, but instead a dedicated checker was introduced. The idea is to use the operating system facilities to resolve the network address. If this succeeds, it is guaranteed that this network address will be valid when it is resolved by the same interface afterwards.
Many network address translators coexist. In POSIX.1-2001
a powerful address translator is provided with the interface getaddrinfo()
. It is a common network address translation for both IPv4 and IPv6. We used it to implement this plugin.
Every key tagged with the metakey check/ipaddr
will be checked using getaddrinfo()
. If additionally the values ipv4
or ipv6
are supplied, the address family will be specified.
`` <h1>Mount Network plugin to
user/tests/network` sudo kdb mount config.file user/tests/network network
kdb set user/tests/network/host 127.0.0.1
kdb setmeta user/tests/network/host check/ipaddr ipv4
kdb set user/tests/network/host 133.133.133.1337
kdb get user/tests/network/host #> 127.0.0.1
kdb set user/tests/network/host 1.2.3.4 #> Set string to "1.2.3.4" kdb get user/tests/network/host #> 1.2.3.4
kdb setmeta user/tests/network/host check/ipaddr ''
localhost
is not a valid network address it is not part of /etc/hostskdb set user/tests/network/host localhost || ! grep -q localhost /etc/hosts
kdb get user/tests/network/host
kdb rm -r user/tests/network sudo kdb umount user/tests/network ```
If check/port
is specified on a given key, the plugin will validate if the port is a correct number between 1 and 65535.
If check/port/listen
is specified, the plugin will check if the application can be started and listen on the given port.
check/port/connect
to check if the port can be pinged/reached (usually for clients). If not reachable, users receive a warning. A correct timeout setting will be problematic though.