diff options
Diffstat (limited to 'implementation/endpoints')
11 files changed, 212 insertions, 59 deletions
diff --git a/implementation/endpoints/include/endpoint_manager_impl.hpp b/implementation/endpoints/include/endpoint_manager_impl.hpp index cdf41b8..a7d28c6 100644 --- a/implementation/endpoints/include/endpoint_manager_impl.hpp +++ b/implementation/endpoints/include/endpoint_manager_impl.hpp @@ -44,12 +44,13 @@ public: std::shared_ptr<endpoint> create_server_endpoint(uint16_t _port, bool _reliable, bool _start); + std::shared_ptr<endpoint> find_server_endpoint(uint16_t _port, bool _reliable) const; std::shared_ptr<endpoint> find_or_create_server_endpoint( uint16_t _port, bool _reliable, bool _start, service_t _service, - instance_t _instance); + instance_t _instance, bool &_is_found, bool _is_multicast = false); bool remove_server_endpoint(uint16_t _port, bool _reliable); @@ -57,6 +58,7 @@ public: bool _reliable); void find_or_create_multicast_endpoint( service_t _service, instance_t _instance, + const boost::asio::ip::address &_sender, const boost::asio::ip::address &_address, uint16_t _port); void clear_multicast_endpoints(service_t _service, instance_t _instance); @@ -70,7 +72,12 @@ public: instance_t find_instance(service_t _service, endpoint* const _endpoint) const; + instance_t find_instance_multicast(service_t _service, + const boost::asio::ip::address &_sender) const; + bool remove_instance(service_t _service, endpoint* const _endpoint); + bool remove_instance_multicast(service_t _service, instance_t _instance); + // endpoint_host interface void on_connect(std::shared_ptr<endpoint> _endpoint); @@ -111,6 +118,7 @@ private: client_endpoints_by_ip_t client_endpoints_by_ip_; std::map<service_t, std::map<endpoint *, instance_t> > service_instances_; + std::map<service_t, std::map<boost::asio::ip::address, instance_t> > service_instances_multicast_; std::map<bool, std::set<uint16_t>> used_client_ports_; std::mutex used_client_ports_mutex_; diff --git a/implementation/endpoints/include/server_endpoint_impl.hpp b/implementation/endpoints/include/server_endpoint_impl.hpp index 4e03115..193043c 100644 --- a/implementation/endpoints/include/server_endpoint_impl.hpp +++ b/implementation/endpoints/include/server_endpoint_impl.hpp @@ -107,6 +107,10 @@ protected: mutable std::mutex mutex_; + std::mutex sent_mutex_; + bool is_sending_; + boost::asio::steady_timer sent_timer_; + private: virtual std::string get_remote_information( const queue_iterator_type _queue_iterator) const = 0; diff --git a/implementation/endpoints/include/tcp_server_endpoint_impl.hpp b/implementation/endpoints/include/tcp_server_endpoint_impl.hpp index c6481b8..af9a724 100644 --- a/implementation/endpoints/include/tcp_server_endpoint_impl.hpp +++ b/implementation/endpoints/include/tcp_server_endpoint_impl.hpp @@ -106,6 +106,7 @@ private: service_t _service, method_t _method, client_t _client, session_t _session, const std::chrono::steady_clock::time_point _start); void stop_and_remove_connection(); + void wait_until_sent(const boost::system::error_code &_error); std::mutex socket_mutex_; tcp_server_endpoint_impl::socket_type socket_; diff --git a/implementation/endpoints/include/udp_server_endpoint_impl.hpp b/implementation/endpoints/include/udp_server_endpoint_impl.hpp index db936f3..4ceefb6 100644 --- a/implementation/endpoints/include/udp_server_endpoint_impl.hpp +++ b/implementation/endpoints/include/udp_server_endpoint_impl.hpp @@ -48,6 +48,7 @@ public: std::chrono::nanoseconds *_maximum_retention) const; VSOMEIP_EXPORT void join(const std::string &_address); + VSOMEIP_EXPORT void join_unlocked(const std::string &_address); void leave(const std::string &_address); void add_default_target(service_t _service, diff --git a/implementation/endpoints/src/endpoint_manager_impl.cpp b/implementation/endpoints/src/endpoint_manager_impl.cpp index dc02aa5..32ba31d 100644 --- a/implementation/endpoints/src/endpoint_manager_impl.cpp +++ b/implementation/endpoints/src/endpoint_manager_impl.cpp @@ -146,18 +146,60 @@ void endpoint_manager_impl::is_remote_service_known( void endpoint_manager_impl::add_remote_service_info( service_t _service, instance_t _instance, const std::shared_ptr<endpoint_definition>& _ep_definition) { - std::lock_guard<std::recursive_mutex> its_lock(endpoint_mutex_); - remote_service_info_[_service][_instance][_ep_definition->is_reliable()] = + + std::shared_ptr<serviceinfo> its_info; + std::shared_ptr<endpoint> its_endpoint; + bool must_report(false); + { + std::lock_guard<std::recursive_mutex> its_lock(endpoint_mutex_); + remote_service_info_[_service][_instance][_ep_definition->is_reliable()] = _ep_definition; + + if (_ep_definition->is_reliable()) { + its_endpoint = find_remote_client(_service, _instance, true); + must_report = (its_endpoint && its_endpoint->is_established_or_connected()); + if (must_report) + its_info = rm_->find_service(_service, _instance); + } + } + + if (must_report) + static_cast<routing_manager_impl*>(rm_)->service_endpoint_connected( + _service, _instance, its_info->get_major(), its_info->get_minor(), + its_endpoint, false); } void endpoint_manager_impl::add_remote_service_info( service_t _service, instance_t _instance, const std::shared_ptr<endpoint_definition>& _ep_definition_reliable, const std::shared_ptr<endpoint_definition>& _ep_definition_unreliable) { - std::lock_guard<std::recursive_mutex> its_lock(endpoint_mutex_); - remote_service_info_[_service][_instance][true] = _ep_definition_reliable; - remote_service_info_[_service][_instance][false] = _ep_definition_unreliable; + + std::shared_ptr<serviceinfo> its_info; + std::shared_ptr<endpoint> its_reliable, its_unreliable; + bool must_report(false); + { + std::lock_guard<std::recursive_mutex> its_lock(endpoint_mutex_); + remote_service_info_[_service][_instance][false] = _ep_definition_unreliable; + remote_service_info_[_service][_instance][true] = _ep_definition_reliable; + + its_unreliable = find_remote_client(_service, _instance, false); + its_reliable = find_remote_client(_service, _instance, true); + + must_report = (its_unreliable && its_unreliable->is_established_or_connected() + && its_reliable && its_reliable->is_established_or_connected()); + + if (must_report) + its_info = rm_->find_service(_service, _instance); + } + + if (must_report) { + static_cast<routing_manager_impl*>(rm_)->service_endpoint_connected( + _service, _instance, its_info->get_major(), its_info->get_minor(), + its_unreliable, false); + static_cast<routing_manager_impl*>(rm_)->service_endpoint_connected( + _service, _instance, its_info->get_major(), its_info->get_minor(), + its_reliable, false); + } } void endpoint_manager_impl::clear_remote_service_info(service_t _service, @@ -230,7 +272,6 @@ std::shared_ptr<endpoint> endpoint_manager_impl::create_server_endpoint( return (its_endpoint); } - std::shared_ptr<endpoint> endpoint_manager_impl::find_server_endpoint( uint16_t _port, bool _reliable) const { std::shared_ptr<endpoint> its_endpoint; @@ -247,15 +288,20 @@ std::shared_ptr<endpoint> endpoint_manager_impl::find_server_endpoint( std::shared_ptr<endpoint> endpoint_manager_impl::find_or_create_server_endpoint( uint16_t _port, bool _reliable, bool _start, service_t _service, - instance_t _instance) { + instance_t _instance, bool &_is_found, bool _is_multicast) { std::shared_ptr<endpoint> its_endpoint = find_server_endpoint(_port, _reliable); + _is_found = false; if (!its_endpoint) { its_endpoint = create_server_endpoint(_port, _reliable, _start); + } else { + _is_found = true; } if (its_endpoint) { std::lock_guard<std::recursive_mutex> its_lock(endpoint_mutex_); - service_instances_[_service][its_endpoint.get()] = _instance; + if (!_is_multicast) { + service_instances_[_service][its_endpoint.get()] = _instance; + } its_endpoint->increment_use_count(); } return (its_endpoint); @@ -369,6 +415,7 @@ void endpoint_manager_impl::clear_client_endpoints(service_t _service, instance_ void endpoint_manager_impl::find_or_create_multicast_endpoint( service_t _service, instance_t _instance, + const boost::asio::ip::address &_sender, const boost::asio::ip::address &_address, uint16_t _port) { bool multicast_known(false); { @@ -386,25 +433,27 @@ void endpoint_manager_impl::find_or_create_multicast_endpoint( } } } - if (!multicast_known) { - // Save multicast info to be able to delete the endpoint - // as soon as the instance stops offering its service - std::shared_ptr<endpoint_definition> endpoint_def = - endpoint_definition::get(_address, _port, false, _service, _instance); - multicast_info[_service][_instance] = endpoint_def; - } } const bool is_someip = configuration_->is_someip(_service, _instance); - + bool _is_found(false); // Create multicast endpoint & join multicase group std::shared_ptr<endpoint> its_endpoint = find_or_create_server_endpoint( - _port, false, is_someip, _service, _instance); + _port, false, is_someip, _service, _instance, _is_found, true); + if (!_is_found) { + // Only save multicast info if we created a new endpoint + // to be able to delete the new endpoint + // as soon as the instance stops offering its service + std::shared_ptr<endpoint_definition> endpoint_def = + endpoint_definition::get(_address, _port, false, _service, _instance); + multicast_info[_service][_instance] = endpoint_def; + } + if (its_endpoint) { if (!multicast_known) { std::lock_guard<std::recursive_mutex> its_lock(endpoint_mutex_); - service_instances_[_service][its_endpoint.get()] = _instance; + service_instances_multicast_[_service][_sender] = _instance; } - dynamic_cast<udp_server_endpoint_impl*>(its_endpoint.get())->join( + dynamic_cast<udp_server_endpoint_impl*>(its_endpoint.get())->join_unlocked( _address.to_string()); } else { VSOMEIP_ERROR <<"Could not find/create multicast endpoint!"; @@ -412,7 +461,6 @@ void endpoint_manager_impl::find_or_create_multicast_endpoint( } void endpoint_manager_impl::clear_multicast_endpoints(service_t _service, instance_t _instance) { - std::shared_ptr<endpoint> multicast_endpoint; std::string address; @@ -438,14 +486,14 @@ void endpoint_manager_impl::clear_multicast_endpoints(service_t _service, instan if (0 >= multicast_info[_service].size()) { multicast_info.erase(_service); } - // Clear service_instances_ for multicast endpoint - (void)remove_instance(_service, multicast_endpoint.get()); + (void)remove_instance_multicast(_service, _instance); } } } if (multicast_endpoint) { dynamic_cast<udp_server_endpoint_impl*>( multicast_endpoint.get())->leave(address); + multicast_endpoint->stop(); } } @@ -607,6 +655,20 @@ instance_t endpoint_manager_impl::find_instance( return its_instance; } +instance_t endpoint_manager_impl::find_instance_multicast( + service_t _service, const boost::asio::ip::address &_sender) const { + instance_t its_instance(0xFFFF); + std::lock_guard<std::recursive_mutex> its_lock(endpoint_mutex_); + auto found_service = service_instances_multicast_.find(_service); + if (found_service != service_instances_multicast_.end()) { + auto found_sender = found_service->second.find(_sender); + if (found_sender != found_service->second.end()) { + its_instance = found_sender->second; + } + } + return its_instance; +} + bool endpoint_manager_impl::remove_instance(service_t _service, endpoint* const _endpoint) { std::lock_guard<std::recursive_mutex> its_lock(endpoint_mutex_); @@ -622,6 +684,25 @@ bool endpoint_manager_impl::remove_instance(service_t _service, return (_endpoint->get_use_count() == 0); } +bool endpoint_manager_impl::remove_instance_multicast(service_t _service, + instance_t _instance) { + std::lock_guard<std::recursive_mutex> its_lock(endpoint_mutex_); + auto found_service = service_instances_multicast_.find(_service); + if (found_service != service_instances_multicast_.end()) { + for (auto &its_sender : found_service->second) { + if (its_sender.second == _instance) { + if (found_service->second.erase(its_sender.first)) { + if (!found_service->second.size()) { + service_instances_multicast_.erase(_service); + } + } + return (true); + } + } + } + return (false); +} + void endpoint_manager_impl::on_connect(std::shared_ptr<endpoint> _endpoint) { // Is called when endpoint->connect succeeded! struct service_info { diff --git a/implementation/endpoints/src/server_endpoint_impl.cpp b/implementation/endpoints/src/server_endpoint_impl.cpp index 06b61f4..90aea96 100644 --- a/implementation/endpoints/src/server_endpoint_impl.cpp +++ b/implementation/endpoints/src/server_endpoint_impl.cpp @@ -34,7 +34,9 @@ server_endpoint_impl<Protocol>::server_endpoint_impl( configuration::endpoint_queue_limit_t _queue_limit, const std::shared_ptr<configuration>& _configuration) : endpoint_impl<Protocol>(_endpoint_host, _routing_host, _local, _io, _max_message_size, - _queue_limit, _configuration) { + _queue_limit, _configuration), + sent_timer_(_io) { + is_sending_ = false; } template<typename Protocol> @@ -594,6 +596,14 @@ void server_endpoint_impl<Protocol>::send_cbk( boost::system::error_code const &_error, std::size_t _bytes) { (void)_bytes; + { + std::lock_guard<std::mutex> its_sent_lock(sent_mutex_); + is_sending_ = false; + + boost::system::error_code ec; + sent_timer_.cancel(ec); + } + std::lock_guard<std::mutex> its_lock(mutex_); auto check_if_all_msgs_for_stopped_service_are_sent = [&]() { diff --git a/implementation/endpoints/src/tcp_client_endpoint_impl.cpp b/implementation/endpoints/src/tcp_client_endpoint_impl.cpp index 2a86244..c490f53 100644 --- a/implementation/endpoints/src/tcp_client_endpoint_impl.cpp +++ b/implementation/endpoints/src/tcp_client_endpoint_impl.cpp @@ -915,7 +915,7 @@ void tcp_client_endpoint_impl::wait_until_sent(const boost::system::error_code & its_sent_lock.unlock(); if (!_error) VSOMEIP_WARNING << __func__ - << ": Maximum wait time for send operation exceeded."; + << ": Maximum wait time for send operation exceeded for tce."; std::shared_ptr<endpoint_host> its_ep_host = endpoint_host_.lock(); its_ep_host->on_disconnect(shared_from_this()); diff --git a/implementation/endpoints/src/tcp_server_endpoint_impl.cpp b/implementation/endpoints/src/tcp_server_endpoint_impl.cpp index b7b1d0a..1cd2b5b 100644 --- a/implementation/endpoints/src/tcp_server_endpoint_impl.cpp +++ b/implementation/endpoints/src/tcp_server_endpoint_impl.cpp @@ -408,6 +408,11 @@ void tcp_server_endpoint_impl::connection::send_queued( { std::lock_guard<std::mutex> its_lock(socket_mutex_); + { + std::lock_guard<std::mutex> its_sent_lock(its_server->sent_mutex_); + its_server->is_sending_ = true; + } + boost::asio::async_write(socket_, boost::asio::buffer(*its_buffer), std::bind(&tcp_server_endpoint_impl::connection::write_completion_condition, shared_from_this(), @@ -652,19 +657,15 @@ void tcp_server_endpoint_impl::connection::receive_cbk( << " remote: " << get_address_port_remote() << ". Closing connection due to missing/broken data TCP stream."; } - { - std::lock_guard<std::mutex> its_lock(its_server->connections_mutex_); - stop(); - } - its_server->remove_connection(this); + wait_until_sent(boost::asio::error::operation_aborted); return; } else if (max_message_size_ != MESSAGE_SIZE_UNLIMITED && current_message_size > max_message_size_) { - std::lock_guard<std::mutex> its_lock(socket_mutex_); recv_buffer_size_ = 0; recv_buffer_.resize(recv_buffer_size_initial_, 0x0); recv_buffer_.shrink_to_fit(); if (magic_cookies_enabled_) { + std::lock_guard<std::mutex> its_lock(socket_mutex_); VSOMEIP_ERROR << "Received a TCP message which exceeds " << "maximum message size (" << std::dec << current_message_size @@ -674,19 +675,18 @@ void tcp_server_endpoint_impl::connection::receive_cbk( << get_address_port_local() << " remote: " << get_address_port_remote(); } else { - VSOMEIP_ERROR << "Received a TCP message which exceeds " - << "maximum message size (" - << std::dec << current_message_size - << " > " << std::dec << max_message_size_ - << ") Magic cookies are disabled: " - << "Connection will be closed! local: " - << get_address_port_local() << " remote: " - << get_address_port_remote(); { - std::lock_guard<std::mutex> its_lock(its_server->connections_mutex_); - stop(); + std::lock_guard<std::mutex> its_lock(socket_mutex_); + VSOMEIP_ERROR << "Received a TCP message which exceeds " + << "maximum message size (" + << std::dec << current_message_size + << " > " << std::dec << max_message_size_ + << ") Magic cookies are disabled: " + << "Connection will be closed! local: " + << get_address_port_local() << " remote: " + << get_address_port_remote(); } - its_server->remove_connection(this); + wait_until_sent(boost::asio::error::operation_aborted); return; } } else if (current_message_size > recv_buffer_size_) { @@ -720,11 +720,7 @@ void tcp_server_endpoint_impl::connection::receive_cbk( << " remote: " << get_address_port_remote() << ". Closing connection due to missing/broken data TCP stream."; } - { - std::lock_guard<std::mutex> its_lock(its_server->connections_mutex_); - stop(); - } - its_server->remove_connection(this); + wait_until_sent(boost::asio::error::operation_aborted); return; } } @@ -752,11 +748,7 @@ void tcp_server_endpoint_impl::connection::receive_cbk( << " local: " << get_address_port_local() << " remote: " << get_address_port_remote(); } - { - std::lock_guard<std::mutex> its_lock(its_server->connections_mutex_); - stop(); - } - its_server->remove_connection(this); + wait_until_sent(boost::asio::error::operation_aborted); } } @@ -962,4 +954,27 @@ bool tcp_server_endpoint_impl::tp_segmentation_enabled(service_t _service, return false; } +void tcp_server_endpoint_impl::connection::wait_until_sent(const boost::system::error_code &_error) { + std::shared_ptr<tcp_server_endpoint_impl> its_server(server_.lock()); + std::unique_lock<std::mutex> its_sent_lock(its_server->sent_mutex_); + if (!its_server->is_sending_ || !_error) { + its_sent_lock.unlock(); + if (!_error) + VSOMEIP_WARNING << __func__ + << ": Maximum wait time for send operation exceeded for tse."; + { + std::lock_guard<std::mutex> its_lock(its_server->connections_mutex_); + stop(); + } + its_server->remove_connection(this); + } else { + std::chrono::milliseconds its_timeout(VSOMEIP_MAX_TCP_SENT_WAIT_TIME); + boost::system::error_code ec; + its_server->sent_timer_.expires_from_now(its_timeout, ec); + its_server->sent_timer_.async_wait(std::bind(&tcp_server_endpoint_impl::connection::wait_until_sent, + std::dynamic_pointer_cast<tcp_server_endpoint_impl::connection>(shared_from_this()), + std::placeholders::_1)); + } +} + } // namespace vsomeip_v3 diff --git a/implementation/endpoints/src/tp_message.cpp b/implementation/endpoints/src/tp_message.cpp index f786a4f..57696ca 100644 --- a/implementation/endpoints/src/tp_message.cpp +++ b/implementation/endpoints/src/tp_message.cpp @@ -301,6 +301,11 @@ bool tp_message::check_lengths(const byte_t* const _data, _data[VSOMEIP_LENGTH_POS_MIN + 1], _data[VSOMEIP_LENGTH_POS_MIN + 2], _data[VSOMEIP_LENGTH_POS_MAX]); + const tp_header_t its_tp_header = VSOMEIP_BYTES_TO_LONG( + _data[VSOMEIP_TP_HEADER_POS_MIN], + _data[VSOMEIP_TP_HEADER_POS_MIN + 1], + _data[VSOMEIP_TP_HEADER_POS_MIN + 2], + _data[VSOMEIP_TP_HEADER_POS_MAX]); bool ret(true); if (!tp::tp_flag_is_set(_data[VSOMEIP_MESSAGE_TYPE_POS])) { VSOMEIP_ERROR << __func__ << ": TP flag not set " @@ -344,6 +349,14 @@ bool tp_message::check_lengths(const byte_t* const _data, << " current message size: " << std::dec << current_message_size_ << " maximum message size: " << std::dec << max_message_size_; ret = false; + } else if (tp::get_offset(its_tp_header) + _segment_size > max_message_size_ ) { + VSOMEIP_ERROR << __func__ << ": SomeIP/TP offset field exceeds maximum configured message size: " + << get_message_id(_data, _data_length) + << " TP offset [bytes]: " << std::dec << tp::get_offset(its_tp_header) + << " segment size: " << std::dec << _segment_size + << " current message size: " << std::dec << current_message_size_ + << " maximum message size: " << std::dec << max_message_size_; + ret = false; } return ret; } diff --git a/implementation/endpoints/src/udp_client_endpoint_impl.cpp b/implementation/endpoints/src/udp_client_endpoint_impl.cpp index 6bbd337..ff24173 100644 --- a/implementation/endpoints/src/udp_client_endpoint_impl.cpp +++ b/implementation/endpoints/src/udp_client_endpoint_impl.cpp @@ -93,8 +93,8 @@ void udp_client_endpoint_impl::connect() { // If specified, bind to device std::string its_device(configuration_->get_device()); if (its_device != "") { - if (!setsockopt(socket_->native_handle(), - SOL_SOCKET, SO_BINDTODEVICE, its_device.c_str(), (int)its_device.size())) { + if (setsockopt(socket_->native_handle(), + SOL_SOCKET, SO_BINDTODEVICE, its_device.c_str(), (int)its_device.size()) == -1) { VSOMEIP_WARNING << "UDP Client: Could not bind to device \"" << its_device << "\""; } } @@ -268,7 +268,7 @@ void udp_client_endpoint_impl::receive_cbk( #if 0 std::stringstream msg; msg << "ucei::rcb(" << _error.message() << "): "; - for (std::size_t i = 0; i < _bytes + recv_buffer_size_; ++i) + for (std::size_t i = 0; i < _bytes; ++i) msg << std::hex << std::setw(2) << std::setfill('0') << (int) (*_recv_buffer)[i] << " "; VSOMEIP_INFO << msg.str(); diff --git a/implementation/endpoints/src/udp_server_endpoint_impl.cpp b/implementation/endpoints/src/udp_server_endpoint_impl.cpp index ce1bb2d..add828c 100644 --- a/implementation/endpoints/src/udp_server_endpoint_impl.cpp +++ b/implementation/endpoints/src/udp_server_endpoint_impl.cpp @@ -291,6 +291,12 @@ bool udp_server_endpoint_impl::is_joined( void udp_server_endpoint_impl::join(const std::string &_address) { + std::lock_guard<std::mutex> its_lock(multicast_mutex_); + join_unlocked(_address); +} + +void udp_server_endpoint_impl::join_unlocked(const std::string &_address) { + bool has_received(false); // @@ -317,11 +323,11 @@ void udp_server_endpoint_impl::join(const std::string &_address) { if (!multicast_local_) { if (is_v4) { multicast_local_ = std::unique_ptr<endpoint_type>( - new endpoint_type(boost::asio::ip::address_v4::any(), local_port_)); + new endpoint_type(boost::asio::ip::address_v4::any(), local_port_)); } if (is_v6) { multicast_local_ = std::unique_ptr<endpoint_type>( - new endpoint_type(boost::asio::ip::address_v6::any(), local_port_)); + new endpoint_type(boost::asio::ip::address_v6::any(), local_port_)); } } @@ -398,7 +404,6 @@ void udp_server_endpoint_impl::join(const std::string &_address) { } }; - std::lock_guard<std::mutex> its_lock(multicast_mutex_); if (!is_joined(_address, &has_received)) { join_func(_address); } else if (!has_received) { @@ -556,7 +561,8 @@ void udp_server_endpoint_impl::on_message_received( } else if (current_message_size > VSOMEIP_RETURN_CODE_POS && (_buffer[i + VSOMEIP_PROTOCOL_VERSION_POS] != VSOMEIP_PROTOCOL_VERSION || !utility::is_valid_message_type(tp::tp::tp_flag_unset(_buffer[i + VSOMEIP_MESSAGE_TYPE_POS])) || - !utility::is_valid_return_code(static_cast<return_code_e>(_buffer[i + VSOMEIP_RETURN_CODE_POS])) + !utility::is_valid_return_code(static_cast<return_code_e>(_buffer[i + VSOMEIP_RETURN_CODE_POS])) || + (tp::tp::tp_flag_is_set(_buffer[i + VSOMEIP_MESSAGE_TYPE_POS]) && get_local_port() == configuration_->get_sd_port()) )) { if (_buffer[i + VSOMEIP_PROTOCOL_VERSION_POS] != VSOMEIP_PROTOCOL_VERSION) { VSOMEIP_ERROR << "use: Wrong protocol version: 0x" @@ -585,6 +591,11 @@ void udp_server_endpoint_impl::on_message_received( << std::uint32_t(_buffer[i + VSOMEIP_RETURN_CODE_POS]) << " local: " << get_address_port_local() << " remote: " << its_remote_address << ":" << std::dec << its_remote_port; + } else if (tp::tp::tp_flag_is_set(_buffer[i + VSOMEIP_MESSAGE_TYPE_POS]) + && get_local_port() == configuration_->get_sd_port()) { + VSOMEIP_WARNING << "use: Received a SomeIP/TP message on SD port:" + << " local: " << get_address_port_local() + << " remote: " << its_remote_address << ":" << std::dec << its_remote_port; } return; } @@ -614,6 +625,15 @@ void udp_server_endpoint_impl::on_message_received( } } if (tp::tp::tp_flag_is_set(_buffer[i + VSOMEIP_MESSAGE_TYPE_POS])) { + const method_t its_method = VSOMEIP_BYTES_TO_WORD(_buffer[i + VSOMEIP_METHOD_POS_MIN], + _buffer[i + VSOMEIP_METHOD_POS_MAX]); + if (!tp_segmentation_enabled(its_service, its_method)) { + VSOMEIP_WARNING << "use: Received a SomeIP/TP message for service: 0x" << std::hex << its_service + << " method: 0x" << its_method << " which is not configured for TP:" + << " local: " << get_address_port_local() + << " remote: " << its_remote_address << ":" << std::dec << its_remote_port; + return; + } const auto res = tp_reassembler_->process_tp_message( &_buffer[i], current_message_size, its_remote_address, its_remote_port); |