瀏覽代碼

[settings] Explicitly separate the concept of a completed fetched setting

The fetch_setting() family of functions may currently modify the
definition of the specified setting (e.g. to add missing type
information).  Clean up this interface by requiring callers to provide
an explicit buffer to contain the completed definition of the fetched
setting, if required.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 年之前
父節點
當前提交
22001cb206

+ 1
- 1
src/arch/i386/interface/vmware/guestinfo.c 查看文件

@@ -51,7 +51,7 @@ static int guestinfo_channel;
51 51
  */
52 52
 static int guestinfo_fetch_type ( struct settings *settings,
53 53
 				  struct setting *setting,
54
-				  struct setting_type *type,
54
+				  const struct setting_type *type,
55 55
 				  void *data, size_t len, int *found ) {
56 56
 	const char *parent_name = settings->parent->name;
57 57
 	char command[ 24 /* "info-get guestinfo.ipxe." */ +

+ 3
- 3
src/arch/x86/core/cpuid_settings.c 查看文件

@@ -117,7 +117,7 @@ enum cpuid_registers {
117 117
 #define CPUID_NUM_REGISTERS( tag ) ( ( ( (tag) >> 16 ) & 0x3 ) + 1 )
118 118
 
119 119
 /** CPUID settings scope */
120
-static struct settings_scope cpuid_settings_scope;
120
+static const struct settings_scope cpuid_settings_scope;
121 121
 
122 122
 /**
123 123
  * Check applicability of CPUID setting
@@ -127,7 +127,7 @@ static struct settings_scope cpuid_settings_scope;
127 127
  * @ret applies		Setting applies within this settings block
128 128
  */
129 129
 static int cpuid_settings_applies ( struct settings *settings __unused,
130
-				    struct setting *setting ) {
130
+				    const struct setting *setting ) {
131 131
 
132 132
 	return ( setting->scope == &cpuid_settings_scope );
133 133
 }
@@ -252,7 +252,7 @@ struct init_fn cpuid_settings_init_fn __init_fn ( INIT_NORMAL ) = {
252 252
 };
253 253
 
254 254
 /** CPUID predefined settings */
255
-struct setting cpuid_predefined_settings[] __setting ( SETTING_HOST_EXTRA ) = {
255
+const struct setting cpuid_predefined_settings[] __setting ( SETTING_HOST_EXTRA ) = {
256 256
 	{
257 257
 		.name = "cpuvendor",
258 258
 		.description = "CPU vendor",

+ 3
- 3
src/core/memmap_settings.c 查看文件

@@ -108,7 +108,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
108 108
 #define MEMMAP_SCALE( tag ) ( (tag) & 0x3f )
109 109
 
110 110
 /** Memory map settings scope */
111
-static struct settings_scope memmap_settings_scope;
111
+static const struct settings_scope memmap_settings_scope;
112 112
 
113 113
 /**
114 114
  * Check applicability of memory map setting
@@ -118,7 +118,7 @@ static struct settings_scope memmap_settings_scope;
118 118
  * @ret applies		Setting applies within this settings block
119 119
  */
120 120
 static int memmap_settings_applies ( struct settings *settings __unused,
121
-				     struct setting *setting ) {
121
+				     const struct setting *setting ) {
122 122
 
123 123
 	return ( setting->scope == &memmap_settings_scope );
124 124
 }
@@ -231,7 +231,7 @@ struct init_fn memmap_settings_init_fn __init_fn ( INIT_NORMAL ) = {
231 231
 };
232 232
 
233 233
 /** Memory map predefined settings */
234
-struct setting memmap_predefined_settings[] __setting ( SETTING_MISC ) = {
234
+const struct setting memmap_predefined_settings[] __setting ( SETTING_MISC ) = {
235 235
 	{
236 236
 		.name = "memsize",
237 237
 		.description = "Memory size (in MB)",

+ 2
- 2
src/core/nvo.c 查看文件

@@ -193,7 +193,7 @@ static int nvo_save ( struct nvo_block *nvo ) {
193 193
  * @ret applies		Setting applies within this settings block
194 194
  */
195 195
 int nvo_applies ( struct settings *settings __unused,
196
-		  struct setting *setting ) {
196
+		  const struct setting *setting ) {
197 197
 
198 198
 	return ( ( setting->scope == NULL ) &&
199 199
 		 dhcpopt_applies ( setting->tag ) );
@@ -208,7 +208,7 @@ int nvo_applies ( struct settings *settings __unused,
208 208
  * @v len		Length of setting data
209 209
  * @ret rc		Return status code
210 210
  */
211
-static int nvo_store ( struct settings *settings, struct setting *setting,
211
+static int nvo_store ( struct settings *settings, const struct setting *setting,
212 212
 		       const void *data, size_t len ) {
213 213
 	struct nvo_block *nvo =
214 214
 		container_of ( settings, struct nvo_block, settings );

+ 253
- 187
src/core/settings.c
文件差異過大導致無法顯示
查看文件


+ 4
- 4
src/crypto/clientcert.c 查看文件

@@ -128,8 +128,8 @@ static int clientcert_apply_settings ( void ) {
128 128
 
129 129
 		/* Fetch new client certificate, if any */
130 130
 		free ( cert );
131
-		if ( ( len = fetch_setting_copy ( NULL, &cert_setting,
132
-						  &cert ) ) >= 0 ) {
131
+		if ( ( len = fetch_raw_setting_copy ( NULL, &cert_setting,
132
+						      &cert ) ) >= 0 ) {
133 133
 			client_certificate.data = cert;
134 134
 			client_certificate.len = len;
135 135
 		}
@@ -140,8 +140,8 @@ static int clientcert_apply_settings ( void ) {
140 140
 
141 141
 		/* Fetch new client private key, if any */
142 142
 		free ( key );
143
-		if ( ( len = fetch_setting_copy ( NULL, &privkey_setting,
144
-						  &key ) ) >= 0 ) {
143
+		if ( ( len = fetch_raw_setting_copy ( NULL, &privkey_setting,
144
+						      &key ) ) >= 0 ) {
145 145
 			client_private_key.data = key;
146 146
 			client_private_key.len = len;
147 147
 		}

+ 2
- 2
src/crypto/rootcert.c 查看文件

@@ -100,8 +100,8 @@ static void rootcert_init ( void ) {
100 100
 		/* Fetch copy of "trust" setting, if it exists.  This
101 101
 		 * memory will never be freed.
102 102
 		 */
103
-		if ( ( len = fetch_setting_copy ( NULL, &trust_setting,
104
-						  &external ) ) >= 0 ) {
103
+		if ( ( len = fetch_raw_setting_copy ( NULL, &trust_setting,
104
+						      &external ) ) >= 0 ) {
105 105
 			root_certificates.fingerprints = external;
106 106
 			root_certificates.count = ( len / FINGERPRINT_LEN );
107 107
 		}

+ 6
- 4
src/drivers/block/ibft.c 查看文件

@@ -107,7 +107,7 @@ static void ibft_set_ipaddr ( struct ibft_ipaddr *ipaddr, struct in_addr in ) {
107 107
  * @v count		Maximum number of IP addresses
108 108
  */
109 109
 static void ibft_set_ipaddr_setting ( struct ibft_ipaddr *ipaddr,
110
-				      struct setting *setting,
110
+				      const struct setting *setting,
111 111
 				      unsigned int count ) {
112 112
 	struct in_addr in[count];
113 113
 	unsigned int i;
@@ -183,11 +183,13 @@ static int ibft_set_string ( struct ibft_strings *strings,
183 183
  */
184 184
 static int ibft_set_string_setting ( struct ibft_strings *strings,
185 185
 				     struct ibft_string *string,
186
-				     struct setting *setting ) {
186
+				     const struct setting *setting ) {
187
+	struct settings *origin;
188
+	struct setting fetched;
187 189
 	int len;
188 190
 	char *dest;
189 191
 
190
-	len = fetch_setting_len ( NULL, setting );
192
+	len = fetch_setting ( NULL, setting, &origin, &fetched, NULL, 0 );
191 193
 	if ( len < 0 ) {
192 194
 		string->offset = 0;
193 195
 		string->len = 0;
@@ -197,7 +199,7 @@ static int ibft_set_string_setting ( struct ibft_strings *strings,
197 199
 	dest = ibft_alloc_string ( strings, string, len );
198 200
 	if ( ! dest )
199 201
 		return -ENOBUFS;
200
-	fetch_string_setting ( NULL, setting, dest, ( len + 1 ) );
202
+	fetch_string_setting ( origin, &fetched, dest, ( len + 1 ));
201 203
 
202 204
 	return 0;
203 205
 }

+ 2
- 2
src/drivers/bus/pci_settings.c 查看文件

@@ -32,7 +32,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
32 32
  */
33 33
 
34 34
 /** PCI device settings scope */
35
-static struct settings_scope pci_settings_scope;
35
+static const struct settings_scope pci_settings_scope;
36 36
 
37 37
 /**
38 38
  * Check applicability of PCI device setting
@@ -42,7 +42,7 @@ static struct settings_scope pci_settings_scope;
42 42
  * @ret applies		Setting applies within this settings block
43 43
  */
44 44
 static int pci_settings_applies ( struct settings *settings __unused,
45
-				  struct setting *setting ) {
45
+				  const struct setting *setting ) {
46 46
 
47 47
 	return ( setting->scope == &pci_settings_scope );
48 48
 }

+ 6
- 5
src/drivers/net/phantom/phantom.c 查看文件

@@ -1455,7 +1455,7 @@ static struct net_device_operations phantom_operations = {
1455 1455
  */
1456 1456
 
1457 1457
 /** Phantom CLP settings scope */
1458
-static struct settings_scope phantom_settings_scope;
1458
+static const struct settings_scope phantom_settings_scope;
1459 1459
 
1460 1460
 /** Phantom CLP data
1461 1461
  *
@@ -1656,7 +1656,7 @@ static int phantom_clp_fetch ( struct phantom_nic *phantom, unsigned int port,
1656 1656
 /** A Phantom CLP setting */
1657 1657
 struct phantom_clp_setting {
1658 1658
 	/** iPXE setting */
1659
-	struct setting *setting;
1659
+	const struct setting *setting;
1660 1660
 	/** Setting number */
1661 1661
 	unsigned int clp_setting;
1662 1662
 };
@@ -1673,7 +1673,8 @@ static struct phantom_clp_setting clp_settings[] = {
1673 1673
  * @v clp_setting	Setting number, or 0 if not found
1674 1674
  */
1675 1675
 static unsigned int
1676
-phantom_clp_setting ( struct phantom_nic *phantom, struct setting *setting ) {
1676
+phantom_clp_setting ( struct phantom_nic *phantom,
1677
+		      const struct setting *setting ) {
1677 1678
 	struct phantom_clp_setting *clp_setting;
1678 1679
 	unsigned int i;
1679 1680
 
@@ -1703,7 +1704,7 @@ phantom_clp_setting ( struct phantom_nic *phantom, struct setting *setting ) {
1703 1704
  * @ret applies		Setting applies within this settings block
1704 1705
  */
1705 1706
 static int phantom_setting_applies ( struct settings *settings,
1706
-				     struct setting *setting ) {
1707
+				     const struct setting *setting ) {
1707 1708
 	struct phantom_nic *phantom =
1708 1709
 		container_of ( settings, struct phantom_nic, settings );
1709 1710
 	unsigned int clp_setting;
@@ -1723,7 +1724,7 @@ static int phantom_setting_applies ( struct settings *settings,
1723 1724
  * @ret rc		Return status code
1724 1725
  */
1725 1726
 static int phantom_store_setting ( struct settings *settings,
1726
-				   struct setting *setting,
1727
+				   const struct setting *setting,
1727 1728
 				   const void *data, size_t len ) {
1728 1729
 	struct phantom_nic *phantom =
1729 1730
 		container_of ( settings, struct phantom_nic, settings );

+ 11
- 12
src/hci/commands/nvo_cmd.c 查看文件

@@ -58,8 +58,10 @@ static int show_exec ( int argc, char **argv ) {
58 58
 	struct show_options opts;
59 59
 	struct named_setting setting;
60 60
 	struct settings *origin;
61
+	struct setting fetched;
61 62
 	char name_buf[32];
62 63
 	char *value;
64
+	int len;
63 65
 	int rc;
64 66
 
65 67
 	/* Parse options */
@@ -71,19 +73,16 @@ static int show_exec ( int argc, char **argv ) {
71 73
 		goto err_parse_setting;
72 74
 
73 75
 	/* Fetch formatted setting value */
74
-	if ( ( rc = fetchf_setting_copy ( setting.settings, &setting.setting,
75
-					  &value ) ) < 0 ) {
76
+	if ( ( len = fetchf_setting_copy ( setting.settings, &setting.setting,
77
+					   &origin, &fetched, &value ) ) < 0 ) {
78
+		rc = len;
76 79
 		printf ( "Could not find \"%s\": %s\n",
77 80
 			 setting.setting.name, strerror ( rc ) );
78 81
 		goto err_fetchf;
79 82
 	}
80 83
 
81
-	/* Fetch origin and format fully-qualified name */
82
-	origin = fetch_setting_origin ( setting.settings, &setting.setting );
83
-	assert ( origin != NULL );
84
-	setting_name ( origin, &setting.setting, name_buf, sizeof ( name_buf ));
85
-
86 84
 	/* Print setting value */
85
+	setting_name ( origin, &fetched, name_buf, sizeof ( name_buf ) );
87 86
 	printf ( "%s = %s\n", name_buf, value );
88 87
 
89 88
 	/* Success */
@@ -234,7 +233,8 @@ static int read_value ( struct named_setting *setting, char **args __unused,
234 233
 	/* Read existing value, treating errors as equivalent to an
235 234
 	 * empty initial setting.
236 235
 	 */
237
-	fetchf_setting_copy ( setting->settings, &setting->setting, &existing );
236
+	fetchf_setting_copy ( setting->settings, &setting->setting,
237
+			      NULL, &setting->setting, &existing );
238 238
 
239 239
 	/* Read new value */
240 240
 	if ( ( rc = readline_history ( NULL, existing, NULL, value ) ) != 0 )
@@ -294,12 +294,11 @@ static int inc_exec ( int argc, char **argv ) {
294 294
 	     ( ( rc = parse_integer ( argv[ optind + 1 ], &increment ) ) != 0))
295 295
 		goto err_parse_increment;
296 296
 
297
-	/* Fetch existing setting value, if any, allowing for the fact
298
-	 * that numeric settings are big-endian and variable-length.
297
+	/* Read existing value, treating errors as equivalent to a
298
+	 * zero-valued :int32 initial setting.
299 299
 	 */
300 300
 	if ( ( rc = fetchn_setting ( setting.settings, &setting.setting,
301
-				     &value ) ) != 0 ) {
302
-		/* Treat as a non-existent :int32 setting with a zero value */
301
+				     NULL, &setting.setting, &value ) ) != 0 ) {
303 302
 		value = 0;
304 303
 		if ( ! setting.setting.type )
305 304
 			setting.setting.type = &setting_type_int32;

+ 2
- 2
src/hci/commands/pci_cmd.c 查看文件

@@ -68,8 +68,8 @@ static int pciscan_exec ( int argc, char **argv ) {
68 68
 		goto err_parse_setting;
69 69
 
70 70
 	/* Determine starting bus:dev.fn address */
71
-	if ( ( len = fetch_uint_setting ( setting.settings, &setting.setting,
72
-					  &prev ) ) < 0 ) {
71
+	if ( ( len = fetchn_setting ( setting.settings, &setting.setting,
72
+				      NULL, &setting.setting, &prev ) ) < 0 ) {
73 73
 		/* Setting not yet defined: start searching from 00:00.0 */
74 74
 		prev = 0;
75 75
 	} else {

+ 28
- 31
src/hci/tui/settings_ui.c 查看文件

@@ -72,11 +72,16 @@ struct setting_row_widget {
72 72
 	 * Valid only for rows that lead to new settings blocks.
73 73
 	 */
74 74
 	struct settings *settings;
75
+	/** Configuration setting origin
76
+	 *
77
+	 * Valid only for rows that represent individual settings.
78
+	 */
79
+	struct settings *origin;
75 80
 	/** Configuration setting
76 81
 	 *
77 82
 	 * Valid only for rows that represent individual settings.
78 83
 	 */
79
-	struct setting *setting;
84
+	struct setting setting;
80 85
 	/** Screen row */
81 86
 	unsigned int row;
82 87
 	/** Screen column */
@@ -85,8 +90,6 @@ struct setting_row_widget {
85 90
 	struct edit_box editbox;
86 91
 	/** Editing in progress flag */
87 92
 	int editing;
88
-	/** Setting originates from this block flag */
89
-	int originates_here;
90 93
 	/** Buffer for setting's value */
91 94
 	char value[256]; /* enough size for a DHCP string */
92 95
 };
@@ -115,7 +118,6 @@ struct setting_widget {
115 118
 static unsigned int select_setting_row ( struct setting_widget *widget,
116 119
 					 unsigned int index ) {
117 120
 	struct settings *settings;
118
-	struct settings *origin;
119 121
 	struct setting *setting;
120 122
 	unsigned int count = 0;
121 123
 
@@ -147,18 +149,13 @@ static unsigned int select_setting_row ( struct setting_widget *widget,
147 149
 		if ( ! setting_applies ( widget->settings, setting ) )
148 150
 			continue;
149 151
 		if ( count++ == index ) {
150
-			widget->row.setting = setting;
151 152
 
152
-			/* Read current setting value */
153
-			fetchf_setting ( widget->settings, widget->row.setting,
153
+			/* Read current setting value and origin */
154
+			fetchf_setting ( widget->settings, setting,
155
+					 &widget->row.origin,
156
+					 &widget->row.setting,
154 157
 					 widget->row.value,
155 158
 					 sizeof ( widget->row.value ) );
156
-
157
-			/* Check setting's origin */
158
-			origin = fetch_setting_origin ( widget->settings,
159
-							widget->row.setting );
160
-			widget->row.originates_here =
161
-				( origin == widget->settings );
162 159
 		}
163 160
 	}
164 161
 
@@ -209,7 +206,7 @@ static void draw_setting_row ( struct setting_widget *widget ) {
209 206
 
210 207
 		/* Construct dot-padded name */
211 208
 		memset ( text.name, '.', sizeof ( text.name ) );
212
-		string_copy ( text.name, widget->row.setting->name,
209
+		string_copy ( text.name, widget->row.setting.name,
213 210
 			      sizeof ( text.name ) );
214 211
 
215 212
 		/* Construct space-padded value */
@@ -222,8 +219,10 @@ static void draw_setting_row ( struct setting_widget *widget ) {
222 219
 	}
223 220
 
224 221
 	/* Print row */
225
-	if ( widget->row.originates_here || widget->row.settings )
222
+	if ( ( widget->row.origin == widget->settings ) ||
223
+	     ( widget->row.settings != NULL ) ) {
226 224
 		attron ( A_BOLD );
225
+	}
227 226
 	mvprintw ( widget->row.row, widget->row.col, "%s", text.start );
228 227
 	attroff ( A_BOLD );
229 228
 	move ( widget->row.row, widget->row.col + curs_offset );
@@ -237,7 +236,7 @@ static void draw_setting_row ( struct setting_widget *widget ) {
237 236
  * @ret key		Key returned to application, or zero
238 237
  */
239 238
 static int edit_setting ( struct setting_widget *widget, int key ) {
240
-	assert ( widget->row.setting != NULL );
239
+	assert ( widget->row.setting.name != NULL );
241 240
 	widget->row.editing = 1;
242 241
 	return edit_editbox ( &widget->row.editbox, key );
243 242
 }
@@ -248,8 +247,8 @@ static int edit_setting ( struct setting_widget *widget, int key ) {
248 247
  * @v widget		Setting widget
249 248
  */
250 249
 static int save_setting ( struct setting_widget *widget ) {
251
-	assert ( widget->row.setting != NULL );
252
-	return storef_setting ( widget->settings, widget->row.setting,
250
+	assert ( widget->row.setting.name != NULL );
251
+	return storef_setting ( widget->settings, &widget->row.setting,
253 252
 				widget->row.value );
254 253
 }
255 254
 
@@ -344,28 +343,26 @@ static void draw_title_row ( struct setting_widget *widget ) {
344 343
  * @v widget		Setting widget
345 344
  */
346 345
 static void draw_info_row ( struct setting_widget *widget ) {
347
-	struct settings *origin;
348 346
 	char buf[32];
349 347
 
350 348
 	/* Draw nothing unless this row represents a setting */
351 349
 	clearmsg ( INFO_ROW );
352 350
 	clearmsg ( INFO_ROW + 1 );
353
-	if ( ! widget->row.setting )
351
+	if ( ! widget->row.setting.name )
354 352
 		return;
355 353
 
356 354
 	/* Determine a suitable setting name */
357
-	origin = fetch_setting_origin ( widget->settings, widget->row.setting );
358
-	if ( ! origin )
359
-		origin = widget->settings;
360
-	setting_name ( origin, widget->row.setting, buf, sizeof ( buf ) );
355
+	setting_name ( ( widget->row.origin ?
356
+			 widget->row.origin : widget->settings ),
357
+		       &widget->row.setting, buf, sizeof ( buf ) );
361 358
 
362 359
 	/* Draw row */
363 360
 	attron ( A_BOLD );
364
-	msg ( INFO_ROW, "%s - %s", buf, widget->row.setting->description );
361
+	msg ( INFO_ROW, "%s - %s", buf, widget->row.setting.description );
365 362
 	attroff ( A_BOLD );
366 363
 	color_set ( CPAIR_URL, NULL );
367 364
 	msg ( ( INFO_ROW + 1 ), "http://ipxe.org/cfg/%s",
368
-	      widget->row.setting->name );
365
+	      widget->row.setting.name );
369 366
 	color_set ( CPAIR_NORMAL, NULL );
370 367
 }
371 368
 
@@ -384,7 +381,7 @@ static void draw_instruction_row ( struct setting_widget *widget ) {
384 381
 	} else {
385 382
 		msg ( INSTRUCTION_ROW,
386 383
 		      "%sCtrl-X - exit configuration utility",
387
-		      ( widget->row.originates_here ?
384
+		      ( ( widget->row.origin == widget->settings ) ?
388 385
 			"Ctrl-D - delete setting" INSTRUCTION_PAD : "" ) );
389 386
 	}
390 387
 }
@@ -479,7 +476,7 @@ static int main_loop ( struct settings *settings ) {
479 476
 		if ( widget.row.editing ) {
480 477
 
481 478
 			/* Sanity check */
482
-			assert ( widget.row.setting != NULL );
479
+			assert ( widget.row.setting.name != NULL );
483 480
 
484 481
 			/* Redraw edit box */
485 482
 			color_set ( CPAIR_EDIT, NULL );
@@ -530,10 +527,10 @@ static int main_loop ( struct settings *settings ) {
530 527
 				move = +widget.num_rows;
531 528
 				break;
532 529
 			case CTRL_D:
533
-				if ( ! widget.row.setting )
530
+				if ( ! widget.row.setting.name )
534 531
 					break;
535 532
 				if ( ( rc = delete_setting ( widget.settings,
536
-						widget.row.setting ) ) != 0 ) {
533
+						&widget.row.setting ) ) != 0 ) {
537 534
 					alert ( " %s ", strerror ( rc ) );
538 535
 				}
539 536
 				select_setting_row ( &widget, widget.current );
@@ -550,7 +547,7 @@ static int main_loop ( struct settings *settings ) {
550 547
 				}
551 548
 				/* Fall through */
552 549
 			default:
553
-				if ( widget.row.setting ) {
550
+				if ( widget.row.setting.name ) {
554 551
 					edit_setting ( &widget, key );
555 552
 					redraw = 1;
556 553
 				}

+ 1
- 1
src/include/ipxe/net80211.h 查看文件

@@ -1093,7 +1093,7 @@ struct net80211_wlan
1093 1093
 
1094 1094
 
1095 1095
 /** 802.11 encryption key setting */
1096
-extern struct setting net80211_key_setting __setting ( SETTING_NETDEV_EXTRA );
1096
+extern const struct setting net80211_key_setting __setting ( SETTING_NETDEV_EXTRA );
1097 1097
 
1098 1098
 
1099 1099
 /**

+ 2
- 1
src/include/ipxe/nvo.h 查看文件

@@ -45,7 +45,8 @@ struct nvo_block {
45 45
 /** Name of non-volatile options settings block */
46 46
 #define NVO_SETTINGS_NAME "nvo"
47 47
 
48
-extern int nvo_applies ( struct settings *settings, struct setting *setting );
48
+extern int nvo_applies ( struct settings *settings,
49
+			 const struct setting *setting );
49 50
 extern void nvo_init ( struct nvo_block *nvo, struct nvs_device *nvs,
50 51
 		       size_t address, size_t len,
51 52
 		       int ( * resize ) ( struct nvo_block *nvo, size_t len ),

+ 99
- 81
src/include/ipxe/settings.h 查看文件

@@ -32,7 +32,7 @@ struct setting {
32 32
 	 * This identifies the type of setting (e.g. string, IPv4
33 33
 	 * address, etc.).
34 34
 	 */
35
-	struct setting_type *type;
35
+	const struct setting_type *type;
36 36
 	/** Setting tag, if applicable
37 37
 	 *
38 38
 	 * The setting tag is a numerical description of the setting
@@ -45,7 +45,7 @@ struct setting {
45 45
 	 * For historic reasons, a NULL scope with a non-zero tag
46 46
 	 * indicates a DHCPv4 option setting.
47 47
 	 */
48
-	struct settings_scope *scope;
48
+	const struct settings_scope *scope;
49 49
 };
50 50
 
51 51
 /** Configuration setting table */
@@ -90,7 +90,7 @@ struct settings_operations {
90 90
 	 * @ret applies		Setting applies within this settings block
91 91
 	 */
92 92
 	int ( * applies ) ( struct settings *settings,
93
-			    struct setting *setting );
93
+			    const struct setting *setting );
94 94
 	/** Store value of setting
95 95
 	 *
96 96
 	 * @v settings		Settings block
@@ -99,7 +99,8 @@ struct settings_operations {
99 99
 	 * @v len		Length of setting data
100 100
 	 * @ret rc		Return status code
101 101
 	 */
102
-	int ( * store ) ( struct settings *settings, struct setting *setting,
102
+	int ( * store ) ( struct settings *settings,
103
+			  const struct setting *setting,
103 104
 			  const void *data, size_t len );
104 105
 	/** Fetch value of setting
105 106
 	 *
@@ -136,7 +137,7 @@ struct settings {
136 137
 	/** Settings block operations */
137 138
 	struct settings_operations *op;
138 139
 	/** Default scope for numerical settings constructed for this block */
139
-	struct settings_scope *default_scope;
140
+	const struct settings_scope *default_scope;
140 141
 };
141 142
 
142 143
 /**
@@ -193,7 +194,7 @@ struct setting_type {
193 194
 	 * @v len		Length of buffer
194 195
 	 * @ret len		Length of raw value, or negative error
195 196
 	 */
196
-	int ( * parse ) ( struct setting_type *type, const char *value,
197
+	int ( * parse ) ( const struct setting_type *type, const char *value,
197 198
 			  void *buf, size_t len );
198 199
 	/** Format setting value as a string
199 200
 	 *
@@ -204,7 +205,7 @@ struct setting_type {
204 205
 	 * @v len		Length of buffer
205 206
 	 * @ret len		Length of formatted value, or negative error
206 207
 	 */
207
-	int ( * format ) ( struct setting_type *type, const void *raw,
208
+	int ( * format ) ( const struct setting_type *type, const void *raw,
208 209
 			   size_t raw_len, char *buf, size_t len );
209 210
 	/** Convert number to setting value
210 211
 	 *
@@ -214,7 +215,8 @@ struct setting_type {
214 215
 	 * @v len		Length of buffer
215 216
 	 * @ret len		Length of raw value, or negative error
216 217
 	 */
217
-	int ( * denumerate ) ( struct setting_type *type, unsigned long value,
218
+	int ( * denumerate ) ( const struct setting_type *type,
219
+			       unsigned long value,
218 220
 			       void *buf, size_t len );
219 221
 	/** Convert setting value to number
220 222
 	 *
@@ -224,7 +226,7 @@ struct setting_type {
224 226
 	 * @v value		Numeric value to fill in
225 227
 	 * @ret rc		Return status code
226 228
 	 */
227
-	int ( * numerate ) ( struct setting_type *type, const void *raw,
229
+	int ( * numerate ) ( const struct setting_type *type, const void *raw,
228 230
 			     size_t raw_len, unsigned long *value );
229 231
 };
230 232
 
@@ -256,7 +258,7 @@ struct settings_applicator {
256 258
 /** A built-in setting */
257 259
 struct builtin_setting {
258 260
 	/** Setting */
259
-	struct setting *setting;
261
+	const struct setting *setting;
260 262
 	/** Fetch setting value
261 263
 	 *
262 264
 	 * @v data		Buffer to fill with setting data
@@ -273,7 +275,7 @@ struct builtin_setting {
273 275
 #define __builtin_setting __table_entry ( BUILTIN_SETTINGS, 01 )
274 276
 
275 277
 /** Built-in setting scope */
276
-extern struct settings_scope builtin_scope;
278
+extern const struct settings_scope builtin_scope;
277 279
 
278 280
 /**
279 281
  * A generic settings block
@@ -291,7 +293,7 @@ typedef struct settings * ( *get_child_settings_t ) ( struct settings *settings,
291 293
 						      const char *name );
292 294
 extern struct settings_operations generic_settings_operations;
293 295
 extern int generic_settings_store ( struct settings *settings,
294
-				    struct setting *setting,
296
+				    const struct setting *setting,
295 297
 				    const void *data, size_t len );
296 298
 extern int generic_settings_fetch ( struct settings *settings,
297 299
 				    struct setting *setting,
@@ -304,42 +306,50 @@ extern void unregister_settings ( struct settings *settings );
304 306
 
305 307
 extern struct settings * settings_target ( struct settings *settings );
306 308
 extern int setting_applies ( struct settings *settings,
307
-			     struct setting *setting );
308
-extern int store_setting ( struct settings *settings, struct setting *setting,
309
+			     const struct setting *setting );
310
+extern int store_setting ( struct settings *settings,
311
+			   const struct setting *setting,
309 312
 			   const void *data, size_t len );
310
-extern int fetch_setting ( struct settings *settings, struct setting *setting,
313
+extern int fetch_setting ( struct settings *settings,
314
+			   const struct setting *setting,
315
+			   struct settings **origin, struct setting *fetched,
311 316
 			   void *data, size_t len );
312
-extern struct settings * fetch_setting_origin ( struct settings *settings,
313
-						struct setting *setting );
314
-extern int fetch_setting_len ( struct settings *settings,
315
-			       struct setting *setting );
316 317
 extern int fetch_setting_copy ( struct settings *settings,
317
-				struct setting *setting, void **data );
318
+				const struct setting *setting,
319
+				struct settings **origin,
320
+				struct setting *fetched, void **data );
321
+extern int fetch_raw_setting ( struct settings *settings,
322
+			       const struct setting *setting,
323
+			       void *data, size_t len );
324
+extern int fetch_raw_setting_copy ( struct settings *settings,
325
+				    const struct setting *setting,
326
+				    void **data );
318 327
 extern int fetch_string_setting ( struct settings *settings,
319
-				  struct setting *setting,
328
+				  const struct setting *setting,
320 329
 				  char *data, size_t len );
321 330
 extern int fetch_string_setting_copy ( struct settings *settings,
322
-				       struct setting *setting,
331
+				       const struct setting *setting,
323 332
 				       char **data );
324 333
 extern int fetch_ipv4_array_setting ( struct settings *settings,
325
-				      struct setting *setting,
326
-				      struct in_addr *inp,
327
-				      unsigned int count );
334
+				      const struct setting *setting,
335
+				      struct in_addr *inp, unsigned int count );
328 336
 extern int fetch_ipv4_setting ( struct settings *settings,
329
-				struct setting *setting, struct in_addr *inp );
337
+				const struct setting *setting,
338
+				struct in_addr *inp );
330 339
 extern int fetch_int_setting ( struct settings *settings,
331
-			       struct setting *setting, long *value );
340
+			       const struct setting *setting, long *value );
332 341
 extern int fetch_uint_setting ( struct settings *settings,
333
-				struct setting *setting,
342
+				const struct setting *setting,
334 343
 				unsigned long *value );
335 344
 extern long fetch_intz_setting ( struct settings *settings,
336
-				 struct setting *setting );
345
+				 const struct setting *setting );
337 346
 extern unsigned long fetch_uintz_setting ( struct settings *settings,
338
-					   struct setting *setting );
347
+					   const struct setting *setting );
339 348
 extern int fetch_uuid_setting ( struct settings *settings,
340
-				struct setting *setting, union uuid *uuid );
349
+				const struct setting *setting,
350
+				union uuid *uuid );
341 351
 extern void clear_settings ( struct settings *settings );
342
-extern int setting_cmp ( struct setting *a, struct setting *b );
352
+extern int setting_cmp ( const struct setting *a, const struct setting *b );
343 353
 
344 354
 extern struct settings * find_child_settings ( struct settings *parent,
345 355
 					       const char *name );
@@ -351,61 +361,68 @@ extern struct setting * find_setting ( const char *name );
351 361
 extern int parse_setting_name ( char *name, get_child_settings_t get_child,
352 362
 				struct settings **settings,
353 363
 				struct setting *setting );
354
-extern int setting_name ( struct settings *settings, struct setting *setting,
364
+extern int setting_name ( struct settings *settings,
365
+			  const struct setting *setting,
355 366
 			  char *buf, size_t len );
356
-extern int setting_format ( struct setting_type *type, const void *raw,
367
+extern int setting_format ( const struct setting_type *type, const void *raw,
357 368
 			    size_t raw_len, char *buf, size_t len );
358
-extern int setting_parse ( struct setting_type *type, const char *value,
369
+extern int setting_parse ( const struct setting_type *type, const char *value,
359 370
 			   void *buf, size_t len );
360
-extern int setting_numerate ( struct setting_type *type, const void *raw,
371
+extern int setting_numerate ( const struct setting_type *type, const void *raw,
361 372
 			      size_t raw_len, unsigned long *value );
362
-extern int setting_denumerate ( struct setting_type *type, unsigned long value,
363
-				void *buf, size_t len );
364
-extern int fetchf_setting ( struct settings *settings, struct setting *setting,
373
+extern int setting_denumerate ( const struct setting_type *type,
374
+				unsigned long value, void *buf, size_t len );
375
+extern int fetchf_setting ( struct settings *settings,
376
+			    const struct setting *setting,
377
+			    struct settings **origin, struct setting *fetched,
365 378
 			    char *buf, size_t len );
366 379
 extern int fetchf_setting_copy ( struct settings *settings,
367
-				 struct setting *setting, char **value );
380
+				 const struct setting *setting,
381
+				 struct settings **origin,
382
+				 struct setting *fetched, char **value );
368 383
 extern int storef_setting ( struct settings *settings,
369
-			    struct setting *setting,
370
-			    const char *value );
371
-extern int fetchn_setting ( struct settings *settings, struct setting *setting,
384
+			    const struct setting *setting, const char *value );
385
+extern int fetchn_setting ( struct settings *settings,
386
+			    const struct setting *setting,
387
+			    struct settings **origin, struct setting *fetched,
372 388
 			    unsigned long *value );
373
-extern int storen_setting ( struct settings *settings, struct setting *setting,
389
+extern int storen_setting ( struct settings *settings,
390
+			    const struct setting *setting,
374 391
 			    unsigned long value );
375 392
 extern char * expand_settings ( const char *string );
376 393
 
377
-extern struct setting_type setting_type_string __setting_type;
378
-extern struct setting_type setting_type_uristring __setting_type;
379
-extern struct setting_type setting_type_ipv4 __setting_type;
380
-extern struct setting_type setting_type_ipv6 __setting_type;
381
-extern struct setting_type setting_type_int8 __setting_type;
382
-extern struct setting_type setting_type_int16 __setting_type;
383
-extern struct setting_type setting_type_int32 __setting_type;
384
-extern struct setting_type setting_type_uint8 __setting_type;
385
-extern struct setting_type setting_type_uint16 __setting_type;
386
-extern struct setting_type setting_type_uint32 __setting_type;
387
-extern struct setting_type setting_type_hex __setting_type;
388
-extern struct setting_type setting_type_hexhyp __setting_type;
389
-extern struct setting_type setting_type_hexraw __setting_type;
390
-extern struct setting_type setting_type_uuid __setting_type;
391
-extern struct setting_type setting_type_busdevfn __setting_type;
392
-
393
-extern struct setting ip_setting __setting ( SETTING_IPv4 );
394
-extern struct setting netmask_setting __setting ( SETTING_IPv4 );
395
-extern struct setting gateway_setting __setting ( SETTING_IPv4 );
396
-extern struct setting dns_setting __setting ( SETTING_IPv4_EXTRA );
397
-extern struct setting hostname_setting __setting ( SETTING_HOST );
398
-extern struct setting domain_setting __setting ( SETTING_IPv4_EXTRA );
399
-extern struct setting filename_setting __setting ( SETTING_BOOT );
400
-extern struct setting root_path_setting __setting ( SETTING_SANBOOT );
401
-extern struct setting username_setting __setting ( SETTING_AUTH );
402
-extern struct setting password_setting __setting ( SETTING_AUTH );
403
-extern struct setting priority_setting __setting ( SETTING_MISC );
404
-extern struct setting uuid_setting __setting ( SETTING_HOST );
405
-extern struct setting next_server_setting __setting ( SETTING_BOOT );
406
-extern struct setting mac_setting __setting ( SETTING_NETDEV );
407
-extern struct setting busid_setting __setting ( SETTING_NETDEV );
408
-extern struct setting user_class_setting __setting ( SETTING_HOST_EXTRA );
394
+extern const struct setting_type setting_type_string __setting_type;
395
+extern const struct setting_type setting_type_uristring __setting_type;
396
+extern const struct setting_type setting_type_ipv4 __setting_type;
397
+extern const struct setting_type setting_type_ipv6 __setting_type;
398
+extern const struct setting_type setting_type_int8 __setting_type;
399
+extern const struct setting_type setting_type_int16 __setting_type;
400
+extern const struct setting_type setting_type_int32 __setting_type;
401
+extern const struct setting_type setting_type_uint8 __setting_type;
402
+extern const struct setting_type setting_type_uint16 __setting_type;
403
+extern const struct setting_type setting_type_uint32 __setting_type;
404
+extern const struct setting_type setting_type_hex __setting_type;
405
+extern const struct setting_type setting_type_hexhyp __setting_type;
406
+extern const struct setting_type setting_type_hexraw __setting_type;
407
+extern const struct setting_type setting_type_uuid __setting_type;
408
+extern const struct setting_type setting_type_busdevfn __setting_type;
409
+
410
+extern const struct setting ip_setting __setting ( SETTING_IPv4 );
411
+extern const struct setting netmask_setting __setting ( SETTING_IPv4 );
412
+extern const struct setting gateway_setting __setting ( SETTING_IPv4 );
413
+extern const struct setting dns_setting __setting ( SETTING_IPv4_EXTRA );
414
+extern const struct setting hostname_setting __setting ( SETTING_HOST );
415
+extern const struct setting domain_setting __setting ( SETTING_IPv4_EXTRA );
416
+extern const struct setting filename_setting __setting ( SETTING_BOOT );
417
+extern const struct setting root_path_setting __setting ( SETTING_SANBOOT );
418
+extern const struct setting username_setting __setting ( SETTING_AUTH );
419
+extern const struct setting password_setting __setting ( SETTING_AUTH );
420
+extern const struct setting priority_setting __setting ( SETTING_MISC );
421
+extern const struct setting uuid_setting __setting ( SETTING_HOST );
422
+extern const struct setting next_server_setting __setting ( SETTING_BOOT );
423
+extern const struct setting mac_setting __setting ( SETTING_NETDEV );
424
+extern const struct setting busid_setting __setting ( SETTING_NETDEV );
425
+extern const struct setting user_class_setting __setting ( SETTING_HOST_EXTRA );
409 426
 
410 427
 /**
411 428
  * Initialise a settings block
@@ -418,7 +435,7 @@ extern struct setting user_class_setting __setting ( SETTING_HOST_EXTRA );
418 435
 static inline void settings_init ( struct settings *settings,
419 436
 				   struct settings_operations *op,
420 437
 				   struct refcnt *refcnt,
421
-				   struct settings_scope *default_scope ) {
438
+				   const struct settings_scope *default_scope ){
422 439
 	INIT_LIST_HEAD ( &settings->siblings );
423 440
 	INIT_LIST_HEAD ( &settings->children );
424 441
 	settings->op = op;
@@ -447,20 +464,21 @@ static inline void generic_settings_init ( struct generic_settings *generics,
447 464
  * @ret rc		Return status code
448 465
  */
449 466
 static inline int delete_setting ( struct settings *settings,
450
-				   struct setting *setting ) {
467
+				   const struct setting *setting ) {
451 468
 	return store_setting ( settings, setting, NULL, 0 );
452 469
 }
453 470
 
454 471
 /**
455
- * Check existence of setting
472
+ * Check existence of predefined setting
456 473
  *
457 474
  * @v settings		Settings block, or NULL to search all blocks
458 475
  * @v setting		Setting to fetch
459 476
  * @ret exists		Setting exists
460 477
  */
461 478
 static inline int setting_exists ( struct settings *settings,
462
-				   struct setting *setting ) {
463
-	return ( fetch_setting_len ( settings, setting ) >= 0 );
479
+				   const struct setting *setting ) {
480
+	return ( fetch_setting ( settings, setting, NULL, NULL,
481
+				 NULL, 0 ) >= 0 );
464 482
 }
465 483
 
466 484
 #endif /* _IPXE_SETTINGS_H */

+ 6
- 2
src/interface/efi/efi_snp_hii.c 查看文件

@@ -276,7 +276,9 @@ static int efi_snp_hii_fetch ( struct efi_snp_device *snpdev,
276 276
 			       const char *key, const char *value,
277 277
 			       wchar_t **results, int *have_setting ) {
278 278
 	struct settings *settings = efi_snp_hii_settings ( snpdev );
279
+	struct settings *origin;
279 280
 	struct setting *setting;
281
+	struct setting fetched;
280 282
 	int len;
281 283
 	char *buf;
282 284
 	char *encoded;
@@ -311,7 +313,8 @@ static int efi_snp_hii_fetch ( struct efi_snp_device *snpdev,
311 313
 	if ( setting_exists ( settings, setting ) ) {
312 314
 
313 315
 		/* Calculate formatted length */
314
-		len = fetchf_setting ( settings, setting, NULL, 0 );
316
+		len = fetchf_setting ( settings, setting, &origin, &fetched,
317
+				       NULL, 0 );
315 318
 		if ( len < 0 ) {
316 319
 			rc = len;
317 320
 			DBGC ( snpdev, "SNPDEV %p could not fetch %s: %s\n",
@@ -328,7 +331,8 @@ static int efi_snp_hii_fetch ( struct efi_snp_device *snpdev,
328 331
 		encoded = ( buf + len + 1 /* NUL */ );
329 332
 
330 333
 		/* Format value */
331
-		fetchf_setting ( settings, setting, buf, ( len + 1 /* NUL */ ));
334
+		fetchf_setting ( origin, &fetched, NULL, NULL, buf,
335
+				 ( len + 1 /* NUL */ ) );
332 336
 		for ( i = 0 ; i < len ; i++ ) {
333 337
 			sprintf ( ( encoded + ( 4 * i ) ), "%04x",
334 338
 				  *( ( uint8_t * ) buf + i ) );

+ 4
- 4
src/interface/smbios/smbios_settings.c 查看文件

@@ -28,7 +28,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
28 28
 #include <ipxe/smbios.h>
29 29
 
30 30
 /** SMBIOS settings scope */
31
-static struct settings_scope smbios_settings_scope;
31
+static const struct settings_scope smbios_settings_scope;
32 32
 
33 33
 /**
34 34
  * Construct SMBIOS raw-data tag
@@ -63,7 +63,7 @@ static struct settings_scope smbios_settings_scope;
63 63
  * @ret applies		Setting applies within this settings block
64 64
  */
65 65
 static int smbios_applies ( struct settings *settings __unused,
66
-			    struct setting *setting ) {
66
+			    const struct setting *setting ) {
67 67
 
68 68
 	return ( setting->scope == &smbios_settings_scope );
69 69
 }
@@ -188,7 +188,7 @@ struct init_fn smbios_init_fn __init_fn ( INIT_NORMAL ) = {
188 188
 };
189 189
 
190 190
 /** UUID setting obtained via SMBIOS */
191
-struct setting uuid_setting __setting ( SETTING_HOST ) = {
191
+const struct setting uuid_setting __setting ( SETTING_HOST ) = {
192 192
 	.name = "uuid",
193 193
 	.description = "UUID",
194 194
 	.tag = SMBIOS_RAW_TAG ( SMBIOS_TYPE_SYSTEM_INFORMATION,
@@ -198,7 +198,7 @@ struct setting uuid_setting __setting ( SETTING_HOST ) = {
198 198
 };
199 199
 
200 200
 /** Other SMBIOS predefined settings */
201
-struct setting smbios_predefined_settings[] __setting ( SETTING_HOST_EXTRA ) = {
201
+const struct setting smbios_predefined_settings[] __setting ( SETTING_HOST_EXTRA ) = {
202 202
 	{
203 203
 		.name = "manufacturer",
204 204
 		.description = "Manufacturer",

+ 3
- 3
src/net/80211/net80211.c 查看文件

@@ -204,7 +204,7 @@ struct settings_applicator net80211_applicator __settings_applicator = {
204 204
  * If this is blank, we scan for all networks and use the one with the
205 205
  * greatest signal strength.
206 206
  */
207
-struct setting net80211_ssid_setting __setting ( SETTING_NETDEV_EXTRA ) = {
207
+const struct setting net80211_ssid_setting __setting ( SETTING_NETDEV_EXTRA ) = {
208 208
 	.name = "ssid",
209 209
 	.description = "Wireless SSID",
210 210
 	.type = &setting_type_string,
@@ -216,7 +216,7 @@ struct setting net80211_ssid_setting __setting ( SETTING_NETDEV_EXTRA ) = {
216 216
  * active scan (send probe packets). If this setting is nonzero, an
217 217
  * active scan on the 2.4GHz band will be used to associate.
218 218
  */
219
-struct setting net80211_active_setting __setting ( SETTING_NETDEV_EXTRA ) = {
219
+const struct setting net80211_active_setting __setting ( SETTING_NETDEV_EXTRA ) = {
220 220
 	.name = "active-scan",
221 221
 	.description = "Actively scan for wireless networks",
222 222
 	.type = &setting_type_int8,
@@ -228,7 +228,7 @@ struct setting net80211_active_setting __setting ( SETTING_NETDEV_EXTRA ) = {
228 228
  * normal iPXE method for entering hex settings; an ASCII string of
229 229
  * hex characters will not behave as expected.
230 230
  */
231
-struct setting net80211_key_setting __setting ( SETTING_NETDEV_EXTRA ) = {
231
+const struct setting net80211_key_setting __setting ( SETTING_NETDEV_EXTRA ) = {
232 232
 	.name = "key",
233 233
 	.description = "Wireless encryption key",
234 234
 	.type = &setting_type_string,

+ 4
- 4
src/net/80211/wep.c 查看文件

@@ -236,8 +236,8 @@ static int trivial_init ( struct net80211_device *dev )
236 236
 	     dev->associating->crypto == NET80211_CRYPT_NONE )
237 237
 		return 0;	/* no crypto? OK. */
238 238
 
239
-	len = fetch_setting ( netdev_settings ( dev->netdev ),
240
-			      &net80211_key_setting, key, WEP_MAX_KEY );
239
+	len = fetch_raw_setting ( netdev_settings ( dev->netdev ),
240
+				  &net80211_key_setting, key, WEP_MAX_KEY );
241 241
 
242 242
 	if ( len <= 0 ) {
243 243
 		DBGC ( dev, "802.11 %p cannot do WEP without a key\n", dev );
@@ -278,8 +278,8 @@ static int trivial_change_key ( struct net80211_device *dev )
278 278
 	if ( ! dev->crypto || ( dev->crypto->init != wep_init ) )
279 279
 		change ^= 1;
280 280
 
281
-	len = fetch_setting ( netdev_settings ( dev->netdev ),
282
-			      &net80211_key_setting, key, WEP_MAX_KEY );
281
+	len = fetch_raw_setting ( netdev_settings ( dev->netdev ),
282
+				  &net80211_key_setting, key, WEP_MAX_KEY );
283 283
 	if ( len <= 0 )
284 284
 		change ^= 1;
285 285
 

+ 2
- 2
src/net/dhcppkt.c 查看文件

@@ -226,7 +226,7 @@ int dhcppkt_fetch ( struct dhcp_packet *dhcppkt, unsigned int tag,
226 226
  * @ret applies		Setting applies within this settings block
227 227
  */
228 228
 static int dhcppkt_settings_applies ( struct settings *settings,
229
-				      struct setting *setting ) {
229
+				      const struct setting *setting ) {
230 230
 	struct dhcp_packet *dhcppkt =
231 231
 		container_of ( settings, struct dhcp_packet, settings );
232 232
 
@@ -244,7 +244,7 @@ static int dhcppkt_settings_applies ( struct settings *settings,
244 244
  * @ret rc		Return status code
245 245
  */
246 246
 static int dhcppkt_settings_store ( struct settings *settings,
247
-				    struct setting *setting,
247
+				    const struct setting *setting,
248 248
 				    const void *data, size_t len ) {
249 249
 	struct dhcp_packet *dhcppkt =
250 250
 		container_of ( settings, struct dhcp_packet, settings );

+ 6
- 12
src/net/fakedhcp.c 查看文件

@@ -49,8 +49,8 @@ static int copy_encap_settings ( struct dhcp_packet *dest,
49 49
 	struct setting setting = { .name = "" };
50 50
 	unsigned int subtag;
51 51
 	unsigned int tag;
52
+	void *data;
52 53
 	int len;
53
-	int check_len;
54 54
 	int rc;
55 55
 
56 56
 	for ( subtag = DHCP_MIN_OPTION; subtag <= DHCP_MAX_OPTION; subtag++ ) {
@@ -66,17 +66,11 @@ static int copy_encap_settings ( struct dhcp_packet *dest,
66 66
 		default:
67 67
 			/* Copy setting, if present */
68 68
 			setting.tag = tag;
69
-			len = fetch_setting_len ( source, &setting );
70
-			if ( len < 0 )
71
-				break;
72
-			{
73
-				char buf[len];
74
-
75
-				check_len = fetch_setting ( source, &setting,
76
-							    buf, sizeof (buf));
77
-				assert ( check_len == len );
78
-				if ( ( rc = dhcppkt_store ( dest, tag, buf,
79
-							    sizeof(buf) )) !=0)
69
+			len = fetch_raw_setting_copy ( source, &setting, &data);
70
+			if ( len >= 0 ) {
71
+				rc = dhcppkt_store ( dest, tag, data, len );
72
+				free ( data );
73
+				if ( rc != 0 )
80 74
 					return rc;
81 75
 			}
82 76
 			break;

+ 3
- 3
src/net/ipv4.c 查看文件

@@ -591,7 +591,7 @@ struct sockaddr_converter ipv4_sockaddr_converter __sockaddr_converter = {
591 591
  */
592 592
 
593 593
 /** IPv4 address setting */
594
-struct setting ip_setting __setting ( SETTING_IPv4 ) = {
594
+const struct setting ip_setting __setting ( SETTING_IPv4 ) = {
595 595
 	.name = "ip",
596 596
 	.description = "IP address",
597 597
 	.tag = DHCP_EB_YIADDR,
@@ -599,7 +599,7 @@ struct setting ip_setting __setting ( SETTING_IPv4 ) = {
599 599
 };
600 600
 
601 601
 /** IPv4 subnet mask setting */
602
-struct setting netmask_setting __setting ( SETTING_IPv4 ) = {
602
+const struct setting netmask_setting __setting ( SETTING_IPv4 ) = {
603 603
 	.name = "netmask",
604 604
 	.description = "Subnet mask",
605 605
 	.tag = DHCP_SUBNET_MASK,
@@ -607,7 +607,7 @@ struct setting netmask_setting __setting ( SETTING_IPv4 ) = {
607 607
 };
608 608
 
609 609
 /** Default gateway setting */
610
-struct setting gateway_setting __setting ( SETTING_IPv4 ) = {
610
+const struct setting gateway_setting __setting ( SETTING_IPv4 ) = {
611 611
 	.name = "gateway",
612 612
 	.description = "Default gateway",
613 613
 	.tag = DHCP_ROUTERS,

+ 3
- 3
src/net/ipv6.c 查看文件

@@ -954,7 +954,7 @@ struct sockaddr_converter ipv6_sockaddr_converter __sockaddr_converter = {
954 954
  * @v len		Length of buffer
955 955
  * @ret len		Length of raw value, or negative error
956 956
  */
957
-static int parse_ipv6_setting ( struct setting_type *type __unused,
957
+static int parse_ipv6_setting ( const struct setting_type *type __unused,
958 958
 				const char *value, void *buf, size_t len ) {
959 959
 	struct in6_addr ipv6;
960 960
 	int rc;
@@ -981,7 +981,7 @@ static int parse_ipv6_setting ( struct setting_type *type __unused,
981 981
  * @v len		Length of buffer
982 982
  * @ret len		Length of formatted value, or negative error
983 983
  */
984
-static int format_ipv6_setting ( struct setting_type *type __unused,
984
+static int format_ipv6_setting ( const struct setting_type *type __unused,
985 985
 				 const void *raw, size_t raw_len, char *buf,
986 986
 				 size_t len ) {
987 987
 	const struct in6_addr *ipv6 = raw;
@@ -992,7 +992,7 @@ static int format_ipv6_setting ( struct setting_type *type __unused,
992 992
 }
993 993
 
994 994
 /** An IPv6 address setting type */
995
-struct setting_type setting_type_ipv6 __setting_type = {
995
+const struct setting_type setting_type_ipv6 __setting_type = {
996 996
 	.name = "ipv6",
997 997
 	.parse = parse_ipv6_setting,
998 998
 	.format = format_ipv6_setting,

+ 8
- 7
src/net/netdev_settings.c 查看文件

@@ -36,27 +36,27 @@ FILE_LICENCE ( GPL2_OR_LATER );
36 36
  */
37 37
 
38 38
 /** Network device predefined settings */
39
-struct setting mac_setting __setting ( SETTING_NETDEV ) = {
39
+const struct setting mac_setting __setting ( SETTING_NETDEV ) = {
40 40
 	.name = "mac",
41 41
 	.description = "MAC address",
42 42
 	.type = &setting_type_hex,
43 43
 };
44
-struct setting bustype_setting __setting ( SETTING_NETDEV ) = {
44
+const struct setting bustype_setting __setting ( SETTING_NETDEV ) = {
45 45
 	.name = "bustype",
46 46
 	.description = "Bus type",
47 47
 	.type = &setting_type_string,
48 48
 };
49
-struct setting busloc_setting __setting ( SETTING_NETDEV ) = {
49
+const struct setting busloc_setting __setting ( SETTING_NETDEV ) = {
50 50
 	.name = "busloc",
51 51
 	.description = "Bus location",
52 52
 	.type = &setting_type_uint32,
53 53
 };
54
-struct setting busid_setting __setting ( SETTING_NETDEV ) = {
54
+const struct setting busid_setting __setting ( SETTING_NETDEV ) = {
55 55
 	.name = "busid",
56 56
 	.description = "Bus ID",
57 57
 	.type = &setting_type_hex,
58 58
 };
59
-struct setting chip_setting __setting ( SETTING_NETDEV ) = {
59
+const struct setting chip_setting __setting ( SETTING_NETDEV ) = {
60 60
 	.name = "chip",
61 61
 	.description = "Chip",
62 62
 	.type = &setting_type_string,
@@ -194,7 +194,7 @@ static int netdev_fetch_chip ( struct net_device *netdev, void *data,
194 194
 /** A network device setting operation */
195 195
 struct netdev_setting_operation {
196 196
 	/** Setting */
197
-	struct setting *setting;
197
+	const struct setting *setting;
198 198
 	/** Store setting (or NULL if not supported)
199 199
 	 *
200 200
 	 * @v netdev		Network device
@@ -232,7 +232,8 @@ static struct netdev_setting_operation netdev_setting_operations[] = {
232 232
  * @v len		Length of setting data
233 233
  * @ret rc		Return status code
234 234
  */
235
-static int netdev_store ( struct settings *settings, struct setting *setting,
235
+static int netdev_store ( struct settings *settings,
236
+			  const struct setting *setting,
236 237
 			  const void *data, size_t len ) {
237 238
 	struct net_device *netdev = container_of ( settings, struct net_device,
238 239
 						   settings.settings );

+ 20
- 41
src/net/tcp/iscsi.c 查看文件

@@ -1860,7 +1860,7 @@ enum iscsi_root_path_component {
1860 1860
 };
1861 1861
 
1862 1862
 /** iSCSI initiator IQN setting */
1863
-struct setting initiator_iqn_setting __setting ( SETTING_SANBOOT_EXTRA ) = {
1863
+const struct setting initiator_iqn_setting __setting ( SETTING_SANBOOT_EXTRA ) = {
1864 1864
 	.name = "initiator-iqn",
1865 1865
 	.description = "iSCSI initiator name",
1866 1866
 	.tag = DHCP_ISCSI_INITIATOR_IQN,
@@ -1868,7 +1868,7 @@ struct setting initiator_iqn_setting __setting ( SETTING_SANBOOT_EXTRA ) = {
1868 1868
 };
1869 1869
 
1870 1870
 /** iSCSI reverse username setting */
1871
-struct setting reverse_username_setting __setting ( SETTING_AUTH_EXTRA ) = {
1871
+const struct setting reverse_username_setting __setting ( SETTING_AUTH_EXTRA ) = {
1872 1872
 	.name = "reverse-username",
1873 1873
 	.description = "Reverse user name",
1874 1874
 	.tag = DHCP_EB_REVERSE_USERNAME,
@@ -1876,7 +1876,7 @@ struct setting reverse_username_setting __setting ( SETTING_AUTH_EXTRA ) = {
1876 1876
 };
1877 1877
 
1878 1878
 /** iSCSI reverse password setting */
1879
-struct setting reverse_password_setting __setting ( SETTING_AUTH_EXTRA ) = {
1879
+const struct setting reverse_password_setting __setting ( SETTING_AUTH_EXTRA ) = {
1880 1880
 	.name = "reverse-password",
1881 1881
 	.description = "Reverse password",
1882 1882
 	.tag = DHCP_EB_REVERSE_PASSWORD,
@@ -1947,46 +1947,23 @@ static int iscsi_fetch_settings ( struct iscsi_session *iscsi ) {
1947 1947
 	/* Fetch relevant settings.  Don't worry about freeing on
1948 1948
 	 * error, since iscsi_free() will take care of that anyway.
1949 1949
 	 */
1950
-	if ( ( len = fetch_string_setting_copy ( NULL, &username_setting,
1951
-					  &iscsi->initiator_username ) ) < 0 ) {
1952
-		DBGC ( iscsi, "iSCSI %p could not fetch username: %s\n",
1953
-		       iscsi, strerror ( len ) );
1954
-		return len;
1955
-	}
1956
-	if ( ( len = fetch_string_setting_copy ( NULL, &password_setting,
1957
-					  &iscsi->initiator_password ) ) < 0 ) {
1958
-		DBGC ( iscsi, "iSCSI %p could not fetch password: %s\n",
1959
-		       iscsi, strerror ( len ) );
1960
-		return len;
1961
-	}
1962
-	if ( ( len = fetch_string_setting_copy( NULL, &reverse_username_setting,
1963
-					     &iscsi->target_username ) ) < 0 ) {
1964
-		DBGC ( iscsi, "iSCSI %p could not fetch reverse username: %s\n",
1965
-		       iscsi, strerror ( len ) );
1966
-		return len;
1967
-	}
1968
-	if ( ( len = fetch_string_setting_copy( NULL, &reverse_password_setting,
1969
-					     &iscsi->target_password ) ) < 0 ) {
1970
-		DBGC ( iscsi, "iSCSI %p could not fetch reverse password: %s\n",
1971
-		       iscsi, strerror ( len ) );
1972
-		return len;
1973
-	}
1974
-
1975
-	/* Find a suitable initiator name */
1976
-	if ( ( len = fetch_string_setting_copy ( NULL, &initiator_iqn_setting,
1977
-					       &iscsi->initiator_iqn ) ) < 0 ) {
1978
-		DBGC ( iscsi, "iSCSI %p could not fetch initiator IQN: %s\n",
1979
-		       iscsi, strerror ( len ) );
1980
-		return len;
1981
-	}
1950
+	fetch_string_setting_copy ( NULL, &username_setting,
1951
+				    &iscsi->initiator_username );
1952
+	fetch_string_setting_copy ( NULL, &password_setting,
1953
+				    &iscsi->initiator_password );
1954
+	fetch_string_setting_copy ( NULL, &reverse_username_setting,
1955
+				    &iscsi->target_username );
1956
+	fetch_string_setting_copy ( NULL, &reverse_password_setting,
1957
+				    &iscsi->target_password );
1958
+
1959
+	/* Use explicit initiator IQN if provided */
1960
+	fetch_string_setting_copy ( NULL, &initiator_iqn_setting,
1961
+				    &iscsi->initiator_iqn );
1982 1962
 	if ( iscsi->initiator_iqn )
1983 1963
 		return 0;
1984
-	if ( ( len = fetch_string_setting_copy ( NULL, &hostname_setting,
1985
-						&hostname ) ) < 0 ) {
1986
-		DBGC ( iscsi, "iSCSI %p could not fetch hostname: %s\n",
1987
-		       iscsi, strerror ( len ) );
1988
-		return len;
1989
-	}
1964
+
1965
+	/* Otherwise, try to construct an initiator IQN from the hostname */
1966
+	fetch_string_setting_copy ( NULL, &hostname_setting, &hostname );
1990 1967
 	if ( hostname ) {
1991 1968
 		len = asprintf ( &iscsi->initiator_iqn,
1992 1969
 				 ISCSI_DEFAULT_IQN_PREFIX ":%s", hostname );
@@ -1999,6 +1976,8 @@ static int iscsi_fetch_settings ( struct iscsi_session *iscsi ) {
1999 1976
 		assert ( iscsi->initiator_iqn );
2000 1977
 		return 0;
2001 1978
 	}
1979
+
1980
+	/* Otherwise, try to construct an initiator IQN from the UUID */
2002 1981
 	if ( ( len = fetch_uuid_setting ( NULL, &uuid_setting, &uuid ) ) < 0 ) {
2003 1982
 		DBGC ( iscsi, "iSCSI %p has no suitable initiator IQN\n",
2004 1983
 		       iscsi );

+ 2
- 2
src/net/tcp/oncrpc.c 查看文件

@@ -58,14 +58,14 @@ struct oncrpc_cred oncrpc_auth_none = {
58 58
 	.length = 0
59 59
 };
60 60
 
61
-struct setting uid_setting __setting ( SETTING_AUTH ) = {
61
+const struct setting uid_setting __setting ( SETTING_AUTH ) = {
62 62
 	.name        = "uid",
63 63
 	.description = "User ID",
64 64
 	.tag         = DHCP_EB_UID,
65 65
 	.type        = &setting_type_uint32
66 66
 };
67 67
 
68
-struct setting gid_setting __setting ( SETTING_AUTH ) = {
68
+const struct setting gid_setting __setting ( SETTING_AUTH ) = {
69 69
 	.name        = "gid",
70 70
 	.description = "Group ID",
71 71
 	.tag         = DHCP_EB_GID,

+ 2
- 8
src/net/tcp/syslogs.c 查看文件

@@ -190,7 +190,7 @@ struct console_driver syslogs_console __console_driver = {
190 190
  */
191 191
 
192 192
 /** Encrypted syslog server setting */
193
-struct setting syslogs_setting __setting ( SETTING_MISC ) = {
193
+const struct setting syslogs_setting __setting ( SETTING_MISC ) = {
194 194
 	.name = "syslogs",
195 195
 	.description = "Encrypted syslog server",
196 196
 	.tag = DHCP_EB_SYSLOGS_SERVER,
@@ -206,15 +206,10 @@ static int apply_syslogs_settings ( void ) {
206 206
 	static char *old_server;
207 207
 	char *server;
208 208
 	struct interface *socket;
209
-	int len;
210 209
 	int rc;
211 210
 
212 211
 	/* Fetch log server */
213
-	len = fetch_string_setting_copy ( NULL, &syslogs_setting, &server );
214
-	if ( len < 0 ) {
215
-		rc = len;
216
-		goto err_fetch_server;
217
-	}
212
+	fetch_string_setting_copy ( NULL, &syslogs_setting, &server );
218 213
 
219 214
 	/* Do nothing unless log server has changed */
220 215
 	if ( ( ( server == NULL ) && ( old_server == NULL ) ) ||
@@ -266,7 +261,6 @@ static int apply_syslogs_settings ( void ) {
266 261
  out_no_server:
267 262
  out_no_change:
268 263
 	free ( server );
269
- err_fetch_server:
270 264
 	return rc;
271 265
 }
272 266
 

+ 25
- 19
src/net/udp/dhcp.c 查看文件

@@ -92,7 +92,7 @@ static uint8_t dhcp_request_options_data[] = {
92 92
 };
93 93
 
94 94
 /** DHCP server address setting */
95
-struct setting dhcp_server_setting __setting ( SETTING_MISC ) = {
95
+const struct setting dhcp_server_setting __setting ( SETTING_MISC ) = {
96 96
 	.name = "dhcp-server",
97 97
 	.description = "DHCP server",
98 98
 	.tag = DHCP_SERVER_IDENTIFIER,
@@ -975,6 +975,7 @@ int dhcp_create_request ( struct dhcp_packet *dhcppkt,
975 975
 	uint8_t *dhcp_features;
976 976
 	size_t dhcp_features_len;
977 977
 	size_t ll_addr_len;
978
+	void *user_class;
978 979
 	ssize_t len;
979 980
 	int rc;
980 981
 
@@ -985,7 +986,7 @@ int dhcp_create_request ( struct dhcp_packet *dhcppkt,
985 986
 					 data, max_len ) ) != 0 ) {
986 987
 		DBG ( "DHCP could not create DHCP packet: %s\n",
987 988
 		      strerror ( rc ) );
988
-		return rc;
989
+		goto err_create_packet;
989 990
 	}
990 991
 
991 992
 	/* Set client IP address */
@@ -998,17 +999,17 @@ int dhcp_create_request ( struct dhcp_packet *dhcppkt,
998 999
 				    dhcp_features_len ) ) != 0 ) {
999 1000
 		DBG ( "DHCP could not set features list option: %s\n",
1000 1001
 		      strerror ( rc ) );
1001
-		return rc;
1002
+		goto err_store_features;
1002 1003
 	}
1003 1004
 
1004 1005
 	/* Add options to identify the network device */
1005
-	fetch_setting ( &netdev->settings.settings, &busid_setting, &dhcp_desc,
1006
-		sizeof ( dhcp_desc ) );
1006
+	fetch_raw_setting ( netdev_settings ( netdev ), &busid_setting,
1007
+			    &dhcp_desc, sizeof ( dhcp_desc ) );
1007 1008
 	if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_EB_BUS_ID, &dhcp_desc,
1008 1009
 				    sizeof ( dhcp_desc ) ) ) != 0 ) {
1009 1010
 		DBG ( "DHCP could not set bus ID option: %s\n",
1010 1011
 		      strerror ( rc ) );
1011
-		return rc;
1012
+		goto err_store_busid;
1012 1013
 	}
1013 1014
 
1014 1015
 	/* Add DHCP client identifier.  Required for Infiniband, and
@@ -1022,7 +1023,7 @@ int dhcp_create_request ( struct dhcp_packet *dhcppkt,
1022 1023
 				    ( ll_addr_len + 1 ) ) ) != 0 ) {
1023 1024
 		DBG ( "DHCP could not set client ID: %s\n",
1024 1025
 		      strerror ( rc ) );
1025
-		return rc;
1026
+		goto err_store_client_id;
1026 1027
 	}
1027 1028
 
1028 1029
 	/* Add client UUID, if we have one.  Required for PXE.  The
@@ -1039,25 +1040,29 @@ int dhcp_create_request ( struct dhcp_packet *dhcppkt,
1039 1040
 					    sizeof ( client_uuid ) ) ) != 0 ) {
1040 1041
 			DBG ( "DHCP could not set client UUID: %s\n",
1041 1042
 			      strerror ( rc ) );
1042
-			return rc;
1043
+			goto err_store_client_uuid;
1043 1044
 		}
1044 1045
 	}
1045 1046
 
1046 1047
 	/* Add user class, if we have one. */
1047
-	if ( ( len = fetch_setting_len ( NULL, &user_class_setting ) ) >= 0 ) {
1048
-		char user_class[len];
1049
-		fetch_setting ( NULL, &user_class_setting, user_class,
1050
-				sizeof ( user_class ) );
1048
+	if ( ( len = fetch_raw_setting_copy ( NULL, &user_class_setting,
1049
+					      &user_class ) ) >= 0 ) {
1051 1050
 		if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_USER_CLASS_ID,
1052
-					    &user_class,
1053
-					    sizeof ( user_class ) ) ) != 0 ) {
1051
+					    user_class, len ) ) != 0 ) {
1054 1052
 			DBG ( "DHCP could not set user class: %s\n",
1055 1053
 			      strerror ( rc ) );
1056
-			return rc;
1054
+			goto err_store_user_class;
1057 1055
 		}
1058 1056
 	}
1059 1057
 
1060
-	return 0;
1058
+ err_store_user_class:
1059
+	free ( user_class );
1060
+ err_store_client_uuid:
1061
+ err_store_client_id:
1062
+ err_store_busid:
1063
+ err_store_features:
1064
+ err_create_packet:
1065
+	return rc;
1061 1066
 }
1062 1067
 
1063 1068
 /****************************************************************************
@@ -1384,7 +1389,8 @@ int start_pxebs ( struct interface *job, struct net_device *netdev,
1384 1389
 	int rc;
1385 1390
 
1386 1391
 	/* Get upper bound for PXE boot server IP address list */
1387
-	pxebs_list_len = fetch_setting_len ( NULL, &pxe_boot_servers_setting );
1392
+	pxebs_list_len = fetch_raw_setting ( NULL, &pxe_boot_servers_setting,
1393
+					     NULL, 0 );
1388 1394
 	if ( pxebs_list_len < 0 )
1389 1395
 		pxebs_list_len = 0;
1390 1396
 
@@ -1422,8 +1428,8 @@ int start_pxebs ( struct interface *job, struct net_device *netdev,
1422 1428
 	if ( pxebs_list_len ) {
1423 1429
 		uint8_t buf[pxebs_list_len];
1424 1430
 
1425
-		fetch_setting ( NULL, &pxe_boot_servers_setting,
1426
-				buf, sizeof ( buf ) );
1431
+		fetch_raw_setting ( NULL, &pxe_boot_servers_setting,
1432
+				    buf, sizeof ( buf ) );
1427 1433
 		pxebs_list ( dhcp, buf, sizeof ( buf ), ip );
1428 1434
 	}
1429 1435
 	if ( ! dhcp->pxe_attempt->s_addr ) {

+ 3
- 3
src/net/udp/dhcpv6.c 查看文件

@@ -256,7 +256,7 @@ static int dhcpv6_iaaddr ( struct dhcpv6_option_list *options, uint32_t iaid,
256 256
  */
257 257
 
258 258
 /** DHCPv6 settings scope */
259
-static struct settings_scope dhcpv6_settings_scope;
259
+static const struct settings_scope dhcpv6_settings_scope;
260 260
 
261 261
 /** A DHCPv6 settings block */
262 262
 struct dhcpv6_settings {
@@ -276,7 +276,7 @@ struct dhcpv6_settings {
276 276
  * @ret applies		Setting applies within this settings block
277 277
  */
278 278
 static int dhcpv6_applies ( struct settings *settings __unused,
279
-			    struct setting *setting ) {
279
+			    const struct setting *setting ) {
280 280
 
281 281
 	return ( setting->scope == &dhcpv6_settings_scope );
282 282
 }
@@ -543,7 +543,7 @@ static size_t dhcpv6_user_class ( void *data, size_t len ) {
543 543
 	int actual_len;
544 544
 
545 545
 	/* Fetch user-class setting, if defined */
546
-	actual_len = fetch_setting ( NULL, &user_class_setting, data, len );
546
+	actual_len = fetch_raw_setting ( NULL, &user_class_setting, data, len );
547 547
 	if ( actual_len >= 0 )
548 548
 		return actual_len;
549 549
 

+ 2
- 6
src/net/udp/dns.c 查看文件

@@ -594,7 +594,7 @@ struct resolver dns_resolver __resolver ( RESOLV_NORMAL ) = {
594 594
  */
595 595
 
596 596
 /** DNS server setting */
597
-struct setting dns_setting __setting ( SETTING_IPv4_EXTRA ) = {
597
+const struct setting dns_setting __setting ( SETTING_IPv4_EXTRA ) = {
598 598
 	.name = "dns",
599 599
 	.description = "DNS server",
600 600
 	.tag = DHCP_DNS_SERVERS,
@@ -622,11 +622,7 @@ static int apply_dns_settings ( void ) {
622 622
 
623 623
 	/* Get local domain DHCP option */
624 624
 	free ( localdomain );
625
-	if ( ( len = fetch_string_setting_copy ( NULL, &domain_setting,
626
-						 &localdomain ) ) < 0 ) {
627
-		DBG ( "DNS could not fetch local domain: %s\n",
628
-		      strerror ( len ) );
629
-	}
625
+	fetch_string_setting_copy ( NULL, &domain_setting, &localdomain );
630 626
 	if ( localdomain )
631 627
 		DBG ( "DNS local domain %s\n", localdomain );
632 628
 

+ 3
- 11
src/net/udp/syslog.c 查看文件

@@ -188,7 +188,7 @@ struct console_driver syslog_console __console_driver = {
188 188
  */
189 189
 
190 190
 /** Syslog server setting */
191
-struct setting syslog_setting __setting ( SETTING_MISC ) = {
191
+const struct setting syslog_setting __setting ( SETTING_MISC ) = {
192 192
 	.name = "syslog",
193 193
 	.description = "Syslog server",
194 194
 	.tag = DHCP_LOG_SERVERS,
@@ -209,17 +209,9 @@ static int apply_syslog_settings ( void ) {
209 209
 
210 210
 	/* Fetch hostname and domain name */
211 211
 	free ( syslog_hostname );
212
-	if ( ( len = fetch_string_setting_copy ( NULL, &hostname_setting,
213
-						 &syslog_hostname ) ) < 0 ) {
214
-		rc = len;
215
-		DBG ( "SYSLOG could not fetch hostname: %s\n", strerror ( rc ));
216
-	}
212
+	fetch_string_setting_copy ( NULL, &hostname_setting, &syslog_hostname );
217 213
 	free ( syslog_domain );
218
-	if ( ( len = fetch_string_setting_copy ( NULL, &domain_setting,
219
-						 &syslog_domain ) ) < 0 ) {
220
-		rc = len;
221
-		DBG ( "SYSLOG could not fetch domain: %s\n", strerror ( rc ) );
222
-	}
214
+	fetch_string_setting_copy ( NULL, &domain_setting, &syslog_domain );
223 215
 
224 216
 	/* Fetch log server */
225 217
 	syslog_console.disabled = CONSOLE_DISABLED;

+ 2
- 10
src/net/validator.c 查看文件

@@ -121,7 +121,7 @@ static struct interface_descriptor validator_job_desc =
121 121
  */
122 122
 
123 123
 /** Cross-signed certificate source setting */
124
-struct setting crosscert_setting __setting ( SETTING_CRYPTO ) = {
124
+const struct setting crosscert_setting __setting ( SETTING_CRYPTO ) = {
125 125
 	.name = "crosscert",
126 126
 	.description = "Cross-signed certificate source",
127 127
 	.tag = DHCP_EB_CROSS_CERT,
@@ -232,14 +232,7 @@ static int validator_start_download ( struct validator *validator,
232 232
 	int rc;
233 233
 
234 234
 	/* Determine cross-signed certificate source */
235
-	len = fetch_string_setting_copy ( NULL, &crosscert_setting,
236
-					  &crosscert_copy );
237
-	if ( len < 0 ) {
238
-		rc = len;
239
-		DBGC ( validator, "VALIDATOR %p could not fetch crosscert "
240
-		       "setting: %s\n", validator, strerror ( rc ) );
241
-		goto err_fetch_crosscert;
242
-	}
235
+	fetch_string_setting_copy ( NULL, &crosscert_setting, &crosscert_copy );
243 236
 	crosscert = ( crosscert_copy ? crosscert_copy : crosscert_default );
244 237
 
245 238
 	/* Allocate URI string */
@@ -279,7 +272,6 @@ static int validator_start_download ( struct validator *validator,
279 272
 	free ( uri_string );
280 273
  err_alloc_uri_string:
281 274
 	free ( crosscert_copy );
282
- err_fetch_crosscert:
283 275
 	return rc;
284 276
 }
285 277
 

+ 54
- 53
src/tests/settings_test.c 查看文件

@@ -38,26 +38,26 @@ FILE_LICENCE ( GPL2_OR_LATER );
38 38
 /**
39 39
  * Report a formatted-store test result
40 40
  *
41
- * @v settings		Settings block
42
- * @v setting		Setting
43
- * @v formatted		Formatted value
44
- * @v raw_array		Expected raw value
41
+ * @v _settings		Settings block
42
+ * @v _setting		Setting
43
+ * @v _formatted	Formatted value
44
+ * @v _raw_array	Expected raw value
45 45
  */
46
-#define storef_ok( settings, setting, formatted, raw_array ) do {	\
47
-	const uint8_t expected[] = raw_array;				\
46
+#define storef_ok( _settings, _setting, _formatted, _raw_array ) do {	\
47
+	const uint8_t expected[] = _raw_array;				\
48 48
 	uint8_t actual[ sizeof ( expected ) ];				\
49 49
 	int len;							\
50 50
 									\
51
-	ok ( storef_setting ( settings, setting, formatted ) == 0 );	\
52
-	len = fetch_setting ( settings, setting, actual,		\
51
+	ok ( storef_setting ( _settings, _setting, _formatted ) == 0 );	\
52
+	len = fetch_setting ( _settings, _setting, NULL, NULL, actual,	\
53 53
 			      sizeof ( actual ) );			\
54 54
 	if ( len >= 0 ) {						\
55
-		DBGC ( settings, "Stored %s \"%s\", got:\n",		\
56
-		       (setting)->type->name, formatted );		\
57
-		DBGC_HDA ( settings, 0, actual, len );			\
55
+		DBGC ( _settings, "Stored %s \"%s\", got:\n",		\
56
+		       (_setting)->type->name, _formatted );		\
57
+		DBGC_HDA ( _settings, 0, actual, len );			\
58 58
 	} else {							\
59
-		DBGC ( settings, "Stored %s \"%s\", got error %s\n",	\
60
-		       (setting)->type->name, formatted,		\
59
+		DBGC ( _settings, "Stored %s \"%s\", got error %s\n",	\
60
+		       (_setting)->type->name, _formatted,		\
61 61
 		       strerror ( len ) );				\
62 62
 	}								\
63 63
 	ok ( len == ( int ) sizeof ( actual ) );			\
@@ -67,52 +67,52 @@ FILE_LICENCE ( GPL2_OR_LATER );
67 67
 /**
68 68
  * Report a formatted-fetch test result
69 69
  *
70
- * @v settings		Settings block
71
- * @v setting		Setting
72
- * @v raw_array		Raw value
73
- * @v formatted		Expected formatted value
70
+ * @v _settings		Settings block
71
+ * @v _setting		Setting
72
+ * @v _raw_array	Raw value
73
+ * @v _formatted	Expected formatted value
74 74
  */
75
-#define fetchf_ok( settings, setting, raw_array, formatted ) do {	\
76
-	const uint8_t raw[] = raw_array;				\
77
-	char actual[ strlen ( formatted ) + 1 ];			\
75
+#define fetchf_ok( _settings, _setting, _raw_array, _formatted ) do {	\
76
+	const uint8_t raw[] = _raw_array;				\
77
+	char actual[ strlen ( _formatted ) + 1 ];			\
78 78
 	int len;							\
79 79
 									\
80
-	ok ( store_setting ( settings, setting, raw,			\
80
+	ok ( store_setting ( _settings, _setting, raw,			\
81 81
 			     sizeof ( raw ) ) == 0 );			\
82
-	len = fetchf_setting ( settings, setting, actual,		\
82
+	len = fetchf_setting ( _settings, _setting, NULL, NULL, actual,	\
83 83
 			       sizeof ( actual ) );			\
84
-	DBGC ( settings, "Fetched %s \"%s\" from:\n",			\
85
-	       (setting)->type->name, actual );				\
86
-	DBGC_HDA ( settings, 0, raw, sizeof ( raw ) );			\
84
+	DBGC ( _settings, "Fetched %s \"%s\" from:\n",			\
85
+	       (_setting)->type->name, actual );			\
86
+	DBGC_HDA ( _settings, 0, raw, sizeof ( raw ) );			\
87 87
 	ok ( len == ( int ) ( sizeof ( actual ) - 1 ) );		\
88
-	ok ( strcmp ( actual, formatted ) == 0 );			\
88
+	ok ( strcmp ( actual, _formatted ) == 0 );			\
89 89
 	} while ( 0 )
90 90
 
91 91
 /**
92 92
  * Report a numeric-store test result
93 93
  *
94
- * @v settings		Settings block
95
- * @v setting		Setting
96
- * @v numeric		Numeric value
97
- * @v raw_array		Expected raw value
94
+ * @v _settings		Settings block
95
+ * @v _setting		Setting
96
+ * @v _numeric		Numeric value
97
+ * @v _raw_array	Expected raw value
98 98
  */
99
-#define storen_ok( settings, setting, numeric, raw_array ) do {		\
100
-	const uint8_t expected[] = raw_array;				\
99
+#define storen_ok( _settings, _setting, _numeric, _raw_array ) do {	\
100
+	const uint8_t expected[] = _raw_array;				\
101 101
 	uint8_t actual[ sizeof ( expected ) ];				\
102 102
 	int len;							\
103 103
 									\
104
-	ok ( storen_setting ( settings, setting, numeric ) == 0 );	\
105
-	len = fetch_setting ( settings, setting, actual,		\
104
+	ok ( storen_setting ( _settings, _setting, _numeric ) == 0 );	\
105
+	len = fetch_setting ( _settings, _setting, NULL, NULL, actual,	\
106 106
 			      sizeof ( actual ) );			\
107 107
 	if ( len >= 0 ) {						\
108
-		DBGC ( settings, "Stored %s %#lx, got:\n",		\
109
-		       (setting)->type->name,				\
110
-		       ( unsigned long ) numeric );			\
111
-		DBGC_HDA ( settings, 0, actual, len );			\
108
+		DBGC ( _settings, "Stored %s %#lx, got:\n",		\
109
+		       (_setting)->type->name,				\
110
+		       ( unsigned long ) _numeric );			\
111
+		DBGC_HDA ( _settings, 0, actual, len );			\
112 112
 	} else {							\
113
-		DBGC ( settings, "Stored %s %#lx, got error %s\n",	\
114
-		       (setting)->type->name,				\
115
-		       ( unsigned long ) numeric, strerror ( len ) );	\
113
+		DBGC ( _settings, "Stored %s %#lx, got error %s\n",	\
114
+		       (_setting)->type->name,				\
115
+		       ( unsigned long ) _numeric, strerror ( len ) );	\
116 116
 	}								\
117 117
 	ok ( len == ( int ) sizeof ( actual ) );			\
118 118
 	ok ( memcmp ( actual, expected, sizeof ( actual ) ) == 0 );	\
@@ -121,22 +121,23 @@ FILE_LICENCE ( GPL2_OR_LATER );
121 121
 /**
122 122
  * Report a numeric-fetch test result
123 123
  *
124
- * @v settings		Settings block
125
- * @v setting		Setting
126
- * @v raw_array		Raw array
127
- * @v numeric		Expected numeric value
124
+ * @v _settings		Settings block
125
+ * @v _setting		Setting
126
+ * @v _raw_array	Raw array
127
+ * @v _numeric		Expected numeric value
128 128
  */
129
-#define fetchn_ok( settings, setting, raw_array, numeric ) do {		\
130
-	const uint8_t raw[] = raw_array;				\
129
+#define fetchn_ok( _settings, _setting, _raw_array, _numeric ) do {	\
130
+	const uint8_t raw[] = _raw_array;				\
131 131
 	unsigned long actual;						\
132 132
 									\
133
-	ok ( store_setting ( settings, setting, raw,			\
133
+	ok ( store_setting ( _settings, _setting, raw,			\
134 134
 			     sizeof ( raw ) ) == 0 );			\
135
-	ok ( fetchn_setting ( settings, setting, &actual ) == 0 );	\
136
-	DBGC ( settings, "Fetched %s %#lx from:\n",			\
137
-	       (setting)->type->name, actual );				\
138
-	DBGC_HDA ( settings, 0, raw, sizeof ( raw ) );			\
139
-	ok ( actual == ( unsigned long ) numeric );			\
135
+	ok ( fetchn_setting ( _settings, _setting, NULL, NULL,		\
136
+			      &actual ) == 0 );				\
137
+	DBGC ( _settings, "Fetched %s %#lx from:\n",			\
138
+	       (_setting)->type->name, actual );			\
139
+	DBGC_HDA ( _settings, 0, raw, sizeof ( raw ) );			\
140
+	ok ( actual == ( unsigned long ) _numeric );			\
140 141
 	} while ( 0 )
141 142
 
142 143
 /** Test generic settings block */

+ 24
- 21
src/usr/autoboot.c 查看文件

@@ -59,7 +59,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
59 59
 #define CYAN	"\033[36m"
60 60
 
61 61
 /** The "scriptlet" setting */
62
-struct setting scriptlet_setting __setting ( SETTING_MISC ) = {
62
+const struct setting scriptlet_setting __setting ( SETTING_MISC ) = {
63 63
 	.name = "scriptlet",
64 64
 	.description = "Boot scriptlet",
65 65
 	.tag = DHCP_EB_SCRIPTLET,
@@ -119,7 +119,7 @@ static struct uri * parse_next_server_and_filename ( struct in_addr next_server,
119 119
 }
120 120
 
121 121
 /** The "keep-san" setting */
122
-struct setting keep_san_setting __setting ( SETTING_SANBOOT_EXTRA ) = {
122
+const struct setting keep_san_setting __setting ( SETTING_SANBOOT_EXTRA ) = {
123 123
 	.name = "keep-san",
124 124
 	.description = "Preserve SAN connection",
125 125
 	.tag = DHCP_EB_KEEP_SAN,
@@ -127,7 +127,7 @@ struct setting keep_san_setting __setting ( SETTING_SANBOOT_EXTRA ) = {
127 127
 };
128 128
 
129 129
 /** The "skip-san-boot" setting */
130
-struct setting skip_san_boot_setting __setting ( SETTING_SANBOOT_EXTRA ) = {
130
+const struct setting skip_san_boot_setting __setting ( SETTING_SANBOOT_EXTRA )={
131 131
 	.name = "skip-san-boot",
132 132
 	.description = "Do not boot from SAN device",
133 133
 	.tag = DHCP_EB_SKIP_SAN_BOOT,
@@ -256,16 +256,15 @@ struct uri * fetch_next_server_and_filename ( struct settings *settings ) {
256 256
 	struct uri *uri = NULL;
257 257
 	char *filename;
258 258
 
259
-	/* Determine settings block containing the filename, if any */
260
-	settings = fetch_setting_origin ( settings, &filename_setting );
261
-
262
-	/* If we have a filename, fetch it along with next-server */
263
-	if ( settings ) {
259
+	/* If we have a filename, fetch it along with the next-server
260
+	 * setting from the same settings block.
261
+	 */
262
+	if ( fetch_setting ( settings, &filename_setting, &settings,
263
+			     NULL, NULL, 0 ) >= 0 ) {
264
+		fetch_string_setting_copy ( settings, &filename_setting,
265
+					    &raw_filename );
264 266
 		fetch_ipv4_setting ( settings, &next_server_setting,
265 267
 				     &next_server );
266
-		if ( fetch_string_setting_copy ( settings, &filename_setting,
267
-						 &raw_filename ) < 0 )
268
-			goto err_fetch;
269 268
 	}
270 269
 
271 270
 	/* Expand filename setting */
@@ -286,7 +285,6 @@ struct uri * fetch_next_server_and_filename ( struct settings *settings ) {
286 285
 	free ( filename );
287 286
  err_expand:
288 287
 	free ( raw_filename );
289
- err_fetch:
290 288
 	return uri;
291 289
 }
292 290
 
@@ -297,25 +295,30 @@ struct uri * fetch_next_server_and_filename ( struct settings *settings ) {
297 295
  * @ret uri		URI, or NULL on failure
298 296
  */
299 297
 static struct uri * fetch_root_path ( struct settings *settings ) {
300
-	char buf[256];
298
+	struct uri *uri = NULL;
299
+	char *raw_root_path;
301 300
 	char *root_path;
302
-	struct uri *uri;
303 301
 
304 302
 	/* Fetch root-path setting */
305
-	fetch_string_setting ( settings, &root_path_setting,
306
-			       buf, sizeof ( buf ) );
307
-	if ( buf[0] )
308
-		printf ( "Root path: %s\n", buf );
303
+	fetch_string_setting_copy ( settings, &root_path_setting,
304
+				    &raw_root_path );
309 305
 
310 306
 	/* Expand filename setting */
311
-	root_path = expand_settings ( buf );
307
+	root_path = expand_settings ( raw_root_path ? raw_root_path : "" );
312 308
 	if ( ! root_path )
313
-		return NULL;
309
+		goto err_expand;
314 310
 
315 311
 	/* Parse root path */
312
+	if ( root_path[0] )
313
+		printf ( "Root path: %s\n", root_path );
316 314
 	uri = parse_uri ( root_path );
315
+	if ( ! uri )
316
+		goto err_parse;
317 317
 
318
+ err_parse:
318 319
 	free ( root_path );
320
+ err_expand:
321
+	free ( raw_root_path );
319 322
 	return uri;
320 323
 }
321 324
 
@@ -331,7 +334,7 @@ static int have_pxe_menu ( void ) {
331 334
 		= { .tag = DHCP_PXE_DISCOVERY_CONTROL };
332 335
 	struct setting pxe_boot_menu_setting
333 336
 		= { .tag = DHCP_PXE_BOOT_MENU };
334
-	char buf[256];
337
+	char buf[ 10 /* "PXEClient" + NUL */ ];
335 338
 	unsigned int pxe_discovery_control;
336 339
 
337 340
 	fetch_string_setting ( NULL, &vendor_class_id_setting,

+ 1
- 1
src/usr/nslookup.c 查看文件

@@ -71,7 +71,7 @@ static void nslookup_close ( struct nslookup *nslookup, int rc ) {
71 71
 static void nslookup_resolv_done ( struct nslookup *nslookup,
72 72
 				   struct sockaddr *sa ) {
73 73
 	struct sockaddr_in *sin;
74
-	struct setting_type *default_type;
74
+	const struct setting_type *default_type;
75 75
 	struct settings *settings;
76 76
 	struct setting setting;
77 77
 	void *data;

+ 8
- 7
src/usr/pxemenu.c 查看文件

@@ -101,9 +101,9 @@ static int pxe_menu_parse ( struct pxe_menu **menu ) {
101 101
 
102 102
 	/* Fetch raw menu */
103 103
 	memset ( raw_menu, 0, sizeof ( raw_menu ) );
104
-	if ( ( raw_menu_len = fetch_setting ( NULL, &pxe_boot_menu_setting,
105
-					      raw_menu,
106
-					      sizeof ( raw_menu ) ) ) < 0 ) {
104
+	if ( ( raw_menu_len = fetch_raw_setting ( NULL, &pxe_boot_menu_setting,
105
+						  raw_menu,
106
+						  sizeof ( raw_menu ) ) ) < 0 ){
107 107
 		rc = raw_menu_len;
108 108
 		DBG ( "Could not retrieve raw PXE boot menu: %s\n",
109 109
 		      strerror ( rc ) );
@@ -116,8 +116,9 @@ static int pxe_menu_parse ( struct pxe_menu **menu ) {
116 116
 	raw_menu_end = ( raw_menu + raw_menu_len );
117 117
 
118 118
 	/* Fetch raw prompt length */
119
-	raw_prompt_len = fetch_setting_len ( NULL,
120
-					     &pxe_boot_menu_prompt_setting );
119
+	raw_prompt_len =
120
+		fetch_raw_setting ( NULL, &pxe_boot_menu_prompt_setting,
121
+				    NULL, 0 );
121 122
 	if ( raw_prompt_len < 0 )
122 123
 		raw_prompt_len = 0;
123 124
 
@@ -168,8 +169,8 @@ static int pxe_menu_parse ( struct pxe_menu **menu ) {
168 169
 	if ( raw_prompt_len ) {
169 170
 		raw_menu_prompt = ( ( ( void * ) raw_menu_item ) +
170 171
 				    1 /* NUL */ );
171
-		fetch_setting ( NULL, &pxe_boot_menu_prompt_setting,
172
-				raw_menu_prompt, raw_prompt_len );
172
+		fetch_raw_setting ( NULL, &pxe_boot_menu_prompt_setting,
173
+				    raw_menu_prompt, raw_prompt_len );
173 174
 		(*menu)->timeout =
174 175
 			( ( raw_menu_prompt->timeout == 0xff ) ?
175 176
 			  -1 : raw_menu_prompt->timeout );

Loading…
取消
儲存