diff --git a/internal/smf/upf.go b/internal/smf/upf.go index 96bc571..0d60ccb 100644 --- a/internal/smf/upf.go +++ b/internal/smf/upf.go @@ -8,7 +8,6 @@ package smf import ( "context" "net/netip" - "strings" "sync" "github.com/nextmn/cp-lite/internal/config" @@ -45,7 +44,7 @@ type Upf struct { func (upf *Upf) GetN3() (netip.Addr, error) { for addr, iface := range upf.interfaces { - if strings.ToLower(iface.Type) == "n3" { + if iface.IsN3() { return addr, nil } } @@ -54,7 +53,7 @@ func (upf *Upf) GetN3() (netip.Addr, error) { func (upf *Upf) GetN6() (netip.Addr, error) { for addr, iface := range upf.interfaces { - if strings.ToLower(iface.Type) == "n6" { + if iface.IsN6() { return addr, nil } } diff --git a/internal/smf/upf_interface.go b/internal/smf/upf_interface.go index 9762658..0049cc3 100644 --- a/internal/smf/upf_interface.go +++ b/internal/smf/upf_interface.go @@ -7,25 +7,47 @@ package smf import ( "net/netip" + "strings" "github.com/nextmn/cp-lite/internal/config" ) type UpfInterface struct { Teids *TEIDsPool - Type string + Types []string } func NewUpfInterface(t string) *UpfInterface { return &UpfInterface{ Teids: NewTEIDsPool(), - Type: t, + Types: []string{t}, } } func NewUpfInterfaceMap(ifaces []config.Interface) map[netip.Addr]*UpfInterface { r := make(map[netip.Addr]*UpfInterface) for _, v := range ifaces { + if i, ok := r[v.Addr]; ok { + i.Types = append(i.Types, v.Type) + } r[v.Addr] = NewUpfInterface(v.Type) } return r } + +func (iface *UpfInterface) IsN3() bool { + for _, t := range iface.Types { + if strings.ToLower(t) == "n3" { + return true + } + } + return false +} + +func (iface *UpfInterface) IsN6() bool { + for _, t := range iface.Types { + if strings.ToLower(t) == "n6" { + return true + } + } + return false +}