Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ipv6 disable option #2

Merged
merged 1 commit into from
May 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions Dockerfile

This file was deleted.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ The bouncer configuration is made via environment variables:
| `MIKROTIK_USER` | Mikrotik appliance username | `none` | ✅ |
| `MIKROTIK_PASS` | Mikrotik appliance password | `none` | ✅ |
| `MIKROTIK_TLS` | User TLS to connect to Mikrotik API | `true` | ❌ |
| `MIKROTIK_IPV6` | Enable / Disable IPv6 support | `true` | ❌ |



# Contribution
Expand Down
4 changes: 4 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var (
password string
async bool
useTLS bool
useIPV6 bool
)

func initConfig() {
Expand All @@ -29,6 +30,8 @@ func initConfig() {
viper.BindEnv("mikrotik_pass")
viper.BindEnv("mikrotik_tls")
viper.SetDefault("mikrotik_tls", "true")
viper.BindEnv("mikrotik_ipv6")
viper.SetDefault("mikrotik_ipv6", "true")

logLevel = viper.GetString("log_level")
level, err := zerolog.ParseLevel(logLevel)
Expand Down Expand Up @@ -58,5 +61,6 @@ func initConfig() {
}

useTLS = viper.GetBool("mikrotik_tls")
useIPV6 = viper.GetBool("mikrotik_ipv6")
log.Printf("Using config: %+v", viper.AllSettings())
}
17 changes: 15 additions & 2 deletions mikrotik.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ func (mal *mikrotikAddrList) initMikrotik() {

mal.cache = make(map[string]string)

protos := []string{"ip", "ipv6"}
protos := []string{"ip"}

if useIPV6 {
protos = append(protos, "ipv6")
}

for _, proto := range protos {
log.Info().Msgf("mikrotik %s list addr", proto)
Expand All @@ -43,7 +47,7 @@ func (mal *mikrotikAddrList) initMikrotik() {
if err != nil {
log.Fatal().Err(err).Msg("address-list print failed")
}
log.Info().Msgf("fill %d entry in internal addrList\n", len(r.Re))
log.Info().Msgf("fill %d entry in internal %s addrList", len(r.Re), proto)
for _, v := range r.Re {
mal.cache[v.Map["address"]] = v.Map[".id"]
}
Expand All @@ -56,7 +60,12 @@ func (mal *mikrotikAddrList) add(decision *models.Decision) {

var proto string
if strings.Contains(*decision.Value, ":") {
if !useIPV6 {
log.Info().Msgf("Ignore adding address %s (IPv6 disabled)", *decision.Value)
return
}
proto = "ipv6"

} else {
proto = "ip"
}
Expand Down Expand Up @@ -91,6 +100,10 @@ func (mal *mikrotikAddrList) remove(decision *models.Decision) {

var proto string
if strings.Contains(*decision.Value, ":") {
log.Info().Msgf("Ignore removing address %s (IPv6 disabled)", *decision.Value)
if !useIPV6 {
return
}
proto = "ipv6"
} else {
proto = "ip"
Expand Down