Browse code

Refactored: Moved BIO debug functions to OpenSSL backend

Signed-off-by: Adriaan de Jong <dejong@fox-it.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Signed-off-by: David Sommerseth <davids@redhat.com>

Adriaan de Jong authored on 2011/06/28 17:08:08
Showing 2 changed files
... ...
@@ -111,68 +111,6 @@ show_tls_performance_stats(void)
111 111
 
112 112
 #endif
113 113
 
114
-#ifdef BIO_DEBUG
115
-
116
-#warning BIO_DEBUG defined
117
-
118
-static FILE *biofp;                            /* GLOBAL */
119
-static bool biofp_toggle;                      /* GLOBAL */
120
-static time_t biofp_last_open;                 /* GLOBAL */
121
-static const int biofp_reopen_interval = 600;  /* GLOBAL */
122
-
123
-static void
124
-close_biofp()
125
-{
126
-  if (biofp)
127
-    {
128
-      ASSERT (!fclose (biofp));
129
-      biofp = NULL;
130
-    }
131
-}
132
-
133
-static void
134
-open_biofp()
135
-{
136
-  const time_t current = time (NULL);
137
-  const pid_t pid = getpid ();
138
-
139
-  if (biofp_last_open + biofp_reopen_interval < current)
140
-    close_biofp();
141
-  if (!biofp)
142
-    {
143
-      char fn[256];
144
-      openvpn_snprintf(fn, sizeof(fn), "bio/%d-%d.log", pid, biofp_toggle);
145
-      biofp = fopen (fn, "w");
146
-      ASSERT (biofp);
147
-      biofp_last_open = time (NULL);
148
-      biofp_toggle ^= 1;
149
-    }
150
-}
151
-
152
-static void
153
-bio_debug_data (const char *mode, BIO *bio, const uint8_t *buf, int len, const char *desc)
154
-{
155
-  struct gc_arena gc = gc_new ();
156
-  if (len > 0)
157
-    {
158
-      open_biofp();
159
-      fprintf(biofp, "BIO_%s %s time=" time_format " bio=" ptr_format " len=%d data=%s\n",
160
-	      mode, desc, time (NULL), (ptr_type)bio, len, format_hex (buf, len, 0, &gc));
161
-      fflush (biofp);
162
-    }
163
-  gc_free (&gc);
164
-}
165
-
166
-static void
167
-bio_debug_oc (const char *mode, BIO *bio)
168
-{
169
-  open_biofp();
170
-  fprintf(biofp, "BIO %s time=" time_format " bio=" ptr_format "\n",
171
-	  mode, time (NULL), (ptr_type)bio);
172
-  fflush (biofp);
173
-}
174
-
175
-#endif
176 114
 
177 115
 /*
178 116
  * Max number of bytes we will add
... ...
@@ -840,6 +840,69 @@ tls_ctx_load_ca (struct tls_root_ctx *ctx, const char *ca_file,
840 840
  *
841 841
  */
842 842
 
843
+#ifdef BIO_DEBUG
844
+
845
+#warning BIO_DEBUG defined
846
+
847
+static FILE *biofp;                            /* GLOBAL */
848
+static bool biofp_toggle;                      /* GLOBAL */
849
+static time_t biofp_last_open;                 /* GLOBAL */
850
+static const int biofp_reopen_interval = 600;  /* GLOBAL */
851
+
852
+static void
853
+close_biofp()
854
+{
855
+  if (biofp)
856
+    {
857
+      ASSERT (!fclose (biofp));
858
+      biofp = NULL;
859
+    }
860
+}
861
+
862
+static void
863
+open_biofp()
864
+{
865
+  const time_t current = time (NULL);
866
+  const pid_t pid = getpid ();
867
+
868
+  if (biofp_last_open + biofp_reopen_interval < current)
869
+    close_biofp();
870
+  if (!biofp)
871
+    {
872
+      char fn[256];
873
+      openvpn_snprintf(fn, sizeof(fn), "bio/%d-%d.log", pid, biofp_toggle);
874
+      biofp = fopen (fn, "w");
875
+      ASSERT (biofp);
876
+      biofp_last_open = time (NULL);
877
+      biofp_toggle ^= 1;
878
+    }
879
+}
880
+
881
+static void
882
+bio_debug_data (const char *mode, BIO *bio, const uint8_t *buf, int len, const char *desc)
883
+{
884
+  struct gc_arena gc = gc_new ();
885
+  if (len > 0)
886
+    {
887
+      open_biofp();
888
+      fprintf(biofp, "BIO_%s %s time=" time_format " bio=" ptr_format " len=%d data=%s\n",
889
+	      mode, desc, time (NULL), (ptr_type)bio, len, format_hex (buf, len, 0, &gc));
890
+      fflush (biofp);
891
+    }
892
+  gc_free (&gc);
893
+}
894
+
895
+static void
896
+bio_debug_oc (const char *mode, BIO *bio)
897
+{
898
+  open_biofp();
899
+  fprintf(biofp, "BIO %s time=" time_format " bio=" ptr_format "\n",
900
+	  mode, time (NULL), (ptr_type)bio);
901
+  fflush (biofp);
902
+}
903
+
904
+#endif
905
+
843 906
 /*
844 907
  * OpenVPN's interface to SSL/TLS authentication,
845 908
  * encryption, and decryption is exclusively