summaryrefslogtreecommitdiffstats
path: root/src/net/udp/tftp.c
diff options
context:
space:
mode:
authorMichael Brown2008-03-21 01:26:29 +0100
committerMichael Brown2008-03-21 01:26:29 +0100
commit1edbcd4246c3de183b1d34ebbc12f4ed19d11aa8 (patch)
treede3f0f0db387796598f2120a8fe5e339e5316f5b /src/net/udp/tftp.c
parent[Misc] Kill off long-redundant tests/dhcptest.c (diff)
downloadipxe-1edbcd4246c3de183b1d34ebbc12f4ed19d11aa8.tar.gz
ipxe-1edbcd4246c3de183b1d34ebbc12f4ed19d11aa8.tar.xz
ipxe-1edbcd4246c3de183b1d34ebbc12f4ed19d11aa8.zip
[Settings] Use a settings applicator to set the default TFTP URI.
Diffstat (limited to 'src/net/udp/tftp.c')
-rw-r--r--src/net/udp/tftp.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/net/udp/tftp.c b/src/net/udp/tftp.c
index e9698004..8bd2b80b 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,
+};