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_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 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 529 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 532 of file dhcp.h.

◆ DHCP_BYTE

#define DHCP_BYTE (   value)    DHCP_OPTION ( value )

Construct a byte-valued DHCP option.

Definition at line 535 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:529

Construct a word-valued DHCP option.

Definition at line 538 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:529

Construct a dword-valued DHCP option.

Definition at line 542 of file dhcp.h.

◆ DHCP_ENCAP

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

Construct a DHCP encapsulated options field.

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

◆ DHCP_MAX_LEN

#define DHCP_MAX_LEN   0xff

Maximum length for a single DHCP option.

Definition at line 585 of file dhcp.h.

◆ BOOTP_REQUEST

#define BOOTP_REQUEST   1

Opcode for a request from client to server.

Definition at line 663 of file dhcp.h.

◆ BOOTP_REPLY

#define BOOTP_REPLY   2

Opcode for a reply from server to client.

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

◆ DHCP_MAGIC_COOKIE

#define DHCP_MAGIC_COOKIE   0x63825363UL

DHCP magic cookie.

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

◆ DHCP_SETTINGS_NAME

#define DHCP_SETTINGS_NAME   "dhcp"

Settings block name used for DHCP responses.

Definition at line 686 of file dhcp.h.

◆ PROXYDHCP_SETTINGS_NAME

#define PROXYDHCP_SETTINGS_NAME   "proxydhcp"

Settings block name used for ProxyDHCP responses.

Definition at line 689 of file dhcp.h.

◆ PXEBS_SETTINGS_NAME

#define PXEBS_SETTINGS_NAME   "pxebs"

Setting block name used for BootServerDHCP responses.

Definition at line 692 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 914 of file dhcp.c.

917  {
918  struct dhcphdr *dhcphdr = data;
919  int rc;
920 
921  /* Sanity check */
922  if ( max_len < ( sizeof ( *dhcphdr ) + options_len ) )
923  return -ENOSPC;
924 
925  /* Initialise DHCP packet content */
926  memset ( dhcphdr, 0, max_len );
927  dhcphdr->xid = xid;
930  dhcphdr->op = dhcp_op[msgtype];
934  memcpy ( dhcphdr->options, options, options_len );
935 
936  /* If the local link-layer address functions only as a name
937  * (i.e. cannot be used as a destination address), then
938  * request broadcast responses.
939  */
942 
943  /* If the network device already has an IPv4 address then
944  * unicast responses from the DHCP server may be rejected, so
945  * request broadcast responses.
946  */
947  if ( ipv4_has_any_addr ( netdev ) )
949 
950  /* Initialise DHCP packet structure */
951  memset ( dhcppkt, 0, sizeof ( *dhcppkt ) );
952  dhcppkt_init ( dhcppkt, data, max_len );
953 
954  /* Set DHCP_MESSAGE_TYPE option */
955  if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_MESSAGE_TYPE,
956  &msgtype, sizeof ( msgtype ) ) ) != 0 )
957  return rc;
958 
959  return 0;
960 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint8_t ll_addr_len
Link-layer address length.
Definition: netdevice.h:198
static void size_t size_t max_len
Definition: entropy.h:153
uint8_t htype
Hardware address type.
Definition: dhcp.h:603
#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:673
#define DHCP_MESSAGE_TYPE
DHCP message type.
Definition: dhcp.h:193
uint8_t options[0]
DHCP options.
Definition: dhcp.h:659
uint32_t xid
Transaction ID.
Definition: dhcp.h:609
#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:613
int ipv4_has_any_addr(struct net_device *netdev)
Check if network device has any IPv4 address.
Definition: ipv4.c:433
uint8_t op
Operation.
Definition: dhcp.h:596
static int options
Definition: 3c515.c:286
#define DHCP_MAGIC_COOKIE
DHCP magic cookie.
Definition: dhcp.h:676
static struct net_device * netdev
Definition: gdbudp.c:52
uint8_t chaddr[16]
Client hardware address.
Definition: dhcp.h:637
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:591
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
uint32_t magic
DHCP magic cookie.
Definition: dhcp.h:652
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:381
uint8_t hlen
Hardware address length.
Definition: dhcp.h:605
#define htons(value)
Definition: byteswap.h:135
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:366
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 977 of file dhcp.c.

980  {
981  struct dhcp_netdev_desc dhcp_desc;
982  struct dhcp_client_id client_id;
983  struct dhcp_client_uuid client_uuid;
984  const struct setting *setting;
985  uint8_t *dhcp_features;
986  size_t dhcp_features_len;
987  size_t ll_addr_len;
988  void *raw;
989  ssize_t len;
990  unsigned int i;
991  int rc;
992 
993  /* Create DHCP packet */
994  if ( ( rc = dhcp_create_packet ( dhcppkt, netdev, msgtype, xid,
996  sizeof ( dhcp_request_options_data ),
997  data, max_len ) ) != 0 ) {
998  DBG ( "DHCP could not create DHCP packet: %s\n",
999  strerror ( rc ) );
1000  goto err_create_packet;
1001  }
1002 
1003  /* Set client IP address */
1004  dhcppkt->dhcphdr->ciaddr = ciaddr;
1005 
1006  /* Add options to identify the feature list */
1007  dhcp_features = table_start ( DHCP_FEATURES );
1008  dhcp_features_len = table_num_entries ( DHCP_FEATURES );
1009  if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_EB_ENCAP, dhcp_features,
1010  dhcp_features_len ) ) != 0 ) {
1011  DBG ( "DHCP could not set features list option: %s\n",
1012  strerror ( rc ) );
1013  goto err_store_features;
1014  }
1015 
1016  /* Add options to identify the network device */
1017  fetch_raw_setting ( netdev_settings ( netdev ), &busid_setting,
1018  &dhcp_desc, sizeof ( dhcp_desc ) );
1019  if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_EB_BUS_ID, &dhcp_desc,
1020  sizeof ( dhcp_desc ) ) ) != 0 ) {
1021  DBG ( "DHCP could not set bus ID option: %s\n",
1022  strerror ( rc ) );
1023  goto err_store_busid;
1024  }
1025 
1026  /* Add DHCP client identifier. Required for Infiniband, and
1027  * doesn't hurt other link layers.
1028  */
1029  client_id.ll_proto = ntohs ( netdev->ll_protocol->ll_proto );
1030  ll_addr_len = netdev->ll_protocol->ll_addr_len;
1031  assert ( ll_addr_len <= sizeof ( client_id.ll_addr ) );
1032  memcpy ( client_id.ll_addr, netdev->ll_addr, ll_addr_len );
1033  if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_CLIENT_ID, &client_id,
1034  ( ll_addr_len + 1 ) ) ) != 0 ) {
1035  DBG ( "DHCP could not set client ID: %s\n",
1036  strerror ( rc ) );
1037  goto err_store_client_id;
1038  }
1039 
1040  /* Add client UUID, if we have one. Required for PXE. The
1041  * PXE spec does not specify a byte ordering for UUIDs, but
1042  * RFC4578 suggests that it follows the EFI spec, in which the
1043  * first three fields are little-endian.
1044  */
1045  client_uuid.type = DHCP_CLIENT_UUID_TYPE;
1046  if ( ( len = fetch_uuid_setting ( NULL, &uuid_setting,
1047  &client_uuid.uuid ) ) >= 0 ) {
1048  uuid_mangle ( &client_uuid.uuid );
1049  if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_CLIENT_UUID,
1050  &client_uuid,
1051  sizeof ( client_uuid ) ) ) != 0 ) {
1052  DBG ( "DHCP could not set client UUID: %s\n",
1053  strerror ( rc ) );
1054  goto err_store_client_uuid;
1055  }
1056  }
1057 
1058  /* Add request settings, if applicable */
1059  for ( i = 0 ; i < ( sizeof ( dhcp_request_settings ) /
1060  sizeof ( dhcp_request_settings[0] ) ) ; i++ ) {
1062  if ( ( len = fetch_raw_setting_copy ( NULL, setting,
1063  &raw ) ) >= 0 ) {
1064  rc = dhcppkt_store ( dhcppkt, setting->tag, raw, len );
1065  free ( raw );
1066  if ( rc != 0 ) {
1067  DBG ( "DHCP could not set %s: %s\n",
1068  setting->name, strerror ( rc ) );
1069  goto err_store_raw;
1070  }
1071  }
1072  }
1073 
1074  err_store_raw:
1075  err_store_client_uuid:
1076  err_store_client_id:
1077  err_store_busid:
1078  err_store_features:
1079  err_create_packet:
1080  return rc;
1081 }
#define DHCP_FEATURES
DHCP feature table.
Definition: features.h:62
#define DHCP_CLIENT_UUID
UUID client identifier.
Definition: dhcp.h:311
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:271
#define DHCP_EB_ENCAP
Etherboot-specific encapsulated options.
Definition: dhcp.h:332
static const struct setting * dhcp_request_settings[]
Settings copied in to all DHCP requests.
Definition: dhcp.c:103
int fetch_raw_setting_copy(struct settings *settings, const struct setting *setting, void **data)
Fetch value of setting.
Definition: settings.c:825
static void size_t size_t max_len
Definition: entropy.h:153
int fetch_raw_setting(struct settings *settings, const struct setting *setting, void *data, size_t len)
Fetch value of setting.
Definition: settings.c:807
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:577
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:914
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:619
#define DHCP_CLIENT_UUID_TYPE
Definition: dhcp.h:321
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:243
Network device descriptor.
Definition: dhcp.h:424
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:314
#define DHCP_CLIENT_ID
Client identifier.
Definition: dhcp.h:240
struct dhcphdr * dhcphdr
The DHCP packet contents.
Definition: dhcppkt.h:24
uint32_t len
Length.
Definition: ena.h:14
__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:1088
signed long ssize_t
Definition: stdint.h:7
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:381
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define DHCP_EB_BUS_ID
Network device descriptor.
Definition: dhcp.h:421
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:366
#define table_num_entries(table)
Get number of entries in linker table.
Definition: tables.h:308

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

1327  {
1328  struct dhcp_session *dhcp;
1329  int rc;
1330 
1331  /* Allocate and initialise structure */
1332  dhcp = zalloc ( sizeof ( *dhcp ) );
1333  if ( ! dhcp )
1334  return -ENOMEM;
1335  ref_init ( &dhcp->refcnt, dhcp_free );
1336  intf_init ( &dhcp->job, &dhcp_job_desc, &dhcp->refcnt );
1337  intf_init ( &dhcp->xfer, &dhcp_xfer_desc, &dhcp->refcnt );
1338  timer_init ( &dhcp->timer, dhcp_timer_expired, &dhcp->refcnt );
1339  dhcp->netdev = netdev_get ( netdev );
1340  dhcp->local.sin_family = AF_INET;
1341  dhcp->local.sin_port = htons ( BOOTPC_PORT );
1342  dhcp->xid = random();
1343 
1344  /* Store DHCP transaction ID for fakedhcp code */
1345  dhcp_last_xid = dhcp->xid;
1346 
1347  /* Instantiate child objects and attach to our interfaces */
1348  if ( ( rc = xfer_open_socket ( &dhcp->xfer, SOCK_DGRAM, &dhcp_peer,
1349  ( struct sockaddr * ) &dhcp->local ) ) != 0 )
1350  goto err;
1351 
1352  /* Enter DHCPDISCOVER state */
1354 
1355  /* Attach parent interface, mortalise self, and return */
1356  intf_plug_plug ( &dhcp->job, job );
1357  ref_put ( &dhcp->refcnt );
1358  return 0;
1359 
1360  err:
1361  dhcp_finished ( dhcp, rc );
1362  ref_put ( &dhcp->refcnt );
1363  return rc;
1364 }
static void dhcp_set_state(struct dhcp_session *dhcp, struct dhcp_session_state *state)
Transition to new DHCP session state.
Definition: dhcp.c:283
static void dhcp_free(struct refcnt *refcnt)
Free DHCP session.
Definition: dhcp.c:252
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:1267
static void dhcp_finished(struct dhcp_session *dhcp, int rc)
Mark DHCP session as complete.
Definition: dhcp.c:267
struct retry_timer timer
Retransmission timer.
Definition: dhcp.c:240
static struct interface_descriptor dhcp_job_desc
DHCP job control interface descriptor.
Definition: dhcp.c:1296
#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:141
#define SOCK_DGRAM
Definition: socket.h:29
static struct sockaddr dhcp_peer
DHCP peer address for socket opening.
Definition: dhcp.c:1312
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:102
A DHCP session.
Definition: dhcp.c:199
struct refcnt refcnt
Reference counter.
Definition: dhcp.c:201
struct interface job
Job control interface.
Definition: dhcp.c:203
sa_family_t sin_family
Socket address family (part of struct sockaddr)
Definition: in.h:87
uint32_t xid
Transaction ID (in network-endian order)
Definition: dhcp.c:214
struct sockaddr_in local
Local socket address.
Definition: dhcp.c:210
#define ENOMEM
Not enough space.
Definition: errno.h:534
static struct interface_descriptor dhcp_xfer_desc
DHCP data transfer interface descriptor.
Definition: dhcp.c:1258
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:205
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:91
long int random(void)
Generate a pseudo-random number between 0 and 2147483647L or 2147483562?
Definition: random.c:30
static struct net_device * netdev_get(struct net_device *netdev)
Get reference to network device.
Definition: netdevice.h:544
uint32_t dhcp_last_xid
Most recent DHCP transaction ID.
Definition: dhcp.c:123
static struct dhcp_session_state dhcp_state_discover
DHCP discovery state operations.
Definition: dhcp.c:193
#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:173
#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:208

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

1418  {
1419  struct setting pxe_discovery_control_setting =
1421  struct setting pxe_boot_servers_setting =
1422  { .tag = DHCP_PXE_BOOT_SERVERS };
1423  struct setting pxe_boot_server_mcast_setting =
1425  ssize_t pxebs_list_len;
1426  struct dhcp_session *dhcp;
1427  struct in_addr *ip;
1428  unsigned int pxe_discovery_control;
1429  int rc;
1430 
1431  /* Get upper bound for PXE boot server IP address list */
1432  pxebs_list_len = fetch_raw_setting ( NULL, &pxe_boot_servers_setting,
1433  NULL, 0 );
1434  if ( pxebs_list_len < 0 )
1435  pxebs_list_len = 0;
1436 
1437  /* Allocate and initialise structure */
1438  dhcp = zalloc ( sizeof ( *dhcp ) + sizeof ( *ip ) /* mcast */ +
1439  sizeof ( *ip ) /* bcast */ + pxebs_list_len +
1440  sizeof ( *ip ) /* terminator */ );
1441  if ( ! dhcp )
1442  return -ENOMEM;
1443  ref_init ( &dhcp->refcnt, dhcp_free );
1444  intf_init ( &dhcp->job, &dhcp_job_desc, &dhcp->refcnt );
1445  intf_init ( &dhcp->xfer, &dhcp_xfer_desc, &dhcp->refcnt );
1446  timer_init ( &dhcp->timer, dhcp_timer_expired, &dhcp->refcnt );
1447  dhcp->netdev = netdev_get ( netdev );
1448  dhcp->local.sin_family = AF_INET;
1449  fetch_ipv4_setting ( netdev_settings ( netdev ), &ip_setting,
1450  &dhcp->local.sin_addr );
1451  dhcp->local.sin_port = htons ( BOOTPC_PORT );
1452  dhcp->pxe_type = cpu_to_le16 ( pxe_type );
1453 
1454  /* Construct PXE boot server IP address lists */
1455  pxe_discovery_control =
1456  fetch_uintz_setting ( NULL, &pxe_discovery_control_setting );
1457  ip = ( ( ( void * ) dhcp ) + sizeof ( *dhcp ) );
1458  dhcp->pxe_attempt = ip;
1459  if ( ! ( pxe_discovery_control & PXEBS_NO_MULTICAST ) ) {
1460  fetch_ipv4_setting ( NULL, &pxe_boot_server_mcast_setting, ip);
1461  if ( ip->s_addr )
1462  ip++;
1463  }
1464  if ( ! ( pxe_discovery_control & PXEBS_NO_BROADCAST ) )
1465  (ip++)->s_addr = INADDR_BROADCAST;
1466  if ( pxe_discovery_control & PXEBS_NO_UNKNOWN_SERVERS )
1467  dhcp->pxe_accept = ip;
1468  if ( pxebs_list_len ) {
1469  uint8_t buf[pxebs_list_len];
1470 
1471  fetch_raw_setting ( NULL, &pxe_boot_servers_setting,
1472  buf, sizeof ( buf ) );
1473  pxebs_list ( dhcp, buf, sizeof ( buf ), ip );
1474  }
1475  if ( ! dhcp->pxe_attempt->s_addr ) {
1476  DBGC ( dhcp, "DHCP %p has no PXE boot servers for type %04x\n",
1477  dhcp, pxe_type );
1478  rc = -EINVAL;
1479  goto err;
1480  }
1481 
1482  /* Dump out PXE server lists */
1483  DBGC ( dhcp, "DHCP %p attempting", dhcp );
1484  for ( ip = dhcp->pxe_attempt ; ip->s_addr ; ip++ )
1485  DBGC ( dhcp, " %s", inet_ntoa ( *ip ) );
1486  DBGC ( dhcp, "\n" );
1487  if ( dhcp->pxe_accept ) {
1488  DBGC ( dhcp, "DHCP %p accepting", dhcp );
1489  for ( ip = dhcp->pxe_accept ; ip->s_addr ; ip++ )
1490  DBGC ( dhcp, " %s", inet_ntoa ( *ip ) );
1491  DBGC ( dhcp, "\n" );
1492  }
1493 
1494  /* Instantiate child objects and attach to our interfaces */
1495  if ( ( rc = xfer_open_socket ( &dhcp->xfer, SOCK_DGRAM, &dhcp_peer,
1496  ( struct sockaddr * ) &dhcp->local ) ) != 0 )
1497  goto err;
1498 
1499  /* Enter PXEBS state */
1500  dhcp_set_state ( dhcp, &dhcp_state_pxebs );
1501 
1502  /* Attach parent interface, mortalise self, and return */
1503  intf_plug_plug ( &dhcp->job, job );
1504  ref_put ( &dhcp->refcnt );
1505  return 0;
1506 
1507  err:
1508  dhcp_finished ( dhcp, rc );
1509  ref_put ( &dhcp->refcnt );
1510  return rc;
1511 }
#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:283
static void dhcp_free(struct refcnt *refcnt)
Free DHCP session.
Definition: dhcp.c:252
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:1267
static void dhcp_finished(struct dhcp_session *dhcp, int rc)
Mark DHCP session as complete.
Definition: dhcp.c:267
struct retry_timer timer
Retransmission timer.
Definition: dhcp.c:240
static struct interface_descriptor dhcp_job_desc
DHCP job control interface descriptor.
Definition: dhcp.c:1296
#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:141
int fetch_ipv4_setting(struct settings *settings, const struct setting *setting, struct in_addr *inp)
Fetch value of IPv4 address setting.
Definition: settings.c:916
#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:1312
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:102
int fetch_raw_setting(struct settings *settings, const struct setting *setting, void *data, size_t len)
Fetch value of setting.
Definition: settings.c:807
A DHCP session.
Definition: dhcp.c:199
struct refcnt refcnt
Reference counter.
Definition: dhcp.c:201
struct interface job
Job control interface.
Definition: dhcp.c:203
sa_family_t sin_family
Socket address family (part of struct sockaddr)
Definition: in.h:87
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:1377
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition: netdevice.h:577
uint64_t tag
Setting tag, if applicable.
Definition: settings.h:43
struct sockaddr_in local
Local socket address.
Definition: dhcp.c:210
#define ENOMEM
Not enough space.
Definition: errno.h:534
static struct interface_descriptor dhcp_xfer_desc
DHCP data transfer interface descriptor.
Definition: dhcp.c:1258
uint16_t pxe_type
PXE Boot Server type.
Definition: dhcp.c:233
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:205
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
IP address structure.
Definition: in.h:39
uint16_t sin_port
TCP/IP port (part of struct sockaddr_tcpip)
Definition: in.h:91
char * inet_ntoa(struct in_addr in)
Convert IPv4 address to dotted-quad notation.
Definition: ipv4.c:658
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:1072
static struct net_device * netdev_get(struct net_device *netdev)
Get reference to network device.
Definition: netdevice.h:544
Accept only servers in DHCP_PXE_BOOT_SERVERS list.
Definition: dhcp.h:102
Inhibit broadcast discovery.
Definition: dhcp.h:98
A setting.
Definition: settings.h:23
uint32_t s_addr
Definition: in.h:40
struct in_addr sin_addr
IPv4 address.
Definition: in.h:98
#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:235
static struct dhcp_session_state dhcp_state_pxebs
PXE Boot Server Discovery state operations.
Definition: dhcp.c:196
#define cpu_to_le16(value)
Definition: byteswap.h:106
struct in_addr * pxe_accept
List of PXE Boot Servers to accept.
Definition: dhcp.c:237
signed long ssize_t
Definition: stdint.h:7
#define DHCP_PXE_DISCOVERY_CONTROL
PXE boot server discovery control.
Definition: dhcp.h:93
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:173
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
#define DHCP_PXE_BOOT_SERVER_MCAST
PXE boot server multicast address.
Definition: dhcp.h:108
#define DHCP_PXE_BOOT_SERVERS
PXE boot servers.
Definition: dhcp.h:111
#define htons(value)
Definition: byteswap.h:135
Inhibit multicast discovery.
Definition: dhcp.h:100
#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:208

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

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