Bläddra i källkod

[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 10 år sedan
förälder
incheckning
17451b53e2
7 ändrade filer med 132 tillägg och 51 borttagningar
  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 Visa fil

28
 #include <errno.h>
28
 #include <errno.h>
29
 #include <assert.h>
29
 #include <assert.h>
30
 #include <ipxe/in.h>
30
 #include <ipxe/in.h>
31
+#include <ipxe/ip.h>
32
+#include <ipxe/ipv6.h>
31
 #include <ipxe/vsprintf.h>
33
 #include <ipxe/vsprintf.h>
32
 #include <ipxe/dhcp.h>
34
 #include <ipxe/dhcp.h>
33
 #include <ipxe/uuid.h>
35
 #include <ipxe/uuid.h>
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
  * @v type		Setting type
1655
  * @v type		Setting type
1654
  * @v value		Formatted setting value
1656
  * @v value		Formatted setting value
1656
  * @v len		Length of buffer
1658
  * @v len		Length of buffer
1657
  * @ret len		Length of raw value, or negative error
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
  * @v type		Setting type
1670
  * @v type		Setting type
1679
  * @v raw		Raw setting value
1671
  * @v raw		Raw setting value
1682
  * @v len		Length of buffer
1674
  * @v len		Length of buffer
1683
  * @ret len		Length of formatted value, or negative error
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
 /** An IPv4 address setting type */
1684
 /** An IPv4 address setting type */
1699
 	.format = format_ipv4_setting,
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
  * Integer setting type indices
1734
  * Integer setting type indices
1704
  *
1735
  *

+ 5
- 0
src/include/ipxe/ip.h Visa fil

75
 extern struct net_protocol ipv4_protocol __net_protocol;
75
 extern struct net_protocol ipv4_protocol __net_protocol;
76
 
76
 
77
 extern int ipv4_has_any_addr ( struct net_device *netdev );
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
 #endif /* _IPXE_IP_H */
84
 #endif /* _IPXE_IP_H */

+ 5
- 0
src/include/ipxe/ipv6.h Visa fil

247
 			     unsigned int prefix_len, struct in6_addr *router );
247
 			     unsigned int prefix_len, struct in6_addr *router );
248
 extern int ipv6_set_address ( struct net_device *netdev,
248
 extern int ipv6_set_address ( struct net_device *netdev,
249
 			      struct in6_addr *address );
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
 #endif /* _IPXE_IPV6_H */
256
 #endif /* _IPXE_IPV6_H */

+ 15
- 10
src/include/ipxe/settings.h Visa fil

62
 #define SETTING_NETDEV_EXTRA	02 /**< Network device additional settings */
62
 #define SETTING_NETDEV_EXTRA	02 /**< Network device additional settings */
63
 #define SETTING_IPv4		03 /**< IPv4 settings */
63
 #define SETTING_IPv4		03 /**< IPv4 settings */
64
 #define SETTING_IPv4_EXTRA	04 /**< IPv4 additional settings */
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
 /** Built-in setting scope */
279
 /** Built-in setting scope */
278
 extern const struct settings_scope builtin_scope;
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
  * A generic settings block
286
  * A generic settings block
282
  *
287
  *

+ 45
- 0
src/net/ipv4.c Visa fil

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
 /** IPv4 address setting */
638
 /** IPv4 address setting */
594
 const struct setting ip_setting __setting ( SETTING_IPv4 ) = {
639
 const struct setting ip_setting __setting ( SETTING_IPv4 ) = {
595
 	.name = "ip",
640
 	.name = "ip",

+ 5
- 12
src/net/ipv6.c Visa fil

954
  * @v len		Length of buffer
954
  * @v len		Length of buffer
955
  * @ret len		Length of raw value, or negative error
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
 	struct in6_addr ipv6;
959
 	struct in6_addr ipv6;
960
 	int rc;
960
 	int rc;
961
 
961
 
981
  * @v len		Length of buffer
981
  * @v len		Length of buffer
982
  * @ret len		Length of formatted value, or negative error
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
 	const struct in6_addr *ipv6 = raw;
987
 	const struct in6_addr *ipv6 = raw;
988
 
988
 
989
 	if ( raw_len < sizeof ( *ipv6 ) )
989
 	if ( raw_len < sizeof ( *ipv6 ) )
991
 	return snprintf ( buf, len, "%s", inet6_ntoa ( ipv6 ) );
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
  * Create IPv6 network device
995
  * Create IPv6 network device
1003
  *
996
  *

+ 2
- 5
src/net/udp/dhcpv6.c Visa fil

255
  *
255
  *
256
  */
256
  */
257
 
257
 
258
-/** DHCPv6 settings scope */
259
-static const struct settings_scope dhcpv6_settings_scope;
260
-
261
 /** A DHCPv6 settings block */
258
 /** A DHCPv6 settings block */
262
 struct dhcpv6_settings {
259
 struct dhcpv6_settings {
263
 	/** Reference count */
260
 	/** Reference count */
278
 static int dhcpv6_applies ( struct settings *settings __unused,
275
 static int dhcpv6_applies ( struct settings *settings __unused,
279
 			    const struct setting *setting ) {
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
 	}
336
 	}
340
 	ref_init ( &dhcpv6set->refcnt, NULL );
337
 	ref_init ( &dhcpv6set->refcnt, NULL );
341
 	settings_init ( &dhcpv6set->settings, &dhcpv6_settings_operations,
338
 	settings_init ( &dhcpv6set->settings, &dhcpv6_settings_operations,
342
-			&dhcpv6set->refcnt, &dhcpv6_settings_scope );
339
+			&dhcpv6set->refcnt, &ipv6_scope );
343
 	data = ( ( ( void * ) dhcpv6set ) + sizeof ( *dhcpv6set ) );
340
 	data = ( ( ( void * ) dhcpv6set ) + sizeof ( *dhcpv6set ) );
344
 	len = options->len;
341
 	len = options->len;
345
 	memcpy ( data, options->data, len );
342
 	memcpy ( data, options->data, len );

Laddar…
Avbryt
Spara