-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
126 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |