BadVPN – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 /**
2 * @file FragmentProtoAssembler.h
3 * @author Ambroz Bizjak <ambrop7@gmail.com>
4 *
5 * @section LICENSE
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the author nor the
15 * names of its contributors may be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * @section DESCRIPTION
30 *
31 * Object which decodes packets according to FragmentProto.
32 */
33  
34 #ifndef BADVPN_CLIENT_FRAGMENTPROTOASSEMBLER_H
35 #define BADVPN_CLIENT_FRAGMENTPROTOASSEMBLER_H
36  
37 #include <stdint.h>
38  
39 #include <protocol/fragmentproto.h>
40 #include <misc/debug.h>
41 #include <misc/compare.h>
42 #include <base/DebugObject.h>
43 #include <base/BLog.h>
44 #include <structure/LinkedList1.h>
45 #include <structure/SAvl.h>
46 #include <flow/PacketPassInterface.h>
47  
48 #define FPA_MAX_TIME UINT32_MAX
49  
50 struct FragmentProtoAssembler_frame;
51  
52 #include "FragmentProtoAssembler_tree.h"
53 #include <structure/SAvl_decl.h>
54  
55 struct FragmentProtoAssembler_chunk {
56 int start;
57 int len;
58 };
59  
60 struct FragmentProtoAssembler_frame {
61 LinkedList1Node list_node; // node in free or used list
62 struct FragmentProtoAssembler_chunk *chunks; // array of chunks, up to num_chunks
63 uint8_t *buffer; // buffer with frame data, size output_mtu
64 // everything below only defined when frame entry is used
65 fragmentproto_frameid id; // frame identifier
66 uint32_t time; // packet time when the last chunk was received
67 FPAFramesTreeNode tree_node; // node fields in tree for searching frames by id
68 int num_chunks; // number of valid chunks
69 int sum; // sum of all chunks' lengths
70 int length; // length of the frame, or -1 if not yet known
71 int length_so_far; // if length=-1, current data set's upper bound
72 };
73  
74 /**
75 * Object which decodes packets according to FragmentProto.
76 *
77 * Input is with {@link PacketPassInterface}.
78 * Output is with {@link PacketPassInterface}.
79 */
80 typedef struct {
81 void *user;
82 BLog_logfunc logfunc;
83 PacketPassInterface input;
84 PacketPassInterface *output;
85 int output_mtu;
86 int num_chunks;
87 uint32_t time;
88 int time_tolerance;
89 struct FragmentProtoAssembler_frame *frames_entries;
90 struct FragmentProtoAssembler_chunk *frames_chunks;
91 uint8_t *frames_buffer;
92 LinkedList1 frames_free;
93 LinkedList1 frames_used;
94 FPAFramesTree frames_used_tree;
95 int in_len;
96 uint8_t *in;
97 int in_pos;
98 DebugObject d_obj;
99 } FragmentProtoAssembler;
100  
101 /**
102 * Initializes the object.
103 * {@link BLog_Init} must have been done.
104 *
105 * @param o the object
106 * @param input_mtu maximum input packet size. Must be >=0.
107 * @param output output interface
108 * @param num_frames number of frames we can hold. Must be >0 and < FPA_MAX_TIME.
109 * To make the assembler tolerate out-of-order input of degree D, set to D+2.
110 * Here, D is the minimum size of a hypothetical buffer needed to order the input.
111 * @param num_chunks maximum number of chunks a frame can come in. Must be >0.
112 * @param pg pending group
113 * @param user argument to handlers
114 * @param logfunc function which prepends the log prefix using {@link BLog_Append}
115 * @return 1 on success, 0 on failure
116 */
117 int FragmentProtoAssembler_Init (FragmentProtoAssembler *o, int input_mtu, PacketPassInterface *output, int num_frames, int num_chunks, BPendingGroup *pg, void *user, BLog_logfunc logfunc) WARN_UNUSED;
118  
119 /**
120 * Frees the object.
121 *
122 * @param o the object
123 */
124 void FragmentProtoAssembler_Free (FragmentProtoAssembler *o);
125  
126 /**
127 * Returns the input interface.
128 *
129 * @param o the object
130 * @return input interface
131 */
132 PacketPassInterface * FragmentProtoAssembler_GetInput (FragmentProtoAssembler *o);
133  
134 #endif