Discussion:
[edk2] [Patch v3] NetworkPkg: Add old IPv4_DEVICE_PATH and IPv6_DEVICE_PATH support
Wang Fan
1970-01-01 00:00:00 UTC
Permalink
v3:
* Update the macro of Ip4 device path node length and Ip6 device path node length.

GatewayIpAddress and SubnetMask do not exist in old IPv4_DEVICE_PATH, IPAddressOrigin, PrefixLength and GatewayIPAddress do not exist in old IPv6_DEVICE_PATH. This will lead new IScsiDxe to error without updating IPv4_DEVICE_PATH and IPv6_DEVICE_PATH in system.
Following UEFI2.5 spec of IPv4_DEVICE_PATH do a check before accessing fields only defined in new version's IPv4_DEVICE_PATH, and revise the same issue for IPv6_DEVICE_PATH in Iscsi driver.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: fanwang2 <***@intel.com>
---
NetworkPkg/IScsiDxe/IScsiMisc.c | 62 +++++++++++++++++++++++++++++++++--------
NetworkPkg/IScsiDxe/IScsiMisc.h | 18 +++++++++++-
2 files changed, 67 insertions(+), 13 deletions(-)

diff --git a/NetworkPkg/IScsiDxe/IScsiMisc.c b/NetworkPkg/IScsiDxe/IScsiMisc.c
index aeb99e5..010d2a4 100644
--- a/NetworkPkg/IScsiDxe/IScsiMisc.c
+++ b/NetworkPkg/IScsiDxe/IScsiMisc.c
@@ -1,9 +1,9 @@
/** @file
Miscellaneous routines for iSCSI driver.

-Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php

@@ -1350,10 +1350,11 @@ IScsiGetTcpConnDevicePath (
{
ISCSI_CONNECTION *Conn;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
EFI_STATUS Status;
EFI_DEV_PATH *DPathNode;
+ UINTN PathLen;

if (Session->State != SESSION_STATE_LOGGED_IN) {
return NULL;
}

@@ -1388,25 +1389,62 @@ IScsiGetTcpConnDevicePath (
DPathNode->Ipv4.LocalPort = 0;

DPathNode->Ipv4.StaticIpAddress =
(BOOLEAN) (!Session->ConfigData->SessionConfigData.InitiatorInfoFromDhcp);

- IP4_COPY_ADDRESS (
- &DPathNode->Ipv4.GatewayIpAddress,
- &Session->ConfigData->SessionConfigData.Gateway
- );
+ //
+ // Add a judgement here to support previous versions of IPv4_DEVICE_PATH.
+ // In previous versions of IPv4_DEVICE_PATH, GatewayIpAddress and SubnetMask
+ // do not exist.
+ // In new version of IPv4_DEVICE_PATH, structcure length is 27.
+ //

- IP4_COPY_ADDRESS (
- &DPathNode->Ipv4.SubnetMask,
- &Session->ConfigData->SessionConfigData.SubnetMask
- );
+ PathLen = DevicePathNodeLength (&DPathNode->Ipv4);
+
+ if (PathLen == IPv4_NODE_LEN_NEW_VERSIONS) {
+
+ IP4_COPY_ADDRESS (
+ &DPathNode->Ipv4.GatewayIpAddress,
+ &Session->ConfigData->SessionConfigData.Gateway
+ );
+
+ IP4_COPY_ADDRESS (
+ &DPathNode->Ipv4.SubnetMask,
+ &Session->ConfigData->SessionConfigData.SubnetMask
+ );
+ }
+
break;
} else if (Conn->Ipv6Flag && DevicePathSubType (&DPathNode->DevPath) == MSG_IPv6_DP) {
DPathNode->Ipv6.LocalPort = 0;
- DPathNode->Ipv6.IpAddressOrigin = 0;
- DPathNode->Ipv6.PrefixLength = IP6_PREFIX_LENGTH;
- ZeroMem (&DPathNode->Ipv6.GatewayIpAddress, sizeof (EFI_IPv6_ADDRESS));
+
+ //
+ // Add a judgement here to support previous versions of IPv6_DEVICE_PATH.
+ // In previous versions of IPv6_DEVICE_PATH, IpAddressOrigin, PrefixLength
+ // and GatewayIpAddress do not exist.
+ // In new version of IPv6_DEVICE_PATH, structure length is 60, while in
+ // old versions, the length is 43.
+ //
+
+ PathLen = DevicePathNodeLength (&DPathNode->Ipv6);
+
+ if (PathLen == IPv6_NODE_LEN_NEW_VERSIONS ) {
+
+ DPathNode->Ipv6.IpAddressOrigin = 0;
+ DPathNode->Ipv6.PrefixLength = IP6_PREFIX_LENGTH;
+ ZeroMem (&DPathNode->Ipv6.GatewayIpAddress, sizeof (EFI_IPv6_ADDRESS));
+ }
+ else if (PathLen == IPv6_NODE_LEN_OLD_VERSIONS) {
+
+ //
+ // StaticIPAddress is a field in old versions of IPv6_DEVICE_PATH, while ignored in new
+ // version. Set StaticIPAddress through its' offset in old IPv6_DEVICE_PATH.
+ //
+ *((UINT8 *)(&DPathNode->Ipv6) + IPv6_OLD_IPADDRESS_OFFSET) =
+ (BOOLEAN) (!Session->ConfigData->SessionConfigData.InitiatorInfoFromDhcp);
+ }
+
break;
}
}

DPathNode = (EFI_DEV_PATH *) NextDevicePathNode (&DPathNode->DevPath);
diff --git a/NetworkPkg/IScsiDxe/IScsiMisc.h b/NetworkPkg/IScsiDxe/IScsiMisc.h
index fd9e3af..0a3b449 100644
--- a/NetworkPkg/IScsiDxe/IScsiMisc.h
+++ b/NetworkPkg/IScsiDxe/IScsiMisc.h
@@ -1,9 +1,9 @@
/** @file
Miscellaneous definitions for iSCSI driver.

-Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php

@@ -15,10 +15,26 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#ifndef _ISCSI_MISC_H_
#define _ISCSI_MISC_H_

typedef struct _ISCSI_DRIVER_DATA ISCSI_DRIVER_DATA;

+///
+/// IPv4 Device Path Node Length
+///
+#define IPv4_NODE_LEN_NEW_VERSIONS 27
+
+///
+/// IPv6 Device Path Node Length
+///
+#define IPv6_NODE_LEN_OLD_VERSIONS 43
+#define IPv6_NODE_LEN_NEW_VERSIONS 60
+
+///
+/// The ignored field StaticIpAddress's offset in old IPv6 Device Path
+///
+#define IPv6_OLD_IPADDRESS_OFFSET 42;
+
#pragma pack(1)
typedef struct _ISCSI_SESSION_CONFIG_NVDATA {
UINT16 TargetPort;
UINT8 Enabled;
UINT8 IpMode;
--
1.9.5.msysgit.1
Ye, Ting
2015-07-22 02:20:28 UTC
Permalink
Reviewed-by: Ye Ting <***@intel.com>

-----Original Message-----
From: Wang, Fan
Sent: Wednesday, July 22, 2015 8:57 AM
To: Ye, Ting; Fu, Siyuan; Wu, Jiaxin; edk2-***@lists.sourceforge.net; edk2-***@lists.01.org
Cc: Tian, Hot; Ni, Ruiyu
Subject: [Patch v3] NetworkPkg: Add old IPv4_DEVICE_PATH and IPv6_DEVICE_PATH support

v3:
* Update the macro of Ip4 device path node length and Ip6 device path node length.

GatewayIpAddress and SubnetMask do not exist in old IPv4_DEVICE_PATH, IPAddressOrigin, PrefixLength and GatewayIPAddress do not exist in old IPv6_DEVICE_PATH. This will lead new IScsiDxe to error without updating IPv4_DEVICE_PATH and IPv6_DEVICE_PATH in system.
Following UEFI2.5 spec of IPv4_DEVICE_PATH do a check before accessing fields only defined in new version's IPv4_DEVICE_PATH, and revise the same issue for IPv6_DEVICE_PATH in Iscsi driver.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: fanwang2 <***@intel.com>
---
NetworkPkg/IScsiDxe/IScsiMisc.c | 62 +++++++++++++++++++++++++++++++++--------
NetworkPkg/IScsiDxe/IScsiMisc.h | 18 +++++++++++-
2 files changed, 67 insertions(+), 13 deletions(-)

diff --git a/NetworkPkg/IScsiDxe/IScsiMisc.c b/NetworkPkg/IScsiDxe/IScsiMisc.c
index aeb99e5..010d2a4 100644
--- a/NetworkPkg/IScsiDxe/IScsiMisc.c
+++ b/NetworkPkg/IScsiDxe/IScsiMisc.c
@@ -1,9 +1,9 @@
/** @file
Miscellaneous routines for iSCSI driver.

-Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php

@@ -1350,10 +1350,11 @@ IScsiGetTcpConnDevicePath (
{
ISCSI_CONNECTION *Conn;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
EFI_STATUS Status;
EFI_DEV_PATH *DPathNode;
+ UINTN PathLen;

if (Session->State != SESSION_STATE_LOGGED_IN) {
return NULL;
}

@@ -1388,25 +1389,62 @@ IScsiGetTcpConnDevicePath (
DPathNode->Ipv4.LocalPort = 0;

DPathNode->Ipv4.StaticIpAddress =
(BOOLEAN) (!Session->ConfigData->SessionConfigData.InitiatorInfoFromDhcp);

- IP4_COPY_ADDRESS (
- &DPathNode->Ipv4.GatewayIpAddress,
- &Session->ConfigData->SessionConfigData.Gateway
- );
+ //
+ // Add a judgement here to support previous versions of IPv4_DEVICE_PATH.
+ // In previous versions of IPv4_DEVICE_PATH, GatewayIpAddress and SubnetMask
+ // do not exist.
+ // In new version of IPv4_DEVICE_PATH, structcure length is 27.
+ //

- IP4_COPY_ADDRESS (
- &DPathNode->Ipv4.SubnetMask,
- &Session->ConfigData->SessionConfigData.SubnetMask
- );
+ PathLen = DevicePathNodeLength (&DPathNode->Ipv4);
+
+ if (PathLen == IPv4_NODE_LEN_NEW_VERSIONS) {
+
+ IP4_COPY_ADDRESS (
+ &DPathNode->Ipv4.GatewayIpAddress,
+ &Session->ConfigData->SessionConfigData.Gateway
+ );
+
+ IP4_COPY_ADDRESS (
+ &DPathNode->Ipv4.SubnetMask,
+ &Session->ConfigData->SessionConfigData.SubnetMask
+ );
+ }
+
break;
} else if (Conn->Ipv6Flag && DevicePathSubType (&DPathNode->DevPath) == MSG_IPv6_DP) {
DPathNode->Ipv6.LocalPort = 0;
- DPathNode->Ipv6.IpAddressOrigin = 0;
- DPathNode->Ipv6.PrefixLength = IP6_PREFIX_LENGTH;
- ZeroMem (&DPathNode->Ipv6.GatewayIpAddress, sizeof (EFI_IPv6_ADDRESS));
+
+ //
+ // Add a judgement here to support previous versions of IPv6_DEVICE_PATH.
+ // In previous versions of IPv6_DEVICE_PATH, IpAddressOrigin, PrefixLength
+ // and GatewayIpAddress do not exist.
+ // In new version of IPv6_DEVICE_PATH, structure length is 60, while in
+ // old versions, the length is 43.
+ //
+
+ PathLen = DevicePathNodeLength (&DPathNode->Ipv6);
+
+ if (PathLen == IPv6_NODE_LEN_NEW_VERSIONS ) {
+
+ DPathNode->Ipv6.IpAddressOrigin = 0;
+ DPathNode->Ipv6.PrefixLength = IP6_PREFIX_LENGTH;
+ ZeroMem (&DPathNode->Ipv6.GatewayIpAddress, sizeof (EFI_IPv6_ADDRESS));
+ }
+ else if (PathLen == IPv6_NODE_LEN_OLD_VERSIONS) {
+
+ //
+ // StaticIPAddress is a field in old versions of IPv6_DEVICE_PATH, while ignored in new
+ // version. Set StaticIPAddress through its' offset in old IPv6_DEVICE_PATH.
+ //
+ *((UINT8 *)(&DPathNode->Ipv6) + IPv6_OLD_IPADDRESS_OFFSET) =
+ (BOOLEAN) (!Session->ConfigData->SessionConfigData.InitiatorInfoFromDhcp);
+ }
+
break;
}
}

DPathNode = (EFI_DEV_PATH *) NextDevicePathNode (&DPathNode->DevPath);
diff --git a/NetworkPkg/IScsiDxe/IScsiMisc.h b/NetworkPkg/IScsiDxe/IScsiMisc.h
index fd9e3af..0a3b449 100644
--- a/NetworkPkg/IScsiDxe/IScsiMisc.h
+++ b/NetworkPkg/IScsiDxe/IScsiMisc.h
@@ -1,9 +1,9 @@
/** @file
Miscellaneous definitions for iSCSI driver.

-Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php

@@ -15,10 +15,26 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#ifndef _ISCSI_MISC_H_
#define _ISCSI_MISC_H_

typedef struct _ISCSI_DRIVER_DATA ISCSI_DRIVER_DATA;

+///
+/// IPv4 Device Path Node Length
+///
+#define IPv4_NODE_LEN_NEW_VERSIONS 27
+
+///
+/// IPv6 Device Path Node Length
+///
+#define IPv6_NODE_LEN_OLD_VERSIONS 43
+#define IPv6_NODE_LEN_NEW_VERSIONS 60
+
+///
+/// The ignored field StaticIpAddress's offset in old IPv6 Device Path
+///
+#define IPv6_OLD_IPADDRESS_OFFSET 42;
+
#pragma pack(1)
typedef struct _ISCSI_SESSION_CONFIG_NVDATA {
UINT16 TargetPort;
UINT8 Enabled;
UINT8 IpMode;
--
1.9.5.msysgit.1
Laszlo Ersek
2015-07-23 17:21:21 UTC
Permalink
Post by Wang Fan
* Update the macro of Ip4 device path node length and Ip6 device path node length.
GatewayIpAddress and SubnetMask do not exist in old IPv4_DEVICE_PATH, IPAddressOrigin, PrefixLength and GatewayIPAddress do not exist in old IPv6_DEVICE_PATH. This will lead new IScsiDxe to error without updating IPv4_DEVICE_PATH and IPv6_DEVICE_PATH in system.
Following UEFI2.5 spec of IPv4_DEVICE_PATH do a check before accessing fields only defined in new version's IPv4_DEVICE_PATH, and revise the same issue for IPv6_DEVICE_PATH in Iscsi driver.
Contributed-under: TianoCore Contribution Agreement 1.0
---
NetworkPkg/IScsiDxe/IScsiMisc.c | 62 +++++++++++++++++++++++++++++++++--------
NetworkPkg/IScsiDxe/IScsiMisc.h | 18 +++++++++++-
2 files changed, 67 insertions(+), 13 deletions(-)
diff --git a/NetworkPkg/IScsiDxe/IScsiMisc.c b/NetworkPkg/IScsiDxe/IScsiMisc.c
index aeb99e5..010d2a4 100644
--- a/NetworkPkg/IScsiDxe/IScsiMisc.c
+++ b/NetworkPkg/IScsiDxe/IScsiMisc.c
@@ -1,9 +1,9 @@
Miscellaneous routines for iSCSI driver.
-Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
@@ -1350,10 +1350,11 @@ IScsiGetTcpConnDevicePath (
{
ISCSI_CONNECTION *Conn;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
EFI_STATUS Status;
EFI_DEV_PATH *DPathNode;
+ UINTN PathLen;
if (Session->State != SESSION_STATE_LOGGED_IN) {
return NULL;
}
@@ -1388,25 +1389,62 @@ IScsiGetTcpConnDevicePath (
DPathNode->Ipv4.LocalPort = 0;
DPathNode->Ipv4.StaticIpAddress =
(BOOLEAN) (!Session->ConfigData->SessionConfigData.InitiatorInfoFromDhcp);
- IP4_COPY_ADDRESS (
- &DPathNode->Ipv4.GatewayIpAddress,
- &Session->ConfigData->SessionConfigData.Gateway
- );
+ //
+ // Add a judgement here to support previous versions of IPv4_DEVICE_PATH.
+ // In previous versions of IPv4_DEVICE_PATH, GatewayIpAddress and SubnetMask
+ // do not exist.
+ // In new version of IPv4_DEVICE_PATH, structcure length is 27.
+ //
- IP4_COPY_ADDRESS (
- &DPathNode->Ipv4.SubnetMask,
- &Session->ConfigData->SessionConfigData.SubnetMask
- );
+ PathLen = DevicePathNodeLength (&DPathNode->Ipv4);
+
+ if (PathLen == IPv4_NODE_LEN_NEW_VERSIONS) {
+
+ IP4_COPY_ADDRESS (
+ &DPathNode->Ipv4.GatewayIpAddress,
+ &Session->ConfigData->SessionConfigData.Gateway
+ );
+
+ IP4_COPY_ADDRESS (
+ &DPathNode->Ipv4.SubnetMask,
+ &Session->ConfigData->SessionConfigData.SubnetMask
+ );
+ }
+
break;
} else if (Conn->Ipv6Flag && DevicePathSubType (&DPathNode->DevPath) == MSG_IPv6_DP) {
DPathNode->Ipv6.LocalPort = 0;
- DPathNode->Ipv6.IpAddressOrigin = 0;
- DPathNode->Ipv6.PrefixLength = IP6_PREFIX_LENGTH;
- ZeroMem (&DPathNode->Ipv6.GatewayIpAddress, sizeof (EFI_IPv6_ADDRESS));
+
+ //
+ // Add a judgement here to support previous versions of IPv6_DEVICE_PATH.
+ // In previous versions of IPv6_DEVICE_PATH, IpAddressOrigin, PrefixLength
+ // and GatewayIpAddress do not exist.
+ // In new version of IPv6_DEVICE_PATH, structure length is 60, while in
+ // old versions, the length is 43.
+ //
+
+ PathLen = DevicePathNodeLength (&DPathNode->Ipv6);
+
+ if (PathLen == IPv6_NODE_LEN_NEW_VERSIONS ) {
+
+ DPathNode->Ipv6.IpAddressOrigin = 0;
+ DPathNode->Ipv6.PrefixLength = IP6_PREFIX_LENGTH;
+ ZeroMem (&DPathNode->Ipv6.GatewayIpAddress, sizeof (EFI_IPv6_ADDRESS));
+ }
+ else if (PathLen == IPv6_NODE_LEN_OLD_VERSIONS) {
+
+ //
+ // StaticIPAddress is a field in old versions of IPv6_DEVICE_PATH, while ignored in new
+ // version. Set StaticIPAddress through its' offset in old IPv6_DEVICE_PATH.
+ //
+ *((UINT8 *)(&DPathNode->Ipv6) + IPv6_OLD_IPADDRESS_OFFSET) =
+ (BOOLEAN) (!Session->ConfigData->SessionConfigData.InitiatorInfoFromDhcp);
+ }
+
break;
}
}
DPathNode = (EFI_DEV_PATH *) NextDevicePathNode (&DPathNode->DevPath);
diff --git a/NetworkPkg/IScsiDxe/IScsiMisc.h b/NetworkPkg/IScsiDxe/IScsiMisc.h
index fd9e3af..0a3b449 100644
--- a/NetworkPkg/IScsiDxe/IScsiMisc.h
+++ b/NetworkPkg/IScsiDxe/IScsiMisc.h
@@ -1,9 +1,9 @@
Miscellaneous definitions for iSCSI driver.
-Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
@@ -15,10 +15,26 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#ifndef _ISCSI_MISC_H_
#define _ISCSI_MISC_H_
typedef struct _ISCSI_DRIVER_DATA ISCSI_DRIVER_DATA;
+///
+/// IPv4 Device Path Node Length
+///
+#define IPv4_NODE_LEN_NEW_VERSIONS 27
+
+///
+/// IPv6 Device Path Node Length
+///
+#define IPv6_NODE_LEN_OLD_VERSIONS 43
+#define IPv6_NODE_LEN_NEW_VERSIONS 60
+
+///
+/// The ignored field StaticIpAddress's offset in old IPv6 Device Path
+///
+#define IPv6_OLD_IPADDRESS_OFFSET 42;
+
#pragma pack(1)
typedef struct _ISCSI_SESSION_CONFIG_NVDATA {
UINT16 TargetPort;
UINT8 Enabled;
UINT8 IpMode;
Until the SVN outage at sourceforge.net gets resolved, we plan to commit
patches that are ready for merging to the "master" branch of the git
repository at <https://github.com/tianocore/edk2-svn-offline.git>.
Please see the announcement:

http://thread.gmane.org/gmane.comp.bios.edk2.devel/227

This particular patch (or series) appears ready for merging, therefore
it is being picked up:

http://thread.gmane.org/gmane.comp.bios.edk2.devel/227/focus=251

Further development should be based on edk2-svn-offline/master, until
the SVN outage is fixed. At that point the accumulated patches will be
mass-committed from edk2-svn-offline/master to SVN.

Thanks
Laszlo


------------------------------------------------------------------------------
Loading...