diff --git a/README.md b/README.md index c131320..7061b9e 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Realized features: - [ ] Rule composer - [ ] List loading/watching (temporary) - [X] IPSet integration -- [ ] Listing of interfaces +- [X] Listing of interfaces - [ ] IPTables rules to IPSet [2] - [ ] It is not a concept now... REFACTORING TIME!!! - [ ] HTTP API diff --git a/kvas2.go b/kvas2.go index 768e140..1b77898 100644 --- a/kvas2.go +++ b/kvas2.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "net" "sync" "time" @@ -130,6 +131,25 @@ func (a *App) AppendGroup(group *models.Group) error { return nil } +func (a *App) ListInterfaces() ([]net.Interface, error) { + interfaceNames := make([]net.Interface, 0) + + interfaces, err := net.Interfaces() + if err != nil { + return nil, fmt.Errorf("failed to get interfaces: %w", err) + } + + for _, iface := range interfaces { + if iface.Flags&net.FlagPointToPoint == 0 { + continue + } + + interfaceNames = append(interfaceNames, iface) + } + + return interfaceNames, nil +} + func (a *App) processARecord(aRecord dnsProxy.Address) { ttlDuration := time.Duration(aRecord.TTL) * time.Second if ttlDuration < a.Config.MinimalTTL {