diff --git a/go.mod b/go.mod index 0d59cef..6f2ced0 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d github.com/davecgh/go-spew v1.1.1 github.com/free5gc/go-gtp5gnl v1.4.6-0.20230629034810-9a49c0a5ee2f - github.com/free5gc/util v1.0.5-0.20230823103219-e511c4fd20ef + github.com/free5gc/util v1.0.5-0.20231012123940-85f4557167be github.com/hashicorp/go-version v1.6.0 github.com/khirono/go-genl v1.0.1 github.com/khirono/go-nl v1.0.5 diff --git a/go.sum b/go.sum index d75828e..fa5285f 100644 --- a/go.sum +++ b/go.sum @@ -14,8 +14,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/free5gc/go-gtp5gnl v1.4.6-0.20230629034810-9a49c0a5ee2f h1:+D0L2ixhbg6Iy/oQEAJQLmOU/w1mmndqVF78GdjX1yo= github.com/free5gc/go-gtp5gnl v1.4.6-0.20230629034810-9a49c0a5ee2f/go.mod h1:TT5aXB90NuSPMehuIK9lV2yJFnq6Qjw37ZqNB1QAKh0= -github.com/free5gc/util v1.0.5-0.20230823103219-e511c4fd20ef h1:ne0EMnst7wbLoaY2Uvn/2Kvp/KkXKMQJcaIJQKFe+a4= -github.com/free5gc/util v1.0.5-0.20230823103219-e511c4fd20ef/go.mod h1:l2Jrml4vojDomW5jdDJhIS60KdbrE9uPYhyAq/7OnF4= +github.com/free5gc/util v1.0.5-0.20231012123940-85f4557167be h1:SglM1KIL+bR50hPzbvxVwNW44+yHR2tq9nTpLra75UE= +github.com/free5gc/util v1.0.5-0.20231012123940-85f4557167be/go.mod h1:d+79g84a3YHhzvjJ2IhurrBOavOA8xWIQ/GCywPXqQk= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= diff --git a/internal/forwarder/flowdesc.go b/internal/forwarder/flowdesc.go index 52603f2..e048646 100644 --- a/internal/forwarder/flowdesc.go +++ b/internal/forwarder/flowdesc.go @@ -129,7 +129,7 @@ func ParseFlowDesc(s string) (*FlowDesc, error) { } func ParseFlowDescIPNet(s string) (*net.IPNet, error) { - if s == "any" { + if s == "any" || s == "assigned" { return &net.IPNet{ IP: net.IPv6zero, Mask: net.CIDRMask(0, 128), diff --git a/internal/forwarder/gtp5g.go b/internal/forwarder/gtp5g.go index d82b752..e9ed74f 100644 --- a/internal/forwarder/gtp5g.go +++ b/internal/forwarder/gtp5g.go @@ -173,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{ @@ -249,7 +252,7 @@ func convertSlice(ports [][]uint16) []byte { return b } -func (g *Gtp5g) newSdfFilter(i *ie.IE) (nl.AttrList, error) { +func (g *Gtp5g) newSdfFilter(i *ie.IE, srcIf uint8) (nl.AttrList, error) { var attrs nl.AttrList v, err := i.SDFFilter() @@ -258,7 +261,8 @@ func (g *Gtp5g) newSdfFilter(i *ie.IE) (nl.AttrList, error) { } if v.HasFD() { - fd, err := g.newFlowDesc(v.FlowDescription) + swapSrcDst := (srcIf == ie.SrcInterfaceAccess) + fd, err := g.newFlowDesc(v.FlowDescription, swapSrcDst) if err != nil { return nil, err } @@ -311,9 +315,17 @@ func (g *Gtp5g) newPdi(i *ie.IE) (nl.AttrList, error) { if err != nil { return nil, err } + + var srcIf uint8 + var sdfIEs []*ie.IE for _, x := range ies { switch x.Type { case ie.SourceInterface: + v, err := x.SourceInterface() + if err != nil { + break + } + srcIf = v case ie.FTEID: v, err := x.FTEID() if err != nil { @@ -343,15 +355,18 @@ func (g *Gtp5g) newPdi(i *ie.IE) (nl.AttrList, error) { Value: nl.AttrBytes(v.IPv4Address), }) case ie.SDFFilter: - v, err := g.newSdfFilter(x) - if err != nil { - break - } + sdfIEs = append(sdfIEs, x) + case ie.ApplicationID: + } + } + + for _, x := range sdfIEs { + v, err := g.newSdfFilter(x, srcIf) + if err == nil { attrs = append(attrs, nl.Attr{ Type: gtp5gnl.PDI_SDF_FILTER, Value: v, }) - case ie.ApplicationID: } }