Exemplo n.º 1
0
Arquivo: bgp.c Projeto: i3149/bird
void
bgp_conn_enter_close_state(struct bgp_conn *conn)
{
  struct bgp_proto *p = conn->bgp;
  int os = conn->state;

  bgp_conn_set_state(conn, BS_CLOSE);
  tm_stop(conn->hold_timer);
  tm_stop(conn->keepalive_timer);
  conn->sk->rx_hook = NULL;

  if (os == BS_ESTABLISHED)
    bgp_conn_leave_established_state(p);
}
Exemplo n.º 2
0
Arquivo: bgp.c Projeto: deepfield/bird
void
bgp_conn_enter_established_state(struct bgp_conn *conn)
{
  struct bgp_proto *p = conn->bgp;
 
  BGP_TRACE(D_EVENTS, "BGP session established");
  DBG("BGP: UP!!!\n");

  /* For multi-hop BGP sessions */
  if (ipa_zero(p->source_addr))
    p->source_addr = conn->sk->saddr;

  p->conn = conn;
  p->last_error_class = 0;
  p->last_error_code = 0;
  bgp_init_bucket_table(p);
  bgp_init_prefix_table(p, 8);

  int peer_gr_ready = conn->peer_gr_aware && !(conn->peer_gr_flags & BGP_GRF_RESTART);

  if (p->p.gr_recovery && !peer_gr_ready)
    proto_graceful_restart_unlock(&p->p);

  if (p->p.gr_recovery && (p->cf->gr_mode == BGP_GR_ABLE) && peer_gr_ready)
    p->p.gr_wait = 1;

  if (p->gr_active)
    tm_stop(p->gr_timer);

  if (p->gr_active && (!conn->peer_gr_able || !(conn->peer_gr_aflags & BGP_GRF_FORWARDING)))
    bgp_graceful_restart_done(p);

  bgp_conn_set_state(conn, BS_ESTABLISHED);
  proto_notify_state(&p->p, PS_UP);
}
Exemplo n.º 3
0
static void
bgp_send_open(struct bgp_conn *conn)
{
  conn->start_state = conn->bgp->start_state;

  // Default values, possibly changed by receiving capabilities.
  conn->advertised_as = 0;
  conn->peer_refresh_support = 0;
  conn->peer_as4_support = 0;
  conn->peer_add_path = 0;
  conn->peer_enhanced_refresh_support = 0;
  conn->peer_gr_aware = 0;
  conn->peer_gr_able = 0;
  conn->peer_gr_time = 0;
  conn->peer_gr_flags = 0;
  conn->peer_gr_aflags = 0;
  conn->peer_ext_messages_support = 0;

  DBG("BGP: Sending open\n");
  conn->sk->rx_hook = bgp_rx;
  conn->sk->tx_hook = bgp_tx;
  tm_stop(conn->connect_retry_timer);
  bgp_schedule_packet(conn, PKT_OPEN);
  bgp_conn_set_state(conn, BS_OPENSENT);
  bgp_start_timer(conn->hold_timer, conn->bgp->cf->initial_hold_time);
}
Exemplo n.º 4
0
Arquivo: bgp.c Projeto: deepfield/bird
/**
 * bgp_graceful_restart_done - finish active BGP graceful restart
 * @p: BGP instance
 *
 * This function is called when the active BGP graceful restart of the neighbor
 * should be finished - either successfully (the neighbor sends all paths and
 * reports end-of-RIB on the new session) or unsuccessfully (the neighbor does
 * not support BGP graceful restart on the new session). The function ends
 * routing table refresh cycle and stops BGP restart timer.
 */
void
bgp_graceful_restart_done(struct bgp_proto *p)
{
  BGP_TRACE(D_EVENTS, "Neighbor graceful restart done");
  p->gr_active = 0;
  tm_stop(p->gr_timer);
  rt_refresh_end(p->p.main_ahook->table, p->p.main_ahook);
}
Exemplo n.º 5
0
/**
 * @brief   Stops a measurement and chains to the next one using the same time
 *          stamp.
 *
 * @param[in,out] tmp1  pointer to the @p time_measurement_t structure to be
 *                      stopped
 * @param[in,out] tmp2  pointer to the @p time_measurement_t structure to be
 *                      started
 *
 *
 * @xclass
 */
NOINLINE void chTMChainMeasurementToX(time_measurement_t *tmp1,
                                      time_measurement_t *tmp2) {

  /* Starts new measurement.*/
  tmp2->last = chSysGetRealtimeCounterX();

  /* Stops previous measurement using the same time stamp.*/
  tm_stop(tmp1, tmp2->last, 0);
}
Exemplo n.º 6
0
Arquivo: bgp.c Projeto: rogerhu/dd-wrt
/**
 * bgp_start_timer - start a BGP timer
 * @t: timer
 * @value: time to fire (0 to disable the timer)
 *
 * This functions calls tm_start() on @t with time @value and the
 * amount of randomization suggested by the BGP standard. Please use
 * it for all BGP timers.
 */
void
bgp_start_timer(timer *t, int value)
{
    if (value)
    {
        /* The randomization procedure is specified in RFC 1771: 9.2.3.3 */
        t->randomize = value / 4;
        tm_start(t, value - t->randomize);
    }
    else
        tm_stop(t);
}
Exemplo n.º 7
0
Arquivo: adc.c Projeto: vis81/uspi
void adc_sync_cb(U32 time)
{
	TRACE_INFO("ADC SYNC\n");
	SANITY_CHECK(gAdcDesc.state==ADC_SYNC);
	
	tm_stop();
	gAdcDesc.state=ADC_PIO;
	pio_start(nDRDY_mask[gAdcDesc.drdy],adc_pio_cb);
	pio_set(ADC_nSYNC);	
	
#if PWM_DEBUG
	pwm_start();
#endif
}
Exemplo n.º 8
0
Arquivo: bgp.c Projeto: rogerhu/dd-wrt
static void
bgp_send_open(struct bgp_conn *conn)
{
    conn->start_state = conn->bgp->start_state;
    conn->want_as4_support = conn->bgp->cf->enable_as4 && (conn->start_state != BSS_CONNECT_NOCAP);
    conn->peer_as4_support = 0;	// Default value, possibly changed by receiving capability.
    conn->advertised_as = 0;

    DBG("BGP: Sending open\n");
    conn->sk->rx_hook = bgp_rx;
    conn->sk->tx_hook = bgp_tx;
    tm_stop(conn->connect_retry_timer);
    bgp_schedule_packet(conn, PKT_OPEN);
    bgp_conn_set_state(conn, BS_OPENSENT);
    bgp_start_timer(conn->hold_timer, conn->bgp->cf->initial_hold_time);
}
Exemplo n.º 9
0
Arquivo: bgp.c Projeto: rogerhu/dd-wrt
void
bgp_conn_enter_close_state(struct bgp_conn *conn)
{
    struct bgp_proto *p = conn->bgp;
    int os = conn->state;

    bgp_conn_set_state(conn, BS_CLOSE);
    tm_stop(conn->keepalive_timer);
    conn->sk->rx_hook = NULL;

    /* Timeout for CLOSE state, if we cannot send notification soon then we just hangup */
    bgp_start_timer(conn->hold_timer, 10);

    if (os == BS_ESTABLISHED)
        bgp_conn_leave_established_state(p);
}
void clk_wait500us( void )
{
	int		ret;
	
	ETM2 = 0;
	(void)tm_init( (unsigned char)CLKSYS_TM_CHNO,		/* Timer channel */
	               (unsigned char)TM_M16_8BIT,			/* 8bit or 16bit mode */
	               (unsigned char)TM_CS_LSCLK,			/* Operation clock */
	               (unsigned short)CLKSYS_TIMER_CNT );	/* Timer count value */
	CLKSYS_TM_IRQ = 0;
	(void)tm_start( (unsigned char)CLKSYS_TM_CHNO );
	do {
		ret = tm_checkOvf( (unsigned char)CLKSYS_TM_CHNO );
	} while( ret == TM_R_NOT_OVF );
	(void)tm_stop( (unsigned char)CLKSYS_TM_CHNO );
	CLKSYS_TM_IRQ = 0;
}
Exemplo n.º 11
0
void
bgp_conn_enter_established_state(struct bgp_conn *conn)
{
  struct bgp_proto *p = conn->bgp;

  BGP_TRACE(D_EVENTS, "BGP session established");
  DBG("BGP: UP!!!\n");

  /* For multi-hop BGP sessions */
  if (ipa_zero(p->source_addr))
    p->source_addr = conn->sk->saddr;

  p->conn = conn;
  p->last_error_class = 0;
  p->last_error_code = 0;
  p->feed_state = BFS_NONE;
  p->load_state = BFS_NONE;
  bgp_init_bucket_table(p);
  bgp_init_prefix_table(p, 8);

  int peer_gr_ready = conn->peer_gr_aware && !(conn->peer_gr_flags & BGP_GRF_RESTART);

  if (p->p.gr_recovery && !peer_gr_ready)
    proto_graceful_restart_unlock(&p->p);

  if (p->p.gr_recovery && (p->cf->gr_mode == BGP_GR_ABLE) && peer_gr_ready)
    p->p.gr_wait = 1;

  if (p->gr_active)
    tm_stop(p->gr_timer);

  if (p->gr_active && (!conn->peer_gr_able || !(conn->peer_gr_aflags & BGP_GRF_FORWARDING)))
    bgp_graceful_restart_done(p);

  /* GR capability implies that neighbor will send End-of-RIB */
  if (conn->peer_gr_aware)
    p->load_state = BFS_LOADING;

  /* proto_notify_state() will likely call bgp_feed_begin(), setting p->feed_state */

  bgp_conn_set_state(conn, BS_ESTABLISHED);
  proto_notify_state(&p->p, PS_UP);
}
Exemplo n.º 12
0
/**
 * @brief   Stops a measurement.
 * @pre     The @p time_measurement_t structure must be initialized.
 *
 * @param[in,out] tmp   pointer to a @p time_measurement_t structure
 *
 * @xclass
 */
NOINLINE void chTMStopMeasurementX(time_measurement_t *tmp) {

  tm_stop(tmp, chSysGetRealtimeCounterX(), ch.tm.offset);
}
Exemplo n.º 13
0
/**
 * Initialize the collection/allocation phase.
 */
void _tm_phase_init(int p)
{
  tm_msg("p %s\n", tm_phase_name[p]);

#if 0
  /* DEBUG: DELETE ME! */
  if ( tm.alloc_id == 1987 )
    tm_stop();
#endif

#if 0
  ++ tm.p.n_phase_transitions[tm.p.phase][p];
  ++ tm.p.n_phase_transitions[tm.p.phase][tm_phase_END];
  ++ tm.p.n_phase_transitions[tm_phase_END][p];
  ++ tm.p.n_phase_transitions[tm_phase_END][tm_phase_END];

  if ( tm.p.phase == tm_SWEEP && tm.p.phase != p ) {
    tm.alloc_since_sweep = 0;
  }
#endif

#if 0
  fprintf(stderr, "\n%s->%s #%lu %lu %lu %lu %lu\n", tm_phase_name[tm.phase], tm_phase_name[p], (unsigned long) tm.alloc_id,
	  (unsigned long) tm.n[WHITE],
	  (unsigned long) tm.n[ECRU],
	  (unsigned long) tm.n[GREY],
	  (unsigned long) tm.n[BLACK],
	  0
	  );
#endif

  switch ( (tm.p.phase = p) ) {
  case tm_ALLOC:
    /**
     * - tm_ALLOC: allocate nodes until memory pressure is high.
     */
    tm.p.allocating = 1;
    tm.p.unmarking = 0;
    tm.p.marking = 0;
    tm.p.scanning = 0;
    tm.p.sweeping = 0;

    tm.alloc_color = tm_DEFAULT_ALLOC_COLOR;

    break;

  case tm_UNMARK:
    /**
     * - tm_UNMARK: begin unmarking BLACK nodes as ECRU:
     */
    tm.p.allocating = 0;
    tm.p.unmarking = 1;
    tm.p.marking = 0;
    tm.p.scanning = 0;
    tm.p.sweeping = 0;

    tm.alloc_color = tm_DEFAULT_ALLOC_COLOR;

    /*! Set up for unmarking. */
    tm_node_LOOP_INIT(BLACK);

    /*! Keep track of how many BLACK nodes are in use. */
    tm.n[tm_NU] = tm.n[BLACK];
    break;

  case tm_ROOT:
    /**
     * - tm_ROOT: begin scanning roots for potential pointers:
     */
    tm.p.allocating = 0;
    tm.p.unmarking = 0;
    tm.p.marking = 1;
    tm.p.scanning = 0;
    tm.p.sweeping = 0;

    tm.alloc_color = tm_DEFAULT_ALLOC_COLOR;

    /*! Mark stack and data roots as un-mutated. */
    tm.stack_mutations = tm.data_mutations = 0;

    /*! Initialize root mark loop. */
    _tm_root_loop_init();
    break;

  case tm_SCAN:
    /**
     * - tm_SCAN: begin scanning tm_GREY nodes for internal pointers:
     */
    tm.p.allocating = 0;
    tm.p.unmarking = 0;
    tm.p.marking = 1;
    tm.p.scanning = 1;
    tm.p.sweeping = 0;

    tm.alloc_color = tm_DEFAULT_ALLOC_COLOR;

    /*! Mark stack and data roots as un-mutated. */
    tm.stack_mutations = tm.data_mutations = 0;

    /*! Set up for marking. */
    tm_node_LOOP_INIT(GREY);
    break;

  case tm_SWEEP:
    /**
     * - tm_SWEEP: begin reclaiming any ECRU nodes as WHITE.
     */
    tm.p.allocating = 0;
    tm.p.unmarking = 0;
    tm.p.marking = 0;
    tm.p.scanning = 0;
    tm.p.sweeping = 1;

    tm.alloc_color = tm_SWEEP_ALLOC_COLOR;

    tm_assert_test(tm.n[GREY] == 0);

    /* Set up for scanning. */
    // tm_node_LOOP_INIT(GREY);

    /* Set up for sweeping. */
    // tm_node_LOOP_INIT(ECRU);
    break;

  default:
    tm_fatal();
    break;
  }

  if ( 1 || p == tm_SWEEP ) {
    // tm_print_stats();
  }
  //tm_validate_lists();
}
Exemplo n.º 14
0
Arquivo: dbdes.c Projeto: ColinBS/bird
void
ospf_receive_dbdes(struct ospf_packet *pkt, struct ospf_iface *ifa,
		   struct ospf_neighbor *n)
{
  struct ospf_proto *p = ifa->oa->po;
  const char *err_dsc = NULL;
  u32 rcv_ddseq, rcv_options;
  u16 rcv_iface_mtu;
  u8 rcv_imms;
  uint plen, err_val = 0;

  /* RFC 2328 10.6 */

  plen = ntohs(pkt->length);
  if (plen < ospf_dbdes_hdrlen(p))
  {
    LOG_PKT("Bad DBDES packet from nbr %R on %s - %s (%u)", n->rid, ifa->ifname, "too short", plen);
    return;
  }

  OSPF_PACKET(ospf_dump_dbdes, pkt, "DBDES packet received from nbr %R on %s", n->rid, ifa->ifname);

  ospf_neigh_sm(n, INM_HELLOREC);

  if (ospf_is_v2(p))
  {
    struct ospf_dbdes2_packet *ps = (void *) pkt;
    rcv_iface_mtu = ntohs(ps->iface_mtu);
    rcv_options = ps->options;
    rcv_imms = ps->imms;
    rcv_ddseq = ntohl(ps->ddseq);
  }
  else /* OSPFv3 */
  {
    struct ospf_dbdes3_packet *ps = (void *) pkt;
    rcv_options = ntohl(ps->options);
    rcv_iface_mtu = ntohs(ps->iface_mtu);
    rcv_imms = ps->imms;
    rcv_ddseq = ntohl(ps->ddseq);
  }

  switch (n->state)
  {
  case NEIGHBOR_DOWN:
  case NEIGHBOR_ATTEMPT:
  case NEIGHBOR_2WAY:
    OSPF_TRACE(D_PACKETS, "DBDES packet ignored - lesser state than ExStart");
    return;

  case NEIGHBOR_INIT:
    ospf_neigh_sm(n, INM_2WAYREC);
    if (n->state != NEIGHBOR_EXSTART)
      return;

  case NEIGHBOR_EXSTART:
    if ((ifa->type != OSPF_IT_VLINK) &&
	(rcv_iface_mtu != ifa->iface->mtu) &&
	(rcv_iface_mtu != 0) &&
	(ifa->iface->mtu != 0))
      LOG_PKT_WARN("MTU mismatch with nbr %R on %s (remote %d, local %d)",
		   n->rid, ifa->ifname, rcv_iface_mtu, ifa->iface->mtu);

    if ((rcv_imms == DBDES_IMMS) &&
	(n->rid > p->router_id) &&
	(plen == ospf_dbdes_hdrlen(p)))
    {
      /* I'm slave! */
      n->dds = rcv_ddseq;
      n->ddr = rcv_ddseq;
      n->options = rcv_options;
      n->myimms &= ~DBDES_MS;
      n->imms = rcv_imms;
      tm_stop(n->dbdes_timer);
      ospf_neigh_sm(n, INM_NEGDONE);
      ospf_send_dbdes(p, n);
      break;
    }

    if (!(rcv_imms & DBDES_I) &&
	!(rcv_imms & DBDES_MS) &&
	(n->rid < p->router_id) &&
	(n->dds == rcv_ddseq))
    {
      /* I'm master! */
      n->options = rcv_options;
      n->ddr = rcv_ddseq - 1;	/* It will be set corectly a few lines down */
      n->imms = rcv_imms;
      ospf_neigh_sm(n, INM_NEGDONE);
      /* Continue to the NEIGHBOR_EXCHANGE case */
    }
    else
    {
      DBG("%s: Nothing happend to %I (imms=%d)\n", p->name, n->ip, rcv_imms);
      break;
    }

  case NEIGHBOR_EXCHANGE:
    if ((rcv_imms == n->imms) &&
	(rcv_options == n->options) &&
	(rcv_ddseq == n->ddr))
      goto duplicate;

    if ((rcv_imms & DBDES_MS) != (n->imms & DBDES_MS))
      DROP("MS-bit mismatch", rcv_imms);

    if (rcv_imms & DBDES_I)
      DROP("I-bit mismatch", rcv_imms);

    if (rcv_options != n->options)
      DROP("options mismatch", rcv_options);

    n->ddr = rcv_ddseq;
    n->imms = rcv_imms;

    if (n->myimms & DBDES_MS)
    {
      /* MASTER */

      if (rcv_ddseq != n->dds)
	DROP("DD sequence number mismatch", rcv_ddseq);

      n->dds++;

      if (ospf_process_dbdes(p, pkt, n) < 0)
	return;

      if (!(n->myimms & DBDES_M) && !(n->imms & DBDES_M))
      {
	tm_stop(n->dbdes_timer);
	ospf_neigh_sm(n, INM_EXDONE);
	break;
      }

      ospf_send_dbdes(p, n);
      tm_start(n->dbdes_timer, n->ifa->rxmtint);
    }
    else
    {
      /* SLAVE */

      if (rcv_ddseq != (n->dds + 1))
	DROP("DD sequence number mismatch", rcv_ddseq);

      n->ddr = rcv_ddseq;
      n->dds = rcv_ddseq;

      if (ospf_process_dbdes(p, pkt, n) < 0)
	return;

      ospf_send_dbdes(p, n);

      if (!(n->myimms & DBDES_M) && !(n->imms & DBDES_M))
	ospf_neigh_sm(n, INM_EXDONE);
    }
    break;

  case NEIGHBOR_LOADING:
  case NEIGHBOR_FULL:
    if ((rcv_imms == n->imms) &&
	(rcv_options == n->options) &&
	(rcv_ddseq == n->ddr))
      goto duplicate;

    DROP("too late for DD exchange", n->state);

  default:
    bug("Undefined interface state");
  }
  return;

duplicate:
  OSPF_TRACE(D_PACKETS, "DBDES packet is duplicate");

  /* Slave should retransmit DBDES packet */
  if (!(n->myimms & DBDES_MS))
    ospf_rxmt_dbdes(p, n);
  return;

drop:
  LOG_PKT("Bad DBDES packet from nbr %R on %s - %s (%u)",
	  n->rid, ifa->ifname, err_dsc, err_val);

  ospf_neigh_sm(n, INM_SEQMIS);
  return;
}