Title: [282831] trunk/Source
Revision
282831
Author
[email protected]
Date
2021-09-21 11:30:37 -0700 (Tue, 21 Sep 2021)

Log Message

NetworkRTCUDPSocketCocoaConnections should handle NAT64 IP addresses correctly
https://bugs.webkit.org/show_bug.cgi?id=230552
<rdar://83297256>

Reviewed by Alex Christensen.

Source/ThirdParty/libwebrtc:

* Configurations/libwebrtc.iOS.exp:
* Configurations/libwebrtc.iOSsim.exp:
* Configurations/libwebrtc.mac.exp:

Source/WebKit:

When opening a UDP socket, check whether it is a NAT64 IPv4 address.
In that case, we cannot bind it like we used to do with the sockets API.
Instead use "0.0.0.0".
Manually tested.

* NetworkProcess/webrtc/NetworkRTCTCPSocketCocoa.mm:
* NetworkProcess/webrtc/NetworkRTCUDPSocketCocoa.mm:
(WebKit::isNat64IPAddress):
(WebKit::computeHostAddress):
(WebKit::NetworkRTCUDPSocketCocoaConnections::NetworkRTCUDPSocketCocoaConnections):
* NetworkProcess/webrtc/NetworkRTCUtilitiesCocoa.h:
* Platform/spi/Cocoa/NWSPI.h: Renamed from Source/WebKit/Platform/spi/Cocoa/NWParametersSPI.h.
* WebKit.xcodeproj/project.pbxproj:

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/ThirdParty/libwebrtc/ChangeLog (282830 => 282831)


--- trunk/Source/ThirdParty/libwebrtc/ChangeLog	2021-09-21 18:27:59 UTC (rev 282830)
+++ trunk/Source/ThirdParty/libwebrtc/ChangeLog	2021-09-21 18:30:37 UTC (rev 282831)
@@ -1,3 +1,15 @@
+2021-09-21  Youenn Fablet  <[email protected]>
+
+        NetworkRTCUDPSocketCocoaConnections should handle NAT64 IP addresses correctly
+        https://bugs.webkit.org/show_bug.cgi?id=230552
+        <rdar://83297256>
+
+        Reviewed by Alex Christensen.
+
+        * Configurations/libwebrtc.iOS.exp:
+        * Configurations/libwebrtc.iOSsim.exp:
+        * Configurations/libwebrtc.mac.exp:
+
 2021-09-15  Youenn Fablet  <[email protected]>
 
         Migrate to libwebrtc non-racy setRemoteDescription/setLocalDescription variants

Modified: trunk/Source/ThirdParty/libwebrtc/Configurations/libwebrtc.iOS.exp (282830 => 282831)


--- trunk/Source/ThirdParty/libwebrtc/Configurations/libwebrtc.iOS.exp	2021-09-21 18:27:59 UTC (rev 282830)
+++ trunk/Source/ThirdParty/libwebrtc/Configurations/libwebrtc.iOS.exp	2021-09-21 18:30:37 UTC (rev 282831)
@@ -326,3 +326,4 @@
 __ZNK3rtc9IPAddress5IsNilEv
 __ZN3rtc12SSLCertChainD1Ev
 __ZN6webrtc24SctpTransportInformationD1Ev
+__ZNK3rtc9IPAddressneERKS0_

Modified: trunk/Source/ThirdParty/libwebrtc/Configurations/libwebrtc.iOSsim.exp (282830 => 282831)


--- trunk/Source/ThirdParty/libwebrtc/Configurations/libwebrtc.iOSsim.exp	2021-09-21 18:27:59 UTC (rev 282830)
+++ trunk/Source/ThirdParty/libwebrtc/Configurations/libwebrtc.iOSsim.exp	2021-09-21 18:30:37 UTC (rev 282831)
@@ -326,3 +326,4 @@
 __ZNK3rtc9IPAddress5IsNilEv
 __ZN3rtc12SSLCertChainD1Ev
 __ZN6webrtc24SctpTransportInformationD1Ev
+__ZNK3rtc9IPAddressneERKS0_

Modified: trunk/Source/ThirdParty/libwebrtc/Configurations/libwebrtc.mac.exp (282830 => 282831)


--- trunk/Source/ThirdParty/libwebrtc/Configurations/libwebrtc.mac.exp	2021-09-21 18:27:59 UTC (rev 282830)
+++ trunk/Source/ThirdParty/libwebrtc/Configurations/libwebrtc.mac.exp	2021-09-21 18:30:37 UTC (rev 282831)
@@ -326,3 +326,4 @@
 __ZNK3rtc9IPAddress5IsNilEv
 __ZN3rtc12SSLCertChainD1Ev
 __ZN6webrtc24SctpTransportInformationD1Ev
+__ZNK3rtc9IPAddressneERKS0_

Modified: trunk/Source/WebKit/ChangeLog (282830 => 282831)


--- trunk/Source/WebKit/ChangeLog	2021-09-21 18:27:59 UTC (rev 282830)
+++ trunk/Source/WebKit/ChangeLog	2021-09-21 18:30:37 UTC (rev 282831)
@@ -1,3 +1,25 @@
+2021-09-21  Youenn Fablet  <[email protected]>
+
+        NetworkRTCUDPSocketCocoaConnections should handle NAT64 IP addresses correctly
+        https://bugs.webkit.org/show_bug.cgi?id=230552
+        <rdar://83297256>
+
+        Reviewed by Alex Christensen.
+
+        When opening a UDP socket, check whether it is a NAT64 IPv4 address.
+        In that case, we cannot bind it like we used to do with the sockets API.
+        Instead use "0.0.0.0".
+        Manually tested.
+
+        * NetworkProcess/webrtc/NetworkRTCTCPSocketCocoa.mm:
+        * NetworkProcess/webrtc/NetworkRTCUDPSocketCocoa.mm:
+        (WebKit::isNat64IPAddress):
+        (WebKit::computeHostAddress):
+        (WebKit::NetworkRTCUDPSocketCocoaConnections::NetworkRTCUDPSocketCocoaConnections):
+        * NetworkProcess/webrtc/NetworkRTCUtilitiesCocoa.h:
+        * Platform/spi/Cocoa/NWSPI.h: Renamed from Source/WebKit/Platform/spi/Cocoa/NWParametersSPI.h.
+        * WebKit.xcodeproj/project.pbxproj:
+
 2021-09-21  Jer Noble  <[email protected]>
 
         [iOS] Enable MSE in WKWebViews by default on iPad

Modified: trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCTCPSocketCocoa.mm (282830 => 282831)


--- trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCTCPSocketCocoa.mm	2021-09-21 18:27:59 UTC (rev 282830)
+++ trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCTCPSocketCocoa.mm	2021-09-21 18:30:37 UTC (rev 282831)
@@ -31,7 +31,7 @@
 #include "DataReference.h"
 #include "LibWebRTCNetworkMessages.h"
 #include "Logging.h"
-#include "NWParametersSPI.h"
+#include "NWSPI.h"
 #include "NetworkRTCUtilitiesCocoa.h"
 #include <WebCore/STUNMessageParsing.h>
 #include <dispatch/dispatch.h>

Modified: trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCUDPSocketCocoa.mm (282830 => 282831)


--- trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCUDPSocketCocoa.mm	2021-09-21 18:27:59 UTC (rev 282830)
+++ trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCUDPSocketCocoa.mm	2021-09-21 18:30:37 UTC (rev 282831)
@@ -31,9 +31,11 @@
 #include "DataReference.h"
 #include "LibWebRTCNetworkMessages.h"
 #include "Logging.h"
-#include "NWParametersSPI.h"
+#include "NWSPI.h"
 #include <WebCore/STUNMessageParsing.h>
 #include <dispatch/dispatch.h>
+#include <ifaddrs.h>
+#include <net/if.h>
 #include <wtf/BlockPtr.h>
 #include <wtf/SoftLinking.h>
 #include <wtf/ThreadSafeRefCounted.h>
@@ -140,6 +142,41 @@
     return rtc::SocketAddress { nw_endpoint_get_hostname(endpoint.get()), nw_endpoint_get_port(endpoint.get()) };
 }
 
+static inline bool isNat64IPAddress(const rtc::IPAddress& ip)
+{
+    if (ip.family() != AF_INET)
+        return false;
+
+    struct ifaddrs* interfaces;
+    if (auto error = getifaddrs(&interfaces))
+        return true;
+    std::unique_ptr<struct ifaddrs> toBeFreed(interfaces);
+
+    for (auto* interface = interfaces; interface; interface = interface->ifa_next) {
+        if (interface->ifa_addr->sa_family != AF_INET)
+            continue;
+
+        rtc::IPAddress interfaceAddress { reinterpret_cast<sockaddr_in*>(interface->ifa_addr)->sin_addr };
+        if (ip != interfaceAddress)
+            continue;
+
+        return nw_nat64_does_interface_index_support_nat64(if_nametoindex(interface->ifa_name));
+    }
+
+    return false;
+}
+
+static std::string computeHostAddress(const rtc::SocketAddress& address)
+{
+    if (address.ipaddr().IsNil())
+        return address.hostname();
+
+    if (!isNat64IPAddress(address.ipaddr()))
+        return address.ipaddr().ToString();
+
+    return "0.0.0.0";
+}
+
 NetworkRTCUDPSocketCocoaConnections::NetworkRTCUDPSocketCocoaConnections(WebCore::LibWebRTCSocketIdentifier identifier, NetworkRTCProvider& rtcProvider, const rtc::SocketAddress& address, Ref<IPC::Connection>&& connection, String&& attributedBundleIdentifier, bool isFirstParty, bool isRelayDisabled, const WebCore::RegistrableDomain& domain)
     : m_identifier(identifier)
     , m_connection(WTFMove(connection))
@@ -152,9 +189,7 @@
 {
     auto parameters = adoptNS(nw_parameters_create_secure_udp(NW_PARAMETERS_DISABLE_PROTOCOL, NW_PARAMETERS_DEFAULT_CONFIGURATION));
     {
-        auto hostAddress = address.ipaddr().ToString();
-        if (address.ipaddr().IsNil())
-            hostAddress = address.hostname();
+        auto hostAddress = computeHostAddress(address);
         auto localEndpoint = adoptNS(nw_endpoint_create_host_with_numeric_port(hostAddress.c_str(), 0));
         m_address = { nw_endpoint_get_hostname(localEndpoint.get()), nw_endpoint_get_port(localEndpoint.get()) };
         nw_parameters_set_local_endpoint(parameters.get(), localEndpoint.get());

Modified: trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCUtilitiesCocoa.h (282830 => 282831)


--- trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCUtilitiesCocoa.h	2021-09-21 18:27:59 UTC (rev 282830)
+++ trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCUtilitiesCocoa.h	2021-09-21 18:30:37 UTC (rev 282831)
@@ -27,7 +27,7 @@
 
 #if USE(LIBWEBRTC)
 
-#include "NWParametersSPI.h"
+#include "NWSPI.h"
 #include <optional>
 #include <wtf/Forward.h>
 

Deleted: trunk/Source/WebKit/Platform/spi/Cocoa/NWParametersSPI.h (282830 => 282831)


--- trunk/Source/WebKit/Platform/spi/Cocoa/NWParametersSPI.h	2021-09-21 18:27:59 UTC (rev 282830)
+++ trunk/Source/WebKit/Platform/spi/Cocoa/NWParametersSPI.h	2021-09-21 18:30:37 UTC (rev 282831)
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2021 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import <Network/Network.h>
-
-#if USE(APPLE_INTERNAL_SDK)
-
-#import <nw/private.h>
-
-#else
-
-WTF_EXTERN_C_BEGIN
-
-void nw_parameters_set_account_id(nw_parameters_t, const char * account_id);
-void nw_parameters_set_source_application(nw_parameters_t, audit_token_t);
-void nw_parameters_set_source_application_by_bundle_id(nw_parameters_t, const char*);
-void nw_parameters_set_attributed_bundle_identifier(nw_parameters_t, const char*);
-nw_endpoint_t nw_endpoint_create_host_with_numeric_port(const char* hostname, uint16_t port_host_order);
-
-#if HAVE(NWPARAMETERS_TRACKER_API)
-void nw_parameters_set_is_third_party_web_content(nw_parameters_t, bool is_third_party_web_content);
-void nw_parameters_set_is_known_tracker(nw_parameters_t, bool is_known_tracker);
-void nw_parameters_allow_sharing_port_with_listener(nw_parameters_t, nw_listener_t);
-#endif // HAVE(NWPARAMETERS_TRACKER_API)
-
-WTF_EXTERN_C_END
-
-#endif // USE(APPLE_INTERNAL_SDK)

Copied: trunk/Source/WebKit/Platform/spi/Cocoa/NWSPI.h (from rev 282830, trunk/Source/WebKit/Platform/spi/Cocoa/NWParametersSPI.h) (0 => 282831)


--- trunk/Source/WebKit/Platform/spi/Cocoa/NWSPI.h	                        (rev 0)
+++ trunk/Source/WebKit/Platform/spi/Cocoa/NWSPI.h	2021-09-21 18:30:37 UTC (rev 282831)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, I NDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Network/Network.h>
+
+#if USE(APPLE_INTERNAL_SDK)
+
+#import <nw/private.h>
+
+#else
+
+WTF_EXTERN_C_BEGIN
+
+void nw_parameters_set_account_id(nw_parameters_t, const char * account_id);
+void nw_parameters_set_source_application(nw_parameters_t, audit_token_t);
+void nw_parameters_set_source_application_by_bundle_id(nw_parameters_t, const char*);
+void nw_parameters_set_attributed_bundle_identifier(nw_parameters_t, const char*);
+nw_endpoint_t nw_endpoint_create_host_with_numeric_port(const char* hostname, uint16_t port_host_order);
+bool nw_nat64_does_interface_index_support_nat64(uint32_t ifindex);
+
+#if HAVE(NWPARAMETERS_TRACKER_API)
+void nw_parameters_set_is_third_party_web_content(nw_parameters_t, bool is_third_party_web_content);
+void nw_parameters_set_is_known_tracker(nw_parameters_t, bool is_known_tracker);
+void nw_parameters_allow_sharing_port_with_listener(nw_parameters_t, nw_listener_t);
+#endif // HAVE(NWPARAMETERS_TRACKER_API)
+
+WTF_EXTERN_C_END
+
+#endif // USE(APPLE_INTERNAL_SDK)

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (282830 => 282831)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2021-09-21 18:27:59 UTC (rev 282830)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2021-09-21 18:30:37 UTC (rev 282831)
@@ -948,7 +948,7 @@
 		41D129DA1F3D101800D15E47 /* WebCacheStorageProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 41D129D91F3D101400D15E47 /* WebCacheStorageProvider.h */; };
 		41DC45961E3D6E2200B11F51 /* NetworkRTCProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 41DC45941E3D6E1E00B11F51 /* NetworkRTCProvider.h */; };
 		41DC459C1E3DBB2800B11F51 /* LibWebRTCSocketClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 41DC459A1E3DBB2400B11F51 /* LibWebRTCSocketClient.h */; };
-		41DD72AB2682167300A90C71 /* NWParametersSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 41DD72AA2682167300A90C71 /* NWParametersSPI.h */; };
+		41DD72AB2682167300A90C71 /* NWSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 41DD72AA2682167300A90C71 /* NWSPI.h */; };
 		41DE7C6C22278F1E00532B65 /* ServiceWorkerFetchTask.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41518536222704F6005430C6 /* ServiceWorkerFetchTask.cpp */; };
 		41E0A7CB23B645CD00561060 /* WebSocketChannel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 417915AC2256BB7400D6F97E /* WebSocketChannel.cpp */; };
 		41E242E026E0C908009A8C64 /* NetworkRTCUtilitiesCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 41E242DF26E0C904009A8C64 /* NetworkRTCUtilitiesCocoa.mm */; };
@@ -3883,7 +3883,7 @@
 		41DC45A01E3DC53C00B11F51 /* WebRTCResolver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebRTCResolver.cpp; path = Network/webrtc/WebRTCResolver.cpp; sourceTree = "<group>"; };
 		41DD72A6267B8C3000A90C71 /* NetworkRTCUDPSocketCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = NetworkRTCUDPSocketCocoa.mm; sourceTree = "<group>"; };
 		41DD72A7267B8C3100A90C71 /* NetworkRTCUDPSocketCocoa.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NetworkRTCUDPSocketCocoa.h; sourceTree = "<group>"; };
-		41DD72AA2682167300A90C71 /* NWParametersSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NWParametersSPI.h; sourceTree = "<group>"; };
+		41DD72AA2682167300A90C71 /* NWSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NWSPI.h; sourceTree = "<group>"; };
 		41E0A7C623B6397800561060 /* LibWebRTCCodecsProxy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LibWebRTCCodecsProxy.h; sourceTree = "<group>"; };
 		41E0A7C723B6397900561060 /* LibWebRTCCodecsProxy.messages.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = LibWebRTCCodecsProxy.messages.in; sourceTree = "<group>"; };
 		41E0A7C823B6397900561060 /* LibWebRTCCodecsProxy.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = LibWebRTCCodecsProxy.mm; sourceTree = "<group>"; };
@@ -8058,7 +8058,7 @@
 				574217912400E098002B303D /* LocalAuthenticationSPI.h */,
 				57B826402304EB3E00B72EB0 /* NearFieldSPI.h */,
 				3754D5441B3A29FD003A4C7F /* NSInvocationSPI.h */,
-				41DD72AA2682167300A90C71 /* NWParametersSPI.h */,
+				41DD72AA2682167300A90C71 /* NWSPI.h */,
 				F4EB4AFC269CD23600D297AE /* OSStateSPI.h */,
 				5CB6AE432609799C00B6ED5A /* ReasonSPI.h */,
 				0E97D74C200E8FF300BF6643 /* SafeBrowsingSPI.h */,
@@ -12371,7 +12371,7 @@
 				1C20936022318CB000026A39 /* NSAttributedString.h in Headers */,
 				1C2184022233872800BAC700 /* NSAttributedStringPrivate.h in Headers */,
 				3754D5451B3A29FD003A4C7F /* NSInvocationSPI.h in Headers */,
-				41DD72AB2682167300A90C71 /* NWParametersSPI.h in Headers */,
+				41DD72AB2682167300A90C71 /* NWSPI.h in Headers */,
 				BC8ACA1316670D89004C1941 /* ObjCObjectGraph.h in Headers */,
 				93085DCA26E29775000EC6A7 /* OriginStorageManager.h in Headers */,
 				F4EB4AFD269CD7F300D297AE /* OSStateSPI.h in Headers */,
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to