aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core/settings.c79
-rw-r--r--src/include/ipxe/ip.h5
-rw-r--r--src/include/ipxe/ipv6.h5
-rw-r--r--src/include/ipxe/settings.h25
-rw-r--r--src/net/ipv4.c45
-rw-r--r--src/net/ipv6.c17
-rw-r--r--src/net/udp/dhcpv6.c7
7 files changed, 132 insertions, 51 deletions
diff --git a/src/core/settings.c b/src/core/settings.c
index e6cfc0d21..9b4087e8b 100644
--- a/src/core/settings.c
+++ b/src/core/settings.c
@@ -28,6 +28,8 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <errno.h>
#include <assert.h>
#include <ipxe/in.h>
+#include <ipxe/ip.h>
+#include <ipxe/ipv6.h>
#include <ipxe/vsprintf.h>
#include <ipxe/dhcp.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 value Formatted setting value
@@ -1656,24 +1658,14 @@ const struct setting_type setting_type_uristring __setting_type = {
* @v len Length of buffer
* @ret len Length of raw value, or negative error
*/
-static 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 ) );
+__weak int parse_ipv4_setting ( const struct setting_type *type __unused,
+ const char *value __unused, void *buf __unused,
+ size_t len __unused ) {
+ return -ENOTSUP;
}
/**
- * Format IPv4 address setting value
+ * Format IPv4 address setting value (when IPv4 support is not present)
*
* @v type Setting type
* @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
* @ret len Length of formatted value, or negative error
*/
-static 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 ) );
+__weak int format_ipv4_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 IPv4 address setting type */
@@ -1700,6 +1689,48 @@ const struct setting_type setting_type_ipv4 __setting_type = {
};
/**
+ * 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
*
* These indexes are defined such that (1<<index) gives the width of
diff --git a/src/include/ipxe/ip.h b/src/include/ipxe/ip.h
index 3234b7b0e..1a93a552e 100644
--- a/src/include/ipxe/ip.h
+++ b/src/include/ipxe/ip.h
@@ -75,5 +75,10 @@ extern struct list_head ipv4_miniroutes;
extern struct net_protocol ipv4_protocol __net_protocol;
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 */
diff --git a/src/include/ipxe/ipv6.h b/src/include/ipxe/ipv6.h
index c4a9f15e3..48aaf677e 100644
--- a/src/include/ipxe/ipv6.h
+++ b/src/include/ipxe/ipv6.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 );
extern int ipv6_set_address ( struct net_device *netdev,
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 */
diff --git a/src/include/ipxe/settings.h b/src/include/ipxe/settings.h
index 25665ca78..3b1328c82 100644
--- a/src/include/ipxe/settings.h
+++ b/src/include/ipxe/settings.h
@@ -62,16 +62,18 @@ struct setting {
#define SETTING_NETDEV_EXTRA 02 /**< Network device additional settings */
#define SETTING_IPv4 03 /**< IPv4 settings */
#define SETTING_IPv4_EXTRA 04 /**< IPv4 additional settings */
-#define SETTING_BOOT 05 /**< Generic boot settings */
-#define SETTING_BOOT_EXTRA 06 /**< Generic boot additional settings */
-#define SETTING_SANBOOT 07 /**< SAN boot settings */
-#define SETTING_SANBOOT_EXTRA 08 /**< SAN boot additional settings */
-#define SETTING_HOST 09 /**< Host identity settings */
-#define SETTING_HOST_EXTRA 10 /**< Host identity additional settings */
-#define SETTING_AUTH 11 /**< Authentication settings */
-#define SETTING_AUTH_EXTRA 12 /**< Authentication additional settings */
-#define SETTING_CRYPTO 13 /**< Cryptography settings */
-#define SETTING_MISC 14 /**< Miscellaneous settings */
+#define SETTING_IPv6 05 /**< IPv6 settings */
+#define SETTING_IPv6_EXTRA 06 /**< IPv6 additional settings */
+#define SETTING_BOOT 07 /**< Generic boot settings */
+#define SETTING_BOOT_EXTRA 08 /**< Generic boot additional settings */
+#define SETTING_SANBOOT 09 /**< SAN boot settings */
+#define SETTING_SANBOOT_EXTRA 10 /**< SAN boot additional settings */
+#define SETTING_HOST 11 /**< Host identity settings */
+#define SETTING_HOST_EXTRA 12 /**< Host identity additional settings */
+#define SETTING_AUTH 13 /**< Authentication 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 */
extern const struct settings_scope builtin_scope;
+/** IPv6 setting scope */
+extern const struct settings_scope ipv6_scope;
+
/**
* A generic settings block
*
diff --git a/src/net/ipv4.c b/src/net/ipv4.c
index f0a2e4d65..5d5c3f753 100644
--- a/src/net/ipv4.c
+++ b/src/net/ipv4.c
@@ -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 */
const struct setting ip_setting __setting ( SETTING_IPv4 ) = {
.name = "ip",
diff --git a/src/net/ipv6.c b/src/net/ipv6.c
index 68a0c89bf..621b4ff11 100644
--- a/src/net/ipv6.c
+++ b/src/net/ipv6.c
@@ -954,8 +954,8 @@ struct sockaddr_converter ipv6_sockaddr_converter __sockaddr_converter = {
* @v len Length of buffer
* @ret len Length of raw value, or negative error
*/
-static int parse_ipv6_setting ( const struct setting_type *type __unused,
- const char *value, void *buf, size_t len ) {
+int parse_ipv6_setting ( const struct setting_type *type __unused,
+ const char *value, void *buf, size_t len ) {
struct in6_addr ipv6;
int rc;
@@ -981,9 +981,9 @@ static int parse_ipv6_setting ( const struct setting_type *type __unused,
* @v len Length of buffer
* @ret len Length of formatted value, or negative error
*/
-static int format_ipv6_setting ( const struct setting_type *type __unused,
- const void *raw, size_t raw_len, char *buf,
- size_t len ) {
+int format_ipv6_setting ( const struct setting_type *type __unused,
+ const void *raw, size_t raw_len, char *buf,
+ size_t len ) {
const struct in6_addr *ipv6 = raw;
if ( raw_len < sizeof ( *ipv6 ) )
@@ -991,13 +991,6 @@ static int format_ipv6_setting ( const struct setting_type *type __unused,
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
*
diff --git a/src/net/udp/dhcpv6.c b/src/net/udp/dhcpv6.c
index 7bed83d92..668974cae 100644
--- a/src/net/udp/dhcpv6.c
+++ b/src/net/udp/dhcpv6.c
@@ -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 */
struct dhcpv6_settings {
/** Reference count */
@@ -278,7 +275,7 @@ struct dhcpv6_settings {
static int dhcpv6_applies ( struct settings *settings __unused,
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 );
settings_init ( &dhcpv6set->settings, &dhcpv6_settings_operations,
- &dhcpv6set->refcnt, &dhcpv6_settings_scope );
+ &dhcpv6set->refcnt, &ipv6_scope );
data = ( ( ( void * ) dhcpv6set ) + sizeof ( *dhcpv6set ) );
len = options->len;
memcpy ( data, options->data, len );