ソースを参照

use BLog instead od DEBUG

ambrop7 15 年 前
コミット
2571e6265c

+ 15 - 0
blog_channels.txt

@@ -67,3 +67,18 @@ NCDUdevMonitorParser 4
 NCDUdevMonitor 4
 NCDUdevMonitor 4
 NCDUdevCache 4
 NCDUdevCache 4
 NCDUdevManager 4
 NCDUdevManager 4
+BTime 4
+BSocket 4
+BEncryption 4
+SPProtoDecoder 4
+LineBuffer 4
+BTap 4
+lwip 4
+NCDConfigParser 4
+BIPC 4
+BIPCServer 4
+nsskey 4
+addr 4
+PasswordListener 4
+NCDInterfaceMonitor 4
+NCDRfkillMonitor 4

+ 2 - 2
client/FrameDecider.c

@@ -558,13 +558,13 @@ int FrameDeciderPeer_Init (FrameDeciderPeer *o, FrameDecider *d)
     
     
     // allocate MAC entries
     // allocate MAC entries
     if (!(o->mac_entries = BAllocArray(d->max_peer_macs, sizeof(struct _FrameDecider_mac_entry)))) {
     if (!(o->mac_entries = BAllocArray(d->max_peer_macs, sizeof(struct _FrameDecider_mac_entry)))) {
-        DEBUG("failed to allocate MAC entries");
+        BLog(BLOG_ERROR, "failed to allocate MAC entries");
         goto fail0;
         goto fail0;
     }
     }
     
     
     // allocate group entries
     // allocate group entries
     if (!(o->group_entries = BAllocArray(d->max_peer_groups, sizeof(struct _FrameDecider_group_entry)))) {
     if (!(o->group_entries = BAllocArray(d->max_peer_groups, sizeof(struct _FrameDecider_group_entry)))) {
-        DEBUG("failed to allocate group entries");
+        BLog(BLOG_ERROR, "failed to allocate group entries");
         goto fail1;
         goto fail1;
     }
     }
     
     

+ 18 - 15
client/PasswordListener.c

@@ -31,11 +31,14 @@
 #include <misc/debug.h>
 #include <misc/debug.h>
 #include <misc/offset.h>
 #include <misc/offset.h>
 #include <misc/byteorder.h>
 #include <misc/byteorder.h>
+#include <system/BLog.h>
 #include <nspr_support/DummyPRFileDesc.h>
 #include <nspr_support/DummyPRFileDesc.h>
 #include <nspr_support/BSocketPRFileDesc.h>
 #include <nspr_support/BSocketPRFileDesc.h>
 
 
 #include <client/PasswordListener.h>
 #include <client/PasswordListener.h>
 
 
+#include <generated/blog_channel_PasswordListener.h>
+
 static int password_comparator (void *user, uint64_t *p1, uint64_t *p2);
 static int password_comparator (void *user, uint64_t *p1, uint64_t *p2);
 static void cleanup_client (PasswordListener *l, struct PasswordListenerClient *client);
 static void cleanup_client (PasswordListener *l, struct PasswordListenerClient *client);
 static void listener_handler (PasswordListener *l);
 static void listener_handler (PasswordListener *l);
@@ -81,17 +84,17 @@ void listener_handler (PasswordListener *l)
     }
     }
     
     
     if (!(client->sock = malloc(sizeof(sslsocket)))) {
     if (!(client->sock = malloc(sizeof(sslsocket)))) {
-        DEBUG("cannot allocate sslsocket");
+        BLog(BLOG_ERROR, "cannot allocate sslsocket");
         goto fail0;
         goto fail0;
     }
     }
     
     
     // accept a client
     // accept a client
     if (!Listener_Accept(&l->listener, &client->sock->sock, NULL)) {
     if (!Listener_Accept(&l->listener, &client->sock->sock, NULL)) {
-        DEBUG("Listener_Accept failed");
+        BLog(BLOG_ERROR, "Listener_Accept failed");
         goto fail1;
         goto fail1;
     }
     }
     
     
-    DEBUG("Connection accepted");
+    BLog(BLOG_INFO, "Connection accepted");
     
     
     if (l->ssl) {
     if (l->ssl) {
         // create BSocket NSPR file descriptor
         // create BSocket NSPR file descriptor
@@ -105,17 +108,17 @@ void listener_handler (PasswordListener *l)
         
         
         // set server mode
         // set server mode
         if (SSL_ResetHandshake(client->sock->ssl_prfd, PR_TRUE) != SECSuccess) {
         if (SSL_ResetHandshake(client->sock->ssl_prfd, PR_TRUE) != SECSuccess) {
-            DEBUG("SSL_ResetHandshake failed");
+            BLog(BLOG_ERROR, "SSL_ResetHandshake failed");
             goto fail3;
             goto fail3;
         }
         }
         
         
         // set require client certificate
         // set require client certificate
         if (SSL_OptionSet(client->sock->ssl_prfd, SSL_REQUEST_CERTIFICATE, PR_TRUE) != SECSuccess) {
         if (SSL_OptionSet(client->sock->ssl_prfd, SSL_REQUEST_CERTIFICATE, PR_TRUE) != SECSuccess) {
-            DEBUG("SSL_OptionSet(SSL_REQUEST_CERTIFICATE) failed");
+            BLog(BLOG_ERROR, "SSL_OptionSet(SSL_REQUEST_CERTIFICATE) failed");
             goto fail3;
             goto fail3;
         }
         }
         if (SSL_OptionSet(client->sock->ssl_prfd, SSL_REQUIRE_CERTIFICATE, PR_TRUE) != SECSuccess) {
         if (SSL_OptionSet(client->sock->ssl_prfd, SSL_REQUIRE_CERTIFICATE, PR_TRUE) != SECSuccess) {
-            DEBUG("SSL_OptionSet(SSL_REQUIRE_CERTIFICATE) failed");
+            BLog(BLOG_ERROR, "SSL_OptionSet(SSL_REQUIRE_CERTIFICATE) failed");
             goto fail3;
             goto fail3;
         }
         }
         
         
@@ -170,11 +173,11 @@ void client_try_read (struct PasswordListenerClient *client)
                     BPRFileDesc_EnableEvent(&client->sock->ssl_bprfd, PR_POLL_READ);
                     BPRFileDesc_EnableEvent(&client->sock->ssl_bprfd, PR_POLL_READ);
                     return;
                     return;
                 }
                 }
-                DEBUG("PR_Read failed (%d)", (int)error);
+                BLog(BLOG_ERROR, "PR_Read failed (%d)", (int)error);
                 goto free_client;
                 goto free_client;
             }
             }
             if (recvd == 0) {
             if (recvd == 0) {
-                DEBUG("Connection terminated");
+                BLog(BLOG_INFO, "Connection terminated");
                 goto free_client;
                 goto free_client;
             }
             }
             client->recv_buffer_pos += recvd;
             client->recv_buffer_pos += recvd;
@@ -192,11 +195,11 @@ void client_try_read (struct PasswordListenerClient *client)
                     BSocket_EnableEvent(&client->sock->sock, BSOCKET_READ);
                     BSocket_EnableEvent(&client->sock->sock, BSOCKET_READ);
                     return;
                     return;
                 }
                 }
-                DEBUG("BSocket_Recv failed (%d)", error);
+                BLog(BLOG_ERROR, "BSocket_Recv failed (%d)", error);
                 goto free_client;
                 goto free_client;
             }
             }
             if (recvd == 0) {
             if (recvd == 0) {
-                DEBUG("Connection terminated");
+                BLog(BLOG_INFO, "Connection terminated");
                 goto free_client;
                 goto free_client;
             }
             }
             client->recv_buffer_pos += recvd;
             client->recv_buffer_pos += recvd;
@@ -207,12 +210,12 @@ void client_try_read (struct PasswordListenerClient *client)
     uint64_t received_pass = ltoh64(client->recv_buffer);
     uint64_t received_pass = ltoh64(client->recv_buffer);
     BAVLNode *pw_tree_node = BAVL_LookupExact(&l->passwords, &received_pass);
     BAVLNode *pw_tree_node = BAVL_LookupExact(&l->passwords, &received_pass);
     if (!pw_tree_node) {
     if (!pw_tree_node) {
-        DEBUG("WARNING: unknown password");
+        BLog(BLOG_WARNING, "unknown password");
         goto free_client;
         goto free_client;
     }
     }
     PasswordListener_pwentry *pw_entry = UPPER_OBJECT(pw_tree_node, PasswordListener_pwentry, tree_node);
     PasswordListener_pwentry *pw_entry = UPPER_OBJECT(pw_tree_node, PasswordListener_pwentry, tree_node);
     
     
-    DEBUG("Password recognized");
+    BLog(BLOG_INFO, "Password recognized");
     
     
     // remove password entry
     // remove password entry
     BAVL_Remove(&l->passwords, &pw_entry->tree_node);
     BAVL_Remove(&l->passwords, &pw_entry->tree_node);
@@ -275,14 +278,14 @@ int PasswordListener_Init (PasswordListener *l, BReactor *bsys, BAddr listen_add
         // initialize model SSL fd
         // initialize model SSL fd
         DummyPRFileDesc_Create(&l->model_dprfd);
         DummyPRFileDesc_Create(&l->model_dprfd);
         if (!(l->model_prfd = SSL_ImportFD(NULL, &l->model_dprfd))) {
         if (!(l->model_prfd = SSL_ImportFD(NULL, &l->model_dprfd))) {
-            DEBUG("SSL_ImportFD failed");
+            BLog(BLOG_ERROR, "SSL_ImportFD failed");
             ASSERT_FORCE(PR_Close(&l->model_dprfd) == PR_SUCCESS)
             ASSERT_FORCE(PR_Close(&l->model_dprfd) == PR_SUCCESS)
             goto fail1;
             goto fail1;
         }
         }
         
         
         // set server certificate
         // set server certificate
         if (SSL_ConfigSecureServer(l->model_prfd, cert, key, NSS_FindCertKEAType(cert)) != SECSuccess) {
         if (SSL_ConfigSecureServer(l->model_prfd, cert, key, NSS_FindCertKEAType(cert)) != SECSuccess) {
-            DEBUG("SSL_ConfigSecureServer failed");
+            BLog(BLOG_ERROR, "SSL_ConfigSecureServer failed");
             goto fail2;
             goto fail2;
         }
         }
     }
     }
@@ -302,7 +305,7 @@ int PasswordListener_Init (PasswordListener *l, BReactor *bsys, BAddr listen_add
     
     
     // initialize listener
     // initialize listener
     if (!Listener_Init(&l->listener, l->bsys, listen_addr, (Listener_handler)listener_handler, l)) {
     if (!Listener_Init(&l->listener, l->bsys, listen_addr, (Listener_handler)listener_handler, l)) {
-        DEBUG("Listener_Init failed");
+        BLog(BLOG_ERROR, "Listener_Init failed");
         goto fail2;
         goto fail2;
     }
     }
     
     

+ 9 - 1
flow/LineBuffer.c

@@ -23,8 +23,12 @@
 #include <stdlib.h>
 #include <stdlib.h>
 #include <string.h>
 #include <string.h>
 
 
+#include <system/BLog.h>
+
 #include <flow/LineBuffer.h>
 #include <flow/LineBuffer.h>
 
 
+#include <generated/blog_channel_LineBuffer.h>
+
 static void input_handler_done (LineBuffer *o, int data_len)
 static void input_handler_done (LineBuffer *o, int data_len)
 {
 {
     DebugObject_Access(&o->d_obj);
     DebugObject_Access(&o->d_obj);
@@ -43,6 +47,10 @@ static void input_handler_done (LineBuffer *o, int data_len)
     }
     }
     
     
     if (i < o->buf_used || o->buf_used == o->buf_size) {
     if (i < o->buf_used || o->buf_used == o->buf_size) {
+        if (i == o->buf_used) {
+            BLog(BLOG_WARNING, "line too long");
+        }
+        
         // pass to output
         // pass to output
         o->buf_consumed = (i < o->buf_used ? i + 1 : i);
         o->buf_consumed = (i < o->buf_used ? i + 1 : i);
         PacketPassInterface_Sender_Send(o->output, o->buf, o->buf_consumed);
         PacketPassInterface_Sender_Send(o->output, o->buf, o->buf_consumed);
@@ -102,7 +110,7 @@ int LineBuffer_Init (LineBuffer *o, StreamRecvInterface *input, PacketPassInterf
     
     
     // allocate buffer
     // allocate buffer
     if (!(o->buf = malloc(o->buf_size))) {
     if (!(o->buf = malloc(o->buf_size))) {
-        DEBUG("malloc failed");
+        BLog(BLOG_ERROR, "malloc failed");
         goto fail0;
         goto fail0;
     }
     }
     
     

+ 13 - 10
flow/SPProtoDecoder.c

@@ -26,9 +26,12 @@
 #include <misc/balign.h>
 #include <misc/balign.h>
 #include <misc/byteorder.h>
 #include <misc/byteorder.h>
 #include <security/BHash.h>
 #include <security/BHash.h>
+#include <system/BLog.h>
 
 
 #include <flow/SPProtoDecoder.h>
 #include <flow/SPProtoDecoder.h>
 
 
+#include <generated/blog_channel_SPProtoDecoder.h>
+
 static void decode_work_func (SPProtoDecoder *o)
 static void decode_work_func (SPProtoDecoder *o)
 {
 {
     ASSERT(o->in_len >= 0)
     ASSERT(o->in_len >= 0)
@@ -49,19 +52,19 @@ static void decode_work_func (SPProtoDecoder *o)
     } else {
     } else {
         // input must be a multiple of blocks size
         // input must be a multiple of blocks size
         if (in_len % o->enc_block_size != 0) {
         if (in_len % o->enc_block_size != 0) {
-            DEBUG("packet size not a multiple of block size");
+            BLog(BLOG_WARNING, "packet size not a multiple of block size");
             return;
             return;
         }
         }
         
         
         // input must have an IV block
         // input must have an IV block
         if (in_len < o->enc_block_size) {
         if (in_len < o->enc_block_size) {
-            DEBUG("packet does not have an IV");
+            BLog(BLOG_WARNING, "packet does not have an IV");
             return;
             return;
         }
         }
         
         
         // check if we have encryption key
         // check if we have encryption key
         if (!o->have_encryption_key) {
         if (!o->have_encryption_key) {
-            DEBUG("have no encryption key");
+            BLog(BLOG_WARNING, "have no encryption key");
             return;
             return;
         }
         }
         
         
@@ -77,7 +80,7 @@ static void decode_work_func (SPProtoDecoder *o)
         
         
         // read padding
         // read padding
         if (ciphertext_len < o->enc_block_size) {
         if (ciphertext_len < o->enc_block_size) {
-            DEBUG("packet does not have a padding block");
+            BLog(BLOG_WARNING, "packet does not have a padding block");
             return;
             return;
         }
         }
         int i;
         int i;
@@ -86,12 +89,12 @@ static void decode_work_func (SPProtoDecoder *o)
                 break;
                 break;
             }
             }
             if (plaintext[i] != 0) {
             if (plaintext[i] != 0) {
-                DEBUG("packet padding wrong (nonzero byte)");
+                BLog(BLOG_WARNING, "packet padding wrong (nonzero byte)");
                 return;
                 return;
             }
             }
         }
         }
         if (i < ciphertext_len - o->enc_block_size) {
         if (i < ciphertext_len - o->enc_block_size) {
-            DEBUG("packet padding wrong (all zeroes)");
+            BLog(BLOG_WARNING, "packet padding wrong (all zeroes)");
             return;
             return;
         }
         }
         plaintext_len = i;
         plaintext_len = i;
@@ -99,14 +102,14 @@ static void decode_work_func (SPProtoDecoder *o)
     
     
     // check for header
     // check for header
     if (plaintext_len < SPPROTO_HEADER_LEN(o->sp_params)) {
     if (plaintext_len < SPPROTO_HEADER_LEN(o->sp_params)) {
-        DEBUG("packet has no header");
+        BLog(BLOG_WARNING, "packet has no header");
         return;
         return;
     }
     }
     uint8_t *header = plaintext;
     uint8_t *header = plaintext;
     
     
     // check data length
     // check data length
     if (plaintext_len - SPPROTO_HEADER_LEN(o->sp_params) > o->output_mtu) {
     if (plaintext_len - SPPROTO_HEADER_LEN(o->sp_params) > o->output_mtu) {
-        DEBUG("packet too long");
+        BLog(BLOG_WARNING, "packet too long");
         return;
         return;
     }
     }
     
     
@@ -133,7 +136,7 @@ static void decode_work_func (SPProtoDecoder *o)
         memcpy(header_hash, hash, o->hash_size);
         memcpy(header_hash, hash, o->hash_size);
         // compare hashes
         // compare hashes
         if (memcmp(hash, hash_calc, o->hash_size)) {
         if (memcmp(hash, hash_calc, o->hash_size)) {
-            DEBUG("packet has wrong hash");
+            BLog(BLOG_WARNING, "packet has wrong hash");
             return;
             return;
         }
         }
     }
     }
@@ -156,7 +159,7 @@ static void decode_work_handler (SPProtoDecoder *o)
     // check OTP
     // check OTP
     if (SPPROTO_HAVE_OTP(o->sp_params) && o->tw_out_len >= 0) {
     if (SPPROTO_HAVE_OTP(o->sp_params) && o->tw_out_len >= 0) {
         if (!OTPChecker_CheckOTP(&o->otpchecker, o->tw_out_seed_id, o->tw_out_otp)) {
         if (!OTPChecker_CheckOTP(&o->otpchecker, o->tw_out_seed_id, o->tw_out_otp)) {
-            DEBUG("packet has wrong OTP");
+            BLog(BLOG_WARNING, "packet has wrong OTP");
             o->tw_out_len = -1;
             o->tw_out_len = -1;
         }
         }
     }
     }

+ 4 - 0
generated/blog_channel_BEncryption.h

@@ -0,0 +1,4 @@
+#ifdef BLOG_CURRENT_CHANNEL
+#undef BLOG_CURRENT_CHANNEL
+#endif
+#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_BEncryption

+ 4 - 0
generated/blog_channel_BIPC.h

@@ -0,0 +1,4 @@
+#ifdef BLOG_CURRENT_CHANNEL
+#undef BLOG_CURRENT_CHANNEL
+#endif
+#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_BIPC

+ 4 - 0
generated/blog_channel_BIPCServer.h

@@ -0,0 +1,4 @@
+#ifdef BLOG_CURRENT_CHANNEL
+#undef BLOG_CURRENT_CHANNEL
+#endif
+#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_BIPCServer

+ 4 - 0
generated/blog_channel_BSocket.h

@@ -0,0 +1,4 @@
+#ifdef BLOG_CURRENT_CHANNEL
+#undef BLOG_CURRENT_CHANNEL
+#endif
+#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_BSocket

+ 4 - 0
generated/blog_channel_BTap.h

@@ -0,0 +1,4 @@
+#ifdef BLOG_CURRENT_CHANNEL
+#undef BLOG_CURRENT_CHANNEL
+#endif
+#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_BTap

+ 4 - 0
generated/blog_channel_BTime.h

@@ -0,0 +1,4 @@
+#ifdef BLOG_CURRENT_CHANNEL
+#undef BLOG_CURRENT_CHANNEL
+#endif
+#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_BTime

+ 4 - 0
generated/blog_channel_LineBuffer.h

@@ -0,0 +1,4 @@
+#ifdef BLOG_CURRENT_CHANNEL
+#undef BLOG_CURRENT_CHANNEL
+#endif
+#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_LineBuffer

+ 4 - 0
generated/blog_channel_NCDConfigParser.h

@@ -0,0 +1,4 @@
+#ifdef BLOG_CURRENT_CHANNEL
+#undef BLOG_CURRENT_CHANNEL
+#endif
+#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_NCDConfigParser

+ 4 - 0
generated/blog_channel_NCDInterfaceMonitor.h

@@ -0,0 +1,4 @@
+#ifdef BLOG_CURRENT_CHANNEL
+#undef BLOG_CURRENT_CHANNEL
+#endif
+#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_NCDInterfaceMonitor

+ 4 - 0
generated/blog_channel_NCDRfkillMonitor.h

@@ -0,0 +1,4 @@
+#ifdef BLOG_CURRENT_CHANNEL
+#undef BLOG_CURRENT_CHANNEL
+#endif
+#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_NCDRfkillMonitor

+ 4 - 0
generated/blog_channel_PasswordListener.h

@@ -0,0 +1,4 @@
+#ifdef BLOG_CURRENT_CHANNEL
+#undef BLOG_CURRENT_CHANNEL
+#endif
+#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_PasswordListener

+ 4 - 0
generated/blog_channel_SPProtoDecoder.h

@@ -0,0 +1,4 @@
+#ifdef BLOG_CURRENT_CHANNEL
+#undef BLOG_CURRENT_CHANNEL
+#endif
+#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_SPProtoDecoder

+ 4 - 0
generated/blog_channel_addr.h

@@ -0,0 +1,4 @@
+#ifdef BLOG_CURRENT_CHANNEL
+#undef BLOG_CURRENT_CHANNEL
+#endif
+#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_addr

+ 4 - 0
generated/blog_channel_lwip.h

@@ -0,0 +1,4 @@
+#ifdef BLOG_CURRENT_CHANNEL
+#undef BLOG_CURRENT_CHANNEL
+#endif
+#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_lwip

+ 4 - 0
generated/blog_channel_nsskey.h

@@ -0,0 +1,4 @@
+#ifdef BLOG_CURRENT_CHANNEL
+#undef BLOG_CURRENT_CHANNEL
+#endif
+#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_nsskey

+ 16 - 1
generated/blog_channels_defines.h

@@ -67,4 +67,19 @@
 #define BLOG_CHANNEL_NCDUdevMonitor 66
 #define BLOG_CHANNEL_NCDUdevMonitor 66
 #define BLOG_CHANNEL_NCDUdevCache 67
 #define BLOG_CHANNEL_NCDUdevCache 67
 #define BLOG_CHANNEL_NCDUdevManager 68
 #define BLOG_CHANNEL_NCDUdevManager 68
-#define BLOG_NUM_CHANNELS 69
+#define BLOG_CHANNEL_BTime 69
+#define BLOG_CHANNEL_BSocket 70
+#define BLOG_CHANNEL_BEncryption 71
+#define BLOG_CHANNEL_SPProtoDecoder 72
+#define BLOG_CHANNEL_LineBuffer 73
+#define BLOG_CHANNEL_BTap 74
+#define BLOG_CHANNEL_lwip 75
+#define BLOG_CHANNEL_NCDConfigParser 76
+#define BLOG_CHANNEL_BIPC 77
+#define BLOG_CHANNEL_BIPCServer 78
+#define BLOG_CHANNEL_nsskey 79
+#define BLOG_CHANNEL_addr 80
+#define BLOG_CHANNEL_PasswordListener 81
+#define BLOG_CHANNEL_NCDInterfaceMonitor 82
+#define BLOG_CHANNEL_NCDRfkillMonitor 83
+#define BLOG_NUM_CHANNELS 84

+ 15 - 0
generated/blog_channels_list.h

@@ -67,3 +67,18 @@
 {.name = "NCDUdevMonitor", .loglevel = 4},
 {.name = "NCDUdevMonitor", .loglevel = 4},
 {.name = "NCDUdevCache", .loglevel = 4},
 {.name = "NCDUdevCache", .loglevel = 4},
 {.name = "NCDUdevManager", .loglevel = 4},
 {.name = "NCDUdevManager", .loglevel = 4},
+{.name = "BTime", .loglevel = 4},
+{.name = "BSocket", .loglevel = 4},
+{.name = "BEncryption", .loglevel = 4},
+{.name = "SPProtoDecoder", .loglevel = 4},
+{.name = "LineBuffer", .loglevel = 4},
+{.name = "BTap", .loglevel = 4},
+{.name = "lwip", .loglevel = 4},
+{.name = "NCDConfigParser", .loglevel = 4},
+{.name = "BIPC", .loglevel = 4},
+{.name = "BIPCServer", .loglevel = 4},
+{.name = "nsskey", .loglevel = 4},
+{.name = "addr", .loglevel = 4},
+{.name = "PasswordListener", .loglevel = 4},
+{.name = "NCDInterfaceMonitor", .loglevel = 4},
+{.name = "NCDRfkillMonitor", .loglevel = 4},

+ 7 - 3
ipc/BIPC.c

@@ -20,8 +20,12 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
  */
 
 
+#include <system/BLog.h>
+
 #include <ipc/BIPC.h>
 #include <ipc/BIPC.h>
 
 
+#include <generated/blog_channel_BIPC.h>
+
 #define COMPONENT_SOURCE 1
 #define COMPONENT_SOURCE 1
 #define COMPONENT_SINK 2
 #define COMPONENT_SINK 2
 #define COMPONENT_DECODER 3
 #define COMPONENT_DECODER 3
@@ -93,13 +97,13 @@ int BIPC_InitConnect (BIPC *o, const char *path, int send_mtu, PacketPassInterfa
     
     
     // init socket
     // init socket
     if (BSocket_Init(&o->sock, reactor, BADDR_TYPE_UNIX, BSOCKET_TYPE_STREAM) < 0) {
     if (BSocket_Init(&o->sock, reactor, BADDR_TYPE_UNIX, BSOCKET_TYPE_STREAM) < 0) {
-        DEBUG("BSocket_Init failed");
+        BLog(BLOG_ERROR, "BSocket_Init failed");
         goto fail0;
         goto fail0;
     }
     }
     
     
     // connect socket
     // connect socket
     if (BSocket_ConnectUnix(&o->sock, path) < 0) {
     if (BSocket_ConnectUnix(&o->sock, path) < 0) {
-        DEBUG("BSocket_ConnectUnix failed (%d)", BSocket_GetError(&o->sock));
+        BLog(BLOG_ERROR, "BSocket_ConnectUnix failed (%d)", BSocket_GetError(&o->sock));
         goto fail1;
         goto fail1;
     }
     }
     
     
@@ -132,7 +136,7 @@ int BIPC_InitAccept (BIPC *o, BIPCServer *server, int send_mtu, PacketPassInterf
     
     
     // accept socket
     // accept socket
     if (!Listener_Accept(&server->listener, &o->sock, NULL)) {
     if (!Listener_Accept(&server->listener, &o->sock, NULL)) {
-        DEBUG("Listener_Accept failed");
+        BLog(BLOG_ERROR, "Listener_Accept failed");
         goto fail0;
         goto fail0;
     }
     }
     
     

+ 7 - 3
ipc/BIPCServer.c

@@ -20,8 +20,12 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
  */
 
 
+#include <system/BLog.h>
+
 #include <ipc/BIPCServer.h>
 #include <ipc/BIPCServer.h>
 
 
+#include <generated/blog_channel_BIPCServer.h>
+
 static void listener_handler (BIPCServer *o)
 static void listener_handler (BIPCServer *o)
 {
 {
     DebugObject_Access(&o->d_obj);
     DebugObject_Access(&o->d_obj);
@@ -38,19 +42,19 @@ int BIPCServer_Init (BIPCServer *o, const char *path, BIPCServer_handler handler
     
     
     // init socket
     // init socket
     if (BSocket_Init(&o->sock, reactor, BADDR_TYPE_UNIX, BSOCKET_TYPE_STREAM) < 0) {
     if (BSocket_Init(&o->sock, reactor, BADDR_TYPE_UNIX, BSOCKET_TYPE_STREAM) < 0) {
-        DEBUG("BSocket_Init failed");
+        BLog(BLOG_ERROR, "BSocket_Init failed");
         goto fail0;
         goto fail0;
     }
     }
     
     
     // bind socket
     // bind socket
     if (BSocket_BindUnix(&o->sock, path) < 0) {
     if (BSocket_BindUnix(&o->sock, path) < 0) {
-        DEBUG("BSocket_BindUnix failed (%d)", BSocket_GetError(&o->sock));
+        BLog(BLOG_ERROR, "BSocket_BindUnix failed (%d)", BSocket_GetError(&o->sock));
         goto fail1;
         goto fail1;
     }
     }
     
     
     // listen socket
     // listen socket
     if (BSocket_Listen(&o->sock, -1) < 0) {
     if (BSocket_Listen(&o->sock, -1) < 0) {
-        DEBUG("BSocket_Listen failed (%d)", BSocket_GetError(&o->sock));
+        BLog(BLOG_ERROR, "BSocket_Listen failed (%d)", BSocket_GetError(&o->sock));
         goto fail1;
         goto fail1;
     }
     }
     
     

+ 4 - 2
lwip/custom/arch/cc.h

@@ -25,10 +25,12 @@
 
 
 #include <inttypes.h>
 #include <inttypes.h>
 #include <stdlib.h>
 #include <stdlib.h>
+#include <stdio.h>
 #include <errno.h>
 #include <errno.h>
 
 
 #include <misc/debug.h>
 #include <misc/debug.h>
 #include <misc/byteorder.h>
 #include <misc/byteorder.h>
+#include <system/BLog.h>
 
 
 #define u8_t uint8_t
 #define u8_t uint8_t
 #define s8_t int8_t
 #define s8_t int8_t
@@ -40,8 +42,8 @@
 
 
 #define PACK_STRUCT_STRUCT __attribute__((packed))
 #define PACK_STRUCT_STRUCT __attribute__((packed))
 
 
-#define LWIP_PLATFORM_DIAG(x) DEBUG x
-#define LWIP_PLATFORM_ASSERT(x) ({ DEBUG("lwip assertion failure: %s", (x)); abort(); })
+#define LWIP_PLATFORM_DIAG(x) { BLog_Append x; BLog_Finish(BLOG_CHANNEL_lwip, BLOG_INFO); }
+#define LWIP_PLATFORM_ASSERT(x) { fprintf(stderr, "%s: lwip assertion failure: %s\n", __FUNCTION__, (x)); abort(); }
 
 
 #define U16_F PRIu16
 #define U16_F PRIu16
 #define S16_F PRId16
 #define S16_F PRId16

+ 6 - 4
misc/nsskey.h

@@ -34,7 +34,9 @@
 #include <keyhi.h>
 #include <keyhi.h>
 #include <pk11func.h>
 #include <pk11func.h>
 
 
-#include <misc/debug.h>
+#include <system/BLog.h>
+
+#include <generated/blog_channel_nsskey.h>
 
 
 /**
 /**
  * Opens a NSS certificate and its private key.
  * Opens a NSS certificate and its private key.
@@ -61,7 +63,7 @@ static SECKEYPrivateKey * find_nss_private_key (char *name)
     for (slot_entry = slot_list->head; !key && slot_entry; slot_entry = slot_entry->next) {
     for (slot_entry = slot_list->head; !key && slot_entry; slot_entry = slot_entry->next) {
         SECKEYPrivateKeyList *key_list = PK11_ListPrivKeysInSlot(slot_entry->slot, name, NULL);
         SECKEYPrivateKeyList *key_list = PK11_ListPrivKeysInSlot(slot_entry->slot, name, NULL);
         if (!key_list) {
         if (!key_list) {
-            DEBUG("PK11_ListPrivKeysInSlot failed");
+            BLog(BLOG_ERROR, "PK11_ListPrivKeysInSlot failed");
             continue;
             continue;
         }
         }
         
         
@@ -90,13 +92,13 @@ int open_nss_cert_and_key (char *name, CERTCertificate **out_cert, SECKEYPrivate
     CERTCertificate *cert;
     CERTCertificate *cert;
     cert = CERT_FindCertByNicknameOrEmailAddr(CERT_GetDefaultCertDB(), name);
     cert = CERT_FindCertByNicknameOrEmailAddr(CERT_GetDefaultCertDB(), name);
     if (!cert) {
     if (!cert) {
-        DEBUG("CERT_FindCertByName failed (%d)", (int)PR_GetError());
+        BLog(BLOG_ERROR, "CERT_FindCertByName failed (%d)", (int)PR_GetError());
         return 0;
         return 0;
     }
     }
     
     
     SECKEYPrivateKey *key = find_nss_private_key(name);
     SECKEYPrivateKey *key = find_nss_private_key(name);
     if (!key) {
     if (!key) {
-        DEBUG("Failed to find private key");
+        BLog(BLOG_ERROR, "Failed to find private key");
         CERT_DestroyCertificate(cert);
         CERT_DestroyCertificate(cert);
         return 0;
         return 0;
     }
     }

+ 9 - 6
ncd/NCDInterfaceMonitor.c

@@ -34,9 +34,12 @@
 
 
 #include <misc/debug.h>
 #include <misc/debug.h>
 #include <misc/nonblocking.h>
 #include <misc/nonblocking.h>
+#include <system/BLog.h>
 
 
 #include <ncd/NCDInterfaceMonitor.h>
 #include <ncd/NCDInterfaceMonitor.h>
 
 
+#include <generated/blog_channel_NCDInterfaceMonitor.h>
+
 static void netlink_fd_handler (NCDInterfaceMonitor *o, int events);
 static void netlink_fd_handler (NCDInterfaceMonitor *o, int events);
 static void process_buffer (NCDInterfaceMonitor *o);
 static void process_buffer (NCDInterfaceMonitor *o);
 static void more_job_handler (NCDInterfaceMonitor *o);
 static void more_job_handler (NCDInterfaceMonitor *o);
@@ -49,7 +52,7 @@ void netlink_fd_handler (NCDInterfaceMonitor *o, int events)
     // read from netlink fd
     // read from netlink fd
     int len = read(o->netlink_fd, o->buf, sizeof(o->buf));
     int len = read(o->netlink_fd, o->buf, sizeof(o->buf));
     if (len < 0) {
     if (len < 0) {
-        DEBUG("read failed");
+        BLog(BLOG_ERROR, "read failed");
         return;
         return;
     }
     }
     
     
@@ -82,7 +85,7 @@ void process_buffer (NCDInterfaceMonitor *o)
         int pl_len = NLMSG_PAYLOAD(o->buf_nh, 0);
         int pl_len = NLMSG_PAYLOAD(o->buf_nh, 0);
         
         
         if (pl_len < sizeof(struct ifinfomsg)) {
         if (pl_len < sizeof(struct ifinfomsg)) {
-            DEBUG("missing infomsg");
+            BLog(BLOG_ERROR, "missing infomsg");
             continue;
             continue;
         }
         }
         struct ifinfomsg *im = (void *)pl;
         struct ifinfomsg *im = (void *)pl;
@@ -143,13 +146,13 @@ int NCDInterfaceMonitor_Init (NCDInterfaceMonitor *o, BReactor *reactor, NCDInte
     
     
     // init netlink fd
     // init netlink fd
     if ((o->netlink_fd = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE)) < 0) {
     if ((o->netlink_fd = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE)) < 0) {
-        DEBUG("socket failed");
+        BLog(BLOG_ERROR, "socket failed");
         goto fail0;
         goto fail0;
     }
     }
     
     
     // set fd non-blocking
     // set fd non-blocking
     if (!badvpn_set_nonblocking(o->netlink_fd)) {
     if (!badvpn_set_nonblocking(o->netlink_fd)) {
-        DEBUG("badvpn_set_nonblocking failed");
+        BLog(BLOG_ERROR, "badvpn_set_nonblocking failed");
         goto fail1;
         goto fail1;
     }
     }
     
     
@@ -159,14 +162,14 @@ int NCDInterfaceMonitor_Init (NCDInterfaceMonitor *o, BReactor *reactor, NCDInte
     sa.nl_family = AF_NETLINK;
     sa.nl_family = AF_NETLINK;
     sa.nl_groups = RTMGRP_LINK;
     sa.nl_groups = RTMGRP_LINK;
     if (bind(o->netlink_fd, (void *)&sa, sizeof(sa)) < 0) {
     if (bind(o->netlink_fd, (void *)&sa, sizeof(sa)) < 0) {
-        DEBUG("bind failed");
+        BLog(BLOG_ERROR, "bind failed");
         goto fail1;
         goto fail1;
     }
     }
     
     
     // init BFileDescriptor
     // init BFileDescriptor
     BFileDescriptor_Init(&o->bfd, o->netlink_fd, (BFileDescriptor_handler)netlink_fd_handler, o);
     BFileDescriptor_Init(&o->bfd, o->netlink_fd, (BFileDescriptor_handler)netlink_fd_handler, o);
     if (!BReactor_AddFileDescriptor(o->reactor, &o->bfd)) {
     if (!BReactor_AddFileDescriptor(o->reactor, &o->bfd)) {
-        DEBUG("BReactor_AddFileDescriptor failed");
+        BLog(BLOG_ERROR, "BReactor_AddFileDescriptor failed");
         goto fail1;
         goto fail1;
     }
     }
     BReactor_SetFileDescriptorEvents(o->reactor, &o->bfd, BREACTOR_READ);
     BReactor_SetFileDescriptorEvents(o->reactor, &o->bfd, BREACTOR_READ);

+ 8 - 5
ncd/NCDRfkillMonitor.c

@@ -27,9 +27,12 @@
 
 
 #include <misc/debug.h>
 #include <misc/debug.h>
 #include <misc/nonblocking.h>
 #include <misc/nonblocking.h>
+#include <system/BLog.h>
 
 
 #include <ncd/NCDRfkillMonitor.h>
 #include <ncd/NCDRfkillMonitor.h>
 
 
+#include <generated/blog_channel_NCDRfkillMonitor.h>
+
 #define RFKILL_DEVICE_NODE "/dev/rfkill"
 #define RFKILL_DEVICE_NODE "/dev/rfkill"
 
 
 static void rfkill_fd_handler (NCDRfkillMonitor *o, int events);
 static void rfkill_fd_handler (NCDRfkillMonitor *o, int events);
@@ -42,11 +45,11 @@ void rfkill_fd_handler (NCDRfkillMonitor *o, int events)
     struct rfkill_event event;
     struct rfkill_event event;
     int len = read(o->rfkill_fd, &event, sizeof(event));
     int len = read(o->rfkill_fd, &event, sizeof(event));
     if (len < 0) {
     if (len < 0) {
-        DEBUG("read failed");
+        BLog(BLOG_ERROR, "read failed");
         return;
         return;
     }
     }
     if (len != sizeof(event)) {
     if (len != sizeof(event)) {
-        DEBUG("read returned wrong length");
+        BLog(BLOG_ERROR, "read returned wrong length");
         return;
         return;
     }
     }
     
     
@@ -64,20 +67,20 @@ int NCDRfkillMonitor_Init (NCDRfkillMonitor *o, BReactor *reactor, NCDRfkillMoni
     
     
     // open rfkill
     // open rfkill
     if ((o->rfkill_fd = open(RFKILL_DEVICE_NODE, O_RDONLY)) < 0) {
     if ((o->rfkill_fd = open(RFKILL_DEVICE_NODE, O_RDONLY)) < 0) {
-        DEBUG("open failed");
+        BLog(BLOG_ERROR, "open failed");
         goto fail0;
         goto fail0;
     }
     }
     
     
     // set fd non-blocking
     // set fd non-blocking
     if (!badvpn_set_nonblocking(o->rfkill_fd)) {
     if (!badvpn_set_nonblocking(o->rfkill_fd)) {
-        DEBUG("badvpn_set_nonblocking failed");
+        BLog(BLOG_ERROR, "badvpn_set_nonblocking failed");
         goto fail1;
         goto fail1;
     }
     }
     
     
     // init BFileDescriptor
     // init BFileDescriptor
     BFileDescriptor_Init(&o->bfd, o->rfkill_fd, (BFileDescriptor_handler)rfkill_fd_handler, o);
     BFileDescriptor_Init(&o->bfd, o->rfkill_fd, (BFileDescriptor_handler)rfkill_fd_handler, o);
     if (!BReactor_AddFileDescriptor(o->reactor, &o->bfd)) {
     if (!BReactor_AddFileDescriptor(o->reactor, &o->bfd)) {
-        DEBUG("BReactor_AddFileDescriptor failed");
+        BLog(BLOG_ERROR, "BReactor_AddFileDescriptor failed");
         goto fail1;
         goto fail1;
     }
     }
     BReactor_SetFileDescriptorEvents(o->reactor, &o->bfd, BREACTOR_READ);
     BReactor_SetFileDescriptorEvents(o->reactor, &o->bfd, BREACTOR_READ);

+ 1 - 0
ncdconfig/CMakeLists.txt

@@ -3,3 +3,4 @@ add_library(ncdconfig
     NCDConfigTokenizer.c
     NCDConfigTokenizer.c
     NCDConfigParser.c
     NCDConfigParser.c
 )
 )
+target_link_libraries(ncdconfig system)

+ 7 - 4
ncdconfig/NCDConfigParser.c

@@ -25,10 +25,13 @@
 #include <string.h>
 #include <string.h>
 
 
 #include <misc/debug.h>
 #include <misc/debug.h>
+#include <system/BLog.h>
 #include <ncdconfig/NCDConfigTokenizer.h>
 #include <ncdconfig/NCDConfigTokenizer.h>
 
 
 #include <ncdconfig/NCDConfigParser.h>
 #include <ncdconfig/NCDConfigParser.h>
 
 
+#include <generated/blog_channel_NCDConfigParser.h>
+
 #include "../generated/NCDConfigParser_parse.c"
 #include "../generated/NCDConfigParser_parse.c"
 #include "../generated/NCDConfigParser_parse.h"
 #include "../generated/NCDConfigParser_parse.h"
 
 
@@ -46,7 +49,7 @@ static int tokenizer_output (void *user, int token, char *value, size_t position
     ASSERT(!state->error)
     ASSERT(!state->error)
     
     
     if (token == NCD_ERROR) {
     if (token == NCD_ERROR) {
-        DEBUG("tokenizer error at %zu", position);
+        BLog(BLOG_ERROR, "tokenizer error at %zu", position);
         state->error = 1;
         state->error = 1;
         return 0;
         return 0;
     }
     }
@@ -122,13 +125,13 @@ static int tokenizer_output (void *user, int token, char *value, size_t position
     
     
     // if we got syntax error, stop parsing
     // if we got syntax error, stop parsing
     if (state->out.syntax_error) {
     if (state->out.syntax_error) {
-        DEBUG("syntax error at %zu", position);
+        BLog(BLOG_ERROR, "syntax error at %zu", position);
         state->error = 1;
         state->error = 1;
         return 0;
         return 0;
     }
     }
     
     
     if (state->out.out_of_memory) {
     if (state->out.out_of_memory) {
-        DEBUG("out of memory at %zu", position);
+        BLog(BLOG_ERROR, "out of memory at %zu", position);
         state->error = 1;
         state->error = 1;
         return 0;
         return 0;
     }
     }
@@ -146,7 +149,7 @@ int NCDConfigParser_Parse (char *config, size_t config_len, struct NCDConfig_int
     state.error = 0;
     state.error = 0;
     
     
     if (!(state.parser = ParseAlloc(malloc))) {
     if (!(state.parser = ParseAlloc(malloc))) {
-        DEBUG("ParseAlloc failed");
+        BLog(BLOG_ERROR, "ParseAlloc failed");
         return 0;
         return 0;
     }
     }
     
     

+ 9 - 6
protocol/addr.h

@@ -35,9 +35,12 @@
 
 
 #include <misc/debug.h>
 #include <misc/debug.h>
 #include <system/BAddr.h>
 #include <system/BAddr.h>
+#include <system/BLog.h>
 
 
 #include <generated/bproto_addr.h>
 #include <generated/bproto_addr.h>
 
 
+#include <generated/blog_channel_addr.h>
+
 #define ADDR_TYPE_IPV4 1
 #define ADDR_TYPE_IPV4 1
 #define ADDR_TYPE_IPV6 2
 #define ADDR_TYPE_IPV6 2
 
 
@@ -145,7 +148,7 @@ int addr_read (uint8_t *data, int data_len, BAddr *out_addr)
     
     
     addrParser parser;
     addrParser parser;
     if (!addrParser_Init(&parser, data, data_len)) {
     if (!addrParser_Init(&parser, data, data_len)) {
-        DEBUG("failed to parse addr");
+        BLog(BLOG_ERROR, "failed to parse addr");
         return 0;
         return 0;
     }
     }
     
     
@@ -156,12 +159,12 @@ int addr_read (uint8_t *data, int data_len, BAddr *out_addr)
         case ADDR_TYPE_IPV4: {
         case ADDR_TYPE_IPV4: {
             uint8_t *port_data;
             uint8_t *port_data;
             if (!addrParser_Getip_port(&parser, &port_data)) {
             if (!addrParser_Getip_port(&parser, &port_data)) {
-                DEBUG("port missing for IPv4 address");
+                BLog(BLOG_ERROR, "port missing for IPv4 address");
                 return 0;
                 return 0;
             }
             }
             uint8_t *addr_data;
             uint8_t *addr_data;
             if (!addrParser_Getipv4_addr(&parser, &addr_data)) {
             if (!addrParser_Getipv4_addr(&parser, &addr_data)) {
-                DEBUG("address missing for IPv4 address");
+                BLog(BLOG_ERROR, "address missing for IPv4 address");
                 return 0;
                 return 0;
             }
             }
             uint16_t port;
             uint16_t port;
@@ -173,12 +176,12 @@ int addr_read (uint8_t *data, int data_len, BAddr *out_addr)
         case ADDR_TYPE_IPV6: {
         case ADDR_TYPE_IPV6: {
             uint8_t *port_data;
             uint8_t *port_data;
             if (!addrParser_Getip_port(&parser, &port_data)) {
             if (!addrParser_Getip_port(&parser, &port_data)) {
-                DEBUG("port missing for IPv6 address");
+                BLog(BLOG_ERROR, "port missing for IPv6 address");
                 return 0;
                 return 0;
             }
             }
             uint8_t *addr_data;
             uint8_t *addr_data;
             if (!addrParser_Getipv6_addr(&parser, &addr_data)) {
             if (!addrParser_Getipv6_addr(&parser, &addr_data)) {
-                DEBUG("address missing for IPv6 address");
+                BLog(BLOG_ERROR, "address missing for IPv6 address");
                 return 0;
                 return 0;
             }
             }
             uint16_t port;
             uint16_t port;
@@ -186,7 +189,7 @@ int addr_read (uint8_t *data, int data_len, BAddr *out_addr)
             BAddr_InitIPv6(out_addr, addr_data, port);
             BAddr_InitIPv6(out_addr, addr_data, port);
         } break;
         } break;
         default:
         default:
-            DEBUG("unknown address type %d", (int)type);
+            BLog(BLOG_ERROR, "unknown address type %d", (int)type);
             return 0;
             return 0;
     }
     }
     
     

+ 7 - 3
security/BEncryption.c

@@ -20,8 +20,12 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
  */
 
 
+#include <system/BLog.h>
+
 #include <security/BEncryption.h>
 #include <security/BEncryption.h>
 
 
+#include <generated/blog_channel_BEncryption.h>
+
 int BEncryption_cipher_valid (int cipher)
 int BEncryption_cipher_valid (int cipher)
 {
 {
     switch (cipher) {
     switch (cipher) {
@@ -78,12 +82,12 @@ void BEncryption_Init (BEncryption *enc, int mode, int cipher, uint8_t *key)
     }
     }
     
     
     if ((enc->cryptodev.fd = open("/dev/crypto", O_RDWR, 0)) < 0) {
     if ((enc->cryptodev.fd = open("/dev/crypto", O_RDWR, 0)) < 0) {
-        DEBUG("failed to open /dev/crypto");
+        BLog(BLOG_ERROR, "failed to open /dev/crypto");
         goto fail1;
         goto fail1;
     }
     }
     
     
     if (ioctl(enc->cryptodev.fd, CRIOGET, &enc->cryptodev.cfd)) {
     if (ioctl(enc->cryptodev.fd, CRIOGET, &enc->cryptodev.cfd)) {
-        DEBUG("failed ioctl(CRIOGET)");
+        BLog(BLOG_ERROR, "failed ioctl(CRIOGET)");
         goto fail2;
         goto fail2;
     }
     }
     
     
@@ -93,7 +97,7 @@ void BEncryption_Init (BEncryption *enc, int mode, int cipher, uint8_t *key)
     sess.keylen = BEncryption_cipher_key_size(enc->cipher);
     sess.keylen = BEncryption_cipher_key_size(enc->cipher);
     sess.key = key;
     sess.key = key;
     if (ioctl(enc->cryptodev.cfd, CIOCGSESSION, &sess)) {
     if (ioctl(enc->cryptodev.cfd, CIOCGSESSION, &sess)) {
-        DEBUG("failed ioctl(CIOCGSESSION)");
+        BLog(BLOG_ERROR, "failed ioctl(CIOCGSESSION)");
         goto fail3;
         goto fail3;
     }
     }
     
     

+ 16 - 13
system/BSocket.c

@@ -45,9 +45,12 @@
 #include <stddef.h>
 #include <stddef.h>
 
 
 #include <misc/debug.h>
 #include <misc/debug.h>
+#include <system/BLog.h>
 
 
 #include <system/BSocket.h>
 #include <system/BSocket.h>
 
 
+#include <generated/blog_channel_BSocket.h>
+
 #define HANDLER_READ 0
 #define HANDLER_READ 0
 #define HANDLER_WRITE 1
 #define HANDLER_WRITE 1
 #define HANDLER_ACCEPT 2
 #define HANDLER_ACCEPT 2
@@ -618,7 +621,7 @@ int BSocket_GlobalInit (void)
     sigemptyset(&act.sa_mask);
     sigemptyset(&act.sa_mask);
     act.sa_flags = 0;
     act.sa_flags = 0;
     if (sigaction(SIGPIPE, &act, NULL) < 0) {
     if (sigaction(SIGPIPE, &act, NULL) < 0) {
-        DEBUG("sigaction failed");
+        BLog(BLOG_ERROR, "sigaction failed");
         goto fail0;
         goto fail0;
     }
     }
     
     
@@ -681,19 +684,19 @@ int BSocket_Init (BSocket *bs, BReactor *bsys, int domain, int type)
     // create socket
     // create socket
     int fd = socket(sys_domain, sys_type, 0);
     int fd = socket(sys_domain, sys_type, 0);
     if (fd < 0) {
     if (fd < 0) {
-        DEBUG("socket() failed");
+        BLog(BLOG_ERROR, "socket() failed");
         goto fail0;
         goto fail0;
     }
     }
 
 
     // set socket nonblocking
     // set socket nonblocking
     if (set_nonblocking(fd) != 0) {
     if (set_nonblocking(fd) != 0) {
-        DEBUG("set_nonblocking failed");
+        BLog(BLOG_ERROR, "set_nonblocking failed");
         goto fail1;
         goto fail1;
     }
     }
     
     
     // set pktinfo if needed
     // set pktinfo if needed
     if (!setup_pktinfo(fd, type, domain)) {
     if (!setup_pktinfo(fd, type, domain)) {
-        DEBUG("setup_pktinfo failed");
+        BLog(BLOG_ERROR, "setup_pktinfo failed");
     }
     }
     
     
     // setup winsock exts
     // setup winsock exts
@@ -719,7 +722,7 @@ int BSocket_Init (BSocket *bs, BReactor *bsys, int domain, int type)
     
     
     // initialize event backend
     // initialize event backend
     if (!init_event_backend(bs)) {
     if (!init_event_backend(bs)) {
-        DEBUG("WARNING: init_event_backend failed");
+        BLog(BLOG_ERROR, "init_event_backend failed");
         goto fail2;
         goto fail2;
     }
     }
     
     
@@ -742,7 +745,7 @@ int BSocket_InitPipe (BSocket *bs, BReactor *bsys, int fd)
 {
 {
     // set socket nonblocking
     // set socket nonblocking
     if (set_nonblocking(fd) != 0) {
     if (set_nonblocking(fd) != 0) {
-        DEBUG("set_nonblocking failed");
+        BLog(BLOG_ERROR, "set_nonblocking failed");
         goto fail0;
         goto fail0;
     }
     }
     
     
@@ -766,7 +769,7 @@ int BSocket_InitPipe (BSocket *bs, BReactor *bsys, int fd)
     
     
     // initialize event backend
     // initialize event backend
     if (!init_event_backend(bs)) {
     if (!init_event_backend(bs)) {
-        DEBUG("WARNING: init_event_backend failed");
+        BLog(BLOG_ERROR, "init_event_backend failed");
         goto fail1;
         goto fail1;
     }
     }
     
     
@@ -1049,7 +1052,7 @@ int BSocket_Bind (BSocket *bs, BAddr *addr)
         int optval = 1;
         int optval = 1;
         #endif
         #endif
         if (setsockopt(bs->socket, SOL_SOCKET, SO_REUSEADDR, (void *)&optval, sizeof(optval)) < 0) {
         if (setsockopt(bs->socket, SOL_SOCKET, SO_REUSEADDR, (void *)&optval, sizeof(optval)) < 0) {
-            DEBUG("WARNING: setsockopt failed");
+            BLog(BLOG_ERROR, "setsockopt failed");
         }
         }
     }
     }
     
     
@@ -1129,13 +1132,13 @@ int BSocket_Accept (BSocket *bs, BSocket *newsock, BAddr *addr)
     } else {
     } else {
         // set nonblocking
         // set nonblocking
         if (set_nonblocking(fd) != 0) {
         if (set_nonblocking(fd) != 0) {
-            DEBUG("WARNING: set_nonblocking failed");
+            BLog(BLOG_ERROR, "set_nonblocking failed");
             goto fail0;
             goto fail0;
         }
         }
         
         
         // set pktinfo if needed
         // set pktinfo if needed
         if (!setup_pktinfo(fd, bs->type, bs->domain)) {
         if (!setup_pktinfo(fd, bs->type, bs->domain)) {
-            DEBUG("setup_pktinfo failed");
+            BLog(BLOG_ERROR, "setup_pktinfo failed");
         }
         }
         
         
         // setup winsock exts
         // setup winsock exts
@@ -1160,7 +1163,7 @@ int BSocket_Accept (BSocket *bs, BSocket *newsock, BAddr *addr)
         BPending_Init(&newsock->connect_job, BReactor_PendingGroup(bs->bsys), (BPending_handler)connect_job_handler, newsock);
         BPending_Init(&newsock->connect_job, BReactor_PendingGroup(bs->bsys), (BPending_handler)connect_job_handler, newsock);
     
     
         if (!init_event_backend(newsock)) {
         if (!init_event_backend(newsock)) {
-            DEBUG("WARNING: init_event_backend failed");
+            BLog(BLOG_ERROR, "init_event_backend failed");
             goto fail1;
             goto fail1;
         }
         }
         
         
@@ -1651,14 +1654,14 @@ static int create_unix_sysaddr (struct sockaddr_un *addr, size_t *addr_len, cons
     size_t path_len = strlen(path);
     size_t path_len = strlen(path);
     
     
     if (path_len == 0) {
     if (path_len == 0) {
-        DEBUG("path empty");
+        BLog(BLOG_ERROR, "path empty");
         return 0;
         return 0;
     }
     }
     
     
     addr->sun_family = AF_UNIX;
     addr->sun_family = AF_UNIX;
     
     
     if (path_len >= sizeof(addr->sun_path)) {
     if (path_len >= sizeof(addr->sun_path)) {
-        DEBUG("path too long");
+        BLog(BLOG_ERROR, "path too long");
         return 0;
         return 0;
     }
     }
     
     

+ 4 - 1
system/BTime.h

@@ -38,6 +38,9 @@
 
 
 #include <misc/debug.h>
 #include <misc/debug.h>
 #include <misc/overflow.h>
 #include <misc/overflow.h>
+#include <system/BLog.h>
+
+#include <generated/blog_channel_BTime.h>
 
 
 typedef int64_t btime_t;
 typedef int64_t btime_t;
 
 
@@ -67,7 +70,7 @@ static void BTime_Init (void)
     
     
     struct timespec ts;
     struct timespec ts;
     if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) {
     if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) {
-        DEBUG("WARNING: CLOCK_MONOTONIC is not available. Timers will be confused by clock changes.");
+        BLog(BLOG_WARNING, "CLOCK_MONOTONIC is not available. Timers will be confused by clock changes.");
         
         
         struct timeval tv;
         struct timeval tv;
         ASSERT_FORCE(gettimeofday(&tv, NULL) == 0)
         ASSERT_FORCE(gettimeofday(&tv, NULL) == 0)

+ 1 - 1
system/BUnixSignal.c

@@ -169,7 +169,7 @@ int BUnixSignal_Init (BUnixSignal *o, BReactor *reactor, sigset_t signals, BUnix
     
     
     // set non-blocking
     // set non-blocking
     if (fcntl(o->signalfd_fd, F_SETFL, O_NONBLOCK) < 0) {
     if (fcntl(o->signalfd_fd, F_SETFL, O_NONBLOCK) < 0) {
-        DEBUG("cannot set non-blocking");
+        BLog(BLOG_ERROR, "cannot set non-blocking");
         goto fail1;
         goto fail1;
     }
     }
     
     

+ 1 - 1
tun2socks/tun2socks.c

@@ -748,7 +748,7 @@ err_t netif_output_func (struct netif *netif, struct pbuf *p, ip_addr_t *ipaddr)
     
     
     uint8_t *out;
     uint8_t *out;
     if (!BufferWriter_StartPacket(&device_write_writer, &out)) {
     if (!BufferWriter_StartPacket(&device_write_writer, &out)) {
-        DEBUG("netif func output: BufferWriter_StartPacket failed");
+        BLog(BLOG_ERROR, "netif func output: BufferWriter_StartPacket failed");
         return ERR_OK;
         return ERR_OK;
     }
     }
     
     

+ 42 - 36
tuntap/BTap.c

@@ -49,8 +49,12 @@
     #endif
     #endif
 #endif
 #endif
 
 
+#include <system/BLog.h>
+
 #include <tuntap/BTap.h>
 #include <tuntap/BTap.h>
 
 
+#include <generated/blog_channel_BTap.h>
+
 static void report_error (BTap *o);
 static void report_error (BTap *o);
 static void input_handler_send (BTap *o, uint8_t *data, int data_len);
 static void input_handler_send (BTap *o, uint8_t *data, int data_len);
 static void output_handler_recv (BTap *o, uint8_t *data);
 static void output_handler_recv (BTap *o, uint8_t *data);
@@ -70,17 +74,17 @@ static int try_send (BTap *o, uint8_t *data, int data_len)
             // write pending
             // write pending
             return 0;
             return 0;
         }
         }
-        DEBUG("WARNING: WriteFile failed (%u)", error);
+        BLog(BLOG_WARNING, "WriteFile failed (%u)", error);
         return 1;
         return 1;
     }
     }
     
     
     // read result
     // read result
     DWORD bytes;
     DWORD bytes;
     if (!GetOverlappedResult(o->device, &o->input_ol, &bytes, FALSE)) {
     if (!GetOverlappedResult(o->device, &o->input_ol, &bytes, FALSE)) {
-        DEBUG("WARNING: GetOverlappedResult failed (%u)", GetLastError());
+        BLog(BLOG_WARNING, "GetOverlappedResult failed (%u)", GetLastError());
     }
     }
     else if (bytes != data_len) {
     else if (bytes != data_len) {
-        DEBUG("WARNING: written %d expected %d", (int)bytes, data_len);
+        BLog(BLOG_WARNING, "written %d expected %d", (int)bytes, data_len);
     }
     }
     
     
     // reset event
     // reset event
@@ -103,7 +107,7 @@ static int try_recv (BTap *o, uint8_t *data, int *data_len)
             return 0;
             return 0;
         }
         }
         
         
-        DEBUG("ReadFile failed (%u)", error);
+        BLog(BLOG_ERROR, "ReadFile failed (%u)", error);
         
         
         // fatal error
         // fatal error
         return -1;
         return -1;
@@ -112,7 +116,7 @@ static int try_recv (BTap *o, uint8_t *data, int *data_len)
     // read result
     // read result
     DWORD bytes;
     DWORD bytes;
     if (!GetOverlappedResult(o->device, &o->output_ol, &bytes, FALSE)) {
     if (!GetOverlappedResult(o->device, &o->output_ol, &bytes, FALSE)) {
-        DEBUG("GetOverlappedResult (output) failed (%u)", GetLastError());
+        BLog(BLOG_ERROR, "GetOverlappedResult (output) failed (%u)", GetLastError());
         
         
         // fatal error
         // fatal error
         return -1;
         return -1;
@@ -139,9 +143,9 @@ static void write_handle_handler (BTap *o)
     // read result
     // read result
     DWORD bytes;
     DWORD bytes;
     if (!GetOverlappedResult(o->device, &o->input_ol, &bytes, FALSE)) {
     if (!GetOverlappedResult(o->device, &o->input_ol, &bytes, FALSE)) {
-        DEBUG("WARNING: GetOverlappedResult (input) failed (%u)", GetLastError());
+        BLog(BLOG_WARNING, "GetOverlappedResult (input) failed (%u)", GetLastError());
     } else if (bytes != o->input_packet_len) {
     } else if (bytes != o->input_packet_len) {
-        DEBUG("WARNING: written %d expected %d", (int)bytes, o->input_packet_len);
+        BLog(BLOG_WARNING, "written %d expected %d", (int)bytes, o->input_packet_len);
     }
     }
     
     
     // set no input packet
     // set no input packet
@@ -166,7 +170,7 @@ static void read_handle_handler (BTap *o)
     DWORD dbytes;
     DWORD dbytes;
     if (!GetOverlappedResult(o->device, &o->output_ol, &dbytes, FALSE)) {
     if (!GetOverlappedResult(o->device, &o->output_ol, &dbytes, FALSE)) {
         DWORD error = GetLastError();
         DWORD error = GetLastError();
-        DEBUG("GetOverlappedResult (output) failed (%u)", error);
+        BLog(BLOG_ERROR, "GetOverlappedResult (output) failed (%u)", error);
         
         
         // set no output packet (so that BTap_Free doesn't try getting the result again)
         // set no output packet (so that BTap_Free doesn't try getting the result again)
         o->output_packet = NULL;
         o->output_packet = NULL;
@@ -202,7 +206,7 @@ static void fd_handler (BTap *o, int events)
     DebugObject_Access(&o->d_obj);
     DebugObject_Access(&o->d_obj);
     
     
     if (events&BREACTOR_ERROR) {
     if (events&BREACTOR_ERROR) {
-        DEBUG("WARNING: device fd reports error?");
+        BLog(BLOG_WARNING, "device fd reports error?");
     }
     }
     
     
     if (events&BREACTOR_WRITE) do {
     if (events&BREACTOR_WRITE) do {
@@ -218,7 +222,7 @@ static void fd_handler (BTap *o, int events)
             // the packet was accepeted
             // the packet was accepeted
         } else {
         } else {
             if (bytes != o->input_packet_len) {
             if (bytes != o->input_packet_len) {
-                DEBUG("WARNING: written %d expected %d", bytes, o->input_packet_len);
+                BLog(BLOG_WARNING, "written %d expected %d", bytes, o->input_packet_len);
             }
             }
         }
         }
         
         
@@ -308,7 +312,7 @@ void input_handler_send (BTap *o, uint8_t *data, int data_len)
         // the packet was accepeted
         // the packet was accepeted
     } else {
     } else {
         if (bytes != data_len) {
         if (bytes != data_len) {
-            DEBUG("WARNING: written %d expected %d", bytes, data_len);
+            BLog(BLOG_WARNING, "written %d expected %d", bytes, data_len);
         }
         }
     }
     }
     
     
@@ -380,7 +384,7 @@ int BTap_Init (BTap *o, BReactor *reactor, char *devname, BTap_handler_error han
     // parse device specification
     // parse device specification
     
     
     if (!devname) {
     if (!devname) {
-        DEBUG("no device specification provided");
+        BLog(BLOG_ERROR, "no device specification provided");
         return 0;
         return 0;
     }
     }
     
     
@@ -392,12 +396,12 @@ int BTap_Init (BTap *o, BReactor *reactor, char *devname, BTap_handler_error han
     
     
     if (tun) {
     if (tun) {
         if (!tapwin32_parse_tun_spec(devname, device_component_id, device_name, tun_addrs)) {
         if (!tapwin32_parse_tun_spec(devname, device_component_id, device_name, tun_addrs)) {
-            DEBUG("failed to parse TUN device specification");
+            BLog(BLOG_ERROR, "failed to parse TUN device specification");
             return 0;
             return 0;
         }
         }
     } else {
     } else {
         if (!tapwin32_parse_tap_spec(devname, device_component_id, device_name)) {
         if (!tapwin32_parse_tap_spec(devname, device_component_id, device_name)) {
-            DEBUG("failed to parse TAP device specification");
+            BLog(BLOG_ERROR, "failed to parse TAP device specification");
             return 0;
             return 0;
         }
         }
     }
     }
@@ -406,20 +410,20 @@ int BTap_Init (BTap *o, BReactor *reactor, char *devname, BTap_handler_error han
     
     
     char device_path[TAPWIN32_MAX_REG_SIZE];
     char device_path[TAPWIN32_MAX_REG_SIZE];
     
     
-    DEBUG("Looking for TAP-Win32 with component ID %s, name %s", device_component_id, device_name);
+    BLog(BLOG_INFO, "Looking for TAP-Win32 with component ID %s, name %s", device_component_id, device_name);
     
     
     if (!tapwin32_find_device(device_component_id, device_name, &device_path)) {
     if (!tapwin32_find_device(device_component_id, device_name, &device_path)) {
-        DEBUG("Could not find device");
+        BLog(BLOG_ERROR, "Could not find device");
         goto fail0;
         goto fail0;
     }
     }
     
     
     // open device
     // open device
     
     
-    DEBUG("Opening device %s", device_path);
+    BLog(BLOG_INFO, "Opening device %s", device_path);
     
     
     o->device = CreateFile(device_path, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM|FILE_FLAG_OVERLAPPED, 0);
     o->device = CreateFile(device_path, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM|FILE_FLAG_OVERLAPPED, 0);
     if (o->device == INVALID_HANDLE_VALUE) {
     if (o->device == INVALID_HANDLE_VALUE) {
-        DEBUG("CreateFile failed");
+        BLog(BLOG_ERROR, "CreateFile failed");
         goto fail0;
         goto fail0;
     }
     }
     
     
@@ -429,7 +433,7 @@ int BTap_Init (BTap *o, BReactor *reactor, char *devname, BTap_handler_error han
     
     
     if (tun) {
     if (tun) {
         if (!DeviceIoControl(o->device, TAP_IOCTL_CONFIG_TUN, tun_addrs, sizeof(tun_addrs), tun_addrs, sizeof(tun_addrs), &len, NULL)) {
         if (!DeviceIoControl(o->device, TAP_IOCTL_CONFIG_TUN, tun_addrs, sizeof(tun_addrs), tun_addrs, sizeof(tun_addrs), &len, NULL)) {
-            DEBUG("DeviceIoControl(TAP_IOCTL_CONFIG_TUN) failed");
+            BLog(BLOG_ERROR, "DeviceIoControl(TAP_IOCTL_CONFIG_TUN) failed");
             goto fail1;
             goto fail1;
         }
         }
     }
     }
@@ -442,7 +446,7 @@ int BTap_Init (BTap *o, BReactor *reactor, char *devname, BTap_handler_error han
         ULONG umtu;
         ULONG umtu;
         
         
         if (!DeviceIoControl(o->device, TAP_IOCTL_GET_MTU, NULL, 0, &umtu, sizeof(umtu), &len, NULL)) {
         if (!DeviceIoControl(o->device, TAP_IOCTL_GET_MTU, NULL, 0, &umtu, sizeof(umtu), &len, NULL)) {
-            DEBUG("DeviceIoControl(TAP_IOCTL_GET_MTU) failed");
+            BLog(BLOG_ERROR, "DeviceIoControl(TAP_IOCTL_GET_MTU) failed");
             goto fail1;
             goto fail1;
         }
         }
         
         
@@ -453,21 +457,21 @@ int BTap_Init (BTap *o, BReactor *reactor, char *devname, BTap_handler_error han
     
     
     ULONG upstatus = TRUE;
     ULONG upstatus = TRUE;
     if (!DeviceIoControl(o->device, TAP_IOCTL_SET_MEDIA_STATUS, &upstatus, sizeof(upstatus), &upstatus, sizeof(upstatus), &len, NULL)) {
     if (!DeviceIoControl(o->device, TAP_IOCTL_SET_MEDIA_STATUS, &upstatus, sizeof(upstatus), &upstatus, sizeof(upstatus), &len, NULL)) {
-        DEBUG("DeviceIoControl(TAP_IOCTL_SET_MEDIA_STATUS) failed");
+        BLog(BLOG_ERROR, "DeviceIoControl(TAP_IOCTL_SET_MEDIA_STATUS) failed");
         goto fail1;
         goto fail1;
     }
     }
     
     
-    DEBUG("Device opened");
+    BLog(BLOG_INFO, "Device opened");
     
     
     // init input/output
     // init input/output
     
     
     if (!(o->input_event = CreateEvent(NULL, TRUE, FALSE, NULL))) {
     if (!(o->input_event = CreateEvent(NULL, TRUE, FALSE, NULL))) {
-        DEBUG("CreateEvent failed");
+        BLog(BLOG_ERROR, "CreateEvent failed");
         goto fail1;
         goto fail1;
     }
     }
     
     
     if (!(o->output_event = CreateEvent(NULL, TRUE, FALSE, NULL))) {
     if (!(o->output_event = CreateEvent(NULL, TRUE, FALSE, NULL))) {
-        DEBUG("CreateEvent failed");
+        BLog(BLOG_ERROR, "CreateEvent failed");
         goto fail2;
         goto fail2;
     }
     }
     
     
@@ -475,9 +479,11 @@ int BTap_Init (BTap *o, BReactor *reactor, char *devname, BTap_handler_error han
     BHandle_Init(&o->output_bhandle, o->output_event, (BHandle_handler)read_handle_handler, o);
     BHandle_Init(&o->output_bhandle, o->output_event, (BHandle_handler)read_handle_handler, o);
     
     
     if (!BReactor_AddHandle(o->reactor, &o->input_bhandle)) {
     if (!BReactor_AddHandle(o->reactor, &o->input_bhandle)) {
+        BLog(BLOG_ERROR, "BReactor_AddHandle failed");
         goto fail3;
         goto fail3;
     }
     }
     if (!BReactor_AddHandle(o->reactor, &o->output_bhandle)) {
     if (!BReactor_AddHandle(o->reactor, &o->output_bhandle)) {
+        BLog(BLOG_ERROR, "BReactor_AddHandle failed");
         goto fail4;
         goto fail4;
     }
     }
     
     
@@ -503,7 +509,7 @@ fail0:
     // open device
     // open device
     
     
     if ((o->fd = open("/dev/net/tun", O_RDWR)) < 0) {
     if ((o->fd = open("/dev/net/tun", O_RDWR)) < 0) {
-        DEBUG("error opening device");
+        BLog(BLOG_ERROR, "error opening device");
         goto fail0;
         goto fail0;
     }
     }
     
     
@@ -522,7 +528,7 @@ fail0:
     }
     }
     
     
     if (ioctl(o->fd, TUNSETIFF, (void *)&ifr) < 0) {
     if (ioctl(o->fd, TUNSETIFF, (void *)&ifr) < 0) {
-        DEBUG("error configuring device");
+        BLog(BLOG_ERROR, "error configuring device");
         goto fail1;
         goto fail1;
     }
     }
     
     
@@ -533,12 +539,12 @@ fail0:
     #ifdef BADVPN_FREEBSD
     #ifdef BADVPN_FREEBSD
     
     
     if (tun) {
     if (tun) {
-        DEBUG("TUN not supported on FreeBSD");
+        BLog(BLOG_ERROR, "TUN not supported on FreeBSD");
         goto fail0;
         goto fail0;
     }
     }
     
     
     if (!devname) {
     if (!devname) {
-        DEBUG("no device specified");
+        BLog(BLOG_ERROR, "no device specified");
         goto fail0;
         goto fail0;
     }
     }
     
     
@@ -548,7 +554,7 @@ fail0:
     snprintf(devnode, sizeof(devnode), "/dev/%s", devname);
     snprintf(devnode, sizeof(devnode), "/dev/%s", devname);
     
     
     if ((o->fd = open(devnode, O_RDWR)) < 0) {
     if ((o->fd = open(devnode, O_RDWR)) < 0) {
-        DEBUG("error opening device");
+        BLog(BLOG_ERROR, "error opening device");
         goto fail0;
         goto fail0;
     }
     }
     
     
@@ -557,7 +563,7 @@ fail0:
     struct ifreq ifr;
     struct ifreq ifr;
     memset(&ifr, 0, sizeof(ifr));
     memset(&ifr, 0, sizeof(ifr));
     if (ioctl(o->fd, TAPGIFNAME, (void *)&ifr) < 0) {
     if (ioctl(o->fd, TAPGIFNAME, (void *)&ifr) < 0) {
-        DEBUG("error configuring device");
+        BLog(BLOG_ERROR, "error configuring device");
         goto fail1;
         goto fail1;
     }
     }
     
     
@@ -572,7 +578,7 @@ fail0:
         // open dummy socket for ioctls
         // open dummy socket for ioctls
         int sock = socket(AF_INET, SOCK_DGRAM, 0);
         int sock = socket(AF_INET, SOCK_DGRAM, 0);
         if (sock < 0) {
         if (sock < 0) {
-            DEBUG("socket failed");
+            BLog(BLOG_ERROR, "socket failed");
             goto fail1;
             goto fail1;
         }
         }
         
         
@@ -580,7 +586,7 @@ fail0:
         strcpy(ifr.ifr_name, o->devname);
         strcpy(ifr.ifr_name, o->devname);
         
         
         if (ioctl(sock, SIOCGIFMTU, (void *)&ifr) < 0) {
         if (ioctl(sock, SIOCGIFMTU, (void *)&ifr) < 0) {
-            DEBUG("error getting MTU");
+            BLog(BLOG_ERROR, "error getting MTU");
             close(sock);
             close(sock);
             goto fail1;
             goto fail1;
         }
         }
@@ -592,14 +598,14 @@ fail0:
     
     
     // set non-blocking
     // set non-blocking
     if (fcntl(o->fd, F_SETFL, O_NONBLOCK) < 0) {
     if (fcntl(o->fd, F_SETFL, O_NONBLOCK) < 0) {
-        DEBUG("cannot set non-blocking");
+        BLog(BLOG_ERROR, "cannot set non-blocking");
         goto fail1;
         goto fail1;
     }
     }
     
     
     // init file descriptor object
     // init file descriptor object
     BFileDescriptor_Init(&o->bfd, o->fd, (BFileDescriptor_handler)fd_handler, o);
     BFileDescriptor_Init(&o->bfd, o->fd, (BFileDescriptor_handler)fd_handler, o);
     if (!BReactor_AddFileDescriptor(o->reactor, &o->bfd)) {
     if (!BReactor_AddFileDescriptor(o->reactor, &o->bfd)) {
-        DEBUG("BReactor_AddFileDescriptor failed");
+        BLog(BLOG_ERROR, "BReactor_AddFileDescriptor failed");
         goto fail1;
         goto fail1;
     }
     }
     o->poll_events = 0;
     o->poll_events = 0;
@@ -653,7 +659,7 @@ void BTap_Free (BTap *o)
         if (!GetOverlappedResult(o->device, &o->input_ol, &bytes, TRUE)) {
         if (!GetOverlappedResult(o->device, &o->input_ol, &bytes, TRUE)) {
             error = GetLastError();
             error = GetLastError();
             if (error != ERROR_OPERATION_ABORTED) {
             if (error != ERROR_OPERATION_ABORTED) {
-                DEBUG("WARNING: GetOverlappedResult (input) failed (%u)", error);
+                BLog(BLOG_WARNING, "GetOverlappedResult (input) failed (%u)", error);
             }
             }
         }
         }
     }
     }
@@ -661,7 +667,7 @@ void BTap_Free (BTap *o)
         if (!GetOverlappedResult(o->device, &o->output_ol, &bytes, TRUE)) {
         if (!GetOverlappedResult(o->device, &o->output_ol, &bytes, TRUE)) {
             error = GetLastError();
             error = GetLastError();
             if (error != ERROR_OPERATION_ABORTED) {
             if (error != ERROR_OPERATION_ABORTED) {
-                DEBUG("WARNING: GetOverlappedResult (output) failed (%u)", error);
+                BLog(BLOG_WARNING, "GetOverlappedResult (output) failed (%u)", error);
             }
             }
         }
         }
     }
     }