Browse Source

[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 years ago
parent
commit
22001cb206

+ 1
- 1
src/arch/i386/interface/vmware/guestinfo.c View File

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

+ 3
- 3
src/arch/x86/core/cpuid_settings.c View File

117
 #define CPUID_NUM_REGISTERS( tag ) ( ( ( (tag) >> 16 ) & 0x3 ) + 1 )
117
 #define CPUID_NUM_REGISTERS( tag ) ( ( ( (tag) >> 16 ) & 0x3 ) + 1 )
118
 
118
 
119
 /** CPUID settings scope */
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
  * Check applicability of CPUID setting
123
  * Check applicability of CPUID setting
127
  * @ret applies		Setting applies within this settings block
127
  * @ret applies		Setting applies within this settings block
128
  */
128
  */
129
 static int cpuid_settings_applies ( struct settings *settings __unused,
129
 static int cpuid_settings_applies ( struct settings *settings __unused,
130
-				    struct setting *setting ) {
130
+				    const struct setting *setting ) {
131
 
131
 
132
 	return ( setting->scope == &cpuid_settings_scope );
132
 	return ( setting->scope == &cpuid_settings_scope );
133
 }
133
 }
252
 };
252
 };
253
 
253
 
254
 /** CPUID predefined settings */
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
 		.name = "cpuvendor",
257
 		.name = "cpuvendor",
258
 		.description = "CPU vendor",
258
 		.description = "CPU vendor",

+ 3
- 3
src/core/memmap_settings.c View File

108
 #define MEMMAP_SCALE( tag ) ( (tag) & 0x3f )
108
 #define MEMMAP_SCALE( tag ) ( (tag) & 0x3f )
109
 
109
 
110
 /** Memory map settings scope */
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
  * Check applicability of memory map setting
114
  * Check applicability of memory map setting
118
  * @ret applies		Setting applies within this settings block
118
  * @ret applies		Setting applies within this settings block
119
  */
119
  */
120
 static int memmap_settings_applies ( struct settings *settings __unused,
120
 static int memmap_settings_applies ( struct settings *settings __unused,
121
-				     struct setting *setting ) {
121
+				     const struct setting *setting ) {
122
 
122
 
123
 	return ( setting->scope == &memmap_settings_scope );
123
 	return ( setting->scope == &memmap_settings_scope );
124
 }
124
 }
231
 };
231
 };
232
 
232
 
233
 /** Memory map predefined settings */
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
 		.name = "memsize",
236
 		.name = "memsize",
237
 		.description = "Memory size (in MB)",
237
 		.description = "Memory size (in MB)",

+ 2
- 2
src/core/nvo.c View File

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

+ 253
- 187
src/core/settings.c
File diff suppressed because it is too large
View File


+ 4
- 4
src/crypto/clientcert.c View File

128
 
128
 
129
 		/* Fetch new client certificate, if any */
129
 		/* Fetch new client certificate, if any */
130
 		free ( cert );
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
 			client_certificate.data = cert;
133
 			client_certificate.data = cert;
134
 			client_certificate.len = len;
134
 			client_certificate.len = len;
135
 		}
135
 		}
140
 
140
 
141
 		/* Fetch new client private key, if any */
141
 		/* Fetch new client private key, if any */
142
 		free ( key );
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
 			client_private_key.data = key;
145
 			client_private_key.data = key;
146
 			client_private_key.len = len;
146
 			client_private_key.len = len;
147
 		}
147
 		}

+ 2
- 2
src/crypto/rootcert.c View File

100
 		/* Fetch copy of "trust" setting, if it exists.  This
100
 		/* Fetch copy of "trust" setting, if it exists.  This
101
 		 * memory will never be freed.
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
 			root_certificates.fingerprints = external;
105
 			root_certificates.fingerprints = external;
106
 			root_certificates.count = ( len / FINGERPRINT_LEN );
106
 			root_certificates.count = ( len / FINGERPRINT_LEN );
107
 		}
107
 		}

+ 6
- 4
src/drivers/block/ibft.c View File

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

+ 2
- 2
src/drivers/bus/pci_settings.c View File

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

+ 6
- 5
src/drivers/net/phantom/phantom.c View File

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

+ 11
- 12
src/hci/commands/nvo_cmd.c View File

58
 	struct show_options opts;
58
 	struct show_options opts;
59
 	struct named_setting setting;
59
 	struct named_setting setting;
60
 	struct settings *origin;
60
 	struct settings *origin;
61
+	struct setting fetched;
61
 	char name_buf[32];
62
 	char name_buf[32];
62
 	char *value;
63
 	char *value;
64
+	int len;
63
 	int rc;
65
 	int rc;
64
 
66
 
65
 	/* Parse options */
67
 	/* Parse options */
71
 		goto err_parse_setting;
73
 		goto err_parse_setting;
72
 
74
 
73
 	/* Fetch formatted setting value */
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
 		printf ( "Could not find \"%s\": %s\n",
79
 		printf ( "Could not find \"%s\": %s\n",
77
 			 setting.setting.name, strerror ( rc ) );
80
 			 setting.setting.name, strerror ( rc ) );
78
 		goto err_fetchf;
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
 	/* Print setting value */
84
 	/* Print setting value */
85
+	setting_name ( origin, &fetched, name_buf, sizeof ( name_buf ) );
87
 	printf ( "%s = %s\n", name_buf, value );
86
 	printf ( "%s = %s\n", name_buf, value );
88
 
87
 
89
 	/* Success */
88
 	/* Success */
234
 	/* Read existing value, treating errors as equivalent to an
233
 	/* Read existing value, treating errors as equivalent to an
235
 	 * empty initial setting.
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
 	/* Read new value */
239
 	/* Read new value */
240
 	if ( ( rc = readline_history ( NULL, existing, NULL, value ) ) != 0 )
240
 	if ( ( rc = readline_history ( NULL, existing, NULL, value ) ) != 0 )
294
 	     ( ( rc = parse_integer ( argv[ optind + 1 ], &increment ) ) != 0))
294
 	     ( ( rc = parse_integer ( argv[ optind + 1 ], &increment ) ) != 0))
295
 		goto err_parse_increment;
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
 	if ( ( rc = fetchn_setting ( setting.settings, &setting.setting,
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
 		value = 0;
302
 		value = 0;
304
 		if ( ! setting.setting.type )
303
 		if ( ! setting.setting.type )
305
 			setting.setting.type = &setting_type_int32;
304
 			setting.setting.type = &setting_type_int32;

+ 2
- 2
src/hci/commands/pci_cmd.c View File

68
 		goto err_parse_setting;
68
 		goto err_parse_setting;
69
 
69
 
70
 	/* Determine starting bus:dev.fn address */
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
 		/* Setting not yet defined: start searching from 00:00.0 */
73
 		/* Setting not yet defined: start searching from 00:00.0 */
74
 		prev = 0;
74
 		prev = 0;
75
 	} else {
75
 	} else {

+ 28
- 31
src/hci/tui/settings_ui.c View File

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

+ 1
- 1
src/include/ipxe/net80211.h View File

1093
 
1093
 
1094
 
1094
 
1095
 /** 802.11 encryption key setting */
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 View File

45
 /** Name of non-volatile options settings block */
45
 /** Name of non-volatile options settings block */
46
 #define NVO_SETTINGS_NAME "nvo"
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
 extern void nvo_init ( struct nvo_block *nvo, struct nvs_device *nvs,
50
 extern void nvo_init ( struct nvo_block *nvo, struct nvs_device *nvs,
50
 		       size_t address, size_t len,
51
 		       size_t address, size_t len,
51
 		       int ( * resize ) ( struct nvo_block *nvo, size_t len ),
52
 		       int ( * resize ) ( struct nvo_block *nvo, size_t len ),

+ 99
- 81
src/include/ipxe/settings.h View File

32
 	 * This identifies the type of setting (e.g. string, IPv4
32
 	 * This identifies the type of setting (e.g. string, IPv4
33
 	 * address, etc.).
33
 	 * address, etc.).
34
 	 */
34
 	 */
35
-	struct setting_type *type;
35
+	const struct setting_type *type;
36
 	/** Setting tag, if applicable
36
 	/** Setting tag, if applicable
37
 	 *
37
 	 *
38
 	 * The setting tag is a numerical description of the setting
38
 	 * The setting tag is a numerical description of the setting
45
 	 * For historic reasons, a NULL scope with a non-zero tag
45
 	 * For historic reasons, a NULL scope with a non-zero tag
46
 	 * indicates a DHCPv4 option setting.
46
 	 * indicates a DHCPv4 option setting.
47
 	 */
47
 	 */
48
-	struct settings_scope *scope;
48
+	const struct settings_scope *scope;
49
 };
49
 };
50
 
50
 
51
 /** Configuration setting table */
51
 /** Configuration setting table */
90
 	 * @ret applies		Setting applies within this settings block
90
 	 * @ret applies		Setting applies within this settings block
91
 	 */
91
 	 */
92
 	int ( * applies ) ( struct settings *settings,
92
 	int ( * applies ) ( struct settings *settings,
93
-			    struct setting *setting );
93
+			    const struct setting *setting );
94
 	/** Store value of setting
94
 	/** Store value of setting
95
 	 *
95
 	 *
96
 	 * @v settings		Settings block
96
 	 * @v settings		Settings block
99
 	 * @v len		Length of setting data
99
 	 * @v len		Length of setting data
100
 	 * @ret rc		Return status code
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
 			  const void *data, size_t len );
104
 			  const void *data, size_t len );
104
 	/** Fetch value of setting
105
 	/** Fetch value of setting
105
 	 *
106
 	 *
136
 	/** Settings block operations */
137
 	/** Settings block operations */
137
 	struct settings_operations *op;
138
 	struct settings_operations *op;
138
 	/** Default scope for numerical settings constructed for this block */
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
 	 * @v len		Length of buffer
194
 	 * @v len		Length of buffer
194
 	 * @ret len		Length of raw value, or negative error
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
 			  void *buf, size_t len );
198
 			  void *buf, size_t len );
198
 	/** Format setting value as a string
199
 	/** Format setting value as a string
199
 	 *
200
 	 *
204
 	 * @v len		Length of buffer
205
 	 * @v len		Length of buffer
205
 	 * @ret len		Length of formatted value, or negative error
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
 			   size_t raw_len, char *buf, size_t len );
209
 			   size_t raw_len, char *buf, size_t len );
209
 	/** Convert number to setting value
210
 	/** Convert number to setting value
210
 	 *
211
 	 *
214
 	 * @v len		Length of buffer
215
 	 * @v len		Length of buffer
215
 	 * @ret len		Length of raw value, or negative error
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
 			       void *buf, size_t len );
220
 			       void *buf, size_t len );
219
 	/** Convert setting value to number
221
 	/** Convert setting value to number
220
 	 *
222
 	 *
224
 	 * @v value		Numeric value to fill in
226
 	 * @v value		Numeric value to fill in
225
 	 * @ret rc		Return status code
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
 			     size_t raw_len, unsigned long *value );
230
 			     size_t raw_len, unsigned long *value );
229
 };
231
 };
230
 
232
 
256
 /** A built-in setting */
258
 /** A built-in setting */
257
 struct builtin_setting {
259
 struct builtin_setting {
258
 	/** Setting */
260
 	/** Setting */
259
-	struct setting *setting;
261
+	const struct setting *setting;
260
 	/** Fetch setting value
262
 	/** Fetch setting value
261
 	 *
263
 	 *
262
 	 * @v data		Buffer to fill with setting data
264
 	 * @v data		Buffer to fill with setting data
273
 #define __builtin_setting __table_entry ( BUILTIN_SETTINGS, 01 )
275
 #define __builtin_setting __table_entry ( BUILTIN_SETTINGS, 01 )
274
 
276
 
275
 /** Built-in setting scope */
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
  * A generic settings block
281
  * A generic settings block
291
 						      const char *name );
293
 						      const char *name );
292
 extern struct settings_operations generic_settings_operations;
294
 extern struct settings_operations generic_settings_operations;
293
 extern int generic_settings_store ( struct settings *settings,
295
 extern int generic_settings_store ( struct settings *settings,
294
-				    struct setting *setting,
296
+				    const struct setting *setting,
295
 				    const void *data, size_t len );
297
 				    const void *data, size_t len );
296
 extern int generic_settings_fetch ( struct settings *settings,
298
 extern int generic_settings_fetch ( struct settings *settings,
297
 				    struct setting *setting,
299
 				    struct setting *setting,
304
 
306
 
305
 extern struct settings * settings_target ( struct settings *settings );
307
 extern struct settings * settings_target ( struct settings *settings );
306
 extern int setting_applies ( struct settings *settings,
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
 			   const void *data, size_t len );
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
 			   void *data, size_t len );
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
 extern int fetch_setting_copy ( struct settings *settings,
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
 extern int fetch_string_setting ( struct settings *settings,
327
 extern int fetch_string_setting ( struct settings *settings,
319
-				  struct setting *setting,
328
+				  const struct setting *setting,
320
 				  char *data, size_t len );
329
 				  char *data, size_t len );
321
 extern int fetch_string_setting_copy ( struct settings *settings,
330
 extern int fetch_string_setting_copy ( struct settings *settings,
322
-				       struct setting *setting,
331
+				       const struct setting *setting,
323
 				       char **data );
332
 				       char **data );
324
 extern int fetch_ipv4_array_setting ( struct settings *settings,
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
 extern int fetch_ipv4_setting ( struct settings *settings,
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
 extern int fetch_int_setting ( struct settings *settings,
339
 extern int fetch_int_setting ( struct settings *settings,
331
-			       struct setting *setting, long *value );
340
+			       const struct setting *setting, long *value );
332
 extern int fetch_uint_setting ( struct settings *settings,
341
 extern int fetch_uint_setting ( struct settings *settings,
333
-				struct setting *setting,
342
+				const struct setting *setting,
334
 				unsigned long *value );
343
 				unsigned long *value );
335
 extern long fetch_intz_setting ( struct settings *settings,
344
 extern long fetch_intz_setting ( struct settings *settings,
336
-				 struct setting *setting );
345
+				 const struct setting *setting );
337
 extern unsigned long fetch_uintz_setting ( struct settings *settings,
346
 extern unsigned long fetch_uintz_setting ( struct settings *settings,
338
-					   struct setting *setting );
347
+					   const struct setting *setting );
339
 extern int fetch_uuid_setting ( struct settings *settings,
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
 extern void clear_settings ( struct settings *settings );
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
 extern struct settings * find_child_settings ( struct settings *parent,
354
 extern struct settings * find_child_settings ( struct settings *parent,
345
 					       const char *name );
355
 					       const char *name );
351
 extern int parse_setting_name ( char *name, get_child_settings_t get_child,
361
 extern int parse_setting_name ( char *name, get_child_settings_t get_child,
352
 				struct settings **settings,
362
 				struct settings **settings,
353
 				struct setting *setting );
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
 			  char *buf, size_t len );
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
 			    size_t raw_len, char *buf, size_t len );
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
 			   void *buf, size_t len );
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
 			      size_t raw_len, unsigned long *value );
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
 			    char *buf, size_t len );
378
 			    char *buf, size_t len );
366
 extern int fetchf_setting_copy ( struct settings *settings,
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
 extern int storef_setting ( struct settings *settings,
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
 			    unsigned long *value );
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
 			    unsigned long value );
391
 			    unsigned long value );
375
 extern char * expand_settings ( const char *string );
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
  * Initialise a settings block
428
  * Initialise a settings block
418
 static inline void settings_init ( struct settings *settings,
435
 static inline void settings_init ( struct settings *settings,
419
 				   struct settings_operations *op,
436
 				   struct settings_operations *op,
420
 				   struct refcnt *refcnt,
437
 				   struct refcnt *refcnt,
421
-				   struct settings_scope *default_scope ) {
438
+				   const struct settings_scope *default_scope ){
422
 	INIT_LIST_HEAD ( &settings->siblings );
439
 	INIT_LIST_HEAD ( &settings->siblings );
423
 	INIT_LIST_HEAD ( &settings->children );
440
 	INIT_LIST_HEAD ( &settings->children );
424
 	settings->op = op;
441
 	settings->op = op;
447
  * @ret rc		Return status code
464
  * @ret rc		Return status code
448
  */
465
  */
449
 static inline int delete_setting ( struct settings *settings,
466
 static inline int delete_setting ( struct settings *settings,
450
-				   struct setting *setting ) {
467
+				   const struct setting *setting ) {
451
 	return store_setting ( settings, setting, NULL, 0 );
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
  * @v settings		Settings block, or NULL to search all blocks
474
  * @v settings		Settings block, or NULL to search all blocks
458
  * @v setting		Setting to fetch
475
  * @v setting		Setting to fetch
459
  * @ret exists		Setting exists
476
  * @ret exists		Setting exists
460
  */
477
  */
461
 static inline int setting_exists ( struct settings *settings,
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
 #endif /* _IPXE_SETTINGS_H */
484
 #endif /* _IPXE_SETTINGS_H */

+ 6
- 2
src/interface/efi/efi_snp_hii.c View File

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

+ 4
- 4
src/interface/smbios/smbios_settings.c View File

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

+ 3
- 3
src/net/80211/net80211.c View File

204
  * If this is blank, we scan for all networks and use the one with the
204
  * If this is blank, we scan for all networks and use the one with the
205
  * greatest signal strength.
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
 	.name = "ssid",
208
 	.name = "ssid",
209
 	.description = "Wireless SSID",
209
 	.description = "Wireless SSID",
210
 	.type = &setting_type_string,
210
 	.type = &setting_type_string,
216
  * active scan (send probe packets). If this setting is nonzero, an
216
  * active scan (send probe packets). If this setting is nonzero, an
217
  * active scan on the 2.4GHz band will be used to associate.
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
 	.name = "active-scan",
220
 	.name = "active-scan",
221
 	.description = "Actively scan for wireless networks",
221
 	.description = "Actively scan for wireless networks",
222
 	.type = &setting_type_int8,
222
 	.type = &setting_type_int8,
228
  * normal iPXE method for entering hex settings; an ASCII string of
228
  * normal iPXE method for entering hex settings; an ASCII string of
229
  * hex characters will not behave as expected.
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
 	.name = "key",
232
 	.name = "key",
233
 	.description = "Wireless encryption key",
233
 	.description = "Wireless encryption key",
234
 	.type = &setting_type_string,
234
 	.type = &setting_type_string,

+ 4
- 4
src/net/80211/wep.c View File

236
 	     dev->associating->crypto == NET80211_CRYPT_NONE )
236
 	     dev->associating->crypto == NET80211_CRYPT_NONE )
237
 		return 0;	/* no crypto? OK. */
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
 	if ( len <= 0 ) {
242
 	if ( len <= 0 ) {
243
 		DBGC ( dev, "802.11 %p cannot do WEP without a key\n", dev );
243
 		DBGC ( dev, "802.11 %p cannot do WEP without a key\n", dev );
278
 	if ( ! dev->crypto || ( dev->crypto->init != wep_init ) )
278
 	if ( ! dev->crypto || ( dev->crypto->init != wep_init ) )
279
 		change ^= 1;
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
 	if ( len <= 0 )
283
 	if ( len <= 0 )
284
 		change ^= 1;
284
 		change ^= 1;
285
 
285
 

+ 2
- 2
src/net/dhcppkt.c View File

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

+ 6
- 12
src/net/fakedhcp.c View File

49
 	struct setting setting = { .name = "" };
49
 	struct setting setting = { .name = "" };
50
 	unsigned int subtag;
50
 	unsigned int subtag;
51
 	unsigned int tag;
51
 	unsigned int tag;
52
+	void *data;
52
 	int len;
53
 	int len;
53
-	int check_len;
54
 	int rc;
54
 	int rc;
55
 
55
 
56
 	for ( subtag = DHCP_MIN_OPTION; subtag <= DHCP_MAX_OPTION; subtag++ ) {
56
 	for ( subtag = DHCP_MIN_OPTION; subtag <= DHCP_MAX_OPTION; subtag++ ) {
66
 		default:
66
 		default:
67
 			/* Copy setting, if present */
67
 			/* Copy setting, if present */
68
 			setting.tag = tag;
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
 					return rc;
74
 					return rc;
81
 			}
75
 			}
82
 			break;
76
 			break;

+ 3
- 3
src/net/ipv4.c View File

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

+ 3
- 3
src/net/ipv6.c View File

954
  * @v len		Length of buffer
954
  * @v len		Length of buffer
955
  * @ret len		Length of raw value, or negative error
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
 				const char *value, void *buf, size_t len ) {
958
 				const char *value, void *buf, size_t len ) {
959
 	struct in6_addr ipv6;
959
 	struct in6_addr ipv6;
960
 	int rc;
960
 	int rc;
981
  * @v len		Length of buffer
981
  * @v len		Length of buffer
982
  * @ret len		Length of formatted value, or negative error
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
 				 const void *raw, size_t raw_len, char *buf,
985
 				 const void *raw, size_t raw_len, char *buf,
986
 				 size_t len ) {
986
 				 size_t len ) {
987
 	const struct in6_addr *ipv6 = raw;
987
 	const struct in6_addr *ipv6 = raw;
992
 }
992
 }
993
 
993
 
994
 /** An IPv6 address setting type */
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
 	.name = "ipv6",
996
 	.name = "ipv6",
997
 	.parse = parse_ipv6_setting,
997
 	.parse = parse_ipv6_setting,
998
 	.format = format_ipv6_setting,
998
 	.format = format_ipv6_setting,

+ 8
- 7
src/net/netdev_settings.c View File

36
  */
36
  */
37
 
37
 
38
 /** Network device predefined settings */
38
 /** Network device predefined settings */
39
-struct setting mac_setting __setting ( SETTING_NETDEV ) = {
39
+const struct setting mac_setting __setting ( SETTING_NETDEV ) = {
40
 	.name = "mac",
40
 	.name = "mac",
41
 	.description = "MAC address",
41
 	.description = "MAC address",
42
 	.type = &setting_type_hex,
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
 	.name = "bustype",
45
 	.name = "bustype",
46
 	.description = "Bus type",
46
 	.description = "Bus type",
47
 	.type = &setting_type_string,
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
 	.name = "busloc",
50
 	.name = "busloc",
51
 	.description = "Bus location",
51
 	.description = "Bus location",
52
 	.type = &setting_type_uint32,
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
 	.name = "busid",
55
 	.name = "busid",
56
 	.description = "Bus ID",
56
 	.description = "Bus ID",
57
 	.type = &setting_type_hex,
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
 	.name = "chip",
60
 	.name = "chip",
61
 	.description = "Chip",
61
 	.description = "Chip",
62
 	.type = &setting_type_string,
62
 	.type = &setting_type_string,
194
 /** A network device setting operation */
194
 /** A network device setting operation */
195
 struct netdev_setting_operation {
195
 struct netdev_setting_operation {
196
 	/** Setting */
196
 	/** Setting */
197
-	struct setting *setting;
197
+	const struct setting *setting;
198
 	/** Store setting (or NULL if not supported)
198
 	/** Store setting (or NULL if not supported)
199
 	 *
199
 	 *
200
 	 * @v netdev		Network device
200
 	 * @v netdev		Network device
232
  * @v len		Length of setting data
232
  * @v len		Length of setting data
233
  * @ret rc		Return status code
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
 			  const void *data, size_t len ) {
237
 			  const void *data, size_t len ) {
237
 	struct net_device *netdev = container_of ( settings, struct net_device,
238
 	struct net_device *netdev = container_of ( settings, struct net_device,
238
 						   settings.settings );
239
 						   settings.settings );

+ 20
- 41
src/net/tcp/iscsi.c View File

1860
 };
1860
 };
1861
 
1861
 
1862
 /** iSCSI initiator IQN setting */
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
 	.name = "initiator-iqn",
1864
 	.name = "initiator-iqn",
1865
 	.description = "iSCSI initiator name",
1865
 	.description = "iSCSI initiator name",
1866
 	.tag = DHCP_ISCSI_INITIATOR_IQN,
1866
 	.tag = DHCP_ISCSI_INITIATOR_IQN,
1868
 };
1868
 };
1869
 
1869
 
1870
 /** iSCSI reverse username setting */
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
 	.name = "reverse-username",
1872
 	.name = "reverse-username",
1873
 	.description = "Reverse user name",
1873
 	.description = "Reverse user name",
1874
 	.tag = DHCP_EB_REVERSE_USERNAME,
1874
 	.tag = DHCP_EB_REVERSE_USERNAME,
1876
 };
1876
 };
1877
 
1877
 
1878
 /** iSCSI reverse password setting */
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
 	.name = "reverse-password",
1880
 	.name = "reverse-password",
1881
 	.description = "Reverse password",
1881
 	.description = "Reverse password",
1882
 	.tag = DHCP_EB_REVERSE_PASSWORD,
1882
 	.tag = DHCP_EB_REVERSE_PASSWORD,
1947
 	/* Fetch relevant settings.  Don't worry about freeing on
1947
 	/* Fetch relevant settings.  Don't worry about freeing on
1948
 	 * error, since iscsi_free() will take care of that anyway.
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
 	if ( iscsi->initiator_iqn )
1962
 	if ( iscsi->initiator_iqn )
1983
 		return 0;
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
 	if ( hostname ) {
1967
 	if ( hostname ) {
1991
 		len = asprintf ( &iscsi->initiator_iqn,
1968
 		len = asprintf ( &iscsi->initiator_iqn,
1992
 				 ISCSI_DEFAULT_IQN_PREFIX ":%s", hostname );
1969
 				 ISCSI_DEFAULT_IQN_PREFIX ":%s", hostname );
1999
 		assert ( iscsi->initiator_iqn );
1976
 		assert ( iscsi->initiator_iqn );
2000
 		return 0;
1977
 		return 0;
2001
 	}
1978
 	}
1979
+
1980
+	/* Otherwise, try to construct an initiator IQN from the UUID */
2002
 	if ( ( len = fetch_uuid_setting ( NULL, &uuid_setting, &uuid ) ) < 0 ) {
1981
 	if ( ( len = fetch_uuid_setting ( NULL, &uuid_setting, &uuid ) ) < 0 ) {
2003
 		DBGC ( iscsi, "iSCSI %p has no suitable initiator IQN\n",
1982
 		DBGC ( iscsi, "iSCSI %p has no suitable initiator IQN\n",
2004
 		       iscsi );
1983
 		       iscsi );

+ 2
- 2
src/net/tcp/oncrpc.c View File

58
 	.length = 0
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
 	.name        = "uid",
62
 	.name        = "uid",
63
 	.description = "User ID",
63
 	.description = "User ID",
64
 	.tag         = DHCP_EB_UID,
64
 	.tag         = DHCP_EB_UID,
65
 	.type        = &setting_type_uint32
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
 	.name        = "gid",
69
 	.name        = "gid",
70
 	.description = "Group ID",
70
 	.description = "Group ID",
71
 	.tag         = DHCP_EB_GID,
71
 	.tag         = DHCP_EB_GID,

+ 2
- 8
src/net/tcp/syslogs.c View File

190
  */
190
  */
191
 
191
 
192
 /** Encrypted syslog server setting */
192
 /** Encrypted syslog server setting */
193
-struct setting syslogs_setting __setting ( SETTING_MISC ) = {
193
+const struct setting syslogs_setting __setting ( SETTING_MISC ) = {
194
 	.name = "syslogs",
194
 	.name = "syslogs",
195
 	.description = "Encrypted syslog server",
195
 	.description = "Encrypted syslog server",
196
 	.tag = DHCP_EB_SYSLOGS_SERVER,
196
 	.tag = DHCP_EB_SYSLOGS_SERVER,
206
 	static char *old_server;
206
 	static char *old_server;
207
 	char *server;
207
 	char *server;
208
 	struct interface *socket;
208
 	struct interface *socket;
209
-	int len;
210
 	int rc;
209
 	int rc;
211
 
210
 
212
 	/* Fetch log server */
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
 	/* Do nothing unless log server has changed */
214
 	/* Do nothing unless log server has changed */
220
 	if ( ( ( server == NULL ) && ( old_server == NULL ) ) ||
215
 	if ( ( ( server == NULL ) && ( old_server == NULL ) ) ||
266
  out_no_server:
261
  out_no_server:
267
  out_no_change:
262
  out_no_change:
268
 	free ( server );
263
 	free ( server );
269
- err_fetch_server:
270
 	return rc;
264
 	return rc;
271
 }
265
 }
272
 
266
 

+ 25
- 19
src/net/udp/dhcp.c View File

92
 };
92
 };
93
 
93
 
94
 /** DHCP server address setting */
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
 	.name = "dhcp-server",
96
 	.name = "dhcp-server",
97
 	.description = "DHCP server",
97
 	.description = "DHCP server",
98
 	.tag = DHCP_SERVER_IDENTIFIER,
98
 	.tag = DHCP_SERVER_IDENTIFIER,
975
 	uint8_t *dhcp_features;
975
 	uint8_t *dhcp_features;
976
 	size_t dhcp_features_len;
976
 	size_t dhcp_features_len;
977
 	size_t ll_addr_len;
977
 	size_t ll_addr_len;
978
+	void *user_class;
978
 	ssize_t len;
979
 	ssize_t len;
979
 	int rc;
980
 	int rc;
980
 
981
 
985
 					 data, max_len ) ) != 0 ) {
986
 					 data, max_len ) ) != 0 ) {
986
 		DBG ( "DHCP could not create DHCP packet: %s\n",
987
 		DBG ( "DHCP could not create DHCP packet: %s\n",
987
 		      strerror ( rc ) );
988
 		      strerror ( rc ) );
988
-		return rc;
989
+		goto err_create_packet;
989
 	}
990
 	}
990
 
991
 
991
 	/* Set client IP address */
992
 	/* Set client IP address */
998
 				    dhcp_features_len ) ) != 0 ) {
999
 				    dhcp_features_len ) ) != 0 ) {
999
 		DBG ( "DHCP could not set features list option: %s\n",
1000
 		DBG ( "DHCP could not set features list option: %s\n",
1000
 		      strerror ( rc ) );
1001
 		      strerror ( rc ) );
1001
-		return rc;
1002
+		goto err_store_features;
1002
 	}
1003
 	}
1003
 
1004
 
1004
 	/* Add options to identify the network device */
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
 	if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_EB_BUS_ID, &dhcp_desc,
1008
 	if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_EB_BUS_ID, &dhcp_desc,
1008
 				    sizeof ( dhcp_desc ) ) ) != 0 ) {
1009
 				    sizeof ( dhcp_desc ) ) ) != 0 ) {
1009
 		DBG ( "DHCP could not set bus ID option: %s\n",
1010
 		DBG ( "DHCP could not set bus ID option: %s\n",
1010
 		      strerror ( rc ) );
1011
 		      strerror ( rc ) );
1011
-		return rc;
1012
+		goto err_store_busid;
1012
 	}
1013
 	}
1013
 
1014
 
1014
 	/* Add DHCP client identifier.  Required for Infiniband, and
1015
 	/* Add DHCP client identifier.  Required for Infiniband, and
1022
 				    ( ll_addr_len + 1 ) ) ) != 0 ) {
1023
 				    ( ll_addr_len + 1 ) ) ) != 0 ) {
1023
 		DBG ( "DHCP could not set client ID: %s\n",
1024
 		DBG ( "DHCP could not set client ID: %s\n",
1024
 		      strerror ( rc ) );
1025
 		      strerror ( rc ) );
1025
-		return rc;
1026
+		goto err_store_client_id;
1026
 	}
1027
 	}
1027
 
1028
 
1028
 	/* Add client UUID, if we have one.  Required for PXE.  The
1029
 	/* Add client UUID, if we have one.  Required for PXE.  The
1039
 					    sizeof ( client_uuid ) ) ) != 0 ) {
1040
 					    sizeof ( client_uuid ) ) ) != 0 ) {
1040
 			DBG ( "DHCP could not set client UUID: %s\n",
1041
 			DBG ( "DHCP could not set client UUID: %s\n",
1041
 			      strerror ( rc ) );
1042
 			      strerror ( rc ) );
1042
-			return rc;
1043
+			goto err_store_client_uuid;
1043
 		}
1044
 		}
1044
 	}
1045
 	}
1045
 
1046
 
1046
 	/* Add user class, if we have one. */
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
 		if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_USER_CLASS_ID,
1050
 		if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_USER_CLASS_ID,
1052
-					    &user_class,
1053
-					    sizeof ( user_class ) ) ) != 0 ) {
1051
+					    user_class, len ) ) != 0 ) {
1054
 			DBG ( "DHCP could not set user class: %s\n",
1052
 			DBG ( "DHCP could not set user class: %s\n",
1055
 			      strerror ( rc ) );
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
 	int rc;
1389
 	int rc;
1385
 
1390
 
1386
 	/* Get upper bound for PXE boot server IP address list */
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
 	if ( pxebs_list_len < 0 )
1394
 	if ( pxebs_list_len < 0 )
1389
 		pxebs_list_len = 0;
1395
 		pxebs_list_len = 0;
1390
 
1396
 
1422
 	if ( pxebs_list_len ) {
1428
 	if ( pxebs_list_len ) {
1423
 		uint8_t buf[pxebs_list_len];
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
 		pxebs_list ( dhcp, buf, sizeof ( buf ), ip );
1433
 		pxebs_list ( dhcp, buf, sizeof ( buf ), ip );
1428
 	}
1434
 	}
1429
 	if ( ! dhcp->pxe_attempt->s_addr ) {
1435
 	if ( ! dhcp->pxe_attempt->s_addr ) {

+ 3
- 3
src/net/udp/dhcpv6.c View File

256
  */
256
  */
257
 
257
 
258
 /** DHCPv6 settings scope */
258
 /** DHCPv6 settings scope */
259
-static struct settings_scope dhcpv6_settings_scope;
259
+static const struct settings_scope dhcpv6_settings_scope;
260
 
260
 
261
 /** A DHCPv6 settings block */
261
 /** A DHCPv6 settings block */
262
 struct dhcpv6_settings {
262
 struct dhcpv6_settings {
276
  * @ret applies		Setting applies within this settings block
276
  * @ret applies		Setting applies within this settings block
277
  */
277
  */
278
 static int dhcpv6_applies ( struct settings *settings __unused,
278
 static int dhcpv6_applies ( struct settings *settings __unused,
279
-			    struct setting *setting ) {
279
+			    const struct setting *setting ) {
280
 
280
 
281
 	return ( setting->scope == &dhcpv6_settings_scope );
281
 	return ( setting->scope == &dhcpv6_settings_scope );
282
 }
282
 }
543
 	int actual_len;
543
 	int actual_len;
544
 
544
 
545
 	/* Fetch user-class setting, if defined */
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
 	if ( actual_len >= 0 )
547
 	if ( actual_len >= 0 )
548
 		return actual_len;
548
 		return actual_len;
549
 
549
 

+ 2
- 6
src/net/udp/dns.c View File

594
  */
594
  */
595
 
595
 
596
 /** DNS server setting */
596
 /** DNS server setting */
597
-struct setting dns_setting __setting ( SETTING_IPv4_EXTRA ) = {
597
+const struct setting dns_setting __setting ( SETTING_IPv4_EXTRA ) = {
598
 	.name = "dns",
598
 	.name = "dns",
599
 	.description = "DNS server",
599
 	.description = "DNS server",
600
 	.tag = DHCP_DNS_SERVERS,
600
 	.tag = DHCP_DNS_SERVERS,
622
 
622
 
623
 	/* Get local domain DHCP option */
623
 	/* Get local domain DHCP option */
624
 	free ( localdomain );
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
 	if ( localdomain )
626
 	if ( localdomain )
631
 		DBG ( "DNS local domain %s\n", localdomain );
627
 		DBG ( "DNS local domain %s\n", localdomain );
632
 
628
 

+ 3
- 11
src/net/udp/syslog.c View File

188
  */
188
  */
189
 
189
 
190
 /** Syslog server setting */
190
 /** Syslog server setting */
191
-struct setting syslog_setting __setting ( SETTING_MISC ) = {
191
+const struct setting syslog_setting __setting ( SETTING_MISC ) = {
192
 	.name = "syslog",
192
 	.name = "syslog",
193
 	.description = "Syslog server",
193
 	.description = "Syslog server",
194
 	.tag = DHCP_LOG_SERVERS,
194
 	.tag = DHCP_LOG_SERVERS,
209
 
209
 
210
 	/* Fetch hostname and domain name */
210
 	/* Fetch hostname and domain name */
211
 	free ( syslog_hostname );
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
 	free ( syslog_domain );
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
 	/* Fetch log server */
216
 	/* Fetch log server */
225
 	syslog_console.disabled = CONSOLE_DISABLED;
217
 	syslog_console.disabled = CONSOLE_DISABLED;

+ 2
- 10
src/net/validator.c View File

121
  */
121
  */
122
 
122
 
123
 /** Cross-signed certificate source setting */
123
 /** Cross-signed certificate source setting */
124
-struct setting crosscert_setting __setting ( SETTING_CRYPTO ) = {
124
+const struct setting crosscert_setting __setting ( SETTING_CRYPTO ) = {
125
 	.name = "crosscert",
125
 	.name = "crosscert",
126
 	.description = "Cross-signed certificate source",
126
 	.description = "Cross-signed certificate source",
127
 	.tag = DHCP_EB_CROSS_CERT,
127
 	.tag = DHCP_EB_CROSS_CERT,
232
 	int rc;
232
 	int rc;
233
 
233
 
234
 	/* Determine cross-signed certificate source */
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
 	crosscert = ( crosscert_copy ? crosscert_copy : crosscert_default );
236
 	crosscert = ( crosscert_copy ? crosscert_copy : crosscert_default );
244
 
237
 
245
 	/* Allocate URI string */
238
 	/* Allocate URI string */
279
 	free ( uri_string );
272
 	free ( uri_string );
280
  err_alloc_uri_string:
273
  err_alloc_uri_string:
281
 	free ( crosscert_copy );
274
 	free ( crosscert_copy );
282
- err_fetch_crosscert:
283
 	return rc;
275
 	return rc;
284
 }
276
 }
285
 
277
 

+ 54
- 53
src/tests/settings_test.c View File

38
 /**
38
 /**
39
  * Report a formatted-store test result
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
 	uint8_t actual[ sizeof ( expected ) ];				\
48
 	uint8_t actual[ sizeof ( expected ) ];				\
49
 	int len;							\
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
 			      sizeof ( actual ) );			\
53
 			      sizeof ( actual ) );			\
54
 	if ( len >= 0 ) {						\
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
 	} else {							\
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
 		       strerror ( len ) );				\
61
 		       strerror ( len ) );				\
62
 	}								\
62
 	}								\
63
 	ok ( len == ( int ) sizeof ( actual ) );			\
63
 	ok ( len == ( int ) sizeof ( actual ) );			\
67
 /**
67
 /**
68
  * Report a formatted-fetch test result
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
 	int len;							\
78
 	int len;							\
79
 									\
79
 									\
80
-	ok ( store_setting ( settings, setting, raw,			\
80
+	ok ( store_setting ( _settings, _setting, raw,			\
81
 			     sizeof ( raw ) ) == 0 );			\
81
 			     sizeof ( raw ) ) == 0 );			\
82
-	len = fetchf_setting ( settings, setting, actual,		\
82
+	len = fetchf_setting ( _settings, _setting, NULL, NULL, actual,	\
83
 			       sizeof ( actual ) );			\
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
 	ok ( len == ( int ) ( sizeof ( actual ) - 1 ) );		\
87
 	ok ( len == ( int ) ( sizeof ( actual ) - 1 ) );		\
88
-	ok ( strcmp ( actual, formatted ) == 0 );			\
88
+	ok ( strcmp ( actual, _formatted ) == 0 );			\
89
 	} while ( 0 )
89
 	} while ( 0 )
90
 
90
 
91
 /**
91
 /**
92
  * Report a numeric-store test result
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
 	uint8_t actual[ sizeof ( expected ) ];				\
101
 	uint8_t actual[ sizeof ( expected ) ];				\
102
 	int len;							\
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
 			      sizeof ( actual ) );			\
106
 			      sizeof ( actual ) );			\
107
 	if ( len >= 0 ) {						\
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
 	} else {							\
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
 	ok ( len == ( int ) sizeof ( actual ) );			\
117
 	ok ( len == ( int ) sizeof ( actual ) );			\
118
 	ok ( memcmp ( actual, expected, sizeof ( actual ) ) == 0 );	\
118
 	ok ( memcmp ( actual, expected, sizeof ( actual ) ) == 0 );	\
121
 /**
121
 /**
122
  * Report a numeric-fetch test result
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
 	unsigned long actual;						\
131
 	unsigned long actual;						\
132
 									\
132
 									\
133
-	ok ( store_setting ( settings, setting, raw,			\
133
+	ok ( store_setting ( _settings, _setting, raw,			\
134
 			     sizeof ( raw ) ) == 0 );			\
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
 	} while ( 0 )
141
 	} while ( 0 )
141
 
142
 
142
 /** Test generic settings block */
143
 /** Test generic settings block */

+ 24
- 21
src/usr/autoboot.c View File

59
 #define CYAN	"\033[36m"
59
 #define CYAN	"\033[36m"
60
 
60
 
61
 /** The "scriptlet" setting */
61
 /** The "scriptlet" setting */
62
-struct setting scriptlet_setting __setting ( SETTING_MISC ) = {
62
+const struct setting scriptlet_setting __setting ( SETTING_MISC ) = {
63
 	.name = "scriptlet",
63
 	.name = "scriptlet",
64
 	.description = "Boot scriptlet",
64
 	.description = "Boot scriptlet",
65
 	.tag = DHCP_EB_SCRIPTLET,
65
 	.tag = DHCP_EB_SCRIPTLET,
119
 }
119
 }
120
 
120
 
121
 /** The "keep-san" setting */
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
 	.name = "keep-san",
123
 	.name = "keep-san",
124
 	.description = "Preserve SAN connection",
124
 	.description = "Preserve SAN connection",
125
 	.tag = DHCP_EB_KEEP_SAN,
125
 	.tag = DHCP_EB_KEEP_SAN,
127
 };
127
 };
128
 
128
 
129
 /** The "skip-san-boot" setting */
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
 	.name = "skip-san-boot",
131
 	.name = "skip-san-boot",
132
 	.description = "Do not boot from SAN device",
132
 	.description = "Do not boot from SAN device",
133
 	.tag = DHCP_EB_SKIP_SAN_BOOT,
133
 	.tag = DHCP_EB_SKIP_SAN_BOOT,
256
 	struct uri *uri = NULL;
256
 	struct uri *uri = NULL;
257
 	char *filename;
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
 		fetch_ipv4_setting ( settings, &next_server_setting,
266
 		fetch_ipv4_setting ( settings, &next_server_setting,
265
 				     &next_server );
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
 	/* Expand filename setting */
270
 	/* Expand filename setting */
286
 	free ( filename );
285
 	free ( filename );
287
  err_expand:
286
  err_expand:
288
 	free ( raw_filename );
287
 	free ( raw_filename );
289
- err_fetch:
290
 	return uri;
288
 	return uri;
291
 }
289
 }
292
 
290
 
297
  * @ret uri		URI, or NULL on failure
295
  * @ret uri		URI, or NULL on failure
298
  */
296
  */
299
 static struct uri * fetch_root_path ( struct settings *settings ) {
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
 	char *root_path;
300
 	char *root_path;
302
-	struct uri *uri;
303
 
301
 
304
 	/* Fetch root-path setting */
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
 	/* Expand filename setting */
306
 	/* Expand filename setting */
311
-	root_path = expand_settings ( buf );
307
+	root_path = expand_settings ( raw_root_path ? raw_root_path : "" );
312
 	if ( ! root_path )
308
 	if ( ! root_path )
313
-		return NULL;
309
+		goto err_expand;
314
 
310
 
315
 	/* Parse root path */
311
 	/* Parse root path */
312
+	if ( root_path[0] )
313
+		printf ( "Root path: %s\n", root_path );
316
 	uri = parse_uri ( root_path );
314
 	uri = parse_uri ( root_path );
315
+	if ( ! uri )
316
+		goto err_parse;
317
 
317
 
318
+ err_parse:
318
 	free ( root_path );
319
 	free ( root_path );
320
+ err_expand:
321
+	free ( raw_root_path );
319
 	return uri;
322
 	return uri;
320
 }
323
 }
321
 
324
 
331
 		= { .tag = DHCP_PXE_DISCOVERY_CONTROL };
334
 		= { .tag = DHCP_PXE_DISCOVERY_CONTROL };
332
 	struct setting pxe_boot_menu_setting
335
 	struct setting pxe_boot_menu_setting
333
 		= { .tag = DHCP_PXE_BOOT_MENU };
336
 		= { .tag = DHCP_PXE_BOOT_MENU };
334
-	char buf[256];
337
+	char buf[ 10 /* "PXEClient" + NUL */ ];
335
 	unsigned int pxe_discovery_control;
338
 	unsigned int pxe_discovery_control;
336
 
339
 
337
 	fetch_string_setting ( NULL, &vendor_class_id_setting,
340
 	fetch_string_setting ( NULL, &vendor_class_id_setting,

+ 1
- 1
src/usr/nslookup.c View File

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

+ 8
- 7
src/usr/pxemenu.c View File

101
 
101
 
102
 	/* Fetch raw menu */
102
 	/* Fetch raw menu */
103
 	memset ( raw_menu, 0, sizeof ( raw_menu ) );
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
 		rc = raw_menu_len;
107
 		rc = raw_menu_len;
108
 		DBG ( "Could not retrieve raw PXE boot menu: %s\n",
108
 		DBG ( "Could not retrieve raw PXE boot menu: %s\n",
109
 		      strerror ( rc ) );
109
 		      strerror ( rc ) );
116
 	raw_menu_end = ( raw_menu + raw_menu_len );
116
 	raw_menu_end = ( raw_menu + raw_menu_len );
117
 
117
 
118
 	/* Fetch raw prompt length */
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
 	if ( raw_prompt_len < 0 )
122
 	if ( raw_prompt_len < 0 )
122
 		raw_prompt_len = 0;
123
 		raw_prompt_len = 0;
123
 
124
 
168
 	if ( raw_prompt_len ) {
169
 	if ( raw_prompt_len ) {
169
 		raw_menu_prompt = ( ( ( void * ) raw_menu_item ) +
170
 		raw_menu_prompt = ( ( ( void * ) raw_menu_item ) +
170
 				    1 /* NUL */ );
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
 		(*menu)->timeout =
174
 		(*menu)->timeout =
174
 			( ( raw_menu_prompt->timeout == 0xff ) ?
175
 			( ( raw_menu_prompt->timeout == 0xff ) ?
175
 			  -1 : raw_menu_prompt->timeout );
176
 			  -1 : raw_menu_prompt->timeout );

Loading…
Cancel
Save