42 BOOLEAN FirstFragment;
48 FirstFragment = IP4_FIRST_FRAGMENT (Head->Fragment);
52 HeadLen = IP4_MIN_HEADLEN + Len;
53 ASSERT (((Len % 4) == 0) && (HeadLen <= IP4_MAX_HEADLEN));
57 if (PacketHead ==
NULL) {
58 return EFI_BAD_BUFFER_SIZE;
61 Ip4CopyOption (Option, OptLen, FirstFragment, (UINT8 *)(PacketHead + 1), &Len);
67 PacketHead->HeadLen = (UINT8)(HeadLen >> 2);
68 PacketHead->Tos = Head->Tos;
69 PacketHead->TotalLen = HTONS ((UINT16)Packet->TotalSize);
70 PacketHead->Id = HTONS (Head->Id);
71 PacketHead->Fragment = HTONS (Head->Fragment);
72 PacketHead->Checksum = 0;
73 PacketHead->Ttl = Head->Ttl;
74 PacketHead->Protocol = Head->Protocol;
75 PacketHead->Src = HTONL (Head->Src);
76 PacketHead->Dst = HTONL (Head->Dst);
77 PacketHead->Checksum = (UINT16)(~
NetblockChecksum ((UINT8 *)PacketHead, HeadLen));
79 Packet->Ip.Ip4 = PacketHead;
114 if ((IpIf !=
NULL) && (IpIf->Ip != IP4_ALLZERO_ADDRESS)) {
123 if ((IpIf !=
NULL) && (IpIf->Ip != IP4_ALLZERO_ADDRESS)) {
133 NET_LIST_FOR_EACH (Entry, &IpSb->Interfaces) {
136 if (IpIf->Configured && ((Selected ==
NULL) || (Selected->Ip == 0))) {
234 if (IpInstance ==
NULL) {
237 IpIf = IpInstance->Interface;
241 return EFI_NO_MAPPING;
244 if ((Head->Src == IP4_ALLZERO_ADDRESS) && (IpInstance ==
NULL)) {
245 Head->Src = IpIf->Ip;
252 HeadLen =
sizeof (
IP4_HEAD) + ((OptLen + 3) & (~0x03));
254 if ((IpInstance !=
NULL) && IpInstance->ConfigData.RawData) {
257 Head->HeadLen = (UINT8)(HeadLen >> 2);
276 if (EFI_ERROR (Status)) {
281 if (IP4_IS_BROADCAST (
Ip4GetNetCast (Dest, IpIf)) || (Dest == IP4_ALLONE_ADDRESS)) {
287 GateWay = IP4_ALLONE_ADDRESS;
288 }
else if (IP4_IS_MULTICAST (Dest)) {
295 }
else if (GateWay == IP4_ALLZERO_ADDRESS) {
299 if (IpInstance ==
NULL) {
300 CacheEntry =
Ip4Route (IpSb->DefaultRouteTable, Head->Dst, Head->Src, IpIf->SubnetMask,
TRUE);
302 CacheEntry =
Ip4Route (IpInstance->RouteTable, Head->Dst, Head->Src, IpIf->SubnetMask,
FALSE);
307 if (CacheEntry ==
NULL) {
308 CacheEntry =
Ip4Route (IpSb->DefaultRouteTable, Head->Dst, Head->Src, IpIf->SubnetMask,
TRUE);
312 if (CacheEntry ==
NULL) {
313 return EFI_NOT_FOUND;
316 GateWay = CacheEntry->NextHop;
324 Mtu = IpSb->MaxPacketSize +
sizeof (
IP4_HEAD);
326 if (Packet->TotalSize + HeadLen > Mtu) {
331 return EFI_BAD_BUFFER_SIZE;
340 Mtu = (Mtu - HeadLen) & (~0x07);
341 Num = (Packet->TotalSize + Mtu - 1) / Mtu;
348 PacketLen = Packet->TotalSize - (Num - 1) * Mtu;
349 Offset = Mtu * (Num - 1);
351 for (Index = 0; Index < Num - 1; Index++, Offset -= Mtu) {
354 if (Fragment ==
NULL) {
355 Status = EFI_OUT_OF_RESOURCES;
381 if (EFI_ERROR (Status)) {
421 Status =
Ip4SendFrame (IpIf, IpInstance, Packet, GateWay, Callback, Context, IpSb);
423 if (EFI_ERROR (Status)) {
451 if ((Frame->Packet == (
NET_BUF *)Context) || (Frame->Context == Context)) {
IP4_INTERFACE * Ip4FindInterface(IN IP4_SERVICE *IpSb, IN IP4_ADDR Ip)
INTN Ip4GetNetCast(IN IP4_ADDR IpAddr, IN IP4_INTERFACE *IpIf)
IP4_INTERFACE * Ip4FindNet(IN IP4_SERVICE *IpSb, IN IP4_ADDR Ip)
#define IP4_HEAD_FRAGMENT_FIELD(Df, Mf, Offset)
EFI_STATUS Ip4SendFrame(IN IP4_INTERFACE *Interface, IN IP4_PROTOCOL *IpInstance OPTIONAL, IN NET_BUF *Packet, IN IP4_ADDR NextHop, IN IP4_FRAME_CALLBACK CallBack, IN VOID *Context, IN IP4_SERVICE *IpSb)
VOID Ip4CancelFrames(IN IP4_INTERFACE *Interface, IN EFI_STATUS IoStatus, IN IP4_FRAME_TO_CANCEL FrameToCancel OPTIONAL, IN VOID *Context)
VOID(* IP4_FRAME_CALLBACK)(IN IP4_PROTOCOL *IpInstance OPTIONAL, IN NET_BUF *Packet, IN EFI_STATUS IoStatus, IN UINT32 LinkFlag, IN VOID *Context)
EFI_STATUS Ip4CopyOption(IN UINT8 *Option, IN UINT32 OptionLen, IN BOOLEAN FirstFragment, IN OUT UINT8 *Buf OPTIONAL, IN OUT UINT32 *BufLen)
VOID Ip4SysPacketSent(IP4_PROTOCOL *Ip4Instance, NET_BUF *Packet, EFI_STATUS IoStatus, UINT32 LinkFlag, VOID *Context)
EFI_STATUS Ip4PrependHead(IN OUT NET_BUF *Packet, IN IP4_HEAD *Head, IN UINT8 *Option, IN UINT32 OptLen)
EFI_STATUS Ip4Output(IN IP4_SERVICE *IpSb, IN IP4_PROTOCOL *IpInstance OPTIONAL, IN NET_BUF *Packet, IN IP4_HEAD *Head, IN UINT8 *Option, IN UINT32 OptLen, IN IP4_ADDR GateWay, IN IP4_FRAME_CALLBACK Callback, IN VOID *Context)
BOOLEAN Ip4CancelPacketFragments(IN IP4_LINK_TX_TOKEN *Frame, IN VOID *Context)
IP4_INTERFACE * Ip4SelectInterface(IN IP4_SERVICE *IpSb, IN IP4_ADDR Dst, IN IP4_ADDR Src)
VOID Ip4CancelPacket(IN IP4_INTERFACE *IpIf, IN NET_BUF *Packet, IN EFI_STATUS IoStatus)
VOID Ip4FreeRouteCacheEntry(IN IP4_ROUTE_CACHE_ENTRY *RtCacheEntry)
IP4_ROUTE_CACHE_ENTRY * Ip4Route(IN IP4_ROUTE_TABLE *RtTable, IN IP4_ADDR Dest, IN IP4_ADDR Src, IN IP4_ADDR SubnetMask, IN BOOLEAN AlwaysTryDestAddr)
VOID EFIAPI NetbufFree(IN NET_BUF *Nbuf)
UINT32 EFIAPI NetbufTrim(IN OUT NET_BUF *Nbuf, IN UINT32 Len, IN BOOLEAN FromHead)
UINT16 EFIAPI NetblockChecksum(IN UINT8 *Bulk, IN UINT32 Len)
NET_BUF *EFIAPI NetbufGetFragment(IN NET_BUF *Nbuf, IN UINT32 Offset, IN UINT32 Len, IN UINT32 HeadSpace)
UINT8 *EFIAPI NetbufAllocSpace(IN OUT NET_BUF *Nbuf, IN UINT32 Len, IN BOOLEAN FromHead)