Browse Source

[Settings] Use a settings applicator in ibft.c

tags/v0.9.4
Michael Brown 17 years ago
parent
commit
a9b62cfe8c
1 changed files with 46 additions and 31 deletions
  1. 46
    31
      src/core/ibft.c

+ 46
- 31
src/core/ibft.c View File

130
  */
130
  */
131
 static void ibft_set_ipaddr_option ( struct ibft_ipaddr *ipaddr,
131
 static void ibft_set_ipaddr_option ( struct ibft_ipaddr *ipaddr,
132
 				     unsigned int tag ) {
132
 				     unsigned int tag ) {
133
-	struct in_addr in;
133
+	struct in_addr in = { 0 };
134
-	find_global_dhcp_ipv4_option ( tag, &in );
134
+	fetch_ipv4_setting ( NULL, tag, &in );
135
 	ibft_set_ipaddr ( ipaddr, in );
135
 	ibft_set_ipaddr ( ipaddr, in );
136
 }
136
 }
137
 
137
 
138
 /**
138
 /**
139
- * Fill in a string field within iBFT
139
+ * Allocate a string within iBFT
140
  *
140
  *
141
  * @v strings		iBFT string block descriptor
141
  * @v strings		iBFT string block descriptor
142
- * @v string		String field
142
+ * @v string		String field to fill in
143
- * @v data		String to fill in
143
+ * @v len		Length of string to allocate (excluding NUL)
144
- * @v len		Length of string to fill in
145
  * @ret rc		Return status code
144
  * @ret rc		Return status code
146
  */
145
  */
147
-static int ibft_set_string ( struct ibft_string_block *strings,
146
+static int ibft_alloc_string ( struct ibft_string_block *strings,
148
-			     struct ibft_string *string,
147
+			       struct ibft_string *string, size_t len ) {
149
-			     const void *data, size_t len ) {
150
 	char *dest;
148
 	char *dest;
151
-	char *end;
152
 	unsigned int remaining;
149
 	unsigned int remaining;
153
 
150
 
154
 	dest = ( ( ( char * ) strings->table ) + strings->offset );
151
 	dest = ( ( ( char * ) strings->table ) + strings->offset );
155
-	end = ( ( ( char * ) strings->table ) + strings->table->acpi.length );
152
+	remaining = ( strings->table->acpi.length - strings->offset );
156
-	remaining = ( end - dest );
157
-
158
 	if ( len >= remaining )
153
 	if ( len >= remaining )
159
 		return -ENOMEM;
154
 		return -ENOMEM;
160
 
155
 
161
-	memcpy ( dest, data, len );
162
-	dest[len] = '\0';
163
-
164
 	string->offset = strings->offset;
156
 	string->offset = strings->offset;
165
 	string->length = len;
157
 	string->length = len;
166
 	strings->offset += ( len + 1 );
158
 	strings->offset += ( len + 1 );
167
 	return 0;
159
 	return 0;
168
 }
160
 }
169
 
161
 
162
+/**
163
+ * Fill in a string field within iBFT
164
+ *
165
+ * @v strings		iBFT string block descriptor
166
+ * @v string		String field
167
+ * @v data		String to fill in
168
+ * @ret rc		Return status code
169
+ */
170
+static int ibft_set_string ( struct ibft_string_block *strings,
171
+			     struct ibft_string *string, const char *data ) {
172
+	size_t len = strlen ( data );
173
+	char *dest;
174
+	int rc;
175
+
176
+	if ( ( rc = ibft_alloc_string ( strings, string, len ) ) != 0 )
177
+		return rc;
178
+	dest = ( ( ( char * ) strings->table ) + string->offset );
179
+	strcpy ( dest, data );
180
+
181
+	return 0;
182
+}
183
+
170
 /**
184
 /**
171
  * Fill in a string field within iBFT from DHCP option
185
  * Fill in a string field within iBFT from DHCP option
172
  *
186
  *
178
 static int ibft_set_string_option ( struct ibft_string_block *strings,
192
 static int ibft_set_string_option ( struct ibft_string_block *strings,
179
 				    struct ibft_string *string,
193
 				    struct ibft_string *string,
180
 				    unsigned int tag ) {
194
 				    unsigned int tag ) {
181
-	struct dhcp_option *option;
195
+	int len;
196
+	char *dest;
197
+	int rc;
182
 
198
 
183
-	option = find_global_dhcp_option ( tag );
199
+	len = fetch_setting_len ( NULL, tag );
184
-	if ( ! option ) {
200
+	if ( len < 0 ) {
185
 		string->offset = 0;
201
 		string->offset = 0;
186
 		string->length = 0;
202
 		string->length = 0;
187
 		return 0;
203
 		return 0;
188
 	}
204
 	}
189
 
205
 
190
-	return ibft_set_string ( strings, string, option->data.string,
206
+	if ( ( rc = ibft_alloc_string ( strings, string, len ) ) != 0 )
191
-				 option->len );
207
+		return rc;
208
+	dest = ( ( ( char * ) strings->table ) + string->offset );
209
+	fetch_string_setting ( NULL, tag, dest, ( len + 1 ) );
210
+	return 0;
192
 }
211
 }
193
 
212
 
194
 /**
213
 /**
202
 static int ibft_fill_nic ( struct ibft_nic *nic,
221
 static int ibft_fill_nic ( struct ibft_nic *nic,
203
 			   struct ibft_string_block *strings,
222
 			   struct ibft_string_block *strings,
204
 			   struct net_device *netdev ) {
223
 			   struct net_device *netdev ) {
205
-	struct in_addr netmask_addr;
224
+	struct in_addr netmask_addr = { 0 };
206
 	unsigned int netmask_count = 0;
225
 	unsigned int netmask_count = 0;
207
 	int rc;
226
 	int rc;
208
 
227
 
215
 		return rc;
234
 		return rc;
216
 
235
 
217
 	/* Derive subnet mask prefix from subnet mask */
236
 	/* Derive subnet mask prefix from subnet mask */
218
-	find_global_dhcp_ipv4_option ( DHCP_SUBNET_MASK, &netmask_addr );
237
+	fetch_ipv4_setting ( NULL, DHCP_SUBNET_MASK, &netmask_addr );
219
 	while ( netmask_addr.s_addr ) {
238
 	while ( netmask_addr.s_addr ) {
220
 		if ( netmask_addr.s_addr & 0x1 )
239
 		if ( netmask_addr.s_addr & 0x1 )
221
 			netmask_count++;
240
 			netmask_count++;
244
 	int rc;
263
 	int rc;
245
 
264
 
246
 	if ( ( rc = ibft_set_string ( strings, &initiator->initiator_name,
265
 	if ( ( rc = ibft_set_string ( strings, &initiator->initiator_name,
247
-				      initiator_iqn,
266
+				      initiator_iqn ) ) != 0 )
248
-				      strlen ( initiator_iqn ) ) ) != 0)
249
 		return rc;
267
 		return rc;
250
 
268
 
251
 	return 0;
269
 	return 0;
270
 	ibft_set_ipaddr ( &target->ip_address, sin_target->sin_addr );
288
 	ibft_set_ipaddr ( &target->ip_address, sin_target->sin_addr );
271
 	target->socket = ntohs ( sin_target->sin_port );
289
 	target->socket = ntohs ( sin_target->sin_port );
272
 	if ( ( rc = ibft_set_string ( strings, &target->target_name,
290
 	if ( ( rc = ibft_set_string ( strings, &target->target_name,
273
-				      iscsi->target_iqn,
291
+				      iscsi->target_iqn ) ) != 0 )
274
-				      strlen ( iscsi->target_iqn ) ) ) != 0 )
275
 		return rc;
292
 		return rc;
276
 	if ( iscsi->username ) {
293
 	if ( iscsi->username ) {
277
 		if ( ( rc = ibft_set_string ( strings, &target->chap_name,
294
 		if ( ( rc = ibft_set_string ( strings, &target->chap_name,
278
-					      iscsi->username,
295
+					      iscsi->username ) ) != 0 )
279
-					      strlen ( iscsi->username ) ))!=0)
280
 			return rc;
296
 			return rc;
281
 	}
297
 	}
282
 	if ( iscsi->password ) {
298
 	if ( iscsi->password ) {
283
 		if ( ( rc = ibft_set_string ( strings, &target->chap_secret,
299
 		if ( ( rc = ibft_set_string ( strings, &target->chap_secret,
284
-					      iscsi->password,
300
+					      iscsi->password ) ) != 0 )
285
-					      strlen ( iscsi->password ) ))!=0)
286
 			return rc;
301
 			return rc;
287
 		target->chap_type = IBFT_CHAP_ONE_WAY;
302
 		target->chap_type = IBFT_CHAP_ONE_WAY;
288
 	}
303
 	}

Loading…
Cancel
Save