浏览代码

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

tags/v0.9.4
Michael Brown 16 年前
父节点
当前提交
a462c96ffc
共有 4 个文件被更改,包括 29 次插入18 次删除
  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 查看文件

@@ -91,13 +91,11 @@ int simple_settings_store ( struct settings *settings, unsigned int tag,
91 91
 // Dummy routine just for testing
92 92
 int simple_settings_fetch ( struct settings *settings, unsigned int tag,
93 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 101
 /** Simple settings operations */
@@ -337,7 +335,7 @@ int fetch_setting ( struct settings *settings, unsigned int tag,
337 335
 
338 336
 	/* Recurse into each child block in turn */
339 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 339
 			return ret;
342 340
 	}
343 341
 

+ 15
- 5
src/net/dhcpopts.c 查看文件

@@ -180,26 +180,36 @@ static int resize_dhcp_option ( struct dhcp_options *options,
180 180
 	void *end;
181 181
 
182 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 185
 		return -ENOSPC;
186
+	}
185 187
 	new_options_len = ( options->len + delta );
186 188
 	if ( new_options_len > options->max_len ) {
187 189
 		/* Reallocate options block if allowed to do so. */
188 190
 		if ( can_realloc ) {
189 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 196
 				return -ENOMEM;
197
+			}
192 198
 			options->data = new_data;
193 199
 			options->max_len = new_options_len;
194 200
 		} else {
201
+			DBGC ( options, "DHCPOPT %p out of space\n", options );
195 202
 			return -ENOMEM;
196 203
 		}
197 204
 	}
198 205
 	if ( encap_offset >= 0 ) {
199 206
 		encapsulator = dhcp_option ( options, encap_offset );
200 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 211
 			return -ENOSPC;
212
+		}
203 213
 		encapsulator->len = new_encapsulator_len;
204 214
 	}
205 215
 	options->len = new_options_len;
@@ -253,7 +263,7 @@ static int set_dhcp_option ( struct dhcp_options *options, unsigned int tag,
253 263
 		       options, dhcp_tag_name ( tag ), old_len, new_len );
254 264
 	} else {
255 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 269
 	/* Ensure that encapsulator exists, if required */
@@ -353,7 +363,7 @@ int dhcpopt_fetch ( struct dhcp_options *options, unsigned int tag,
353 363
 		return offset;
354 364
 
355 365
 	option = dhcp_option ( options, offset );
356
-	option_len = dhcp_option_len ( option );
366
+	option_len = option->len;
357 367
 	if ( len > option_len )
358 368
 		len = option_len;
359 369
 	memcpy ( data, option->data, len );

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

@@ -1649,8 +1649,10 @@ static int apply_iscsi_string_setting ( struct iscsi_string_setting *setting ){
1649 1649
 	/* Allocate new string */
1650 1650
 	prefix_len = strlen ( setting->prefix );
1651 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 1656
 	len = ( prefix_len + setting_len + 1 );
1655 1657
 	p = *setting->string = malloc ( len );
1656 1658
 	if ( ! p )

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

@@ -175,7 +175,7 @@ static int create_dhcp_packet ( struct dhcp_packet *dhcppkt,
175 175
 	}
176 176
 	dhcphdr->hlen = hlen;
177 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 180
 	/* Initialise DHCP packet structure and settings interface */
181 181
 	dhcppkt_init ( dhcppkt, NULL, data, max_len );
@@ -258,9 +258,10 @@ int create_dhcp_request ( struct dhcp_packet *dhcppkt,
258 258
 			      "option: %s\n", strerror ( rc ) );
259 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 263
 					   offer_settings,
263
-					   DHCP_REQUESTED_ADDRESS ) ) != 0 ) {
264
+					   DHCP_EB_YIADDR ) ) != 0 ) {
264 265
 			DBG ( "DHCP could not set requested address "
265 266
 			      "option: %s\n", strerror ( rc ) );
266 267
 			return rc;

正在加载...
取消
保存