Commit fa36e6b2 authored by Dustin Lundquist's avatar Dustin Lundquist

Improve listener fallback address handling

parent a7da99b0
......@@ -139,8 +139,9 @@ request. If no table directive is specified the default, unnamed, table will be
used.
The fallback directive specifies a server to be used if the client request can
not be parsed or a server can not be found in the table for the hostname
specified.
not be parsed, a server can not be found in the table for the hostname
specified or the hostname can not be resolved.. This should be an IP address
and port or unix socket path.
The bad_requests directive allows logging the contents of the client request if
it is not parsable, this is useful for debugging.
......
......@@ -259,31 +259,35 @@ accept_listener_fallback_address(struct Listener *listener, char *fallback) {
err("Duplicate fallback address: %s", fallback);
return 0;
}
listener->fallback_address = new_address(fallback);
if (listener->fallback_address == NULL) {
struct Address *fallback_address = new_address(fallback);
if (fallback_address == NULL) {
err("Unable to parse fallback address: %s", fallback);
return 0;
}
} else if (address_is_sockaddr(fallback_address)) {
listener->fallback_address = fallback_address;
return 1;
} else if (address_is_hostname(fallback_address)) {
#ifndef HAVE_LIBUDNS
if (!address_is_sockaddr(listener->fallback_address)) {
err("Only fallback socket addresses permitted when compiled without libudns");
free(listener->fallback_address);
listener->fallback_address = NULL;
free(fallback_address);
return 0;
}
#else
warn("Using hostname as fallback address is strongly discouraged");
listener->fallback_address = fallback_address;
return 1;
#endif
if (address_is_wildcard(listener->fallback_address)) {
free(listener->fallback_address);
listener->fallback_address = NULL;
} else if (address_is_wildcard(fallback_address)) {
/* The wildcard functionality requires successfully parsing the
* hostname from the client's request, if we couldn't find the
* hostname and are using a fallback address it doesn't make
* much sense to configure it as a wildcard. */
err("Wildcard address prohibited as fallback address");
free(fallback_address);
return 0;
} else {
fatal("Unexpected fallback address type");
return 0;
}
return 1;
}
int
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment