aboutsummaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorMichael Brown <mcb30@etherboot.org>2008-03-21 00:26:29 +0000
committerMichael Brown <mcb30@etherboot.org>2008-03-21 00:26:29 +0000
commit1edbcd4246c3de183b1d34ebbc12f4ed19d11aa8 (patch)
treede3f0f0db387796598f2120a8fe5e339e5316f5b /src/net
parent720e256c5022adb8713e0d682067958244800f46 (diff)
downloadipxe-1edbcd4246c3de183b1d34ebbc12f4ed19d11aa8.zip
ipxe-1edbcd4246c3de183b1d34ebbc12f4ed19d11aa8.tar.gz
ipxe-1edbcd4246c3de183b1d34ebbc12f4ed19d11aa8.tar.bz2
[Settings] Use a settings applicator to set the default TFTP URI.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/dhcpopts.c35
-rw-r--r--src/net/udp/tftp.c43
2 files changed, 43 insertions, 35 deletions
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,
+};