wireguard-go-bridge: simplify logging and remove tags
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
d2f3a29f45
commit
2a9c7e4745
|
@ -133,7 +133,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
private func configureLogger() {
|
private func configureLogger() {
|
||||||
wgSetLogger { (level, tagCStr, msgCStr) in
|
wgSetLogger { (level, msgCStr) in
|
||||||
let logType: OSLogType
|
let logType: OSLogType
|
||||||
switch level {
|
switch level {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -145,9 +145,8 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||||
default:
|
default:
|
||||||
logType = .default
|
logType = .default
|
||||||
}
|
}
|
||||||
let tag = (tagCStr != nil) ? String(cString: tagCStr!) : ""
|
|
||||||
let msg = (msgCStr != nil) ? String(cString: msgCStr!) : ""
|
let msg = (msgCStr != nil) ? String(cString: msgCStr!) : ""
|
||||||
os_log("wg log: %{public}s: %{public}s", log: OSLog.default, type: logType, tag, msg)
|
os_log("%{public}s", log: OSLog.default, type: logType, msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,9 +27,9 @@ ssize_t do_write(void *ctx, unsigned char *buf, size_t len)
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_log(int level, const char *tag, const char *msg)
|
void do_log(int level, const char *msg)
|
||||||
{
|
{
|
||||||
printf("Log level %d for %s: %s", level, tag, msg);
|
printf("Log level %d: %s", level, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
|
|
|
@ -7,9 +7,9 @@ package main
|
||||||
|
|
||||||
// #include <stdlib.h>
|
// #include <stdlib.h>
|
||||||
// #include <sys/types.h>
|
// #include <sys/types.h>
|
||||||
// static void callLogger(void *func, int level, const char *tag, const char *msg)
|
// static void callLogger(void *func, int level, const char *msg)
|
||||||
// {
|
// {
|
||||||
// ((void(*)(int, const char *, const char *))func)(level, tag, msg);
|
// ((void(*)(int, const char *))func)(level, msg);
|
||||||
// }
|
// }
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
|
@ -40,10 +40,8 @@ func (l *CLogger) Write(p []byte) (int, error) {
|
||||||
if uintptr(loggerFunc) == 0 {
|
if uintptr(loggerFunc) == 0 {
|
||||||
return 0, errors.New("No logger initialized")
|
return 0, errors.New("No logger initialized")
|
||||||
}
|
}
|
||||||
tag := C.CString("WireGuard/GoBackend/"+l.interfaceName)
|
message := C.CString(l.interfaceName + ": " + string(p))
|
||||||
message := C.CString(string(p))
|
C.callLogger(loggerFunc, l.level, message)
|
||||||
C.callLogger(loggerFunc, l.level, tag, message)
|
|
||||||
C.free(unsafe.Pointer(tag))
|
|
||||||
C.free(unsafe.Pointer(message))
|
C.free(unsafe.Pointer(message))
|
||||||
return len(p), nil
|
return len(p), nil
|
||||||
}
|
}
|
||||||
|
@ -64,9 +62,7 @@ func init() {
|
||||||
n := runtime.Stack(buf, true)
|
n := runtime.Stack(buf, true)
|
||||||
buf[n] = 0
|
buf[n] = 0
|
||||||
if uintptr(loggerFunc) != 0 {
|
if uintptr(loggerFunc) != 0 {
|
||||||
tag := C.CString("WireGuard/GoBackend/Stacktrace")
|
C.callLogger(loggerFunc, 0, (*_Ctype_char)(unsafe.Pointer(&buf[0])))
|
||||||
C.callLogger(loggerFunc, 0, tag, (*_Ctype_char)(unsafe.Pointer(&buf[0])))
|
|
||||||
C.free(unsafe.Pointer(tag))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
typedef struct { const char *p; size_t n; } gostring_t;
|
typedef struct { const char *p; size_t n; } gostring_t;
|
||||||
typedef ssize_t(*read_write_fn_t)(void *ctx, unsigned char *buf, size_t len);
|
typedef ssize_t(*read_write_fn_t)(void *ctx, unsigned char *buf, size_t len);
|
||||||
typedef void(*logger_fn_t)(int level, const char *tag, const char *msg);
|
typedef void(*logger_fn_t)(int level, const char *msg);
|
||||||
extern void wgSetLogger(logger_fn_t logger_fn);
|
extern void wgSetLogger(logger_fn_t logger_fn);
|
||||||
extern int wgTurnOn(gostring_t ifname, gostring_t settings, uint16_t mtu, read_write_fn_t read_fn, read_write_fn_t write_fn, void *ctx);
|
extern int wgTurnOn(gostring_t ifname, gostring_t settings, uint16_t mtu, read_write_fn_t read_fn, read_write_fn_t write_fn, void *ctx);
|
||||||
extern void wgTurnOff(int handle);
|
extern void wgTurnOff(int handle);
|
||||||
|
|
Loading…
Reference in New Issue