Skip to content

Commit 9957796

Browse files
authored
Merge branch 'master' into update-endpoint-ip
2 parents 7ce8acd + 182247f commit 9957796

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+141
-126
lines changed

conf/config.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ type Endpoint struct {
2727
Port uint16
2828
}
2929

30-
type Key [KeyLength]byte
31-
type HandshakeTime time.Duration
32-
type Bytes uint64
30+
type (
31+
Key [KeyLength]byte
32+
HandshakeTime time.Duration
33+
Bytes uint64
34+
)
3335

3436
type Config struct {
3537
Name string

conf/migration_windows.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ import (
1818
"golang.org/x/sys/windows"
1919
)
2020

21-
var migrating sync.Mutex
22-
var lastMigrationTimer *time.Timer
21+
var (
22+
migrating sync.Mutex
23+
lastMigrationTimer *time.Timer
24+
)
2325

2426
type MigrationCallback func(name, oldPath, newPath string)
2527

@@ -53,7 +55,7 @@ func migrateUnencryptedConfigs(sharingBase int, migrated MigrationCallback) {
5355
if err != nil {
5456
continue
5557
}
56-
if info.Mode().Perm()&0444 == 0 {
58+
if info.Mode().Perm()&0o444 == 0 {
5759
continue
5860
}
5961

conf/name.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ var reservedNames = []string{
1818
"LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9",
1919
}
2020

21-
const serviceNameForbidden = "$"
22-
const netshellDllForbidden = "\\/:*?\"<>|\t"
23-
const specialChars = "/\\<>:\"|?*\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x00"
21+
const (
22+
serviceNameForbidden = "$"
23+
netshellDllForbidden = "\\/:*?\"<>|\t"
24+
specialChars = "/\\<>:\"|?*\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x00"
25+
)
2426

2527
var allowedNameFormat = regexp.MustCompile("^[a-zA-Z0-9_=+.-]{1,32}$")
2628

@@ -60,6 +62,7 @@ type naturalSortToken struct {
6062
maybeString string
6163
maybeNumber int
6264
}
65+
6366
type naturalSortString struct {
6467
originalString string
6568
tokens []naturalSortToken

conf/parser.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func (c *Config) maybeAddPeer(p *Peer) {
172172
}
173173
}
174174

175-
func FromWgQuick(s string, name string) (*Config, error) {
175+
func FromWgQuick(s, name string) (*Config, error) {
176176
if !TunnelNameIsValid(name) {
177177
return nil, &ParseError{l18n.Sprintf("Tunnel name is not valid"), name}
178178
}
@@ -339,7 +339,7 @@ func FromWgQuick(s string, name string) (*Config, error) {
339339
return &conf, nil
340340
}
341341

342-
func FromWgQuickWithUnknownEncoding(s string, name string) (*Config, error) {
342+
func FromWgQuickWithUnknownEncoding(s, name string) (*Config, error) {
343343
c, firstErr := FromWgQuick(s, name)
344344
if firstErr == nil {
345345
return c, nil

conf/parser_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func equal(t *testing.T, expected, actual interface{}) bool {
5454
t.Errorf("Failed equals at %s:%d\nactual %#v\nexpected %#v", fn, line, actual, expected)
5555
return false
5656
}
57+
5758
func lenTest(t *testing.T, actualO interface{}, expected int) bool {
5859
actual := reflect.ValueOf(actualO).Len()
5960
if reflect.DeepEqual(expected, actual) {
@@ -63,6 +64,7 @@ func lenTest(t *testing.T, actualO interface{}, expected int) bool {
6364
t.Errorf("Wrong length at %s:%d\nactual %#v\nexpected %#v", fn, line, actual, expected)
6465
return false
6566
}
67+
6668
func contains(t *testing.T, list, element interface{}) bool {
6769
listValue := reflect.ValueOf(list)
6870
for i := 0; i < listValue.Len(); i++ {

conf/path_windows.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ import (
1515
"golang.org/x/sys/windows"
1616
)
1717

18-
var cachedConfigFileDir string
19-
var cachedRootDir string
18+
var (
19+
cachedConfigFileDir string
20+
cachedRootDir string
21+
)
2022

2123
func tunnelConfigurationsDirectory() (string, error) {
2224
if cachedConfigFileDir != "" {
@@ -27,7 +29,7 @@ func tunnelConfigurationsDirectory() (string, error) {
2729
return "", err
2830
}
2931
c := filepath.Join(root, "Configurations")
30-
err = os.Mkdir(c, os.ModeDir|0700)
32+
err = os.Mkdir(c, os.ModeDir|0o700)
3133
if err != nil && !os.IsExist(err) {
3234
return "", err
3335
}

conf/store.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ import (
1414
"golang.zx2c4.com/wireguard/windows/conf/dpapi"
1515
)
1616

17-
const configFileSuffix = ".conf.dpapi"
18-
const configFileUnencryptedSuffix = ".conf"
17+
const (
18+
configFileSuffix = ".conf.dpapi"
19+
configFileUnencryptedSuffix = ".conf"
20+
)
1921

2022
func ListConfigNames() ([]string, error) {
2123
configFileDir, err := tunnelConfigurationsDirectory()
@@ -40,7 +42,7 @@ func ListConfigNames() ([]string, error) {
4042
if err != nil {
4143
continue
4244
}
43-
if info.Mode().Perm()&0444 == 0 {
45+
if info.Mode().Perm()&0o444 == 0 {
4446
continue
4547
}
4648
configs[i] = name

driver/driver_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func closeAdapter(wireguard *Adapter) {
7979
// the GUID of the created network adapter, which then influences NLA generation
8080
// deterministically. If it is set to nil, the GUID is chosen by the system at random,
8181
// and hence a new NLA entry is created for each new adapter.
82-
func CreateAdapter(name string, tunnelType string, requestedGUID *windows.GUID) (wireguard *Adapter, err error) {
82+
func CreateAdapter(name, tunnelType string, requestedGUID *windows.GUID) (wireguard *Adapter, err error) {
8383
var name16 *uint16
8484
name16, err = windows.UTF16PtrFromString(name)
8585
if err != nil {

driver/memmod/memmod_windows.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (module *Module) headerDirectory(idx int) *IMAGE_DATA_DIRECTORY {
4747
return &module.headers.OptionalHeader.DataDirectory[idx]
4848
}
4949

50-
func (module *Module) copySections(address uintptr, size uintptr, oldHeaders *IMAGE_NT_HEADERS) error {
50+
func (module *Module) copySections(address, size uintptr, oldHeaders *IMAGE_NT_HEADERS) error {
5151
sections := module.headers.Sections()
5252
for i := range sections {
5353
if sections[i].SizeOfRawData == 0 {
@@ -139,7 +139,7 @@ func (module *Module) finalizeSection(sectionData *sectionFinalizeData) error {
139139
}
140140

141141
// determine protection flags based on characteristics
142-
var ProtectionFlags = [8]uint32{
142+
ProtectionFlags := [8]uint32{
143143
windows.PAGE_NOACCESS, // not writeable, not readable, not executable
144144
windows.PAGE_EXECUTE, // not writeable, not readable, executable
145145
windows.PAGE_READONLY, // not writeable, readable, not executable
@@ -387,10 +387,12 @@ type addressRange struct {
387387
end uintptr
388388
}
389389

390-
var loadedAddressRanges []addressRange
391-
var loadedAddressRangesMu sync.RWMutex
392-
var haveHookedRtlPcToFileHeader sync.Once
393-
var hookRtlPcToFileHeaderResult error
390+
var (
391+
loadedAddressRanges []addressRange
392+
loadedAddressRangesMu sync.RWMutex
393+
haveHookedRtlPcToFileHeader sync.Once
394+
hookRtlPcToFileHeaderResult error
395+
)
394396

395397
func hookRtlPcToFileHeader() error {
396398
var kernelBase windows.Handle

driver/wintunremoval_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
func UninstallLegacyWintun() error {
15-
var deviceClassNetGUID = &windows.GUID{0x4d36e972, 0xe325, 0x11ce, [8]byte{0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18}}
15+
deviceClassNetGUID := &windows.GUID{0x4d36e972, 0xe325, 0x11ce, [8]byte{0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18}}
1616
devInfo, err := windows.SetupDiCreateDeviceInfoListEx(deviceClassNetGUID, 0, "")
1717
if err != nil {
1818
return err

0 commit comments

Comments
 (0)