mirror of
https://github.com/luckfox-eng29/kvm.git
synced 2026-01-18 11:38:32 +01:00
feat: Adds IPv6 disabling feature (#803)
* Allow disabling IPv6 Simply ignores any IPv6 addresses in the lease and doesn't offer them to the RPC Also fixed display issue for IPv6 link local address. Fixes https://github.com/orgs/jetkvm/projects/7/views/1?pane=issue&itemId=122761546&issue=jetkvm%7Ckvm%7C685 * Don't listen on disabled addresses in mDNS or web server. * We have to set the IPv4 and IPv6 modes on the server.
This commit is contained in:
25
web.go
25
web.go
@@ -562,14 +562,31 @@ func RunWebServer() {
|
||||
r := setupRouter()
|
||||
|
||||
// Determine the binding address based on the config
|
||||
bindAddress := ":80" // Default to all interfaces
|
||||
var bindAddress string
|
||||
listenPort := 80 // default port
|
||||
useIPv4 := config.NetworkConfig.IPv4Mode.String != "disabled"
|
||||
useIPv6 := config.NetworkConfig.IPv6Mode.String != "disabled"
|
||||
|
||||
if config.LocalLoopbackOnly {
|
||||
bindAddress = "localhost:80" // Loopback only (both IPv4 and IPv6)
|
||||
if useIPv4 && useIPv6 {
|
||||
bindAddress = fmt.Sprintf("localhost:%d", listenPort)
|
||||
} else if useIPv4 {
|
||||
bindAddress = fmt.Sprintf("127.0.0.1:%d", listenPort)
|
||||
} else if useIPv6 {
|
||||
bindAddress = fmt.Sprintf("[::1]:%d", listenPort)
|
||||
}
|
||||
} else {
|
||||
if useIPv4 && useIPv6 {
|
||||
bindAddress = fmt.Sprintf(":%d", listenPort)
|
||||
} else if useIPv4 {
|
||||
bindAddress = fmt.Sprintf("0.0.0.0:%d", listenPort)
|
||||
} else if useIPv6 {
|
||||
bindAddress = fmt.Sprintf("[::]:%d", listenPort)
|
||||
}
|
||||
}
|
||||
|
||||
logger.Info().Str("bindAddress", bindAddress).Bool("loopbackOnly", config.LocalLoopbackOnly).Msg("Starting web server")
|
||||
err := r.Run(bindAddress)
|
||||
if err != nil {
|
||||
if err := r.Run(bindAddress); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user