/* * Forward an IP packet. It finds an appropriate route for the packet, * decrements the TTL value of the packet, adjusts the checksum and outputs * the packet on the appropriate interface. */ static void ip_forward (ip_t *ip, buf_t *p, ip_addr_const gateway, netif_t *netif, ip_addr_const netif_ipaddr) { ip_hdr_t *iphdr = (ip_hdr_t*) p->payload; /* Decrement TTL and send ICMP if ttl == 0. */ if (iphdr->ttl <= 1) { /* Don't send ICMP messages in response to ICMP messages */ if (iphdr->proto != IP_PROTO_ICMP) { icmp_time_exceeded (ip, p); } return; } iphdr->ttl--; /* Incremental update of the IP checksum. */ if (iphdr->chksum_h != 0xff) iphdr->chksum_h += 1; else if (iphdr->chksum_l != 0xff) { iphdr->chksum_h = 0; iphdr->chksum_l += 1; } else { iphdr->chksum_h = 1; iphdr->chksum_l = 0; } /* Forwarding packet to netif. */ if (! gateway) gateway = iphdr->dest.var; netif_output (netif, p, gateway, netif_ipaddr); ++ip->forw_datagrams; }
void test_task () { buf_t *p; for (;;) { /* Check received data. */ p = netif_input (ð.netif); if (p) { if (memcmp (p->payload, data_pattern, packet_size) != 0) printf (&debug, "\npacket #%ld: data error\n", eth.netif.in_packets); buf_free (p); continue; } /* Send packets - make transmit queue full. */ if (run_test_flag) { p = buf_alloc (&pool, packet_size, 16); if (p) { memcpy (p->payload, data_pattern, packet_size); netif_output (ð.netif, p, 0, 0); } } k5600bg1_poll (ð); } }
void send_packets(int num) { int i; buf_t *p; for (i = 0; i < num; ++i) { p = buf_alloc(&pool, packet_size, 16); if (!p) { printf(&debug, "out of memory\n"); break; } memcpy(p->payload, data_pattern, packet_size); if (!netif_output(ð.netif, p, 0, 0)) printf(&debug, "cannot send packet\n"); } }
void main_test () { buf_t *p; int i = 0; const unsigned delay = 20; mdelay(start_delay); data_pattern = mem_alloc (&pool, packet_size); memset (data_pattern, 0xa5, packet_size); if (packet_size >= 12) memcpy (data_pattern+6, eth.netif.ethaddr, 6); unsigned long time0 = timer_milliseconds(&timer); while (1) { //for (i = 0; i < nb_of_packets; ++i) { /* Check received data. */ p = netif_input (ð.netif); if (p) { if (memcmp (p->payload, data_pattern, packet_size) != 0) nerr++; nb_of_received++; buf_free (p); continue; } /* Send packets - make transmit queue full. */ if (i++ < nb_of_packets) { p = buf_alloc (&pool, packet_size, 16); if (p) { memcpy (p->payload, data_pattern, packet_size); netif_output (ð.netif, p, 0, 0); } else debug_printf("no mem\n"); } if ((nb_of_received == nb_of_packets) || timer_passed(&timer, time0, delay * nb_of_packets * 2)) break; timer_delay (&timer, delay); } nerr += nb_of_packets - nb_of_received; STOP; }
void hello (void *data) { buf_t *p; debug_printf ("\n*** Testing SLIP on UART 1 ***\n"); mutex_lock (&slip.netif.lock); for (;;) { mutex_wait (&slip.netif.lock); p = netif_input (&slip.netif); if (p) { buf_print_ip (p); #if 1 netif_output (&slip.netif, p, 0, 0); #else buf_free (p); #endif } } }