|  | @@ -21,6 +21,8 @@
 | 
		
	
		
			
			| 21 | 21 |  #include <string.h>
 | 
		
	
		
			
			| 22 | 22 |  #include <errno.h>
 | 
		
	
		
			
			| 23 | 23 |  #include <assert.h>
 | 
		
	
		
			
			|  | 24 | +#include <vsprintf.h>
 | 
		
	
		
			
			|  | 25 | +#include <gpxe/in.h>
 | 
		
	
		
			
			| 24 | 26 |  #include <gpxe/settings.h>
 | 
		
	
		
			
			| 25 | 27 |  
 | 
		
	
		
			
			| 26 | 28 |  /** @file
 | 
		
	
	
		
			
			|  | @@ -195,3 +197,57 @@ struct config_setting_type config_setting_type_string __config_setting_type = {
 | 
		
	
		
			
			| 195 | 197 |  	.show = show_string,
 | 
		
	
		
			
			| 196 | 198 |  	.set = set_string,
 | 
		
	
		
			
			| 197 | 199 |  };
 | 
		
	
		
			
			|  | 200 | +
 | 
		
	
		
			
			|  | 201 | +/**
 | 
		
	
		
			
			|  | 202 | + * Show value of IPv4 setting
 | 
		
	
		
			
			|  | 203 | + *
 | 
		
	
		
			
			|  | 204 | + * @v context		Configuration context
 | 
		
	
		
			
			|  | 205 | + * @v setting		Configuration setting
 | 
		
	
		
			
			|  | 206 | + * @v buf		Buffer to contain value
 | 
		
	
		
			
			|  | 207 | + * @v len		Length of buffer
 | 
		
	
		
			
			|  | 208 | + * @ret rc		Return status code
 | 
		
	
		
			
			|  | 209 | + */
 | 
		
	
		
			
			|  | 210 | +static int show_ipv4 ( struct config_context *context,
 | 
		
	
		
			
			|  | 211 | +		       struct config_setting *setting,
 | 
		
	
		
			
			|  | 212 | +		       char *buf, size_t len ) {
 | 
		
	
		
			
			|  | 213 | +	struct dhcp_option *option;
 | 
		
	
		
			
			|  | 214 | +	struct in_addr ipv4;
 | 
		
	
		
			
			|  | 215 | +
 | 
		
	
		
			
			|  | 216 | +	option = find_dhcp_option ( context->options, setting->tag );
 | 
		
	
		
			
			|  | 217 | +	if ( ! option )
 | 
		
	
		
			
			|  | 218 | +		return -ENOENT;
 | 
		
	
		
			
			|  | 219 | +	dhcp_ipv4_option ( option, &ipv4 );
 | 
		
	
		
			
			|  | 220 | +	snprintf ( buf, len, inet_ntoa ( ipv4 ) );
 | 
		
	
		
			
			|  | 221 | +	return 0;
 | 
		
	
		
			
			|  | 222 | +}
 | 
		
	
		
			
			|  | 223 | +
 | 
		
	
		
			
			|  | 224 | +/** Set value of IPV4 setting
 | 
		
	
		
			
			|  | 225 | + *
 | 
		
	
		
			
			|  | 226 | + * @v context		Configuration context
 | 
		
	
		
			
			|  | 227 | + * @v setting		Configuration setting
 | 
		
	
		
			
			|  | 228 | + * @v value		Setting value (as a string)
 | 
		
	
		
			
			|  | 229 | + * @ret rc		Return status code
 | 
		
	
		
			
			|  | 230 | + */ 
 | 
		
	
		
			
			|  | 231 | +static int set_ipv4 ( struct config_context *context,
 | 
		
	
		
			
			|  | 232 | +		      struct config_setting *setting,
 | 
		
	
		
			
			|  | 233 | +		      const char *value ) {
 | 
		
	
		
			
			|  | 234 | +	struct dhcp_option *option;
 | 
		
	
		
			
			|  | 235 | +	struct in_addr ipv4;
 | 
		
	
		
			
			|  | 236 | +	int rc;
 | 
		
	
		
			
			|  | 237 | +	
 | 
		
	
		
			
			|  | 238 | +	if ( ( rc = inet_aton ( value, &ipv4 ) ) != 0 )
 | 
		
	
		
			
			|  | 239 | +		return rc;
 | 
		
	
		
			
			|  | 240 | +	option = set_dhcp_option ( context->options, setting->tag,
 | 
		
	
		
			
			|  | 241 | +				   &ipv4, sizeof ( ipv4 ) );
 | 
		
	
		
			
			|  | 242 | +	if ( ! option )
 | 
		
	
		
			
			|  | 243 | +		return -ENOMEM;
 | 
		
	
		
			
			|  | 244 | +	return 0;
 | 
		
	
		
			
			|  | 245 | +}
 | 
		
	
		
			
			|  | 246 | +
 | 
		
	
		
			
			|  | 247 | +/** An IPv4 configuration setting */
 | 
		
	
		
			
			|  | 248 | +struct config_setting_type config_setting_type_ipv4 __config_setting_type = {
 | 
		
	
		
			
			|  | 249 | +	.name = "ipv4",
 | 
		
	
		
			
			|  | 250 | +	.show = show_ipv4,
 | 
		
	
		
			
			|  | 251 | +	.set = set_ipv4,
 | 
		
	
		
			
			|  | 252 | +};
 | 
		
	
		
			
			|  | 253 | +
 |