TianoCore EDK2 master
Loading...
Searching...
No Matches
Dhcp4Option.c File Reference
#include "Dhcp4Impl.h"

Go to the source code of this file.

Functions

DHCP_OPTION_FORMATDhcpFindOptionFormat (IN UINT8 Tag)
 
BOOLEAN DhcpOptionIsValid (IN DHCP_OPTION_FORMAT *Format, IN UINT8 *OptValue, IN INTN Len)
 
EFI_STATUS DhcpGetParameter (IN UINT8 Tag, IN INTN Len, IN UINT8 *Data, OUT DHCP_PARAMETER *Para)
 
EFI_STATUS DhcpIterateBufferOptions (IN UINT8 *Buffer, IN INTN BufLen, IN DHCP_CHECK_OPTION Check OPTIONAL, IN VOID *Context, OUT UINT8 *Overload OPTIONAL)
 
EFI_STATUS DhcpIterateOptions (IN EFI_DHCP4_PACKET *Packet, IN DHCP_CHECK_OPTION Check OPTIONAL, IN VOID *Context)
 
EFI_STATUS DhcpGetOptionLen (IN UINT8 Tag, IN UINT8 Len, IN UINT8 *Data, IN VOID *Context)
 
EFI_STATUS DhcpFillOption (IN UINT8 Tag, IN UINT8 Len, IN UINT8 *Data, IN VOID *Context)
 
EFI_STATUS DhcpParseOption (IN EFI_DHCP4_PACKET *Packet, OUT INTN *Count, OUT DHCP_OPTION **OptionPoint)
 
EFI_STATUS DhcpValidateOptions (IN EFI_DHCP4_PACKET *Packet, OUT DHCP_PARAMETER **Para OPTIONAL)
 
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)
 

Variables

DHCP_OPTION_FORMAT DhcpOptionFormats []
 

Detailed Description

Function to validate, parse, process the DHCP options.

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

Definition in file Dhcp4Option.c.

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.

◆ DhcpFillOption()

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

Call back function to DhcpIterateOptions to consolidate each option's data. There are maybe several occurrence of the same option.

Parameters
[in]TagThe option to consolidate its data
[in]LenThe length of option data
[in]DataThe data of the option's current occurrence
[in]ContextThe context, which is DHCP_OPTION_CONTEXT. This array is just a wrap to pass THREE parameters.
Return values
EFI_SUCCESSIt always returns EFI_SUCCESS

Definition at line 480 of file Dhcp4Option.c.

◆ DhcpFindOptionFormat()

DHCP_OPTION_FORMAT * DhcpFindOptionFormat ( IN UINT8  Tag)

Binary search the DhcpOptionFormats array to find the format information about a specific option.

Parameters
[in]TagThe option's tag.
Returns
The point to the option's format, NULL if not found.

Definition at line 114 of file Dhcp4Option.c.

◆ DhcpGetOptionLen()

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

Call back function to DhcpIterateOptions to compute each option's length. It just adds the data length of all the occurrences of this Tag. Context is an array of 256 DHCP_OPTION_COUNT.

Parameters
[in]TagThe current option to check
[in]LenThe length of the option data
[in]DataThe option data
[in]ContextThe context, which is a array of 256 DHCP_OPTION_COUNT.
Return values
EFI_SUCCESSIt always returns EFI_SUCCESS.

Definition at line 451 of file Dhcp4Option.c.

◆ DhcpGetParameter()

EFI_STATUS DhcpGetParameter ( IN UINT8  Tag,
IN INTN  Len,
IN UINT8 *  Data,
OUT DHCP_PARAMETER Para 
)

Extract the client interested options, all the parameters are converted to host byte order.

Parameters
[in]TagThe DHCP option tag
[in]LenThe length of the option
[in]DataThe value of the DHCP option
[out]ParaThe variable to save the interested parameter
Return values
EFI_SUCCESSThe DHCP option is successfully extracted.
EFI_INVALID_PARAMETERThe DHCP option is mal-formatted

Definition at line 235 of file Dhcp4Option.c.

◆ DhcpIterateBufferOptions()

EFI_STATUS DhcpIterateBufferOptions ( IN UINT8 *  Buffer,
IN INTN  BufLen,
IN DHCP_CHECK_OPTION Check  OPTIONAL,
IN VOID *  Context,
OUT UINT8 *Overload  OPTIONAL 
)

Inspect all the options in a single buffer. DHCP options may be contained in several buffers, such as the BOOTP options filed, boot file or server name. Each option buffer is required to end with DHCP4_TAG_EOP.

Parameters
[in]BufferThe buffer which contains DHCP options
[in]BufLenThe length of the buffer
[in]CheckThe callback function for each option found
[in]ContextThe opaque parameter for the Check
[out]OverloadVariable to save the value of DHCP4_TAG_OVERLOAD option.
Return values
EFI_SUCCESSAll the options are valid
EFI_INVALID_PARAMETERThe options are mal-formatted.

Definition at line 309 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.

◆ DhcpOptionIsValid()

BOOLEAN DhcpOptionIsValid ( IN DHCP_OPTION_FORMAT Format,
IN UINT8 *  OptValue,
IN INTN  Len 
)

Validate whether a single DHCP option is valid according to its format.

Parameters
[in]FormatThe option's format
[in]OptValueThe value of the option
[in]LenThe length of the option value
Return values
TRUEThe option is valid.
FALSEOtherwise.

Definition at line 154 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.

Variable Documentation

◆ DhcpOptionFormats

DHCP_OPTION_FORMAT DhcpOptionFormats[]

A list of the format of DHCP Options sorted by option tag to validate a dhcp message. Refere the comments of the DHCP_OPTION_FORMAT structure.

Definition at line 16 of file Dhcp4Option.c.