Skip to content

Commit

Permalink
Port to QNX (no tests yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
Milan Ziegler committed Jan 12, 2024
1 parent a495be4 commit 4188851
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 24 deletions.
8 changes: 2 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ if (NOT GTEST_ROOT)
if (DEFINED ENV{GTEST_ROOT})
set(GTEST_ROOT $ENV{GTEST_ROOT})
else()
include(FetchContent)
FetchContent_Declare(googletest GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG v1.14.0)
FetchContent_Populate(googletest)
set(GTEST_ROOT ${googletest_SOURCE_DIR})
set(GTEST_ROOT "n/a" CACHE STRING "Path to root folder of googletest. Must be set for building the tests.")
endif()
endif()

Expand Down Expand Up @@ -270,7 +267,6 @@ endif()

if ("${CMAKE_SYSTEM_NAME}" STREQUAL "QNX")
add_definitions(-DBOOST_ASIO_DISABLE_STRING_VIEW)
set (VSOMEIP_BASE_PATH "/var")
set(USE_RT "")
endif()

Expand Down Expand Up @@ -320,7 +316,7 @@ add_library(${VSOMEIP_NAME} SHARED ${${VSOMEIP_NAME}_SRC})
set_target_properties (${VSOMEIP_NAME} PROPERTIES VERSION ${VSOMEIP_VERSION} SOVERSION ${VSOMEIP_MAJOR_VERSION})
if (MSVC)
set_target_properties(${VSOMEIP_NAME} PROPERTIES COMPILE_DEFINITIONS "VSOMEIP_DLL_COMPILATION")
elseif (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "QNX")
else ()
set_target_properties(${VSOMEIP_NAME} PROPERTIES LINK_FLAGS "-Wl,-wrap,socket -Wl,-wrap,accept -Wl,-wrap,open")
endif ()
target_include_directories(${VSOMEIP_NAME} INTERFACE
Expand Down
2 changes: 2 additions & 0 deletions implementation/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ cc_library(
],
exclude = [
"utility/src/wrappers.cpp",
"utility/src/wrappers_qnx.cpp",
],
),
hdrs = glob(
Expand All @@ -116,6 +117,7 @@ cc_library(
# since CLOEXEC is not immediately necessary for our use-case, disable the wrappers for now
#"-Wl,-wrap,socket",
#"-Wl,-wrap,accept",
#"-Wl,-wrap,open",
],
"//conditions:default": [],
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ receive_cb (std::shared_ptr<storage> _data) {
its_vec[0].iov_base = _data->buffer_;
its_vec[0].iov_len = _data->length_;

#if !defined(__QNX__)
union {
struct cmsghdr cmh;
char control[CMSG_SPACE(sizeof(struct ucred))];
Expand All @@ -75,13 +76,16 @@ receive_cb (std::shared_ptr<storage> _data) {
control_un.cmh.cmsg_len = CMSG_LEN(sizeof(struct ucred));
control_un.cmh.cmsg_level = SOL_SOCKET;
control_un.cmh.cmsg_type = SCM_CREDENTIALS;
#endif

// Build header with all informations to call ::recvmsg
msghdr its_header = msghdr();
its_header.msg_iov = its_vec;
its_header.msg_iovlen = 1;
#if !defined(__QNX__)
its_header.msg_control = control_un.control;
its_header.msg_controllen = sizeof(control_un.control);
#endif

// Call recvmsg and handle its result
errno = 0;
Expand All @@ -105,6 +109,7 @@ receive_cb (std::shared_ptr<storage> _data) {
if (_data->bytes_ == 0)
_error = boost::asio::error::eof;

#if !defined(__QNX__)
// Extract credentials (UID/GID)
struct ucred *its_credentials;
for (struct cmsghdr *cmsg = CMSG_FIRSTHDR(&its_header);
Expand All @@ -123,6 +128,7 @@ receive_cb (std::shared_ptr<storage> _data) {
}
}
}
#endif

break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

#include <iomanip>
#include <memory>
#ifdef __QNX__
#include <vector>
#endif

#include <boost/asio/ip/udp.hpp>

Expand Down Expand Up @@ -41,6 +44,10 @@ struct storage :
bool is_v4_;
boost::asio::ip::address destination_;
size_t bytes_;
#ifdef __QNX__
std::vector<char> control_v4_buf{CMSG_SPACE(sizeof(struct in_pktinfo)), 0};
std::vector<char> control_v6_buf{CMSG_SPACE(sizeof(struct in6_pktinfo)), 0};
#endif

storage(
std::recursive_mutex &_multicast_mutex,
Expand Down Expand Up @@ -238,27 +245,38 @@ receive_cb (std::shared_ptr<storage> _data) {
struct sockaddr_in6 v6;
} addr;

#ifdef __QNX__
void * control_v4_ptr = _data->control_v4_buf.data();
size_t control_v4_len = _data->control_v4_buf.size();
void * control_v6_ptr = _data->control_v6_buf.data();
size_t control_v6_len = _data->control_v6_buf.size();
#else
union {
struct cmsghdr cmh;
union {
char v4[CMSG_SPACE(sizeof(struct in_pktinfo))];
char v6[CMSG_SPACE(sizeof(struct in6_pktinfo))];
} control;
} control_un;
void * control_v4_ptr = control_un.control.v4;
size_t control_v4_len = sizeof(control_un.control.v4);
void * control_v6_ptr = control_un.control.v6;
size_t control_v6_len = sizeof(control_un.control.v6);
#endif

// Prepare
if (_data->is_v4_) {
its_header.msg_name = &addr;
its_header.msg_namelen = sizeof(sockaddr_in);

its_header.msg_control = control_un.control.v4;
its_header.msg_controllen = sizeof(control_un.control.v4);
its_header.msg_control = control_v4_ptr;
its_header.msg_controllen = control_v4_len;
} else {
its_header.msg_name = &addr;
its_header.msg_namelen = sizeof(sockaddr_in6);

its_header.msg_control = control_un.control.v6;
its_header.msg_controllen = sizeof(control_un.control.v6);
its_header.msg_control = control_v6_ptr;
its_header.msg_controllen = control_v6_len;
}

// Call recvmsg and handle its result
Expand Down
4 changes: 2 additions & 2 deletions implementation/endpoints/src/endpoint_manager_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,8 @@ endpoint_manager_base::get_local_server_port(port_t &_port,
uid_t its_uid { ANY_UID };
gid_t its_gid { ANY_GID };
#else
uid_t its_uid { getuid() };
gid_t its_gid { getgid() };
uid_t its_uid { static_cast<uid_t>(getuid()) };
gid_t its_gid { static_cast<gid_t>(getgid()) };
#endif

auto its_port_ranges = configuration_->get_routing_guest_ports(
Expand Down
6 changes: 1 addition & 5 deletions implementation/endpoints/src/server_endpoint_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -877,18 +877,14 @@ void server_endpoint_impl<Protocol>::update_last_departure(
}

// Instantiate template
#ifdef __linux__
#if defined(__linux__) || defined(__QNX__)
#if VSOMEIP_BOOST_VERSION < 106600
template class server_endpoint_impl<boost::asio::local::stream_protocol_ext>;
#else
template class server_endpoint_impl<boost::asio::local::stream_protocol>;
#endif
#endif

#ifdef __QNX__
template class server_endpoint_impl<boost::asio::local::stream_protocol_ext>;
#endif

template class server_endpoint_impl<boost::asio::ip::tcp>;
template class server_endpoint_impl<boost::asio::ip::udp>;

Expand Down
4 changes: 2 additions & 2 deletions implementation/routing/src/routing_manager_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1645,7 +1645,7 @@ void routing_manager_client::on_message(
auto its_policy = its_command.get_policy();
uint32_t its_uid;
uint32_t its_gid;
if (its_policy->get_uid_gid(its_uid, its_gid)) {
if (its_policy->get_uid_gid(reinterpret_cast<uid_t&>(its_uid), reinterpret_cast<gid_t&>(its_gid))) {
if (is_internal_policy_update
|| its_security->is_policy_update_allowed(its_uid, its_policy)) {
its_security->update_security_policy(its_uid, its_gid, its_policy);
Expand Down Expand Up @@ -2832,7 +2832,7 @@ void routing_manager_client::on_update_security_credentials(

for (const auto &c : _command.get_credentials()) {
std::shared_ptr<policy> its_policy(std::make_shared<policy>());
boost::icl::interval_set<uint32_t> its_gid_set;
boost::icl::interval_set<gid_t> its_gid_set;
uid_t its_uid(c.first);
gid_t its_gid(c.second);

Expand Down
2 changes: 1 addition & 1 deletion implementation/routing/src/routing_manager_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ void routing_manager_stub::send_client_credentials(const client_t _target,
if (its_endpoint) {
protocol::update_security_credentials_command its_command;
its_command.set_client(_target);
its_command.set_credentials(_credentials);
its_command.set_credentials(reinterpret_cast<std::set<std::pair<uid_t, gid_t>> &>(_credentials));

#if 0
std::stringstream msg;
Expand Down
1 change: 1 addition & 0 deletions implementation/security/include/policy_manager_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class VSOMEIP_IMPORT_EXPORT policy_manager_impl
static std::shared_ptr<policy_manager_impl> get();

policy_manager_impl();
virtual ~policy_manager_impl();

#ifndef VSOMEIP_DISABLE_SECURITY
// policy_manager interface
Expand Down
4 changes: 2 additions & 2 deletions implementation/security/src/policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ policy::deserialize_uid_gid(const byte_t * &_data, uint32_t &_size,

bool its_result;

its_result = deserialize_u32(_data, _size, _uid);
its_result = deserialize_u32(_data, _size, reinterpret_cast<uint32_t &>(_uid));
if (its_result == false)
return false;

its_result = deserialize_u32(_data, _size, _gid);
its_result = deserialize_u32(_data, _size, reinterpret_cast<uint32_t &>(_gid));
if (its_result == false)
return false;

Expand Down
6 changes: 4 additions & 2 deletions implementation/security/src/policy_manager_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ policy_manager_impl::policy_manager_impl()
{
}

policy_manager_impl::~policy_manager_impl() = default;

bool
policy_manager_impl::is_enabled() const {
#ifdef VSOMEIP_DISABLE_SECURITY
Expand Down Expand Up @@ -619,7 +621,7 @@ policy_manager_impl::parse_policy(const byte_t* &_buffer, uint32_t &_buffer_size

bool is_valid = _policy->deserialize(_buffer, _buffer_size);
if (is_valid)
is_valid = _policy->get_uid_gid(_uid, _gid);
is_valid = _policy->get_uid_gid(reinterpret_cast<uid_t&>(_uid), reinterpret_cast<gid_t&>(_gid));
return is_valid;
}

Expand Down Expand Up @@ -1313,7 +1315,7 @@ policy_manager_impl::parse_uid_gid(const byte_t* &_buffer,

const auto its_policy = std::make_shared<policy>();
return (its_policy
&& its_policy->deserialize_uid_gid(_buffer, _buffer_size, _uid, _gid));
&& its_policy->deserialize_uid_gid(_buffer, _buffer_size, reinterpret_cast<uid_t&>(_uid), reinterpret_cast<gid_t&>(_gid)));
}

#endif // !VSOMEIP_DISABLE_SECURITY
Expand Down
2 changes: 2 additions & 0 deletions implementation/utility/include/byteorder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <endian.h>
#elif defined(__freebsd__)
#include <sys/endian.h>
#elif defined(__QNX__)
#include <sys/types.h>
#else
// TEST IF THERE COULD BE AN ERROR!
//#error "Undefined OS (only Linux/FreeBSD are currently supported)"
Expand Down

0 comments on commit 4188851

Please sign in to comment.