From nobody Wed Dec 25 13:23:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1508303832679458.1249265801915; Tue, 17 Oct 2017 22:17:12 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 7381F20945BCB; Tue, 17 Oct 2017 22:13:34 -0700 (PDT) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 97BA121F38859 for ; Tue, 17 Oct 2017 22:13:33 -0700 (PDT) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP; 17 Oct 2017 22:17:10 -0700 Received: from sfu5-mobl.ccr.corp.intel.com ([10.239.192.56]) by fmsmga004.fm.intel.com with ESMTP; 17 Oct 2017 22:17:09 -0700 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=siyuan.fu@intel.com; receiver=edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,394,1503385200"; d="scan'208";a="324497785" From: Fu Siyuan To: edk2-devel@lists.01.org Date: Wed, 18 Oct 2017 13:17:05 +0800 Message-Id: <20171018051705.13832-1-siyuan.fu@intel.com> X-Mailer: git-send-email 2.13.0.windows.1 Subject: [edk2] [Patch] MdeModulePkg: Update IP4 stack to support point-to-point link with 31-bit mask. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ye Ting , Wu Jiaxin MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This patch is to follow RFC3021 which allows to use 31-bit mask in point-to-point link. If a 31-bit subnet mask is assigned to a point-to-point link, it leaves the with only 1 bit. Consequently, only two possible addresses may result: {, 0} and {, -1} These addresses have historically been associated with network and broadcast addresses (see Section 2.2). In a point-to-point link with a 31-bit subnet mask, the two addresses above MUST be interpreted as host addresses. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Fu Siyuan Cc: Wu Jiaxin Cc: Ye Ting Reviewed-by: Wu Jiaxin --- MdeModulePkg/Include/Library/NetLib.h | 6 ++++-- MdeModulePkg/Library/DxeNetLib/DxeNetLib.c | 14 ++++++++++---- MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c | 20 +++++++++++++------- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/MdeModulePkg/Include/Library/NetLib.h b/MdeModulePkg/Include/L= ibrary/NetLib.h index 4cd4227..b9df46c 100644 --- a/MdeModulePkg/Include/Library/NetLib.h +++ b/MdeModulePkg/Include/Library/NetLib.h @@ -414,8 +414,10 @@ NetGetIpClass ( =20 ASSERT if NetMask is zero. =20 - If all bits of the host address of IP are 0 or 1, IP is also not a valid= unicast address. - + If all bits of the host address of IP are 0 or 1, IP is also not a valid= unicast address, + except when the originator is one of the endpoints of a point-to-point l= ink with a 31-bit + mask (RFC3021). + =20 @param[in] Ip The IP to check against. @param[in] NetMask The mask of the IP. =20 diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c b/MdeModulePkg/Libr= ary/DxeNetLib/DxeNetLib.c index 1ee77fe..b8544b8 100644 --- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c +++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c @@ -637,7 +637,9 @@ NetGetIpClass ( =20 ASSERT if NetMask is zero. =20 - If all bits of the host address of IP are 0 or 1, IP is also not a valid= unicast address. + If all bits of the host address of IP are 0 or 1, IP is also not a valid= unicast address, + except when the originator is one of the endpoints of a point-to-point l= ink with a 31-bit + mask (RFC3021). =20 @param[in] Ip The IP to check against. @param[in] NetMask The mask of the IP. @@ -657,9 +659,13 @@ NetIp4IsUnicast ( if (Ip =3D=3D 0 || IP4_IS_LOCAL_BROADCAST (Ip)) { return FALSE; } - =20 - if (((Ip &~NetMask) =3D=3D ~NetMask) || ((Ip &~NetMask) =3D=3D 0)) { - return FALSE; + + if (NetGetMaskLength (NetMask) !=3D 31) { + if (((Ip &~NetMask) =3D=3D ~NetMask) || ((Ip &~NetMask) =3D=3D 0)) { + return FALSE; + } + } else { + return TRUE; } =20 return TRUE; diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c b/MdeModuleP= kg/Universal/Network/Ip4Dxe/Ip4Common.c index 7c7d182..b8160c1 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c @@ -314,16 +314,22 @@ Ip4StationAddressValid ( =20 // // Station address can't be subnet broadcast/net broadcast address + // RFC3021: In a point-to-point network with 31-bit mask, the only has + // 1 bit, only two possible addresses may result: + // {, 0} and {, -1} + // The two address above must be interpreted as host addresses. // - if ((Ip =3D=3D (Ip & Netmask)) || (Ip =3D=3D (Ip | ~Netmask))) { - return FALSE; - } + if (Len !=3D 31) { + if ((Ip =3D=3D (Ip & Netmask)) || (Ip =3D=3D (Ip | ~Netmask))) { + return FALSE; + } =20 - NetBrdcastMask =3D gIp4AllMasks[MIN (Len, Type << 3)]; + NetBrdcastMask =3D gIp4AllMasks[MIN (Len, Type << 3)]; =20 - if (Ip =3D=3D (Ip | ~NetBrdcastMask)) { - return FALSE; + if (Ip =3D=3D (Ip | ~NetBrdcastMask)) { + return FALSE; + } } =20 return TRUE; -} \ No newline at end of file +} --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel