Esempio n. 1
0
void pim_zebra_init (struct thread_master *master, char *zebra_sock_path)
{
  int i;

  if (zebra_sock_path)
    zclient_serv_path_set(zebra_sock_path);

#ifdef HAVE_TCP_ZEBRA
  zlog_notice("zclient update contacting ZEBRA daemon at socket TCP %s,%d", "127.0.0.1", ZEBRA_PORT);
#else
  zlog_notice("zclient update contacting ZEBRA daemon at socket UNIX %s", zclient_serv_path_get());
#endif

  /* Socket for receiving updates from Zebra daemon */
  qpim_zclient_update = zclient_new (master);

  qpim_zclient_update->zebra_connected          = pim_zebra_connected;
  qpim_zclient_update->router_id_update         = pim_router_id_update_zebra;
  qpim_zclient_update->interface_add            = pim_zebra_if_add;
  qpim_zclient_update->interface_delete         = pim_zebra_if_del;
  qpim_zclient_update->interface_up             = pim_zebra_if_state_up;
  qpim_zclient_update->interface_down           = pim_zebra_if_state_down;
  qpim_zclient_update->interface_address_add    = pim_zebra_if_address_add;
  qpim_zclient_update->interface_address_delete = pim_zebra_if_address_del;
  qpim_zclient_update->ipv4_route_add           = redist_read_ipv4_route;
  qpim_zclient_update->ipv4_route_delete        = redist_read_ipv4_route;

  zclient_init(qpim_zclient_update, ZEBRA_ROUTE_PIM);
  if (PIM_DEBUG_PIM_TRACE) {
    zlog_info("zclient_init cleared redistribution request");
  }

  zassert(qpim_zclient_update->redist_default == ZEBRA_ROUTE_PIM);

  /* Request all redistribution */
  for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
    if (i == qpim_zclient_update->redist_default)
      continue;
    vrf_bitmap_set(qpim_zclient_update->redist[i], VRF_DEFAULT);
    if (PIM_DEBUG_PIM_TRACE) {
      zlog_debug("%s: requesting redistribution for %s (%i)", 
		 __PRETTY_FUNCTION__, zebra_route_string(i), i);
    }
  }

  /* Request default information */
  vrf_bitmap_set(qpim_zclient_update->default_information, VRF_DEFAULT);
  if (PIM_DEBUG_PIM_TRACE) {
    zlog_info("%s: requesting default information redistribution",
	      __PRETTY_FUNCTION__);

    zlog_notice("%s: zclient update socket initialized",
		__PRETTY_FUNCTION__);
  }

  zassert(!qpim_zclient_lookup);
  qpim_zclient_lookup = zclient_lookup_new();
  zassert(qpim_zclient_lookup);
}
Esempio n. 2
0
/* Send requests to zebra daemon for the information in a VRF. */
void
zclient_send_requests (struct zclient *zclient, vrf_id_t vrf_id)
{
  int i;

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

  /* If not connected to the zebra yet. */
  if (zclient->sock < 0)
    return;

  if (zclient_debug)
    zlog_debug ("%s: send messages for VRF %u", __func__, vrf_id);

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

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

  /* Set unwanted redistribute route. */
  vrf_bitmap_set (zclient->redist[zclient->redist_default], vrf_id);

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

  /* If default information is needed. */
  if (vrf_bitmap_check (zclient->default_information, VRF_DEFAULT))
    zebra_message_send (zclient, ZEBRA_REDISTRIBUTE_DEFAULT_ADD, vrf_id);
}
Esempio n. 3
0
void
zclient_redistribute_default (int command, struct zclient *zclient,
    vrf_id_t vrf_id)
{

  if (command == ZEBRA_REDISTRIBUTE_DEFAULT_ADD)
    {
      if (vrf_bitmap_check (zclient->default_information, vrf_id))
        return;
      vrf_bitmap_set (zclient->default_information, vrf_id);
    }
  else 
    {
      if (!vrf_bitmap_check (zclient->default_information, vrf_id))
        return;
      vrf_bitmap_unset (zclient->default_information, vrf_id);
    }

  if (zclient->sock > 0)
    zebra_message_send (zclient, command, vrf_id);
}
Esempio n. 4
0
void
zclient_redistribute (int command, struct zclient *zclient, int type,
    vrf_id_t vrf_id)
{

  if (command == ZEBRA_REDISTRIBUTE_ADD) 
    {
      if (vrf_bitmap_check (zclient->redist[type], vrf_id))
         return;
      vrf_bitmap_set (zclient->redist[type], vrf_id);
    }
  else
    {
      if (!vrf_bitmap_check (zclient->redist[type], vrf_id))
         return;
      vrf_bitmap_unset (zclient->redist[type], vrf_id);
    }

  if (zclient->sock > 0)
    zebra_redistribute_send (command, zclient, type, vrf_id);
}
Esempio n. 5
0
/* Other routes redistribution into BGP. */
int
bgp_redistribute_set (struct bgp *bgp, afi_t afi, int type)
{
  /* Set flag to BGP instance. */
  bgp->redist[afi][type] = 1;

  /* Return if already redistribute flag is set. */
  if (vrf_bitmap_check (zclient->redist[type], VRF_DEFAULT))
    return CMD_WARNING;

  vrf_bitmap_set (zclient->redist[type], VRF_DEFAULT);

  /* Return if zebra connection is not established. */
  if (zclient->sock < 0)
    return CMD_WARNING;

  if (BGP_DEBUG(zebra, ZEBRA))
    zlog_debug("Zebra send: redistribute add %s", zebra_route_string(type));
    
  /* Send distribute add message to zebra. */
  zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, type, VRF_DEFAULT);

  return CMD_SUCCESS;
}