summaryrefslogtreecommitdiffstats
path: root/src/core/settings.c
diff options
context:
space:
mode:
authorMichael Brown2013-12-04 23:06:10 +0100
committerMichael Brown2013-12-05 01:41:49 +0100
commit17451b53e2fc696730586edb9d0a858bcc0b2ec8 (patch)
treee885da23313491fc49f6fcefaef6ac34107c146b /src/core/settings.c
parent[settings] Explicitly separate the concept of a completed fetched setting (diff)
downloadipxe-17451b53e2fc696730586edb9d0a858bcc0b2ec8.tar.gz
ipxe-17451b53e2fc696730586edb9d0a858bcc0b2ec8.tar.xz
ipxe-17451b53e2fc696730586edb9d0a858bcc0b2ec8.zip
[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>
Diffstat (limited to 'src/core/settings.c')
-rw-r--r--src/core/settings.c79
1 files changed, 55 insertions, 24 deletions
diff --git a/src/core/settings.c b/src/core/settings.c
index e6cfc0d2..9b4087e8 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