TianoCore EDK2 master
Loading...
Searching...
No Matches
Ip4Common.c
Go to the documentation of this file.
1
8#include "Ip4Impl.h"
9
25INTN
27 IN IP4_ADDR IpAddr,
28 IN IP4_INTERFACE *IpIf
29 )
30{
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;
37 }
38
39 return 0;
40}
41
58INTN
60 IN IP4_SERVICE *IpSb,
61 IN IP4_ADDR Dst,
62 IN IP4_ADDR Src
63 )
64{
65 LIST_ENTRY *Entry;
66 IP4_INTERFACE *IpIf;
67 INTN Type;
68 INTN Class;
69
70 Type = 0;
71
72 if (IpSb->MnpConfigData.EnablePromiscuousReceive) {
73 Type = IP4_PROMISCUOUS;
74 }
75
76 //
77 // Go through the interface list of the IP service, most likely.
78 //
79 NET_LIST_FOR_EACH (Entry, &IpSb->Interfaces) {
80 IpIf = NET_LIST_USER_STRUCT (Entry, IP4_INTERFACE, Link);
81
82 //
83 // Skip the unconfigured interface and invalid source address:
84 // source address can't be broadcast.
85 //
86 if (!IpIf->Configured || IP4_IS_BROADCAST (Ip4GetNetCast (Src, IpIf))) {
87 continue;
88 }
89
90 if ((Class = Ip4GetNetCast (Dst, IpIf)) > Type) {
91 return Class;
92 }
93 }
94
95 //
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
99 // the group.
100 //
101 if (Dst == IP4_ALLONE_ADDRESS) {
102 IpIf = Ip4FindNet (IpSb, Src);
103
104 if ((IpIf != NULL) && !IP4_IS_BROADCAST (Ip4GetNetCast (Src, IpIf))) {
105 return IP4_LOCAL_BROADCAST;
106 }
107 } else if (IP4_IS_MULTICAST (Dst) && (Ip4FindGroup (&IpSb->IgmpCtrl, Dst) != NULL)) {
108 return IP4_MULTICAST;
109 }
110
111 return Type;
112}
113
125 IN IP4_SERVICE *IpSb,
126 IN IP4_ADDR Ip
127 )
128{
129 LIST_ENTRY *Entry;
130 IP4_INTERFACE *IpIf;
131
132 NET_LIST_FOR_EACH (Entry, &IpSb->Interfaces) {
133 IpIf = NET_LIST_USER_STRUCT (Entry, IP4_INTERFACE, Link);
134
135 if (IpIf->Configured && (IpIf->Ip == Ip)) {
136 return IpIf;
137 }
138 }
139
140 return NULL;
141}
142
154 IN IP4_SERVICE *IpSb,
155 IN IP4_ADDR Ip
156 )
157{
158 LIST_ENTRY *Entry;
159 IP4_INTERFACE *IpIf;
160
161 NET_LIST_FOR_EACH (Entry, &IpSb->Interfaces) {
162 IpIf = NET_LIST_USER_STRUCT (Entry, IP4_INTERFACE, Link);
163
164 if (IpIf->Configured && IP4_NET_EQUAL (Ip, IpIf->Ip, IpIf->SubnetMask)) {
165 return IpIf;
166 }
167 }
168
169 return NULL;
170}
171
184 IN IP4_SERVICE *IpSb,
185 IN IP4_ADDR Ip,
186 IN IP4_ADDR Netmask
187 )
188{
189 LIST_ENTRY *Entry;
190 IP4_INTERFACE *IpIf;
191
192 NET_LIST_FOR_EACH (Entry, &IpSb->Interfaces) {
193 IpIf = NET_LIST_USER_STRUCT (Entry, IP4_INTERFACE, Link);
194
195 if (IpIf->Configured && (IpIf->Ip == Ip) && (IpIf->SubnetMask == Netmask)) {
196 return IpIf;
197 }
198 }
199
200 return NULL;
201}
202
220 IN IP4_ADDR Multicast,
222 )
223{
224 EFI_IP_ADDRESS EfiIp;
225
226 EFI_IP4 (EfiIp.v4) = HTONL (Multicast);
227 return Mnp->McastIpToMac (Mnp, FALSE, &EfiIp, Mac);
228}
229
240IP4_HEAD *
242 IN IP4_HEAD *Head
243 )
244{
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);
250
251 return Head;
252}
253
266BOOLEAN
268 IN IP4_ADDR Ip,
269 IN IP4_ADDR Netmask
270 )
271{
272 //
273 // Only support the station address with 0.0.0.0/0 to enable DHCP client.
274 //
275 if (Netmask == IP4_ALLZERO_ADDRESS) {
276 return (BOOLEAN)(Ip == IP4_ALLZERO_ADDRESS);
277 }
278
279 //
280 // Only support the continuous net masks
281 //
282 if (NetGetMaskLength (Netmask) == (IP4_MASK_MAX + 1)) {
283 return FALSE;
284 }
285
286 //
287 // Station address can't be class D or class E address
288 //
289 if (NetGetIpClass (Ip) > IP4_ADDR_CLASSC) {
290 return FALSE;
291 }
292
293 return NetIp4IsUnicast (Ip, Netmask);
294}
INT64 INTN
INTN Ip4GetHostCast(IN IP4_SERVICE *IpSb, IN IP4_ADDR Dst, IN IP4_ADDR Src)
Definition: Ip4Common.c:59
IP4_INTERFACE * Ip4FindInterface(IN IP4_SERVICE *IpSb, IN IP4_ADDR Ip)
Definition: Ip4Common.c:124
INTN Ip4GetNetCast(IN IP4_ADDR IpAddr, IN IP4_INTERFACE *IpIf)
Definition: Ip4Common.c:26
IP4_HEAD * Ip4NtohHead(IN IP4_HEAD *Head)
Definition: Ip4Common.c:241
IP4_INTERFACE * Ip4FindStationAddress(IN IP4_SERVICE *IpSb, IN IP4_ADDR Ip, IN IP4_ADDR Netmask)
Definition: Ip4Common.c:183
BOOLEAN Ip4StationAddressValid(IN IP4_ADDR Ip, IN IP4_ADDR Netmask)
Definition: Ip4Common.c:267
IP4_INTERFACE * Ip4FindNet(IN IP4_SERVICE *IpSb, IN IP4_ADDR Ip)
Definition: Ip4Common.c:153
EFI_STATUS Ip4GetMulticastMac(IN EFI_MANAGED_NETWORK_PROTOCOL *Mnp, IN IP4_ADDR Multicast, OUT EFI_MAC_ADDRESS *Mac)
Definition: Ip4Common.c:218
IGMP_GROUP * Ip4FindGroup(IN IGMP_SERVICE_DATA *IgmpCtrl, IN IP4_ADDR Address)
Definition: Ip4Igmp.c:89
#define NULL
Definition: Base.h:319
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
BOOLEAN EFIAPI NetIp4IsUnicast(IN IP4_ADDR Ip, IN IP4_ADDR NetMask)
Definition: DxeNetLib.c:683
INTN EFIAPI NetGetIpClass(IN IP4_ADDR Addr)
Definition: DxeNetLib.c:643
INTN EFIAPI NetGetMaskLength(IN IP4_ADDR NetMask)
Definition: DxeNetLib.c:600
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29