list interfaces

This commit is contained in:
Vladimir Avtsenov 2024-08-30 04:44:08 +03:00
parent 3fd43f0d18
commit d940897a55
2 changed files with 21 additions and 1 deletions

View File

@ -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

View File

@ -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 {