Skip to content

Commit

Permalink
Allow upf interfaces to be reused for N3/N6
Browse files Browse the repository at this point in the history
  • Loading branch information
louisroyer committed Dec 13, 2024
1 parent d07641f commit d431a0e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
5 changes: 2 additions & 3 deletions internal/smf/upf.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package smf
import (
"context"
"net/netip"
"strings"
"sync"

"github.com/nextmn/cp-lite/internal/config"
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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
}
}
Expand Down
26 changes: 24 additions & 2 deletions internal/smf/upf_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit d431a0e

Please sign in to comment.