all: dccp2tcp dccp2tcp.1
-dccp2tcp: dccp2tcp.o encap.o connections.o ccid2.o
- gcc ${CFLAGS} ${LDLIBS} --std=gnu99 dccp2tcp.o encap.o connections.o ccid2.o -odccp2tcp
+dccp2tcp: dccp2tcp.o encap.o connections.o ccid2.o checksums.o
+ gcc ${CFLAGS} ${LDLIBS} --std=gnu99 dccp2tcp.o encap.o connections.o ccid2.o checksums.o -odccp2tcp
dccp2tcp.o: dccp2tcp.h dccp2tcp.c
gcc ${CFLAGS} ${LDLIBS} --std=gnu99 -c dccp2tcp.c -odccp2tcp.o
connections.o: dccp2tcp.h connections.c
gcc ${CFLAGS} ${LDLIBS} --std=gnu99 -c connections.c -oconnections.o
+
+checksums.o: checksums.c checksums.h
+ gcc ${CFLAGS} ${LDLIBS} --std=gnu99 -c checksums.c -ochecksums.o
dccp2tcp.1: dccp2tcp.pod
pod2man -s 1 -c "dccp2tcp" dccp2tcp.pod > dccp2tcp.1
This program does have several important limitations:
1)CCID2 ONLY
2)DCCP MUST use 48 bit sequence numbers.
- 3)Checksums are not computed (they are zeroed).
- 4)DCCP DATA packets are not implemented (Linux doesn't use them)
- 5)DCCP Ack packets show up as TCP packets containing one byte
+ 3)DCCP DATA packets are not implemented (Linux doesn't use them)
+ 4)DCCP Ack packets show up as TCP packets containing one byte
dccp2tcp is free software: you can redistribute it and/or modify
Utility to convert a DCCP flow to a TCP flow for DCCP analysis via
tcptrace.
-Copyright (C) 2012 Samuel Jero <sj323707@ohio.edu>
+Copyright (C) 2013 Samuel Jero <sj323707@ohio.edu>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
along with this program. If not, see <http://www.gnu.org/licenses/>.
Author: Samuel Jero <sj323707@ohio.edu>
-Date: 11/2012
+Date: 02/2013
Notes:
1)CCID2 ONLY
2)DCCP MUST use 48 bit sequence numbers
- 3)Checksums are not computed (they are zeroed)
- 4)DCCP DATA packets are not implemented (Linux doesn't use them)
- 5)DCCP Ack packets show up as TCP packets containing one byte
+ 3)DCCP DATA packets are not implemented (Linux doesn't use them)
+ 4)DCCP Ack packets show up as TCP packets containing one byte
******************************************************************************/
#include "dccp2tcp.h"
--- /dev/null
+/******************************************************************************
+IPv4 and IPv6 Header Checksum Code
+
+Copyright (C) 2013 Samuel Jero <sj323707@ohio.edu>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Author: Samuel Jero <sj323707@ohio.edu>
+Date: 02/2013
+******************************************************************************/
+#include <string.h>
+#include <arpa/inet.h>
+#include "checksums.h"
+
+/*Stupid Solaris*/
+#ifndef u_int32_t
+#define u_int32_t uint32_t
+#endif
+#ifndef u_int16_t
+#define u_int16_t uint16_t
+#endif
+
+//Pseudo Headers for checksums
+struct ip6_pseudo_hdr{
+ u_char src[IP6_ADDR_LEN];
+ u_char dest[IP6_ADDR_LEN];
+ unsigned int len;
+ u_char zero[3];
+ u_char nxt;
+};
+struct ip4_pseudo_hdr{
+ u_char src[IP4_ADDR_LEN];
+ u_char dest[IP4_ADDR_LEN];
+ unsigned int len;
+ u_char zero[3];
+ u_char nxt;
+};
+
+/*From http://gitorious.org/freebsd/freebsd/blobs/HEAD/sbin/dhclient/packet.c
+ * under GNU GPL*/
+u_int32_t checksum(u_char *buf, unsigned nbytes, u_int32_t sum)
+{
+ int i;
+ /* Checksum all the pairs of bytes first... */
+ for (i = 0; i < (nbytes & ~1U); i += 2) {
+ sum += (u_int16_t)ntohs(*((u_int16_t *)(buf + i)));
+ if (sum > 0xFFFF)
+ sum -= 0xFFFF;
+ }
+ /*
+ * If there's a single byte left over, checksum it, too.
+ * Network byte order is big-endian, so the remaining byte is
+ * the high byte.
+ */
+ if (i < nbytes) {
+ sum += buf[i] << 8;
+ if (sum > 0xFFFF)
+ sum -= 0xFFFF;
+ }
+ return (sum);
+}
+
+/*From http://gitorious.org/freebsd/freebsd/blobs/HEAD/sbin/dhclient/packet.c
+ * under GNU GPL*/
+u_int32_t wrapsum(u_int32_t sum)
+{
+ sum = ~sum & 0xFFFF;
+ return (htons(sum));
+}
+
+u_int16_t ipv6_pseudohdr_chksum(u_char* buff, int len, u_char* dest, u_char* src, int type){
+ struct ip6_pseudo_hdr hdr;
+
+ //create pseudo header
+ memset(&hdr, 0, sizeof(struct ip6_pseudo_hdr));
+ memcpy(hdr.src, src, IP6_ADDR_LEN);
+ memcpy(hdr.dest, dest, IP6_ADDR_LEN);
+ hdr.nxt=type;
+ hdr.len=htonl(len);
+
+ //calculate total checksum
+ return wrapsum(checksum((unsigned char*)&hdr,sizeof(struct ip6_pseudo_hdr),checksum(buff,len,0)));
+}
+
+u_int16_t ipv4_pseudohdr_chksum(u_char* buff, int len, u_char* dest, u_char* src, int type){
+ struct ip4_pseudo_hdr hdr;
+
+ //create pseudo header
+ memset(&hdr, 0, sizeof(struct ip4_pseudo_hdr));
+ memcpy(hdr.src, src, IP4_ADDR_LEN);
+ memcpy(hdr.dest, dest, IP4_ADDR_LEN);
+ hdr.nxt=type;
+ hdr.len=htonl(len);
+
+ //calculate total checksum
+ return wrapsum(checksum((u_char*)&hdr,sizeof(struct ip4_pseudo_hdr),checksum(buff,len,0)));
+}
+
+u_int16_t ipv4_chksum(u_char* buff, int len){
+ return wrapsum(checksum(buff,len,0));
+}
--- /dev/null
+/******************************************************************************
+IPv4 and IPv6 Header Checksum Code
+
+Copyright (C) 2013 Samuel Jero <sj323707@ohio.edu>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Author: Samuel Jero <sj323707@ohio.edu>
+Date: 02/2013
+******************************************************************************/
+#ifndef CHECKUMS_H
+#define CHECKSUMS_H
+
+#include <ctype.h>
+#include <sys/types.h>
+
+#define IP4_ADDR_LEN 4
+#define IP6_ADDR_LEN 16
+
+u_int16_t ipv6_pseudohdr_chksum(u_char* buff, int len, u_char* dest, u_char* src, int type);
+u_int16_t ipv4_pseudohdr_chksum(u_char* buff, int len, u_char* dest, u_char* src, int type);
+u_int16_t ipv4_chksum(u_char* buff, int len);
+
+
+#endif
Notes:
1)CCID2 ONLY
2)DCCP MUST use 48 bit sequence numbers
- 3)Checksums are not computed (they are zeroed)
- 4)DCCP DATA packets are not implemented (Linux doesn't use them)
- 5)DCCP Ack packets show up as TCP packets containing one byte
+ 3)DCCP DATA packets are not implemented (Linux doesn't use them)
+ 4)DCCP Ack packets show up as TCP packets containing one byte
******************************************************************************/
#include "dccp2tcp.h"
/*do all the dccp to tcp conversions*/
int convert_packet(struct packet *new, const struct const_packet* old)
{
+ struct tcphdr *tcph;
struct dccp_hdr *dccph;
struct dccp_hdr_ext *dccphex;
struct host *h1=NULL;
}
/*cast header pointers*/
+ tcph=(struct tcphdr*)new->data;
dccph=(struct dccp_hdr*)old->data;
dccphex=(struct dccp_hdr_ext*)(old->data+sizeof(struct dccp_hdr));
/*TODO: Add CCID detection*/
if(h1->type==CCID2 && h2->type==CCID2){
- return ccid2_convert_packet(new,old);
+ if(ccid2_convert_packet(new,old)==0){
+ return 0;
+ }
}
if(h1->type==CCID3 && h2->type==CCID3){
- //return ccid3_convert_packet(new,old);
+ //ccid3_convert_packet(new,old);
+ }
+ if(ccid2_convert_packet(new,old)==0){
+ return 0;
+ }
+
+ /*Compute TCP checksums*/
+ if(new->id_len==IP4_ADDR_LEN){
+ tcph->check=0;
+ tcph->check=ipv4_pseudohdr_chksum(new->data,
+ new->length, new->dest_id, new->src_id, 6);
+ }else if(new->id_len==IP6_ADDR_LEN){
+ tcph->check=0;
+ tcph->check=ipv6_pseudohdr_chksum(new->data,
+ new->length, new->dest_id, new->src_id, 6);
+ }else{
+ tcph->check=0;
+ dbgprintf(2,"Unknown ID Length, can't do checksums");
}
- return ccid2_convert_packet(new,old);
+ return 1;
}
void version(){
Notes:
1)CCID2 ONLY
2)DCCP MUST use 48 bit sequence numbers
- 3)Checksums are not computed (they are zeroed)
- 4)DCCP DATA packets are not implemented (Linux doesn't use them)
- 5)DCCP Ack packets show up as TCP packets containing one byte
+ 3)DCCP DATA packets are not implemented (Linux doesn't use them)
+ 4)DCCP Ack packets show up as TCP packets containing one byte
******************************************************************************/
#ifndef _DCCP2TCP_H
#define _DCCP2TCP_H
#include <ctype.h>
#include <pcap.h>
#include <linux/dccp.h>
+#include "checksums.h"
#define MAX_PACKET 1600 /*Maximum size of TCP packet */
from http://www.tcptrace.org and the version of B<xplot> available from http://www.tcptrace.org under
"Useful Companion Programs".
-B<dccp2tcp> only supports DCCP CCID 2 with 48 bit sequence numbers at this time. Further, checksums are
-not computed on the output packets---they are simply zeroed.
+B<dccp2tcp> only supports DCCP CCID 2 with 48 bit sequence numbers at this time.
=head1 OPTIONS
Notes:
1)CCID2 ONLY
2)DCCP MUST use 48 bit sequence numbers
- 3)Checksums are not computed (they are zeroed)
- 4)DCCP DATA packets are not implemented (Linux doesn't use them)
- 5)DCCP Ack packets show up as TCP packets containing one byte
+ 3)DCCP DATA packets are not implemented (Linux doesn't use them)
+ 4)DCCP Ack packets show up as TCP packets containing one byte
******************************************************************************/
#include "dccp2tcp.h"
#include "encap.h"
+#include "checksums.h"
#include <pcap/sll.h>
#include <netinet/ip6.h>
/*Adjust IPv4 header to account for packet's total length*/
iph->tot_len=htons(new->length);
+ /*Compute IPv4 Checksum*/
+ iph->check=0;
+ iph->check=ipv4_chksum(new->data,iph->ihl*4);
+
/*Cleanup*/
free(nnew.src_id);
free(nnew.dest_id);