Exemplo n.º 1
0
/* Test zebra client main routine. */
int
main (int argc, char **argv)
{
    FILE *fp;

    if (argc == 1)
        usage_exit ();

    /* Establish connection to zebra. */
    zclient = zclient_new ();
    zclient->enable = 1;
#ifdef HAVE_TCP_ZEBRA
    zclient->sock = zclient_socket ();
#else
    zclient->sock = zclient_socket_un (ZEBRA_SERV_PATH);
#endif /* HAVE_TCP_ZEBRA */

    /* Open simulation file. */
    fp = fopen (argv[1], "r");
    if (fp == NULL)
    {
        fprintf (stderr, "can't open %s\n", argv[1]);
        exit (1);
    }

    /* Do main work. */
    zebra_sim (fp);

    sleep (100);

    fclose (fp);
    close (sock);

    return 0;
}
Exemplo n.º 2
0
/**
 * Connect to zebra daemon.
 * @param zclient a pointer to zclient structure
 * @return socket fd just to make sure that connection established
 * @see zclient_init
 * @see zclient_new
 */
int
zclient_socket_connect (struct zclient *zclient)
{
#ifdef HAVE_TCP_ZEBRA
  zclient->sock = zclient_socket ();
#else
  zclient->sock = zclient_socket_un (zclient_serv_path_get());
#endif
  return zclient->sock;
}
Exemplo n.º 3
0
/* Connect to zebra for nexthop lookup. */
static int
zlookup_connect (struct thread *t)
{
  struct zclient *zlookup;

  zlookup = THREAD_ARG (t);
  zlookup->t_connect = NULL;

  if (zlookup->sock != -1)
    return 0;

#ifdef HAVE_TCP_ZEBRA
  zlookup->sock = zclient_socket ();
#else
  zlookup->sock = zclient_socket_un (ZEBRA_SERV_PATH);
#endif /* HAVE_TCP_ZEBRA */
  if (zlookup->sock < 0)
    return -1;

  return 0;
}
Exemplo n.º 4
0
/* Make connection to zebra daemon. */
int
zclient_start (struct zclient *zclient)
{
  int i;

  #ifdef ZCLIENT_DEBUG
    zlog_debug ("zclient_start is called");
#endif

  /* zclient is disabled. */
  if (! zclient->enable)
    return 0;

  /* If already connected to the zebra. */
  if (zclient->sock >= 0)
    return 0;

  /* Check connect thread. */
  if (zclient->t_connect)
    return 0;
#ifdef HAVE_TCP_ZEBRA
	zclient->sock = zclient_socket ();
#else
	zclient->sock = zclient_socket_un (ZEBRA_SERV_PATH);
#endif /* HAVE_TCP_ZEBRA */

  /* Make socket. */
  if (zclient->sock < 0)
    {
      #ifdef ZCLIENT_DEBUG
		zlog_debug ("zclient connection fail");
	  #endif
      zclient->fail++;
      zclient_event (ZCLIENT_CONNECT, zclient);
      return -1;
    }

  if (set_nonblocking(zclient->sock) < 0)
    zlog_warn("%s: set_nonblocking(%d) failed", __func__, zclient->sock);

  /* Clear fail count. */
  zclient->fail = 0;
  #ifdef ZCLIENT_DEBUG
    zlog_debug ("zclient connect success with socket [%d]", zclient->sock);
  #endif
      
  /* Create read thread. */
  zclient_event (ZCLIENT_READ, zclient);

  /* We need interface information. */
  zebra_message_send (zclient, ZEBRA_INTERFACE_ADD);

  /* We need router-id information. */
  zebra_message_send (zclient, ZEBRA_ROUTER_ID_ADD);

  /* Flush all redistribute request. */
  for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
    if (i != zclient->redist_default && zclient->redist[i])
      zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, i);

  /* If default information is needed. */
  if (zclient->default_information)
    zebra_message_send (zclient, ZEBRA_REDISTRIBUTE_DEFAULT_ADD);

  return 0;
}