Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Z3028 vpn ipv4 support #114

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/daemonStorage/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Data struct {
ProjectId string
UserId string
VpnNetwork net.IPNet
VpnNetwork4 net.IPNet
GrpcApiAddress string
GrpcVpnAddress string
GrpcTargetVpnAddress string
Expand All @@ -36,7 +37,9 @@ type Data struct {

ServerIp net.IP
DnsIp net.IP
DnsIp4 net.IP
ClientIp net.IP
ClientIp4 net.IP
Mtu uint32
DnsManagement LocalDnsManagement

Expand Down
3 changes: 2 additions & 1 deletion src/proto/vpnproxy/build-pb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ PTYPES=`go list -f '{{ .Dir }}' -m github.com/golang/protobuf`
protoc \
-I . \
-I ${PTYPES}/ptypes \
--go_out=plugins=grpc,paths=source_relative:. *.proto
--go_out=paths=source_relative:. \
--go-grpc_out=paths=source_relative:. *.proto

if [ $? -ne 0 ]; then
echo FAIL
Expand Down
299 changes: 112 additions & 187 deletions src/proto/vpnproxy/zeropsVpnProtocol.pb.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/proto/vpnproxy/zeropsVpnProtocol.proto
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ message startVpnOutDto {
IP assignedClientIp = 3;
IP serverIp = 4;
IPRange vpnIpRange = 5;
IPRange vpnIp4Range = 7;
IP dnsIp = 6;
IP dnsIp4 = 8;
IP assignedClientIp4 = 9;
IP serverIp4 = 10;
}

message prolongVpnRequest {
Expand Down
141 changes: 141 additions & 0 deletions src/proto/vpnproxy/zeropsVpnProtocol_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions src/vpn/dnsCleanNetworkSetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@ package vpn

import (
"context"
"fmt"
"os"
)

func (h *Handler) dnsCleanNetworkSetup(ctx context.Context) error {

os.Remove("/etc/resolver/zerops")
{
stdin := "remove State:/Network/Service/zerops_vpn_service/IPv6\n"
if _, err := h.runCommand(ctx, makeCommand("scutil", commandWithStdin(stdin))); err != nil {
return err
}
}

stdin := fmt.Sprintf(`remove State:/Network/Service/zerops_vpn_service/IPv6
remove Setup:/Network/Service/zerops_vpn_service/IPv6`)

if _, err := h.runCommand(ctx, makeCommand("scutil", commandWithStdin(stdin))); err != nil {
return err
{
stdin := "remove Setup:/Network/Service/zerops_vpn_service/IPv6\n"
if _, err := h.runCommand(ctx, makeCommand("scutil", commandWithStdin(stdin))); err != nil {
return err
}
}

return nil
Expand Down
32 changes: 12 additions & 20 deletions src/vpn/dnsIsAlive.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
package vpn

import (
"context"
"errors"
"time"

"github.com/zeropsio/zcli/src/i18n"
"github.com/zeropsio/zcli/src/nettools"
)

func (h *Handler) dnsIsAlive() (bool, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()

if !nettools.HasIPv6PingCommand() {
return false, errors.New(i18n.VpnStatusDnsNoCheckFunction)
}
err := nettools.Ping(ctx, "node1.master.core.zerops")
if err != nil {
h.logger.Error(err)
return false, nil
}
return true, nil
//ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
//defer cancel()
//
//if !nettools.HasIPv6PingCommand() {
// return false, errors.New(i18n.VpnStatusDnsNoCheckFunction)
//}
//err := nettools.Ping(ctx, "node1.master.core.zerops")
//if err != nil {
// h.logger.Error(err)
// return false, nil
//}
//return true, nil
}
36 changes: 18 additions & 18 deletions src/vpn/isVpnTunnelAlive.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@ package vpn
import (
"context"
"net"

"github.com/zeropsio/zcli/src/nettools"
)

func (h *Handler) isVpnTunnelAlive(ctx context.Context, serverIp net.IP) bool {

if serverIp.String() == "" {
return false
}
return true
/*
if serverIp.String() == "" {
return false
}

for i := 0; i < h.config.VpnCheckRetryCount; i++ {
if func() bool {
ctx, cancel := context.WithTimeout(ctx, h.config.VpnCheckTimeout)
defer cancel()
for i := 0; i < h.config.VpnCheckRetryCount; i++ {
if func() bool {
ctx, cancel := context.WithTimeout(ctx, h.config.VpnCheckTimeout)
defer cancel()

err := nettools.Ping(ctx, serverIp.String())
if err != nil {
h.logger.Error(err)
return false
err := nettools.Ping(ctx, serverIp.String())
if err != nil {
h.logger.Error(err)
return false
}
return true
}() {
return true
}
return true
}() {
return true
}
}
return false
*/
}
10 changes: 5 additions & 5 deletions src/vpn/public_statusVpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@
if dnsIsAlive {
vpnStatus.DnsState = daemon.DnsState_DNS_ACTIVE
} else {
vpnStatus.AdditionalInfo += fmt.Sprintf(

Check failure on line 54 in src/vpn/public_statusVpn.go

View workflow job for this annotation

GitHub Actions / Build && tests for linux amd64

fmt.Sprintf call needs 6 args but has 7 args
"dns ip: %s\n"+
"vpn network: %s\n"+
"dns ip: %s, %s\n"+
"vpn network: %s, %s\n"+
"client ip: %s\n"+
"interface: %s\n",
data.DnsIp.String(),
data.VpnNetwork.String(),
data.ClientIp.String(),
data.DnsIp.String(), data.DnsIp4.String(),
data.VpnNetwork.String(), data.VpnNetwork4.String(),
data.ClientIp.String(), data.ClientIp4.String(),
data.InterfaceName,
)
}
Expand Down
25 changes: 21 additions & 4 deletions src/vpn/setDnsNetworksetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,35 @@ func (h *Handler) setDnsNetworksetup(ctx context.Context) error {
return err
}

stdin := fmt.Sprintf(`d.init
{
stdin := fmt.Sprintf(`d.init
d.add Addresses * fe80::1d04:6b6d:7ad7:85e4 2600:3c03::de:d002
d.add DestAddresses * ::ffff:ffff:ffff:ffff:0:0 ::
d.add Flags * 0 0
d.add InterfaceName %s
d.add PrefixLength * 64 116
set State:/Network/Service/zerops_vpn_service/IPv6
set Setup:/Network/Service/zerops_vpn_service/IPv6`, data.InterfaceName)
`, data.InterfaceName)

if _, err := h.runCommand(ctx, makeCommand("scutil", commandWithStdin(stdin))); err != nil {
return err
}

if _, err := h.runCommand(ctx, makeCommand("scutil", commandWithStdin(stdin))); err != nil {
return err
}
{
stdin := fmt.Sprintf(`d.init
d.add Addresses * fe80::1d04:6b6d:7ad7:85e4 2600:3c03::de:d002
d.add DestAddresses * ::ffff:ffff:ffff:ffff:0:0 ::
d.add Flags * 0 0
d.add InterfaceName %s
d.add PrefixLength * 64 116
set Setup:/Network/Service/zerops_vpn_service/IPv6
`, data.InterfaceName)

if _, err := h.runCommand(ctx, makeCommand("scutil", commandWithStdin(stdin))); err != nil {
return err
}

}
return nil
}
Loading
Loading