From 1ea9cb1f6b41cd8728a2f050550c1db529985696 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Wed, 3 Aug 2022 10:15:33 -0400
Subject: [PATCH] ios: ignore point-to-point network

On a lot of iOS devices, a lot of weird IPv6 candidates seems to
be added from generally unused interfaces (tun0->2, ipsec_0-9, pdp_ip1->4)
Those interfaces seems to be up and running but instead a classic
link-local address (fe80:: like on macOS), some un-assigned ipv6
seems to be generated (2605:8d80:: or  2001:56f::) and seems un-documented.

Except ignoring point to point network for now, I don't see any good
solution. And this problem seems to only appears on iOS (macOS got tun0->2
but with a correct link local address).

Change-Id: I7724150ea2fdd93fbccac83cfa0c0c691452e820
---
 .../0003-disable-ios-pointtopoint.patch       | 55 +++++++++++++++++++
 contrib/src/pjproject/rules.mak               |  3 +
 2 files changed, 58 insertions(+)
 create mode 100644 contrib/src/pjproject/0003-disable-ios-pointtopoint.patch

diff --git a/contrib/src/pjproject/0003-disable-ios-pointtopoint.patch b/contrib/src/pjproject/0003-disable-ios-pointtopoint.patch
new file mode 100644
index 0000000000..30aa08858e
--- /dev/null
+++ b/contrib/src/pjproject/0003-disable-ios-pointtopoint.patch
@@ -0,0 +1,55 @@
+ pjlib/src/pj/ip_helper_generic.c | 23 ++++++++++++++++++++++-
+ 1 file changed, 22 insertions(+), 1 deletion(-)
+
+diff --git a/pjlib/src/pj/ip_helper_generic.c b/pjlib/src/pj/ip_helper_generic.c
+index ab441a504..c818468b3 100644
+--- a/pjlib/src/pj/ip_helper_generic.c
++++ b/pjlib/src/pj/ip_helper_generic.c
+@@ -102,6 +102,13 @@ static pj_status_t if_enum_by_af(int af,
+ 	    continue; /* Skip when interface is not running */
+ 	}
+ 
++#if defined(__APPLE__)
++	if (it->ifa_flags & IFF_POINTOPOINT) {
++	    TRACE_((THIS_FILE, "  point to point interface"));
++	    continue; /* Skip point to point interface */
++	}
++#endif
++
+ #if PJ_IP_HELPER_IGNORE_LOOPBACK_IF
+ 	if (it->ifa_flags & IFF_LOOPBACK) {
+ 	    TRACE_((THIS_FILE, "  loopback interface"));
+@@ -231,6 +238,13 @@ static pj_status_t if_enum_by_af(int af,
+ 	    continue; /* Skip when interface is not running */
+ 	}
+ 
++#if defined(__APPLE__)
++	if (iff.ifr_flags & IFF_POINTOPOINT) {
++	    TRACE_((THIS_FILE, "  point to point interface"));
++	    continue; /* Skip point to point interface */
++	}
++#endif
++
+ #if PJ_IP_HELPER_IGNORE_LOOPBACK_IF
+ 	if (iff.ifr_flags & IFF_LOOPBACK) {
+ 	    TRACE_((THIS_FILE, "  loopback interface"));
+@@ -322,11 +336,18 @@ static pj_status_t if_enum_by_af(int af, unsigned *p_cnt, pj_sockaddr ifs[])
+ 	    continue; /* Skip when interface is down */
+ 	}
+ 
+-        if ((ifreq.ifr_flags & IFF_RUNNING)==0) {
++	if ((ifreq.ifr_flags & IFF_RUNNING)==0) {
+ 	    TRACE_((THIS_FILE, "  interface is not running"));
+ 	    continue; /* Skip when interface is not running */
+ 	}
+ 
++#if defined(__APPLE__)
++	if (ifreq.ifr_flags & IFF_POINTOPOINT) {
++	    TRACE_((THIS_FILE, "  point to point interface"));
++	    continue; /* Skip point to point interface */
++	}
++#endif
++
+ #if PJ_IP_HELPER_IGNORE_LOOPBACK_IF
+ 	if (ifreq.ifr_flags & IFF_LOOPBACK) {
+ 	    TRACE_((THIS_FILE, "  loopback interface"));
diff --git a/contrib/src/pjproject/rules.mak b/contrib/src/pjproject/rules.mak
index 742600962a..5bba769a42 100644
--- a/contrib/src/pjproject/rules.mak
+++ b/contrib/src/pjproject/rules.mak
@@ -48,6 +48,9 @@ pjproject: pjproject-$(PJPROJECT_VERSION).tar.gz .sum-pjproject
 	$(APPLY) $(SRC)/pjproject/0009-add-config-site.patch
 ifdef HAVE_ANDROID
 	$(APPLY) $(SRC)/pjproject/0001-android.patch
+endif
+ifdef HAVE_IOS
+	$(APPLY) $(SRC)/pjproject/0003-disable-ios-pointtopoint.patch
 endif
 	$(UPDATE_AUTOCONFIG)
 	$(MOVE)
-- 
GitLab