1 /******************************************************************************
2 Utility to convert a DCCP flow to a TCP flow for DCCP analysis via
5 Copyright (C) 2012 Samuel Jero <sj323707@ohio.edu>
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.
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.
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/>.
20 Author: Samuel Jero <sj323707@ohio.edu>
25 2)DCCP MUST use 48 bit sequence numbers
26 3)Checksums are not computed (they are zeroed)
27 4)DCCP DATA packets are not implemented (Linux doesn't use them)
28 5)DCCP Ack packets show up as TCP packets containing one byte
29 ******************************************************************************/
38 #include <sys/types.h>
42 #include <sys/socket.h>
44 #include <netinet/in.h>
45 #include <netinet/in_systm.h>
46 #include <arpa/inet.h>
47 #include <netinet/if_ether.h>
48 #include <netinet/ip.h>
49 #include <netinet/tcp.h>
50 #include <netinet/tcp.h>
51 #include <netinet/udp.h>
55 #include <linux/dccp.h>
58 #define MAX_PACKET 1600 /*Maximum size of TCP packet */
59 #define TBL_SZ 40000 /*Size of Sequence Number Table*/
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*/
74 /*Constant Packet structure*/
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*/
91 /*Host---half of a connection*/
93 int id_len; /*Length of ID*/
94 u_char *id; /*Host ID*/
95 __be16 port; /*Host DCCP port*/
96 struct tbl *table; /*Host Sequence Number Table*/
97 int size; /*Size of Sequence Number Table*/
98 int cur; /*Current TCP Sequence Number*/
99 enum con_state state; /*Connection state*/
102 /*Connection structure*/
104 struct connection *next; /*List pointer*/
105 struct host A; /*Host A*/
106 struct host B; /*Host B*/
109 /*sequence number table structure */
111 __be32 old; /*DCCP sequence number */
112 u_int32_t new; /*TCP sequence number */
113 int size; /*packet size*/
114 enum dccp_pkt_type type; /*packet type*/
118 extern int debug; /*set to 1 to turn on debugging information*/
119 extern int yellow; /*tcptrace yellow line as currently acked packet*/
120 extern int green; /*tcptrace green line as currently acked packet*/
121 extern int sack; /*add TCP SACKS*/
123 extern struct connection *chead;/*connection list*/
128 * 0) Always print even if debug isn't specified
129 * 1) Errors and warnings... Don't overload the screen with too much output
130 * 2) Notes and per-packet processing info... as verbose as needed
132 void dbgprintf(int level, const char *fmt, ...);
134 /*Function to parse encapsulation*/
135 int do_encap(int link, struct packet *new, const struct const_packet *old);
137 /*Connection functions*/
138 int get_host(u_char *src_id, u_char* dest_id, int id_len, int src_port, int dest_port,
139 struct host **fwd, struct host **rev);
140 struct connection *add_connection(u_char *src_id, u_char* dest_id, int id_len,
141 int src_port, int dest_port);
142 int update_state(struct host* hst, enum con_state st);
143 void cleanup_connections();