Lines Matching refs: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 if (server->port_status == PORT_NOT_WORKING) {
385 timeout = server->service->ctx->opts->retry_timeout;
386 if (timeout != 0 && server->port_status == PORT_NOT_WORKING) {
388 if (STATUS_DIFF(server, tv) > timeout) {
390 "Resetting the status of port %d for server '%s'\n",
391 server->port, SERVER_NAME(server));
392 server->port_status = PORT_NEUTRAL;
393 server->last_status_change.tv_sec = tv.tv_sec;
397 return server->port_status;
401 server_works(struct fo_server *server)
403 if (get_server_status(server) == SERVER_NOT_WORKING)
410 service_works(struct fo_server *server)
412 if (!server_works(server))
414 if (get_port_status(server) == PORT_NOT_WORKING)
511 "BUG: pending requests still associated with this server\n");
552 static struct fo_server *server;
560 server = rc_alloc(server_owner, struct fo_server);
561 if (server == NULL) {
565 server->fo_internal_owner = server_owner;
567 server->common = NULL;
568 server->next = NULL;
569 server->prev = NULL;
570 server->srv_data = NULL;
571 server->last_status_change.tv_sec = 0;
572 server->last_status_change.tv_usec = 0;
574 server->port = port;
575 server->user_data = user_data;
576 server->service = service;
577 server->port_status = DEFAULT_PORT_STATUS;
578 server->primary = primary;
580 return server;
588 struct fo_server *server;
591 "Adding new SRV server to service '%s' using '%s'.\n",
594 DLIST_FOR_EACH(server, service->server_list) {
598 if (server->service->user_data_cmp && user_data && server->user_data) {
599 if (server->service->user_data_cmp(server->user_data, user_data)) {
604 if (fo_is_srv_lookup(server)) {
606 server->srv_data->dns_domain == NULL) ||
608 server->srv_data->dns_domain != NULL &&
609 strcasecmp(server->srv_data->dns_domain, discovery_domain) == 0)) &&
610 strcasecmp(server->srv_data->proto, proto) == 0) {
617 server = fo_server_alloc(service, 0, user_data, true);
618 if (server == NULL) {
623 server->srv_data = talloc_zero(service, struct srv_data);
624 if (server->srv_data == NULL)
627 server->srv_data->proto = talloc_strdup(server->srv_data, proto);
628 server->srv_data->srv = talloc_strdup(server->srv_data, srv);
629 if (server->srv_data->proto == NULL ||
630 server->srv_data->srv == NULL)
634 server->srv_data->discovery_domain = talloc_strdup(server->srv_data,
636 if (server->srv_data->discovery_domain == NULL)
638 server->srv_data->dns_domain = talloc_strdup(server->srv_data,
640 if (server->srv_data->dns_domain == NULL)
644 server->srv_data->sssd_domain =
645 talloc_strdup(server->srv_data, sssd_domain);
646 if (server->srv_data->sssd_domain == NULL)
649 server->srv_data->meta = server;
650 server->srv_data->srv_lookup_status = DEFAULT_SRV_STATUS;
651 server->srv_data->last_status_change.tv_sec = 0;
653 DLIST_ADD_END(service->server_list, server, struct fo_server *);
661 struct fo_server *server;
664 server = fo_server_alloc(service, port, user_data, primary);
665 if (server == NULL)
668 server->port = port;
669 server->user_data = user_data;
670 server->service = service;
671 server->port_status = DEFAULT_PORT_STATUS;
672 server->primary = primary;
675 ret = get_server_common(server, service->ctx, name, &server->common);
677 server->common = create_server_common(server, service->ctx, name);
678 if (server->common == NULL) {
679 fo_server_free(server);
683 fo_server_free(server);
688 return server;
694 struct fo_server *server;
697 DLIST_FOR_EACH(server, service->server_list) {
704 static bool fo_server_match(struct fo_server *server,
709 if (server->port != port) {
716 if (server->service->user_data_cmp && server->user_data && user_data) {
717 if (server->service->user_data_cmp(server->user_data, user_data)) {
722 if (name == NULL && server->common == NULL) {
727 server->common != NULL && server->common->name != NULL) {
728 if (!strcasecmp(name, server->common->name))
751 struct fo_server *server = NULL;
753 DLIST_FOR_EACH(server, list) {
754 if (fo_server_match(server, name, port, user_data)) {
764 struct fo_server *server,
771 if (server->common == NULL || server->common->name == NULL) {
775 debug_name = server->common->name;
776 name = server->common->name;
779 exists = fo_server_exists(check_list, name, server->port,
780 server->user_data);
784 "is already present\n", debug_name, server->port, service_name);
788 DLIST_ADD_END(*to_list, server, struct fo_server *);
790 DEBUG(SSSDBG_TRACE_FUNC, "Inserted %s server '%s:%d' to service "
791 "'%s'\n", (server->primary ? "primary" : "backup"),
792 debug_name, server->port, service_name);
806 struct fo_server *server = NULL;
813 server = create_fo_server(service, servers[i].host, servers[i].port,
815 if (server == NULL) {
819 server->srv_data = srv_data;
822 server, service->name);
824 fo_server_free(server);
828 last_server = server;
847 struct fo_server *server;
850 server = create_fo_server(service, name, port, user_data, primary);
851 if (!server) {
856 server, service->name);
858 fo_server_free(server);
865 struct fo_server *server)
867 if (server) {
868 server = rc_reference(ref_ctx, struct fo_server, server);
875 struct fo_server *server;
877 /* If we already have a working server, use that one. */
878 server = service->active_server;
879 if (server != NULL) {
880 if (service_works(server) && fo_is_server_primary(server)) {
887 * Otherwise iterate through the server list.
897 server = service->last_tried_server;
901 DLIST_FOR_EACH(server, service->last_tried_server->next) {
903 if (!server->primary) continue;
905 if (service_works(server)) {
912 DLIST_FOR_EACH(server, service->server_list) {
914 if (!server->primary) continue;
916 if (service_works(server)) {
919 if (server == service->last_tried_server) {
924 DLIST_FOR_EACH(server, service->server_list) {
926 if (server->primary) continue;
928 if (service_works(server)) {
937 service->last_tried_server = server;
938 *_server = server;
951 struct fo_server *server,
963 server->common);
970 DLIST_ADD(server->common->request_list, request);
979 * Get server to connect to. *
983 struct fo_server *server;
1001 struct fo_server *server);
1003 resolve_srv_recv(struct tevent_req *req, struct fo_server **server);
1011 struct fo_server *server;
1026 ret = get_first_server_entity(service, &server);
1041 if (fo_is_srv_lookup(server)) {
1042 /* Don't know the server yet, must do a SRV lookup */
1044 ctx, server);
1056 /* This is a regular server, just do hostname lookup */
1057 state->server = server;
1108 /* SRV resolving finished, see if we got server to work with */
1118 ret = resolve_srv_recv(subreq, &state->server);
1121 /* We will proceed normally on ERR_SRV_DUPLICATES and if the server
1139 switch (get_server_status(state->server)) {
1141 subreq = resolv_gethostbyname_send(state->server->common,
1143 state->server->common->name,
1151 state->server->common);
1152 fo_set_server_status(state->server, SERVER_RESOLVING_NAME);
1158 ret = set_lookup_hook(state->ev, state->server, req);
1190 DEBUG(SSSDBG_CRIT_FAILURE, "Failed to resolve server '%s': %s\n",
1194 * encounter an error, tell the caller to retry another server.
1207 /* Take care of all requests for this server. */
1212 * server, we would have crashed as common would not be valid
1228 struct fo_server **server)
1234 /* always return the server if asked for, otherwise the caller
1236 if (server != NULL) {
1237 fo_ref_server(ref_ctx, state->server);
1238 *server = state->server;
1247 * Resolve the server to connect to using a SRV query. *
1266 struct fo_server *server)
1278 state->service = server->service;
1282 state->meta = server->srv_data->meta;
1284 status = get_srv_data_status(server->srv_data);
1289 state->meta = collapse_srv_lookup(&server);
1291 * "server" might be invalid now if the SRV
1296 if (server != NULL && server != state->meta) {
1297 /* A server created by expansion of meta server was marked as
1300 state->meta = collapse_srv_lookup(&server);
1323 state->out = server;
1331 state->out = server;
1337 "Unexpected status %d for a SRV server\n", status);
1413 * exist. We will return server, but won't set any state. */
1415 "any new server.\n");
1418 /* Since no new server is returned, state->meta->next is NULL.
1419 * We return last tried server if possible which is server
1420 * from previous resolution of SRV record, and first server
1431 /* At least one new server was inserted.
1432 * We will return the first new server. */
1442 /* And remove meta server from the server list. It will be
1479 resolve_srv_recv(struct tevent_req *req, struct fo_server **server)
1484 /* always return the server if asked for, otherwise the caller
1486 if (server) {
1487 *server = state->out;
1502 DEBUG(SSSDBG_CONF_SETTINGS, "Marking server '%s' as '%s'\n", common->name,
1510 fo_set_server_status(struct fo_server *server, enum server_status status)
1512 if (server->common == NULL) {
1514 "Bug: Trying to set server status of a name-less server\n");
1518 set_server_common_status(server->common, status);
1522 fo_set_port_status(struct fo_server *server, enum port_status status)
1527 "Marking port %d of server '%s' as '%s'\n", server->port,
1528 SERVER_NAME(server), str_port_status(status));
1530 server->port_status = status;
1531 gettimeofday(&server->last_status_change, NULL);
1533 fo_set_server_status(server, SERVER_WORKING);
1534 server->service->active_server = server;
1537 if (!server->common || !server->common->name) return;
1542 DLIST_FOR_EACH(siter, server->service->server_list) {
1543 if (fo_server_cmp(siter, server)) {
1545 "Marking port %d of duplicate server '%s' as '%s'\n",
1561 struct fo_server *server;
1568 server = service->active_server;
1569 if (!server) {
1575 if (server->port_status == PORT_WORKING) {
1576 server->port_status = PORT_NOT_WORKING;
1581 fo_get_server_user_data(struct fo_server *server)
1583 return server->user_data;
1587 fo_get_server_port(struct fo_server *server)
1589 return server->port;
1593 fo_get_server_name(struct fo_server *server)
1595 if (!server->common) {
1598 return server->common->name;
1601 const char *fo_get_server_str_name(struct fo_server *server)
1603 if (!server->common) {
1604 if (fo_is_srv_lookup(server)) {
1605 return "SRV lookup meta-server";
1610 return server->common->name;
1614 fo_get_server_hostent(struct fo_server *server)
1616 if (server->common == NULL) {
1618 "Bug: Trying to get hostent from a name-less server\n");
1622 return server->common->rhostent;
1626 fo_is_server_primary(struct fo_server *server)
1628 return server->primary;
1632 fo_get_server_hostname_last_change(struct fo_server *server)
1634 if (server->common == NULL) {
1637 return server->common->last_status_change.tv_sec;
1651 struct fo_server *server;
1653 DLIST_FOR_EACH(server, service->server_list) {
1654 if (server->srv_data != NULL) {
1655 set_srv_data_status(server->srv_data, SRV_NEUTRAL);
1658 if (server->common) {
1659 fo_set_server_status(server, SERVER_NAME_NOT_RESOLVED);
1662 fo_set_port_status(server, PORT_NEUTRAL);
1679 bool fo_svc_has_server(struct fo_service *service, struct fo_server *server)
1684 if (srv == server) return true;
1695 const char *server;
1711 server = fo_get_server_name(srv);
1712 if (server == NULL) {
1717 list[count] = talloc_strdup(list, server);