mirror of
https://github.com/xcat2/xNBA.git
synced 2024-11-22 17:41:55 +00:00
[Settings] Use a settings applicator to set the default TFTP URI.
This commit is contained in:
parent
720e256c50
commit
1edbcd4246
@ -542,9 +542,6 @@ extern void find_global_dhcp_ipv4_option ( unsigned int tag,
|
||||
extern void delete_dhcp_option ( struct dhcp_option_block *options,
|
||||
unsigned int tag );
|
||||
|
||||
extern int apply_dhcp_options ( struct dhcp_option_block *options );
|
||||
extern int apply_global_dhcp_options ( void );
|
||||
|
||||
extern int create_dhcp_request ( struct net_device *netdev, int msgtype,
|
||||
struct dhcp_option_block *options,
|
||||
void *data, size_t max_len,
|
||||
|
@ -284,8 +284,6 @@ void register_dhcp_options ( struct dhcp_option_block *options ) {
|
||||
dhcpopt_get ( options );
|
||||
list_add_tail ( &options->list, &existing->list );
|
||||
|
||||
/* Apply all registered DHCP options */
|
||||
apply_global_dhcp_options();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -564,36 +562,3 @@ void delete_dhcp_option ( struct dhcp_option_block *options,
|
||||
unsigned int tag ) {
|
||||
set_dhcp_option ( options, tag, NULL, 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply DHCP options
|
||||
*
|
||||
* @v options DHCP options block, or NULL
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
int apply_dhcp_options ( struct dhcp_option_block *options ) {
|
||||
struct in_addr tftp_server;
|
||||
struct uri *uri;
|
||||
char uri_string[32];
|
||||
|
||||
/* Set current working URI based on TFTP server */
|
||||
find_dhcp_ipv4_option ( options, DHCP_EB_SIADDR, &tftp_server );
|
||||
snprintf ( uri_string, sizeof ( uri_string ),
|
||||
"tftp://%s/", inet_ntoa ( tftp_server ) );
|
||||
uri = parse_uri ( uri_string );
|
||||
if ( ! uri )
|
||||
return -ENOMEM;
|
||||
churi ( uri );
|
||||
uri_put ( uri );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply global DHCP options
|
||||
*
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
int apply_global_dhcp_options ( void ) {
|
||||
return apply_dhcp_options ( NULL );
|
||||
}
|
||||
|
@ -32,6 +32,9 @@
|
||||
#include <gpxe/retry.h>
|
||||
#include <gpxe/features.h>
|
||||
#include <gpxe/bitmap.h>
|
||||
#include <gpxe/settings.h>
|
||||
#include <gpxe/dhcp.h>
|
||||
#include <gpxe/uri.h>
|
||||
#include <gpxe/tftp.h>
|
||||
|
||||
/** @file
|
||||
@ -1089,3 +1092,43 @@ struct uri_opener mtftp_uri_opener __uri_opener = {
|
||||
.scheme = "mtftp",
|
||||
.open = mtftp_open,
|
||||
};
|
||||
|
||||
/**
|
||||
* Apply TFTP configuration settings
|
||||
*
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int tftp_apply_settings ( void ) {
|
||||
static struct in_addr tftp_server = { 0 };
|
||||
struct in_addr last_tftp_server;
|
||||
char uri_string[32];
|
||||
struct uri *uri;
|
||||
|
||||
/* Retrieve TFTP server setting */
|
||||
last_tftp_server = tftp_server;
|
||||
fetch_ipv4_setting ( NULL, DHCP_EB_SIADDR, &tftp_server );
|
||||
|
||||
/* If TFTP server setting has changed, set the current working
|
||||
* URI to match. Do it only when the TFTP server has changed
|
||||
* to try to minimise surprises to the user, who probably
|
||||
* won't expect the CWURI to change just because they updated
|
||||
* an unrelated setting and triggered all the settings
|
||||
* applicators.
|
||||
*/
|
||||
if ( tftp_server.s_addr != last_tftp_server.s_addr ) {
|
||||
snprintf ( uri_string, sizeof ( uri_string ),
|
||||
"tftp://%s/", inet_ntoa ( tftp_server ) );
|
||||
uri = parse_uri ( uri_string );
|
||||
if ( ! uri )
|
||||
return -ENOMEM;
|
||||
churi ( uri );
|
||||
uri_put ( uri );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** TFTP settings applicator */
|
||||
struct settings_applicator tftp_settings_applicator __settings_applicator = {
|
||||
.apply = tftp_apply_settings,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user