Lines Matching defs:server
217 return "unknown server status";
225 static void fo_server_free(struct fo_server *server)
227 if (server == NULL) {
231 talloc_free(server->fo_internal_owner);
237 struct fo_server *tmp, *meta, *server;
239 server = *_server;
240 meta = server->srv_data->meta;
244 if (server != meta) {
245 while (server->prev && server->prev->srv_data == meta->srv_data) {
246 tmp = server->prev;
247 DLIST_REMOVE(server->service->server_list, tmp);
250 while (server->next && server->next->srv_data == meta->srv_data) {
251 tmp = server->next;
252 DLIST_REMOVE(server->service->server_list, tmp);
256 if (server == server->service->active_server) {
257 server->service->active_server = NULL;
259 if (server == server->service->last_tried_server) {
260 server->service->last_tried_server = meta;
263 /* add back the meta server to denote SRV lookup */
264 DLIST_ADD_AFTER(server->service->server_list, meta, server);
265 DLIST_REMOVE(server->service->server_list, server);
266 fo_server_free(server);
309 DEBUG(SSSDBG_CRIT_FAILURE, "Unknown state for SRV server!\n");
327 * This function will return the status of the server. If the status was
331 get_server_status(struct fo_server *server)
336 if (server->common == NULL)
340 "Status of server '%s' is '%s'\n", SERVER_NAME(server),
341 str_server_status(server->common->server_status));
343 timeout = server->service->ctx->opts->retry_timeout;
345 if (timeout != 0 && server->common->server_status == SERVER_NOT_WORKING) {
346 if (STATUS_DIFF(server->common, tv) > timeout) {
347 DEBUG(SSSDBG_CONF_SETTINGS, "Reseting the server status of '%s'\n",
348 SERVER_NAME(server));
349 server->common->server_status = SERVER_NAME_NOT_RESOLVED;
350 server->common->last_status_change.tv_sec = tv.tv_sec;
354 if (server->common->rhostent && STATUS_DIFF(server->common, tv) >
355 server->common->rhostent->addr_list[0]->ttl) {
357 "Hostname resolution expired, resetting the server "
358 "status of '%s'\n", SERVER_NAME(server));
359 fo_set_server_status(server, SERVER_NAME_NOT_RESOLVED);
362 return server->common->server_status;
370 get_port_status(struct fo_server *server)
376 "Port status of port %d for server '%s' is '%s'\n", server->port,
377 SERVER_NAME(server), str_port_status(server->port_status));
379 timeout = server->service->ctx->opts->retry_timeout;
380 if (timeout != 0 && server->port_status == PORT_NOT_WORKING) {
382 if (STATUS_DIFF(server, tv) > timeout) {
384 "Reseting the status of port %d for server '%s'\n",
385 server->port, SERVER_NAME(server));
386 server->port_status = PORT_NEUTRAL;
387 server->last_status_change.tv_sec = tv.tv_sec;
391 return server->port_status;
395 server_works(struct fo_server *server)
397 if (get_server_status(server) == SERVER_NOT_WORKING)
404 service_works(struct fo_server *server)
406 if (!server_works(server))
408 if (get_port_status(server) == PORT_NOT_WORKING)
505 "BUG: pending requests still associated with this server\n");
546 static struct fo_server *server;
554 server = rc_alloc(server_owner, struct fo_server);
555 if (server == NULL) {
559 server->fo_internal_owner = server_owner;
561 server->common = NULL;
562 server->next = NULL;
563 server->prev = NULL;
564 server->srv_data = NULL;
565 server->last_status_change.tv_sec = 0;
566 server->last_status_change.tv_usec = 0;
568 server->port = port;
569 server->user_data = user_data;
570 server->service = service;
571 server->port_status = DEFAULT_PORT_STATUS;
572 server->primary = primary;
574 return server;
582 struct fo_server *server;
585 "Adding new SRV server to service '%s' using '%s'.\n",
588 DLIST_FOR_EACH(server, service->server_list) {
592 if (server->service->user_data_cmp && user_data && server->user_data) {
593 if (server->service->user_data_cmp(server->user_data, user_data)) {
598 if (fo_is_srv_lookup(server)) {
600 server->srv_data->dns_domain == NULL) ||
602 server->srv_data->dns_domain != NULL &&
603 strcasecmp(server->srv_data->dns_domain, discovery_domain) == 0)) &&
604 strcasecmp(server->srv_data->proto, proto) == 0) {
611 server = fo_server_alloc(service, 0, user_data, true);
612 if (server == NULL) {
617 server->srv_data = talloc_zero(service, struct srv_data);
618 if (server->srv_data == NULL)
621 server->srv_data->proto = talloc_strdup(server->srv_data, proto);
622 server->srv_data->srv = talloc_strdup(server->srv_data, srv);
623 if (server->srv_data->proto == NULL ||
624 server->srv_data->srv == NULL)
628 server->srv_data->discovery_domain = talloc_strdup(server->srv_data,
630 if (server->srv_data->discovery_domain == NULL)
632 server->srv_data->dns_domain = talloc_strdup(server->srv_data,
634 if (server->srv_data->dns_domain == NULL)
638 server->srv_data->sssd_domain =
639 talloc_strdup(server->srv_data, sssd_domain);
640 if (server->srv_data->sssd_domain == NULL)
643 server->srv_data->meta = server;
644 server->srv_data->srv_lookup_status = DEFAULT_SRV_STATUS;
645 server->srv_data->last_status_change.tv_sec = 0;
647 DLIST_ADD_END(service->server_list, server, struct fo_server *);
655 struct fo_server *server;
658 server = fo_server_alloc(service, port, user_data, primary);
659 if (server == NULL)
662 server->port = port;
663 server->user_data = user_data;
664 server->service = service;
665 server->port_status = DEFAULT_PORT_STATUS;
666 server->primary = primary;
669 ret = get_server_common(server, service->ctx, name, &server->common);
671 server->common = create_server_common(server, service->ctx, name);
672 if (server->common == NULL) {
673 fo_server_free(server);
677 fo_server_free(server);
682 return server;
688 struct fo_server *server;
691 DLIST_FOR_EACH(server, service->server_list) {
698 static bool fo_server_match(struct fo_server *server,
703 if (server->port != port) {
710 if (server->service->user_data_cmp && server->user_data && user_data) {
711 if (server->service->user_data_cmp(server->user_data, user_data)) {
716 if (name == NULL && server->common == NULL) {
721 server->common != NULL && server->common->name != NULL) {
722 if (!strcasecmp(name, server->common->name))
745 struct fo_server *server = NULL;
747 DLIST_FOR_EACH(server, list) {
748 if (fo_server_match(server, name, port, user_data)) {
758 struct fo_server *server,
765 if (server->common == NULL || server->common->name == NULL) {
769 debug_name = server->common->name;
770 name = server->common->name;
773 exists = fo_server_exists(check_list, name, server->port,
774 server->user_data);
778 "is already present\n", debug_name, server->port, service_name);
782 DLIST_ADD_END(*to_list, server, struct fo_server *);
784 DEBUG(SSSDBG_TRACE_FUNC, "Inserted %s server '%s:%d' to service "
785 "'%s'\n", (server->primary ? "primary" : "backup"),
786 debug_name, server->port, service_name);
800 struct fo_server *server = NULL;
807 server = create_fo_server(service, servers[i].host, servers[i].port,
809 if (server == NULL) {
813 server->srv_data = srv_data;
816 server, service->name);
818 fo_server_free(server);
822 last_server = server;
841 struct fo_server *server;
844 server = create_fo_server(service, name, port, user_data, primary);
845 if (!server) {
850 server, service->name);
852 fo_server_free(server);
859 struct fo_server *server)
861 if (server) {
862 server = rc_reference(ref_ctx, struct fo_server, server);
869 struct fo_server *server;
871 /* If we already have a working server, use that one. */
872 server = service->active_server;
873 if (server != NULL) {
874 if (service_works(server) && fo_is_server_primary(server)) {
881 * Otherwise iterate through the server list.
891 server = service->last_tried_server;
895 DLIST_FOR_EACH(server, service->last_tried_server->next) {
897 if (!server->primary) continue;
899 if (service_works(server)) {
906 DLIST_FOR_EACH(server, service->server_list) {
908 if (!server->primary) continue;
910 if (service_works(server)) {
913 if (server == service->last_tried_server) {
918 DLIST_FOR_EACH(server, service->server_list) {
920 if (server->primary) continue;
922 if (service_works(server)) {
931 service->last_tried_server = server;
932 *_server = server;
945 struct fo_server *server,
957 server->common);
964 DLIST_ADD(server->common->request_list, request);
973 * Get server to connect to. *
977 struct fo_server *server;
995 struct fo_server *server);
997 resolve_srv_recv(struct tevent_req *req, struct fo_server **server);
1005 struct fo_server *server;
1020 ret = get_first_server_entity(service, &server);
1035 if (fo_is_srv_lookup(server)) {
1036 /* Don't know the server yet, must do a SRV lookup */
1038 ctx, server);
1050 /* This is a regular server, just do hostname lookup */
1051 state->server = server;
1102 /* SRV resolving finished, see if we got server to work with */
1112 ret = resolve_srv_recv(subreq, &state->server);
1115 /* We will proceed normally on ERR_SRV_DUPLICATES and if the server
1133 switch (get_server_status(state->server)) {
1135 subreq = resolv_gethostbyname_send(state->server->common,
1137 state->server->common->name,
1145 state->server->common);
1146 fo_set_server_status(state->server, SERVER_RESOLVING_NAME);
1151 ret = set_lookup_hook(state->ev, state->server, req);
1183 DEBUG(SSSDBG_CRIT_FAILURE, "Failed to resolve server '%s': %s\n",
1187 * encounter an error, tell the caller to retry another server.
1200 /* Take care of all requests for this server. */
1205 * server, we would have crashed as common would not be valid
1221 struct fo_server **server)
1227 /* always return the server if asked for, otherwise the caller
1229 if (server != NULL) {
1230 fo_ref_server(ref_ctx, state->server);
1231 *server = state->server;
1240 * Resolve the server to connect to using a SRV query. *
1259 struct fo_server *server)
1271 state->service = server->service;
1275 state->meta = server->srv_data->meta;
1277 status = get_srv_data_status(server->srv_data);
1282 state->meta = collapse_srv_lookup(&server);
1284 * "server" might be invalid now if the SRV
1288 if (server != NULL && server != state->meta) {
1289 /* A server created by expansion of meta server was marked as
1292 state->meta = collapse_srv_lookup(&server);
1315 state->out = server;
1323 state->out = server;
1329 "Unexpected status %d for a SRV server\n", status);
1405 * exist. We will return server, but won't set any state. */
1407 "any new server.\n");
1410 /* Since no new server is returned, state->meta->next is NULL.
1411 * We return last tried server if possible which is server
1412 * from previous resolution of SRV record, and first server
1423 /* At least one new server was inserted.
1424 * We will return the first new server. */
1434 /* And remove meta server from the server list. It will be
1469 resolve_srv_recv(struct tevent_req *req, struct fo_server **server)
1474 /* always return the server if asked for, otherwise the caller
1476 if (server) {
1477 *server = state->out;
1492 DEBUG(SSSDBG_CONF_SETTINGS, "Marking server '%s' as '%s'\n", common->name,
1500 fo_set_server_status(struct fo_server *server, enum server_status status)
1502 if (server->common == NULL) {
1504 "Bug: Trying to set server status of a name-less server\n");
1508 set_server_common_status(server->common, status);
1512 fo_set_port_status(struct fo_server *server, enum port_status status)
1517 "Marking port %d of server '%s' as '%s'\n", server->port,
1518 SERVER_NAME(server), str_port_status(status));
1520 server->port_status = status;
1521 gettimeofday(&server->last_status_change, NULL);
1523 fo_set_server_status(server, SERVER_WORKING);
1524 server->service->active_server = server;
1527 if (!server->common || !server->common->name) return;
1532 DLIST_FOR_EACH(siter, server->service->server_list) {
1533 if (fo_server_cmp(siter, server)) {
1535 "Marking port %d of duplicate server '%s' as '%s'\n",
1551 struct fo_server *server;
1558 server = service->active_server;
1559 if (!server) {
1565 if (server->port_status == PORT_WORKING) {
1566 server->port_status = PORT_NOT_WORKING;
1571 fo_get_server_user_data(struct fo_server *server)
1573 return server->user_data;
1577 fo_get_server_port(struct fo_server *server)
1579 return server->port;
1583 fo_get_server_name(struct fo_server *server)
1585 if (!server->common) {
1588 return server->common->name;
1591 const char *fo_get_server_str_name(struct fo_server *server)
1593 if (!server->common) {
1594 if (fo_is_srv_lookup(server)) {
1595 return "SRV lookup meta-server";
1600 return server->common->name;
1604 fo_get_server_hostent(struct fo_server *server)
1606 if (server->common == NULL) {
1608 "Bug: Trying to get hostent from a name-less server\n");
1612 return server->common->rhostent;
1616 fo_is_server_primary(struct fo_server *server)
1618 return server->primary;
1622 fo_get_server_hostname_last_change(struct fo_server *server)
1624 if (server->common == NULL) {
1627 return server->common->last_status_change.tv_sec;
1641 struct fo_server *server;
1643 DLIST_FOR_EACH(server, service->server_list) {
1644 if (server->srv_data != NULL) {
1645 set_srv_data_status(server->srv_data, SRV_NEUTRAL);
1648 if (server->common) {
1649 fo_set_server_status(server, SERVER_NAME_NOT_RESOLVED);
1652 fo_set_port_status(server, PORT_NEUTRAL);
1669 bool fo_svc_has_server(struct fo_service *service, struct fo_server *server)
1674 if (srv == server) return true;
1685 const char *server;
1701 server = fo_get_server_name(srv);
1702 if (server == NULL) {
1707 list[count] = talloc_strdup(list, server);