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

feat: use max qfi in PDU session as tunnel key #34

Closed
wants to merge 1 commit into from
Closed
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
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
Loading