Skip to content

Commit

Permalink
swapSrcDst() in newSdfFilter()
Browse files Browse the repository at this point in the history
  • Loading branch information
brianchennn committed Dec 1, 2023
1 parent 838afdf commit 2fde71f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
9 changes: 1 addition & 8 deletions internal/forwarder/flowdesc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"net"
"strconv"
"strings"

"github.com/wmnsk/go-pfcp/ie"
)

// IPFilterRule <- action s dir s proto s 'from' s src 'to' s dst
Expand All @@ -33,7 +31,7 @@ type FlowDesc struct {
DstPorts [][]uint16
}

func ParseFlowDesc(s string, sourceInterface uint8) (*FlowDesc, error) {
func ParseFlowDesc(s string) (*FlowDesc, error) {
fd := new(FlowDesc)
token := strings.Fields(s)
pos := 0
Expand Down Expand Up @@ -127,11 +125,6 @@ func ParseFlowDesc(s string, sourceInterface uint8) (*FlowDesc, error) {
}
}

if sourceInterface == ie.SrcInterfaceAccess { // TS 29.244 5.2.1A.2A
fd.Dst, fd.Src = fd.Src, fd.Dst
fd.DstPorts, fd.SrcPorts = fd.SrcPorts, fd.DstPorts
}

return fd, nil
}

Expand Down
43 changes: 34 additions & 9 deletions internal/forwarder/gtp5g.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package forwarder
import (
"fmt"
"net"
"strings"
"sync"
"syscall"
"time"
Expand Down Expand Up @@ -173,9 +174,9 @@ func (g *Gtp5g) Link() *Gtp5gLink {
return g.link
}

func (g *Gtp5g) newFlowDesc(s string, sourceInterface uint8) (nl.AttrList, error) {
func (g *Gtp5g) newFlowDesc(s string) (nl.AttrList, error) {
var attrs nl.AttrList
fd, err := ParseFlowDesc(s, sourceInterface)
fd, err := ParseFlowDesc(s)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -249,6 +250,21 @@ 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) {
var attrs nl.AttrList

Expand All @@ -258,7 +274,15 @@ func (g *Gtp5g) newSdfFilter(i *ie.IE, sourceInterface uint8) (nl.AttrList, erro
}

if v.HasFD() {
fd, err := g.newFlowDesc(v.FlowDescription, sourceInterface)
fdStr := v.FlowDescription
if sourceInterface == ie.SrcInterfaceAccess {
fdStr, err = swapSrcDst(fdStr)
if err != nil {
return nil, err
}
}

fd, err := g.newFlowDesc(fdStr)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -314,18 +338,19 @@ func (g *Gtp5g) newPdi(i *ie.IE) (nl.AttrList, error) {

var sourceInterface uint8
var sdfFilterIE *ie.IE

L:
for _, x := range ies {
switch x.Type {
case ie.SourceInterface:
var err1 error
sourceInterface, err1 = x.SourceInterface()
if err1 != nil {
break
sourceInterface, err = x.SourceInterface()
if err != nil {
break L
}
case ie.FTEID:
v, err := x.FTEID()
if err != nil {
break
break L
}
attrs = append(attrs, nl.Attr{
Type: gtp5gnl.PDI_F_TEID,
Expand All @@ -344,7 +369,7 @@ func (g *Gtp5g) newPdi(i *ie.IE) (nl.AttrList, error) {
case ie.UEIPAddress:
v, err := x.UEIPAddress()
if err != nil {
break
break L
}
attrs = append(attrs, nl.Attr{
Type: gtp5gnl.PDI_UE_ADDR_IPV4,
Expand Down

0 comments on commit 2fde71f

Please sign in to comment.