Compare commits
3 commits
17c1063e1f
...
3feb93e679
| Author | SHA1 | Date | |
|---|---|---|---|
| 3feb93e679 | |||
| ed672e7311 | |||
| 995504d761 |
2 changed files with 21 additions and 3 deletions
|
|
@ -21,7 +21,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
clientStr = "SoftEther VPN Client"
|
clientStr = "Softether Go Client"
|
||||||
clientVer = 502
|
clientVer = 502
|
||||||
clientBuild = 5187
|
clientBuild = 5187
|
||||||
|
|
||||||
|
|
@ -128,6 +128,14 @@ func Connect(cfg Config) (*Session, error) {
|
||||||
return sess, nil
|
return sess, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// swapLE32 byte-swaps a uint32 to encode it as little-endian within a big-endian Pack int.
|
||||||
|
// SoftEther's OutRpcNodeInfo wraps node info fields with LittleEndian32() before PackAddInt,
|
||||||
|
// and InRpcNodeInfo reads them with LittleEndian32(PackGetInt(...)). Our Pack writes big-endian,
|
||||||
|
// so we pre-swap to match the C client's wire format.
|
||||||
|
func swapLE32(v uint32) uint32 {
|
||||||
|
return (v>>24)&0xFF | (v>>8)&0xFF00 | (v<<8)&0xFF0000 | (v<<24)&0xFF000000
|
||||||
|
}
|
||||||
|
|
||||||
// buildAuthPack constructs the authentication Pack sent to the server.
|
// buildAuthPack constructs the authentication Pack sent to the server.
|
||||||
// This includes credentials, client version, connection options, node info, and OS info.
|
// This includes credentials, client version, connection options, node info, and OS info.
|
||||||
// See: https://github.com/SoftEtherVPN/SoftEtherVPN/blob/v5.02.5187/src/Cedar/Protocol.c#L7289
|
// See: https://github.com/SoftEtherVPN/SoftEtherVPN/blob/v5.02.5187/src/Cedar/Protocol.c#L7289
|
||||||
|
|
@ -206,8 +214,10 @@ func buildAuthPack(cfg Config, random [sha1Size]byte) *protocol.Pack {
|
||||||
// (case-insensitive), and PackRead returns NULL on AddElement failure.
|
// (case-insensitive), and PackRead returns NULL on AddElement failure.
|
||||||
// p.AddStr("HubName", cfg.Hub)
|
// p.AddStr("HubName", cfg.Hub)
|
||||||
p.AddData("UniqueId", uniqueID[:16])
|
p.AddData("UniqueId", uniqueID[:16])
|
||||||
p.AddInt("ClientProductVer", clientVer)
|
// Node info ints use LittleEndian32 encoding (see Admin.c:OutRpcNodeInfo).
|
||||||
p.AddInt("ClientProductBuild", clientBuild)
|
// The server reads them back with LittleEndian32(PackGetInt(...)).
|
||||||
|
p.AddInt("ClientProductVer", swapLE32(clientVer))
|
||||||
|
p.AddInt("ClientProductBuild", swapLE32(clientBuild))
|
||||||
p.AddInt("ServerProductVer", 0)
|
p.AddInt("ServerProductVer", 0)
|
||||||
p.AddInt("ServerProductBuild", 0)
|
p.AddInt("ServerProductBuild", 0)
|
||||||
p.AddIP4("ClientIpAddress", 0)
|
p.AddIP4("ClientIpAddress", 0)
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ func ConfigureTAP(ifname string, lease *dhcp.Lease, acceptDefaultGW, acceptStati
|
||||||
ones, _ := lease.SubnetMask.Size()
|
ones, _ := lease.SubnetMask.Size()
|
||||||
addr := fmt.Sprintf("%s/%d", lease.ClientIP, ones)
|
addr := fmt.Sprintf("%s/%d", lease.ClientIP, ones)
|
||||||
|
|
||||||
|
log.Printf("tap %s: adding address %s", ifname, addr)
|
||||||
if err := run("ip", "addr", "add", addr, "dev", ifname); err != nil {
|
if err := run("ip", "addr", "add", addr, "dev", ifname); err != nil {
|
||||||
return noop, fmt.Errorf("ip addr add: %w", err)
|
return noop, fmt.Errorf("ip addr add: %w", err)
|
||||||
}
|
}
|
||||||
|
|
@ -39,12 +40,16 @@ func ConfigureTAP(ifname string, lease *dhcp.Lease, acceptDefaultGW, acceptStati
|
||||||
dest := r.Dest.String()
|
dest := r.Dest.String()
|
||||||
if dest == "0.0.0.0/0" {
|
if dest == "0.0.0.0/0" {
|
||||||
if acceptDefaultGW {
|
if acceptDefaultGW {
|
||||||
|
log.Printf("tap %s: adding static default route via %s", ifname, r.Gateway)
|
||||||
if err := run("ip", "route", "add", "default", "via", r.Gateway.String(), "dev", ifname, "metric", "50"); err != nil {
|
if err := run("ip", "route", "add", "default", "via", r.Gateway.String(), "dev", ifname, "metric", "50"); err != nil {
|
||||||
log.Printf("warning: static default route: %v", err)
|
log.Printf("warning: static default route: %v", err)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log.Printf("tap %s: skipping static default route via %s (accept-default-gateway not set)", ifname, r.Gateway)
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
log.Printf("tap %s: adding static route %s via %s", ifname, dest, r.Gateway)
|
||||||
if err := run("ip", "route", "add", dest, "via", r.Gateway.String(), "dev", ifname); err != nil {
|
if err := run("ip", "route", "add", dest, "via", r.Gateway.String(), "dev", ifname); err != nil {
|
||||||
log.Printf("warning: static route %s via %s: %v", dest, r.Gateway, err)
|
log.Printf("warning: static route %s via %s: %v", dest, r.Gateway, err)
|
||||||
}
|
}
|
||||||
|
|
@ -52,6 +57,7 @@ func ConfigureTAP(ifname string, lease *dhcp.Lease, acceptDefaultGW, acceptStati
|
||||||
}
|
}
|
||||||
|
|
||||||
if acceptDefaultGW && lease.Gateway != nil && !hasDefaultRoute(lease.Routes) {
|
if acceptDefaultGW && lease.Gateway != nil && !hasDefaultRoute(lease.Routes) {
|
||||||
|
log.Printf("tap %s: adding default route via %s", ifname, lease.Gateway)
|
||||||
if err := run("ip", "route", "add", "default", "via", lease.Gateway.String(), "dev", ifname, "metric", "50"); err != nil {
|
if err := run("ip", "route", "add", "default", "via", lease.Gateway.String(), "dev", ifname, "metric", "50"); err != nil {
|
||||||
log.Printf("warning: default route: %v", err)
|
log.Printf("warning: default route: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -59,11 +65,13 @@ func ConfigureTAP(ifname string, lease *dhcp.Lease, acceptDefaultGW, acceptStati
|
||||||
|
|
||||||
var savedResolv []byte
|
var savedResolv []byte
|
||||||
if acceptDNS && len(lease.DNS) > 0 {
|
if acceptDNS && len(lease.DNS) > 0 {
|
||||||
|
log.Printf("tap %s: setting DNS servers %v", ifname, lease.DNS)
|
||||||
savedResolv = backupResolv()
|
savedResolv = backupResolv()
|
||||||
writeResolv(lease.DNS)
|
writeResolv(lease.DNS)
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup := func() {
|
cleanup := func() {
|
||||||
|
log.Printf("tap %s: flushing addresses", ifname)
|
||||||
run("ip", "addr", "flush", "dev", ifname)
|
run("ip", "addr", "flush", "dev", ifname)
|
||||||
if savedResolv != nil {
|
if savedResolv != nil {
|
||||||
restoreResolv(savedResolv)
|
restoreResolv(savedResolv)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue