diff --git a/go.mod b/go.mod index 4d450f0..4eed143 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/adrg/xdg v0.5.3 github.com/gin-gonic/gin v1.10.0 github.com/gofrs/uuid v4.4.0+incompatible - github.com/nextmn/go-pfcp-networking v0.0.38 + github.com/nextmn/go-pfcp-networking v0.0.39 github.com/nextmn/json-api v0.0.14 github.com/nextmn/logrus-formatter v0.0.1 github.com/nextmn/rfc9433 v0.0.2 diff --git a/go.sum b/go.sum index 13b14cc..3c2da97 100644 --- a/go.sum +++ b/go.sum @@ -52,6 +52,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/nextmn/go-pfcp-networking v0.0.38 h1:C7HgLh6UUbqfoTHl/uvUcYNZUBPSur68rOHdLUnpx9Q= github.com/nextmn/go-pfcp-networking v0.0.38/go.mod h1:KYoKLiltDmHL2YMU5mz2k/E1xMoz4TpmzTz6Nr5u5gA= +github.com/nextmn/go-pfcp-networking v0.0.39 h1:8LDz3O0pjQ3PPLGDnds3z369mB7xBEkTtLqAzMMrtFE= +github.com/nextmn/go-pfcp-networking v0.0.39/go.mod h1:KYoKLiltDmHL2YMU5mz2k/E1xMoz4TpmzTz6Nr5u5gA= 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= diff --git a/internal/app/http.go b/internal/app/http.go index 4d4b8f6..b70b76a 100644 --- a/internal/app/http.go +++ b/internal/app/http.go @@ -1,7 +1,8 @@ -// Copyright 2023 Louis Royer and the NextMN-SRv6-ctrl contributors. All rights reserved. +// Copyright 2023 Louis Royer and the NextMN 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 app import ( @@ -9,6 +10,7 @@ import ( "fmt" "net" "net/http" + "net/netip" "sync" "time" @@ -32,7 +34,7 @@ type RouterRegistry struct { pfcpSrv *pfcp_networking.PFCPEntityUP } -func NewHttpServerEntity(httpAddr string, pfcp *pfcp_networking.PFCPEntityUP) *HttpServerEntity { +func NewHttpServerEntity(httpAddr netip.AddrPort, pfcp *pfcp_networking.PFCPEntityUP) *HttpServerEntity { rr := RouterRegistry{ routers: make(n4tosrv6.RouterMap), pfcpSrv: pfcp, @@ -48,7 +50,7 @@ func NewHttpServerEntity(httpAddr string, pfcp *pfcp_networking.PFCPEntityUP) *H e := HttpServerEntity{ routers: &rr, srv: &http.Server{ - Addr: httpAddr, + Addr: httpAddr.String(), Handler: r, }, } diff --git a/internal/app/rules-pusher.go b/internal/app/rules-pusher.go index aa19b63..1755ea7 100644 --- a/internal/app/rules-pusher.go +++ b/internal/app/rules-pusher.go @@ -1,7 +1,8 @@ -// Copyright 2024 Louis Royer and the NextMN-SRv6-ctrl contributors. All rights reserved. +// Copyright 2024 Louis Royer and the NextMN 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 app import ( @@ -13,15 +14,16 @@ import ( "net/netip" "sync" - "github.com/sirupsen/logrus" - "github.com/wmnsk/go-pfcp/ie" - pfcp_networking "github.com/nextmn/go-pfcp-networking/pfcp" pfcpapi "github.com/nextmn/go-pfcp-networking/pfcp/api" "github.com/nextmn/go-pfcp-networking/pfcputil" + "github.com/nextmn/json-api/jsonapi" "github.com/nextmn/json-api/jsonapi/n4tosrv6" "github.com/nextmn/rfc9433/encoding" "github.com/nextmn/srv6-ctrl/internal/config" + + "github.com/sirupsen/logrus" + "github.com/wmnsk/go-pfcp/ie" ) const UserAgent = "go-github-nextmn-srv6-ctrl" @@ -48,8 +50,8 @@ func NewRulesPusher(config *config.CtrlConfig) *RulesPusher { } } -func (pusher *RulesPusher) pushSingleRule(client http.Client, uri string, data []byte) error { - req, err := http.NewRequest(http.MethodPost, uri+"/rules", bytes.NewBuffer(data)) +func (pusher *RulesPusher) pushSingleRule(ctx context.Context, client http.Client, uri jsonapi.ControlURI, data []byte) error { + req, err := http.NewRequestWithContext(ctx, http.MethodPost, uri.JoinPath("rules").String(), bytes.NewBuffer(data)) if err != nil { logrus.WithError(err).Error("could not create http request") return err @@ -76,7 +78,7 @@ func (pusher *RulesPusher) pushSingleRule(client http.Client, uri string, data [ return nil } -func (pusher *RulesPusher) pushRTRRule(ue_ip string) error { +func (pusher *RulesPusher) pushRTRRule(ctx context.Context, ue_ip string) error { i, ok := pusher.ues.Load(ue_ip) infos := i.(*ueInfos) infos.Lock() @@ -137,7 +139,7 @@ func (pusher *RulesPusher) pushRTRRule(ue_ip string) error { wg.Add(1) go func() error { defer wg.Done() - return pusher.pushSingleRule(client, r.ControlURI, rule_json) + return pusher.pushSingleRule(ctx, client, r.ControlURI, rule_json) }() } @@ -191,7 +193,7 @@ func (pusher *RulesPusher) pushRTRRule(ue_ip string) error { wg.Add(1) go func() error { defer wg.Done() - return pusher.pushSingleRule(client, r.ControlURI, rule_json) + return pusher.pushSingleRule(ctx, client, r.ControlURI, rule_json) }() } @@ -317,7 +319,7 @@ func (pusher *RulesPusher) updateRoutersRules(ctx context.Context, msgType pfcpu wg.Add(1) go func() { defer wg.Done() - pusher.pushRTRRule(ip.(string)) + pusher.pushRTRRule(ctx, ip.(string)) // TODO: check pushRTRRule return code and send pfcp error on failure }() return true diff --git a/internal/app/setup.go b/internal/app/setup.go index fe24567..eb350d6 100644 --- a/internal/app/setup.go +++ b/internal/app/setup.go @@ -1,7 +1,8 @@ -// Copyright 2024 Louis Royer and the NextMN-SRv6-ctrl contributors. All rights reserved. +// Copyright 2024 Louis Royer and the NextMN 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 app import ( diff --git a/internal/app/upf.go b/internal/app/upf.go index 7b5cb47..1737308 100644 --- a/internal/app/upf.go +++ b/internal/app/upf.go @@ -1,7 +1,8 @@ -// Copyright 2023 Louis Royer and the NextMN-SRv6-ctrl contributors. All rights reserved. +// Copyright 2023 Louis Royer and the NextMN 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 app import ( 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/config/rule.go b/internal/config/rule.go index 3e3086a..cd5099a 100644 --- a/internal/config/rule.go +++ b/internal/config/rule.go @@ -5,8 +5,12 @@ package config +import ( + "github.com/nextmn/json-api/jsonapi" +) + type Rule struct { - ControlURI string `yaml:"control-uri"` // e.g. http://srgw.local:8080 - Enabled bool `yaml:"enabled"` - SegmentsList []string `yaml:"segments-list"` // Segment[0] is the ultimate node, Segment[n-1] is the next hop ; Segment[0] can be a prefix (for downlink) + ControlURI jsonapi.ControlURI `yaml:"control-uri"` // e.g. http://srgw.local:8080 + Enabled bool `yaml:"enabled"` + SegmentsList []string `yaml:"segments-list"` // Segment[0] is the ultimate node, Segment[n-1] is the next hop ; Segment[0] can be a prefix (for downlink) } diff --git a/main.go b/main.go index b85216d..0f045dc 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,8 @@ -// Copyright 2023 Louis Royer and the NextMN-SRv6-ctrl contributors. All rights reserved. +// Copyright 2023 Louis Royer and the NextMN 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 (