From a8dc1c689ec5b86b73d92d58221106505edc8903 Mon Sep 17 00:00:00 2001 From: Louis Royer Date: Wed, 4 Dec 2024 13:59:12 +0100 Subject: [PATCH] Update jsonapi --- go.mod | 22 ++++---- go.sum | 47 ++++++++--------- internal/app/setup.go | 2 +- internal/config/config.go | 14 ++--- internal/config/control.go | 4 +- internal/ctrl/controller-registry.go | 5 +- internal/ctrl/rules-registry.go | 6 ++- internal/database/api/downlink.go | 4 +- internal/database/api/uplink.go | 4 +- internal/database/database.go | 75 ++++++++++++++------------- internal/netfunc/packet.go | 13 +++-- internal/tasks/controller-registry.go | 5 +- internal/tasks/http-server.go | 7 +-- 13 files changed, 108 insertions(+), 100 deletions(-) diff --git a/go.mod b/go.mod index b7c44ef..5cc7874 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/lib/pq v1.10.9 github.com/nextmn/gopacket-gtp v0.0.8-0.20241203192927-2f656a5e3753 github.com/nextmn/gopacket-srv6 v0.0.8 - github.com/nextmn/json-api v0.0.13 + github.com/nextmn/json-api v0.0.14 github.com/nextmn/logrus-formatter v0.0.1 github.com/nextmn/rfc9433 v0.0.2 github.com/sirupsen/logrus v1.9.3 @@ -20,19 +20,19 @@ require ( ) require ( - github.com/bytedance/sonic v1.12.3 // indirect - github.com/bytedance/sonic/loader v0.2.0 // indirect + github.com/bytedance/sonic v1.12.5 // indirect + github.com/bytedance/sonic/loader v0.2.1 // indirect github.com/cloudwego/base64x v0.1.4 // indirect github.com/cloudwego/iasm v0.2.0 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect - github.com/gabriel-vasile/mimetype v1.4.6 // indirect + github.com/gabriel-vasile/mimetype v1.4.7 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.22.1 // indirect + github.com/go-playground/validator/v10 v10.23.0 // indirect github.com/goccy/go-json v0.10.3 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/klauspost/cpuid/v2 v2.2.8 // indirect + github.com/klauspost/cpuid/v2 v2.2.9 // indirect github.com/leodido/go-urn v1.4.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect @@ -42,10 +42,10 @@ require ( github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.12 // indirect github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect - golang.org/x/arch v0.11.0 // indirect - golang.org/x/crypto v0.28.0 // indirect - golang.org/x/net v0.30.0 // indirect + golang.org/x/arch v0.12.0 // indirect + golang.org/x/crypto v0.29.0 // indirect + golang.org/x/net v0.31.0 // indirect golang.org/x/sys v0.27.0 // indirect - golang.org/x/text v0.19.0 // indirect - google.golang.org/protobuf v1.35.1 // indirect + golang.org/x/text v0.20.0 // indirect + google.golang.org/protobuf v1.35.2 // indirect ) diff --git a/go.sum b/go.sum index 5a58f8c..4bbd8e2 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,10 @@ github.com/adrg/xdg v0.5.3 h1:xRnxJXne7+oWDatRhR1JLnvuccuIeCoBu2rtuLqQB78= github.com/adrg/xdg v0.5.3/go.mod h1:nlTsY+NNiCBGCK2tpm09vRqfVzrc2fLmXGpBLF0zlTQ= -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 v1.12.5 h1:hoZxY8uW+mT+OpkcUWw4k0fDINtOcVavEsGfzwzFU/w= +github.com/bytedance/sonic v1.12.5/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk= github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= -github.com/bytedance/sonic/loader v0.2.0 h1:zNprn+lsIP06C/IqCHs3gPQIvnvpKbbxyXQP1iU4kWM= -github.com/bytedance/sonic/loader v0.2.0/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= +github.com/bytedance/sonic/loader v0.2.1 h1:1GgorWTqf12TA8mma4DDSbaQigE2wOgQo7iCjjJv3+E= +github.com/bytedance/sonic/loader v0.2.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y= github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= @@ -14,8 +14,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 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/gabriel-vasile/mimetype v1.4.6 h1:3+PzJTKLkvgjeTbts6msPJt4DixhT4YtFNf1gtGe3zc= -github.com/gabriel-vasile/mimetype v1.4.6/go.mod h1:JX1qVKqZd40hUPpAfiNTe0Sne7hdfKSbOqqmkq8GCXc= +github.com/gabriel-vasile/mimetype v1.4.7 h1:SKFKl7kD0RiPdbht0s7hFtjl489WcQ1VyPW8ZzUMYCA= +github.com/gabriel-vasile/mimetype v1.4.7/go.mod h1:GDlAgAyIRT27BhFl53XNAFtfjzOkLaF35JdEG0P7LtU= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= @@ -26,8 +26,8 @@ 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.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA= -github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= +github.com/go-playground/validator/v10 v10.23.0 h1:/PwmTwZhS0dPkav3cdK9kV1FsAmrL8sThn8IHr/sO+o= +github.com/go-playground/validator/v10 v10.23.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA= github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA= @@ -40,8 +40,8 @@ github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM= -github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/klauspost/cpuid/v2 v2.2.9 h1:66ze0taIn2H33fBvCkXuv9BmCwDfafmiIVpKV9kKGuY= +github.com/klauspost/cpuid/v2 v2.2.9/go.mod h1:rqkxqrZ1EhYM9G+hXH7YdowN5R5RGN6NK4QwQ3WMXF8= github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= @@ -54,14 +54,12 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/nextmn/gopacket-gtp v0.0.7 h1:O2cuShLTlpVBEXyHn9OIi1Nd+j4QCB66RAwzKBeyscI= -github.com/nextmn/gopacket-gtp v0.0.7/go.mod h1:94jLjLU04IOVTKBXUP09MXZCgmlizqmflU2ion1ht6E= github.com/nextmn/gopacket-gtp v0.0.8-0.20241203192927-2f656a5e3753 h1:jfdtkHj5JkjAd2Puv5geF6TCBUIhbpie2LpGeOofbCA= github.com/nextmn/gopacket-gtp v0.0.8-0.20241203192927-2f656a5e3753/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.13 h1:k8Z0Oo9et5PvdCa4wUmJE9TAHJp1zTkoAmvy1LQcoyQ= -github.com/nextmn/json-api v0.0.13/go.mod h1:CQXeNPj9MDGsEExtnqJFIGjLgZAKsmOoO2fy+mep7Ak= +github.com/nextmn/json-api v0.0.14 h1:m4uHOVcXsxkXoxbrhqemLTRG4T86eYkejjirew1nDUU= +github.com/nextmn/json-api v0.0.14/go.mod h1:CQXeNPj9MDGsEExtnqJFIGjLgZAKsmOoO2fy+mep7Ak= github.com/nextmn/logrus-formatter v0.0.1 h1:Bsf78jjiEESc+rV8xE6IyKj4frDPGMwXFNrLQzm6A1E= github.com/nextmn/logrus-formatter v0.0.1/go.mod h1:vdSZ+sIcSna8vjbXkSFxsnsKHqRwaUEed4JCPcXoGyM= github.com/nextmn/rfc9433 v0.0.2 h1:6FjMY+Qy8MNXQ0PPxezUsyXDxJiCbTp5j3OcXQgIQh8= @@ -94,33 +92,32 @@ github.com/urfave/cli/v2 v2.27.5 h1:WoHEJLdsXr6dDWoJgMq/CboDmyY/8HMMH1fTECbih+w= github.com/urfave/cli/v2 v2.27.5/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ= 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.11.0 h1:KXV8WWKCXm6tRpLirl2szsO5j/oOODwZf4hATmGVNs4= -golang.org/x/arch v0.11.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= +golang.org/x/arch v0.12.0 h1:UsYJhbzPYGsT0HbEdmYcqtCv8UNGvnaL561NnIUvaKg= +golang.org/x/arch v0.12.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.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= -golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= +golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ= +golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg= 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.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= -golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= +golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo= +golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 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.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s= golang.org/x/sys v0.27.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.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= -golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug= +golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4= golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= -google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io= +google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/app/setup.go b/internal/app/setup.go index 02b7780..0d12836 100644 --- a/internal/app/setup.go +++ b/internal/app/setup.go @@ -11,7 +11,7 @@ import ( app_api "github.com/nextmn/srv6/internal/app/api" "github.com/nextmn/srv6/internal/config" "github.com/nextmn/srv6/internal/constants" - tasks "github.com/nextmn/srv6/internal/tasks" + "github.com/nextmn/srv6/internal/tasks" tasks_api "github.com/nextmn/srv6/internal/tasks/api" ) diff --git a/internal/config/config.go b/internal/config/config.go index b1a9ea8..0ffa2db 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -11,6 +11,7 @@ import ( "path/filepath" "github.com/nextmn/json-api/jsonapi" + "github.com/nextmn/json-api/jsonapi/n4tosrv6" "gopkg.in/yaml.v3" ) @@ -34,12 +35,11 @@ type SRv6Config struct { Hooks *Hooks `yaml:"hooks"` // interface with controller - Control Control `yaml:"control"` - // TODO: use a better type for this information - ControllerURI jsonapi.ControlURI `yaml:"controller-uri"` // example: http://192.0.2.2/8080 + Control Control `yaml:"control"` + ControllerURI jsonapi.ControlURI `yaml:"controller-uri"` // example: http://192.0.2.2:8080 // Backbone IPv6 address - BackboneIP jsonapi.BackboneIP `yaml:"backbone-ip"` + BackboneIP n4tosrv6.BackboneIP `yaml:"backbone-ip"` // headends LinuxHeadendSetSourceAddress *netip.Addr `yaml:"linux-headend-set-source-address,omitempty"` @@ -48,7 +48,7 @@ type SRv6Config struct { Headends Headends `yaml:"headends"` // endpoints - Locator *jsonapi.Locator `yaml:"locator,omitempty"` // example of locator: fd00:51D5:0000:1::/64 - Endpoints Endpoints `yaml:"endpoints"` - Logger *Logger `yaml:"logger,omitempty"` + Locator *n4tosrv6.Locator `yaml:"locator,omitempty"` // example of locator: fd00:51D5:0000:1::/64 + Endpoints Endpoints `yaml:"endpoints"` + Logger *Logger `yaml:"logger,omitempty"` } diff --git a/internal/config/control.go b/internal/config/control.go index b83d3e7..ec14380 100644 --- a/internal/config/control.go +++ b/internal/config/control.go @@ -6,10 +6,12 @@ package config import ( + "net/netip" + "github.com/nextmn/json-api/jsonapi" ) type Control struct { Uri jsonapi.ControlURI `yaml:"uri"` // may contain domain name instead of ip address - BindAddr string `yaml:"bind-addr"` // in the form `ip:port` + BindAddr netip.AddrPort `yaml:"bind-addr"` // in the form `ip:port` } diff --git a/internal/ctrl/controller-registry.go b/internal/ctrl/controller-registry.go index fbc2a54..bc6073d 100644 --- a/internal/ctrl/controller-registry.go +++ b/internal/ctrl/controller-registry.go @@ -6,12 +6,13 @@ package ctrl import ( "github.com/nextmn/json-api/jsonapi" + "github.com/nextmn/json-api/jsonapi/n4tosrv6" ) type ControllerRegistry struct { RemoteControlURI jsonapi.ControlURI // URI of the controller LocalControlURI jsonapi.ControlURI // URI of the router, used to control it - Locator jsonapi.Locator - Backbone jsonapi.BackboneIP + Locator n4tosrv6.Locator + Backbone n4tosrv6.BackboneIP Resource string } diff --git a/internal/ctrl/rules-registry.go b/internal/ctrl/rules-registry.go index c4eb092..a96697a 100644 --- a/internal/ctrl/rules-registry.go +++ b/internal/ctrl/rules-registry.go @@ -10,9 +10,11 @@ import ( "github.com/nextmn/srv6/internal/database" + "github.com/nextmn/json-api/jsonapi" + "github.com/nextmn/json-api/jsonapi/n4tosrv6" + "github.com/gin-gonic/gin" "github.com/gofrs/uuid" - "github.com/nextmn/json-api/jsonapi" "github.com/sirupsen/logrus" ) @@ -139,7 +141,7 @@ func (rr *RulesRegistry) SwitchRule(c *gin.Context) { // Post a new rule func (rr *RulesRegistry) PostRule(c *gin.Context) { - var rule jsonapi.Rule + var rule n4tosrv6.Rule if err := c.BindJSON(&rule); err != nil { logrus.WithError(err).Error("could not deserialize") c.JSON(http.StatusBadRequest, jsonapi.MessageWithError{Message: "could not deserialize", Error: err}) diff --git a/internal/database/api/downlink.go b/internal/database/api/downlink.go index b3fc6b6..9bdee11 100644 --- a/internal/database/api/downlink.go +++ b/internal/database/api/downlink.go @@ -8,9 +8,9 @@ import ( "context" "net/netip" - "github.com/nextmn/json-api/jsonapi" + "github.com/nextmn/json-api/jsonapi/n4tosrv6" ) type Downlink interface { - GetDownlinkAction(ctx context.Context, ueIp netip.Addr) (jsonapi.Action, error) + GetDownlinkAction(ctx context.Context, ueIp netip.Addr) (n4tosrv6.Action, error) } diff --git a/internal/database/api/uplink.go b/internal/database/api/uplink.go index f124d7e..9ef0828 100644 --- a/internal/database/api/uplink.go +++ b/internal/database/api/uplink.go @@ -8,9 +8,9 @@ import ( "context" "net/netip" - "github.com/nextmn/json-api/jsonapi" + "github.com/nextmn/json-api/jsonapi/n4tosrv6" ) type Uplink interface { - GetUplinkAction(ctx context.Context, UplinkTeid uint32, GnbIp netip.Addr, UeIp netip.Addr, ServiceIp netip.Addr) (jsonapi.Action, error) + GetUplinkAction(ctx context.Context, UplinkTeid uint32, GnbIp netip.Addr, UeIp netip.Addr, ServiceIp netip.Addr) (n4tosrv6.Action, error) } diff --git a/internal/database/database.go b/internal/database/database.go index eeb183c..692f9b6 100644 --- a/internal/database/database.go +++ b/internal/database/database.go @@ -12,9 +12,10 @@ import ( "net/netip" "strings" + "github.com/nextmn/json-api/jsonapi/n4tosrv6" + "github.com/gofrs/uuid" "github.com/lib/pq" - "github.com/nextmn/json-api/jsonapi" ) //go:generate go run gen.go database.sql @@ -82,7 +83,7 @@ func (db *Database) Exit() { } } -func (db *Database) InsertRule(ctx context.Context, r jsonapi.Rule) (*uuid.UUID, error) { +func (db *Database) InsertRule(ctx context.Context, r n4tosrv6.Rule) (*uuid.UUID, error) { srh := []string{} for _, ip := range r.Action.SRH { srh = append(srh, ip.String()) @@ -130,7 +131,7 @@ func (db *Database) InsertRule(ctx context.Context, r jsonapi.Rule) (*uuid.UUID, } } -func (db *Database) GetRule(ctx context.Context, uuid uuid.UUID) (jsonapi.Rule, error) { +func (db *Database) GetRule(ctx context.Context, uuid uuid.UUID) (n4tosrv6.Rule, error) { var type_uplink bool var enabled bool var action_srh []string @@ -141,15 +142,15 @@ func (db *Database) GetRule(ctx context.Context, uuid uuid.UUID) (jsonapi.Rule, if stmt, ok := db.stmt["get_rule"]; ok { err := stmt.QueryRowContext(ctx, uuid.String()).Scan(&type_uplink, &enabled, pq.Array(&action_srh), &match_ue_ip, &match_gnb_ip, &match_uplink_teid, &match_service_ip) if err != nil { - return jsonapi.Rule{}, err + return n4tosrv6.Rule{}, err } - rule := jsonapi.Rule{ + rule := n4tosrv6.Rule{ Enabled: enabled, - Match: jsonapi.Match{}, + Match: n4tosrv6.Match{}, } if type_uplink { rule.Type = "uplink" - rule.Match.Header = &jsonapi.GtpHeader{} + rule.Match.Header = &n4tosrv6.GtpHeader{} if match_gnb_ip != nil { p, err := netip.ParsePrefix(*match_gnb_ip) if err == nil && p.Bits() == 32 { @@ -162,7 +163,7 @@ func (db *Database) GetRule(ctx context.Context, uuid uuid.UUID) (jsonapi.Rule, if match_service_ip != nil { p, err := netip.ParsePrefix(*match_service_ip) if err == nil && p.Bits() == 32 { - rule.Match.Payload = &jsonapi.Payload{ + rule.Match.Payload = &n4tosrv6.Payload{ Dst: p.Addr(), } } @@ -176,27 +177,27 @@ func (db *Database) GetRule(ctx context.Context, uuid uuid.UUID) (jsonapi.Rule, a := p.Addr() rule.Match.Header.InnerIpSrc = &a } else { - rule.Match.Payload = &jsonapi.Payload{ + rule.Match.Payload = &n4tosrv6.Payload{ Dst: p.Addr(), } } } - srh, err := jsonapi.NewSRH(action_srh) + srh, err := n4tosrv6.NewSRH(action_srh) if err != nil { - return jsonapi.Rule{}, err + return n4tosrv6.Rule{}, err } - rule.Action = jsonapi.Action{ + rule.Action = n4tosrv6.Action{ SRH: *srh, } return rule, err } else { - return jsonapi.Rule{}, fmt.Errorf("Procedure not registered") + return n4tosrv6.Rule{}, fmt.Errorf("Procedure not registered") } } -func (db *Database) GetRules(ctx context.Context) (jsonapi.RuleMap, error) { +func (db *Database) GetRules(ctx context.Context) (n4tosrv6.RuleMap, error) { var uuid uuid.UUID var type_uplink bool var enabled bool @@ -205,7 +206,7 @@ func (db *Database) GetRules(ctx context.Context) (jsonapi.RuleMap, error) { var match_gnb_ip *string var match_uplink_teid *uint32 var match_service_ip *string - m := jsonapi.RuleMap{} + m := n4tosrv6.RuleMap{} if stmt, ok := db.stmt["get_all_rules"]; ok { rows, err := stmt.QueryContext(ctx) if err != nil { @@ -215,19 +216,19 @@ func (db *Database) GetRules(ctx context.Context) (jsonapi.RuleMap, error) { select { case <-ctx.Done(): // avoid looping if no longer necessary - return jsonapi.RuleMap{}, ctx.Err() + return n4tosrv6.RuleMap{}, ctx.Err() default: err := rows.Scan(&uuid, &type_uplink, &enabled, pq.Array(&action_srh), &match_ue_ip, &match_gnb_ip, &match_uplink_teid, &match_service_ip) if err != nil { return m, err } - rule := jsonapi.Rule{ + rule := n4tosrv6.Rule{ Enabled: enabled, - Match: jsonapi.Match{}, + Match: n4tosrv6.Match{}, } if type_uplink { rule.Type = "uplink" - rule.Match.Header = &jsonapi.GtpHeader{} + rule.Match.Header = &n4tosrv6.GtpHeader{} if match_gnb_ip != nil { p, err := netip.ParsePrefix(*match_gnb_ip) if err == nil && p.Bits() == 32 { @@ -240,7 +241,7 @@ func (db *Database) GetRules(ctx context.Context) (jsonapi.RuleMap, error) { if match_service_ip != nil { p, err := netip.ParsePrefix(*match_service_ip) if err == nil && p.Bits() == 32 { - rule.Match.Payload = &jsonapi.Payload{ + rule.Match.Payload = &n4tosrv6.Payload{ Dst: p.Addr(), } } @@ -254,18 +255,18 @@ func (db *Database) GetRules(ctx context.Context) (jsonapi.RuleMap, error) { a := p.Addr() rule.Match.Header.InnerIpSrc = &a } else { - rule.Match.Payload = &jsonapi.Payload{ + rule.Match.Payload = &n4tosrv6.Payload{ Dst: p.Addr(), } } } - srh, err := jsonapi.NewSRH(action_srh) + srh, err := n4tosrv6.NewSRH(action_srh) if err != nil { - return jsonapi.RuleMap{}, err + return n4tosrv6.RuleMap{}, err } - rule.Action = jsonapi.Action{ + rule.Action = n4tosrv6.Action{ SRH: *srh, } m[uuid] = rule @@ -274,7 +275,7 @@ func (db *Database) GetRules(ctx context.Context) (jsonapi.RuleMap, error) { return m, nil } else { - return jsonapi.RuleMap{}, fmt.Errorf("Procedure not registered") + return n4tosrv6.RuleMap{}, fmt.Errorf("Procedure not registered") } } @@ -314,36 +315,36 @@ func (db *Database) DeleteRule(ctx context.Context, uuid uuid.UUID) error { } } -func (db *Database) GetUplinkAction(ctx context.Context, uplinkTeid uint32, gnbIp netip.Addr, ueIp netip.Addr, serviceIp netip.Addr) (jsonapi.Action, error) { +func (db *Database) GetUplinkAction(ctx context.Context, uplinkTeid uint32, gnbIp netip.Addr, ueIp netip.Addr, serviceIp netip.Addr) (n4tosrv6.Action, error) { var action_srh []string if stmt, ok := db.stmt["get_uplink_action"]; ok { err := stmt.QueryRowContext(ctx, uplinkTeid, gnbIp.String(), ueIp.String(), serviceIp.String()).Scan(pq.Array(&action_srh)) if err != nil { - return jsonapi.Action{}, err + return n4tosrv6.Action{}, err } - srh, err := jsonapi.NewSRH(action_srh) + srh, err := n4tosrv6.NewSRH(action_srh) if err != nil { - return jsonapi.Action{}, err + return n4tosrv6.Action{}, err } - return jsonapi.Action{SRH: *srh}, err + return n4tosrv6.Action{SRH: *srh}, err } else { - return jsonapi.Action{}, fmt.Errorf("Procedure not registered") + return n4tosrv6.Action{}, fmt.Errorf("Procedure not registered") } } -func (db *Database) GetDownlinkAction(ctx context.Context, ueIp netip.Addr) (jsonapi.Action, error) { +func (db *Database) GetDownlinkAction(ctx context.Context, ueIp netip.Addr) (n4tosrv6.Action, error) { var action_srh []string if stmt, ok := db.stmt["get_downlink_action"]; ok { err := stmt.QueryRowContext(ctx, ueIp.String()).Scan(pq.Array(&action_srh)) if err != nil { - return jsonapi.Action{}, err + return n4tosrv6.Action{}, err } - srh, err := jsonapi.NewSRH(action_srh) + srh, err := n4tosrv6.NewSRH(action_srh) if err != nil { - return jsonapi.Action{}, err + return n4tosrv6.Action{}, err } - return jsonapi.Action{SRH: *srh}, err + return n4tosrv6.Action{SRH: *srh}, err } else { - return jsonapi.Action{}, fmt.Errorf("Procedure not registered") + return n4tosrv6.Action{}, fmt.Errorf("Procedure not registered") } } diff --git a/internal/netfunc/packet.go b/internal/netfunc/packet.go index e9f5ffb..fcc8df6 100644 --- a/internal/netfunc/packet.go +++ b/internal/netfunc/packet.go @@ -2,6 +2,7 @@ // 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 netfunc import ( @@ -10,11 +11,13 @@ import ( "fmt" "net/netip" - "github.com/google/gopacket" - "github.com/google/gopacket/layers" - json_api "github.com/nextmn/json-api/jsonapi" "github.com/nextmn/srv6/internal/constants" db_api "github.com/nextmn/srv6/internal/database/api" + + "github.com/nextmn/json-api/jsonapi/n4tosrv6" + + "github.com/google/gopacket" + "github.com/google/gopacket/layers" ) type Packet struct { @@ -86,11 +89,11 @@ func (p *Packet) GetSrcAddr() (netip.Addr, error) { } // Returns the DownlinkAction related to this packet -func (p *Packet) DownlinkAction(ctx context.Context, db db_api.Downlink) (json_api.Action, error) { +func (p *Packet) DownlinkAction(ctx context.Context, db db_api.Downlink) (n4tosrv6.Action, error) { dstSlice := p.NetworkLayer().NetworkFlow().Dst().Raw() dst, ok := netip.AddrFromSlice(dstSlice) if !ok { - return json_api.Action{}, fmt.Errorf("Malformed packet") + return n4tosrv6.Action{}, fmt.Errorf("Malformed packet") } return db.GetDownlinkAction(ctx, dst) } diff --git a/internal/tasks/controller-registry.go b/internal/tasks/controller-registry.go index f8b74c7..a5299d8 100644 --- a/internal/tasks/controller-registry.go +++ b/internal/tasks/controller-registry.go @@ -15,6 +15,7 @@ import ( "github.com/nextmn/srv6/internal/ctrl" "github.com/nextmn/json-api/jsonapi" + "github.com/nextmn/json-api/jsonapi/n4tosrv6" ) const UserAgent = "go-github-nextmn-srv6" @@ -29,7 +30,7 @@ type ControllerRegistryTask struct { } // Create a new ControllerRegistry -func NewControllerRegistryTask(name string, remoteControlURI jsonapi.ControlURI, backbone jsonapi.BackboneIP, locator jsonapi.Locator, localControlURI jsonapi.ControlURI, setup_registry app_api.Registry) *ControllerRegistryTask { +func NewControllerRegistryTask(name string, remoteControlURI jsonapi.ControlURI, backbone n4tosrv6.BackboneIP, locator n4tosrv6.Locator, localControlURI jsonapi.ControlURI, setup_registry app_api.Registry) *ControllerRegistryTask { return &ControllerRegistryTask{ WithName: NewName(name), WithState: NewState(), @@ -52,7 +53,7 @@ func (t *ControllerRegistryTask) RunInit(ctx context.Context) error { } else { return fmt.Errorf("could not register controllerregistry") } - data := jsonapi.Router{ + data := n4tosrv6.Router{ Locator: t.ControllerRegistry.Locator, Backbone: t.ControllerRegistry.Backbone, Control: t.ControllerRegistry.LocalControlURI, diff --git a/internal/tasks/http-server.go b/internal/tasks/http-server.go index f2c0f79..ecb58bf 100644 --- a/internal/tasks/http-server.go +++ b/internal/tasks/http-server.go @@ -9,6 +9,7 @@ import ( "fmt" "net" "net/http" + "net/netip" "time" app_api "github.com/nextmn/srv6/internal/app/api" @@ -25,13 +26,13 @@ type HttpServerTask struct { WithName WithState srv *http.Server - httpAddr string + httpAddr netip.AddrPort rulesRegistryHTTP ctrl_api.RulesRegistryHTTP setupRegistry app_api.Registry } // Create a new HttpServerTask -func NewHttpServerTask(name string, httpAddr string, setupRegistry app_api.Registry) *HttpServerTask { +func NewHttpServerTask(name string, httpAddr netip.AddrPort, setupRegistry app_api.Registry) *HttpServerTask { return &HttpServerTask{ WithName: NewName(name), WithState: NewState(), @@ -67,7 +68,7 @@ func (t *HttpServerTask) RunInit(ctx context.Context) error { r.PATCH("/rules/switch/:enable_uuid/:disable_uuid", t.rulesRegistryHTTP.SwitchRule) r.DELETE("/rules/:uuid", t.rulesRegistryHTTP.DeleteRule) t.srv = &http.Server{ - Addr: t.httpAddr, + Addr: t.httpAddr.String(), Handler: r, }