3 Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>
4 SPDX-License-Identifier: BSD-2-Clause-Patent
12 Return the cast type (Unicast/Boradcast) specific to an
13 interface. All the addresses are host byte ordered.
15 @param[in] IpAddr The IP address to classify in host byte order
16 @param[in] IpIf The interface that IpAddr received from
18 @return The cast type of this IP address specific to the interface.
19 @retval IP4_LOCAL_HOST The IpAddr equals to the interface's address
20 @retval IP4_SUBNET_BROADCAST The IpAddr is a directed subnet boradcast to the
22 @retval IP4_NET_BROADCAST The IpAddr is a network broadcast to the interface
29 IN IP4_INTERFACE
*IpIf
32 if (IpAddr
== IpIf
->Ip
) {
33 return IP4_LOCAL_HOST
;
35 } else if (IpAddr
== IpIf
->SubnetBrdcast
) {
36 return IP4_SUBNET_BROADCAST
;
38 } else if (IpAddr
== IpIf
->NetBrdcast
) {
39 return IP4_NET_BROADCAST
;
48 Find the cast type of the packet related to the local host.
49 This isn't the same as link layer cast type. For example, DHCP
50 server may send local broadcast to the local unicast MAC.
52 @param[in] IpSb The IP4 service binding instance that received the
54 @param[in] Dst The destination address in the packet (host byte
56 @param[in] Src The source address in the packet (host byte order)
58 @return The cast type for the Dst, it will return on the first non-promiscuous
59 cast type to a configured interface. If the packet doesn't match any of
60 the interface, multicast address and local broadcast address are checked.
77 if (IpSb
->MnpConfigData
.EnablePromiscuousReceive
) {
78 Type
= IP4_PROMISCUOUS
;
82 // Go through the interface list of the IP service, most likely.
84 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
85 IpIf
= NET_LIST_USER_STRUCT (Entry
, IP4_INTERFACE
, Link
);
88 // Skip the unconfigured interface and invalid source address:
89 // source address can't be broadcast.
91 if (!IpIf
->Configured
|| IP4_IS_BROADCAST (Ip4GetNetCast (Src
, IpIf
))) {
95 if ((Class
= Ip4GetNetCast (Dst
, IpIf
)) > Type
) {
101 // If it is local broadcast address. The source address must
102 // be a unicast address on one of the direct connected network.
103 // If it is a multicast address, accept it only if we are in
106 if (Dst
== IP4_ALLONE_ADDRESS
) {
107 IpIf
= Ip4FindNet (IpSb
, Src
);
109 if (IpIf
!= NULL
&& !IP4_IS_BROADCAST (Ip4GetNetCast (Src
, IpIf
))) {
110 return IP4_LOCAL_BROADCAST
;
113 } else if (IP4_IS_MULTICAST (Dst
) && Ip4FindGroup (&IpSb
->IgmpCtrl
, Dst
) != NULL
) {
114 return IP4_MULTICAST
;
122 Find an interface whose configured IP address is Ip.
124 @param[in] IpSb The IP4 service binding instance
125 @param[in] Ip The Ip address (host byte order) to find
127 @return The IP4_INTERFACE point if found, otherwise NULL
132 IN IP4_SERVICE
*IpSb
,
139 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
140 IpIf
= NET_LIST_USER_STRUCT (Entry
, IP4_INTERFACE
, Link
);
142 if (IpIf
->Configured
&& (IpIf
->Ip
== Ip
)) {
152 Find an interface that Ip is on that connected network.
154 @param[in] IpSb The IP4 service binding instance
155 @param[in] Ip The Ip address (host byte order) to find
157 @return The IP4_INTERFACE point if found, otherwise NULL
162 IN IP4_SERVICE
*IpSb
,
169 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
170 IpIf
= NET_LIST_USER_STRUCT (Entry
, IP4_INTERFACE
, Link
);
172 if (IpIf
->Configured
&& IP4_NET_EQUAL (Ip
, IpIf
->Ip
, IpIf
->SubnetMask
)) {
182 Find an interface of the service with the same Ip/Netmask pair.
184 @param[in] IpSb Ip4 service binding instance
185 @param[in] Ip The Ip adress to find (host byte order)
186 @param[in] Netmask The network to find (host byte order)
188 @return The IP4_INTERFACE point if found, otherwise NULL
192 Ip4FindStationAddress (
193 IN IP4_SERVICE
*IpSb
,
201 NET_LIST_FOR_EACH (Entry
, &IpSb
->Interfaces
) {
202 IpIf
= NET_LIST_USER_STRUCT (Entry
, IP4_INTERFACE
, Link
);
204 if (IpIf
->Configured
&& (IpIf
->Ip
== Ip
) && (IpIf
->SubnetMask
== Netmask
)) {
214 Get the MAC address for a multicast IP address. Call
215 Mnp's McastIpToMac to find the MAC address in stead of
216 hard code the NIC to be Ethernet.
218 @param[in] Mnp The Mnp instance to get the MAC address.
219 @param[in] Multicast The multicast IP address to translate.
220 @param[out] Mac The buffer to hold the translated address.
222 @retval EFI_SUCCESS if the multicast IP is successfully translated to a
223 multicast MAC address.
224 @retval other Otherwise some error.
229 IN EFI_MANAGED_NETWORK_PROTOCOL
*Mnp
,
230 IN IP4_ADDR Multicast
,
231 OUT EFI_MAC_ADDRESS
*Mac
234 EFI_IP_ADDRESS EfiIp
;
236 EFI_IP4 (EfiIp
.v4
) = HTONL (Multicast
);
237 return Mnp
->McastIpToMac (Mnp
, FALSE
, &EfiIp
, Mac
);
242 Convert the multibyte field in IP header's byter order.
243 In spite of its name, it can also be used to convert from
244 host to network byte order.
246 @param[in] Head The IP head to convert
248 @return Point to the converted IP head
256 Head
->TotalLen
= NTOHS (Head
->TotalLen
);
257 Head
->Id
= NTOHS (Head
->Id
);
258 Head
->Fragment
= NTOHS (Head
->Fragment
);
259 Head
->Src
= NTOHL (Head
->Src
);
260 Head
->Dst
= NTOHL (Head
->Dst
);
267 Validate that Ip/Netmask pair is OK to be used as station
268 address. Only continuous netmasks are supported. and check
269 that StationAddress is a unicast address on the newtwork.
271 @param[in] Ip The IP address to validate.
272 @param[in] Netmask The netmaks of the IP.
274 @retval TRUE The Ip/Netmask pair is valid.
275 @retval FALSE The Ip/Netmask pair is invalid.
279 Ip4StationAddressValid (
285 // Only support the station address with 0.0.0.0/0 to enable DHCP client.
287 if (Netmask
== IP4_ALLZERO_ADDRESS
) {
288 return (BOOLEAN
) (Ip
== IP4_ALLZERO_ADDRESS
);
292 // Only support the continuous net masks
294 if (NetGetMaskLength (Netmask
) == (IP4_MASK_MAX
+ 1)) {
299 // Station address can't be class D or class E address
301 if (NetGetIpClass (Ip
) > IP4_ADDR_CLASSC
) {
305 return NetIp4IsUnicast (Ip
, Netmask
);