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

RPKI: Improve get_status cb and add show_proto_info cb

parent 25fc1cc6
Loading
Loading
Loading
Loading
+58 −31
Original line number Original line Diff line number Diff line
@@ -31,6 +31,7 @@
#include "lib/idm.h"
#include "lib/idm.h"
#include "lib/string.h"
#include "lib/string.h"
#include "lib/unix.h"
#include "lib/unix.h"
#include "nest/cli.h"


static struct idm cache_uniq_id_generator;
static struct idm cache_uniq_id_generator;


@@ -82,7 +83,10 @@ rpki_print_groups(struct rpki_proto *p)
    struct rpki_cache *c;
    struct rpki_cache *c;
    WALK_LIST(c, g->cache_list)
    WALK_LIST(c, g->cache_list)
    {
    {
      DBG("  Cache(%s) %s \n", get_cache_ident(c), rtr_state_to_str(c->rtr_socket->state));
      DBG("  Cache(%s) %s, last update was before %d sec\n",
	  get_cache_ident(c),
	  rtr_state_to_str(c->rtr_socket->state),
	  (c->rtr_socket->last_update ? now - c->rtr_socket->last_update : -1));
    }
    }
  }
  }
}
}
@@ -650,6 +654,10 @@ rpki_get_status(struct proto *P, byte *buf)
{
{
  struct rpki_proto *p = (struct rpki_proto *) P;
  struct rpki_proto *p = (struct rpki_proto *) P;


  if (P->proto_state != PS_DOWN)
    buf[0] = 0;
  else
  {
    uint established_connections = 0;
    uint established_connections = 0;
    uint cache_servers = 0;
    uint cache_servers = 0;
    uint connecting = 0;
    uint connecting = 0;
@@ -679,7 +687,7 @@ rpki_get_status(struct proto *P, byte *buf)
    }
    }


    if (established_connections > 0)
    if (established_connections > 0)
    bsprintf(buf, "Keep synchronized with %u cache server%s", established_connections, (established_connections > 1) ? "s" : "");
      bsprintf(buf, "Connection established with %u cache server%s", established_connections, (established_connections > 1) ? "s" : "");
    else if (connecting > 0)
    else if (connecting > 0)
      bsprintf(buf, "Connecting to %u cache server%s", connecting, (connecting > 1) ? "s" : "");
      bsprintf(buf, "Connecting to %u cache server%s", connecting, (connecting > 1) ? "s" : "");
    else if (cache_servers == 0)
    else if (cache_servers == 0)
@@ -689,6 +697,25 @@ rpki_get_status(struct proto *P, byte *buf)
    else
    else
      bsprintf(buf, "Cannot connect to any cache servers");
      bsprintf(buf, "Cannot connect to any cache servers");
  }
  }
}

static void
rpki_show_proto_info(struct proto *P)
{
  struct rpki_proto *p = (struct rpki_proto *) P;

  struct rpki_cache_group *g;
  WALK_LIST(g, p->group_list)
  {
    cli_msg(-1006, "  Group(preference: %u) %s", g->preference, get_group_status(g));

    struct rpki_cache *c;
    WALK_LIST(c, g->cache_list)
    {
      cli_msg(-1006, "    Cache(%s) %s", get_cache_ident(c), rtr_state_to_str(c->rtr_socket->state));
    }
  }
}


static int
static int
rpki_start(struct proto *P)
rpki_start(struct proto *P)
@@ -713,7 +740,7 @@ struct protocol proto_rpki = {
  .config_size =	sizeof(struct rpki_config),
  .config_size =	sizeof(struct rpki_config),
  .init = 		rpki_init,
  .init = 		rpki_init,
  .start = 		rpki_start,
  .start = 		rpki_start,
//  .show_proto_info =	rpki_show_proto_info,	// TODO: be nice to be implemented
  .show_proto_info =	rpki_show_proto_info,
  .shutdown = 		rpki_shutdown,
  .shutdown = 		rpki_shutdown,
  .reconfigure = 	rpki_reconfigure,
  .reconfigure = 	rpki_reconfigure,
  .get_status = 	rpki_get_status,
  .get_status = 	rpki_get_status,