aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ui/syntax
diff options
context:
space:
mode:
Diffstat (limited to 'ui/syntax')
-rw-r--r--ui/syntax/highlighter.go22
-rw-r--r--ui/syntax/syntaxedit.go50
2 files changed, 45 insertions, 27 deletions
diff --git a/ui/syntax/highlighter.go b/ui/syntax/highlighter.go
index d49cab32..099a23b0 100644
--- a/ui/syntax/highlighter.go
+++ b/ui/syntax/highlighter.go
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: MIT
*
- * Copyright (C) 2019-2021 WireGuard LLC. All Rights Reserved.
+ * Copyright (C) 2019-2022 WireGuard LLC. All Rights Reserved.
*
* This is a direct translation of the original C, and for that reason, it's pretty unusual Go code:
* https://git.zx2c4.com/wireguard-tools/tree/contrib/highlighter/highlighter.c
@@ -26,6 +26,7 @@ const (
highlightKeepalive
highlightComment
highlightDelimiter
+ highlightTable
highlightCmd
highlightError
)
@@ -61,7 +62,7 @@ type stringSpan struct {
}
func (s stringSpan) at(i int) *byte {
- return (*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(s.s)) + uintptr(i)))
+ return (*byte)(unsafe.Add(unsafe.Pointer(s.s), uintptr(i)))
}
func (s stringSpan) isSame(c string) bool {
@@ -221,7 +222,7 @@ func (s stringSpan) isValidIPv6() bool {
return true
}
-func (s stringSpan) isValidUint(supportHex bool, min uint64, max uint64) bool {
+func (s stringSpan) isValidUint(supportHex bool, min, max uint64) bool {
// Bound this around 32 bits, so that we don't have to write overflow logic.
if s.len > 10 || s.len == 0 {
return false
@@ -256,6 +257,10 @@ func (s stringSpan) isValidMTU() bool {
return s.isValidUint(false, 576, 65535)
}
+func (s stringSpan) isValidTable() bool {
+ return s.isSame("off") || s.isSame("auto") || s.isSame("main") || s.isValidUint(false, 0, (1<<32)-1)
+}
+
func (s stringSpan) isValidPersistentKeepAlive() bool {
if s.isSame("off") {
return true
@@ -360,6 +365,7 @@ const (
fieldAddress
fieldDNS
fieldMTU
+ fieldTable
fieldPreUp
fieldPostUp
fieldPreDown
@@ -395,6 +401,8 @@ func (s stringSpan) field() field {
return fieldDNS
case s.isCaselessSame("MTU"):
return fieldMTU
+ case s.isCaselessSame("Table"):
+ return fieldTable
case s.isCaselessSame("PublicKey"):
return fieldPublicKey
case s.isCaselessSame("PresharedKey"):
@@ -436,7 +444,7 @@ func (hsa *highlightSpanArray) append(o *byte, s stringSpan, t highlight) {
*hsa = append(*hsa, highlightSpan{t, int((uintptr(unsafe.Pointer(s.s))) - (uintptr(unsafe.Pointer(o)))), s.len})
}
-func (hsa *highlightSpanArray) highlightMultivalueValue(parent stringSpan, s stringSpan, section field) {
+func (hsa *highlightSpanArray) highlightMultivalueValue(parent, s stringSpan, section field) {
switch section {
case fieldDNS:
if s.isValidIPv4() || s.isValidIPv6() {
@@ -469,7 +477,7 @@ func (hsa *highlightSpanArray) highlightMultivalueValue(parent stringSpan, s str
}
}
-func (hsa *highlightSpanArray) highlightMultivalue(parent stringSpan, s stringSpan, section field) {
+func (hsa *highlightSpanArray) highlightMultivalue(parent, s stringSpan, section field) {
currentSpan := stringSpan{s.s, 0}
lenAtLastSpace := 0
for i := 0; i < s.len; i++ {
@@ -498,7 +506,7 @@ func (hsa *highlightSpanArray) highlightMultivalue(parent stringSpan, s stringSp
}
}
-func (hsa *highlightSpanArray) highlightValue(parent stringSpan, s stringSpan, section field) {
+func (hsa *highlightSpanArray) highlightValue(parent, s stringSpan, section field) {
switch section {
case fieldPrivateKey:
hsa.append(parent.s, s, validateHighlight(s.isValidKey(), highlightPrivateKey))
@@ -508,6 +516,8 @@ func (hsa *highlightSpanArray) highlightValue(parent stringSpan, s stringSpan, s
hsa.append(parent.s, s, validateHighlight(s.isValidKey(), highlightPresharedKey))
case fieldMTU:
hsa.append(parent.s, s, validateHighlight(s.isValidMTU(), highlightMTU))
+ case fieldTable:
+ hsa.append(parent.s, s, validateHighlight(s.isValidTable(), highlightTable))
case fieldPreUp, fieldPostUp, fieldPreDown, fieldPostDown:
hsa.append(parent.s, s, validateHighlight(s.isValidPrePostUpDown(), highlightCmd))
case fieldListenPort:
diff --git a/ui/syntax/syntaxedit.go b/ui/syntax/syntaxedit.go
index 26cd533f..a3c94d86 100644
--- a/ui/syntax/syntaxedit.go
+++ b/ui/syntax/syntaxedit.go
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: MIT
*
- * Copyright (C) 2019-2021 WireGuard LLC. All Rights Reserved.
+ * Copyright (C) 2019-2022 WireGuard LLC. All Rights Reserved.
*/
package syntax
@@ -90,26 +90,29 @@ type spanStyle struct {
}
var stylemap = map[highlight]spanStyle{
- highlightSection: spanStyle{color: win.RGB(0x32, 0x6D, 0x74), effects: win.CFE_BOLD},
- highlightField: spanStyle{color: win.RGB(0x9B, 0x23, 0x93), effects: win.CFE_BOLD},
- highlightPrivateKey: spanStyle{color: win.RGB(0x64, 0x38, 0x20)},
- highlightPublicKey: spanStyle{color: win.RGB(0x64, 0x38, 0x20)},
- highlightPresharedKey: spanStyle{color: win.RGB(0x64, 0x38, 0x20)},
- highlightIP: spanStyle{color: win.RGB(0x0E, 0x0E, 0xFF)},
- highlightCidr: spanStyle{color: win.RGB(0x81, 0x5F, 0x03)},
- highlightHost: spanStyle{color: win.RGB(0x0E, 0x0E, 0xFF)},
- highlightPort: spanStyle{color: win.RGB(0x81, 0x5F, 0x03)},
- highlightMTU: spanStyle{color: win.RGB(0x1C, 0x00, 0xCF)},
- highlightKeepalive: spanStyle{color: win.RGB(0x1C, 0x00, 0xCF)},
- highlightComment: spanStyle{color: win.RGB(0x53, 0x65, 0x79), effects: win.CFE_ITALIC},
- highlightDelimiter: spanStyle{color: win.RGB(0x00, 0x00, 0x00)},
- highlightCmd: spanStyle{color: win.RGB(0x63, 0x75, 0x89)},
- highlightError: spanStyle{color: win.RGB(0xC4, 0x1A, 0x16), effects: win.CFE_UNDERLINE},
+ highlightSection: {color: win.RGB(0x32, 0x6D, 0x74), effects: win.CFE_BOLD},
+ highlightField: {color: win.RGB(0x9B, 0x23, 0x93), effects: win.CFE_BOLD},
+ highlightPrivateKey: {color: win.RGB(0x64, 0x38, 0x20)},
+ highlightPublicKey: {color: win.RGB(0x64, 0x38, 0x20)},
+ highlightPresharedKey: {color: win.RGB(0x64, 0x38, 0x20)},
+ highlightIP: {color: win.RGB(0x0E, 0x0E, 0xFF)},
+ highlightCidr: {color: win.RGB(0x81, 0x5F, 0x03)},
+ highlightHost: {color: win.RGB(0x0E, 0x0E, 0xFF)},
+ highlightPort: {color: win.RGB(0x81, 0x5F, 0x03)},
+ highlightMTU: {color: win.RGB(0x1C, 0x00, 0xCF)},
+ highlightTable: {color: win.RGB(0x1C, 0x00, 0xCF)},
+ highlightKeepalive: {color: win.RGB(0x1C, 0x00, 0xCF)},
+ highlightComment: {color: win.RGB(0x53, 0x65, 0x79), effects: win.CFE_ITALIC},
+ highlightDelimiter: {color: win.RGB(0x00, 0x00, 0x00)},
+ highlightCmd: {color: win.RGB(0x63, 0x75, 0x89)},
+ highlightError: {color: win.RGB(0xC4, 0x1A, 0x16), effects: win.CFE_UNDERLINE},
}
func (se *SyntaxEdit) evaluateUntunneledBlocking(cfg string, spans []highlightSpan) {
state := InevaluableBlockingUntunneledTraffic
var onAllowedIPs,
+ onTable,
+ tableOff,
seenPeer,
seen00v6,
seen00v4,
@@ -132,10 +135,13 @@ func (se *SyntaxEdit) evaluateUntunneledBlocking(cfg string, spans []highlightSp
} else {
goto done
}
- break
case highlightField:
onAllowedIPs = strings.EqualFold(cfg[span.s:span.s+span.len], "AllowedIPs")
- break
+ onTable = strings.EqualFold(cfg[span.s:span.s+span.len], "Table")
+ case highlightTable:
+ if onTable {
+ tableOff = cfg[span.s:span.s+span.len] == "off"
+ }
case highlightIP:
if !onAllowedIPs || !seenPeer {
break
@@ -166,9 +172,11 @@ func (se *SyntaxEdit) evaluateUntunneledBlocking(cfg string, spans []highlightSp
seen80001v6 = true
}
}
- break
}
}
+ if tableOff {
+ return
+ }
if seen00v4 || seen00v6 {
state = BlockingUntunneledTraffic
@@ -469,10 +477,10 @@ func NewSyntaxEdit(parent walk.Container) (*SyntaxEdit, error) {
se.GraphicsEffects().Add(walk.InteractionEffect)
se.GraphicsEffects().Add(walk.FocusEffect)
se.MustRegisterProperty("Text", walk.NewProperty(
- func() interface{} {
+ func() any {
return se.Text()
},
- func(v interface{}) error {
+ func(v any) error {
if s, ok := v.(string); ok {
return se.SetText(s)
}