/* * the main procedure for processing udp packets */ bool tc_proc_ingress(tc_iph_t *ip, tc_udpt_t *udp) { int ret; uint16_t tot_len; transfer_map_t *test; tot_len = ntohs(ip->tot_len); test = get_test_pair(&(clt_settings.transfer), ip->daddr, udp->dest); if (test == NULL) { tc_log_info(LOG_ERR, 0, "retrieve test pair error"); return false; } ip->daddr = test->target_ip; udp->dest = test->target_port; udpcsum(ip, udp); /* check if it needs fragmentation */ if (tot_len > clt_settings.mtu) { ip_fragmentation(ip); } else { ret = tc_raw_socket_snd(tc_raw_socket_out, ip, tot_len, ip->daddr); if (ret == TC_ERR) { tc_log_info(LOG_ERR, 0, "send to back error,tot_len:%d", tot_len); } clt_udp_send_cnt++; } return true; }
/* * The main procedure for processing the filtered packets */ bool process(char *packet, int pack_src) { ssize_t send_len; uint16_t size_ip, tot_len; struct iphdr *ip_header; struct udphdr *udp_header; ip_port_pair_mapping_t *test; ip_header = (struct iphdr*)packet; size_ip = ip_header->ihl<<2; tot_len = ntohs(ip_header->tot_len); udp_header = (struct udphdr*)((char *)ip_header + size_ip); test = get_test_pair(&(clt_settings.transfer), ip_header->saddr, udp_header->source); ip_header->daddr = test->target_ip; udp_header->dest = test->target_port; udpcsum(ip_header, udp_header); ip_header->check = 0; ip_header->check = csum((unsigned short *)ip_header, size_ip); send_len = send_ip_packet(ip_header, tot_len); if (-1 == send_len) { log_info(LOG_ERR, "send to back error,tot_len:%d", tot_len); return false; } return true; }
/* * the main procedure for processing the filtered packets */ bool process(char *packet, int pack_src) { int diff; time_t cur_time; ssize_t send_len; uint16_t size_ip, tot_len; struct iphdr *ip_header; struct udphdr *udp_header; ip_port_pair_mapping_t *test; /* TODO time update will be optimized later */ cur_time = time(0); if (last_record_time != 0) { diff = cur_time - last_record_time; if (diff > 3) { log_info(LOG_INFO, "udp packets captured:%llu,packets sent:%llu", clt_udp_cnt, clt_udp_send_cnt); last_record_time = cur_time; } } else { last_record_time = cur_time; } ip_header = (struct iphdr *)packet; size_ip = ip_header->ihl<<2; tot_len = ntohs(ip_header->tot_len); udp_header = (struct udphdr*)((char *)ip_header + size_ip); test = get_test_pair(&(clt_settings.transfer), ip_header->daddr, udp_header->dest); ip_header->daddr = test->target_ip; udp_header->dest = test->target_port; udpcsum(ip_header, udp_header); ip_header->check = 0; ip_header->check = csum((unsigned short *)ip_header, size_ip); /* check if it needs fragmentation */ if (tot_len > clt_settings.mtu) { ip_fragmentation(ip_header, udp_header); } else { send_len = send_ip_packet(ip_header, tot_len); if (-1 == send_len) { log_info(LOG_ERR, "send to back error,tot_len:%d", tot_len); return false; } clt_udp_send_cnt++; } return true; }