Skip to content

Commit

Permalink
feat: use max qfi in PDU session as tunnel key
Browse files Browse the repository at this point in the history
  • Loading branch information
andy89923 committed Jun 6, 2024
1 parent 2687db9 commit ddb2383
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
18 changes: 18 additions & 0 deletions clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

sudo ip xfrm policy flush
sudo ip xfrm state flush

# Remove all GRE interfaces
GREs=$(ip link show type gre | awk 'NR%2==1 {print $2}' | cut -d @ -f 1)
for GRE in ${GREs}; do
sudo ip link del ${GRE}
echo del ${GRE}
done

# Remove all XFRM interfaces
XFRMIs=$(ip link show type xfrm | awk 'NR%2==1 {print $2}' | cut -d @ -f 1)
for XFRMI in ${XFRMIs}; do
sudo ip link del ${XFRMI}
echo del ${XFRMI}
done
10 changes: 10 additions & 0 deletions internal/gtp/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func forward(packet gtpQoSMsg.QoSTPDUPacket) {
return
}

// The QFI field of the GRE header is set to the QFI associated with the user data packet
// [Implement] we use the largest QFI in this PDU session as key
var tunnelKey uint8 = 0

// UE inner IP in IPSec
ueInnerIPAddr := ikeUe.IPSecInnerIPAddr

Expand All @@ -68,6 +72,7 @@ func forward(packet gtpQoSMsg.QoSTPDUPacket) {
cm = &ipv4.ControlMessage{
IfIndex: childSA.XfrmIface.Attrs().Index,
}
tunnelKey = pdusession.MaxQFI()
break
}
}
Expand All @@ -83,6 +88,11 @@ func forward(packet gtpQoSMsg.QoSTPDUPacket) {
logger.GTPLog.Tracef("QFI: %v, RQI: %v", qfi, rqi)
}

if tunnelKey != uint8(0) {
// [Implement] we use the largest QFI in this PDU session as tunnel key
qfi = tunnelKey
}

// Encasulate IPv4 packet with GRE header before forward to UE through IPsec
grePacket := gre.GREPacket{}

Expand Down
8 changes: 8 additions & 0 deletions pkg/context/ue.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,3 +431,11 @@ func (ranUe *N3IWFRanUe) DetachAMF() {
}
delete(ranUe.AMF.N3iwfRanUeList, ranUe.RanUeNgapId)
}

func (pdusession PDUSession) MaxQFI() uint8 {
var maxQfi uint8 = 0
for _, qfi := range pdusession.QFIList {
maxQfi = max(maxQfi, qfi)
}
return maxQfi
}
1 change: 1 addition & 0 deletions pkg/ike/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1777,6 +1777,7 @@ func CreatePDUSessionChildSA(ikeUe *context.N3IWFIkeUe,

// Notify-Qos
ikePayload.BuildNotify5G_QOS_INFO(uint8(pduSessionID), pduSession.QFIList, true, false, 0)
logger.IKELog.Infoln("pduSession", pduSessionID, "QFIList:", pduSession.QFIList)

// Notify-UP_IP_ADDRESS
ikePayload.BuildNotifyUP_IP4_ADDRESS(n3iwfSelf.IPSecGatewayAddress)
Expand Down

0 comments on commit ddb2383

Please sign in to comment.