TianoCore EDK2 master
Loading...
Searching...
No Matches
Ip4Common.h File Reference

Go to the source code of this file.

Macros

#define IP4_ETHER_PROTO   0x0800
 
#define IP4_LINK_BROADCAST   0x00000001
 
#define IP4_LINK_MULTICAST   0x00000002
 
#define IP4_LINK_PROMISC   0x00000004
 
#define IP4_PROMISCUOUS   1
 
#define IP4_LOCAL_HOST   2
 
#define IP4_MULTICAST   3
 
#define IP4_LOCAL_BROADCAST   4
 
#define IP4_SUBNET_BROADCAST   5
 
#define IP4_NET_BROADCAST   6
 
#define IP4_HEAD_DF_MASK   0x4000
 
#define IP4_HEAD_MF_MASK   0x2000
 
#define IP4_HEAD_OFFSET_MASK   0x1fff
 
#define IP4_ALLZERO_ADDRESS   0x00000000u
 
#define IP4_ALLONE_ADDRESS   0xFFFFFFFFu
 
#define IP4_ALLSYSTEM_ADDRESS   0xE0000001u
 
#define IP4_ALLROUTER_ADDRESS   0xE0000002u
 
#define IP4_HEAD_FRAGMENT_FIELD(Df, Mf, Offset)    ((UINT16)(((Df) ? IP4_HEAD_DF_MASK : 0) | ((Mf) ? IP4_HEAD_MF_MASK : 0) | (((Offset) >> 3) & IP4_HEAD_OFFSET_MASK)))
 
#define IP4_LAST_FRAGMENT(FragmentField)    (((FragmentField) & IP4_HEAD_MF_MASK) == 0)
 
#define IP4_FIRST_FRAGMENT(FragmentField)    ((BOOLEAN)(((FragmentField) & IP4_HEAD_OFFSET_MASK) == 0))
 
#define IP4_DO_NOT_FRAGMENT(FragmentField)    ((BOOLEAN)(((FragmentField) & IP4_HEAD_DF_MASK) == IP4_HEAD_DF_MASK))
 
#define IP4_IS_BROADCAST(CastType)   ((CastType) >= IP4_LOCAL_BROADCAST)
 
#define IP4_US_TO_SEC(Us)   (((Us) + 999999) / 1000000)
 

Typedefs

typedef struct _IP4_INTERFACE IP4_INTERFACE
 
typedef struct _IP4_PROTOCOL IP4_PROTOCOL
 
typedef struct _IP4_SERVICE IP4_SERVICE
 

Functions

INTN Ip4GetNetCast (IN IP4_ADDR IpAddr, IN IP4_INTERFACE *IpIf)
 
INTN Ip4GetHostCast (IN IP4_SERVICE *IpSb, IN IP4_ADDR Dst, IN IP4_ADDR Src)
 
IP4_INTERFACEIp4FindInterface (IN IP4_SERVICE *IpSb, IN IP4_ADDR Ip)
 
IP4_INTERFACEIp4FindNet (IN IP4_SERVICE *IpSb, IN IP4_ADDR Ip)
 
IP4_INTERFACEIp4FindStationAddress (IN IP4_SERVICE *IpSb, IN IP4_ADDR Ip, IN IP4_ADDR Netmask)
 
EFI_STATUS Ip4GetMulticastMac (IN EFI_MANAGED_NETWORK_PROTOCOL *Mnp, IN IP4_ADDR Multicast, OUT EFI_MAC_ADDRESS *Mac)
 
IP4_HEADIp4NtohHead (IN IP4_HEAD *Head)
 
BOOLEAN Ip4StationAddressValid (IN IP4_ADDR Ip, IN IP4_ADDR Netmask)
 

Detailed Description

Common definition for IP4.

Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file Ip4Common.h.

Macro Definition Documentation

◆ IP4_ALLONE_ADDRESS

#define IP4_ALLONE_ADDRESS   0xFFFFFFFFu

Definition at line 44 of file Ip4Common.h.

◆ IP4_ALLROUTER_ADDRESS

#define IP4_ALLROUTER_ADDRESS   0xE0000002u

Definition at line 46 of file Ip4Common.h.

◆ IP4_ALLSYSTEM_ADDRESS

#define IP4_ALLSYSTEM_ADDRESS   0xE0000001u

Definition at line 45 of file Ip4Common.h.

◆ IP4_ALLZERO_ADDRESS

#define IP4_ALLZERO_ADDRESS   0x00000000u

Definition at line 43 of file Ip4Common.h.

◆ IP4_DO_NOT_FRAGMENT

#define IP4_DO_NOT_FRAGMENT (   FragmentField)     ((BOOLEAN)(((FragmentField) & IP4_HEAD_DF_MASK) == IP4_HEAD_DF_MASK))

Definition at line 60 of file Ip4Common.h.

◆ IP4_ETHER_PROTO

#define IP4_ETHER_PROTO   0x0800

Definition at line 16 of file Ip4Common.h.

◆ IP4_FIRST_FRAGMENT

#define IP4_FIRST_FRAGMENT (   FragmentField)     ((BOOLEAN)(((FragmentField) & IP4_HEAD_OFFSET_MASK) == 0))

Definition at line 57 of file Ip4Common.h.

◆ IP4_HEAD_DF_MASK

#define IP4_HEAD_DF_MASK   0x4000

Definition at line 39 of file Ip4Common.h.

◆ IP4_HEAD_FRAGMENT_FIELD

#define IP4_HEAD_FRAGMENT_FIELD (   Df,
  Mf,
  Offset 
)     ((UINT16)(((Df) ? IP4_HEAD_DF_MASK : 0) | ((Mf) ? IP4_HEAD_MF_MASK : 0) | (((Offset) >> 3) & IP4_HEAD_OFFSET_MASK)))

Compose the fragment field to be used in the IP4 header.

Definition at line 51 of file Ip4Common.h.

◆ IP4_HEAD_MF_MASK

#define IP4_HEAD_MF_MASK   0x2000

Definition at line 40 of file Ip4Common.h.

◆ IP4_HEAD_OFFSET_MASK

#define IP4_HEAD_OFFSET_MASK   0x1fff

Definition at line 41 of file Ip4Common.h.

◆ IP4_IS_BROADCAST

#define IP4_IS_BROADCAST (   CastType)    ((CastType) >= IP4_LOCAL_BROADCAST)

Definition at line 63 of file Ip4Common.h.

◆ IP4_LAST_FRAGMENT

#define IP4_LAST_FRAGMENT (   FragmentField)     (((FragmentField) & IP4_HEAD_MF_MASK) == 0)

Definition at line 54 of file Ip4Common.h.

◆ IP4_LINK_BROADCAST

#define IP4_LINK_BROADCAST   0x00000001

Definition at line 21 of file Ip4Common.h.

◆ IP4_LINK_MULTICAST

#define IP4_LINK_MULTICAST   0x00000002

Definition at line 22 of file Ip4Common.h.

◆ IP4_LINK_PROMISC

#define IP4_LINK_PROMISC   0x00000004

Definition at line 23 of file Ip4Common.h.

◆ IP4_LOCAL_BROADCAST

#define IP4_LOCAL_BROADCAST   4

Definition at line 32 of file Ip4Common.h.

◆ IP4_LOCAL_HOST

#define IP4_LOCAL_HOST   2

Definition at line 30 of file Ip4Common.h.

◆ IP4_MULTICAST

#define IP4_MULTICAST   3

Definition at line 31 of file Ip4Common.h.

◆ IP4_NET_BROADCAST

#define IP4_NET_BROADCAST   6

Definition at line 34 of file Ip4Common.h.

◆ IP4_PROMISCUOUS

#define IP4_PROMISCUOUS   1

Definition at line 29 of file Ip4Common.h.

◆ IP4_SUBNET_BROADCAST

#define IP4_SUBNET_BROADCAST   5

Definition at line 33 of file Ip4Common.h.

◆ IP4_US_TO_SEC

#define IP4_US_TO_SEC (   Us)    (((Us) + 999999) / 1000000)

Convert the Microsecond to second. IP transmit/receive time is in the unit of microsecond. IP ticks once per second.

Definition at line 69 of file Ip4Common.h.

Typedef Documentation

◆ IP4_INTERFACE

typedef struct _IP4_INTERFACE IP4_INTERFACE

Definition at line 12 of file Ip4Common.h.

◆ IP4_PROTOCOL

typedef struct _IP4_PROTOCOL IP4_PROTOCOL

Definition at line 13 of file Ip4Common.h.

◆ IP4_SERVICE

typedef struct _IP4_SERVICE IP4_SERVICE

Definition at line 14 of file Ip4Common.h.

Function Documentation

◆ Ip4FindInterface()

IP4_INTERFACE * Ip4FindInterface ( IN IP4_SERVICE IpSb,
IN IP4_ADDR  Ip 
)

Find an interface whose configured IP address is Ip.

Parameters
[in]IpSbThe IP4 service binding instance
[in]IpThe Ip address (host byte order) to find
Returns
The IP4_INTERFACE point if found, otherwise NULL

Definition at line 124 of file Ip4Common.c.

◆ Ip4FindNet()

IP4_INTERFACE * Ip4FindNet ( IN IP4_SERVICE IpSb,
IN IP4_ADDR  Ip 
)

Find an interface that Ip is on that connected network.

Parameters
[in]IpSbThe IP4 service binding instance
[in]IpThe Ip address (host byte order) to find
Returns
The IP4_INTERFACE point if found, otherwise NULL

Definition at line 153 of file Ip4Common.c.

◆ Ip4FindStationAddress()

IP4_INTERFACE * Ip4FindStationAddress ( IN IP4_SERVICE IpSb,
IN IP4_ADDR  Ip,
IN IP4_ADDR  Netmask 
)

Find an interface of the service with the same Ip/Netmask pair.

Parameters
[in]IpSbIp4 service binding instance
[in]IpThe Ip address to find (host byte order)
[in]NetmaskThe network to find (host byte order)
Returns
The IP4_INTERFACE point if found, otherwise NULL

Definition at line 183 of file Ip4Common.c.

◆ Ip4GetHostCast()

INTN Ip4GetHostCast ( IN IP4_SERVICE IpSb,
IN IP4_ADDR  Dst,
IN IP4_ADDR  Src 
)

Find the cast type of the packet related to the local host. This isn't the same as link layer cast type. For example, DHCP server may send local broadcast to the local unicast MAC.

Parameters
[in]IpSbThe IP4 service binding instance that received the packet
[in]DstThe destination address in the packet (host byte order)
[in]SrcThe source address in the packet (host byte order)
Returns
The cast type for the Dst, it will return on the first non-promiscuous cast type to a configured interface. If the packet doesn't match any of the interface, multicast address and local broadcast address are checked.

Definition at line 59 of file Ip4Common.c.

◆ Ip4GetMulticastMac()

EFI_STATUS Ip4GetMulticastMac ( IN EFI_MANAGED_NETWORK_PROTOCOL Mnp,
IN IP4_ADDR  Multicast,
OUT EFI_MAC_ADDRESS Mac 
)

Get the MAC address for a multicast IP address. Call Mnp's McastIpToMac to find the MAC address in stead of hard code the NIC to be Ethernet.

Parameters
[in]MnpThe Mnp instance to get the MAC address.
[in]MulticastThe multicast IP address to translate.
[out]MacThe buffer to hold the translated address.
Return values
EFI_SUCCESSif the multicast IP is successfully translated to a multicast MAC address.
otherOtherwise some error.

Definition at line 218 of file Ip4Common.c.

◆ Ip4GetNetCast()

INTN Ip4GetNetCast ( IN IP4_ADDR  IpAddr,
IN IP4_INTERFACE IpIf 
)

Return the cast type (Unicast/Broadcast) specific to an interface. All the addresses are host byte ordered.

Parameters
[in]IpAddrThe IP address to classify in host byte order
[in]IpIfThe interface that IpAddr received from
Returns
The cast type of this IP address specific to the interface.
Return values
IP4_LOCAL_HOSTThe IpAddr equals to the interface's address
IP4_SUBNET_BROADCASTThe IpAddr is a directed subnet broadcast to the interface
IP4_NET_BROADCASTThe IpAddr is a network broadcast to the interface
0Otherwise.

Definition at line 26 of file Ip4Common.c.

◆ Ip4NtohHead()

IP4_HEAD * Ip4NtohHead ( IN IP4_HEAD Head)

Convert the multibyte field in IP header's byter order. In spite of its name, it can also be used to convert from host to network byte order.

Parameters
[in]HeadThe IP head to convert
Returns
Point to the converted IP head

Definition at line 241 of file Ip4Common.c.

◆ Ip4StationAddressValid()

BOOLEAN Ip4StationAddressValid ( IN IP4_ADDR  Ip,
IN IP4_ADDR  Netmask 
)

Validate that Ip/Netmask pair is OK to be used as station address. Only continuous netmasks are supported. and check that StationAddress is a unicast address on the network.

Parameters
[in]IpThe IP address to validate.
[in]NetmaskThe netmask of the IP.
Return values
TRUEThe Ip/Netmask pair is valid.
FALSEThe Ip/Netmask pair is invalid.

Definition at line 267 of file Ip4Common.c.