Esempio n. 1
0
void NAT_event_add
   (
      TCPIP_EVENT_PTR         tcpip_event_ptr,         /* [IN] Controller event */
      NAT_EVENT_STRUCT_PTR    nat_event_ptr      /* [IN] NAT event to add */
   )
{ /* Body */
   NAT_EVENT_HEAD_PTR      nat_event_head_ptr = tcpip_event_ptr->PRIVATE;
   
   NAT_event_tick(tcpip_event_ptr, FALSE);
      
   /* We know the event will be placed at the end of the list */
   nat_event_ptr->TIME -= nat_event_head_ptr->TIMEDELTA;       
   nat_event_head_ptr->TIMEDELTA += nat_event_ptr->TIME;
   nat_event_ptr->NEXT = NULL;
   
   if (nat_event_head_ptr->FIRST) {      /* If there are already elements in list .. */
      nat_event_ptr->PREV = nat_event_head_ptr->LAST;
      nat_event_ptr->PREV->NEXT = nat_event_ptr;
      nat_event_head_ptr->LAST = nat_event_ptr;
      
   } else {
      nat_event_head_ptr->FIRST = nat_event_ptr;
      nat_event_head_ptr->LAST = nat_event_ptr;
      nat_event_ptr->PREV = NULL;
      tcpip_event_ptr->TIME = nat_event_ptr->TIME;
      TCPIP_Event_add(tcpip_event_ptr);
   } /* Endif */

   nat_event_ptr->EVENT = tcpip_event_ptr;
   
} /* Endbody */
Esempio n. 2
0
uint32_t RIP_init (void)
{ /* Body */
    RIP_CFG_STRUCT_PTR  cfg = RTCS_getcfg(RIP);
    uint32_t err;

    if (RTCS_getcfg(RIP)) return RTCS_OK;
    /* allocate the memory */
    cfg = RTCS_mem_alloc_zero(sizeof(*cfg));
    if (!cfg)  return RTCSERR_OUT_OF_MEMORY;
    /* bind the udp port */
    err = UDP_openbind_internal(IPPORT_RIP, RIP_service, &cfg->UCB);
    if (err){
        _mem_free(cfg);
        return err;
    }

    RTCS_setcfg(RIP, cfg);
    ROUTE_register(&RIP_routefn);

    /* Start the retransmission timer to start sending immediately */
    cfg->TIMER_PERIODIC.TIME    = 0;
    cfg->TIMER_PERIODIC.EVENT   = RIP_expire_periodic;
    cfg->TIMER_PERIODIC.PRIVATE = NULL;
    TCPIP_Event_add(&cfg->TIMER_PERIODIC);

    /* probe all the interfaces now to build the route table faster */
    err = RIP_send_req();

    return RTCS_OK;
} /* Endbody */
Esempio n. 3
0
static IP_DGRAM_PTR IPREASM_get_dgram
   (
      _ip_address ipsrc,   /* [IN] the IP source */
      _ip_address ipdst,   /* [IN] the IP destination */
      uint8_t      proto,   /* [IN] the IP protocol */
      uint16_t     id       /* [IN] the IP ID */
   )
{ /* Body */
   register IP_DGRAM_PTR dgram;

   RTCS_DLIST_PEEK(IPREASM_head, dgram);
   if (dgram) {

      /* There's a good probability our IP_DGRAM is at the head of the list */
      if (dgram->family==AF_INET
       && ipsrc == dgram->header.IP4.IPSRC
       && ipdst == dgram->header.IP4.IPDST
       && proto == dgram->header.IP4.PROTO
       && id    == dgram->header.IP4.ID) {
         return dgram;
      } /* Endif */

      /* It's not at the head.  Scan the list for it */
      RTCS_DLIST_SEARCH_REST(IPREASM_head, dgram) {
         if (ipsrc == dgram->header.IP4.IPSRC
          && ipdst == dgram->header.IP4.IPDST
          && proto == dgram->header.IP4.PROTO
          && id    == dgram->header.IP4.ID) {
            /* Found it.  Move it to the head of the list */
            RTCS_DLIST_DEL(IPREASM_head, dgram);
            RTCS_DLIST_INS(IPREASM_head, dgram);
            return dgram;
         } /* Endif */
      } /* End SEARCH */

   } /* Endif */

   /* Not found.  Allocate one */
   dgram = RTCS_part_alloc_zero(IPREASM_part);
   if (!dgram) return NULL;

   /* Initialize it */
    dgram->family=AF_INET;
   dgram->header.IP4.IPSRC = ipsrc;
   dgram->header.IP4.IPDST = ipdst;
   dgram->header.IP4.PROTO = proto;
   dgram->header.IP4.ID    = id;
   dgram->TIMER.TIME  = IPREASM_TTL;
   dgram->TIMER.EVENT = IPREASM_expire;
   dgram->TIMER.PRIVATE = dgram;
   TCPIP_Event_add(&dgram->TIMER);

   /* Add it to the list*/
   RTCS_DLIST_INS(IPREASM_head, dgram);
   return dgram;

} /* Endbody */
Esempio n. 4
0
void NAT_event_del
   (
      NAT_EVENT_STRUCT_PTR    nat_event_ptr   /* [IN] NAT event to del */
   )
{ /* Body */
   TCPIP_EVENT_PTR      tcpip_event_ptr = nat_event_ptr->EVENT;
   NAT_EVENT_HEAD_PTR   nat_event_head_ptr;
   
   if (tcpip_event_ptr == NULL) {  /* If the event isn't in any queue, return */
      return;
   } /* Endif */ 
   
   /* If event is already deleted return */
   if ((nat_event_ptr->NEXT == NULL) && (nat_event_ptr->PREV == NULL) && (nat_event_ptr->EVENT == NULL))
   {
	   return;
   }
   NAT_event_tick(tcpip_event_ptr, FALSE);
   nat_event_head_ptr = tcpip_event_ptr->PRIVATE;   
   
   if (nat_event_ptr == nat_event_head_ptr->FIRST) {        /* 1st in the queue */
      TCPIP_Event_cancel(tcpip_event_ptr);
      nat_event_head_ptr->FIRST = nat_event_ptr->NEXT;
      if (nat_event_head_ptr->FIRST != NULL) {          /* If there are other nodes */
         nat_event_head_ptr->FIRST->TIME += nat_event_ptr->TIME;
         tcpip_event_ptr->TIME = nat_event_head_ptr->FIRST->TIME;
         nat_event_head_ptr->FIRST->PREV = NULL;
         TCPIP_Event_add(tcpip_event_ptr);
      } else { 
         nat_event_head_ptr->TIMEDELTA = 0;
         nat_event_head_ptr->LAST = NULL;
      } /* Endif */
   } else {                                  /* Not first in the queue */
      
      if (nat_event_head_ptr->LAST != nat_event_ptr) {                 /* Not last in the queue */
         nat_event_ptr->NEXT->TIME += nat_event_ptr->TIME;
         nat_event_ptr->NEXT->PREV = nat_event_ptr->PREV;
      } else { 
         nat_event_head_ptr->TIMEDELTA -= nat_event_ptr->TIME;
         nat_event_head_ptr->LAST = nat_event_ptr->PREV;
      } /* Endif */
      
      nat_event_ptr->PREV->NEXT = nat_event_ptr->NEXT;
      
   } /* Endif */   
   
   nat_event_ptr->NEXT = NULL;
   nat_event_ptr->PREV = NULL;
   nat_event_ptr->EVENT = NULL;
 
} /* Endbody */
Esempio n. 5
0
void IGMP_launch_timer
   (
      MC_MEMBER_PTR  member,
      uint32_t        delay
   )
{ /* Body */

   if (member->RUNNING_TIMER) {
      return;
   } /* Endif */

   member->TIMER.TIME = delay;
   member->RUNNING_TIMER = TRUE;
   TCPIP_Event_add(&member->TIMER);
} /* Endbody */
Esempio n. 6
0
void BOOTP_open
   (
      TCPIP_PARM_BOOTP _PTR_ parms
   )
{ /* Body */
   IP_IF_PTR      if_ptr = (IP_IF_PTR)parms->handle;
   BOOTP_CFG_PTR  bootp = (BOOTP_CFG_PTR) &parms->config;
   uint_32        error;

   error = BOOT_open(BOOT_service);
   if (error) {
      RTCSCMD_complete(parms, error);
      return;
   } /* Endif */

   if_ptr->BOOTFN = BOOTP_service;

   /* Pick a random transaction ID */
   bootp->XID = RTCS_rand();

   /* Set initial timeout */
   bootp->TIMEOUT = BOOTP_TIMEOUT_MIN;
   bootp->SECS = 0;

   /* Build a BOOTREQUEST packet */
   htonc(bootp->PACKET.OP,    BOOTPOP_BOOTREQUEST);
   htonc(bootp->PACKET.HTYPE, if_ptr->DEV_TYPE);
   htonc(bootp->PACKET.HLEN,  if_ptr->DEV_ADDRLEN);
   htonc(bootp->PACKET.HOPS,  0);
   htonl(bootp->PACKET.XID,   bootp->XID);
   htons(bootp->PACKET.FLAGS, 0x8000);
   htonl(bootp->PACKET.CIADDR, INADDR_ANY);
   htonl(bootp->PACKET.YIADDR, INADDR_ANY);
   htonl(bootp->PACKET.SIADDR, INADDR_ANY);
   htonl(bootp->PACKET.GIADDR, INADDR_ANY);

   _mem_zero(bootp->PACKET.CHADDR, sizeof(bootp->PACKET.CHADDR));
   _mem_copy(if_ptr->DEV_ADDR, bootp->PACKET.CHADDR, if_ptr->DEV_ADDRLEN);

   /* Start the retransmission timer to start sending immediately */
   bootp->RESEND.TIME    = 0;
   bootp->RESEND.EVENT   = BOOTP_send;
   bootp->RESEND.PRIVATE = if_ptr;
   TCPIP_Event_add(&bootp->RESEND);

   if_ptr->BOOT = (pointer)parms;

} /* Endbody */
Esempio n. 7
0
static void RIP_init_timer(
    IP_ROUTE_INDIRECT_PTR     gate,
    uint32_t                   metric
)
{ /* Body */

    if (metric < RIP_MAX_METRIC){  /* init the timeout */
        gate->RIP.TIMEOUT.TIME    = RIP_TIMEOUT_DEL;
        gate->RIP.TIMEOUT.EVENT   = RIP_expire_rte;
    }else{  /* init the garbage collection */
        gate->RIP.TIMEOUT.TIME    = RIP_TIMEOUT_GC;
        gate->RIP.TIMEOUT.EVENT   = RIP_expire_gc;
    }
    gate->RIP.TIMEOUT.PRIVATE = gate;
    TCPIP_Event_add(&gate->RIP.TIMEOUT);
} /* Endbody */
Esempio n. 8
0
static void RIP_trig_upd(
    void
)
{ /* Body */
    RIP_CFG_STRUCT_PTR     ripcfg = RTCS_getcfg(RIP);

    if (RTCS_getcfg(RIP) == NULL) return;

    /* if the timer is currently running, dont send the data */
    if (ripcfg->TIMER_TRIG_UPD.PRIVATE)
        return;

    /* send the changed routes */
    RIP_send_resp(ADV_VERSION, TRUE);

    /* start the timer */
    ripcfg->TIMER_TRIG_UPD.TIME = RND_RANGE(RIP_TIME_MIN_TRIG_UPD,
                        RIP_TIME_MAX_TRIG_UPD);
    ripcfg->TIMER_TRIG_UPD.EVENT = RIP_expire_trig_upd;
    ripcfg->TIMER_TRIG_UPD.PRIVATE = ripcfg;
    TCPIP_Event_add(&ripcfg->TIMER_TRIG_UPD);
} /* Endbody */
Esempio n. 9
0
/*FUNCTION*-------------------------------------------------------------
*
* Function Name   : ICMP6_send_echo
* Parameters      :
*
*     _ip_address       ipaddress   [IN] destination IP address
*     uint_32           timeout     [IN/OUT] timeout/rtt
*     uint_16           id          [IN] identification for echo message.
*     uint_16           seq         not used
*
* Comments        :
*     Send an ICMP Echo Request packet.
*
*END*-----------------------------------------------------------------*/
void ICMP6_send_echo(ICMP_ECHO_PARAM_PTR     parms)
{

#if RTCSCFG_ENABLE_IP6

   ICMP6_CFG_STRUCT_PTR     ICMP6_cfg_ptr = RTCS_getcfg(ICMP6);
   RTCSPCB_PTR              pcb;
   ICMP6_ECHO_HEADER_PTR    packet;
   _rtcs_if_handle          ihandle_dest = NULL; 
   uint_32                  error;


   IF_ICMP6_STATS_ENABLED(ICMP6_cfg_ptr->STATS.COMMON.ST_TX_TOTAL++);
   parms->seq = ICMP6_cfg_ptr->ECHO_SEQ++;

   pcb = RTCSPCB_alloc_send();
   if (pcb == NULL)
   {
      IF_ICMP6_STATS_ENABLED(ICMP6_cfg_ptr->STATS.COMMON.ST_TX_MISSED++);
      RTCSCMD_complete(parms, RTCSERR_PCB_ALLOC);
      return;
   } 
        
    if(parms->ping_param->data_buffer && parms->ping_param->data_buffer_size)
    {
        error = RTCSPCB_append_fragment(pcb, parms->ping_param->data_buffer_size, parms->ping_param->data_buffer);
        if (error) 
        {
            IF_ICMP6_STATS_ENABLED(ICMP6_cfg_ptr->STATS.COMMON.ST_TX_ERRORS++);
            RTCSLOG_PCB_FREE(pcb, error);
            RTCSPCB_free(pcb);
            RTCSCMD_complete(parms, error);
            return;
        }
   }

   error = RTCSPCB_insert_header(pcb, sizeof(ICMP6_ECHO_HEADER));
   if (error)
   {
      IF_ICMP6_STATS_ENABLED(ICMP6_cfg_ptr->STATS.COMMON.ST_TX_ERRORS++);
      IF_ICMP6_STATS_ENABLED(RTCS_seterror(&ICMP6_cfg_ptr->STATS.ERR_TX, error, (uint_32)pcb));
      RTCSLOG_PCB_FREE(pcb, error);
      RTCSPCB_free(pcb);
      RTCSCMD_complete(parms, error);
      return;
   } 

   RTCSLOG_PCB_WRITE(pcb, RTCS_LOGCTRL_PROTO(IPPROTO_ICMPV6), 0);

   packet = (ICMP6_ECHO_HEADER_PTR)RTCSPCB_DATA(pcb);
   pcb->TRANSPORT_LAYER = (uchar_ptr)packet;
   htonc(packet->HEAD.TYPE, ICMP6_TYPE_ECHO_REQ);
   htonc(packet->HEAD.CODE, 0);
   htons(packet->HEAD.CHECKSUM, 0);
   htons(packet->ID,  parms->ping_param->id);
   htons(packet->SEQ, parms->seq);

   pcb->IP_SUM     = IP_Sum_PCB(RTCSPCB_SIZE(pcb), pcb);
   pcb->IP_SUM_PTR = packet->HEAD.CHECKSUM;
  
   if(((sockaddr_in6 *)(&parms->ping_param->addr))->sin6_scope_id)
   {
        ihandle_dest = ip6_if_get_by_scope_id(((sockaddr_in6 *)(&parms->ping_param->addr))->sin6_scope_id);
   }

   parms->EXPIRE.TIME    = parms->ping_param->timeout;
   parms->EXPIRE.EVENT   = ICMP6_expire_echo;
   parms->EXPIRE.PRIVATE = parms;
   parms->start_time = RTCS_time_get();   /* get timestamp */

   error = IP6_send(pcb, IPPROTO_ICMPV6|IPTTL(parms->ping_param->hop_limit), NULL/*ipsrc*/, &((sockaddr_in6 *)(&parms->ping_param->addr))->sin6_addr/*ipdest*/, ihandle_dest, 0);


   if (error != RTCS_OK)
   {
      IF_ICMP6_STATS_ENABLED(ICMP6_cfg_ptr->STATS.COMMON.ST_TX_MISSED++);
      RTCSCMD_complete(parms, error);
      return;
   }

   /*
   ** If there is no error add the parm struct to config struct
   ** and initiate the event timer
   */

   IF_ICMP6_STATS_ENABLED(ICMP6_cfg_ptr->STATS.ST_TX_ECHO_REQ++);

   /* add the prameter structure to ICMP  cfg */
   parms->NEXT = ICMP6_cfg_ptr->ECHO_PARAM_HEAD;
   if (parms->NEXT)
   {
      parms->NEXT->PREV = &parms->NEXT;
   } /* Endif */
   ICMP6_cfg_ptr->ECHO_PARAM_HEAD = parms;
   parms->PREV = &ICMP6_cfg_ptr->ECHO_PARAM_HEAD;

   TCPIP_Event_add(&parms->EXPIRE);

#else
    RTCSCMD_complete(parms, RTCSERR_IP_IS_DISABLED);
#endif /* RTCSCFG_ENABLE_IP6 */
}