diff options
-rw-r--r-- | src/include/gpxe/dhcp.h | 3 | ||||
-rw-r--r-- | src/net/dhcpopts.c | 35 | ||||
-rw-r--r-- | src/net/udp/tftp.c | 43 |
3 files changed, 43 insertions, 38 deletions
diff --git a/src/include/gpxe/dhcp.h b/src/include/gpxe/dhcp.h index de10cc9..7a52477 100644 --- a/src/include/gpxe/dhcp.h +++ b/src/include/gpxe/dhcp.h @@ -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, diff --git a/src/net/dhcpopts.c b/src/net/dhcpopts.c index 75a9f2a..25b517d 100644 --- a/src/net/dhcpopts.c +++ b/src/net/dhcpopts.c @@ -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 ); -} diff --git a/src/net/udp/tftp.c b/src/net/udp/tftp.c index e969800..8bd2b80 100644 --- a/src/net/udp/tftp.c +++ b/src/net/udp/tftp.c @@ -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, +}; |