Skip to content

Commit

Permalink
Implement TUN device configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jyyi1 committed Nov 23, 2024
1 parent 787e605 commit 46b8a25
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 10 deletions.
2 changes: 1 addition & 1 deletion client/electron/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import {GoApiName, invokeGoApi} from './go_plugin';
import {GoVpnTunnel} from './go_vpn_tunnel';
import {installRoutingServices, RoutingDaemon} from './routing_service';
import {TunnelStore} from './tunnel_store';
import {VpnTunnel} from './vpn_tunnel';
import {closeVpn, establishVpn} from './vpn_service';
import {VpnTunnel} from './vpn_tunnel';
import * as config from '../src/www/app/outline_server_repository/config';
import {
StartRequestJson,
Expand Down
8 changes: 6 additions & 2 deletions client/electron/vpn_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {TransportConfigJson} from '../src/www/app/outline_server_repository/config';
import {invokeGoApi} from './go_plugin';
import {TransportConfigJson} from '../src/www/app/outline_server_repository/config';

interface VpnConfig {
interfaceName: string;
Expand All @@ -29,7 +29,11 @@ export async function establishVpn(transportConfig: TransportConfigJson) {
dnsServers: ['9.9.9.9'],
transport: JSON.stringify(transportConfig),
};
const connection = await invokeGoApi('EstablishVPN', JSON.stringify(config));
const connectionJson = await invokeGoApi(
'EstablishVPN',
JSON.stringify(config)
);
console.info(JSON.parse(connectionJson));
}

export async function closeVpn() {}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
package main

import (
"context"
"encoding/json"
"io"

"github.com/Jigsaw-Code/outline-apps/client/go/outline/platerrors"
"github.com/Jigsaw-Code/outline-sdk/network"
)

type VPNConfig struct {
Expand All @@ -28,7 +31,11 @@ type VPNConfig struct {
}

type VPNConnection struct {
RouteUDP bool `json:"routeUDP"`
Status string `json:"status"`
RouteUDP bool `json:"routeUDP"`

tun io.ReadWriteCloser `json:"-"`
outline network.IPDevice
}

func EstablishVPN(configStr string) (string, *platerrors.PlatformError) {
Expand All @@ -42,7 +49,7 @@ func EstablishVPN(configStr string) (string, *platerrors.PlatformError) {
}
}

conn, perr := establishVPN(&config)
conn, perr := establishVPN(context.TODO(), &config)
if perr != nil {
return "", perr
}
Expand Down
53 changes: 53 additions & 0 deletions client/go/outline/electron/vpn_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2024 The Outline Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"context"

"github.com/Jigsaw-Code/outline-apps/client/go/outline/electron/vpnlinux"
"github.com/Jigsaw-Code/outline-apps/client/go/outline/platerrors"
)

func establishVPN(ctx context.Context, config *VPNConfig) (_ *VPNConnection, perr *platerrors.PlatformError) {
conn := &VPNConnection{}

if conn.tun, perr = vpnlinux.ConfigureTUNDevice(config.InterfaceName); perr != nil {
return nil, perr
}
defer func() {
if perr != nil {
conn.tun.Close()
}
}()

// Configure Network Manager connection

// Create Outline socket and protect it
if conn.outline, perr = vpnlinux.ConfigureOutlineDevice(config.TransportConfig); perr != nil {
return nil, perr
}
defer func() {
if perr != nil {
conn.outline.Close()
}
}()

// Create routing table

// Add IP rule to route all traffic to outline

return conn, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@

package main

import "github.com/Jigsaw-Code/outline-apps/client/go/outline/platerrors"
import (
"context"

func establishVPN(config *VPNConfig) (*VPNConnection, *platerrors.PlatformError) {
"github.com/Jigsaw-Code/outline-apps/client/go/outline/platerrors"
)

func establishVPN(ctx context.Context, config *VPNConfig) (*VPNConnection, *platerrors.PlatformError) {
return nil, &platerrors.PlatformError{
Code: platerrors.InternalError,
Message: "not implemented yet",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package main
package vpnlinux

import (
"github.com/Jigsaw-Code/outline-apps/client/go/outline/platerrors"
"github.com/Jigsaw-Code/outline-sdk/network"
)

func establishVPN(config *VPNConfig) (*VPNConnection, *platerrors.PlatformError) {
return nil, platerrors.NewPlatformError(platerrors.InternalError, "Working in progress !!!")
func ConfigureOutlineDevice(transportConfig string) (network.IPDevice, *platerrors.PlatformError) {
return nil, nil
}
47 changes: 47 additions & 0 deletions client/go/outline/electron/vpnlinux/tun_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2024 The Outline Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package vpnlinux

import (
"io"

"github.com/Jigsaw-Code/outline-apps/client/go/outline/platerrors"
"github.com/songgao/water"
)

func ConfigureTUNDevice(name string) (_ io.ReadWriteCloser, perr *platerrors.PlatformError) {
tun, err := water.New(water.Config{
DeviceType: water.TUN,
PlatformSpecificParams: water.PlatformSpecificParams{
Name: name,
Persist: false,
},
})
if err != nil {
return nil, &platerrors.PlatformError{
Code: platerrors.SetupSystemVPNFailed,
Message: "failed to open the TUN device",
Details: platerrors.ErrorDetails{"name": name},
Cause: platerrors.ToPlatformError(err),
}
}
defer func() {
if perr != nil {
tun.Close()
}
}()

return tun, nil
}

0 comments on commit 46b8a25

Please sign in to comment.