iPXE
Functions
fakedhcp.h File Reference

Fake DHCP packets. More...

#include <stdint.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
int create_fakedhcpdiscover (struct net_device *netdev, void *data, size_t max_len)
 Create fake DHCPDISCOVER packet. More...
 
int create_fakedhcpack (struct net_device *netdev, void *data, size_t max_len)
 Create fake DHCPACK packet. More...
 
int create_fakepxebsack (struct net_device *netdev, void *data, size_t max_len)
 Create fake PXE Boot Server ACK packet. More...
 

Detailed Description

Fake DHCP packets.

Definition in file fakedhcp.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ create_fakedhcpdiscover()

int create_fakedhcpdiscover ( struct net_device netdev,
void *  data,
size_t  max_len 
)

Create fake DHCPDISCOVER packet.

Parameters
netdevNetwork device
dataBuffer for DHCP packet
max_lenSize of DHCP packet buffer
Return values
rcReturn status code

Used by external code.

Definition at line 109 of file fakedhcp.c.

110  {
111  struct dhcp_packet dhcppkt;
112  struct in_addr ciaddr = { 0 };
113  int rc;
114 
115  if ( ( rc = dhcp_create_request ( &dhcppkt, netdev, DHCPDISCOVER,
116  dhcp_last_xid, ciaddr, data,
117  max_len ) ) != 0 ) {
118  DBG ( "Could not create DHCPDISCOVER: %s\n",
119  strerror ( rc ) );
120  return rc;
121  }
122 
123  return 0;
124 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
A DHCP packet.
Definition: dhcppkt.h:20
static void size_t size_t max_len
Definition: entropy.h:153
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.
Definition: dhcp.c:977
static struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define DHCPDISCOVER
Definition: dhcp.h:195
IP address structure.
Definition: in.h:39
uint32_t dhcp_last_xid
Most recent DHCP transaction ID.
Definition: dhcp.c:123
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498

References data, DBG, dhcp_create_request(), dhcp_last_xid, DHCPDISCOVER, max_len, netdev, rc, and strerror().

Referenced by efi_pxe_fake_all().

◆ create_fakedhcpack()

int create_fakedhcpack ( struct net_device netdev,
void *  data,
size_t  max_len 
)

Create fake DHCPACK packet.

Parameters
netdevNetwork device
dataBuffer for DHCP packet
max_lenSize of DHCP packet buffer
Return values
rcReturn status code

Used by external code.

Definition at line 136 of file fakedhcp.c.

137  {
138  struct dhcp_packet dhcppkt;
139  int rc;
140 
141  /* Create base DHCPACK packet */
142  if ( ( rc = dhcp_create_packet ( &dhcppkt, netdev, DHCPACK,
143  dhcp_last_xid, NULL, 0,
144  data, max_len ) ) != 0 ) {
145  DBG ( "Could not create DHCPACK: %s\n", strerror ( rc ) );
146  return rc;
147  }
148 
149  /* Merge in globally-scoped settings, then netdev-specific
150  * settings. Do it in this order so that netdev-specific
151  * settings take precedence regardless of stated priorities.
152  */
153  if ( ( rc = copy_settings ( &dhcppkt, NULL ) ) != 0 ) {
154  DBG ( "Could not set DHCPACK global settings: %s\n",
155  strerror ( rc ) );
156  return rc;
157  }
158  if ( ( rc = copy_settings ( &dhcppkt,
159  netdev_settings ( netdev ) ) ) != 0 ) {
160  DBG ( "Could not set DHCPACK netdev settings: %s\n",
161  strerror ( rc ) );
162  return rc;
163  }
164 
165  return 0;
166 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
A DHCP packet.
Definition: dhcppkt.h:20
static void size_t size_t max_len
Definition: entropy.h:153
static int copy_settings(struct dhcp_packet *dest, struct settings *source)
Copy settings to DHCP packet.
Definition: fakedhcp.c:94
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition: netdevice.h:577
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 struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define DHCPACK
Definition: dhcp.h:199
uint32_t dhcp_last_xid
Most recent DHCP transaction ID.
Definition: dhcp.c:123
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References copy_settings(), data, DBG, dhcp_create_packet(), dhcp_last_xid, DHCPACK, max_len, netdev, netdev_settings(), NULL, rc, and strerror().

Referenced by create_fakepxebsack(), efi_pxe_fake_all(), and nbi_prepare_dhcp().

◆ create_fakepxebsack()

int create_fakepxebsack ( struct net_device netdev,
void *  data,
size_t  max_len 
)

Create fake PXE Boot Server ACK packet.

Parameters
netdevNetwork device
dataBuffer for DHCP packet
max_lenSize of DHCP packet buffer
Return values
rcReturn status code

Used by external code.

Definition at line 178 of file fakedhcp.c.

179  {
180  struct dhcp_packet dhcppkt;
181  struct settings *proxy_settings;
182  struct settings *pxebs_settings;
183  int rc;
184 
185  /* Identify available settings */
186  proxy_settings = find_settings ( PROXYDHCP_SETTINGS_NAME );
187  pxebs_settings = find_settings ( PXEBS_SETTINGS_NAME );
188  if ( ( ! proxy_settings ) && ( ! pxebs_settings ) ) {
189  /* No PXE boot server; return the regular DHCPACK */
190  return create_fakedhcpack ( netdev, data, max_len );
191  }
192 
193  /* Create base DHCPACK packet */
194  if ( ( rc = dhcp_create_packet ( &dhcppkt, netdev, DHCPACK,
195  dhcp_last_xid, NULL, 0,
196  data, max_len ) ) != 0 ) {
197  DBG ( "Could not create PXE BS ACK: %s\n",
198  strerror ( rc ) );
199  return rc;
200  }
201 
202  /* Populate ciaddr */
203  fetch_ipv4_setting ( netdev_settings ( netdev ), &ip_setting,
204  &dhcppkt.dhcphdr->ciaddr );
205 
206  /* Merge in ProxyDHCP options */
207  if ( proxy_settings &&
208  ( ( rc = copy_settings ( &dhcppkt, proxy_settings ) ) != 0 ) ) {
209  DBG ( "Could not copy ProxyDHCP settings: %s\n",
210  strerror ( rc ) );
211  return rc;
212  }
213 
214  /* Merge in BootServerDHCP options, if present */
215  if ( pxebs_settings &&
216  ( ( rc = copy_settings ( &dhcppkt, pxebs_settings ) ) != 0 ) ) {
217  DBG ( "Could not copy PXE BS settings: %s\n",
218  strerror ( rc ) );
219  return rc;
220  }
221 
222  return 0;
223 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
A DHCP packet.
Definition: dhcppkt.h:20
static void size_t size_t max_len
Definition: entropy.h:153
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
int create_fakedhcpack(struct net_device *netdev, void *data, size_t max_len)
Create fake DHCPACK packet.
Definition: fakedhcp.c:136
static int copy_settings(struct dhcp_packet *dest, struct settings *source)
Copy settings to DHCP packet.
Definition: fakedhcp.c:94
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition: netdevice.h:577
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
#define PROXYDHCP_SETTINGS_NAME
Settings block name used for ProxyDHCP responses.
Definition: dhcp.h:689
static struct net_device * netdev
Definition: gdbudp.c:52
#define PXEBS_SETTINGS_NAME
Setting block name used for BootServerDHCP responses.
Definition: dhcp.h:692
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
A settings block.
Definition: settings.h:132
#define DHCPACK
Definition: dhcp.h:199
uint32_t dhcp_last_xid
Most recent DHCP transaction ID.
Definition: dhcp.c:123
struct settings * find_settings(const char *name)
Find settings block.
Definition: settings.c:406
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References dhcphdr::ciaddr, copy_settings(), create_fakedhcpack(), data, DBG, dhcp_create_packet(), dhcp_last_xid, DHCPACK, dhcp_packet::dhcphdr, fetch_ipv4_setting(), find_settings(), max_len, netdev, netdev_settings(), NULL, PROXYDHCP_SETTINGS_NAME, PXEBS_SETTINGS_NAME, rc, and strerror().

Referenced by efi_pxe_fake_all().