]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[settings] Allow for IPv6 setting types in non-IPv6 builds
authorMichael Brown <mcb30@ipxe.org>
Wed, 4 Dec 2013 22:06:10 +0000 (22:06 +0000)
committerMichael Brown <mcb30@ipxe.org>
Thu, 5 Dec 2013 00:41:49 +0000 (00:41 +0000)
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>
src/core/settings.c
src/include/ipxe/ip.h
src/include/ipxe/ipv6.h
src/include/ipxe/settings.h
src/net/ipv4.c
src/net/ipv6.c
src/net/udp/dhcpv6.c

index e6cfc0d212022bfdfa546763cbee1c0a6cd0ce41..9b4087e8b70224937999259d04fe481028a5bc6f 100644 (file)
@@ -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 */
@@ -1699,6 +1688,48 @@ const struct setting_type setting_type_ipv4 __setting_type = {
        .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
  *
index 3234b7b0ef8af69e6438e5b13ae740cd11c0b10d..1a93a552e997077437465c6c1cc791a90c7d0b42 100644 (file)
@@ -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 */
index c4a9f15e3fededdbef16c9ca486db3448dce5db5..48aaf677efc134496cc130d0eb81a0ad104816c6 100644 (file)
@@ -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 */
index 25665ca7841ebebb29fde848b8601e0699499889..3b1328c826904efc77c43be21ff2e517f30f9ed3 100644 (file)
@@ -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
  *
index f0a2e4d6520ce7423d77065e2e95b8c0172e458a..5d5c3f753ef3c7ef5e7718c11c0a23adcd6f5d57 100644 (file)
@@ -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",
index 68a0c89bf81b58f78a57b5fb079574feb437cc26..621b4ff111bdd9bbe38fb59844d90aa58f4d61d8 100644 (file)
@@ -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
  *
index 7bed83d92ab148b264d0f5986a90fc42477f1258..668974caec31829650108dc3d736164a9767cf2b 100644 (file)
@@ -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 );