Browse Source

[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>
tags/v1.20.1
Michael Brown 11 years ago
parent
commit
17451b53e2
7 changed files with 132 additions and 51 deletions
  1. 55
    24
      src/core/settings.c
  2. 5
    0
      src/include/ipxe/ip.h
  3. 5
    0
      src/include/ipxe/ipv6.h
  4. 15
    10
      src/include/ipxe/settings.h
  5. 45
    0
      src/net/ipv4.c
  6. 5
    12
      src/net/ipv6.c
  7. 2
    5
      src/net/udp/dhcpv6.c

+ 55
- 24
src/core/settings.c View File

@@ -28,6 +28,8 @@ FILE_LICENCE ( GPL2_OR_LATER );
28 28
 #include <errno.h>
29 29
 #include <assert.h>
30 30
 #include <ipxe/in.h>
31
+#include <ipxe/ip.h>
32
+#include <ipxe/ipv6.h>
31 33
 #include <ipxe/vsprintf.h>
32 34
 #include <ipxe/dhcp.h>
33 35
 #include <ipxe/uuid.h>
@@ -1648,7 +1650,7 @@ const struct setting_type setting_type_uristring __setting_type = {
1648 1650
 };
1649 1651
 
1650 1652
 /**
1651
- * Parse IPv4 address setting value
1653
+ * Parse IPv4 address setting value (when IPv4 support is not present)
1652 1654
  *
1653 1655
  * @v type		Setting type
1654 1656
  * @v value		Formatted setting value
@@ -1656,24 +1658,14 @@ const struct setting_type setting_type_uristring __setting_type = {
1656 1658
  * @v len		Length of buffer
1657 1659
  * @ret len		Length of raw value, or negative error
1658 1660
  */
1659
-static int parse_ipv4_setting ( const struct setting_type *type __unused,
1660
-				const char *value, void *buf, size_t len ) {
1661
-	struct in_addr ipv4;
1662
-
1663
-	/* Parse IPv4 address */
1664
-	if ( inet_aton ( value, &ipv4 ) == 0 )
1665
-		return -EINVAL;
1666
-
1667
-	/* Copy to buffer */
1668
-	if ( len > sizeof ( ipv4 ) )
1669
-		len = sizeof ( ipv4 );
1670
-	memcpy ( buf, &ipv4, len );
1671
-
1672
-	return ( sizeof ( ipv4 ) );
1661
+__weak int parse_ipv4_setting ( const struct setting_type *type __unused,
1662
+				const char *value __unused, void *buf __unused,
1663
+				size_t len __unused ) {
1664
+	return -ENOTSUP;
1673 1665
 }
1674 1666
 
1675 1667
 /**
1676
- * Format IPv4 address setting value
1668
+ * Format IPv4 address setting value (when IPv4 support is not present)
1677 1669
  *
1678 1670
  * @v type		Setting type
1679 1671
  * @v raw		Raw setting value
@@ -1682,14 +1674,11 @@ static int parse_ipv4_setting ( const struct setting_type *type __unused,
1682 1674
  * @v len		Length of buffer
1683 1675
  * @ret len		Length of formatted value, or negative error
1684 1676
  */
1685
-static int format_ipv4_setting ( const struct setting_type *type __unused,
1686
-				 const void *raw, size_t raw_len, char *buf,
1687
-				 size_t len ) {
1688
-	const struct in_addr *ipv4 = raw;
1689
-
1690
-	if ( raw_len < sizeof ( *ipv4 ) )
1691
-		return -EINVAL;
1692
-	return snprintf ( buf, len, "%s", inet_ntoa ( *ipv4 ) );
1677
+__weak int format_ipv4_setting ( const struct setting_type *type __unused,
1678
+				 const void *raw __unused,
1679
+				 size_t raw_len __unused, char *buf __unused,
1680
+				 size_t len __unused ) {
1681
+	return -ENOTSUP;
1693 1682
 }
1694 1683
 
1695 1684
 /** An IPv4 address setting type */
@@ -1699,6 +1688,48 @@ const struct setting_type setting_type_ipv4 __setting_type = {
1699 1688
 	.format = format_ipv4_setting,
1700 1689
 };
1701 1690
 
1691
+/**
1692
+ * Parse IPv6 address setting value (when IPv6 support is not present)
1693
+ *
1694
+ * @v type		Setting type
1695
+ * @v value		Formatted setting value
1696
+ * @v buf		Buffer to contain raw value
1697
+ * @v len		Length of buffer
1698
+ * @ret len		Length of raw value, or negative error
1699
+ */
1700
+__weak int parse_ipv6_setting ( const struct setting_type *type __unused,
1701
+				const char *value __unused, void *buf __unused,
1702
+				size_t len __unused ) {
1703
+	return -ENOTSUP;
1704
+}
1705
+
1706
+/**
1707
+ * Format IPv6 address setting value (when IPv6 support is not present)
1708
+ *
1709
+ * @v type		Setting type
1710
+ * @v raw		Raw setting value
1711
+ * @v raw_len		Length of raw setting value
1712
+ * @v buf		Buffer to contain formatted value
1713
+ * @v len		Length of buffer
1714
+ * @ret len		Length of formatted value, or negative error
1715
+ */
1716
+__weak int format_ipv6_setting ( const struct setting_type *type __unused,
1717
+				 const void *raw __unused,
1718
+				 size_t raw_len __unused, char *buf __unused,
1719
+				 size_t len __unused ) {
1720
+	return -ENOTSUP;
1721
+}
1722
+
1723
+/** An IPv6 address setting type */
1724
+const struct setting_type setting_type_ipv6 __setting_type = {
1725
+	.name = "ipv6",
1726
+	.parse = parse_ipv6_setting,
1727
+	.format = format_ipv6_setting,
1728
+};
1729
+
1730
+/** IPv6 settings scope */
1731
+const struct settings_scope ipv6_scope;
1732
+
1702 1733
 /**
1703 1734
  * Integer setting type indices
1704 1735
  *

+ 5
- 0
src/include/ipxe/ip.h View File

@@ -75,5 +75,10 @@ extern struct list_head ipv4_miniroutes;
75 75
 extern struct net_protocol ipv4_protocol __net_protocol;
76 76
 
77 77
 extern int ipv4_has_any_addr ( struct net_device *netdev );
78
+extern int parse_ipv4_setting ( const struct setting_type *type,
79
+				const char *value, void *buf, size_t len );
80
+extern int format_ipv4_setting ( const struct setting_type *type,
81
+				 const void *raw, size_t raw_len, char *buf,
82
+				 size_t len );
78 83
 
79 84
 #endif /* _IPXE_IP_H */

+ 5
- 0
src/include/ipxe/ipv6.h View File

@@ -247,5 +247,10 @@ extern int ipv6_set_prefix ( struct net_device *netdev, struct in6_addr *prefix,
247 247
 			     unsigned int prefix_len, struct in6_addr *router );
248 248
 extern int ipv6_set_address ( struct net_device *netdev,
249 249
 			      struct in6_addr *address );
250
+extern int parse_ipv6_setting ( const struct setting_type *type,
251
+				const char *value, void *buf, size_t len );
252
+extern int format_ipv6_setting ( const struct setting_type *type,
253
+				 const void *raw, size_t raw_len, char *buf,
254
+				 size_t len );
250 255
 
251 256
 #endif /* _IPXE_IPV6_H */

+ 15
- 10
src/include/ipxe/settings.h View File

@@ -62,16 +62,18 @@ struct setting {
62 62
 #define SETTING_NETDEV_EXTRA	02 /**< Network device additional settings */
63 63
 #define SETTING_IPv4		03 /**< IPv4 settings */
64 64
 #define SETTING_IPv4_EXTRA	04 /**< IPv4 additional settings */
65
-#define SETTING_BOOT		05 /**< Generic boot settings */
66
-#define SETTING_BOOT_EXTRA	06 /**< Generic boot additional settings */
67
-#define SETTING_SANBOOT		07 /**< SAN boot settings */
68
-#define SETTING_SANBOOT_EXTRA	08 /**< SAN boot additional settings */
69
-#define SETTING_HOST		09 /**< Host identity settings */
70
-#define SETTING_HOST_EXTRA	10 /**< Host identity additional settings */
71
-#define SETTING_AUTH		11 /**< Authentication settings */
72
-#define SETTING_AUTH_EXTRA	12 /**< Authentication additional settings */
73
-#define SETTING_CRYPTO		13 /**< Cryptography settings */
74
-#define SETTING_MISC		14 /**< Miscellaneous settings */
65
+#define SETTING_IPv6		05 /**< IPv6 settings */
66
+#define SETTING_IPv6_EXTRA	06 /**< IPv6 additional settings */
67
+#define SETTING_BOOT		07 /**< Generic boot settings */
68
+#define SETTING_BOOT_EXTRA	08 /**< Generic boot additional settings */
69
+#define SETTING_SANBOOT		09 /**< SAN boot settings */
70
+#define SETTING_SANBOOT_EXTRA	10 /**< SAN boot additional settings */
71
+#define SETTING_HOST		11 /**< Host identity settings */
72
+#define SETTING_HOST_EXTRA	12 /**< Host identity additional settings */
73
+#define SETTING_AUTH		13 /**< Authentication settings */
74
+#define SETTING_AUTH_EXTRA	14 /**< Authentication additional settings */
75
+#define SETTING_CRYPTO		15 /**< Cryptography settings */
76
+#define SETTING_MISC		16 /**< Miscellaneous settings */
75 77
 
76 78
 /** @} */
77 79
 
@@ -277,6 +279,9 @@ struct builtin_setting {
277 279
 /** Built-in setting scope */
278 280
 extern const struct settings_scope builtin_scope;
279 281
 
282
+/** IPv6 setting scope */
283
+extern const struct settings_scope ipv6_scope;
284
+
280 285
 /**
281 286
  * A generic settings block
282 287
  *

+ 45
- 0
src/net/ipv4.c View File

@@ -590,6 +590,51 @@ struct sockaddr_converter ipv4_sockaddr_converter __sockaddr_converter = {
590 590
  ******************************************************************************
591 591
  */
592 592
 
593
+/**
594
+ * Parse IPv4 address setting value
595
+ *
596
+ * @v type		Setting type
597
+ * @v value		Formatted setting value
598
+ * @v buf		Buffer to contain raw value
599
+ * @v len		Length of buffer
600
+ * @ret len		Length of raw value, or negative error
601
+ */
602
+int parse_ipv4_setting ( const struct setting_type *type __unused,
603
+			 const char *value, void *buf, size_t len ) {
604
+	struct in_addr ipv4;
605
+
606
+	/* Parse IPv4 address */
607
+	if ( inet_aton ( value, &ipv4 ) == 0 )
608
+		return -EINVAL;
609
+
610
+	/* Copy to buffer */
611
+	if ( len > sizeof ( ipv4 ) )
612
+		len = sizeof ( ipv4 );
613
+	memcpy ( buf, &ipv4, len );
614
+
615
+	return ( sizeof ( ipv4 ) );
616
+}
617
+
618
+/**
619
+ * Format IPv4 address setting value
620
+ *
621
+ * @v type		Setting type
622
+ * @v raw		Raw setting value
623
+ * @v raw_len		Length of raw setting value
624
+ * @v buf		Buffer to contain formatted value
625
+ * @v len		Length of buffer
626
+ * @ret len		Length of formatted value, or negative error
627
+ */
628
+int format_ipv4_setting ( const struct setting_type *type __unused,
629
+			  const void *raw, size_t raw_len, char *buf,
630
+			  size_t len ) {
631
+	const struct in_addr *ipv4 = raw;
632
+
633
+	if ( raw_len < sizeof ( *ipv4 ) )
634
+		return -EINVAL;
635
+	return snprintf ( buf, len, "%s", inet_ntoa ( *ipv4 ) );
636
+}
637
+
593 638
 /** IPv4 address setting */
594 639
 const struct setting ip_setting __setting ( SETTING_IPv4 ) = {
595 640
 	.name = "ip",

+ 5
- 12
src/net/ipv6.c View File

@@ -954,8 +954,8 @@ struct sockaddr_converter ipv6_sockaddr_converter __sockaddr_converter = {
954 954
  * @v len		Length of buffer
955 955
  * @ret len		Length of raw value, or negative error
956 956
  */
957
-static int parse_ipv6_setting ( const struct setting_type *type __unused,
958
-				const char *value, void *buf, size_t len ) {
957
+int parse_ipv6_setting ( const struct setting_type *type __unused,
958
+			 const char *value, void *buf, size_t len ) {
959 959
 	struct in6_addr ipv6;
960 960
 	int rc;
961 961
 
@@ -981,9 +981,9 @@ static int parse_ipv6_setting ( const struct setting_type *type __unused,
981 981
  * @v len		Length of buffer
982 982
  * @ret len		Length of formatted value, or negative error
983 983
  */
984
-static int format_ipv6_setting ( const struct setting_type *type __unused,
985
-				 const void *raw, size_t raw_len, char *buf,
986
-				 size_t len ) {
984
+int format_ipv6_setting ( const struct setting_type *type __unused,
985
+			  const void *raw, size_t raw_len, char *buf,
986
+			  size_t len ) {
987 987
 	const struct in6_addr *ipv6 = raw;
988 988
 
989 989
 	if ( raw_len < sizeof ( *ipv6 ) )
@@ -991,13 +991,6 @@ static int format_ipv6_setting ( const struct setting_type *type __unused,
991 991
 	return snprintf ( buf, len, "%s", inet6_ntoa ( ipv6 ) );
992 992
 }
993 993
 
994
-/** An IPv6 address setting type */
995
-const struct setting_type setting_type_ipv6 __setting_type = {
996
-	.name = "ipv6",
997
-	.parse = parse_ipv6_setting,
998
-	.format = format_ipv6_setting,
999
-};
1000
-
1001 994
 /**
1002 995
  * Create IPv6 network device
1003 996
  *

+ 2
- 5
src/net/udp/dhcpv6.c View File

@@ -255,9 +255,6 @@ static int dhcpv6_iaaddr ( struct dhcpv6_option_list *options, uint32_t iaid,
255 255
  *
256 256
  */
257 257
 
258
-/** DHCPv6 settings scope */
259
-static const struct settings_scope dhcpv6_settings_scope;
260
-
261 258
 /** A DHCPv6 settings block */
262 259
 struct dhcpv6_settings {
263 260
 	/** Reference count */
@@ -278,7 +275,7 @@ struct dhcpv6_settings {
278 275
 static int dhcpv6_applies ( struct settings *settings __unused,
279 276
 			    const struct setting *setting ) {
280 277
 
281
-	return ( setting->scope == &dhcpv6_settings_scope );
278
+	return ( setting->scope == &ipv6_scope );
282 279
 }
283 280
 
284 281
 /**
@@ -339,7 +336,7 @@ static int dhcpv6_register ( struct dhcpv6_option_list *options,
339 336
 	}
340 337
 	ref_init ( &dhcpv6set->refcnt, NULL );
341 338
 	settings_init ( &dhcpv6set->settings, &dhcpv6_settings_operations,
342
-			&dhcpv6set->refcnt, &dhcpv6_settings_scope );
339
+			&dhcpv6set->refcnt, &ipv6_scope );
343 340
 	data = ( ( ( void * ) dhcpv6set ) + sizeof ( *dhcpv6set ) );
344 341
 	len = options->len;
345 342
 	memcpy ( data, options->data, len );

Loading…
Cancel
Save