Skip to content

Commit fb2ae84

Browse files
committed
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
1 parent 3ec2432 commit fb2ae84

File tree

6 files changed

+126
-120
lines changed

6 files changed

+126
-120
lines changed

internal/network/netif.go

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ func (s *NetworkInterfaceState) update() (DhcpTargetState, error) {
239239
ipv4Addresses = append(ipv4Addresses, addr.IP)
240240
ipv4AddressesString = append(ipv4AddressesString, addr.IPNet.String())
241241
} else if addr.IP.To16() != nil {
242+
if s.config.IPv6Mode.String == "disabled" {
243+
continue
244+
}
245+
242246
scopedLogger := s.l.With().Str("ipv6", addr.IP.String()).Logger()
243247
// check if it's a link local address
244248
if addr.IP.IsLinkLocalUnicast() {
@@ -287,35 +291,37 @@ func (s *NetworkInterfaceState) update() (DhcpTargetState, error) {
287291
}
288292
s.ipv4Addresses = ipv4AddressesString
289293

290-
if ipv6LinkLocal != nil {
291-
if s.ipv6LinkLocal == nil || s.ipv6LinkLocal.String() != ipv6LinkLocal.String() {
292-
scopedLogger := s.l.With().Str("ipv6", ipv6LinkLocal.String()).Logger()
293-
if s.ipv6LinkLocal != nil {
294-
scopedLogger.Info().
295-
Str("old_ipv6", s.ipv6LinkLocal.String()).
296-
Msg("IPv6 link local address changed")
297-
} else {
298-
scopedLogger.Info().Msg("IPv6 link local address found")
294+
if s.config.IPv6Mode.String != "disabled" {
295+
if ipv6LinkLocal != nil {
296+
if s.ipv6LinkLocal == nil || s.ipv6LinkLocal.String() != ipv6LinkLocal.String() {
297+
scopedLogger := s.l.With().Str("ipv6", ipv6LinkLocal.String()).Logger()
298+
if s.ipv6LinkLocal != nil {
299+
scopedLogger.Info().
300+
Str("old_ipv6", s.ipv6LinkLocal.String()).
301+
Msg("IPv6 link local address changed")
302+
} else {
303+
scopedLogger.Info().Msg("IPv6 link local address found")
304+
}
305+
s.ipv6LinkLocal = ipv6LinkLocal
306+
changed = true
299307
}
300-
s.ipv6LinkLocal = ipv6LinkLocal
301-
changed = true
302308
}
303-
}
304-
s.ipv6Addresses = ipv6Addresses
305-
306-
if len(ipv6Addresses) > 0 {
307-
// compare the addresses to see if there's a change
308-
if s.ipv6Addr == nil || s.ipv6Addr.String() != ipv6Addresses[0].Address.String() {
309-
scopedLogger := s.l.With().Str("ipv6", ipv6Addresses[0].Address.String()).Logger()
310-
if s.ipv6Addr != nil {
311-
scopedLogger.Info().
312-
Str("old_ipv6", s.ipv6Addr.String()).
313-
Msg("IPv6 address changed")
314-
} else {
315-
scopedLogger.Info().Msg("IPv6 address found")
309+
s.ipv6Addresses = ipv6Addresses
310+
311+
if len(ipv6Addresses) > 0 {
312+
// compare the addresses to see if there's a change
313+
if s.ipv6Addr == nil || s.ipv6Addr.String() != ipv6Addresses[0].Address.String() {
314+
scopedLogger := s.l.With().Str("ipv6", ipv6Addresses[0].Address.String()).Logger()
315+
if s.ipv6Addr != nil {
316+
scopedLogger.Info().
317+
Str("old_ipv6", s.ipv6Addr.String()).
318+
Msg("IPv6 address changed")
319+
} else {
320+
scopedLogger.Info().Msg("IPv6 address found")
321+
}
322+
s.ipv6Addr = &ipv6Addresses[0].Address
323+
changed = true
316324
}
317-
s.ipv6Addr = &ipv6Addresses[0].Address
318-
changed = true
319325
}
320326
}
321327

internal/network/rpc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (s *NetworkInterfaceState) IPv6LinkLocalAddress() string {
6565
func (s *NetworkInterfaceState) RpcGetNetworkState() RpcNetworkState {
6666
ipv6Addresses := make([]RpcIPv6Address, 0)
6767

68-
if s.ipv6Addresses != nil {
68+
if s.ipv6Addresses != nil && s.config.IPv6Mode.String != "disabled" {
6969
for _, addr := range s.ipv6Addresses {
7070
ipv6Addresses = append(ipv6Addresses, RpcIPv6Address{
7171
Address: addr.Prefix.String(),

0 commit comments

Comments
 (0)