]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[peerdist] Allow PeerDist to be globally enabled or disabled
authorMichael Brown <mcb30@ipxe.org>
Fri, 13 Dec 2019 14:44:22 +0000 (14:44 +0000)
committerMichael Brown <mcb30@ipxe.org>
Fri, 13 Dec 2019 14:44:22 +0000 (14:44 +0000)
Allow the use of PeerDist content encoding to be enabled or disabled
via the ${peerdist} setting, e.g.:

  # Disable PeerDist
  set peerdist 0

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/net/peerdist.c

index 48933f951c8d251e42583d894dc533ef93259035..3210ac0ec0b970090b43967ade01b4edca0b2ef8 100644 (file)
@@ -25,6 +25,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 
 #include <stdio.h>
 #include <ipxe/http.h>
+#include <ipxe/settings.h>
 #include <ipxe/peermux.h>
 
 /** @file
@@ -35,6 +36,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  * misfortune to encounter, and I've encountered multicast TFTP.
  */
 
+/** PeerDist is globally enabled */
+static long peerdist_enabled = 1;
+
 /**
  * Check whether or not to support PeerDist encoding for this request
  *
@@ -43,6 +47,10 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  */
 static int http_peerdist_supported ( struct http_transaction *http ) {
 
+       /* Allow PeerDist to be globally enabled/disabled */
+       if ( ! peerdist_enabled )
+               return 0;
+
        /* Support PeerDist encoding only if we can directly access an
         * underlying data transfer buffer.  Direct access is required
         * in order to support decryption of data received via the
@@ -143,3 +151,33 @@ struct http_content_encoding peerdist_encoding __http_content_encoding = {
        .supported = http_peerdist_supported,
        .init = http_peerdist_init,
 };
+
+/** PeerDist enabled setting */
+const struct setting peerdist_setting __setting ( SETTING_MISC, peerdist ) = {
+       .name = "peerdist",
+       .description = "PeerDist enabled",
+       .type = &setting_type_int8,
+};
+
+/**
+ * Apply PeerDist settings
+ *
+ * @ret rc             Return status code
+ */
+static int apply_peerdist_settings ( void ) {
+
+       /* Fetch global PeerDist enabled setting */
+       if ( fetch_int_setting ( NULL, &peerdist_setting,
+                                &peerdist_enabled ) < 0 ) {
+               peerdist_enabled = 1;
+       }
+       DBGC ( &peerdist_enabled, "PEERDIST is %s\n",
+              ( peerdist_enabled ? "enabled" : "disabled" ) );
+
+       return 0;
+}
+
+/** PeerDist settings applicator */
+struct settings_applicator peerdist_applicator __settings_applicator = {
+       .apply = apply_peerdist_settings,
+};