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
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
16 diff --git a/CMakeLists.txt b/CMakeLists.txt
18 index 0000000..7499c19
22 +cmake_minimum_required(VERSION 2.8)
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)
32 +add_executable(mcproxy-bin mcproxy/src/main.cpp
33 + mcproxy/src/hamcast_logging.cpp
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
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
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
68 +target_link_libraries(mcproxy-bin pthread)
71 +install(TARGETS mcproxy-bin DESTINATION bin/)
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)
79 if (m_current_token.get_type() == TT_STRING) {
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)
88 if (m_current_token.get_type() == TT_STRING) {
90 - unsigned int prefix = std::stoi(m_current_token.get_string());
91 + unsigned int prefix = atoi(m_current_token.get_string().c_str());
95 @@ -560,7 +560,7 @@ void parser::parse_interface_rule_match_binding(
97 if (m_current_token.get_type() == TT_STRING) {
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);
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)
110 addr_storage& addr_storage::set_port(const std::string& port)
112 - set_port(std::stoi(port.c_str()));
113 + set_port(atoi(port.c_str()));
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
125 +#include "sourcefilter.cpp"
127 std::string ipAddrResolver(std::string ipAddr)
129 std::string str[][2] = {
130 diff --git a/mcproxy/src/utils/sourcefilter.cpp b/mcproxy/src/utils/sourcefilter.cpp
132 index 0000000..64aafde
134 +++ b/mcproxy/src/utils/sourcefilter.cpp
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.
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.
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.
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/>. */
160 +#include <netinet/in.h>
161 +#include <netpacket/packet.h>
162 +#include <sys/param.h>
163 +#include <sys/socket.h>
165 +#define getsourcefilter getsourcefilter2
166 +#define setsourcefilter setsourcefilter2
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) }
181 +#define NSOL_MAP (sizeof (sol_map) / sizeof (sol_map[0]))
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. */
189 +__get_sol (int af, socklen_t len)
191 + int first_size_sol = -1;
193 + for (size_t cnt = 0; cnt < NSOL_MAP; ++cnt)
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);
199 + if (len == sol_map[cnt].size)
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
205 + if (af == sol_map[cnt].af)
207 + return sol_map[cnt].sol;
209 + if (first_size_sol == -1)
210 + first_size_sol = sol_map[cnt].sol;
214 + return first_size_sol;
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)
223 + /* We have to create an struct ip_msfilter object which we can pass
225 + socklen_t needed = GROUP_FILTER_SIZE (*numsrc);
226 + struct group_filter *gf;
227 + gf = (struct group_filter *) malloc (needed);
231 + gf->gf_interface = interface;
232 + memcpy (&gf->gf_group, group, grouplen);
233 + gf->gf_numsrc = *numsrc;
235 + /* We need to provide the appropriate socket level value. */
237 + int sol = __get_sol (group->sa_family, grouplen);
245 + result = getsockopt (s, sol, MCAST_MSFILTER, gf, &needed);
247 + /* If successful, copy the results to the places the caller wants
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;
259 + int save_errno = errno;
261 + errno = save_errno;
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)
272 + /* We have to create an struct ip_msfilter object which we can pass
274 + size_t needed = GROUP_FILTER_SIZE (numsrc);
276 + struct group_filter *gf;
277 + gf = (struct group_filter *) malloc (needed);
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));
287 + /* We need to provide the appropriate socket level value. */
289 + int sol = __get_sol (group->sa_family, grouplen);
296 + result = setsockopt (s, sol, MCAST_MSFILTER, gf, needed);
298 + int save_errno = errno;
300 + errno = save_errno;