Bladeren bron

[settings] Add fetch_ipv4_array_setting()

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 14 jaren geleden
bovenliggende
commit
cb838cc419
2 gewijzigde bestanden met toevoegingen van 25 en 5 verwijderingen
  1. 21
    5
      src/core/settings.c
  2. 4
    0
      src/include/ipxe/settings.h

+ 21
- 5
src/core/settings.c Bestand weergeven

@@ -651,21 +651,37 @@ int fetch_string_setting_copy ( struct settings *settings,
651 651
  *
652 652
  * @v settings		Settings block, or NULL to search all blocks
653 653
  * @v setting		Setting to fetch
654
- * @v inp		IPv4 address to fill in
654
+ * @v inp		IPv4 addresses to fill in
655
+ * @v count		Maximum number of IPv4 addresses
655 656
  * @ret len		Length of setting, or negative error
656 657
  */
657
-int fetch_ipv4_setting ( struct settings *settings, struct setting *setting,
658
-			 struct in_addr *inp ) {
658
+int fetch_ipv4_array_setting ( struct settings *settings,
659
+			       struct setting *setting,
660
+			       struct in_addr *inp, unsigned int count ) {
659 661
 	int len;
660 662
 
661
-	len = fetch_setting ( settings, setting, inp, sizeof ( *inp ) );
663
+	len = fetch_setting ( settings, setting, inp,
664
+			      ( sizeof ( *inp ) * count ) );
662 665
 	if ( len < 0 )
663 666
 		return len;
664
-	if ( len < ( int ) sizeof ( *inp ) )
667
+	if ( ( len % sizeof ( *inp ) ) != 0 )
665 668
 		return -ERANGE;
666 669
 	return len;
667 670
 }
668 671
 
672
+/**
673
+ * Fetch value of IPv4 address setting
674
+ *
675
+ * @v settings		Settings block, or NULL to search all blocks
676
+ * @v setting		Setting to fetch
677
+ * @v inp		IPv4 address to fill in
678
+ * @ret len		Length of setting, or negative error
679
+ */
680
+int fetch_ipv4_setting ( struct settings *settings, struct setting *setting,
681
+			 struct in_addr *inp ) {
682
+	return fetch_ipv4_array_setting ( settings, setting, inp, 1 );
683
+}
684
+
669 685
 /**
670 686
  * Fetch value of signed integer setting
671 687
  *

+ 4
- 0
src/include/ipxe/settings.h Bestand weergeven

@@ -193,6 +193,10 @@ extern int fetch_string_setting ( struct settings *settings,
193 193
 extern int fetch_string_setting_copy ( struct settings *settings,
194 194
 				       struct setting *setting,
195 195
 				       char **data );
196
+extern int fetch_ipv4_array_setting ( struct settings *settings,
197
+				      struct setting *setting,
198
+				      struct in_addr *inp,
199
+				      unsigned int count );
196 200
 extern int fetch_ipv4_setting ( struct settings *settings,
197 201
 				struct setting *setting, struct in_addr *inp );
198 202
 extern int fetch_int_setting ( struct settings *settings,

Laden…
Annuleren
Opslaan