-
-
Notifications
You must be signed in to change notification settings - Fork 506
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into use-offload
- Loading branch information
Showing
26 changed files
with
422 additions
and
933 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package peer | ||
|
||
import ( | ||
"net" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func remoteConnNil(log *log.Entry, conn net.Conn) bool { | ||
if conn == nil { | ||
log.Errorf("ice conn is nil") | ||
return true | ||
} | ||
|
||
if conn.RemoteAddr() == nil { | ||
log.Errorf("ICE remote address is nil") | ||
return true | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//go:build !windows | ||
|
||
package server | ||
|
||
func handlePanicLog() error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package server | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"syscall" | ||
|
||
log "github.com/sirupsen/logrus" | ||
|
||
"github.com/netbirdio/netbird/util" | ||
) | ||
|
||
const ( | ||
windowsPanicLogEnvVar = "NB_WINDOWS_PANIC_LOG" | ||
// STD_ERROR_HANDLE ((DWORD)-12) = 4294967284 | ||
stdErrorHandle = ^uintptr(11) | ||
) | ||
|
||
var ( | ||
kernel32 = syscall.NewLazyDLL("kernel32.dll") | ||
|
||
// https://learn.microsoft.com/en-us/windows/console/setstdhandle | ||
setStdHandleFn = kernel32.NewProc("SetStdHandle") | ||
) | ||
|
||
func handlePanicLog() error { | ||
logPath := os.Getenv(windowsPanicLogEnvVar) | ||
if logPath == "" { | ||
return nil | ||
} | ||
|
||
// Ensure the directory exists | ||
logDir := filepath.Dir(logPath) | ||
if err := os.MkdirAll(logDir, 0750); err != nil { | ||
return fmt.Errorf("create panic log directory: %w", err) | ||
} | ||
if err := util.EnforcePermission(logPath); err != nil { | ||
return fmt.Errorf("enforce permission on panic log file: %w", err) | ||
} | ||
|
||
// Open log file with append mode | ||
f, err := os.OpenFile(logPath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644) | ||
if err != nil { | ||
return fmt.Errorf("open panic log file: %w", err) | ||
} | ||
|
||
// Redirect stderr to the file | ||
if err = redirectStderr(f); err != nil { | ||
if closeErr := f.Close(); closeErr != nil { | ||
log.Warnf("failed to close file after redirect error: %v", closeErr) | ||
} | ||
return fmt.Errorf("redirect stderr: %w", err) | ||
} | ||
|
||
log.Infof("successfully configured panic logging to: %s", logPath) | ||
return nil | ||
} | ||
|
||
// redirectStderr redirects stderr to the provided file | ||
func redirectStderr(f *os.File) error { | ||
// Get the current process's stderr handle | ||
if err := setStdHandle(f); err != nil { | ||
return fmt.Errorf("failed to set stderr handle: %w", err) | ||
} | ||
|
||
// Also set os.Stderr for Go's standard library | ||
os.Stderr = f | ||
|
||
return nil | ||
} | ||
|
||
func setStdHandle(f *os.File) error { | ||
handle := f.Fd() | ||
r0, _, e1 := setStdHandleFn.Call(stdErrorHandle, handle) | ||
if r0 == 0 { | ||
if e1 != nil { | ||
return e1 | ||
} | ||
return syscall.EINVAL | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.