diff options
Diffstat (limited to 'exports')
| -rw-r--r-- | exports/exports.go | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/exports/exports.go b/exports/exports.go index f1b55cd..a569b8e 100644 --- a/exports/exports.go +++ b/exports/exports.go @@ -72,6 +72,7 @@ import ( "github.com/eduvpn/eduvpn-common/types/cookie" errtypes "github.com/eduvpn/eduvpn-common/types/error" srvtypes "github.com/eduvpn/eduvpn-common/types/server" + "github.com/eduvpn/eduvpn-common/util" ) // VPNState is the current state of the library @@ -885,7 +886,7 @@ func RenewSession(c C.uintptr_t) *C.char { // Which is useful to go from a broken WireGuard connection to OpenVPN over TCP // // - `c` is the cookie that is passed for cancellation. To create a cookie, use the `CookieNew` function -// - `gateway` is the gateway IP of the VPN +// - `gateway` is the gateway IP of the VPN. You MAY calculate this with the `CalculateGateway` function // - `readRxBytes` is a function that returns the current rx bytes of the VPN interface, this should return a `long long int` in c // // It returns a boolean whether or not the common lib has determined that it cannot reach the gateway. Non-zero=dropped, zero=not dropped. @@ -1129,6 +1130,23 @@ func SetTokenHandler(getter C.TokenGetter, setter C.TokenSetter) *C.char { return nil } +// CalculateGateway calculates the gateway for a subnet, it can take IPv4 or IPv6 networks with CIDR notation as inputs and returns the gateway address +// This is useful to pass to `StartFailover`. It returns an error if it fails to calculate a gateway. +// This is implemented according to: https://docs.eduvpn.org/server/v3/client-implementation-notes.html#fail-over +// +// Example Input: ```CalculateGateway("10.10.0.5/24")``` +// +// Example Output: ```"10.10.0.1", null``` +// +//export CalculateGateway +func CalculateGateway(subnet *C.char) (*C.char, *C.char) { + gw, err := util.CalculateGateway(C.GoString(subnet)) + if err != nil { + return nil, getCError(err) + } + return C.CString(gw), nil +} + // CookieNew creates a new cookie and returns it // // This value should not be parsed or converted somehow by the client |
