From 8db6b19ef9484f4dea097337127db3c5545b26ca Mon Sep 17 00:00:00 2001 From: Louis Royer Date: Wed, 25 Sep 2024 10:45:57 +0200 Subject: [PATCH] Move `internal/mup` to `github.com/nextmn/rfc9433` --- go.mod | 4 +- go.sum | 20 +-- internal/mup/args-mob-session.go | 116 ----------------- internal/mup/constants.go | 60 --------- internal/mup/doc.go | 8 -- internal/mup/errors.go | 15 --- internal/mup/m-gtp4-ipv6-dst.go | 141 -------------------- internal/mup/m-gtp4-ipv6-dst_test.go | 13 -- internal/mup/m-gtp4-ipv6-src.go | 177 -------------------------- internal/mup/m-gtp4-ipv6-src_test.go | 58 --------- internal/mup/utils.go | 64 ---------- internal/mup/utils_test.go | 54 -------- internal/netfunc/endpoint-m-gtp4-e.go | 12 +- internal/netfunc/headend-gtp4-ctrl.go | 6 +- internal/netfunc/headend-gtp4.go | 10 +- 15 files changed, 21 insertions(+), 737 deletions(-) delete mode 100644 internal/mup/args-mob-session.go delete mode 100644 internal/mup/constants.go delete mode 100644 internal/mup/doc.go delete mode 100644 internal/mup/errors.go delete mode 100644 internal/mup/m-gtp4-ipv6-dst.go delete mode 100644 internal/mup/m-gtp4-ipv6-dst_test.go delete mode 100644 internal/mup/m-gtp4-ipv6-src.go delete mode 100644 internal/mup/m-gtp4-ipv6-src_test.go delete mode 100644 internal/mup/utils.go delete mode 100644 internal/mup/utils_test.go diff --git a/go.mod b/go.mod index 9f8b168..0278742 100644 --- a/go.mod +++ b/go.mod @@ -1,17 +1,17 @@ module github.com/nextmn/srv6 -go 1.22.1 +go 1.22.7 require ( github.com/adrg/xdg v0.5.0 github.com/gin-gonic/gin v1.10.0 github.com/gofrs/uuid v4.4.0+incompatible - github.com/google/go-cmp v0.6.0 github.com/google/gopacket v1.1.19 github.com/lib/pq v1.10.9 github.com/nextmn/gopacket-gtp v0.0.7 github.com/nextmn/gopacket-srv6 v0.0.8 github.com/nextmn/json-api v0.0.7 + github.com/nextmn/rfc9433 v0.0.2 github.com/sirupsen/logrus v1.9.3 github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8 github.com/urfave/cli/v2 v2.27.4 diff --git a/go.sum b/go.sum index e1da632..0862cc5 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,5 @@ github.com/adrg/xdg v0.5.0 h1:dDaZvhMXatArP1NPHhnfaQUqWBLBsmx1h1HXQdMoFCY= github.com/adrg/xdg v0.5.0/go.mod h1:dDdY4M4DF9Rjy4kHPeNL+ilVF+p2lK8IdM9/rTSGcI4= -github.com/bytedance/sonic v1.12.2 h1:oaMFuRTpMHYLpCntGca65YWt5ny+wAceDERTkT2L9lg= -github.com/bytedance/sonic v1.12.2/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk= github.com/bytedance/sonic v1.12.3 h1:W2MGa7RCU1QTeYRTPE3+88mVC0yXmsRQRChiyVocVjU= github.com/bytedance/sonic v1.12.3/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk= github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= @@ -11,8 +9,6 @@ github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/ github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= -github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4= -github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc= github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -30,8 +26,6 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.22.0 h1:k6HsTZ0sTnROkhS//R0O+55JgM8C4Bx7ia+JlgcnOao= -github.com/go-playground/validator/v10 v10.22.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA= github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA= @@ -64,10 +58,10 @@ github.com/nextmn/gopacket-gtp v0.0.7 h1:O2cuShLTlpVBEXyHn9OIi1Nd+j4QCB66RAwzKBe github.com/nextmn/gopacket-gtp v0.0.7/go.mod h1:94jLjLU04IOVTKBXUP09MXZCgmlizqmflU2ion1ht6E= github.com/nextmn/gopacket-srv6 v0.0.8 h1:oP4wuJ7dOiV/gWmX3zoFcdp2dKdSWLUaxH2fJ3TYAwA= github.com/nextmn/gopacket-srv6 v0.0.8/go.mod h1:2Tyuo9zsG0bP2IhC4tVRgPRuyUqOgrvEEH9seJSZTlU= -github.com/nextmn/json-api v0.0.6 h1:YvYWarvCSX9pHyexy9uOR2IK8xpnsKkIqAALG3k+XMg= -github.com/nextmn/json-api v0.0.6/go.mod h1:gi9IhsD+FFg7iEnJaZtEaY1WlZkQ75KBBk0z5FmSJBU= github.com/nextmn/json-api v0.0.7 h1:cM1DJhOTleeESDQIGn8Ahuo3szCW9YEiymbsng+aFws= github.com/nextmn/json-api v0.0.7/go.mod h1:0py63IYCOBp1ZtLkMjNCNnOwbwhOmkh+ymJ0/OrxYx8= +github.com/nextmn/rfc9433 v0.0.2 h1:6FjMY+Qy8MNXQ0PPxezUsyXDxJiCbTp5j3OcXQgIQh8= +github.com/nextmn/rfc9433 v0.0.2/go.mod h1:uVEEXunVOe3dMDV8eHr8ViPT/RnJ5WxjeQhycgaqFh4= github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M= github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -96,22 +90,16 @@ github.com/urfave/cli/v2 v2.27.4 h1:o1owoI+02Eb+K107p27wEX9Bb8eqIoZCfLXloLUSWJ8= github.com/urfave/cli/v2 v2.27.4/go.mod h1:m4QzxcD2qpra4z7WhzEGn74WZLViBnMpb1ToCAKdGRQ= github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4= github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM= -golang.org/x/arch v0.9.0 h1:ub9TgUInamJ8mrZIGlBG6/4TqWeMszd4N8lNorbrr6k= -golang.org/x/arch v0.9.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= golang.org/x/arch v0.10.0 h1:S3huipmSclq3PJMNe76NGwkBR504WFkQ5dhzWzP8ZW8= golang.org/x/arch v0.10.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= -golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A= golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70= golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= -golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -120,13 +108,9 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= -golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= -golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= diff --git a/internal/mup/args-mob-session.go b/internal/mup/args-mob-session.go deleted file mode 100644 index 235b3f1..0000000 --- a/internal/mup/args-mob-session.go +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright 2023 Louis Royer and the NextMN-SRv6 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 mup - -import "encoding/binary" - -// Args.Mob.Session as defined in RFC 9433, section 6.1: -// -// 0 1 2 3 -// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | QFI |R|U| PDU Session ID | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// |PDU Sess(cont')| -// +-+-+-+-+-+-+-+-+ -// Figure 8: Args.Mob.Session Format -type ArgsMobSession struct { - qfi uint8 // QoS Flow Identifier (6 bits) - r uint8 // Reflective QoS Indication (1 bit) - u uint8 // Unused and for future use (1 bit) - pduSessionID uint32 // Identifier of PDU Session. The GTP-U equivalent is TEID (32 bits) -} - -// NewArgsMobSession creates an ArgsMobSession. -func NewArgsMobSession(qfi uint8, r bool, u bool, pduSessionID uint32) *ArgsMobSession { - var ruint uint8 = 0 - if r { - ruint = 1 - } - var uuint uint8 = 0 - if u { - uuint = 1 - } - return &ArgsMobSession{ - qfi: qfi, - r: ruint, - u: uuint, - pduSessionID: pduSessionID, - } -} - -// ParseArgsMobSession parses given byte sequence as an ArgsMobSession. -func ParseArgsMobSession(b []byte) (*ArgsMobSession, error) { - a := &ArgsMobSession{} - if err := a.UnmarshalBinary(b); err != nil { - return nil, err - } - return a, nil -} - -// QFI returns the Qos Flow Identifier for this ArgsMobSession. -func (a *ArgsMobSession) QFI() uint8 { - return a.qfi -} - -// R returns the Reflective QoS Indication for this ArgsMobSession. -func (a *ArgsMobSession) R() bool { - if a.r == 0 { - return false - } - return true -} - -// U returns the U bit for this ArgsMobSession. -func (a *ArgsMobSession) U() bool { - if a.u == 0 { - return false - } - return true -} - -// PDUSessionID returns the PDU Session Identifier for this ArgsMobSession. The GTP-U equivalent is TEID. -func (a *ArgsMobSession) PDUSessionID() uint32 { - return a.pduSessionID -} - -// MarshalLen returns the serial length of ArgsMobSession. -func (a *ArgsMobSession) MarshalLen() int { - return ARGS_MOB_SESSION_SIZE_BYTE -} - -// Marshal returns the byte sequence generated from ArgsMobSession. -func (a *ArgsMobSession) Marshal() ([]byte, error) { - b := make([]byte, a.MarshalLen()) - if err := a.MarshalTo(b); err != nil { - return nil, err - } - return b, nil -} - -// MarshalTo puts the byte sequence in the byte array given as b. -func (a *ArgsMobSession) MarshalTo(b []byte) error { - if len(b) < a.MarshalLen() { - return ErrTooShortToMarshal - } - b[QFI_POS_BYTE] |= (QFI_MASK & a.qfi) << QFI_POS_BIT - b[R_POS_BYTE] |= (R_MASK & a.r) << R_POS_BIT - b[U_POS_BYTE] |= (U_MASK & a.u) << U_POS_BIT - binary.BigEndian.PutUint32(b[TEID_POS_BYTE:TEID_POS_BYTE+TEID_SIZE_BYTE], a.pduSessionID) - return nil -} - -// UnmarshalBinary sets the values retrieved from byte sequence in an ArgsMobSession. -func (a *ArgsMobSession) UnmarshalBinary(b []byte) error { - if len(b) < ARGS_MOB_SESSION_SIZE_BYTE { - return ErrTooShortToParse - } - a.qfi = QFI_MASK & (b[QFI_POS_BYTE] >> QFI_POS_BIT) - a.r = R_MASK & (b[R_POS_BYTE] >> R_POS_BIT) - a.u = U_MASK & (b[U_POS_BYTE] >> U_POS_BIT) - a.pduSessionID = binary.BigEndian.Uint32(b[TEID_POS_BYTE : TEID_POS_BYTE+TEID_SIZE_BYTE]) - return nil -} diff --git a/internal/mup/constants.go b/internal/mup/constants.go deleted file mode 100644 index 39e49f1..0000000 --- a/internal/mup/constants.go +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2023 Louis Royer and the NextMN-SRv6 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 mup - -// Sizes for IP Packets and IPv6 Fields -const ( - // Size of IPv6 Address - IPV6_ADDR_SIZE_BYTE = 16 - IPV6_ADDR_SIZE_BIT = IPV6_ADDR_SIZE_BYTE * 8 - - // Size of IPv4 Address - IPV4_ADDR_SIZE_BYTE = 4 - IPV4_ADDR_SIZE_BIT = IPV4_ADDR_SIZE_BYTE * 8 - - // Size of Args.Mob.Session - ARGS_MOB_SESSION_SIZE_BYTE = 5 - ARGS_MOB_SESSION_SIZE_BIT = ARGS_MOB_SESSION_SIZE_BYTE * 8 -) - -// NextMN MGTP4IPv6Src additional fields -const ( - // UDP Port Number field - UDP_PORT_SIZE_BYTE = 2 // size of the field in bytes - UDP_PORT_SIZE_BIT = UDP_PORT_SIZE_BYTE * 8 // size of the field in bits - - // "IPv6 Length" field - IPV6_LEN_ENCODING_SIZE_BIT = 7 // size of the field in bits - IPV6_LEN_ENCODING_POS_BIT = 0 // position from right of the byte in bits - IPV6_LEN_ENCODING_POS_BYTE = 15 // position from left in bytes - IPV6_LEN_ENCODING_MASK = (0xFF >> (8 - IPV6_LEN_ENCODING_SIZE_BIT)) // mask (decoding: after shift to right; encoding before shift to left) -) - -// Args.Mob.Session fields -const ( - // Field TEID - TEID_SIZE_BYTE = 4 // size of the field in bytes - TEID_SIZE_BIT = TEID_SIZE_BYTE * 8 // size of the field in bits - TEID_POS_BYTE = 1 // position of the field from the left in bytes - - // Field QFI - QFI_SIZE_BIT = 6 // size of the field - QFI_POS_BIT = 2 // position from right of the byte in bits - QFI_POS_BYTE = 0 // position from left in bytes - QFI_MASK = (0xFF >> (8 - QFI_SIZE_BIT)) // mask (decoding: after shift to right; encoding before shift to left) - - // Field R - R_SIZE_BIT = 1 // size of the field - R_POS_BIT = 1 // position from right of the byte in bits - R_POS_BYTE = 0 // position from left in bytes - R_MASK = (0xFF >> (8 - R_SIZE_BIT)) // mask (decoding: after shift to right; encoding before shift to left) - - // Field U - U_SIZE_BIT = 1 // size of the field - U_POS_BIT = 0 // position from right of the byte in bits - U_POS_BYTE = 0 // position from left in bytes - U_MASK = (0xFF >> (8 - U_SIZE_BIT)) // mask (decoding: after shift to right; encoding before shift to left) -) diff --git a/internal/mup/doc.go b/internal/mup/doc.go deleted file mode 100644 index c0c0ba8..0000000 --- a/internal/mup/doc.go +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright 2023 Louis Royer and the NextMN-SRv6 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 mup provides encoding and decoding of IPv6 Addresses -// used by RFC 9433 (Segment Routing over IPv6 for the Mobile User Plane). -package mup diff --git a/internal/mup/errors.go b/internal/mup/errors.go deleted file mode 100644 index cd9c8e8..0000000 --- a/internal/mup/errors.go +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2023 Louis Royer and the NextMN-SRv6 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 mup - -import "errors" - -var ( - ErrTooShortToMarshal = errors.New("too short to serialize") - ErrTooShortToParse = errors.New("too short to parse") - ErrPrefixLength = errors.New("wrong prefix length") - ErrOutOfRange = errors.New("out of range") -) diff --git a/internal/mup/m-gtp4-ipv6-dst.go b/internal/mup/m-gtp4-ipv6-dst.go deleted file mode 100644 index 9ad7ca2..0000000 --- a/internal/mup/m-gtp4-ipv6-dst.go +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright 2023 Louis Royer and the NextMN-SRv6 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 mup - -import ( - "net/netip" -) - -// RFC 9433, section 6.6 (End.M.GTP4.E): -// The End.M.GTP.E SID in S has the following format: -// -// 0 127 -// +-----------------------+-------+----------------+---------+ -// | SRGW-IPv6-LOC-FUNC |IPv4DA |Args.Mob.Session|0 Padded | -// +-----------------------+-------+----------------+---------+ -// 128-a-b-c a b c -// Figure 9: End.M.GTP4.E SID Encoding -type MGTP4IPv6Dst struct { - prefix netip.Prefix // prefix in canonical form - ipv4 [IPV4_ADDR_SIZE_BYTE]byte - argsMobSession *ArgsMobSession -} - -// NewMGTP4IPv6Dst creates a new MGTP4IPv6Dst. -func NewMGTP4IPv6Dst(prefix netip.Prefix, ipv4 [IPV4_ADDR_SIZE_BYTE]byte, a *ArgsMobSession) *MGTP4IPv6Dst { - return &MGTP4IPv6Dst{ - prefix: prefix.Masked(), - ipv4: ipv4, - argsMobSession: a, - } -} - -// ParseMGTP4IPv6Dst parses a given byte sequence into a MGTP4IPv6Dst according to the given prefixLength. -func ParseMGTP4IPv6Dst(ipv6Addr [IPV6_ADDR_SIZE_BYTE]byte, prefixLength uint) (*MGTP4IPv6Dst, error) { - // prefix extraction - a := netip.AddrFrom16(ipv6Addr) - prefix := netip.PrefixFrom(a, int(prefixLength)).Masked() - - // ipv4 extraction - var ipv4 [IPV4_ADDR_SIZE_BYTE]byte - if src, err := fromIPv6(ipv6Addr, prefixLength, IPV4_ADDR_SIZE_BYTE); err != nil { - return nil, err - } else { - copy(ipv4[:], src[:IPV4_ADDR_SIZE_BYTE]) - } - - // argMobSession extraction - argsMobSessionSlice, err := fromIPv6(ipv6Addr, prefixLength+IPV4_ADDR_SIZE_BIT, ARGS_MOB_SESSION_SIZE_BYTE) - argsMobSession, err := ParseArgsMobSession(argsMobSessionSlice) - if err != nil { - return nil, err - } - return &MGTP4IPv6Dst{ - prefix: prefix, - ipv4: ipv4, - argsMobSession: argsMobSession, - }, nil -} - -// IPv4 returns the IPv4 Address encoded in the MGTP4IPv6Dst. -func (e *MGTP4IPv6Dst) IPv4() netip.Addr { - return netip.AddrFrom4(e.ipv4) -} - -// ArgsMobSession returns the ArgsMobSession encoded in the MGTP4IPv6Dst. -func (e *MGTP4IPv6Dst) ArgsMobSession() *ArgsMobSession { - return e.argsMobSession -} - -// QFI returns the QFI encoded in the MGTP4IPv6Dst's ArgsMobSession. -func (e *MGTP4IPv6Dst) QFI() uint8 { - return e.argsMobSession.QFI() -} - -// R returns the R bit encoded in the MGTP4IPv6Dst's ArgsMobSession. -func (e *MGTP4IPv6Dst) R() bool { - return e.argsMobSession.R() -} - -// U returns the U bit encoded in the MGTP4IPv6Dst's ArgsMobSession. -func (e *MGTP4IPv6Dst) U() bool { - return e.argsMobSession.U() -} - -// PDUSessionID returns the PDUSessionID for this MGTP4IPv6Dst's ArgsMobSession. -func (a *MGTP4IPv6Dst) PDUSessionID() uint32 { - return a.argsMobSession.PDUSessionID() -} - -// Prefix returns the IPv6 Prefix for this MGTP4IPv6Dst. -func (e *MGTP4IPv6Dst) Prefix() netip.Prefix { - return e.prefix -} - -// MarshalLen returns the serial length of MGTP4IPv6Dst. -func (a *MGTP4IPv6Dst) MarshalLen() int { - return IPV6_ADDR_SIZE_BYTE -} - -// Marshal returns the byte sequence generated from MGTP4IPv6Dst. -func (a *MGTP4IPv6Dst) Marshal() ([]byte, error) { - b := make([]byte, a.MarshalLen()) - if err := a.MarshalTo(b); err != nil { - return nil, err - } - return b, nil -} - -// MarshalTo puts the byte sequence in the byte array given as b. -// warning: no caching is done, this result will be recomputed at each call -func (a *MGTP4IPv6Dst) MarshalTo(b []byte) error { - if len(b) < a.MarshalLen() { - return ErrTooShortToMarshal - } - // init ipv6 with the prefix - prefix := a.prefix.Addr().As16() - copy(b, prefix[:]) - - ipv4 := netip.AddrFrom4(a.ipv4).AsSlice() - bits := a.prefix.Bits() - if bits == -1 { - return ErrPrefixLength - } - - // add ipv4 - if err := appendToSlice(b, uint(bits), ipv4); err != nil { - return err - } - argsMobSessionB, err := a.argsMobSession.Marshal() - if err != nil { - return err - } - // add Args-Mob-Session - if err := appendToSlice(b, uint(bits+IPV4_ADDR_SIZE_BIT), argsMobSessionB); err != nil { - return err - } - return nil -} diff --git a/internal/mup/m-gtp4-ipv6-dst_test.go b/internal/mup/m-gtp4-ipv6-dst_test.go deleted file mode 100644 index fcc794c..0000000 --- a/internal/mup/m-gtp4-ipv6-dst_test.go +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2023 Louis Royer and the NextMN-SRv6 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 mup - -import "net/netip" - -func ExampleMGTP4IPv6Dst() { - dst := NewMGTP4IPv6Dst(netip.MustParsePrefix("3fff::/20"), netip.MustParseAddr("203.0.113.1").As4(), NewArgsMobSession(0, false, false, 1)) - dst.Marshal() -} diff --git a/internal/mup/m-gtp4-ipv6-src.go b/internal/mup/m-gtp4-ipv6-src.go deleted file mode 100644 index d79423f..0000000 --- a/internal/mup/m-gtp4-ipv6-src.go +++ /dev/null @@ -1,177 +0,0 @@ -// Copyright 2023 Louis Royer and the NextMN-SRv6 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 mup - -import ( - "encoding/binary" - "net/netip" -) - -// RFC 9433, section 6.6 (End.M.GTP4.E): -// The IPv6 Source Address has the following format: -// -// 0 127 -// +----------------------+--------+--------------------------+ -// | Source UPF Prefix |IPv4 SA | any bit pattern(ignored) | -// +----------------------+--------+--------------------------+ -// 128-a-b a b -// Figure 10: IPv6 SA Encoding for End.M.GTP4.E -// -// With NextMN implementation, we choose to deviate from the RFC -// because RFC's proposal doesn't allow to retrieve -// the IPv4 SA without knowing the prefix length, -// which may be different for 2 packets issued from 2 different headends. -// -// To allow the endpoint to be stateless, we need to know the prefix. -// We propose to encode it on the 7 last bits of the IPv6 SA. -// -// The other option would have been to directly put the IPv4 SA at the end of the IPv6 SA (bytes 12 to 15), -// but this would imply matching on /128 if the IPv4 SA is used for source routing purpose, -// and thus breaking compatibility with future new patterns. -// -// We also introduce a new field that will carry the source UDP port to be used in the newly created GTP4 packet. -// -// This field is intended to help load balancing, as specified in [TS 129.281, section 4.4.2.0]: -// -// "For the GTP-U messages described below (other than the Echo Response message, see clause 4.4.2.2), the UDP Source Port -// or the Flow Label field (see IETF RFC 6437) should be set dynamically by the sending GTP-U entity to help -// balancing the load in the transport network". -// -// Since the headend has a better view than End.M.GTP4.E on -// the origin of the flows, and can be helped by the control plane, -// it makes sense to generate the source port number on headend side, -// and to carry it during transit through SR domain. -// -// Note: even with this proposal, the remaining space (73 bits) is bigger -// than what remains for LOC+FUNC in the SID (56 bits). -// -// 0 127 -// +----------------------+--------+----------------+--------------------------+---------------+ -// | Source UPF Prefix |IPv4 SA | UDP Source Port| any bit pattern(ignored) | Prefix length | -// +----------------------+--------+----------------+--------------------------+---------------+ -// 128-a-b'-c-7 a (32 bits) c (16 bits) b' 7 bits -// IPv6 SA Encoding for End.M.GTP4.E in NextMN -// -// [TS 129.281, section 4.4.2.0]: https://www.etsi.org/deliver/etsi_ts/129200_129299/129281/17.04.00_60/ts_129281v170400p.pdf#page=16 -type MGTP4IPv6Src struct { - prefix netip.Prefix // prefix in canonical form - ipv4 [IPV4_ADDR_SIZE_BYTE]byte - udp uint16 -} - -// NewMGTP4IPv6Src creates a nw MGTP4IPv6Src -func NewMGTP4IPv6Src(prefix netip.Prefix, ipv4 [IPV4_ADDR_SIZE_BYTE]byte, udpPortNumber uint16) *MGTP4IPv6Src { - return &MGTP4IPv6Src{ - prefix: prefix.Masked(), - ipv4: ipv4, - udp: udpPortNumber, - } -} - -// ParseMGTP4IPv6SrcNextMN parses a given IPv6 source address with NextMN bit pattern into a MGTP4IPv6Src -func ParseMGTP4IPv6SrcNextMN(addr [IPV6_ADDR_SIZE_BYTE]byte) (*MGTP4IPv6Src, error) { - // Prefix length extraction - prefixLen := uint(IPV6_LEN_ENCODING_MASK & (addr[IPV6_LEN_ENCODING_POS_BYTE] >> IPV6_LEN_ENCODING_POS_BIT)) - if prefixLen == 0 { - // even if globally routable IPv6 Prefix size cannot currently be less than 32 (per ICANN policy), - // nothing prevent the use of such prefix with ULA (fc00::/7) - // or, in the future, a prefix from a currently not yet allocated address block. - return nil, ErrPrefixLength - } - if prefixLen+IPV4_ADDR_SIZE_BIT+UDP_PORT_SIZE_BIT+IPV6_LEN_ENCODING_SIZE_BIT > IPV6_ADDR_SIZE_BIT { - return nil, ErrOutOfRange - } - - // udp port extraction - var udp [UDP_PORT_SIZE_BYTE]byte - if src, err := fromIPv6(addr, prefixLen+IPV4_ADDR_SIZE_BIT, UDP_PORT_SIZE_BYTE); err != nil { - return nil, err - } else { - copy(udp[:], src[:UDP_PORT_SIZE_BYTE]) - } - - if r, err := ParseMGTP4IPv6Src(addr, prefixLen); err != nil { - return nil, err - } else { - r.udp = binary.BigEndian.Uint16([]byte{udp[0], udp[1]}) - return r, nil - } -} - -// ParseMGTP4IPv6SrcNextMN parses a given IPv6 source address without any specific bit pattern into a MGTP4IPv6Src -func ParseMGTP4IPv6Src(addr [IPV6_ADDR_SIZE_BYTE]byte, prefixLen uint) (*MGTP4IPv6Src, error) { - // prefix extraction - a := netip.AddrFrom16(addr) - prefix := netip.PrefixFrom(a, int(prefixLen)).Masked() - - // ipv4 extraction - var ipv4 [IPV4_ADDR_SIZE_BYTE]byte - if src, err := fromIPv6(addr, prefixLen, IPV4_ADDR_SIZE_BYTE); err != nil { - return nil, err - } else { - copy(ipv4[:], src[:IPV4_ADDR_SIZE_BYTE]) - } - - return &MGTP4IPv6Src{ - prefix: prefix, - ipv4: ipv4, - }, nil -} - -// IPv4 returns the IPv4 Address encoded in the MGTP4IPv6Src. -func (e *MGTP4IPv6Src) IPv4() netip.Addr { - return netip.AddrFrom4(e.ipv4) -} - -// UDPPortNumber returns the UDP Port Number encoded in the MGTP4IPv6Src (0 if not set). -func (e *MGTP4IPv6Src) UDPPortNumber() uint16 { - return e.udp -} - -// MarshalLen returns the serial length of MGTP4IPv6Src. -func (a *MGTP4IPv6Src) MarshalLen() int { - return IPV6_ADDR_SIZE_BYTE -} - -// Marshal returns the byte sequence generated from MGTP4IPv6Src. -func (a *MGTP4IPv6Src) Marshal() ([]byte, error) { - b := make([]byte, a.MarshalLen()) - if err := a.MarshalTo(b); err != nil { - return nil, err - } - return b, nil -} - -// MarshalTo puts the byte sequence in the byte array given as b. -// warning: no caching is done, this result will be recomputed at each call -func (a *MGTP4IPv6Src) MarshalTo(b []byte) error { - if len(b) < a.MarshalLen() { - return ErrTooShortToMarshal - } - // init b with prefix - prefix := a.prefix.Addr().As16() - copy(b, prefix[:]) - - ipv4 := netip.AddrFrom4(a.ipv4).AsSlice() - udp := make([]byte, 2) - binary.BigEndian.PutUint16(udp, a.udp) - bits := a.prefix.Bits() - if bits == -1 { - return ErrPrefixLength - } - - // add ipv4 - if err := appendToSlice(b, uint(bits), ipv4); err != nil { - return err - } - // add upd port - if err := appendToSlice(b, uint(bits+IPV4_ADDR_SIZE_BIT), udp); err != nil { - return err - } - // add prefix length - b[IPV6_LEN_ENCODING_POS_BYTE] = byte(bits) - return nil -} diff --git a/internal/mup/m-gtp4-ipv6-src_test.go b/internal/mup/m-gtp4-ipv6-src_test.go deleted file mode 100644 index 2ff2c7e..0000000 --- a/internal/mup/m-gtp4-ipv6-src_test.go +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2023 Louis Royer and the NextMN-SRv6 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 mup - -import ( - "fmt" - "net/netip" - "testing" - - "github.com/google/go-cmp/cmp" -) - -func ExampleMGTP4IPv6Src() { - src := NewMGTP4IPv6Src(netip.MustParsePrefix("3fff::/20"), netip.MustParseAddr("203.0.113.1").As4(), 1337) - src.Marshal() -} - -func TestMGTP4IPv6Src(t *testing.T) { - ip_addr := [16]byte{ - 0x20, 0x01, 0xDB, 0x08, - 192, 0, 2, 1, - 0x01, 0x23, - 0x55, 0x55, 0x55, 0x55, 0x55, - 32, - } - - e, err := ParseMGTP4IPv6SrcNextMN(ip_addr) - if err != nil { - t.Fatal(err) - } - if e.IPv4().Compare(netip.MustParseAddr("192.0.2.1")) != 0 { - t.Fatalf("Cannot extract ipv4 correctly: %s", e.IPv4()) - } - if e.UDPPortNumber() != 0x0123 { - t.Fatalf("Cannot extract udp port number correctly: %x", e.UDPPortNumber()) - } - ip_addr2 := NewMGTP4IPv6Src(netip.MustParsePrefix("fd00:1:1::/48"), [4]byte{10, 0, 4, 1}, 0x1234) - b, err := ip_addr2.Marshal() - if err != nil { - t.Fatal(err) - } - res2 := []byte{ - 0xfd, 0x00, 0x00, 0x01, 0x00, 0x01, - 10, 0, 4, 1, - 0x12, 0x34, - 0x00, 0x00, 0x00, - 48, - } - fmt.Println(b) - fmt.Println(res2) - if diff := cmp.Diff(b, res2); diff != "" { - t.Error(diff) - } - -} diff --git a/internal/mup/utils.go b/internal/mup/utils.go deleted file mode 100644 index 6b04e12..0000000 --- a/internal/mup/utils.go +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2023 Louis Royer and the NextMN-SRv6 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 mup - -// ipv6: Address to extract bits from -// startBit: offset in bits -// length: length of result in Bytes -func fromIPv6(ipv6 [IPV6_ADDR_SIZE_BYTE]byte, startBit uint, length uint) ([]byte, error) { - if uint(len(ipv6)) < length { - return nil, ErrTooShortToParse - } - if startBit > IPV6_ADDR_SIZE_BIT { - return nil, ErrOutOfRange - } - startByte := startBit / 8 - offset := startBit % 8 - ret := make([]byte, length) - if offset == 0 { - copy(ret, ipv6[startByte:startByte+length]) - return ret, nil - } - - // init left - for i, b := range ipv6[startByte : startByte+length] { - ret[i] = (b << offset) - } - // init right - for i, b := range ipv6[startByte+1 : startByte+length] { - ret[i] |= b >> (8 - offset) - } - return ret, nil -} - -// usage conditions : -// 1. slice must be large enough -// 2. every bit after endBit should be zero (no reset is performed in the function) -func appendToSlice(slice []byte, endBit uint, appendThis []byte) error { - endByte := endBit / 8 - offset := endBit % 8 - isOffset := 0 - if offset > 0 { - isOffset = 1 - } - if isOffset+int(endByte)+len(appendThis) > len(slice) { - return ErrTooShortToMarshal - } - if offset == 0 { - // concatenate slices - copy(slice[endByte:], appendThis[:]) - return nil - } - // add right part of bytes - for i, b := range appendThis { - slice[int(endByte)+i] |= b >> offset - } - // add left part of bytes - for i, b := range appendThis { - slice[int(endByte)+isOffset+i] |= b << (8 - offset) - } - return nil -} diff --git a/internal/mup/utils_test.go b/internal/mup/utils_test.go deleted file mode 100644 index 2c79562..0000000 --- a/internal/mup/utils_test.go +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2023 Louis Royer and the NextMN-SRv6 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 mup - -import ( - "net/netip" - "testing" - - "github.com/google/go-cmp/cmp" -) - -func TestFromIPv6(t *testing.T) { - res, err := fromIPv6(netip.MustParseAddr("::ff:192.168.0.1").As16(), 128-8*4, 4) - if err != nil { - t.Fatal(err) - } - if diff := cmp.Diff(res, []byte{192, 168, 0, 1}); diff != "" { - t.Error(diff) - } - res, err = fromIPv6(netip.MustParseAddr("ff00::").As16(), 1, 1) - if err != nil { - t.Fatal(err) - } - if diff := cmp.Diff(res, []byte{0xFE}); diff != "" { - t.Error(diff) - } - res, err = fromIPv6(netip.MustParseAddr("ff55::").As16(), 2, 2) - if err != nil { - t.Fatal(err) - } - if diff := cmp.Diff(res, []byte{0xFD, 0x54}); diff != "" { - t.Error(diff) - } -} - -func TestAppendToSlice(t *testing.T) { - b1 := []byte{0xFF, 0x00, 0x00, 0x00} - if err := appendToSlice(b1, 8, []byte{0x00, 0xAA}); err != nil { - t.Fatal(err) - } - if diff := cmp.Diff(b1, []byte{0xFF, 0x00, 0xAA, 0x00}); diff != "" { - t.Error(diff) - } - b2 := []byte{0xE0, 0x00, 0x00, 0x00} - if err := appendToSlice(b2, 3, []byte{0x00, 0xAA, 0xFF}); err != nil { - t.Fatal(err) - } - if diff := cmp.Diff(b2, []byte{0xE0, 0x15, 0x5F, 0xE0}); diff != "" { - t.Error(diff) - } -} diff --git a/internal/netfunc/endpoint-m-gtp4-e.go b/internal/netfunc/endpoint-m-gtp4-e.go index 7661591..ea872db 100644 --- a/internal/netfunc/endpoint-m-gtp4-e.go +++ b/internal/netfunc/endpoint-m-gtp4-e.go @@ -11,10 +11,12 @@ import ( "github.com/google/gopacket" "github.com/google/gopacket/layers" + gopacket_gtp "github.com/nextmn/gopacket-gtp" gopacket_srv6 "github.com/nextmn/gopacket-srv6" + "github.com/nextmn/rfc9433/encoding" + "github.com/nextmn/srv6/internal/constants" - "github.com/nextmn/srv6/internal/mup" ) type EndpointMGTP4E struct { @@ -28,7 +30,7 @@ func NewEndpointMGTP4E(prefix netip.Prefix, ttl uint8, hopLimit uint8) *Endpoint } // Get IPv6 Destination Address Fields from Packet -func (e EndpointMGTP4E) ipv6DAFields(p *Packet) (*mup.MGTP4IPv6Dst, error) { +func (e EndpointMGTP4E) ipv6DAFields(p *Packet) (*encoding.MGTP4IPv6Dst, error) { layerIPv6 := p.Layer(layers.LayerTypeIPv6) if layerIPv6 == nil { return nil, fmt.Errorf("Malformed IPv6 packet") @@ -39,7 +41,7 @@ func (e EndpointMGTP4E) ipv6DAFields(p *Packet) (*mup.MGTP4IPv6Dst, error) { if prefix < 0 { return nil, fmt.Errorf("Wrong prefix") } - if dst, err := mup.ParseMGTP4IPv6Dst([16]byte(dstSlice), uint(prefix)); err != nil { + if dst, err := encoding.ParseMGTP4IPv6Dst([16]byte(dstSlice), uint(prefix)); err != nil { return nil, err } else { return dst, nil @@ -47,14 +49,14 @@ func (e EndpointMGTP4E) ipv6DAFields(p *Packet) (*mup.MGTP4IPv6Dst, error) { } // Get IPv6 Source Address Fields from Packet -func (e EndpointMGTP4E) ipv6SAFields(p *Packet) (*mup.MGTP4IPv6Src, error) { +func (e EndpointMGTP4E) ipv6SAFields(p *Packet) (*encoding.MGTP4IPv6Src, error) { layerIPv6 := p.Layer(layers.LayerTypeIPv6) if layerIPv6 == nil { return nil, fmt.Errorf("Malformed IPv6 packet") } // get destination address srcSlice := layerIPv6.(*layers.IPv6).NetworkFlow().Src().Raw() - if src, err := mup.ParseMGTP4IPv6SrcNextMN([16]byte(srcSlice)); err != nil { + if src, err := encoding.ParseMGTP4IPv6SrcNextMN([16]byte(srcSlice)); err != nil { return nil, err } else { return src, nil diff --git a/internal/netfunc/headend-gtp4-ctrl.go b/internal/netfunc/headend-gtp4-ctrl.go index 7ef5781..cd1bb54 100644 --- a/internal/netfunc/headend-gtp4-ctrl.go +++ b/internal/netfunc/headend-gtp4-ctrl.go @@ -13,9 +13,11 @@ import ( "github.com/google/gopacket" "github.com/google/gopacket/layers" + gopacket_srv6 "github.com/nextmn/gopacket-srv6" + "github.com/nextmn/rfc9433/encoding" + db_api "github.com/nextmn/srv6/internal/database/api" - "github.com/nextmn/srv6/internal/mup" ) type HeadendGTP4WithCtrl struct { @@ -70,7 +72,7 @@ func (h HeadendGTP4WithCtrl) Handle(ctx context.Context, packet []byte) ([]byte, udpSP := pqt.TransportLayer().TransportFlow().Src().Raw() srcPrefix := netip.MustParsePrefix("fc00:1:1::/48") // FIXME: dont hardcode - ipv6SA := mup.NewMGTP4IPv6Src(srcPrefix, [4]byte(ipv4SA), binary.BigEndian.Uint16(udpSP)) + ipv6SA := encoding.NewMGTP4IPv6Src(srcPrefix, [4]byte(ipv4SA), binary.BigEndian.Uint16(udpSP)) src, err := ipv6SA.Marshal() if err != nil { diff --git a/internal/netfunc/headend-gtp4.go b/internal/netfunc/headend-gtp4.go index 54add14..989f39f 100644 --- a/internal/netfunc/headend-gtp4.go +++ b/internal/netfunc/headend-gtp4.go @@ -13,9 +13,11 @@ import ( "github.com/google/gopacket" "github.com/google/gopacket/layers" + gopacket_srv6 "github.com/nextmn/gopacket-srv6" + "github.com/nextmn/rfc9433/encoding" + "github.com/nextmn/srv6/internal/config" - "github.com/nextmn/srv6/internal/mup" ) type HeadendGTP4 struct { @@ -79,7 +81,7 @@ func (h HeadendGTP4) Handle(ctx context.Context, packet []byte) ([]byte, error) } } ipv4DA := pqt.NetworkLayer().NetworkFlow().Dst().Raw() - argsMobSession := mup.NewArgsMobSession(qfi, reflectiveQosIndication, false, teid) + argsMobSession := encoding.NewArgsMobSession(qfi, reflectiveQosIndication, false, teid) var innerHeaderIPv4 netip.Addr isInnerHeaderIPv4 := false @@ -142,14 +144,14 @@ func (h HeadendGTP4) Handle(ctx context.Context, packet []byte) ([]byte, error) if err != nil { return nil, err } - ipv6DA := mup.NewMGTP4IPv6Dst(dstPrefix, [4]byte(ipv4DA), argsMobSession) + ipv6DA := encoding.NewMGTP4IPv6Dst(dstPrefix, [4]byte(ipv4DA), argsMobSession) // S04. Copy IPv4 SA to form IPv6 SA B' ipv4SA := pqt.NetworkLayer().NetworkFlow().Src().Raw() udpSP := pqt.TransportLayer().TransportFlow().Src().Raw() srcPrefix := h.sourceAddressPrefix - ipv6SA := mup.NewMGTP4IPv6Src(srcPrefix, [4]byte(ipv4SA), binary.BigEndian.Uint16(udpSP)) + ipv6SA := encoding.NewMGTP4IPv6Src(srcPrefix, [4]byte(ipv4SA), binary.BigEndian.Uint16(udpSP)) if err != nil { return nil, fmt.Errorf("Error during creation of IPv6 SA: %s", err) }