]> sjero.net Git - dccp2tcp/blob - dccp2tcp.h
7f106a5973f051220f6ad33a33006674109c95e3
[dccp2tcp] / dccp2tcp.h
1 /******************************************************************************
2 Author: Samuel Jero
3
4 Date: 11/2012
5
6 Description: Header file for program to convert a DCCP flow to a TCP flow for DCCP
7                  analysis via tcptrace.
8
9 Notes:
10         1)CCID2 ONLY
11         2)DCCP MUST use 48 bit sequence numbers
12         3)Checksums are not computed (they are zeroed)
13         4)DCCP DATA packets are not implemented (Linux doesn't use them)
14         5)DCCP Ack packets show up as TCP packets containing one byte
15 ******************************************************************************/
16 #ifndef _DCCP2TCP_H
17 #define _DCCP2TCP_H
18
19 #include <stdarg.h>
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include <strings.h>
24 #include <sys/types.h>
25 #include <unistd.h>
26 #include <time.h>
27 #include <sys/time.h>
28 #include <sys/socket.h>
29 #include <net/if.h>
30 #include <netinet/in.h>
31 #include <netinet/in_systm.h>
32 #include <arpa/inet.h>
33 #include <netinet/if_ether.h>
34 #include <netinet/ip.h>
35 #include <netinet/tcp.h>
36 #include <netinet/tcp.h>
37 #include <netinet/udp.h>
38 #include <netdb.h>
39 #include <ctype.h>
40 #include <pcap.h>
41 #include <linux/dccp.h>
42
43
44 #define MAX_PACKET      1600    /*Maximum size of TCP packet */
45 #define TBL_SZ          40000   /*Size of Sequence Number Table*/
46
47
48
49
50 /*Packet structure*/
51 struct packet{
52         struct pcap_pkthdr      *h;             /*libpcap header*/
53         u_char                          *data;  /*Packet Data*/
54         int                                     length; /*Packet length*/
55         int                                     id_len; /*Length of IDs*/
56         u_char                          *src_id; /*Source ID of packet*/
57         u_char                          *dest_id;/*Destination ID of packet*/
58 };
59
60 /*Constant Packet structure*/
61 struct const_packet{
62         const struct pcap_pkthdr *h;    /*libpcap header*/
63         const u_char                    *data;  /*Packet Data*/
64         int                                             length; /*Packet length*/
65         int                                             id_len; /*Length of IDs*/
66         u_char                                  *src_id; /*Source ID of packet*/
67         u_char                                  *dest_id;/*Destination ID of packet*/
68 };
69
70 /*Connection states*/
71 enum con_state{
72         INIT,
73         OPEN,
74         CLOSE,
75 };
76
77 /*Host---half of a connection*/
78 struct host{
79         int                                     id_len; /*Length of ID*/
80         u_char                          *id;    /*Host ID*/
81         __be16                          port;   /*Host DCCP port*/
82         struct tbl                      *table; /*Host Sequence Number Table*/
83         int                                     size;   /*Size of Sequence Number Table*/
84         int                                     cur;    /*Current TCP Sequence Number*/
85         enum con_state          state;  /*Connection state*/
86 };
87
88 /*Connection structure*/
89 struct connection{
90         struct connection       *next;  /*List pointer*/
91         struct host                     A;              /*Host A*/
92         struct host                     B;              /*Host B*/
93 };
94
95 /*sequence number table structure */
96 struct tbl{
97         __be32                          old;    /*DCCP sequence number */
98         u_int32_t                       new;    /*TCP sequence number */
99         int                                     size;   /*packet size*/
100         enum dccp_pkt_type      type;   /*packet type*/
101 };
102
103 /*Option flags*/
104 extern int debug;               /*set to 1 to turn on debugging information*/
105 extern int yellow;              /*tcptrace yellow line as currently acked packet*/
106 extern int green;               /*tcptrace green line as currently acked packet*/
107 extern int sack;                /*add TCP SACKS*/
108
109 extern struct connection *chead;/*connection list*/
110
111
112 /*debug printf
113  * Levels:
114  *      0) Always print even if debug isn't specified
115  *  1) Errors and warnings... Don't overload the screen with too much output
116  *  2) Notes and per-packet processing info... as verbose as needed
117  */
118 void dbgprintf(int level, const char *fmt, ...);
119
120 /*Function to parse encapsulation*/
121 int do_encap(int link, struct packet *new, const struct const_packet *old);
122
123 /*Connection functions*/
124 int get_host(u_char *src_id, u_char* dest_id, int id_len, int src_port, int dest_port,
125                 struct host **fwd, struct host **rev);
126 struct connection *add_connection(u_char *src_id, u_char* dest_id, int id_len,
127                 int src_port, int dest_port);
128 int update_state(struct host* hst, enum con_state st);
129 void cleanup_connections();
130
131 #endif