]> sjero.net Git - dccp2tcp/blob - dccp2tcp.h
IPv6 encapsulation bugfix
[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) 2013  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: 02/2013
22
23 Notes:
24         1)DCCP MUST use 48 bit sequence numbers
25         2)DCCP Ack packets show up as TCP packets containing one byte
26 ******************************************************************************/
27 #ifndef _DCCP2TCP_H
28 #define _DCCP2TCP_H
29
30 #include <stdarg.h>
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <string.h>
34 #include <strings.h>
35 #include <sys/types.h>
36 #include <unistd.h>
37 #include <time.h>
38 #include <sys/time.h>
39 #include <sys/socket.h>
40 #include <net/if.h>
41 #include <netinet/in.h>
42 #include <netinet/in_systm.h>
43 #include <arpa/inet.h>
44 #include <netinet/if_ether.h>
45 #include <netinet/ip.h>
46 #include <netinet/tcp.h>
47 #include <netinet/tcp.h>
48 #include <netinet/udp.h>
49 #include <netdb.h>
50 #include <ctype.h>
51 #include <pcap.h>
52 #include <linux/dccp.h>
53 #include "checksums.h"
54
55
56 #define MAX_PACKET      1600    /*Maximum size of TCP packet */
57 #define TBL_SZ          40000   /*Size of Sequence Number Table*/
58
59 #define TRUE 1
60 #define FALSE 0
61
62 /*Packet structure*/
63 struct packet{
64         struct pcap_pkthdr      *h;             /*libpcap header*/
65         u_char                          *data;  /*Packet Data*/
66         int                                     length; /*Packet length*/
67         int                                     id_len; /*Length of IDs*/
68         u_char                          *src_id; /*Source ID of packet*/
69         u_char                          *dest_id;/*Destination ID of packet*/
70 };
71
72 /*Constant Packet structure*/
73 struct const_packet{
74         const struct pcap_pkthdr *h;    /*libpcap header*/
75         const u_char                    *data;  /*Packet Data*/
76         int                                             length; /*Packet length*/
77         int                                             id_len; /*Length of IDs*/
78         u_char                                  *src_id; /*Source ID of packet*/
79         u_char                                  *dest_id;/*Destination ID of packet*/
80 };
81
82 /*Connection states*/
83 enum con_state{
84         INIT,
85         OPEN,
86         CLOSE,
87 };
88
89 /*Connection Types (i.e. CCID)*/
90 enum con_type{
91         UNKNOWN,
92         CCID2,
93         CCID3,
94 };
95
96 /*Half Connection structure*/
97 struct hcon{
98         int                                     id_len; /*Length of ID*/
99         u_char                          *id;    /*Host ID*/
100         __be16                          port;   /*Host DCCP port*/
101         struct tbl                      *table; /*Host Sequence Number Table*/
102         int                                     size;   /*Size of Sequence Number Table*/
103         int                                     cur;    /*Current TCP Sequence Number*/
104         int                                     high_ack;/*Highest ACK seen*/
105         enum con_state          state;  /*Connection state*/
106         enum con_type           type;   /*Connection type*/
107 };
108
109 /*Connection structure*/
110 struct connection{
111         struct connection       *next;  /*List pointer*/
112         struct hcon                     A;              /*Host A*/
113         struct hcon                     B;              /*Host B*/
114 };
115
116 /*sequence number table structure */
117 struct tbl{
118         __be32                          old;    /*DCCP sequence number */
119         u_int32_t                       new;    /*TCP sequence number */
120         int                                     size;   /*packet size*/
121         enum dccp_pkt_type      type;   /*packet type*/
122 };
123
124 /*Option flags*/
125 extern int debug;               /*set to 1 to turn on debugging information*/
126 extern int yellow;              /*tcptrace yellow line as currently acked packet*/
127 extern int green;               /*tcptrace green line as currently acked packet*/
128 extern int sack;                /*add TCP SACKS*/
129
130 extern struct connection *chead;/*connection list*/
131
132 /*debug printf
133  * Levels:
134  *      0) Always print even if debug isn't specified
135  *  1) Errors and warnings... Don't overload the screen with too much output
136  *  2) Notes and per-packet processing info... as verbose as needed
137  */
138 void dbgprintf(int level, const char *fmt, ...);
139
140 /*Function to parse encapsulation*/
141 int do_encap(int link, struct packet *new, const struct const_packet *old);
142
143 /*Connection functions*/
144 int get_host(u_char *src_id, u_char* dest_id, int id_len, int src_port, int dest_port,
145                 struct hcon **fwd, struct hcon **rev);
146 struct connection *add_connection(u_char *src_id, u_char* dest_id, int id_len,
147                 int src_port, int dest_port);
148 int update_state(struct hcon* hst, enum con_state st);
149 void cleanup_connections();
150
151 /*Half Connection/Sequence number functions*/
152 u_int32_t initialize_hcon(struct hcon *hcn, __be32 initial);
153 u_int32_t add_new_seq(struct hcon *hcn, __be32 num, int size, enum dccp_pkt_type type);
154 u_int32_t convert_ack(struct hcon *hcn, __be32 num, struct hcon *o_hcn);
155 int acked_packet_size(struct hcon *hcn, __be32 num);
156 unsigned int interp_ack_vect(u_char* hdr);
157
158 #endif