BadVPN – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /** |
2 | * @file FrameDecider.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 | * Mudule which decides to which peers frames from the device are to be |
||
32 | * forwarded. |
||
33 | */ |
||
34 | |||
35 | #ifndef BADVPN_CLIENT_FRAMEDECIDER_H |
||
36 | #define BADVPN_CLIENT_FRAMEDECIDER_H |
||
37 | |||
38 | #include <stdint.h> |
||
39 | |||
40 | #include <structure/LinkedList1.h> |
||
41 | #include <structure/LinkedList3.h> |
||
42 | #include <structure/SAvl.h> |
||
43 | #include <base/DebugObject.h> |
||
44 | #include <base/BLog.h> |
||
45 | #include <system/BReactor.h> |
||
46 | |||
47 | struct _FrameDeciderPeer; |
||
48 | struct _FrameDecider_mac_entry; |
||
49 | struct _FrameDecider_group_entry; |
||
50 | |||
51 | typedef const uint8_t *FDMacsTree_key; |
||
52 | |||
53 | #include "FrameDecider_macs_tree.h" |
||
54 | #include <structure/SAvl_decl.h> |
||
55 | |||
56 | #include "FrameDecider_groups_tree.h" |
||
57 | #include <structure/SAvl_decl.h> |
||
58 | |||
59 | #include "FrameDecider_multicast_tree.h" |
||
60 | #include <structure/SAvl_decl.h> |
||
61 | |||
62 | struct _FrameDecider_mac_entry { |
||
63 | struct _FrameDeciderPeer *peer; |
||
64 | LinkedList1Node list_node; // node in FrameDeciderPeer.mac_entries_free or FrameDeciderPeer.mac_entries_used |
||
65 | // defined when used: |
||
66 | uint8_t mac[6]; |
||
67 | FDMacsTreeNode tree_node; // node in FrameDecider.macs_tree, indexed by mac |
||
68 | }; |
||
69 | |||
70 | struct _FrameDecider_group_entry { |
||
71 | struct _FrameDeciderPeer *peer; |
||
72 | LinkedList1Node list_node; // node in FrameDeciderPeer.group_entries_free or FrameDeciderPeer.group_entries_used |
||
73 | BTimer timer; // timer for removing the group entry, running when used |
||
74 | // defined when used: |
||
75 | // basic group data |
||
76 | uint32_t group; // group address |
||
77 | FDGroupsTreeNode tree_node; // node in FrameDeciderPeer.groups_tree, indexed by group |
||
78 | // all that folows is managed by add_to_multicast() and remove_from_multicast() |
||
79 | LinkedList3Node sig_list_node; // node in list of group entries with the same sig |
||
80 | btime_t timer_endtime; |
||
81 | int is_master; |
||
82 | // defined when used and we are master: |
||
83 | struct { |
||
84 | uint32_t sig; // last 23 bits of group address |
||
85 | FDMulticastTreeNode tree_node; // node in FrameDecider.multicast_tree, indexed by sig |
||
86 | } master; |
||
87 | }; |
||
88 | |||
89 | /** |
||
90 | * Object that represents a local device. |
||
91 | */ |
||
92 | typedef struct { |
||
93 | int max_peer_macs; |
||
94 | int max_peer_groups; |
||
95 | btime_t igmp_group_membership_interval; |
||
96 | btime_t igmp_last_member_query_time; |
||
97 | BReactor *reactor; |
||
98 | LinkedList1 peers_list; |
||
99 | FDMacsTree macs_tree; |
||
100 | FDMulticastTree multicast_tree; |
||
101 | int decide_state; |
||
102 | LinkedList1Node *decide_flood_current; |
||
103 | struct _FrameDeciderPeer *decide_unicast_peer; |
||
104 | LinkedList3Iterator decide_multicast_it; |
||
105 | DebugObject d_obj; |
||
106 | } FrameDecider; |
||
107 | |||
108 | /** |
||
109 | * Object that represents a peer that a local device can send frames to. |
||
110 | */ |
||
111 | typedef struct _FrameDeciderPeer { |
||
112 | FrameDecider *d; |
||
113 | void *user; |
||
114 | BLog_logfunc logfunc; |
||
115 | struct _FrameDecider_mac_entry *mac_entries; |
||
116 | struct _FrameDecider_group_entry *group_entries; |
||
117 | LinkedList1Node list_node; // node in FrameDecider.peers_list |
||
118 | LinkedList1 mac_entries_free; |
||
119 | LinkedList1 mac_entries_used; |
||
120 | LinkedList1 group_entries_free; |
||
121 | LinkedList1 group_entries_used; |
||
122 | FDGroupsTree groups_tree; |
||
123 | DebugObject d_obj; |
||
124 | } FrameDeciderPeer; |
||
125 | |||
126 | /** |
||
127 | * Initializes the object. |
||
128 | * |
||
129 | * @param o the object |
||
130 | * @param max_peer_macs maximum number of MAC addresses a peer may posess. Must be >0. |
||
131 | * @param max_peer_groups maximum number of multicast groups a peer may belong to. Must be >0. |
||
132 | * @param igmp_group_membership_interval IGMP Group Membership Interval value. When a join |
||
133 | * is detected for a peer in {@link FrameDeciderPeer_Analyze}, this is how long we wait |
||
134 | * for another join before we remove the group from the peer. Note that the group may |
||
135 | * be removed sooner if the peer fails to respond to a Group-Specific Query (see below). |
||
136 | * @param igmp_last_member_query_time IGMP Last Member Query Time value. When a Group-Specific |
||
137 | * Query is detected in {@link FrameDecider_AnalyzeAndDecide}, this is how long we wait for a peer |
||
138 | * belonging to the group to send a join before we remove the group from it. |
||
139 | */ |
||
140 | void FrameDecider_Init (FrameDecider *o, int max_peer_macs, int max_peer_groups, btime_t igmp_group_membership_interval, btime_t igmp_last_member_query_time, BReactor *reactor); |
||
141 | |||
142 | /** |
||
143 | * Frees the object. |
||
144 | * There must be no {@link FrameDeciderPeer} objects using this decider. |
||
145 | * |
||
146 | * @param o the object |
||
147 | */ |
||
148 | void FrameDecider_Free (FrameDecider *o); |
||
149 | |||
150 | /** |
||
151 | * Analyzes a frame read from the local device and starts deciding which peers |
||
152 | * the frame should be forwarded to. |
||
153 | * |
||
154 | * @param o the object |
||
155 | * @param frame frame data |
||
156 | * @param frame_len frame length. Must be >=0. |
||
157 | */ |
||
158 | void FrameDecider_AnalyzeAndDecide (FrameDecider *o, const uint8_t *frame, int frame_len); |
||
159 | |||
160 | /** |
||
161 | * Returns the next peer that the frame submitted to {@link FrameDecider_AnalyzeAndDecide} should be |
||
162 | * forwarded to. |
||
163 | * |
||
164 | * @param o the object |
||
165 | * @return peer to forward the frame to, or NULL if no more |
||
166 | */ |
||
167 | FrameDeciderPeer * FrameDecider_NextDestination (FrameDecider *o); |
||
168 | |||
169 | /** |
||
170 | * Initializes the object. |
||
171 | * |
||
172 | * @param o the object |
||
173 | * @param d decider this peer will belong to |
||
174 | * @param user argument to log function |
||
175 | * @param logfunc function which prepends the log prefix using {@link BLog_Append} |
||
176 | * @return 1 on success, 0 on failure |
||
177 | */ |
||
178 | int FrameDeciderPeer_Init (FrameDeciderPeer *o, FrameDecider *d, void *user, BLog_logfunc logfunc) WARN_UNUSED; |
||
179 | |||
180 | /** |
||
181 | * Frees the object. |
||
182 | * |
||
183 | * @param o the object |
||
184 | */ |
||
185 | void FrameDeciderPeer_Free (FrameDeciderPeer *o); |
||
186 | |||
187 | /** |
||
188 | * Analyzes a frame received from the peer. |
||
189 | * |
||
190 | * @param o the object |
||
191 | * @param frame frame data |
||
192 | * @param frame_len frame length. Must be >=0. |
||
193 | */ |
||
194 | void FrameDeciderPeer_Analyze (FrameDeciderPeer *o, const uint8_t *frame, int frame_len); |
||
195 | |||
196 | #endif |