diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-03-26 18:11:41 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-04-23 12:02:11 +0200 |
commit | a1fdbcbe3d0ab58ac274f5a6a0669752d5b4238b (patch) | |
tree | 3d0310e615a8f7ee185646092f6cbc2ac2333b1f /src/nss-myhostname | |
parent | 54e6f97bc9931679aa9b895546621b15e0f464a4 (diff) | |
download | systemd-a1fdbcbe3d0ab58ac274f5a6a0669752d5b4238b.tar.gz |
nss-myhostname: expose the "outbound" IP addresses under the synthetic "_outbound" hostname
I found myself often looking for a quick way to determine "the local IP
address", and then being lost in the "ip addr" output to find for the
right one to use. This is supposed to help a bit with that. Let's
introduce a new special hostname "_outbound" with semantics similar to
"_gateway" that resolves to addresses that are the closest I could come
up with that maps to "the" local IP address.
Diffstat (limited to 'src/nss-myhostname')
-rw-r--r-- | src/nss-myhostname/nss-myhostname.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/nss-myhostname/nss-myhostname.c b/src/nss-myhostname/nss-myhostname.c index 6e37966da0..3536c5fc83 100644 --- a/src/nss-myhostname/nss-myhostname.c +++ b/src/nss-myhostname/nss-myhostname.c @@ -54,8 +54,7 @@ enum nss_status _nss_myhostname_gethostbyname4_r( assert(h_errnop); if (is_localhost(name)) { - /* We respond to 'localhost', so that /etc/hosts - * is optional */ + /* We respond to 'localhost', so that /etc/hosts is optional */ canonical = "localhost"; local_address_ipv4 = htobe32(INADDR_LOOPBACK); @@ -68,6 +67,14 @@ enum nss_status _nss_myhostname_gethostbyname4_r( canonical = "_gateway"; + } else if (is_outbound_hostname(name)) { + + n_addresses = local_outbounds(NULL, 0, AF_UNSPEC, &addresses); + if (n_addresses <= 0) + goto not_found; + + canonical = "_outbound"; + } else { hn = gethostname_malloc(); if (!hn) { @@ -343,6 +350,14 @@ enum nss_status _nss_myhostname_gethostbyname3_r( canonical = "_gateway"; + } else if (is_outbound_hostname(name)) { + + n_addresses = local_outbounds(NULL, 0, af, &addresses); + if (n_addresses <= 0) + goto not_found; + + canonical = "_outbound"; + } else { hn = gethostname_malloc(); if (!hn) { |