iPXE
Data Structures | Macros | Enumerations | Functions | Variables
dhcp.h File Reference

Dynamic Host Configuration Protocol. More...

#include <stdint.h>
#include <stdarg.h>
#include <ipxe/in.h>
#include <ipxe/list.h>
#include <ipxe/refcnt.h>
#include <ipxe/tables.h>
#include <ipxe/uuid.h>
#include <ipxe/netdevice.h>
#include <ipxe/uaccess.h>

Go to the source code of this file.

Data Structures

struct  dhcp_pxe_boot_server
 PXE boot server. More...
 
struct  dhcp_pxe_boot_menu
 PXE boot menu. More...
 
struct  dhcp_pxe_boot_menu_prompt
 PXE boot menu prompt. More...
 
struct  dhcp_pxe_boot_menu_item
 PXE boot menu item. More...
 
struct  dhcp_client_id
 Client identifier. More...
 
struct  dhcp_client_architecture
 DHCP client architecture. More...
 
struct  dhcp_client_uuid
 UUID client identifier. More...
 
struct  dhcp_netdev_desc
 Network device descriptor. More...
 
struct  dhcp_option
 A DHCP option. More...
 
struct  dhcphdr
 A DHCP header. More...
 

Macros

#define BOOTPS_PORT   67
 BOOTP/DHCP server port. More...
 
#define BOOTPC_PORT   68
 BOOTP/DHCP client port. More...
 
#define PXE_PORT   4011
 PXE server port. More...
 
#define DHCP_ENCAP_OPT(encapsulator, encapsulated)   ( ( (encapsulator) << 8 ) | (encapsulated) )
 Construct a tag value for an encapsulated option. More...
 
#define DHCP_ENCAPSULATOR(encap_opt)   ( (encap_opt) >> 8 )
 Extract encapsulating option block tag from encapsulated tag value. More...
 
#define DHCP_ENCAPSULATED(encap_opt)   ( (encap_opt) & 0xff )
 Extract encapsulated option tag from encapsulated tag value. More...
 
#define DHCP_IS_ENCAP_OPT(opt)   DHCP_ENCAPSULATOR( opt )
 Option is encapsulated. More...
 
#define DHCP_PAD   0
 Padding. More...
 
#define DHCP_MIN_OPTION   1
 Minimum normal DHCP option. More...
 
#define DHCP_SUBNET_MASK   1
 Subnet mask. More...
 
#define DHCP_ROUTERS   3
 Routers. More...
 
#define DHCP_DNS_SERVERS   6
 DNS servers. More...
 
#define DHCP_LOG_SERVERS   7
 Syslog servers. More...
 
#define DHCP_HOST_NAME   12
 Host name. More...
 
#define DHCP_DOMAIN_NAME   15
 Domain name. More...
 
#define DHCP_ROOT_PATH   17
 Root path. More...
 
#define DHCP_MTU   26
 Maximum transmission unit. More...
 
#define DHCP_NTP_SERVERS   42
 NTP servers. More...
 
#define DHCP_VENDOR_ENCAP   43
 Vendor encapsulated options. More...
 
#define DHCP_PXE_DISCOVERY_CONTROL   DHCP_ENCAP_OPT ( DHCP_VENDOR_ENCAP, 6 )
 PXE boot server discovery control. More...
 
#define DHCP_PXE_BOOT_SERVER_MCAST   DHCP_ENCAP_OPT ( DHCP_VENDOR_ENCAP, 7 )
 PXE boot server multicast address. More...
 
#define DHCP_PXE_BOOT_SERVERS   DHCP_ENCAP_OPT ( DHCP_VENDOR_ENCAP, 8 )
 PXE boot servers. More...
 
#define DHCP_PXE_BOOT_MENU   DHCP_ENCAP_OPT ( DHCP_VENDOR_ENCAP, 9 )
 PXE boot menu. More...
 
#define DHCP_PXE_BOOT_MENU_PROMPT   DHCP_ENCAP_OPT ( DHCP_VENDOR_ENCAP, 10 )
 PXE boot menu prompt. More...
 
#define DHCP_PXE_BOOT_MENU_ITEM   DHCP_ENCAP_OPT ( DHCP_VENDOR_ENCAP, 71 )
 PXE boot menu item. More...
 
#define DHCP_REQUESTED_ADDRESS   50
 Requested IP address. More...
 
#define DHCP_LEASE_TIME   51
 Lease time. More...
 
#define DHCP_OPTION_OVERLOAD   52
 Option overloading. More...
 
#define DHCP_OPTION_OVERLOAD_FILE   1
 The "file" field is overloaded to contain extra DHCP options. More...
 
#define DHCP_OPTION_OVERLOAD_SNAME   2
 The "sname" field is overloaded to contain extra DHCP options. More...
 
#define DHCP_MESSAGE_TYPE   53
 DHCP message type. More...
 
#define DHCPNONE   0
 
#define DHCPDISCOVER   1
 
#define DHCPOFFER   2
 
#define DHCPREQUEST   3
 
#define DHCPDECLINE   4
 
#define DHCPACK   5
 
#define DHCPNAK   6
 
#define DHCPRELEASE   7
 
#define DHCPINFORM   8
 
#define DHCP_SERVER_IDENTIFIER   54
 DHCP server identifier. More...
 
#define DHCP_PARAMETER_REQUEST_LIST   55
 Parameter request list. More...
 
#define DHCP_MAX_MESSAGE_SIZE   57
 Maximum DHCP message size. More...
 
#define DHCP_VENDOR_CLASS_ID   60
 Vendor class identifier. More...
 
#define DHCP_VENDOR_PXECLIENT(arch, ndi)
 Vendor class identifier for PXE clients. More...
 
#define DHCP_VENDOR_PXECLIENT_ARCH(arch)
 Vendor class identifier architecture for PXE clients. More...
 
#define DHCP_VENDOR_PXECLIENT_UNDI(type, major, minor)
 Vendor class identifier UNDI version for PXE clients. More...
 
#define DHCP_VENDOR_PXECLIENT_UNDI_VERSION(version)
 
#define DHCP_CLIENT_ID   61
 Client identifier. More...
 
#define DHCP_TFTP_SERVER_NAME   66
 TFTP server name. More...
 
#define DHCP_BOOTFILE_NAME   67
 Bootfile name. More...
 
#define DHCP_USER_CLASS_ID   77
 User class identifier. More...
 
#define DHCP_CLIENT_ARCHITECTURE   93
 Client system architecture. More...
 
#define DHCP_CLIENT_NDI   94
 Client network device interface. More...
 
#define DHCP_CLIENT_UUID   97
 UUID client identifier. More...
 
#define DHCP_CLIENT_UUID_TYPE   0
 
#define DHCP_DOMAIN_SEARCH   119
 DNS domain search list. More...
 
#define DHCP_EB_ENCAP   175
 Etherboot-specific encapsulated options. More...
 
#define DHCP_EB_PRIORITY   DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x01 )
 Priority of this options block. More...
 
#define DHCP_EB_YIADDR   DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x02 )
 "Your" IP address More...
 
#define DHCP_EB_SIADDR   DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x03 )
 "Server" IP address More...
 
#define DHCP_EB_KEEP_SAN   DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x08 )
 Keep SAN drive registered. More...
 
#define DHCP_EB_SKIP_SAN_BOOT   DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x09 )
 Skip booting from SAN drive. More...
 
#define DHCP_EB_SCRIPTLET   DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x51 )
 Scriptlet. More...
 
#define DHCP_EB_SYSLOGS_SERVER   DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x55 )
 Encrypted syslog server. More...
 
#define DHCP_EB_TRUST   DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x5a )
 Trusted root certficate fingerprints. More...
 
#define DHCP_EB_CERT   DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x5b )
 Client certficate. More...
 
#define DHCP_EB_KEY   DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x5c )
 Client private key. More...
 
#define DHCP_EB_CROSS_CERT   DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0x5d )
 Cross-signed certificate source. More...
 
#define DHCP_EB_NO_PXEDHCP   DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xb0 )
 Skip PXE DHCP protocol extensions such as ProxyDHCP. More...
 
#define DHCP_EB_BUS_ID   DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xb1 )
 Network device descriptor. More...
 
#define DHCP_EB_USE_CACHED   DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xb2 )
 Use cached network settings (obsolete; do not reuse this value) More...
 
#define DHCP_EB_SAN_RETRY   DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xbb )
 SAN retry count. More...
 
#define DHCP_EB_SAN_FILENAME   DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xbc )
 SAN filename. More...
 
#define DHCP_EB_SAN_DRIVE   DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xbd )
 SAN drive number. More...
 
#define DHCP_EB_USERNAME   DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xbe )
 Username. More...
 
#define DHCP_EB_PASSWORD   DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xbf )
 Password. More...
 
#define DHCP_EB_REVERSE_USERNAME   DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xc0 )
 Reverse username. More...
 
#define DHCP_EB_REVERSE_PASSWORD   DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xc1 )
 Reverse password. More...
 
#define DHCP_EB_UID   DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xc2 )
 User ID. More...
 
#define DHCP_EB_GID   DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xc3 )
 Group ID. More...
 
#define DHCP_EB_VERSION   DHCP_ENCAP_OPT ( DHCP_EB_ENCAP, 0xeb )
 iPXE version number More...
 
#define DHCP_ISCSI_PRIMARY_TARGET_IQN   201
 iSCSI primary target IQN More...
 
#define DHCP_ISCSI_SECONDARY_TARGET_IQN   202
 iSCSI secondary target IQN More...
 
#define DHCP_ISCSI_INITIATOR_IQN   203
 iSCSI initiator IQN More...
 
#define DHCP_MAX_OPTION   254
 Maximum normal DHCP option. More...
 
#define DHCP_END   255
 End of options. More...
 
#define DHCP_OPTION(...)   VA_ARG_COUNT ( __VA_ARGS__ ), __VA_ARGS__
 Construct a DHCP option from a list of bytes. More...
 
#define DHCP_STRING(...)   DHCP_OPTION ( __VA_ARGS__ )
 Construct a DHCP option from a list of characters. More...
 
#define DHCP_BYTE(value)   DHCP_OPTION ( value )
 Construct a byte-valued DHCP option. More...
 
#define DHCP_WORD(value)
 Construct a word-valued DHCP option. More...
 
#define DHCP_DWORD(value)
 Construct a dword-valued DHCP option. More...
 
#define DHCP_ENCAP(...)   DHCP_OPTION ( __VA_ARGS__, DHCP_END )
 Construct a DHCP encapsulated options field. More...
 
#define DHCP_OPTION_HEADER_LEN   ( offsetof ( struct dhcp_option, data ) )
 Length of a DHCP option header. More...
 
#define DHCP_MAX_LEN   0xff
 Maximum length for a single DHCP option. More...
 
#define BOOTP_REQUEST   1
 Opcode for a request from client to server. More...
 
#define BOOTP_REPLY   2
 Opcode for a reply from server to client. More...
 
#define BOOTP_FL_BROADCAST   0x8000
 BOOTP reply must be broadcast. More...
 
#define DHCP_MAGIC_COOKIE   0x63825363UL
 DHCP magic cookie. More...
 
#define DHCP_MIN_LEN   552
 DHCP minimum packet length. More...
 
#define DHCP_SETTINGS_NAME   "dhcp"
 Settings block name used for DHCP responses. More...
 
#define PROXYDHCP_SETTINGS_NAME   "proxydhcp"
 Settings block name used for ProxyDHCP responses. More...
 
#define PXEBS_SETTINGS_NAME   "pxebs"
 Setting block name used for BootServerDHCP responses. More...
 

Enumerations

enum  dhcp_pxe_discovery_control { PXEBS_NO_BROADCAST = 1, PXEBS_NO_MULTICAST = 2, PXEBS_NO_UNKNOWN_SERVERS = 4, PXEBS_SKIP = 8 }
 PXE boot server discovery control bits. More...
 
enum  dhcp_client_architecture_values {
  DHCP_CLIENT_ARCHITECTURE_X86 = 0x0000, DHCP_CLIENT_ARCHITECTURE_PC98 = 0x0001, DHCP_CLIENT_ARCHITECTURE_IA64 = 0x0002, DHCP_CLIENT_ARCHITECTURE_ALPHA = 0x0003,
  DHCP_CLIENT_ARCHITECTURE_ARCX86 = 0x0004, DHCP_CLIENT_ARCHITECTURE_LC = 0x0005, DHCP_CLIENT_ARCHITECTURE_IA32 = 0x0006, DHCP_CLIENT_ARCHITECTURE_X86_64 = 0x0007,
  DHCP_CLIENT_ARCHITECTURE_XSCALE = 0x0008, DHCP_CLIENT_ARCHITECTURE_EFI = 0x0009, DHCP_CLIENT_ARCHITECTURE_ARM32 = 0x000a, DHCP_CLIENT_ARCHITECTURE_ARM64 = 0x000b,
  DHCP_CLIENT_ARCHITECTURE_RISCV32 = 0x0019, DHCP_CLIENT_ARCHITECTURE_RISCV64 = 0x001b, DHCP_CLIENT_ARCHITECTURE_RISCV128 = 0x001d, DHCP_CLIENT_ARCHITECTURE_MIPS32 = 0x0021,
  DHCP_CLIENT_ARCHITECTURE_MIPS64 = 0x0022, DHCP_CLIENT_ARCHITECTURE_SUNWAY32 = 0x0023, DHCP_CLIENT_ARCHITECTURE_SUNWAY64 = 0x0024, DHCP_CLIENT_ARCHITECTURE_LOONG32 = 0x0025,
  DHCP_CLIENT_ARCHITECTURE_LOONG64 = 0x0027
}
 DHCP client architecture values. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
int dhcp_create_packet (struct dhcp_packet *dhcppkt, struct net_device *netdev, uint8_t msgtype, uint32_t xid, const void *options, size_t options_len, void *data, size_t max_len)
 Create a DHCP packet. More...
 
int dhcp_create_request (struct dhcp_packet *dhcppkt, struct net_device *netdev, unsigned int msgtype, uint32_t xid, struct in_addr ciaddr, void *data, size_t max_len)
 Create DHCP request packet. More...
 
int start_dhcp (struct interface *job, struct net_device *netdev)
 Start DHCP state machine on a network device. More...
 
int start_pxebs (struct interface *job, struct net_device *netdev, unsigned int pxe_type)
 Start PXE Boot Server Discovery on a network device. More...
 

Variables

uint32_t dhcp_last_xid
 Most recent DHCP transaction ID. More...
 

Detailed Description

Dynamic Host Configuration Protocol.

Definition in file dhcp.h.

Macro Definition Documentation

◆ BOOTPS_PORT

#define BOOTPS_PORT   67

BOOTP/DHCP server port.

Definition at line 27 of file dhcp.h.

◆ BOOTPC_PORT

#define BOOTPC_PORT   68

BOOTP/DHCP client port.

Definition at line 30 of file dhcp.h.

◆ PXE_PORT

#define PXE_PORT   4011

PXE server port.

Definition at line 33 of file dhcp.h.

◆ DHCP_ENCAP_OPT

#define DHCP_ENCAP_OPT (   encapsulator,
  encapsulated 
)    ( ( (encapsulator) << 8 ) | (encapsulated) )

Construct a tag value for an encapsulated option.

This tag value can be passed to Etherboot functions when searching for DHCP options in order to search for a tag within an encapsulated options block.

Definition at line 41 of file dhcp.h.

◆ DHCP_ENCAPSULATOR

#define DHCP_ENCAPSULATOR (   encap_opt)    ( (encap_opt) >> 8 )

Extract encapsulating option block tag from encapsulated tag value.

Definition at line 44 of file dhcp.h.

◆ DHCP_ENCAPSULATED

#define DHCP_ENCAPSULATED (   encap_opt)    ( (encap_opt) & 0xff )

Extract encapsulated option tag from encapsulated tag value.

Definition at line 46 of file dhcp.h.

◆ DHCP_IS_ENCAP_OPT

#define DHCP_IS_ENCAP_OPT (   opt)    DHCP_ENCAPSULATOR( opt )

Option is encapsulated.

Definition at line 48 of file dhcp.h.

◆ DHCP_OPTION

#define DHCP_OPTION (   ...)    VA_ARG_COUNT ( __VA_ARGS__ ), __VA_ARGS__

Construct a DHCP option from a list of bytes.

Definition at line 551 of file dhcp.h.

◆ DHCP_STRING

#define DHCP_STRING (   ...)    DHCP_OPTION ( __VA_ARGS__ )

Construct a DHCP option from a list of characters.

Definition at line 554 of file dhcp.h.

◆ DHCP_BYTE

#define DHCP_BYTE (   value)    DHCP_OPTION ( value )

Construct a byte-valued DHCP option.

Definition at line 557 of file dhcp.h.

◆ DHCP_WORD

#define DHCP_WORD (   value)
Value:
DHCP_OPTION ( ( ( (value) >> 8 ) & 0xff ), \
( ( (value) >> 0 ) & 0xff ) )
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
#define DHCP_OPTION(...)
Construct a DHCP option from a list of bytes.
Definition: dhcp.h:551

Construct a word-valued DHCP option.

Definition at line 560 of file dhcp.h.

◆ DHCP_DWORD

#define DHCP_DWORD (   value)
Value:
DHCP_OPTION ( ( ( (value) >> 24 ) & 0xff ), \
( ( (value) >> 16 ) & 0xff ), \
( ( (value) >> 8 ) & 0xff ), \
( ( (value) >> 0 ) & 0xff ) )
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
#define DHCP_OPTION(...)
Construct a DHCP option from a list of bytes.
Definition: dhcp.h:551

Construct a dword-valued DHCP option.

Definition at line 564 of file dhcp.h.

◆ DHCP_ENCAP

#define DHCP_ENCAP (   ...)    DHCP_OPTION ( __VA_ARGS__, DHCP_END )

Construct a DHCP encapsulated options field.

Definition at line 570 of file dhcp.h.

◆ DHCP_OPTION_HEADER_LEN

#define DHCP_OPTION_HEADER_LEN   ( offsetof ( struct dhcp_option, data ) )

Length of a DHCP option header.

The header is the portion excluding the data, i.e. the tag and the length.

Definition at line 604 of file dhcp.h.

◆ DHCP_MAX_LEN

#define DHCP_MAX_LEN   0xff

Maximum length for a single DHCP option.

Definition at line 607 of file dhcp.h.

◆ BOOTP_REQUEST

#define BOOTP_REQUEST   1

Opcode for a request from client to server.

Definition at line 685 of file dhcp.h.

◆ BOOTP_REPLY

#define BOOTP_REPLY   2

Opcode for a reply from server to client.

Definition at line 688 of file dhcp.h.

◆ BOOTP_FL_BROADCAST

#define BOOTP_FL_BROADCAST   0x8000

BOOTP reply must be broadcast.

Clients that cannot accept unicast BOOTP replies must set this flag.

Definition at line 695 of file dhcp.h.

◆ DHCP_MAGIC_COOKIE

#define DHCP_MAGIC_COOKIE   0x63825363UL

DHCP magic cookie.

Definition at line 698 of file dhcp.h.

◆ DHCP_MIN_LEN

#define DHCP_MIN_LEN   552

DHCP minimum packet length.

This is the mandated minimum packet length that a DHCP participant must be prepared to receive.

Definition at line 705 of file dhcp.h.

◆ DHCP_SETTINGS_NAME

#define DHCP_SETTINGS_NAME   "dhcp"

Settings block name used for DHCP responses.

Definition at line 708 of file dhcp.h.

◆ PROXYDHCP_SETTINGS_NAME

#define PROXYDHCP_SETTINGS_NAME   "proxydhcp"

Settings block name used for ProxyDHCP responses.

Definition at line 711 of file dhcp.h.

◆ PXEBS_SETTINGS_NAME

#define PXEBS_SETTINGS_NAME   "pxebs"

Setting block name used for BootServerDHCP responses.

Definition at line 714 of file dhcp.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ dhcp_create_packet()

int dhcp_create_packet ( struct dhcp_packet dhcppkt,
struct net_device netdev,
uint8_t  msgtype,
uint32_t  xid,
const void *  options,
size_t  options_len,
void *  data,
size_t  max_len 
)

Create a DHCP packet.

Parameters
dhcppktDHCP packet structure to fill in
netdevNetwork device
msgtypeDHCP message type
xidTransaction ID (in network-endian order)
optionsInitial options to include (or NULL)
options_lenLength of initial options
dataBuffer for DHCP packet
max_lenSize of DHCP packet buffer
Return values
rcReturn status code

Creates a DHCP packet in the specified buffer, and initialise a DHCP packet structure.

Definition at line 944 of file dhcp.c.

947  {
948  struct dhcphdr *dhcphdr = data;
949  int rc;
950 
951  /* Sanity check */
952  if ( max_len < ( sizeof ( *dhcphdr ) + options_len ) )
953  return -ENOSPC;
954 
955  /* Initialise DHCP packet content */
956  memset ( dhcphdr, 0, max_len );
957  dhcphdr->xid = xid;
960  dhcphdr->op = dhcp_op[msgtype];
964  memcpy ( dhcphdr->options, options, options_len );
965 
966  /* If the local link-layer address functions only as a name
967  * (i.e. cannot be used as a destination address), then
968  * request broadcast responses.
969  */
972 
973  /* If the network device already has an IPv4 address then
974  * unicast responses from the DHCP server may be rejected, so
975  * request broadcast responses.
976  */
977  if ( ipv4_has_any_addr ( netdev ) )
979 
980  /* Initialise DHCP packet structure */
981  memset ( dhcppkt, 0, sizeof ( *dhcppkt ) );
982  dhcppkt_init ( dhcppkt, data, max_len );
983 
984  /* Set DHCP_MESSAGE_TYPE option */
985  if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_MESSAGE_TYPE,
986  &msgtype, sizeof ( msgtype ) ) ) != 0 )
987  return rc;
988 
989  return 0;
990 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint8_t ll_addr_len
Link-layer address length.
Definition: netdevice.h:198
uint16_t max_len
Maximum length (in bytes)
Definition: ntlm.h:18
uint8_t htype
Hardware address type.
Definition: dhcp.h:625
#define LL_NAME_ONLY
Local link-layer address functions only as a name.
Definition: netdevice.h:210
#define BOOTP_FL_BROADCAST
BOOTP reply must be broadcast.
Definition: dhcp.h:695
#define DHCP_MESSAGE_TYPE
DHCP message type.
Definition: dhcp.h:196
uint8_t options[0]
DHCP options.
Definition: dhcp.h:681
uint32_t xid
Transaction ID.
Definition: dhcp.h:631
#define ntohs(value)
Definition: byteswap.h:136
static const uint8_t dhcp_op[]
DHCP operation types.
Definition: dhcp.c:69
#define htonl(value)
Definition: byteswap.h:133
void * memcpy(void *dest, const void *src, size_t len) __nonnull
uint16_t flags
Flags.
Definition: dhcp.h:635
int ipv4_has_any_addr(struct net_device *netdev)
Check if network device has any IPv4 address.
Definition: ipv4.c:443
uint8_t op
Operation.
Definition: dhcp.h:618
static int options
Definition: 3c515.c:286
#define DHCP_MAGIC_COOKIE
DHCP magic cookie.
Definition: dhcp.h:698
static struct net_device * netdev
Definition: gdbudp.c:52
uint8_t chaddr[16]
Client hardware address.
Definition: dhcp.h:659
int dhcppkt_store(struct dhcp_packet *dhcppkt, unsigned int tag, const void *data, size_t len)
Store value of DHCP packet setting.
Definition: dhcppkt.c:164
unsigned int flags
Flags.
Definition: netdevice.h:202
uint16_t ll_proto
Link-layer protocol.
Definition: netdevice.h:194
A DHCP header.
Definition: dhcp.h:613
void dhcppkt_init(struct dhcp_packet *dhcppkt, struct dhcphdr *data, size_t len)
Initialise DHCP packet.
Definition: dhcppkt.c:300
#define ENOSPC
No space left on device.
Definition: errno.h:549
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint32_t magic
DHCP magic cookie.
Definition: dhcp.h:674
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:387
uint8_t hlen
Hardware address length.
Definition: dhcp.h:627
#define htons(value)
Definition: byteswap.h:135
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372
void * memset(void *dest, int character, size_t len) __nonnull

References BOOTP_FL_BROADCAST, dhcphdr::chaddr, data, DHCP_MAGIC_COOKIE, DHCP_MESSAGE_TYPE, dhcp_op, dhcppkt_init(), dhcppkt_store(), ENOSPC, ll_protocol::flags, dhcphdr::flags, dhcphdr::hlen, htonl, htons, dhcphdr::htype, ipv4_has_any_addr(), net_device::ll_addr, ll_protocol::ll_addr_len, LL_NAME_ONLY, ll_protocol::ll_proto, net_device::ll_protocol, dhcphdr::magic, max_len, memcpy(), memset(), netdev, ntohs, dhcphdr::op, options, dhcphdr::options, rc, and dhcphdr::xid.

Referenced by create_fakedhcpack(), create_fakepxebsack(), and dhcp_create_request().

◆ dhcp_create_request()

int dhcp_create_request ( struct dhcp_packet dhcppkt,
struct net_device netdev,
unsigned int  msgtype,
uint32_t  xid,
struct in_addr  ciaddr,
void *  data,
size_t  max_len 
)

Create DHCP request packet.

Parameters
dhcppktDHCP packet structure to fill in
netdevNetwork device
msgtypeDHCP message type
xidTransaction ID (in network-endian order)
ciaddrClient IP address
dataBuffer for DHCP packet
max_lenSize of DHCP packet buffer
Return values
rcReturn status code

Creates a DHCP request packet in the specified buffer, and initialise a DHCP packet structure.

Definition at line 1007 of file dhcp.c.

1010  {
1011  struct dhcp_netdev_desc dhcp_desc;
1012  struct dhcp_client_id client_id;
1013  struct dhcp_client_uuid client_uuid;
1014  const struct setting *setting;
1015  uint8_t *dhcp_features;
1016  size_t dhcp_features_len;
1017  size_t ll_addr_len;
1018  void *raw;
1019  ssize_t len;
1020  unsigned int i;
1021  int rc;
1022 
1023  /* Create DHCP packet */
1024  if ( ( rc = dhcp_create_packet ( dhcppkt, netdev, msgtype, xid,
1026  sizeof ( dhcp_request_options_data ),
1027  data, max_len ) ) != 0 ) {
1028  DBG ( "DHCP could not create DHCP packet: %s\n",
1029  strerror ( rc ) );
1030  goto err_create_packet;
1031  }
1032 
1033  /* Set client IP address */
1034  dhcppkt->dhcphdr->ciaddr = ciaddr;
1035 
1036  /* Add options to identify the feature list */
1037  dhcp_features = table_start ( DHCP_FEATURES );
1038  dhcp_features_len = table_num_entries ( DHCP_FEATURES );
1039  if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_EB_ENCAP, dhcp_features,
1040  dhcp_features_len ) ) != 0 ) {
1041  DBG ( "DHCP could not set features list option: %s\n",
1042  strerror ( rc ) );
1043  goto err_store_features;
1044  }
1045 
1046  /* Add options to identify the network device */
1047  fetch_raw_setting ( netdev_settings ( netdev ), &busid_setting,
1048  &dhcp_desc, sizeof ( dhcp_desc ) );
1049  if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_EB_BUS_ID, &dhcp_desc,
1050  sizeof ( dhcp_desc ) ) ) != 0 ) {
1051  DBG ( "DHCP could not set bus ID option: %s\n",
1052  strerror ( rc ) );
1053  goto err_store_busid;
1054  }
1055 
1056  /* Add DHCP client identifier. Required for Infiniband, and
1057  * doesn't hurt other link layers.
1058  */
1059  client_id.ll_proto = ntohs ( netdev->ll_protocol->ll_proto );
1060  ll_addr_len = netdev->ll_protocol->ll_addr_len;
1061  assert ( ll_addr_len <= sizeof ( client_id.ll_addr ) );
1062  memcpy ( client_id.ll_addr, netdev->ll_addr, ll_addr_len );
1063  if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_CLIENT_ID, &client_id,
1064  ( ll_addr_len + 1 ) ) ) != 0 ) {
1065  DBG ( "DHCP could not set client ID: %s\n",
1066  strerror ( rc ) );
1067  goto err_store_client_id;
1068  }
1069 
1070  /* Add client UUID, if we have one. Required for PXE. The
1071  * PXE spec does not specify a byte ordering for UUIDs, but
1072  * RFC4578 suggests that it follows the EFI spec, in which the
1073  * first three fields are little-endian.
1074  */
1075  client_uuid.type = DHCP_CLIENT_UUID_TYPE;
1076  if ( ( len = fetch_uuid_setting ( NULL, &uuid_setting,
1077  &client_uuid.uuid ) ) >= 0 ) {
1078  uuid_mangle ( &client_uuid.uuid );
1079  if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_CLIENT_UUID,
1080  &client_uuid,
1081  sizeof ( client_uuid ) ) ) != 0 ) {
1082  DBG ( "DHCP could not set client UUID: %s\n",
1083  strerror ( rc ) );
1084  goto err_store_client_uuid;
1085  }
1086  }
1087 
1088  /* Add request settings, if applicable */
1089  for ( i = 0 ; i < ( sizeof ( dhcp_request_settings ) /
1090  sizeof ( dhcp_request_settings[0] ) ) ; i++ ) {
1092  if ( ( len = fetch_raw_setting_copy ( NULL, setting,
1093  &raw ) ) >= 0 ) {
1094  rc = dhcppkt_store ( dhcppkt, setting->tag, raw, len );
1095  free ( raw );
1096  if ( rc != 0 ) {
1097  DBG ( "DHCP could not set %s: %s\n",
1098  setting->name, strerror ( rc ) );
1099  goto err_store_raw;
1100  }
1101  }
1102  }
1103 
1104  err_store_raw:
1105  err_store_client_uuid:
1106  err_store_client_id:
1107  err_store_busid:
1108  err_store_features:
1109  err_create_packet:
1110  return rc;
1111 }
#define DHCP_FEATURES
DHCP feature table.
Definition: features.h:62
#define DHCP_CLIENT_UUID
UUID client identifier.
Definition: dhcp.h:333
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint8_t ll_addr_len
Link-layer address length.
Definition: netdevice.h:198
#define table_start(table)
Get start of linker table.
Definition: tables.h:282
#define DHCP_EB_ENCAP
Etherboot-specific encapsulated options.
Definition: dhcp.h:354
static const struct setting * dhcp_request_settings[]
Settings copied in to all DHCP requests.
Definition: dhcp.c:104
int fetch_raw_setting_copy(struct settings *settings, const struct setting *setting, void **data)
Fetch value of setting.
Definition: settings.c:821
uint16_t max_len
Maximum length (in bytes)
Definition: ntlm.h:18
int fetch_raw_setting(struct settings *settings, const struct setting *setting, void *data, size_t len)
Fetch value of setting.
Definition: settings.c:803
static uint8_t dhcp_request_options_data[]
Raw option data for options common to all DHCP requests.
Definition: dhcp.c:81
#define ntohs(value)
Definition: byteswap.h:136
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition: netdevice.h:583
const char * name
Name.
Definition: settings.h:28
int dhcp_create_packet(struct dhcp_packet *dhcppkt, struct net_device *netdev, uint8_t msgtype, uint32_t xid, const void *options, size_t options_len, void *data, size_t max_len)
Create a DHCP packet.
Definition: dhcp.c:944
static void uuid_mangle(union uuid *uuid)
Change UUID endianness.
Definition: uuid.h:43
uint64_t tag
Setting tag, if applicable.
Definition: settings.h:43
void * memcpy(void *dest, const void *src, size_t len) __nonnull
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static struct net_device * netdev
Definition: gdbudp.c:52
struct in_addr ciaddr
"Client" IP address
Definition: dhcp.h:641
#define DHCP_CLIENT_UUID_TYPE
Definition: dhcp.h:343
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
Client identifier.
Definition: dhcp.h:246
Network device descriptor.
Definition: dhcp.h:446
int dhcppkt_store(struct dhcp_packet *dhcppkt, unsigned int tag, const void *data, size_t len)
Store value of DHCP packet setting.
Definition: dhcppkt.c:164
unsigned char uint8_t
Definition: stdint.h:10
uint16_t ll_proto
Link-layer protocol.
Definition: netdevice.h:194
A setting.
Definition: settings.h:23
UUID client identifier.
Definition: dhcp.h:336
#define DHCP_CLIENT_ID
Client identifier.
Definition: dhcp.h:243
struct dhcphdr * dhcphdr
The DHCP packet contents.
Definition: dhcppkt.h:24
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22
__be32 raw[7]
Definition: CIB_PRM.h:28
int fetch_uuid_setting(struct settings *settings, const struct setting *setting, union uuid *uuid)
Fetch value of UUID setting.
Definition: settings.c:1084
signed long ssize_t
Definition: stdint.h:7
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:387
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define DHCP_EB_BUS_ID
Network device descriptor.
Definition: dhcp.h:443
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372
#define table_num_entries(table)
Get number of entries in linker table.
Definition: tables.h:335

References assert(), dhcphdr::ciaddr, data, DBG, DHCP_CLIENT_ID, DHCP_CLIENT_UUID, DHCP_CLIENT_UUID_TYPE, dhcp_create_packet(), DHCP_EB_BUS_ID, DHCP_EB_ENCAP, DHCP_FEATURES, dhcp_request_options_data, dhcp_request_settings, dhcp_packet::dhcphdr, dhcppkt_store(), fetch_raw_setting(), fetch_raw_setting_copy(), fetch_uuid_setting(), free, len, dhcp_client_id::ll_addr, net_device::ll_addr, ll_protocol::ll_addr_len, ll_protocol::ll_proto, dhcp_client_id::ll_proto, net_device::ll_protocol, max_len, memcpy(), setting::name, netdev, netdev_settings(), ntohs, NULL, raw, rc, strerror(), table_num_entries, table_start, setting::tag, dhcp_client_uuid::type, dhcp_client_uuid::uuid, and uuid_mangle().

Referenced by create_fakedhcpdiscover(), and dhcp_tx().

◆ start_dhcp()

int start_dhcp ( struct interface job,
struct net_device netdev 
)

Start DHCP state machine on a network device.

Parameters
jobJob control interface
netdevNetwork device
Return values
rcReturn status code

Starts DHCP on the specified network device. If successful, the DHCPACK (and ProxyDHCPACK, if applicable) will be registered as option sources.

Definition at line 1357 of file dhcp.c.

1357  {
1358  struct dhcp_session *dhcp;
1359  int rc;
1360 
1361  /* Allocate and initialise structure */
1362  dhcp = zalloc ( sizeof ( *dhcp ) );
1363  if ( ! dhcp )
1364  return -ENOMEM;
1365  ref_init ( &dhcp->refcnt, dhcp_free );
1366  intf_init ( &dhcp->job, &dhcp_job_desc, &dhcp->refcnt );
1367  intf_init ( &dhcp->xfer, &dhcp_xfer_desc, &dhcp->refcnt );
1368  timer_init ( &dhcp->timer, dhcp_timer_expired, &dhcp->refcnt );
1369  dhcp->netdev = netdev_get ( netdev );
1370  dhcp->local.sin_family = AF_INET;
1371  dhcp->local.sin_port = htons ( BOOTPC_PORT );
1372  dhcp->xid = random();
1373 
1374  /* Store DHCP transaction ID for fakedhcp code */
1375  dhcp_last_xid = dhcp->xid;
1376 
1377  /* Instantiate child objects and attach to our interfaces */
1378  if ( ( rc = xfer_open_socket ( &dhcp->xfer, SOCK_DGRAM, &dhcp_peer,
1379  ( struct sockaddr * ) &dhcp->local ) ) != 0 )
1380  goto err;
1381 
1382  /* Enter DHCPDISCOVER state */
1384 
1385  /* Attach parent interface, mortalise self, and return */
1386  intf_plug_plug ( &dhcp->job, job );
1387  ref_put ( &dhcp->refcnt );
1388  return 0;
1389 
1390  err:
1391  dhcp_finished ( dhcp, rc );
1392  ref_put ( &dhcp->refcnt );
1393  return rc;
1394 }
static void dhcp_set_state(struct dhcp_session *dhcp, struct dhcp_session_state *state)
Transition to new DHCP session state.
Definition: dhcp.c:284
static void dhcp_free(struct refcnt *refcnt)
Free DHCP session.
Definition: dhcp.c:253
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void dhcp_timer_expired(struct retry_timer *timer, int fail)
Handle DHCP retry timer expiry.
Definition: dhcp.c:1297
static void dhcp_finished(struct dhcp_session *dhcp, int rc)
Mark DHCP session as complete.
Definition: dhcp.c:268
struct retry_timer timer
Retransmission timer.
Definition: dhcp.c:241
static struct interface_descriptor dhcp_job_desc
DHCP job control interface descriptor.
Definition: dhcp.c:1326
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
int xfer_open_socket(struct interface *intf, int semantics, struct sockaddr *peer, struct sockaddr *local)
Open socket.
Definition: open.c:142
#define SOCK_DGRAM
Definition: socket.h:29
static struct sockaddr dhcp_peer
DHCP peer address for socket opening.
Definition: dhcp.c:1342
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:107
A DHCP session.
Definition: dhcp.c:200
struct refcnt refcnt
Reference counter.
Definition: dhcp.c:202
struct interface job
Job control interface.
Definition: dhcp.c:204
sa_family_t sin_family
Socket address family (part of struct sockaddr)
Definition: in.h:89
uint32_t xid
Transaction ID (in network-endian order)
Definition: dhcp.c:215
struct sockaddr_in local
Local socket address.
Definition: dhcp.c:211
#define ENOMEM
Not enough space.
Definition: errno.h:534
static struct interface_descriptor dhcp_xfer_desc
DHCP data transfer interface descriptor.
Definition: dhcp.c:1288
static struct net_device * netdev
Definition: gdbudp.c:52
Generalized socket address structure.
Definition: socket.h:96
struct interface xfer
Data transfer interface.
Definition: dhcp.c:206
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
uint16_t sin_port
TCP/IP port (part of struct sockaddr_tcpip)
Definition: in.h:93
long int random(void)
Generate a pseudo-random number between 0 and 2147483647L or 2147483562?
Definition: random.c:31
static struct net_device * netdev_get(struct net_device *netdev)
Get reference to network device.
Definition: netdevice.h:561
uint32_t dhcp_last_xid
Most recent DHCP transaction ID.
Definition: dhcp.c:124
static struct dhcp_session_state dhcp_state_discover
DHCP discovery state operations.
Definition: dhcp.c:194
#define BOOTPC_PORT
BOOTP/DHCP client port.
Definition: dhcp.h:30
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:203
#define htons(value)
Definition: byteswap.h:135
#define AF_INET
IPv4 Internet addresses.
Definition: socket.h:63
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106
struct net_device * netdev
Network device being configured.
Definition: dhcp.c:209

References AF_INET, BOOTPC_PORT, dhcp_finished(), dhcp_free(), dhcp_job_desc, dhcp_last_xid, dhcp_peer, dhcp_set_state(), dhcp_state_discover, dhcp_timer_expired(), dhcp_xfer_desc, ENOMEM, htons, intf_init(), intf_plug_plug(), dhcp_session::job, dhcp_session::local, netdev, dhcp_session::netdev, netdev_get(), random(), rc, ref_init, ref_put, dhcp_session::refcnt, sockaddr_in::sin_family, sockaddr_in::sin_port, SOCK_DGRAM, dhcp_session::timer, dhcp_session::xfer, xfer_open_socket(), dhcp_session::xid, and zalloc().

◆ start_pxebs()

int start_pxebs ( struct interface job,
struct net_device netdev,
unsigned int  pxe_type 
)

Start PXE Boot Server Discovery on a network device.

Parameters
jobJob control interface
netdevNetwork device
pxe_typePXE server type
Return values
rcReturn status code

Starts PXE Boot Server Discovery on the specified network device. If successful, the Boot Server ACK will be registered as an option source.

Definition at line 1447 of file dhcp.c.

1448  {
1449  struct setting pxe_discovery_control_setting =
1451  struct setting pxe_boot_servers_setting =
1452  { .tag = DHCP_PXE_BOOT_SERVERS };
1453  struct setting pxe_boot_server_mcast_setting =
1455  ssize_t pxebs_list_len;
1456  struct dhcp_session *dhcp;
1457  struct in_addr *ip;
1458  unsigned int pxe_discovery_control;
1459  int rc;
1460 
1461  /* Get upper bound for PXE boot server IP address list */
1462  pxebs_list_len = fetch_raw_setting ( NULL, &pxe_boot_servers_setting,
1463  NULL, 0 );
1464  if ( pxebs_list_len < 0 )
1465  pxebs_list_len = 0;
1466 
1467  /* Allocate and initialise structure */
1468  dhcp = zalloc ( sizeof ( *dhcp ) + sizeof ( *ip ) /* mcast */ +
1469  sizeof ( *ip ) /* bcast */ + pxebs_list_len +
1470  sizeof ( *ip ) /* terminator */ );
1471  if ( ! dhcp )
1472  return -ENOMEM;
1473  ref_init ( &dhcp->refcnt, dhcp_free );
1474  intf_init ( &dhcp->job, &dhcp_job_desc, &dhcp->refcnt );
1475  intf_init ( &dhcp->xfer, &dhcp_xfer_desc, &dhcp->refcnt );
1476  timer_init ( &dhcp->timer, dhcp_timer_expired, &dhcp->refcnt );
1477  dhcp->netdev = netdev_get ( netdev );
1478  dhcp->local.sin_family = AF_INET;
1479  fetch_ipv4_setting ( netdev_settings ( netdev ), &ip_setting,
1480  &dhcp->local.sin_addr );
1481  dhcp->local.sin_port = htons ( BOOTPC_PORT );
1482  dhcp->pxe_type = cpu_to_le16 ( pxe_type );
1483 
1484  /* Construct PXE boot server IP address lists */
1485  pxe_discovery_control =
1486  fetch_uintz_setting ( NULL, &pxe_discovery_control_setting );
1487  ip = ( ( ( void * ) dhcp ) + sizeof ( *dhcp ) );
1488  dhcp->pxe_attempt = ip;
1489  if ( ! ( pxe_discovery_control & PXEBS_NO_MULTICAST ) ) {
1490  fetch_ipv4_setting ( NULL, &pxe_boot_server_mcast_setting, ip);
1491  if ( ip->s_addr )
1492  ip++;
1493  }
1494  if ( ! ( pxe_discovery_control & PXEBS_NO_BROADCAST ) )
1495  (ip++)->s_addr = INADDR_BROADCAST;
1496  if ( pxe_discovery_control & PXEBS_NO_UNKNOWN_SERVERS )
1497  dhcp->pxe_accept = ip;
1498  if ( pxebs_list_len ) {
1499  uint8_t buf[pxebs_list_len];
1500 
1501  fetch_raw_setting ( NULL, &pxe_boot_servers_setting,
1502  buf, sizeof ( buf ) );
1503  pxebs_list ( dhcp, buf, sizeof ( buf ), ip );
1504  }
1505  if ( ! dhcp->pxe_attempt->s_addr ) {
1506  DBGC ( dhcp, "DHCP %p has no PXE boot servers for type %04x\n",
1507  dhcp, pxe_type );
1508  rc = -EINVAL;
1509  goto err;
1510  }
1511 
1512  /* Dump out PXE server lists */
1513  DBGC ( dhcp, "DHCP %p attempting", dhcp );
1514  for ( ip = dhcp->pxe_attempt ; ip->s_addr ; ip++ )
1515  DBGC ( dhcp, " %s", inet_ntoa ( *ip ) );
1516  DBGC ( dhcp, "\n" );
1517  if ( dhcp->pxe_accept ) {
1518  DBGC ( dhcp, "DHCP %p accepting", dhcp );
1519  for ( ip = dhcp->pxe_accept ; ip->s_addr ; ip++ )
1520  DBGC ( dhcp, " %s", inet_ntoa ( *ip ) );
1521  DBGC ( dhcp, "\n" );
1522  }
1523 
1524  /* Instantiate child objects and attach to our interfaces */
1525  if ( ( rc = xfer_open_socket ( &dhcp->xfer, SOCK_DGRAM, &dhcp_peer,
1526  ( struct sockaddr * ) &dhcp->local ) ) != 0 )
1527  goto err;
1528 
1529  /* Enter PXEBS state */
1530  dhcp_set_state ( dhcp, &dhcp_state_pxebs );
1531 
1532  /* Attach parent interface, mortalise self, and return */
1533  intf_plug_plug ( &dhcp->job, job );
1534  ref_put ( &dhcp->refcnt );
1535  return 0;
1536 
1537  err:
1538  dhcp_finished ( dhcp, rc );
1539  ref_put ( &dhcp->refcnt );
1540  return rc;
1541 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
static void dhcp_set_state(struct dhcp_session *dhcp, struct dhcp_session_state *state)
Transition to new DHCP session state.
Definition: dhcp.c:284
static void dhcp_free(struct refcnt *refcnt)
Free DHCP session.
Definition: dhcp.c:253
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void dhcp_timer_expired(struct retry_timer *timer, int fail)
Handle DHCP retry timer expiry.
Definition: dhcp.c:1297
static void dhcp_finished(struct dhcp_session *dhcp, int rc)
Mark DHCP session as complete.
Definition: dhcp.c:268
struct retry_timer timer
Retransmission timer.
Definition: dhcp.c:241
static struct interface_descriptor dhcp_job_desc
DHCP job control interface descriptor.
Definition: dhcp.c:1326
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
int xfer_open_socket(struct interface *intf, int semantics, struct sockaddr *peer, struct sockaddr *local)
Open socket.
Definition: open.c:142
int fetch_ipv4_setting(struct settings *settings, const struct setting *setting, struct in_addr *inp)
Fetch value of IPv4 address setting.
Definition: settings.c:912
#define SOCK_DGRAM
Definition: socket.h:29
#define DBGC(...)
Definition: compiler.h:505
static struct sockaddr dhcp_peer
DHCP peer address for socket opening.
Definition: dhcp.c:1342
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:107
int fetch_raw_setting(struct settings *settings, const struct setting *setting, void *data, size_t len)
Fetch value of setting.
Definition: settings.c:803
A DHCP session.
Definition: dhcp.c:200
struct refcnt refcnt
Reference counter.
Definition: dhcp.c:202
struct interface job
Job control interface.
Definition: dhcp.c:204
sa_family_t sin_family
Socket address family (part of struct sockaddr)
Definition: in.h:89
static void pxebs_list(struct dhcp_session *dhcp, void *raw, size_t raw_len, struct in_addr *ip)
Retrieve list of PXE boot servers for a given server type.
Definition: dhcp.c:1407
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition: netdevice.h:583
uint64_t tag
Setting tag, if applicable.
Definition: settings.h:43
struct sockaddr_in local
Local socket address.
Definition: dhcp.c:211
#define ENOMEM
Not enough space.
Definition: errno.h:534
static struct interface_descriptor dhcp_xfer_desc
DHCP data transfer interface descriptor.
Definition: dhcp.c:1288
uint16_t pxe_type
PXE Boot Server type.
Definition: dhcp.c:234
static struct net_device * netdev
Definition: gdbudp.c:52
#define INADDR_BROADCAST
Definition: in.h:21
Generalized socket address structure.
Definition: socket.h:96
struct interface xfer
Data transfer interface.
Definition: dhcp.c:206
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
IP address structure.
Definition: in.h:41
uint16_t sin_port
TCP/IP port (part of struct sockaddr_tcpip)
Definition: in.h:93
char * inet_ntoa(struct in_addr in)
Convert IPv4 address to dotted-quad notation.
Definition: ipv4.c:668
IP4_t ip
Destination IP address.
Definition: pxe_api.h:58
unsigned char uint8_t
Definition: stdint.h:10
unsigned long fetch_uintz_setting(struct settings *settings, const struct setting *setting)
Fetch value of unsigned integer setting, or zero.
Definition: settings.c:1068
static struct net_device * netdev_get(struct net_device *netdev)
Get reference to network device.
Definition: netdevice.h:561
Accept only servers in DHCP_PXE_BOOT_SERVERS list.
Definition: dhcp.h:105
Inhibit broadcast discovery.
Definition: dhcp.h:101
A setting.
Definition: settings.h:23
uint32_t s_addr
Definition: in.h:42
struct in_addr sin_addr
IPv4 address.
Definition: in.h:100
#define BOOTPC_PORT
BOOTP/DHCP client port.
Definition: dhcp.h:30
struct in_addr * pxe_attempt
List of PXE Boot Servers to attempt.
Definition: dhcp.c:236
static struct dhcp_session_state dhcp_state_pxebs
PXE Boot Server Discovery state operations.
Definition: dhcp.c:197
#define cpu_to_le16(value)
Definition: byteswap.h:106
struct in_addr * pxe_accept
List of PXE Boot Servers to accept.
Definition: dhcp.c:238
signed long ssize_t
Definition: stdint.h:7
#define DHCP_PXE_DISCOVERY_CONTROL
PXE boot server discovery control.
Definition: dhcp.h:96
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:203
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
#define DHCP_PXE_BOOT_SERVER_MCAST
PXE boot server multicast address.
Definition: dhcp.h:111
#define DHCP_PXE_BOOT_SERVERS
PXE boot servers.
Definition: dhcp.h:114
#define htons(value)
Definition: byteswap.h:135
Inhibit multicast discovery.
Definition: dhcp.h:103
#define AF_INET
IPv4 Internet addresses.
Definition: socket.h:63
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106
struct net_device * netdev
Network device being configured.
Definition: dhcp.c:209

References AF_INET, BOOTPC_PORT, cpu_to_le16, DBGC, dhcp_finished(), dhcp_free(), dhcp_job_desc, dhcp_peer, DHCP_PXE_BOOT_SERVER_MCAST, DHCP_PXE_BOOT_SERVERS, DHCP_PXE_DISCOVERY_CONTROL, dhcp_set_state(), dhcp_state_pxebs, dhcp_timer_expired(), dhcp_xfer_desc, EINVAL, ENOMEM, fetch_ipv4_setting(), fetch_raw_setting(), fetch_uintz_setting(), htons, INADDR_BROADCAST, inet_ntoa(), intf_init(), intf_plug_plug(), ip, dhcp_session::job, dhcp_session::local, netdev, dhcp_session::netdev, netdev_get(), netdev_settings(), NULL, dhcp_session::pxe_accept, dhcp_session::pxe_attempt, dhcp_session::pxe_type, pxebs_list(), PXEBS_NO_BROADCAST, PXEBS_NO_MULTICAST, PXEBS_NO_UNKNOWN_SERVERS, rc, ref_init, ref_put, dhcp_session::refcnt, in_addr::s_addr, sockaddr_in::sin_addr, sockaddr_in::sin_family, sockaddr_in::sin_port, SOCK_DGRAM, setting::tag, dhcp_session::timer, dhcp_session::xfer, xfer_open_socket(), and zalloc().

Referenced by pxebs().

Variable Documentation

◆ dhcp_last_xid

uint32_t dhcp_last_xid

Most recent DHCP transaction ID.

This is exposed for use by the fakedhcp code when reconstructing DHCP packets for PXE NBPs.

Definition at line 124 of file dhcp.c.

Referenced by create_fakedhcpack(), create_fakedhcpdiscover(), create_fakepxebsack(), and start_dhcp().