Commit e189e2f5 authored by Pavel Tvrdík's avatar Pavel Tvrdík
Browse files

RPKI: improved rpki_get_status()

parent 50791a41
Loading
Loading
Loading
Loading
+13 −6
Original line number Original line Diff line number Diff line
@@ -824,7 +824,9 @@ rpki_get_status(struct proto *P, byte *buf)


  uint established_connections = 0;
  uint established_connections = 0;
  uint cache_servers = 0;
  uint cache_servers = 0;
  uint synchronizing = 0;


  pthread_mutex_lock(&p->rtr_conf->mutex);
  for (i = 0; i < p->rtr_conf->len; i++)
  for (i = 0; i < p->rtr_conf->len; i++)
  {
  {
    for (j = 0; j < p->rtr_conf->groups[i].sockets_len; j++)
    for (j = 0; j < p->rtr_conf->groups[i].sockets_len; j++)
@@ -833,22 +835,27 @@ rpki_get_status(struct proto *P, byte *buf)
      switch (p->rtr_conf->groups[i].sockets[j]->state)
      switch (p->rtr_conf->groups[i].sockets[j]->state)
      {
      {
	case RTR_ESTABLISHED:
	case RTR_ESTABLISHED:
	  established_connections++;
	  break;
	case RTR_RESET:
	case RTR_RESET:
	case RTR_SYNC:
	case RTR_SYNC:
	  established_connections++;
	case RTR_FAST_RECONNECT:
	case RTR_CONNECTING:
	  synchronizing++;
	  break;
	  break;
      }
      }
    }
    }
  }
  }
  pthread_mutex_unlock(&p->rtr_conf->mutex);


  if (established_connections == 1)
  if (established_connections > 0)
    bsprintf(buf, "Keep synchronized with 1 cache server");
    bsprintf(buf, "Keep synchronized with %u cache server%s", established_connections, (established_connections > 1) ? "s" : "");
  else if (established_connections > 1)
  else if (synchronizing > 0)
    bsprintf(buf, "Keep synchronized with %u cache servers", established_connections);
    bsprintf(buf, "Synchronizing with %u cache server%s", synchronizing, (synchronizing > 1) ? "s" : "");
  else if (cache_servers == 0)
  else if (cache_servers == 0)
    bsprintf(buf, "No cache server is configured");
    bsprintf(buf, "No cache server is configured");
  else if (cache_servers == 1)
  else if (cache_servers == 1)
    bsprintf(buf, "Cannot connect to cache server");
    bsprintf(buf, "Cannot connect to a cache server");
  else
  else
    bsprintf(buf, "Cannot connect to any cache servers");
    bsprintf(buf, "Cannot connect to any cache servers");
}
}
+3 −2
Original line number Original line Diff line number Diff line
@@ -195,10 +195,11 @@ struct rtr_mgr_group {
struct rtr_mgr_config {
struct rtr_mgr_config {
    struct rtr_mgr_group *groups;
    struct rtr_mgr_group *groups;
    unsigned int len;
    unsigned int len;
    /* some items deleted for mockuping */
    pthread_mutex_t mutex;
    void *status_fp; /* voided for mockuping */
    void *status_fp_data;
};
};



/**
/**
 * @brief Version of the IP protocol.
 * @brief Version of the IP protocol.
 */
 */