diff --git a/README.md b/README.md index cd77336..0ac08a9 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ Group properties that can be changed include: #### Verbose Logging -If you would like more verbose logging, you can apply the environment variable `VERBOSE=true` to lazytainer like so +For more verbose logging, you can apply the environment variable `VERBOSE=true` to lazytainer: ```yaml lazytainer: @@ -96,6 +96,18 @@ lazytainer: - VERBOSE=true ``` +#### ipv4/ipv6 toggles + +To disable ipv4 or ipv6, pass environment variables: + +```yaml +lazytainer: + # ... configuration omitted for brevity + environment: + - IPV6_DISABLED=true + - IPV4_DISABLED=true +``` + #### Volumes If using lazytainer, you MUST provide the following volume to lazytainer diff --git a/docker-compose.yaml b/docker-compose.yaml index 1b10290..7f0a80e 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -10,6 +10,8 @@ services: # build: . environment: - VERBOSE=true # probably set this to false unless you're debugging or doing the initial demo + - IPV4_DISABLED=false + - IPV6_DISABLED=false ports: - 81:81 - 82:82 diff --git a/src/group.go b/src/group.go index 86795d5..fda529f 100644 --- a/src/group.go +++ b/src/group.go @@ -148,17 +148,29 @@ func (lg LazyGroup) getRxPackets(packetCount *int) { func (lg LazyGroup) getActiveClients() int { // get active clients var allSocks []netstat.SockTabEntry - udpSocks, err := netstat.UDPSocks(netstat.NoopFilter) - check(err) - udp6Socks, err := netstat.UDP6Socks(netstat.NoopFilter) - check(err) - tcpSocks, err := netstat.TCPSocks(netstat.NoopFilter) - check(err) - tcp6Socks, err := netstat.TCP6Socks(netstat.NoopFilter) - check(err) + + // ipv4 + if ipv6Enabled { + udpSocks, err := netstat.UDPSocks(netstat.NoopFilter) + check(err) + allSocks = append(allSocks, udpSocks...) + tcpSocks, err := netstat.TCPSocks(netstat.NoopFilter) + check(err) + allSocks = append(allSocks, tcpSocks...) + } + + // ipv6 + if ipv6Enabled { + udp6Socks, err := netstat.UDP6Socks(netstat.NoopFilter) + check(err) + allSocks = append(allSocks, udp6Socks...) + tcp6Socks, err := netstat.TCP6Socks(netstat.NoopFilter) + check(err) + allSocks = append(allSocks, tcp6Socks...) + } activeClients := 0 - for _, socketEntry := range append(append(append(append(allSocks, udp6Socks...), tcp6Socks...), tcpSocks...), udpSocks...) { + for _, socketEntry := range allSocks { if socketEntry.State.String() == "ESTABLISHED" { for _, aPort := range lg.ports { if strconv.FormatUint(uint64(aPort), 10) == fmt.Sprintf("%v", socketEntry.LocalAddr.Port) { diff --git a/src/lazytainer.go b/src/lazytainer.go index 3f35d16..d121970 100644 --- a/src/lazytainer.go +++ b/src/lazytainer.go @@ -17,6 +17,8 @@ import ( var infoLogger *log.Logger var debugLogger *log.Logger var dockerClient *client.Client +var ipv6Enabled bool +var ipv4Enabled bool func main() { flags := log.LstdFlags | log.Lshortfile @@ -29,6 +31,22 @@ func main() { debugLogger.SetOutput(io.Discard) } + // if the IPV6_DISABLED flag isn't set to true, leave ipv6 enabled + envIpv6, existsEnvDisableIpv6 := os.LookupEnv("IPV6_DISABLED") + if existsEnvDisableIpv6 && strings.ToLower(envIpv6) != "true" { + ipv6Enabled = true + } else { + ipv6Enabled = false + } + + // if the IPV4_DISABLED flag isn't set to true, leave ipv4 enabled + envIpv4, existsEnvDisableIpv4 := os.LookupEnv("IPV4_DISABLED") + if existsEnvDisableIpv4 && strings.ToLower(envIpv4) != "true" { + ipv4Enabled = true + } else { + ipv4Enabled = false + } + // configure groups. eventually it might be nice to have file based config as well. groups := configureFromLabels() for _, v := range groups {