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

Go to the source code of this file.

Data Structures

struct  DHCP_OPTION
 
struct  DHCP_OPTION_COUNT
 
struct  DHCP_OPTION_CONTEXT
 
struct  DHCP_PARAMETER
 
struct  DHCP_OPTION_FORMAT
 

Macros

#define DHCP_OPTION_MAGIC   0x63538263
 
#define DHCP_MAX_OPTIONS   256
 
#define DHCP_OPTION_SWITCH   1
 
#define DHCP_OPTION_INT8   2
 
#define DHCP_OPTION_INT16   3
 
#define DHCP_OPTION_INT32   4
 
#define DHCP_OPTION_IP   5
 
#define DHCP_OPTION_IPPAIR   6
 
#define DHCP_OVERLOAD_FILENAME   1
 
#define DHCP_OVERLOAD_SVRNAME   2
 
#define DHCP_OVERLOAD_BOTH   3
 

Typedefs

typedef EFI_STATUS(* DHCP_CHECK_OPTION) (IN UINT8 Tag, IN UINT8 Len, IN UINT8 *Data, IN VOID *Context)
 

Functions

EFI_STATUS DhcpIterateOptions (IN EFI_DHCP4_PACKET *Packet, IN DHCP_CHECK_OPTION Check OPTIONAL, IN VOID *Context)
 
EFI_STATUS DhcpValidateOptions (IN EFI_DHCP4_PACKET *Packet, OUT DHCP_PARAMETER **Para OPTIONAL)
 
EFI_STATUS DhcpParseOption (IN EFI_DHCP4_PACKET *Packet, OUT INTN *Count, OUT DHCP_OPTION **OptionPoint)
 
UINT8 * DhcpAppendOption (OUT UINT8 *Buf, IN UINT8 Tag, IN UINT16 DataLen, IN UINT8 *Data)
 
EFI_STATUS DhcpBuild (IN EFI_DHCP4_PACKET *SeedPacket, IN UINT32 DeleteCount, IN UINT8 *DeleteList OPTIONAL, IN UINT32 AppendCount, IN EFI_DHCP4_PACKET_OPTION *AppendList[] OPTIONAL, OUT EFI_DHCP4_PACKET **NewPacket)
 

Detailed Description

To validate, parse and process the DHCP options.

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

Definition in file Dhcp4Option.h.

Macro Definition Documentation

◆ DHCP_MAX_OPTIONS

#define DHCP_MAX_OPTIONS   256

Definition at line 17 of file Dhcp4Option.h.

◆ DHCP_OPTION_INT16

#define DHCP_OPTION_INT16   3

Definition at line 24 of file Dhcp4Option.h.

◆ DHCP_OPTION_INT32

#define DHCP_OPTION_INT32   4

Definition at line 25 of file Dhcp4Option.h.

◆ DHCP_OPTION_INT8

#define DHCP_OPTION_INT8   2

Definition at line 23 of file Dhcp4Option.h.

◆ DHCP_OPTION_IP

#define DHCP_OPTION_IP   5

Definition at line 26 of file Dhcp4Option.h.

◆ DHCP_OPTION_IPPAIR

#define DHCP_OPTION_IPPAIR   6

Definition at line 27 of file Dhcp4Option.h.

◆ DHCP_OPTION_MAGIC

#define DHCP_OPTION_MAGIC   0x63538263

DHCP option tags (types)

Definition at line 16 of file Dhcp4Option.h.

◆ DHCP_OPTION_SWITCH

#define DHCP_OPTION_SWITCH   1

Definition at line 22 of file Dhcp4Option.h.

◆ DHCP_OVERLOAD_BOTH

#define DHCP_OVERLOAD_BOTH   3

Definition at line 34 of file Dhcp4Option.h.

◆ DHCP_OVERLOAD_FILENAME

#define DHCP_OVERLOAD_FILENAME   1

Definition at line 32 of file Dhcp4Option.h.

◆ DHCP_OVERLOAD_SVRNAME

#define DHCP_OVERLOAD_SVRNAME   2

Definition at line 33 of file Dhcp4Option.h.

Typedef Documentation

◆ DHCP_CHECK_OPTION

typedef EFI_STATUS(* DHCP_CHECK_OPTION) (IN UINT8 Tag, IN UINT8 Len, IN UINT8 *Data, IN VOID *Context)

Definition at line 97 of file Dhcp4Option.h.

Function Documentation

◆ DhcpAppendOption()

UINT8 * DhcpAppendOption ( OUT UINT8 *  Buf,
IN UINT8  Tag,
IN UINT16  DataLen,
IN UINT8 *  Data 
)

Append an option to the memory, if the option is longer than 255 bytes, splits it into several options.

Parameters
[out]BufThe buffer to append the option to
[in]TagThe option's tag
[in]DataLenThe length of the option's data
[in]DataThe option's data
Returns
The position to append the next option

Definition at line 727 of file Dhcp4Option.c.

◆ DhcpBuild()

EFI_STATUS DhcpBuild ( IN EFI_DHCP4_PACKET SeedPacket,
IN UINT32  DeleteCount,
IN UINT8 *DeleteList  OPTIONAL,
IN UINT32  AppendCount,
IN EFI_DHCP4_PACKET_OPTION *AppendList[]  OPTIONAL,
OUT EFI_DHCP4_PACKET **  NewPacket 
)

Build a new DHCP packet from a seed packet. Options may be deleted or appended. The caller should free the NewPacket when finished using it.

Parameters
[in]SeedPacketThe seed packet to start with
[in]DeleteCountThe number of options to delete
[in]DeleteListThe options to delete from the packet
[in]AppendCountThe number of options to append
[in]AppendListThe options to append to the packet
[out]NewPacketThe new packet, allocated and built by this function.
Return values
EFI_OUT_OF_RESOURCESFailed to allocate memory
EFI_INVALID_PARAMETERThe options in SeekPacket are mal-formatted
EFI_SUCCESSThe packet is build.

Definition at line 770 of file Dhcp4Option.c.

◆ DhcpIterateOptions()

EFI_STATUS DhcpIterateOptions ( IN EFI_DHCP4_PACKET Packet,
IN DHCP_CHECK_OPTION Check  OPTIONAL,
IN VOID *  Context 
)

Iterate through a DHCP message to visit each option. First inspect all the options in the OPTION field. Then if overloaded, inspect the options in FILENAME and SERVERNAME fields. One option may be encoded in several places. See RFC 3396 Encoding Long Options in DHCP

Parameters
[in]PacketThe DHCP packet to check the options for
[in]CheckThe callback function to be called for each option found
[in]ContextThe opaque parameter for Check
Return values
EFI_SUCCESSThe DHCP packet's options are well formatted
EFI_INVALID_PARAMETERThe DHCP packet's options are not well formatted

Definition at line 382 of file Dhcp4Option.c.

◆ DhcpParseOption()

EFI_STATUS DhcpParseOption ( IN EFI_DHCP4_PACKET Packet,
OUT INTN Count,
OUT DHCP_OPTION **  OptionPoint 
)

Parse the options of a DHCP packet. It supports RFC 3396: Encoding Long Options in DHCP. That is, it will combine all the option value of all the occurrences of each option. A little bit of implementation: It adopts the "Key indexed counting" algorithm. First, it allocates an array of 256 DHCP_OPTION_COUNTs because DHCP option tag is encoded as a UINT8. It then iterates the DHCP packet to get data length of each option by calling DhcpIterOptions with DhcpGetOptionLen. Now, it knows the number of present options and their length. It allocates a array of DHCP_OPTION and a continuous buffer after the array to put all the options' data. Each option's data is pointed to by the Data field in DHCP_OPTION structure. At last, it call DhcpIterateOptions with DhcpFillOption to fill each option's data to its position in the buffer.

Parameters
[in]PacketThe DHCP packet to parse the options
[out]CountThe number of valid dhcp options present in the packet
[out]OptionPointThe array that contains the DHCP options. Caller should free it.
Return values
EFI_NOT_FOUNDCannot find any option.
EFI_OUT_OF_RESOURCESFailed to allocate memory to parse the packet.
EFI_INVALID_PARAMETERThe options are mal-formatted
EFI_SUCCESSThe options are parsed into OptionPoint

Definition at line 541 of file Dhcp4Option.c.

◆ DhcpValidateOptions()

EFI_STATUS DhcpValidateOptions ( IN EFI_DHCP4_PACKET Packet,
OUT DHCP_PARAMETER **Para  OPTIONAL 
)

Validate the packet's options. If necessary, allocate and fill in the interested parameters.

Parameters
[in]PacketThe packet to validate the options
[out]ParaThe variable to save the DHCP parameters.
Return values
EFI_OUT_OF_RESOURCESFailed to allocate memory to validate the packet.
EFI_INVALID_PARAMETERThe options are mal-formatted
EFI_SUCCESSThe options are parsed into OptionPoint

Definition at line 641 of file Dhcp4Option.c.