]> sjero.net Git - dccp2tcp/blobdiff - dccp2tcp.c
Minor Makefile change for greater compatibility
[dccp2tcp] / dccp2tcp.c
index db9ca53181241d0e9a4461778ee8ed2edacef554..caa7d6ae97d8c0df98995a47dcdd72de4bca99e2 100644 (file)
@@ -53,10 +53,12 @@ int handle_reset(struct packet* new, const struct const_packet* old, struct hcon
 int handle_sync(struct packet* new, const struct const_packet* old, struct hcon* h1, struct hcon* h2);
 int handle_syncack(struct packet* new, const struct const_packet* old, struct hcon* h1, struct hcon* h2);
 int handle_data(struct packet* new, const struct const_packet* old, struct hcon* h1, struct hcon* h2);
-int parse_options(const u_char* opt_start, int len, struct hcon* A, struct hcon* B);
-int process_feature(const u_char* feat, int len, int confirm, int L, struct hcon* A, struct hcon* B);
-void ack_vect2sack(struct hcon *seq, struct tcphdr *tcph, u_char* tcpopts, u_char* dccphdr,
-                               __be32 dccpack, struct hcon* o_hcn);
+int parse_options(const u_char* opt_start, int len,
+                       const struct const_packet* pkt, struct hcon* A, struct hcon* B);
+int process_feature(const u_char* feat, int len, int confirm, int L,
+                       const struct const_packet* pkt, struct hcon* A, struct hcon* B);
+void ack_vect2sack(struct hcon *seq, struct tcphdr *tcph,
+                       u_char* tcpopts, u_char* dccphdr, d_seq_num dccpack, struct hcon* o_hcn);
 void version();
 void usage();
 
@@ -88,23 +90,20 @@ int main(int argc, char *argv[])
                                }
                        }
                }else{
-                       if(argv[i][1]=='d' && strlen(argv[i])==2){ /* -d */
+                       if(argv[i][1]=='v' && strlen(argv[i])==2){ /* -v */
                                debug++;
-                       }
-                       if(argv[i][1]=='y' && strlen(argv[i])==2){ /* -y */
+                       }else if(argv[i][1]=='y' && strlen(argv[i])==2){ /* -y */
                                yellow=1;
-                       }
-                       if(argv[i][1]=='g' && strlen(argv[i])==2){ /* -g */
+                       }else if(argv[i][1]=='g' && strlen(argv[i])==2){ /* -g */
                                green=1;
-                       }
-                       if(argv[i][1]=='s' && strlen(argv[i])==2){ /* -s */
+                       }else if(argv[i][1]=='s' && strlen(argv[i])==2){ /* -s */
                                sack++;
-                       }
-                       if(argv[i][1]=='h' && strlen(argv[i])==2){ /* -h */
+                       }else if(argv[i][1]=='h' && strlen(argv[i])==2){ /* -h */
                                usage();
-                       }
-                       if(argv[i][1]=='V' && strlen(argv[i])==2){ /* -V */
+                       }else if(argv[i][1]=='V' && strlen(argv[i])==2){ /* -V */
                                version();
+                       }else{
+                               usage();
                        }
                }
        }
@@ -116,7 +115,6 @@ int main(int argc, char *argv[])
        /*all options validated*/
 
        if(debug){
-               dbgprintf(1,"Debug On\n");
                if(green){
                        dbgprintf(1,"Tcptrace green line at highest acknowledgment\n");
                }else{
@@ -220,6 +218,8 @@ int convert_packet(struct packet *new, const struct const_packet* old)
        struct dccp_hdr_ext             *dccphex;
        struct hcon                                     *h1=NULL;
        struct hcon                                     *h2=NULL;
+       char buf1[100];
+       char buf2[100];
 
        /*Safety checks*/
        if(!new || !old || !new->data || !old->data || !new->h || !old->h){
@@ -248,8 +248,8 @@ int convert_packet(struct packet *new, const struct const_packet* old)
        }
 
        /*Get Hosts*/
-       if(get_host(new->src_id, new->dest_id, new->id_len,
-                       dccph->dccph_sport, dccph->dccph_dport, &h1, &h2)){
+       if(get_host(new->src_id, new->dest_id, new->id_len, dccph->dccph_sport,
+                       dccph->dccph_dport, dccph->dccph_type,&h1, &h2)){
                dbgprintf(0,"Error: Can't Get Hosts!\n");
                return 0;
        }
@@ -257,6 +257,17 @@ int convert_packet(struct packet *new, const struct const_packet* old)
                dbgprintf(0, "Error: Can't Get Hosts!\n");
                return 0;
        }
+       if(h1->state==IGNORE || h2->state==IGNORE){
+               if(old->print_id){
+                       dbgprintf(2,"Ignoring packet between %s:%i and %s:%i\n",
+                               old->print_id(buf1,100,old->src_id,old->id_len),ntohs(dccph->dccph_sport),
+                               old->print_id(buf2,100,old->dest_id,old->id_len), ntohs(dccph->dccph_dport));
+               }else{
+                       dbgprintf(2,"Ignoring packet between %i and %i\n",
+                                       ntohs(dccph->dccph_sport), ntohs(dccph->dccph_dport));
+               }
+               return 0;
+       }
 
        /*set TCP standard features*/
        tcph->source=dccph->dccph_sport;
@@ -380,7 +391,7 @@ int handle_request(struct packet* new, const struct const_packet* old, struct hc
        /*Process DCCP Options*/
        dccpopt=old->data + sizeof(struct dccp_hdr) + sizeof(struct dccp_hdr_ext)+sizeof(struct dccp_hdr_request);
        optlen=dccph->dccph_doff*4 - sizeof(struct dccp_hdr)-sizeof(struct dccp_hdr_ext)-sizeof(struct dccp_hdr_request);
-       if(!parse_options(dccpopt,optlen,h1,h2)){
+       if(!parse_options(dccpopt,optlen,old,h1,h2)){
                return 0;
        }
 
@@ -440,7 +451,7 @@ int handle_response(struct packet* new, const struct const_packet* old, struct h
                        sizeof(struct dccp_hdr_ack_bits) + sizeof(struct dccp_hdr_request);
        optlen=dccph->dccph_doff*4 - sizeof(struct dccp_hdr) - sizeof(struct dccp_hdr_ext)
                        - sizeof(struct dccp_hdr_ack_bits) - sizeof(struct dccp_hdr_request);
-       if(!parse_options(dccpopt,optlen,h1,h2)){
+       if(!parse_options(dccpopt,optlen,old,h1,h2)){
                return 0;
        }
 
@@ -504,7 +515,7 @@ int handle_dataack(struct packet* new, const struct const_packet* old, struct hc
        /*Process DCCP Options*/
        dccpopt=old->data + sizeof(struct dccp_hdr) + sizeof(struct dccp_hdr_ext) + sizeof(struct dccp_hdr_ack_bits);
        optlen=dccph->dccph_doff*4 - sizeof(struct dccp_hdr) - sizeof(struct dccp_hdr_ext) - sizeof(struct dccp_hdr_ack_bits);
-       if(!parse_options(dccpopt,optlen,h1,h2)){
+       if(!parse_options(dccpopt,optlen,old,h1,h2)){
                return 0;
        }
 
@@ -561,7 +572,7 @@ int handle_ack(struct packet* new, const struct const_packet* old, struct hcon*
        /*Process DCCP Options*/
        dccpopt=old->data + sizeof(struct dccp_hdr) + sizeof(struct dccp_hdr_ext) + sizeof(struct dccp_hdr_ack_bits);
        optlen=dccph->dccph_doff*4 - sizeof(struct dccp_hdr) - sizeof(struct dccp_hdr_ext) - sizeof(struct dccp_hdr_ack_bits);
-       if(!parse_options(dccpopt,optlen,h1,h2)){
+       if(!parse_options(dccpopt,optlen,old,h1,h2)){
                return 0;
        }
 
@@ -618,7 +629,7 @@ int handle_closereq(struct packet* new, const struct const_packet* old, struct h
        /*Process DCCP Options*/
        dccpopt=old->data + sizeof(struct dccp_hdr) + sizeof(struct dccp_hdr_ext) + sizeof(struct dccp_hdr_ack_bits);
        optlen=dccph->dccph_doff*4 - sizeof(struct dccp_hdr) - sizeof(struct dccp_hdr_ext) - sizeof(struct dccp_hdr_ack_bits);
-       if(!parse_options(dccpopt,optlen,h1,h2)){
+       if(!parse_options(dccpopt,optlen,old,h1,h2)){
                return 0;
        }
 
@@ -672,7 +683,7 @@ int handle_close(struct packet* new, const struct const_packet* old, struct hcon
        /*Process DCCP Options*/
        dccpopt=old->data + sizeof(struct dccp_hdr) + sizeof(struct dccp_hdr_ext) + sizeof(struct dccp_hdr_ack_bits);
        optlen=dccph->dccph_doff*4 - sizeof(struct dccp_hdr) - sizeof(struct dccp_hdr_ext) - sizeof(struct dccp_hdr_ack_bits);
-       if(!parse_options(dccpopt,optlen,h1,h2)){
+       if(!parse_options(dccpopt,optlen,old,h1,h2)){
                return 0;
        }
 
@@ -727,7 +738,7 @@ int handle_reset(struct packet* new, const struct const_packet* old, struct hcon
        /*Process DCCP Options*/
        dccpopt=old->data + sizeof(struct dccp_hdr) + sizeof(struct dccp_hdr_ext) + sizeof(struct dccp_hdr_ack_bits);
        optlen=dccph->dccph_doff*4 - sizeof(struct dccp_hdr) - sizeof(struct dccp_hdr_ext) - sizeof(struct dccp_hdr_ack_bits);
-       if(!parse_options(dccpopt,optlen,h1,h2)){
+       if(!parse_options(dccpopt,optlen,old,h1,h2)){
                return 0;
        }
 
@@ -784,7 +795,7 @@ int handle_sync(struct packet* new, const struct const_packet* old, struct hcon*
        /*Process DCCP Options*/
        dccpopt=old->data + sizeof(struct dccp_hdr) + sizeof(struct dccp_hdr_ext) + sizeof(struct dccp_hdr_ack_bits);
        optlen=dccph->dccph_doff*4 - sizeof(struct dccp_hdr) - sizeof(struct dccp_hdr_ext) - sizeof(struct dccp_hdr_ack_bits);
-       if(!parse_options(dccpopt,optlen,h1,h2)){
+       if(!parse_options(dccpopt,optlen,old,h1,h2)){
                return 0;
        }
 
@@ -840,7 +851,7 @@ int handle_syncack(struct packet* new, const struct const_packet* old, struct hc
        /*Process DCCP Options*/
        dccpopt=old->data + sizeof(struct dccp_hdr) + sizeof(struct dccp_hdr_ext) + sizeof(struct dccp_hdr_ack_bits);
        optlen=dccph->dccph_doff*4 - sizeof(struct dccp_hdr) - sizeof(struct dccp_hdr_ext) - sizeof(struct dccp_hdr_ack_bits);
-       if(!parse_options(dccpopt,optlen,h1,h2)){
+       if(!parse_options(dccpopt,optlen,old,h1,h2)){
                return 0;
        }
 
@@ -901,7 +912,7 @@ int handle_data(struct packet* new, const struct const_packet* old, struct hcon*
        /*Process DCCP Options*/
        dccpopt=old->data + sizeof(struct dccp_hdr) + sizeof(struct dccp_hdr_ext);
        optlen=dccph->dccph_doff*4 - sizeof(struct dccp_hdr) - sizeof(struct dccp_hdr_ext);
-       if(!parse_options(dccpopt,optlen,h1,h2)){
+       if(!parse_options(dccpopt,optlen,old,h1,h2)){
                return 0;
        }
 
@@ -922,11 +933,14 @@ int handle_data(struct packet* new, const struct const_packet* old, struct hcon*
        return 1;
 }
 
-int parse_options(const u_char* opt_start, int len, struct hcon* A, struct hcon* B)
+int parse_options(const u_char* opt_start, int len, const struct const_packet* pkt,
+                                                                                                                                       struct hcon* A, struct hcon* B)
 {
        int optlen;
        int length;
        const u_char* opt;
+       char buf1[100];
+       char buf2[100];
 
        /*setup pointer to DCCP options and determine how long the options are*/
        optlen=len;
@@ -954,36 +968,56 @@ int parse_options(const u_char* opt_start, int len, struct hcon* A, struct hcon*
 
                /*Ack Vector Option*/
                if(*opt==38 || *opt==39){
-
+                       if(B->type==UNKNOWN){
+                               B->type=CCID2;
+                               if(pkt->print_id){
+                                       dbgprintf(1,"Half-connection from %s:%i to %s:%i probably using CCID 2\n",
+                                               pkt->print_id(buf1,100,pkt->dest_id,pkt->id_len),ntohs(B->port),
+                                               pkt->print_id(buf2,100,pkt->src_id,pkt->id_len), ntohs(A->port));
+                               }else{
+                                       dbgprintf(1,"Half-connection from  port %i to %i probably using CCID 2\n",
+                                               ntohs(B->port),ntohs(A->port));
+                               }
+                       }
                }
 
                /*NDP Count Option*/
                if(*opt==37){
-
+                       if(B->type==UNKNOWN){
+                               B->type=CCID3;
+                               if(pkt->print_id){
+                                       dbgprintf(1,"Half-connection from %s:%i to %s:%i probably using CCID 3\n",
+                                               pkt->print_id(buf1,100,pkt->dest_id,pkt->id_len),ntohs(B->port),
+                                               pkt->print_id(buf2,100,pkt->src_id,pkt->id_len), ntohs(A->port));
+                               }else{
+                                       dbgprintf(1,"Half-connection from  port %i to %i probably using CCID 3\n",
+                                               ntohs(B->port),ntohs(A->port));
+                               }
+                       }
                }
 
                /*Feature negotation*/
                if(*opt==32){
                        /*Change L*/
-                       if(!process_feature(opt+2,length-2,FALSE,TRUE,A,B)){
+                       if(!process_feature(opt+2,length-2,FALSE,TRUE,pkt,A,B)){
                                return 0;
                        }
                }
                if(*opt==33){
                        /*Confirm L*/
-                       if(!process_feature(opt+2,length-2,TRUE,TRUE,A,B)){
+                       if(!process_feature(opt+2,length-2,TRUE,TRUE,pkt,A,B)){
                                return 0;
                        }
                }
                if(*opt==34){
                        /*Change R*/
-                       if(!process_feature(opt+2,length-2,FALSE,FALSE,A,B)){
+                       if(!process_feature(opt+2,length-2,FALSE,FALSE,pkt,A,B)){
                                return 0;
                        }
                }
                if(*opt==35){
                        /*Confirm R*/
-                       if(!process_feature(opt+2,length-2,TRUE,FALSE,A,B)){
+                       if(!process_feature(opt+2,length-2,TRUE,FALSE,pkt,A,B)){
                                return 0;
                        }
                }
@@ -995,17 +1029,20 @@ int parse_options(const u_char* opt_start, int len, struct hcon* A, struct hcon*
        return 1;
 }
 
-int process_feature(const u_char* feat, int len, int confirm, int L, struct hcon* A, struct hcon* B)
+int process_feature(const u_char* feat, int len, int confirm, int L,
+                                                       const struct const_packet* pkt, struct hcon* A, struct hcon* B)
 {
        const u_char* val;
        int ccid;
+       char buf1[100];
+       char buf2[100];
 
        val=feat+1;
 
        switch(*feat){
                case 1:
                        /*CCID*/
-                       if(confirm==FALSE){
+                       if(confirm==TRUE){
                                switch(*val){
                                        case 2:
                                                ccid=CCID2;
@@ -1019,16 +1056,36 @@ int process_feature(const u_char* feat, int len, int confirm, int L, struct hcon
                                }
                                if(L==TRUE){
                                        B->type=ccid;
+                                       if(pkt->print_id){
+                                               dbgprintf(1,"Half-connection from %s:%i to %s:%i using CCID %i\n",
+                                                       pkt->print_id(buf1,100,pkt->dest_id,pkt->id_len),ntohs(B->port),
+                                                       pkt->print_id(buf2,100,pkt->src_id,pkt->id_len), ntohs(A->port), *val);
+                                       }else{
+                                               dbgprintf(1,"Half-connection from  port %i to %i using CCID %i\n",
+                                                       ntohs(B->port),ntohs(A->port), *val);
+                                       }
                                }else{
                                        A->type=ccid;
+                                       if(pkt->print_id){
+                                               dbgprintf(1,"Half-connection from %s:%i to %s:%i using CCID %i\n",
+                                                       pkt->print_id(buf1,100,pkt->src_id,pkt->id_len),ntohs(A->port),
+                                                       pkt->print_id(buf2,100,pkt->dest_id,pkt->id_len), ntohs(B->port), *val);
+                                       }else{
+                                               dbgprintf(1,"Half-connection from  port %i to %i using CCID %i\n",
+                                                       ntohs(A->port),ntohs(B->port), *val);
+                                       }
                                }
                        }
                        break;
                case 2:
                        /*Short sequence nums*/
-                       if(confirm==FALSE && *val==1){
-                               dbgprintf(0,"Error! DCCP is trying to turn on short sequence numbers! We do not support this!!\n");
-                               exit(1);
+                       if(confirm==TRUE && *val==1){
+                               B->type=IGNORE;
+                               A->type=IGNORE;
+                               dbgprintf(0,"Error: DCCP is trying to turn on short sequence numbers\n"
+                                               "  for the connection between %i and %i. We do not support this.\n"
+                                               "  This connection will be ignored.",ntohs(A->port),ntohs(B->port));
+                               return 0;
                        }
                        break;
        }
@@ -1037,13 +1094,13 @@ int process_feature(const u_char* feat, int len, int confirm, int L, struct hcon
 
 /*Ack Vector to SACK Option*/
 void ack_vect2sack(struct hcon *hcn, struct tcphdr *tcph, u_char* tcpopts, u_char* dccphdr,
-                                                                                                                               __be32 dccpack, struct hcon* o_hcn)
+                                                                                                                               d_seq_num dccpack, struct hcon* o_hcn)
 {
        int hdrlen=((struct dccp_hdr*)dccphdr)->dccph_doff*4;
        int optlen;
        int len;
        int tmp;
-       __be32 bp;
+       d_seq_num bp;
        u_char* temp;
        u_char* opt;
        u_char* cur;
@@ -1157,17 +1214,19 @@ return;
 
 void version()
 {
-       dbgprintf(0, "dccp2tcp version %.1f\nCopyright (C) %i Samuel Jero <sj323707@ohio.edu>\n", DCCP2TCP_VERSION,COPYRIGHT_YEAR);
+       dbgprintf(0, "dccp2tcp version %.1f\n",DCCP2TCP_VERSION);
+       dbgprintf(0, "Copyright (C) %i Samuel Jero <sj323707@ohio.edu>\n",COPYRIGHT_YEAR);
        dbgprintf(0, "This program comes with ABSOLUTELY NO WARRANTY.\n");
-       dbgprintf(0, "This is free software, and you are welcome to\nredistribute it under certain conditions.\n");
+       dbgprintf(0, "This is free software, and you are welcome to\n");
+       dbgprintf(0, "redistribute it under certain conditions.\n");
        exit(0);
 }
 
 /*Usage information for program*/
 void usage()
 {
-       dbgprintf(0,"Usage: dccp2tcp [-d] [-h] [-V] [-y] [-g] [-s] dccp_file tcp_file\n");
-       dbgprintf(0, "          -d   Debug. May be repeated for aditional verbosity.\n");
+       dbgprintf(0,"Usage: dccp2tcp [-v] [-h] [-V] [-y] [-g] [-s] dccp_file tcp_file\n");
+       dbgprintf(0, "          -v   verbose. May be repeated for additional verbosity.\n");
        dbgprintf(0, "          -V   Version information\n");
        dbgprintf(0, "          -h   Help\n");
        dbgprintf(0, "          -y   Yellow line is highest ACK\n");