1 /******************************************************************************
2 Utility to convert a DCCP flow to a TCP flow for DCCP analysis via
5 Copyright (C) 2013 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>
24 1)DCCP MUST use 48 bit sequence numbers
25 2)DCCP Ack packets show up as TCP packets containing one byte
26 ******************************************************************************/
35 #include <sys/types.h>
39 #include <sys/socket.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>
52 #include <linux/dccp.h>
53 #include "checksums.h"
56 #define MAX_PACKET 1600 /*Maximum size of TCP packet */
57 #define TBL_SZ 40000 /*Size of Sequence Number Table*/
62 typedef __be16 dccp_port;
63 typedef __be32 d_seq_num;
67 struct pcap_pkthdr *h; /*libpcap header*/
68 u_char *data; /*Packet Data*/
69 int length; /*Packet length*/
70 int id_len; /*Length of IDs*/
71 u_char *src_id; /*Source ID of packet*/
72 u_char *dest_id;/*Destination ID of packet*/
73 char* (*print_id)(char* buf, int len, u_char* id, int id_len); /*Function to print ID*/
76 /*Constant Packet structure*/
78 const struct pcap_pkthdr *h; /*libpcap header*/
79 const u_char *data; /*Packet Data*/
80 int length; /*Packet length*/
81 int id_len; /*Length of IDs*/
82 u_char *src_id; /*Source ID of packet*/
83 u_char *dest_id;/*Destination ID of packet*/
84 char* (*print_id)(char* buf, int len, u_char* id, int id_len); /*Function to print ID*/
96 /*Connection Types (i.e. CCID)*/
103 /*Half Connection structure*/
105 int id_len; /*Length of ID*/
106 u_char *id; /*Host ID*/
107 dccp_port port; /*Host DCCP port*/
108 struct tbl *table; /*Host Sequence Number Table*/
109 int size; /*Size of Sequence Number Table*/
110 int cur; /*Current TCP Sequence Number*/
111 int high_ack;/*Highest ACK seen*/
112 enum con_state state; /*Connection state*/
113 enum con_type type; /*Connection type*/
116 /*Connection structure*/
118 struct connection *next; /*List pointer*/
119 struct hcon A; /*Host A*/
120 struct hcon B; /*Host B*/
123 /*sequence number table structure */
125 d_seq_num old; /*DCCP sequence number */
126 u_int32_t new; /*TCP sequence number */
127 int size; /*packet size*/
128 enum dccp_pkt_type type; /*packet type*/
132 extern int debug; /*set to 1 to turn on debugging information*/
133 extern int yellow; /*tcptrace yellow line as currently acked packet*/
134 extern int green; /*tcptrace green line as currently acked packet*/
135 extern int sack; /*add TCP SACKS*/
137 extern struct connection *chead;/*connection list*/
141 * 0) Always print even if debug isn't specified
142 * 1) Errors and warnings... Don't overload the screen with too much output
143 * 2) Notes and per-packet processing info... as verbose as needed
145 void dbgprintf(int level, const char *fmt, ...);
147 /*Function to parse encapsulation*/
148 int do_encap(int link, struct packet *new, const struct const_packet *old);
150 /*Connection functions*/
151 int get_host(u_char *src_id, u_char* dest_id, int id_len, int src_port, int dest_port,
152 enum dccp_pkt_type pkt_type, struct hcon **fwd, struct hcon **rev);
153 struct connection *add_connection(u_char *src_id, u_char* dest_id, int id_len,
154 int src_port, int dest_port);
155 int update_state(struct hcon* hst, enum con_state st);
156 void cleanup_connections();
158 /*Half Connection/Sequence number functions*/
159 u_int32_t initialize_hcon(struct hcon *hcn, d_seq_num initial);
160 u_int32_t add_new_seq(struct hcon *hcn, d_seq_num num, int size, enum dccp_pkt_type type);
161 u_int32_t convert_ack(struct hcon *hcn, d_seq_num num, struct hcon *o_hcn);
162 int acked_packet_size(struct hcon *hcn, d_seq_num num);
163 unsigned int interp_ack_vect(u_char* hdr);