Skip to content

Commit

Permalink
toggles for ipv4 and ipv6
Browse files Browse the repository at this point in the history
  • Loading branch information
vmorganp committed Aug 14, 2024
1 parent 79ba9d0 commit 89aa33e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 10 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 21 additions & 9 deletions src/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 18 additions & 0 deletions src/lazytainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 89aa33e

Please sign in to comment.