]> sjero.net Git - dccp2tcp/blob - dccp2tcp.h
Checksum computation!
[dccp2tcp] / dccp2tcp.h
1 /******************************************************************************
2 Utility to convert a DCCP flow to a TCP flow for DCCP analysis via
3                 tcptrace.
4
5 Copyright (C) 2012  Samuel Jero <sj323707@ohio.edu>
6
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20 Author: Samuel Jero <sj323707@ohio.edu>
21 Date: 11/2012
22
23 Notes:
24         1)CCID2 ONLY
25         2)DCCP MUST use 48 bit sequence numbers
26         3)DCCP DATA packets are not implemented (Linux doesn't use them)
27         4)DCCP Ack packets show up as TCP packets containing one byte
28 ******************************************************************************/
29 #ifndef _DCCP2TCP_H
30 #define _DCCP2TCP_H
31
32 #include <stdarg.h>
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <string.h>
36 #include <strings.h>
37 #include <sys/types.h>
38 #include <unistd.h>
39 #include <time.h>
40 #include <sys/time.h>
41 #include <sys/socket.h>
42 #include <net/if.h>
43 #include <netinet/in.h>
44 #include <netinet/in_systm.h>
45 #include <arpa/inet.h>
46 #include <netinet/if_ether.h>
47 #include <netinet/ip.h>
48 #include <netinet/tcp.h>
49 #include <netinet/tcp.h>
50 #include <netinet/udp.h>
51 #include <netdb.h>
52 #include <ctype.h>
53 #include <pcap.h>
54 #include <linux/dccp.h>
55 #include "checksums.h"
56
57
58 #define MAX_PACKET      1600    /*Maximum size of TCP packet */
59 #define TBL_SZ          40000   /*Size of Sequence Number Table*/
60
61
62
63
64 /*Packet structure*/
65 struct packet{
66         struct pcap_pkthdr      *h;             /*libpcap header*/
67         u_char                          *data;  /*Packet Data*/
68         int                                     length; /*Packet length*/
69         int                                     id_len; /*Length of IDs*/
70         u_char                          *src_id; /*Source ID of packet*/
71         u_char                          *dest_id;/*Destination ID of packet*/
72 };
73
74 /*Constant Packet structure*/
75 struct const_packet{
76         const struct pcap_pkthdr *h;    /*libpcap header*/
77         const u_char                    *data;  /*Packet Data*/
78         int                                             length; /*Packet length*/
79         int                                             id_len; /*Length of IDs*/
80         u_char                                  *src_id; /*Source ID of packet*/
81         u_char                                  *dest_id;/*Destination ID of packet*/
82 };
83
84 /*Connection states*/
85 enum con_state{
86         INIT,
87         OPEN,
88         CLOSE,
89 };
90
91 /*Connection Types (i.e. CCID)*/
92 enum con_type{
93         UNKNOWN,
94         CCID2,
95         CCID3,
96 };
97
98 /*Host---half of a connection*/
99 struct host{
100         int                                     id_len; /*Length of ID*/
101         u_char                          *id;    /*Host ID*/
102         __be16                          port;   /*Host DCCP port*/
103         struct tbl                      *table; /*Host Sequence Number Table*/
104         int                                     size;   /*Size of Sequence Number Table*/
105         int                                     cur;    /*Current TCP Sequence Number*/
106         enum con_state          state;  /*Connection state*/
107         enum con_type           type;   /*Connection type*/
108 };
109
110 /*Connection structure*/
111 struct connection{
112         struct connection       *next;  /*List pointer*/
113         struct host                     A;              /*Host A*/
114         struct host                     B;              /*Host B*/
115 };
116
117 /*sequence number table structure */
118 struct tbl{
119         __be32                          old;    /*DCCP sequence number */
120         u_int32_t                       new;    /*TCP sequence number */
121         int                                     size;   /*packet size*/
122         enum dccp_pkt_type      type;   /*packet type*/
123 };
124
125 /*Option flags*/
126 extern int debug;               /*set to 1 to turn on debugging information*/
127 extern int yellow;              /*tcptrace yellow line as currently acked packet*/
128 extern int green;               /*tcptrace green line as currently acked packet*/
129 extern int sack;                /*add TCP SACKS*/
130
131 extern struct connection *chead;/*connection list*/
132
133 /*debug printf
134  * Levels:
135  *      0) Always print even if debug isn't specified
136  *  1) Errors and warnings... Don't overload the screen with too much output
137  *  2) Notes and per-packet processing info... as verbose as needed
138  */
139 void dbgprintf(int level, const char *fmt, ...);
140
141 /*Function to parse encapsulation*/
142 int do_encap(int link, struct packet *new, const struct const_packet *old);
143
144 /*Connection functions*/
145 int get_host(u_char *src_id, u_char* dest_id, int id_len, int src_port, int dest_port,
146                 struct host **fwd, struct host **rev);
147 struct connection *add_connection(u_char *src_id, u_char* dest_id, int id_len,
148                 int src_port, int dest_port);
149 int update_state(struct host* hst, enum con_state st);
150 void cleanup_connections();
151
152 /*Per-CCID convert functions*/
153 int ccid2_convert_packet(struct packet *new, const struct const_packet* old);
154
155 #endif