From owner-p4-projects@FreeBSD.ORG Tue May 20 03:33:06 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 4745C1065671; Tue, 20 May 2008 03:33:06 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E2EB01065670 for ; Tue, 20 May 2008 03:33:05 +0000 (UTC) (envelope-from rfrench@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id DF6368FC1F for ; Tue, 20 May 2008 03:33:05 +0000 (UTC) (envelope-from rfrench@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m4K3X5dx066523 for ; Tue, 20 May 2008 03:33:05 GMT (envelope-from rfrench@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m4K3X5Jd066521 for perforce@freebsd.org; Tue, 20 May 2008 03:33:05 GMT (envelope-from rfrench@FreeBSD.org) Date: Tue, 20 May 2008 03:33:05 GMT Message-Id: <200805200333.m4K3X5Jd066521@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to rfrench@FreeBSD.org using -f From: Ryan French To: Perforce Change Reviews Cc: Subject: PERFORCE change 141883 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 May 2008 03:33:06 -0000 http://perforce.freebsd.org/chv.cgi?CH=141883 Change 141883 by rfrench@rfrench_mpls on 2008/05/20 03:32:12 MPLS-Needle is now working as planned. It will read in the config file, extract the information from the file for the headers, and send the packets to an available BPF device. I will include a readme file on how the config file is structured at a later date. All in all it should be pretty simple to see from the included one thou. Submitted by: Ryan French Affected files ... .. //depot/projects/soc2008/rfrench_mpls/mpls-needle/mpls-needle.c#3 edit .. //depot/projects/soc2008/rfrench_mpls/mpls-needle/mpls-needle.conf#2 edit Differences ... ==== //depot/projects/soc2008/rfrench_mpls/mpls-needle/mpls-needle.c#3 (text+ko) ==== @@ -58,10 +58,9 @@ char line[128]; uint32_t i; - char dev[16]; - size_t len = 16; + int fd; + size_t len; - uint8_t *buf; ssize_t wb; //datagram data @@ -71,11 +70,9 @@ if (argc < 5) { fprintf(stderr,"incorrect usage of program - refer to documentation\n"); - return 1; + return -1; } - dl_bpf_open(&if_name); - for(i=1; iip_hl = 5; iph->ip_v = 4; iph->ip_tos = ip4_tos; - iph->ip_len = (sizeof(struct ip) + sizeof(struct icmphdr)); + iph->ip_len = htons((iph->ip_hl<<2) + 8 + 20); iph->ip_id = htonl (54321); iph->ip_off = 0; iph->ip_ttl = ip4_ttl; iph->ip_p = 1; iph->ip_sum = 0; - iph->ip_sum = in_cksum((unsigned short *)iph, sizeof(iph)); iph->ip_src.s_addr = inet_addr(inet_ntoa(ip4_src)); iph->ip_dst.s_addr = inet_addr(inet_ntoa(ip4_dst)); + iph->ip_sum = in_cksum((unsigned short *)iph, iph->ip_hl<<2); //set values in icmp header icmph->icmp_type = icmp_type; icmph->icmp_code = icmp_code; icmph->icmp_cksum = 0; - icmph->icmp_cksum = in_cksum((unsigned short *)icmph, sizeof(icmph)); + icmph->icmp_cksum = htons(in_cksum((unsigned short *)icmph, sizeof(icmph))); //set values in mpls header - uint32_t mplsh = htonl(mpls_label << 12 | mpls_qos << 9 | mpls_bos_flag << 8 | mpls_ttl); + mplsh = htonl(mpls_label << 12 | mpls_qos << 9 | mpls_bos_flag << 8 | mpls_ttl); memcpy(&datagram[14], &mplsh, 4); + *len = (14 + (sizeof(mplsh)) + (iph->ip_hl<<2) + 8 + 20); + printf("\nbuilt packets values\n"); printf("dst_mac = %s\n", ether_ntoa(&dst_mac)); @@ -468,7 +476,7 @@ do { - snprintf(dev, len, "/dev/bpf%d\n", i); + snprintf(dev, len, "/dev/bpf%d", i); if((fd = open(dev, O_RDWR)) == -1) { if(errno == EBUSY) @@ -513,4 +521,3 @@ return fd; } - ==== //depot/projects/soc2008/rfrench_mpls/mpls-needle/mpls-needle.conf#2 (text+ko) ==== @@ -1,1 +1,3 @@ -dst_mac 00:16:d3:fc:c0:b8 ip4 10.1.60.134/10.1.60.134/2/0 icmp 0/0 mpls 1/1/1/3 +dst_mac 00:16:d3:fc:c0:b8 ip4 10.1.18.149/10.1.18.162/2/0 icmp 0/0 mpls 55/1/1/3 +dst_mac 00:16:d3:fc:c0:b8 ip4 10.1.18.149/10.1.18.162/2/0 icmp 0/0 mpls 44/1/1/3 +dst_mac 00:16:d3:fc:c0:b8 ip4 10.1.18.149/10.1.18.162/2/0 icmp 0/0 mpls 66/1/1/3