01571e919a311041f2ac827ab05ca58c38f85430
[feed/routing.git] / mcproxy / patches / 0001-Add-CMake-and-uclibc-compatibility-support.patch
1 From 7618500760e3c9c0d831714fdedb497c0738e131 Mon Sep 17 00:00:00 2001
2 From: Steven Barth <steven@midlink.org>
3 Date: Tue, 25 Mar 2014 15:09:11 +0100
4 Subject: [PATCH] Add CMake and uclibc support
5
6 ---
7 CMakeLists.txt | 51 +++++++++++
8 mcproxy/src/parser/parser.cpp | 6 +-
9 mcproxy/src/utils/addr_storage.cpp | 2 +-
10 mcproxy/src/utils/mc_socket.cpp | 2 +
11 mcproxy/src/utils/sourcefilter.cpp | 168 +++++++++++++++++++++++++++++++++++++
12 5 files changed, 225 insertions(+), 4 deletions(-)
13 create mode 100644 CMakeLists.txt
14 create mode 100644 mcproxy/src/utils/sourcefilter.cpp
15
16 diff --git a/CMakeLists.txt b/CMakeLists.txt
17 new file mode 100644
18 index 0000000..7499c19
19 --- /dev/null
20 +++ b/CMakeLists.txt
21 @@ -0,0 +1,51 @@
22 +cmake_minimum_required(VERSION 2.8)
23 +
24 +# Project Definition
25 +project(mcproxy CXX)
26 +set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
27 +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++11")
28 +add_definitions(-Wall -Wextra -pedantic)
29 +include_directories(${CMAKE_SOURCE_DIR}/mcproxy)
30 +
31 +
32 +add_executable(mcproxy-bin mcproxy/src/main.cpp
33 + mcproxy/src/hamcast_logging.cpp
34 + #utils
35 + mcproxy/src/utils/mc_socket.cpp
36 + mcproxy/src/utils/addr_storage.cpp
37 + mcproxy/src/utils/mroute_socket.cpp
38 + mcproxy/src/utils/if_prop.cpp
39 + mcproxy/src/utils/reverse_path_filter.cpp
40 + #proxy
41 + mcproxy/src/proxy/proxy.cpp
42 + mcproxy/src/proxy/sender.cpp
43 + mcproxy/src/proxy/receiver.cpp
44 + mcproxy/src/proxy/mld_receiver.cpp
45 + mcproxy/src/proxy/igmp_receiver.cpp
46 + mcproxy/src/proxy/mld_sender.cpp
47 + mcproxy/src/proxy/igmp_sender.cpp
48 + mcproxy/src/proxy/proxy_instance.cpp
49 + mcproxy/src/proxy/routing.cpp
50 + mcproxy/src/proxy/worker.cpp
51 + mcproxy/src/proxy/timing.cpp
52 + mcproxy/src/proxy/check_if.cpp
53 + mcproxy/src/proxy/check_kernel.cpp
54 + mcproxy/src/proxy/membership_db.cpp
55 + mcproxy/src/proxy/querier.cpp
56 + mcproxy/src/proxy/timers_values.cpp
57 + mcproxy/src/proxy/interfaces.cpp
58 + mcproxy/src/proxy/def.cpp
59 + mcproxy/src/proxy/simple_mc_proxy_routing.cpp
60 + mcproxy/src/proxy/simple_routing_data.cpp
61 + #parser
62 + mcproxy/src/parser/scanner.cpp
63 + mcproxy/src/parser/token.cpp
64 + mcproxy/src/parser/configuration.cpp
65 + mcproxy/src/parser/parser.cpp
66 + mcproxy/src/parser/interface.cpp
67 +)
68 +target_link_libraries(mcproxy-bin pthread)
69 +
70 +# Installation
71 +install(TARGETS mcproxy-bin DESTINATION bin/)
72 +
73 diff --git a/mcproxy/src/parser/parser.cpp b/mcproxy/src/parser/parser.cpp
74 index c196be9..516a700 100644
75 --- a/mcproxy/src/parser/parser.cpp
76 +++ b/mcproxy/src/parser/parser.cpp
77 @@ -125,7 +125,7 @@ void parser::parse_instance_definition(inst_def_set& ids)
78 get_next_token();
79 if (m_current_token.get_type() == TT_STRING) {
80 try {
81 - table_number = std::stoi(m_current_token.get_string());
82 + table_number = atoi(m_current_token.get_string().c_str());
83 user_selected_table_number = true;
84 } catch (std::logic_error e) {
85 HC_LOG_ERROR("failed to parse line " << m_current_line << " table number: " << table_number << " is not a number");
86 @@ -298,7 +298,7 @@ std::unique_ptr<addr_match> parser::parse_rule_part(group_mem_protocol gmp)
87 get_next_token();
88 if (m_current_token.get_type() == TT_STRING) {
89 try {
90 - unsigned int prefix = std::stoi(m_current_token.get_string());
91 + unsigned int prefix = atoi(m_current_token.get_string().c_str());
92 if (prefix > 128) {
93 throw;
94 }
95 @@ -560,7 +560,7 @@ void parser::parse_interface_rule_match_binding(
96 get_next_token();
97 if (m_current_token.get_type() == TT_STRING) {
98 try {
99 - int tmp_timeout = std::stoi(m_current_token.get_string());
100 + int tmp_timeout = atoi(m_current_token.get_string().c_str());
101 timeout = std::chrono::milliseconds(tmp_timeout);
102 } catch (...) {
103 error_notification();
104 diff --git a/mcproxy/src/utils/addr_storage.cpp b/mcproxy/src/utils/addr_storage.cpp
105 index 125ccbf..e812ac9 100644
106 --- a/mcproxy/src/utils/addr_storage.cpp
107 +++ b/mcproxy/src/utils/addr_storage.cpp
108 @@ -298,7 +298,7 @@ addr_storage& addr_storage::set_port(uint16_t port)
109
110 addr_storage& addr_storage::set_port(const std::string& port)
111 {
112 - set_port(std::stoi(port.c_str()));
113 + set_port(atoi(port.c_str()));
114 return *this;
115 }
116
117 diff --git a/mcproxy/src/utils/mc_socket.cpp b/mcproxy/src/utils/mc_socket.cpp
118 index b8fb3ae..8c32e08 100644
119 --- a/mcproxy/src/utils/mc_socket.cpp
120 +++ b/mcproxy/src/utils/mc_socket.cpp
121 @@ -37,6 +37,8 @@
122 #include <numeric>
123 #include <unistd.h>
124
125 +#include "sourcefilter.cpp"
126 +
127 std::string ipAddrResolver(std::string ipAddr)
128 {
129 std::string str[][2] = {
130 diff --git a/mcproxy/src/utils/sourcefilter.cpp b/mcproxy/src/utils/sourcefilter.cpp
131 new file mode 100644
132 index 0000000..64aafde
133 --- /dev/null
134 +++ b/mcproxy/src/utils/sourcefilter.cpp
135 @@ -0,0 +1,168 @@
136 +/* Get source filter. Linux version.
137 + Copyright (C) 2004-2014 Free Software Foundation, Inc.
138 + This file is part of the GNU C Library.
139 + Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
140 +
141 + The GNU C Library is free software; you can redistribute it and/or
142 + modify it under the terms of the GNU Lesser General Public
143 + License as published by the Free Software Foundation; either
144 + version 2.1 of the License, or (at your option) any later version.
145 +
146 + The GNU C Library is distributed in the hope that it will be useful,
147 + but WITHOUT ANY WARRANTY; without even the implied warranty of
148 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
149 + Lesser General Public License for more details.
150 +
151 + You should have received a copy of the GNU Lesser General Public
152 + License along with the GNU C Library; if not, see
153 + <http://www.gnu.org/licenses/>. */
154 +
155 +#include <assert.h>
156 +#include <errno.h>
157 +#include <stdlib.h>
158 +#include <string.h>
159 +#include <stdint.h>
160 +#include <netinet/in.h>
161 +#include <netpacket/packet.h>
162 +#include <sys/param.h>
163 +#include <sys/socket.h>
164 +
165 +#define getsourcefilter getsourcefilter2
166 +#define setsourcefilter setsourcefilter2
167 +
168 +static const struct
169 +{
170 + int sol;
171 + int af;
172 + socklen_t size;
173 +} sol_map[] =
174 + {
175 + /* Sort the array according to importance of the protocols. Add
176 + more protocols when they become available. */
177 + { SOL_IP, AF_INET, sizeof (struct sockaddr_in) },
178 + { SOL_IPV6, AF_INET6, sizeof (struct sockaddr_in6) },
179 + { SOL_PACKET, AF_PACKET, sizeof (struct sockaddr_ll) }
180 + };
181 +#define NSOL_MAP (sizeof (sol_map) / sizeof (sol_map[0]))
182 +
183 +
184 +/* Try to determine the socket level value. Ideally both side and
185 + family are set. But sometimes only the size is correct and the
186 + family value might be bogus. Loop over the array entries and look
187 + for a perfect match or the first match based on size. */
188 +static int
189 +__get_sol (int af, socklen_t len)
190 +{
191 + int first_size_sol = -1;
192 +
193 + for (size_t cnt = 0; cnt < NSOL_MAP; ++cnt)
194 + {
195 + /* Just a test so that we make sure the special value used to
196 + signal the "we have so far no socket level value" is OK. */
197 + assert (sol_map[cnt].sol != -1);
198 +
199 + if (len == sol_map[cnt].size)
200 + {
201 + /* The size matches, which is a requirement. If the family
202 + matches, too, we have a winner. Otherwise we remember the
203 + socket level value for this protocol if it is the first
204 + match. */
205 + if (af == sol_map[cnt].af)
206 + /* Bingo! */
207 + return sol_map[cnt].sol;
208 +
209 + if (first_size_sol == -1)
210 + first_size_sol = sol_map[cnt].sol;
211 + }
212 + }
213 +
214 + return first_size_sol;
215 +}
216 +
217 +
218 +int
219 +getsourcefilter2 (int s, uint32_t interface, const struct sockaddr *group,
220 + socklen_t grouplen, uint32_t *fmode, uint32_t *numsrc,
221 + struct sockaddr_storage *slist)
222 +{
223 + /* We have to create an struct ip_msfilter object which we can pass
224 + to the kernel. */
225 + socklen_t needed = GROUP_FILTER_SIZE (*numsrc);
226 + struct group_filter *gf;
227 + gf = (struct group_filter *) malloc (needed);
228 + if (gf == NULL)
229 + return -1;
230 +
231 + gf->gf_interface = interface;
232 + memcpy (&gf->gf_group, group, grouplen);
233 + gf->gf_numsrc = *numsrc;
234 +
235 + /* We need to provide the appropriate socket level value. */
236 + int result;
237 + int sol = __get_sol (group->sa_family, grouplen);
238 + if (sol == -1)
239 + {
240 + errno = EINVAL;
241 + result = -1;
242 + }
243 + else
244 + {
245 + result = getsockopt (s, sol, MCAST_MSFILTER, gf, &needed);
246 +
247 + /* If successful, copy the results to the places the caller wants
248 + them in. */
249 + if (result == 0)
250 + {
251 + *fmode = gf->gf_fmode;
252 + memcpy (slist, gf->gf_slist,
253 + MIN (*numsrc, gf->gf_numsrc)
254 + * sizeof (struct sockaddr_storage));
255 + *numsrc = gf->gf_numsrc;
256 + }
257 + }
258 +
259 + int save_errno = errno;
260 + free (gf);
261 + errno = save_errno;
262 +
263 + return result;
264 +}
265 +
266 +
267 +int
268 +setsourcefilter2 (int s, uint32_t interface, const struct sockaddr *group,
269 + socklen_t grouplen, uint32_t fmode, uint32_t numsrc,
270 + const struct sockaddr_storage *slist)
271 +{
272 + /* We have to create an struct ip_msfilter object which we can pass
273 + to the kernel. */
274 + size_t needed = GROUP_FILTER_SIZE (numsrc);
275 +
276 + struct group_filter *gf;
277 + gf = (struct group_filter *) malloc (needed);
278 + if (gf == NULL)
279 + return -1;
280 +
281 + gf->gf_interface = interface;
282 + memcpy (&gf->gf_group, group, grouplen);
283 + gf->gf_fmode = fmode;
284 + gf->gf_numsrc = numsrc;
285 + memcpy (gf->gf_slist, slist, numsrc * sizeof (struct sockaddr_storage));
286 +
287 + /* We need to provide the appropriate socket level value. */
288 + int result;
289 + int sol = __get_sol (group->sa_family, grouplen);
290 + if (sol == -1)
291 + {
292 + errno = EINVAL;
293 + result = -1;
294 + }
295 + else
296 + result = setsockopt (s, sol, MCAST_MSFILTER, gf, needed);
297 +
298 + int save_errno = errno;
299 + free (gf);
300 + errno = save_errno;
301 +
302 + return result;
303 +}
304 --
305 1.8.3.2
306