3 Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>
4 SPDX-License-Identifier: BSD-2-Clause-Patent
11 Return the cast type (Unicast/Broadcast) specific to an
12 interface. All the addresses are host byte ordered.
14 @param[in] IpAddr The IP address to classify in host byte order
15 @param[in] IpIf The interface that IpAddr received from
17 @return The cast type of this IP address specific to the interface.
18 @retval IP4_LOCAL_HOST The IpAddr equals to the interface's address
19 @retval IP4_SUBNET_BROADCAST The IpAddr is a directed subnet broadcast to the
21 @retval IP4_NET_BROADCAST The IpAddr is a network broadcast to the interface
28 IN IP4_INTERFACE
*IpIf
31 if (IpAddr
== IpIf
->Ip
) {
32 return IP4_LOCAL_HOST
;
33 } else if (IpAddr
== IpIf
->SubnetBrdcast
) {
34 return IP4_SUBNET_BROADCAST
;
35 } else if (IpAddr
== IpIf
->NetBrdcast
) {
36 return IP4_NET_BROADCAST
;
43 Find the cast type of the packet related to the local host.
44 This isn't the same as link layer cast type. For example, DHCP
45 server may send local broadcast to the local unicast MAC.
47 @param[in] IpSb The IP4 service binding instance that received the
49 @param[in] Dst The destination address in the packet (host byte
51 @param[in] Src The source address in the packet (host byte order)
53 @return The cast type for the Dst, it will return on the first non-promiscuous
54 cast type to a configured interface. If the packet doesn't match any of
55 the interface, multicast address and local broadcast address are checked.
72 if (IpSb
->MnpConfigData
.EnablePromiscuousReceive
) {
73 Type
= IP4_PROMISCUOUS
;
77 // Go through the interface list of the IP service, most likely.
79 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
80 IpIf
= NET_LIST_USER_STRUCT (Entry
, IP4_INTERFACE
, Link
);
83 // Skip the unconfigured interface and invalid source address:
84 // source address can't be broadcast.
86 if (!IpIf
->Configured
|| IP4_IS_BROADCAST (Ip4GetNetCast (Src
, IpIf
))) {
90 if ((Class
= Ip4GetNetCast (Dst
, IpIf
)) > Type
) {
96 // If it is local broadcast address. The source address must
97 // be a unicast address on one of the direct connected network.
98 // If it is a multicast address, accept it only if we are in
101 if (Dst
== IP4_ALLONE_ADDRESS
) {
102 IpIf
= Ip4FindNet (IpSb
, Src
);
104 if ((IpIf
!= NULL
) && !IP4_IS_BROADCAST (Ip4GetNetCast (Src
, IpIf
))) {
105 return IP4_LOCAL_BROADCAST
;
107 } else if (IP4_IS_MULTICAST (Dst
) && (Ip4FindGroup (&IpSb
->IgmpCtrl
, Dst
) != NULL
)) {
108 return IP4_MULTICAST
;
115 Find an interface whose configured IP address is Ip.
117 @param[in] IpSb The IP4 service binding instance
118 @param[in] Ip The Ip address (host byte order) to find
120 @return The IP4_INTERFACE point if found, otherwise NULL
125 IN IP4_SERVICE
*IpSb
,
132 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
133 IpIf
= NET_LIST_USER_STRUCT (Entry
, IP4_INTERFACE
, Link
);
135 if (IpIf
->Configured
&& (IpIf
->Ip
== Ip
)) {
144 Find an interface that Ip is on that connected network.
146 @param[in] IpSb The IP4 service binding instance
147 @param[in] Ip The Ip address (host byte order) to find
149 @return The IP4_INTERFACE point if found, otherwise NULL
154 IN IP4_SERVICE
*IpSb
,
161 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
162 IpIf
= NET_LIST_USER_STRUCT (Entry
, IP4_INTERFACE
, Link
);
164 if (IpIf
->Configured
&& IP4_NET_EQUAL (Ip
, IpIf
->Ip
, IpIf
->SubnetMask
)) {
173 Find an interface of the service with the same Ip/Netmask pair.
175 @param[in] IpSb Ip4 service binding instance
176 @param[in] Ip The Ip address to find (host byte order)
177 @param[in] Netmask The network to find (host byte order)
179 @return The IP4_INTERFACE point if found, otherwise NULL
183 Ip4FindStationAddress (
184 IN IP4_SERVICE
*IpSb
,
192 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
193 IpIf
= NET_LIST_USER_STRUCT (Entry
, IP4_INTERFACE
, Link
);
195 if (IpIf
->Configured
&& (IpIf
->Ip
== Ip
) && (IpIf
->SubnetMask
== Netmask
)) {
204 Get the MAC address for a multicast IP address. Call
205 Mnp's McastIpToMac to find the MAC address in stead of
206 hard code the NIC to be Ethernet.
208 @param[in] Mnp The Mnp instance to get the MAC address.
209 @param[in] Multicast The multicast IP address to translate.
210 @param[out] Mac The buffer to hold the translated address.
212 @retval EFI_SUCCESS if the multicast IP is successfully translated to a
213 multicast MAC address.
214 @retval other Otherwise some error.
219 IN EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
,
220 IN IP4_ADDR Multicast
,
221 OUT EFI_MAC_ADDRESS
*Mac
224 EFI_IP_ADDRESS EfiIp
;
226 EFI_IP4 (EfiIp
.v4
) = HTONL (Multicast
);
227 return Mnp
->McastIpToMac (Mnp
, FALSE
, &EfiIp
, Mac
);
231 Convert the multibyte field in IP header's byter order.
232 In spite of its name, it can also be used to convert from
233 host to network byte order.
235 @param[in] Head The IP head to convert
237 @return Point to the converted IP head
245 Head
->TotalLen
= NTOHS (Head
->TotalLen
);
246 Head
->Id
= NTOHS (Head
->Id
);
247 Head
->Fragment
= NTOHS (Head
->Fragment
);
248 Head
->Src
= NTOHL (Head
->Src
);
249 Head
->Dst
= NTOHL (Head
->Dst
);
255 Validate that Ip/Netmask pair is OK to be used as station
256 address. Only continuous netmasks are supported. and check
257 that StationAddress is a unicast address on the network.
259 @param[in] Ip The IP address to validate.
260 @param[in] Netmask The netmask of the IP.
262 @retval TRUE The Ip/Netmask pair is valid.
263 @retval FALSE The Ip/Netmask pair is invalid.
267 Ip4StationAddressValid (
273 // Only support the station address with 0.0.0.0/0 to enable DHCP client.
275 if (Netmask
== IP4_ALLZERO_ADDRESS
) {
276 return (BOOLEAN
)(Ip
== IP4_ALLZERO_ADDRESS
);
280 // Only support the continuous net masks
282 if (NetGetMaskLength (Netmask
) == (IP4_MASK_MAX
+ 1)) {
287 // Station address can't be class D or class E address
289 if (NetGetIpClass (Ip
) > IP4_ADDR_CLASSC
) {
293 return NetIp4IsUnicast (Ip
, Netmask
);