From: Samuel Jero Date: Fri, 28 Jun 2013 18:15:45 +0000 (-0400) Subject: Remove extra SLL.patch X-Git-Url: http://sjero.net/git/?p=ltp2tcp;a=commitdiff_plain;h=415ee2322fe2a27adcd10e5db2871699fc4f4f07 Remove extra SLL.patch --- diff --git a/SLL.patch b/SLL.patch deleted file mode 100644 index 98b6cd8..0000000 --- a/SLL.patch +++ /dev/null @@ -1,573 +0,0 @@ -diff -r ab54ffb0cb71 Makefile ---- a/Makefile Fri Mar 04 11:30:16 2011 -0500 -+++ b/Makefile Thu May 19 01:11:51 2011 -0400 -@@ -22,8 +22,8 @@ - - all: ltptrace - --ltptrace: main.o ltp.o encap.o udp.o dccp.o Makefile -- gcc ${CFLAGS} ${LDLIBS} --std=gnu99 main.o ltp.o encap.o udp.o dccp.o -oltptrace -+ltptrace: main.o ltp.o encap.o udp.o dccp.o sll.o Makefile -+ gcc ${CFLAGS} ${LDLIBS} --std=gnu99 main.o ltp.o encap.o udp.o dccp.o sll.o -oltptrace - - main.o: ltp2tcp.c ltp2tcp.h - gcc -c ${CFLAGS} ${LDLIBS} --std=gnu99 ltp2tcp.c -omain.o -@@ -40,6 +40,9 @@ - dccp.o: dccp_encap.c encap.h ltp2tcp.h - gcc -c ${CFLAGS} ${LDLIBS} --std=gnu99 dccp_encap.c -odccp.o - -+sll.o: sll_encap.c encap.h ltp2tcp.h -+ gcc -c ${CFLAGS} ${LDLIBS} --std=gnu99 sll_encap.c -osll.o -+ - - install: ltptrace - install -m 755 -o bin -g bin ltptrace ${BINDIR}/ltptrace -diff -r ab54ffb0cb71 encap.c ---- a/encap.c Fri Mar 04 11:30:16 2011 -0500 -+++ b/encap.c Thu May 19 01:11:51 2011 -0400 -@@ -20,6 +20,10 @@ - state.en_ops=&dccp_encap; - return; - } -+ if(strcmp(string, "sll")==0 || strcmp(string,"SLL")==0){ /*SLL (Linux Cooked Capture)*/ -+ state.en_ops=&sll_encap; -+ return; -+ } - printf("Encapsulation type: %s is not supported\n", string); - exit(1); - return; -@@ -245,7 +249,6 @@ - u_char *ptr; - struct pcap_pkthdr nh; - u_int32_t temp; -- struct udp_en_p *uep; - - /*Safety Check*/ - if(eip==NULL){ -@@ -275,7 +278,6 @@ - - /* Copy Ethernet and IP headers from private data area*/ - /* These are headers from the first packet in the capture*/ -- uep=(struct udp_en_p *) state.en_priv; - memcpy(ptr, eip->od, sizeof(struct ether_header)+ sizeof(struct iphdr)); - - /*Adjust IP header*/ -diff -r ab54ffb0cb71 LTP connection visualization/encap.h ---- a/LTP connection visualization/encap.h Fri Mar 04 11:30:16 2011 -0500 -+++ b/LTP connection visualization/encap.h Thu May 19 01:11:51 2011 -0400 -@@ -68,6 +68,7 @@ - /*Encapsulation Operations Structures*/ - extern struct encap_ops udp_encap; - extern struct encap_ops dccp_encap; -+extern struct encap_ops sll_encap; - - - /*Encapsulation Selector*/ -diff -r ab54ffb0cb71 sll_encap.c ---- /dev/null Thu Jan 01 00:00:00 1970 +0000 -+++ b/sll_encap.c Thu May 19 01:11:51 2011 -0400 -@@ -0,0 +1,487 @@ -+/****************************************************************************** -+Author: Samuel Jero -+ -+Date: 5/2011 -+ -+Description: encapsulation functions -+ -+******************************************************************************/ -+#include "ltp2tcp.h" -+#include -+#include -+ -+extern int debug; -+ -+ -+ -+/*SLL encapsulation private data structure*/ -+struct sll_en_p{ -+ int first; -+ struct pcap_pkthdr header; -+ u_char od[sizeof(struct sll_header)+sizeof(struct iphdr)+sizeof(struct udphdr)]; -+}; -+ -+ -+/*Fill the encapsulation structure*/ -+int fill_sllip4_encap(struct sll_en_p *slip, const u_char* data, int dlen, struct pcap_pkthdr *h){ -+ /*safety check*/ -+ if(slip==NULL || data==NULL || h==NULL || dlen < sizeof(struct sll_header)+sizeof(struct iphdr)){ -+ dbgprintf(1, "Error: SLL, IPv4 Encapsulation method given bad data!\n"); -+ return -1; -+ } -+ -+ if(slip->first==0){ -+ /* First time, allocate memory and copy libpcap header and encap headers -+ * this guarantees the IP "direction" of the encap headers */ -+ memcpy(&slip->header, h, sizeof(struct pcap_pkthdr)); -+ memcpy(slip->od, data,sizeof(struct sll_header)+sizeof(struct iphdr)); -+ slip->first=1; -+ }else{ -+ /* Just update the libpcap header (and associated timestamp)*/ -+ memcpy(&slip->header, h, sizeof(struct pcap_pkthdr)); -+ } -+ return 0; -+} -+ -+/* encapsulation manipulation previous to packet conversion */ -+int sll_encap_pre(struct pcap_pkthdr *h, const u_char **odata, u_char **ndata, int* olength, int* nlength) -+{ -+ struct iphdr *iph; -+ struct sll_header *slh; -+ struct udphdr *udph; -+ -+ /*Safety checks*/ -+ if(!h || !odata || !ndata || !*odata || !*ndata || !olength || !nlength){ -+ dbgprintf(0,"Error: SLL Encapsulation given bad data!\n"); -+ exit(1); -+ } -+ if(*olength < sizeof(struct ether_header)+sizeof(struct iphdr)+sizeof(struct udphdr) -+ || *nlength < sizeof(struct ether_header)+sizeof(struct iphdr)+sizeof(struct tcphdr)){ -+ dbgprintf(0, "Error: SLL Encapsulation given packet of wrong size!\n"); -+ return -1; -+ } -+ -+ /*initialize encapsulation private data*/ -+ if(state.en_priv==NULL){ -+ /* First time, allocate memory and copy libpcap header and encap headers -+ * this guarantees the IP "direction" of the encap headers */ -+ state.en_priv=malloc(sizeof(struct sll_en_p)); -+ if(state.en_priv==NULL){ -+ dbgprintf(0,"Error: Couldn't allocate Memory\n"); -+ exit(1); -+ } -+ } -+ if(fill_sllip4_encap((struct sll_en_p*)state.en_priv, *odata, *olength, h)<0){ -+ return -1; -+ } -+ -+ /*Copy SLL and IPv4 headers over*/ -+ memcpy(*ndata, *odata, sizeof(struct sll_header)+sizeof(struct iphdr)); -+ *odata+=sizeof(struct sll_header)+ sizeof(struct iphdr); -+ *ndata+=sizeof(struct sll_header)+ sizeof(struct iphdr); -+ -+ /*Confirm that this is Ethernet and that IPv4 is next*/ -+ slh=(struct sll_header*)(*odata -sizeof(struct sll_header)- sizeof(struct iphdr)); -+ if(slh->sll_protocol!=htons(ETHERTYPE_IP)){ -+ dbgprintf(1, "Note: Packet not SLL or Not IPv4 next\n"); -+ return -1; -+ } -+ -+ /* Check That this is IPv4 and that UDP is next*/ -+ iph= (struct iphdr *) (*ndata - sizeof(struct iphdr)); -+ if(iph->version!=4){ -+ dbgprintf(1, "Note: Packet is not IPv4\n"); -+ return -1; -+ } -+ if(iph->protocol!=0x11){ -+ dbgprintf(1, "Note: Packet is not UDP\n"); -+ return -1; -+ } -+ -+ /*set ip to indicate that tcp is next protocol*/ -+ iph->protocol=6; -+ iph->check=htonl(0); -+ -+ /* Adjust libpcap headers*/ -+ h->caplen=sizeof(struct sll_header) +sizeof(struct iphdr); -+ h->len=sizeof(struct sll_header) +sizeof(struct iphdr); -+ -+ /*Adjust packet length*/ -+ udph=(struct udphdr*)*odata; -+ *olength=ntohs(udph->len); -+ -+ /*Adjust New Packet Length*/ -+ *nlength-=sizeof(struct sll_header) +sizeof(struct iphdr); -+ -+ /*Move Packet Pointer past UDP header*/ -+ *odata+=sizeof(struct udphdr); -+return 0; -+} -+ -+/* encapsulation manipulation after conversion */ -+int sll_encap_post(int tlen, u_char *data) -+{ -+ struct iphdr *iph; -+ -+ /* Move data pointer to start of IPv4 header*/ -+ data+=sizeof(struct sll_header); -+ -+ /*Determine if the given length is reasonable*/ -+ if((tlen+sizeof(struct iphdr)) > 0xFFFF){ -+ dbgprintf(1, "Error: Given TCP header+data length is too large for an IPv4 packet!\n"); -+ return -1; -+ } -+ -+ /*Adjust IPv4 header to account for packet's total length*/ -+ iph=(struct iphdr*)data; -+ iph->tot_len=htons(sizeof(struct iphdr)+tlen); -+ return 0; -+} -+ -+/* Create a TCP three-way handshake */ -+int sll_encap_handshake(struct pcap_pkthdr *h) -+{ -+ struct iphdr *iph; -+ struct tcphdr *tcph; -+ u_char *data; -+ u_char *ptr; -+ struct pcap_pkthdr nh; -+ u_int32_t temp; -+ struct sll_en_p *slip=(struct sll_en_p*)state.en_priv; -+ -+ -+ /*Safety Check*/ -+ if(h==NULL || state.en_priv==NULL){ -+ dbgprintf(1, "Error: SLL, IPv4 Encapsulation handshake method given bad data!\n"); -+ return -1; -+ } -+ -+ /*create new libpcap header*/ -+ memcpy(&nh, h, sizeof(struct pcap_pkthdr)); -+ -+ /*create buffer for new packet*/ -+ ptr=data=malloc(MAX_PACKET); -+ if(data==NULL){ -+ dbgprintf(0,"Error: Couldn't allocate Memory\n"); -+ exit(1); -+ } -+ -+ /* 1)Create Syn Packet*/ -+ /*make sure the packet is all zero*/ -+ memset(data, 0, MAX_PACKET); -+ ptr=data; -+ -+ /*Set the libpcap header*/ -+ nh.caplen=sizeof(struct sll_header) +sizeof(struct iphdr)+sizeof(struct tcphdr)+4; -+ nh.len=sizeof(struct sll_header) +sizeof(struct iphdr)+sizeof(struct tcphdr)+4; -+ nh.ts.tv_usec-=3000; /*Time comes from the first packet received, so make these packets earlier*/ -+ -+ /* Copy SLL and IP headers from private data area*/ -+ /* These are headers from the first packet in the capture*/ -+ memcpy(ptr, slip->od, sizeof(struct sll_header)+ sizeof(struct iphdr)); -+ -+ /*Adjust IP header*/ -+ iph= (struct iphdr *) (ptr + sizeof(struct sll_header)); -+ iph->protocol=6; -+ iph->check=htonl(0); -+ iph->tot_len=htons(sizeof(struct iphdr)+sizeof(struct tcphdr)+4); -+ -+ /*Build TCP header*/ -+ ptr+=sizeof(struct sll_header)+ sizeof(struct iphdr); -+ tcph=(struct tcphdr*)ptr; -+ tcph->source=htons(1113); -+ tcph->dest=htons(1113); -+ tcph->doff=6; -+ tcph->check=htonl(0); -+ tcph->urg_ptr=0; -+ tcph->urg=0; -+ tcph->psh=0; -+ tcph->fin=0; -+ tcph->syn=1; -+ tcph->rst=0; -+ tcph->ack=0; -+ -+ /*Initialize Sequence and Acknowledgment Numbers and Window*/ -+ tcph->seq=htonl(state.seq_num++); -+ tcph->ack_seq=htonl(0); -+ tcph->window=htons(WIN_FACTOR); -+ -+ /* Add SACK permitted option*/ -+ ptr+=sizeof(struct tcphdr); -+ *ptr=4; -+ ptr++; -+ *ptr=2; -+ -+ /*Save To Packet Capture*/ -+ pcap_dump((u_char*)state.out,&nh, data); -+ -+ -+ /* 2)Create Syn,Ack Packet*/ -+ /*make sure the packet is all zero*/ -+ memset(data, 0, MAX_PACKET); -+ ptr=data; -+ -+ /*Set the libpcap header*/ -+ nh.caplen=sizeof(struct sll_header) +sizeof(struct iphdr)+sizeof(struct tcphdr)+4; -+ nh.len=sizeof(struct sll_header) +sizeof(struct iphdr)+sizeof(struct tcphdr)+4; -+ nh.ts.tv_usec+=1000; /*This packet is 1/3rd closer to the first packet then the previous packet created*/ -+ -+ /* Copy SLL and IP headers from private data area*/ -+ /* These are headers from the first packet in the capture*/ -+ memcpy(data, slip->od, sizeof(struct sll_header)+ sizeof(struct iphdr)); -+ -+ /*Adjust IP header, including swapping source and destination*/ -+ iph= (struct iphdr *) (ptr + sizeof(struct sll_header)); -+ iph->protocol=6; -+ iph->check=htonl(0); -+ temp=iph->saddr; -+ iph->saddr=iph->daddr; -+ iph->daddr=temp; -+ iph->tot_len=htons(sizeof(struct iphdr)+sizeof(struct tcphdr)+4); -+ -+ /*Build TCP header*/ -+ ptr+=sizeof(struct sll_header)+ sizeof(struct iphdr); -+ tcph=(struct tcphdr*)ptr; -+ tcph->source=htons(1113); -+ tcph->dest=htons(1113); -+ tcph->doff=6; -+ tcph->check=htonl(0); -+ tcph->urg_ptr=0; -+ tcph->urg=0; -+ tcph->psh=0; -+ tcph->fin=0; -+ tcph->syn=1; -+ tcph->rst=0; -+ tcph->ack=1; -+ -+ /*Initialize Sequence and Acknowledgement Numbers and Window*/ -+ tcph->seq=htonl(state.ack_num++); -+ tcph->ack_seq=htonl(state.seq_num); -+ tcph->window=htons(WIN_FACTOR); -+ -+ /* Add SACK permitted option*/ -+ ptr+=sizeof(struct tcphdr); -+ *ptr=4; -+ ptr++; -+ *ptr=2; -+ -+ /*Save To Packet Capture*/ -+ pcap_dump((u_char*)state.out,&nh, data); -+ -+ /* 3)Create Ack Packet*/ -+ /*make sure the packet is all zero*/ -+ memset(data, 0, MAX_PACKET); -+ ptr=data; -+ -+ /*Set the libpcap header*/ -+ nh.caplen=sizeof(struct sll_header) +sizeof(struct iphdr)+sizeof(struct tcphdr); -+ nh.len=sizeof(struct sll_header) +sizeof(struct iphdr)+sizeof(struct tcphdr); -+ nh.ts.tv_usec+=1000; /*This packet is 2/3rds between SYN and first packet*/ -+ -+ /* Copy SLL and IP headers from private data area*/ -+ /* These are headers from the first packet in the capture*/ -+ memcpy(data, slip->od, sizeof(struct sll_header)+ sizeof(struct iphdr)); -+ -+ /*Adjust IP header*/ -+ iph= (struct iphdr *) (ptr + sizeof(struct sll_header)); -+ iph->protocol=6; -+ iph->check=htonl(0); -+ iph->tot_len=htons(sizeof(struct iphdr)+sizeof(struct tcphdr)); -+ -+ /*Build TCP header*/ -+ ptr+=sizeof(struct sll_header)+ sizeof(struct iphdr); -+ tcph=(struct tcphdr*)ptr; -+ tcph->source=htons(1113); -+ tcph->dest=htons(1113); -+ tcph->doff=5; -+ tcph->check=htonl(0); -+ tcph->urg_ptr=0; -+ tcph->urg=0; -+ tcph->psh=0; -+ tcph->fin=0; -+ tcph->syn=0; -+ tcph->rst=0; -+ tcph->ack=1; -+ -+ /*Initialize Sequence and Acknowledgement numbers and window*/ -+ tcph->seq=htonl(state.seq_num++); -+ tcph->ack_seq=htonl(state.ack_num); -+ tcph->window=htons(WIN_FACTOR); -+ -+ /*Save To Packet Capture*/ -+ pcap_dump((u_char*)state.out,&nh, data); -+ return 0; -+} -+ -+/* Create a TCP ending handshake */ -+int sll_encap_fin() -+{ -+ struct iphdr *iph; -+ struct tcphdr *tcph; -+ u_char *data; -+ u_char *ptr; -+ struct pcap_pkthdr nh; -+ u_int32_t temp; -+ struct sll_en_p *slip=(struct sll_en_p*)state.en_priv; -+ -+ /*Safety Check*/ -+ if(slip==NULL){ -+ dbgprintf(1,"Error: SLL, IPv4 Encapsulation Finish method given invalid data!\n"); -+ return -1; -+ } -+ -+ /*copy the libpcap header from private data area*/ -+ memcpy(&nh, &slip->header, sizeof(struct pcap_pkthdr)); -+ -+ /*create buffer for new packet*/ -+ ptr=data=malloc(MAX_PACKET); -+ if(data==NULL){ -+ dbgprintf(0,"Error: Couldn't allocate Memory\n"); -+ exit(1); -+ } -+ -+ /* 1)Create Fin Packet*/ -+ /*make sure the packet is all zero*/ -+ memset(data, 0, MAX_PACKET); -+ ptr=data; -+ -+ /*Set the libpcap header*/ -+ nh.caplen=sizeof(struct sll_header) +sizeof(struct iphdr)+sizeof(struct tcphdr); -+ nh.len=sizeof(struct sll_header) +sizeof(struct iphdr)+sizeof(struct tcphdr); -+ nh.ts.tv_usec+=1000; /*Time is from the last packet in the capture; make this packet after that packet*/ -+ -+ /* Copy Ethernet and IP headers from private data area*/ -+ /* These are headers from the first packet in the capture*/ -+ memcpy(ptr, slip->od, sizeof(struct sll_header)+ sizeof(struct iphdr)); -+ -+ /*Adjust IP header*/ -+ iph= (struct iphdr *) (ptr + sizeof(struct sll_header)); -+ iph->protocol=6; -+ iph->check=htonl(0); -+ iph->tot_len=htons(sizeof(struct iphdr)+sizeof(struct tcphdr)); -+ -+ /*Build TCP header*/ -+ ptr+=sizeof(struct sll_header)+ sizeof(struct iphdr); -+ tcph=(struct tcphdr*)ptr; -+ tcph->source=htons(1113); -+ tcph->dest=htons(1113); -+ tcph->doff=5; -+ tcph->check=htonl(0); -+ tcph->urg_ptr=0; -+ tcph->urg=0; -+ tcph->psh=0; -+ tcph->fin=1; -+ tcph->syn=0; -+ tcph->rst=0; -+ tcph->ack=1; -+ -+ /* Adjust Sequence and Acknowledgment numbers and window*/ -+ tcph->seq=htonl(++state.seq_num); -+ tcph->ack_seq=htonl(state.ack_num); -+ tcph->window=htons(WIN_FACTOR); -+ -+ /*Update Sequence Number to include the fin packet in the sequence number space*/ -+ state.seq_num++; -+ -+ /* Save To Packet Capture*/ -+ pcap_dump((u_char*)state.out,&nh, data); -+ -+ /* 2)Create Fin,Ack Packet*/ -+ /*make sure the packet is all zero*/ -+ memset(data, 0, MAX_PACKET); -+ ptr=data; -+ -+ /*Set the libpcap header*/ -+ nh.caplen=sizeof(struct sll_header) +sizeof(struct iphdr)+sizeof(struct tcphdr); -+ nh.len=sizeof(struct sll_header) +sizeof(struct iphdr)+sizeof(struct tcphdr); -+ nh.ts.tv_usec+=1000; /*After the previous packet*/ -+ -+ /* Copy Ethernet and IP headers from private data area*/ -+ /* These are headers from the first packet in the capture*/ -+ memcpy(ptr, slip->od, sizeof(struct sll_header)+ sizeof(struct iphdr)); -+ -+ /*Update IP header, including swapping source and destination addresses*/ -+ iph= (struct iphdr *) (ptr + sizeof(struct sll_header)); -+ iph->protocol=6; -+ iph->check=htonl(0); -+ temp=iph->saddr; -+ iph->saddr=iph->daddr; -+ iph->daddr=temp; -+ iph->tot_len=htons(sizeof(struct iphdr)+sizeof(struct tcphdr)); -+ -+ /*Build TCP header*/ -+ ptr+=sizeof(struct sll_header)+ sizeof(struct iphdr); -+ tcph=(struct tcphdr*)ptr; -+ tcph->source=htons(1113); -+ tcph->dest=htons(1113); -+ tcph->doff=5; -+ tcph->check=htonl(0); -+ tcph->urg_ptr=0; -+ tcph->urg=0; -+ tcph->psh=0; -+ tcph->fin=1; -+ tcph->syn=0; -+ tcph->rst=0; -+ tcph->ack=1; -+ -+ /*Adjust Sequence and Acknowledgment numbers and window*/ -+ tcph->seq=htonl(state.ack_num++); -+ tcph->ack_seq=htonl(state.seq_num); -+ tcph->window=htons(WIN_FACTOR); -+ -+ /*Save To Packet Capture*/ -+ pcap_dump((u_char*)state.out,&nh, data); -+ -+ /* 3)Create Ack Packet*/ -+ /*make sure the packet is all zero*/ -+ memset(data, 0, MAX_PACKET); -+ ptr=data; -+ -+ /*Set the libpcap header*/ -+ nh.caplen=sizeof(struct sll_header) +sizeof(struct iphdr)+sizeof(struct tcphdr); -+ nh.len=sizeof(struct sll_header) +sizeof(struct iphdr)+sizeof(struct tcphdr); -+ nh.ts.tv_usec+=1000; /*After the previous packet*/ -+ -+ /* Copy Ethernet and IP headers from private data area*/ -+ /* These are headers from the first packet in the capture*/ -+ memcpy(ptr, slip->od, sizeof(struct sll_header)+ sizeof(struct iphdr)); -+ -+ /*Update IP header*/ -+ iph= (struct iphdr *) (ptr + sizeof(struct sll_header)); -+ iph->protocol=6; -+ iph->check=htonl(0); -+ iph->tot_len=htons(sizeof(struct iphdr)+sizeof(struct tcphdr)); -+ -+ /*Build TCP header*/ -+ ptr+=sizeof(struct ether_header)+ sizeof(struct iphdr); -+ tcph=(struct tcphdr*)ptr; -+ tcph->source=htons(1113); -+ tcph->dest=htons(1113); -+ tcph->doff=5; -+ tcph->check=htonl(0); -+ tcph->urg_ptr=0; -+ tcph->urg=0; -+ tcph->psh=0; -+ tcph->fin=0; -+ tcph->syn=0; -+ tcph->rst=0; -+ tcph->ack=1; -+ -+ /*Adjust Sequence and Acknowledgment numbers and window*/ -+ tcph->seq=htonl(state.seq_num++); -+ tcph->ack_seq=htonl(state.ack_num); -+ tcph->window=htons(WIN_FACTOR); -+ -+ /*Save To Packet Capture*/ -+ pcap_dump((u_char*)state.out,&nh, data); -+ return 0; -+} -+ -+ -+ -+ -+/* The UDP Encapsulation Structure*/ -+struct encap_ops sll_encap = { -+ .pre=sll_encap_pre, -+ .post=sll_encap_post, -+}; -diff -r ab54ffb0cb71 udp_encap.c ---- a/udp_encap.c Fri Mar 04 11:30:16 2011 -0500 -+++ b/udp_encap.c Thu May 19 01:11:51 2011 -0400 -@@ -15,13 +15,6 @@ - - - --/*UDP encapsulation private data structure*/ --struct udp_en_p{ -- struct pcap_pkthdr header; -- u_char od[sizeof(struct ether_header)+sizeof(struct iphdr)+sizeof(struct udphdr)]; --}; -- -- - - /* encapsulation manipulation previous to packet conversion */ - int udp_encap_pre(struct pcap_pkthdr *h, const u_char **odata, u_char **ndata, int* olength, int* nlength)