From nobody Sun Feb 27 16:47:40 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 5C35419E983D; Sun, 27 Feb 2022 16:47:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4K68ZP0fJGz4lmL; Sun, 27 Feb 2022 16:47:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645980461; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=e28Y7jb8lgUYISEYVX3NwciW9hRSU8CTzbqqKUmdV5U=; b=ltdd6rrQPepB8LdSj3vuFMclqq5zsB88DFuftr65Cj0KktTSZGf4mulmTeu0E2EZB2IRbO UcTom5W0w7mQJhP4fo9Ql4U7Cv/sPGgs/rPT/DwaJE0qWvz1v/TwTWYUozl4dqcWdVSraV o9lcaDP474PFq/Fe0oGtonWSHfg919CA3hKJ2eG3wToY/xc+HyQgyAV2a3mcG2zdoDLAFN RBhYANzQfXaZpUPEe/RVAqI5Ab/D31sDAd5QVnY/vfynyTAqC6eektbEFA6dxlkVOhwd/b mbSsoQgG8p0Zfs/mVi6LafoWZelfan3n/CMK5mH/u5nY+pq4dEdY5ITWiQ811g== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 826E12D2B; Sun, 27 Feb 2022 16:47:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 21RGleHV036751; Sun, 27 Feb 2022 16:47:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21RGlecs036750; Sun, 27 Feb 2022 16:47:40 GMT (envelope-from git) Date: Sun, 27 Feb 2022 16:47:40 GMT Message-Id: <202202271647.21RGlecs036750@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: d9d1a1e7ab29 - main - libefivar: Add DevPathFromTextDns and DevPathToTextDns libraries List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d9d1a1e7ab29b4645415f5f572faea41efc5a0c2 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645980461; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=e28Y7jb8lgUYISEYVX3NwciW9hRSU8CTzbqqKUmdV5U=; b=af0ZZ4tk++b7dfh6XQfkrFs8yfSFog06Kk7kHTr3Nhy9ag4xAGK9L73ZUbw2TcVswN8HPg xpvEIXKLDfBQ7nzgSBSc/B72kOH7Z8BjOk9jZYdkae45VTdCMKKlOa1yVFleGcpoLwJYQh CXy0Yu3thSFs00qrxcYsDqZR7CWxqdil3Ic3EUra1v5aYxmvjFyeLozicffVlLDw78xI+h rJ1YD5G5iD17qHcS5R/0EGvpaYXDjClEfWVJj/H7aZQhgk9QWPuyGsmd74+DfzVafIYd1k GDei8PO49c3ogGP6+/9bCakuh/Tv/voDPKqxD7J2ffhZMEhU/kGBcPkNfaqHhQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1645980461; a=rsa-sha256; cv=none; b=oZY7HZKvPnd9iJ266/BDoGh8EAOprIbKixyh7OnZ1QRGIJFMStYP4Raai9VnaFAXpWRwF4 gETxMobV6o1Rw3z8mj923dz/5UHi38GIt5BnXbSAQpjFXLEzcZ7kWKO6AjAEg4t4ISvxio pxMqsOn0r6UoSGzRK0xB8JzDcRFXmle2NrtGKsihKnQ7idGKZU4+CH2XGNnk7gvn/qxW1Q E8cr854/HMT5yoJjUTYRmoMUi/DeKPHLaqLbfc1BXHrW+9ZJb3cffjPdfAupKI8YpC79ee kexzzKHcUn7BN4//9gnVMULlY/rPV55bKlm4R8ZfV6K/TMexWMtgxLGOpk9qdg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=d9d1a1e7ab29b4645415f5f572faea41efc5a0c2 commit d9d1a1e7ab29b4645415f5f572faea41efc5a0c2 Author: Jose Luis Duran AuthorDate: 2022-02-24 00:39:13 +0000 Commit: Warner Losh CommitDate: 2022-02-27 16:12:29 +0000 libefivar: Add DevPathFromTextDns and DevPathToTextDns libraries V3: * Fix the bug in DevPathFromTextDns() V2: * Add no IP instance case check. Obtained from: https://github.com/tianocore/edk2/commit/9b9d0655c1547384c2b34cea94eab4b8b83bd1b9 Pull Request: https://github.com/freebsd/freebsd-src/pull/581 --- lib/libefivar/efivar-dp-format.c | 46 ++++++++++++++++++++ lib/libefivar/efivar-dp-parse.c | 94 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+) diff --git a/lib/libefivar/efivar-dp-format.c b/lib/libefivar/efivar-dp-format.c index 667a794b34db..8aa8a4798389 100644 --- a/lib/libefivar/efivar-dp-format.c +++ b/lib/libefivar/efivar-dp-format.c @@ -1758,6 +1758,51 @@ DevPathToTextBluetoothLE ( ); } +/** + Converts a DNS device path structure to its string representative. + + @param Str The string representative of input device. + @param DevPath The input device path structure. + @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation + of the display node is used, where applicable. If DisplayOnly + is FALSE, then the longer text representation of the display node + is used. + @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text + representation for a device node can be used, where applicable. + +**/ +static VOID +DevPathToTextDns ( + IN OUT POOL_PRINT *Str, + IN VOID *DevPath, + IN BOOLEAN DisplayOnly, + IN BOOLEAN AllowShortcuts + ) +{ + DNS_DEVICE_PATH *DnsDevPath; + UINT32 DnsServerIpCount; + UINT32 DnsServerIpIndex; + + DnsDevPath = DevPath; + DnsServerIpCount = (UINT32) (DevicePathNodeLength(DnsDevPath) - sizeof (EFI_DEVICE_PATH_PROTOCOL) - sizeof (DnsDevPath->IsIPv6)) / sizeof (EFI_IP_ADDRESS); + + UefiDevicePathLibCatPrint (Str, "Dns("); + + for (DnsServerIpIndex = 0; DnsServerIpIndex < DnsServerIpCount; DnsServerIpIndex++) { + if (DnsDevPath->IsIPv6 == 0x00) { + CatIPv4Address (Str, &(DnsDevPath->DnsServerIp[DnsServerIpIndex].v4)); + } else { + CatIPv6Address (Str, &(DnsDevPath->DnsServerIp[DnsServerIpIndex].v6)); + } + + if (DnsServerIpIndex < DnsServerIpCount - 1) { + UefiDevicePathLibCatPrint (Str, ","); + } + } + + UefiDevicePathLibCatPrint (Str, ")"); +} + /** Converts a URI device path structure to its string representative. @@ -2291,6 +2336,7 @@ static const DEVICE_PATH_TO_TEXT_TABLE mUefiDevicePathLibToTextTable[] = { {MESSAGING_DEVICE_PATH, MSG_VENDOR_DP, DevPathToTextVendor }, {MESSAGING_DEVICE_PATH, MSG_ISCSI_DP, DevPathToTextiSCSI }, {MESSAGING_DEVICE_PATH, MSG_VLAN_DP, DevPathToTextVlan }, + {MESSAGING_DEVICE_PATH, MSG_DNS_DP, DevPathToTextDns }, {MESSAGING_DEVICE_PATH, MSG_URI_DP, DevPathToTextUri }, {MESSAGING_DEVICE_PATH, MSG_BLUETOOTH_DP, DevPathToTextBluetooth }, {MESSAGING_DEVICE_PATH, MSG_WIFI_DP, DevPathToTextWiFi }, diff --git a/lib/libefivar/efivar-dp-parse.c b/lib/libefivar/efivar-dp-parse.c index 80270aad1d5c..b755ea4a6146 100644 --- a/lib/libefivar/efivar-dp-parse.c +++ b/lib/libefivar/efivar-dp-parse.c @@ -2872,6 +2872,99 @@ DevPathFromTextBluetoothLE ( return (EFI_DEVICE_PATH_PROTOCOL *) BluetoothLeDp; } +/** + Converts a text device path node to DNS device path structure. + + @param TextDeviceNode The input Text device path node. + + @return A pointer to the newly-created DNS device path structure. + +**/ +static +EFI_DEVICE_PATH_PROTOCOL * +DevPathFromTextDns ( + IN CHAR16 *TextDeviceNode + ) +{ + CHAR16 *DeviceNodeStr; + CHAR16 *DeviceNodeStrPtr; + UINT32 DnsServerIpCount; + UINT16 DnsDeviceNodeLength; + DNS_DEVICE_PATH *DnsDeviceNode; + UINT32 DnsServerIpIndex; + CHAR16 *DnsServerIp; + + + // + // Count the DNS server address number. + // + DeviceNodeStr = UefiDevicePathLibStrDuplicate (TextDeviceNode); + if (DeviceNodeStr == NULL) { + return NULL; + } + + DeviceNodeStrPtr = DeviceNodeStr; + + DnsServerIpCount = 0; + while (DeviceNodeStrPtr != NULL && *DeviceNodeStrPtr != '\0') { + GetNextParamStr (&DeviceNodeStrPtr); + DnsServerIpCount ++; + } + + FreePool (DeviceNodeStr); + DeviceNodeStr = NULL; + + // + // One or more instances of the DNS server address in EFI_IP_ADDRESS, + // otherwise, NULL will be returned. + // + if (DnsServerIpCount == 0) { + return NULL; + } + + // + // Create the DNS DeviceNode. + // + DnsDeviceNodeLength = (UINT16) (sizeof (EFI_DEVICE_PATH_PROTOCOL) + sizeof (UINT8) + DnsServerIpCount * sizeof (EFI_IP_ADDRESS)); + DnsDeviceNode = (DNS_DEVICE_PATH *) CreateDeviceNode ( + MESSAGING_DEVICE_PATH, + MSG_DNS_DP, + DnsDeviceNodeLength + ); + if (DnsDeviceNode == NULL) { + return NULL; + } + + // + // Confirm the DNS server address is IPv4 or IPv6 type. + // + DeviceNodeStrPtr = TextDeviceNode; + while (!IS_NULL (*DeviceNodeStrPtr)) { + if (*DeviceNodeStrPtr == '.') { + DnsDeviceNode->IsIPv6 = 0x00; + break; + } + + if (*DeviceNodeStrPtr == ':') { + DnsDeviceNode->IsIPv6 = 0x01; + break; + } + + DeviceNodeStrPtr++; + } + + for (DnsServerIpIndex = 0; DnsServerIpIndex < DnsServerIpCount; DnsServerIpIndex++) { + DnsServerIp = GetNextParamStr (&TextDeviceNode); + if (DnsDeviceNode->IsIPv6 == 0x00) { + StrToIpv4Address (DnsServerIp, NULL, &(DnsDeviceNode->DnsServerIp[DnsServerIpIndex].v4), NULL); + } else { + StrToIpv6Address (DnsServerIp, NULL, &(DnsDeviceNode->DnsServerIp[DnsServerIpIndex].v6), NULL); + } + } + + return (EFI_DEVICE_PATH_PROTOCOL *) DnsDeviceNode; +} + /** Converts a text device path node to URI device path structure. @@ -3575,6 +3668,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevP {"Unit", DevPathFromTextUnit }, {"iSCSI", DevPathFromTextiSCSI }, {"Vlan", DevPathFromTextVlan }, + {"Dns", DevPathFromTextDns }, {"Uri", DevPathFromTextUri }, {"Bluetooth", DevPathFromTextBluetooth }, {"Wi-Fi", DevPathFromTextWiFi },