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>

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_STATIC_ROUTES   121
 Classless static routes. 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)
 
 FILE_SECBOOT (PERMITTED)
 
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 554 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 557 of file dhcp.h.

◆ DHCP_BYTE

#define DHCP_BYTE (   value)    DHCP_OPTION ( value )

Construct a byte-valued DHCP option.

Definition at line 560 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:554

Construct a word-valued DHCP option.

Definition at line 563 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:554

Construct a dword-valued DHCP option.

Definition at line 567 of file dhcp.h.

◆ DHCP_ENCAP

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

Construct a DHCP encapsulated options field.

Definition at line 573 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 607 of file dhcp.h.

◆ DHCP_MAX_LEN

#define DHCP_MAX_LEN   0xff

Maximum length for a single DHCP option.

Definition at line 610 of file dhcp.h.

◆ BOOTP_REQUEST

#define BOOTP_REQUEST   1

Opcode for a request from client to server.

Definition at line 688 of file dhcp.h.

◆ BOOTP_REPLY

#define BOOTP_REPLY   2

Opcode for a reply from server to client.

Definition at line 691 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 698 of file dhcp.h.

◆ DHCP_MAGIC_COOKIE

#define DHCP_MAGIC_COOKIE   0x63825363UL

DHCP magic cookie.

Definition at line 701 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 708 of file dhcp.h.

◆ DHCP_SETTINGS_NAME

#define DHCP_SETTINGS_NAME   "dhcp"

Settings block name used for DHCP responses.

Definition at line 711 of file dhcp.h.

◆ PROXYDHCP_SETTINGS_NAME

#define PROXYDHCP_SETTINGS_NAME   "proxydhcp"

Settings block name used for ProxyDHCP responses.

Definition at line 714 of file dhcp.h.

◆ PXEBS_SETTINGS_NAME

#define PXEBS_SETTINGS_NAME   "pxebs"

Setting block name used for BootServerDHCP responses.

Definition at line 717 of file dhcp.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ 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 945 of file dhcp.c.

948  {
949  struct dhcphdr *dhcphdr = data;
950  int rc;
951 
952  /* Sanity check */
953  if ( max_len < ( sizeof ( *dhcphdr ) + options_len ) )
954  return -ENOSPC;
955 
956  /* Initialise DHCP packet content */
957  memset ( dhcphdr, 0, max_len );
958  dhcphdr->xid = xid;
961  dhcphdr->op = dhcp_op[msgtype];
965  memcpy ( dhcphdr->options, options, options_len );
966 
967  /* If the local link-layer address functions only as a name
968  * (i.e. cannot be used as a destination address), then
969  * request broadcast responses.
970  */
973 
974  /* If the network device already has an IPv4 address then
975  * unicast responses from the DHCP server may be rejected, so
976  * request broadcast responses.
977  */
978  if ( ipv4_has_any_addr ( netdev ) )
980 
981  /* Initialise DHCP packet structure */
982  memset ( dhcppkt, 0, sizeof ( *dhcppkt ) );
983  dhcppkt_init ( dhcppkt, data, max_len );
984 
985  /* Set DHCP_MESSAGE_TYPE option */
986  if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_MESSAGE_TYPE,
987  &msgtype, sizeof ( msgtype ) ) ) != 0 )
988  return rc;
989 
990  return 0;
991 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint8_t ll_addr_len
Link-layer address length.
Definition: netdevice.h:199
uint8_t htype
Hardware address type.
Definition: dhcp.h:628
#define LL_NAME_ONLY
Local link-layer address functions only as a name.
Definition: netdevice.h:211
#define BOOTP_FL_BROADCAST
BOOTP reply must be broadcast.
Definition: dhcp.h:698
#define DHCP_MESSAGE_TYPE
DHCP message type.
Definition: dhcp.h:196
uint8_t options[0]
DHCP options.
Definition: dhcp.h:684
uint32_t xid
Transaction ID.
Definition: dhcp.h:634
#define ntohs(value)
Definition: byteswap.h:137
static const uint8_t dhcp_op[]
DHCP operation types.
Definition: dhcp.c:70
#define htonl(value)
Definition: byteswap.h:134
void * memcpy(void *dest, const void *src, size_t len) __nonnull
uint16_t flags
Flags.
Definition: dhcp.h:638
int ipv4_has_any_addr(struct net_device *netdev)
Check if network device has any IPv4 address.
Definition: ipv4.c:589
uint8_t op
Operation.
Definition: dhcp.h:621
static int options
Definition: 3c515.c:286
#define DHCP_MAGIC_COOKIE
DHCP magic cookie.
Definition: dhcp.h:701
static struct net_device * netdev
Definition: gdbudp.c:52
uint8_t chaddr[16]
Client hardware address.
Definition: dhcp.h:662
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:165
unsigned int flags
Flags.
Definition: netdevice.h:203
uint16_t ll_proto
Link-layer protocol.
Definition: netdevice.h:195
A DHCP header.
Definition: dhcp.h:616
void dhcppkt_init(struct dhcp_packet *dhcppkt, struct dhcphdr *data, size_t len)
Initialise DHCP packet.
Definition: dhcppkt.c:301
#define ENOSPC
No space left on device.
Definition: errno.h:550
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint32_t magic
DHCP magic cookie.
Definition: dhcp.h:677
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:388
uint8_t hlen
Hardware address length.
Definition: dhcp.h:630
#define htons(value)
Definition: byteswap.h:136
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:373
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, 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 1008 of file dhcp.c.

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

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, 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 1358 of file dhcp.c.

1358  {
1359  struct dhcp_session *dhcp;
1360  int rc;
1361 
1362  /* Allocate and initialise structure */
1363  dhcp = zalloc ( sizeof ( *dhcp ) );
1364  if ( ! dhcp )
1365  return -ENOMEM;
1366  ref_init ( &dhcp->refcnt, dhcp_free );
1367  intf_init ( &dhcp->job, &dhcp_job_desc, &dhcp->refcnt );
1368  intf_init ( &dhcp->xfer, &dhcp_xfer_desc, &dhcp->refcnt );
1369  timer_init ( &dhcp->timer, dhcp_timer_expired, &dhcp->refcnt );
1370  dhcp->netdev = netdev_get ( netdev );
1371  dhcp->local.sin_family = AF_INET;
1372  dhcp->local.sin_port = htons ( BOOTPC_PORT );
1373  dhcp->xid = random();
1374 
1375  /* Store DHCP transaction ID for fakedhcp code */
1376  dhcp_last_xid = dhcp->xid;
1377 
1378  /* Instantiate child objects and attach to our interfaces */
1379  if ( ( rc = xfer_open_socket ( &dhcp->xfer, SOCK_DGRAM, &dhcp_peer,
1380  ( struct sockaddr * ) &dhcp->local ) ) != 0 )
1381  goto err;
1382 
1383  /* Enter DHCPDISCOVER state */
1385 
1386  /* Attach parent interface, mortalise self, and return */
1387  intf_plug_plug ( &dhcp->job, job );
1388  ref_put ( &dhcp->refcnt );
1389  return 0;
1390 
1391  err:
1392  dhcp_finished ( dhcp, rc );
1393  ref_put ( &dhcp->refcnt );
1394  return rc;
1395 }
static void dhcp_set_state(struct dhcp_session *dhcp, struct dhcp_session_state *state)
Transition to new DHCP session state.
Definition: dhcp.c:285
static void dhcp_free(struct refcnt *refcnt)
Free DHCP session.
Definition: dhcp.c:254
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:1298
static void dhcp_finished(struct dhcp_session *dhcp, int rc)
Mark DHCP session as complete.
Definition: dhcp.c:269
struct retry_timer timer
Retransmission timer.
Definition: dhcp.c:242
static struct interface_descriptor dhcp_job_desc
DHCP job control interface descriptor.
Definition: dhcp.c:1327
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:65
int xfer_open_socket(struct interface *intf, int semantics, struct sockaddr *peer, struct sockaddr *local)
Open socket.
Definition: open.c:143
#define SOCK_DGRAM
Definition: socket.h:30
static struct sockaddr dhcp_peer
DHCP peer address for socket opening.
Definition: dhcp.c:1343
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:108
A DHCP session.
Definition: dhcp.c:201
struct refcnt refcnt
Reference counter.
Definition: dhcp.c:203
struct interface job
Job control interface.
Definition: dhcp.c:205
sa_family_t sin_family
Socket address family (part of struct sockaddr)
Definition: in.h:90
uint32_t xid
Transaction ID (in network-endian order)
Definition: dhcp.c:216
struct sockaddr_in local
Local socket address.
Definition: dhcp.c:212
#define ENOMEM
Not enough space.
Definition: errno.h:535
static struct interface_descriptor dhcp_xfer_desc
DHCP data transfer interface descriptor.
Definition: dhcp.c:1289
static struct net_device * netdev
Definition: gdbudp.c:52
Generalized socket address structure.
Definition: socket.h:97
struct interface xfer
Data transfer interface.
Definition: dhcp.c:207
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:662
uint16_t sin_port
TCP/IP port (part of struct sockaddr_tcpip)
Definition: in.h:94
long int random(void)
Generate a pseudo-random number between 0 and 2147483647L or 2147483562?
Definition: random.c:32
static struct net_device * netdev_get(struct net_device *netdev)
Get reference to network device.
Definition: netdevice.h:565
uint32_t dhcp_last_xid
Most recent DHCP transaction ID.
Definition: dhcp.c:125
static struct dhcp_session_state dhcp_state_discover
DHCP discovery state operations.
Definition: dhcp.c:195
#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:204
#define htons(value)
Definition: byteswap.h:136
#define AF_INET
IPv4 Internet addresses.
Definition: socket.h:64
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:107
struct net_device * netdev
Network device being configured.
Definition: dhcp.c:210

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 1448 of file dhcp.c.

1449  {
1450  struct setting pxe_discovery_control_setting =
1452  struct setting pxe_boot_servers_setting =
1453  { .tag = DHCP_PXE_BOOT_SERVERS };
1454  struct setting pxe_boot_server_mcast_setting =
1456  ssize_t pxebs_list_len;
1457  struct dhcp_session *dhcp;
1458  struct in_addr *ip;
1459  unsigned int pxe_discovery_control;
1460  int rc;
1461 
1462  /* Get upper bound for PXE boot server IP address list */
1463  pxebs_list_len = fetch_raw_setting ( NULL, &pxe_boot_servers_setting,
1464  NULL, 0 );
1465  if ( pxebs_list_len < 0 )
1466  pxebs_list_len = 0;
1467 
1468  /* Allocate and initialise structure */
1469  dhcp = zalloc ( sizeof ( *dhcp ) + sizeof ( *ip ) /* mcast */ +
1470  sizeof ( *ip ) /* bcast */ + pxebs_list_len +
1471  sizeof ( *ip ) /* terminator */ );
1472  if ( ! dhcp )
1473  return -ENOMEM;
1474  ref_init ( &dhcp->refcnt, dhcp_free );
1475  intf_init ( &dhcp->job, &dhcp_job_desc, &dhcp->refcnt );
1476  intf_init ( &dhcp->xfer, &dhcp_xfer_desc, &dhcp->refcnt );
1477  timer_init ( &dhcp->timer, dhcp_timer_expired, &dhcp->refcnt );
1478  dhcp->netdev = netdev_get ( netdev );
1479  dhcp->local.sin_family = AF_INET;
1480  fetch_ipv4_setting ( netdev_settings ( netdev ), &ip_setting,
1481  &dhcp->local.sin_addr );
1482  dhcp->local.sin_port = htons ( BOOTPC_PORT );
1483  dhcp->pxe_type = cpu_to_le16 ( pxe_type );
1484 
1485  /* Construct PXE boot server IP address lists */
1486  pxe_discovery_control =
1487  fetch_uintz_setting ( NULL, &pxe_discovery_control_setting );
1488  ip = ( ( ( void * ) dhcp ) + sizeof ( *dhcp ) );
1489  dhcp->pxe_attempt = ip;
1490  if ( ! ( pxe_discovery_control & PXEBS_NO_MULTICAST ) ) {
1491  fetch_ipv4_setting ( NULL, &pxe_boot_server_mcast_setting, ip);
1492  if ( ip->s_addr )
1493  ip++;
1494  }
1495  if ( ! ( pxe_discovery_control & PXEBS_NO_BROADCAST ) )
1496  (ip++)->s_addr = INADDR_BROADCAST;
1497  if ( pxe_discovery_control & PXEBS_NO_UNKNOWN_SERVERS )
1498  dhcp->pxe_accept = ip;
1499  if ( pxebs_list_len ) {
1500  uint8_t buf[pxebs_list_len];
1501 
1502  fetch_raw_setting ( NULL, &pxe_boot_servers_setting,
1503  buf, sizeof ( buf ) );
1504  pxebs_list ( dhcp, buf, sizeof ( buf ), ip );
1505  }
1506  if ( ! dhcp->pxe_attempt->s_addr ) {
1507  DBGC ( dhcp, "DHCP %p has no PXE boot servers for type %04x\n",
1508  dhcp, pxe_type );
1509  rc = -EINVAL;
1510  goto err;
1511  }
1512 
1513  /* Dump out PXE server lists */
1514  DBGC ( dhcp, "DHCP %p attempting", dhcp );
1515  for ( ip = dhcp->pxe_attempt ; ip->s_addr ; ip++ )
1516  DBGC ( dhcp, " %s", inet_ntoa ( *ip ) );
1517  DBGC ( dhcp, "\n" );
1518  if ( dhcp->pxe_accept ) {
1519  DBGC ( dhcp, "DHCP %p accepting", dhcp );
1520  for ( ip = dhcp->pxe_accept ; ip->s_addr ; ip++ )
1521  DBGC ( dhcp, " %s", inet_ntoa ( *ip ) );
1522  DBGC ( dhcp, "\n" );
1523  }
1524 
1525  /* Instantiate child objects and attach to our interfaces */
1526  if ( ( rc = xfer_open_socket ( &dhcp->xfer, SOCK_DGRAM, &dhcp_peer,
1527  ( struct sockaddr * ) &dhcp->local ) ) != 0 )
1528  goto err;
1529 
1530  /* Enter PXEBS state */
1531  dhcp_set_state ( dhcp, &dhcp_state_pxebs );
1532 
1533  /* Attach parent interface, mortalise self, and return */
1534  intf_plug_plug ( &dhcp->job, job );
1535  ref_put ( &dhcp->refcnt );
1536  return 0;
1537 
1538  err:
1539  dhcp_finished ( dhcp, rc );
1540  ref_put ( &dhcp->refcnt );
1541  return rc;
1542 }
#define EINVAL
Invalid argument.
Definition: errno.h:429
static void dhcp_set_state(struct dhcp_session *dhcp, struct dhcp_session_state *state)
Transition to new DHCP session state.
Definition: dhcp.c:285
static void dhcp_free(struct refcnt *refcnt)
Free DHCP session.
Definition: dhcp.c:254
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:1298
static void dhcp_finished(struct dhcp_session *dhcp, int rc)
Mark DHCP session as complete.
Definition: dhcp.c:269
struct retry_timer timer
Retransmission timer.
Definition: dhcp.c:242
static struct interface_descriptor dhcp_job_desc
DHCP job control interface descriptor.
Definition: dhcp.c:1327
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:65
int xfer_open_socket(struct interface *intf, int semantics, struct sockaddr *peer, struct sockaddr *local)
Open socket.
Definition: open.c:143
int fetch_ipv4_setting(struct settings *settings, const struct setting *setting, struct in_addr *inp)
Fetch value of IPv4 address setting.
Definition: settings.c:913
#define SOCK_DGRAM
Definition: socket.h:30
#define DBGC(...)
Definition: compiler.h:505
static struct sockaddr dhcp_peer
DHCP peer address for socket opening.
Definition: dhcp.c:1343
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:108
int fetch_raw_setting(struct settings *settings, const struct setting *setting, void *data, size_t len)
Fetch value of setting.
Definition: settings.c:804
A DHCP session.
Definition: dhcp.c:201
struct refcnt refcnt
Reference counter.
Definition: dhcp.c:203
struct interface job
Job control interface.
Definition: dhcp.c:205
sa_family_t sin_family
Socket address family (part of struct sockaddr)
Definition: in.h:90
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:1408
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition: netdevice.h:587
uint64_t tag
Setting tag, if applicable.
Definition: settings.h:44
struct sockaddr_in local
Local socket address.
Definition: dhcp.c:212
#define ENOMEM
Not enough space.
Definition: errno.h:535
static struct interface_descriptor dhcp_xfer_desc
DHCP data transfer interface descriptor.
Definition: dhcp.c:1289
uint16_t pxe_type
PXE Boot Server type.
Definition: dhcp.c:235
static struct net_device * netdev
Definition: gdbudp.c:52
#define INADDR_BROADCAST
Definition: in.h:22
Generalized socket address structure.
Definition: socket.h:97
struct interface xfer
Data transfer interface.
Definition: dhcp.c:207
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:662
IP address structure.
Definition: in.h:42
uint16_t sin_port
TCP/IP port (part of struct sockaddr_tcpip)
Definition: in.h:94
char * inet_ntoa(struct in_addr in)
Convert IPv4 address to dotted-quad notation.
Definition: ipv4.c:814
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:1069
static struct net_device * netdev_get(struct net_device *netdev)
Get reference to network device.
Definition: netdevice.h:565
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:24
uint32_t s_addr
Definition: in.h:43
struct in_addr sin_addr
IPv4 address.
Definition: in.h:101
#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:237
static struct dhcp_session_state dhcp_state_pxebs
PXE Boot Server Discovery state operations.
Definition: dhcp.c:198
#define cpu_to_le16(value)
Definition: byteswap.h:107
struct in_addr * pxe_accept
List of PXE Boot Servers to accept.
Definition: dhcp.c:239
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:204
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
#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:136
Inhibit multicast discovery.
Definition: dhcp.h:103
#define AF_INET
IPv4 Internet addresses.
Definition: socket.h:64
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:107
struct net_device * netdev
Network device being configured.
Definition: dhcp.c:210

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 125 of file dhcp.c.

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