Browse Source

[Settings] DHCP is now working using the new settings API.

tags/v0.9.4
Michael Brown 17 years ago
parent
commit
a462c96ffc
4 changed files with 29 additions and 18 deletions
  1. 6
    8
      src/core/settings.c
  2. 15
    5
      src/net/dhcpopts.c
  3. 4
    2
      src/net/tcp/iscsi.c
  4. 4
    3
      src/net/udp/dhcp.c

+ 6
- 8
src/core/settings.c View File

91
 // Dummy routine just for testing
91
 // Dummy routine just for testing
92
 int simple_settings_fetch ( struct settings *settings, unsigned int tag,
92
 int simple_settings_fetch ( struct settings *settings, unsigned int tag,
93
 			    void *data, size_t len ) {
93
 			    void *data, size_t len ) {
94
-	unsigned int i;
95
-
96
-	DBGC ( settings, "Settings %p: fetch %s\n",
97
-	       settings, setting_tag_name ( tag ) );
98
-	for ( i = 0 ; i < len ; i++ )
99
-		*( ( ( uint8_t * ) data ) + i ) = i;
100
-	return ( len ? len : 8 );
94
+	( void ) settings;
95
+	( void ) tag;
96
+	( void ) data;
97
+	( void ) len;
98
+	return -ENOENT;
101
 }
99
 }
102
 
100
 
103
 /** Simple settings operations */
101
 /** Simple settings operations */
337
 
335
 
338
 	/* Recurse into each child block in turn */
336
 	/* Recurse into each child block in turn */
339
 	list_for_each_entry ( child, &settings->children, siblings ) {
337
 	list_for_each_entry ( child, &settings->children, siblings ) {
340
-		if ( ( ret = fetch_setting ( settings, tag, data, len ) ) >= 0)
338
+		if ( ( ret = fetch_setting ( child, tag, data, len ) ) >= 0)
341
 			return ret;
339
 			return ret;
342
 	}
340
 	}
343
 
341
 

+ 15
- 5
src/net/dhcpopts.c View File

180
 	void *end;
180
 	void *end;
181
 
181
 
182
 	/* Check for sufficient space, and update length fields */
182
 	/* Check for sufficient space, and update length fields */
183
-	if ( new_len > DHCP_MAX_LEN )
183
+	if ( new_len > DHCP_MAX_LEN ) {
184
+		DBGC ( options, "DHCPOPT %p overlength option\n", options );
184
 		return -ENOSPC;
185
 		return -ENOSPC;
186
+	}
185
 	new_options_len = ( options->len + delta );
187
 	new_options_len = ( options->len + delta );
186
 	if ( new_options_len > options->max_len ) {
188
 	if ( new_options_len > options->max_len ) {
187
 		/* Reallocate options block if allowed to do so. */
189
 		/* Reallocate options block if allowed to do so. */
188
 		if ( can_realloc ) {
190
 		if ( can_realloc ) {
189
 			new_data = realloc ( options->data, new_options_len );
191
 			new_data = realloc ( options->data, new_options_len );
190
-			if ( ! new_data )
192
+			if ( ! new_data ) {
193
+				DBGC ( options, "DHCPOPT %p could not "
194
+				       "reallocate to %zd bytes\n", options,
195
+				       new_options_len );
191
 				return -ENOMEM;
196
 				return -ENOMEM;
197
+			}
192
 			options->data = new_data;
198
 			options->data = new_data;
193
 			options->max_len = new_options_len;
199
 			options->max_len = new_options_len;
194
 		} else {
200
 		} else {
201
+			DBGC ( options, "DHCPOPT %p out of space\n", options );
195
 			return -ENOMEM;
202
 			return -ENOMEM;
196
 		}
203
 		}
197
 	}
204
 	}
198
 	if ( encap_offset >= 0 ) {
205
 	if ( encap_offset >= 0 ) {
199
 		encapsulator = dhcp_option ( options, encap_offset );
206
 		encapsulator = dhcp_option ( options, encap_offset );
200
 		new_encapsulator_len = ( encapsulator->len + delta );
207
 		new_encapsulator_len = ( encapsulator->len + delta );
201
-		if ( new_encapsulator_len > DHCP_MAX_LEN )
208
+		if ( new_encapsulator_len > DHCP_MAX_LEN ) {
209
+			DBGC ( options, "DHCPOPT %p overlength encapsulator\n",
210
+			       options );
202
 			return -ENOSPC;
211
 			return -ENOSPC;
212
+		}
203
 		encapsulator->len = new_encapsulator_len;
213
 		encapsulator->len = new_encapsulator_len;
204
 	}
214
 	}
205
 	options->len = new_options_len;
215
 	options->len = new_options_len;
253
 		       options, dhcp_tag_name ( tag ), old_len, new_len );
263
 		       options, dhcp_tag_name ( tag ), old_len, new_len );
254
 	} else {
264
 	} else {
255
 		DBGC ( options, "DHCPOPT %p creating %s (length %zd)\n",
265
 		DBGC ( options, "DHCPOPT %p creating %s (length %zd)\n",
256
-		       options, dhcp_tag_name ( tag ), len );
266
+		       options, dhcp_tag_name ( tag ), new_len );
257
 	}
267
 	}
258
 
268
 
259
 	/* Ensure that encapsulator exists, if required */
269
 	/* Ensure that encapsulator exists, if required */
353
 		return offset;
363
 		return offset;
354
 
364
 
355
 	option = dhcp_option ( options, offset );
365
 	option = dhcp_option ( options, offset );
356
-	option_len = dhcp_option_len ( option );
366
+	option_len = option->len;
357
 	if ( len > option_len )
367
 	if ( len > option_len )
358
 		len = option_len;
368
 		len = option_len;
359
 	memcpy ( data, option->data, len );
369
 	memcpy ( data, option->data, len );

+ 4
- 2
src/net/tcp/iscsi.c View File

1649
 	/* Allocate new string */
1649
 	/* Allocate new string */
1650
 	prefix_len = strlen ( setting->prefix );
1650
 	prefix_len = strlen ( setting->prefix );
1651
 	setting_len = fetch_setting_len ( NULL, setting->tag );
1651
 	setting_len = fetch_setting_len ( NULL, setting->tag );
1652
-	if ( setting_len < 0 )
1653
-		return setting_len;
1652
+	if ( setting_len < 0 ) {
1653
+		/* Missing settings are not errors; leave strings as NULL */
1654
+		return 0;
1655
+	}
1654
 	len = ( prefix_len + setting_len + 1 );
1656
 	len = ( prefix_len + setting_len + 1 );
1655
 	p = *setting->string = malloc ( len );
1657
 	p = *setting->string = malloc ( len );
1656
 	if ( ! p )
1658
 	if ( ! p )

+ 4
- 3
src/net/udp/dhcp.c View File

175
 	}
175
 	}
176
 	dhcphdr->hlen = hlen;
176
 	dhcphdr->hlen = hlen;
177
 	memcpy ( dhcphdr->chaddr, netdev->ll_addr, hlen );
177
 	memcpy ( dhcphdr->chaddr, netdev->ll_addr, hlen );
178
-	memcpy ( dhcphdr->options, options, options_len );
178
+	memcpy ( dhcphdr->options, options->data, options_len );
179
 
179
 
180
 	/* Initialise DHCP packet structure and settings interface */
180
 	/* Initialise DHCP packet structure and settings interface */
181
 	dhcppkt_init ( dhcppkt, NULL, data, max_len );
181
 	dhcppkt_init ( dhcppkt, NULL, data, max_len );
258
 			      "option: %s\n", strerror ( rc ) );
258
 			      "option: %s\n", strerror ( rc ) );
259
 			return rc;
259
 			return rc;
260
 		}
260
 		}
261
-		if ( ( rc = copy_setting ( &dhcppkt->settings, DHCP_EB_YIADDR,
261
+		if ( ( rc = copy_setting ( &dhcppkt->settings,
262
+					   DHCP_REQUESTED_ADDRESS,
262
 					   offer_settings,
263
 					   offer_settings,
263
-					   DHCP_REQUESTED_ADDRESS ) ) != 0 ) {
264
+					   DHCP_EB_YIADDR ) ) != 0 ) {
264
 			DBG ( "DHCP could not set requested address "
265
 			DBG ( "DHCP could not set requested address "
265
 			      "option: %s\n", strerror ( rc ) );
266
 			      "option: %s\n", strerror ( rc ) );
266
 			return rc;
267
 			return rc;

Loading…
Cancel
Save