浏览代码

[Settings] Use a settings applicator to set the default TFTP URI.

tags/v0.9.4
Michael Brown 16 年前
父节点
当前提交
1edbcd4246
共有 3 个文件被更改,包括 43 次插入38 次删除
  1. 0
    3
      src/include/gpxe/dhcp.h
  2. 0
    35
      src/net/dhcpopts.c
  3. 43
    0
      src/net/udp/tftp.c

+ 0
- 3
src/include/gpxe/dhcp.h 查看文件

@@ -542,9 +542,6 @@ extern void find_global_dhcp_ipv4_option ( unsigned int tag,
542 542
 extern void delete_dhcp_option ( struct dhcp_option_block *options,
543 543
 				 unsigned int tag );
544 544
 
545
-extern int apply_dhcp_options ( struct dhcp_option_block *options );
546
-extern int apply_global_dhcp_options ( void );
547
-
548 545
 extern int create_dhcp_request ( struct net_device *netdev, int msgtype,
549 546
 				 struct dhcp_option_block *options,
550 547
 				 void *data, size_t max_len,

+ 0
- 35
src/net/dhcpopts.c 查看文件

@@ -284,8 +284,6 @@ void register_dhcp_options ( struct dhcp_option_block *options ) {
284 284
 	dhcpopt_get ( options );
285 285
 	list_add_tail ( &options->list, &existing->list );
286 286
 
287
-	/* Apply all registered DHCP options */
288
-	apply_global_dhcp_options();
289 287
 }
290 288
 
291 289
 /**
@@ -564,36 +562,3 @@ void delete_dhcp_option ( struct dhcp_option_block *options,
564 562
 			  unsigned int tag ) {
565 563
 	set_dhcp_option ( options, tag, NULL, 0 );
566 564
 }
567
-
568
-/**
569
- * Apply DHCP options
570
- *
571
- * @v options		DHCP options block, or NULL
572
- * @ret rc		Return status code
573
- */
574
-int apply_dhcp_options ( struct dhcp_option_block *options ) {
575
-	struct in_addr tftp_server;
576
-	struct uri *uri;
577
-	char uri_string[32];
578
-
579
-	/* Set current working URI based on TFTP server */
580
-	find_dhcp_ipv4_option ( options, DHCP_EB_SIADDR, &tftp_server );
581
-	snprintf ( uri_string, sizeof ( uri_string ),
582
-		   "tftp://%s/", inet_ntoa ( tftp_server ) );
583
-	uri = parse_uri ( uri_string );
584
-	if ( ! uri )
585
-		return -ENOMEM;
586
-	churi ( uri );
587
-	uri_put ( uri );
588
-
589
-	return 0;
590
-}
591
-
592
-/**
593
- * Apply global DHCP options
594
- *
595
- * @ret rc		Return status code
596
- */
597
-int apply_global_dhcp_options ( void ) {
598
-	return apply_dhcp_options ( NULL );
599
-}

+ 43
- 0
src/net/udp/tftp.c 查看文件

@@ -32,6 +32,9 @@
32 32
 #include <gpxe/retry.h>
33 33
 #include <gpxe/features.h>
34 34
 #include <gpxe/bitmap.h>
35
+#include <gpxe/settings.h>
36
+#include <gpxe/dhcp.h>
37
+#include <gpxe/uri.h>
35 38
 #include <gpxe/tftp.h>
36 39
 
37 40
 /** @file
@@ -1089,3 +1092,43 @@ struct uri_opener mtftp_uri_opener __uri_opener = {
1089 1092
 	.scheme	= "mtftp",
1090 1093
 	.open	= mtftp_open,
1091 1094
 };
1095
+
1096
+/**
1097
+ * Apply TFTP configuration settings
1098
+ *
1099
+ * @ret rc		Return status code
1100
+ */
1101
+static int tftp_apply_settings ( void ) {
1102
+	static struct in_addr tftp_server = { 0 };
1103
+	struct in_addr last_tftp_server;
1104
+	char uri_string[32];
1105
+	struct uri *uri;
1106
+
1107
+	/* Retrieve TFTP server setting */
1108
+	last_tftp_server = tftp_server;
1109
+	fetch_ipv4_setting ( NULL, DHCP_EB_SIADDR, &tftp_server );
1110
+
1111
+	/* If TFTP server setting has changed, set the current working
1112
+	 * URI to match.  Do it only when the TFTP server has changed
1113
+	 * to try to minimise surprises to the user, who probably
1114
+	 * won't expect the CWURI to change just because they updated
1115
+	 * an unrelated setting and triggered all the settings
1116
+	 * applicators.
1117
+	 */
1118
+	if ( tftp_server.s_addr != last_tftp_server.s_addr ) {
1119
+		snprintf ( uri_string, sizeof ( uri_string ),
1120
+			   "tftp://%s/", inet_ntoa ( tftp_server ) );
1121
+		uri = parse_uri ( uri_string );
1122
+		if ( ! uri )
1123
+			return -ENOMEM;
1124
+		churi ( uri );
1125
+		uri_put ( uri );
1126
+	}
1127
+
1128
+	return 0;
1129
+}
1130
+
1131
+/** TFTP settings applicator */
1132
+struct settings_applicator tftp_settings_applicator __settings_applicator = {
1133
+	.apply = tftp_apply_settings,
1134
+};

正在加载...
取消
保存