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

938  {
939  struct dhcphdr *dhcphdr = data;
940  int rc;
941 
942  /* Sanity check */
943  if ( max_len < ( sizeof ( *dhcphdr ) + options_len ) )
944  return -ENOSPC;
945 
946  /* Initialise DHCP packet content */
947  memset ( dhcphdr, 0, max_len );
948  dhcphdr->xid = xid;
951  dhcphdr->op = dhcp_op[msgtype];
955  memcpy ( dhcphdr->options, options, options_len );
956 
957  /* If the local link-layer address functions only as a name
958  * (i.e. cannot be used as a destination address), then
959  * request broadcast responses.
960  */
963 
964  /* If the network device already has an IPv4 address then
965  * unicast responses from the DHCP server may be rejected, so
966  * request broadcast responses.
967  */
968  if ( ipv4_has_any_addr ( netdev ) )
970 
971  /* Initialise DHCP packet structure */
972  memset ( dhcppkt, 0, sizeof ( *dhcppkt ) );
973  dhcppkt_init ( dhcppkt, data, max_len );
974 
975  /* Set DHCP_MESSAGE_TYPE option */
976  if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_MESSAGE_TYPE,
977  &msgtype, sizeof ( msgtype ) ) ) != 0 )
978  return rc;
979 
980  return 0;
981 }
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:387
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: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 998 of file dhcp.c.

1001  {
1002  struct dhcp_netdev_desc dhcp_desc;
1003  struct dhcp_client_id client_id;
1004  struct dhcp_client_uuid client_uuid;
1005  const struct setting *setting;
1006  uint8_t *dhcp_features;
1007  size_t dhcp_features_len;
1008  size_t ll_addr_len;
1009  void *raw;
1010  ssize_t len;
1011  unsigned int i;
1012  int rc;
1013 
1014  /* Create DHCP packet */
1015  if ( ( rc = dhcp_create_packet ( dhcppkt, netdev, msgtype, xid,
1017  sizeof ( dhcp_request_options_data ),
1018  data, max_len ) ) != 0 ) {
1019  DBG ( "DHCP could not create DHCP packet: %s\n",
1020  strerror ( rc ) );
1021  goto err_create_packet;
1022  }
1023 
1024  /* Set client IP address */
1025  dhcppkt->dhcphdr->ciaddr = ciaddr;
1026 
1027  /* Add options to identify the feature list */
1028  dhcp_features = table_start ( DHCP_FEATURES );
1029  dhcp_features_len = table_num_entries ( DHCP_FEATURES );
1030  if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_EB_ENCAP, dhcp_features,
1031  dhcp_features_len ) ) != 0 ) {
1032  DBG ( "DHCP could not set features list option: %s\n",
1033  strerror ( rc ) );
1034  goto err_store_features;
1035  }
1036 
1037  /* Add options to identify the network device */
1038  fetch_raw_setting ( netdev_settings ( netdev ), &busid_setting,
1039  &dhcp_desc, sizeof ( dhcp_desc ) );
1040  if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_EB_BUS_ID, &dhcp_desc,
1041  sizeof ( dhcp_desc ) ) ) != 0 ) {
1042  DBG ( "DHCP could not set bus ID option: %s\n",
1043  strerror ( rc ) );
1044  goto err_store_busid;
1045  }
1046 
1047  /* Add DHCP client identifier. Required for Infiniband, and
1048  * doesn't hurt other link layers.
1049  */
1050  client_id.ll_proto = ntohs ( netdev->ll_protocol->ll_proto );
1051  ll_addr_len = netdev->ll_protocol->ll_addr_len;
1052  assert ( ll_addr_len <= sizeof ( client_id.ll_addr ) );
1053  memcpy ( client_id.ll_addr, netdev->ll_addr, ll_addr_len );
1054  if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_CLIENT_ID, &client_id,
1055  ( ll_addr_len + 1 ) ) ) != 0 ) {
1056  DBG ( "DHCP could not set client ID: %s\n",
1057  strerror ( rc ) );
1058  goto err_store_client_id;
1059  }
1060 
1061  /* Add client UUID, if we have one. Required for PXE. The
1062  * PXE spec does not specify a byte ordering for UUIDs, but
1063  * RFC4578 suggests that it follows the EFI spec, in which the
1064  * first three fields are little-endian.
1065  */
1066  client_uuid.type = DHCP_CLIENT_UUID_TYPE;
1067  if ( ( len = fetch_uuid_setting ( NULL, &uuid_setting,
1068  &client_uuid.uuid ) ) >= 0 ) {
1069  uuid_mangle ( &client_uuid.uuid );
1070  if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_CLIENT_UUID,
1071  &client_uuid,
1072  sizeof ( client_uuid ) ) ) != 0 ) {
1073  DBG ( "DHCP could not set client UUID: %s\n",
1074  strerror ( rc ) );
1075  goto err_store_client_uuid;
1076  }
1077  }
1078 
1079  /* Add request settings, if applicable */
1080  for ( i = 0 ; i < ( sizeof ( dhcp_request_settings ) /
1081  sizeof ( dhcp_request_settings[0] ) ) ; i++ ) {
1083  if ( ( len = fetch_raw_setting_copy ( NULL, setting,
1084  &raw ) ) >= 0 ) {
1085  rc = dhcppkt_store ( dhcppkt, setting->tag, raw, len );
1086  free ( raw );
1087  if ( rc != 0 ) {
1088  DBG ( "DHCP could not set %s: %s\n",
1089  setting->name, strerror ( rc ) );
1090  goto err_store_raw;
1091  }
1092  }
1093  }
1094 
1095  err_store_raw:
1096  err_store_client_uuid:
1097  err_store_client_id:
1098  err_store_busid:
1099  err_store_features:
1100  err_create_packet:
1101  return rc;
1102 }
#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:589
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:935
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:387
#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:372
#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 1348 of file dhcp.c.

1348  {
1349  struct dhcp_session *dhcp;
1350  int rc;
1351 
1352  /* Allocate and initialise structure */
1353  dhcp = zalloc ( sizeof ( *dhcp ) );
1354  if ( ! dhcp )
1355  return -ENOMEM;
1356  ref_init ( &dhcp->refcnt, dhcp_free );
1357  intf_init ( &dhcp->job, &dhcp_job_desc, &dhcp->refcnt );
1358  intf_init ( &dhcp->xfer, &dhcp_xfer_desc, &dhcp->refcnt );
1359  timer_init ( &dhcp->timer, dhcp_timer_expired, &dhcp->refcnt );
1360  dhcp->netdev = netdev_get ( netdev );
1361  dhcp->local.sin_family = AF_INET;
1362  dhcp->local.sin_port = htons ( BOOTPC_PORT );
1363  dhcp->xid = random();
1364 
1365  /* Store DHCP transaction ID for fakedhcp code */
1366  dhcp_last_xid = dhcp->xid;
1367 
1368  /* Instantiate child objects and attach to our interfaces */
1369  if ( ( rc = xfer_open_socket ( &dhcp->xfer, SOCK_DGRAM, &dhcp_peer,
1370  ( struct sockaddr * ) &dhcp->local ) ) != 0 )
1371  goto err;
1372 
1373  /* Enter DHCPDISCOVER state */
1375 
1376  /* Attach parent interface, mortalise self, and return */
1377  intf_plug_plug ( &dhcp->job, job );
1378  ref_put ( &dhcp->refcnt );
1379  return 0;
1380 
1381  err:
1382  dhcp_finished ( dhcp, rc );
1383  ref_put ( &dhcp->refcnt );
1384  return rc;
1385 }
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:1288
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:1317
#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:1333
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: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:1279
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:556
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:190
#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 1438 of file dhcp.c.

1439  {
1440  struct setting pxe_discovery_control_setting =
1442  struct setting pxe_boot_servers_setting =
1443  { .tag = DHCP_PXE_BOOT_SERVERS };
1444  struct setting pxe_boot_server_mcast_setting =
1446  ssize_t pxebs_list_len;
1447  struct dhcp_session *dhcp;
1448  struct in_addr *ip;
1449  unsigned int pxe_discovery_control;
1450  int rc;
1451 
1452  /* Get upper bound for PXE boot server IP address list */
1453  pxebs_list_len = fetch_raw_setting ( NULL, &pxe_boot_servers_setting,
1454  NULL, 0 );
1455  if ( pxebs_list_len < 0 )
1456  pxebs_list_len = 0;
1457 
1458  /* Allocate and initialise structure */
1459  dhcp = zalloc ( sizeof ( *dhcp ) + sizeof ( *ip ) /* mcast */ +
1460  sizeof ( *ip ) /* bcast */ + pxebs_list_len +
1461  sizeof ( *ip ) /* terminator */ );
1462  if ( ! dhcp )
1463  return -ENOMEM;
1464  ref_init ( &dhcp->refcnt, dhcp_free );
1465  intf_init ( &dhcp->job, &dhcp_job_desc, &dhcp->refcnt );
1466  intf_init ( &dhcp->xfer, &dhcp_xfer_desc, &dhcp->refcnt );
1467  timer_init ( &dhcp->timer, dhcp_timer_expired, &dhcp->refcnt );
1468  dhcp->netdev = netdev_get ( netdev );
1469  dhcp->local.sin_family = AF_INET;
1470  fetch_ipv4_setting ( netdev_settings ( netdev ), &ip_setting,
1471  &dhcp->local.sin_addr );
1472  dhcp->local.sin_port = htons ( BOOTPC_PORT );
1473  dhcp->pxe_type = cpu_to_le16 ( pxe_type );
1474 
1475  /* Construct PXE boot server IP address lists */
1476  pxe_discovery_control =
1477  fetch_uintz_setting ( NULL, &pxe_discovery_control_setting );
1478  ip = ( ( ( void * ) dhcp ) + sizeof ( *dhcp ) );
1479  dhcp->pxe_attempt = ip;
1480  if ( ! ( pxe_discovery_control & PXEBS_NO_MULTICAST ) ) {
1481  fetch_ipv4_setting ( NULL, &pxe_boot_server_mcast_setting, ip);
1482  if ( ip->s_addr )
1483  ip++;
1484  }
1485  if ( ! ( pxe_discovery_control & PXEBS_NO_BROADCAST ) )
1486  (ip++)->s_addr = INADDR_BROADCAST;
1487  if ( pxe_discovery_control & PXEBS_NO_UNKNOWN_SERVERS )
1488  dhcp->pxe_accept = ip;
1489  if ( pxebs_list_len ) {
1490  uint8_t buf[pxebs_list_len];
1491 
1492  fetch_raw_setting ( NULL, &pxe_boot_servers_setting,
1493  buf, sizeof ( buf ) );
1494  pxebs_list ( dhcp, buf, sizeof ( buf ), ip );
1495  }
1496  if ( ! dhcp->pxe_attempt->s_addr ) {
1497  DBGC ( dhcp, "DHCP %p has no PXE boot servers for type %04x\n",
1498  dhcp, pxe_type );
1499  rc = -EINVAL;
1500  goto err;
1501  }
1502 
1503  /* Dump out PXE server lists */
1504  DBGC ( dhcp, "DHCP %p attempting", dhcp );
1505  for ( ip = dhcp->pxe_attempt ; ip->s_addr ; ip++ )
1506  DBGC ( dhcp, " %s", inet_ntoa ( *ip ) );
1507  DBGC ( dhcp, "\n" );
1508  if ( dhcp->pxe_accept ) {
1509  DBGC ( dhcp, "DHCP %p accepting", dhcp );
1510  for ( ip = dhcp->pxe_accept ; ip->s_addr ; ip++ )
1511  DBGC ( dhcp, " %s", inet_ntoa ( *ip ) );
1512  DBGC ( dhcp, "\n" );
1513  }
1514 
1515  /* Instantiate child objects and attach to our interfaces */
1516  if ( ( rc = xfer_open_socket ( &dhcp->xfer, SOCK_DGRAM, &dhcp_peer,
1517  ( struct sockaddr * ) &dhcp->local ) ) != 0 )
1518  goto err;
1519 
1520  /* Enter PXEBS state */
1521  dhcp_set_state ( dhcp, &dhcp_state_pxebs );
1522 
1523  /* Attach parent interface, mortalise self, and return */
1524  intf_plug_plug ( &dhcp->job, job );
1525  ref_put ( &dhcp->refcnt );
1526  return 0;
1527 
1528  err:
1529  dhcp_finished ( dhcp, rc );
1530  ref_put ( &dhcp->refcnt );
1531  return rc;
1532 }
#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:1288
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:1317
#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: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:1333
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: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:1398
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition: netdevice.h:589
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:1279
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:556
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:190
#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().