Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue in PDI matching function #2

Merged
merged 1 commit into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2022 Louis Royer and the NextMN-UPF contributors. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.
// SPDX-License-Identifier: MIT
package main

import (
Expand All @@ -23,8 +27,8 @@ func main() {
log.SetPrefix("[nextmn-upf] ")
var config string
app := &cli.App{
Name: "nextmn-upf",
Usage: "An upf",
Name: "NextMN-UPF",
Usage: "Experimental 5G UPF",
EnableBashCompletion: true,
Authors: []*cli.Author{
{Name: "Louis Royer"},
Expand Down
46 changes: 28 additions & 18 deletions runtime/up-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,12 @@ func handleOuterHeaderRemoval(packet []byte, isGTP bool, outerHeaderRemoval *ie.
}

func handleIncommingPacket(db *FARAssociationDB, packet []byte, isGTP bool, session api.PFCPSessionInterface, pdr api.PDRInterface) (err error) {
//log.Println("Start handling of packet PDR:", pdr.ID)
// pdrid, err := pdr.ID()
// if err != nil {
// log.Println("Bad PDRID")
// return
// }
// log.Println("Start handling of packet PDR:", pdrid)
// Remove outer header if requested, and store GTP headers
var gtpHeaders []*message.ExtensionHeader
ohr := pdr.OuterHeaderRemoval()
Expand All @@ -188,6 +193,9 @@ func handleIncommingPacket(db *FARAssociationDB, packet []byte, isGTP bool, sess
if err != nil {
return err
}
if (packet[0]&0xF0 != 0x40) && (packet[0]&0xF0 != 0x60) {
log.Println("Warning: Non IP PDU detected")
}
}
if len(packet) == 0 {
return fmt.Errorf("Incomming packet of len 0")
Expand Down Expand Up @@ -283,22 +291,22 @@ func handleIncommingPacket(db *FARAssociationDB, packet []byte, isGTP bool, sess
} else {
// forward using TUN interface
// debug log start
var srcpdu net.IP
var dstpdu net.IP
if waterutil.IsIPv4(packet) {
p := gopacket.NewPacket(packet, layers.LayerTypeIPv4, gopacket.Default).NetworkLayer().(*layers.IPv4)
srcpdu = p.SrcIP
dstpdu = p.DstIP
log.Printf("Forwarding IP packet to TUN interface, src: %s, dst %s\n", srcpdu.String(), dstpdu.String())
} else if waterutil.IsIPv6(packet) {
p := gopacket.NewPacket(packet, layers.LayerTypeIPv6, gopacket.Default).NetworkLayer().(*layers.IPv6)
srcpdu = p.SrcIP
dstpdu = p.DstIP
log.Printf("Forwarding IP packet to TUN interface, src: %s, dst %s\n", srcpdu.String(), dstpdu.String())
} else {
log.Printf("Forwarding IP packet to TUN interface\n")
log.Println("Could not find PDR for IP packet on TUN interface")
}
// var srcpdu net.IP
// var dstpdu net.IP
// if waterutil.IsIPv4(packet) {
// p := gopacket.NewPacket(packet, layers.LayerTypeIPv4, gopacket.Default).NetworkLayer().(*layers.IPv4)
// srcpdu = p.SrcIP
// dstpdu = p.DstIP
// log.Printf("Forwarding IP packet to TUN interface, src: %s, dst %s\n", srcpdu.String(), dstpdu.String())
// } else if waterutil.IsIPv6(packet) {
// p := gopacket.NewPacket(packet, layers.LayerTypeIPv6, gopacket.Default).NetworkLayer().(*layers.IPv6)
// srcpdu = p.SrcIP
// dstpdu = p.DstIP
// log.Printf("Forwarding IP packet to TUN interface, src: %s, dst %s\n", srcpdu.String(), dstpdu.String())
// } else {
// log.Printf("Forwarding IP packet to TUN interface\n")
// log.Println("Could not find PDR for IP packet on TUN interface")
// }
// debug log end
TUNInterface.Write(packet)
}
Expand Down Expand Up @@ -361,7 +369,7 @@ func forwardGTP(gpdu *message.Header, ipAddress string, dscpecn int, session api
if err != nil {
return err
}
log.Printf("Forwarding gpdu to %s with TEID %d\n", raddr, gpdu.TEID)
//log.Printf("Forwarding gpdu to %s with TEID %d\n", raddr, gpdu.TEID)
uConn.WriteToWithDSCPECN(b, raddr, dscpecn)
return nil
}
Expand Down Expand Up @@ -470,6 +478,8 @@ func isPDIMatching(isGTP bool, pdi *ie.IE, teid uint32, iface string, packet []b
} else if !((fteid.TEID == teid) && ((fteid.HasIPv4() && fteid.IPv4Address.Equal(net.ParseIP(iface))) || (fteid.HasIPv6() && fteid.IPv6Address.Equal(net.ParseIP(iface))))) {
return false
}
} else if isGTP {
return false
}
SDFFilter, _ := pdi.SDFFilter()
UEIPAddress, _ := pdi.UEIPAddress()
Expand Down