diff options
| author | Jeroen Wijenbergh <jeroen.wijenbergh@geant.org> | 2025-08-25 10:59:37 +0200 |
|---|---|---|
| committer | Jeroen Wijenbergh <jeroen.wijenbergh@geant.org> | 2025-08-25 13:06:41 +0200 |
| commit | 27b95b4911da055fe9b5fb37b5fb4a33eda6b989 (patch) | |
| tree | f6eb1143fa9bd2995d671b71d75c950e2c703660 /client/client.go | |
| parent | b4f4f5600298436c63b89f289c318d777300c499 (diff) | |
All: Remove util packages
Was giving linting errors and it's not a good idea anyways
Diffstat (limited to 'client/client.go')
| -rw-r--r-- | client/client.go | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/client/client.go b/client/client.go index d668eb0..59b425d 100644 --- a/client/client.go +++ b/client/client.go @@ -7,11 +7,12 @@ import ( "context" "errors" "log/slog" + "net" "os" "sync" "time" - "codeberg.org/eduVPN/eduvpn-common/i18nerr" + "codeberg.org/eduVPN/eduvpn-common/i18n/err" "codeberg.org/eduVPN/eduvpn-common/internal/api" "codeberg.org/eduVPN/eduvpn-common/internal/config" "codeberg.org/eduVPN/eduvpn-common/internal/discovery" @@ -25,6 +26,31 @@ import ( "github.com/jwijenbergh/eduoauth-go" ) +// CalculateGateway takes a CIDR encoded subnet `cidr` and returns the gateway and an error +// TODO: move this somewhere else? +func CalculateGateway(cidr string) (string, error) { + _, ipn, err := net.ParseCIDR(cidr) + if err != nil { + return "", i18nerr.WrapInternalf(err, "failed to parse CIDR for calculating gateway: %v", cidr) + } + + ret := make(net.IP, len(ipn.IP)) + copy(ret, ipn.IP) + + for i := len(ret) - 1; i >= 0; i-- { + ret[i]++ + if ret[i] > 0 { + break + } + } + + if !ipn.Contains(ret) { + return "", i18nerr.Newf("IP network does not contain incremented IP: %v", ret) + } + + return ret.String(), nil +} + // Client is the main struct for the VPN client. type Client struct { // The name of the client |
