[Github Sync] Merge github/main to aosp/main

Bug: 333301206

* github/main:
  submodule: bump third_party/openthread/repo from `38418ae` to `65bc830` (#2240)
  submodule: bump third_party/openthread/repo from `0e36799` to `38418ae` (#2239)
  [continuous-integration] install `socat` for docker-based BR tests (#2236)
  submodule: bump third_party/openthread/repo from `d099d78` to `0e36799` (#2238)
  submodule: bump third_party/openthread/repo from `37144f0` to `d099d78` (#2237)
  submodule: bump third_party/openthread/repo from `58b230f` to `37144f0` (#2235)
  submodule: bump third_party/openthread/repo from `7d4a1f8` to `58b230f` (#2234)
  [border-agent] remove duplicate Thread state callback registrations (#2233)
  submodule: bump third_party/openthread/repo from `4db6520` to `7d4a1f8` (#2232)
  submodule: bump third_party/openthread/repo from `90adc86` to `4db6520` (#2231)
  [version] introduce `OT_THREAD_VERSION_1_4` (#2229)
  submodule: bump third_party/openthread/repo from `51ab865` to `90adc86` (#2230)
  submodule: bump third_party/openthread/repo from `8b906eb` to `51ab865` (#2227)
  submodule: bump third_party/openthread/repo from `9d6321b` to `8b906eb` (#2225)
  [meshcop] support runtime custom vendor and product name (#2200)
  submodule: bump third_party/openthread/repo from `3ebc3d3` to `9d6321b` (#2224)
  submodule: bump third_party/openthread/repo from `8769898` to `3ebc3d3` (#2222)
  submodule: bump third_party/openthread/repo from `8e9d58f` to `8769898` (#2221)
  [ncp] clear handlers and callbacks in `NcpOpenThread::Deinit()` (#2220)
  [mdns-avahi] handle potential unknown Avahi states gracefully (#2210)
  submodule: bump third_party/openthread/repo from `53382ec` to `8e9d58f` (#2219)
  [logging] add command line arg to disable syslog (#2102)
  [github-actions] fix macOS CI (#2218)
  submodule: bump third_party/openthread/repo from `39fcc5e` to `53382ec` (#2215)
  submodule: bump third_party/openthread/repo from `d63da4f` to `39fcc5e` (#2214)
  submodule: bump third_party/openthread/repo from `08a7600` to `d63da4f` (#2213)
  [mdns-avahi] allow `UnsubscribeService/Host()` to remove non-present entries (#2209)
  submodule: bump third_party/openthread/repo from `41526d5` to `08a7600` (#2212)
  submodule: bump third_party/openthread/repo from `b9dcdbc` to `41526d5` (#2211)
  [discovery-proxy] remove `assert` checks on query name parse errors (#2208)
  [mdns] allow `UnsubscribeService/Host()` to remove non-present entries (#2206)
  submodule: bump third_party/openthread/repo from `f0b6fce` to `b9dcdbc` (#2205)
  [github-actions] add `brew upgrade node` (#2204)
  submodule: bump third_party/openthread/repo from `6cfe14c` to `f0b6fce` (#2199)
  [openwrt] remove usage of `OT_NETWORK_DIAGNOSTIC_TYPELIST_MAX_ENTRIES` (#2198)
  submodule: bump third_party/openthread/repo from `33574ad` to `6cfe14c` (#2196)

Change-Id: Idf632ab5b108304a6d875bf501cf482e7aaefd78
diff --git a/.github/workflows/macOS.yml b/.github/workflows/macOS.yml
index 11f1566..a99adde 100644
--- a/.github/workflows/macOS.yml
+++ b/.github/workflows/macOS.yml
@@ -49,18 +49,13 @@
         submodules: true
     - name: Bootstrap
       run: |
-        rm -f /usr/local/bin/2to3
-        rm -f /usr/local/bin/2to3-3.11
-        rm -f /usr/local/bin/idle3
-        rm -f /usr/local/bin/idle3.11
-        rm -f /usr/local/bin/pydoc3
-        rm -f /usr/local/bin/pydoc3.11
-        rm -f /usr/local/bin/python3
-        rm -f /usr/local/bin/python3.11
-        rm -f /usr/local/bin/python3-config
-        rm -f /usr/local/bin/python3.11-config
+        rm -f /usr/local/bin/2to3*
+        rm -f /usr/local/bin/idle3*
+        rm -f /usr/local/bin/pydoc3*
+        rm -f /usr/local/bin/python3*
         brew update
         brew reinstall boost cmake cpputest dbus jsoncpp ninja protobuf@21 pkg-config
+        brew upgrade node
     - name: Build
       run: |
         OTBR_OPTIONS="-DOTBR_BORDER_AGENT=OFF \
diff --git a/etc/docker/Dockerfile b/etc/docker/Dockerfile
index eef7a94..08f160c 100644
--- a/etc/docker/Dockerfile
+++ b/etc/docker/Dockerfile
@@ -78,7 +78,7 @@
   libnetfilter-queue-dev
 
 # Required for OpenThread Backbone CI
-ENV OTBR_OT_BACKBONE_CI_DEPS curl lcov wget build-essential python3-dbus python3-zeroconf
+ENV OTBR_OT_BACKBONE_CI_DEPS curl lcov wget build-essential python3-dbus python3-zeroconf socat
 
 # Required and installed during build (script/bootstrap) when RELEASE=1, could be removed
 ENV OTBR_NORELEASE_DEPS \
diff --git a/src/agent/main.cpp b/src/agent/main.cpp
index 4ed5e27..776c3e7 100644
--- a/src/agent/main.cpp
+++ b/src/agent/main.cpp
@@ -70,6 +70,7 @@
     OTBR_OPT_HELP                    = 'h',
     OTBR_OPT_INTERFACE_NAME          = 'I',
     OTBR_OPT_VERBOSE                 = 'v',
+    OTBR_OPT_SYSLOG_DISABLE          = 's',
     OTBR_OPT_VERSION                 = 'V',
     OTBR_OPT_SHORTMAX                = 128,
     OTBR_OPT_RADIO_VERSION,
@@ -90,6 +91,7 @@
     {"help", no_argument, nullptr, OTBR_OPT_HELP},
     {"thread-ifname", required_argument, nullptr, OTBR_OPT_INTERFACE_NAME},
     {"verbose", no_argument, nullptr, OTBR_OPT_VERBOSE},
+    {"syslog-disable", no_argument, nullptr, OTBR_OPT_SYSLOG_DISABLE},
     {"version", no_argument, nullptr, OTBR_OPT_VERSION},
     {"radio-version", no_argument, nullptr, OTBR_OPT_RADIO_VERSION},
     {"auto-attach", optional_argument, nullptr, OTBR_OPT_AUTO_ATTACH},
@@ -136,9 +138,10 @@
 static void PrintHelp(const char *aProgramName)
 {
     fprintf(stderr,
-            "Usage: %s [-I interfaceName] [-B backboneIfName] [-d DEBUG_LEVEL] [-v] [--auto-attach[=0/1]] RADIO_URL "
-            "[RADIO_URL]\n"
-            "    --auto-attach defaults to 1\n",
+            "Usage: %s [-I interfaceName] [-B backboneIfName] [-d DEBUG_LEVEL] [-v] [-s] [--auto-attach[=0/1]] "
+            "RADIO_URL [RADIO_URL]\n"
+            "    --auto-attach defaults to 1\n"
+            "    -s disables syslog and prints to standard out\n",
             aProgramName);
     fprintf(stderr, "%s", otSysGetRadioUrlHelpString());
 }
@@ -195,6 +198,7 @@
     int                       ret               = EXIT_SUCCESS;
     const char               *interfaceName     = kDefaultInterfaceName;
     bool                      verbose           = false;
+    bool                      syslogDisable     = false;
     bool                      printRadioVersion = false;
     bool                      enableAutoAttach  = true;
     const char               *restListenAddress = "";
@@ -205,7 +209,7 @@
 
     std::set_new_handler(OnAllocateFailed);
 
-    while ((opt = getopt_long(argc, argv, "B:d:hI:Vv", kOptions, nullptr)) != -1)
+    while ((opt = getopt_long(argc, argv, "B:d:hI:Vvs", kOptions, nullptr)) != -1)
     {
         switch (opt)
         {
@@ -228,6 +232,10 @@
             verbose = true;
             break;
 
+        case OTBR_OPT_SYSLOG_DISABLE:
+            syslogDisable = true;
+            break;
+
         case OTBR_OPT_VERSION:
             PrintVersion();
             ExitNow();
@@ -269,7 +277,7 @@
         }
     }
 
-    otbrLogInit(argv[0], logLevel, verbose);
+    otbrLogInit(argv[0], logLevel, verbose, syslogDisable);
     otbrLogNotice("Running %s", OTBR_PACKAGE_VERSION);
     otbrLogNotice("Thread version: %s", otbr::Ncp::ControllerOpenThread::GetThreadVersion());
     otbrLogNotice("Thread interface: %s", interfaceName);
diff --git a/src/common/logging.cpp b/src/common/logging.cpp
index 5a787e8..c5f7018 100644
--- a/src/common/logging.cpp
+++ b/src/common/logging.cpp
@@ -53,6 +53,7 @@
 static const char   sLevelString[][8] = {
       "[EMERG]", "[ALERT]", "[CRIT]", "[ERR ]", "[WARN]", "[NOTE]", "[INFO]", "[DEBG]",
 };
+static bool sSyslogDisabled = false;
 
 static otbrLogLevel sDefaultLevel = OTBR_LOG_INFO;
 
@@ -77,8 +78,14 @@
     sLevel = aLevel;
 }
 
+/** Enable/disable logging with syslog */
+void otbrLogSyslogSetEnabled(bool aEnabled)
+{
+    sSyslogDisabled = !aEnabled;
+}
+
 /** Initialize logging */
-void otbrLogInit(const char *aProgramName, otbrLogLevel aLevel, bool aPrintStderr)
+void otbrLogInit(const char *aProgramName, otbrLogLevel aLevel, bool aPrintStderr, bool aSyslogDisable)
 {
     const char *ident;
 
@@ -88,7 +95,12 @@
     ident = strrchr(aProgramName, '/');
     ident = (ident != nullptr) ? ident + 1 : aProgramName;
 
-    openlog(ident, (LOG_CONS | LOG_PID) | (aPrintStderr ? LOG_PERROR : 0), OTBR_SYSLOG_FACILITY_ID);
+    otbrLogSyslogSetEnabled(!aSyslogDisable);
+
+    if (!sSyslogDisabled)
+    {
+        openlog(ident, (LOG_CONS | LOG_PID) | (aPrintStderr ? LOG_PERROR : 0), OTBR_SYSLOG_FACILITY_ID);
+    }
     sLevel        = aLevel;
     sDefaultLevel = sLevel;
 }
@@ -118,7 +130,7 @@
     return prefix;
 }
 
-/** log to the syslog or log file */
+/** log to the syslog or standard out */
 void otbrLog(otbrLogLevel aLevel, const char *aLogTag, const char *aFormat, ...)
 {
     const uint16_t kBufferSize = 1024;
@@ -129,7 +141,14 @@
 
     if ((aLevel <= sLevel) && (vsnprintf(buffer, sizeof(buffer), aFormat, ap) > 0))
     {
-        syslog(static_cast<int>(aLevel), "%s%s: %s", sLevelString[aLevel], GetPrefix(aLogTag), buffer);
+        if (sSyslogDisabled)
+        {
+            printf("%s%s: %s\n", sLevelString[aLevel], GetPrefix(aLogTag), buffer);
+        }
+        else
+        {
+            syslog(static_cast<int>(aLevel), "%s%s: %s", sLevelString[aLevel], GetPrefix(aLogTag), buffer);
+        }
     }
 
     va_end(ap);
@@ -137,7 +156,7 @@
     return;
 }
 
-/** log to the syslog or log file */
+/** log to the syslog or standard out */
 void otbrLogv(otbrLogLevel aLevel, const char *aFormat, va_list aArgList)
 {
     assert(aFormat);
@@ -148,9 +167,18 @@
     }
 }
 
+/** log to the syslog or standard out */
 void otbrLogvNoFilter(otbrLogLevel aLevel, const char *aFormat, va_list aArgList)
 {
-    vsyslog(static_cast<int>(aLevel), aFormat, aArgList);
+    if (sSyslogDisabled)
+    {
+        vprintf(aFormat, aArgList);
+        printf("\n");
+    }
+    else
+    {
+        vsyslog(static_cast<int>(aLevel), aFormat, aArgList);
+    }
 }
 
 /** Hex dump data to the log */
diff --git a/src/common/logging.hpp b/src/common/logging.hpp
index 0acdf87..ad36d4f 100644
--- a/src/common/logging.hpp
+++ b/src/common/logging.hpp
@@ -78,20 +78,21 @@
 /**
  * Control log to syslog.
  *
- * @param[in] enable  True to log to/via syslog.
+ * @param[in] aEnabled  True to enable logging to/via syslog.
  *
  */
-void otbrLogEnableSyslog(bool aEnabled);
+void otbrLogSyslogSetEnabled(bool aEnabled);
 
 /**
  * This function initialize the logging service.
  *
- * @param[in] aProgramName  The name of this runnable program.
- * @param[in] aLevel        Log level of the logger.
- * @param[in] aPrintStderr  Whether to log to stderr.
+ * @param[in] aProgramName    The name of this runnable program.
+ * @param[in] aLevel          Log level of the logger.
+ * @param[in] aPrintStderr    Whether to log to stderr.
+ * @param[in] aSyslogDisable  Whether to disable logging to syslog.
  *
  */
-void otbrLogInit(const char *aProgramName, otbrLogLevel aLevel, bool aPrintStderr);
+void otbrLogInit(const char *aProgramName, otbrLogLevel aLevel, bool aPrintStderr, bool aSyslogDisable);
 
 /**
  * This function log at level @p aLevel.
diff --git a/src/mdns/mdns_avahi.cpp b/src/mdns/mdns_avahi.cpp
index ba01519..2f3984d 100644
--- a/src/mdns/mdns_avahi.cpp
+++ b/src/mdns/mdns_avahi.cpp
@@ -570,10 +570,6 @@
     case AVAHI_ENTRY_GROUP_UNCOMMITED:
     case AVAHI_ENTRY_GROUP_REGISTERING:
         break;
-
-    default:
-        assert(false);
-        break;
     }
 }
 
@@ -696,10 +692,6 @@
     case AVAHI_CLIENT_CONNECTING:
         otbrLogInfo("Avahi client is connecting to the server");
         break;
-
-    default:
-        assert(false);
-        break;
     }
 }
 
@@ -1047,7 +1039,7 @@
                           return aService->mType == aType && aService->mInstanceName == aInstanceName;
                       });
 
-    assert(it != mSubscribedServices.end());
+    VerifyOrExit(it != mSubscribedServices.end());
 
     {
         std::unique_ptr<ServiceSubscription> service = std::move(*it);
@@ -1106,7 +1098,7 @@
         mSubscribedHosts.begin(), mSubscribedHosts.end(),
         [&aHostName](const std::unique_ptr<HostSubscription> &aHost) { return aHost->mHostName == aHostName; });
 
-    assert(it != mSubscribedHosts.end());
+    VerifyOrExit(it != mSubscribedHosts.end());
 
     {
         std::unique_ptr<HostSubscription> host = std::move(*it);
diff --git a/src/mdns/mdns_mdnssd.cpp b/src/mdns/mdns_mdnssd.cpp
index b820f4c..689634a 100644
--- a/src/mdns/mdns_mdnssd.cpp
+++ b/src/mdns/mdns_mdnssd.cpp
@@ -948,7 +948,7 @@
                       [&aType, &aInstanceName](const std::unique_ptr<ServiceSubscription> &aService) {
                           return aService->mType == aType && aService->mInstanceName == aInstanceName;
                       });
-    assert(it != mSubscribedServices.end());
+    VerifyOrExit(it != mSubscribedServices.end());
 
     mSubscribedServices.erase(it);
 
@@ -998,7 +998,7 @@
         mSubscribedHosts.begin(), mSubscribedHosts.end(),
         [&aHostName](const std::unique_ptr<HostSubscription> &aHost) { return aHost->mHostName == aHostName; });
 
-    assert(it != mSubscribedHosts.end());
+    VerifyOrExit(it != mSubscribedHosts.end());
 
     mSubscribedHosts.erase(it);
 
diff --git a/src/ncp/ncp_openthread.cpp b/src/ncp/ncp_openthread.cpp
index 84a8601..df3dcd5 100644
--- a/src/ncp/ncp_openthread.cpp
+++ b/src/ncp/ncp_openthread.cpp
@@ -60,10 +60,10 @@
 namespace otbr {
 namespace Ncp {
 
-static const uint16_t kThreadVersion11  = 2; ///< Thread Version 1.1
-static const uint16_t kThreadVersion12  = 3; ///< Thread Version 1.2
-static const uint16_t kThreadVersion13  = 4; ///< Thread Version 1.3
-static const uint16_t kThreadVersion131 = 5; ///< Thread Version 1.3.1
+static const uint16_t kThreadVersion11 = 2; ///< Thread Version 1.1
+static const uint16_t kThreadVersion12 = 3; ///< Thread Version 1.2
+static const uint16_t kThreadVersion13 = 4; ///< Thread Version 1.3
+static const uint16_t kThreadVersion14 = 5; ///< Thread Version 1.4
 
 ControllerOpenThread::ControllerOpenThread(const char                      *aInterfaceName,
                                            const std::vector<const char *> &aRadioUrls,
@@ -388,8 +388,8 @@
     case kThreadVersion13:
         version = "1.3.0";
         break;
-    case kThreadVersion131:
-        version = "1.3.1";
+    case kThreadVersion14:
+        version = "1.4";
         break;
     default:
         otbrLogEmerg("Unexpected thread version %hu", otThreadGetVersion());
diff --git a/src/openwrt/ubus/otubus.cpp b/src/openwrt/ubus/otubus.cpp
index 4d807a9..4dfaac2 100644
--- a/src/openwrt/ubus/otubus.cpp
+++ b/src/openwrt/ubus/otubus.cpp
@@ -1190,8 +1190,10 @@
         ubus_send_reply(aContext, aRequest, mNetworkdataBuf.head);
         if (time(nullptr) - mSecond > 10)
         {
+            static constexpr uint16_t kMaxTlvs = 35;
+
             struct otIp6Address address;
-            uint8_t             tlvTypes[OT_NETWORK_DIAGNOSTIC_TYPELIST_MAX_ENTRIES];
+            uint8_t             tlvTypes[kMaxTlvs];
             uint8_t             count             = 0;
             char                multicastAddr[10] = "ff03::2";
 
diff --git a/src/sdp_proxy/discovery_proxy.cpp b/src/sdp_proxy/discovery_proxy.cpp
index 0cf5733..ea0072a 100644
--- a/src/sdp_proxy/discovery_proxy.cpp
+++ b/src/sdp_proxy/discovery_proxy.cpp
@@ -214,11 +214,9 @@
         {
         case OT_DNSSD_QUERY_TYPE_BROWSE:
             splitError = SplitFullServiceName(queryName, serviceName, domain);
-            assert(splitError == OTBR_ERROR_NONE);
             break;
         case OT_DNSSD_QUERY_TYPE_RESOLVE:
             splitError = SplitFullServiceInstanceName(queryName, instanceName, serviceName, domain);
-            assert(splitError == OTBR_ERROR_NONE);
             break;
         default:
             splitError = OTBR_ERROR_NOT_FOUND;
@@ -226,6 +224,7 @@
         }
         if (splitError != OTBR_ERROR_NONE)
         {
+            // Incoming service/instance was not what current query wanted to see, move on.
             continue;
         }
 
@@ -284,8 +283,13 @@
         {
             continue;
         }
+
         splitError = SplitFullHostName(queryName, hostName, domain);
-        assert(splitError == OTBR_ERROR_NONE);
+
+        if (splitError != OTBR_ERROR_NONE)
+        {
+            continue;
+        }
 
         if (DnsLabelsEqual(hostName, aHostName))
         {
diff --git a/src/web/main.cpp b/src/web/main.cpp
index 4e25e05..922038d 100644
--- a/src/web/main.cpp
+++ b/src/web/main.cpp
@@ -111,7 +111,7 @@
         }
     }
 
-    otbrLogInit(argv[0], logLevel, true);
+    otbrLogInit(argv[0], logLevel, true, false);
     otbrLogInfo("Running %s", OTBR_PACKAGE_VERSION);
 
     if (interfaceName == nullptr)
diff --git a/tests/mdns/main.cpp b/tests/mdns/main.cpp
index e8fe355..acf8777 100644
--- a/tests/mdns/main.cpp
+++ b/tests/mdns/main.cpp
@@ -482,7 +482,7 @@
         return 1;
     }
 
-    otbrLogInit("otbr-mdns", OTBR_LOG_DEBUG, true);
+    otbrLogInit("otbr-mdns", OTBR_LOG_DEBUG, true, false);
     // allow quitting elegantly
     signal(SIGTERM, RecoverSignal);
     switch (argv[1][0])
diff --git a/tests/mdns/test_subscribe.cpp b/tests/mdns/test_subscribe.cpp
index 554a33f..b01be3e 100644
--- a/tests/mdns/test_subscribe.cpp
+++ b/tests/mdns/test_subscribe.cpp
@@ -130,7 +130,7 @@
 
 void SetUp(void)
 {
-    otbrLogInit("test-mdns-subscriber", OTBR_LOG_INFO, true);
+    otbrLogInit("test-mdns-subscriber", OTBR_LOG_INFO, true, false);
     SuccessOrDie(Ip6Address::FromString("2002::1", sAddr1), "");
     SuccessOrDie(Ip6Address::FromString("2002::2", sAddr2), "");
     SuccessOrDie(Ip6Address::FromString("2002::3", sAddr3), "");
diff --git a/tests/unit/test_logging.cpp b/tests/unit/test_logging.cpp
index 30bd476..c299703 100644
--- a/tests/unit/test_logging.cpp
+++ b/tests/unit/test_logging.cpp
@@ -43,7 +43,7 @@
     char ident[20];
 
     snprintf(ident, sizeof(ident), "otbr-test-%ld", clock());
-    otbrLogInit(ident, OTBR_LOG_INFO, true);
+    otbrLogInit(ident, OTBR_LOG_INFO, true, false);
     otbrLog(OTBR_LOG_DEBUG, OTBR_LOG_TAG, "cool-higher");
     otbrLogDeinit();
     sleep(0);
@@ -58,7 +58,7 @@
     char ident[20];
 
     snprintf(ident, sizeof(ident), "otbr-test-%ld", clock());
-    otbrLogInit(ident, OTBR_LOG_INFO, true);
+    otbrLogInit(ident, OTBR_LOG_INFO, true, false);
     otbrLog(OTBR_LOG_INFO, OTBR_LOG_TAG, "cool-equal");
     otbrLogDeinit();
     sleep(0);
@@ -69,13 +69,29 @@
     CHECK(0 == system(cmd));
 }
 
+TEST(Logging, TestLoggingEqualLevelNoSyslog)
+{
+    char ident[20];
+
+    snprintf(ident, sizeof(ident), "otbr-test-%ld", clock());
+    otbrLogInit(ident, OTBR_LOG_INFO, true, true);
+    otbrLog(OTBR_LOG_INFO, OTBR_LOG_TAG, "cool-equal");
+    otbrLogDeinit();
+    sleep(0);
+
+    char cmd[128];
+    snprintf(cmd, sizeof(cmd), "grep '%s.*cool-equal' /var/log/syslog", ident);
+    printf("CMD = %s\n", cmd);
+    CHECK(0 != system(cmd));
+}
+
 TEST(Logging, TestLoggingLowerLevel)
 {
     char ident[20];
     char cmd[128];
 
     snprintf(ident, sizeof(ident), "otbr-test-%ld", clock());
-    otbrLogInit(ident, OTBR_LOG_INFO, true);
+    otbrLogInit(ident, OTBR_LOG_INFO, true, false);
     otbrLog(OTBR_LOG_WARNING, OTBR_LOG_TAG, "cool-lower");
     otbrLogDeinit();
     sleep(0);
@@ -90,7 +106,7 @@
     char cmd[128];
 
     snprintf(ident, sizeof(ident), "otbr-test-%ld", clock());
-    otbrLogInit(ident, OTBR_LOG_DEBUG, true);
+    otbrLogInit(ident, OTBR_LOG_DEBUG, true, false);
     const char s[] = "one super long string with lots of text";
     otbrDump(OTBR_LOG_INFO, "Test", "foobar", s, sizeof(s));
     otbrLogDeinit();