mirror of https://github.com/ipxe/ipxe.git
[settings] Allow for IPv6 setting types in non-IPv6 builds
Allow for the existence of references to IPv6 setting types without dragging in the whole IPv6 stack, by placing the definition of setting_type_ipv6 in core/settings.c and providing weak stub methods for parse_ipv6_setting() and format_ipv6_setting(). Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/17/head
parent
22001cb206
commit
17451b53e2
|
@ -28,6 +28,8 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <ipxe/in.h>
|
#include <ipxe/in.h>
|
||||||
|
#include <ipxe/ip.h>
|
||||||
|
#include <ipxe/ipv6.h>
|
||||||
#include <ipxe/vsprintf.h>
|
#include <ipxe/vsprintf.h>
|
||||||
#include <ipxe/dhcp.h>
|
#include <ipxe/dhcp.h>
|
||||||
#include <ipxe/uuid.h>
|
#include <ipxe/uuid.h>
|
||||||
|
@ -1648,7 +1650,7 @@ const struct setting_type setting_type_uristring __setting_type = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse IPv4 address setting value
|
* Parse IPv4 address setting value (when IPv4 support is not present)
|
||||||
*
|
*
|
||||||
* @v type Setting type
|
* @v type Setting type
|
||||||
* @v value Formatted setting value
|
* @v value Formatted setting value
|
||||||
|
@ -1656,24 +1658,14 @@ const struct setting_type setting_type_uristring __setting_type = {
|
||||||
* @v len Length of buffer
|
* @v len Length of buffer
|
||||||
* @ret len Length of raw value, or negative error
|
* @ret len Length of raw value, or negative error
|
||||||
*/
|
*/
|
||||||
static int parse_ipv4_setting ( const struct setting_type *type __unused,
|
__weak int parse_ipv4_setting ( const struct setting_type *type __unused,
|
||||||
const char *value, void *buf, size_t len ) {
|
const char *value __unused, void *buf __unused,
|
||||||
struct in_addr ipv4;
|
size_t len __unused ) {
|
||||||
|
return -ENOTSUP;
|
||||||
/* Parse IPv4 address */
|
|
||||||
if ( inet_aton ( value, &ipv4 ) == 0 )
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
/* Copy to buffer */
|
|
||||||
if ( len > sizeof ( ipv4 ) )
|
|
||||||
len = sizeof ( ipv4 );
|
|
||||||
memcpy ( buf, &ipv4, len );
|
|
||||||
|
|
||||||
return ( sizeof ( ipv4 ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format IPv4 address setting value
|
* Format IPv4 address setting value (when IPv4 support is not present)
|
||||||
*
|
*
|
||||||
* @v type Setting type
|
* @v type Setting type
|
||||||
* @v raw Raw setting value
|
* @v raw Raw setting value
|
||||||
|
@ -1682,14 +1674,11 @@ static int parse_ipv4_setting ( const struct setting_type *type __unused,
|
||||||
* @v len Length of buffer
|
* @v len Length of buffer
|
||||||
* @ret len Length of formatted value, or negative error
|
* @ret len Length of formatted value, or negative error
|
||||||
*/
|
*/
|
||||||
static int format_ipv4_setting ( const struct setting_type *type __unused,
|
__weak int format_ipv4_setting ( const struct setting_type *type __unused,
|
||||||
const void *raw, size_t raw_len, char *buf,
|
const void *raw __unused,
|
||||||
size_t len ) {
|
size_t raw_len __unused, char *buf __unused,
|
||||||
const struct in_addr *ipv4 = raw;
|
size_t len __unused ) {
|
||||||
|
return -ENOTSUP;
|
||||||
if ( raw_len < sizeof ( *ipv4 ) )
|
|
||||||
return -EINVAL;
|
|
||||||
return snprintf ( buf, len, "%s", inet_ntoa ( *ipv4 ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** An IPv4 address setting type */
|
/** An IPv4 address setting type */
|
||||||
|
@ -1699,6 +1688,48 @@ const struct setting_type setting_type_ipv4 __setting_type = {
|
||||||
.format = format_ipv4_setting,
|
.format = format_ipv4_setting,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse IPv6 address setting value (when IPv6 support is not present)
|
||||||
|
*
|
||||||
|
* @v type Setting type
|
||||||
|
* @v value Formatted setting value
|
||||||
|
* @v buf Buffer to contain raw value
|
||||||
|
* @v len Length of buffer
|
||||||
|
* @ret len Length of raw value, or negative error
|
||||||
|
*/
|
||||||
|
__weak int parse_ipv6_setting ( const struct setting_type *type __unused,
|
||||||
|
const char *value __unused, void *buf __unused,
|
||||||
|
size_t len __unused ) {
|
||||||
|
return -ENOTSUP;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format IPv6 address setting value (when IPv6 support is not present)
|
||||||
|
*
|
||||||
|
* @v type Setting type
|
||||||
|
* @v raw Raw setting value
|
||||||
|
* @v raw_len Length of raw setting value
|
||||||
|
* @v buf Buffer to contain formatted value
|
||||||
|
* @v len Length of buffer
|
||||||
|
* @ret len Length of formatted value, or negative error
|
||||||
|
*/
|
||||||
|
__weak int format_ipv6_setting ( const struct setting_type *type __unused,
|
||||||
|
const void *raw __unused,
|
||||||
|
size_t raw_len __unused, char *buf __unused,
|
||||||
|
size_t len __unused ) {
|
||||||
|
return -ENOTSUP;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** An IPv6 address setting type */
|
||||||
|
const struct setting_type setting_type_ipv6 __setting_type = {
|
||||||
|
.name = "ipv6",
|
||||||
|
.parse = parse_ipv6_setting,
|
||||||
|
.format = format_ipv6_setting,
|
||||||
|
};
|
||||||
|
|
||||||
|
/** IPv6 settings scope */
|
||||||
|
const struct settings_scope ipv6_scope;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integer setting type indices
|
* Integer setting type indices
|
||||||
*
|
*
|
||||||
|
|
|
@ -75,5 +75,10 @@ extern struct list_head ipv4_miniroutes;
|
||||||
extern struct net_protocol ipv4_protocol __net_protocol;
|
extern struct net_protocol ipv4_protocol __net_protocol;
|
||||||
|
|
||||||
extern int ipv4_has_any_addr ( struct net_device *netdev );
|
extern int ipv4_has_any_addr ( struct net_device *netdev );
|
||||||
|
extern int parse_ipv4_setting ( const struct setting_type *type,
|
||||||
|
const char *value, void *buf, size_t len );
|
||||||
|
extern int format_ipv4_setting ( const struct setting_type *type,
|
||||||
|
const void *raw, size_t raw_len, char *buf,
|
||||||
|
size_t len );
|
||||||
|
|
||||||
#endif /* _IPXE_IP_H */
|
#endif /* _IPXE_IP_H */
|
||||||
|
|
|
@ -247,5 +247,10 @@ extern int ipv6_set_prefix ( struct net_device *netdev, struct in6_addr *prefix,
|
||||||
unsigned int prefix_len, struct in6_addr *router );
|
unsigned int prefix_len, struct in6_addr *router );
|
||||||
extern int ipv6_set_address ( struct net_device *netdev,
|
extern int ipv6_set_address ( struct net_device *netdev,
|
||||||
struct in6_addr *address );
|
struct in6_addr *address );
|
||||||
|
extern int parse_ipv6_setting ( const struct setting_type *type,
|
||||||
|
const char *value, void *buf, size_t len );
|
||||||
|
extern int format_ipv6_setting ( const struct setting_type *type,
|
||||||
|
const void *raw, size_t raw_len, char *buf,
|
||||||
|
size_t len );
|
||||||
|
|
||||||
#endif /* _IPXE_IPV6_H */
|
#endif /* _IPXE_IPV6_H */
|
||||||
|
|
|
@ -62,16 +62,18 @@ struct setting {
|
||||||
#define SETTING_NETDEV_EXTRA 02 /**< Network device additional settings */
|
#define SETTING_NETDEV_EXTRA 02 /**< Network device additional settings */
|
||||||
#define SETTING_IPv4 03 /**< IPv4 settings */
|
#define SETTING_IPv4 03 /**< IPv4 settings */
|
||||||
#define SETTING_IPv4_EXTRA 04 /**< IPv4 additional settings */
|
#define SETTING_IPv4_EXTRA 04 /**< IPv4 additional settings */
|
||||||
#define SETTING_BOOT 05 /**< Generic boot settings */
|
#define SETTING_IPv6 05 /**< IPv6 settings */
|
||||||
#define SETTING_BOOT_EXTRA 06 /**< Generic boot additional settings */
|
#define SETTING_IPv6_EXTRA 06 /**< IPv6 additional settings */
|
||||||
#define SETTING_SANBOOT 07 /**< SAN boot settings */
|
#define SETTING_BOOT 07 /**< Generic boot settings */
|
||||||
#define SETTING_SANBOOT_EXTRA 08 /**< SAN boot additional settings */
|
#define SETTING_BOOT_EXTRA 08 /**< Generic boot additional settings */
|
||||||
#define SETTING_HOST 09 /**< Host identity settings */
|
#define SETTING_SANBOOT 09 /**< SAN boot settings */
|
||||||
#define SETTING_HOST_EXTRA 10 /**< Host identity additional settings */
|
#define SETTING_SANBOOT_EXTRA 10 /**< SAN boot additional settings */
|
||||||
#define SETTING_AUTH 11 /**< Authentication settings */
|
#define SETTING_HOST 11 /**< Host identity settings */
|
||||||
#define SETTING_AUTH_EXTRA 12 /**< Authentication additional settings */
|
#define SETTING_HOST_EXTRA 12 /**< Host identity additional settings */
|
||||||
#define SETTING_CRYPTO 13 /**< Cryptography settings */
|
#define SETTING_AUTH 13 /**< Authentication settings */
|
||||||
#define SETTING_MISC 14 /**< Miscellaneous settings */
|
#define SETTING_AUTH_EXTRA 14 /**< Authentication additional settings */
|
||||||
|
#define SETTING_CRYPTO 15 /**< Cryptography settings */
|
||||||
|
#define SETTING_MISC 16 /**< Miscellaneous settings */
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
@ -277,6 +279,9 @@ struct builtin_setting {
|
||||||
/** Built-in setting scope */
|
/** Built-in setting scope */
|
||||||
extern const struct settings_scope builtin_scope;
|
extern const struct settings_scope builtin_scope;
|
||||||
|
|
||||||
|
/** IPv6 setting scope */
|
||||||
|
extern const struct settings_scope ipv6_scope;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A generic settings block
|
* A generic settings block
|
||||||
*
|
*
|
||||||
|
|
|
@ -590,6 +590,51 @@ struct sockaddr_converter ipv4_sockaddr_converter __sockaddr_converter = {
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse IPv4 address setting value
|
||||||
|
*
|
||||||
|
* @v type Setting type
|
||||||
|
* @v value Formatted setting value
|
||||||
|
* @v buf Buffer to contain raw value
|
||||||
|
* @v len Length of buffer
|
||||||
|
* @ret len Length of raw value, or negative error
|
||||||
|
*/
|
||||||
|
int parse_ipv4_setting ( const struct setting_type *type __unused,
|
||||||
|
const char *value, void *buf, size_t len ) {
|
||||||
|
struct in_addr ipv4;
|
||||||
|
|
||||||
|
/* Parse IPv4 address */
|
||||||
|
if ( inet_aton ( value, &ipv4 ) == 0 )
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
/* Copy to buffer */
|
||||||
|
if ( len > sizeof ( ipv4 ) )
|
||||||
|
len = sizeof ( ipv4 );
|
||||||
|
memcpy ( buf, &ipv4, len );
|
||||||
|
|
||||||
|
return ( sizeof ( ipv4 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format IPv4 address setting value
|
||||||
|
*
|
||||||
|
* @v type Setting type
|
||||||
|
* @v raw Raw setting value
|
||||||
|
* @v raw_len Length of raw setting value
|
||||||
|
* @v buf Buffer to contain formatted value
|
||||||
|
* @v len Length of buffer
|
||||||
|
* @ret len Length of formatted value, or negative error
|
||||||
|
*/
|
||||||
|
int format_ipv4_setting ( const struct setting_type *type __unused,
|
||||||
|
const void *raw, size_t raw_len, char *buf,
|
||||||
|
size_t len ) {
|
||||||
|
const struct in_addr *ipv4 = raw;
|
||||||
|
|
||||||
|
if ( raw_len < sizeof ( *ipv4 ) )
|
||||||
|
return -EINVAL;
|
||||||
|
return snprintf ( buf, len, "%s", inet_ntoa ( *ipv4 ) );
|
||||||
|
}
|
||||||
|
|
||||||
/** IPv4 address setting */
|
/** IPv4 address setting */
|
||||||
const struct setting ip_setting __setting ( SETTING_IPv4 ) = {
|
const struct setting ip_setting __setting ( SETTING_IPv4 ) = {
|
||||||
.name = "ip",
|
.name = "ip",
|
||||||
|
|
|
@ -954,7 +954,7 @@ struct sockaddr_converter ipv6_sockaddr_converter __sockaddr_converter = {
|
||||||
* @v len Length of buffer
|
* @v len Length of buffer
|
||||||
* @ret len Length of raw value, or negative error
|
* @ret len Length of raw value, or negative error
|
||||||
*/
|
*/
|
||||||
static int parse_ipv6_setting ( const struct setting_type *type __unused,
|
int parse_ipv6_setting ( const struct setting_type *type __unused,
|
||||||
const char *value, void *buf, size_t len ) {
|
const char *value, void *buf, size_t len ) {
|
||||||
struct in6_addr ipv6;
|
struct in6_addr ipv6;
|
||||||
int rc;
|
int rc;
|
||||||
|
@ -981,7 +981,7 @@ static int parse_ipv6_setting ( const struct setting_type *type __unused,
|
||||||
* @v len Length of buffer
|
* @v len Length of buffer
|
||||||
* @ret len Length of formatted value, or negative error
|
* @ret len Length of formatted value, or negative error
|
||||||
*/
|
*/
|
||||||
static int format_ipv6_setting ( const struct setting_type *type __unused,
|
int format_ipv6_setting ( const struct setting_type *type __unused,
|
||||||
const void *raw, size_t raw_len, char *buf,
|
const void *raw, size_t raw_len, char *buf,
|
||||||
size_t len ) {
|
size_t len ) {
|
||||||
const struct in6_addr *ipv6 = raw;
|
const struct in6_addr *ipv6 = raw;
|
||||||
|
@ -991,13 +991,6 @@ static int format_ipv6_setting ( const struct setting_type *type __unused,
|
||||||
return snprintf ( buf, len, "%s", inet6_ntoa ( ipv6 ) );
|
return snprintf ( buf, len, "%s", inet6_ntoa ( ipv6 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/** An IPv6 address setting type */
|
|
||||||
const struct setting_type setting_type_ipv6 __setting_type = {
|
|
||||||
.name = "ipv6",
|
|
||||||
.parse = parse_ipv6_setting,
|
|
||||||
.format = format_ipv6_setting,
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create IPv6 network device
|
* Create IPv6 network device
|
||||||
*
|
*
|
||||||
|
|
|
@ -255,9 +255,6 @@ static int dhcpv6_iaaddr ( struct dhcpv6_option_list *options, uint32_t iaid,
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** DHCPv6 settings scope */
|
|
||||||
static const struct settings_scope dhcpv6_settings_scope;
|
|
||||||
|
|
||||||
/** A DHCPv6 settings block */
|
/** A DHCPv6 settings block */
|
||||||
struct dhcpv6_settings {
|
struct dhcpv6_settings {
|
||||||
/** Reference count */
|
/** Reference count */
|
||||||
|
@ -278,7 +275,7 @@ struct dhcpv6_settings {
|
||||||
static int dhcpv6_applies ( struct settings *settings __unused,
|
static int dhcpv6_applies ( struct settings *settings __unused,
|
||||||
const struct setting *setting ) {
|
const struct setting *setting ) {
|
||||||
|
|
||||||
return ( setting->scope == &dhcpv6_settings_scope );
|
return ( setting->scope == &ipv6_scope );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -339,7 +336,7 @@ static int dhcpv6_register ( struct dhcpv6_option_list *options,
|
||||||
}
|
}
|
||||||
ref_init ( &dhcpv6set->refcnt, NULL );
|
ref_init ( &dhcpv6set->refcnt, NULL );
|
||||||
settings_init ( &dhcpv6set->settings, &dhcpv6_settings_operations,
|
settings_init ( &dhcpv6set->settings, &dhcpv6_settings_operations,
|
||||||
&dhcpv6set->refcnt, &dhcpv6_settings_scope );
|
&dhcpv6set->refcnt, &ipv6_scope );
|
||||||
data = ( ( ( void * ) dhcpv6set ) + sizeof ( *dhcpv6set ) );
|
data = ( ( ( void * ) dhcpv6set ) + sizeof ( *dhcpv6set ) );
|
||||||
len = options->len;
|
len = options->len;
|
||||||
memcpy ( data, options->data, len );
|
memcpy ( data, options->data, len );
|
||||||
|
|
Loading…
Reference in New Issue