fail_over.c revision b509de2164be8fa9a8d52d70883f4ec70b4bddf8
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny Fail over helper functions.
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny Martin Nagy <mnagy@redhat.com>
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny Jakub Hrozek <jhrozek@redhat.com>
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny Copyright (C) Red Hat, Inc 2010
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny This program is free software; you can redistribute it and/or modify
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny it under the terms of the GNU General Public License as published by
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny the Free Software Foundation; either version 3 of the License, or
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny (at your option) any later version.
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny This program is distributed in the hope that it will be useful,
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny but WITHOUT ANY WARRANTY; without even the implied warranty of
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny GNU General Public License for more details.
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny You should have received a copy of the GNU General Public License
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny along with this program. If not, see <http://www.gnu.org/licenses/>.
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny#define STATUS_DIFF(p, now) ((now).tv_sec - (p)->last_status_change.tv_sec)
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny#define SERVER_NAME(s) ((s)->common ? (s)->common->name : "(no name)")
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny#define DEFAULT_SERVER_STATUS SERVER_NAME_NOT_RESOLVED
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny SRV_NEUTRAL, /* We didn't try this SRV lookup yet */
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny SRV_RESOLVE_ERROR, /* Could not resolve this SRV lookup */
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny /* Function pointed by user_data_cmp returns 0 if user_data is equal
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny * or nonzero value if not. Set to NULL if no user data comparison
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny * is needed in fail over duplicate servers detection.
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zelenyfo_context_init(TALLOC_CTX *mem_ctx, struct fo_options *opts)
2f3ee3f49019f5b60adbe073070f31e6e2d7c7abStephen Gallagher ctx = talloc_zero(mem_ctx, struct fo_ctx);
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny ctx->opts->srv_retry_timeout = opts->srv_retry_timeout;
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny ctx->opts->service_resolv_timeout = opts->service_resolv_timeout;
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny DEBUG(SSSDBG_TRACE_FUNC, ("Created new fail over context, retry timeout is %d\n",
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zelenystatic const char *
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny return "neutral";
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov return "working";
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny return "not working";
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny return "unknown port status";
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zelenystatic const char *
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zelenystr_srv_data_status(enum srv_lookup_status status)
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny return "neutral";
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny return "resolved";
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny return "not resolved";
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny return "expired";
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny return "unknown SRV lookup status";
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zelenystatic const char *
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashovstr_server_status(enum server_status status)
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny return "name not resolved";
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny return "resolving name";
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny return "name resolved";
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny return "working";
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny return "not working";
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny return "unknown server status";
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zeleny return s && s->srv_data;
1a853121ca2ba8ede6df429ee76942131ffb0f65Jan Zelenystatic struct fo_server *
return meta;
static enum srv_lookup_status
case SRV_EXPIRED:
case SRV_NEUTRAL:
case SRV_RESOLVED:
case SRV_RESOLVE_ERROR:
static enum server_status
return SERVER_NAME_RESOLVED;
static enum port_status
int ret;
if (_service) {
return EEXIST;
return ret;
return ENOMEM;
return ENOMEM;
if (_service) {
return EOK;
return EOK;
return ENOENT;
return ENOMEM;
return EOK;
return ENOENT;
static struct server_common *
return NULL;
return NULL;
return common;
return EEXIST;
return ENOMEM;
return ENOMEM;
return ENOMEM;
if (discovery_domain) {
return ENOMEM;
return ENOMEM;
return ENOMEM;
return EOK;
static struct fo_server *
int ret;
return NULL;
return NULL;
return NULL;
return server;
int count = 0;
count++;
return count;
const char *name,
int port,
void *user_data)
const char *name,
int port,
void *user_data)
const char *service_name)
bool exists;
if (exists) {
return EEXIST;
return EOK;
void *user_data,
bool primary,
size_t i;
for (i = 0; i < num_servers; i++) {
return ENOMEM;
return EOK;
if (!server) {
return ENOMEM;
return ret;
goto done;
goto done;
goto done;
goto done;
goto done;
return ENOENT;
done:
return EOK;
return ENOMEM;
return ENOMEM;
return EOK;
struct resolve_service_state {
static struct tevent_req *
struct tevent_req *
int ret;
return NULL;
goto done;
goto done;
goto done;
req);
return req;
done:
return req;
static errno_t
const unsigned long timeout_seconds)
struct resolve_service_state);
return ENOMEM;
return EOK;
struct tevent_req);
struct resolve_service_state);
int ret;
if (ret) {
struct resolve_service_state);
int ret;
case SERVER_RESOLVING_NAME:
struct server_common);
int resolv_status;
int ret;
if (ret) {
if (server)
return EOK;
struct resolve_srv_state {
static struct tevent_req *
int ret;
int status;
return NULL;
switch(status) {
goto done;
goto done;
goto done;
return req;
goto done;
done:
return req;
struct tevent_req);
struct resolve_srv_state);
int ret;
switch (ret) {
case EOK:
goto done;
true, &last_server);
goto done;
false, NULL);
goto done;
case ERR_SRV_NOT_FOUND:
case ERR_SRV_LOOKUP_ERROR:
done:
struct resolve_srv_state);
if (server) {
return EOK;
struct resolve_get_domain_state {
char *fqdn;
if (!service) {
if (!server) {
return NULL;
struct resolv_hostent *
return NULL;
void *pvt)