NetworkPkg: Update IP4 stack drivers for classless address unicast check.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
Reviewed-by: Wu Jiaxin <jiaxin.wu@intel.com>
This commit is contained in:
Fu Siyuan
2016-10-27 09:23:22 +08:00
parent 01b5ac880f
commit 6c12fe63f9
4 changed files with 45 additions and 21 deletions

View File

@@ -856,8 +856,7 @@ EfiPxeBcMtftp (
(BufferSize == NULL) ||
(ServerIp == NULL) ||
((BufferPtr == NULL) && DontUseBuffer) ||
((BlockSize != NULL) && (*BlockSize < PXE_MTFTP_DEFAULT_BLOCK_SIZE)) ||
(!NetIp4IsUnicast (NTOHL (ServerIp->Addr[0]), 0) && !NetIp6IsValidUnicast (&ServerIp->v6))) {
((BlockSize != NULL) && (*BlockSize < PXE_MTFTP_DEFAULT_BLOCK_SIZE))) {
return EFI_INVALID_PARAMETER;
}
@@ -866,6 +865,16 @@ EfiPxeBcMtftp (
Private = PXEBC_PRIVATE_DATA_FROM_PXEBC (This);
Mode = Private->PxeBc.Mode;
if (Mode->UsingIpv6) {
if (!NetIp6IsValidUnicast (&ServerIp->v6)) {
return EFI_INVALID_PARAMETER;
}
} else {
if (IP4_IS_UNSPECIFIED (NTOHL (ServerIp->Addr[0])) || IP4_IS_LOCAL_BROADCAST (NTOHL (ServerIp->Addr[0]))) {
return EFI_INVALID_PARAMETER;
}
}
if (Mode->UsingIpv6) {
//
// Set configuration data for Mtftp6 instance.
@@ -1076,7 +1085,7 @@ EfiPxeBcUdpWrite (
DoNotFragment = TRUE;
}
if (!Mode->UsingIpv6 && GatewayIp != NULL && !NetIp4IsUnicast (NTOHL (GatewayIp->Addr[0]), 0)) {
if (!Mode->UsingIpv6 && GatewayIp != NULL && !NetIp4IsUnicast (NTOHL (GatewayIp->Addr[0]), EFI_NTOHL(Mode->SubnetMask))) {
//
// Gateway is provided but it's not a unicast IPv4 address, while it will be ignored for IPv6.
//
@@ -1587,13 +1596,16 @@ EfiPxeBcSetIpFilter (
//
return EFI_INVALID_PARAMETER;
}
if ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP) != 0 &&
(NetIp4IsUnicast (EFI_IP4 (NewFilter->IpList[Index].v4), 0) ||
NetIp6IsValidUnicast (&NewFilter->IpList[Index].v6))) {
//
// If EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP is set and IPv4/IPv6 address
// is in IpList, promiscuous mode is needed.
//
if (Mode->UsingIpv6) {
if ((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP) != 0 &&
NetIp6IsValidUnicast (&NewFilter->IpList[Index].v6)) {
NeedPromiscuous = TRUE;
}
} else if ((EFI_NTOHL(Mode->StationIp) != 0) &&
(EFI_NTOHL(Mode->SubnetMask) != 0) &&
IP4_NET_EQUAL(EFI_NTOHL(Mode->StationIp), EFI_NTOHL(NewFilter->IpList[Index].v4), EFI_NTOHL(Mode->SubnetMask.v4)) &&
NetIp4IsUnicast (EFI_IP4 (NewFilter->IpList[Index].v4), EFI_NTOHL(Mode->SubnetMask)) &&
((NewFilter->Filters & EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP) != 0)) {
NeedPromiscuous = TRUE;
}
}
@@ -1987,9 +1999,7 @@ EfiPxeBcSetStationIP (
return EFI_INVALID_PARAMETER;
}
if (NewStationIp != NULL &&
(!NetIp4IsUnicast (NTOHL (NewStationIp->Addr[0]), 0) &&
!NetIp6IsValidUnicast (&NewStationIp->v6))) {
if (NewStationIp != NULL && !NetIp6IsValidUnicast (&NewStationIp->v6)) {
return EFI_INVALID_PARAMETER;
}
@@ -2003,6 +2013,10 @@ EfiPxeBcSetStationIP (
return EFI_INVALID_PARAMETER;
}
if (!Mode->UsingIpv6 && NewStationIp != NULL && !NetIp4IsUnicast (NTOHL (NewStationIp->Addr[0]), NTOHL (NewSubnetMask->Addr[0]))) {
return EFI_INVALID_PARAMETER;
}
if (!Mode->Started) {
return EFI_NOT_STARTED;
}