]> sjero.net Git - ltp2tcp/blob - encap.h
Add some captures and further documentation
[ltp2tcp] / encap.h
1 /******************************************************************************
2
3 File: encap.h
4
5 Author: Samuel Jero
6
7 Date: 12/2010
8
9 Description:  Declarations of encapsulation functions for ltp2tcp
10
11 ******************************************************************************/
12
13 #ifndef ENCAP_H_
14 #define ENCAP_H_
15 #include <netinet/if_ether.h>
16 #include <netinet/ip.h>
17
18 /*
19
20
21 */
22
23 /* Encapsulation Operations*/
24 struct encap_ops{
25         /* Handle all headers up to LTP:
26          *      h is the libpcap header. It should be returned with the Link+IP length in it.
27          *  odata is the packet being processed starting at the Link header. It should be returned starting at the LTP header.
28          *  ndata is the new packet. It should be returned with a Link+IP header in it.
29          *  olength is the length of the packet being processed. It should be returned as the length of the LTP segment.
30          *  nlength is the remaining length of the new packet. The Link+IP headers should be subtracted from it.
31          *
32          *  Other things to do:
33          *  1)IP must say that TCP is next header
34          *  2)Initialize encapsulation private data as needed (typically store h and Link+IP header for fin() method)
35          */
36         int (*pre)(struct pcap_pkthdr *h, const u_char **odata, u_char **ndata, int* olength, int* nlength);
37         /*
38          * Do any needed post processing on packet:
39          *  tlen is the length of the TCP segment (data+header)
40          *  data is the new packet starting at the link header
41          *
42          *  Typically update IP length
43          */
44         int (*post)(int tlen, u_char *data);
45         /*
46          * Add a TCP initial Threeway handshake to the connection:
47          *  h is the libpcap header of the current packet.
48          *
49          *  This means create three packets:
50          *      SYN in current Direction (SEQ=0,ACK=0)
51          *      SYN,ACK in opposite Direction (SEQ=0,ACK=1)
52          *      ACK in current Direction (SEQ=1,ACK=1)
53          *
54          *  You typically need Link+IP header from private data
55          *  Output packets to state.out
56          */
57         int (*handshake)(struct pcap_pkthdr *h);
58         /*
59          * Add TCP closing handshake:
60          *      This means create three packets:
61          *              FIN,ACK in current Direction (SEQ=state.seq_num+1, ACK=state.ack_num)
62          *              FIN,ACK in opposite Direction (SEQ=state.ack_num, ACK=state.seq_num+2)
63          *              ACK             in current Direction (SEQ=state.seq_num+2,ACK=state.ack_num+1)
64          *
65          *      You typically need the libpcap header and the Link+IP header from private data
66          *  Output packets to state.out
67          */
68         int (*fin)();
69 };
70
71
72 /*Encapsulation Operations Structures*/
73 extern struct encap_ops udp_encap;
74 extern struct encap_ops dccp_encap;
75 extern struct encap_ops sll_encap;
76
77
78 /*Encapsulation Selector*/
79 void encap_sel(char* string);
80
81 /*Standard Ethernet, IP encapsulation structures and functions*/
82 struct eip4_en_p{
83         struct pcap_pkthdr      header;
84         u_char                          od[sizeof(struct ether_header)+sizeof(struct iphdr)];
85         int                                     first;
86 };
87 int fill_eip4_encap(struct eip4_en_p *eip, const u_char* data, int dlen, struct pcap_pkthdr *h);
88 int eip4_post(struct eip4_en_p *eip, int tlen, u_char* data);
89 int eip4_handshake(struct eip4_en_p *eip, struct pcap_pkthdr *h);
90 int eip4_fin(struct eip4_en_p *eip);
91
92 #endif /* ENCAP_H_ */