diff options
| -rw-r--r-- | client/proxy.go | 20 | ||||
| -rw-r--r-- | exports/exports.go | 19 | ||||
| -rw-r--r-- | wrappers/python/eduvpn_common/loader.py | 4 | ||||
| -rw-r--r-- | wrappers/python/eduvpn_common/main.py | 6 | ||||
| -rw-r--r-- | wrappers/python/eduvpn_common/types.py | 2 |
5 files changed, 30 insertions, 21 deletions
diff --git a/client/proxy.go b/client/proxy.go index 4f87a3f..2f05f8a 100644 --- a/client/proxy.go +++ b/client/proxy.go @@ -1,7 +1,10 @@ package client import ( + "encoding/json" + "codeberg.org/eduVPN/proxyguard" + "github.com/eduvpn/eduvpn-common/i18nerr" "github.com/eduvpn/eduvpn-common/internal/log" "github.com/eduvpn/eduvpn-common/types/cookie" @@ -21,18 +24,23 @@ func (pl *ProxyLogger) Log(msg string) { } // StartProxyguard starts proxyguard for proxied WireGuard connections -func (c *Client) StartProxyguard(ck *cookie.Cookie, listen string, tcpsp int, peer string, gotFD func(fd int), ready func()) error { +func (c *Client) StartProxyguard(ck *cookie.Cookie, listen string, tcpsp int, peer string, gotFD func(fd int, pips string), ready func()) error { var err error proxyguard.UpdateLogger(&ProxyLogger{}) proxyc := proxyguard.Client{ - Listen: listen, + Listen: listen, TCPSourcePort: tcpsp, - SetupSocket: func(fd int, _ []string) { - if gotFD != nil { - gotFD(fd) + SetupSocket: func(fd int, pips []string) { + if gotFD == nil { + return + } + b, err := json.Marshal(pips) + if err != nil { + log.Logger.Errorf("marshalling peer IPs failed: %v", err) + return } - // TODO: support peerips + gotFD(fd, string(b)) }, Ready: ready, } diff --git a/exports/exports.go b/exports/exports.go index 8f806d7..d065d18 100644 --- a/exports/exports.go +++ b/exports/exports.go @@ -23,7 +23,7 @@ typedef int (*StateCB)(int oldstate, int newstate, void* data); typedef void (*TokenGetter)(const char* server_id, int server_type, char* out, size_t len); typedef void (*TokenSetter)(const char* server_id, int server_type, const char* tokens); -typedef void (*ProxyFD)(int fd); +typedef void (*ProxySetup)(int fd, const char* peer_ips); typedef void (*ProxyReady)(); static long long int get_read_rx_bytes(ReadRxBytes read) @@ -42,9 +42,9 @@ static void call_token_setter(TokenSetter setter, const char* server_id, int ser { setter(server_id, server_type, tokens); } -static void call_proxy_fd(ProxyFD proxyfd, int fd) +static void call_proxy_setup(ProxySetup proxysetup, int fd, const char* peer_ips) { - proxyfd(fd); + proxysetup(fd, peer_ips); } static void call_proxy_ready(ProxyReady ready) { @@ -910,14 +910,13 @@ func StartFailover(c C.uintptr_t, gateway *C.char, mtu C.int, readRxBytes C.Read // - `listen` is the ip:port of the local udp connection, this is what is set to the WireGuard endpoint // - `tcpsp` is the TCP source port // - `peer` is the ip:port of the remote server -// - `proxyFD` is a callback with the file descriptor as only argument. It can be used to set certain -// socket option, e.g. to exclude the proxy connection from going over the VPN +// - `proxySetup` is a callback which is called when the socket is setting up, this can be used for configuring routing in the client. It takes two arguments: the file descriptor (integer) and a JSON list of IPs the client connects to // - `proxyReady` is a callback when the proxy is ready to be used. This is only called when the client is not connected yet. Use this to determine when the actual wireguard connection can be started. This callback returns and takes no arguments // // If the proxy cannot be started it returns an error // //export StartProxyguard -func StartProxyguard(c C.uintptr_t, listen *C.char, tcpsp C.int, peer *C.char, proxyFD C.ProxyFD, proxyReady C.ProxyReady) *C.char { +func StartProxyguard(c C.uintptr_t, listen *C.char, tcpsp C.int, peer *C.char, proxySetup C.ProxySetup, proxyReady C.ProxyReady) *C.char { state, stateErr := getVPNState() if stateErr != nil { return getCError(stateErr) @@ -927,11 +926,13 @@ func StartProxyguard(c C.uintptr_t, listen *C.char, tcpsp C.int, peer *C.char, p return getCError(err) } - proxyErr := state.StartProxyguard(ck, C.GoString(listen), int(tcpsp), C.GoString(peer), func(fd int) { - if proxyFD == nil { + proxyErr := state.StartProxyguard(ck, C.GoString(listen), int(tcpsp), C.GoString(peer), func(fd int, pips string) { + if proxySetup == nil { return } - C.call_proxy_fd(proxyFD, C.int(fd)) + cpip := C.CString(pips) + C.call_proxy_setup(proxySetup, C.int(fd), cpip) + FreeString(cpip) }, func() { if proxyReady == nil { return diff --git a/wrappers/python/eduvpn_common/loader.py b/wrappers/python/eduvpn_common/loader.py index c7c2233..674c010 100644 --- a/wrappers/python/eduvpn_common/loader.py +++ b/wrappers/python/eduvpn_common/loader.py @@ -6,8 +6,8 @@ from ctypes import CDLL, c_char_p, c_int, c_void_p, cdll from eduvpn_common import __version__ from eduvpn_common.types import ( BoolError, - GotProxyFD, ProxyReady, + ProxySetup, DataError, ReadRxBytes, TokenGetter, @@ -132,6 +132,6 @@ def initialize_functions(lib: CDLL) -> None: c_char_p, c_int, c_char_p, - GotProxyFD, + ProxySetup, ProxyReady, ], c_void_p diff --git a/wrappers/python/eduvpn_common/main.py b/wrappers/python/eduvpn_common/main.py index ea0ebb3..e96f7e2 100644 --- a/wrappers/python/eduvpn_common/main.py +++ b/wrappers/python/eduvpn_common/main.py @@ -5,8 +5,8 @@ from typing import Any, Callable, Iterator, Optional from eduvpn_common.loader import initialize_functions, load_lib from eduvpn_common.types import ( - GotProxyFD, ProxyReady, + ProxySetup, ReadRxBytes, TokenGetter, TokenSetter, @@ -347,13 +347,13 @@ class EduVPN(object): forwardError(dropped_err) return dropped - def start_proxyguard(self, listen: str, source_port: int, peer: str, gotfd: GotProxyFD, ready: ProxyReady): + def start_proxyguard(self, listen: str, source_port: int, peer: str, setup: ProxySetup, ready: ProxyReady): proxy_err = self.go_cookie_function( self.lib.StartProxyguard, listen, source_port, peer, - gotfd, + setup, ready, ) if proxy_err: diff --git a/wrappers/python/eduvpn_common/types.py b/wrappers/python/eduvpn_common/types.py index e46522a..3375258 100644 --- a/wrappers/python/eduvpn_common/types.py +++ b/wrappers/python/eduvpn_common/types.py @@ -34,7 +34,7 @@ class BoolError(Structure): # The type for a Go state change callback VPNStateChange = CFUNCTYPE(c_int, c_int, c_int, c_char_p) -GotProxyFD = CFUNCTYPE(c_void_p, c_int) +ProxySetup = CFUNCTYPE(c_void_p, c_int, c_char_p) ProxyReady = CFUNCTYPE(c_void_p) ReadRxBytes = CFUNCTYPE(c_ulonglong) TokenGetter = CFUNCTYPE(c_void_p, c_char_p, c_int, POINTER(c_char), c_size_t) |
