From: Lennart Poettering Date: Mon, 17 Aug 2015 21:35:09 +0000 (+0200) Subject: hostname-util: introduce new is_gateway_hostname() call X-Git-Tag: v225~40^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=46a5e0e7421bcc47755ae15d430c15a16dc9e03e;p=thirdparty%2Fsystemd.git hostname-util: introduce new is_gateway_hostname() call This moves is_gateway() from nss-myhostname into the basic APIs, and makes it more like is_localhost(). Also, we rename it to is_gateway_hostname() to make it more expressive. Sharing this function in src/basic/ allows us to reuse the function for routing name requests in resolved (in a later commit). --- diff --git a/src/basic/hostname-util.c b/src/basic/hostname-util.c index d901a5e82bc..dc5434fcd12 100644 --- a/src/basic/hostname-util.c +++ b/src/basic/hostname-util.c @@ -151,6 +151,17 @@ bool is_localhost(const char *hostname) { endswith_no_case(hostname, ".localdomain."); } +bool is_gateway_hostname(const char *hostname) { + assert(hostname); + + /* This tries to identify the valid syntaxes for the our + * synthetic "gateway" host. */ + + return + strcaseeq(hostname, "gateway") || + strcaseeq(hostname, "gateway."); +} + int sethostname_idempotent(const char *s) { char buf[HOST_NAME_MAX + 1] = {}; diff --git a/src/basic/hostname-util.h b/src/basic/hostname-util.h index 6f2b5b66ff0..a1ca94980d7 100644 --- a/src/basic/hostname-util.h +++ b/src/basic/hostname-util.h @@ -33,6 +33,7 @@ bool hostname_is_valid(const char *s, bool relax) _pure_; char* hostname_cleanup(char *s); bool is_localhost(const char *hostname); +bool is_gateway_hostname(const char *hostname); int sethostname_idempotent(const char *s); diff --git a/src/nss-myhostname/nss-myhostname.c b/src/nss-myhostname/nss-myhostname.c index 69069cc75d2..0dca8914479 100644 --- a/src/nss-myhostname/nss-myhostname.c +++ b/src/nss-myhostname/nss-myhostname.c @@ -43,13 +43,6 @@ NSS_GETHOSTBYNAME_PROTOTYPES(myhostname); NSS_GETHOSTBYADDR_PROTOTYPES(myhostname); -static bool is_gateway(const char *hostname) { - assert(hostname); - - return streq(hostname, "gateway") || - streq(hostname, "gateway."); -} - enum nss_status _nss_myhostname_gethostbyname4_r( const char *name, struct gaih_addrtuple **pat, @@ -81,7 +74,7 @@ enum nss_status _nss_myhostname_gethostbyname4_r( canonical = "localhost"; local_address_ipv4 = htonl(INADDR_LOOPBACK); - } else if (is_gateway(name)) { + } else if (is_gateway_hostname(name)) { n_addresses = local_gateways(NULL, 0, AF_UNSPEC, &addresses); if (n_addresses <= 0) { @@ -351,7 +344,7 @@ enum nss_status _nss_myhostname_gethostbyname3_r( canonical = "localhost"; local_address_ipv4 = htonl(INADDR_LOOPBACK); - } else if (is_gateway(name)) { + } else if (is_gateway_hostname(name)) { n_addresses = local_gateways(NULL, 0, af, &addresses); if (n_addresses <= 0) {