From 938de6255507ecb44b769cc60209d20c52f6a8d6 Mon Sep 17 00:00:00 2001 From: Erik Boasson Date: Wed, 20 Mar 2024 12:48:47 +0100 Subject: [PATCH] Add option for disabling use of IP_PKTINFO There is a small performance penalty associated with the use of the IP_PKTINFO socket option. This adds an option Internal/ExtendedPacketInfo to disable it because there may be cases where preventing the performance loss is more important than preventing some discovery mishaps. Signed-off-by: Erik Boasson --- docs/manual/config/config_file_reference.rst | 18 +++++++++++++++--- docs/manual/options.md | 14 +++++++++++--- etc/cyclonedds.rnc | 10 ++++++++-- etc/cyclonedds.xsd | 12 ++++++++++-- src/core/ddsi/defconfig.c | 5 +++-- src/core/ddsi/include/dds/ddsi/ddsi_config.h | 1 + src/core/ddsi/src/ddsi__cfgelems.h | 8 ++++++++ src/core/ddsi/src/ddsi_udp.c | 3 ++- 8 files changed, 58 insertions(+), 13 deletions(-) diff --git a/docs/manual/config/config_file_reference.rst b/docs/manual/config/config_file_reference.rst index d667de00c4..8f9b08018c 100644 --- a/docs/manual/config/config_file_reference.rst +++ b/docs/manual/config/config_file_reference.rst @@ -818,7 +818,7 @@ The default value is: ``default`` //CycloneDDS/Domain/Internal ============================ -Children: :ref:`AccelerateRexmitBlockSize`, :ref:`AckDelay`, :ref:`AutoReschedNackDelay`, :ref:`BuiltinEndpointSet`, :ref:`BurstSize`, :ref:`ControlTopic`, :ref:`DefragReliableMaxSamples`, :ref:`DefragUnreliableMaxSamples`, :ref:`DeliveryQueueMaxSamples`, :ref:`EnableExpensiveChecks`, :ref:`GenerateKeyhash`, :ref:`HeartbeatInterval`, :ref:`LateAckMode`, :ref:`LivelinessMonitoring`, :ref:`MaxParticipants`, :ref:`MaxQueuedRexmitBytes`, :ref:`MaxQueuedRexmitMessages`, :ref:`MaxSampleSize`, :ref:`MeasureHbToAckLatency`, :ref:`MonitorPort`, :ref:`MultipleReceiveThreads`, :ref:`NackDelay`, :ref:`PreEmptiveAckDelay`, :ref:`PrimaryReorderMaxSamples`, :ref:`PrioritizeRetransmit`, :ref:`RediscoveryBlacklistDuration`, :ref:`RetransmitMerging`, :ref:`RetransmitMergingPeriod`, :ref:`RetryOnRejectBestEffort`, :ref:`SPDPResponseMaxDelay`, :ref:`SecondaryReorderMaxSamples`, :ref:`SocketReceiveBufferSize`, :ref:`SocketSendBufferSize`, :ref:`SquashParticipants`, :ref:`SynchronousDeliveryLatencyBound`, :ref:`SynchronousDeliveryPriorityThreshold`, :ref:`Test`, :ref:`UnicastResponseToSPDPMessages`, :ref:`UseMulticastIfMreqn`, :ref:`Watermarks`, :ref:`WriterLingerDuration` +Children: :ref:`AccelerateRexmitBlockSize`, :ref:`AckDelay`, :ref:`AutoReschedNackDelay`, :ref:`BuiltinEndpointSet`, :ref:`BurstSize`, :ref:`ControlTopic`, :ref:`DefragReliableMaxSamples`, :ref:`DefragUnreliableMaxSamples`, :ref:`DeliveryQueueMaxSamples`, :ref:`EnableExpensiveChecks`, :ref:`ExtendedPacketInfo`, :ref:`GenerateKeyhash`, :ref:`HeartbeatInterval`, :ref:`LateAckMode`, :ref:`LivelinessMonitoring`, :ref:`MaxParticipants`, :ref:`MaxQueuedRexmitBytes`, :ref:`MaxQueuedRexmitMessages`, :ref:`MaxSampleSize`, :ref:`MeasureHbToAckLatency`, :ref:`MonitorPort`, :ref:`MultipleReceiveThreads`, :ref:`NackDelay`, :ref:`PreEmptiveAckDelay`, :ref:`PrimaryReorderMaxSamples`, :ref:`PrioritizeRetransmit`, :ref:`RediscoveryBlacklistDuration`, :ref:`RetransmitMerging`, :ref:`RetransmitMergingPeriod`, :ref:`RetryOnRejectBestEffort`, :ref:`SPDPResponseMaxDelay`, :ref:`SecondaryReorderMaxSamples`, :ref:`SocketReceiveBufferSize`, :ref:`SocketSendBufferSize`, :ref:`SquashParticipants`, :ref:`SynchronousDeliveryLatencyBound`, :ref:`SynchronousDeliveryPriorityThreshold`, :ref:`Test`, :ref:`UnicastResponseToSPDPMessages`, :ref:`UseMulticastIfMreqn`, :ref:`Watermarks`, :ref:`WriterLingerDuration` The Internal elements deal with a variety of settings that are evolving and that are not necessarily fully supported. For the majority of the Internal settings the functionality is supported, but the right to change the way the options control the functionality is reserved. This includes renaming or moving options. @@ -999,6 +999,18 @@ In addition, there is the keyword all that enables all checks. The default value is: ```` +.. _`//CycloneDDS/Domain/Internal/ExtendedPacketInfo`: + +//CycloneDDS/Domain/Internal/ExtendedPacketInfo +----------------------------------------------- + +Boolean + +Whether to enable the IP\_PKTINFO on UDP sockets to get hold of the packet destination address and interface on which it was received. This allows for better filtering on discovery packets, but comes at a small performance penalty. + +The default value is: ``true`` + + .. _`//CycloneDDS/Domain/Internal/GenerateKeyhash`: //CycloneDDS/Domain/Internal/GenerateKeyhash @@ -2687,9 +2699,9 @@ The categorisation of tracing output is incomplete and hence most of the verbosi The default value is: ``none`` .. - generated from ddsi_config.h[a0a5954a97ea0cf110e0ee1b38507b762abecbab] + generated from ddsi_config.h[9f834d377bdea61bea6507feed2fc4a8924dc02e] generated from ddsi__cfgunits.h[bd22f0c0ed210501d0ecd3b07c992eca549ef5aa] - generated from ddsi__cfgelems.h[114a2466af9993b70e96466a47fdbf8a125f1ff9] + generated from ddsi__cfgelems.h[f10059d775cf2e4961a2e9520bb1a4da6a124778] generated from ddsi_config.c[0a59324bd889637ea7d04765da9b76bbe74997c1] generated from _confgen.h[e32eabfc35e9f3a7dcb63b19ed148c0d17c6e5fc] generated from _confgen.c[237308acd53897a34e8c643e16e05a61d73ffd65] diff --git a/docs/manual/options.md b/docs/manual/options.md index 291074ca8a..1c0571abd7 100644 --- a/docs/manual/options.md +++ b/docs/manual/options.md @@ -552,7 +552,7 @@ The default value is: `default` ### //CycloneDDS/Domain/Internal -Children: [AccelerateRexmitBlockSize](#cycloneddsdomaininternalacceleraterexmitblocksize), [AckDelay](#cycloneddsdomaininternalackdelay), [AutoReschedNackDelay](#cycloneddsdomaininternalautoreschednackdelay), [BuiltinEndpointSet](#cycloneddsdomaininternalbuiltinendpointset), [BurstSize](#cycloneddsdomaininternalburstsize), [ControlTopic](#cycloneddsdomaininternalcontroltopic), [DefragReliableMaxSamples](#cycloneddsdomaininternaldefragreliablemaxsamples), [DefragUnreliableMaxSamples](#cycloneddsdomaininternaldefragunreliablemaxsamples), [DeliveryQueueMaxSamples](#cycloneddsdomaininternaldeliveryqueuemaxsamples), [EnableExpensiveChecks](#cycloneddsdomaininternalenableexpensivechecks), [GenerateKeyhash](#cycloneddsdomaininternalgeneratekeyhash), [HeartbeatInterval](#cycloneddsdomaininternalheartbeatinterval), [LateAckMode](#cycloneddsdomaininternallateackmode), [LivelinessMonitoring](#cycloneddsdomaininternallivelinessmonitoring), [MaxParticipants](#cycloneddsdomaininternalmaxparticipants), [MaxQueuedRexmitBytes](#cycloneddsdomaininternalmaxqueuedrexmitbytes), [MaxQueuedRexmitMessages](#cycloneddsdomaininternalmaxqueuedrexmitmessages), [MaxSampleSize](#cycloneddsdomaininternalmaxsamplesize), [MeasureHbToAckLatency](#cycloneddsdomaininternalmeasurehbtoacklatency), [MonitorPort](#cycloneddsdomaininternalmonitorport), [MultipleReceiveThreads](#cycloneddsdomaininternalmultiplereceivethreads), [NackDelay](#cycloneddsdomaininternalnackdelay), [PreEmptiveAckDelay](#cycloneddsdomaininternalpreemptiveackdelay), [PrimaryReorderMaxSamples](#cycloneddsdomaininternalprimaryreordermaxsamples), [PrioritizeRetransmit](#cycloneddsdomaininternalprioritizeretransmit), [RediscoveryBlacklistDuration](#cycloneddsdomaininternalrediscoveryblacklistduration), [RetransmitMerging](#cycloneddsdomaininternalretransmitmerging), [RetransmitMergingPeriod](#cycloneddsdomaininternalretransmitmergingperiod), [RetryOnRejectBestEffort](#cycloneddsdomaininternalretryonrejectbesteffort), [SPDPResponseMaxDelay](#cycloneddsdomaininternalspdpresponsemaxdelay), [SecondaryReorderMaxSamples](#cycloneddsdomaininternalsecondaryreordermaxsamples), [SocketReceiveBufferSize](#cycloneddsdomaininternalsocketreceivebuffersize), [SocketSendBufferSize](#cycloneddsdomaininternalsocketsendbuffersize), [SquashParticipants](#cycloneddsdomaininternalsquashparticipants), [SynchronousDeliveryLatencyBound](#cycloneddsdomaininternalsynchronousdeliverylatencybound), [SynchronousDeliveryPriorityThreshold](#cycloneddsdomaininternalsynchronousdeliveryprioritythreshold), [Test](#cycloneddsdomaininternaltest), [UnicastResponseToSPDPMessages](#cycloneddsdomaininternalunicastresponsetospdpmessages), [UseMulticastIfMreqn](#cycloneddsdomaininternalusemulticastifmreqn), [Watermarks](#cycloneddsdomaininternalwatermarks), [WriterLingerDuration](#cycloneddsdomaininternalwriterlingerduration) +Children: [AccelerateRexmitBlockSize](#cycloneddsdomaininternalacceleraterexmitblocksize), [AckDelay](#cycloneddsdomaininternalackdelay), [AutoReschedNackDelay](#cycloneddsdomaininternalautoreschednackdelay), [BuiltinEndpointSet](#cycloneddsdomaininternalbuiltinendpointset), [BurstSize](#cycloneddsdomaininternalburstsize), [ControlTopic](#cycloneddsdomaininternalcontroltopic), [DefragReliableMaxSamples](#cycloneddsdomaininternaldefragreliablemaxsamples), [DefragUnreliableMaxSamples](#cycloneddsdomaininternaldefragunreliablemaxsamples), [DeliveryQueueMaxSamples](#cycloneddsdomaininternaldeliveryqueuemaxsamples), [EnableExpensiveChecks](#cycloneddsdomaininternalenableexpensivechecks), [ExtendedPacketInfo](#cycloneddsdomaininternalextendedpacketinfo), [GenerateKeyhash](#cycloneddsdomaininternalgeneratekeyhash), [HeartbeatInterval](#cycloneddsdomaininternalheartbeatinterval), [LateAckMode](#cycloneddsdomaininternallateackmode), [LivelinessMonitoring](#cycloneddsdomaininternallivelinessmonitoring), [MaxParticipants](#cycloneddsdomaininternalmaxparticipants), [MaxQueuedRexmitBytes](#cycloneddsdomaininternalmaxqueuedrexmitbytes), [MaxQueuedRexmitMessages](#cycloneddsdomaininternalmaxqueuedrexmitmessages), [MaxSampleSize](#cycloneddsdomaininternalmaxsamplesize), [MeasureHbToAckLatency](#cycloneddsdomaininternalmeasurehbtoacklatency), [MonitorPort](#cycloneddsdomaininternalmonitorport), [MultipleReceiveThreads](#cycloneddsdomaininternalmultiplereceivethreads), [NackDelay](#cycloneddsdomaininternalnackdelay), [PreEmptiveAckDelay](#cycloneddsdomaininternalpreemptiveackdelay), [PrimaryReorderMaxSamples](#cycloneddsdomaininternalprimaryreordermaxsamples), [PrioritizeRetransmit](#cycloneddsdomaininternalprioritizeretransmit), [RediscoveryBlacklistDuration](#cycloneddsdomaininternalrediscoveryblacklistduration), [RetransmitMerging](#cycloneddsdomaininternalretransmitmerging), [RetransmitMergingPeriod](#cycloneddsdomaininternalretransmitmergingperiod), [RetryOnRejectBestEffort](#cycloneddsdomaininternalretryonrejectbesteffort), [SPDPResponseMaxDelay](#cycloneddsdomaininternalspdpresponsemaxdelay), [SecondaryReorderMaxSamples](#cycloneddsdomaininternalsecondaryreordermaxsamples), [SocketReceiveBufferSize](#cycloneddsdomaininternalsocketreceivebuffersize), [SocketSendBufferSize](#cycloneddsdomaininternalsocketsendbuffersize), [SquashParticipants](#cycloneddsdomaininternalsquashparticipants), [SynchronousDeliveryLatencyBound](#cycloneddsdomaininternalsynchronousdeliverylatencybound), [SynchronousDeliveryPriorityThreshold](#cycloneddsdomaininternalsynchronousdeliveryprioritythreshold), [Test](#cycloneddsdomaininternaltest), [UnicastResponseToSPDPMessages](#cycloneddsdomaininternalunicastresponsetospdpmessages), [UseMulticastIfMreqn](#cycloneddsdomaininternalusemulticastifmreqn), [Watermarks](#cycloneddsdomaininternalwatermarks), [WriterLingerDuration](#cycloneddsdomaininternalwriterlingerduration) The Internal elements deal with a variety of settings that are evolving and that are not necessarily fully supported. For the majority of the Internal settings the functionality is supported, but the right to change the way the options control the functionality is reserved. This includes renaming or moving options. @@ -680,6 +680,14 @@ In addition, there is the keyword all that enables all checks. The default value is: `` +#### //CycloneDDS/Domain/Internal/ExtendedPacketInfo +Boolean + +Whether to enable the IP\_PKTINFO on UDP sockets to get hold of the packet destination address and interface on which it was received. This allows for better filtering on discovery packets, but comes at a small performance penalty. + +The default value is: `true` + + #### //CycloneDDS/Domain/Internal/GenerateKeyhash Boolean @@ -1881,9 +1889,9 @@ While none prevents any message from being written to a DDSI2 log file. The categorisation of tracing output is incomplete and hence most of the verbosity levels and categories are not of much use in the current release. This is an ongoing process and here we describe the target situation rather than the current situation. Currently, the most useful verbosity levels are config, fine and finest. The default value is: `none` - + - + diff --git a/etc/cyclonedds.rnc b/etc/cyclonedds.rnc index 66675b8991..e8cc343f05 100644 --- a/etc/cyclonedds.rnc +++ b/etc/cyclonedds.rnc @@ -483,6 +483,12 @@ CycloneDDS configuration""" ] ] xsd:token { pattern = "((whc|rhc|xevent|all)(,(whc|rhc|xevent|all))*)|" } }? & [ a:documentation [ xml:lang="en" """ +

Whether to enable the IP_PKTINFO on UDP sockets to get hold of the packet destination address and interface on which it was received. This allows for better filtering on discovery packets, but comes at a small performance penalty.

+

The default value is: true

""" ] ] + element ExtendedPacketInfo { + xsd:boolean + }? + & [ a:documentation [ xml:lang="en" """

When true, include keyhashes in outgoing data for topics with keys.

The default value is: false

""" ] ] element GenerateKeyhash { @@ -1304,9 +1310,9 @@ MIIEpAIBAAKCAQEA3HIh...AOBaaqSV37XBUJg==
duration_inf = xsd:token { pattern = "inf|0|(\d+(\.\d*)?([Ee][\-+]?\d+)?|\.\d+([Ee][\-+]?\d+)?) *([num]?s|min|hr|day)" } memsize = xsd:token { pattern = "0|(\d+(\.\d*)?([Ee][\-+]?\d+)?|\.\d+([Ee][\-+]?\d+)?) *([kMG]i?)?B" } } -# generated from ddsi_config.h[a0a5954a97ea0cf110e0ee1b38507b762abecbab] +# generated from ddsi_config.h[9f834d377bdea61bea6507feed2fc4a8924dc02e] # generated from ddsi__cfgunits.h[bd22f0c0ed210501d0ecd3b07c992eca549ef5aa] -# generated from ddsi__cfgelems.h[114a2466af9993b70e96466a47fdbf8a125f1ff9] +# generated from ddsi__cfgelems.h[f10059d775cf2e4961a2e9520bb1a4da6a124778] # generated from ddsi_config.c[0a59324bd889637ea7d04765da9b76bbe74997c1] # generated from _confgen.h[e32eabfc35e9f3a7dcb63b19ed148c0d17c6e5fc] # generated from _confgen.c[237308acd53897a34e8c643e16e05a61d73ffd65] diff --git a/etc/cyclonedds.xsd b/etc/cyclonedds.xsd index b4f80cb3be..893b41d8a7 100644 --- a/etc/cyclonedds.xsd +++ b/etc/cyclonedds.xsd @@ -623,6 +623,7 @@ CycloneDDS configuration + @@ -779,6 +780,13 @@ CycloneDDS configuration + + + +<p>Whether to enable the IP_PKTINFO on UDP sockets to get hold of the packet destination address and interface on which it was received. This allows for better filtering on discovery packets, but comes at a small performance penalty.</p> +<p>The default value is: <code>true</code></p> + + @@ -1962,9 +1970,9 @@ MIIEpAIBAAKCAQEA3HIh...AOBaaqSV37XBUJg==<br> - + - + diff --git a/src/core/ddsi/defconfig.c b/src/core/ddsi/defconfig.c index 07a0af6fdc..b1e7c1e663 100644 --- a/src/core/ddsi/defconfig.c +++ b/src/core/ddsi/defconfig.c @@ -84,6 +84,7 @@ void ddsi_config_init_default (struct ddsi_config *cfg) cfg->max_rexmit_burst_size = UINT32_C (1048576); cfg->init_transmit_extra_pct = UINT32_C (4294967295); cfg->max_frags_in_rexmit_of_sample = UINT32_C (1); + cfg->extended_packet_info = INT32_C (1); cfg->tcp_nodelay = INT32_C (1); cfg->tcp_port = INT32_C (-1); cfg->tcp_read_timeout = INT64_C (2000000000); @@ -99,9 +100,9 @@ void ddsi_config_init_default (struct ddsi_config *cfg) cfg->ssl_min_version.minor = 3; #endif /* DDS_HAS_SSL */ } -/* generated from ddsi_config.h[a0a5954a97ea0cf110e0ee1b38507b762abecbab] */ +/* generated from ddsi_config.h[9f834d377bdea61bea6507feed2fc4a8924dc02e] */ /* generated from ddsi__cfgunits.h[bd22f0c0ed210501d0ecd3b07c992eca549ef5aa] */ -/* generated from ddsi__cfgelems.h[114a2466af9993b70e96466a47fdbf8a125f1ff9] */ +/* generated from ddsi__cfgelems.h[f10059d775cf2e4961a2e9520bb1a4da6a124778] */ /* generated from ddsi_config.c[0a59324bd889637ea7d04765da9b76bbe74997c1] */ /* generated from _confgen.h[e32eabfc35e9f3a7dcb63b19ed148c0d17c6e5fc] */ /* generated from _confgen.c[237308acd53897a34e8c643e16e05a61d73ffd65] */ diff --git a/src/core/ddsi/include/dds/ddsi/ddsi_config.h b/src/core/ddsi/include/dds/ddsi/ddsi_config.h index 974baa3928..334032089c 100644 --- a/src/core/ddsi/include/dds/ddsi/ddsi_config.h +++ b/src/core/ddsi/include/dds/ddsi/ddsi_config.h @@ -401,6 +401,7 @@ struct ddsi_config int retry_on_reject_besteffort; int generate_keyhash; uint32_t max_sample_size; + bool extended_packet_info; /* compability options */ enum ddsi_standards_conformance standards_conformance; diff --git a/src/core/ddsi/src/ddsi__cfgelems.h b/src/core/ddsi/src/ddsi__cfgelems.h index 39a5accd5d..8204f5541c 100644 --- a/src/core/ddsi/src/ddsi__cfgelems.h +++ b/src/core/ddsi/src/ddsi__cfgelems.h @@ -1582,6 +1582,14 @@ static struct cfgelem internal_cfgelems[] = { NOMEMBER, NOFUNCTIONS, DESCRIPTION("

Setting for controlling the size of transmitting bursts.

")), + BOOL("ExtendedPacketInfo", NULL, 1, "true", + MEMBER(extended_packet_info), + FUNCTIONS(0, uf_boolean, 0, pf_boolean), + DESCRIPTION( + "

Whether to enable the IP_PKTINFO on UDP sockets to get hold of the packet " + "destination address and interface on which it was received. This allows " + "for better filtering on discovery packets, but comes at a small performance " + "penalty.

")), LIST("EnableExpensiveChecks", NULL, 1, "", MEMBER(enabled_xchecks), FUNCTIONS(0, uf_xcheck, 0, pf_xcheck), diff --git a/src/core/ddsi/src/ddsi_udp.c b/src/core/ddsi/src/ddsi_udp.c index fc6df0ce63..236cf08d2c 100644 --- a/src/core/ddsi/src/ddsi_udp.c +++ b/src/core/ddsi/src/ddsi_udp.c @@ -645,7 +645,8 @@ static dds_return_t ddsi_udp_create_conn (struct ddsi_tran_conn **conn_out, stru // on which the packet was received. If it doesn't work, we don't mind: it simply // means there is slightly less information available for making sense of addresses // or deciding whether multicast SPDP packet really is to be processed - (void) setsockopt_pktinfo (gv, sock, ipv6); + if (gv->config.extended_packet_info) + (void) setsockopt_pktinfo (gv, sock, ipv6); if ((rc = ddsrt_bind (sock, &socketname.a, ddsrt_sockaddr_get_size (&socketname.a))) != DDS_RETCODE_OK) {