Skip to content

Commit

Permalink
fix to handle multi sdfIE and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-ywliu committed Feb 16, 2024
1 parent 2fde71f commit 0e85605
Showing 1 changed file with 19 additions and 36 deletions.
55 changes: 19 additions & 36 deletions internal/forwarder/gtp5g.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package forwarder
import (
"fmt"
"net"
"strings"
"sync"
"syscall"
"time"
Expand Down Expand Up @@ -174,12 +173,15 @@ func (g *Gtp5g) Link() *Gtp5gLink {
return g.link
}

func (g *Gtp5g) newFlowDesc(s string) (nl.AttrList, error) {
func (g *Gtp5g) newFlowDesc(s string, swapSrcDst bool) (nl.AttrList, error) {
var attrs nl.AttrList
fd, err := ParseFlowDesc(s)
if err != nil {
return nil, err
}
if swapSrcDst {
fd.Src, fd.Dst = fd.Dst, fd.Src
}
switch fd.Action {
case "permit":
attrs = append(attrs, nl.Attr{
Expand Down Expand Up @@ -250,22 +252,7 @@ func convertSlice(ports [][]uint16) []byte {
return b
}

func swapSrcDst(fdStr string) (string, error) {
strs1 := strings.Split(fdStr, "from")
if len(strs1) != 2 {
return "", fmt.Errorf("invalid flow description format")
}

strs2 := strings.Split(strs1[1], "to")
if len(strs2) != 2 {
return "", fmt.Errorf("invalid flow description format")
}

ret := strs1[0] + "from" + strs2[1] + " to" + strs2[0]
return ret, nil
}

func (g *Gtp5g) newSdfFilter(i *ie.IE, sourceInterface uint8) (nl.AttrList, error) {
func (g *Gtp5g) newSdfFilter(i *ie.IE, srcIf uint8) (nl.AttrList, error) {
var attrs nl.AttrList

v, err := i.SDFFilter()
Expand All @@ -274,15 +261,12 @@ func (g *Gtp5g) newSdfFilter(i *ie.IE, sourceInterface uint8) (nl.AttrList, erro
}

if v.HasFD() {
fdStr := v.FlowDescription
if sourceInterface == ie.SrcInterfaceAccess {
fdStr, err = swapSrcDst(fdStr)
if err != nil {
return nil, err
}
swapSrcDst := false
if srcIf == ie.SrcInterfaceAccess {
swapSrcDst = true
}

fd, err := g.newFlowDesc(fdStr)
fd, err := g.newFlowDesc(v.FlowDescription, swapSrcDst)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -336,21 +320,20 @@ func (g *Gtp5g) newPdi(i *ie.IE) (nl.AttrList, error) {
return nil, err
}

var sourceInterface uint8
var sdfFilterIE *ie.IE

L:
var srcIf uint8
var sdfIEs []*ie.IE
for _, x := range ies {
switch x.Type {
case ie.SourceInterface:
sourceInterface, err = x.SourceInterface()
v, err := x.SourceInterface()
if err != nil {
break L
break
}
srcIf = v
case ie.FTEID:
v, err := x.FTEID()
if err != nil {
break L
break
}
attrs = append(attrs, nl.Attr{
Type: gtp5gnl.PDI_F_TEID,
Expand All @@ -369,20 +352,20 @@ L:
case ie.UEIPAddress:
v, err := x.UEIPAddress()
if err != nil {
break L
break
}
attrs = append(attrs, nl.Attr{
Type: gtp5gnl.PDI_UE_ADDR_IPV4,
Value: nl.AttrBytes(v.IPv4Address),
})
case ie.SDFFilter:
sdfFilterIE = x
sdfIEs = append(sdfIEs, x)
case ie.ApplicationID:
}
}

if sdfFilterIE != nil {
v, err := g.newSdfFilter(sdfFilterIE, sourceInterface)
for _, x := range sdfIEs {
v, err := g.newSdfFilter(x, srcIf)
if err == nil {
attrs = append(attrs, nl.Attr{
Type: gtp5gnl.PDI_SDF_FILTER,
Expand Down

0 comments on commit 0e85605

Please sign in to comment.