V2 update: Directly use NetIp4IsUnicast() to check station address in IP driver.
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 <Host-number> with only 1 bit. Consequently, only two
possible addresses may result:
{<Network-number>, 0} and {<Network-number>, -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 <siyuan.fu@intel.com>
Reviewed-by: Wu Jiaxin <jiaxin.wu@intel.com>
\r
ASSERT if NetMask is zero.\r
\r
\r
ASSERT if NetMask is zero.\r
\r
- If all bits of the host address of IP are 0 or 1, IP is also not a valid unicast address.\r
-\r
+ If all bits of the host address of IP are 0 or 1, IP is also not a valid unicast address,\r
+ except when the originator is one of the endpoints of a point-to-point link with a 31-bit\r
+ mask (RFC3021).\r
+ \r
@param[in] Ip The IP to check against.\r
@param[in] NetMask The mask of the IP.\r
\r
@param[in] Ip The IP to check against.\r
@param[in] NetMask The mask of the IP.\r
\r
\r
ASSERT if NetMask is zero.\r
\r
\r
ASSERT if NetMask is zero.\r
\r
- If all bits of the host address of IP are 0 or 1, IP is also not a valid unicast address.\r
+ If all bits of the host address of IP are 0 or 1, IP is also not a valid unicast address,\r
+ except when the originator is one of the endpoints of a point-to-point link with a 31-bit\r
+ mask (RFC3021).\r
\r
@param[in] Ip The IP to check against.\r
@param[in] NetMask The mask of the IP.\r
\r
@param[in] Ip The IP to check against.\r
@param[in] NetMask The mask of the IP.\r
if (Ip == 0 || IP4_IS_LOCAL_BROADCAST (Ip)) {\r
return FALSE;\r
}\r
if (Ip == 0 || IP4_IS_LOCAL_BROADCAST (Ip)) {\r
return FALSE;\r
}\r
- \r
- if (((Ip &~NetMask) == ~NetMask) || ((Ip &~NetMask) == 0)) {\r
- return FALSE;\r
+\r
+ if (NetGetMaskLength (NetMask) != 31) {\r
+ if (((Ip &~NetMask) == ~NetMask) || ((Ip &~NetMask) == 0)) {\r
+ return FALSE;\r
+ }\r
+ } else {\r
+ return TRUE;\r
IN IP4_ADDR Netmask\r
)\r
{\r
IN IP4_ADDR Netmask\r
)\r
{\r
- IP4_ADDR NetBrdcastMask;\r
- INTN Len;\r
- INTN Type;\r
-\r
//\r
// Only support the station address with 0.0.0.0/0 to enable DHCP client.\r
//\r
//\r
// Only support the station address with 0.0.0.0/0 to enable DHCP client.\r
//\r
//\r
// Only support the continuous net masks\r
//\r
//\r
// Only support the continuous net masks\r
//\r
- if ((Len = NetGetMaskLength (Netmask)) == (IP4_MASK_MAX + 1)) {\r
+ if (NetGetMaskLength (Netmask) == (IP4_MASK_MAX + 1)) {\r
return FALSE;\r
}\r
\r
//\r
// Station address can't be class D or class E address\r
//\r
return FALSE;\r
}\r
\r
//\r
// Station address can't be class D or class E address\r
//\r
- if ((Type = NetGetIpClass (Ip)) > IP4_ADDR_CLASSC) {\r
- return FALSE;\r
- }\r
-\r
- //\r
- // Station address can't be subnet broadcast/net broadcast address\r
- //\r
- if ((Ip == (Ip & Netmask)) || (Ip == (Ip | ~Netmask))) {\r
+ if (NetGetIpClass (Ip) > IP4_ADDR_CLASSC) {\r
- NetBrdcastMask = gIp4AllMasks[MIN (Len, Type << 3)];\r
-\r
- if (Ip == (Ip | ~NetBrdcastMask)) {\r
- return FALSE;\r
- }\r
-\r
- return TRUE;\r
-}
\ No newline at end of file
+ return NetIp4IsUnicast (Ip, Netmask);\r
+}\r